prism_put_restart.F90

Go to the documentation of this file.
00001 !-----------------------------------------------------------------------
00002 ! Copyright 2006-2010, CERFACS, Toulouse, France.
00003 ! Copyright 2006-2010, SGI Germany, Munich, Germany.
00004 ! Copyright 2006-2010, NEC Europe Ltd., London, UK.
00005 ! All rights reserved. Use is subject to OASIS4 license terms.
00006 !-----------------------------------------------------------------------
00007 !BOP
00008 !
00009 ! !ROUTINE: PRISM_Put_restart
00010 !
00011 ! !INTERFACE:
00012 
00013    subroutine prism_put_restart ( field_id, date, date_bounds, data_array, info, ierror )
00014 !
00015 ! !USES:
00016 !
00017       use PRISM_constants
00018       use PRISM_calendar
00019 
00020       use PSMILe
00021       use PSMILe_SMIOC, only : sga_smioc_comp, transient
00022 
00023       implicit none
00024 !
00025 ! !INPUT PARAMETERS:
00026 !
00027       Integer, Intent (In)                 :: field_id
00028 
00029 !     Handle to the variable information
00030 
00031       Type(PRISM_Time_Struct), Intent (In) :: date
00032 
00033 !     Date on which the information is located in time
00034 
00035       Type(PRISM_Time_Struct), Intent (In) :: date_bounds(2)
00036 
00037 !     Time interval for which the data is representative
00038 !     lower bound: date_bounds(1), upper bound: date_bounds(2)
00039 
00040       Double Precision, Intent (In)        :: data_array(*)
00041 
00042 !     the data itself
00043 !
00044 ! !OUTPUT PARAMETERS:
00045 !
00046 
00047       integer, Intent (Out)               :: info
00048 
00049 !     returned info about action performed
00050 
00051       integer, Intent (Out)               :: ierror
00052 
00053 !     Returns the error code of prism_put_restart;
00054 !             ierror = 0 : No error
00055 !             ierror > 0 : Severe error
00056 !
00057 ! !LOCAL VARIABLES
00058 !
00059       Integer            :: il_taskid_restr, il_transiouts, il_smioc_loc
00060       Double Precision   :: julian_day, julian_dayb(2)
00061       Double Precision   :: julian_sec, julian_secb(2)
00062 
00063 ! WARNING: WORKAROUND
00064       Logical            :: restart_action
00065 
00066       Integer            :: task_id
00067       Integer, Parameter :: nerrp = 1
00068       Integer            :: ierrp (nerrp)
00069 
00070       Type (Transient), pointer    :: sga_smioc_transi(:)
00071       Type (GridFunction), Pointer :: fp
00072 
00073 ! !DESCRIPTION:
00074 !
00075 !    Subroutine "prism_put_restart" takes the data and writes a restart.
00076 !
00077 ! !REVISION HISTORY:
00078 !
00079 !   Date      Programmer   Description
00080 ! ----------  ----------   -----------
00081 ! 04.11.18    R. Redler    created
00082 !
00083 !EOP
00084 !----------------------------------------------------------------------
00085 !
00086 ! $Id: prism_put_restart.F90 2325 2010-04-21 15:00:07Z valcke $
00087 ! $Author: valcke $
00088 !
00089   Character(len=len_cvs_string), save :: mycvs = 
00090       '$Id: prism_put_restart.F90 2325 2010-04-21 15:00:07Z valcke $'
00091 !
00092 !----------------------------------------------------------------------
00093 #ifdef VERBOSE
00094       print *, trim(ch_id), ': prism_put_restart: field_id', field_id
00095 
00096       call psmile_flushstd
00097 #endif /* VERBOSE */
00098 
00099 !-----------------------------------------------------------------------
00100 ! 1st Initialization
00101 !-----------------------------------------------------------------------
00102 
00103       ierror = 0
00104       info   = PRISM_NOACTION
00105 
00106       sga_smioc_transi => sga_smioc_comp(Fields(field_id)%comp_id)%sga_smioc_transi
00107       fp               => Fields(field_id)
00108 
00109 !-----------------------------------------------------------------------
00110 ! 2nd Check field_id
00111 !-----------------------------------------------------------------------
00112 
00113       if ( Fields(field_id)%status /= PSMILe_status_defined ) then
00114          ierrp (1) = field_id
00115       
00116          ierror = PRISM_Error_Arg
00117       
00118          call psmile_error ( ierror, 'field_id', &
00119                              ierrp(1), 1, __FILE__, __LINE__ )
00120          return
00121       endif
00122 
00123 !-----------------------------------------------------------------------
00124 ! 3rd Return in case there is nothing to do
00125 !-----------------------------------------------------------------------
00126 
00127       if ( Fields(field_id)%smioc_loc == PRISM_UNDEFINED ) return
00128 
00129 !-----------------------------------------------------------------------
00130 ! 4th Check date information
00131 !-----------------------------------------------------------------------
00132 !
00133 !  ... convert date and date bounds into julian days and seconds
00134 !
00135       call psmile_date2ju ( date,           julian_day,     julian_sec    )
00136       call psmile_date2ju ( date_bounds(1), julian_dayb(1), julian_secb(1))
00137       call psmile_date2ju ( date_bounds(2), julian_dayb(2), julian_secb(2))
00138 
00139 !   ... check whether bounds are consistent
00140 
00141       if ( julian_dayb(2) <  julian_dayb(1) .or. &
00142          ( julian_dayb(1) == julian_dayb(2) .and. &
00143            julian_secb(2) <  julian_secb(1) ) ) then
00144 
00145            ierrp (1) = field_id
00146 
00147            ierror = PRISM_Error_Date
00148 
00149            call psmile_error ( ierror, 'upper bound < lower bound', &
00150                              ierrp(1), 1, __FILE__, __LINE__ )
00151            return
00152 
00153       endif
00154 
00155 !  ... check whether date is within bounds
00156 
00157       if ( ( julian_dayb(1) >  julian_day       .or.  &
00158              julian_day     >  julian_dayb(2) ) .or.  &
00159            ( julian_dayb(1) == julian_day       .and. &
00160              julian_sec     <  julian_secb(1) ) .or.  &
00161            ( julian_dayb(2) == julian_day       .and. &
00162              julian_sec     >  julian_secb(2) ) ) then
00163 
00164          ierrp (1) = field_id
00165 
00166          ierror = PRISM_Error_Date
00167 
00168          call psmile_error ( ierror, 'date out of bounds', &
00169                              ierrp(1), 1, __FILE__, __LINE__ )
00170          return
00171 
00172       endif
00173 
00174 !-----------------------------------------------------------------------
00175 ! 5th Write out for the first task only
00176 !-----------------------------------------------------------------------
00177 
00178       task_id = 1
00179 
00180 !-----------------------------------------------------------------------
00181 ! ... set the concrete action that has to be performed for this
00182 !     particular task.
00183 !-----------------------------------------------------------------------
00184 
00185       il_smioc_loc=fp%smioc_loc
00186 
00187       il_transiouts=0
00188 
00189       if(associated(sga_smioc_transi(il_smioc_loc)%sga_transi_out)) &
00190            il_transiouts=size(sga_smioc_transi(il_smioc_loc)%sga_transi_out)
00191       !
00192       !      Shift task id into the range of task ids for restart!
00193       !
00194 
00195       il_taskid_restr=3*il_transiouts+task_id+1
00196 
00197       !
00198       !      Coherence check
00199       !
00200 
00201       restart_action = .false.
00202 
00203       if(il_taskid_restr.le.size( fp%io_task_lookup)) &
00204            restart_action = fp%io_task_lookup(il_taskid_restr).gt.0
00205 
00206 !------------------------------------------------------------------------
00207 ! 6th Dump out fields into restart file
00208 !------------------------------------------------------------------------
00209 
00210       if ( restart_action ) then
00211 
00212 #ifdef VERBOSE
00213           print *, trim(ch_id), ': prism_put_restart: dump out field ', trim(fp%local_name)
00214           call psmile_flushstd
00215 #endif /* VERBOSE */
00216 
00217           if ( Fields(field_id)%dataType == PRISM_Integer ) &
00218                call psmile_write_byid_int ( field_id, il_taskid_restr, &
00219                data_array, julian_dayb(2), julian_secb(2), ierror )
00220 
00221           if ( Fields(field_id)%dataType == PRISM_Real ) &
00222                call psmile_write_byid_real ( field_id, il_taskid_restr, &
00223                data_array, julian_dayb(2), julian_secb(2), ierror )
00224 
00225           if ( Fields(field_id)%dataType == PRISM_Double_Precision ) &
00226                call psmile_write_byid_dble ( field_id, il_taskid_restr, &
00227                data_array, julian_dayb(2), julian_secb(2), ierror )
00228 
00229           info = info + 10
00230 
00231       endif
00232 
00233 #ifdef VERBOSE
00234       print *, trim(ch_id), ': prism_put_restart: eof ierror ', ierror
00235 
00236       call psmile_flushstd
00237 #endif /* VERBOSE */
00238 !
00239    end subroutine prism_put_restart

Generated on 18 Mar 2011 for Oasis4 by  doxygen 1.6.1