source: LMDZ6/trunk/libf/misc/nf95_gw_var_m.F90 @ 4068

Last change on this file since 4068 was 1907, checked in by lguez, 11 years ago

Added a copyright property to every file of the distribution, except
for the fcm files (which have their own copyright). Use svn propget on
a file to see the copyright. For instance:

$ svn propget copyright libf/phylmd/physiq.F90
Name of program: LMDZ
Creation date: 1984
Version: LMDZ5
License: CeCILL version 2
Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
See the license file in the root directory

Also added the files defining the CeCILL version 2 license, in French
and English, at the top of the LMDZ tree.

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
File size: 9.3 KB
Line 
1! $Id$
2module nf95_gw_var_m
3
4  use nf95_get_var_m, only: NF95_GET_VAR
5  use simple, only: nf95_inquire_variable, nf95_inquire_dimension
6
7  implicit none
8
9  interface nf95_gw_var
10     ! "nf95_gw_var" stands for "NetCDF 1995 get whole variable".
11     ! These procedures read a whole NetCDF variable (coordinate or
12     ! primary) into an array.
13     ! The difference between the procedures is the rank and type of
14     ! argument "values".
15     ! The procedures do not check the type of the NetCDF variable.
16
17     ! Not including double precision procedures in the generic
18     ! interface because we use a compilation option that changes default
19     ! real precision.
20     module procedure nf95_gw_var_real_1d, nf95_gw_var_real_2d, &
21          nf95_gw_var_real_3d, nf95_gw_var_real_4d, nf95_gw_var_real_5d, &
22          nf95_gw_var_int_1d, nf95_gw_var_int_3d
23  end interface
24
25  private
26  public nf95_gw_var
27
28contains
29
30  subroutine nf95_gw_var_real_1d(ncid, varid, values)
31
32    ! Real type, the array has rank 1.
33
34    integer, intent(in):: ncid
35    integer, intent(in):: varid
36    real, pointer:: values(:)
37
38    ! Variables local to the procedure:
39    integer nclen
40    integer, pointer:: dimids(:)
41
42    !---------------------
43
44    call nf95_inquire_variable(ncid, varid, dimids=dimids)
45
46    if (size(dimids) /= 1) then
47       print *, "nf95_gw_var_real_1d:"
48       print *, "varid = ", varid
49       print *, "rank of NetCDF variable is ", size(dimids), ", not 1"
50       stop 1
51    end if
52
53    call nf95_inquire_dimension(ncid, dimids(1), nclen=nclen)
54    deallocate(dimids) ! pointer
55
56    allocate(values(nclen))
57    if (nclen /= 0) call NF95_GET_VAR(ncid, varid, values)
58
59  end subroutine nf95_gw_var_real_1d
60
61  !************************************
62
63  subroutine nf95_gw_var_real_2d(ncid, varid, values)
64
65    ! Real type, the array has rank 2.
66
67    integer, intent(in):: ncid
68    integer, intent(in):: varid
69    real, pointer:: values(:, :)
70
71    ! Variables local to the procedure:
72    integer nclen1, nclen2
73    integer, pointer:: dimids(:)
74
75    !---------------------
76
77    call nf95_inquire_variable(ncid, varid, dimids=dimids)
78
79    if (size(dimids) /= 2) then
80       print *, "nf95_gw_var_real_2d:"
81       print *, "varid = ", varid
82       print *, "rank of NetCDF variable is ", size(dimids), ", not 2"
83       stop 1
84    end if
85
86    call nf95_inquire_dimension(ncid, dimids(1), nclen=nclen1)
87    call nf95_inquire_dimension(ncid, dimids(2), nclen=nclen2)
88    deallocate(dimids) ! pointer
89
90    allocate(values(nclen1, nclen2))
91    if (nclen1 /= 0 .and. nclen2 /= 0) call NF95_GET_VAR(ncid, varid, values)
92
93  end subroutine nf95_gw_var_real_2d
94
95  !************************************
96
97  subroutine nf95_gw_var_real_3d(ncid, varid, values)
98
99    ! Real type, the array has rank 3.
100
101    integer, intent(in):: ncid
102    integer, intent(in):: varid
103    real, pointer:: values(:, :, :)
104
105    ! Variables local to the procedure:
106    integer nclen1, nclen2, nclen3
107    integer, pointer:: dimids(:)
108
109    !---------------------
110
111    call nf95_inquire_variable(ncid, varid, dimids=dimids)
112
113    if (size(dimids) /= 3) then
114       print *, "nf95_gw_var_real_3d:"
115       print *, "varid = ", varid
116       print *, "rank of NetCDF variable is ", size(dimids), ", not 3"
117       stop 1
118    end if
119
120    call nf95_inquire_dimension(ncid, dimids(1), nclen=nclen1)
121    call nf95_inquire_dimension(ncid, dimids(2), nclen=nclen2)
122    call nf95_inquire_dimension(ncid, dimids(3), nclen=nclen3)
123    deallocate(dimids) ! pointer
124
125    allocate(values(nclen1, nclen2, nclen3))
126    if (nclen1 * nclen2 * nclen3 /= 0) call NF95_GET_VAR(ncid, varid, values)
127
128  end subroutine nf95_gw_var_real_3d
129
130  !************************************
131
132  subroutine nf95_gw_var_real_4d(ncid, varid, values)
133
134    ! Real type, the array has rank 4.
135
136    integer, intent(in):: ncid
137    integer, intent(in):: varid
138    real, pointer:: values(:, :, :, :)
139
140    ! Variables local to the procedure:
141    integer len_dim(4), i
142    integer, pointer:: dimids(:)
143
144    !---------------------
145
146    call nf95_inquire_variable(ncid, varid, dimids=dimids)
147
148    if (size(dimids) /= 4) then
149       print *, "nf95_gw_var_real_4d:"
150       print *, "varid = ", varid
151       print *, "rank of NetCDF variable is ", size(dimids), ", not 4"
152       stop 1
153    end if
154
155    do i = 1, 4
156       call nf95_inquire_dimension(ncid, dimids(i), nclen=len_dim(i))
157    end do
158    deallocate(dimids) ! pointer
159
160    allocate(values(len_dim(1), len_dim(2), len_dim(3), len_dim(4)))
161    if (all(len_dim /= 0)) call NF95_GET_VAR(ncid, varid, values)
162
163  end subroutine nf95_gw_var_real_4d
164
165  !************************************
166
167  subroutine nf95_gw_var_real_5d(ncid, varid, values)
168
169    ! Real type, the array has rank 5.
170
171    integer, intent(in):: ncid
172    integer, intent(in):: varid
173    real, pointer:: values(:, :, :, :, :)
174
175    ! Variables local to the procedure:
176    integer len_dim(5), i
177    integer, pointer:: dimids(:)
178
179    !---------------------
180
181    call nf95_inquire_variable(ncid, varid, dimids=dimids)
182
183    if (size(dimids) /= 5) then
184       print *, "nf95_gw_var_real_5d:"
185       print *, "varid = ", varid
186       print *, "rank of NetCDF variable is ", size(dimids), ", not 5"
187       stop 1
188    end if
189
190    do i = 1, 5
191       call nf95_inquire_dimension(ncid, dimids(i), nclen=len_dim(i))
192    end do
193    deallocate(dimids) ! pointer
194
195    allocate(values(len_dim(1), len_dim(2), len_dim(3), len_dim(4), len_dim(5)))
196    if (all(len_dim /= 0)) call NF95_GET_VAR(ncid, varid, values)
197
198  end subroutine nf95_gw_var_real_5d
199
200  !************************************
201
202!!$  subroutine nf95_gw_var_dble_1d(ncid, varid, values)
203!!$
204!!$    ! Double precision, the array has rank 1.
205!!$
206!!$    integer, intent(in):: ncid
207!!$    integer, intent(in):: varid
208!!$    double precision, pointer:: values(:)
209!!$
210!!$    ! Variables local to the procedure:
211!!$    integer nclen
212!!$    integer, pointer:: dimids(:)
213!!$
214!!$    !---------------------
215!!$
216!!$    call nf95_inquire_variable(ncid, varid, dimids=dimids)
217!!$
218!!$    if (size(dimids) /= 1) then
219!!$       print *, "nf95_gw_var_dble_1d:"
220!!$       print *, "varid = ", varid
221!!$       print *, "rank of NetCDF variable is ", size(dimids), ", not 1"
222!!$        stop 1
223!!$    end if
224!!$
225!!$    call nf95_inquire_dimension(ncid, dimids(1), nclen=nclen)
226!!$    deallocate(dimids) ! pointer
227!!$
228!!$    allocate(values(nclen))
229!!$    if (nclen /= 0) call NF95_GET_VAR(ncid, varid, values)
230!!$
231!!$  end subroutine nf95_gw_var_dble_1d
232!!$
233!!$  !************************************
234!!$
235!!$  subroutine nf95_gw_var_dble_3d(ncid, varid, values)
236!!$
237!!$    ! Double precision, the array has rank 3.
238!!$
239!!$    integer, intent(in):: ncid
240!!$    integer, intent(in):: varid
241!!$    double precision, pointer:: values(:, :, :)
242!!$
243!!$    ! Variables local to the procedure:
244!!$    integer nclen1, nclen2, nclen3
245!!$    integer, pointer:: dimids(:)
246!!$
247!!$    !---------------------
248!!$
249!!$    call nf95_inquire_variable(ncid, varid, dimids=dimids)
250!!$
251!!$    if (size(dimids) /= 3) then
252!!$       print *, "nf95_gw_var_dble_3d:"
253!!$       print *, "varid = ", varid
254!!$       print *, "rank of NetCDF variable is ", size(dimids), ", not 3"
255!!$       stop 1
256!!$    end if
257!!$
258!!$    call nf95_inquire_dimension(ncid, dimids(1), nclen=nclen1)
259!!$    call nf95_inquire_dimension(ncid, dimids(2), nclen=nclen2)
260!!$    call nf95_inquire_dimension(ncid, dimids(3), nclen=nclen3)
261!!$    deallocate(dimids) ! pointer
262!!$
263!!$    allocate(values(nclen1, nclen2, nclen3))
264!!$    if (nclen1 * nclen2 * nclen3 /= 0) call NF95_GET_VAR(ncid, varid, values)
265!!$
266!!$  end subroutine nf95_gw_var_dble_3d
267!!$
268  !************************************
269
270  subroutine nf95_gw_var_int_1d(ncid, varid, values)
271
272    ! Integer type, the array has rank 1.
273
274    integer, intent(in):: ncid
275    integer, intent(in):: varid
276    integer, pointer:: values(:)
277
278    ! Variables local to the procedure:
279    integer nclen
280    integer, pointer:: dimids(:)
281
282    !---------------------
283
284    call nf95_inquire_variable(ncid, varid, dimids=dimids)
285
286    if (size(dimids) /= 1) then
287       print *, "nf95_gw_var_int_1d:"
288       print *, "varid = ", varid
289       print *, "rank of NetCDF variable is ", size(dimids), ", not 1"
290       stop 1
291    end if
292
293    call nf95_inquire_dimension(ncid, dimids(1), nclen=nclen)
294    deallocate(dimids) ! pointer
295
296    allocate(values(nclen))
297    if (nclen /= 0) call NF95_GET_VAR(ncid, varid, values)
298
299  end subroutine nf95_gw_var_int_1d
300
301  !************************************
302
303  subroutine nf95_gw_var_int_3d(ncid, varid, values)
304
305    ! Integer type, the array has rank 3.
306
307    integer, intent(in):: ncid
308    integer, intent(in):: varid
309    integer, pointer:: values(:, :, :)
310
311    ! Variables local to the procedure:
312    integer nclen1, nclen2, nclen3
313    integer, pointer:: dimids(:)
314
315    !---------------------
316
317    call nf95_inquire_variable(ncid, varid, dimids=dimids)
318
319    if (size(dimids) /= 3) then
320       print *, "nf95_gw_var_int_3d:"
321       print *, "varid = ", varid
322       print *, "rank of NetCDF variable is ", size(dimids), ", not 3"
323       stop 1
324    end if
325
326    call nf95_inquire_dimension(ncid, dimids(1), nclen=nclen1)
327    call nf95_inquire_dimension(ncid, dimids(2), nclen=nclen2)
328    call nf95_inquire_dimension(ncid, dimids(3), nclen=nclen3)
329    deallocate(dimids) ! pointer
330
331    allocate(values(nclen1, nclen2, nclen3))
332    if (nclen1 * nclen2 * nclen3 /= 0) call NF95_GET_VAR(ncid, varid, values)
333
334  end subroutine nf95_gw_var_int_3d
335
336end module nf95_gw_var_m
Note: See TracBrowser for help on using the repository browser.