libsim Versione 7.2.6

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

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