Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

format specifier 1

Status
Not open for further replies.

bhorn63

Mechanical
Dec 13, 2010
3
thread545-223362

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!
 
Replies continue below

Recommended for you

Could you post a sample of the data you are trying to read. I tried your other sample you posted with the prvious thread. I had to change the top value of M to 9 but it didn't have any errors even though all the values it read ignored the sign. Could it have something to do with the ES format?
 
xwb- the previous thread wasnt mine, I was just referencing it because of the similarity. But attached is a an example file being read. I have tried using ES and just E, it doesnt seem to make a difference.

- 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.
 
 http://files.engineering.com/getfile.aspx?folder=b55e1b65-bc50-4d16-a9a6-19e5c9c583f7&file=Log10.txt
The problem is in the data. When there is a negative number, everything shifts by one column
Code:
11/29/2010 12:18:49.3 5.10E-7 2.94E-7 8.98E-7 ...
11/29/2010 12:20:11.5 -3.80E-8 3.10E-7 -1.60E-8 ...
One way around that is to read the date and time as fixed and then read the rest of the numbers in free format. Something like this (I've switched your m and n round so that it is easier to debug)
Code:
      integer, parameter:: nmax = 50
      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
 
Thank you very much XWB, It worked! The only fix I had to do was to lengthen the buff and a few small other changes for my code. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor