output.F90 17.6 KB
Newer Older
1
!$Id: output.F90,v 1.12 2005-09-23 11:27:11 kbk Exp $
gotm's avatar
gotm committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include "cppdefs.h"
!-----------------------------------------------------------------------
!BOP
!
! !MODULE:  output - output specifications
!
! !INTERFACE:
   module output
!
! !DESCRIPTION:
!
! !USES:
   use time, only: write_time_string,timestep,timestr
   use ncdf_out
   use ascii_out
#ifdef TEST_NESTING
   use nesting
#endif
   IMPLICIT NONE
!
! !PUBLIC DATA MEMBERS:
kbk's avatar
kbk committed
23 24 25 26 27
   integer                             :: out_fmt=NETCDF
   character(LEN = PATH_MAX)           :: in_dir='.'
   character(LEN = PATH_MAX)           :: out_dir='.'
   character(LEN = PATH_MAX)           :: out_f_2d
   character(LEN = PATH_MAX)           :: out_f_3d
kbk's avatar
kbk committed
28
   character(LEN = PATH_MAX)           :: out_f_mean
kbk's avatar
kbk committed
29
   character(LEN = PATH_MAX)           :: hot_out
gotm's avatar
gotm committed
30

kbk's avatar
kbk committed
31 32 33
   logical                             :: save_meteo=.false.
   logical                             :: save_2d=.true.
   logical                             :: save_3d=.true.
kbk's avatar
kbk committed
34
   logical                             :: save_mean=.false. 
kbk's avatar
kbk committed
35
   logical                             :: save_vel=.true.
36
   logical                             :: destag=.false.
kbk's avatar
kbk committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
   logical                             :: save_strho=.true.
   logical                             :: save_s=.true.
   logical                             :: save_t=.true.
   logical                             :: save_rho=.true.
   logical                             :: save_turb=.true.
   logical                             :: save_tke=.true.
   logical                             :: save_eps=.true.
   logical                             :: save_num=.true.
   logical                             :: save_nuh=.true.
   logical                             :: save_spm=.false.
   integer                             :: first_2d=1
   integer                             :: step_2d=1
   integer                             :: first_3d=1
   integer                             :: step_3d=1
   integer                             :: hotout=-1
kbk's avatar
kbk committed
52
   integer                             :: meanout=-1
gotm's avatar
gotm committed
53 54 55 56 57
!
! !REVISION HISTORY:
!  Original author(s): Karsten Bolding & Hans Burchard
!
!  $Log: output.F90,v $
58 59 60 61
!  Revision 1.12  2005-09-23 11:27:11  kbk
!  support for biology via GOTMs biology modules
!
!  Revision 1.11  2005/05/04 11:45:30  kbk
kbk's avatar
kbk committed
62 63 64
!  adding model time stamp on IO
!
!  Revision 1.10  2005/04/25 09:32:34  kbk
65 66 67
!  added NetCDF IO rewrite + de-stag of velocities - Umlauf
!
!  Revision 1.9  2004/06/15 08:25:57  kbk
kbk's avatar
kbk committed
68 69 70
!  added supoort for spm - Ruiz
!
!  Revision 1.8  2004/03/29 15:35:52  kbk
kbk's avatar
kbk committed
71 72 73
!  possible to store calculated mean fields
!
!  Revision 1.7  2003/12/16 16:50:41  kbk
74 75 76
!  added support for Intel/IFORT compiler - expanded TABS, same types in subroutine calls
!
!  Revision 1.6  2003/09/30 09:44:27  kbk
77 78 79
!  hotout=0 -> save hot-files at last time step only
!
!  Revision 1.5  2003/09/16 07:45:30  kbk
80 81 82
!  additional info written when hotstart time mismatch
!
!  Revision 1.4  2003/09/03 05:55:13  kbk
kbk's avatar
kbk committed
83 84 85
!  continuous=.false. - allows change of dt
!
!  Revision 1.3  2003/04/23 12:07:12  kbk
kbk's avatar
kbk committed
86 87 88
!  cleaned code + TABS to spaces
!
!  Revision 1.2  2003/04/07 12:32:58  kbk
kbk's avatar
kbk committed
89 90 91 92
!  parallel support + NO_3D, NO_BAROCLINIC
!
!  Revision 1.1.1.1  2002/05/02 14:01:52  gotm
!  recovering after CVS crash
gotm's avatar
gotm committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
!
!  Revision 1.8  2001/10/23 07:37:17  bbh
!  Saving spm - if calc_spm and save_spm are both true
!
!  Revision 1.7  2001/10/18 07:14:57  bbh
!  Resolved conflicts
!
!  Revision 1.6  2001/09/18 20:08:11  bbh
!  Added save_nuh
!
!  Revision 1.5  2001/09/13 14:50:02  bbh
!  Cleaner and smaller NetCDF implementation + better axis support
!
!  Revision 1.4  2001/07/26 13:57:14  bbh
!  Meteo working - needs some polishing
!
!  Revision 1.3  2001/06/04 13:09:53  bbh
!  Includes - dryrun - in call to init_output()
!
!  Revision 1.2  2001/04/24 08:24:58  bbh
!  Use runtype instead of macro
!
!  Revision 1.1.1.1  2001/04/17 08:43:08  bbh
!  initial import into CVS
!
! !LOCAL VARIABLES:
!
!EOP
!-----------------------------------------------------------------------

   contains

