psmile_grid.F90

Go to the documentation of this file.
00001 !------------------------------------------------------------------------
00002 ! Copyright 2010, DKRZ, Hamburg, Germany.
00003 ! All rights reserved. Use is subject to OASIS4 license terms.
00004 !------------------------------------------------------------------------
00005 
00006 module psmile_grid
00007 
00008 !
00009 ! available grid types
00010 !
00011    use prism_constants, only : PRISM_Reglonlatvrt, &
00012                                PRISM_Irrlonlat_regvrt, &
00013                                PRISM_Irrlonlatvrt, &
00014                                PRISM_Irrlonlat_sigmavrt, &
00015                                PRISM_Reglonlat_sigmavrt, &
00016                                PRISM_Unstructlonlat_regvrt, &
00017                                PRISM_Unstructlonlat_sigmavrt, &
00018                                PRISM_Unstructlonlatvrt, &
00019                                PRISM_Gridless, &
00020                                PRISM_Gaussreduced_regvrt, &
00021                                PRISM_Gaussreduced_sigmavrt
00022    use psmile_common, only : psmile_float_kind, ndim_1d, ndim_2d, &
00023                              ndim_3d, psmile_undef
00024 
00025    implicit none
00026 
00027 !
00028 ! maximum number of parts a given extention can be
00029 ! splitted into by psmile_transform_extent_cyclic
00030 !
00031    integer, parameter :: max_num_trans_parts = 3*3 ! be carefull: if this value is changed, you will
00032                                                    ! have to adjust the interface for
00033                                                    ! "psmile_transform_extent_cyclic" accordingly
00034                                                    ! (NEC does not like import statement)
00035 !
00036 ! code return by psmile_transform_extent_cyclic which indicates,
00037 ! that no transformation was performed
00038 !
00039    integer, parameter :: code_no_trans = 0
00040 !
00041 ! all grids are transformed automatically into the common grid range
00042 ! in order to be able to compare them
00043 !
00044    real (psmile_float_kind), parameter :: common_grid_range(2,ndim_3d) = 
00045       reshape( (/-180, 180, -90, 90, 0, 0/), (/2, 3/) )
00046 !
00047 ! lists of grids which arr allowed to be cyclic in a certain dimension
00048 !
00049    integer, parameter :: grids_cyclic_in_first_dim(9) = 
00050                   (/PRISM_Reglonlatvrt, PRISM_Irrlonlat_regvrt,         
00051                     PRISM_Irrlonlatvrt,                                 
00052                     PRISM_Irrlonlat_sigmavrt, PRISM_Reglonlat_sigmavrt, 
00053                     PRISM_Unstructlonlat_regvrt,                        
00054                     PRISM_Unstructlonlat_sigmavrt,                      
00055                     PRISM_Unstructlonlatvrt,                            
00056                     PRISM_Gaussreduced_regvrt/)
00057 
00058    integer, parameter :: grids_cyclic_in_second_dim(9) = 
00059                   (/PRISM_Reglonlatvrt, PRISM_Irrlonlat_regvrt,         
00060                     PRISM_Irrlonlatvrt,                                 
00061                     PRISM_Irrlonlat_sigmavrt, PRISM_Reglonlat_sigmavrt, 
00062                     PRISM_Unstructlonlat_regvrt,                        
00063                     PRISM_Unstructlonlat_sigmavrt,                      
00064                     PRISM_Unstructlonlatvrt,                            
00065                     PRISM_Gaussreduced_regvrt/)
00066    integer, parameter :: grids_cyclic_in_third_dimension(1) = (/psmile_undef/)
00067 
00068 !
00069 ! defines a threshold which triggers a special handling for cell near the pole
00070 !
00071    double precision, parameter :: pole_threshold = 86.0d0 ! transformer uses a north_threshold
00072                                                           ! maybe these parameters can be unified
00073 
00074    interface
00075 
00076 !
00077 ! routines for transforming the user given coords range into
00078 ! the common -180 to 180 range and back
00079 !
00080 
00081       subroutine psmile_transform_extent_cyclic (grid_type, extent, &
00082                                                 transformed, tr_codes, n_trans, &
00083                                                 ierror)
00084          use psmile_common, only : psmile_float_kind, ndim_3d
00085 
00086          integer,                  intent (in)  :: grid_type
00087          real (psmile_float_kind), intent (in)  :: extent (2, ndim_3d)
00088          real (psmile_float_kind), intent (out) :: transformed (2, ndim_3d, 3*3)
00089          integer,                  intent (out) :: tr_codes(3*3)
00090          integer,                  intent (out) :: ierror, n_trans
00091       end subroutine
00092 
00093       subroutine psmile_transform_extent_back (tr_codes, extents, &
00094                                                transformed, n_trans,  &
00095                                                ierror)
00096          use psmile_common, only : psmile_float_kind, ndim_3d, nd_extent_infos
00097 
00098          integer,                  intent (in)  :: n_trans
00099          integer,                  intent (in)  :: tr_codes (n_trans)
00100          real (psmile_float_kind), intent (in)  :: extents (2, ndim_3d, 
00101                                                             n_trans)
00102          real (psmile_float_kind), intent (out) :: transformed (2, ndim_3d, 
00103                                                                 n_trans)
00104          integer,                  intent (out) :: ierror
00105       end subroutine
00106 
00107       subroutine psmile_transform_coords (comp_info, search, ierror)
00108          use psmile_common, only : enddef_comp, enddef_search
00109 
00110          type (enddef_comp),   intent (in)    :: comp_info
00111          type (enddef_search), intent (inout) :: search
00112          integer,              intent (out)   :: ierror
00113       end subroutine
00114 
00115       subroutine psmile_transform_coords_db_re (tr_code_to, tr_code_from, &
00116                           coords_data_dble, coords_data_real, &
00117                           coords_size, datatype, ierror)
00118          use psmile_common, only : dble_vector, real_vector, ndim_3d
00119 
00120          integer, intent (in)                        :: tr_code_to
00121          integer, intent (in)                        :: tr_code_from
00122          integer, intent (in)                        :: coords_size (ndim_3d)
00123          integer, intent (in)                        :: datatype
00124          type (dble_vector), intent(inout), optional :: coords_data_dble (ndim_3d)
00125          type (real_vector), intent(inout), optional :: coords_data_real (ndim_3d)
00126          integer, intent (out)                       :: ierror
00127       end subroutine
00128 
00129    end interface
00130 
00131    interface psmile_transform_cell_cyclic
00132 !
00133 ! routine for transforming cells that cross cyclic boundaries (360->0 or 180->-180)
00134 !
00135 
00136       subroutine psmile_transform_cell_cyclic_dble (cell, cyclic_grid_extent, ierror)
00137 
00138          double precision, intent(in)    :: cyclic_grid_extent
00139          double precision, intent(inout) :: cell (4)
00140          integer, intent (out)           :: ierror
00141       end subroutine psmile_transform_cell_cyclic_dble
00142 
00143       subroutine psmile_transform_cell_cyclic_real (cell, cyclic_grid_extent, ierror)
00144 
00145          real, intent(in)      :: cyclic_grid_extent
00146          real, intent(inout)   :: cell (4)
00147          integer, intent (out) :: ierror
00148       end subroutine psmile_transform_cell_cyclic_real
00149 
00150    end interface psmile_transform_cell_cyclic
00151 
00152    private :: psmile_transform_cell_cyclic_dble
00153    private :: psmile_transform_cell_cyclic_real
00154 
00155    contains
00156 
00157       function get_size_of_shape(grid_type)
00158 
00159          use prism_constants, only : PRISM_Error_Grid
00160 
00161          integer, intent(in) :: grid_type
00162          integer :: get_size_of_shape(2)
00163 
00164          get_size_of_shape(1) = 2
00165 
00166          select case ( grid_type )
00167 
00168          case ( PRISM_Unstructlonlatvrt )
00169 
00170             get_size_of_shape(2) = 1
00171 
00172          case ( PRISM_Unstructlonlat_regvrt,   &
00173                 PRISM_Unstructlonlat_sigmavrt, &
00174                 PRISM_Gaussreduced_regvrt,     &
00175                 PRISM_Gaussreduced_sigmavrt)
00176 
00177             get_size_of_shape(2) = 2
00178 
00179          case ( PRISM_Gridless,           &
00180                 PRISM_Irrlonlatvrt,       &
00181                 PRISM_Irrlonlat_sigmavrt, &
00182                 PRISM_Irrlonlat_regvrt,   &
00183                 PRISM_Reglonlatvrt,       &
00184                 PRISM_Reglonlat_sigmavrt)
00185 
00186             get_size_of_shape(2) = 3
00187 
00188          case  DEFAULT
00189 
00190             call psmile_error ( PRISM_Error_Grid, 'unsupported grid type', &
00191                (/0, 0, grid_type/), 3, __FILE__, __LINE__ )
00192 
00193          end select ! grid_type
00194 
00195       end function get_size_of_shape
00196 
00197       function get_num_independent_dims(grid_type)
00198 
00199          use prism_constants, only : PRISM_Error_Grid
00200 
00201          integer, intent(in) :: grid_type
00202          integer :: get_num_independent_dims
00203 
00204          select case ( grid_type )
00205 
00206                                
00207          case ( PRISM_Reglonlatvrt, &
00208                 PRISM_Reglonlat_sigmavrt)
00209 
00210             get_num_independent_dims = ndim_3d
00211 
00212          case ( PRISM_Irrlonlat_regvrt,        &
00213                 PRISM_Irrlonlat_sigmavrt,      &
00214                 PRISM_Unstructlonlat_regvrt,   &
00215                 PRISM_Unstructlonlat_sigmavrt, &
00216                 PRISM_Gaussreduced_regvrt,     &
00217                 PRISM_Gaussreduced_sigmavrt)
00218 
00219             get_num_independent_dims = ndim_2d
00220 
00221          case ( PRISM_Irrlonlatvrt,      &
00222                 PRISM_Unstructlonlatvrt, &
00223                 PRISM_Gridless )
00224 
00225             get_num_independent_dims = ndim_1d
00226 
00227          case  DEFAULT
00228 
00229             get_num_independent_dims = psmile_undef
00230 
00231             call psmile_error ( PRISM_Error_Grid, 'unsupported grid type', &
00232                (/0, 0, grid_type/), 3, __FILE__, __LINE__ )
00233 
00234          end select ! grid_type
00235 
00236       end function get_num_independent_dims
00237 
00238 end module psmile_grid

Generated on 1 Dec 2011 for Oasis4 by  doxygen 1.6.1