简体   繁体   中英

fortran77 to fortran90 differences in output

I have downloaded the following fortran program dragon.f at http://www.iamg.org/documents/oldftp/VOL32/v32-10-11.zip

I need to do a minor modification to the program which requires the program to be translated to fortran90 (see below to confirm if this is truly needed).

I have managed to do this (translation only) by three different methods:

  1. replacing comment line indicators (c for !) and line continuation indicators (* in column 6 for & at the end of last line)
  2. using convert.f90 (see https ://wwwasdoc.web.cern.ch/wwwasdoc/WWW/f90/convert.f90)
  3. using f2f.pl (see https :// bitbucket.org/lemonlab/f2f/downloads)

Both 1) and 3) worked (ie managed to compile program) while 2) didn't work straight away.

However, after testing the program I found that the results are different. With the fortran77 program, I get the "expected" results for the example provided with the program (the program comes with an example data "grdata.txt", and its example output "flm.txt" and "check.txt"). However, after running the translated (fortran90) program the results I get are different.

I suspect there are some issues with the way some variables are declared.

Can you give me recommendations in how to properly translate this program so I get the exact same results?

The reason I need to do it in fortran90 is because I need to input the parameters via a text file instead of modifying the program. This shouldnt be an issue for most of the parameters involved, except for the declaration of the last one, in which the size is determined from parameters that the program does not know a priori (see below):

implicit double precision(a-h,o-z)
parameter(lmax=90,imax=45,jmax=30)
parameter(dcta=4.0d0,dfai=4.0d0)
parameter(thetaa=0.d0,thetab=180.d0,phaia=0.d0,phaib=120.d0)
dimension f(0:imax,0:jmax),coe(imax,jmax,4),coew(4),fw(4)

So for example, I will read lmax, imax, jmax, dcta, dfai, thetaa, thetab, phaia, and phaib and the program needs to declare f and coe but as far as I read after googling this issue, they cannot be declared with an unknown size in fortran77.

Edit: This was my attempt to do this modification:

character fname1*100
call getarg(1,fname1)
open(10,file=fname1)
read(10,*)lmax,imax,jmax,dcta,dfai,thetaa,thetab,phaia,phaib
close(10)

So the program will read these constants from a file (eg params.txt), where the name of the file is supplied as an argument when invoking the program. The problem when I do this is that I do not know how to modify the line

dimension f(0:imax,0:jmax)...

in order to declare this array when the values imax and jmax are not known when compiling the program (they depend on the size of the data that the user will use).

As has been pointed out in the comments above, parameters cannot be read from file since they are set at compile time. Read them in as integer, declare the arrays as allocatable, and then allocate. integer imax,jmax real(8), allocatable :: f(:,:),coe(:,:,:) read(10,*) imax,jmax allocate(f(0:imax,0:jmax),coe(imax,jmax,4))

I found out that the differences in the results were attributed to using different compilers.

PS I ended up adding a lot more code than I intended at the beginning to allow reading data from netcdf files. This program in particular is really helpful for spherical harmonic expansion. [tag:spherical harmonics]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM