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