libsim Versione 7.2.6

◆ vol7d_compute_stat_proc_agg()

subroutine vol7d_compute_stat_proc_agg ( type(vol7d), intent(inout) this,
type(vol7d), intent(out) that,
integer, intent(in) stat_proc,
type(timedelta), intent(in) step,
type(datetime), intent(in), optional start,
logical, intent(in), optional full_steps,
type(timedelta), intent(in), optional max_step,
logical, intent(in), optional weighted,
type(vol7d), intent(inout), optional other )

Method for statistically processing a set of instantaneous data.

This method performs statistical processing by aggregation of instantaneous data. Only floating point single or double precision data are processed.

The output that vol7d object contains elements from the original volume this satisfying the conditions

Output data will have timerange of type stat_proc, and p2 = step. The supported statistical processing methods (parameter stat_proc) are:

  • 0 average
  • 2 maximum
  • 3 minimum
  • 4 difference
  • 6 standard deviation
  • 201 mode (only for wind direction sectors)

In the case of average, it is possible to weigh the data proportionally to the length of the time interval for which every single value is valid, i.e. halfway between the time level of the value itself and the time of its nearest valid neighbours (argument weighted). A maximum distance in time for input valid data can be assigned with the optional argument max_step, in order to filter datasets with too long "holes".

Parametri
[in,out]thisvolume providing data to be computed, it is not modified by the method, apart from performing a vol7d_alloc_vol on it
[out]thatoutput volume which will contain the computed data
[in]stat_proctype of statistical processing to be computed (from grib2 table)
[in]steplength of the step over which the statistical processing is performed
[in]startstart of statistical processing interval
[in]full_stepsif .TRUE. and start is not provided, apply processing only on intervals starting at a forecast time or a reference time modulo step
[in]max_stepmaximum allowed distance in time between two contiguougs valid data within an interval, for the interval to be eligible for statistical processing
[in]weightedif provided and .TRUE., the statistical process is computed, if possible, by weighting every value with a weight proportional to its validity interval
[in,out]otheroptional volume that, on exit, is going to contain the data that did not contribute to the accumulation computation

Definizione alla linea 672 del file vol7d_class_compute.F90.

