libsim Versione 8.0.0

◆ vol7d_vartype()

elemental integer function vol7d_vartype ( type(vol7d_var), intent(in) this)

Return the physical type of the variable.

Returns a rough classification of the variable depending on the physical parameter it represents. The result is one of the constants vartype_* defined in the module. To be extended.

Parametri
[in]thisvol7d_var object to be tested

Definizione alla linea 605 del file vol7d_var_class.F90.

606! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
607! authors:
608! Davide Cesari <dcesari@arpa.emr.it>
609! Paolo Patruno <ppatruno@arpa.emr.it>
610
611! This program is free software; you can redistribute it and/or
612! modify it under the terms of the GNU General Public License as
613! published by the Free Software Foundation; either version 2 of
614! the License, or (at your option) any later version.
615
616! This program is distributed in the hope that it will be useful,
617! but WITHOUT ANY WARRANTY; without even the implied warranty of
618! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
619! GNU General Public License for more details.
620
621! You should have received a copy of the GNU General Public License
622! along with this program. If not, see <http://www.gnu.org/licenses/>.
623#include "config.h"
624
625!> Classe per la gestione delle variabili osservate da stazioni meteo e affini.
626!! Questo modulo definisce una classe per rappresentare variabili meteorologiche
627!! osservate, o attributi, aventi diversi tipi numerici o carattere.
628!! \ingroup vol7d
629MODULE vol7d_var_class
630USE kinds
633IMPLICIT NONE
634
635!> Definisce una variabile meteorologica osservata o un suo attributo.
636!! I membri \a r, \a d, \a i, \a b, \a c servono, internamente a vol7d,
637!! per associare le variabili agli attributi, e indicano
638!! a quale variabile, nel descrittore delle variabili, coincide
639!! la variabile corrente nel descrittore delle "variabili aventi attributo".
640!! I membri di \a vol7d_var sono pubblici e quindi liberamente
641!! accessibili e scrivibili, ma è comunque consigliato assegnarli tramite
642!! il costruttore ::init.
643TYPE vol7d_var
644 CHARACTER(len=10) :: btable=cmiss !< codice della variabile secondo la tabella B del WMO.
645 CHARACTER(len=65) :: description=cmiss !< descrizione testuale della variabile (opzionale)
646 CHARACTER(len=24) :: unit=cmiss !< descrizione testuale dell'unità di misura (opzionale)
647 INTEGER :: scalefactor=imiss !< numero di decimali nella rappresentazione intera o character (opzionale)
648
649 INTEGER :: r=imiss !< indice della variabile nel volume degli attributi reali
650 INTEGER :: d=imiss !< indice della variabile nel volume degli attributi double precision
651 INTEGER :: i=imiss !< indice della variabile nel volume degli attributi integer
652 INTEGER :: b=imiss !< indice della variabile nel volume degli attributi byte
653 INTEGER :: c=imiss !< indice della variabile nel volume degli attributi character
654 INTEGER :: gribhint(4)=imiss !< hint for conversion from/to grib when btable is not found
655 INTEGER :: feat_ind=imiss !< cached index to corresponding entry in feature table
656END TYPE vol7d_var
657
658!> Valore mancante per vol7d_var.
659TYPE(vol7d_var),PARAMETER :: vol7d_var_miss= &
660 vol7d_var(cmiss,cmiss,cmiss,imiss,imiss,imiss,imiss,imiss,imiss, &
661 (/imiss,imiss,imiss,imiss/))
662
663!> Costruttore per la classe vol7d_var.
664!! Deve essere richiamato
665!! per tutti gli oggetti di questo tipo definiti in un programma.
666INTERFACE init
667 MODULE PROCEDURE vol7d_var_init
668END INTERFACE
669
670!> Distruttore per la classe vol7d_var.
671!! Distrugge l'oggetto in maniera pulita, assegnandogli un valore mancante.
672INTERFACE delete
673 MODULE PROCEDURE vol7d_var_delete
674END INTERFACE
675
676!> Operatore logico di uguaglianza tra oggetti della classe vol7d_var.
677!! Funziona anche per
678!! confronti di tipo array-array (qualsiasi n. di dimensioni) e di tipo
679!! scalare-vettore(1-d) (ma non vettore(1-d)-scalare o tra array con più
680!! di 1 dimensione e scalari).
681INTERFACE OPERATOR (==)
682 MODULE PROCEDURE vol7d_var_eq
683END INTERFACE
684
685!> Operatore logico di disuguaglianza tra oggetti della classe vol7d_var.
686!! Funziona anche per
687!! confronti di tipo array-array (qualsiasi n. di dimensioni) e di tipo
688!! scalare-vettore(1-d) (ma non vettore(1-d)-scalare o tra array con più
689!! di 1 dimensione e scalari).
690INTERFACE OPERATOR (/=)
691 MODULE PROCEDURE vol7d_var_ne, vol7d_var_nesv
692END INTERFACE
693
694!> to be documented
695INTERFACE c_e
696 MODULE PROCEDURE vol7d_var_c_e
697END INTERFACE
698
699#define VOL7D_POLY_TYPE TYPE(vol7d_var)
700#define VOL7D_POLY_TYPES _var
701#include "array_utilities_pre.F90"
702
703!> \brief display on the screen a brief content of object
704INTERFACE display
705 MODULE PROCEDURE display_var, display_var_vect
706END INTERFACE
707
708
709TYPE vol7d_var_features
710 TYPE(vol7d_var) :: var !< the variable (only btable is relevant)
711 REAL :: posdef !< if not missing, minimum physically reasonable value for the variable
712 INTEGER :: vartype !< type of variable, one of the var_* constants
713END TYPE vol7d_var_features
714
715TYPE(vol7d_var_features),ALLOCATABLE :: var_features(:)
716
717! constants for vol7d_vartype
718INTEGER,PARAMETER :: var_ord=0 !< unclassified variable (vol7d_vartype function)
719INTEGER,PARAMETER :: var_dir360=1 !< direction in degrees (vol7d_vartype function)
720INTEGER,PARAMETER :: var_press=2 !< pressure in Pa (vol7d_vartype function)
721INTEGER,PARAMETER :: var_ucomp=3 !< u component of a vector field (vol7d_vartype function)
722INTEGER,PARAMETER :: var_vcomp=4 !< v component of a vector field (vol7d_vartype function)
723INTEGER,PARAMETER :: var_wcomp=5 !< w component of a vector field (vol7d_vartype function)
724
725PRIVATE vol7d_var_features_init
726
727CONTAINS
728
729!> Inizializza un oggetto \a vol7d_var con i parametri opzionali forniti.
730!! Se non viene passato nessun parametro opzionale l'oggetto è
731!! inizializzato a valore mancante.
732!! I membri \a r, \a d, \a i, \a b, \a c non possono essere assegnati
733!! tramite costruttore, ma solo direttamente.
734elemental SUBROUTINE vol7d_var_init(this, btable, description, unit, scalefactor)
735TYPE(vol7d_var),INTENT(INOUT) :: this !< oggetto da inizializzare
736CHARACTER(len=*),INTENT(in),OPTIONAL :: btable !< codice della variabile
737CHARACTER(len=*),INTENT(in),OPTIONAL :: description !< descrizione della variabile
738CHARACTER(len=*),INTENT(in),OPTIONAL :: unit !< unità di misura
739INTEGER,INTENT(in),OPTIONAL :: scalefactor !< decimali nella rappresentazione intera e character
740
741IF (PRESENT(btable)) THEN
742 this%btable = btable
743ELSE
744 this%btable = cmiss
745 this%description = cmiss
746 this%unit = cmiss
747 this%scalefactor = imiss
748 RETURN
749ENDIF
750IF (PRESENT(description)) THEN
751 this%description = description
752ELSE
753 this%description = cmiss
754ENDIF
755IF (PRESENT(unit)) THEN
756 this%unit = unit
757ELSE
758 this%unit = cmiss
759ENDIF
760if (present(scalefactor)) then
761 this%scalefactor = scalefactor
762else
763 this%scalefactor = imiss
764endif
765
766this%r = -1
767this%d = -1
768this%i = -1
769this%b = -1
770this%c = -1
771
772END SUBROUTINE vol7d_var_init
773
774
775ELEMENTAL FUNCTION vol7d_var_new(btable, description, unit, scalefactor) RESULT(this)
776CHARACTER(len=*),INTENT(in),OPTIONAL :: btable !< codice della variabile
777CHARACTER(len=*),INTENT(in),OPTIONAL :: description !< descrizione della variabile
778CHARACTER(len=*),INTENT(in),OPTIONAL :: unit !< unità di misura
779INTEGER,INTENT(in),OPTIONAL :: scalefactor !< decimali nella rappresentazione intera e character
780
781TYPE(vol7d_var) :: this
782
783CALL init(this, btable, description, unit, scalefactor)
784
785END FUNCTION vol7d_var_new
786
787
788!> Distrugge l'oggetto in maniera pulita, assegnandogli un valore mancante.
789elemental SUBROUTINE vol7d_var_delete(this)
790TYPE(vol7d_var),INTENT(INOUT) :: this !< oggetto da distruggre
791
792this%btable = cmiss
793this%description = cmiss
794this%unit = cmiss
795this%scalefactor = imiss
796
797END SUBROUTINE vol7d_var_delete
798
799
800ELEMENTAL FUNCTION vol7d_var_eq(this, that) RESULT(res)
801TYPE(vol7d_var),INTENT(IN) :: this, that
802LOGICAL :: res
803
804res = this%btable == that%btable
805
806END FUNCTION vol7d_var_eq
807
808
809ELEMENTAL FUNCTION vol7d_var_ne(this, that) RESULT(res)
810TYPE(vol7d_var),INTENT(IN) :: this, that
811LOGICAL :: res
812
813res = .NOT.(this == that)
814
815END FUNCTION vol7d_var_ne
816
817
818FUNCTION vol7d_var_nesv(this, that) RESULT(res)
819TYPE(vol7d_var),INTENT(IN) :: this, that(:)
820LOGICAL :: res(SIZE(that))
821
822INTEGER :: i
823
824DO i = 1, SIZE(that)
825 res(i) = .NOT.(this == that(i))
826ENDDO
827
828END FUNCTION vol7d_var_nesv
829
830
831
832!> \brief display on the screen a brief content of vol7d_var object
833subroutine display_var(this)
834
835TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to display
836
837print*,"VOL7DVAR: ",this%btable,trim(this%description)," : ",this%unit,&
838 " scale factor",this%scalefactor
839
840end subroutine display_var
841
842
843!> \brief display on the screen a brief content of vector of vol7d_var object
844subroutine display_var_vect(this)
845
846TYPE(vol7d_var),INTENT(in) :: this(:) !< vol7d_var vector object to display
847integer :: i
848
849do i=1,size(this)
850 call display_var(this(i))
851end do
852
853end subroutine display_var_vect
854
855FUNCTION vol7d_var_c_e(this) RESULT(c_e)
856TYPE(vol7d_var),INTENT(IN) :: this
857LOGICAL :: c_e
858c_e = this /= vol7d_var_miss
859END FUNCTION vol7d_var_c_e
860
861
862SUBROUTINE vol7d_var_features_set(this)
863TYPE(vol7d_var),INTENT(inout) :: this
864INTEGER :: i
865
866CALL vol7d_var_features_init()
867
868IF (ALLOCATED(var_features)) THEN
869 DO i = 1, SIZE(var_features)
870 IF (this == var_features(i)%var) THEN
871 this%feat_ind = i
872 EXIT
873 ENDIF
874 ENDDO
875ENDIF
876
877END SUBROUTINE vol7d_var_features_set
878
879
880!> Initialise the global table of variable features.
881!! This subroutine reads the table of variable features from an
882!! external file and stores it in a global array. It has to be called
883!! once at the beginning of the program. At the moment it gives access
884!! to the information about type of variable and positive
885!! definitness. The table is based on the unique bufr-like variable
886!! table. The table is contained in the csv file `vargrib.csv`.
887!! It is not harmful to call this subroutine multiple times.
888SUBROUTINE vol7d_var_features_init()
889INTEGER :: un, i, n
890TYPE(csv_record) :: csv
891CHARACTER(len=1024) :: line
892
893IF (ALLOCATED(var_features)) RETURN
894
895un = open_package_file('varbufr.csv', filetype_data)
896n=0
897DO WHILE(.true.)
898 READ(un,*,END=100)
899 n = n + 1
900ENDDO
901
902100 CONTINUE
903
904rewind(un)
905ALLOCATE(var_features(n))
906
907DO i = 1, n
908 READ(un,'(A)',END=200)line
909 CALL init(csv, line)
910 CALL csv_record_getfield(csv, var_features(i)%var%btable)
911 CALL csv_record_getfield(csv)
912 CALL csv_record_getfield(csv)
913 CALL csv_record_getfield(csv, var_features(i)%posdef)
914 CALL csv_record_getfield(csv, var_features(i)%vartype)
915 CALL delete(csv)
916ENDDO
917
918200 CONTINUE
919CLOSE(un)
920
921END SUBROUTINE vol7d_var_features_init
922
923
924!> Deallocate the global table of variable features.
925!! This subroutine deallocates the table of variable features
926!! allocated in the `vol7d_var_features_init` subroutine.
927SUBROUTINE vol7d_var_features_delete()
928IF (ALLOCATED(var_features)) DEALLOCATE(var_features)
929END SUBROUTINE vol7d_var_features_delete
930
931
932!> Return the physical type of the variable.
933!! Returns a rough classification of the variable depending on the
934!! physical parameter it represents. The result is one of the
935!! constants vartype_* defined in the module. To be extended.
936!! In order for this to work, the subroutine \a
937!! vol7d_var_features_set has to be preliminary called.
938ELEMENTAL FUNCTION vol7d_var_features_vartype(this) RESULT(vartype)
939TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be tested
940INTEGER :: vartype
941
942IF (c_e(this%feat_ind)) THEN
943 vartype = var_features(this%feat_ind)%vartype
944ELSE
945 vartype = imiss
946ENDIF
947
948END FUNCTION vol7d_var_features_vartype
949
950
951!> Apply a positive definite flag to a variable.
952!! This subroutine resets the value of a variable depending on its
953!! positive definite flag defined in the associated \a c_func object.
954!! The \a c_func object can be obtained for example by the \a convert
955!! (interfaced to vargrib2varbufr_convert) function. The value is
956!! reset to the maximum between the value itself and and 0 (or the
957!! value set in \a c_func%posdef. These values are set from the
958!! varbufr.csv file.
959!! In order for this to work, the subroutine \a
960!! vol7d_var_features_set has to be preliminary called.
961ELEMENTAL SUBROUTINE vol7d_var_features_posdef_apply(this, val)
962TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be reset
963REAL,INTENT(inout) :: val !< value to be reset, it is reset in place
964
965IF (c_e(this%feat_ind)) THEN
966 IF (c_e(var_features(this%feat_ind)%posdef)) THEN
967 IF (c_e(val)) THEN
968 val = max(var_features(this%feat_ind)%posdef, val)
969 ENDIF
970 ENDIF
971ENDIF
972
973END SUBROUTINE vol7d_var_features_posdef_apply
974
975
976!> Return the physical type of the variable.
977!! Returns a rough classification of the variable depending on the
978!! physical parameter it represents. The result is one of the
979!! constants vartype_* defined in the module. To be extended.
980ELEMENTAL FUNCTION vol7d_vartype(this) RESULT(vartype)
981TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be tested
982
983INTEGER :: vartype
984
985vartype = var_ord
986SELECT CASE(this%btable)
987CASE('B01012', 'B11001', 'B11043', 'B22001') ! direction, degree true
988 vartype = var_dir360
989CASE('B07004', 'B10004', 'B10051', 'B10060') ! pressure, Pa
990 vartype = var_press
991CASE('B11003', 'B11200') ! u-component
992 vartype = var_ucomp
993CASE('B11004', 'B11201') ! v-component
994 vartype = var_vcomp
995CASE('B11005', 'B11006') ! w-component
996 vartype = var_wcomp
997END SELECT
998
999END FUNCTION vol7d_vartype
1000
1001
1002#include "array_utilities_inc.F90"
1003
1004
1005END 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.