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!

Need help Fortran

Status
Not open for further replies.

Carbai

Programmer
Mar 14, 2019
1
IT
Hi everybody.

I'm new in the community of Fortran. I have a problem with a code I'm trying to write using Fortran95. I need my code read an array of unknown size from a file. I know how find the dimensions of the array and how allocate it but when I try to read the numbers into the array I get this error and I can't figure out what is the problem. I attach some part of the code to better explain.

!Reading the arrays

integer, parameter:: kp=selected_real_kind(18,50)

real(kp),dimension:),:),allocatable:: A

integer :: A_rows, A_col

..........

..........

allocate(A(A_rows,A_col))

doI=1,A_rows
read(iu,200,end=90)A(I,:)

write(*,200)A(I,:)

end do

90continue

200format(5E18.6)

Fortran runtime error: Bad value during floating point read

Thanks for any help.


 
I assume you know the number of rows in the data file but didn't know the number of rows.
You can first read the file and count the number of rows.
Then you allocate your array, rewind your file and read the data into an array in the second reading of the file.
Maybe look at the example here:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top