|
libsim Versione 8.0.0
|
◆ pack_distinct_var()
compatta gli elementi distinti di vect in un array Definizione alla linea 731 del file vol7d_var_class.F90. 733! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
734! authors:
735! Davide Cesari <dcesari@arpa.emr.it>
736! Paolo Patruno <ppatruno@arpa.emr.it>
737
738! This program is free software; you can redistribute it and/or
739! modify it under the terms of the GNU General Public License as
740! published by the Free Software Foundation; either version 2 of
741! the License, or (at your option) any later version.
742
743! This program is distributed in the hope that it will be useful,
744! but WITHOUT ANY WARRANTY; without even the implied warranty of
745! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
746! GNU General Public License for more details.
747
748! You should have received a copy of the GNU General Public License
749! along with this program. If not, see <http://www.gnu.org/licenses/>.
750#include "config.h"
751
752!> Classe per la gestione delle variabili osservate da stazioni meteo e affini.
753!! Questo modulo definisce una classe per rappresentare variabili meteorologiche
754!! osservate, o attributi, aventi diversi tipi numerici o carattere.
755!! \ingroup vol7d
760IMPLICIT NONE
761
762!> Definisce una variabile meteorologica osservata o un suo attributo.
763!! I membri \a r, \a d, \a i, \a b, \a c servono, internamente a vol7d,
764!! per associare le variabili agli attributi, e indicano
765!! a quale variabile, nel descrittore delle variabili, coincide
766!! la variabile corrente nel descrittore delle "variabili aventi attributo".
767!! I membri di \a vol7d_var sono pubblici e quindi liberamente
768!! accessibili e scrivibili, ma è comunque consigliato assegnarli tramite
769!! il costruttore ::init.
771 CHARACTER(len=10) :: btable=cmiss !< codice della variabile secondo la tabella B del WMO.
772 CHARACTER(len=65) :: description=cmiss !< descrizione testuale della variabile (opzionale)
773 CHARACTER(len=24) :: unit=cmiss !< descrizione testuale dell'unità di misura (opzionale)
774 INTEGER :: scalefactor=imiss !< numero di decimali nella rappresentazione intera o character (opzionale)
775
776 INTEGER :: r=imiss !< indice della variabile nel volume degli attributi reali
777 INTEGER :: d=imiss !< indice della variabile nel volume degli attributi double precision
778 INTEGER :: i=imiss !< indice della variabile nel volume degli attributi integer
779 INTEGER :: b=imiss !< indice della variabile nel volume degli attributi byte
780 INTEGER :: c=imiss !< indice della variabile nel volume degli attributi character
781 INTEGER :: gribhint(4)=imiss !< hint for conversion from/to grib when btable is not found
782 INTEGER :: feat_ind=imiss !< cached index to corresponding entry in feature table
784
785!> Valore mancante per vol7d_var.
786TYPE(vol7d_var),PARAMETER :: vol7d_var_miss= &
787 vol7d_var(cmiss,cmiss,cmiss,imiss,imiss,imiss,imiss,imiss,imiss, &
788 (/imiss,imiss,imiss,imiss/))
789
790!> Costruttore per la classe vol7d_var.
791!! Deve essere richiamato
792!! per tutti gli oggetti di questo tipo definiti in un programma.
794 MODULE PROCEDURE vol7d_var_init
795END INTERFACE
796
797!> Distruttore per la classe vol7d_var.
798!! Distrugge l'oggetto in maniera pulita, assegnandogli un valore mancante.
800 MODULE PROCEDURE vol7d_var_delete
801END INTERFACE
802
803!> Operatore logico di uguaglianza tra oggetti della classe vol7d_var.
804!! Funziona anche per
805!! confronti di tipo array-array (qualsiasi n. di dimensioni) e di tipo
806!! scalare-vettore(1-d) (ma non vettore(1-d)-scalare o tra array con più
807!! di 1 dimensione e scalari).
808INTERFACE OPERATOR (==)
809 MODULE PROCEDURE vol7d_var_eq
810END INTERFACE
811
812!> Operatore logico di disuguaglianza tra oggetti della classe vol7d_var.
813!! Funziona anche per
814!! confronti di tipo array-array (qualsiasi n. di dimensioni) e di tipo
815!! scalare-vettore(1-d) (ma non vettore(1-d)-scalare o tra array con più
816!! di 1 dimensione e scalari).
817INTERFACE OPERATOR (/=)
818 MODULE PROCEDURE vol7d_var_ne, vol7d_var_nesv
819END INTERFACE
820
821!> to be documented
823 MODULE PROCEDURE vol7d_var_c_e
824END INTERFACE
825
826#define VOL7D_POLY_TYPE TYPE(vol7d_var)
827#define VOL7D_POLY_TYPES _var
828#include "array_utilities_pre.F90"
829
830!> \brief display on the screen a brief content of object
832 MODULE PROCEDURE display_var, display_var_vect
833END INTERFACE
834
835
836TYPE vol7d_var_features
837 TYPE(vol7d_var) :: var !< the variable (only btable is relevant)
838 REAL :: posdef !< if not missing, minimum physically reasonable value for the variable
839 INTEGER :: vartype !< type of variable, one of the var_* constants
840END TYPE vol7d_var_features
841
842TYPE(vol7d_var_features),ALLOCATABLE :: var_features(:)
843
844! constants for vol7d_vartype
845INTEGER,PARAMETER :: var_ord=0 !< unclassified variable (vol7d_vartype function)
846INTEGER,PARAMETER :: var_dir360=1 !< direction in degrees (vol7d_vartype function)
847INTEGER,PARAMETER :: var_press=2 !< pressure in Pa (vol7d_vartype function)
848INTEGER,PARAMETER :: var_ucomp=3 !< u component of a vector field (vol7d_vartype function)
849INTEGER,PARAMETER :: var_vcomp=4 !< v component of a vector field (vol7d_vartype function)
850INTEGER,PARAMETER :: var_wcomp=5 !< w component of a vector field (vol7d_vartype function)
851
852PRIVATE vol7d_var_features_init
853
854CONTAINS
855
856!> Inizializza un oggetto \a vol7d_var con i parametri opzionali forniti.
857!! Se non viene passato nessun parametro opzionale l'oggetto è
858!! inizializzato a valore mancante.
859!! I membri \a r, \a d, \a i, \a b, \a c non possono essere assegnati
860!! tramite costruttore, ma solo direttamente.
861elemental SUBROUTINE vol7d_var_init(this, btable, description, unit, scalefactor)
862TYPE(vol7d_var),INTENT(INOUT) :: this !< oggetto da inizializzare
863CHARACTER(len=*),INTENT(in),OPTIONAL :: btable !< codice della variabile
864CHARACTER(len=*),INTENT(in),OPTIONAL :: description !< descrizione della variabile
865CHARACTER(len=*),INTENT(in),OPTIONAL :: unit !< unità di misura
866INTEGER,INTENT(in),OPTIONAL :: scalefactor !< decimali nella rappresentazione intera e character
867
868IF (PRESENT(btable)) THEN
869 this%btable = btable
870ELSE
871 this%btable = cmiss
872 this%description = cmiss
873 this%unit = cmiss
874 this%scalefactor = imiss
875 RETURN
876ENDIF
877IF (PRESENT(description)) THEN
878 this%description = description
879ELSE
880 this%description = cmiss
881ENDIF
882IF (PRESENT(unit)) THEN
883 this%unit = unit
884ELSE
885 this%unit = cmiss
886ENDIF
887if (present(scalefactor)) then
888 this%scalefactor = scalefactor
889else
890 this%scalefactor = imiss
891endif
892
893this%r = -1
894this%d = -1
895this%i = -1
896this%b = -1
897this%c = -1
898
899END SUBROUTINE vol7d_var_init
900
901
902ELEMENTAL FUNCTION vol7d_var_new(btable, description, unit, scalefactor) RESULT(this)
903CHARACTER(len=*),INTENT(in),OPTIONAL :: btable !< codice della variabile
904CHARACTER(len=*),INTENT(in),OPTIONAL :: description !< descrizione della variabile
905CHARACTER(len=*),INTENT(in),OPTIONAL :: unit !< unità di misura
906INTEGER,INTENT(in),OPTIONAL :: scalefactor !< decimali nella rappresentazione intera e character
907
908TYPE(vol7d_var) :: this
909
911
912END FUNCTION vol7d_var_new
913
914
915!> Distrugge l'oggetto in maniera pulita, assegnandogli un valore mancante.
916elemental SUBROUTINE vol7d_var_delete(this)
917TYPE(vol7d_var),INTENT(INOUT) :: this !< oggetto da distruggre
918
919this%btable = cmiss
920this%description = cmiss
921this%unit = cmiss
922this%scalefactor = imiss
923
924END SUBROUTINE vol7d_var_delete
925
926
927ELEMENTAL FUNCTION vol7d_var_eq(this, that) RESULT(res)
928TYPE(vol7d_var),INTENT(IN) :: this, that
929LOGICAL :: res
930
931res = this%btable == that%btable
932
933END FUNCTION vol7d_var_eq
934
935
936ELEMENTAL FUNCTION vol7d_var_ne(this, that) RESULT(res)
937TYPE(vol7d_var),INTENT(IN) :: this, that
938LOGICAL :: res
939
940res = .NOT.(this == that)
941
942END FUNCTION vol7d_var_ne
943
944
945FUNCTION vol7d_var_nesv(this, that) RESULT(res)
946TYPE(vol7d_var),INTENT(IN) :: this, that(:)
947LOGICAL :: res(SIZE(that))
948
949INTEGER :: i
950
951DO i = 1, SIZE(that)
952 res(i) = .NOT.(this == that(i))
953ENDDO
954
955END FUNCTION vol7d_var_nesv
956
957
958
959!> \brief display on the screen a brief content of vol7d_var object
960subroutine display_var(this)
961
962TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to display
963
964print*,"VOL7DVAR: ",this%btable,trim(this%description)," : ",this%unit,&
965 " scale factor",this%scalefactor
966
967end subroutine display_var
968
969
970!> \brief display on the screen a brief content of vector of vol7d_var object
971subroutine display_var_vect(this)
972
973TYPE(vol7d_var),INTENT(in) :: this(:) !< vol7d_var vector object to display
974integer :: i
975
976do i=1,size(this)
977 call display_var(this(i))
978end do
979
980end subroutine display_var_vect
981
982FUNCTION vol7d_var_c_e(this) RESULT(c_e)
983TYPE(vol7d_var),INTENT(IN) :: this
984LOGICAL :: c_e
985c_e = this /= vol7d_var_miss
986END FUNCTION vol7d_var_c_e
987
988
989SUBROUTINE vol7d_var_features_set(this)
990TYPE(vol7d_var),INTENT(inout) :: this
991INTEGER :: i
992
993CALL vol7d_var_features_init()
994
995IF (ALLOCATED(var_features)) THEN
996 DO i = 1, SIZE(var_features)
997 IF (this == var_features(i)%var) THEN
998 this%feat_ind = i
999 EXIT
1000 ENDIF
1001 ENDDO
1002ENDIF
1003
1004END SUBROUTINE vol7d_var_features_set
1005
1006
1007!> Initialise the global table of variable features.
1008!! This subroutine reads the table of variable features from an
1009!! external file and stores it in a global array. It has to be called
1010!! once at the beginning of the program. At the moment it gives access
1011!! to the information about type of variable and positive
1012!! definitness. The table is based on the unique bufr-like variable
1013!! table. The table is contained in the csv file `vargrib.csv`.
1014!! It is not harmful to call this subroutine multiple times.
1015SUBROUTINE vol7d_var_features_init()
1016INTEGER :: un, i, n
1017TYPE(csv_record) :: csv
1018CHARACTER(len=1024) :: line
1019
1020IF (ALLOCATED(var_features)) RETURN
1021
1022un = open_package_file('varbufr.csv', filetype_data)
1023n=0
1024DO WHILE(.true.)
1025 READ(un,*,END=100)
1026 n = n + 1
1027ENDDO
1028
1029100 CONTINUE
1030
1031rewind(un)
1032ALLOCATE(var_features(n))
1033
1034DO i = 1, n
1035 READ(un,'(A)',END=200)line
1037 CALL csv_record_getfield(csv, var_features(i)%var%btable)
1038 CALL csv_record_getfield(csv)
1039 CALL csv_record_getfield(csv)
1040 CALL csv_record_getfield(csv, var_features(i)%posdef)
1041 CALL csv_record_getfield(csv, var_features(i)%vartype)
1043ENDDO
1044
1045200 CONTINUE
1046CLOSE(un)
1047
1048END SUBROUTINE vol7d_var_features_init
1049
1050
1051!> Deallocate the global table of variable features.
1052!! This subroutine deallocates the table of variable features
1053!! allocated in the `vol7d_var_features_init` subroutine.
1054SUBROUTINE vol7d_var_features_delete()
1055IF (ALLOCATED(var_features)) DEALLOCATE(var_features)
1056END SUBROUTINE vol7d_var_features_delete
1057
1058
1059!> Return the physical type of the variable.
1060!! Returns a rough classification of the variable depending on the
1061!! physical parameter it represents. The result is one of the
1062!! constants vartype_* defined in the module. To be extended.
1063!! In order for this to work, the subroutine \a
1064!! vol7d_var_features_set has to be preliminary called.
1065ELEMENTAL FUNCTION vol7d_var_features_vartype(this) RESULT(vartype)
1066TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be tested
1067INTEGER :: vartype
1068
1070 vartype = var_features(this%feat_ind)%vartype
1071ELSE
1072 vartype = imiss
1073ENDIF
1074
1075END FUNCTION vol7d_var_features_vartype
1076
1077
1078!> Apply a positive definite flag to a variable.
1079!! This subroutine resets the value of a variable depending on its
1080!! positive definite flag defined in the associated \a c_func object.
1081!! The \a c_func object can be obtained for example by the \a convert
1082!! (interfaced to vargrib2varbufr_convert) function. The value is
1083!! reset to the maximum between the value itself and and 0 (or the
1084!! value set in \a c_func%posdef. These values are set from the
1085!! varbufr.csv file.
1086!! In order for this to work, the subroutine \a
1087!! vol7d_var_features_set has to be preliminary called.
1088ELEMENTAL SUBROUTINE vol7d_var_features_posdef_apply(this, val)
1089TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be reset
1090REAL,INTENT(inout) :: val !< value to be reset, it is reset in place
1091
1095 val = max(var_features(this%feat_ind)%posdef, val)
1096 ENDIF
1097 ENDIF
1098ENDIF
1099
1100END SUBROUTINE vol7d_var_features_posdef_apply
1101
1102
1103!> Return the physical type of the variable.
1104!! Returns a rough classification of the variable depending on the
1105!! physical parameter it represents. The result is one of the
1106!! constants vartype_* defined in the module. To be extended.
1107ELEMENTAL FUNCTION vol7d_vartype(this) RESULT(vartype)
1108TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be tested
1109
1110INTEGER :: vartype
1111
1112vartype = var_ord
1113SELECT CASE(this%btable)
1114CASE('B01012', 'B11001', 'B11043', 'B22001') ! direction, degree true
1115 vartype = var_dir360
1116CASE('B07004', 'B10004', 'B10051', 'B10060') ! pressure, Pa
1117 vartype = var_press
1118CASE('B11003', 'B11200') ! u-component
1119 vartype = var_ucomp
1120CASE('B11004', 'B11201') ! v-component
1121 vartype = var_vcomp
1122CASE('B11005', 'B11006') ! w-component
1123 vartype = var_wcomp
1124END SELECT
1125
1126END FUNCTION vol7d_vartype
1127
1128
1129#include "array_utilities_inc.F90"
1130
1131
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 |