format specifier
format specifier
(OP)
thread545-223362: Help read the file
My question is related to the above thread. I am trying to read from an input file a date/time stamp followed by 2000 data values. I can read correctly the date/time stamp and all positive values but if i try to read any negative values the read statement crashes. Below is my read and format statement. So the question is how can I read both positive and negative values without knowing exactly where they are in the array?
READ(Unit=InFileUnit,FMT=30,END=990,ERR=920) Datemm(N),
1 Datedd(N),Dateyyyy(N),Timehh(N),Timemm(N),
2 Timess(N),Timep(N),(Value(N,M),M=1,22)
30 FORMAT(I2,1X,I2,1X,I4, 1X,I2,1X,I2,1X,I2,1X,I1,
1 22(1X,ES7.2E1))
The M=22 is because that happens to be the number of values that are all positive before the first negative value. I have tried just using E7.2 and if i change it to 8.2 to count for the negative sign then the positive values wont even read in. ps. this is not for any homework this is for my own research. Thank you for any and all help!
My question is related to the above thread. I am trying to read from an input file a date/time stamp followed by 2000 data values. I can read correctly the date/time stamp and all positive values but if i try to read any negative values the read statement crashes. Below is my read and format statement. So the question is how can I read both positive and negative values without knowing exactly where they are in the array?
READ(Unit=InFileUnit,FMT=30,END=990,ERR=920) Datemm(N),
1 Datedd(N),Dateyyyy(N),Timehh(N),Timemm(N),
2 Timess(N),Timep(N),(Value(N,M),M=1,22)
30 FORMAT(I2,1X,I2,1X,I4, 1X,I2,1X,I2,1X,I2,1X,I1,
1 22(1X,ES7.2E1))
The M=22 is because that happens to be the number of values that are all positive before the first negative value. I have tried just using E7.2 and if i change it to 8.2 to count for the negative sign then the positive values wont even read in. ps. this is not for any homework this is for my own research. Thank you for any and all help!





RE: format specifier
RE: format specifier
- I have temporarily solved the problem by importing the file into an excel sheet, deleting the date/time stamp, exporting to a text file, and then reading from both files to get my date/time stamp and values so that I can specify my format for the date/time stamp and use free formating for the values. Though I would like to correct the original issue to save on data processing time.
-for the file, ignore the first two lines as I have written code to import those. I also tried to import just the date/time stamp, close and reopen the file, and read the date time stamp as a character of equal length and use free formating for the values, but the / in the stamp is read as an end of file I believe and stops the read statement.
RE: format specifier
CODE
11/29/2010 12:20:11.5 -3.80E-8 3.10E-7 -1.60E-8 ...
CODE
integer, parameter:: mmax = 22
integer datemm(nmax), datedd(nmax), dateyyyy(nmax)
integer timehh(nmax), timemm(nmax), timess(nmax), timep(nmax)
real value(mmax,nmax)
character(len=2048) buff
integer, parameter:: infileunit = 20
open (infileunit, file='log10.txt', status='unknown');
read (infileunit, *) buff
read (infileunit, *) buff
do n = 1, nmax
read (infileunit, '(A)', end=990) buff
read (buff,FMT=30, ERR=920)
1 Datemm(N), Datedd(N), Dateyyyy(N),
2 Timehh(N),Timemm(N), Timess(N),Timep(N)
30 FORMAT(I2,1X,I2,1X,I4, 1X,I2,1X,I2,1X,I2,1X,I1)
read (buff(22:), *) (value(m,n), m = 1, mmax)
print '(8E9.3E1)', (value(m,n), m = 1, mmax)
end do
RE: format specifier