!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: init_output - initialise all external files and units
!
! !INTERFACE:
kbk's avatar
kbk committed
131
   subroutine init_output(runid,title,starttime,runtype,dryrun,myid)
gotm's avatar
gotm committed
132 133 134
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
kbk's avatar
kbk committed
135 136 137
   character(len=*), intent(in)        :: runid,title,starttime
   integer, intent(in)                 :: runtype,myid
   logical, intent(in)                 :: dryrun
gotm's avatar
gotm committed
138 139 140 141 142 143 144 145 146 147 148 149
!
! !INPUT/OUTPUT PARAMETERS:
!
! !OUTPUT PARAMETERS:
!
! !DESCRIPTION:
!
! !REVISION HISTORY:
!
!  See log for module
!
! !LOCAL VARIABLES:
kbk's avatar
kbk committed
150 151 152
   namelist /io_spec/ &
             out_fmt, &
             in_dir,out_dir, &
153
             save_2d,save_3d,save_vel,destag, &
kbk's avatar
kbk committed
154 155 156
             save_strho,save_s,save_t,save_rho, &
             save_turb,save_tke,save_eps,save_num,save_nuh, &
             save_spm, &
kbk's avatar
kbk committed
157
             first_2d,step_2d,first_3d,step_3d,hotout,meanout, &
kbk's avatar
kbk committed
158 159
             save_meteo
!   logical :: nesting=.true.
gotm's avatar
gotm committed
160 161 162 163 164 165 166 167 168 169 170 171
!EOP
!-------------------------------------------------------------------------
!BOC
#ifdef DEBUG
   integer, save :: Ncall = 0
   Ncall = Ncall+1
   write(debug,*) 'init_output() # ',Ncall
#endif

   LEVEL1 'init_output'

   read(NAMLST, nml=io_spec)
kbk's avatar
kbk committed
172 173 174
   LEVEL2 'save_nuh',save_nuh
   LEVEL2 'save_num',save_num
   LEVEL2 'save_tke',save_tke
gotm's avatar
gotm committed
175 176 177 178 179 180 181 182

   if (runtype .eq. 1) then
      save_3d = .false.
      save_vel = .false.
      save_strho = .false.
      save_turb = .false.
      save_spm = .false.
   end if
kbk's avatar
kbk committed
183 184 185 186 187 188
  
   if (runtype .eq. 2) then
      save_strho = .false.
      save_s = .false.
      save_t = .false.
   end if
