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 branches/2014/dev_r4650_UKMO14.5_SST_BIAS_CORRECTION/NEMOGCM/NEMO/OPA_SRC/ICB – NEMO

source: branches/2014/dev_r4650_UKMO14.5_SST_BIAS_CORRECTION/NEMOGCM/NEMO/OPA_SRC/ICB/icbrst.F90 @ 5967

Last change on this file since 5967 was 5967, checked in by timgraham, 8 years ago

Reset keywords before merging with head of trunk

  • Property svn:keywords set to Id
File size: 21.5 KB
Line 
1MODULE icbrst
2
3   !!======================================================================
4   !!                       ***  MODULE  icbrst  ***
5   !! Ocean physics:  read and write iceberg restart files
6   !!======================================================================
7   !! History : 3.3.1 !  2010-01  (Martin&Adcroft) Original code
8   !!            -    !  2011-03  (Madec)          Part conversion to NEMO form
9   !!            -    !                            Removal of mapping from another grid
10   !!            -    !  2011-04  (Alderson)       Split into separate modules
11   !!            -    !  2011-04  (Alderson)       Restore restart routine
12   !!            -    !                            Currently needs a fixed processor
13   !!            -    !                            layout between restarts
14   !!----------------------------------------------------------------------
15   !!----------------------------------------------------------------------
16   !!   icb_rst_read    : read restart file
17   !!   icb_rst_write   : write restart file
18   !!----------------------------------------------------------------------
19   USE par_oce        ! NEMO parameters
20   USE dom_oce        ! NEMO domain
21   USE in_out_manager ! NEMO IO routines
22   USE lib_mpp        ! NEMO MPI library, lk_mpp in particular
23   USE netcdf         ! netcdf routines for IO
24   USE icb_oce        ! define iceberg arrays
25   USE icbutl         ! iceberg utility routines
26
27   IMPLICIT NONE
28   PRIVATE
29
30   PUBLIC   icb_rst_read    ! routine called in icbini.F90 module
31   PUBLIC   icb_rst_write   ! routine called in icbstp.F90 module
32   
33   INTEGER ::   nlonid, nlatid, nxid, nyid, nuvelid, nvvelid
34   INTEGER ::   nmassid, nthicknessid, nwidthid, nlengthid
35   INTEGER ::   nyearid, ndayid
36   INTEGER ::   nscaling_id, nmass_of_bits_id, nheat_density_id, numberid
37   INTEGER ::   nsiceid, nsheatid, ncalvid, ncalvhid, nkountid
38   INTEGER ::   nret, ncid, nc_dim
39   
40   INTEGER,  DIMENSION(3)                  :: nstrt3, nlngth3
41
42   !!----------------------------------------------------------------------
43   !! NEMO/OPA 3.3 , NEMO Consortium (2011)
44   !! $Id$
45   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
46   !!----------------------------------------------------------------------
47CONTAINS
48
49   SUBROUTINE icb_rst_read()
50      !!----------------------------------------------------------------------
51      !!                 ***  SUBROUTINE icb_rst_read  ***
52      !!
53      !! ** Purpose :   read a iceberg restart file
54      !!      NB: for this version, we just read back in the restart for this processor
55      !!      so we cannot change the processor layout currently with iceberg code
56      !!----------------------------------------------------------------------
57      INTEGER                      ::   idim, ivar, iatt
58      INTEGER                      ::   jn, iunlim_dim, ibergs_in_file
59      INTEGER                      ::   iclass
60      INTEGER, DIMENSION(1)        ::   istrt, ilngth, idata
61      INTEGER, DIMENSION(2)        ::   istrt2, ilngth2
62      INTEGER, DIMENSION(nkounts)  ::   idata2
63      REAL(wp), DIMENSION(1)       ::   zdata                                         ! need 1d array to read in with
64                                                                                            ! start and count arrays
65      LOGICAL                      ::   ll_found_restart
66      CHARACTER(len=256)           ::   cl_path
67      CHARACTER(len=256)           ::   cl_filename
68      CHARACTER(len=NF90_MAX_NAME) ::   cl_dname
69      TYPE(iceberg)                ::   localberg ! NOT a pointer but an actual local variable
70      TYPE(point)                  ::   localpt   ! NOT a pointer but an actual local variable
71      !!----------------------------------------------------------------------
72
73      ! Find a restart file. Assume iceberg restarts in same directory as ocean restarts.
74      cl_path = TRIM(cn_ocerst_indir)
75      IF( cl_path(LEN_TRIM(cl_path):) /= '/' ) cl_path = TRIM(cl_path) // '/'
76      cl_filename = ' '
77      IF ( lk_mpp ) THEN
78         cl_filename = ' '
79         WRITE( cl_filename, '("restart_icebergs_",I4.4,".nc")' ) narea-1
80         INQUIRE( file=TRIM(cl_path)//TRIM(cl_filename), exist=ll_found_restart )
81      ELSE
82         cl_filename = 'restart_icebergs.nc'
83         INQUIRE( file=TRIM(cl_path)//TRIM(cl_filename), exist=ll_found_restart )
84      ENDIF
85
86      IF ( .NOT. ll_found_restart) THEN                     ! only do the following if a file was found
87         CALL ctl_stop('icebergs: no restart file found')
88      ENDIF
89
90      IF (nn_verbose_level >= 0 .AND. lwp)  &
91         WRITE(numout,'(2a)') 'icebergs, read_restart_bergs: found restart file = ',TRIM(cl_path)//TRIM(cl_filename)
92
93      nret = NF90_OPEN(TRIM(cl_path)//TRIM(cl_filename), NF90_NOWRITE, ncid)
94      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, read_restart_bergs: nf_open failed')
95
96      nret = nf90_inquire(ncid, idim, ivar, iatt, iunlim_dim)
97      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, read_restart_bergs: nf_inquire failed')
98
99      IF( iunlim_dim .NE. -1) THEN
100
101         nret = nf90_inquire_dimension(ncid, iunlim_dim, cl_dname, ibergs_in_file)
102         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, read_restart_bergs: nf_inq_dimlen failed')
103
104         nret = NF90_INQ_VARID(ncid, 'number', numberid)
105         nret = NF90_INQ_VARID(ncid, 'mass_scaling', nscaling_id)
106         nret = NF90_INQ_VARID(ncid, 'xi', nxid)
107         nret = NF90_INQ_VARID(ncid, 'yj', nyid)
108         nret = NF90_INQ_VARID(ncid, 'lon', nlonid)
109         nret = NF90_INQ_VARID(ncid, 'lat', nlatid)
110         nret = NF90_INQ_VARID(ncid, 'uvel', nuvelid)
111         nret = NF90_INQ_VARID(ncid, 'vvel', nvvelid)
112         nret = NF90_INQ_VARID(ncid, 'mass', nmassid)
113         nret = NF90_INQ_VARID(ncid, 'thickness', nthicknessid)
114         nret = NF90_INQ_VARID(ncid, 'width', nwidthid)
115         nret = NF90_INQ_VARID(ncid, 'length', nlengthid)
116         nret = NF90_INQ_VARID(ncid, 'year', nyearid)
117         nret = NF90_INQ_VARID(ncid, 'day', ndayid)
118         nret = NF90_INQ_VARID(ncid, 'mass_of_bits', nmass_of_bits_id)
119         nret = NF90_INQ_VARID(ncid, 'heat_density', nheat_density_id)
120
121         ilngth(1) = 1
122         istrt2(1) = 1
123         ilngth2(1) = nkounts
124         ilngth2(2) = 1
125         DO jn=1, ibergs_in_file
126
127            istrt(1) = jn
128            istrt2(2) = jn
129
130            nret = NF90_GET_VAR(ncid, numberid, idata2, istrt2, ilngth2 )
131            localberg%number(:) = idata2(:)
132
133            nret = NF90_GET_VAR(ncid, nscaling_id, zdata, istrt, ilngth )
134            localberg%mass_scaling = zdata(1)
135
136            nret = NF90_GET_VAR(ncid, nlonid, zdata, istrt, ilngth)
137            localpt%lon = zdata(1)
138            nret = NF90_GET_VAR(ncid, nlatid, zdata, istrt, ilngth)
139            localpt%lat = zdata(1)
140            IF (nn_verbose_level >= 2 .AND. lwp) THEN
141               WRITE(numout,'(a,i5,a,2f10.4,a,i5)') 'icebergs, read_restart_bergs: berg ',jn,' is at ', &
142                                              localpt%lon,localpt%lat,' on PE ',narea-1
143            ENDIF
144            nret = NF90_GET_VAR(ncid, nxid, zdata, istrt, ilngth)
145            localpt%xi = zdata(1)
146            nret = NF90_GET_VAR(ncid, nyid, zdata, istrt, ilngth)
147            localpt%yj = zdata(1)
148            nret = NF90_GET_VAR(ncid, nuvelid, zdata, istrt, ilngth )
149            localpt%uvel = zdata(1)
150            nret = NF90_GET_VAR(ncid, nvvelid, zdata, istrt, ilngth )
151            localpt%vvel = zdata(1)
152            nret = NF90_GET_VAR(ncid, nmassid, zdata, istrt, ilngth )
153            localpt%mass = zdata(1)
154            nret = NF90_GET_VAR(ncid, nthicknessid, zdata, istrt, ilngth )
155            localpt%thickness = zdata(1)
156            nret = NF90_GET_VAR(ncid, nwidthid, zdata, istrt, ilngth )
157            localpt%width = zdata(1)
158            nret = NF90_GET_VAR(ncid, nlengthid, zdata, istrt, ilngth )
159            localpt%length = zdata(1)
160            nret = NF90_GET_VAR(ncid, nyearid, idata, istrt, ilngth )
161            localpt%year = idata(1)
162            nret = NF90_GET_VAR(ncid, ndayid, zdata, istrt, ilngth )
163            localpt%day = zdata(1)
164            nret = NF90_GET_VAR(ncid, nmass_of_bits_id, zdata, istrt, ilngth )
165            localpt%mass_of_bits = zdata(1)
166            nret = NF90_GET_VAR(ncid, nheat_density_id, zdata, istrt, ilngth )
167            localpt%heat_density = zdata(1)
168            !
169            CALL icb_utl_add( localberg, localpt )
170         END DO
171         !
172      ENDIF
173
174      nret = NF90_INQ_DIMID( ncid, 'c', nc_dim )
175      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, read_restart: nf_inq_dimid c failed')
176
177      nret = NF90_INQUIRE_DIMENSION( ncid, nc_dim, cl_dname, iclass )
178      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, read_restart: nf_inquire_dimension failed')
179
180      nret = NF90_INQ_VARID(ncid, 'kount'       , nkountid)
181      nret = NF90_INQ_VARID(ncid, 'calving'     , ncalvid)
182      nret = NF90_INQ_VARID(ncid, 'calving_hflx', ncalvhid)
183      nret = NF90_INQ_VARID(ncid, 'stored_ice'  , nsiceid)
184      nret = NF90_INQ_VARID(ncid, 'stored_heat' , nsheatid)
185
186      nstrt3(1) = 1
187      nstrt3(2) = 1
188      nlngth3(1) = jpi
189      nlngth3(2) = jpj
190      nlngth3(3) = 1
191
192      DO jn = 1, iclass
193         nstrt3(3) = jn
194         nret      = NF90_GET_VAR( ncid, nsiceid , griddata, nstrt3, nlngth3 )
195         berg_grid%stored_ice(:,:,jn) = griddata(:,:,1)
196      END DO
197
198      nret = NF90_GET_VAR( ncid, ncalvid , src_calving          (:,:) )
199      nret = NF90_GET_VAR( ncid, ncalvhid, src_calving_hflx     (:,:) )
200      nret = NF90_GET_VAR( ncid, nsheatid, berg_grid%stored_heat(:,:) )
201      nret = NF90_GET_VAR( ncid, nkountid, idata2(:) )
202      num_bergs(:) = idata2(:)
203
204      ! Finish up
205      nret = NF90_CLOSE(ncid)
206      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, read_restart: nf_close failed')
207
208      ! Sanity check
209      jn = icb_utl_count()
210      IF (nn_verbose_level >= 0)   &
211         WRITE(numout,'(2(a,i5))') 'icebergs, read_restart_bergs: # bergs =',jn,' on PE',narea-1
212      IF( lk_mpp ) THEN
213         CALL mpp_sum(ibergs_in_file)
214         CALL mpp_sum(jn)
215      ENDIF
216      IF(lwp)   WRITE(numout,'(a,i5,a,i5,a)') 'icebergs, read_restart_bergs: there were',ibergs_in_file,   &
217         &                                    ' bergs in the restart file and', jn,' bergs have been read'
218      !
219      IF( lwp .and. nn_verbose_level >= 0)  WRITE(numout,'(a)') 'icebergs, read_restart_bergs: completed'
220      !
221   END SUBROUTINE icb_rst_read
222
223
224   SUBROUTINE icb_rst_write( kt )
225      !!----------------------------------------------------------------------
226      !!                 ***  SUBROUTINE icb_rst_write  ***
227      !!
228      !!----------------------------------------------------------------------
229      INTEGER, INTENT( in ) :: kt
230      !
231      INTEGER ::   jn   ! dummy loop index
232      INTEGER ::   ix_dim, iy_dim, ik_dim, in_dim
233      CHARACTER(len=256)     :: cl_path
234      CHARACTER(len=256)     :: cl_filename
235      TYPE(iceberg), POINTER :: this
236      TYPE(point)  , POINTER :: pt
237      !!----------------------------------------------------------------------
238
239      ! Assume we write iceberg restarts to same directory as ocean restarts.
240      cl_path = TRIM(cn_ocerst_outdir)
241      IF( cl_path(LEN_TRIM(cl_path):) /= '/' ) cl_path = TRIM(cl_path) // '/'
242      IF( lk_mpp ) THEN
243         WRITE(cl_filename,'(A,"_icebergs_",I8.8,"_restart_",I4.4,".nc")') TRIM(cexper), kt, narea-1
244      ELSE
245         WRITE(cl_filename,'(A,"_icebergs_",I8.8,"_restart.nc")') TRIM(cexper), kt
246      ENDIF
247      IF (nn_verbose_level >= 0) WRITE(numout,'(2a)') 'icebergs, write_restart: creating ',TRIM(cl_path)//TRIM(cl_filename)
248
249      nret = NF90_CREATE(TRIM(cl_path)//TRIM(cl_filename), NF90_CLOBBER, ncid)
250      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_create failed')
251
252      ! Dimensions
253      nret = NF90_DEF_DIM(ncid, 'x', jpi, ix_dim)
254      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim x failed')
255
256      nret = NF90_DEF_DIM(ncid, 'y', jpj, iy_dim)
257      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim y failed')
258
259      nret = NF90_DEF_DIM(ncid, 'c', nclasses, nc_dim)
260      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim c failed')
261
262      nret = NF90_DEF_DIM(ncid, 'k', nkounts, ik_dim)
263      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim k failed')
264
265      ! global attributes
266      IF( lk_mpp ) THEN
267         ! Set domain parameters (assume jpdom_local_full)
268         nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_number_total'   , jpnij              )
269         nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_number'         , narea-1            )
270         nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_dimensions_ids' , (/1     , 2     /) )
271         nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_size_global'    , (/jpiglo, jpjglo/) )
272         nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_size_local'     , (/jpi   , jpj   /) )
273         nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_position_first' , (/nimpp , njmpp /) )
274         nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_position_last'  , (/nimpp + jpi - 1 , njmpp + jpj - 1  /) )
275         nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_halo_size_start', (/nldi - 1        , nldj - 1         /) )
276         nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_halo_size_end'  , (/jpi - nlei      , jpj - nlej       /) )
277         nret = NF90_PUT_ATT( ncid, NF90_GLOBAL, 'DOMAIN_type'           , 'BOX'              )
278      ENDIF
279     
280      IF (associated(first_berg)) then
281         nret = NF90_DEF_DIM(ncid, 'n', NF90_UNLIMITED, in_dim)
282         IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_def_dim n failed')
283      ENDIF
284
285      ! Variables
286      nret = NF90_DEF_VAR(ncid, 'kount'       , NF90_INT   , (/ ik_dim /), nkountid)
287      nret = NF90_DEF_VAR(ncid, 'calving'     , NF90_DOUBLE, (/ ix_dim, iy_dim /), ncalvid)
288      nret = NF90_DEF_VAR(ncid, 'calving_hflx', NF90_DOUBLE, (/ ix_dim, iy_dim /), ncalvhid)
289      nret = NF90_DEF_VAR(ncid, 'stored_ice'  , NF90_DOUBLE, (/ ix_dim, iy_dim, nc_dim /), nsiceid)
290      nret = NF90_DEF_VAR(ncid, 'stored_heat' , NF90_DOUBLE, (/ ix_dim, iy_dim /), nsheatid)
291
292      ! Attributes
293      nret = NF90_PUT_ATT(ncid, ncalvid , 'long_name', 'iceberg calving')
294      nret = NF90_PUT_ATT(ncid, ncalvid , 'units', 'some')
295      nret = NF90_PUT_ATT(ncid, ncalvhid, 'long_name', 'heat flux associated with iceberg calving')
296      nret = NF90_PUT_ATT(ncid, ncalvhid, 'units', 'some')
297      nret = NF90_PUT_ATT(ncid, nsiceid , 'long_name', 'stored ice used to calve icebergs')
298      nret = NF90_PUT_ATT(ncid, nsiceid , 'units', 'kg/s')
299      nret = NF90_PUT_ATT(ncid, nsheatid, 'long_name', 'heat in stored ice used to calve icebergs')
300      nret = NF90_PUT_ATT(ncid, nsheatid, 'units', 'J/kg/s')
301
302      IF ( ASSOCIATED(first_berg) ) THEN
303
304         ! Only add berg variables for this PE if we have anything to say
305
306         ! Variables
307         nret = NF90_DEF_VAR(ncid, 'lon', NF90_DOUBLE, in_dim, nlonid)
308         nret = NF90_DEF_VAR(ncid, 'lat', NF90_DOUBLE, in_dim, nlatid)
309         nret = NF90_DEF_VAR(ncid, 'xi', NF90_DOUBLE, in_dim, nxid)
310         nret = NF90_DEF_VAR(ncid, 'yj', NF90_DOUBLE, in_dim, nyid)
311         nret = NF90_DEF_VAR(ncid, 'uvel', NF90_DOUBLE, in_dim, nuvelid)
312         nret = NF90_DEF_VAR(ncid, 'vvel', NF90_DOUBLE, in_dim, nvvelid)
313         nret = NF90_DEF_VAR(ncid, 'mass', NF90_DOUBLE, in_dim, nmassid)
314         nret = NF90_DEF_VAR(ncid, 'thickness', NF90_DOUBLE, in_dim, nthicknessid)
315         nret = NF90_DEF_VAR(ncid, 'width', NF90_DOUBLE, in_dim, nwidthid)
316         nret = NF90_DEF_VAR(ncid, 'length', NF90_DOUBLE, in_dim, nlengthid)
317         nret = NF90_DEF_VAR(ncid, 'number', NF90_INT, (/ik_dim,in_dim/), numberid)
318         nret = NF90_DEF_VAR(ncid, 'year', NF90_INT, in_dim, nyearid)
319         nret = NF90_DEF_VAR(ncid, 'day', NF90_DOUBLE, in_dim, ndayid)
320         nret = NF90_DEF_VAR(ncid, 'mass_scaling', NF90_DOUBLE, in_dim, nscaling_id)
321         nret = NF90_DEF_VAR(ncid, 'mass_of_bits', NF90_DOUBLE, in_dim, nmass_of_bits_id)
322         nret = NF90_DEF_VAR(ncid, 'heat_density', NF90_DOUBLE, in_dim, nheat_density_id)
323
324         ! Attributes
325         nret = NF90_PUT_ATT(ncid, nlonid, 'long_name', 'longitude')
326         nret = NF90_PUT_ATT(ncid, nlonid, 'units', 'degrees_E')
327         nret = NF90_PUT_ATT(ncid, nlatid, 'long_name', 'latitude')
328         nret = NF90_PUT_ATT(ncid, nlatid, 'units', 'degrees_N')
329         nret = NF90_PUT_ATT(ncid, nxid, 'long_name', 'x grid box position')
330         nret = NF90_PUT_ATT(ncid, nxid, 'units', 'fractional')
331         nret = NF90_PUT_ATT(ncid, nyid, 'long_name', 'y grid box position')
332         nret = NF90_PUT_ATT(ncid, nyid, 'units', 'fractional')
333         nret = NF90_PUT_ATT(ncid, nuvelid, 'long_name', 'zonal velocity')
334         nret = NF90_PUT_ATT(ncid, nuvelid, 'units', 'm/s')
335         nret = NF90_PUT_ATT(ncid, nvvelid, 'long_name', 'meridional velocity')
336         nret = NF90_PUT_ATT(ncid, nvvelid, 'units', 'm/s')
337         nret = NF90_PUT_ATT(ncid, nmassid, 'long_name', 'mass')
338         nret = NF90_PUT_ATT(ncid, nmassid, 'units', 'kg')
339         nret = NF90_PUT_ATT(ncid, nthicknessid, 'long_name', 'thickness')
340         nret = NF90_PUT_ATT(ncid, nthicknessid, 'units', 'm')
341         nret = NF90_PUT_ATT(ncid, nwidthid, 'long_name', 'width')
342         nret = NF90_PUT_ATT(ncid, nwidthid, 'units', 'm')
343         nret = NF90_PUT_ATT(ncid, nlengthid, 'long_name', 'length')
344         nret = NF90_PUT_ATT(ncid, nlengthid, 'units', 'm')
345         nret = NF90_PUT_ATT(ncid, numberid, 'long_name', 'iceberg number on this processor')
346         nret = NF90_PUT_ATT(ncid, numberid, 'units', 'count')
347         nret = NF90_PUT_ATT(ncid, nyearid, 'long_name', 'calendar year of calving event')
348         nret = NF90_PUT_ATT(ncid, nyearid, 'units', 'years')
349         nret = NF90_PUT_ATT(ncid, ndayid, 'long_name', 'year day of calving event')
350         nret = NF90_PUT_ATT(ncid, ndayid, 'units', 'days')
351         nret = NF90_PUT_ATT(ncid, nscaling_id, 'long_name', 'scaling factor for mass of calving berg')
352         nret = NF90_PUT_ATT(ncid, nscaling_id, 'units', 'none')
353         nret = NF90_PUT_ATT(ncid, nmass_of_bits_id, 'long_name', 'mass of bergy bits')
354         nret = NF90_PUT_ATT(ncid, nmass_of_bits_id, 'units', 'kg')
355         nret = NF90_PUT_ATT(ncid, nheat_density_id, 'long_name', 'heat density')
356         nret = NF90_PUT_ATT(ncid, nheat_density_id, 'units', 'J/kg')
357
358      ENDIF ! associated(first_berg)
359
360      ! End define mode
361      nret = NF90_ENDDEF(ncid)
362
363      ! --------------------------------
364      ! now write some data
365
366      nstrt3(1) = 1
367      nstrt3(2) = 1
368      nlngth3(1) = jpi
369      nlngth3(2) = jpj
370      nlngth3(3) = 1
371
372      DO jn=1,nclasses
373         griddata(:,:,1) = berg_grid%stored_ice(:,:,jn)
374         nstrt3(3) = jn
375         nret = NF90_PUT_VAR( ncid, nsiceid, griddata, nstrt3, nlngth3 )
376         IF (nret .ne. NF90_NOERR) THEN
377            IF( lwp ) WRITE(numout,*) TRIM(NF90_STRERROR( nret ))
378            CALL ctl_stop('icebergs, write_restart: nf_put_var stored_ice failed')
379         ENDIF
380      ENDDO
381      IF( lwp ) WRITE(numout,*) 'file: ',TRIM(cl_path)//TRIM(cl_filename),' var: stored_ice  written'
382
383      nret = NF90_PUT_VAR( ncid, nkountid, num_bergs(:) )
384      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_put_var kount failed')
385
386      nret = NF90_PUT_VAR( ncid, nsheatid, berg_grid%stored_heat(:,:) )
387      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_put_var stored_heat failed')
388      IF( lwp ) WRITE(numout,*) 'file: ',TRIM(cl_path)//TRIM(cl_filename),' var: stored_heat written'
389
390      nret = NF90_PUT_VAR( ncid, ncalvid , src_calving(:,:) )
391      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_put_var calving failed')
392      nret = NF90_PUT_VAR( ncid, ncalvhid, src_calving_hflx(:,:) )
393      IF (nret .ne. NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_put_var calving_hflx failed')
394      IF( lwp ) WRITE(numout,*) 'file: ',TRIM(cl_path)//TRIM(cl_filename),' var: calving written'
395
396      IF ( ASSOCIATED(first_berg) ) THEN
397
398         ! Write variables
399         ! just write out the current point of the trajectory
400
401         this => first_berg
402         jn = 0
403         DO WHILE (ASSOCIATED(this))
404            pt => this%current_point
405            jn=jn+1
406
407            nret = NF90_PUT_VAR(ncid, numberid, this%number, (/1,jn/), (/nkounts,1/) )
408            nret = NF90_PUT_VAR(ncid, nscaling_id, this%mass_scaling, (/ jn /) )
409
410            nret = NF90_PUT_VAR(ncid, nlonid, pt%lon, (/ jn /) )
411            nret = NF90_PUT_VAR(ncid, nlatid, pt%lat, (/ jn /) )
412            nret = NF90_PUT_VAR(ncid, nxid, pt%xi, (/ jn /) )
413            nret = NF90_PUT_VAR(ncid, nyid, pt%yj, (/ jn /) )
414            nret = NF90_PUT_VAR(ncid, nuvelid, pt%uvel, (/ jn /) )
415            nret = NF90_PUT_VAR(ncid, nvvelid, pt%vvel, (/ jn /) )
416            nret = NF90_PUT_VAR(ncid, nmassid, pt%mass, (/ jn /) )
417            nret = NF90_PUT_VAR(ncid, nthicknessid, pt%thickness, (/ jn /) )
418            nret = NF90_PUT_VAR(ncid, nwidthid, pt%width, (/ jn /) )
419            nret = NF90_PUT_VAR(ncid, nlengthid, pt%length, (/ jn /) )
420            nret = NF90_PUT_VAR(ncid, nyearid, pt%year, (/ jn /) )
421            nret = NF90_PUT_VAR(ncid, ndayid, pt%day, (/ jn /) )
422            nret = NF90_PUT_VAR(ncid, nmass_of_bits_id, pt%mass_of_bits, (/ jn /) )
423            nret = NF90_PUT_VAR(ncid, nheat_density_id, pt%heat_density, (/ jn /) )
424
425            this=>this%next
426         END DO
427         !
428      ENDIF ! associated(first_berg)
429
430      ! Finish up
431      nret = NF90_CLOSE(ncid)
432      IF (nret /= NF90_NOERR) CALL ctl_stop('icebergs, write_restart: nf_close failed')
433      !
434   END SUBROUTINE icb_rst_write
435   !
436END MODULE icbrst
Note: See TracBrowser for help on using the repository browser.