libsim Versione 8.0.0

◆ display_var()

subroutine display_var ( type(vol7d_var), intent(in) this)

display on the screen a brief content of vol7d_var object

Parametri
[in]thisvol7d_var object to display

Definizione alla linea 458 del file vol7d_var_class.F90.

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