libsim Versione 8.0.0

◆ vol7d_var_delete()

elemental subroutine vol7d_var_delete ( type(vol7d_var), intent(inout) this)

Distrugge l'oggetto in maniera pulita, assegnandogli un valore mancante.

Parametri
[in,out]thisoggetto da distruggre

Definizione alla linea 414 del file vol7d_var_class.F90.

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