- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My program scans a data file and reads real numbersvia internal readings. The numbers can be with or without E exponent. Also they may not have a decimal point. I solved it as bellow and would appreciate any comment.
Kind regards
Hamid
DOUBLE PRECISION XCOORD
CHARACTER*80, TEMPSTRING
TEMPSTRING = " 1E+03 "
! Remove leading blanks
TEMPSTRING = ADJUSTL(TEMPSTRING)
! Position of decimal point
IF (INDEX(TEMPSTRING,'.') .EQ. 0) THEN
I3 = INDEX(TEMPSTRING,' ') ! Position of next first blank
READ(TEMPSTRING, '(E
ELSE
READ(TEMPSTRING, '(E)') XCOORD
END IF
PRINT *, "XCOORD", XCOORD
END
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
However, if this meets your needs, then that's what really matters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
However, if this meets your needs, then that's what really matters.
Many thanks for this.
Using only the E format with .0 seems work but I am not completely sure. As I know the .d is the number of places after the decimal point (please correct me if I am mistaken) and I don't know if it can always be zero. That is why I used different formats.
I used VFE to specify the field width as they vary. Is it possible to read from a substring when the width is unknown?
Hamid
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is possible to read from a substring when the width is unknown, though you really have to take advantage of another extension to do so, unless you're willing to write a format string. The Intel compiler will shorten the format width if the input field is short. Maybe using the VFE isn't so bad after all!
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page