libsim Versione 7.2.6

◆ vol7d_var_features_init()

subroutine vol7d_var_features_init

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 493 del file vol7d_var_class.F90.

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