New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
icbrst.F90 in NEMO/trunk/src/OCE/ICB – NEMO

source: NEMO/trunk/src/OCE/ICB/icbrst.F90

Last change on this file was 15088, checked in by acc, 3 years ago

Check in ICB changes from 2021/ticket2696_icb_halo1_halo2_compatibility (#2696) to restore halo1 - halo2 equivalence with ORCA2_ICE_PISCES and icebergs. The benefit won't be apparent until the reproducibility issue with icedyn_rhg_evp.F90 is sorted. This fix closes #2696

  • Property svn:keywords set to Id
File size: 22.4 KB
RevLine 
[3614]1MODULE icbrst
2   !!======================================================================
3   !!                       ***  MODULE  icbrst  ***
4   !! Ocean physics:  read and write iceberg restart files
5   !!======================================================================
6   !! History : 3.3.1 !  2010-01  (Martin&Adcroft) Original code
7   !!            -    !  2011-03  (Madec)          Part conversion to NEMO form
8   !!            -    !                            Removal of mapping from another grid
9   !!            -    !  2011-04  (Alderson)       Split into separate modules
10   !!            -    !  2011-04  (Alderson)       Restore restart routine
11   !!            -    !                            Currently needs a fixed processor
12   !!            -    !                            layout between restarts
[6140]13   !!            -    !  2015-11  Dave Storkey     Convert icb_rst_read to use IOM so can
14   !!                                              read single restart files
[3614]15   !!----------------------------------------------------------------------
[9190]16
[3614]17   !!----------------------------------------------------------------------
18   !!   icb_rst_read    : read restart file
19   !!   icb_rst_write   : write restart file
20   !!----------------------------------------------------------------------
21   USE par_oce        ! NEMO parameters
22   USE dom_oce        ! NEMO domain
23   USE in_out_manager ! NEMO IO routines
24   USE lib_mpp        ! NEMO MPI library, lk_mpp in particular
25   USE netcdf         ! netcdf routines for IO
[6140]26   USE iom
[3614]27   USE icb_oce        ! define iceberg arrays
28   USE icbutl         ! iceberg utility routines
29
30   IMPLICIT NONE
31   PRIVATE
32
33   PUBLIC   icb_rst_read    ! routine called in icbini.F90 module
34   PUBLIC   icb_rst_write   ! routine called in icbstp.F90 module
35   
36   INTEGER ::   nlonid, nlatid, nxid, nyid, nuvelid, nvvelid
37   INTEGER ::   nmassid, nthicknessid, nwidthid, nlengthid
38   INTEGER ::   nyearid, ndayid
39   INTEGER ::   nscaling_id, nmass_of_bits_id, nheat_density_id, numberid
40   INTEGER ::   nsiceid, nsheatid, ncalvid, ncalvhid, nkountid
41   INTEGER ::   nret, ncid, nc_dim
42   
43   INTEGER,  DIMENSION(3)                  :: nstrt3, nlngth3
44
45   !!----------------------------------------------------------------------
[9598]46   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
[5215]47   !! $Id$
[10068]48   !! Software governed by the CeCILL license (see ./LICENSE)
[3614]49   !!----------------------------------------------------------------------
50CONTAINS
51
52   SUBROUTINE icb_rst_read()
53      !!----------------------------------------------------------------------
54      !!                 ***  SUBROUTINE icb_rst_read  ***
55      !!
56      !! ** Purpose :   read a iceberg restart file
57      !!      NB: for this version, we just read back in the restart for this processor
58      !!      so we cannot change the processor layout currently with iceberg code
59      !!----------------------------------------------------------------------
60      INTEGER                      ::   idim, ivar, iatt
61      INTEGER                      ::   jn, iunlim_dim, ibergs_in_file
[10065]62      INTEGER                      ::   ii, ij, iclass, ibase_err, imax_icb
[6140]63      REAL(wp), DIMENSION(nkounts) ::   zdata     
[3614]64      LOGICAL                      ::   ll_found_restart
[5341]65      CHARACTER(len=256)           ::   cl_path
[4990]66      CHARACTER(len=256)           ::   cl_filename
[3614]67      CHARACTER(len=NF90_MAX_NAME) ::   cl_dname
68      TYPE(iceberg)                ::   localberg ! NOT a pointer but an actual local variable
69      TYPE(point)                  ::   localpt   ! NOT a pointer but an actual local variable
70      !!----------------------------------------------------------------------
[6140]71      ! Find a restart file. Assume iceberg restarts in same directory as ocean restarts
72      ! and are called TRIM(cn_ocerst)//'_icebergs'
[12472]73      cl_path = TRIM(cn_icbrst_indir)
[5341]74      IF( cl_path(LEN_TRIM(cl_path):) /= '/' ) cl_path = TRIM(cl_path) // '/'
[12472]75      cl_filename = TRIM(cn_icbrst_in)
[6140]76      CALL iom_open( TRIM(cl_path)//cl_filename, ncid )
[3614]77
[10065]78      imax_icb = 0
[6140]79      IF( iom_file(ncid)%iduld .GE. 0) THEN
[3614]80
[6140]81         ibergs_in_file = iom_file(ncid)%lenuld
82         DO jn = 1,ibergs_in_file
[3614]83
[6140]84            ! iom_get treats the unlimited dimension as time. Here the unlimited dimension
85            ! is the iceberg index, but we can still use the ktime keyword to get the iceberg we want.
[3614]86
[6140]87            CALL iom_get( ncid, 'xi'     ,localpt%xi  , ktime=jn )
88            CALL iom_get( ncid, 'yj'     ,localpt%yj  , ktime=jn )
[3614]89
[15088]90            ii = INT( localpt%xi + 0.5 ) + ( nn_hls-1 )
91            ij = INT( localpt%yj + 0.5 ) + ( nn_hls-1 )
[6140]92            ! Only proceed if this iceberg is on the local processor (excluding halos).
[13286]93            IF ( ii >= mig(Nis0) .AND. ii <= mig(Nie0) .AND.   &
94           &     ij >= mjg(Njs0) .AND. ij <= mjg(Nje0) ) THEN           
[3614]95
[13286]96               CALL iom_get( ncid, jpdom_unknown, 'number', zdata(:) , ktime=jn, kstart=(/1/), kcount=(/nkounts/) )
[6140]97               localberg%number(:) = INT(zdata(:))
[10065]98               imax_icb = MAX( imax_icb, INT(zdata(1)) )
[6140]99               CALL iom_get( ncid, 'mass_scaling' , localberg%mass_scaling, ktime=jn )
100               CALL iom_get( ncid, 'lon'          , localpt%lon           , ktime=jn )
101               CALL iom_get( ncid, 'lat'          , localpt%lat           , ktime=jn )
102               CALL iom_get( ncid, 'uvel'         , localpt%uvel          , ktime=jn )
103               CALL iom_get( ncid, 'vvel'         , localpt%vvel          , ktime=jn )
104               CALL iom_get( ncid, 'mass'         , localpt%mass          , ktime=jn )
105               CALL iom_get( ncid, 'thickness'    , localpt%thickness     , ktime=jn )
106               CALL iom_get( ncid, 'width'        , localpt%width         , ktime=jn )
107               CALL iom_get( ncid, 'length'       , localpt%length        , ktime=jn )
108               CALL iom_get( ncid, 'year'         , zdata(1)              , ktime=jn )
109               localpt%year = INT(zdata(1))
110               CALL iom_get( ncid, 'day'          , localpt%day           , ktime=jn )
111               CALL iom_get( ncid, 'mass_of_bits' , localpt%mass_of_bits  , ktime=jn )
112               CALL iom_get( ncid, 'heat_density' , localpt%heat_density  , ktime=jn )
113               !
114               CALL icb_utl_add( localberg, localpt )
[9190]115               !
[6140]116            ENDIF
[9190]117            !
[3614]118         END DO
[9190]119         !
[9932]120      ELSE
121         ibergs_in_file = 0
[6140]122      ENDIF 
[3614]123
[6140]124      ! Gridded variables
[13286]125      CALL iom_get( ncid, jpdom_auto,    'calving'     , src_calving  )
126      CALL iom_get( ncid, jpdom_auto,    'calving_hflx', src_calving_hflx  )
127      CALL iom_get( ncid, jpdom_auto,    'stored_heat' , berg_grid%stored_heat  )
128      ! with jpdom_auto_xy, ue use only the third element of kstart and kcount.
129      CALL iom_get( ncid, jpdom_auto_xy, 'stored_ice'  , berg_grid%stored_ice, kstart=(/-99,-99,1/), kcount=(/-99,-99,nclasses/) )
[6140]130     
[6623]131      CALL iom_get( ncid, jpdom_unknown, 'kount' , zdata(:) )
[6140]132      num_bergs(:) = INT(zdata(:))
[10065]133      !
[3614]134
[10065]135      ! Sanity checks
[3614]136      jn = icb_utl_count()
[9932]137      IF ( lwp .AND. nn_verbose_level >= 0 )   &
[3614]138         WRITE(numout,'(2(a,i5))') 'icebergs, read_restart_bergs: # bergs =',jn,' on PE',narea-1
139      IF( lk_mpp ) THEN
[6140]140         ! Only mpp_sum ibergs_in_file if we are reading from multiple restart files.
[10425]141         IF( INDEX(iom_file(ncid)%name,'icebergs.nc' ) .EQ. 0 ) CALL mpp_sum('icbrst', ibergs_in_file)
142         CALL mpp_sum('icbrst', jn)
[3614]143      ENDIF
[9932]144      IF( lwp )   WRITE(numout,'(a,i5,a,i5,a)') 'icebergs, icb_rst_read: there were',ibergs_in_file,   &
[3614]145         &                                    ' bergs in the restart file and', jn,' bergs have been read'
[11536]146      ! Close file
147      CALL iom_close( ncid )
[3614]148      !
[10065]149      ! Confirm that all areas have a suitable base for assigning new iceberg
150      ! numbers. This will not be the case if restarting from a collated dataset
151      ! (even if using the same processor decomposition)
[6140]152      !
[10065]153      ibase_err = 0
154      IF( num_bergs(1) < 0 .AND. num_bergs(1) /= narea - jpnij ) THEN
155         ! If this area has never calved a new berg then the base should be
156         ! set to narea - jpnij. If it is negative but something else then
157         ! a new base will be needed to guarantee unique, future iceberg numbers
158         ibase_err = 1
159      ELSEIF( MOD( num_bergs(1) - narea , jpnij ) /= 0 ) THEN
160         ! If this area has a base which is not in the set {narea + N*jpnij}
161         ! for positive integers N then a new base will be needed to guarantee
162         ! unique, future iceberg numbers
163         ibase_err = 1
164      ENDIF
165      IF( lk_mpp ) THEN
[10425]166         CALL mpp_sum('icbrst', ibase_err)
[10065]167      ENDIF
168      IF( ibase_err > 0 ) THEN
169         !
170         ! A new base is needed. The only secure solution is to set bases such that
171         ! all future icebergs numbers will be greater than the current global maximum
172         IF( lk_mpp ) THEN
[10425]173            CALL mpp_max('icbrst', imax_icb)
[10065]174         ENDIF
175         num_bergs(1) = imax_icb - jpnij + narea
176      ENDIF
177      !
[9932]178      IF( lwp .AND. nn_verbose_level >= 0 )  WRITE(numout,'(a)') 'icebergs, icb_rst_read: completed'
[3614]179      !
180   END SUBROUTINE icb_rst_read
181
182
183   SUBROUTINE icb_rst_write( kt )
184      !!----------------------------------------------------------------------
185      !!                 ***  SUBROUTINE icb_rst_write  ***
186      !!
187      !!----------------------------------------------------------------------
188      INTEGER, INTENT( in ) :: kt
189      !
190      INTEGER ::   jn   ! dummy loop index
[12933]191      INTEGER ::   idg  ! number of digits
[3614]192      INTEGER ::   ix_dim, iy_dim, ik_dim, in_dim
[5341]193      CHARACTER(len=256)     :: cl_path
[4990]194      CHARACTER(len=256)     :: cl_filename
[13062]195      CHARACTER(len=8  )     :: cl_kt
[12933]196      CHARACTER(LEN=12 )     :: clfmt            ! writing format
[3614]197      TYPE(iceberg), POINTER :: this
198      TYPE(point)  , POINTER :: pt
199      !!----------------------------------------------------------------------
200
[9932]201      ! Following the normal restart procedure, this routine will be called
202      ! the timestep before a restart stage as well as the restart timestep.
203      ! This is a performance step enabling the file to be opened and contents
204      ! defined in advance of the write. This is not possible with icebergs
205      ! since the number of bergs to be written could change between timesteps
206      IF( kt == nitrst ) THEN
207         ! Only operate on the restart timestep itself.
208         ! Assume we write iceberg restarts to same directory as ocean restarts.
[12472]209         !
210         ! directory name
211         cl_path = TRIM(cn_icbrst_outdir)
[9932]212         IF( cl_path(LEN_TRIM(cl_path):) /= '/' ) cl_path = TRIM(cl_path) // '/'
[12472]213         !
214         ! file name
215         WRITE(cl_kt, '(i8.8)') kt
[13062]216         cl_filename = TRIM(cexper)//"_"//cl_kt//"_"//TRIM(cn_icbrst_out)
[9932]217         IF( lk_mpp ) THEN
[13009]218            idg = MAX( INT(LOG10(REAL(MAX(1,jpnij-1),wp))) + 1, 4 )          ! how many digits to we need to write? min=4, max=9
219            WRITE(clfmt, "('(a,a,i', i1, '.', i1, ',a)')") idg, idg          ! '(a,a,ix.x,a)'
[13062]220            WRITE(cl_filename,  clfmt) TRIM(cl_filename), '_', narea-1, '.nc'
[9932]221         ELSE
[13062]222            WRITE(cl_filename,'(a,a)') TRIM(cl_filename),               '.nc'
[9932]223         ENDIF
[12472]224
[9932]225         IF ( lwp .AND. nn_verbose_level >= 0) WRITE(numout,'(2a)') 'icebergs, write_restart: creating ',  &
226           &                                                         TRIM(cl_path)//TRIM(cl_filename)
227   
228         nret = NF90_CREATE(TRIM(cl_path)//TRIM(cl_filename), NF90_CLOBBER, ncid)
229         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_create failed')
230   
231         ! Dimensions
[13286]232         nret = NF90_DEF_DIM(ncid, 'x', Ni_0, ix_dim)
[9932]233         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim x failed')
234   
[13286]235         nret = NF90_DEF_DIM(ncid, 'y', Nj_0, iy_dim)
[9932]236         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim y failed')
237   
238         nret = NF90_DEF_DIM(ncid, 'c', nclasses, nc_dim)
239         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim c failed')
240   
241         nret = NF90_DEF_DIM(ncid, 'k', nkounts, ik_dim)
242         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim k failed')
243   
244         ! global attributes
245         IF( lk_mpp ) THEN
246            ! Set domain parameters (assume jpdom_local_full)
[13286]247            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_number_total'   , jpnij                        )
248            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_number'         , narea-1                      )
249            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_dimensions_ids' , (/ 1         , 2          /) )
250            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_size_global'    , (/ Ni0glo    , Nj0glo     /) )
251            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_size_local'     , (/ Ni_0      , Nj_0       /) )
252            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_position_first' , (/ mig0(Nis0), mjg0(Njs0) /) )
253            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_position_last'  , (/ mig0(Nie0), mjg0(Nje0) /) )
254            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_halo_size_start', (/ 0         , 0          /) )
255            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_halo_size_end'  , (/ 0         , 0          /) )
256            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_type'           , 'BOX'                        )
[9932]257         ENDIF
258         
259         IF (associated(first_berg)) then
260            nret = NF90_DEF_DIM(ncid, 'n', NF90_UNLIMITED, in_dim)
261            IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim n failed')
262         ENDIF
263   
[3614]264         ! Variables
[9932]265         nret = NF90_DEF_VAR(ncid, 'kount'       , NF90_INT   , (/ ik_dim /), nkountid)
266         nret = NF90_DEF_VAR(ncid, 'calving'     , NF90_DOUBLE, (/ ix_dim, iy_dim /), ncalvid)
267         nret = NF90_DEF_VAR(ncid, 'calving_hflx', NF90_DOUBLE, (/ ix_dim, iy_dim /), ncalvhid)
268         nret = NF90_DEF_VAR(ncid, 'stored_ice'  , NF90_DOUBLE, (/ ix_dim, iy_dim, nc_dim /), nsiceid)
269         nret = NF90_DEF_VAR(ncid, 'stored_heat' , NF90_DOUBLE, (/ ix_dim, iy_dim /), nsheatid)
270   
[3614]271         ! Attributes
[9932]272         nret = NF90_PUT_ATT(ncid, ncalvid , 'long_name', 'iceberg calving')
273         nret = NF90_PUT_ATT(ncid, ncalvid , 'units', 'some')
274         nret = NF90_PUT_ATT(ncid, ncalvhid, 'long_name', 'heat flux associated with iceberg calving')
275         nret = NF90_PUT_ATT(ncid, ncalvhid, 'units', 'some')
276         nret = NF90_PUT_ATT(ncid, nsiceid , 'long_name', 'stored ice used to calve icebergs')
277         nret = NF90_PUT_ATT(ncid, nsiceid , 'units', 'kg/s')
278         nret = NF90_PUT_ATT(ncid, nsheatid, 'long_name', 'heat in stored ice used to calve icebergs')
279         nret = NF90_PUT_ATT(ncid, nsheatid, 'units', 'J/kg/s')
280   
281         IF ( ASSOCIATED(first_berg) ) THEN
282   
283            ! Only add berg variables for this PE if we have anything to say
284   
285            ! Variables
286            nret = NF90_DEF_VAR(ncid, 'lon', NF90_DOUBLE, in_dim, nlonid)
287            nret = NF90_DEF_VAR(ncid, 'lat', NF90_DOUBLE, in_dim, nlatid)
288            nret = NF90_DEF_VAR(ncid, 'xi', NF90_DOUBLE, in_dim, nxid)
289            nret = NF90_DEF_VAR(ncid, 'yj', NF90_DOUBLE, in_dim, nyid)
290            nret = NF90_DEF_VAR(ncid, 'uvel', NF90_DOUBLE, in_dim, nuvelid)
291            nret = NF90_DEF_VAR(ncid, 'vvel', NF90_DOUBLE, in_dim, nvvelid)
292            nret = NF90_DEF_VAR(ncid, 'mass', NF90_DOUBLE, in_dim, nmassid)
293            nret = NF90_DEF_VAR(ncid, 'thickness', NF90_DOUBLE, in_dim, nthicknessid)
294            nret = NF90_DEF_VAR(ncid, 'width', NF90_DOUBLE, in_dim, nwidthid)
295            nret = NF90_DEF_VAR(ncid, 'length', NF90_DOUBLE, in_dim, nlengthid)
296            nret = NF90_DEF_VAR(ncid, 'number', NF90_INT, (/ik_dim,in_dim/), numberid)
297            nret = NF90_DEF_VAR(ncid, 'year', NF90_INT, in_dim, nyearid)
298            nret = NF90_DEF_VAR(ncid, 'day', NF90_DOUBLE, in_dim, ndayid)
299            nret = NF90_DEF_VAR(ncid, 'mass_scaling', NF90_DOUBLE, in_dim, nscaling_id)
300            nret = NF90_DEF_VAR(ncid, 'mass_of_bits', NF90_DOUBLE, in_dim, nmass_of_bits_id)
301            nret = NF90_DEF_VAR(ncid, 'heat_density', NF90_DOUBLE, in_dim, nheat_density_id)
302   
303            ! Attributes
304            nret = NF90_PUT_ATT(ncid, nlonid, 'long_name', 'longitude')
305            nret = NF90_PUT_ATT(ncid, nlonid, 'units', 'degrees_E')
306            nret = NF90_PUT_ATT(ncid, nlatid, 'long_name', 'latitude')
307            nret = NF90_PUT_ATT(ncid, nlatid, 'units', 'degrees_N')
308            nret = NF90_PUT_ATT(ncid, nxid, 'long_name', 'x grid box position')
309            nret = NF90_PUT_ATT(ncid, nxid, 'units', 'fractional')
310            nret = NF90_PUT_ATT(ncid, nyid, 'long_name', 'y grid box position')
311            nret = NF90_PUT_ATT(ncid, nyid, 'units', 'fractional')
312            nret = NF90_PUT_ATT(ncid, nuvelid, 'long_name', 'zonal velocity')
313            nret = NF90_PUT_ATT(ncid, nuvelid, 'units', 'm/s')
314            nret = NF90_PUT_ATT(ncid, nvvelid, 'long_name', 'meridional velocity')
315            nret = NF90_PUT_ATT(ncid, nvvelid, 'units', 'm/s')
316            nret = NF90_PUT_ATT(ncid, nmassid, 'long_name', 'mass')
317            nret = NF90_PUT_ATT(ncid, nmassid, 'units', 'kg')
318            nret = NF90_PUT_ATT(ncid, nthicknessid, 'long_name', 'thickness')
319            nret = NF90_PUT_ATT(ncid, nthicknessid, 'units', 'm')
320            nret = NF90_PUT_ATT(ncid, nwidthid, 'long_name', 'width')
321            nret = NF90_PUT_ATT(ncid, nwidthid, 'units', 'm')
322            nret = NF90_PUT_ATT(ncid, nlengthid, 'long_name', 'length')
323            nret = NF90_PUT_ATT(ncid, nlengthid, 'units', 'm')
324            nret = NF90_PUT_ATT(ncid, numberid, 'long_name', 'iceberg number on this processor')
325            nret = NF90_PUT_ATT(ncid, numberid, 'units', 'count')
326            nret = NF90_PUT_ATT(ncid, nyearid, 'long_name', 'calendar year of calving event')
327            nret = NF90_PUT_ATT(ncid, nyearid, 'units', 'years')
328            nret = NF90_PUT_ATT(ncid, ndayid, 'long_name', 'year day of calving event')
329            nret = NF90_PUT_ATT(ncid, ndayid, 'units', 'days')
330            nret = NF90_PUT_ATT(ncid, nscaling_id, 'long_name', 'scaling factor for mass of calving berg')
331            nret = NF90_PUT_ATT(ncid, nscaling_id, 'units', 'none')
332            nret = NF90_PUT_ATT(ncid, nmass_of_bits_id, 'long_name', 'mass of bergy bits')
333            nret = NF90_PUT_ATT(ncid, nmass_of_bits_id, 'units', 'kg')
334            nret = NF90_PUT_ATT(ncid, nheat_density_id, 'long_name', 'heat density')
335            nret = NF90_PUT_ATT(ncid, nheat_density_id, 'units', 'J/kg')
336   
337         ENDIF ! associated(first_berg)
338   
339         ! End define mode
340         nret = NF90_ENDDEF(ncid)
341   
342         ! --------------------------------
343         ! now write some data
344   
345         nstrt3(1) = 1
346         nstrt3(2) = 1
[13286]347         nlngth3(1) = Ni_0
348         nlngth3(2) = Nj_0
[9932]349         nlngth3(3) = 1
350   
351         DO jn=1,nclasses
352            nstrt3(3) = jn
[13286]353            nret = NF90_PUT_VAR( ncid, nsiceid, berg_grid%stored_ice(Nis0:Nie0,Njs0:Nje0,jn), nstrt3, nlngth3 )
[9932]354            IF (nret .ne. NF90_NOERR) THEN
355               IF( lwp ) WRITE(numout,*) TRIM(NF90_STRERROR( nret ))
356               CALL ctl_stop('icebergs, write_restart: nf_put_var stored_ice failed')
357            ENDIF
358         ENDDO
359         IF( lwp ) WRITE(numout,*) 'file: ',TRIM(cl_path)//TRIM(cl_filename),' var: stored_ice  written'
360   
361         nret = NF90_PUT_VAR( ncid, nkountid, num_bergs(:) )
362         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_put_var kount failed')
363   
[13286]364         nret = NF90_PUT_VAR( ncid, nsheatid, berg_grid%stored_heat(Nis0:Nie0,Njs0:Nje0) )
[9932]365         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_put_var stored_heat failed')
366         IF( lwp ) WRITE(numout,*) 'file: ',TRIM(cl_path)//TRIM(cl_filename),' var: stored_heat written'
367   
[13286]368         nret = NF90_PUT_VAR( ncid, ncalvid , src_calving(Nis0:Nie0,Njs0:Nje0) )
[9932]369         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_put_var calving failed')
[13286]370         nret = NF90_PUT_VAR( ncid, ncalvhid, src_calving_hflx(Nis0:Nie0,Njs0:Nje0) )
[9932]371         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_put_var calving_hflx failed')
372         IF( lwp ) WRITE(numout,*) 'file: ',TRIM(cl_path)//TRIM(cl_filename),' var: calving written'
373   
374         IF ( ASSOCIATED(first_berg) ) THEN
375   
376            ! Write variables
377            ! just write out the current point of the trajectory
378   
379            this => first_berg
380            jn = 0
381            DO WHILE (ASSOCIATED(this))
382               pt => this%current_point
383               jn=jn+1
384   
385               nret = NF90_PUT_VAR(ncid, numberid, this%number, (/1,jn/), (/nkounts,1/) )
386               nret = NF90_PUT_VAR(ncid, nscaling_id, this%mass_scaling, (/ jn /) )
387   
388               nret = NF90_PUT_VAR(ncid, nlonid, pt%lon, (/ jn /) )
389               nret = NF90_PUT_VAR(ncid, nlatid, pt%lat, (/ jn /) )
390               nret = NF90_PUT_VAR(ncid, nxid, pt%xi, (/ jn /) )
391               nret = NF90_PUT_VAR(ncid, nyid, pt%yj, (/ jn /) )
392               nret = NF90_PUT_VAR(ncid, nuvelid, pt%uvel, (/ jn /) )
393               nret = NF90_PUT_VAR(ncid, nvvelid, pt%vvel, (/ jn /) )
394               nret = NF90_PUT_VAR(ncid, nmassid, pt%mass, (/ jn /) )
395               nret = NF90_PUT_VAR(ncid, nthicknessid, pt%thickness, (/ jn /) )
396               nret = NF90_PUT_VAR(ncid, nwidthid, pt%width, (/ jn /) )
397               nret = NF90_PUT_VAR(ncid, nlengthid, pt%length, (/ jn /) )
398               nret = NF90_PUT_VAR(ncid, nyearid, pt%year, (/ jn /) )
399               nret = NF90_PUT_VAR(ncid, ndayid, pt%day, (/ jn /) )
400               nret = NF90_PUT_VAR(ncid, nmass_of_bits_id, pt%mass_of_bits, (/ jn /) )
401               nret = NF90_PUT_VAR(ncid, nheat_density_id, pt%heat_density, (/ jn /) )
402   
403               this=>this%next
404            END DO
405            !
406         ENDIF ! associated(first_berg)
407   
408         ! Finish up
409         nret = NF90_CLOSE(ncid)
410         IF (nret /= NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_close failed')
411   
412         ! Sanity check
413         jn = icb_utl_count()
414         IF ( lwp .AND. nn_verbose_level >= 0)   &
415            WRITE(numout,'(2(a,i5))') 'icebergs, icb_rst_write: # bergs =',jn,' on PE',narea-1
416         IF( lk_mpp ) THEN
[10425]417            CALL mpp_sum('icbrst', jn)
[3614]418         ENDIF
[9932]419         IF(lwp)   WRITE(numout,'(a,i5,a,i5,a)') 'icebergs, icb_rst_write: ', jn,   &
420            &                                    ' bergs in total have been written at timestep ', kt
[3614]421         !
[9932]422         ! Finish up
423         !
424      ENDIF
[3614]425   END SUBROUTINE icb_rst_write
426   !
[9190]427   !!======================================================================
[3614]428END MODULE icbrst
Note: See TracBrowser for help on using the repository browser.