1!
2!  Copyright (C) 2013, Northwestern University and Argonne National Laboratory
3!  See COPYRIGHT notice in top-level directory.
4!
5! $Id: variables.f90 2012 2015-02-16 05:52:44Z wkliao $
6!
7! This file is taken from netcdf_variables.f90 with changes for PnetCDF use
8!
9!
10
11  ! -----
12  ! Variable definitions and inquiry
13  ! -----
14  function nf90mpi_def_var_Scalar(ncid, name, xtype, varid)
15    integer,               intent( in) :: ncid
16    character (len = *),   intent( in) :: name
17    integer,               intent( in) :: xtype
18    integer,               intent(out) :: varid
19    integer                            :: nf90mpi_def_var_Scalar
20
21    ! Dummy - shouldn't get used
22    integer, dimension(1) :: dimids
23
24    nf90mpi_def_var_Scalar = nfmpi_def_var(ncid, name, xtype, 0, dimids, varid)
25  end function nf90mpi_def_var_Scalar
26  ! -----
27  function nf90mpi_def_var_oneDim(ncid, name, xtype, dimids, varid)
28    integer,               intent( in) :: ncid
29    character (len = *),   intent( in) :: name
30    integer,               intent( in) :: xtype
31    integer,               intent( in) :: dimids
32    integer,               intent(out) :: varid
33    integer                            :: nf90mpi_def_var_oneDim
34
35    integer, dimension(1) :: dimidsA
36    dimidsA(1) = dimids
37    nf90mpi_def_var_oneDim = nfmpi_def_var(ncid, name, xtype, 1, dimidsA, varid)
38  end function nf90mpi_def_var_oneDim
39  ! -----
40  function nf90mpi_def_var_ManyDims(ncid, name, xtype, dimids, varid)
41    integer,               intent( in) :: ncid
42    character (len = *),   intent( in) :: name
43    integer,               intent( in) :: xtype
44    integer, dimension(:), intent( in) :: dimids
45    integer,               intent(out) :: varid
46    integer                            :: nf90mpi_def_var_ManyDims
47
48    nf90mpi_def_var_ManyDims = nfmpi_def_var(ncid, name, xtype, size(dimids), dimids, varid)
49  end function nf90mpi_def_var_ManyDims
50  ! -----
51  function nf90mpi_inq_varid(ncid, name, varid)
52    integer,             intent( in) :: ncid
53    character (len = *), intent( in) :: name
54    integer,             intent(out) :: varid
55    integer                          :: nf90mpi_inq_varid
56
57    nf90mpi_inq_varid = nfmpi_inq_varid(ncid, name, varid)
58  end function nf90mpi_inq_varid
59  ! -----
60  function nf90mpi_inquire_variable(ncid, varid, name, xtype, ndims, dimids, nAtts)
61    integer,                         intent( in) :: ncid, varid
62    character (len = *),   optional, intent(out) :: name
63    integer,               optional, intent(out) :: xtype, ndims
64    integer, dimension(:), optional, intent(out) :: dimids
65    integer,               optional, intent(out) :: nAtts
66    integer                                      :: nf90mpi_inquire_variable
67
68    ! Local variables
69    character (len = nf90_max_name)       :: varName
70    integer                               :: externalType, numDimensions
71    integer, dimension(nf90_max_var_dims) :: dimensionIDs
72    integer                               :: numAttributes
73
74    nf90mpi_inquire_variable = nfmpi_inq_var(ncid, varid, varName, externalType, &
75                                       numDimensions, dimensionIDs, numAttributes)
76    if (nf90mpi_inquire_variable == nf90_noerr) then
77        if(present(name))   name                   = trim(varName)
78        if(present(xtype))  xtype                  = externalType
79        if(present(ndims))  ndims                  = numDimensions
80        if(present(dimids)) then
81            if (size(dimids) .ge. numDimensions) then
82                dimids(:numDimensions) = dimensionIDs(:numDimensions)
83            else
84                nf90mpi_inquire_variable = nf90_einval
85            endif
86        endif
87        if(present(nAtts))  nAtts                  = numAttributes
88    endif
89  end function nf90mpi_inquire_variable
90  ! -----
91  function nf90mpi_rename_var(ncid, varid, newname)
92    integer,             intent( in) :: ncid, varid
93    character (len = *), intent( in) :: newname
94    integer                          :: nf90mpi_rename_var
95
96    nf90mpi_rename_var = nfmpi_rename_var(ncid, varid, newname)
97  end function nf90mpi_rename_var
98  ! -----
99  ! nf90mpi_def_var_fill
100  ! -----
101  function nf90mpi_def_var_fill_text(ncid, varid, no_fill, fill_value)
102    integer,             intent( in) :: ncid, varid, no_fill
103    character,           intent( in) :: fill_value
104    integer                          :: nf90mpi_def_var_fill_text
105
106    nf90mpi_def_var_fill_text = nfmpi_def_var_fill(ncid, varid, no_fill, fill_value)
107  end function nf90mpi_def_var_fill_text
108  ! -----
109  function nf90mpi_def_var_fill_OneByteInt(ncid, varid, no_fill, fill_value)
110    integer,                  intent( in) :: ncid, varid, no_fill
111    integer(kind=OneByteInt), intent( in) :: fill_value
112    integer                               :: nf90mpi_def_var_fill_OneByteInt
113
114    nf90mpi_def_var_fill_OneByteInt = nfmpi_def_var_fill(ncid, varid, no_fill, fill_value)
115  end function nf90mpi_def_var_fill_OneByteInt
116  ! -----
117  function nf90mpi_def_var_fill_TwoByteInt(ncid, varid, no_fill, fill_value)
118    integer,                  intent( in) :: ncid, varid, no_fill
119    integer(kind=TwoByteInt), intent( in) :: fill_value
120    integer                               :: nf90mpi_def_var_fill_TwoByteInt
121
122    nf90mpi_def_var_fill_TwoByteInt = nfmpi_def_var_fill(ncid, varid, no_fill, fill_value)
123  end function nf90mpi_def_var_fill_TwoByteInt
124  ! -----
125  function nf90mpi_def_var_fill_FourByteInt(ncid, varid, no_fill, fill_value)
126    integer,                   intent( in) :: ncid, varid, no_fill
127    integer(kind=FourByteInt), intent( in) :: fill_value
128    integer                                :: nf90mpi_def_var_fill_FourByteInt
129
130    nf90mpi_def_var_fill_FourByteInt = nfmpi_def_var_fill(ncid, varid, no_fill, fill_value)
131  end function nf90mpi_def_var_fill_FourByteInt
132  ! -----
133  function nf90mpi_def_var_fill_EightByteInt(ncid, varid, no_fill, fill_value)
134    integer,                    intent( in) :: ncid, varid, no_fill
135    integer(kind=EightByteInt), intent( in) :: fill_value
136    integer                                 :: nf90mpi_def_var_fill_EightByteInt
137
138    nf90mpi_def_var_fill_EightByteInt = nfmpi_def_var_fill(ncid, varid, no_fill, fill_value)
139  end function nf90mpi_def_var_fill_EightByteInt
140  ! -----
141  function nf90mpi_def_var_fill_FourByteReal(ncid, varid, no_fill, fill_value)
142    integer,                 intent( in) :: ncid, varid, no_fill
143    real(kind=FourByteReal), intent( in) :: fill_value
144    integer                              :: nf90mpi_def_var_fill_FourByteReal
145
146    nf90mpi_def_var_fill_FourByteReal = nfmpi_def_var_fill(ncid, varid, no_fill, fill_value)
147  end function nf90mpi_def_var_fill_FourByteReal
148  ! -----
149  function nf90mpi_def_var_fill_EightByteReal(ncid, varid, no_fill, fill_value)
150    integer,                  intent( in) :: ncid, varid, no_fill
151    real(kind=EightByteReal), intent( in) :: fill_value
152    integer                               :: nf90mpi_def_var_fill_EightByteReal
153
154    nf90mpi_def_var_fill_EightByteReal = nfmpi_def_var_fill(ncid, varid, no_fill, fill_value)
155  end function nf90mpi_def_var_fill_EightByteReal
156  ! -----
157  ! nf90mpi_inq_var_fill
158  ! -----
159  function nf90mpi_inq_var_fill_text(ncid, varid, no_fill, fill_value)
160    integer,             intent( in) :: ncid, varid
161    integer,             intent(out) :: no_fill
162    character,           intent(out) :: fill_value
163    integer                          :: nf90mpi_inq_var_fill_text
164
165    nf90mpi_inq_var_fill_text = nfmpi_inq_var_fill(ncid, varid, no_fill, fill_value)
166  end function nf90mpi_inq_var_fill_text
167  ! -----
168  function nf90mpi_inq_var_fill_OneByteInt(ncid, varid, no_fill, fill_value)
169    integer,                  intent( in) :: ncid, varid
170    integer,                  intent(out) :: no_fill
171    integer(kind=OneByteInt), intent(out) :: fill_value
172    integer                               :: nf90mpi_inq_var_fill_OneByteInt
173
174    nf90mpi_inq_var_fill_OneByteInt = nfmpi_inq_var_fill(ncid, varid, no_fill, fill_value)
175  end function nf90mpi_inq_var_fill_OneByteInt
176  ! -----
177  function nf90mpi_inq_var_fill_TwoByteInt(ncid, varid, no_fill, fill_value)
178    integer,                  intent( in) :: ncid, varid
179    integer,                  intent(out) :: no_fill
180    integer(kind=TwoByteInt), intent(out) :: fill_value
181    integer                               :: nf90mpi_inq_var_fill_TwoByteInt
182
183    nf90mpi_inq_var_fill_TwoByteInt = nfmpi_inq_var_fill(ncid, varid, no_fill, fill_value)
184  end function nf90mpi_inq_var_fill_TwoByteInt
185  ! -----
186  function nf90mpi_inq_var_fill_FourByteInt(ncid, varid, no_fill, fill_value)
187    integer,                   intent( in) :: ncid, varid
188    integer,                   intent(out) :: no_fill
189    integer(kind=FourByteInt), intent(out) :: fill_value
190    integer                                :: nf90mpi_inq_var_fill_FourByteInt
191
192    nf90mpi_inq_var_fill_FourByteInt = nfmpi_inq_var_fill(ncid, varid, no_fill, fill_value)
193  end function nf90mpi_inq_var_fill_FourByteInt
194  ! -----
195  function nf90mpi_inq_var_fill_EightByteInt(ncid, varid, no_fill, fill_value)
196    integer,                    intent( in) :: ncid, varid
197    integer,                    intent(out) :: no_fill
198    integer(kind=EightByteInt), intent(out) :: fill_value
199    integer                                 :: nf90mpi_inq_var_fill_EightByteInt
200
201    nf90mpi_inq_var_fill_EightByteInt = nfmpi_inq_var_fill(ncid, varid, no_fill, fill_value)
202  end function nf90mpi_inq_var_fill_EightByteInt
203  ! -----
204  function nf90mpi_inq_var_fill_FourByteReal(ncid, varid, no_fill, fill_value)
205    integer,                 intent( in) :: ncid, varid
206    integer,                 intent(out) :: no_fill
207    real(kind=FourByteReal), intent(out) :: fill_value
208    integer                              :: nf90mpi_inq_var_fill_FourByteReal
209
210    nf90mpi_inq_var_fill_FourByteReal = nfmpi_inq_var_fill(ncid, varid, no_fill, fill_value)
211  end function nf90mpi_inq_var_fill_FourByteReal
212  ! -----
213  function nf90mpi_inq_var_fill_EightByteReal(ncid, varid, no_fill, fill_value)
214    integer,                  intent( in) :: ncid, varid
215    integer,                  intent(out) :: no_fill
216    real(kind=EightByteReal), intent(out) :: fill_value
217    integer                               :: nf90mpi_inq_var_fill_EightByteReal
218
219    nf90mpi_inq_var_fill_EightByteReal = nfmpi_inq_var_fill(ncid, varid, no_fill, fill_value)
220  end function nf90mpi_inq_var_fill_EightByteReal
221  ! -----
222  function nf90mpi_fill_var_rec(ncid, varid, recno)
223    integer,                       intent(in) :: ncid, varid
224    integer(kind=MPI_OFFSET_KIND), intent(in) :: recno
225    integer                                   :: nf90mpi_fill_var_rec
226
227    nf90mpi_fill_var_rec = nfmpi_fill_var_rec(ncid, varid, recno)
228  end function nf90mpi_fill_var_rec
229  ! -----
230