Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Problem with READing char into real variable!!! 1

Status
Not open for further replies.

mjs84

Aerospace
Aug 20, 2003
27
0
0
US
I am having a problem reading a 'character' string into a 'real' variable. The only way I know how to do it is:

character cstr
real realva
read(cstr,'(f8.3)') realva

I think that's what I have employed below, but as you can tell from the 'output', I am not getting what I'm expecting.

If anyone can see a problem with this code, I would surely appreciate it.

Thanks, mjs84



CHARACTER*42 LIDEN
REAL*8 TMPVAR

LIDEN = 'MIN.375/MAX.378_1'

WRITE(7,'(2A)') 'Element ID is: ', LIDEN
WRITE(7,'(2A)') 'chrs 4:7 are: ', LIDEN(4:7)
READ(LIDEN(4:7),'(f8.3)') TMPVAR
WRITE(7,'(A,F8.3)') 'tmp real var: ', TMPVAR


.......................................................
Output:

Element ID is: MIN.375/MAX.378_1
chrs 4:7 are: .375
tmp real var: .000 (I am expecting a ' .375' here.)
 
Replies continue below

Recommended for you

The floating point field width is 4, not 8, and so I think you need to change your format from f8.3 to f4.3. Acutally, I think for input the number of decimal places is subject to over-ride by the decimal point so f4.0 should also work.
 
I agree with Toog. To be safe... you may even want to develop a more standard/generic way of doing this ( ie, less subject to simple errors and easy to implement over and over again ).

Character*80 tmpchar
Real*8 tmpreal
: : : : : :
tmpchar = Liden(4:7)
Read(tmpchar,'(f80.0)') tmpreal

tmpreal will now contain the value you want.

Dan :)
 
Status
Not open for further replies.
Back
Top