initialise.F90 8.62 KB
Newer Older
1
!$Id: initialise.F90,v 1.8 2005-09-23 11:27:10 kbk Exp $
gotm's avatar
gotm committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#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
17 18 19
   public                              :: init_model
   integer                             :: runtype=1
   logical                             :: dryrun=.false.
gotm's avatar
gotm committed
20 21 22 23 24
!
! !REVISION HISTORY:
!  Original author(s): Karsten Bolding & Hans Burchard
!
!  $Log: initialise.F90,v $
25 26 27 28
!  Revision 1.8  2005-09-23 11:27:10  kbk
!  support for biology via GOTMs biology modules
!
!  Revision 1.7  2004/06/15 09:04:51  kbk
kbk's avatar
kbk committed
29 30 31
!  CONST_VISC --> CONSTANT_VISCOSITY - Ruiz
!
!  Revision 1.6  2004/01/13 07:49:06  kbk
32 33 34
!  need maxdepth in parameter list to coordinates()
!
!  Revision 1.5  2003/09/03 05:49:31  kbk
kbk's avatar
kbk committed
35 36 37
!  hotstart files now read from - out_dir
!
!  Revision 1.4  2003/08/15 12:50:12  kbk
kbk's avatar
kbk committed
38 39 40
!  use HALO in loop boundaries
!
!  Revision 1.3  2003/04/23 12:03:46  kbk
kbk's avatar
kbk committed
41 42 43
!  cleaned code + TABS to spaces
!
!  Revision 1.2  2003/04/07 16:39:16  kbk
kbk's avatar
kbk committed
44 45 46 47
!  parallel support, NO_3D
!
!  Revision 1.1.1.1  2002/05/02 14:01:25  gotm
!  recovering after CVS crash
gotm's avatar
gotm committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
!
!  Revision 1.10  2001/10/22 12:24:07  bbh
!  Typo
!
!  Revision 1.9  2001/10/22 11:45:27  bbh
!  Only save initial fields if not dryrun
!
!  Revision 1.8  2001/09/18 17:52:03  bbh
!  save_initial now in namelist
!
!  Revision 1.7  2001/09/18 17:48:32  bbh
!  Added algoritm for rivers - getting river data still missing
!
!  Revision 1.6  2001/09/13 15:00:28  bbh
!  Use the new ncdf-scheme
!
!  Revision 1.5  2001/07/26 13:57:14  bbh
!  Meteo working - needs some polishing
!
!  Revision 1.4  2001/06/04 13:09:53  bbh
!  Includes - dryrun - in call to init_output()
!
!  Revision 1.3  2001/05/03 20:11:11  bbh
!  Use runtype in init_3d
!
!  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_model - initialise getm
!
! !INTERFACE:
kbk's avatar
kbk committed
92
   subroutine init_model(dstr,tstr)
gotm's avatar
gotm committed
93 94
!
! !USES:
kbk's avatar
kbk committed
95
   use kurt_parallel, only: init_parallel,myid
kbk's avatar
kbk committed
96
   use output, only: init_output,do_output,restart_file,out_dir
kbk's avatar
kbk committed
97 98 99 100
   use input,  only: init_input
   use domain, only: init_domain
   use domain, only: iextr,jextr,imin,imax,jmin,jmax
   use domain, only: iimin,iimax,jjmin,jjmax,kmax
101
   use domain, only: vert_cord,maxdepth
kbk's avatar
kbk committed
102 103 104
   use time, only: init_time,update_time,write_time_string
   use time, only: start,timestr,timestep
   use m2d, only: init_2d,z,zu,zv
kbk's avatar
kbk committed
105
#ifndef NO_3D
kbk's avatar
kbk committed
106
   use m3d, only: cord_relax,init_3d,ssen,ssun,ssvn
kbk's avatar
kbk committed
107
#ifndef NO_BAROCLINIC
kbk's avatar
kbk committed
108
   use m3d, only: T
109 110 111
#endif
#ifdef GETM_BIO
   use rivers, only: init_rivers_bio
kbk's avatar
kbk committed
112
#endif
kbk's avatar
kbk committed
113
   use turbulence, only: init_turbulence
gotm's avatar
gotm committed
114
   use mtridiagonal, only: init_tridiagonal
kbk's avatar
kbk committed
115
   use rivers, only: init_rivers
kbk's avatar
kbk committed
116
   use variables_3d, only: avmback,avhback
kbk's avatar
kbk committed
117
#endif
kbk's avatar
kbk committed
118
   use meteo, only: init_meteo,do_meteo
gotm's avatar
gotm committed
119
   use integration,  only: MinN,MaxN
kbk's avatar
kbk committed
120
#ifndef NO_BAROCLINIC
kbk's avatar
kbk committed
121
   use eqstate, only: do_eqstate
kbk's avatar
kbk committed
122
#endif
gotm's avatar
gotm committed
123 124 125
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
kbk's avatar
kbk committed
126
   character(len=*)                    :: dstr,tstr
gotm's avatar
gotm committed
127 128 129 130 131 132 133 134 135 136 137 138 139
!
! !INPUT/OUTPUT PARAMETERS:
!
! !OUTPUT PARAMETERS:
!
! !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
140 141 142 143 144 145 146
   integer:: i,j
   character(len=8)          :: buf
   character(len=64)         :: runid
   character(len=80)         :: title
   logical                   :: parallel=.false.
   logical                   :: hotstart=.false.
   logical                   :: save_initial=.false.
kbk's avatar
kbk committed
147
#if (defined PARALLEL && defined INPUT_DIR)
kbk's avatar
kbk committed
148
   character(len=PATH_MAX)   :: input_dir=INPUT_DIR
kbk's avatar
kbk committed
149
#else
kbk's avatar
kbk committed
150
   character(len=PATH_MAX)   :: input_dir='./'
