libsim Versione 8.0.0

◆ vol7d_var_features_delete()

subroutine vol7d_var_features_delete

Deallocate the global table of variable features.

This subroutine deallocates the table of variable features allocated in the vol7d_var_features_init subroutine.

Definizione alla linea 552 del file vol7d_var_class.F90.

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