psmile_put_int.F90

Go to the documentation of this file.
00001 !-----------------------------------------------------------------------
00002 ! Copyright 2006-2010, NEC Europe Ltd., London, UK.
00003 ! All rights reserved. Use is subject to OASIS4 license terms.
00004 !-----------------------------------------------------------------------
00005 !BOP
00006 !
00007 ! !ROUTINE: PSMILe_Put_int 
00008 !
00009 ! !INTERFACE:
00010 
00011 subroutine psmile_put_int  ( field_id, task_id, julian_day, julian_sec, &
00012               julian_dayb, julian_secb, data_array, action, info, ierror )
00013 !
00014 ! !USES:
00015 !
00016    use PRISM_constants
00017    use PRISM_calendar
00018 
00019    use PSMILe
00020    use PSMILe_SMIOC, only : sga_smioc_comp, transient, transient_out
00021 
00022    implicit none
00023 !
00024 ! !INPUT PARAMETERS:
00025 !
00026    Integer, Intent (In)            :: field_id
00027 
00028 !  Handle to the variable information
00029 
00030    Integer, Intent (In)            :: task_id
00031 
00032 !  Task number for the Output
00033 
00034    Real (PSMILe_float_kind), Intent (In)   :: julian_day, julian_dayb(2)
00035    Real (PSMILe_float_kind), Intent (In)   :: julian_sec, julian_secb(2)
00036 
00037 !  Date with  bounds on which the information is located in time
00038 !  Time interval for which the data is representative
00039 !  lower bound: julian_*b(1), upper bound: julian_*b(2)
00040 !
00041    Integer, Intent (In)            :: data_array(*)
00042 
00043 !  The data itself
00044 
00045    Logical, Intent (In)            :: action(3)  ! 1: Coupling ation
00046                                                  ! 2: IO action
00047                                                  ! 3: Restart action
00048 !
00049 !  Switches to activate calls for coupling and/or I/O
00050 !
00051 ! !OUTPUT PARAMETERS:
00052 !
00053    Integer, Intent (InOut)         :: info
00054 
00055 !  Returned info about action performed
00056 
00057    Integer, Intent (Out)           :: ierror
00058 
00059 !  Returns the error code of psmile_put_int ;
00060 !             ierror = 0 : No error
00061 !             ierror > 0 : Severe error
00062 !
00063 ! !LOCAL VARIABLES
00064 !
00065    Integer            :: add_scalar
00066    Integer            :: mul_scalar
00067 
00068    Integer, Allocatable           :: data_scattered(:)
00069    Integer, Allocatable           :: data_reduced(:)
00070 
00071    Integer            :: shape_in(2,6)
00072 
00073    Integer            :: i, j ! loop count
00074    Integer            :: len_gathered, len_scattered
00075    Integer            :: len, len_3d, len_reduced
00076    Integer            :: nbr_fields ! number of fields in a bundle
00077 
00078    Integer            :: rdim(6)
00079    Integer            :: nbr_reductions
00080 
00081    Integer            :: local_reduce
00082    Integer            :: local_timeop
00083 
00084    Logical            :: local_scatter
00085    Logical            :: local_multiply
00086    Logical            :: local_add
00087 
00088    Logical            :: local_operation = .false.
00089    Logical            :: mask_set
00090    Logical            :: mask_needed
00091    Logical, Pointer   :: mask_array(:)
00092    Logical, Pointer   :: mask_aux  (:)
00093 
00094    Type (GridFunction), Pointer :: fp
00095    Type (Taskout_type), Pointer :: Taskout
00096 
00097 !  SMIOC data
00098 
00099    Type (transient),     Pointer :: sga_smioc_transi(:)
00100    Type (transient_out), Pointer :: sga_transi_out
00101 
00102 !  For I/O
00103 
00104 #ifdef __PSMILE_WITH_IO
00105    Real (PSMILe_float_kind) :: jd_end,js_end,delta_sec
00106    Real (PSMILe_float_kind) :: jd_cur,js_cur
00107 
00108    Integer            :: il_taskid,il_transiouts,il_smioc_loc
00109    Integer            :: il_taskid_restr
00110    Integer            :: lag,add_days
00111 
00112    Logical            :: debug_action, restart_action
00113 #endif
00114 
00115 !  For statistics
00116   
00117    Integer            :: stat_nsum
00118    Integer            :: nsum
00119 
00120    Integer            :: shape_out(2,6)
00121 
00122    Integer, Allocatable           :: recv_buf(:)
00123    Integer, Allocatable           :: stat_max(:)
00124    Integer, Allocatable           :: stat_min(:)
00125    Integer, Allocatable           :: stat_sum(:)
00126    Integer, Allocatable           :: stat_mean(:)
00127 
00128    Logical            :: stats
00129 
00130    Character(len=6), Save :: cstats (3)
00131 
00132    Integer :: n_grid_dim
00133 
00134 !  Error parameters
00135 
00136    Integer            :: ierr
00137    Integer, Parameter :: nerrp = 3
00138    Integer            :: ierrp (nerrp)
00139 
00140 !
00141 ! !DESCRIPTION:
00142 !
00143 ! Subroutine "PSMILe_Put_int " takes the data and sends them
00144 !          to remote application on the the io library
00145 !
00146 ! TO DO: rdim, the dimension along which the reduction operation shall
00147 !        be performed needs to be read in from the SMIOC.
00148 !
00149 !        We still need to center the date/time for output of
00150 !        summed/averaged fields
00151 !
00152 !        Apply error handling for coupling and I/O
00153 
00154 !        Fill info object
00155 !
00156 ! !REVISION HISTORY:
00157 !
00158 !   Date      Programmer   Description
00159 ! ----------  ----------   -----------
00160 ! 03.07.02    R. Redler    created
00161 ! 04.01.28    R. Redler    major revision to adjust to SMIOC
00162 ! 04.07.05    R. Redler    Restart added
00163 !
00164 !EOP
00165 !----------------------------------------------------------------------
00166 ! $Id: psmile_put_int.F90 2687 2010-10-28 15:15:52Z coquart $
00167 ! $Author: coquart $
00168 !----------------------------------------------------------------------
00169 !
00170    Data cstats /'masked', 'valid', 'all'/
00171 !
00172 #ifdef VERBOSE
00173    print *, trim(ch_id), ': psmile_put_int : field_id', field_id
00174 
00175    call psmile_flushstd
00176 #endif /* VERBOSE */
00177 
00178 !-----------------------------------------------------------------------
00179 !  1st Initialization
00180 !-----------------------------------------------------------------------
00181 
00182    ierror         = 0
00183    local_reduce   = PSMILe_undef
00184 
00185    local_operation = .false.
00186 
00187    Nullify(mask_array)
00188    Nullify(mask_aux)
00189 
00190    fp      => Fields(field_id)
00191    Taskout => Fields(field_id)%Taskout(task_id)
00192    sga_smioc_transi => sga_smioc_comp(Fields(field_id)%comp_id)%sga_smioc_transi
00193    sga_transi_out => sga_smioc_transi(fp%smioc_loc)%sga_transi_out(task_id)
00194    n_grid_dim = Grids(Methods(fp%method_id)%grid_id)%n_dim
00195 
00196 !-----------------------------------------------------------------------
00197 ! Determine size of data_array
00198 !-----------------------------------------------------------------------
00199 
00200    len = fp%size
00201 
00202    if ( fp%transi_type == PSMILe_bundle ) then
00203        nbr_fields = fp%var_shape(2,n_grid_dim+1)
00204    else
00205        nbr_fields = 1
00206    endif
00207 
00208    len_3d = len / nbr_fields
00209 
00210 !-----------------------------------------------------------------------
00211 ! Set switches
00212 !-----------------------------------------------------------------------
00213 
00214    local_scatter = sga_transi_out%sg_src_local_trans%ig_scatter == PSMILe_true
00215    local_timeop  = sga_transi_out%ig_src_timeop
00216 !rr local reduction operation currently not yet activated
00217 !  local_reduce  = PSMILe_undef
00218 
00219    mul_scalar = sga_transi_out%sg_src_local_trans%dg_mult_scalar
00220    add_scalar = sga_transi_out%sg_src_local_trans%dg_add_scalar
00221 
00222    local_add      = add_scalar /= PSMILe_dundef
00223    local_multiply = mul_scalar /= PSMILe_dundef
00224 
00225 !  local_operation = .false.
00226 
00227    mask_set = fp%mask_id /= PRISM_UNDEFINED
00228 
00229    if (mask_set) then
00230       mask_set = Masks(fp%mask_id)%status /= PSMILe_status_free
00231    endif
00232 
00233 !-----------------------------------------------------------------------
00234 ! In case that there is no mask defined for the field create one.
00235 !-----------------------------------------------------------------------
00236 
00237    stats = sga_transi_out%iga_stats(1) == PSMILe_true .or. &
00238            sga_transi_out%iga_stats(2) == PSMILe_true .or. &
00239            sga_transi_out%iga_stats(3) == PSMILe_true
00240 
00241    mask_needed = stats .or. local_scatter .or. &
00242                  local_reduce == PSMILe_max .or.  local_reduce == PSMILe_min
00243 
00244    if ( mask_set ) mask_array => Masks(fp%mask_id)%mask_array
00245 
00246    if ( mask_needed ) then
00247      allocate (mask_aux(len_3d), STAT=ierr)
00248      if ( ierr /= 0 ) then
00249         ierrp (1) = 1
00250         ierror = PRISM_Error_Alloc
00251         call psmile_error ( ierror, 'mask_aux', ierrp(1), 1, &
00252                             __FILE__, __LINE__ )
00253         return
00254      endif
00255 
00256      mask_aux = .true.
00257 
00258      if (.not. mask_set) mask_array => mask_aux
00259    endif
00260 
00261 !-----------------------------------------------------------------------
00262 ! Set lower date bounds
00263 !-----------------------------------------------------------------------
00264 
00265    if ( Taskout%nsum == 0 ) then
00266       Taskout%start_day = julian_dayb(1)
00267       Taskout%start_sec = julian_secb(1)
00268    endif
00269 
00270 !-----------------------------------------------------------------------
00271 ! Allocate arrays for manipulation of data_array
00272 !-----------------------------------------------------------------------
00273 
00274 
00275    if ( local_timeop /= PSMILe_undef .or. local_add .or. local_multiply ) then
00276 
00277       local_operation = .true.
00278 
00279       if ( .not. associated(Taskout%buffer_int ) ) then
00280          Allocate(Taskout%buffer_int (1:len), STAT = ierr )
00281          if ( ierr /= 0 ) then
00282             ierrp (1) = 1
00283             ierror = PRISM_Error_Alloc
00284             call psmile_error ( ierror, 'Taskout%buffer_int ', &
00285                  ierrp(1), 1, __FILE__, __LINE__ )
00286             return
00287          endif
00288 
00289          Taskout%buffer_int  = 0.0
00290          Taskout%nsum = 0
00291       endif
00292 
00293    endif
00294 
00295 
00296 !-----------------------------------------------------------------------
00297 ! 2nd  Sum up if local_timeop = 3601 or local_timeop = 3600 
00298 !-----------------------------------------------------------------------
00299 
00300    if ( local_timeop /= PSMILe_undef ) then
00301 
00302       Taskout%nsum=Taskout%nsum+1
00303  
00304       Taskout%buffer_int (1:len) = &
00305            Taskout%buffer_int (1:len) + data_array(1:len)
00306 
00307       info = info + 1
00308 
00309    endif
00310 
00311 !-----------------------------------------------------------------------
00312 ! Set upper date bounds
00313 !-----------------------------------------------------------------------
00314 
00315    Taskout%end_day = julian_dayb(2)
00316    Taskout%end_sec = julian_secb(2)
00317 
00318 !-----------------------------------------------------------------------
00319 ! ... Return if no I/O or coupling is required.
00320 !-----------------------------------------------------------------------
00321 
00322    if ( .not. action(1) .and. .not. action(2) .and. .not. action(3) ) then
00323 #ifdef VERBOSE
00324          print *, trim(ch_id), ': psmile_put_int: eof nothing to do! ierror ', ierror
00325 #endif /* VERBOSE */
00326          return
00327       endif
00328 
00329 !-----------------------------------------------------------------------
00330 ! 3rd  Multiply and/or add scalar on summation or original fields
00331 !-----------------------------------------------------------------------
00332 !
00333 ! ... Multiplication with a constant
00334 
00335    IF ( local_multiply ) THEN
00336 
00337 ! ... for time averaged fields
00338 
00339       if (( local_timeop /= PSMILe_undef) .OR. ( local_add ) ) then 
00340 
00341          Taskout%buffer_int (1:len) = Taskout%buffer_int (1:len) * mul_scalar
00342 
00343       else
00344 
00345 ! ... for ordinary fields
00346 
00347          Taskout%buffer_int (1:len) = data_array(1:len) * mul_scalar
00348 
00349       endif
00350 
00351   ENDIF
00352   !
00353   !
00354 ! Addition of a constant
00355 
00356    if ( local_add ) then
00357 
00358 ! ... for time averaged fields
00359 
00360       if ( local_timeop /= PSMILe_undef ) then
00361 
00362          Taskout%buffer_int (1:len) = Taskout%buffer_int (1:len)   &
00363                                     + (add_scalar*Taskout%nsum)
00364 
00365       else
00366 
00367 ! ... for ordinary fields
00368 
00369          Taskout%buffer_int (1:len) = data_array(1:len) + add_scalar
00370 
00371       endif
00372 
00373    endif
00374 !-----------------------------------------------------------------------
00375 ! ... Do the average if required if local_timeop = 3600
00376 !-----------------------------------------------------------------------
00377 
00378    if ( local_timeop == PSMILe_tave  .and. Taskout%nsum > 0 ) then
00379 
00380        Taskout%buffer_int (1:len) = Taskout%buffer_int (1:len) &
00381                                   / int (Taskout%nsum)
00382    endif
00383 
00384 !-----------------------------------------------------------------------
00385 ! 4th  Scatter original data or summed up fields
00386 !-----------------------------------------------------------------------
00387 
00388    if ( local_scatter ) then
00389 
00390       !
00391       ! WARNING: Implement procedure for bundles and vectors
00392       !
00393       ! ... Determine length of data arrays to be handled (ignoring the number
00394       !     of fields for the moment) number of fields is taken into account
00395       !     again during the scattering and gathering.
00396       
00397       if ( .not. mask_set ) then
00398 
00399          len_gathered  = len_3d
00400          len_scattered = len_gathered
00401 
00402       else
00403          len           = len_3d
00404          len_gathered  = 0
00405          len_scattered = 1
00406 
00407          do i = 1, n_grid_dim
00408 
00409             len_scattered = len_scattered                                &
00410                  * ( Masks(fp%mask_id)%mask_shape(2,i) -   &
00411                      Masks(fp%mask_id)%mask_shape(1,i) + 1 )
00412          enddo
00413 
00414          if ( len_scattered /= len ) then
00415             ierrp (1) = field_id
00416             ierrp (2) = len
00417             ierrp (3) = len_scattered
00418             ierror = PRISM_Error_Size
00419 
00420             call psmile_error ( ierror,  fp%local_name, ierrp, 3, &
00421                __FILE__, __LINE__ )
00422             return
00423          endif
00424 
00425          len_gathered = count(mask_array)
00426 
00427       endif
00428 
00429 !-----------------------------------------------------------------------
00430 ! Allocate appropriate memory and scatter data onto data_scattered
00431 !-----------------------------------------------------------------------
00432 
00433       Allocate (data_scattered(len_scattered), STAT = ierr )
00434 
00435       if ( ierr /= 0 ) then
00436          ierrp (1) = len_scattered
00437          ierror = PRISM_Error_Alloc
00438          call psmile_error ( ierror, 'data_scattered', &
00439               ierrp(1), 1, __FILE__, __LINE__ )
00440          return
00441       endif
00442 
00443       if ( local_operation ) then
00444 
00445          call psmile_loc_trans_int  ( PSMILe_scat, nbr_fields, &
00446               len_gathered, Taskout%buffer_int , &
00447               len_scattered, data_scattered, field_id )
00448       else
00449 
00450          call psmile_loc_trans_int  ( PSMILe_scat, nbr_fields, &
00451               len_gathered, data_array, &
00452               len_scattered, data_scattered, field_id )
00453 
00454       endif
00455 
00456    endif ! local_scatter
00457 
00458 
00459 
00460 !-----------------------------------------------------------------------
00461 ! 5th Determine the input shape for reduction operations
00462 !-----------------------------------------------------------------------
00463 
00464    shape_in = 1
00465 
00466    do i = 1, n_grid_dim
00467       shape_in(1,i) = fp%var_shape(1,i)
00468       shape_in(2,i) = fp%var_shape(2,i)
00469    enddo
00470 
00471    if ( Fields(field_id)%transi_type == PSMILe_bundle ) &
00472       shape_in(2,6) = nbr_fields
00473 
00474 !-----------------------------------------------------------------------
00475 ! 6th  Minimum or Maximum reduction operations
00476 !-----------------------------------------------------------------------
00477 
00478    if ( local_reduce == PSMILe_max .or. local_reduce == PSMILe_min )  then
00479 
00480 ! ... Determine and set shapes of input and output arrays
00481 
00482       shape_out   = shape_in
00483       len_reduced = 1
00484 
00485       nbr_reductions = 0 ! needs to be set according to SMIOC input
00486       rdim = 6
00487 
00488       do i = 1, nbr_reductions
00489          shape_out(1,rdim(i)) = 1
00490          shape_out(2,rdim(i)) = 1
00491       enddo
00492 
00493       do i = 1, 6
00494          len_reduced = len_reduced * ( shape_out(2,i)-shape_out(1,i) + 1 )
00495       enddo
00496 
00497       allocate (data_reduced(len_reduced), STAT=ierr)
00498       if ( ierr /= 0 ) then
00499          ierrp (1) = len_reduced
00500          ierror = PRISM_Error_Alloc
00501          call psmile_error ( ierror, 'data_reduced', ierrp(1), 1, &
00502               __FILE__, __LINE__ )
00503          return
00504       endif
00505 
00506       if ( local_scatter ) then
00507 
00508 ! ... for gathered fields
00509 
00510          call psmile_multi_reduce_int  ( local_reduce, shape_in, &
00511               data_scattered, shape_out, data_reduced, mask_array, ierror )
00512       else
00513 
00514          if ( local_operation ) then
00515 
00516 ! ... for locally modified fields
00517 
00518             call psmile_multi_reduce_int  ( local_reduce, shape_in, &
00519                  Taskout%buffer_int ,     &
00520                  shape_out, data_reduced, mask_array, ierror )
00521          else
00522 
00523 ! ... for ordinary fields
00524 
00525             call psmile_multi_reduce_int  ( local_reduce,shape_in, &
00526                  data_array, shape_out, data_reduced, mask_array, ierror )
00527 
00528          endif ! local_operation
00529 
00530       endif ! local_scatter
00531 
00532    endif ! local_reduce
00533 
00534 !-----------------------------------------------------------------------
00535 ! 7th  Calculate statistics
00536 !
00537 !      j = 1: for masked points
00538 !      j = 2: for valid points
00539 !      j = 3: for all points
00540 !
00541 !-----------------------------------------------------------------------
00542 
00543    if (stats) then
00544 
00545       shape_out      = 1
00546       shape_out(2,6) = nbr_fields
00547 
00548 !     Allocate work vectors for statistics
00549 
00550       allocate (recv_buf(1:shape_out(2,6)), &
00551                 stat_max(1:shape_out(2,6)), &
00552                 stat_min(1:shape_out(2,6)), &
00553                 stat_sum(1:shape_out(2,6)), &
00554                 stat_mean(1:shape_out(2,6)), STAT=ierr)
00555       if ( ierr /= 0 ) then
00556          ierrp (1) = nbr_fields * 5
00557          ierror = PRISM_Error_Alloc
00558          call psmile_error ( ierror, 'recv_buf', ierrp(1), 1, __FILE__, __LINE__ )
00559          return
00560       endif
00561 
00562 !     Compute statistics for each statistic which is available
00563 
00564       do j = 1, 3
00565 
00566       if ( sga_transi_out%iga_stats(j) == PSMILe_true ) then 
00567 
00568          !-----------------------------------------------------------------------
00569          ! In case that there is no mask defined for the field create one.
00570          !-----------------------------------------------------------------------
00571 
00572          if ( mask_set ) then
00573 
00574             select case (j) 
00575             case (1) 
00576                mask_aux = .not. Masks(fp%mask_id)%mask_array
00577                mask_array => mask_aux            
00578             case (2)
00579                mask_array => Masks(fp%mask_id)%mask_array
00580             case (3)
00581                mask_aux = .true.
00582                mask_array => mask_aux            
00583             end select
00584 
00585          else
00586 
00587             mask_aux = j > 1
00588             mask_array => mask_aux            
00589 
00590          endif
00591 
00592          if ( local_scatter ) then
00593 
00594             ! ... for gathered fields
00595 
00596             call psmile_multi_reduce_int  ( PSMILe_max, shape_in, &
00597                  data_scattered, shape_out, stat_max, mask_array, ierror )
00598 
00599             call psmile_multi_reduce_int  ( PSMILe_min, shape_in, &
00600                  data_scattered, shape_out, stat_min, mask_array, ierror )
00601 
00602             call psmile_multi_reduce_int  ( PSMILe_integral, shape_in, &
00603                  data_scattered, shape_out, stat_sum, mask_array, ierror )
00604          else
00605 
00606             if ( local_operation ) then
00607 
00608                ! ... for locally modified fields
00609 
00610                call psmile_multi_reduce_int  ( PSMILe_max, shape_in, &
00611                     Taskout%buffer_int ,   &
00612                     shape_out, stat_max, mask_array, ierror )
00613 
00614                call psmile_multi_reduce_int  ( PSMILe_min, shape_in, &
00615                     Taskout%buffer_int ,   &
00616                     shape_out, stat_min, mask_array, ierror )
00617 
00618                call psmile_multi_reduce_int  ( PSMILe_integral, shape_in, &
00619                     Taskout%buffer_int ,   &
00620                     shape_out, stat_sum, mask_array, ierror )
00621             else
00622 
00623                ! ... for ordinary fields
00624 
00625                call psmile_multi_reduce_int  ( PSMILe_max,   &
00626                     shape_in, data_array, shape_out, stat_max, &
00627                     mask_array, ierror )
00628 
00629                call psmile_multi_reduce_int  ( PSMILe_min,   &
00630                     shape_in, data_array, shape_out, stat_min, &
00631                     mask_array, ierror )
00632 
00633                call psmile_multi_reduce_int  ( PSMILe_integral,   &
00634                     shape_in, data_array, shape_out, stat_sum, &
00635                     mask_array, ierror )
00636 
00637             endif ! local_operation
00638 
00639          endif ! local_scatter
00640 
00641          if ( Comps(fp%comp_id)%act_comm /= MPI_COMM_NULL ) then
00642 
00643             call MPI_Allreduce ( stat_max, recv_buf, shape_out(2,6), MPI_INTEGER, &
00644                  MPI_MAX, Comps(fp%comp_id)%act_comm, ierror )
00645 
00646             stat_max (:) = recv_buf(:)
00647 
00648             call MPI_Allreduce ( stat_min, recv_buf, shape_out(2,6), MPI_INTEGER, &
00649                  MPI_MIN, Comps(fp%comp_id)%act_comm, ierror )
00650 
00651             stat_min (:) = recv_buf(:)
00652 
00653             call MPI_Allreduce ( stat_sum, recv_buf, shape_out(2,6), MPI_INTEGER, &
00654                  MPI_SUM, Comps(fp%comp_id)%act_comm, ierror )
00655 
00656             stat_sum (:) = recv_buf(:)
00657 
00658             !if the whole field is being used
00659             if (j == 3) then
00660                stat_nsum = len_3d
00661             else
00662                stat_nsum = count(mask_array)
00663             endif
00664 
00665             call MPI_Allreduce ( stat_nsum, nsum, 1, MPI_INTEGER, &
00666                  MPI_SUM, Comps(fp%comp_id)%act_comm, ierror )
00667 
00668             if (nsum > 0) then
00669                stat_mean(:) = stat_sum(:) / nsum
00670             else
00671                stat_mean = 0.0
00672             endif
00673 
00674          endif
00675 
00676          write (*, 9990) trim(ch_id)
00677          write (*, 9980) trim(ch_id), trim(cstats (j))
00678 
00679          write (*,*) trim(ch_id), &
00680               ': ... for field ', trim(fp%local_name)
00681 
00682          write (*,'(1x,a,a)') trim(ch_id), &
00683               ': BundleNr.       Min           Max           Sum           Mean'
00684 
00685          write (*, 9950)
00686 
00687          do i = 1, shape_out(2,6)
00688             write(*,'(1x,a,a2,i3,6x,4(1x,e14.6))') trim(ch_id), &
00689                  ': ', i, stat_min(i), stat_max(i), stat_sum(i), stat_mean(i)
00690          enddo
00691 
00692          write (*, 9990) trim(ch_id)
00693 
00694          call psmile_flushstd
00695 
00696       endif ! iga_stat
00697 
00698       enddo ! j-loop
00699 
00700 !     Deallocate arrays needed for statistics
00701 
00702       Deallocate (recv_buf, stat_min, stat_max, stat_sum, stat_mean, STAT=ierror)
00703 #if defined ( VERBOSE) 
00704       if ( ierror /= 0 ) then
00705          ierrp (1) = nbr_fields
00706          ierror = PRISM_Error_Dealloc
00707          call psmile_error ( ierror, 'recv_buf, stat_{min,max,sum,mean}', &
00708               ierrp(1), 1, __FILE__, __LINE__ )
00709          return
00710       endif
00711 #endif
00712    end if ! stats
00713 
00714 
00715 #ifdef __PSMILE_WITH_IO
00716 !RV  For testing only. At this position the call anticipates the OASIS 3 flag
00717 !RV  EXPOUT.
00718 !-----------------------------------------------------------------------
00719 ! 8th Perform I/O if required
00720 !-----------------------------------------------------------------------
00721 
00722 #ifdef VERBOSE
00723    print *, trim(ch_id), ': psmile_put_int : io_action', action(2)
00724 
00725    call psmile_flushstd
00726 #endif /* VERBOSE */
00727 
00728    lag = sga_transi_out%ig_lag
00729 
00730    if ( action(2) ) then
00731 !
00732 !     The time stamps written to a file are mapped onto the
00733 !     model time axis.
00734 !
00735       if(lag /= PSMILe_undef) then
00736 
00737         delta_sec = (julian_dayb(2) - julian_day) * 86400.0 &
00738                    +  julian_secb(2) - julian_secb(1)
00739 
00740         js_cur   = julian_sec - lag * delta_sec
00741         add_days = floor(js_end / 86400.0)
00742         jd_cur   = julian_day + add_days
00743         js_cur = js_cur - int (add_days) * 86400.0
00744 
00745       else
00746 
00747         js_cur=julian_sec
00748         jd_cur=julian_day
00749 
00750       endif
00751 
00752       if ( local_reduce /= PSMILe_undef )  then
00753 
00754 !!$             call psmile_write_byid_int  ( field_id, task_id, data_reduced, &
00755 !!$                                           jd_cur, js_cur, ierror )
00756           
00757          print *, 'psmile_put_int : output of reduced field not supported.'
00758 
00759       else if ( local_scatter ) then
00760 
00761          call psmile_write_byid_int  ( field_id, task_id, data_scattered, &
00762               jd_cur, js_cur, ierror )
00763 
00764       else
00765 
00766          if ( local_operation ) then
00767 
00768             call psmile_write_byid_int  ( field_id, task_id, &
00769                  Taskout%buffer_int , &
00770                  jd_cur, js_cur, ierror )
00771 
00772             Taskout%buffer_int  = 0.0
00773             Taskout%nsum = 0
00774          else
00775 
00776             call psmile_write_byid_int  ( field_id, task_id, data_array, &
00777                  jd_cur, js_cur, ierror )
00778 
00779          endif ! local_operation
00780 
00781       endif ! local_reduce
00782 
00783    endif ! action(2)
00784 
00785 !-----------------------------------------------------------------------
00786 ! 9th Debug output of Send data if required
00787 !-----------------------------------------------------------------------
00788 
00789    il_smioc_loc=fp%smioc_loc
00790    debug_action=sga_transi_out%ig_debugmode.eq.PSMILe_true
00791    if ( debug_action ) then
00792       il_transiouts=0
00793       if(associated(sga_smioc_transi(il_smioc_loc)%sga_transi_out)) &
00794            il_transiouts=size(sga_smioc_transi(il_smioc_loc)%sga_transi_out)
00795 !
00796 !      Shift task id into the range of task ids for debugging!
00797 !
00798       il_taskid=il_transiouts+task_id
00799 !
00800 !      Coherence check
00801 !
00802       if(il_taskid.le.size( fp%io_task_lookup)) &
00803          debug_action= fp%io_task_lookup(il_taskid).gt.0
00804    endif
00805 
00806 #ifdef VERBOSE
00807    print *, trim(ch_id), ': psmile_put_int : debug_action', debug_action
00808 
00809    call psmile_flushstd
00810 #endif /* VERBOSE */
00811 
00812    if ( debug_action ) then
00813  
00814        if ( local_reduce /= PSMILe_undef )  then
00815  
00816 !!$             call psmile_write_byid_int  ( field_id, il_taskid, data_reduced, &
00817 !!$                                           julian_day, julian_sec, ierror )
00818           
00819           print *, 'psmile_put_int : output of reduced field not supported.'
00820 
00821        else if ( local_scatter ) then
00822 
00823           call psmile_write_byid_int  ( field_id, il_taskid, data_scattered, &
00824                julian_day, julian_sec, ierror )
00825 
00826        else
00827 
00828           if ( local_operation ) then
00829 
00830              call psmile_write_byid_int  ( field_id, il_taskid, &
00831                   Taskout%buffer_int , &
00832                   julian_day, julian_sec, ierror )
00833           else
00834 
00835              call psmile_write_byid_int  ( field_id, il_taskid, data_array, &
00836                   julian_day, julian_sec, ierror )
00837 
00838           endif ! local_operation
00839 
00840        endif ! local_reduce
00841 
00842     endif ! debug_action
00843 
00844 #endif
00845 
00846 !-----------------------------------------------------------------------
00847 ! 10th Send data if required
00848 !-----------------------------------------------------------------------
00849 
00850     if ( action(1) ) then
00851 
00852        if ( local_reduce /= PSMILe_undef )  then
00853 
00854 !!$         call psmile_put_field_int  (field_id, task_id, data_reduced, &
00855 !!$                                     len_3d, nbr_fields, ierror)
00856 
00857          print *, 'psmile_put_int : coupling of reduced field not supported.'
00858 
00859       else if ( local_scatter ) then
00860 
00861          call psmile_put_field_int  (field_id, task_id, data_scattered, &
00862               len_3d, nbr_fields, ierror)
00863 
00864       else
00865 
00866          if ( local_operation ) then
00867 
00868             call psmile_put_field_int  (field_id, task_id, &
00869                  Taskout%buffer_int , &
00870                  len_3d, nbr_fields, ierror)
00871 
00872             ! defer reset when it is time for lag driven restart action
00873             if ( .not. action(3) ) then
00874                Taskout%buffer_int  = 0.0
00875                Taskout%nsum = 0
00876             endif
00877 
00878          else
00879 
00880             call psmile_put_field_int  (field_id, task_id, data_array, &
00881                  len_3d, nbr_fields, ierror)
00882 
00883          endif ! local_operation
00884 
00885       endif ! local_reduce
00886 
00887    endif ! action(1)
00888 
00889 #ifdef __PSMILE_WITH_IO
00890 
00891 !-----------------------------------------------------------------------
00892 ! 11th Write coupling restart if required
00893 !-----------------------------------------------------------------------
00894 
00895     if ( action(3) ) then
00896 
00897        il_transiouts=0
00898        if(associated(sga_smioc_transi(il_smioc_loc)%sga_transi_out)) &
00899             il_transiouts=size(sga_smioc_transi(il_smioc_loc)%sga_transi_out)
00900 !
00901 !      Shift task id into the range of task ids for restart!
00902 !
00903        il_taskid_restr=3*il_transiouts+task_id+1
00904 !
00905 !      Coherence check
00906 !
00907        restart_action = .false.
00908        if(il_taskid_restr.le.size( fp%io_task_lookup)) &
00909             restart_action = fp%io_task_lookup(il_taskid_restr).gt.0
00910 !
00911 !      The time stamp which has to be written to the lag restart file is
00912 !      Jobend date to be able to relocated these data in the next job
00913 !      where the new JobStart date corresponds to the old JobEnd date. 
00914 !
00915        if(restart_action) &
00916           call psmile_date2ju ( PRISM_Jobend_date, jd_end, js_end )
00917 
00918        if ( local_reduce /= PSMILe_undef )  then
00919 
00920 !!$         if ( restart_action ) &
00921 !!$         call psmile_write_byid_int  ( field_id, il_taskid_restr, data_reduced, &
00922 !!$                                       jd_end, js_end, ierror )
00923           print *, 'psmile_put_int : restart of reduced field not supported.'
00924 
00925        else if ( local_scatter ) then
00926 
00927           if ( restart_action ) &
00928           call psmile_write_byid_int  ( field_id, il_taskid_restr, &
00929                                         data_scattered, &
00930                                         jd_end, js_end, ierror )
00931 
00932        else
00933 
00934           if ( local_operation ) then
00935 
00936              if ( restart_action ) &
00937                call psmile_write_byid_int  ( field_id, il_taskid_restr, &
00938                                              Taskout%buffer_int , &
00939                                              jd_end, js_end, ierror )
00940 
00941              Taskout%buffer_int  = 0.0
00942              Taskout%nsum = 0
00943 
00944           else
00945 
00946              if ( restart_action )  &
00947                call psmile_write_byid_int  ( field_id, il_taskid_restr, &
00948                                              data_array, &
00949                                              jd_end, js_end, ierror )
00950 
00951           endif ! local_operation
00952 
00953        endif ! local_reduce
00954 
00955     endif ! action(3)
00956 
00957 #endif
00958 
00959 !-----------------------------------------------------------------------
00960 ! 12th Free Memory
00961 !-----------------------------------------------------------------------
00962 
00963    if ( allocated(data_reduced) )   deallocate(data_reduced)
00964    if ( allocated(data_scattered) ) deallocate(data_scattered)
00965    if ( associated(mask_aux) )      deallocate(mask_aux)
00966 
00967 #ifdef VERBOSE
00968    print *, trim(ch_id), ': psmile_put_int : eof ierror ', ierror
00969 
00970    call psmile_flushstd
00971 #endif /* VERBOSE */
00972 
00973 !  Formats
00974 
00975 9990  format (1x, a, ': ', 65('='))
00976 9980  format (1x, a, ': Statistics over ', a, ' points')
00977 9950  format (1x, a, ': ', 65('-'))
00978 
00979 ! 
00980 end subroutine psmile_put_int 

Generated on 18 Mar 2011 for Oasis4 by  doxygen 1.6.1