674 ENDDO
675 IF (ndtr == 0) cycle
676 IF (lweighted) THEN
677 CALL compute_stat_proc_agg_sw(map_ttr(i,j)%array(1:ninp)%time, &
678 pstart, pend, lin_mask(1:ninp), act_max_step, weights)
679 ELSE
680 CALL compute_stat_proc_agg_sw(map_ttr(i,j)%array(1:ninp)%time, &
681 pstart, pend, lin_mask(1:ninp), act_max_step)
682 ENDIF
683 IF (act_max_step > lmax_step) cycle
684
685 SELECT CASE(stat_proc)
686 CASE (0) ! average
687 IF (lweighted) THEN
688 that%voldatid(i1,i,i3,j,i5,i6) = &
689 sum(real(weights(1:ndtr))*tmpvold(1:ndtr))
690 ELSE
691 that%voldatid(i1,i,i3,j,i5,i6) = &
692 sum(tmpvold(1:ndtr))/ndtr
693 ENDIF
694 CASE (2) ! maximum
695 that%voldatid(i1,i,i3,j,i5,i6) = &
696 maxval(tmpvold(1:ndtr))
697 CASE (3) ! minimum
698 that%voldatid(i1,i,i3,j,i5,i6) = &
699 minval(tmpvold(1:ndtr))
700 CASE (6) ! stddev
701 that%voldatid(i1,i,i3,j,i5,i6) = &
702 stat_stddev(tmpvold(1:ndtr))
703 CASE (201) ! mode
704! mode only for angles at the moment, with predefined histogram
705 IF (vartype == var_dir360) THEN
706! remove undefined wind direction (=0), improve check?
707! and reduce to interval [22.5,382.5[
708 WHERE (tmpvold(1:ndtr) == 0.0d0)
709 tmpvold(1:ndtr) = dmiss
710 ELSE WHERE (tmpvold(1:ndtr) < 22.5d0 .AND. tmpvold(1:ndtr) > 0.0d0)
711 tmpvold(1:ndtr) = tmpvold(1:ndtr) + 360.0d0
712 END WHERE
713 that%voldatid(i1,i,i3,j,i5,i6) = &
714 stat_mode_histogram(tmpvold(1:ndtr), &
715 8, 22.5d0, 382.5d0)
716 ENDIF
717 END SELECT
718 ENDDO
719 ENDDO
720 ENDDO
721 ENDDO
722 ENDIF
723
724 CALL delete(map_ttr(i,j))
725 ENDDO do_otime
726ENDDO do_otimerange
727
728DEALLOCATE(map_ttr)
729DEALLOCATE(tmpvolr, tmpvold, lin_mask, weights)
730
731IF (PRESENT(other)) THEN ! create volume with the remaining data for further processing
732 CALL vol7d_copy(this, other, miss=.false., sort=.false., unique=.false., &
733 ltimerange=(this%timerange(:)%timerange /= tri))
734ENDIF
735
736END SUBROUTINE vol7d_compute_stat_proc_agg
737
738
739!> Method to transform the timerange of a set of data from
740!! statistically processed to instantaneous. The data does not change,
741!! only time and timerange descriptors change.
742!!
743!! The output \a that vol7d object contains elements from the original volume
744!! \a this satisfying the conditions
745!! - real single or double precision variables
746!! - timerange (vol7d_timerange_class::vol7d_timerange::timerange)
747!! of type 0 (average) or \a stat_proc_input if provided
748!! - p1 = 0 (end of period == reference time, analysis/observation)
749!! - p2 == \a step
750!!
751!! Output data will have timerange 254, p1 = 0 and p2 = 0; the time
752!! dimension is shifted by half \a step so that it coincides with the
753!! mid point of the input statistical processing interval.
754SUBROUTINE vol7d_decompute_stat_proc(this, that, step, other, stat_proc_input)
755TYPE(vol7d),INTENT(inout) :: this !< volume providing data to be recomputed, it is not modified by the method, apart from performing a \a vol7d_alloc_vol on it
756TYPE(vol7d),INTENT(out) :: that !< output volume which will contain the recomputed data
757TYPE(timedelta),INTENT(in) :: step !< length of the step over which the statistical processing is performed
758TYPE(vol7d),INTENT(inout),OPTIONAL :: other !< optional volume that, on exit, is going to contain the data that did not contribute to the statistical processing
759INTEGER,INTENT(in),OPTIONAL :: stat_proc_input !< type of statistical processing of data that has to be processed (from grib2 table), if not provided, averaged data (statistical processing = 0) is processed
760
761INTEGER :: i, tri, steps
762
763
764IF (PRESENT(stat_proc_input)) THEN
765 tri = stat_proc_input
766ELSE
767 tri = 0
768ENDIF
769! be safe
770CALL vol7d_alloc_vol(this)
771
772! compute length of cumulation step in seconds
773CALL getval(step, asec=steps)
774
775! filter requested data
776CALL vol7d_copy(this, that, miss=.FALSE., sort=.FALSE., unique=.FALSE., &
777 ltimerange=(this%timerange(:)%timerange == tri .AND. &
778 this%timerange(:)%p1 == 0 .AND. this%timerange(:)%p2 == steps))
779
780! convert timerange to instantaneous and go back half step in time
781that%timerange(:)%timerange = 254
782that%timerange(:)%p2 = 0
783DO i = 1, SIZE(that%time(:))
784 that%time(i) = that%time(i) - step/2
785ENDDO
786
787IF (PRESENT(other)) THEN ! create volume with the remaining data for further processing
788 CALL vol7d_copy(this, other, miss=.false., sort=.false., unique=.false., &
789 ltimerange=(this%timerange(:)%timerange /= tri .OR. &
790 this%timerange(:)%p1 /= 0 .OR. this%timerange(:)%p2 /= steps))
791ENDIF
792
793END SUBROUTINE vol7d_decompute_stat_proc
794
795
796!> Specialized method for statistically processing a set of data
797!! already processed with the same statistical processing, on a
798!! different time interval. This method performs statistical
799!! processing by difference of different intervals. Only floating
800!! point single or double precision data with analysis/observation
801!! or forecast timerange are processed.
802!!
803!! The output \a that vol7d object contains elements from the original volume
804!! \a this satisfying the conditions
805!! - real single or double precision variables
806!! - timerange (vol7d_timerange_class::vol7d_timerange::timerange)
807!! of type \a stat_proc
808!! - any p1 (analysis/observation or forecast)
809!! - p2 &gt; 0 (processing interval non null, non instantaneous data)
810!! and equal to a multiplier of \a step if \a full_steps is \c .TRUE.
811!!
812!! Output data will have timerange of type \a stat_proc and p2 = \a
813!! step. The supported statistical processing methods (parameter \a
814!! stat_proc) are:
815!!
816!! - 0 average
817!! - 1 cumulation
818!! - 4 difference
819!!
820!! Input volume may have any value of \a this%time_definition, and
821!! that value will be conserved in the output volume.
822SUBROUTINE vol7d_recompute_stat_proc_diff(this, that, stat_proc, step, full_steps, start, other)
823TYPE(vol7d),INTENT(inout) :: this !< volume providing data to be recomputed, it is not modified by the method, apart from performing a \a vol7d_alloc_vol on it
824TYPE(vol7d),INTENT(out) :: that !< output volume which will contain the recomputed data
825INTEGER,INTENT(in) :: stat_proc !< type of statistical processing to be recomputed (from grib2 table), only data having timerange of this type will be recomputed and will appear in the output volume
826TYPE(timedelta),INTENT(in) :: step !< length of the step over which the statistical processing is performed
827LOGICAL,INTENT(in),OPTIONAL :: full_steps !< if provided and \a .TRUE., process only data having processing interval (p2) equal to a multiplier of \a step
828TYPE(datetime),INTENT(in),OPTIONAL :: start !< start of statistical processing interval
829TYPE(vol7d),INTENT(out),OPTIONAL :: other !< optional volume that, on exit, is going to contain the data that did not contribute to the statistical processing
830
831INTEGER :: i1, i3, i5, i6, i, j, k, l, nitr, steps
832INTEGER,ALLOCATABLE :: map_tr(:,:,:,:,:), f(:), keep_tr(:,:,:)
833LOGICAL,ALLOCATABLE :: mask_timerange(:)
834LOGICAL,ALLOCATABLE :: mask_time(:)
835TYPE(vol7d) :: v7dtmp
836
837
838! be safe
839CALL vol7d_alloc_vol(this)
840! initialise the template of the output volume
841CALL init(that, time_definition=this%time_definition)
842
843! compute length of cumulation step in seconds
844CALL getval(step, asec=steps)
845
846! compute the statistical processing relations, output time and
847! timerange are defined here
848CALL recompute_stat_proc_diff_common(this%time, this%timerange, stat_proc, step, &
849 that%time, that%timerange, map_tr, f, keep_tr, &
850 this%time_definition, full_steps, start)
851nitr = SIZE(f)
852
853! complete the definition of the empty output template
854CALL vol7d_alloc(that, nana=0, nlevel=0, nnetwork=0)
855CALL vol7d_alloc_vol(that)
856! shouldn't we exit here with an empty volume if stat_proc/=0,1 ?
857ALLOCATE(mask_time(SIZE(this%time)), mask_timerange(SIZE(this%timerange)))
858DO l = 1, SIZE(this%time)
859 mask_time(l) = any(this%time(l) == that%time(:))
860ENDDO
861DO l = 1, SIZE(this%timerange)
862 mask_timerange(l) = any(this%timerange(l) == that%timerange(:))
863ENDDO
864! create template for the output volume, keep all ana, level, network
865! and variables; copy only the timeranges already satisfying the
866! requested step, if any and only the times already existing in the
867! output
868CALL vol7d_copy(this, v7dtmp, miss=.FALSE., sort=.FALSE., unique=.FALSE., &
869 ltimerange=mask_timerange(:), ltime=mask_time(:))
870! merge output created so far with template
871CALL vol7d_merge(that, v7dtmp, lanasimple=.TRUE., llevelsimple=.TRUE.)
872
873! compute statistical processing
874IF (ASSOCIATED(this%voldatir)) THEN
875 DO l = 1, SIZE(this%time)
876 DO k = 1, nitr
877 DO j = 1, SIZE(this%time)
878 DO i = 1, nitr
879 IF (c_e(map_tr(i,j,k,l,1))) THEN
880 DO i6 = 1, SIZE(this%network)
881 DO i5 = 1, SIZE(this%dativar%r)
882 DO i3 = 1, SIZE(this%level)
883 DO i1 = 1, SIZE(this%ana)
884 IF (c_e(this%voldatir(i1,l,i3,f(k),i5,i6)) .AND. &
885 c_e(this%voldatir(i1,j,i3,f(i),i5,i6))) THEN
886
887 IF (stat_proc == 0) THEN ! average
888 that%voldatir( &
889 i1,map_tr(i,j,k,l,1),i3,map_tr(i,j,k,l,2),i5,i6) = &
890 (this%voldatir(i1,l,i3,f(k),i5,i6)*this%timerange(f(k))%p2 - &
891 this%voldatir(i1,j,i3,f(i),i5,i6)*this%timerange(f(i))%p2)/ &
892 steps ! optimize avoiding conversions
893 ELSE IF (stat_proc == 1 .OR. stat_proc == 4) THEN ! acc, diff
894 that%voldatir( &
895 i1,map_tr(i,j,k,l,1),i3,map_tr(i,j,k,l,2),i5,i6) = &
896 this%voldatir(i1,l,i3,f(k),i5,i6) - &
897 this%voldatir(i1,j,i3,f(i),i5,i6)
898 ENDIF
899
900 ENDIF
901 ENDDO
902 ENDDO
903 ENDDO
904 ENDDO
905 ENDIF
906 ENDDO
907 ENDDO
908 ENDDO
909 ENDDO
910ENDIF
911
912IF (ASSOCIATED(this%voldatid)) THEN
913 DO l = 1, SIZE(this%time)
914 DO k = 1, nitr
915 DO j = 1, SIZE(this%time)
916 DO i = 1, nitr
917 IF (c_e(map_tr(i,j,k,l,1))) THEN
918 DO i6 = 1, SIZE(this%network)
919 DO i5 = 1, SIZE(this%dativar%d)
920 DO i3 = 1, SIZE(this%level)
921 DO i1 = 1, SIZE(this%ana)
922 IF (c_e(this%voldatid(i1,l,i3,f(k),i5,i6)) .AND. &
923 c_e(this%voldatid(i1,j,i3,f(i),i5,i6))) THEN

Generated with Doxygen.