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/branches/2020/dev_r12953_ENHANCE-10_acc_fix_traqsr/src/OCE/ICB – NEMO

source: NEMO/branches/2020/dev_r12953_ENHANCE-10_acc_fix_traqsr/src/OCE/ICB/icbrst.F90 @ 13121

Last change on this file since 13121 was 13121, checked in by acc, 4 years ago

2020/dev_r12953_ENHANCE-10_acc_fix_traqsr. Merge in trunk changes from 12953 to current HEAD (13115). Fully SETTE tested

  • Property svn:keywords set to Id
File size: 22.3 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
[6140]90            ii = INT( localpt%xi + 0.5 )
91            ij = INT( localpt%yj + 0.5 )
92            ! Only proceed if this iceberg is on the local processor (excluding halos).
93            IF ( ii .GE. nldi+nimpp-1 .AND. ii .LE. nlei+nimpp-1 .AND. &
94           &     ij .GE. nldj+njmpp-1 .AND. ij .LE. nlej+njmpp-1 ) THEN           
[3614]95
[6623]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
125      CALL iom_get( ncid, jpdom_autoglo,    'calving'     , src_calving  )
126      CALL iom_get( ncid, jpdom_autoglo,    'calving_hflx', src_calving_hflx  )
127      CALL iom_get( ncid, jpdom_autoglo,    'stored_heat' , berg_grid%stored_heat  )
128      CALL iom_get( ncid, jpdom_autoglo_xy, 'stored_ice'  , berg_grid%stored_ice, kstart=(/1,1,1/), kcount=(/1,1,nclasses/) )
129     
[6623]130      CALL iom_get( ncid, jpdom_unknown, 'kount' , zdata(:) )
[6140]131      num_bergs(:) = INT(zdata(:))
[10065]132      !
[3614]133
[10065]134      ! Sanity checks
[3614]135      jn = icb_utl_count()
[9932]136      IF ( lwp .AND. nn_verbose_level >= 0 )   &
[3614]137         WRITE(numout,'(2(a,i5))') 'icebergs, read_restart_bergs: # bergs =',jn,' on PE',narea-1
138      IF( lk_mpp ) THEN
[6140]139         ! Only mpp_sum ibergs_in_file if we are reading from multiple restart files.
[10425]140         IF( INDEX(iom_file(ncid)%name,'icebergs.nc' ) .EQ. 0 ) CALL mpp_sum('icbrst', ibergs_in_file)
141         CALL mpp_sum('icbrst', jn)
[3614]142      ENDIF
[9932]143      IF( lwp )   WRITE(numout,'(a,i5,a,i5,a)') 'icebergs, icb_rst_read: there were',ibergs_in_file,   &
[3614]144         &                                    ' bergs in the restart file and', jn,' bergs have been read'
[11536]145      ! Close file
146      CALL iom_close( ncid )
[3614]147      !
[10065]148      ! Confirm that all areas have a suitable base for assigning new iceberg
149      ! numbers. This will not be the case if restarting from a collated dataset
150      ! (even if using the same processor decomposition)
[6140]151      !
[10065]152      ibase_err = 0
153      IF( num_bergs(1) < 0 .AND. num_bergs(1) /= narea - jpnij ) THEN
154         ! If this area has never calved a new berg then the base should be
155         ! set to narea - jpnij. If it is negative but something else then
156         ! a new base will be needed to guarantee unique, future iceberg numbers
157         ibase_err = 1
158      ELSEIF( MOD( num_bergs(1) - narea , jpnij ) /= 0 ) THEN
159         ! If this area has a base which is not in the set {narea + N*jpnij}
160         ! for positive integers N then a new base will be needed to guarantee
161         ! unique, future iceberg numbers
162         ibase_err = 1
163      ENDIF
164      IF( lk_mpp ) THEN
[10425]165         CALL mpp_sum('icbrst', ibase_err)
[10065]166      ENDIF
167      IF( ibase_err > 0 ) THEN
168         !
169         ! A new base is needed. The only secure solution is to set bases such that
170         ! all future icebergs numbers will be greater than the current global maximum
171         IF( lk_mpp ) THEN
[10425]172            CALL mpp_max('icbrst', imax_icb)
[10065]173         ENDIF
174         num_bergs(1) = imax_icb - jpnij + narea
175      ENDIF
176      !
[9932]177      IF( lwp .AND. nn_verbose_level >= 0 )  WRITE(numout,'(a)') 'icebergs, icb_rst_read: completed'
[3614]178      !
179   END SUBROUTINE icb_rst_read
180
181
182   SUBROUTINE icb_rst_write( kt )
183      !!----------------------------------------------------------------------
184      !!                 ***  SUBROUTINE icb_rst_write  ***
185      !!
186      !!----------------------------------------------------------------------
187      INTEGER, INTENT( in ) :: kt
188      !
189      INTEGER ::   jn   ! dummy loop index
[12933]190      INTEGER ::   idg  ! number of digits
[3614]191      INTEGER ::   ix_dim, iy_dim, ik_dim, in_dim
[5341]192      CHARACTER(len=256)     :: cl_path
[4990]193      CHARACTER(len=256)     :: cl_filename
[13121]194      CHARACTER(len=8  )     :: cl_kt
[12933]195      CHARACTER(LEN=12 )     :: clfmt            ! writing format
[3614]196      TYPE(iceberg), POINTER :: this
197      TYPE(point)  , POINTER :: pt
198      !!----------------------------------------------------------------------
199
[9932]200      ! Following the normal restart procedure, this routine will be called
201      ! the timestep before a restart stage as well as the restart timestep.
202      ! This is a performance step enabling the file to be opened and contents
203      ! defined in advance of the write. This is not possible with icebergs
204      ! since the number of bergs to be written could change between timesteps
205      IF( kt == nitrst ) THEN
206         ! Only operate on the restart timestep itself.
207         ! Assume we write iceberg restarts to same directory as ocean restarts.
[12472]208         !
209         ! directory name
210         cl_path = TRIM(cn_icbrst_outdir)
[9932]211         IF( cl_path(LEN_TRIM(cl_path):) /= '/' ) cl_path = TRIM(cl_path) // '/'
[12472]212         !
213         ! file name
214         WRITE(cl_kt, '(i8.8)') kt
[13121]215         cl_filename = TRIM(cexper)//"_"//cl_kt//"_"//TRIM(cn_icbrst_out)
[9932]216         IF( lk_mpp ) THEN
[13121]217            idg = MAX( INT(LOG10(REAL(MAX(1,jpnij-1),wp))) + 1, 4 )          ! how many digits to we need to write? min=4, max=9
218            WRITE(clfmt, "('(a,a,i', i1, '.', i1, ',a)')") idg, idg          ! '(a,a,ix.x,a)'
219            WRITE(cl_filename,  clfmt) TRIM(cl_filename), '_', narea-1, '.nc'
[9932]220         ELSE
[13121]221            WRITE(cl_filename,'(a,a)') TRIM(cl_filename),               '.nc'
[9932]222         ENDIF
[12472]223
[9932]224         IF ( lwp .AND. nn_verbose_level >= 0) WRITE(numout,'(2a)') 'icebergs, write_restart: creating ',  &
225           &                                                         TRIM(cl_path)//TRIM(cl_filename)
226   
227         nret = NF90_CREATE(TRIM(cl_path)//TRIM(cl_filename), NF90_CLOBBER, ncid)
228         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_create failed')
229   
230         ! Dimensions
231         nret = NF90_DEF_DIM(ncid, 'x', jpi, ix_dim)
232         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim x failed')
233   
234         nret = NF90_DEF_DIM(ncid, 'y', jpj, iy_dim)
235         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim y failed')
236   
237         nret = NF90_DEF_DIM(ncid, 'c', nclasses, nc_dim)
238         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim c failed')
239   
240         nret = NF90_DEF_DIM(ncid, 'k', nkounts, ik_dim)
241         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim k failed')
242   
243         ! global attributes
244         IF( lk_mpp ) THEN
245            ! Set domain parameters (assume jpdom_local_full)
246            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_number_total'   , jpnij              )
247            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_number'         , narea-1            )
248            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_dimensions_ids' , (/1     , 2     /) )
249            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_size_global'    , (/jpiglo, jpjglo/) )
250            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_size_local'     , (/jpi   , jpj   /) )
251            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_position_first' , (/nimpp , njmpp /) )
252            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_position_last'  , (/nimpp + jpi - 1 , njmpp + jpj - 1  /) )
253            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_halo_size_start', (/nldi - 1        , nldj - 1         /) )
254            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_halo_size_end'  , (/jpi - nlei      , jpj - nlej       /) )
255            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_type'           , 'BOX'              )
256         ENDIF
257         
258         IF (associated(first_berg)) then
259            nret = NF90_DEF_DIM(ncid, 'n', NF90_UNLIMITED, in_dim)
260            IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim n failed')
261         ENDIF
262   
[3614]263         ! Variables
[9932]264         nret = NF90_DEF_VAR(ncid, 'kount'       , NF90_INT   , (/ ik_dim /), nkountid)
265         nret = NF90_DEF_VAR(ncid, 'calving'     , NF90_DOUBLE, (/ ix_dim, iy_dim /), ncalvid)
266         nret = NF90_DEF_VAR(ncid, 'calving_hflx', NF90_DOUBLE, (/ ix_dim, iy_dim /), ncalvhid)
267         nret = NF90_DEF_VAR(ncid, 'stored_ice'  , NF90_DOUBLE, (/ ix_dim, iy_dim, nc_dim /), nsiceid)
268         nret = NF90_DEF_VAR(ncid, 'stored_heat' , NF90_DOUBLE, (/ ix_dim, iy_dim /), nsheatid)
269   
[3614]270         ! Attributes
[9932]271         nret = NF90_PUT_ATT(ncid, ncalvid , 'long_name', 'iceberg calving')
272         nret = NF90_PUT_ATT(ncid, ncalvid , 'units', 'some')
273         nret = NF90_PUT_ATT(ncid, ncalvhid, 'long_name', 'heat flux associated with iceberg calving')
274         nret = NF90_PUT_ATT(ncid, ncalvhid, 'units', 'some')
275         nret = NF90_PUT_ATT(ncid, nsiceid , 'long_name', 'stored ice used to calve icebergs')
276         nret = NF90_PUT_ATT(ncid, nsiceid , 'units', 'kg/s')
277         nret = NF90_PUT_ATT(ncid, nsheatid, 'long_name', 'heat in stored ice used to calve icebergs')
278         nret = NF90_PUT_ATT(ncid, nsheatid, 'units', 'J/kg/s')
279   
280         IF ( ASSOCIATED(first_berg) ) THEN
281   
282            ! Only add berg variables for this PE if we have anything to say
283   
284            ! Variables
285            nret = NF90_DEF_VAR(ncid, 'lon', NF90_DOUBLE, in_dim, nlonid)
286            nret = NF90_DEF_VAR(ncid, 'lat', NF90_DOUBLE, in_dim, nlatid)
287            nret = NF90_DEF_VAR(ncid, 'xi', NF90_DOUBLE, in_dim, nxid)
288            nret = NF90_DEF_VAR(ncid, 'yj', NF90_DOUBLE, in_dim, nyid)
289            nret = NF90_DEF_VAR(ncid, 'uvel', NF90_DOUBLE, in_dim, nuvelid)
290            nret = NF90_DEF_VAR(ncid, 'vvel', NF90_DOUBLE, in_dim, nvvelid)
291            nret = NF90_DEF_VAR(ncid, 'mass', NF90_DOUBLE, in_dim, nmassid)
292            nret = NF90_DEF_VAR(ncid, 'thickness', NF90_DOUBLE, in_dim, nthicknessid)
293            nret = NF90_DEF_VAR(ncid, 'width', NF90_DOUBLE, in_dim, nwidthid)
294            nret = NF90_DEF_VAR(ncid, 'length', NF90_DOUBLE, in_dim, nlengthid)
295            nret = NF90_DEF_VAR(ncid, 'number', NF90_INT, (/ik_dim,in_dim/), numberid)
296            nret = NF90_DEF_VAR(ncid, 'year', NF90_INT, in_dim, nyearid)
297            nret = NF90_DEF_VAR(ncid, 'day', NF90_DOUBLE, in_dim, ndayid)
298            nret = NF90_DEF_VAR(ncid, 'mass_scaling', NF90_DOUBLE, in_dim, nscaling_id)
299            nret = NF90_DEF_VAR(ncid, 'mass_of_bits', NF90_DOUBLE, in_dim, nmass_of_bits_id)
300            nret = NF90_DEF_VAR(ncid, 'heat_density', NF90_DOUBLE, in_dim, nheat_density_id)
301   
302            ! Attributes
303            nret = NF90_PUT_ATT(ncid, nlonid, 'long_name', 'longitude')
304            nret = NF90_PUT_ATT(ncid, nlonid, 'units', 'degrees_E')
305            nret = NF90_PUT_ATT(ncid, nlatid, 'long_name', 'latitude')
306            nret = NF90_PUT_ATT(ncid, nlatid, 'units', 'degrees_N')
307            nret = NF90_PUT_ATT(ncid, nxid, 'long_name', 'x grid box position')
308            nret = NF90_PUT_ATT(ncid, nxid, 'units', 'fractional')
309            nret = NF90_PUT_ATT(ncid, nyid, 'long_name', 'y grid box position')
310            nret = NF90_PUT_ATT(ncid, nyid, 'units', 'fractional')
311            nret = NF90_PUT_ATT(ncid, nuvelid, 'long_name', 'zonal velocity')
312            nret = NF90_PUT_ATT(ncid, nuvelid, 'units', 'm/s')
313            nret = NF90_PUT_ATT(ncid, nvvelid, 'long_name', 'meridional velocity')
314            nret = NF90_PUT_ATT(ncid, nvvelid, 'units', 'm/s')
315            nret = NF90_PUT_ATT(ncid, nmassid, 'long_name', 'mass')
316            nret = NF90_PUT_ATT(ncid, nmassid, 'units', 'kg')
317            nret = NF90_PUT_ATT(ncid, nthicknessid, 'long_name', 'thickness')
318            nret = NF90_PUT_ATT(ncid, nthicknessid, 'units', 'm')
319            nret = NF90_PUT_ATT(ncid, nwidthid, 'long_name', 'width')
320            nret = NF90_PUT_ATT(ncid, nwidthid, 'units', 'm')
321            nret = NF90_PUT_ATT(ncid, nlengthid, 'long_name', 'length')
322            nret = NF90_PUT_ATT(ncid, nlengthid, 'units', 'm')
323            nret = NF90_PUT_ATT(ncid, numberid, 'long_name', 'iceberg number on this processor')
324            nret = NF90_PUT_ATT(ncid, numberid, 'units', 'count')
325            nret = NF90_PUT_ATT(ncid, nyearid, 'long_name', 'calendar year of calving event')
326            nret = NF90_PUT_ATT(ncid, nyearid, 'units', 'years')
327            nret = NF90_PUT_ATT(ncid, ndayid, 'long_name', 'year day of calving event')
328            nret = NF90_PUT_ATT(ncid, ndayid, 'units', 'days')
329            nret = NF90_PUT_ATT(ncid, nscaling_id, 'long_name', 'scaling factor for mass of calving berg')
330            nret = NF90_PUT_ATT(ncid, nscaling_id, 'units', 'none')
331            nret = NF90_PUT_ATT(ncid, nmass_of_bits_id, 'long_name', 'mass of bergy bits')
332            nret = NF90_PUT_ATT(ncid, nmass_of_bits_id, 'units', 'kg')
333            nret = NF90_PUT_ATT(ncid, nheat_density_id, 'long_name', 'heat density')
334            nret = NF90_PUT_ATT(ncid, nheat_density_id, 'units', 'J/kg')
335   
336         ENDIF ! associated(first_berg)
337   
338         ! End define mode
339         nret = NF90_ENDDEF(ncid)
340   
341         ! --------------------------------
342         ! now write some data
343   
344         nstrt3(1) = 1
345         nstrt3(2) = 1
346         nlngth3(1) = jpi
347         nlngth3(2) = jpj
348         nlngth3(3) = 1
349   
350         DO jn=1,nclasses
351            griddata(:,:,1) = berg_grid%stored_ice(:,:,jn)
352            nstrt3(3) = jn
353            nret = NF90_PUT_VAR( ncid, nsiceid, griddata, nstrt3, nlngth3 )
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   
364         nret = NF90_PUT_VAR( ncid, nsheatid, berg_grid%stored_heat(:,:) )
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   
368         nret = NF90_PUT_VAR( ncid, ncalvid , src_calving(:,:) )
369         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_put_var calving failed')
370         nret = NF90_PUT_VAR( ncid, ncalvhid, src_calving_hflx(:,:) )
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.