source: LMDZ6/trunk/libf/misc/lmdz_netcdf.F90 @ 5068

Last change on this file since 5068 was 5068, checked in by abarral, 12 months ago

[to be continued, but should be stable]
Create lmdz_netcdf.F90 as a wrapper around netcdf, to

1) expose netcdf as a pure Fortran module (rather than module + include header)
2) handle NC_DOUBLE in a centralized way

Use said module in dynredem_mod.F90, guide_mod.F90

File size: 1.7 KB
Line 
1! ---------------------------------------------
2! This module serves as a wrapper around netcdf.
3! It serves two primary functions:
4!  1) Turn netcdf into a "real" fortran module, without the INCLUDE call
5!  2) Handle the NC_DOUBLE CPP key
6! ---------------------------------------------
7
8MODULE lmdz_netcdf
9  USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY : REAL64, REAL32
10  USE netcdf
11  IMPLICIT NONE
12  ! Note: as we want to expose netcdf through this module, we don't make all PRIVATE by default as usual
13  ! Instead, explicitely make PRIVATE the relevant items.
14
15  INCLUDE 'netcdf.inc'
16
17#ifdef NC_DOUBLE
18  INTEGER, PARAMETER :: NF90_FORMAT = NF90_DOUBLE
19  INTEGER, PARAMETER :: REAL_FORMAT = REAL64
20#else
21  INTEGER, PARAMETER :: NF90_FORMAT = NF90_FLOAT
22  INTEGER, PARAMETER :: REAL_FORMAT = REAL32
23#endif
24CONTAINS
25
26  ! We'd like to use "nf_put_var", but it already exists as a legacy nc4 function
27  INTEGER FUNCTION nf_put_var_rd(ncid, varid, vals)
28    INTEGER, INTENT(IN) :: ncid, varid
29    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
35  END FUNCTION nf_put_var_rd
36
37  INTEGER FUNCTION nf_put_vara_rd(ncid, varid, start, counts, vals)
38    INTEGER, INTENT(IN) :: ncid, varid
39    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
46  END FUNCTION nf_put_vara_rd
47
48END 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 TracBrowser for help on using the repository browser.