kbk's avatar
kbk committed
151
#endif
kbk's avatar
kbk committed
152
   character(len=PATH_MAX)   :: hot_in=''
kbk's avatar
kbk committed
153

kbk's avatar
kbk committed
154 155 156
   namelist /param/ &
             dryrun,runid,title,parallel,runtype,  &
             hotstart,save_initial
gotm's avatar
gotm committed
157 158 159 160 161 162 163 164 165 166
!
!EOP
!-------------------------------------------------------------------------
!BOC
#ifdef DEBUG
   integer, save :: Ncall = 0
   Ncall = Ncall+1
   write(debug,*) 'init_model() # ',Ncall
#endif

kbk's avatar
kbk committed
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
   ! 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

#if (defined PARALLEL && defined INPUT_DIR)
   STDERR 'input_dir:'
   STDERR trim(input_dir)
#endif
gotm's avatar
gotm committed
182 183 184 185
!
! 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
186
   open(NAMLST,status='unknown',file=trim(input_dir) // "/getm.inp")
gotm's avatar
gotm committed
187 188
   read(NAMLST,NML=param)

kbk's avatar
kbk committed
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
#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
205
   if (parallel) then
kbk's avatar
kbk committed
206 207 208 209 210 211 212
#ifdef PARALLEL
      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
213
   end if
kbk's avatar
kbk committed
214 215 216 217 218 219 220
   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
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237

   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
238
   call init_domain(input_dir)
gotm's avatar
gotm committed
239 240 241

   call init_meteo()

kbk's avatar
kbk committed
242
#ifndef NO_3D
gotm's avatar
gotm committed
243
   call init_rivers()
kbk's avatar
kbk committed
244 245
#endif

gotm's avatar
gotm committed
246 247
   call init_2d(runtype,timestep,hotstart)

kbk's avatar
kbk committed
248
#ifndef NO_3D
gotm's avatar
gotm committed
249 250
   if (runtype .gt. 1) then
      call init_3d(runtype,timestep,hotstart)
251 252 253
#ifdef GETM_BIO
      call init_rivers_bio
#endif
kbk's avatar
kbk committed
254
#ifndef CONSTANT_VISCOSITY
kbk's avatar
kbk committed
255
      call init_turbulence(60,trim(input_dir) // 'gotmturb.inp',kmax)
kbk's avatar
kbk committed
256 257 258 259 260
#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
261
      call init_tridiagonal(kmax)
262

gotm's avatar
gotm committed
263
   end if
kbk's avatar
kbk committed
264
#endif
gotm's avatar
gotm committed
265

266 267
   call init_output(runid,title,start,runtype,dryrun,myid)

gotm's avatar
gotm committed
268 269 270 271 272 273 274
#if 0
   call init_waves(hotstart)
   call init_biology(hotstart)
#endif

   if (hotstart) then
      LEVEL1 'hotstart'
kbk's avatar
kbk committed
275
      if (myid .ge. 0) then
kbk's avatar
kbk committed
276 277
         write(buf,'(I3.3)') myid
         buf = '.' // trim(buf) // '.in'
kbk's avatar
kbk committed
278 279 280
      else
         buf = '.in'
      end if
kbk's avatar
kbk committed
281
      hot_in = trim(out_dir) //'/'// 'restart' // trim(buf)
kbk's avatar
kbk committed
282 283
      call restart_file(READING,trim(hot_in),MinN,runtype)
#ifndef NO_3D
gotm's avatar
gotm committed
284 285
      if (runtype .gt. 1) then
         call start_macro()
286
         call coordinates(vert_cord,cord_relax,maxdepth)
gotm's avatar
gotm committed
287
      end if
kbk's avatar
kbk committed
288
#endif
gotm's avatar
gotm committed
289
      call depth_update
kbk's avatar
kbk committed
290 291 292
#ifndef NO_BAROCLINIC
      if (runtype .ge. 3) call do_eqstate()
#endif
gotm's avatar
gotm committed
293 294 295 296 297 298
      call update_time(MinN)
      call write_time_string()
      LEVEL3 timestr
      MinN = MinN+1
   end if

kbk's avatar
kbk committed
299 300
#ifndef NO_3D
   if (runtype .ge. 2) then
kbk's avatar
kbk committed
301 302
      do j=jjmin-HALO,jjmax+HALO
         do i=iimin-HALO,iimax+HALO
gotm's avatar
gotm committed
303
            ssen(i,j)=z(i,j)
kbk's avatar
kbk committed
304 305 306 307
         end do
      end do
      do j=jjmin-HALO,jjmax+HALO
         do i=iimin-HALO,iimax+HALO-1
gotm's avatar
gotm committed
308
            ssun(i,j)=zu(i,j)
kbk's avatar
kbk committed
309 310 311 312
         end do
      end do
      do j=jjmin-HALO,jjmax+HALO-1
         do i=iimin-HALO,iimax+HALO
gotm's avatar
gotm committed
313 314 315 316
            ssvn(i,j)=zv(i,j)
         end do
      end do
   end if
kbk's avatar
kbk committed
317
#endif
gotm's avatar
gotm committed
318

kbk's avatar
kbk committed
319
   call init_input(input_dir,MinN)
gotm's avatar
gotm committed
320

kbk's avatar
kbk committed
321 322 323 324 325 326 327
   if(runtype .le. 2) then
      call do_meteo(MinN)
#ifndef NO_BAROCLINIC
   else
      call do_meteo(MinN,T(:,:,kmax))
#endif
   end if
gotm's avatar
gotm committed
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345

   if (save_initial .and. .not. dryrun) call do_output(runtype,0,_ZERO_)

#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               !
!-----------------------------------------------------------------------