initialise.F90 8.11 KB
Newer Older
gotm's avatar
gotm committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include "cppdefs.h"
!-----------------------------------------------------------------------
!BOP
!
! !MODULE:  initialise - setup the entire model
!
! !INTERFACE:
   module initialise
!
! !DESCRIPTION:
!
! !USES:
   IMPLICIT NONE
!
! !PUBLIC DATA MEMBERS:
kbk's avatar
kbk committed
16 17 18
   public                              :: init_model
   integer                             :: runtype=1
   logical                             :: dryrun=.false.
gotm's avatar
gotm committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
!
! !REVISION HISTORY:
!  Original author(s): Karsten Bolding & Hans Burchard
!
!EOP
!-----------------------------------------------------------------------

   contains

!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: init_model - initialise getm
!
! !INTERFACE:
kbk's avatar
kbk committed
34
   subroutine init_model(dstr,tstr)
gotm's avatar
gotm committed
35 36
!
! !USES:
kbk's avatar
kbk committed
37
   use kurt_parallel, only: init_parallel,myid
38
#ifdef GETM_PARALLEL
39 40
   use halo_mpi, only: init_mpi,print_MPI_info
#endif
kbk's avatar
kbk committed
41
   use output, only: init_output,do_output,restart_file,out_dir
kbk's avatar
kbk committed
42 43
   use input,  only: init_input
   use domain, only: init_domain
44
   use domain, only: iextr,jextr,imin,imax,jmin,jmax,kmax
45
   use domain, only: vert_cord,maxdepth
kbk's avatar
kbk committed
46 47
   use time, only: init_time,update_time,write_time_string
   use time, only: start,timestr,timestep
48
   use m2d, only: init_2d,postinit_2d, z,zu,zv
bjb's avatar
bjb committed
49
   use getm_timers, only: init_getm_timers, tic, toc, TIM_INITIALIZE
kbk's avatar
kbk committed
50
#ifndef NO_3D
51
   use m2d, only: Uint,Vint
52
   use m3d, only: cord_relax,init_3d,postinit_3d, ssen,ssun,ssvn
kbk's avatar
kbk committed
53
#ifndef NO_BAROCLINIC
kbk's avatar
kbk committed
54
   use m3d, only: T
kbk's avatar
kbk committed
55
#endif
kbk's avatar
kbk committed
56
   use turbulence, only: init_turbulence
gotm's avatar
gotm committed
57
   use mtridiagonal, only: init_tridiagonal
kbk's avatar
kbk committed
58
   use rivers, only: init_rivers
kbk's avatar
kbk committed
59
   use variables_3d, only: avmback,avhback
kbk's avatar
kbk committed
60 61 62
#ifdef SPM
   use suspended_matter, only: init_spm
#endif
Karsten Bolding's avatar
Karsten Bolding committed
63 64 65
#ifdef _FABM_
   use getm_fabm, only: init_getm_fabm
#endif
kbk's avatar
kbk committed
66
#ifdef GETM_BIO
kbk's avatar
kbk committed
67 68
   use bio, only: bio_calc
   use getm_bio, only: init_getm_bio
kbk's avatar
kbk committed
69 70
   use rivers, only: init_rivers_bio
#endif
kbk's avatar
kbk committed
71
#endif
kbk's avatar
kbk committed
72
   use meteo, only: init_meteo,do_meteo
gotm's avatar
gotm committed
73
   use integration,  only: MinN,MaxN
kbk's avatar
kbk committed
74
#ifndef NO_BAROCLINIC
kbk's avatar
kbk committed
75
   use eqstate, only: do_eqstate
kbk's avatar
kbk committed
76
#endif
kbk's avatar
kbk committed
77
   use exceptions
gotm's avatar
gotm committed
78 79 80
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
kbk's avatar
kbk committed
81
   character(len=*)                    :: dstr,tstr
gotm's avatar
gotm committed
82 83 84 85 86 87 88 89 90
!
! !DESCRIPTION:
!  Reads the namelist and makes calls to the init functions of the
!  various model components.
!
! !REVISION HISTORY:
!  22Nov Author name Initial code
!
! !LOCAL VARIABLES:
kbk's avatar
kbk committed
91 92 93 94 95 96
   integer:: i,j
   character(len=8)          :: buf
   character(len=64)         :: runid
   character(len=80)         :: title
   logical                   :: parallel=.false.
   logical                   :: hotstart=.false.
97
   logical                   :: use_epoch=.false.
kbk's avatar
kbk committed
98
   logical                   :: save_initial=.false.
99
#if (defined GETM_PARALLEL && defined INPUT_DIR)
kbk's avatar
kbk committed
100
   character(len=PATH_MAX)   :: input_dir=INPUT_DIR
