Mar 20, 2008 #1 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?
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?
Mar 20, 2008 1 #2 xwb Programmer Jul 11, 2002 6,828 0 36 GB Read it Code: character*20::strvalue real:: fval strvalue = '0.5' read (strvalue, *) fval Upvote 0 Downvote
Mar 20, 2008 Thread starter #3 arunmd1 Programmer Mar 20, 2008 24 0 0 FR 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 Upvote 0 Downvote
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
Mar 20, 2008 #4 xwb Programmer Jul 11, 2002 6,828 0 36 GB Which version of fortran are you using? 66 77 90 95 or 2003. Should work from 77 onwards. What is strvalue declared as? Upvote 0 Downvote
Which version of fortran are you using? 66 77 90 95 or 2003. Should work from 77 onwards. What is strvalue declared as?
Mar 21, 2008 Thread starter #5 arunmd1 Programmer Mar 20, 2008 24 0 0 FR I am using 77 . String value is '0.5' Upvote 0 Downvote
Mar 25, 2008 #6 xwb Programmer Jul 11, 2002 6,828 0 36 GB 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 Upvote 0 Downvote
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
Apr 1, 2008 Thread starter #7 arunmd1 Programmer Mar 20, 2008 24 0 0 FR Hey i got the answer. we can use STRVAL = '0.5' READ (STRVAL,'(f3.2)') Floatvariable Upvote 0 Downvote