libsim  Versione 7.1.6

◆ vol7d_compute_stat_proc_agg()

subroutine vol7d_class_compute::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 677 del file vol7d_class_compute.F90.

679  CALL compute_stat_proc_agg_sw(map_ttr(i,j)%array(1:ninp)%time, &
680  pstart, pend, lin_mask(1:ninp), act_max_step)
681  ENDIF
682  IF (act_max_step > lmax_step) cycle
683 
684  SELECT CASE(stat_proc)
685  CASE (0) ! average
686  IF (lweighted) THEN
687  that%voldatid(i1,i,i3,j,i5,i6) = &
688  sum(real(weights(1:ndtr))*tmpvold(1:ndtr))
689  ELSE
690  that%voldatid(i1,i,i3,j,i5,i6) = &
691  sum(tmpvold(1:ndtr))/ndtr
692  ENDIF
693  CASE (2) ! maximum
694  that%voldatid(i1,i,i3,j,i5,i6) = &
695  maxval(tmpvold(1:ndtr))
696  CASE (3) ! minimum
697  that%voldatid(i1,i,i3,j,i5,i6) = &
698  minval(tmpvold(1:ndtr))
699  CASE (6) ! stddev
700  that%voldatid(i1,i,i3,j,i5,i6) = &
701  stat_stddev(tmpvold(1:ndtr))
702  CASE (201) ! mode
703 ! mode only for angles at the moment, with predefined histogram
704  IF (vartype == var_dir360) THEN
705 ! remove undefined wind direction (=0), improve check?
706 ! and reduce to interval [22.5,382.5[
707  WHERE (tmpvold(1:ndtr) == 0.0d0)
708  tmpvold(1:ndtr) = dmiss
709  ELSE WHERE (tmpvold(1:ndtr) < 22.5d0 .AND. tmpvold(1:ndtr) > 0.0d0)
710  tmpvold(1:ndtr) = tmpvold(1:ndtr) + 360.0d0
711  END WHERE
712  that%voldatid(i1,i,i3,j,i5,i6) = &
713  stat_mode_histogram(tmpvold(1:ndtr), &
714  8, 22.5d0, 382.5d0)
715  ENDIF
716  END SELECT
717  ENDDO
718  ENDDO
719  ENDDO
720  ENDDO
721  ENDIF
722 
723  CALL delete(map_ttr(i,j))
724  ENDDO do_otime
725 ENDDO do_otimerange
726 
727 DEALLOCATE(map_ttr)
728 DEALLOCATE(tmpvolr, tmpvold, lin_mask, weights)
729 
730 IF (PRESENT(other)) THEN ! create volume with the remaining data for further processing
731  CALL vol7d_copy(this, other, miss=.false., sort=.false., unique=.false., &
732  ltimerange=(this%timerange(:)%timerange /= tri))
733 ENDIF
734 
735 END SUBROUTINE vol7d_compute_stat_proc_agg
736 
737 
753 SUBROUTINE vol7d_decompute_stat_proc(this, that, step, other, stat_proc_input)
754 TYPE(vol7d),INTENT(inout) :: this
755 TYPE(vol7d),INTENT(out) :: that
756 TYPE(timedelta),INTENT(in) :: step
757 TYPE(vol7d),INTENT(inout),OPTIONAL :: other
758 INTEGER,INTENT(in),OPTIONAL :: stat_proc_input
759 
760 INTEGER :: i, tri, steps
761 
762 
763 IF (PRESENT(stat_proc_input)) THEN
764  tri = stat_proc_input
765 ELSE
766  tri = 0
767 ENDIF
768 ! be safe
769 CALL vol7d_alloc_vol(this)
770 
771 ! compute length of cumulation step in seconds
772 CALL getval(step, asec=steps)
773 
774 ! filter requested data
775 CALL vol7d_copy(this, that, miss=.false., sort=.false., unique=.false., &
776  ltimerange=(this%timerange(:)%timerange == tri .AND. &
777  this%timerange(:)%p1 == 0 .AND. this%timerange(:)%p2 == steps))
778 
779 ! convert timerange to instantaneous and go back half step in time
780 that%timerange(:)%timerange = 254
781 that%timerange(:)%p2 = 0
782 DO i = 1, SIZE(that%time(:))
783  that%time(i) = that%time(i) - step/2
784 ENDDO
785 
786 IF (PRESENT(other)) THEN ! create volume with the remaining data for further processing
787  CALL vol7d_copy(this, other, miss=.false., sort=.false., unique=.false., &
788  ltimerange=(this%timerange(:)%timerange /= tri .OR. &
789  this%timerange(:)%p1 /= 0 .OR. this%timerange(:)%p2 /= steps))
790 ENDIF
791 
792 END SUBROUTINE vol7d_decompute_stat_proc
793 
794 
821 SUBROUTINE vol7d_recompute_stat_proc_diff(this, that, stat_proc, step, full_steps, other)
822 TYPE(vol7d),INTENT(inout) :: this
823 TYPE(vol7d),INTENT(out) :: that
824 INTEGER,INTENT(in) :: stat_proc
825 TYPE(timedelta),INTENT(in) :: step
826 LOGICAL,INTENT(in),OPTIONAL :: full_steps
827 TYPE(vol7d),INTENT(out),OPTIONAL :: other
828 
829 INTEGER :: i1, i3, i5, i6, i, j, k, l, nitr, steps
830 INTEGER,ALLOCATABLE :: map_tr(:,:,:,:,:), f(:), keep_tr(:,:,:)
831 LOGICAL,ALLOCATABLE :: mask_timerange(:)
832 LOGICAL,ALLOCATABLE :: mask_time(:)
833 TYPE(vol7d) :: v7dtmp
834 
835 
836 ! be safe
837 CALL vol7d_alloc_vol(this)
838 ! initialise the template of the output volume
839 CALL init(that, time_definition=this%time_definition)
840 
841 ! compute length of cumulation step in seconds
842 CALL getval(step, asec=steps)
843 
844 ! compute the statistical processing relations, output time and
845 ! timerange are defined here
846 CALL recompute_stat_proc_diff_common(this%time, this%timerange, stat_proc, step, &
847  that%time, that%timerange, map_tr, f, keep_tr, &
848  this%time_definition, full_steps)
849 nitr = SIZE(f)
850 
851 ! complete the definition of the empty output template
852 CALL vol7d_alloc(that, nana=0, nlevel=0, nnetwork=0)
853 CALL vol7d_alloc_vol(that)
854 ! shouldn't we exit here with an empty volume if stat_proc/=0,1 ?
855 ALLOCATE(mask_time(SIZE(this%time)), mask_timerange(SIZE(this%timerange)))
856 DO l = 1, SIZE(this%time)
857  mask_time(l) = any(this%time(l) == that%time(:))
858 ENDDO
859 DO l = 1, SIZE(this%timerange)
860  mask_timerange(l) = any(this%timerange(l) == that%timerange(:))
861 ENDDO
862 ! create template for the output volume, keep all ana, level, network
863 ! and variables; copy only the timeranges already satisfying the
864 ! requested step, if any and only the times already existing in the
865 ! output
866 CALL vol7d_copy(this, v7dtmp, miss=.false., sort=.false., unique=.false., &
867  ltimerange=mask_timerange(:), ltime=mask_time(:))
868 ! merge output created so far with template
869 CALL vol7d_merge(that, v7dtmp, lanasimple=.true., llevelsimple=.true.)
870 
871 ! compute statistical processing
872 IF (ASSOCIATED(this%voldatir)) THEN
873  DO l = 1, SIZE(this%time)
874  DO k = 1, nitr
875  DO j = 1, SIZE(this%time)
876  DO i = 1, nitr
877  IF (c_e(map_tr(i,j,k,l,1))) THEN
878  DO i6 = 1, SIZE(this%network)
879  DO i5 = 1, SIZE(this%dativar%r)
880  DO i3 = 1, SIZE(this%level)
881  DO i1 = 1, SIZE(this%ana)
882  IF (c_e(this%voldatir(i1,l,i3,f(k),i5,i6)) .AND. &
883  c_e(this%voldatir(i1,j,i3,f(i),i5,i6))) THEN
884 
885  IF (stat_proc == 0) THEN ! average
886  that%voldatir( &
887  i1,map_tr(i,j,k,l,1),i3,map_tr(i,j,k,l,2),i5,i6) = &
888  (this%voldatir(i1,l,i3,f(k),i5,i6)*this%timerange(f(k))%p2 - &
889  this%voldatir(i1,j,i3,f(i),i5,i6)*this%timerange(f(i))%p2)/ &
890  steps ! optimize avoiding conversions
891  ELSE IF (stat_proc == 1 .OR. stat_proc == 4) THEN ! acc, diff
892  that%voldatir( &
893  i1,map_tr(i,j,k,l,1),i3,map_tr(i,j,k,l,2),i5,i6) = &
894  this%voldatir(i1,l,i3,f(k),i5,i6) - &
895  this%voldatir(i1,j,i3,f(i),i5,i6)
896  ENDIF
897 
898  ENDIF
899  ENDDO
900  ENDDO
901  ENDDO
902  ENDDO
903  ENDIF
904  ENDDO
905  ENDDO
906  ENDDO
907  ENDDO
908 ENDIF
909 
910 IF (ASSOCIATED(this%voldatid)) THEN
911  DO l = 1, SIZE(this%time)
912  DO k = 1, nitr
913  DO j = 1, SIZE(this%time)
914  DO i = 1, nitr
915  IF (c_e(map_tr(i,j,k,l,1))) THEN
916  DO i6 = 1, SIZE(this%network)
917  DO i5 = 1, SIZE(this%dativar%d)
918  DO i3 = 1, SIZE(this%level)
919  DO i1 = 1, SIZE(this%ana)
920  IF (c_e(this%voldatid(i1,l,i3,f(k),i5,i6)) .AND. &
921  c_e(this%voldatid(i1,j,i3,f(i),i5,i6))) THEN
922 ! IF (.NOT.c_e(that%voldatid( &
923 ! i1,map_tr(i,j,k,l,1),i3,map_tr(i,j,k,l,2),i5,i6))) THEN
924 
925  IF (stat_proc == 0) THEN ! average
926  that%voldatid( &
927  i1,map_tr(i,j,k,l,1),i3,map_tr(i,j,k,l,2),i5,i6) = &
928  (this%voldatid(i1,l,i3,f(k),i5,i6)*this%timerange(f(k))%p2 - &

Generated with Doxygen.