Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

How to convert String literals to integers ? 1

Status
Not open for further replies.

arunmd1

Programmer
Mar 20, 2008
24
0
0
FR
Hi . my program is reading a string '0.5' from a supplied input file. I have to convert this into a real value of 0.5
Does anybody know how to do it?
 
Read it
Code:
character*20::strvalue
real:: fval
strvalue = '0.5'
read (strvalue, *) fval
 
Hi xwb, Thanks for ur reply.
But while i try to execute the code u gave, it is throwing 3 errors.
One of the error is given below.

Error: A REAL or INTEGER or LOGICAL data type is required in this context. [STRVALUE]
read(strvalue,*) fval
 
Which version of fortran are you using? 66 77 90 95 or 2003.

Should work from 77 onwards. What is strvalue declared as?
 
I am using 77 . String value is '0.5'
 
Try this and see if it builds - it works on g77
Code:
      program atol
      character*16 strval
      real fval
      strval = '0.5'
      read (strval, *) fval
      write (*, *) fval
      stop
      end program
 
Hey i got the answer.

we can use

STRVAL = '0.5'
READ (STRVAL,'(f3.2)') Floatvariable
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top