Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29242 Discussions

Character to Real conversion-Fortran90

stearns
Beginner
2,465 Views
I have a program that scans a text file and finds strings in a certain column that look like numbers, ie 100.3, it grabs these strings and prints them out.Now I want to use the same routine, but once the character string is found, ie 100.3, I would like to assign it to a real variable so I can use it in a math expression.. Can this be done?
0 Kudos
6 Replies
TimP
Honored Contributor III
2,465 Views
This could be as simple as
READ(charstr,*)realval
The "rules and restrictions" in Adams, Brainerd et al are in the section titled "Data Transfer on Internal Files."
Examples of Internal File I/O appear in the Intel compiler .pdf manual.
0 Kudos
vinicius_reis
Beginner
2,465 Views

And what do I do If I want do to exactly the opposite?

0 Kudos
Steven_L_Intel1
Employee
2,465 Views
WRITE (STRING,*) variable....

The * can be an explicit format as well.

This is called "Internal I/O" and is a standard language feature of Fortran. You can read about it in the Intel Fortran Language Reference.
0 Kudos
vinicius_reis
Beginner
2,465 Views

Sorry, but with opposite I meant read a real variable and pass its value to a string.

0 Kudos
Steven_L_Intel1
Employee
2,465 Views
I understood - that's what I described above.

The way one does this sort of thing in Fortran is to pretend you are writing to or reading from a file, except that the character variable takes the place of the unit number.
0 Kudos
vinicius_reis
Beginner
2,465 Views
Got the idea! Thanks very much!
0 Kudos
Reply