Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a fortran program that calculates global mean SST Sample code that reads t

ID: 3783053 • Letter: W

Question

write a fortran program that calculates global mean SST

Sample code that reads the text file is given in the following slide

program global_mean_sst

implicit none

integer, parameter :: NL=4606

real, dimension(NL) :: longitude, latitude, sst

integer :: i

! open the text file

open (11,file='global_sst.txt', status='old')

! read the text file

do i=1,NL

read (11,'(2f10.3,2x,e12.5)') longitude(i),latitude(i),sst(i)

enddo

! after above do-loop values are in variables longitude, latitude and sst

end program global_mean_sst

Explanation / Answer

You either need to use an implicit do loop or a formate statement. I like the method of the implicit do loop since formate strings are messy in fortran. Some times, there is no way around them especially when writing files try this do loop

do j= 1,378

read. (2,*) (A(i,j),i =1,378)

enddo

Usually, you can also do this

read (2,*) A

And it will fill A until A is full or until there is no data, but then you have no guarentee on which elements get filled I still recomended the implicit do loop method if you know the column count