libsim  Versione8.0.0
vol7d_var_class.F90
1 ! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
2 ! authors:
3 ! Davide Cesari <dcesari@arpa.emr.it>
4 ! Paolo Patruno <ppatruno@arpa.emr.it>
5 
6 ! This program is free software; you can redistribute it and/or
7 ! modify it under the terms of the GNU General Public License as
8 ! published by the Free Software Foundation; either version 2 of
9 ! the License, or (at your option) any later version.
10 
11 ! This program is distributed in the hope that it will be useful,
12 ! but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ! GNU General Public License for more details.
15 
16 ! You should have received a copy of the GNU General Public License
17 ! along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "config.h"
19 
24 MODULE vol7d_var_class
25 USE kinds
28 IMPLICIT NONE
29 
38 TYPE vol7d_var
39  CHARACTER(len=10) :: btable=cmiss
40  CHARACTER(len=65) :: description=cmiss
41  CHARACTER(len=24) :: unit=cmiss
42  INTEGER :: scalefactor=imiss
43 
44  INTEGER :: r=imiss
45  INTEGER :: d=imiss
46  INTEGER :: i=imiss
47  INTEGER :: b=imiss
48  INTEGER :: c=imiss
49  INTEGER :: gribhint(4)=imiss
50  INTEGER :: feat_ind=imiss
51 END TYPE vol7d_var
52 
54 TYPE(vol7d_var),PARAMETER :: vol7d_var_miss= &
55  vol7d_var(cmiss,cmiss,cmiss,imiss,imiss,imiss,imiss,imiss,imiss, &
56  (/imiss,imiss,imiss,imiss/))
57 
61 INTERFACE init
62  MODULE PROCEDURE vol7d_var_init
63 END INTERFACE
64 
67 INTERFACE delete
68  MODULE PROCEDURE vol7d_var_delete
69 END INTERFACE
70 
76 INTERFACE OPERATOR (==)
77  MODULE PROCEDURE vol7d_var_eq
78 END INTERFACE
79 
85 INTERFACE OPERATOR (/=)
86  MODULE PROCEDURE vol7d_var_ne, vol7d_var_nesv
87 END INTERFACE
88 
90 INTERFACE c_e
91  MODULE PROCEDURE vol7d_var_c_e
92 END INTERFACE
93 
94 #define VOL7D_POLY_TYPE TYPE(vol7d_var)
95 #define VOL7D_POLY_TYPES _var
96 #include "array_utilities_pre.F90"
97 
99 INTERFACE display
100  MODULE PROCEDURE display_var, display_var_vect
101 END INTERFACE
102 
103 
104 TYPE vol7d_var_features
105  TYPE(vol7d_var) :: var
106  REAL :: posdef
107  INTEGER :: vartype
108 END TYPE vol7d_var_features
109 
110 TYPE(vol7d_var_features),ALLOCATABLE :: var_features(:)
111 
112 ! constants for vol7d_vartype
113 INTEGER,PARAMETER :: var_ord=0
114 INTEGER,PARAMETER :: var_dir360=1
115 INTEGER,PARAMETER :: var_press=2
116 INTEGER,PARAMETER :: var_ucomp=3
117 INTEGER,PARAMETER :: var_vcomp=4
118 INTEGER,PARAMETER :: var_wcomp=5
119 
120 PRIVATE vol7d_var_features_init
121 
122 CONTAINS
123 
129 elemental SUBROUTINE vol7d_var_init(this, btable, description, unit, scalefactor)
130 TYPE(vol7d_var),INTENT(INOUT) :: this
131 CHARACTER(len=*),INTENT(in),OPTIONAL :: btable
132 CHARACTER(len=*),INTENT(in),OPTIONAL :: description
133 CHARACTER(len=*),INTENT(in),OPTIONAL :: unit
134 INTEGER,INTENT(in),OPTIONAL :: scalefactor
135 
136 IF (PRESENT(btable)) THEN
137  this%btable = btable
138 ELSE
139  this%btable = cmiss
140  this%description = cmiss
141  this%unit = cmiss
142  this%scalefactor = imiss
143  RETURN
144 ENDIF
145 IF (PRESENT(description)) THEN
146  this%description = description
147 ELSE
148  this%description = cmiss
149 ENDIF
150 IF (PRESENT(unit)) THEN
151  this%unit = unit
152 ELSE
153  this%unit = cmiss
154 ENDIF
155 if (present(scalefactor)) then
156  this%scalefactor = scalefactor
157 else
158  this%scalefactor = imiss
159 endif
160 
161 this%r = -1
162 this%d = -1
163 this%i = -1
164 this%b = -1
165 this%c = -1
166 
167 END SUBROUTINE vol7d_var_init
168 
169 
170 ELEMENTAL FUNCTION vol7d_var_new(btable, description, unit, scalefactor) RESULT(this)
171 CHARACTER(len=*),INTENT(in),OPTIONAL :: btable
172 CHARACTER(len=*),INTENT(in),OPTIONAL :: description
173 CHARACTER(len=*),INTENT(in),OPTIONAL :: unit
174 INTEGER,INTENT(in),OPTIONAL :: scalefactor
175 
176 TYPE(vol7d_var) :: this
177 
178 CALL init(this, btable, description, unit, scalefactor)
179 
180 END FUNCTION vol7d_var_new
181 
182 
184 elemental SUBROUTINE vol7d_var_delete(this)
185 TYPE(vol7d_var),INTENT(INOUT) :: this
186 
187 this%btable = cmiss
188 this%description = cmiss
189 this%unit = cmiss
190 this%scalefactor = imiss
191 
192 END SUBROUTINE vol7d_var_delete
193 
194 
195 ELEMENTAL FUNCTION vol7d_var_eq(this, that) RESULT(res)
196 TYPE(vol7d_var),INTENT(IN) :: this, that
197 LOGICAL :: res
198 
199 res = this%btable == that%btable
200 
201 END FUNCTION vol7d_var_eq
202 
203 
204 ELEMENTAL FUNCTION vol7d_var_ne(this, that) RESULT(res)
205 TYPE(vol7d_var),INTENT(IN) :: this, that
206 LOGICAL :: res
207 
208 res = .NOT.(this == that)
209 
210 END FUNCTION vol7d_var_ne
211 
212 
213 FUNCTION vol7d_var_nesv(this, that) RESULT(res)
214 TYPE(vol7d_var),INTENT(IN) :: this, that(:)
215 LOGICAL :: res(SIZE(that))
216 
217 INTEGER :: i
218 
219 DO i = 1, SIZE(that)
220  res(i) = .NOT.(this == that(i))
221 ENDDO
223 END FUNCTION vol7d_var_nesv
224 
225 
226 
228 subroutine display_var(this)
229 
230 TYPE(vol7d_var),INTENT(in) :: this
231 
232 print*,"VOL7DVAR: ",this%btable,trim(this%description)," : ",this%unit,&
233  " scale factor",this%scalefactor
234 
235 end subroutine display_var
239 subroutine display_var_vect(this)
241 TYPE(vol7d_var),INTENT(in) :: this(:)
242 integer :: i
244 do i=1,size(this)
245  call display_var(this(i))
246 end do
248 end subroutine display_var_vect
249 
250 FUNCTION vol7d_var_c_e(this) RESULT(c_e)
251 TYPE(vol7d_var),INTENT(IN) :: this
252 LOGICAL :: c_e
253 c_e = this /= vol7d_var_miss
254 END FUNCTION vol7d_var_c_e
255 
256 
257 SUBROUTINE vol7d_var_features_set(this)
258 TYPE(vol7d_var),INTENT(inout) :: this
259 INTEGER :: i
260 
261 CALL vol7d_var_features_init()
262 
263 IF (ALLOCATED(var_features)) THEN
264  DO i = 1, SIZE(var_features)
265  IF (this == var_features(i)%var) THEN
266  this%feat_ind = i
267  EXIT
268  ENDIF
269  ENDDO
270 ENDIF
271 
272 END SUBROUTINE vol7d_var_features_set
273 
283 SUBROUTINE vol7d_var_features_init()
284 INTEGER :: un, i, n
285 TYPE(csv_record) :: csv
286 CHARACTER(len=1024) :: line
287 
288 IF (ALLOCATED(var_features)) RETURN
289 
290 un = open_package_file('varbufr.csv', filetype_data)
291 n=0
292 DO WHILE(.true.)
293  READ(un,*,end=100)
294  n = n + 1
295 ENDDO
296 
297 100 CONTINUE
298 
299 rewind(un)
300 ALLOCATE(var_features(n))
301 
302 DO i = 1, n
303  READ(un,'(A)',end=200)line
304  CALL init(csv, line)
305  CALL csv_record_getfield(csv, var_features(i)%var%btable)
306  CALL csv_record_getfield(csv)
307  CALL csv_record_getfield(csv)
308  CALL csv_record_getfield(csv, var_features(i)%posdef)
309  CALL csv_record_getfield(csv, var_features(i)%vartype)
310  CALL delete(csv)
311 ENDDO
312 
313 200 CONTINUE
314 CLOSE(un)
315 
316 END SUBROUTINE vol7d_var_features_init
317 
318 
322 SUBROUTINE vol7d_var_features_delete()
323 IF (ALLOCATED(var_features)) DEALLOCATE(var_features)
324 END SUBROUTINE vol7d_var_features_delete
325 
326 
333 ELEMENTAL FUNCTION vol7d_var_features_vartype(this) RESULT(vartype)
334 TYPE(vol7d_var),INTENT(in) :: this
335 INTEGER :: vartype
336 
337 IF (c_e(this%feat_ind)) THEN
338  vartype = var_features(this%feat_ind)%vartype
339 ELSE
340  vartype = imiss
341 ENDIF
342 
343 END FUNCTION vol7d_var_features_vartype
344 
345 
356 ELEMENTAL SUBROUTINE vol7d_var_features_posdef_apply(this, val)
357 TYPE(vol7d_var),INTENT(in) :: this
358 REAL,INTENT(inout) :: val
359 
360 IF (c_e(this%feat_ind)) THEN
361  IF (c_e(var_features(this%feat_ind)%posdef)) THEN
362  IF (c_e(val)) THEN
363  val = max(var_features(this%feat_ind)%posdef, val)
364  ENDIF
365  ENDIF
366 ENDIF
367 
368 END SUBROUTINE vol7d_var_features_posdef_apply
369 
375 ELEMENTAL FUNCTION vol7d_vartype(this) RESULT(vartype)
376 TYPE(vol7d_var),INTENT(in) :: this
377 
378 INTEGER :: vartype
379 
380 vartype = var_ord
381 SELECT CASE(this%btable)
382 CASE('B01012', 'B11001', 'B11043', 'B22001') ! direction, degree true
383  vartype = var_dir360
384 CASE('B07004', 'B10004', 'B10051', 'B10060') ! pressure, Pa
385  vartype = var_press
386 CASE('B11003', 'B11200') ! u-component
387  vartype = var_ucomp
388 CASE('B11004', 'B11201') ! v-component
389  vartype = var_vcomp
390 CASE('B11005', 'B11006') ! w-component
391  vartype = var_wcomp
392 END SELECT
393 
394 END FUNCTION vol7d_vartype
395 
396 
397 #include "array_utilities_inc.F90"
398 
399 
400 END MODULE vol7d_var_class
Distruttore per la classe vol7d_var.
display on the screen a brief content of object
Utilities for managing files.
Methods for successively obtaining the fields of a csv_record object.
Classe per la gestione delle variabili osservate da stazioni meteo e affini.
Costruttore per la classe vol7d_var.
to be documented
Definitions of constants and functions for working with missing values.
Definisce una variabile meteorologica osservata o un suo attributo.
Definition of constants to be used for declaring variables of a desired type.
Definition: kinds.F90:255

Generated with Doxygen.