Merge remote-tracking branch 'origin/release-v4.5'
[WRF.git] / hydro / IO / netcdf_layer.f90
blob850f2e8266fc174aa21b7ea399262bb3df1836ad
1 module netcdf_layer_base
2 use netcdf
3 use mpi
4 implicit none
6 type, abstract :: NetCDF_layer_
7 procedure (nf90_open), pointer, nopass :: open_file ! => nf90_open
8 procedure (nf90_def_dim), pointer, nopass :: def_dim !=> nf90_def_dim
9 procedure (nf90_inq_varid), pointer, nopass :: inq_varid !=> nf90_inq_varid
10 procedure (nf90_close), pointer, nopass :: close_file !=> nf90_close
12 procedure (integer), pointer, nopass :: put_var !=> nf_put_var
13 procedure (integer), pointer, nopass :: get_var !=> nf_get_var
14 procedure (integer), pointer, nopass :: put_att !=> nf_put_att
15 procedure (integer), pointer, nopass :: def_var !=> nf_def_var
16 contains
17 procedure (create_file_signature), pass(object), deferred :: create_file
18 end type NetCDF_layer_
20 integer, external :: nf_put_att
21 integer, external :: nf_def_var
22 integer, external :: nf_put_var
23 integer, external :: nf_get_var
25 abstract interface
27 function create_file_signature(object, path, cmode, initialsize, chunksize, ncid) result(res)
28 import NetCDF_layer_
29 class(NetCDF_layer_), intent(in ) :: object
30 character (len = *), intent(in ) :: path
31 integer, intent(in ) :: cmode
32 integer, optional, intent(in ) :: initialsize
33 integer, optional, intent(inout) :: chunksize
34 integer, intent( out) :: ncid
35 integer :: res
36 end function create_file_signature
38 end interface
40 type, extends(NetCDF_layer_) :: NetCDF_serial_
41 contains
42 procedure, pass(object) :: create_file => create_file_serial
43 end type NetCDF_serial_
45 type, extends(NetCDF_layer_) :: NetCDF_parallel_
46 integer :: MPI_communicator
47 integer :: default_info = MPI_INFO_NULL
48 contains
49 procedure, pass(object) :: create_file => create_file_parallel
50 end type NetCDF_parallel_
52 contains
54 function create_file_serial (object, path, cmode, initialsize, chunksize, ncid) result(res)
55 class(NetCDF_serial_), intent(in) :: object
56 character (len = *), intent(in ) :: path
57 integer, intent(in ) :: cmode
58 integer, optional, intent(in ) :: initialsize
59 integer, optional, intent(inout) :: chunksize
60 integer, intent( out) :: ncid
61 integer :: res
63 res = nf90_create(path = path, cmode = cmode, ncid = ncid)
65 end function create_file_serial
67 function create_file_parallel(object, path, cmode, initialsize, chunksize, ncid) result(res)
68 class(NetCDF_parallel_),intent(in) :: object
69 character (len = *), intent(in ) :: path
70 integer, intent(in ) :: cmode
71 integer, optional, intent(in ) :: initialsize
72 integer, optional, intent(inout) :: chunksize
73 integer, intent( out) :: ncid
74 integer :: res
76 res = nf90_create(path = path, cmode = cmode, ncid = ncid, &
77 & comm = object%mpi_communicator, info = object%default_info)
79 end function create_file_parallel
81 end module netcdf_layer_base