189 190 191 192 193 194

   if(destag) then
      LEVEL2 'de-stag velocities to T-points'
   else
      LEVEL2 'keeping velocities on calculation grid'
   end if
kbk's avatar
kbk committed
195
   
kbk's avatar
kbk committed
196
   call file_names(runid,myid)
gotm's avatar
gotm committed
197 198

   if(save_2d) then
kbk's avatar
kbk committed
199
      LEVEL2 '2D results: ',trim(out_f_2d)
gotm's avatar
gotm committed
200 201 202 203 204
      LEVEL2 'First=',first_2d,' step=',step_2d
      if(save_meteo) then
         LEVEL2 'Saving meteo forcing in ',trim(out_f_2d)
      end if
   end if
kbk's avatar
kbk committed
205
#ifndef NO_3D
gotm's avatar
gotm committed
206
   if(save_3d) then
kbk's avatar
kbk committed
207
      LEVEL2 '3D results: ',trim(out_f_3d)
gotm's avatar
gotm committed
208 209
      LEVEL2 'First=',first_3d,' step=',step_3d
   end if
kbk's avatar
kbk committed
210
#endif
gotm's avatar
gotm committed
211

kbk's avatar
kbk committed
212 213 214 215 216
   save_mean=(meanout .ge. 0 .and. runtype .gt. 1)
   if ( save_mean ) then
      LEVEL2 'Mean fields in: ',trim(out_f_mean)
   end if

gotm's avatar
gotm committed
217
   if( .not. dryrun) then
kbk's avatar
kbk committed
218

gotm's avatar
gotm committed
219 220 221 222 223 224 225
      select case (out_fmt)
         case (ASCII)
#if 0
            if (save_2d) call init_2d_ascii(out_f_2d,title,starttime)
            if (save_3d) call init_3d_ascii(out_f_3d,title,starttime)
#else
            STDERR 'ASCII output - not coded yet'
kbk's avatar
kbk committed
226
            stop 'init_output'
gotm's avatar
gotm committed
227 228 229
#endif
         case (NETCDF)
            if (save_2d) call init_2d_ncdf(out_f_2d,title,starttime)
kbk's avatar
kbk committed
230
#ifndef NO_3D
gotm's avatar
gotm committed
231
            if (save_3d) call init_3d_ncdf(out_f_3d,title,starttime)
kbk's avatar
kbk committed
232
#endif
kbk's avatar
kbk committed
233 234
            if (save_mean)  &
                     call init_mean_ncdf(out_f_mean,title,starttime)
gotm's avatar
gotm committed
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
         case (GRADS)
         case DEFAULT
           STDERR 'Fatal error: A non valid input format has been chosen'
           stop 'init_output'
      end select
   end if
#ifdef TEST_NESTING
!   if(nesting) then
      call init_nesting()
!   end if
#endif

#ifdef DEBUG
   write(debug,*) 'Leaving init_output()'
   write(debug,*)
#endif
   return
   end subroutine init_output

!EOC

!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: do_output - write model results to file(s)
!
! !INTERFACE:
   subroutine do_output(runtype,n,timestep)
!
! !DESCRIPTION:
!  Writes calculated fields to files.
!
! !USES:
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
kbk's avatar
kbk committed
271 272
   integer, intent(in)                 :: runtype,n
   REALTYPE, intent(in)                :: timestep
gotm's avatar
gotm committed
273 274 275 276 277 278 279 280 281
!
! !INPUT/OUTPUT PARAMETERS:
!
! !OUTPUT PARAMETERS:
!
! !REVISION HISTORY:
!  22Nov Author name Initial code
!
! !LOCAL VARIABLES:
kbk's avatar
kbk committed
282
   REALTYPE                  :: secs
kbk's avatar
kbk committed
283
   logical                   :: write_2d,write_3d,write_mean=.false.
kbk's avatar
kbk committed
284
   integer                   :: dummy
