Dear All,
I'm having trouble reading in a text file with dates and times in the
form:
11/10/99<tab><sp>16<sp>:<sp>47
where <tab> and <sp> represent tabs and spaces.
Sometimes the day/months are consist of only 1 char (e.g. 3/4/99). I
can write a separate FORMAT statement for each case but when I try to
use I0 to deal with both cases it doesn't work and it seems to be due
to the TAB char.
Am I just being foolish or what?
The following short program might hepl explain. I'm using IDL 5.2
under NT4.0.
Cheers,
Justin
pro test_read
;Create a Tab character
tab = STRING(9B)
;Create 2 lines of dummy input
line1 = '10/11/99' + tab + ' 19 : 42'
line2 = '1/3/99' + tab + ' 19 : 42'
;This format works for days/months with 2 digits
READS, line1, FORMAT='(I2,x,I2,x,I2,2x,I2,3x,I2)', dd,mm,yy,hh,mn
print, dd,mm,yy,hh,mn
;This format works for days/months with 1 digit
READS, line2, FORMAT='(I1,x,I1,x,I2,2x,I2,3x,I2)', d,m,yy,hh,mn
print, d,m,yy,hh,mn
;How to use the same format code for both line1 and line2?
;Presumably need to use I0 to automatically adjust to different
;widths.
;Just trying to read in the first 3 numbers (the date)
READS, line1, FORMAT='(I0,x,I0)', dd,mm ;This works
print, dd,mm
READS, line1, FORMAT='(I0,x,I0,x,I0)', dd,mm,yy ;This DOESN'T work
READS, line1, FORMAT='(I0,x,I0,x,I2)', dd,mm,yy ;This DOESN'T work
;Is there something strange going on with the tab character?
end
|