psmile_set_userdef.F90

Go to the documentation of this file.
00001 !-----------------------------------------------------------------------
00002 ! $COPYRIGHT_CERFACS
00003 ! $COPYRIGHT_SGI
00004 ! $COPYRIGHT_CCRL
00005 !-----------------------------------------------------------------------
00006 !BOP
00007 !
00008 ! !ROUTINE: PSMILe_set_userdef
00009 !
00010 ! !INTERFACE:
00011 
00012       subroutine psmile_set_userdef (var_id, il_side, chan_id, ierror)
00013 
00014 !
00015 ! !USES:
00016 !
00017       Use PRISM_Constants
00018       Use PSMILe, dummy_interface => psmile_set_userdef
00019       Use PSMILe_smioc
00020       Use prism
00021       use psmile_user_data, only : psmile_store_data_intern_field, &
00022                                    psmile_store_data_intern_points
00023 !
00024       Implicit none
00025 !
00026       INCLUDE 'netcdf.inc'
00027 !
00028 ! !INPUT PARAMETERS:
00029 !
00030       Integer, intent (In)                :: var_id
00031 
00032 !     Index to the global Field array (identify the transient variable)
00033 
00034       Integer, intent (In)                :: il_side
00035 
00036 !     = 0 on source il_side,    = 1 on target il_side of the transient
00037 !
00038       Integer, intent (In)                :: chan_id
00039 
00040 !     last index of input or output channel using a User-Defined Interpolation
00041 !
00042 ! !OUTPUT PARAMETERS:
00043 !
00044       Integer, Intent (Out)               :: ierror
00045 
00046 !     Returns the error code of prism_enddef;
00047 !             ierror = 0 : No error
00048 !             ierror > 0 : Severe error
00049 !
00050 ! !LOCAL VARIABLES
00051 !
00052       Character(len=max_name)      :: cl_file_name
00053       Character(len=16), parameter :: point_name_2 = 'grid-point'
00054 
00055       Integer                  :: i, j, k, il_fileid, il_varid, il_dimid
00056       Integer                  :: nlinks,  ilink, il_celldim
00057       Integer                  :: il_grid_id
00058       Integer                  :: indi_min, indi_max, indj_min, indj_max
00059       Integer                  :: indk_min, indk_max
00060       Integer                  :: il_val11, il_val12, il_val13
00061       Integer                  :: il_nb_ppp, iloc, il_blocks
00062       Integer                  :: il_nbr_blocks, il_ndim
00063       Integer                  :: isbd, il_deb
00064       Integer                  :: iming, imaxg, jming, jmaxg, kming, kmaxg
00065       Integer                  :: indi, indj, indk
00066       Integer                  :: gr_id, meth_id, mk_id
00067       Integer                  :: lenbuf
00068 !
00069 !     Variables for gridless grid, mask and function
00070 !
00071       Integer                  :: method_id_2
00072       Integer                  :: grid_id_2
00073       Integer                  :: mask_id_2
00074       Integer                  :: grid_type_2
00075       Integer                  :: id_comp_id
00076       Integer                  :: ass_var_id_2
00077       Integer                  :: userdef_id_2
00078       Integer                  :: valid_shape_pr(2,4)
00079       Integer                  :: actual_shape_pr(2,4)
00080       Integer, allocatable     :: il_offspr(:,:)
00081       Integer, allocatable     :: il_extepr(:,:)
00082       Integer                  :: il_var_nodims(2)
00083       Integer                  :: id_var_type
00084       Integer                  :: nbr_fields
00085 
00086       Character(len=max_name)  :: var_name_gl
00087       Character(len=max_name)  :: grid_name_gl
00088       Character(len=max_name)  :: cl_buffer
00089 
00090       Logical                  :: ll_novar
00091       Logical, parameter       :: new_points = .TRUE.
00092       Logical, parameter       :: new_mask = .TRUE.
00093       Logical, allocatable     :: gprmask (:,:,:)
00094 !
00095 !     local array for the links when reading the weight and address file
00096       Type(PSMILe_Link), pointer :: ila_links(:)
00097       Integer                    :: ierrp(2)
00098 !
00099 !     Pointers on global variables
00100 !
00101       Type(Grid),POINTER            :: gp
00102       Type(Userdef),POINTER         :: up
00103       Type(GridFunction),POINTER    :: fp
00104 
00105 
00106 
00107 #ifdef VERBOSE
00108       print *, trim(ch_id), ': psmile_set_userdef : start'
00109       call PSMILe_Flushstd
00110 #endif /* VERBOSE */
00111 !
00112 !   Initialization
00113 !
00114       ierror = 0
00115 !
00116 !  Get a handle in the Userdefs array
00117 
00118       call psmile_get_userdef_handle (userdef_id_2, ierror)
00119       up => Userdefs(userdef_id_2)
00120 !
00121       up%var_id     = var_id               ! geographical field id
00122       up%ig_transi_side = il_side             !  source   .OR.   target
00123 !
00124       fp => Fields(var_id)                 ! geographical field structure
00125 !  
00126 !  Get the name of the file containing the weights and addresses
00127 !
00128       if ( il_side == 0 ) then
00129          cl_file_name = &
00130          trim(fp%Taskout(chan_id)%interp%arg10%cg_file_name)
00131       elseif ( il_side == 1 ) then
00132          cl_file_name = &
00133          trim(fp%Taskin%In_channel(chan_id)%interp%arg10%cg_file_name)
00134       endif
00135 #ifdef DEBUG
00136       PRINT *, trim(ch_id), ': psmile_set_userdef : cl_file_name = ',trim(cl_file_name)
00137 #endif
00138 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00139 !!!!! 1. Open and read  user-defined weight-and-address file
00140 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00141 !
00142       CALL psmile_ud_hdlerr(NF_OPEN(TRIM(cl_file_name), NF_NOWRITE, il_fileid))
00143 !
00144 #ifdef DEBUG
00145       PRINT *, trim(ch_id), ': psmile_set_userdef : il_fileid = ',il_fileid
00146 #endif
00147 !  Get dimension of array src_ind1 i.e. the number of links
00148       CALL psmile_ud_hdlerr(NF_INQ_VARID   (il_fileid, 'src_ind1', il_varid))
00149       CALL psmile_ud_hdlerr(NF_INQ_VARDIMID(il_fileid, il_varid, il_dimid))
00150       CALL psmile_ud_hdlerr(NF_INQ_DIMLEN  (il_fileid, il_dimid, nlinks))
00151       up%ig_nb_links = nlinks
00152 #ifdef DEBUG
00153       PRINT *, trim(ch_id), ': psmile_set_userdef : nlinks =', nlinks
00154 #endif
00155 !
00156 !  Allocate array for links ( same number on any side )
00157       ALLOCATE (ila_links(1:nlinks), STAT=ierror )
00158       IF (ierror /= 0) THEN
00159          PRINT *, 'Error in allocating weight-and-address arrays = ', ierror
00160          CALL PSMILe_Flushstd
00161          CALL PSMILe_Abort
00162       ENDIF
00163       do k = 1, nlinks
00164          ila_links(k)%cell_id(1) = 0
00165          ila_links(k)%cell_id(2) = 0
00166          ila_links(k)%cell_id(3) = 0
00167          ila_links(k)%weight = 0.0D0
00168       enddo
00169 !
00170 !  Get dimension of cell_id array defined in the file by the user(depends on side)
00171 !
00172       il_celldim = 3
00173       if ( il_side == 0 ) then
00174          CALL psmile_ud_hdlerr2( NF_INQ_VARID(il_fileid, 'src_ind3', il_varid), ll_novar)
00175          if ( ll_novar ) il_celldim = 2
00176          CALL psmile_ud_hdlerr2( NF_INQ_VARID(il_fileid, 'src_ind2', il_varid), ll_novar)
00177          if ( ll_novar ) il_celldim = 1
00178       elseif (il_side == 1 ) then
00179          CALL psmile_ud_hdlerr2( NF_INQ_VARID(il_fileid, 'tgt_ind3', il_varid), ll_novar)
00180          if ( ll_novar ) il_celldim = 2
00181          CALL psmile_ud_hdlerr2( NF_INQ_VARID(il_fileid, 'tgt_ind2', il_varid), ll_novar)
00182          if ( ll_novar ) il_celldim = 1
00183       endif
00184 !     keep geographical cell dimension in Userdef structure
00185       up%ig_celldim = il_celldim
00186 
00187 #ifdef DEBUG
00188       PRINT *, trim(ch_id), ': psmile_set_userdef : cell_dim =', il_celldim
00189 #endif
00190 !
00191 !  Read links depending on the side (source links .OR. target links)
00192 !
00193       if ( il_side == 0 ) then
00194 !        Get source links in array ila_links on the source side
00195          CALL psmile_ud_hdlerr(NF_INQ_VARID   (il_fileid, 'src_ind1', il_varid))
00196          CALL psmile_ud_hdlerr(NF_GET_VAR_INT (il_fileid, il_varid,     &
00197                      ila_links(:)%cell_id(1)))
00198          if ( il_celldim >= 2 ) then
00199             CALL psmile_ud_hdlerr(NF_INQ_VARID(il_fileid, 'src_ind2', il_varid))
00200             CALL psmile_ud_hdlerr(NF_GET_VAR_INT (il_fileid, il_varid,     &
00201                         ila_links(:)%cell_id(2)))
00202          endif
00203          if ( il_celldim == 3 ) then         
00204             CALL psmile_ud_hdlerr(NF_INQ_VARID(il_fileid, 'src_ind3', il_varid))
00205             CALL psmile_ud_hdlerr(NF_GET_VAR_INT (il_fileid, il_varid,     &
00206                         ila_links(:)%cell_id(3)))
00207          endif
00208          CALL psmile_ud_hdlerr(NF_INQ_VARID(il_fileid, 'weight', il_varid))
00209          CALL psmile_ud_hdlerr(NF_GET_VAR_DOUBLE (il_fileid, il_varid,  &
00210                      ila_links(:)%weight))
00211 !
00212       elseif ( il_side == 1 ) then
00213 !        Get target links in array ila_links on the target side
00214          CALL psmile_ud_hdlerr(NF_INQ_VARID(il_fileid, 'tgt_ind1', il_varid))
00215          CALL psmile_ud_hdlerr(NF_GET_VAR_INT (il_fileid, il_varid,     &
00216                      ila_links(:)%cell_id(1)))
00217          if ( il_celldim >= 2 ) then
00218             CALL psmile_ud_hdlerr(NF_INQ_VARID(il_fileid, 'tgt_ind2', il_varid))
00219             CALL psmile_ud_hdlerr(NF_GET_VAR_INT (il_fileid, il_varid,     &
00220                         ila_links(:)%cell_id(2)))
00221          endif
00222          if ( il_celldim == 3 ) then
00223             CALL psmile_ud_hdlerr(NF_INQ_VARID(il_fileid, 'tgt_ind3', il_varid))
00224             CALL psmile_ud_hdlerr(NF_GET_VAR_INT (il_fileid, il_varid,     &
00225                         ila_links(:)%cell_id(3)))
00226          endif
00227       endif
00228 !
00229 !  Close Netcdf file
00230          CALL psmile_ud_hdlerr(NF_CLOSE(il_fileid))
00231 #ifdef DEBUGX
00232     PRINT *,'links(:)%cell_id(1)= ',ila_links(:)%cell_id(1)
00233     PRINT *,'links(:)%cell_id(2)= ',ila_links(:)%cell_id(2)
00234     PRINT *,'links(:)%cell_id(3)= ',ila_links(:)%cell_id(3)
00235     if (il_side == 0 ) then
00236        PRINT *,'links(:)%weight = ',ila_links(:)%weight
00237     endif
00238 #endif
00239 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00240 !!!!! 2. Define and declare intermediate gridless exchange grid
00241 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00242 !
00243 !  2.1  Get offsets and extents of geographical grid 
00244 !
00245       il_grid_id = Methods(fp%method_id)%grid_id
00246       gp => Grids(il_grid_id)
00247 
00248       il_blocks = size(gp%partition(:,:),DIM=1)
00249       IF (il_blocks /= 1) THEN
00250           PRINT*, 'psmile_set_userdef does not support more than one block yet'
00251           CALL PSMILe_Abort
00252       ENDIF
00253 !
00254 !  2.2  store limits of geographical grid partition
00255 !
00256       indi_min = gp%partition(1,1)+1
00257       indi_max = gp%partition(1,1)+gp%extent(1,1)
00258       if ( il_celldim >= 2 ) then
00259          indj_min = gp%partition(1,2)+1
00260          indj_max = gp%partition(1,2)+gp%extent(1,2)
00261       endif
00262       if ( il_celldim == 3 ) then
00263          indk_min = gp%partition(1,3)+1
00264          indk_max = gp%partition(1,3)+gp%extent(1,3)
00265       endif
00266   !
00267       il_val11 = fp%var_shape(1,1)
00268       if ( il_celldim >= 2 ) then
00269          il_val12 = fp%var_shape(1,2)
00270       endif
00271       if ( il_celldim == 3 ) then
00272          il_val13 = fp%var_shape(1,3)
00273       endif
00274 
00275 #ifdef DEBUG
00276   PRINT *," i min max, j min max, k min max "
00277   PRINT *, indi_min,indi_max,indj_min,indj_max,indk_min,indk_max
00278   PRINT *, il_val11, il_val12, il_val13
00279 #endif
00280 !
00281 ! 2.3  Compute the number of points in my gridlessgrid partition :
00282 !      = number of links for which the src index in geographic grid
00283 !        is within the limits of the geographic partition for this PE
00284 !      Tests on indexes depend on the number of dimensions of the geo-grid
00285 !
00286       il_nb_ppp = 0           ! initial (and may be final !) value
00287 !
00288 !   Specific to One-dimensional grid
00289       if ( il_celldim == 1 ) then
00290          do i = 1, nlinks
00291             indi = ila_links(i)%cell_id(1)
00292             IF (indi .GE. indi_min .AND. indi .LE. indi_max ) THEN
00293                il_nb_ppp = il_nb_ppp + 1
00294             ENDIF
00295          enddo
00296 !   Specific to Bi-dimensional grid
00297       elseif ( il_celldim == 2 ) then
00298          do i = 1, nlinks
00299             indi = ila_links(i)%cell_id(1)
00300             indj = ila_links(i)%cell_id(2)
00301             IF (indi .GE. indi_min .AND. indi .LE. indi_max &
00302                .AND. indj .GE. indj_min .AND. indj .LE. indj_max) THEN
00303                il_nb_ppp = il_nb_ppp + 1
00304             ENDIF
00305          enddo
00306 !   Specific to Three-dimensional grid
00307       elseif ( il_celldim == 3 ) then
00308          do i = 1, nlinks
00309             indi = ila_links(i)%cell_id(1)
00310             indj = ila_links(i)%cell_id(2)
00311             indk = ila_links(i)%cell_id(3)
00312             IF (indi .GE. indi_min .AND. indi .LE. indi_max &
00313                .AND. indj .GE. indj_min .AND. indj .LE. indj_max &
00314                .AND. indk .GE. indk_min .AND. indk .LE. indk_max) THEN
00315                il_nb_ppp = il_nb_ppp + 1
00316             ENDIF
00317          enddo
00318       endif
00319       up%ig_nb_ppp = il_nb_ppp
00320 #ifdef DEBUG
00321       PRINT *, "il_nb_ppp = ", il_nb_ppp
00322 #endif
00323 !
00324 ! Case where there is no link for this PE : 
00325       IF (il_nb_ppp .EQ. 0) THEN
00326         PRINT *, " Warning : No gridless point for this PE"
00327         CALL PSMILe_Flushstd
00328         gp%used_for_coupling = .false.
00329         fp%used_for_coupling = .false.
00330 !  If no gridless point : no gridless grid for this PE
00331 #ifdef VERBOSE
00332       print *, trim(ch_id), ': psmile_set_userdef : eof, ierror = ', ierror
00333       call PSMILe_Flushstd
00334 #endif /* VERBOSE */
00335 
00336         return
00337       ENDIF
00338 !
00339 !  2.4  Allocate  arrays in global Userdefs structure  for the gridless grid
00340 !
00341       ALLOCATE (up%iga_igl(1:il_nb_ppp,4), STAT=ierror)
00342       ALLOCATE (up%dga_wght(1:il_nb_ppp), STAT=ierror)
00343 !
00344 !  2.5  Select links that are relevant for this PE partition
00345 !       indi, indj, indk are the indices of the geographical points
00346 !       ilink : index of the link in the w&a file (or grless grid) 1 to nlinks
00347 !       iloc  : local index in the local partition (1 to il_nb_ppp)
00348 !
00349 !   Case where at least one usr-defined link concerns this PE partition
00350       iloc = 0
00351 !   Specific to One-dimensional grid
00352       if ( il_celldim == 1 ) then
00353          do ilink = 1, nlinks
00354             indi = ila_links(ilink)%cell_id(1)
00355             IF (indi .GE. indi_min .AND. indi .LE. indi_max ) THEN
00356                iloc = iloc + 1
00357                up%iga_igl(iloc,1) = indi + il_val11 - indi_min
00358                up%iga_igl(iloc,4) = ilink
00359                up%dga_wght(iloc)  = ila_links(ilink)%weight
00360             ENDIF
00361          enddo
00362 !   Specific to Bi-dimensional grid
00363       elseif ( il_celldim == 2 ) then
00364          do ilink = 1, nlinks
00365             indi = ila_links(ilink)%cell_id(1)
00366             indj = ila_links(ilink)%cell_id(2)
00367             IF (indi .GE. indi_min .AND. indi .LE. indi_max &
00368                .AND. indj .GE. indj_min .AND. indj .LE. indj_max) THEN
00369                iloc = iloc + 1
00370                up%iga_igl(iloc,1) = indi + il_val11 - indi_min
00371                up%iga_igl(iloc,2) = indj + il_val12 - indj_min
00372                up%iga_igl(iloc,4) = ilink
00373                up%dga_wght(iloc)  = ila_links(ilink)%weight
00374             ENDIF
00375          enddo
00376 !   Specific to Three-dimensional grid
00377       elseif ( il_celldim == 3 ) then
00378          do ilink = 1, nlinks
00379             indi = ila_links(ilink)%cell_id(1)
00380             indj = ila_links(ilink)%cell_id(2)
00381             indk = ila_links(ilink)%cell_id(3)
00382             IF (indi .GE. indi_min .AND. indi .LE. indi_max &
00383                .AND. indj .GE. indj_min .AND. indj .LE. indj_max &
00384                .AND. indk .GE. indk_min .AND. indk .LE. indk_max) THEN
00385                iloc = iloc + 1
00386                up%iga_igl(iloc,1) = indi + il_val11 - indi_min
00387                up%iga_igl(iloc,2) = indj + il_val12 - indj_min
00388                up%iga_igl(iloc,3) = indk + il_val13 - indk_min
00389                up%iga_igl(iloc,4) = ilink
00390                up%dga_wght(iloc)  = ila_links(ilink)%weight
00391             ENDIF
00392          enddo
00393       endif
00394 !!!      endif                ! lg_nolink
00395 !
00396 !   Deallocate ila_links. Local info is kept in up%iga_igl and up%dga_wght
00397 !
00398       DEALLOCATE ( ila_links, STAT=ierror )
00399       IF (ierror > 0) THEN
00400           ierrp (1) = ierror
00401           ierror = 14
00402 
00403           CALL PSMILe_Error ( ierror, 'ila_links', &
00404              ierrp, 1, __FILE__, __LINE__ )
00405           RETURN
00406       ENDIF
00407 
00408 
00409 #ifdef DEBUG
00410       PRINT *," iga_igl(:,1:4) = "
00411       do i = 1, up%ig_nb_ppp
00412         PRINT *, up%iga_igl(i,:)
00413       enddo
00414 #endif
00415 !
00416 ! 2.6  find the number of subdomains of the gridlessgrid in my PE partition
00417 !
00418 !      1 subdomain = suite of contiguous indices in gridlessgrid (ilink values)
00419 !
00420       il_nbr_blocks = 1  ! initial number of sub-domains of gridless grid
00421       il_ndim = 3        ! il_ndim is always 3 for gridless grid
00422 !
00423       do iloc=2, il_nb_ppp
00424          if ( (up%iga_igl(iloc,4) - up%iga_igl(iloc-1,4)) .GT. 1) then
00425 !      A new subdomain in the gridless grid indices is found
00426             il_nbr_blocks = il_nbr_blocks + 1
00427          endif
00428       enddo
00429 #ifdef DEBUG
00430       PRINT *, "il_nbr_blocks = ", il_nbr_blocks
00431 #endif
00432 !
00433 ! 2.7   For the Gridless grid : allocate arrays for offsets and extents 
00434 !       of the subdomains with exact dimensions
00435 !
00436       ALLOCATE (il_offspr(il_nbr_blocks,il_ndim), STAT=ierror)
00437       ALLOCATE (il_extepr(il_nbr_blocks,il_ndim), STAT=ierror)
00438 
00439 #ifdef DEBUG
00440       IF ( ierror /= 0 ) then
00441         PRINT *, 'Error allocating partition il_offspr or il_extepr = ', ierror
00442         CALL PSMILe_Flushstd
00443         CALL PSMILe_Abort
00444       ENDIF
00445 #endif
00446 !
00447 !  2.8  compute index limits for this PE (offsets and extent of each subdomain)
00448 !
00449       isbd = 1            ! Subdomain (block) index
00450       il_deb = 1          ! Keep the index value of the first point in subdomain
00451       il_offspr(isbd,1) = up%iga_igl(1,4) - 1           ! offset of first block
00452       il_extepr(isbd,1) = 1                             ! min number for extent
00453       do iloc=2, il_nb_ppp
00454          if ( (up%iga_igl(iloc,4) - up%iga_igl(iloc-1,4)) .GT. 1) then
00455 !        A new block in the gridless grid indices is found
00456            il_extepr(isbd,1) = iloc - 1 - il_deb + 1   ! previous block extent
00457            il_deb = iloc                               ! a new bloc begin now
00458            isbd = isbd + 1                             ! increment block index
00459            il_offspr(isbd,1) = up%iga_igl(iloc,4) - 1  ! offset of new block
00460          endif
00461          il_extepr(isbd,1) = iloc - il_deb + 1         ! current block extent
00462       enddo
00463 !
00464 !  2.9  Gridless grid : index limits for this PE
00465 !
00466       valid_shape_pr(1,1) = 1
00467       valid_shape_pr(2,1) = il_nb_ppp
00468       valid_shape_pr(1:2,2:4) = 1
00469 !
00470       il_extepr(:,2:3) = 1
00471       il_offspr(:,2:3) = 0
00472 
00473       actual_shape_pr(1:2,1:4) = valid_shape_pr(1:2,1:4)
00474 #ifdef DEBUG
00475       PRINT *, 'il_extepr = ',il_extepr
00476       PRINT *, 'il_offspr = ',il_offspr
00477       PRINT*, 'actual_shape_pr(:,1) :',actual_shape_pr(1,1),actual_shape_pr(2,1)
00478       PRINT*, 'actual_shape_pr(:,2) :',actual_shape_pr(1,2),actual_shape_pr(2,2)
00479       PRINT*, 'actual_shape_pr(:,3) :',actual_shape_pr(1,3),actual_shape_pr(2,3)
00480 #endif
00481 !
00482 !  Build gridless grid
00483 !
00484       grid_type_2 = PRISM_Gridless
00485       id_comp_id  = fp%comp_id
00486 !  Uses transient local_name when generating the name of the gridless grid
00487 !  (Matches the name generated by prismdrv_get_all_grids)
00488 !
00489       call put_udef_suffix ( fp%local_name, grid_name_gl, chan_id, il_side )
00490 #ifdef DEBUG
00491    PRINT *, ' psmile_set_userdef,  grid_name_gl = ',grid_name_gl
00492 #endif
00493 
00494       CALL psmile_def_grid ( grid_id_2 , grid_name_gl, id_comp_id, valid_shape_pr, &
00495                             grid_type_2, ierror )
00496 !
00497 !  Keep values in Userdef structure
00498 !
00499       up%igl_grid_id = grid_id_2
00500       up%status = PSMILe_Status_defined
00501 !
00502 #ifdef DEBUG
00503       IF ( ierror /= 0 ) PRINT *,'Error in gridless psmile_def_grid = ', ierror
00504 #endif
00505 !
00506       CALL psmile_def_partition ( grid_id_2, il_nbr_blocks, il_offspr, il_extepr, &
00507                                  ierror )
00508 #ifdef DEBUG
00509       IF ( ierror /= 0 ) PRINT *,'Error in gridless psmile_def_partition = ',ierror
00510 #endif
00511 !
00512       CALL psmile_set_points_gridless (method_id_2, point_name_2, grid_id_2, new_points, ierror)
00513 
00514       ! make this method know to psmile_user_data, this way it will not be ignored in psmile_merge_fields
00515       call psmile_store_data_intern_points (method_id_2)
00516 !
00517 #ifdef DEBUG
00518       IF ( ierror /= 0 ) PRINT *,'Error in psmile_set_points_gridless = ', ierror
00519 #endif
00520 !
00521       iming = valid_shape_pr(1,1)
00522       imaxg = valid_shape_pr(2,1)
00523       jming = valid_shape_pr(1,2)
00524       jmaxg = valid_shape_pr(2,2)
00525       kming = valid_shape_pr(1,3)
00526       kmaxg = valid_shape_pr(2,3)
00527 !
00528 ! ... allocate mask
00529 !
00530       ALLOCATE ( gprmask(iming:imaxg,jming:jmaxg,kming:kmaxg), STAT=ierror )
00531 !
00532 #ifdef DEBUG
00533       IF (ierror /= 0) THEN
00534           PRINT *, 'Error in allocating gprmask arrays = ', ierror
00535           CALL PSMILe_Flushstd
00536           CALL PSMILe_Abort
00537       ENDIF
00538 #endif
00539 !
00540 ! Definition du masque
00541 !
00542       DO k = kming, kmaxg
00543         DO j = jming, jmaxg
00544           DO i = iming, imaxg
00545             gprmask(i,j,k)=.TRUE.
00546           ENDDO
00547         ENDDO
00548       ENDDO
00549 !
00550       CALL  psmile_set_mask ( mask_id_2, grid_id_2, valid_shape_pr, &
00551                              gprmask, new_mask, ierror )
00552 #ifdef DEBUG
00553       IF ( ierror /= 0 ) PRINT *, 'Error in psmile_set_mask = ', ierror
00554 #endif
00555 !
00556 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00557 !!!!! 3. declares the associates variable : gridless grid function
00558 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00559 !     Gridless functions is always 3dim + bundles
00560       il_var_nodims(1) = 3
00561 !     Detect bundle number from Geographical Function
00562       if ( fp%transi_type == PSMILe_bundle ) then
00563           nbr_fields = fp%var_shape(2,gp%n_dim+1)
00564           il_var_nodims(1) = 4
00565           il_var_nodims(2) = nbr_fields
00566       else
00567           nbr_fields = 1
00568           il_var_nodims(2) = 0
00569       endif
00570       up%ig_nbr_fields = nbr_fields
00571 
00572 !!! Set by def_var in fp%var_shape for the "gridfunction"
00573       actual_shape_pr(1,4) = 1
00574       actual_shape_pr(2,4) = nbr_fields
00575 !
00576       id_var_type = fp%dataType
00577       call put_udef_suffix ( fp%local_name, var_name_gl, chan_id, il_side )
00578 !
00579 #ifdef DEBUG
00580    print *,' psmile_set_userdef: var_name_gl nbr_bundles = ',var_name_gl, il_var_nodims(2)
00581 #endif
00582 !
00583       CALL psmile_def_var (ass_var_id_2, var_name_gl, grid_id_2, method_id_2, &
00584            mask_id_2, il_var_nodims, actual_shape_pr, id_var_type, ierror )
00585 
00586 
00587       ! make this field know to psmile_user_data, this way it will not be ignored in psmile_merge_fields
00588       call psmile_store_data_intern_field (ass_var_id_2)
00589 !
00590 !    4. Updates geographical grid and field structures with associated userdef values
00591 !
00592         gp%assoc_grid_id = grid_id_2
00593         gp%used_for_coupling = .false.
00594 !
00595         if  ( il_side == 0 ) then
00596 !       Geographic transient
00597            fp%Taskout(chan_id)%assoc_var_id  = ass_var_id_2
00598            fp%Taskout(chan_id)%userdef_id    = userdef_id_2
00599         elseif ( il_side == 1 ) then
00600 !       Geographic transient
00601            fp%Taskin%In_channel(chan_id)%assoc_var_id  = ass_var_id_2
00602            fp%Taskin%In_channel(chan_id)%userdef_id    = userdef_id_2
00603         endif
00604 !
00605 #ifdef VERBOSE
00606       print *, trim(ch_id), ': psmile_set_userdef : eof, ierror = ', ierror
00607       call PSMILe_Flushstd
00608 #endif /* VERBOSE */
00609 !
00610       return
00611 !
00612       END SUBROUTINE psmile_set_userdef
00613 !
00614 !
00615       SUBROUTINE psmile_ud_hdlerr2(istatus, lnotfound)
00616       integer     :: istatus
00617       logical     :: lnotfound
00618       INCLUDE 'netcdf.inc'
00619       lnotfound = .false.
00620       IF (istatus .NE. NF_NOERR) THEN
00621          if ( istatus .EQ. NF_ENOTVAR ) then
00622             lnotfound = .true.
00623             return
00624          endif 
00625          PRINT *, NF_STRERROR(istatus)
00626          STOP 'netcdf stopped'
00627       ENDIF
00628       return
00629       END SUBROUTINE psmile_ud_hdlerr2
00630 
00631       SUBROUTINE psmile_ud_hdlerr(istatus)
00632       INTEGER        :: istatus
00633       INCLUDE 'netcdf.inc'
00634       IF (istatus .NE. NF_NOERR) THEN
00635          PRINT *, NF_STRERROR(istatus)
00636          STOP 'netcdf stopped'
00637       ENDIF
00638       RETURN
00639       END SUBROUTINE psmile_ud_hdlerr
00640 
00641 
00642 
00643 

Generated on 18 Mar 2011 for Oasis4 by  doxygen 1.6.1