PDA

View Full Version : Problem using DC_READ_FREE



hcrisp
09-22-2009, 10:48 AM
I have a long ASCII file which I am trying to read in with DC_READ_FREE. The file includes the following lines ("?" character indicates a line break):



...
$TEXT?
70?
0?
9?
$TEXT?
1?
?
9?
...


DC_READ_FREE results in a missing line where there is no characters, only a line break (see bold above). In other words, if I print the result it gives:



$TEXT
70
0
9
$TEXT
1
9


How can I get it to read in a blank line where no text exists? I am using WAVE 8.00 with the following call:



strdata = STRARR(2)
st = DC_READ_FREE(file, strdata, /ROW, DELIM='|', RESIZE = [1])

hcrisp
09-23-2009, 02:52 PM
Found a work-around which uses READU instead. I could not find a way to do it with DC_READ_FREE. Example .txt file is attached.

Here is the code which doesn't work (note the missing line):


strdata = STRARR(2)
st = DC_READ_FREE('example.txt', strdata, /ROW, DELIM='|', RESIZE=[1])
info, strdata
; STRDATA STRING = Array(7)
pm, strdata
; $TEXT
; 70
; 0
; 9
; $TEXT
; 1
9


Here is the code which works:


OPENR, unit, 'example.txt', /GET_LUN
res = LFSTAT(unit)
nbytes = res.size
bdata = BYTARR(nbytes)
READU, unit, bdata
FREE_LUN, unit

CR_b = 13B
LF_b = 10B
nbytes = N_ELEMENTS(bdata)
id = WHERE(bdata(0:nbytes-2) EQ LF_b AND bdata(1:*) EQ CR_b, cnt)

bsub = bdata(0:id(0))
bsub = [bsub, 32B, bdata(id(0)+1:*)]
strdata = STRING(bdata)
pm, strdata
; $TEXT
; 70
; 0
; 9
; $TEXT
; 1
;
; 9


If you have multiple blank lines you would loop over the WHERE indicies and keep appending bsub. Thereafter you can parse strdata as if you had read each line as it is written.

Was there an easier way to do it?