Skip to content

Commit

Permalink
improve doc and implement percentile also for boxregrid
Browse files Browse the repository at this point in the history
  • Loading branch information
dcesari committed Feb 5, 2018
1 parent 56ae706 commit c9b1c10
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 34 deletions.
9 changes: 5 additions & 4 deletions bin/vg6d_transform.F90
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,23 @@ PROGRAM vg6d_transform

CALL optionparser_add(opt, 'v', 'trans-type', trans_type, 'none', help= &
'transformation type: ''inter'' for interpolation, ''boxinter'' for &
&statistical interpolation on boxes, ''zoom'' for zooming, &
&statistical interpolation on boxes, ''stencilinter'' for statistical interpolation &
&on a circular stencil, ''zoom'' for zooming, &
&''boxregrid'' for resolution reduction, ''metamorphosis'' for &
&keeping the same grid but changing e.g. the component flag, '&
#ifdef HAVE_SHAPELIB
//'maskgen for generating a mask field on polygons, polyinter for intepolating &
//'''maskgen'' for generating a mask field on polygons, ''polyinter'' for intepolating &
&on polygons, '&
#endif
//'''none'' for no transformation (input/output only)')
sub_type = ''
CALL optionparser_add(opt, 'z', 'sub-type', sub_type, help= &
'transformation subtype, for inter: ''near'', ''bilin'', &
&for boxinter, boxregrid'&
&for boxinter, stencilinter, boxregrid'&
#ifdef HAVE_SHAPELIB
//', polyinter'&
#endif
//': ''average'', ''stddev'', ''max'', ''min'', ''percentile'', &
//': ''average'', ''stddev'', ''stddevnm1'', ''max'', ''min'', ''percentile'', &
&for zoom: ''index'', ''coord'', ''coordbb'', ''projcoord'', '&
#ifdef HAVE_SHAPELIB
//'for maskgen: ''poly'', '&
Expand Down
77 changes: 47 additions & 30 deletions volgrid6d/grid_transform_class.F90
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@
!! (grid-to-grid)
!! - sub_type='average' the function used is the average.
!! - sub_type='stddev' the function used is the standard deviation.
!! - sub_type='stddevnm1' the function used is the standard
!! deviation computed with n-1.
!! - sub_type='max' the function used is the maximum
!! - sub_type='min' the function used is the minimum
!! - sub_type='percentile' the function used is a requested
!! percentile of the input points distribution.
!!
!! - trans_type='inter' interpolates the input data on a new set of
!! specified points
Expand All @@ -87,6 +91,8 @@
!! (grid-to-grid and sparse points-to-grid)
!! - sub_type='average' the function used is the average
!! - sub_type='stddev' the function used is the standard deviation.
!! - sub_type='stddevnm1' the function used is the standard
!! deviation computed with n-1.
!! - sub_type='max' the function used is the maximum
!! - sub_type='min' the function used is the minimum
!! - sub_type='percentile' the function used is a requested
Expand Down Expand Up @@ -116,6 +122,9 @@
!! radius in input grid point units; stencils can overlap each
!! other (grid-to-grid and grid-to-sparse points)
!! - sub_type='average' the function used is the average
!! - sub_type='stddev' the function used is the standard deviation.
!! - sub_type='stddevnm1' the function used is the standard
!! deviation computed with n-1.
!! - sub_type='max' the function used is the maximum
!! - sub_type='min' the function used is the minimum
!! - sub_type='percentile' the function used is a requested
Expand All @@ -133,6 +142,8 @@
!! subareas (grid-to-sparse points)
!! - sub_type='average' the function used is the average
!! - sub_type='stddev' the function used is the standard deviation.
!! - sub_type='stddevnm1' the function used is the standard
!! deviation computed with n-1.
!! - sub_type='max' the function used is the maximum
!! - sub_type='min' the function used is the minimum
!! - sub_type='percentile' the function used is a requested
Expand Down Expand Up @@ -512,33 +523,6 @@ SUBROUTINE transform_init(this, trans_type, sub_type, &
RETURN
END IF

ELSE IF (this%trans_type == 'boxregrid') THEN

IF (c_e(this%box_info%npx) .AND. c_e(this%box_info%npy)) THEN

IF (this%box_info%npx <= 0 .OR. this%box_info%npy <= 0 ) THEN
CALL l4f_category_log(this%category,L4F_ERROR,'invalid regrid parameters: '//&
TRIM(to_char(this%box_info%npx))//' '//TRIM(to_char(this%box_info%npy)))
CALL raise_fatal_error()
ENDIF

ELSE

CALL l4f_category_log(this%category,L4F_ERROR, &
'boxregrid parameters npx, npy not provided')
CALL raise_fatal_error()

ENDIF

IF (this%sub_type == 'average' .OR. this%sub_type == 'max' .OR. &
this%sub_type == 'min' .OR. this%sub_type == 'stddev' &
.OR. this%sub_type == 'stddevnm1') THEN
! nothing to do here
ELSE
CALL sub_type_error()
RETURN
ENDIF

ELSE IF (this%trans_type == 'inter') THEN

IF (this%sub_type == 'near' .OR. this%sub_type == 'bilin' .OR. &
Expand All @@ -549,8 +533,22 @@ SUBROUTINE transform_init(this, trans_type, sub_type, &
RETURN
ENDIF

ELSE IF (this%trans_type == 'boxinter' .OR. this%trans_type == 'polyinter' &
.OR. this%trans_type == 'maskinter' .OR. this%trans_type == 'stencilinter') THEN
ELSE IF (this%trans_type == 'boxregrid' .OR. this%trans_type == 'boxinter' &
.OR. this%trans_type == 'polyinter' .OR. this%trans_type == 'stencilinter') THEN

IF (this%trans_type == 'boxregrid') THEN
IF (c_e(this%box_info%npx) .AND. c_e(this%box_info%npy)) THEN
IF (this%box_info%npx <= 0 .OR. this%box_info%npy <= 0 ) THEN
CALL l4f_category_log(this%category,L4F_ERROR,'boxregrid: invalid parameters '//&
TRIM(to_char(this%box_info%npx))//' '//TRIM(to_char(this%box_info%npy)))
CALL raise_fatal_error()
ENDIF
ELSE
CALL l4f_category_log(this%category,L4F_ERROR, &
'boxregrid: parameters npx, npy missing')
CALL raise_fatal_error()
ENDIF
ENDIF

IF (this%trans_type == 'polyinter') THEN
IF (this%poly%arraysize <= 0) THEN
Expand Down Expand Up @@ -2814,7 +2812,26 @@ RECURSIVE SUBROUTINE grid_transform_compute(this, field_in, field_out, var, &
ENDDO
ENDDO

ENDIF
ELSE IF (this%trans%sub_type == 'percentile') THEN

navg = this%trans%box_info%npx*this%trans%box_info%npy
DO k = 1, innz
jj = 0
DO j = 1, this%inny - this%trans%box_info%npy + 1, this%trans%box_info%npy
je = j+this%trans%box_info%npy-1
jj = jj+1
ii = 0
DO i = 1, this%innx - this%trans%box_info%npx + 1, this%trans%box_info%npx
ie = i+this%trans%box_info%npx-1
ii = ii+1
field_out(ii:ii,jj,k) = stat_percentile( &
RESHAPE(field_in(i:ie,j:je,k),(/navg/)), &
(/REAL(this%trans%stat_info%percentile)/))
ENDDO
ENDDO
ENDDO

ENDIF

ELSE IF (this%trans%trans_type == 'inter') THEN

Expand Down

0 comments on commit c9b1c10

Please sign in to comment.