save_3d_ncdf.F90 9.16 KB
Newer Older
1
!$Id: save_3d_ncdf.F90,v 1.11 2005-09-23 11:27:10 kbk Exp $
gotm's avatar
gotm committed
2 3 4 5
#include "cppdefs.h"
!-----------------------------------------------------------------------
!BOP
!
6
! !ROUTINE: Save 3D netCDF variables
gotm's avatar
gotm committed
7 8 9 10 11 12 13
!
! !INTERFACE:
   subroutine save_3d_ncdf(secs)
!
! !DESCRIPTION:
!
! !USES:
14
   use exceptions
gotm's avatar
gotm committed
15
   use ncdf_3d
16 17 18 19 20 21
   use grid_ncdf
   use domain,       only: ioff,joff,imin,imax,jmin,jmax
   use domain,       only: iimin,iimax,jjmin,jjmax,kmax
   use domain,       only: H,az,au,av,min_depth
   use variables_2d, only: z,D
   use variables_2d, only: U,V,DU,DV
22
   use variables_3d, only: kmin,hn,uu,hun,vv,hvn,ww,hcc
kbk's avatar
kbk committed
23
#ifndef NO_BAROCLINIC
gotm's avatar
gotm committed
24
   use variables_3d, only: S,T,rho
kbk's avatar
kbk committed
25
#endif
gotm's avatar
gotm committed
26
   use variables_3d, only: tke,num,nuh,eps
kbk's avatar
kbk committed
27
#ifdef SPM
kbk's avatar
kbk committed
28
   use variables_3d, only: spm_pool,spm
29 30 31 32
#endif
#ifdef GETM_BIO
   use bio_var, only: numc
   use variables_3d, only: cc3d,ws3d
kbk's avatar
kbk committed
33
#endif
34
   use parameters,   only: g,rho_0
gotm's avatar
gotm committed
35 36 37 38 39
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
   REALTYPE, intent(in) :: secs
!
40 41
! !DEFINED PARAMTERS:
   logical, parameter   :: save3d=.true.
gotm's avatar
gotm committed
42 43 44 45 46
!
! !REVISION HISTORY:
!  Original author(s): Karsten Bolding & Hans Burchard
!
!  $Log: save_3d_ncdf.F90,v $
47 48 49 50
!  Revision 1.11  2005-09-23 11:27:10  kbk
!  support for biology via GOTMs biology modules
!
!  Revision 1.10  2005/04/25 09:32:34  kbk
51 52 53
!  added NetCDF IO rewrite + de-stag of velocities - Umlauf
!
!  Revision 1.9  2004/06/15 08:25:57  kbk
kbk's avatar
kbk committed
54 55 56
!  added supoort for spm - Ruiz
!
!  Revision 1.8  2004/05/04 09:23:51  kbk
57 58 59
!  hydrostatic consistency criteria stored in .3d.nc file
!
!  Revision 1.7  2003/12/16 12:47:11  kbk
kbk's avatar
kbk committed
60 61 62
!  rho_0 and g from parameters (manuel)
!
!  Revision 1.6  2003/12/08 07:21:53  hb
63 64 65
!  use proper layer heights for saving velocities
!
!  Revision 1.5  2003/05/09 11:53:13  kbk
kbk's avatar
kbk committed
66 67 68
!  forgot to delete some debug lines
!
!  Revision 1.4  2003/05/09 11:38:26  kbk
69 70 71
!  added proper undef support - based on Adolf Stips patch
!
!  Revision 1.3  2003/04/23 11:53:24  kbk
kbk's avatar
kbk committed
72 73 74
!  save lat/lon info for spherical grid
!
!  Revision 1.2  2003/04/07 12:43:12  kbk
kbk's avatar
kbk committed
75 76 77 78
!  SPHERICAL and NO_BAROCLINIC
!
!  Revision 1.1.1.1  2002/05/02 14:01:48  gotm
!  recovering after CVS crash
gotm's avatar
gotm committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
!
!  Revision 1.4  2001/10/25 16:16:21  bbh
!  No actual storing of data in init_3d_ncdf.F90 -> save_3d_ncdf.F90
!
!  Revision 1.3  2001/10/23 14:19:20  bbh
!  Stores h if general vertical coordinates
!
!  Revision 1.2  2001/10/23 07:37:17  bbh
!  Saving spm - if calc_spm and save_spm are both true
!
!  Revision 1.1  2001/09/13 14:50:02  bbh
!  Cleaner and smaller NetCDF implementation + better axis support
!
!
! !LOCAL VARIABLES:
94
   integer                   :: err,n
kbk's avatar
kbk committed
95 96
   integer                   :: start(4),edges(4)
   integer, save             :: n3d=0
kbk's avatar
kbk committed
97
   REALTYPE, parameter       :: x=-rho_0/g
98

gotm's avatar
gotm committed
99 100 101 102
!EOP
!-----------------------------------------------------------------------
!BOC
   include "netcdf.inc"
103

gotm's avatar
gotm committed
104 105 106
   n3d = n3d + 1
   if (n3d .eq. 1) then

107
      call save_grid_ncdf(ncid,save3d)
