With a cursory look, I see a few problems:
1) Where do you define the variables year, month, day, hour, min, sec?
Any reads/readf needs the output variables to be defined, so that it
will know what kind of (and how much) data to read.
2) You define data as an array with one element per file line. But you
try to read the whole array for every line of the file.
The next are not what is causing the problem here, are just some
advice:
3) You should avoid using a literal for the unit number (1). You
should use a variable, and let open give it a number on execution (as
in 'openr,unit,file,/get_lun', which would then be closed by a
'free_lun,unit', with no need for close).
4) If the file has constant width columns and you want do do formatted
reads, it would be easier to read the whole thing into arrays with a
single readf, instead of line by line. If columns are not constant
width, but separated by markers, or you want to read line by line, it
would probably be easier and more robust to parse each line with
strsplit() or stregex().
On May 11, 9:49 am, Metzlmane <metzlm...@googlemail.com> wrote:
> Hy,
>
> i try to read data form an ASCII-File and get always the same error.
> if i use READF, i get "end of file encountered" and READS returns "End
> of input data ..."
>
> PRO Getdata,start_time,end_time
> Dir = 'C:\Dokumente und Einstellungen\luchs\Desktop\'
> file=Dir + '2011-04-22.txt'
>
> n = file_lines(file) - 1
> print,n
> data=replicate({TempK,Setp:0.0,A:0.0,B:
> 0.0,C1:0.0,C2:0.0,C3:0.0,C4:0.0,D1:0.0,D2:0.0,D3:0.0,D4:0.0, TCool:
> 0.0,HT:0.0,AH:0.0},n)
> time = timestamputc(1970,1,1,0,0,0)
>
> filename = FILE_BASENAME(file,'.txt')
> reads,filename,format='(I4,x,I2,x,I2)',year,month,day
> CLOSE,1 & OPENR,1,file
> ;on_ioerror, ers
> line = ''
> READF,1,line ;jump over Header
> WHILE ~ EOF(1) DO BEGIN
> ;-----------------Text in ASCII-
> File----------------------------------
> ;00:00:02|295.0| | |289.9|290.0|290.0|290.5| |
> | | | 0.0| 0.0| |
> READF,1,line
> Time = strmid(line,0,8)
> reads,time,format='(I2,x,I2,x,I2)',hour,min,sec ; equals '(9x)'
> ;time = timestamputc(year,month,day,hour,min,sec)
> print,strlen(line)
>
> reads,line,data,format='(9x,F5.1,x,F5.1,x,F5.1,x,F5.1,x,F5.1 ,x,F5.1,x,F5.1,x,F5.1,x,F5.1,x,F5.1,x,F5.1,x,F5.1,x,F5.1,x ,F5.1,x)'
> ;reads,line,format='(I2,x,I2,x,I2,x,F5.1,x,F5.1,x,F5.1,x,F5. 1,x,F5.1,x,F5.1,x,F5.1,x,F5.1,x,F5.1,x,F5.1,x,F5.1,x,F5.1, x,F5.1,x,F5.1,x)',hour,min,sec,data
>
> stop
> ENDWHILE
>
> on mouseover, the data is written into the the array "data" and
> strlen(line) shows 93.
> it also don't work if i remove the last "x" in the format-string.
>
> can anybody please tell me what i'm doing wrong? :)
|