gotm's avatar
gotm committed
285 286 287 288 289 290 291 292 293 294 295
!EOP
!-------------------------------------------------------------------------
!BOC
#ifdef DEBUG
   integer, save :: Ncall = 0
   Ncall = Ncall+1
   write(debug,*) 'do_output() # ',Ncall
#endif

   write_2d = save_2d .and. n .ge. first_2d .and. mod(n,step_2d).eq.0
   write_3d = save_3d .and. n .ge. first_3d .and. mod(n,step_3d).eq.0
kbk's avatar
kbk committed
296 297 298
   if (meanout .gt. 0 .and. n .gt. 0) then
      write_mean = save_mean .and. (mod(n,meanout) .eq. 0)
   end if
gotm's avatar
gotm committed
299

kbk's avatar
kbk committed
300
   if (write_2d .or. write_3d .or. write_mean) then
gotm's avatar
gotm committed
301
      call write_time_string()
kbk's avatar
kbk committed
302 303 304
      if (write_2d)   LEVEL2 timestr, ': saving 2D .... '
      if (write_3d)   LEVEL2 timestr, ': saving 3D .... '
      if (write_mean) LEVEL2 timestr, ': saving mean fields .... '
kbk's avatar
kbk committed
305
!      call divergence()
gotm's avatar
gotm committed
306 307 308 309 310 311 312 313
      secs = n*timestep
      select case (out_fmt)
         case (ASCII)
#if 0
            if (write_2d) call save_2d_ascii(secs,save_meteo)
            if (write_3d) call save_3d_ascii(secs)
#else
            STDERR 'ASCII output - not coded yet'
kbk's avatar
kbk committed
314
            stop 'do_output'
gotm's avatar
gotm committed
315 316 317
#endif
         case (NETCDF)
            if (write_2d) call save_2d_ncdf(secs)
kbk's avatar
kbk committed
318
#ifndef NO_3D
gotm's avatar
gotm committed
319
            if (write_3d) call save_3d_ncdf(secs)
kbk's avatar
kbk committed
320
#endif
kbk's avatar
kbk committed
321
            if (write_mean) call save_mean_ncdf(secs)
gotm's avatar
gotm committed
322 323 324 325 326 327 328 329 330
         case DEFAULT
           STDERR 'Fatal error: A non valid input format has been chosen'
           stop 'do_output'
      end select
   end if

!  Restart file
   if (hotout .gt. 0 .and. mod(n,hotout) .eq. 0) then
      dummy = n
kbk's avatar
kbk committed
331
      call restart_file(WRITING,trim(hot_out),dummy,runtype)
gotm's avatar
gotm committed
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
   end if

#ifdef DEBUG
   write(debug,*) 'Leaving do_output()'
   write(debug,*)
#endif
   return
   end subroutine do_output

!EOC

!-----------------------------------------------------------------------
!BOP
!
! !ROUTINE: restart_file - read/write the restart file
!
! !INTERFACE:
   subroutine restart_file(mode,fname,loop,runtype)
!
! !DESCRIPTION:
!  This routine write the variables necesaary for a 'hot' model start.
!
! !USES:
   use time, only: timestep,julianday,secondsofday
   use m2d,  only: z,zo,U,fU,zu,zub,SlUx,Slru,V,fV,zv,zvb,SlVx,Slrv,Uint,Vint
kbk's avatar
kbk committed
357 358 359 360 361 362
#ifndef NO_3D
   use m3d,  only: uu,vv,tke,eps,num,nuh,ssen,ssun,ssvn
#ifndef NO_BAROCLINIC
   use m3d,  only: T,S
#endif
#endif
kbk's avatar
kbk committed
363 364
#ifdef SPM
  use m3d,  only: spm,spm_pool,calc_spm,hotstart_spm
365 366 367 368 369 370 371
#endif
#ifdef GETM_BIO
  use bio, only: bio_calc
  use bio_var, only: numc
  use getm_bio, only: hotstart_bio
  use variables_3d,  only: cc3d