gotm's avatar
gotm committed
108 109 110

      start(1) = 1
      start(2) = 1
111
      start(3) = 1
gotm's avatar
gotm committed
112 113
      edges(1) = xlen
      edges(2) = ylen
114
      edges(3) = zlen
115

116 117 118 119 120
      call cnv_3d(imin,jmin,imax,jmax,iimin,jjmin,iimax,jjmax,kmax, &
                  kmin,az,hcc,-_ONE_,ws)
      err = nf_put_vara_real(ncid,hcc_id,start,edges,ws)
      if (err .NE. NF_NOERR) go to 10

gotm's avatar
gotm committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
      err = nf_sync(ncid)
      if (err .NE. NF_NOERR) go to 10

   end if ! (n3d .eq. 1)

   start(1) = n3d
   edges(1) = 1
   ws(1) = secs
   err = nf_put_vara_real(ncid,time_id,start,edges,ws(1))

   start(1) = 1
   start(2) = 1
   start(3) = n3d
   edges(1) = xlen
   edges(2) = ylen
   edges(3) = 1

!  elevations
139 140
   call eta_mask(imin,jmin,imax,jmax,az,H,D,z,min_depth,elev_missing, &
                 iimin,jmin,iimax,jjmax,ws)
gotm's avatar
gotm committed
141 142 143 144
   err = nf_put_vara_real(ncid,elev_id,start,edges,ws)
   if (err .NE. NF_NOERR) go to 10

!  depth integrated zonal velocity
145
   call to_2d_vel(imin,jmin,imax,jmax,au,U,DU,vel_missing, &
146
                  imin,jmin,imax,jmax,ws)
gotm's avatar
gotm committed
147 148 149 150
   err = nf_put_vara_real(ncid,u_id,start,edges,ws)
   if (err .NE. NF_NOERR) go to 10

!  depth integrated meridional velocity
151
   call to_2d_vel(imin,jmin,imax,jmax,av,V,DV,vel_missing, &
152
                  imin,jmin,imax,jmax,ws)
gotm's avatar
gotm committed
153 154 155 156 157 158 159 160 161 162 163 164 165
   err = nf_put_vara_real(ncid,v_id,start,edges,ws)
   if (err .NE. NF_NOERR) go to 10

   start(1) = 1
   start(2) = 1
   start(3) = 1
   start(4) = n3d
   edges(1) = xlen
   edges(2) = ylen
   edges(3) = zlen
   edges(4) = 1

   if (h_id .gt. 0) then
166 167
      call cnv_3d(imin,jmin,imax,jmax,iimin,jjmin,iimax,jjmax,kmax,    &
                  kmin,az,hn,hh_missing,ws)
gotm's avatar
gotm committed
168 169 170 171 172
      err = nf_put_vara_real(ncid,h_id,start,edges,ws)
      if (err .NE. NF_NOERR) go to 10
   end if

   if (save_vel) then
173 174 175 176 177 178 179 180 181 182 183

      if (destag) then
         call to_3d_uu(imin, jmin, imax, jmax,  az,                    &
                       iimin,jjmin,iimax,jjmax,kmax,                   &
                       kmin,hun,uu,vel_missing,ws)
      else
         call to_3d_vel( imin, jmin, imax, jmax,  au,                  &
                        iimin,jjmin,iimax,jjmax,kmax,                  &
                        kmin,hun,uu,vel_missing,ws)
      endif

gotm's avatar
gotm committed
184 185 186
      err = nf_put_vara_real(ncid,uu_id,start,edges,ws)
      if (err .NE. NF_NOERR) go to 10

187 188 189 190 191 192 193 194 195 196 197

      if (destag) then
         call to_3d_vv ( imin, jmin, imax, jmax,  az,                 &
                        iimin,jjmin,iimax,jjmax,kmax,                 &
                        kmin,hvn,vv,vel_missing,ws)
      else
         call to_3d_vel( imin, jmin, imax, jmax,  av,                 &
                        iimin,jjmin,iimax,jjmax,kmax,                 &
                        kmin,hvn,vv,vel_missing,ws)
      endif

gotm's avatar
gotm committed
198 199 200
      err = nf_put_vara_real(ncid,vv_id,start,edges,ws)
      if (err .NE. NF_NOERR) go to 10

201
      call tow(ws,ww,iimin,jjmin,0,iimax,jjmax,kmax)
gotm's avatar
gotm committed
202 203
      err = nf_put_vara_real(ncid,w_id,start,edges,ws)
      if (err .NE. NF_NOERR) go to 10
204

gotm's avatar
gotm committed
205 206
   end if

kbk's avatar
kbk committed
207
#ifndef NO_BAROCLINIC
gotm's avatar
gotm committed
208 209 210
   if (save_strho) then

      if (save_s) then
211 212
         call cnv_3d(imin,jmin,imax,jmax,iimin,jjmin,iimax,jjmax,kmax, &
                     kmin,az,S,salt_missing,ws)
gotm's avatar
gotm committed
213 214 215 216 217
         err = nf_put_vara_real(ncid, salt_id, start, edges, ws)
         if (err .NE. NF_NOERR) go to 10
      end if

      if (save_t) then
