Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

format specifier

format specifier

format specifier

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!

RE: format specifier

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?

RE: format specifier

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.  

RE: format specifier

The problem is in the data.  When there is a negative number, everything shifts by one column


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)


      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

RE: format specifier

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!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close