libsim Versione 8.0.0

◆ grid_transform_vol7d_vol7d_init()

subroutine grid_transform_vol7d_vol7d_init ( type(grid_transform), intent(out) this,
type(transform_def), intent(in) trans,
type(vol7d), intent(in) v7d_in,
type(vol7d), intent(inout) v7d_out,
real, dimension(:), intent(in), optional maskbounds,
character(len=*), intent(in), optional categoryappend )
private

Constructor for a grid_transform object, defining a particular sparse points-to-sparse points transformation.

It defines an object describing a transformation from a set of sparse points to a set of sparse points; the abstract type of transformation is described in the transformation object trans (type transform_def) which must have been properly initialised. The additional information required here is the list of the input sparse points in the form of a vol7d object (parameter v7d_in), which can be the same volume that will be successively used for interpolation, or a volume with just the same coordinate data, and, if required by the transformation type, the information about the target sparse points over which the transformation should take place:

  • for 'inter' transformation, this is provided in the form of a vol7d object (v7d_out argument, input), which must have been initialized with the coordinates of desired sparse points
  • for 'polyinter' transformation, no target point information has to be provided in input (it is calculated on the basis of input grid and trans object), and the coordinates of the target points (polygons' centroids) are returned in output in v7d_out argument
  • for 'metamorphosis' transformation, no target point information has to be provided in input (it is calculated on the basis of input grid and trans object), and, as for 'polyinter', this information is returned in output in v7d_out argument.

The generated grid_transform object is specific to the input and output sparse point lists provided or computed. The function c_e can be used in order to check whether the object has been successfully initialised, if the result is .FALSE., it should not be used further on.

Parametri
[out]thisgrid_transformation object
[in]transtransformation object
[in]v7d_invol7d object with the coordinates of the sparse point to be used as input (only information about coordinates is used)
[in,out]v7d_outvol7d object with the coordinates of the sparse points to be used as transformation target (input or output depending on type of transformation, when output, it must have been initialised anyway)
[in]maskboundsarray of boundary values for defining a subset of valid points where the values of maskgrid are within the first and last value of maskbounds (for transformation type 'metamorphosis:maskvalid/settoinvalid' and others)
[in]categoryappendappend this suffix to log4fortran namespace category

Definizione alla linea 2753 del file grid_transform_class.F90.

2755#ifdef DEBUG
2756 CALL l4f_category_log(this%category, l4f_debug, &
2757 "grid_transform_init setting invalid data to "//t2c(this%val1))
2758#endif
2759 ENDIF
2760
2761 CALL metamorphosis_all_setup()
2762
2763 ELSE IF (this%trans%sub_type == 'settoinvalid' ) THEN
2764
2765 IF (.NOT.PRESENT(maskbounds)) THEN
2766 CALL l4f_category_log(this%category,l4f_error, &
2767 'grid_transform_init maskbounds missing for metamorphosis:'// &
2768 trim(this%trans%sub_type)//' transformation')
2769 CALL raise_error()
2770 RETURN
2771 ELSE IF (SIZE(maskbounds) < 2) THEN
2772 CALL l4f_category_log(this%category,l4f_error, &
2773 'grid_transform_init maskbounds must have at least 2 elements for metamorphosis:'// &
2774 trim(this%trans%sub_type)//' transformation')
2775 CALL raise_error()
2776 RETURN
2777 ELSE
2778 this%val1 = maskbounds(1)
2779 this%val2 = maskbounds(SIZE(maskbounds))
2780#ifdef DEBUG
2781 CALL l4f_category_log(this%category, l4f_debug, &
2782 "grid_transform_init setting to invalid interval ]"//t2c(this%val1)//','// &
2783 t2c(this%val2)//']')
2784#endif
2785 ENDIF
2786
2787 CALL metamorphosis_all_setup()
2788
2789 ENDIF
2790ENDIF
2791
2792CONTAINS
2793
2794! common code to metamorphosis transformations conserving the number
2795! of points
2796SUBROUTINE metamorphosis_all_setup()
2797
2798this%outnx = SIZE(v7d_in%ana)
2799this%outny = 1
2800this%point_index(:,1) = (/(i,i=1,this%innx)/)
2801CALL vol7d_alloc(v7d_out, nana=SIZE(v7d_in%ana))
2802v7d_out%ana = v7d_in%ana
2803
2804this%valid = .true.
2805
2806END SUBROUTINE metamorphosis_all_setup
2807
2808END SUBROUTINE grid_transform_vol7d_vol7d_init
2809
2810
2811! Private subroutine for performing operations common to all constructors
2812SUBROUTINE grid_transform_init_common(this, trans, categoryappend)
2813TYPE(grid_transform),INTENT(inout) :: this
2814TYPE(transform_def),INTENT(in) :: trans
2815CHARACTER(len=*),INTENT(in),OPTIONAL :: categoryappend
2816
2817CHARACTER(len=512) :: a_name
2818
2819IF (PRESENT(categoryappend)) THEN
2820 CALL l4f_launcher(a_name,a_name_append=trim(subcategory)//"."// &
2821 trim(categoryappend))
2822ELSE
2823 CALL l4f_launcher(a_name,a_name_append=trim(subcategory))
2824ENDIF
2825this%category=l4f_category_get_handle(a_name)
2826
2827#ifdef DEBUG
2828CALL l4f_category_log(this%category,l4f_debug,"start init_grid_transform")
2829#endif
2830
2831this%trans=trans
2832
2833END SUBROUTINE grid_transform_init_common
2834
2835! internal subroutine to correctly initialise the output coordinates
2836! with polygon centroid coordinates
2837SUBROUTINE poly_to_coordinates(poly, v7d_out)
2838TYPE(arrayof_georef_coord_array),intent(in) :: poly
2839TYPE(vol7d),INTENT(inout) :: v7d_out
2840
2841INTEGER :: n, sz
2842DOUBLE PRECISION,ALLOCATABLE :: lon(:), lat(:)
2843
2844DO n = 1, poly%arraysize
2845 CALL getval(poly%array(n), x=lon, y=lat)
2846 sz = min(SIZE(lon), SIZE(lat))
2847 IF (lon(1) == lon(sz) .AND. lat(1) == lat(sz)) THEN ! closed polygon
2848 sz = sz - 1
2849 ENDIF
2850 CALL init(v7d_out%ana(n), lon=stat_average(lon(1:sz)), lat=stat_average(lat(1:sz)))
2851ENDDO
2852
2853END SUBROUTINE poly_to_coordinates
2854
2855!> Destructor of \a grid_tranform object.
2856!! It releases any memory and data associated to
2857!! \a grid_transform object \a this, the logger category will be deleted too.
2858SUBROUTINE grid_transform_delete(this)
2859TYPE(grid_transform),INTENT(inout) :: this !< grid_transform object
2860
2861CALL delete(this%trans)
2862
2863this%innx=imiss
2864this%inny=imiss
2865this%outnx=imiss
2866this%outny=imiss
2867this%iniox=imiss
2868this%inioy=imiss
2869this%infox=imiss
2870this%infoy=imiss
2871this%outinx=imiss
2872this%outiny=imiss
2873this%outfnx=imiss
2874this%outfny=imiss
2875
2876if (associated(this%inter_index_x)) deallocate (this%inter_index_x)
2877if (associated(this%inter_index_y)) deallocate (this%inter_index_y)
2878if (associated(this%inter_index_z)) deallocate (this%inter_index_z)
2879if (associated(this%point_index)) deallocate (this%point_index)
2880
2881if (associated(this%inter_x)) deallocate (this%inter_x)
2882if (associated(this%inter_y)) deallocate (this%inter_y)
2883
2884if (associated(this%inter_xp)) deallocate (this%inter_xp)
2885if (associated(this%inter_yp)) deallocate (this%inter_yp)
2886if (associated(this%inter_zp)) deallocate (this%inter_zp)
2887if (associated(this%vcoord_in)) deallocate (this%vcoord_in)
2888if (associated(this%vcoord_out)) deallocate (this%vcoord_out)
2889if (associated(this%point_mask)) deallocate (this%point_mask)
2890if (associated(this%stencil)) deallocate (this%stencil)
2891if (associated(this%output_level_auto)) deallocate (this%output_level_auto)
2892IF (ALLOCATED(this%coord_3d_in)) DEALLOCATE(this%coord_3d_in)
2893this%valid = .false.
2894
2895! close the logger
2896call l4f_category_delete(this%category)
2897
2898END SUBROUTINE grid_transform_delete
2899
2900
2901!> Method for returning the contents of the object.
2902!! Only a few selected memebrs of \a grid_transform object can be
2903!! queried, this is mainly for use by \a volgrid6d_class, rather than
2904!! for public use.
2905SUBROUTINE grid_transform_get_val(this, output_level_auto, point_mask, &
2906 point_index, output_point_index, levshift, levused)
2907TYPE(grid_transform),INTENT(in) :: this !< object to examine
2908TYPE(vol7d_level),POINTER,OPTIONAL :: output_level_auto(:) !< array of auto-generated output levels
2909LOGICAL,INTENT(out),ALLOCATABLE,OPTIONAL :: point_mask(:) !< mask array indicating the input points that are kept in the output, for metamorphosis transformations
2910INTEGER,INTENT(out),ALLOCATABLE,OPTIONAL :: point_index(:) !< array of indices indicating the polygon to which every input point has been assigned, if applicable
2911INTEGER,INTENT(out),ALLOCATABLE,OPTIONAL :: output_point_index(:) !< array of indices indicating the polygon to which every output point has been assigned, if applicable
2912INTEGER,INTENT(out),OPTIONAL :: levshift !< shift between input and output levels for vertint
2913INTEGER,INTENT(out),OPTIONAL :: levused !< number of input levels used for vertint
2914
2915INTEGER :: i
2916
2917IF (PRESENT(output_level_auto)) output_level_auto => this%output_level_auto
2918IF (PRESENT(point_mask)) THEN
2919 IF (ASSOCIATED(this%point_index)) THEN
2920 point_mask = c_e(reshape(this%point_index, (/SIZE(this%point_index)/)))
2921 ENDIF
2922ENDIF
2923IF (PRESENT(point_index)) THEN
2924 IF (ASSOCIATED(this%point_index)) THEN
2925 point_index = reshape(this%point_index, (/SIZE(this%point_index)/))
2926 ENDIF
2927ENDIF
2928IF (PRESENT(output_point_index)) THEN
2929 IF (ASSOCIATED(this%point_index)) THEN
2930! metamorphosis, index is computed from input origin of output point
2931 output_point_index = pack(this%point_index(:,:), c_e(this%point_index))
2932 ELSE IF (this%trans%trans_type == 'polyinter' .OR. &
2933 this%trans%trans_type == 'maskinter') THEN
2934! other cases, index is order of output point
2935 output_point_index = (/(i,i=1,this%outnx)/)
2936 ENDIF
2937ENDIF
2938IF (PRESENT(levshift)) levshift = this%levshift
2939IF (PRESENT(levused)) levused = this%levused
2940
2941END SUBROUTINE grid_transform_get_val
2942
2943
2944!> Returns \a .TRUE. if, after \a init , the corresponding \a grid_transform
2945!! object has been correctly initilised.
2946FUNCTION grid_transform_c_e(this)
2947TYPE(grid_transform),INTENT(in) :: this !< grid_transform object
2948LOGICAL :: grid_transform_c_e
2949
2950grid_transform_c_e = this%valid
2951
2952END FUNCTION grid_transform_c_e
2953
2954
2955!> Compute the output data array from input data array according to
2956!! the defined transformation. The \a grid_transform object \a this
2957!! must have been properly initialised, so that it contains all the
2958!! information needed for computing the transformation. This is the
2959!! grid-to-grid and grid-to-sparse points version. In the case of
2960!! grid-to-sparse points transformation, the output argument is still
2961!! a 2-d array with shape \a (np,1), which may have to be reshaped and
2962!! assigned to the target 1-d array after the subroutine call by means
2963!! of the \a RESHAPE() intrinsic function.
2964RECURSIVE SUBROUTINE grid_transform_compute(this, field_in, field_out, var, &
2965 coord_3d_in, zlist)
2966TYPE(grid_transform),INTENT(in),TARGET :: this !< grid_transformation object
2967REAL,INTENT(in) :: field_in(:,:,:) !< input array
2968REAL,INTENT(out) :: field_out(:,:,:) !< output array
2969TYPE(vol7d_var),INTENT(in),OPTIONAL :: var !< physical variable to be interpolated, if provided, some ad-hoc algorithms may be used where possible
2970REAL,INTENT(in),OPTIONAL,TARGET :: coord_3d_in(:,:,:) !< input vertical coordinate for vertical interpolation, if not provided by other means
2971LOGICAL,INTENT(in),OPTIONAL :: zlist(:) !< list of levels actually present in input volume, if provided, levels marked as \a .FALSE. will not be interpolated regardless of their content (optimisation to avoid interpolating missing data)
2972
2973INTEGER :: i, j, k, l, m, s, ii, jj, ie, je, n, navg, kk, kkcache, kkup, kkdown, &
2974 kfound, kfoundin, inused, i1, i2, j1, j2, np, ns, ix, iy
2975INTEGER,ALLOCATABLE :: nval(:,:)
2976REAL :: z1,z2,z3,z4,z(4)
2977DOUBLE PRECISION :: x1,x3,y1,y3,xp,yp, disttmp, dist
2978INTEGER :: innx, inny, innz, outnx, outny, outnz, vartype, nearcount
2979REAL,ALLOCATABLE :: coord_in(:)
2980LOGICAL,ALLOCATABLE :: mask_in(:)
2981REAL,ALLOCATABLE :: val_in(:), field_tmp(:,:,:)
2982REAL,POINTER :: coord_3d_in_act(:,:,:)
2983TYPE(grid_transform) :: likethis
2984LOGICAL :: alloc_coord_3d_in_act, nm1, optsearch, farenough
2985CHARACTER(len=4) :: env_var
2986LOGICAL,ALLOCATABLE :: lzlist(:)
2987
2988#ifdef DEBUG

Generated with Doxygen.