Contact US

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

Problem with READing char into real variable!!!

Problem with READing char into real variable!!!

Problem with READing char into real variable!!!

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

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


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

RE: Problem with READing char into real variable!!!

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.

RE: Problem with READing char into real variable!!!

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.


RE: Problem with READing char into real variable!!!

Why not use free format? Just replace the format string with an asterisk.


RE: Problem with READing char into real variable!!!

Equivalence the REAL with a character array.


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