Reputation: 37
I am finding difficult to read the text file assign the values for respective variables as soon in code.Please help me, Thank you
Program Console2
IMPLICIT NONE
Real :: BB,CC,DD
Integer n,AA
Character (LEN=8) Line
OPEN(UNIT=2,FILE="Chaq.txt",STATUS='unknown')
Do n=1,10
READ (2,('(a6,I12,F8.2,F8.2,F8.2)'))Line,AA,BB,CC,DD
write (*,*) AA,BB,CC,DD
End Do
End program Console2
Input File is
GRID 3954 -182.53196.65596-28.5831
GRID 3955 -186.40268.61172-28.5831
GRID 3957 -187.65493.24453-28.5831
GRID 3958 -173.982108.158 -28.5831
GRID 3959 -166.58396.77976-28.5831
GRID 3960 -164.51897.80294-28.5831
GRID 3961 -194.53573.86154-28.5831
GRID 3962 -186.237101.5011-28.5831
GRID 3963 -174.59296.25317-28.5831
GRID 3965 -184.89788.38072-28.5831
GRID 3966 -193.65277.39146-28.5831
GRID 3967 -168.41599.97072-28.5831
GRID 3968 -165.85866.80172-28.5831
GRID 3970 -174.87381.45816-28.5831
GRID 3971 -184.27268.54756-28.5831
GRID 3972 -173.699100.7843-28.5831
GRID 3973 -172.326102.0733-28.5831
GRID 3974 -178.06985.87581-28.5831
GRID 3975 -173.97666.80172-28.5831
Upvotes: 1
Views: 98
Reputation: 78364
You just need to take account of the spaces in the input file. Try this modification of your read
statement:
READ (2,('(1x,a4,8x,I4,8x,f8.2,f8.2,f8.2)')) Line,AA,BB,CC,DD
Note the use of the x
control edit descriptor, which tells the run-time how many character positions to ignore. Note also that I've understood your input file lines to start with one blank.
Upvotes: 2