My other solution was to write some Java which would read the blw file and re-write it !
import java.io.*;
import java.lang.*;
import java.util.Vector;
public class StartHere {
public static void main(String[] args) {
Vector<Ratings> Ratings = new Vector<Ratings>();
System.out.println("Hello World");
String RatingsFile = "";
String OutputFile = "";
String inputStr = "";
if(args[0].compareTo("Normal")==0) {
RatingsFile = "C:/Dropbox/Kevin/Sailing/PH_Sailwave/NormalHandicaps/NormalRatingsXXAutumn2013.csv";
OutputFile = "C:/Dropbox/Kevin/Sailing/PH_Sailwave/PH Everybody 2014 Normal.blw";
} else if(args[0].compareTo("Personal")==0) {
RatingsFile = "C:/Dropbox/Kevin/Sailing/PH_Sailwave/PersonalHandicaps/PHratingsXXAutumn2013.csv";
OutputFile = "C:/Dropbox/Kevin/Sailing/PH_Sailwave/PH Everybody 2014 PH.blw";
} else {
System.out.println("Usage is ConvertBLW Normal/Personal");
}
if(RatingsFile.compareTo("")!=0) {
try{
InputStream is = new FileInputStream(RatingsFile);
int size = is.available();
int iField = 0;
String TextFieldOne = "";
String TextFieldTwo = "";
String TextFieldThree = "";
for(int iReadLine=0; iReadLine< size; iReadLine++){
char nextchar=(char)is.read();
if(nextchar==','){
if( iField==0) {
TextFieldOne = inputStr;
inputStr = "";
} else if( iField==1) {
TextFieldTwo = inputStr;
inputStr = "";
}
iField += 1;
}else if (nextchar=='\r') {
TextFieldThree = inputStr;
inputStr = "";
iField = 0;
System.out.println(".");
}else if (nextchar=='\n') {
Ratings ptrRating = new Ratings(TextFieldOne, TextFieldTwo, TextFieldThree);
Ratings.add(ptrRating);
}else{
System.out.print(nextchar);
inputStr = inputStr.concat(Character.toString(nextchar));
}
} // end for
is.close();
}catch(IOException e){
System.out.print("Exception failed to read ratings file");
}
// now read and convert the blw file
try{
int iField = 0;
boolean bFoundClass = false;
boolean bFoundRating = false;
String inputLine = "";
String StringNewRating = "";
String StrCompClass = "\"compclass\"";
String StrCompRating = "\"comprating\"";
InputStream is = new FileInputStream("C:/Dropbox/Kevin/Sailing/PH_Sailwave/PH Everybody 2014.blw");
int size = is.available();
OutputStream iout = new FileOutputStream(OutputFile);
for (int iReadLine=0; iReadLine< size; iReadLine++){
char nextchar=(char)is.read();
inputLine = inputLine.concat(Character.toString(nextchar));
if (nextchar==','){
if (iField==0) { // looking for start of first field
if (inputStr.compareTo(StrCompClass)==0) {
bFoundClass = true;
}else if (inputStr.compareTo(StrCompRating)==0) {
bFoundRating = true;
}
}else if (iField==1) {
if (bFoundClass == true) {
// look through the vectors of ratings to find this one
int iRatings = Ratings.size();
int iLength = inputStr.length()-1;
String StrClass = inputStr.substring(1,iLength);
boolean boolFound = false;
for (int i=0; (i<iRatings && boolFound==false); i++){
Ratings ptrRating = (Ratings) Ratings.elementAt(i);
StringNewRating = ptrRating.Match(StrClass);
if (StringNewRating.compareTo("")!=0){
boolFound = true; // break out of loop
}
} // end for
if (boolFound == false) {
System.out.println("There is no Rating entry for " + inputStr + " FIX THIS NOW!");
}
bFoundClass = false;
}
}
iField += 1;
inputStr = "";
}else if (nextchar=='\n') {
// write the line back out
if (bFoundRating == true) {
// overwrite inputLine with a nobled version
String StrTail = inputLine.substring(18);
if (inputLine.charAt(17)=='"') {
StrTail = inputLine.substring(17);
}
inputLine = "\"comprating\",\"";
inputLine = inputLine.concat(StringNewRating);
inputLine = inputLine.concat(StrTail);
bFoundRating = false;
}
int iBytes = inputLine.length();
for (int i=0; i<iBytes; i++){
int iChar = inputLine.charAt(i);
try {
iout.write(iChar);
} catch (IOException e) {
e.printStackTrace();
}
} // end for
iField = 0;
inputStr = "";
inputLine = "";
} else {
inputStr = inputStr.concat(Character.toString(nextchar));
}
System.out.print(nextchar);
} // end for
is.close();
iout.flush();
iout.close();
}catch(IOException e){
System.out.print("Exception failed to read the blw file correctly");
}
finally {
}
}
System.out.println("Goodbye World");
}
}