218 219
         call cnv_3d(imin,jmin,imax,jmax,iimin,jjmin,iimax,jjmax,kmax, &
                     kmin,az,T,temp_missing,ws)
gotm's avatar
gotm committed
220 221 222 223 224
         err = nf_put_vara_real(ncid, temp_id, start, edges, ws)
         if (err .NE. NF_NOERR) go to 10
      end if

      if (save_rho) then
225
         call cnv_3d(imin,jmin,imax,jmax,iimin,jjmin,iimax,jjmax,kmax, &
kbk's avatar
kbk committed
226
                     kmin,az,x*rho+rho_0-1000.,rho_missing,ws)
gotm's avatar
gotm committed
227 228 229 230
         err = nf_put_vara_real(ncid, sigma_t_id, start, edges, ws)
         if (err .NE. NF_NOERR) go to 10
      end if
   end if ! save_strho
kbk's avatar
kbk committed
231
#endif
gotm's avatar
gotm committed
232 233 234 235

   if (save_turb) then

      if (save_tke) then
236 237
         call cnv_3d(imin,jmin,imax,jmax,iimin,jjmin,iimax,jjmax,kmax, &
                     kmin,az,tke,tke_missing,ws)
gotm's avatar
gotm committed
238 239 240 241 242
         err = nf_put_vara_real(ncid,tke_id,start,edges,ws)
         if (err .NE. NF_NOERR) go to 10
      end if

      if (save_num) then
243 244
         call cnv_3d(imin,jmin,imax,jmax,iimin,jjmin,iimax,jjmax,kmax, &
                     kmin,az,num,num_missing,ws)
gotm's avatar
gotm committed
245 246 247 248 249
         err = nf_put_vara_real(ncid,num_id,start,edges,ws)
         if (err .NE. NF_NOERR) go to 10
      end if

      if (save_nuh) then
250 251
         call cnv_3d(imin,jmin,imax,jmax,iimin,jjmin,iimax,jjmax,kmax, &
                     kmin,az,nuh,nuh_missing,ws)
gotm's avatar
gotm committed
252 253 254 255 256
         err = nf_put_vara_real(ncid,nuh_id,start,edges,ws)
         if (err .NE. NF_NOERR) go to 10
      end if

      if (save_eps) then
257 258
         call cnv_3d(imin,jmin,imax,jmax,iimin,jjmin,iimax,jjmax,kmax, &
                     kmin,az,eps,eps_missing,ws)
gotm's avatar
gotm committed
259 260 261 262 263
         err = nf_put_vara_real(ncid, eps_id, start, edges, ws)
         if (err .NE. NF_NOERR) go to 10
      end if
   end if ! save_turb

kbk's avatar
kbk committed
264
#ifdef SPM
gotm's avatar
gotm committed
265
   if (save_spm) then
266
      call cnv_3d(imin,jmin,imax,jmax,iimin,jjmin,iimax,jjmax,kmax,    &
267
                  kmin,az,spm,spm_missing,ws)
gotm's avatar
gotm committed
268 269
      err = nf_put_vara_real(ncid, spm_id, start, edges, ws)
      if (err .NE. NF_NOERR) go to 10
kbk's avatar
kbk committed
270 271 272 273 274 275 276
      !spm pool is a 2d magnitude
      start(1) = 1
      start(2) = 1
      start(3) = n3d
      edges(1) = xlen
      edges(2) = ylen
      edges(3) = 1
277
      call cnv_2d(imin,jmin,imax,jmax,az,spm_pool,spmpool_missing,    &
kbk's avatar
kbk committed
278 279 280
                  imin,jmin,imax,jmax,ws)
      err = nf_put_vara_real(ncid, spmpool_id, start, edges, ws)
      if (err .NE. NF_NOERR) go to 10
gotm's avatar
gotm committed
281
   end if
kbk's avatar
kbk committed
282
#endif
gotm's avatar
gotm committed
283

284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
#ifdef GETM_BIO
!   if (save_bio) then
      start(1) = 1
      start(2) = 1
      start(3) = 1
      start(4) = n3d
      edges(1) = xlen
      edges(2) = ylen
      edges(3) = zlen
      edges(4) = 1
      do n=1,numc
         call cnv_3d(imin,jmin,imax,jmax,iimin,jjmin,iimax,jjmax,kmax, &
                     kmin,az,cc3d(n,:,:,:),bio_missing,ws)
         err = nf_put_vara_real(ncid, bio_ids(n), start, edges, ws)
         if (err .NE.  NF_NOERR) go to 10
      end do
!   end if
#endif

gotm's avatar
gotm committed
303 304 305 306 307
   err = nf_sync(ncid)
   if (err .NE. NF_NOERR) go to 10

   return

308
10 FATAL 'save_3d_ncdf: ',nf_strerror(err)
gotm's avatar
gotm committed
309 310 311 312 313 314 315 316 317
   stop

   return
   end subroutine save_3d_ncdf
!EOC

!-----------------------------------------------------------------------
! Copyright (C) 2001 - Hans Burchard and Karsten Bolding (BBH)         !
!-----------------------------------------------------------------------