libsim Versione 8.0.0

◆ count_distinct_var()

integer function count_distinct_var ( type(vol7d_var), dimension(:), intent(in) vect,
logical, dimension(:), intent(in), optional mask,
logical, intent(in), optional back )

conta gli elementi distinti in vect

Definizione alla linea 653 del file vol7d_var_class.F90.

654! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
655! authors:
656! Davide Cesari <dcesari@arpa.emr.it>
657! Paolo Patruno <ppatruno@arpa.emr.it>
658
659! This program is free software; you can redistribute it and/or
660! modify it under the terms of the GNU General Public License as
661! published by the Free Software Foundation; either version 2 of
662! the License, or (at your option) any later version.
663
664! This program is distributed in the hope that it will be useful,
665! but WITHOUT ANY WARRANTY; without even the implied warranty of
666! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
667! GNU General Public License for more details.
668
669! You should have received a copy of the GNU General Public License
670! along with this program. If not, see <http://www.gnu.org/licenses/>.
671#include "config.h"
672
673!> Classe per la gestione delle variabili osservate da stazioni meteo e affini.
674!! Questo modulo definisce una classe per rappresentare variabili meteorologiche
675!! osservate, o attributi, aventi diversi tipi numerici o carattere.
676!! \ingroup vol7d
677MODULE vol7d_var_class
678USE kinds
681IMPLICIT NONE
682
683!> Definisce una variabile meteorologica osservata o un suo attributo.
684!! I membri \a r, \a d, \a i, \a b, \a c servono, internamente a vol7d,
685!! per associare le variabili agli attributi, e indicano
686!! a quale variabile, nel descrittore delle variabili, coincide
687!! la variabile corrente nel descrittore delle "variabili aventi attributo".
688!! I membri di \a vol7d_var sono pubblici e quindi liberamente
689!! accessibili e scrivibili, ma è comunque consigliato assegnarli tramite
690!! il costruttore ::init.
691TYPE vol7d_var
692 CHARACTER(len=10) :: btable=cmiss !< codice della variabile secondo la tabella B del WMO.
693 CHARACTER(len=65) :: description=cmiss !< descrizione testuale della variabile (opzionale)
694 CHARACTER(len=24) :: unit=cmiss !< descrizione testuale dell'unità di misura (opzionale)
695 INTEGER :: scalefactor=imiss !< numero di decimali nella rappresentazione intera o character (opzionale)
696
697 INTEGER :: r=imiss !< indice della variabile nel volume degli attributi reali
698 INTEGER :: d=imiss !< indice della variabile nel volume degli attributi double precision
699 INTEGER :: i=imiss !< indice della variabile nel volume degli attributi integer
700 INTEGER :: b=imiss !< indice della variabile nel volume degli attributi byte
701 INTEGER :: c=imiss !< indice della variabile nel volume degli attributi character
702 INTEGER :: gribhint(4)=imiss !< hint for conversion from/to grib when btable is not found
703 INTEGER :: feat_ind=imiss !< cached index to corresponding entry in feature table
704END TYPE vol7d_var
705
706!> Valore mancante per vol7d_var.
707TYPE(vol7d_var),PARAMETER :: vol7d_var_miss= &
708 vol7d_var(cmiss,cmiss,cmiss,imiss,imiss,imiss,imiss,imiss,imiss, &
709 (/imiss,imiss,imiss,imiss/))
710
711!> Costruttore per la classe vol7d_var.
712!! Deve essere richiamato
713!! per tutti gli oggetti di questo tipo definiti in un programma.
714INTERFACE init
715 MODULE PROCEDURE vol7d_var_init
716END INTERFACE
717
718!> Distruttore per la classe vol7d_var.
719!! Distrugge l'oggetto in maniera pulita, assegnandogli un valore mancante.
720INTERFACE delete
721 MODULE PROCEDURE vol7d_var_delete
722END INTERFACE
723
724!> Operatore logico di uguaglianza tra oggetti della classe vol7d_var.
725!! Funziona anche per
726!! confronti di tipo array-array (qualsiasi n. di dimensioni) e di tipo
727!! scalare-vettore(1-d) (ma non vettore(1-d)-scalare o tra array con più
728!! di 1 dimensione e scalari).
729INTERFACE OPERATOR (==)
730 MODULE PROCEDURE vol7d_var_eq
731END INTERFACE
732
733!> Operatore logico di disuguaglianza tra oggetti della classe vol7d_var.
734!! Funziona anche per
735!! confronti di tipo array-array (qualsiasi n. di dimensioni) e di tipo
736!! scalare-vettore(1-d) (ma non vettore(1-d)-scalare o tra array con più
737!! di 1 dimensione e scalari).
738INTERFACE OPERATOR (/=)
739 MODULE PROCEDURE vol7d_var_ne, vol7d_var_nesv
740END INTERFACE
741
742!> to be documented
743INTERFACE c_e
744 MODULE PROCEDURE vol7d_var_c_e
745END INTERFACE
746
747#define VOL7D_POLY_TYPE TYPE(vol7d_var)
748#define VOL7D_POLY_TYPES _var
749#include "array_utilities_pre.F90"
750
751!> \brief display on the screen a brief content of object
752INTERFACE display
753 MODULE PROCEDURE display_var, display_var_vect
754END INTERFACE
755
756
757TYPE vol7d_var_features
758 TYPE(vol7d_var) :: var !< the variable (only btable is relevant)
759 REAL :: posdef !< if not missing, minimum physically reasonable value for the variable
760 INTEGER :: vartype !< type of variable, one of the var_* constants
761END TYPE vol7d_var_features
762
763TYPE(vol7d_var_features),ALLOCATABLE :: var_features(:)
764
765! constants for vol7d_vartype
766INTEGER,PARAMETER :: var_ord=0 !< unclassified variable (vol7d_vartype function)
767INTEGER,PARAMETER :: var_dir360=1 !< direction in degrees (vol7d_vartype function)
768INTEGER,PARAMETER :: var_press=2 !< pressure in Pa (vol7d_vartype function)
769INTEGER,PARAMETER :: var_ucomp=3 !< u component of a vector field (vol7d_vartype function)
770INTEGER,PARAMETER :: var_vcomp=4 !< v component of a vector field (vol7d_vartype function)
771INTEGER,PARAMETER :: var_wcomp=5 !< w component of a vector field (vol7d_vartype function)
772
773PRIVATE vol7d_var_features_init
774
775CONTAINS
776
777!> Inizializza un oggetto \a vol7d_var con i parametri opzionali forniti.
778!! Se non viene passato nessun parametro opzionale l'oggetto è
779!! inizializzato a valore mancante.
780!! I membri \a r, \a d, \a i, \a b, \a c non possono essere assegnati
781!! tramite costruttore, ma solo direttamente.
782elemental SUBROUTINE vol7d_var_init(this, btable, description, unit, scalefactor)
783TYPE(vol7d_var),INTENT(INOUT) :: this !< oggetto da inizializzare
784CHARACTER(len=*),INTENT(in),OPTIONAL :: btable !< codice della variabile
785CHARACTER(len=*),INTENT(in),OPTIONAL :: description !< descrizione della variabile
786CHARACTER(len=*),INTENT(in),OPTIONAL :: unit !< unità di misura
787INTEGER,INTENT(in),OPTIONAL :: scalefactor !< decimali nella rappresentazione intera e character
788
789IF (PRESENT(btable)) THEN
790 this%btable = btable
791ELSE
792 this%btable = cmiss
793 this%description = cmiss
794 this%unit = cmiss
795 this%scalefactor = imiss
796 RETURN
797ENDIF
798IF (PRESENT(description)) THEN
799 this%description = description
800ELSE
801 this%description = cmiss
802ENDIF
803IF (PRESENT(unit)) THEN
804 this%unit = unit
805ELSE
806 this%unit = cmiss
807ENDIF
808if (present(scalefactor)) then
809 this%scalefactor = scalefactor
810else
811 this%scalefactor = imiss
812endif
813
814this%r = -1
815this%d = -1
816this%i = -1
817this%b = -1
818this%c = -1
819
820END SUBROUTINE vol7d_var_init
821
822
823ELEMENTAL FUNCTION vol7d_var_new(btable, description, unit, scalefactor) RESULT(this)
824CHARACTER(len=*),INTENT(in),OPTIONAL :: btable !< codice della variabile
825CHARACTER(len=*),INTENT(in),OPTIONAL :: description !< descrizione della variabile
826CHARACTER(len=*),INTENT(in),OPTIONAL :: unit !< unità di misura
827INTEGER,INTENT(in),OPTIONAL :: scalefactor !< decimali nella rappresentazione intera e character
828
829TYPE(vol7d_var) :: this
830
831CALL init(this, btable, description, unit, scalefactor)
832
833END FUNCTION vol7d_var_new
834
835
836!> Distrugge l'oggetto in maniera pulita, assegnandogli un valore mancante.
837elemental SUBROUTINE vol7d_var_delete(this)
838TYPE(vol7d_var),INTENT(INOUT) :: this !< oggetto da distruggre
839
840this%btable = cmiss
841this%description = cmiss
842this%unit = cmiss
843this%scalefactor = imiss
844
845END SUBROUTINE vol7d_var_delete
846
847
848ELEMENTAL FUNCTION vol7d_var_eq(this, that) RESULT(res)
849TYPE(vol7d_var),INTENT(IN) :: this, that
850LOGICAL :: res
851
852res = this%btable == that%btable
853
854END FUNCTION vol7d_var_eq
855
856
857ELEMENTAL FUNCTION vol7d_var_ne(this, that) RESULT(res)
858TYPE(vol7d_var),INTENT(IN) :: this, that
859LOGICAL :: res
860
861res = .NOT.(this == that)
862
863END FUNCTION vol7d_var_ne
864
865
866FUNCTION vol7d_var_nesv(this, that) RESULT(res)
867TYPE(vol7d_var),INTENT(IN) :: this, that(:)
868LOGICAL :: res(SIZE(that))
869
870INTEGER :: i
871
872DO i = 1, SIZE(that)
873 res(i) = .NOT.(this == that(i))
874ENDDO
875
876END FUNCTION vol7d_var_nesv
877
878
879
880!> \brief display on the screen a brief content of vol7d_var object
881subroutine display_var(this)
882
883TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to display
884
885print*,"VOL7DVAR: ",this%btable,trim(this%description)," : ",this%unit,&
886 " scale factor",this%scalefactor
887
888end subroutine display_var
889
890
891!> \brief display on the screen a brief content of vector of vol7d_var object
892subroutine display_var_vect(this)
893
894TYPE(vol7d_var),INTENT(in) :: this(:) !< vol7d_var vector object to display
895integer :: i
896
897do i=1,size(this)
898 call display_var(this(i))
899end do
900
901end subroutine display_var_vect
902
903FUNCTION vol7d_var_c_e(this) RESULT(c_e)
904TYPE(vol7d_var),INTENT(IN) :: this
905LOGICAL :: c_e
906c_e = this /= vol7d_var_miss
907END FUNCTION vol7d_var_c_e
908
909
910SUBROUTINE vol7d_var_features_set(this)
911TYPE(vol7d_var),INTENT(inout) :: this
912INTEGER :: i
913
914CALL vol7d_var_features_init()
915
916IF (ALLOCATED(var_features)) THEN
917 DO i = 1, SIZE(var_features)
918 IF (this == var_features(i)%var) THEN
919 this%feat_ind = i
920 EXIT
921 ENDIF
922 ENDDO
923ENDIF
924
925END SUBROUTINE vol7d_var_features_set
926
927
928!> Initialise the global table of variable features.
929!! This subroutine reads the table of variable features from an
930!! external file and stores it in a global array. It has to be called
931!! once at the beginning of the program. At the moment it gives access
932!! to the information about type of variable and positive
933!! definitness. The table is based on the unique bufr-like variable
934!! table. The table is contained in the csv file `vargrib.csv`.
935!! It is not harmful to call this subroutine multiple times.
936SUBROUTINE vol7d_var_features_init()
937INTEGER :: un, i, n
938TYPE(csv_record) :: csv
939CHARACTER(len=1024) :: line
940
941IF (ALLOCATED(var_features)) RETURN
942
943un = open_package_file('varbufr.csv', filetype_data)
944n=0
945DO WHILE(.true.)
946 READ(un,*,END=100)
947 n = n + 1
948ENDDO
949
950100 CONTINUE
951
952rewind(un)
953ALLOCATE(var_features(n))
954
955DO i = 1, n
956 READ(un,'(A)',END=200)line
957 CALL init(csv, line)
958 CALL csv_record_getfield(csv, var_features(i)%var%btable)
959 CALL csv_record_getfield(csv)
960 CALL csv_record_getfield(csv)
961 CALL csv_record_getfield(csv, var_features(i)%posdef)
962 CALL csv_record_getfield(csv, var_features(i)%vartype)
963 CALL delete(csv)
964ENDDO
965
966200 CONTINUE
967CLOSE(un)
968
969END SUBROUTINE vol7d_var_features_init
970
971
972!> Deallocate the global table of variable features.
973!! This subroutine deallocates the table of variable features
974!! allocated in the `vol7d_var_features_init` subroutine.
975SUBROUTINE vol7d_var_features_delete()
976IF (ALLOCATED(var_features)) DEALLOCATE(var_features)
977END SUBROUTINE vol7d_var_features_delete
978
979
980!> Return the physical type of the variable.
981!! Returns a rough classification of the variable depending on the
982!! physical parameter it represents. The result is one of the
983!! constants vartype_* defined in the module. To be extended.
984!! In order for this to work, the subroutine \a
985!! vol7d_var_features_set has to be preliminary called.
986ELEMENTAL FUNCTION vol7d_var_features_vartype(this) RESULT(vartype)
987TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be tested
988INTEGER :: vartype
989
990IF (c_e(this%feat_ind)) THEN
991 vartype = var_features(this%feat_ind)%vartype
992ELSE
993 vartype = imiss
994ENDIF
995
996END FUNCTION vol7d_var_features_vartype
997
998
999!> Apply a positive definite flag to a variable.
1000!! This subroutine resets the value of a variable depending on its
1001!! positive definite flag defined in the associated \a c_func object.
1002!! The \a c_func object can be obtained for example by the \a convert
1003!! (interfaced to vargrib2varbufr_convert) function. The value is
1004!! reset to the maximum between the value itself and and 0 (or the
1005!! value set in \a c_func%posdef. These values are set from the
1006!! varbufr.csv file.
1007!! In order for this to work, the subroutine \a
1008!! vol7d_var_features_set has to be preliminary called.
1009ELEMENTAL SUBROUTINE vol7d_var_features_posdef_apply(this, val)
1010TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be reset
1011REAL,INTENT(inout) :: val !< value to be reset, it is reset in place
1012
1013IF (c_e(this%feat_ind)) THEN
1014 IF (c_e(var_features(this%feat_ind)%posdef)) THEN
1015 IF (c_e(val)) THEN
1016 val = max(var_features(this%feat_ind)%posdef, val)
1017 ENDIF
1018 ENDIF
1019ENDIF
1020
1021END SUBROUTINE vol7d_var_features_posdef_apply
1022
1023
1024!> Return the physical type of the variable.
1025!! Returns a rough classification of the variable depending on the
1026!! physical parameter it represents. The result is one of the
1027!! constants vartype_* defined in the module. To be extended.
1028ELEMENTAL FUNCTION vol7d_vartype(this) RESULT(vartype)
1029TYPE(vol7d_var),INTENT(in) :: this !< vol7d_var object to be tested
1030
1031INTEGER :: vartype
1032
1033vartype = var_ord
1034SELECT CASE(this%btable)
1035CASE('B01012', 'B11001', 'B11043', 'B22001') ! direction, degree true
1036 vartype = var_dir360
1037CASE('B07004', 'B10004', 'B10051', 'B10060') ! pressure, Pa
1038 vartype = var_press
1039CASE('B11003', 'B11200') ! u-component
1040 vartype = var_ucomp
1041CASE('B11004', 'B11201') ! v-component
1042 vartype = var_vcomp
1043CASE('B11005', 'B11006') ! w-component
1044 vartype = var_wcomp
1045END SELECT
1046
1047END FUNCTION vol7d_vartype
1048
1049
1050#include "array_utilities_inc.F90"
1051
1052
1053END 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.