Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran: String to Real Conversion

  1. Feb 7, 2009 #1
    This has been bugging my (and my program) for a few days now. I'm searching for a way to convert a string (or more properly; a collect of characters) to a Real data type. I'm new to Fortran, but as I understand it there seems to be no intrinsic function to make this easy.

    I have tried various solutions to this problem, just as using Write(*,*) to write the string to the real, but the real seems to stubbornly stay 0.

    The reason I require this is that I'm taking data straight from the command line which is parsed in string format. Other information that may be useful is that my compiler of choice is the G77 compiler.

    Solution to this problem would be must appreciated,
    Matt
     
  2. jcsd
  3. Feb 7, 2009 #2
    Here's a quick F77 example that demostrates how you can do it, an internal read (from a character string).
    Code (Text):
          REAL*8 A,B
          CHARACTER*80 LINE
          READ(5,999)LINE
          READ(LINE,998)A,B
          WRITE(6,998)A,B
          STOP
    999   FORMAT(A80)
    998   FORMAT(F10.2,F10.2)
          END
    If you need more information, google "fortran internal read", or try the following links:
    http://en.wikibooks.org/wiki/Fortran_FAQ [Broken]
    http://www-mipl.jpl.nasa.gov/portguide/subsection3.9.5.html
    http://www.megasolutions.net/fortran/internal-read-of-character-array_F-ifort-differences-77847.aspx
     
    Last edited by a moderator: May 4, 2017
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fortran: String to Real Conversion
  1. FORTRAN REAL*INT error (Replies: 2)

Loading...