#endif
gotm's avatar
gotm committed
372 373 374
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
kbk's avatar
kbk committed
375 376 377
   integer, intent(in)                 :: mode
   character(len=*), intent(in)        :: fname
   integer, intent(in)                 :: runtype
gotm's avatar
gotm committed
378 379
!
! !INPUT/OUTPUT PARAMETERS:
kbk's avatar
kbk committed
380
   integer, intent(inout)              :: loop
gotm's avatar
gotm committed
381 382 383 384 385 386 387
!
! !OUTPUT PARAMETERS:
!
! !REVISION HISTORY:
!  22Nov Author name Initial code
!
! !LOCAL VARIABLES
kbk's avatar
kbk committed
388
   integer, save             :: n=0
389
   integer                   :: i
kbk's avatar
kbk committed
390
   logical, save             :: continuous=.false.
391
   integer                   :: jd,secs 
kbk's avatar
kbk committed
392
   character(len=19)         :: timestr_out
kbk's avatar
kbk committed
393
   REALTYPE                  :: dt
gotm's avatar
gotm committed
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
!
!EOP
!-----------------------------------------------------------------------
!BOC
#ifdef DEBUG
   integer, save :: Ncall = 0
   Ncall = Ncall+1
   write(debug,*) 'restart_file() # ',Ncall
#endif

   if (mode .eq. WRITING) then
      n = n + 1
      LEVEL2 'Saving hotstart file # ',n,' as ',fname
      open(RESTART,file=fname,status='unknown',form='unformatted')
      LEVEL3 'saving loop, julianday, secondsofday and timestep'
      write(RESTART) loop,julianday,secondsofday,timestep
      LEVEL3 'saving basic variables'
      write(RESTART) z,zo,U,zu,zub,SlUx,Slru,V,zv,zvb,SlVx,Slrv
kbk's avatar
kbk committed
412 413
#ifndef NO_3D
      if (runtype .ge. 2)  then
gotm's avatar
gotm committed
414 415 416 417 418
         LEVEL3 'saving 3D barotropic variables'
!kbk         write(RESTART) Uint,Vint
         write(RESTART) uu,vv
         write(RESTART) tke,eps
         write(RESTART) num,nuh
kbk's avatar
kbk committed
419
#ifndef NO_BAROCLINIC
gotm's avatar
gotm committed
420 421 422 423
         if(runtype .ge. 3) then
            LEVEL3 'saving 3D baroclinic variables'
            write(RESTART) T,S
         end if
kbk's avatar
kbk committed
424 425 426 427 428 429
#endif
#ifdef SPM 
         if(save_spm) then 
            LEVEL3 'saving spm'
            write(RESTART) spm
            write(RESTART) spm_pool
430 431 432 433 434 435 436
         end if
#endif
#ifdef GETM_BIO
         if(bio_calc) then
            LEVEL3 'saving bio variables'
            write(RESTART) cc3d
         end if
kbk's avatar
kbk committed
437
#endif
gotm's avatar
gotm committed
438
      end if
kbk's avatar
kbk committed
439
#endif
gotm's avatar
gotm committed
440 441 442 443 444 445 446 447
      close(RESTART)
   end if

   if (mode .eq. READING) then
      LEVEL2 'Reading hotstart file: '
      LEVEL3 trim(fname)
      open(RESTART,file=fname,status='unknown',form='unformatted')
      LEVEL3 'reading loop, julianday, secondsofday and timestep'
kbk's avatar
kbk committed
448 449
!KBK      read(RESTART) loop,julianday,secondsofday,timestep
      read(RESTART) n,jd,secs,dt
gotm's avatar
gotm committed
450 451
      LEVEL3 'reading basic variables'
      read(RESTART) z,zo,U,zu,zub,SlUx,Slru,V,zv,zvb,SlVx,Slrv
kbk's avatar
kbk committed
452 453
#ifndef NO_3D
      if (runtype .ge. 2)  then
gotm's avatar
gotm committed
454 455
!KBK This needs to be changed !!!! KBK
!Only works because E2DFIELD = I2DFIELD
kbk's avatar
kbk committed
456 457 458
         ssen=z
         ssun=zu
         ssvn=zv
