|
libsim Versione 8.0.0
|
◆ index_var()
Cerca l'indice del primo o ultimo elemento di vect uguale a search. Definizione alla linea 1062 del file vol7d_var_class.F90. 1064! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
1065! authors:
1066! Davide Cesari <dcesari@arpa.emr.it>
1067! Paolo Patruno <ppatruno@arpa.emr.it>
1068
1069! This program is free software; you can redistribute it and/or
1070! modify it under the terms of the GNU General Public License as
1071! published by the Free Software Foundation; either version 2 of
1072! the License, or (at your option) any later version.
1073
1074! This program is distributed in the hope that it will be useful,
1075! but WITHOUT ANY WARRANTY; without even the implied warranty of
1076! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1077! GNU General Public License for more details.
1078
1079! You should have received a copy of the GNU General Public License
1080! along with this program. If not, see <http://www.gnu.org/licenses/>.
1081#include "config.h"
1082
1083!> Classe per la gestione delle variabili osservate da stazioni meteo e affini.
1084!! Questo modulo definisce una classe per rappresentare variabili meteorologiche
1085!! osservate, o attributi, aventi diversi tipi numerici o carattere.
1086!! \ingroup vol7d
1091IMPLICIT NONE
1092
1093!> Definisce una variabile meteorologica osservata o un suo attributo.
1094!! I membri \a r, \a d, \a i, \a b, \a c servono, internamente a vol7d,
1095!! per associare le variabili agli attributi, e indicano
1096!! a quale variabile, nel descrittore delle variabili, coincide
1097!! la variabile corrente nel descrittore delle "variabili aventi attributo".
1098!! I membri di \a vol7d_var sono pubblici e quindi liberamente
1099!! accessibili e scrivibili, ma è comunque consigliato assegnarli tramite
1100!! il costruttore ::init.
1102 CHARACTER(len=10) :: btable=cmiss !< codice della variabile secondo la tabella B del WMO.
1103 CHARACTER(len=65) :: description=cmiss !< descrizione testuale della variabile (opzionale)
1104 CHARACTER(len=24) :: unit=cmiss !< descrizione testuale dell'unità di misura (opzionale)
1105 INTEGER :: scalefactor=imiss !< numero di decimali nella rappresentazione intera o character (opzionale)
1106
1107 INTEGER :: r=imiss !< indice della variabile nel volume degli attributi reali
1108 INTEGER :: d=imiss !< indice della variabile nel volume degli attributi double precision
1109 INTEGER :: i=imiss !< indice della variabile nel volume degli attributi integer
1110 INTEGER :: b=imiss !< indice della variabile nel volume degli attributi byte
1111 INTEGER :: c=imiss !< indice della variabile nel volume degli attributi character
1112 INTEGER :: gribhint(4)=imiss !< hint for conversion from/to grib when btable is not found
1113 INTEGER :: feat_ind=imiss !< cached index to corresponding entry in feature table
1115
1116!> Valore mancante per vol7d_var.
1117TYPE(vol7d_var),PARAMETER :: vol7d_var_miss= &
1118 vol7d_var(cmiss,cmiss,cmiss,imiss,imiss,imiss,imiss,imiss,imiss, &
1119 (/imiss,imiss,imiss,imiss/))
1120
1121!> Costruttore per la classe vol7d_var.
1122!! Deve essere richiamato
1123!! per tutti gli oggetti di questo tipo definiti in un programma.
1125 MODULE PROCEDURE vol7d_var_init
1126END INTERFACE
1127
1128!> Distruttore per la classe vol7d_var.
1129!! Distrugge l'oggetto in maniera pulita, assegnandogli un valore mancante.
1131 MODULE PROCEDURE vol7d_var_delete
1132END INTERFACE
1133
1134!> Operatore logico di uguaglianza tra oggetti della classe vol7d_var.
1135!! Funziona anche per
1136!! confronti di tipo array-array (qualsiasi n. di dimensioni) e di tipo
1137!! scalare-vettore(1-d) (ma non vettore(1-d)-scalare o tra array con più
1138!! di 1 dimensione e scalari).
1139INTERFACE OPERATOR (==)
1140 MODULE PROCEDURE vol7d_var_eq
1141END INTERFACE
1142
1143!> Operatore logico di disuguaglianza tra oggetti della classe vol7d_var.
1144!! Funziona anche per
1145!! confronti di tipo array-array (qualsiasi n. di dimensioni) e di tipo
1146!! scalare-vettore(1-d) (ma non vettore(1-d)-scalare o tra array con più
1147!! di 1 dimensione e scalari).
1148INTERFACE OPERATOR (/=)
1149 MODULE PROCEDURE vol7d_var_ne, vol7d_var_nesv
1150END INTERFACE
1151
1152!> to be documented
1154 MODULE PROCEDURE vol7d_var_c_e
1155END INTERFACE
1156
1157#define VOL7D_POLY_TYPE TYPE(vol7d_var)
1158#define VOL7D_POLY_TYPES _var
1159#include "array_utilities_pre.F90"
1160
1161!> \brief display on the screen a brief content of object
1163 MODULE PROCEDURE display_var, display_var_vect
1164END INTERFACE
1165
1166
1167TYPE vol7d_var_features
1168 TYPE(vol7d_var) :: var !< the variable (only btable is relevant)
1169 REAL :: posdef !< if not missing, minimum physically reasonable value for the variable
1170 INTEGER :: vartype !< type of variable, one of the var_* constants
1171END TYPE vol7d_var_features
1172
1173TYPE(vol7d_var_features),ALLOCATABLE :: var_features(:)
1174
1175! constants for vol7d_vartype
1176INTEGER,PARAMETER :: var_ord=0 !< unclassified variable (vol7d_vartype function)
1177INTEGER,PARAMETER :: var_dir360=1 !< direction in degrees (vol7d_vartype function)
1178INTEGER,PARAMETER :: var_press=2 !< pressure in Pa (vol7d_vartype function)
1179INTEGER,PARAMETER :: var_ucomp=3 !< u component of a vector field (vol7d_vartype function)
1180INTEGER,PARAMETER :: var_vcomp=4 !< v component of a vector field (vol7d_vartype function)
1181INTEGER,PARAMETER :: var_wcomp=5 !< w component of a vector field (vol7d_vartype function)
1182
1183PRIVATE vol7d_var_features_init
1184
1185CONTAINS
1186
1187!> Inizializza un oggetto \a vol7d_var con i parametri opzionali forniti.
1188!! Se non viene passato nessun parametro opzionale l'oggetto è
1189!! inizializzato a valore mancante.
1190!! I membri \a r, \a d, \a i, \a b, \a c non possono essere assegnati
1191!! tramite costruttore, ma solo direttamente.
1192elemental SUBROUTINE vol7d_var_init(this, btable, description, unit, scalefactor)
1193TYPE(vol7d_var),INTENT(INOUT) :: this !< oggetto da inizializzare
1194CHARACTER(len=*),INTENT(in),OPTIONAL :: btable !< codice della variabile
1195CHARACTER(len=*),INTENT(in),OPTIONAL :: description !< descrizione della variabile
1196CHARACTER(len=*),INTENT(in),OPTIONAL :: unit !< unità di misura
1197INTEGER,INTENT(in),OPTIONAL :: scalefactor !< decimali nella rappresentazione intera e character
1198
1199IF (PRESENT(btable)) THEN
1200 this%btable = btable
1201ELSE
1202 this%btable = cmiss
1203 this%description = cmiss
1204 this%unit = cmiss
1205 this%scalefactor = imiss
1206 RETURN
1207ENDIF
1208IF (PRESENT(description)) THEN
1209 this%description = description
1210ELSE
1211 this%description = cmiss
1212ENDIF
1213IF (PRESENT(unit)) THEN
1214 this%unit = unit
1215ELSE
1216 this%unit = cmiss
1217ENDIF
1218if (present(scalefactor)) then
1219 this%scalefactor = scalefactor
1220else
1221 this%scalefactor = imiss
1222endif
1223
1224this%r = -1
1225this%d = -1
1226this%i = -1
1227this%b = -1
1228this%c = -1
1229
1230END SUBROUTINE vol7d_var_init
1231
1232
1233ELEMENTAL FUNCTION vol7d_var_new(btable, description, unit, scalefactor) RESULT(this)
1234CHARACTER(len=*),INTENT(in),OPTIONAL :: btable !< codice della variabile
1235CHARACTER(len=*),INTENT(in),OPTIONAL :: description !< descrizione della variabile
1236CHARACTER(len=*),INTENT(in),OPTIONAL :: unit !< unità di misura
1237INTEGER,INTENT(in),OPTIONAL :: scalefactor !< decimali nella rappresentazione intera e character
1238
1239TYPE(vol7d_var) :: this
1240
1242
1243END FUNCTION vol7d_var_new
1244
1245
1246!> Distrugge l'oggetto in maniera pulita, assegnandogli un valore mancante.
1247elemental SUBROUTINE vol7d_var_delete(this)
1248TYPE(vol7d_var),INTENT(INOUT) :: this !< oggetto da distruggre
1249
1250this%btable = cmiss
1251this%description = cmiss
1252this%unit = cmiss
1253this%scalefactor = imiss
1254
1255END SUBROUTINE vol7d_var_delete
1256
1257
1258ELEMENTAL FUNCTION vol7d_var_eq(this, that) RESULT(res)
1259TYPE(vol7d_var),INTENT(IN) :: this, that
1260LOGICAL :: res
1261
1262res = this%btable == that%btable
1263
1264END FUNCTION vol7d_var_eq
1265
1266
1267ELEMENTAL FUNCTION vol7d_var_ne(this, that) RESULT(res)
1268TYPE(vol7d_var),INTENT(IN) :: this, that
1269LOGICAL :: res
1270
1271res = .NOT.(this == that)
1272
1273END FUNCTION vol7d_var_ne
1274
1275
1276FUNCTION vol7d_var_nesv(this, that) RESULT(res)
1277TYPE(vol7d_var),INTENT(IN) :: this, that(:)
1278LOGICAL :: res(SIZE(that))
1279
1280INTEGER :: i
1281
1282DO i = 1, SIZE(that)
1283 res(i) = .NOT.(this == that(i))
1284ENDDO
1285
1286END FUNCTION vol7d_var_nesv
1287
1288
1289
1290!> \brief display on the screen a brief content of vol7d_var object
1291subroutine display_var(this)
1292
1293TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to display
1294
1295print*,"VOL7DVAR: ",this%btable,trim(this%description)," : ",this%unit,&
1296 " scale factor",this%scalefactor
1297
1298end subroutine display_var
1299
1300
1301!> \brief display on the screen a brief content of vector of vol7d_var object
1302subroutine display_var_vect(this)
1303
1304TYPE(vol7d_var),INTENT(in) :: this(:) !< vol7d_var vector object to display
1305integer :: i
1306
1307do i=1,size(this)
1308 call display_var(this(i))
1309end do
1310
1311end subroutine display_var_vect
1312
1313FUNCTION vol7d_var_c_e(this) RESULT(c_e)
1314TYPE(vol7d_var),INTENT(IN) :: this
1315LOGICAL :: c_e
1316c_e = this /= vol7d_var_miss
1317END FUNCTION vol7d_var_c_e
1318
1319
1320SUBROUTINE vol7d_var_features_set(this)
1321TYPE(vol7d_var),INTENT(inout) :: this
1322INTEGER :: i
1323
1324CALL vol7d_var_features_init()
1325
1326IF (ALLOCATED(var_features)) THEN
1327 DO i = 1, SIZE(var_features)
1328 IF (this == var_features(i)%var) THEN
1329 this%feat_ind = i
1330 EXIT
1331 ENDIF
1332 ENDDO
1333ENDIF
1334
1335END SUBROUTINE vol7d_var_features_set
1336
1337
1338!> Initialise the global table of variable features.
1339!! This subroutine reads the table of variable features from an
1340!! external file and stores it in a global array. It has to be called
1341!! once at the beginning of the program. At the moment it gives access
1342!! to the information about type of variable and positive
1343!! definitness. The table is based on the unique bufr-like variable
1344!! table. The table is contained in the csv file `vargrib.csv`.
1345!! It is not harmful to call this subroutine multiple times.
1346SUBROUTINE vol7d_var_features_init()
1347INTEGER :: un, i, n
1348TYPE(csv_record) :: csv
1349CHARACTER(len=1024) :: line
1350
1351IF (ALLOCATED(var_features)) RETURN
1352
1353un = open_package_file('varbufr.csv', filetype_data)
1354n=0
1355DO WHILE(.true.)
1356 READ(un,*,END=100)
1357 n = n + 1
1358ENDDO
1359
1360100 CONTINUE
1361
1362rewind(un)
1363ALLOCATE(var_features(n))
1364
1365DO i = 1, n
1366 READ(un,'(A)',END=200)line
1368 CALL csv_record_getfield(csv, var_features(i)%var%btable)
1369 CALL csv_record_getfield(csv)
1370 CALL csv_record_getfield(csv)
1371 CALL csv_record_getfield(csv, var_features(i)%posdef)
1372 CALL csv_record_getfield(csv, var_features(i)%vartype)
1374ENDDO
1375
1376200 CONTINUE
1377CLOSE(un)
1378
1379END SUBROUTINE vol7d_var_features_init
1380
1381
1382!> Deallocate the global table of variable features.
1383!! This subroutine deallocates the table of variable features
1384!! allocated in the `vol7d_var_features_init` subroutine.
1385SUBROUTINE vol7d_var_features_delete()
1386IF (ALLOCATED(var_features)) DEALLOCATE(var_features)
1387END SUBROUTINE vol7d_var_features_delete
1388
1389
1390!> Return the physical type of the variable.
1391!! Returns a rough classification of the variable depending on the
1392!! physical parameter it represents. The result is one of the
1393!! constants vartype_* defined in the module. To be extended.
1394!! In order for this to work, the subroutine \a
1395!! vol7d_var_features_set has to be preliminary called.
1396ELEMENTAL FUNCTION vol7d_var_features_vartype(this) RESULT(vartype)
1397TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be tested
1398INTEGER :: vartype
1399
1401 vartype = var_features(this%feat_ind)%vartype
1402ELSE
1403 vartype = imiss
1404ENDIF
1405
1406END FUNCTION vol7d_var_features_vartype
1407
1408
1409!> Apply a positive definite flag to a variable.
1410!! This subroutine resets the value of a variable depending on its
1411!! positive definite flag defined in the associated \a c_func object.
1412!! The \a c_func object can be obtained for example by the \a convert
1413!! (interfaced to vargrib2varbufr_convert) function. The value is
1414!! reset to the maximum between the value itself and and 0 (or the
1415!! value set in \a c_func%posdef. These values are set from the
1416!! varbufr.csv file.
1417!! In order for this to work, the subroutine \a
1418!! vol7d_var_features_set has to be preliminary called.
1419ELEMENTAL SUBROUTINE vol7d_var_features_posdef_apply(this, val)
1420TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be reset
1421REAL,INTENT(inout) :: val !< value to be reset, it is reset in place
1422
1426 val = max(var_features(this%feat_ind)%posdef, val)
1427 ENDIF
1428 ENDIF
1429ENDIF
1430
1431END SUBROUTINE vol7d_var_features_posdef_apply
1432
1433
1434!> Return the physical type of the variable.
1435!! Returns a rough classification of the variable depending on the
1436!! physical parameter it represents. The result is one of the
1437!! constants vartype_* defined in the module. To be extended.
1438ELEMENTAL FUNCTION vol7d_vartype(this) RESULT(vartype)
1439TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be tested
1440
1441INTEGER :: vartype
1442
1443vartype = var_ord
1444SELECT CASE(this%btable)
1445CASE('B01012', 'B11001', 'B11043', 'B22001') ! direction, degree true
1446 vartype = var_dir360
1447CASE('B07004', 'B10004', 'B10051', 'B10060') ! pressure, Pa
1448 vartype = var_press
1449CASE('B11003', 'B11200') ! u-component
1450 vartype = var_ucomp
1451CASE('B11004', 'B11201') ! v-component
1452 vartype = var_vcomp
1453CASE('B11005', 'B11006') ! w-component
1454 vartype = var_wcomp
1455END SELECT
1456
1457END FUNCTION vol7d_vartype
1458
1459
1460#include "array_utilities_inc.F90"
1461
1462
display on the screen a brief content of object Definition vol7d_var_class.F90:329 Definition of constants to be used for declaring variables of a desired type. Definition kinds.F90:245 Definitions of constants and functions for working with missing values. Definition missing_values.f90:50 Classe per la gestione delle variabili osservate da stazioni meteo e affini. Definition vol7d_var_class.F90:212 Definisce una variabile meteorologica osservata o un suo attributo. Definition vol7d_var_class.F90:226 |