kbk's avatar
kbk committed
101
#else
kbk's avatar
kbk committed
102
   character(len=PATH_MAX)   :: input_dir='./'
kbk's avatar
kbk committed
103
#endif
kbk's avatar
kbk committed
104
   character(len=PATH_MAX)   :: hot_in=''
kbk's avatar
kbk committed
105

kbk's avatar
kbk committed
106 107
   namelist /param/ &
             dryrun,runid,title,parallel,runtype,  &
108
             hotstart,use_epoch,save_initial
gotm's avatar
gotm committed
109 110 111 112 113 114 115 116
!EOP
!-------------------------------------------------------------------------
!BOC
#ifdef DEBUG
   integer, save :: Ncall = 0
   Ncall = Ncall+1
   write(debug,*) 'init_model() # ',Ncall
#endif
bjb's avatar
bjb committed
117 118 119 120 121
#ifndef NO_TIMERS
   call init_getm_timers()
#endif
   ! Immediately start to time (rest of) init:
   call tic(TIM_INITIALIZE)
gotm's avatar
gotm committed
122

kbk's avatar
kbk committed
123 124 125 126 127 128 129 130 131 132 133
   ! We need to pass info about the input directory
#if 0
   call getarg(1,base_dir)
   if(len_trim(base_dir) .eq. 0) then
      call getenv("base_dir",base_dir)
   end if
   if(len_trim(base_dir) .gt. 0) then
      base_dir = trim(base_dir) // '/'
   end if
#endif

134
!
135
! In parallel mode it is imperative to let the instances
136 137 138
! "say hello" right away. For MPI this changes the working directory,
! so that input files can be read.
!
139
#ifdef GETM_PARALLEL
140 141 142
   call init_mpi()
#endif

143
#if (defined GETM_PARALLEL && defined INPUT_DIR)
kbk's avatar
kbk committed
144 145 146
   STDERR 'input_dir:'
   STDERR trim(input_dir)
#endif
gotm's avatar
gotm committed
147 148 149 150
!
! Open the namelist file to get basic run parameters.
!
   title='A descriptive title can be specified in the param namelist'