gotm's avatar
gotm committed
459 460 461 462 463
         LEVEL3 'reading 3D barotropic variables'
!kbk         read(RESTART) Uint,Vint
         read(RESTART) uu,vv
         read(RESTART) tke,eps
         read(RESTART) num,nuh
kbk's avatar
kbk committed
464
#ifndef NO_BAROCLINIC
gotm's avatar
gotm committed
465 466 467 468
         if(runtype .ge. 3) then
            LEVEL3 'reading 3D baroclinic variables'
            read(RESTART) T,S
         end if
kbk's avatar
kbk committed
469 470 471 472 473 474 475 476 477 478 479 480
#endif
#ifdef SPM 
         if(calc_spm) then
            if (hotstart_spm) then 
               LEVEL3 'reading spm variables'
               read(RESTART) spm
               read(RESTART) spm_pool
            else
               LEVEL3 'spm variables not read from hotstart file'
               LEVEL3 'set spm_init_method=0 to read them from hotstart file'
            end if     
         end if
481 482 483 484 485 486
#endif
#ifdef GETM_BIO
         if(bio_calc .and. hotstart_bio) then
            LEVEL3 'reading bio variables'
            read(RESTART) cc3d
         end if
kbk's avatar
kbk committed
487
#endif
gotm's avatar
gotm committed
488
      end if
kbk's avatar
kbk committed
489
#endif
gotm's avatar
gotm committed
490
      close(RESTART)
kbk's avatar
kbk committed
491 492 493 494 495 496 497
!     make some sanity checks
      if (continuous) then
         loop=n; 
         julianday=jd; secondsofday=secs; timestep=dt;
      else
         if (jd .ne. julianday .or. secs .ne. secondsofday) then
            FATAL 'start time given in getm.inp does not match time'
kbk's avatar
kbk committed
498
            FATAL 'read from hot-start file'
499
            FATAL 'from getm.inp: ',julianday,secondsofday
kbk's avatar
kbk committed
500 501
            call write_time_string(julianday,secondsofday,timestr_out)
            LEVEL3 timestr_out
502
            FATAL 'from hotstart: ',jd,secs
kbk's avatar
kbk committed
503 504
            call write_time_string(jd,secs,timestr_out)
            LEVEL3 timestr_out
kbk's avatar
kbk committed
505 506 507 508
            stop 'restart_file()'
         end if
         if (dt .ne. timestep) then
            LEVEL3 ''
kbk's avatar
kbk committed
509
            LEVEL3 'INFO:'
kbk's avatar
kbk committed
510 511 512 513 514 515
            LEVEL3 'time step changed between hotstart file and value '
            LEVEL3 'given in getm.inp (this is OK - but beware when post-'
            LEVEL3 'processing)'
            LEVEL3 ''
         end if
         loop = 0
kbk's avatar
kbk committed
516
         julianday=jd; secondsofday=secs
kbk's avatar
kbk committed
517
      end if
gotm's avatar
gotm committed
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
   end if
#ifdef DEBUG
   write(debug,*) 'Leaving restart_file()'
   write(debug,*)
#endif
   return
   end subroutine restart_file
!EOC

!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: clean_output - cleans up after run
!
! !INTERFACE:
533
   subroutine clean_output(runtype)
gotm's avatar
gotm committed
534 535 536
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
537
   integer, intent(in)                 :: runtype
gotm's avatar
gotm committed
538 539 540 541 542 543 544 545 546 547 548 549
!
! !INPUT/OUTPUT PARAMETERS:
!
! !OUTPUT PARAMETERS:
!
! !DESCRIPTION:
!  Writes calculated fields to files.
!
! !REVISION HISTORY:
!  22Nov Author name Initial code
!
! !LOCAL VARIABLES:
550
   integer :: zero=0
kbk's avatar
kbk committed
551
   REALTYPE :: dummy
