S
Sue
I have a text file in the following format -- I need to read and parse
this file and extract values for minDoseBinIndex and minimumDose. Any
pointers on how to do this will be of much help. I spend hours trying
to do this and all I have is code below which for some reason does not
work, I am not able to capture the values that I need. Can someone
PLEASE help? Thank you SO very much!
----------sample data file-----------------
voxelVolume: 0.004395
binSize: 0.163389
structureSetUID:
doseVolumeUID:
œ(A¼t @ëÿ@>*A¼t @
normalizationPointDose= 0.000000;
normalizationPoint={ 0.000000 0.000000 0.000000 };
numOfdvhCurves= 16;
dvhCurveList={
structure name: motion envelope
associatedROIUID: 0
minDoseBinIndex= 61203;
minimumDose= 10000.000000;
precedence= 10;
isTarget= 0;
numOfBins= 1;
voxelCounts={ 0
}
}
----------code extract------------------------
FileReader rd = new FileReader(strFileName);
StreamTokenizer st = new
StreamTokenizer(rd);
// Prepare the tokenizer for
Java-style tokenizing rules
st.parseNumbers();
//st.wordChars('_', '_');
st.eolIsSignificant(true);
// If whitespace is not to be
discarded, make this call
st.ordinaryChars(0, ' ');
// These calls caused comments to be
discarded
st.slashSlashComments(true);
st.slashStarComments(true);
// Parse the file
int token = st.nextToken();
while (token !=
StreamTokenizer.TT_EOF) {
token = st.nextToken();
switch (token) {
case StreamTokenizer.TT_NUMBER:
// A number was found; the
value is in nval
double num = st.nval;
System.out.println("num=" +
num);
// break;
case StreamTokenizer.TT_WORD:
// A word was found; the
value is in sval
//if
(st.sval.equals("minDoseBinIndex")) {
String word = st.sval;
System.out.println("word="
+ word);
// }
break;
case '"':
// A double-quoted string
was found; sval contains the contents
String dquoteVal = st.sval;
//
System.out.println("dquoteVal" + dquoteVal);
break;
case '\'':
// A single-quoted string
was found; sval contains the contents
String squoteVal = st.sval;
//
System.out.println("squoteVal=" + squoteVal);
break;
case StreamTokenizer.TT_EOL:
// End of line character
found
break;
case StreamTokenizer.TT_EOF:
// End of file has been
reached
break;
default:
// A regular character was
found; the value is the token itself
char ch = (char)st.ttype;
System.out.println("ch" +
ch);
break;
}
}
rd.close();
} catch (IOException et) {
}
this file and extract values for minDoseBinIndex and minimumDose. Any
pointers on how to do this will be of much help. I spend hours trying
to do this and all I have is code below which for some reason does not
work, I am not able to capture the values that I need. Can someone
PLEASE help? Thank you SO very much!
----------sample data file-----------------
voxelVolume: 0.004395
binSize: 0.163389
structureSetUID:
doseVolumeUID:
œ(A¼t @ëÿ@>*A¼t @
normalizationPointDose= 0.000000;
normalizationPoint={ 0.000000 0.000000 0.000000 };
numOfdvhCurves= 16;
dvhCurveList={
structure name: motion envelope
associatedROIUID: 0
minDoseBinIndex= 61203;
minimumDose= 10000.000000;
precedence= 10;
isTarget= 0;
numOfBins= 1;
voxelCounts={ 0
}
}
----------code extract------------------------
FileReader rd = new FileReader(strFileName);
StreamTokenizer st = new
StreamTokenizer(rd);
// Prepare the tokenizer for
Java-style tokenizing rules
st.parseNumbers();
//st.wordChars('_', '_');
st.eolIsSignificant(true);
// If whitespace is not to be
discarded, make this call
st.ordinaryChars(0, ' ');
// These calls caused comments to be
discarded
st.slashSlashComments(true);
st.slashStarComments(true);
// Parse the file
int token = st.nextToken();
while (token !=
StreamTokenizer.TT_EOF) {
token = st.nextToken();
switch (token) {
case StreamTokenizer.TT_NUMBER:
// A number was found; the
value is in nval
double num = st.nval;
System.out.println("num=" +
num);
// break;
case StreamTokenizer.TT_WORD:
// A word was found; the
value is in sval
//if
(st.sval.equals("minDoseBinIndex")) {
String word = st.sval;
System.out.println("word="
+ word);
// }
break;
case '"':
// A double-quoted string
was found; sval contains the contents
String dquoteVal = st.sval;
//
System.out.println("dquoteVal" + dquoteVal);
break;
case '\'':
// A single-quoted string
was found; sval contains the contents
String squoteVal = st.sval;
//
System.out.println("squoteVal=" + squoteVal);
break;
case StreamTokenizer.TT_EOL:
// End of line character
found
break;
case StreamTokenizer.TT_EOF:
// End of file has been
reached
break;
default:
// A regular character was
found; the value is the token itself
char ch = (char)st.ttype;
System.out.println("ch" +
ch);
break;
}
}
rd.close();
} catch (IOException et) {
}