libsim Versione 8.0.0

◆ vol7d_var_features_posdef_apply()

elemental subroutine vol7d_var_features_posdef_apply ( type(vol7d_var), intent(in) this,
real, intent(inout) val )

Apply a positive definite flag to a variable.

This subroutine resets the value of a variable depending on its positive definite flag defined in the associated c_func object. The c_func object can be obtained for example by the convert (interfaced to vargrib2varbufr_convert) function. The value is reset to the maximum between the value itself and and 0 (or the value set in c_funcposdef. These values are set from the varbufr.csv file. In order for this to work, the subroutine vol7d_var_features_set has to be preliminary called.

Parametri
[in]thisvol7d_var object to be reset
[in,out]valvalue to be reset, it is reset in place

Definizione alla linea 586 del file vol7d_var_class.F90.

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