gotm's avatar
gotm committed
552 553 554 555 556 557 558 559 560 561
!
!EOP
!-------------------------------------------------------------------------
!BOC
#ifdef DEBUG
   integer, save :: Ncall = 0
   Ncall = Ncall+1
   write(debug,*) 'clean_output() # ',Ncall
#endif

562 563 564 565 566
!  Save last restart file
   if (hotout .eq. 0) then
      call restart_file(WRITING,trim(hot_out),zero,runtype)
   end if

kbk's avatar
kbk committed
567 568 569 570 571 572 573 574
   if (meanout .eq. 0) then
      select case (out_fmt)
         case(NETCDF)
            dummy=-_ZERO_
            call save_mean_ncdf(dummy)
      end select
   end if

gotm's avatar
gotm committed
575 576
   select case (out_fmt)
      case (NETCDF)
kbk's avatar
kbk committed
577 578
         dummy = -_ONE_*1.
         call save_2d_ncdf(dummy)
gotm's avatar
gotm committed
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
         call ncdf_close()
      case DEFAULT
         STDERR 'Fatal error: A non valid input format has been chosen'
         stop 'clean_output'
   end select

#ifdef DEBUG
   write(debug,*) 'Leaving clean_output()'
   write(debug,*)
#endif
   return
   end subroutine clean_output

!EOC

!-----------------------------------------------------------------------
!BOP
! !IROUTINE: file_names - setup output file names
!
! !INTERFACE:
kbk's avatar
kbk committed
599
   subroutine file_names(runid,myid)
gotm's avatar
gotm committed
600 601 602
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
kbk's avatar
kbk committed
603 604
   character(len=*), intent(in)        ::  runid
   integer, intent(in)                 ::  myid
gotm's avatar
gotm committed
605 606 607 608 609 610 611 612 613 614 615
!
! !INPUT/OUTPUT PARAMETERS:
!
! !OUTPUT PARAMETERS:
!
! !DESCRIPTION:
!
! !REVISION HISTORY:
!  22Nov Author name Initial code
!
! !LOCAL VARIABLES:
kbk's avatar
kbk committed
616 617 618
   character(len=3)                    :: buf
   character(len=16)                   :: pid,ext
   character(len=PATH_MAX)             :: fname
gotm's avatar
gotm committed
619 620 621 622
!
!EOP
!-----------------------------------------------------------------------
!BOC
kbk's avatar
kbk committed
623
   if (myid .ge. 0) then
gotm's avatar
gotm committed
624
      write(buf,'(I3.3)') myid
kbk's avatar
kbk committed
625
      pid = '.' // trim(buf)
gotm's avatar
gotm committed
626 627 628 629
   else
      pid = ''
   end if

kbk's avatar
kbk committed
630
   hot_out = trim(out_dir) //'/'// 'restart' // trim(pid) // '.out'
gotm's avatar
gotm committed
631 632 633
   if (out_fmt .eq. NETCDF) then
      ext = 'nc'
      out_f_2d =  &
kbk's avatar
kbk committed
634
         trim(out_dir) //'/'// trim(runid) // '.2d' // trim(pid) // '.' // ext
gotm's avatar
gotm committed
635
      out_f_3d =  &
kbk's avatar
kbk committed
636
         trim(out_dir) //'/'// trim(runid) // '.3d' // trim(pid) // '.' // ext
kbk's avatar
kbk committed
637 638
      out_f_mean =  &
         trim(out_dir) //'/'// trim(runid) // '.mean' // trim(pid) // '.' // ext
gotm's avatar
gotm committed
639 640 641 642 643 644
   end if

   return
   end subroutine file_names
!EOC

kbk's avatar
kbk committed
645

gotm's avatar
gotm committed
646 647 648 649 650 651
!-----------------------------------------------------------------------

   end module output

!-----------------------------------------------------------------------
! Copyright (C) 2001 - Hans Burchard and Karsten Bolding               !
kbk's avatar
kbk committed
652
!----------------------------------------------------------------------