Conversion of ARPS 4.5.0 to ARPS Fortran 90 Standard

and Testing of the F90 Version

 

Presentation by Yanming Li

July 9, 1999

 

 

·       ARPS coding standard in F90 and sample code

·       An Overview of F77toF90 Converter

·       Modification of Makefiles

·       Testing of ARPS

·       Dynamic Memory Allocation (ARPS4.4.0)

 

 

ARPS coding standard in F90 and sample code

See ARPS homepage—future plan

 

·       F77 to F90 Convertor Overview

·       A Flowchart

·       Input(*. f)

·       Read the code line by line and

·       Build a linked list.

·       Replace tabs anywhere with space

·       Convert lowcase keywords into uppercase

·       Adjust all lines to column 1

·       Modify variable declaration

·       REMOVE INCLUDE

·       INSERT USE before implicit NONE

·       Writing out and Indention

·       Output (*. f90)

 

F77toF90 Converter Overview

How to use

 

       Two versions:

 

·       One for conversion of  *.f  to *.f90

/work/yli/arps4.5.0.release.f90/src/to_f90.f90
·       One for conversion of  *.inc  to *.f90
/work/yli/arps4.5.0.release.f90/include/to_f90.f90

                           (We add the following functions in this version

                                           Remove COMMON statements

                                           Insert IMPLICIT NONE

                                           Insert SAVE)

 

Converting ARPS

 

·   Compile the converter: f90 to_f90.f90

·   Create a file of name list

         ‘ ls –1 */*.f  > enlist ’  in src directory

          (or ‘ ls –1 *.inc > enlist ’ in the include dir.)

·   Insert a empty line at the end of enlist (in order for the last file to be converted and interruption of the convertor)

·   a.out < enlist

·   Remove all *.f  (preparation for makearps)

·   makearps –90 --- and start hand modification

 

F77toF90 Converter Overview

Common Problems/hand modifications

 

    Continuation lines/Quotation marks (80%)

·       write(*, ‘very long format’), the quotaton marks were broken by continuation marks

 

           solution 1: Rewritten with “ write(*, 1111) +

           1111 format ( very long format)”  in the present                                   

           ARPS f90 version.

 

                Solution 2:  Use two quotation marks: one at the
                end of previous line and the other at the beginning  
                of the continued line ?

 

·       Very long strings have been broken into separate small strings in all ARPS code except arps_mpi.

   

     Character declarations (1-5%)

  

       Check with the F77 code when compiler Complains      (When character variables with different lengths were declared in one single line, the converter will rewrite them into separate lines such that all the character variables on the same line have same length, like CHARCTER(LEN=*) :: filename.  However, during extraction, the converter may introduce some bugs, but only several files for the whole ARPS)  

 

    Others

           The converter may have problems to convert Dummy subroutines. In this case, you may need to insert an comment line between ‘SUBROUTINE …’ and ‘END SUBROUTINE …’.  We need at least three-line long subroutine to make the converter run properly. (This is a problem of linked list in this converter.)

 

          Spaces between dot and ‘AND’/’OR’ are not allowed in F90.  If there is a space between dot and ‘EQ’ / ‘LT’ …, the converter will not convert it into ‘==’ / ‘<=’. We may fix this in the later version of the converter.

 

Modification of Makefiles

· Added a new Makefile in the include dir.

    See /work/yli/arps4.5.0.release.f90/include

· Modify the Makefile in the root of ARPS in order to compile data Modules first

          see /work/yli/arps4.5.0.release.f90/Makefile

· Update dependencies for all Makefiles in src dirs

· Add  SUFFIXES  to all Makefiles in order to compile f90 code:

     .SUFFIXES: $(SUFFIXES) .f90

     .f90.o:

               $(F90) $(FFLAGS) -c $<

· Need to REMOVE  all “*.f” file before compile “*.f90” code

· Working version on origin

 

TESTING

Issues in arps testing

 

   Initialization

Initialization in f90 data module, such as soilcst.f90, is not allowed:

              Break soilcst.f90 into two parts:

                          Soilcst.f90 for pure variable declaration

              Soilcst.init for initialization using F90 array

                          initializer

               insert “ INCLUDE ‘soilcst.init’ ” right before the   excutable in the subroutine which has a ‘USE soilcst’ statement.

 

  USE statements cause difference

·       Variables in soilcst.inc in f77 version are local to the subroutines which have a “INCLUDE ‘soilcst.inc’ ” statement.

·       Variables in soilcst.f90 in f90 version are shared(like COMMON, partially global) between the subroutines which have a ‘USE soilcst’ statement.

·       REALCASE tests show a minute difference between these two version. See /scratch/origin/yli/std_test_90/realcase.

          

TESTING

Issues in ext2arps/adas testing

 

Ext2arps:

 

·                Break gribcst.inc into two parts:

             Gribcst.f90 data module for pure variable declarations

            Gribcst.init for variable initialization

·                2D-array initialization has problems in F90?

         See /work/yli/arps4.5.0.release.f90/include/soilcst.init for 2D array initialization in F90.

 

adas

 

Initadas.f90 

                   READ(5, adas_backerf, END=300)

                   300 CONTINUE

These two lines are correct, but it may come with a little problem when adas is executed. REWRITE them or MOVE them up. Problem disappears.

 

TESTING

In Summary

 

·       Testing standard: for same f90 compiler and some options, we should obtain exactly same results from the f77 code and the f90 code (realcase is the only exception so far and we have identified the reason)

·       No bugs in F90 version found so far after

Makearps

·       A minor difference in ‘realcase’ testing due to

    USE module

·       Passed all the standard tests except arps_mpi

·       Still working on arps_mpi

·       Conversion based on arps4.5.0.release

·       Testing results available on /scratch/origin/yli/std_test_90

 

Dynamic Memory Allocation

ARPS4.4.0-arps

 

Hand modification

 

·       Remove dims.f90

·       Declare all the arrays in arps.f90 using      ALLOCATABLE attribute

·       CALL initpara(nx,ny,nz) and obtain nx, ny, nz (nx, ny, nz are passed to initpara3d.f90 by a NAMELIST called (&)dimensions)

·       Use ALLOCATE / allocfail(istatus, ‘—‘)

     See /work/yli/arps4.4.0.f90/src/arps/arps44.f90

·       Modify nx, ny, nz without recompiling (dynamic allocation)

 

Timing fixed/dynamic allocation

 

Dynamic allocation improve the speed of arps by 15%-20%  on Origin200 (may20 test, compare results from arps.output.f90.alloc.7200 and arps.output.f90.7200 in /work/yli/arps4.4.0.f90 )