libsim Versione 8.0.0

◆ vol7d_var_new()

elemental type(vol7d_var) function vol7d_var_new ( character(len=*), intent(in), optional btable,
character(len=*), intent(in), optional description,
character(len=*), intent(in), optional unit,
integer, intent(in), optional scalefactor )
Parametri
[in]btablecodice della variabile
[in]descriptiondescrizione della variabile
[in]unitunità di misura
[in]scalefactordecimali nella rappresentazione intera e character

Definizione alla linea 400 del file vol7d_var_class.F90.

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