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,
  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
    999   FORMAT(A80)
    998   FORMAT(F10.2,F10.2)
    If you need more information, google "fortran internal read", or try the following links:
    http://en.wikibooks.org/wiki/Fortran_FAQ [Broken]
    Last edited by a moderator: May 4, 2017
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook