libsim Versione 8.0.0

◆ vol7d_var_features_vartype()

elemental integer function vol7d_var_features_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. In order for this to work, the subroutine vol7d_var_features_set has to be preliminary called.

Parametri
[in]thisvol7d_var object to be tested

Definizione alla linea 563 del file vol7d_var_class.F90.

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