Fortran: String to Real Conversion

  • Context: Fortran 
  • Thread starter Thread starter DizzyDoo
  • Start date Start date
  • Tags Tags
    Fortran String
Click For Summary
SUMMARY

The discussion focuses on converting a string to a Real data type in Fortran, specifically using the G77 compiler. The user, Matt, encountered challenges due to the lack of an intrinsic function for this conversion. A solution is provided using an internal read method, demonstrating how to read from a character string into Real variables. The provided Fortran 77 example illustrates the process effectively.

PREREQUISITES
  • Understanding of Fortran programming language
  • Familiarity with G77 compiler
  • Knowledge of data types in Fortran, specifically Real and CHARACTER
  • Basic concepts of internal file reading in Fortran
NEXT STEPS
  • Research "Fortran internal read" for detailed examples and explanations
  • Explore advanced data type conversions in Fortran
  • Learn about Fortran 77 syntax and best practices
  • Investigate other Fortran compilers and their handling of string conversions
USEFUL FOR

This discussion is beneficial for Fortran developers, particularly those working with G77, and anyone needing to perform string to Real conversions in their applications.

DizzyDoo
Messages
13
Reaction score
0
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
 
Technology news on Phys.org
Here's a quick F77 example that demostrates how you can do it, an internal read (from a character string).
Code:
      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
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:

Similar threads

  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K