read and parse file

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) {
}
 
D

dar7yl

What is the expected output of your program, and what are you actually
getting?
What is the program doing when it fails. ie, what input line is it reading?
Is this your complete program?

You might want to create a mini-language, concentrating first on the
simplest form of the data you want to extract
vis:
<data> ::= <property> | <value>

<property> ::= <label> ':' <number>|<string>
// for instance 'structure name: motion envelope'

<value> ::= <label> '=' <number>|<array> ';'
// for instance 'minimumDose= 10000.000000;'
or 'normalizationPoint={ 0.000000 0.000000 0.000000 };'

Then design your parser to extract the appropriate elements, and place
them somewhere to be dealt with after the parsing is completed,
either on a line-by-line basis, or the complete file.

I suspect that your next assignment is to parse the dvhCurveList
which would involve a wee bit of recursion. You should structure
your solution to anticipate this.

regards,
Dar7yl
 
G

gimme_this_gimme_that

You can get it in a few lines if you use a regular expression.

I'm used to using the jakarta oro package.

If you agree to use oro I'll write up a solution.
 
H

Heiner Kücker

Sue wrote
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
}
}

Is this useful for you:

http://www.heinerkuecker.de/DomainParser.html

Download:

http://www.heinerkuecker.de/DomainParser.zip

Sorry, doc is only in german laguage,
but code is readeable for englisch speakers.

See the HierarchicProperties example.

Heiner Kuecker
Internet: http://www.heinerkuecker.de http://www.heiner-kuecker.de
JSP WorkFlow PageFlow Page Flow FlowControl Navigation: http://www.control-and-command.de
Java Expression Formula Parser: http://www.heinerkuecker.de/Expression.html
CnC Template Technology http://www.heinerkuecker.de/Expression.html#templ
Domain Specific Languages http://www.heinerkuecker.de/DomainParser.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top