Ignore:
Timestamp:
Jul 18, 2024, 2:27:04 PM (4 months ago)
Author:
abarral
Message:

Reduce use of #ifdef NC_DOUBLE to single instance in lmdz_netcdf.F90
Add nf_get_vara_rd in lmdz_netcdf.F90
Remove #ifdef NC_DOUBLE in dynredem_mod.F90 & guide_loc_mod.F90
(minor) fix some casting in ncdf calls in guide_loc_mod.F90
(minor) replace netcdf call & reduncate implicit none in dynredem_mod.F90

File:
1 edited

Legend:

Unmodified
Added
Removed
  • LMDZ6/trunk/libf/misc/lmdz_netcdf.F90

    r5068 r5069  
    33! It serves two primary functions:
    44!  1) Turn netcdf into a "real" fortran module, without the INCLUDE call
    5 !  2) Handle the NC_DOUBLE CPP key
     5!  2) Handle the NC_DOUBLE CPP key. Ideally, this key should ONLY appear here (WIP). TODO
     6! Ideally, the "real" netcdf module/headers should ONLY be called here. (WIP) TODO
    67! ---------------------------------------------
     8! TODO check that none of the wrapped functions remain elsewhere
     9! TODO check all uses of `use netcdf` + netcdf.inc
    710
    811MODULE lmdz_netcdf
     
    1215  ! Note: as we want to expose netcdf through this module, we don't make all PRIVATE by default as usual
    1316  ! Instead, explicitely make PRIVATE the relevant items.
     17  PRIVATE CPP_NC_DOUBLE
    1418
    1519  INCLUDE 'netcdf.inc'
    1620
    1721#ifdef NC_DOUBLE
     22  LOGICAL, PARAMETER :: CPP_NC_DOUBLE = .TRUE.  ! Define a variable to reduce use of preprocessor ahead
    1823  INTEGER, PARAMETER :: NF90_FORMAT = NF90_DOUBLE
    1924  INTEGER, PARAMETER :: REAL_FORMAT = REAL64
    2025#else
     26  LOGICAL, PARAMETER :: CPP_NC_DOUBLE = .FALSE.
    2127  INTEGER, PARAMETER :: NF90_FORMAT = NF90_FLOAT
    2228  INTEGER, PARAMETER :: REAL_FORMAT = REAL32
     
    2430CONTAINS
    2531
     32  ! Note: below, we use the same declarations as the fortran netcdf lib, hence the use of (*)
     33
    2634  ! We'd like to use "nf_put_var", but it already exists as a legacy nc4 function
     35  ! CPP_NC_DOUBLE wrapper around nf_put_var_real, nf_put_var_double
    2736  INTEGER FUNCTION nf_put_var_rd(ncid, varid, vals)
    2837    INTEGER, INTENT(IN) :: ncid, varid
    2938    REAl(REAL_FORMAT), INTENT(IN) :: vals(*)  ! (*) as declared in netcdf lib
    30 #ifdef NC_DOUBLE
    31     nf_put_var_rd = nf_put_var_double(ncid, varid, vals)
    32 #else
    33     nf_put_var_rd = nf_put_var_real(ncid, varid, vals)
    34 #endif
     39
     40    IF (CPP_NC_DOUBLE) THEN
     41      nf_put_var_rd = nf_put_var_double(ncid, varid, vals)
     42    ELSE
     43      nf_put_var_rd = nf_put_var_real(ncid, varid, vals)
     44    END IF
    3545  END FUNCTION nf_put_var_rd
    3646
     47  ! CPP_NC_DOUBLE wrapper around nf_put_vara_real, nf_put_vara_double
    3748  INTEGER FUNCTION nf_put_vara_rd(ncid, varid, start, counts, vals)
    3849    INTEGER, INTENT(IN) :: ncid, varid
    3950    INTEGER, INTENT(IN) :: start(*), counts(*)
    40     REAl(REAL_FORMAT), INTENT(IN) :: vals(*)  ! (*) as declared in netcdf lib
    41 #ifdef NC_DOUBLE
    42     nf_put_vara_rd = nf_put_vara_double(ncid, varid, vals)
    43 #else
    44     nf_put_vara_rd = nf_put_vara_real(ncid, varid, vals)
    45 #endif
     51    REAl(REAL_FORMAT), INTENT(IN) :: vals(*)
     52
     53    IF (CPP_NC_DOUBLE) THEN
     54      nf_put_vara_rd = nf_put_vara_double(ncid, varid, start, counts, vals)
     55    ELSE
     56      nf_put_vara_rd = nf_put_vara_real(ncid, varid, start, counts, vals)
     57    END IF
    4658  END FUNCTION nf_put_vara_rd
    4759
     60  ! CPP_NC_DOUBLE wrapper around nf_get_vara_real, nf_get_vara_double
     61  INTEGER FUNCTION nf_get_vara_rd(ncid, varid, start, counts, vals)
     62    INTEGER, INTENT(IN) :: ncid, varid
     63    INTEGER, INTENT(IN) :: start(*), counts(*)
     64    REAl(REAL_FORMAT), INTENT(OUT) :: vals(*)
     65
     66    IF (CPP_NC_DOUBLE) THEN
     67      nf_get_vara_rd = nf_get_vara_double(ncid, varid, start, counts, vals)
     68    ELSE
     69      nf_get_vara_rd = nf_get_vara_real(ncid, varid, start, counts, vals)
     70    END IF
     71  END FUNCTION nf_get_vara_rd
     72
    4873END MODULE lmdz_netcdf
    49 
    50 ! TODO check that none of the wrapped functions remain elsewhere
    51 ! TODO check all uses of `use netcdf`
Note: See TracChangeset for help on using the changeset viewer.