libsim Versione 8.0.0

◆ vol7d_var_features_init()

subroutine, private vol7d_var_features_init
private

Initialise the global table of variable features.

This subroutine reads the table of variable features from an external file and stores it in a global array. It has to be called once at the beginning of the program. At the moment it gives access to the information about type of variable and positive definitness. The table is based on the unique bufr-like variable table. The table is contained in the csv file vargrib.csv. It is not harmful to call this subroutine multiple times.

Definizione alla linea 513 del file vol7d_var_class.F90.

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