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