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_r12558_HPC-08_epico_Extra_Halo/src/OCE/ICB – NEMO

source: NEMO/branches/2020/dev_r12558_HPC-08_epico_Extra_Halo/src/OCE/ICB/icbrst.F90 @ 12807

Last change on this file since 12807 was 12807, checked in by smasson, 4 years ago

Extra_Halo: input file only over inner domain + new variables names, see #2366

  • Property svn:keywords set to Id
File size: 22.0 KB
Line 
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
13   !!            -    !  2015-11  Dave Storkey     Convert icb_rst_read to use IOM so can
14   !!                                              read single restart files
15   !!----------------------------------------------------------------------
16
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
26   USE iom
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   !!----------------------------------------------------------------------
46   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
47   !! $Id$
48   !! Software governed by the CeCILL license (see ./LICENSE)
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
62      INTEGER                      ::   ii, ij, iclass, ibase_err, imax_icb
63      REAL(wp), DIMENSION(nkounts) ::   zdata     
64      LOGICAL                      ::   ll_found_restart
65      CHARACTER(len=256)           ::   cl_path
66      CHARACTER(len=256)           ::   cl_filename
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      !!----------------------------------------------------------------------
71      ! Find a restart file. Assume iceberg restarts in same directory as ocean restarts
72      ! and are called TRIM(cn_ocerst)//'_icebergs'
73      cl_path = TRIM(cn_icbrst_indir)
74      IF( cl_path(LEN_TRIM(cl_path):) /= '/' ) cl_path = TRIM(cl_path) // '/'
75      cl_filename = TRIM(cn_icbrst_in)
76      CALL iom_open( TRIM(cl_path)//cl_filename, ncid )
77
78      imax_icb = 0
79      IF( iom_file(ncid)%iduld .GE. 0) THEN
80
81         ibergs_in_file = iom_file(ncid)%lenuld
82         DO jn = 1,ibergs_in_file
83
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.
86
87            CALL iom_get( ncid, 'xi'     ,localpt%xi  , ktime=jn )
88            CALL iom_get( ncid, 'yj'     ,localpt%yj  , ktime=jn )
89
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 >= mig(Nis0) .AND. ii <= mig(Nie0) .AND.   &
94           &     ij >= mjg(Njs0) .AND. ij <= mjg(Nje0) ) THEN           
95
96               CALL iom_get( ncid, jpdom_unknown, 'number', zdata(:) , ktime=jn, kstart=(/1/), kcount=(/nkounts/) )
97               localberg%number(:) = INT(zdata(:))
98               imax_icb = MAX( imax_icb, INT(zdata(1)) )
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 )
115               !
116            ENDIF
117            !
118         END DO
119         !
120      ELSE
121         ibergs_in_file = 0
122      ENDIF 
123
124      ! Gridded variables
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/) )
130     
131      CALL iom_get( ncid, jpdom_unknown, 'kount' , zdata(:) )
132      num_bergs(:) = INT(zdata(:))
133      !
134
135      ! Sanity checks
136      jn = icb_utl_count()
137      IF ( lwp .AND. nn_verbose_level >= 0 )   &
138         WRITE(numout,'(2(a,i5))') 'icebergs, read_restart_bergs: # bergs =',jn,' on PE',narea-1
139      IF( lk_mpp ) THEN
140         ! Only mpp_sum ibergs_in_file if we are reading from multiple restart files.
141         IF( INDEX(iom_file(ncid)%name,'icebergs.nc' ) .EQ. 0 ) CALL mpp_sum('icbrst', ibergs_in_file)
142         CALL mpp_sum('icbrst', jn)
143      ENDIF
144      IF( lwp )   WRITE(numout,'(a,i5,a,i5,a)') 'icebergs, icb_rst_read: there were',ibergs_in_file,   &
145         &                                    ' bergs in the restart file and', jn,' bergs have been read'
146      ! Close file
147      CALL iom_close( ncid )
148      !
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)
152      !
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
166         CALL mpp_sum('icbrst', ibase_err)
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
173            CALL mpp_max('icbrst', imax_icb)
174         ENDIF
175         num_bergs(1) = imax_icb - jpnij + narea
176      ENDIF
177      !
178      IF( lwp .AND. nn_verbose_level >= 0 )  WRITE(numout,'(a)') 'icebergs, icb_rst_read: completed'
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
191      INTEGER ::   ix_dim, iy_dim, ik_dim, in_dim
192      CHARACTER(len=256)     :: cl_path
193      CHARACTER(len=256)     :: cl_filename
194      CHARACTER(len=256)     :: cl_kt
195      TYPE(iceberg), POINTER :: this
196      TYPE(point)  , POINTER :: pt
197      !!----------------------------------------------------------------------
198
199      ! Following the normal restart procedure, this routine will be called
200      ! the timestep before a restart stage as well as the restart timestep.
201      ! This is a performance step enabling the file to be opened and contents
202      ! defined in advance of the write. This is not possible with icebergs
203      ! since the number of bergs to be written could change between timesteps
204      IF( kt == nitrst ) THEN
205         ! Only operate on the restart timestep itself.
206         ! Assume we write iceberg restarts to same directory as ocean restarts.
207         !
208         ! directory name
209         cl_path = TRIM(cn_icbrst_outdir)
210         IF( cl_path(LEN_TRIM(cl_path):) /= '/' ) cl_path = TRIM(cl_path) // '/'
211         !
212         ! file name
213         WRITE(cl_kt, '(i8.8)') kt
214         cl_filename = TRIM(cexper)//"_"//TRIM(ADJUSTL(cl_kt))//"_"//TRIM(cn_icbrst_out)
215         IF( lk_mpp ) THEN
216            WRITE(cl_filename,'(A,"_",I4.4,".nc")') TRIM(cl_filename), narea-1
217         ELSE
218            WRITE(cl_filename,'(A,".nc")') TRIM(cl_filename)
219         ENDIF
220
221         IF ( lwp .AND. nn_verbose_level >= 0) WRITE(numout,'(2a)') 'icebergs, write_restart: creating ',  &
222           &                                                         TRIM(cl_path)//TRIM(cl_filename)
223   
224         nret = NF90_CREATE(TRIM(cl_path)//TRIM(cl_filename), NF90_CLOBBER, ncid)
225         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_create failed')
226   
227         ! Dimensions
228         nret = NF90_DEF_DIM(ncid, 'x', Ni_0, ix_dim)
229         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim x failed')
230   
231         nret = NF90_DEF_DIM(ncid, 'y', Nj_0, iy_dim)
232         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim y failed')
233   
234         nret = NF90_DEF_DIM(ncid, 'c', nclasses, nc_dim)
235         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim c failed')
236   
237         nret = NF90_DEF_DIM(ncid, 'k', nkounts, ik_dim)
238         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim k failed')
239   
240         ! global attributes
241         IF( lk_mpp ) THEN
242            ! Set domain parameters (assume jpdom_local_full)
243            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_number_total'   , jpnij              )
244            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_number'         , narea-1            )
245            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_dimensions_ids' , (/ 1        , 2         /) )
246            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_size_global'    , (/ jpiglo   , jpjglo    /) )
247            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_size_local'     , (/ Ni_0     , Nj_0      /) )
248            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_position_first' , (/ mig(Nis0), mjg(Njs0) /) )
249            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_position_last'  , (/ mig(Nie0), mjg(Nje0) /) )
250            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_halo_size_start', (/ 0        , 0         /) )
251            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_halo_size_end'  , (/ 0        , 0         /) )
252            nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_type'           , 'BOX'              )
253         ENDIF
254         
255         IF (associated(first_berg)) then
256            nret = NF90_DEF_DIM(ncid, 'n', NF90_UNLIMITED, in_dim)
257            IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim n failed')
258         ENDIF
259   
260         ! Variables
261         nret = NF90_DEF_VAR(ncid, 'kount'       , NF90_INT   , (/ ik_dim /), nkountid)
262         nret = NF90_DEF_VAR(ncid, 'calving'     , NF90_DOUBLE, (/ ix_dim, iy_dim /), ncalvid)
263         nret = NF90_DEF_VAR(ncid, 'calving_hflx', NF90_DOUBLE, (/ ix_dim, iy_dim /), ncalvhid)
264         nret = NF90_DEF_VAR(ncid, 'stored_ice'  , NF90_DOUBLE, (/ ix_dim, iy_dim, nc_dim /), nsiceid)
265         nret = NF90_DEF_VAR(ncid, 'stored_heat' , NF90_DOUBLE, (/ ix_dim, iy_dim /), nsheatid)
266   
267         ! Attributes
268         nret = NF90_PUT_ATT(ncid, ncalvid , 'long_name', 'iceberg calving')
269         nret = NF90_PUT_ATT(ncid, ncalvid , 'units', 'some')
270         nret = NF90_PUT_ATT(ncid, ncalvhid, 'long_name', 'heat flux associated with iceberg calving')
271         nret = NF90_PUT_ATT(ncid, ncalvhid, 'units', 'some')
272         nret = NF90_PUT_ATT(ncid, nsiceid , 'long_name', 'stored ice used to calve icebergs')
273         nret = NF90_PUT_ATT(ncid, nsiceid , 'units', 'kg/s')
274         nret = NF90_PUT_ATT(ncid, nsheatid, 'long_name', 'heat in stored ice used to calve icebergs')
275         nret = NF90_PUT_ATT(ncid, nsheatid, 'units', 'J/kg/s')
276   
277         IF ( ASSOCIATED(first_berg) ) THEN
278   
279            ! Only add berg variables for this PE if we have anything to say
280   
281            ! Variables
282            nret = NF90_DEF_VAR(ncid, 'lon', NF90_DOUBLE, in_dim, nlonid)
283            nret = NF90_DEF_VAR(ncid, 'lat', NF90_DOUBLE, in_dim, nlatid)
284            nret = NF90_DEF_VAR(ncid, 'xi', NF90_DOUBLE, in_dim, nxid)
285            nret = NF90_DEF_VAR(ncid, 'yj', NF90_DOUBLE, in_dim, nyid)
286            nret = NF90_DEF_VAR(ncid, 'uvel', NF90_DOUBLE, in_dim, nuvelid)
287            nret = NF90_DEF_VAR(ncid, 'vvel', NF90_DOUBLE, in_dim, nvvelid)
288            nret = NF90_DEF_VAR(ncid, 'mass', NF90_DOUBLE, in_dim, nmassid)
289            nret = NF90_DEF_VAR(ncid, 'thickness', NF90_DOUBLE, in_dim, nthicknessid)
290            nret = NF90_DEF_VAR(ncid, 'width', NF90_DOUBLE, in_dim, nwidthid)
291            nret = NF90_DEF_VAR(ncid, 'length', NF90_DOUBLE, in_dim, nlengthid)
292            nret = NF90_DEF_VAR(ncid, 'number', NF90_INT, (/ik_dim,in_dim/), numberid)
293            nret = NF90_DEF_VAR(ncid, 'year', NF90_INT, in_dim, nyearid)
294            nret = NF90_DEF_VAR(ncid, 'day', NF90_DOUBLE, in_dim, ndayid)
295            nret = NF90_DEF_VAR(ncid, 'mass_scaling', NF90_DOUBLE, in_dim, nscaling_id)
296            nret = NF90_DEF_VAR(ncid, 'mass_of_bits', NF90_DOUBLE, in_dim, nmass_of_bits_id)
297            nret = NF90_DEF_VAR(ncid, 'heat_density', NF90_DOUBLE, in_dim, nheat_density_id)
298   
299            ! Attributes
300            nret = NF90_PUT_ATT(ncid, nlonid, 'long_name', 'longitude')
301            nret = NF90_PUT_ATT(ncid, nlonid, 'units', 'degrees_E')
302            nret = NF90_PUT_ATT(ncid, nlatid, 'long_name', 'latitude')
303            nret = NF90_PUT_ATT(ncid, nlatid, 'units', 'degrees_N')
304            nret = NF90_PUT_ATT(ncid, nxid, 'long_name', 'x grid box position')
305            nret = NF90_PUT_ATT(ncid, nxid, 'units', 'fractional')
306            nret = NF90_PUT_ATT(ncid, nyid, 'long_name', 'y grid box position')
307            nret = NF90_PUT_ATT(ncid, nyid, 'units', 'fractional')
308            nret = NF90_PUT_ATT(ncid, nuvelid, 'long_name', 'zonal velocity')
309            nret = NF90_PUT_ATT(ncid, nuvelid, 'units', 'm/s')
310            nret = NF90_PUT_ATT(ncid, nvvelid, 'long_name', 'meridional velocity')
311            nret = NF90_PUT_ATT(ncid, nvvelid, 'units', 'm/s')
312            nret = NF90_PUT_ATT(ncid, nmassid, 'long_name', 'mass')
313            nret = NF90_PUT_ATT(ncid, nmassid, 'units', 'kg')
314            nret = NF90_PUT_ATT(ncid, nthicknessid, 'long_name', 'thickness')
315            nret = NF90_PUT_ATT(ncid, nthicknessid, 'units', 'm')
316            nret = NF90_PUT_ATT(ncid, nwidthid, 'long_name', 'width')
317            nret = NF90_PUT_ATT(ncid, nwidthid, 'units', 'm')
318            nret = NF90_PUT_ATT(ncid, nlengthid, 'long_name', 'length')
319            nret = NF90_PUT_ATT(ncid, nlengthid, 'units', 'm')
320            nret = NF90_PUT_ATT(ncid, numberid, 'long_name', 'iceberg number on this processor')
321            nret = NF90_PUT_ATT(ncid, numberid, 'units', 'count')
322            nret = NF90_PUT_ATT(ncid, nyearid, 'long_name', 'calendar year of calving event')
323            nret = NF90_PUT_ATT(ncid, nyearid, 'units', 'years')
324            nret = NF90_PUT_ATT(ncid, ndayid, 'long_name', 'year day of calving event')
325            nret = NF90_PUT_ATT(ncid, ndayid, 'units', 'days')
326            nret = NF90_PUT_ATT(ncid, nscaling_id, 'long_name', 'scaling factor for mass of calving berg')
327            nret = NF90_PUT_ATT(ncid, nscaling_id, 'units', 'none')
328            nret = NF90_PUT_ATT(ncid, nmass_of_bits_id, 'long_name', 'mass of bergy bits')
329            nret = NF90_PUT_ATT(ncid, nmass_of_bits_id, 'units', 'kg')
330            nret = NF90_PUT_ATT(ncid, nheat_density_id, 'long_name', 'heat density')
331            nret = NF90_PUT_ATT(ncid, nheat_density_id, 'units', 'J/kg')
332   
333         ENDIF ! associated(first_berg)
334   
335         ! End define mode
336         nret = NF90_ENDDEF(ncid)
337   
338         ! --------------------------------
339         ! now write some data
340   
341         nstrt3(1) = 1
342         nstrt3(2) = 1
343         nlngth3(1) = Ni_0
344         nlngth3(2) = Nj_0
345         nlngth3(3) = 1
346   
347         DO jn=1,nclasses
348            nstrt3(3) = jn
349            nret = NF90_PUT_VAR( ncid, nsiceid, berg_grid%stored_ice(Nis0:Nie0,Njs0:Nje0,jn), nstrt3, nlngth3 )
350            IF (nret .ne. NF90_NOERR) THEN
351               IF( lwp ) WRITE(numout,*) TRIM(NF90_STRERROR( nret ))
352               CALL ctl_stop('icebergs, write_restart: nf_put_var stored_ice failed')
353            ENDIF
354         ENDDO
355         IF( lwp ) WRITE(numout,*) 'file: ',TRIM(cl_path)//TRIM(cl_filename),' var: stored_ice  written'
356   
357         nret = NF90_PUT_VAR( ncid, nkountid, num_bergs(:) )
358         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_put_var kount failed')
359   
360         nret = NF90_PUT_VAR( ncid, nsheatid, berg_grid%stored_heat(Nis0:Nie0,Njs0:Nje0) )
361         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_put_var stored_heat failed')
362         IF( lwp ) WRITE(numout,*) 'file: ',TRIM(cl_path)//TRIM(cl_filename),' var: stored_heat written'
363   
364         nret = NF90_PUT_VAR( ncid, ncalvid , src_calving(Nis0:Nie0,Njs0:Nje0) )
365         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_put_var calving failed')
366         nret = NF90_PUT_VAR( ncid, ncalvhid, src_calving_hflx(Nis0:Nie0,Njs0:Nje0) )
367         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_put_var calving_hflx failed')
368         IF( lwp ) WRITE(numout,*) 'file: ',TRIM(cl_path)//TRIM(cl_filename),' var: calving written'
369   
370         IF ( ASSOCIATED(first_berg) ) THEN
371   
372            ! Write variables
373            ! just write out the current point of the trajectory
374   
375            this => first_berg
376            jn = 0
377            DO WHILE (ASSOCIATED(this))
378               pt => this%current_point
379               jn=jn+1
380   
381               nret = NF90_PUT_VAR(ncid, numberid, this%number, (/1,jn/), (/nkounts,1/) )
382               nret = NF90_PUT_VAR(ncid, nscaling_id, this%mass_scaling, (/ jn /) )
383   
384               nret = NF90_PUT_VAR(ncid, nlonid, pt%lon, (/ jn /) )
385               nret = NF90_PUT_VAR(ncid, nlatid, pt%lat, (/ jn /) )
386               nret = NF90_PUT_VAR(ncid, nxid, pt%xi, (/ jn /) )
387               nret = NF90_PUT_VAR(ncid, nyid, pt%yj, (/ jn /) )
388               nret = NF90_PUT_VAR(ncid, nuvelid, pt%uvel, (/ jn /) )
389               nret = NF90_PUT_VAR(ncid, nvvelid, pt%vvel, (/ jn /) )
390               nret = NF90_PUT_VAR(ncid, nmassid, pt%mass, (/ jn /) )
391               nret = NF90_PUT_VAR(ncid, nthicknessid, pt%thickness, (/ jn /) )
392               nret = NF90_PUT_VAR(ncid, nwidthid, pt%width, (/ jn /) )
393               nret = NF90_PUT_VAR(ncid, nlengthid, pt%length, (/ jn /) )
394               nret = NF90_PUT_VAR(ncid, nyearid, pt%year, (/ jn /) )
395               nret = NF90_PUT_VAR(ncid, ndayid, pt%day, (/ jn /) )
396               nret = NF90_PUT_VAR(ncid, nmass_of_bits_id, pt%mass_of_bits, (/ jn /) )
397               nret = NF90_PUT_VAR(ncid, nheat_density_id, pt%heat_density, (/ jn /) )
398   
399               this=>this%next
400            END DO
401            !
402         ENDIF ! associated(first_berg)
403   
404         ! Finish up
405         nret = NF90_CLOSE(ncid)
406         IF (nret /= NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_close failed')
407   
408         ! Sanity check
409         jn = icb_utl_count()
410         IF ( lwp .AND. nn_verbose_level >= 0)   &
411            WRITE(numout,'(2(a,i5))') 'icebergs, icb_rst_write: # bergs =',jn,' on PE',narea-1
412         IF( lk_mpp ) THEN
413            CALL mpp_sum('icbrst', jn)
414         ENDIF
415         IF(lwp)   WRITE(numout,'(a,i5,a,i5,a)') 'icebergs, icb_rst_write: ', jn,   &
416            &                                    ' bergs in total have been written at timestep ', kt
417         !
418         ! Finish up
419         !
420      ENDIF
421   END SUBROUTINE icb_rst_write
422   !
423   !!======================================================================
424END MODULE icbrst
Note: See TracBrowser for help on using the repository browser.