kbk's avatar
kbk committed
151
   open(NAMLST,status='unknown',file=trim(input_dir) // "/getm.inp")
gotm's avatar
gotm committed
152 153
   read(NAMLST,NML=param)

kbk's avatar
kbk committed
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
#ifdef NO_BAROCLINIC
   if(runtype .ge. 3) then
      FATAL 'getm not compiled for baroclinic runs'
      stop 'init_model()'
   end if
#endif

#ifdef NO_3D
   if(runtype .ge. 2) then
      FATAL 'getm not compiled for 3D runs'
      stop 'init_model()'
   end if
#endif

! call all modules init_ ... routines

gotm's avatar
gotm committed
170
   if (parallel) then
171
#ifdef GETM_PARALLEL
kbk's avatar
kbk committed
172 173 174 175 176 177
      call init_parallel(runid,input_dir)
#else
      STDERR 'You must define GETM_PARALLEL and recompile'
      STDERR 'in order to run in parallel'
      stop 'init_model()'
#endif
gotm's avatar
gotm committed
178
   end if
179

180
#if (defined GETM_PARALLEL && defined SLICE_MODEL)
181
    call getm_error('init_model()', &
182
         'SLICE_MODEL does not work with GETM_PARALLEL - for now')
183 184
#endif

kbk's avatar
kbk committed
185 186 187 188 189 190 191
   STDERR LINE
   STDERR 'getm ver. ',RELEASE,': Started on  ',dstr,' ',tstr
   STDERR LINE
   STDERR 'Initialising....'
   STDERR LINE
   LEVEL1 'the run id is: ',trim(runid)
   LEVEL1 'the title is:  ',trim(title)
gotm's avatar
gotm committed
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207

   select case (runtype)
      case (1)
         LEVEL1 '2D run (hotstart=',hotstart,')'
      case (2)
         LEVEL1 '3D run - no density (hotstart=',hotstart,')'
      case (3)
         LEVEL1 '3D run - frozen density (hotstart=',hotstart,')'
      case (4)
         LEVEL1 '3D run - full (hotstart=',hotstart,')'
      case default
         FATAL 'A non valid runtype has been specified.'
         stop 'initialise()'
   end select

   call init_time(MinN,MaxN)
kbk's avatar
kbk committed
208 209 210
   if(use_epoch) then
      LEVEL2 'using "',start,'" as time reference'
   end if
gotm's avatar
gotm committed
211

kbk's avatar
kbk committed
212
   call init_domain(input_dir)
gotm's avatar
gotm committed
213

kbk's avatar
kbk committed
214
   call init_meteo(hotstart)
gotm's avatar
gotm committed
215

kbk's avatar
kbk committed
216
#ifndef NO_3D
gotm's avatar
gotm committed
217
   call init_rivers()
kbk's avatar
kbk committed
218 219
#endif

gotm's avatar
gotm committed
220 221
   call init_2d(runtype,timestep,hotstart)

kbk's avatar
kbk committed
222
#ifndef NO_3D
gotm's avatar
gotm committed
223 224
   if (runtype .gt. 1) then
      call init_3d(runtype,timestep,hotstart)
kbk's avatar
kbk committed
225
#ifndef CONSTANT_VISCOSITY
kbk's avatar
kbk committed
226
      call init_turbulence(60,trim(input_dir) // 'gotmturb.nml',kmax)
kbk's avatar
kbk committed
227 228 229 230 231
#else
      LEVEL3 'turbulent viscosity and diffusivity set to constant (-DCONSTANT_VISCOSITY)'
#endif
      LEVEL2 'background turbulent viscosity set to',avmback
      LEVEL2 'background turbulent diffusivity set to',avhback
gotm's avatar
gotm committed
232
      call init_tridiagonal(kmax)
233

kbk's avatar
kbk committed
234 235 236
#ifdef SPM
      call init_spm(trim(input_dir) // 'spm.inp',runtype)
#endif
Karsten Bolding's avatar
Karsten Bolding committed
237 238 239 240
#ifdef _FABM_
      call init_getm_fabm(trim(input_dir) // 'getm_fabm.inp')
!KB      call init_rivers_bio
#endif
kbk's avatar
kbk committed
241
#ifdef GETM_BIO
kbk's avatar
kbk committed
242
      call init_getm_bio(trim(input_dir) // 'getm_bio.inp')
kbk's avatar
kbk committed
243 244
      call init_rivers_bio
#endif
gotm's avatar
gotm committed
245
   end if
kbk's avatar
kbk committed
246
#endif
gotm's avatar
gotm committed
247

248 249
   call init_output(runid,title,start,runtype,dryrun,myid)

kbk's avatar
kbk committed
250 251
   close(NAMLST)

gotm's avatar
gotm committed
252 253 254 255 256 257 258
#if 0
   call init_waves(hotstart)
   call init_biology(hotstart)
#endif

   if (hotstart) then
      LEVEL1 'hotstart'
kbk's avatar
kbk committed
259
      if (myid .ge. 0) then
kbk's avatar
kbk committed
260 261
         write(buf,'(I3.3)') myid
         buf = '.' // trim(buf) // '.in'
kbk's avatar
kbk committed
262 263 264
      else
         buf = '.in'
      end if
kbk's avatar
kbk committed
265
      hot_in = trim(out_dir) //'/'// 'restart' // trim(buf)
266
      call restart_file(READING,trim(hot_in),MinN,runtype,use_epoch)
kbk's avatar
kbk committed
267
      LEVEL3 'MinN adjusted to ',MinN
268 269 270 271
      call postinit_2d(runtype)
#ifndef NO_3D
      call postinit_3d(runtype)
#endif
272
      call depth_update
kb's avatar
kb committed
273
#ifndef NO_3D
274
      if (runtype .ge. 2) then
275
         call coordinates(hotstart)
276 277
         Uint=_ZERO_
         Vint=_ZERO_
gotm's avatar
gotm committed
278
      end if
kb's avatar
kb committed
279
#endif
280

kbk's avatar
kbk committed
281 282 283
#ifndef NO_BAROCLINIC
      if (runtype .ge. 3) call do_eqstate()
#endif
gotm's avatar
gotm committed
284 285 286 287 288 289
      call update_time(MinN)
      call write_time_string()
      LEVEL3 timestr
      MinN = MinN+1
   end if

kbk's avatar
kbk committed
290
   call init_input(input_dir,MinN)
gotm's avatar
gotm committed
291

bjb's avatar
bjb committed
292 293 294
   call toc(TIM_INITIALIZE)
   ! The rest is timed with meteo and output.

kbk's avatar
kbk committed
295 296
   if(runtype .le. 2) then
      call do_meteo(MinN)
kb's avatar
kb committed
297
#ifndef NO_3D
kbk's avatar
kbk committed
298 299 300
#ifndef NO_BAROCLINIC
   else
      call do_meteo(MinN,T(:,:,kmax))
kb's avatar
kb committed
301
#endif
kbk's avatar
kbk committed
302 303
#endif
   end if
gotm's avatar
gotm committed
304

305 306 307
   if (save_initial .and. .not. dryrun) then
      call do_output(runtype,MinN-1,timestep)
   end if
gotm's avatar
gotm committed
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323

#ifdef DEBUG
   write(debug,*) 'Leaving init_model()'
   write(debug,*)
#endif
   return
   end subroutine init_model
!EOC

!-----------------------------------------------------------------------

   end module initialise

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