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!

Reading Complex Format

Status
Not open for further replies.

taka144

Technical User
Nov 13, 2012
1
AR
Hi, i'm very new at Fortran language and resently i've been having trouble with formats, specifically with complex formats while reading from an external file.
The file contains this matrix:
( 8.40, 0.62) (11.78, 1.14) (-2.17,-4.77) ( 4.84, 1.64) ( 3.26,-5.53)
( 0.44, 6.13) (-1.84,-5.56) ( 5.85, 3.40) (-3.61,-0.12) ( 9.05,-5.67)
( 5.80,-3.28) ( 6.46, 6.03) ( 1.49,-2.24) (-3.61, 5.05) ( 4.46, 4.09)
( 3.59,-4.65) (11.05, 0.12) ( 6.55,-5.00) ( 4.89, 0.39) ( 9.13, 5.14)
(10.51,-1.64) ( 5.71,-5.95) ( 5.58, 4.77) ( 9.43,-3.11) ( 3.92,-1.75)

In my code i've writen:
Open(10,file='P06-Matriz.dat')
Do i=1,5
Read(10,90)(Q(i,j),j=1,5) !line17
End Do
90 Format((f5.2,f5.2),2x)

But when executing de compiled program, this message results:
At line 17 of file Ejercicio12.f (unit = 10, file = 'P06-Matriz.dat')
Fortran runtime error: Bad value during floating point read

I've been trying changing the formats from the real and imaginary parts, but none resulted good.


Well, hope you guys can help me with this. Thanks in advance.


 
The format statement you have given expects blocks of 5 character numbers with no readability characters i.e.
Code:
 8.40 0.6211.78 1.14-2.17-4.77 4.84 1.64 3.26,-5.53
 0.44 6.13-1.84-5.56 5.85 3.40-3.61-0.12 9.05,-5.67
...
If you wish to read the data in the format you have given, the format statement needs to be changed to
Code:
!              (  8.40  ,   0.62  )
90 format (5 (1X, F5.2, 1X, F5.2, 2X))
The comment above tells you which part of the data you are reading.
 
For as long as Q has been declared COMPLEX, you can simply read list directed without any format specification...I recommend that over any format...don't like column-oriented reading.

So, simply do:
Code:
Do i=1,5
Read(10,*)(Q(i,j),j=1,5)
End Do

In fact, I always read from standard input, so that I am not stuck with hard coded input file names. I run my files like this:
Code:
> myprogram < myinputfile
and read like this
Code:
Do i=1,5
Read(*,*)(Q(i,j),j=1,5)
End Do
i.e., no unit number.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top