|
libsim Versione 8.0.0
|
◆ map_distinct_var()
map distinct Definizione alla linea 880 del file vol7d_var_class.F90. 881! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
882! authors:
883! Davide Cesari <dcesari@arpa.emr.it>
884! Paolo Patruno <ppatruno@arpa.emr.it>
885
886! This program is free software; you can redistribute it and/or
887! modify it under the terms of the GNU General Public License as
888! published by the Free Software Foundation; either version 2 of
889! the License, or (at your option) any later version.
890
891! This program is distributed in the hope that it will be useful,
892! but WITHOUT ANY WARRANTY; without even the implied warranty of
893! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
894! GNU General Public License for more details.
895
896! You should have received a copy of the GNU General Public License
897! along with this program. If not, see <http://www.gnu.org/licenses/>.
898#include "config.h"
899
900!> Classe per la gestione delle variabili osservate da stazioni meteo e affini.
901!! Questo modulo definisce una classe per rappresentare variabili meteorologiche
902!! osservate, o attributi, aventi diversi tipi numerici o carattere.
903!! \ingroup vol7d
908IMPLICIT NONE
909
910!> Definisce una variabile meteorologica osservata o un suo attributo.
911!! I membri \a r, \a d, \a i, \a b, \a c servono, internamente a vol7d,
912!! per associare le variabili agli attributi, e indicano
913!! a quale variabile, nel descrittore delle variabili, coincide
914!! la variabile corrente nel descrittore delle "variabili aventi attributo".
915!! I membri di \a vol7d_var sono pubblici e quindi liberamente
916!! accessibili e scrivibili, ma è comunque consigliato assegnarli tramite
917!! il costruttore ::init.
919 CHARACTER(len=10) :: btable=cmiss !< codice della variabile secondo la tabella B del WMO.
920 CHARACTER(len=65) :: description=cmiss !< descrizione testuale della variabile (opzionale)
921 CHARACTER(len=24) :: unit=cmiss !< descrizione testuale dell'unità di misura (opzionale)
922 INTEGER :: scalefactor=imiss !< numero di decimali nella rappresentazione intera o character (opzionale)
923
924 INTEGER :: r=imiss !< indice della variabile nel volume degli attributi reali
925 INTEGER :: d=imiss !< indice della variabile nel volume degli attributi double precision
926 INTEGER :: i=imiss !< indice della variabile nel volume degli attributi integer
927 INTEGER :: b=imiss !< indice della variabile nel volume degli attributi byte
928 INTEGER :: c=imiss !< indice della variabile nel volume degli attributi character
929 INTEGER :: gribhint(4)=imiss !< hint for conversion from/to grib when btable is not found
930 INTEGER :: feat_ind=imiss !< cached index to corresponding entry in feature table
932
933!> Valore mancante per vol7d_var.
934TYPE(vol7d_var),PARAMETER :: vol7d_var_miss= &
935 vol7d_var(cmiss,cmiss,cmiss,imiss,imiss,imiss,imiss,imiss,imiss, &
936 (/imiss,imiss,imiss,imiss/))
937
938!> Costruttore per la classe vol7d_var.
939!! Deve essere richiamato
940!! per tutti gli oggetti di questo tipo definiti in un programma.
942 MODULE PROCEDURE vol7d_var_init
943END INTERFACE
944
945!> Distruttore per la classe vol7d_var.
946!! Distrugge l'oggetto in maniera pulita, assegnandogli un valore mancante.
948 MODULE PROCEDURE vol7d_var_delete
949END INTERFACE
950
951!> Operatore logico di uguaglianza tra oggetti della classe vol7d_var.
952!! Funziona anche per
953!! confronti di tipo array-array (qualsiasi n. di dimensioni) e di tipo
954!! scalare-vettore(1-d) (ma non vettore(1-d)-scalare o tra array con più
955!! di 1 dimensione e scalari).
956INTERFACE OPERATOR (==)
957 MODULE PROCEDURE vol7d_var_eq
958END INTERFACE
959
960!> Operatore logico di disuguaglianza tra oggetti della classe vol7d_var.
961!! Funziona anche per
962!! confronti di tipo array-array (qualsiasi n. di dimensioni) e di tipo
963!! scalare-vettore(1-d) (ma non vettore(1-d)-scalare o tra array con più
964!! di 1 dimensione e scalari).
965INTERFACE OPERATOR (/=)
966 MODULE PROCEDURE vol7d_var_ne, vol7d_var_nesv
967END INTERFACE
968
969!> to be documented
971 MODULE PROCEDURE vol7d_var_c_e
972END INTERFACE
973
974#define VOL7D_POLY_TYPE TYPE(vol7d_var)
975#define VOL7D_POLY_TYPES _var
976#include "array_utilities_pre.F90"
977
978!> \brief display on the screen a brief content of object
980 MODULE PROCEDURE display_var, display_var_vect
981END INTERFACE
982
983
984TYPE vol7d_var_features
985 TYPE(vol7d_var) :: var !< the variable (only btable is relevant)
986 REAL :: posdef !< if not missing, minimum physically reasonable value for the variable
987 INTEGER :: vartype !< type of variable, one of the var_* constants
988END TYPE vol7d_var_features
989
990TYPE(vol7d_var_features),ALLOCATABLE :: var_features(:)
991
992! constants for vol7d_vartype
993INTEGER,PARAMETER :: var_ord=0 !< unclassified variable (vol7d_vartype function)
994INTEGER,PARAMETER :: var_dir360=1 !< direction in degrees (vol7d_vartype function)
995INTEGER,PARAMETER :: var_press=2 !< pressure in Pa (vol7d_vartype function)
996INTEGER,PARAMETER :: var_ucomp=3 !< u component of a vector field (vol7d_vartype function)
997INTEGER,PARAMETER :: var_vcomp=4 !< v component of a vector field (vol7d_vartype function)
998INTEGER,PARAMETER :: var_wcomp=5 !< w component of a vector field (vol7d_vartype function)
999
1000PRIVATE vol7d_var_features_init
1001
1002CONTAINS
1003
1004!> Inizializza un oggetto \a vol7d_var con i parametri opzionali forniti.
1005!! Se non viene passato nessun parametro opzionale l'oggetto è
1006!! inizializzato a valore mancante.
1007!! I membri \a r, \a d, \a i, \a b, \a c non possono essere assegnati
1008!! tramite costruttore, ma solo direttamente.
1009elemental SUBROUTINE vol7d_var_init(this, btable, description, unit, scalefactor)
1010TYPE(vol7d_var),INTENT(INOUT) :: this !< oggetto da inizializzare
1011CHARACTER(len=*),INTENT(in),OPTIONAL :: btable !< codice della variabile
1012CHARACTER(len=*),INTENT(in),OPTIONAL :: description !< descrizione della variabile
1013CHARACTER(len=*),INTENT(in),OPTIONAL :: unit !< unità di misura
1014INTEGER,INTENT(in),OPTIONAL :: scalefactor !< decimali nella rappresentazione intera e character
1015
1016IF (PRESENT(btable)) THEN
1017 this%btable = btable
1018ELSE
1019 this%btable = cmiss
1020 this%description = cmiss
1021 this%unit = cmiss
1022 this%scalefactor = imiss
1023 RETURN
1024ENDIF
1025IF (PRESENT(description)) THEN
1026 this%description = description
1027ELSE
1028 this%description = cmiss
1029ENDIF
1030IF (PRESENT(unit)) THEN
1031 this%unit = unit
1032ELSE
1033 this%unit = cmiss
1034ENDIF
1035if (present(scalefactor)) then
1036 this%scalefactor = scalefactor
1037else
1038 this%scalefactor = imiss
1039endif
1040
1041this%r = -1
1042this%d = -1
1043this%i = -1
1044this%b = -1
1045this%c = -1
1046
1047END SUBROUTINE vol7d_var_init
1048
1049
1050ELEMENTAL FUNCTION vol7d_var_new(btable, description, unit, scalefactor) RESULT(this)
1051CHARACTER(len=*),INTENT(in),OPTIONAL :: btable !< codice della variabile
1052CHARACTER(len=*),INTENT(in),OPTIONAL :: description !< descrizione della variabile
1053CHARACTER(len=*),INTENT(in),OPTIONAL :: unit !< unità di misura
1054INTEGER,INTENT(in),OPTIONAL :: scalefactor !< decimali nella rappresentazione intera e character
1055
1056TYPE(vol7d_var) :: this
1057
1059
1060END FUNCTION vol7d_var_new
1061
1062
1063!> Distrugge l'oggetto in maniera pulita, assegnandogli un valore mancante.
1064elemental SUBROUTINE vol7d_var_delete(this)
1065TYPE(vol7d_var),INTENT(INOUT) :: this !< oggetto da distruggre
1066
1067this%btable = cmiss
1068this%description = cmiss
1069this%unit = cmiss
1070this%scalefactor = imiss
1071
1072END SUBROUTINE vol7d_var_delete
1073
1074
1075ELEMENTAL FUNCTION vol7d_var_eq(this, that) RESULT(res)
1076TYPE(vol7d_var),INTENT(IN) :: this, that
1077LOGICAL :: res
1078
1079res = this%btable == that%btable
1080
1081END FUNCTION vol7d_var_eq
1082
1083
1084ELEMENTAL FUNCTION vol7d_var_ne(this, that) RESULT(res)
1085TYPE(vol7d_var),INTENT(IN) :: this, that
1086LOGICAL :: res
1087
1088res = .NOT.(this == that)
1089
1090END FUNCTION vol7d_var_ne
1091
1092
1093FUNCTION vol7d_var_nesv(this, that) RESULT(res)
1094TYPE(vol7d_var),INTENT(IN) :: this, that(:)
1095LOGICAL :: res(SIZE(that))
1096
1097INTEGER :: i
1098
1099DO i = 1, SIZE(that)
1100 res(i) = .NOT.(this == that(i))
1101ENDDO
1102
1103END FUNCTION vol7d_var_nesv
1104
1105
1106
1107!> \brief display on the screen a brief content of vol7d_var object
1108subroutine display_var(this)
1109
1110TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to display
1111
1112print*,"VOL7DVAR: ",this%btable,trim(this%description)," : ",this%unit,&
1113 " scale factor",this%scalefactor
1114
1115end subroutine display_var
1116
1117
1118!> \brief display on the screen a brief content of vector of vol7d_var object
1119subroutine display_var_vect(this)
1120
1121TYPE(vol7d_var),INTENT(in) :: this(:) !< vol7d_var vector object to display
1122integer :: i
1123
1124do i=1,size(this)
1125 call display_var(this(i))
1126end do
1127
1128end subroutine display_var_vect
1129
1130FUNCTION vol7d_var_c_e(this) RESULT(c_e)
1131TYPE(vol7d_var),INTENT(IN) :: this
1132LOGICAL :: c_e
1133c_e = this /= vol7d_var_miss
1134END FUNCTION vol7d_var_c_e
1135
1136
1137SUBROUTINE vol7d_var_features_set(this)
1138TYPE(vol7d_var),INTENT(inout) :: this
1139INTEGER :: i
1140
1141CALL vol7d_var_features_init()
1142
1143IF (ALLOCATED(var_features)) THEN
1144 DO i = 1, SIZE(var_features)
1145 IF (this == var_features(i)%var) THEN
1146 this%feat_ind = i
1147 EXIT
1148 ENDIF
1149 ENDDO
1150ENDIF
1151
1152END SUBROUTINE vol7d_var_features_set
1153
1154
1155!> Initialise the global table of variable features.
1156!! This subroutine reads the table of variable features from an
1157!! external file and stores it in a global array. It has to be called
1158!! once at the beginning of the program. At the moment it gives access
1159!! to the information about type of variable and positive
1160!! definitness. The table is based on the unique bufr-like variable
1161!! table. The table is contained in the csv file `vargrib.csv`.
1162!! It is not harmful to call this subroutine multiple times.
1163SUBROUTINE vol7d_var_features_init()
1164INTEGER :: un, i, n
1165TYPE(csv_record) :: csv
1166CHARACTER(len=1024) :: line
1167
1168IF (ALLOCATED(var_features)) RETURN
1169
1170un = open_package_file('varbufr.csv', filetype_data)
1171n=0
1172DO WHILE(.true.)
1173 READ(un,*,END=100)
1174 n = n + 1
1175ENDDO
1176
1177100 CONTINUE
1178
1179rewind(un)
1180ALLOCATE(var_features(n))
1181
1182DO i = 1, n
1183 READ(un,'(A)',END=200)line
1185 CALL csv_record_getfield(csv, var_features(i)%var%btable)
1186 CALL csv_record_getfield(csv)
1187 CALL csv_record_getfield(csv)
1188 CALL csv_record_getfield(csv, var_features(i)%posdef)
1189 CALL csv_record_getfield(csv, var_features(i)%vartype)
1191ENDDO
1192
1193200 CONTINUE
1194CLOSE(un)
1195
1196END SUBROUTINE vol7d_var_features_init
1197
1198
1199!> Deallocate the global table of variable features.
1200!! This subroutine deallocates the table of variable features
1201!! allocated in the `vol7d_var_features_init` subroutine.
1202SUBROUTINE vol7d_var_features_delete()
1203IF (ALLOCATED(var_features)) DEALLOCATE(var_features)
1204END SUBROUTINE vol7d_var_features_delete
1205
1206
1207!> Return the physical type of the variable.
1208!! Returns a rough classification of the variable depending on the
1209!! physical parameter it represents. The result is one of the
1210!! constants vartype_* defined in the module. To be extended.
1211!! In order for this to work, the subroutine \a
1212!! vol7d_var_features_set has to be preliminary called.
1213ELEMENTAL FUNCTION vol7d_var_features_vartype(this) RESULT(vartype)
1214TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be tested
1215INTEGER :: vartype
1216
1218 vartype = var_features(this%feat_ind)%vartype
1219ELSE
1220 vartype = imiss
1221ENDIF
1222
1223END FUNCTION vol7d_var_features_vartype
1224
1225
1226!> Apply a positive definite flag to a variable.
1227!! This subroutine resets the value of a variable depending on its
1228!! positive definite flag defined in the associated \a c_func object.
1229!! The \a c_func object can be obtained for example by the \a convert
1230!! (interfaced to vargrib2varbufr_convert) function. The value is
1231!! reset to the maximum between the value itself and and 0 (or the
1232!! value set in \a c_func%posdef. These values are set from the
1233!! varbufr.csv file.
1234!! In order for this to work, the subroutine \a
1235!! vol7d_var_features_set has to be preliminary called.
1236ELEMENTAL SUBROUTINE vol7d_var_features_posdef_apply(this, val)
1237TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be reset
1238REAL,INTENT(inout) :: val !< value to be reset, it is reset in place
1239
1243 val = max(var_features(this%feat_ind)%posdef, val)
1244 ENDIF
1245 ENDIF
1246ENDIF
1247
1248END SUBROUTINE vol7d_var_features_posdef_apply
1249
1250
1251!> Return the physical type of the variable.
1252!! Returns a rough classification of the variable depending on the
1253!! physical parameter it represents. The result is one of the
1254!! constants vartype_* defined in the module. To be extended.
1255ELEMENTAL FUNCTION vol7d_vartype(this) RESULT(vartype)
1256TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be tested
1257
1258INTEGER :: vartype
1259
1260vartype = var_ord
1261SELECT CASE(this%btable)
1262CASE('B01012', 'B11001', 'B11043', 'B22001') ! direction, degree true
1263 vartype = var_dir360
1264CASE('B07004', 'B10004', 'B10051', 'B10060') ! pressure, Pa
1265 vartype = var_press
1266CASE('B11003', 'B11200') ! u-component
1267 vartype = var_ucomp
1268CASE('B11004', 'B11201') ! v-component
1269 vartype = var_vcomp
1270CASE('B11005', 'B11006') ! w-component
1271 vartype = var_wcomp
1272END SELECT
1273
1274END FUNCTION vol7d_vartype
1275
1276
1277#include "array_utilities_inc.F90"
1278
1279
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 |