2
votes

We have recently started lectures on fortran in Uni and our lecturer has very limited time to actually explain something. So since I have never had any experience with that programming language I am struggling on some of the problems. In particular the whole idea of formats. I am trying to assign a value to a variable from a text file.

program interpolation

implicit none
integer :: i,N
real :: T1,Hfg1,T2,Hfg2,T,Hfg
!-------------------------------------
open(20,file='values.txt')
!Input temperature to be interpolated
print*,'Input temperature to be interpolated'
read(*,*) T
!Read number of values from file
read(20,1000) N
1000 format(I5)

The code goes on from here, but what I am really struggling to understand is the whole format concept. The way I see it is that I open a file 'values.txt' and assign unit 20 to it, so whenever I call unit 20 I am refering to that file. Right ? After that I ask the user to input some initial value for T. Doesn't really matter. Now after that I read a value from the unit=20 file assign to a variable N. Now what does digit 1000 mean ? And what is the purpose of the next step, '1000 format(I5)' ? As far as I understand 'I5' means Integer with max number of characters of 5 ? Or am I wrong?

1

1 Answers

2
votes

"1000" is the statement label that connects the read to the format statement. On a read, "I5" means that the integer needs to be right justified in the first five columns.

See http://en.wikipedia.org/wiki/Fortran_95_language_features for the features of the language.