libsim Versione 8.0.0

◆ map_inv_distinct_var()

integer function, dimension(dim) map_inv_distinct_var ( type(vol7d_var), dimension(:), intent(in) vect,
integer, intent(in) dim,
logical, dimension(:), intent(in), optional mask,
logical, intent(in), optional back )

map inv distinct

Definizione alla linea 976 del file vol7d_var_class.F90.

978! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
979! authors:
980! Davide Cesari <dcesari@arpa.emr.it>
981! Paolo Patruno <ppatruno@arpa.emr.it>
982
983! This program is free software; you can redistribute it and/or
984! modify it under the terms of the GNU General Public License as
985! published by the Free Software Foundation; either version 2 of
986! the License, or (at your option) any later version.
987
988! This program is distributed in the hope that it will be useful,
989! but WITHOUT ANY WARRANTY; without even the implied warranty of
990! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
991! GNU General Public License for more details.
992
993! You should have received a copy of the GNU General Public License
994! along with this program. If not, see <http://www.gnu.org/licenses/>.
995#include "config.h"
996
997!> Classe per la gestione delle variabili osservate da stazioni meteo e affini.
998!! Questo modulo definisce una classe per rappresentare variabili meteorologiche
999!! osservate, o attributi, aventi diversi tipi numerici o carattere.
1000!! \ingroup vol7d
1001MODULE vol7d_var_class
1002USE kinds
1005IMPLICIT NONE
1006
1007!> Definisce una variabile meteorologica osservata o un suo attributo.
1008!! I membri \a r, \a d, \a i, \a b, \a c servono, internamente a vol7d,
1009!! per associare le variabili agli attributi, e indicano
1010!! a quale variabile, nel descrittore delle variabili, coincide
1011!! la variabile corrente nel descrittore delle "variabili aventi attributo".
1012!! I membri di \a vol7d_var sono pubblici e quindi liberamente
1013!! accessibili e scrivibili, ma è comunque consigliato assegnarli tramite
1014!! il costruttore ::init.
1015TYPE vol7d_var
1016 CHARACTER(len=10) :: btable=cmiss !< codice della variabile secondo la tabella B del WMO.
1017 CHARACTER(len=65) :: description=cmiss !< descrizione testuale della variabile (opzionale)
1018 CHARACTER(len=24) :: unit=cmiss !< descrizione testuale dell'unità di misura (opzionale)
1019 INTEGER :: scalefactor=imiss !< numero di decimali nella rappresentazione intera o character (opzionale)
1020
1021 INTEGER :: r=imiss !< indice della variabile nel volume degli attributi reali
1022 INTEGER :: d=imiss !< indice della variabile nel volume degli attributi double precision
1023 INTEGER :: i=imiss !< indice della variabile nel volume degli attributi integer
1024 INTEGER :: b=imiss !< indice della variabile nel volume degli attributi byte
1025 INTEGER :: c=imiss !< indice della variabile nel volume degli attributi character
1026 INTEGER :: gribhint(4)=imiss !< hint for conversion from/to grib when btable is not found
1027 INTEGER :: feat_ind=imiss !< cached index to corresponding entry in feature table
1028END TYPE vol7d_var
1029
1030!> Valore mancante per vol7d_var.
1031TYPE(vol7d_var),PARAMETER :: vol7d_var_miss= &
1032 vol7d_var(cmiss,cmiss,cmiss,imiss,imiss,imiss,imiss,imiss,imiss, &
1033 (/imiss,imiss,imiss,imiss/))
1034
1035!> Costruttore per la classe vol7d_var.
1036!! Deve essere richiamato
1037!! per tutti gli oggetti di questo tipo definiti in un programma.
1038INTERFACE init
1039 MODULE PROCEDURE vol7d_var_init
1040END INTERFACE
1041
1042!> Distruttore per la classe vol7d_var.
1043!! Distrugge l'oggetto in maniera pulita, assegnandogli un valore mancante.
1044INTERFACE delete
1045 MODULE PROCEDURE vol7d_var_delete
1046END INTERFACE
1047
1048!> Operatore logico di uguaglianza tra oggetti della classe vol7d_var.
1049!! Funziona anche per
1050!! confronti di tipo array-array (qualsiasi n. di dimensioni) e di tipo
1051!! scalare-vettore(1-d) (ma non vettore(1-d)-scalare o tra array con più
1052!! di 1 dimensione e scalari).
1053INTERFACE OPERATOR (==)
1054 MODULE PROCEDURE vol7d_var_eq
1055END INTERFACE
1056
1057!> Operatore logico di disuguaglianza tra oggetti della classe vol7d_var.
1058!! Funziona anche per
1059!! confronti di tipo array-array (qualsiasi n. di dimensioni) e di tipo
1060!! scalare-vettore(1-d) (ma non vettore(1-d)-scalare o tra array con più
1061!! di 1 dimensione e scalari).
1062INTERFACE OPERATOR (/=)
1063 MODULE PROCEDURE vol7d_var_ne, vol7d_var_nesv
1064END INTERFACE
1065
1066!> to be documented
1067INTERFACE c_e
1068 MODULE PROCEDURE vol7d_var_c_e
1069END INTERFACE
1070
1071#define VOL7D_POLY_TYPE TYPE(vol7d_var)
1072#define VOL7D_POLY_TYPES _var
1073#include "array_utilities_pre.F90"
1074
1075!> \brief display on the screen a brief content of object
1076INTERFACE display
1077 MODULE PROCEDURE display_var, display_var_vect
1078END INTERFACE
1079
1080
1081TYPE vol7d_var_features
1082 TYPE(vol7d_var) :: var !< the variable (only btable is relevant)
1083 REAL :: posdef !< if not missing, minimum physically reasonable value for the variable
1084 INTEGER :: vartype !< type of variable, one of the var_* constants
1085END TYPE vol7d_var_features
1086
1087TYPE(vol7d_var_features),ALLOCATABLE :: var_features(:)
1088
1089! constants for vol7d_vartype
1090INTEGER,PARAMETER :: var_ord=0 !< unclassified variable (vol7d_vartype function)
1091INTEGER,PARAMETER :: var_dir360=1 !< direction in degrees (vol7d_vartype function)
1092INTEGER,PARAMETER :: var_press=2 !< pressure in Pa (vol7d_vartype function)
1093INTEGER,PARAMETER :: var_ucomp=3 !< u component of a vector field (vol7d_vartype function)
1094INTEGER,PARAMETER :: var_vcomp=4 !< v component of a vector field (vol7d_vartype function)
1095INTEGER,PARAMETER :: var_wcomp=5 !< w component of a vector field (vol7d_vartype function)
1096
1097PRIVATE vol7d_var_features_init
1098
1099CONTAINS
1100
1101!> Inizializza un oggetto \a vol7d_var con i parametri opzionali forniti.
1102!! Se non viene passato nessun parametro opzionale l'oggetto è
1103!! inizializzato a valore mancante.
1104!! I membri \a r, \a d, \a i, \a b, \a c non possono essere assegnati
1105!! tramite costruttore, ma solo direttamente.
1106elemental SUBROUTINE vol7d_var_init(this, btable, description, unit, scalefactor)
1107TYPE(vol7d_var),INTENT(INOUT) :: this !< oggetto da inizializzare
1108CHARACTER(len=*),INTENT(in),OPTIONAL :: btable !< codice della variabile
1109CHARACTER(len=*),INTENT(in),OPTIONAL :: description !< descrizione della variabile
1110CHARACTER(len=*),INTENT(in),OPTIONAL :: unit !< unità di misura
1111INTEGER,INTENT(in),OPTIONAL :: scalefactor !< decimali nella rappresentazione intera e character
1112
1113IF (PRESENT(btable)) THEN
1114 this%btable = btable
1115ELSE
1116 this%btable = cmiss
1117 this%description = cmiss
1118 this%unit = cmiss
1119 this%scalefactor = imiss
1120 RETURN
1121ENDIF
1122IF (PRESENT(description)) THEN
1123 this%description = description
1124ELSE
1125 this%description = cmiss
1126ENDIF
1127IF (PRESENT(unit)) THEN
1128 this%unit = unit
1129ELSE
1130 this%unit = cmiss
1131ENDIF
1132if (present(scalefactor)) then
1133 this%scalefactor = scalefactor
1134else
1135 this%scalefactor = imiss
1136endif
1137
1138this%r = -1
1139this%d = -1
1140this%i = -1
1141this%b = -1
1142this%c = -1
1143
1144END SUBROUTINE vol7d_var_init
1145
1146
1147ELEMENTAL FUNCTION vol7d_var_new(btable, description, unit, scalefactor) RESULT(this)
1148CHARACTER(len=*),INTENT(in),OPTIONAL :: btable !< codice della variabile
1149CHARACTER(len=*),INTENT(in),OPTIONAL :: description !< descrizione della variabile
1150CHARACTER(len=*),INTENT(in),OPTIONAL :: unit !< unità di misura
1151INTEGER,INTENT(in),OPTIONAL :: scalefactor !< decimali nella rappresentazione intera e character
1152
1153TYPE(vol7d_var) :: this
1154
1155CALL init(this, btable, description, unit, scalefactor)
1156
1157END FUNCTION vol7d_var_new
1158
1159
1160!> Distrugge l'oggetto in maniera pulita, assegnandogli un valore mancante.
1161elemental SUBROUTINE vol7d_var_delete(this)
1162TYPE(vol7d_var),INTENT(INOUT) :: this !< oggetto da distruggre
1163
1164this%btable = cmiss
1165this%description = cmiss
1166this%unit = cmiss
1167this%scalefactor = imiss
1168
1169END SUBROUTINE vol7d_var_delete
1170
1171
1172ELEMENTAL FUNCTION vol7d_var_eq(this, that) RESULT(res)
1173TYPE(vol7d_var),INTENT(IN) :: this, that
1174LOGICAL :: res
1175
1176res = this%btable == that%btable
1177
1178END FUNCTION vol7d_var_eq
1179
1180
1181ELEMENTAL FUNCTION vol7d_var_ne(this, that) RESULT(res)
1182TYPE(vol7d_var),INTENT(IN) :: this, that
1183LOGICAL :: res
1184
1185res = .NOT.(this == that)
1186
1187END FUNCTION vol7d_var_ne
1188
1189
1190FUNCTION vol7d_var_nesv(this, that) RESULT(res)
1191TYPE(vol7d_var),INTENT(IN) :: this, that(:)
1192LOGICAL :: res(SIZE(that))
1193
1194INTEGER :: i
1195
1196DO i = 1, SIZE(that)
1197 res(i) = .NOT.(this == that(i))
1198ENDDO
1199
1200END FUNCTION vol7d_var_nesv
1201
1202
1203
1204!> \brief display on the screen a brief content of vol7d_var object
1205subroutine display_var(this)
1206
1207TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to display
1208
1209print*,"VOL7DVAR: ",this%btable,trim(this%description)," : ",this%unit,&
1210 " scale factor",this%scalefactor
1211
1212end subroutine display_var
1213
1214
1215!> \brief display on the screen a brief content of vector of vol7d_var object
1216subroutine display_var_vect(this)
1217
1218TYPE(vol7d_var),INTENT(in) :: this(:) !< vol7d_var vector object to display
1219integer :: i
1220
1221do i=1,size(this)
1222 call display_var(this(i))
1223end do
1224
1225end subroutine display_var_vect
1226
1227FUNCTION vol7d_var_c_e(this) RESULT(c_e)
1228TYPE(vol7d_var),INTENT(IN) :: this
1229LOGICAL :: c_e
1230c_e = this /= vol7d_var_miss
1231END FUNCTION vol7d_var_c_e
1232
1233
1234SUBROUTINE vol7d_var_features_set(this)
1235TYPE(vol7d_var),INTENT(inout) :: this
1236INTEGER :: i
1237
1238CALL vol7d_var_features_init()
1239
1240IF (ALLOCATED(var_features)) THEN
1241 DO i = 1, SIZE(var_features)
1242 IF (this == var_features(i)%var) THEN
1243 this%feat_ind = i
1244 EXIT
1245 ENDIF
1246 ENDDO
1247ENDIF
1248
1249END SUBROUTINE vol7d_var_features_set
1250
1251
1252!> Initialise the global table of variable features.
1253!! This subroutine reads the table of variable features from an
1254!! external file and stores it in a global array. It has to be called
1255!! once at the beginning of the program. At the moment it gives access
1256!! to the information about type of variable and positive
1257!! definitness. The table is based on the unique bufr-like variable
1258!! table. The table is contained in the csv file `vargrib.csv`.
1259!! It is not harmful to call this subroutine multiple times.
1260SUBROUTINE vol7d_var_features_init()
1261INTEGER :: un, i, n
1262TYPE(csv_record) :: csv
1263CHARACTER(len=1024) :: line
1264
1265IF (ALLOCATED(var_features)) RETURN
1266
1267un = open_package_file('varbufr.csv', filetype_data)
1268n=0
1269DO WHILE(.true.)
1270 READ(un,*,END=100)
1271 n = n + 1
1272ENDDO
1273
1274100 CONTINUE
1275
1276rewind(un)
1277ALLOCATE(var_features(n))
1278
1279DO i = 1, n
1280 READ(un,'(A)',END=200)line
1281 CALL init(csv, line)
1282 CALL csv_record_getfield(csv, var_features(i)%var%btable)
1283 CALL csv_record_getfield(csv)
1284 CALL csv_record_getfield(csv)
1285 CALL csv_record_getfield(csv, var_features(i)%posdef)
1286 CALL csv_record_getfield(csv, var_features(i)%vartype)
1287 CALL delete(csv)
1288ENDDO
1289
1290200 CONTINUE
1291CLOSE(un)
1292
1293END SUBROUTINE vol7d_var_features_init
1294
1295
1296!> Deallocate the global table of variable features.
1297!! This subroutine deallocates the table of variable features
1298!! allocated in the `vol7d_var_features_init` subroutine.
1299SUBROUTINE vol7d_var_features_delete()
1300IF (ALLOCATED(var_features)) DEALLOCATE(var_features)
1301END SUBROUTINE vol7d_var_features_delete
1302
1303
1304!> Return the physical type of the variable.
1305!! Returns a rough classification of the variable depending on the
1306!! physical parameter it represents. The result is one of the
1307!! constants vartype_* defined in the module. To be extended.
1308!! In order for this to work, the subroutine \a
1309!! vol7d_var_features_set has to be preliminary called.
1310ELEMENTAL FUNCTION vol7d_var_features_vartype(this) RESULT(vartype)
1311TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be tested
1312INTEGER :: vartype
1313
1314IF (c_e(this%feat_ind)) THEN
1315 vartype = var_features(this%feat_ind)%vartype
1316ELSE
1317 vartype = imiss
1318ENDIF
1319
1320END FUNCTION vol7d_var_features_vartype
1321
1322
1323!> Apply a positive definite flag to a variable.
1324!! This subroutine resets the value of a variable depending on its
1325!! positive definite flag defined in the associated \a c_func object.
1326!! The \a c_func object can be obtained for example by the \a convert
1327!! (interfaced to vargrib2varbufr_convert) function. The value is
1328!! reset to the maximum between the value itself and and 0 (or the
1329!! value set in \a c_func%posdef. These values are set from the
1330!! varbufr.csv file.
1331!! In order for this to work, the subroutine \a
1332!! vol7d_var_features_set has to be preliminary called.
1333ELEMENTAL SUBROUTINE vol7d_var_features_posdef_apply(this, val)
1334TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be reset
1335REAL,INTENT(inout) :: val !< value to be reset, it is reset in place
1336
1337IF (c_e(this%feat_ind)) THEN
1338 IF (c_e(var_features(this%feat_ind)%posdef)) THEN
1339 IF (c_e(val)) THEN
1340 val = max(var_features(this%feat_ind)%posdef, val)
1341 ENDIF
1342 ENDIF
1343ENDIF
1344
1345END SUBROUTINE vol7d_var_features_posdef_apply
1346
1347
1348!> Return the physical type of the variable.
1349!! Returns a rough classification of the variable depending on the
1350!! physical parameter it represents. The result is one of the
1351!! constants vartype_* defined in the module. To be extended.
1352ELEMENTAL FUNCTION vol7d_vartype(this) RESULT(vartype)
1353TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be tested
1354
1355INTEGER :: vartype
1356
1357vartype = var_ord
1358SELECT CASE(this%btable)
1359CASE('B01012', 'B11001', 'B11043', 'B22001') ! direction, degree true
1360 vartype = var_dir360
1361CASE('B07004', 'B10004', 'B10051', 'B10060') ! pressure, Pa
1362 vartype = var_press
1363CASE('B11003', 'B11200') ! u-component
1364 vartype = var_ucomp
1365CASE('B11004', 'B11201') ! v-component
1366 vartype = var_vcomp
1367CASE('B11005', 'B11006') ! w-component
1368 vartype = var_wcomp
1369END SELECT
1370
1371END FUNCTION vol7d_vartype
1372
1373
1374#include "array_utilities_inc.F90"
1375
1376
1377END MODULE vol7d_var_class
Distruttore per la classe vol7d_var.
display on the screen a brief content of object
Costruttore per la classe vol7d_var.
Utilities for managing files.
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.
Classe per la gestione delle variabili osservate da stazioni meteo e affini.
Definisce una variabile meteorologica osservata o un suo attributo.

Generated with Doxygen.