Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to adjust the reading format?

Status
Not open for further replies.

ranaobaid

Instructor
Apr 18, 2013
1
Hi,

I have a file which contains the following data:

(1.642725279821993E-015,0.000000000000000E+000)
(-1.001572459876100E-015,0.000000000000000E+000)
(1.272947723002678E-015,0.000000000000000E+000)
(-1.469368207939234E-018,0.000000000000000E+000)
(-4.339782372036402E-015,0.000000000000000E+000)
(6.649449890178669E-016,0.000000000000000E+000)
(1.828705241163553E-015,0.000000000000000E+000)

Will you please help me to know how to adjust the reading format in Fortran 90 to read the above data without the brackets"()".

Thanks in advance,
Rana.
 
It is not that you need to read the data without the parenthesis...I think you are looking at COMPLEX quantities, i.e., numbers with REAL and IMAGINARY components. So, to read this data, you simply declare the variable COMPLEX and use to read each number...the whole number will go into a single variable, "including" the parenthesis...then, when you need to real part of it, you use REAL(variable) and when needing the imaginary part you use AIMAG(variable)

For example, if you wanted to read the 7 numbers listed above, you could put them in a file and read them like this:
Code:
program rcomp
    complex c
    integer i
    do i = 1, 7
        read(*,*) c
        write(*,*) 'c = ', c 
        write(*,*) 'real(c) = ',real(c) 
        write(*,*) 'imag(c) = ',aimag(c) 
    end do
end program rcomp
where you need to run the program by simply using re-direction (no need to open specific filename, etc):

myprog < inputfile












 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top