source: trunk/LMDZ.GENERIC/libf/phystd/dyn1d/kcm1d.F90 @ 2987

Last change on this file since 2987 was 2898, checked in by emillour, 21 months ago

Generic PCM:
Some cleanup in aerosol_mod.F90 : integrate "iniaerosol" in the module.
Also adapted kcm1d to follow up on recent code updates.
EM

  • Property svn:executable set to *
File size: 15.5 KB
Line 
1program kcm1d
2
3  use infotrac, only: nqtot
4  use radinc_h,      only: NAERKIND
5  use radcommon_h,   only: L_NSPECTI, L_NSPECTV, sigma, glat
6  use watercommon_h, only: mH2O
7  use ioipsl_getincom, only: getin
8  use comsaison_h, only: mu0, fract, dist_star
9  use planete_mod
10  use callkeys_mod, only: pceil, tstrat, tracer, global1d
11  use inifis_mod, only: inifis
12  use aerosol_mod, only: iniaerosol
13  use callcorrk_mod, only: callcorrk
14  use comcstfi_mod
15  use mod_grid_phy_lmdz, only : regular_lonlat
16  use regular_lonlat_mod, only: init_regular_lonlat
17  use physics_distribution_mod, only: init_physics_distribution
18  use regular_lonlat_mod, only: init_regular_lonlat
19  use mod_interface_dyn_phys, only: init_interface_dyn_phys
20  use geometry_mod, only: init_geometry
21  use dimphy, only : init_dimphy
22
23  implicit none
24
25  !==================================================================
26  !     
27  !     Purpose
28  !     -------
29  !     Run the universal model radiative transfer once in a 1D column.
30  !     Useful for climate evolution studies etc.
31  !     
32  !     It can be compiled with a command like (e.g. for 25 layers):
33  !                                  "makegcm -p std -d 25 kcm1d"
34  !     It requires the files "callphys.def", "gases.def"
35  !     "traceur.def", and "run.def" with a line "INCLUDEDEF=callphys.def"
36  !
37  !     Authors
38  !     -------
39  !     - R. Wordsworth
40  !     - updated by M. Turbet (June 2017)
41  !
42  !==================================================================
43
44#include "dimensions.h"
45!#include "dimphys.h"
46
47  ! --------------------------------------------------------------
48  !  Declarations
49  ! --------------------------------------------------------------
50
51  integer nlayer,nlevel,nq
52  integer ilay,ilev,iq,iw,iter
53  real play(llm)     ! Pressure at the middle of the layers [Pa]
54  real zlay(llm)     ! Altitude at middle of the layers [km]
55  real plev(llm+1)   ! Intermediate pressure levels [Pa]
56  real temp(llm)     ! temperature at the middle of the layers [K]
57  real,allocatable :: q(:,:)   ! tracer mixing ratio [kg/kg]
58  real,allocatable :: vmr(:,:) ! tracer mixing ratio [mol/mol]
59  real,allocatable :: qsurf(:)        ! tracer surface budget [kg/kg] ????
60  real psurf,psurf_n,tsurf(1)     
61
62  real emis(1), albedo(1), albedo_equivalent(1)
63  real albedo_wv(1,L_NSPECTV)
64
65  real muvar(llm+1)
66
67  real dtsw(llm) ! heating rate (K/s) due to SW
68  real dtlw(llm) ! heating rate (K/s) due to LW
69  real fluxsurf_lw(1)   ! incident LW flux to surf (W/m2)
70  real fluxtop_lw(1)    ! outgoing LW flux to space (W/m2)
71  real fluxsurf_sw(1)   ! incident SW flux to surf (W/m2)
72  real fluxsurfabs_sw(1) ! absorbed SW flux by the surf (W/m2)
73  real fluxabs_sw(1)    ! SW flux absorbed by planet (W/m2)
74  real fluxtop_dn(1)    ! incident top of atmosphere SW flux (W/m2)
75
76  ! not used
77  real cloudfrac(1,llm)
78  real totcloudfrac(1)
79  real tau_col(1)
80
81  real dTstrat
82  real aerosol(llm,naerkind) ! aerosol tau (kg/kg)
83  real OLR_nu(1,L_NSPECTI)
84  real OSR_nu(1,L_NSPECTV)
85  real GSR_nu(1,L_NSPECTV)
86  real int_dtaui(1,llm,L_NSPECTI)
87  real int_dtauv(1,llm,L_NSPECTV)
88  real Eatmtot
89
90  integer ierr
91  logical firstcall,lastcall
92
93  character*20,allocatable :: nametrac(:)   ! name of the tracer (no need for adv trac common)
94 
95  real :: latitude(1), longitude(1), cell_area(1), phisfi(1)
96 
97  !     added by JVO and YJ to read modern traceur.def
98  character(len=500) :: line ! to store a line of text
99  LOGICAL :: moderntracdef=.false. ! JVO, YJ : modern traceur.def
100
101  ! --------------
102  ! Initialisation
103  ! --------------
104
105  pi=2.E+0*asin(1.E+0)
106
107  cloudfrac(1,:)  = 0.0
108  totcloudfrac(1)  = 0.0
109
110
111  nlayer=llm
112  nlevel=nlayer+1
113
114  !! this is defined in comsaison_h
115  ALLOCATE(mu0(1))
116  ALLOCATE(fract(1))
117  ALLOCATE(glat(1))
118
119  !  Load parameters from "run.def"
120  ! -------------------------------
121
122  ! check if 'kcm1d.def' file is around (otherwise reading parameters
123  ! from callphys.def via getin() routine won't work.)
124  open(90,file='kcm1d.def',status='old',form='formatted',&
125       iostat=ierr)
126  if (ierr.ne.0) then
127     write(*,*) 'Cannot find required file "kcm1d.def"'
128     write(*,*) '  (which should contain some input parameters'
129     write(*,*) '   along with the following line:'
130     write(*,*) '   INCLUDEDEF=callphys.def'
131     write(*,*) '   )'
132     write(*,*) ' ... might as well stop here ...'
133     stop
134  else
135     close(90)
136  endif
137 
138! now, run.def is needed anyway. so we create a dummy temporary one
139! for ioipsl to work. if a run.def is already here, stop the
140! program and ask the user to do a bit of cleaning
141  open(90,file='run.def',status='old',form='formatted',&
142       iostat=ierr)
143  if (ierr.eq.0) then
144     close(90)
145     write(*,*) 'There is already a run.def file.'
146     write(*,*) 'This is not compatible with 1D runs.'
147     write(*,*) 'Please remove the file and restart the run.'
148     write(*,*) 'Runtime parameters are supposed to be in kcm1d.def'
149     stop
150  else
151     call system('touch run.def')
152     call system("echo 'INCLUDEDEF=callphys.def' >> run.def")
153     call system("echo 'INCLUDEDEF=kcm1d.def' >> run.def")
154  endif
155   
156! check if we are going to run with or without tracers
157  write(*,*) "Run with or without tracer transport ?"
158  tracer=.false. ! default value
159  call getin("tracer",tracer)
160  write(*,*) " tracer = ",tracer
161
162
163
164  ! Tracer initialisation
165  ! ---------------------
166  if (tracer) then
167     ! load tracer names from file 'traceur.def'
168     open(90,file='traceur.def',status='old',form='formatted',&
169          iostat=ierr)
170     if (ierr.eq.0) then
171        write(*,*) "kcm1d: Reading file traceur.def"
172        ! read number of tracers:
173        !! - Modif. by JVO and YJ for modern planetary traceur.def ---------------
174        READ(90,'(A)') line
175        IF (trim(line).ne.'#ModernTrac-v1') THEN ! Test modern traceur.def
176           READ(line,*,iostat=ierr) nq ! Try standard traceur.def
177        ELSE
178           moderntracdef = .true.
179           DO
180             READ(90,'(A)',iostat=ierr) line
181             IF (ierr.eq.0) THEN
182               IF (index(line,'#').ne.1) THEN ! Allows arbitary number of comments lines in the header
183                 READ(line,*,iostat=ierr) nq
184                 EXIT
185               ENDIF
186             ELSE ! If pb, or if reached EOF without having found nbtr
187                write(*,*) "rcm1d: error reading number of tracers"
188                write(*,*) "   (first line of traceur.def) "
189                stop
190             ENDIF
191           ENDDO
192        ENDIF ! if modern or standard traceur.def
193        if (ierr.ne.0) then
194           write(*,*) "kcm1d: error reading number of tracers"
195           write(*,*) "   (first line of traceur.def) "
196           stop
197        endif
198        nqtot=nq
199        ! allocate arrays which depend on number of tracers
200        allocate(nametrac(nq))
201        allocate(q(nlayer,nq))
202        allocate(vmr(nlayer,nq))
203        allocate(qsurf(nq))
204
205        do iq=1,nq
206           ! minimal version, just read in the tracer names, 1 per line
207           read(90,*,iostat=ierr) nametrac(iq)
208           write(*,*) 'tracer here is', nametrac(iq)
209           if (ierr.ne.0) then
210              write(*,*) 'kcm1d: error reading tracer names...'
211              stop
212           endif
213        enddo !of do iq=1,nq
214        close(90)
215     endif
216
217     call initracer(1,nq)
218
219  endif
220 
221
222
223
224
225  psurf_n=100000. ! default value for psurf
226  print*,'Dry surface pressure (Pa)?'
227  call getin("psurf",psurf_n)
228  write(*,*) " psurf = ",psurf_n
229
230! OK. now that run.def has been read once -- any variable is in memory.
231! so we can dump the dummy run.def
232  call system("rm -rf run.def")
233
234  tsurf=300.0 ! default value for tsurf
235  print*,'Surface temperature (K)?'
236  call getin("tref",tsurf)
237  write(*,*) " tsurf = ",tsurf
238
239  g=10.0 ! default value for g
240  print*,'Gravity ?'
241  call getin("g",g)
242  write(*,*) " g = ",g
243  glat(1)=g
244
245  periastr = 1.0
246  apoastr  = 1.0
247  print*,'Periastron (AU)?'
248  call getin("periastr",periastr)
249  write(*,*) "periastron = ",periastr
250  dist_star = periastr
251  fract     = 0.5
252  print*,'Apoastron (AU)?'
253  call getin("apoastr",apoastr)
254  write(*,*) "apoastron = ",apoastr
255
256  albedo=0.2 ! default value for albedo
257  print*,'Albedo of bare ground?'
258  call getin("albedo",albedo)
259  write(*,*) " albedo = ",albedo
260  do iw=1,L_NSPECTV
261     albedo_wv(1,iw)=albedo(1)
262  enddo
263
264  emis=1.0 ! default value for emissivity
265  PRINT *,'Emissivity of bare ground ?'
266  call getin("emis",emis)
267  write(*,*) " emis = ",emis
268
269  pceil=100.0 ! Pascals
270  PRINT *,'Ceiling pressure (Pa) ?'
271  call getin("pceil",pceil)
272  write(*,*) " pceil = ", pceil
273
274!!! GEOGRAPHICAL INITIALIZATIONS
275     !!! AREA. useless in 1D
276  cell_area(1)=1.E+0 !JL+EM to have access to the area in the diagfi.nc files.
277     !!! GEOPOTENTIAL. useless in 1D because control by surface pressure
278  phisfi(1)=0.E+0
279     !!! LATITUDE. can be set.
280  latitude=0 ! default value for latitude
281  PRINT *,'latitude (in degrees) ?'
282  call getin("latitude",latitude)
283  write(*,*) " latitude = ",latitude
284  latitude=latitude*pi/180.E+0
285     !!! LONGITUDE. useless in 1D.
286  longitude=0.E+0
287  longitude=longitude*pi/180.E+0
288
289  rad=6400000.
290  !rad = -99999.
291  !PRINT *,'PLANETARY RADIUS in m ?'
292  !call getin("rad",rad)
293  ! Planetary  radius is needed to compute shadow of the rings
294  !IF (rad.eq.-99999. .and. rings_shadow .eqv. .true.) THEN
295  !   PRINT *,"STOP. I NEED rad IN RCM1D.DEF."
296  !   STOP
297  !ELSE
298  !   PRINT *,"--> rad = ",rad
299  !ENDIF
300
301
302
303  call init_physics_distribution(regular_lonlat,4,1,1,1,nlayer,1)
304  call init_interface_dyn_phys
305  CALL init_regular_lonlat(1,1,longitude,latitude,(/0.,0./),(/0.,0./))
306  call init_geometry(1,longitude,latitude,(/0.,0.,0.,0./),(/0.,0.,0.,0./),cell_area)
307  call init_dimphy(1,nlayer) ! Initialize dimphy module
308
309!!! CALL INIFIS
310!!! - read callphys.def
311!!! - calculate sine and cosine of longitude and latitude
312!!! - calculate mugaz and cp
313!!! NB: some operations are being done dummily in inifis in 1D
314!!! - physical constants: nevermind, things are done allright below
315!!! - physical frequency: nevermind, in inifis this is a simple print
316
317  cpp=1.d-7 !JL because we divide by cpp in inifis, there may be a more elegant solution
318  CALL inifis(1,llm,nq,0,86400.0,1,1.0,latitude,longitude,cell_area,rad,g,r,cpp)
319
320  if(.not.global1d)then
321     print*,'Error, kcm1d must have global1d=.true. in kcm1d.def!'
322     stop
323  end if
324
325  !write(*,*) 'BASE 1'
326  !write(*,*) 1,llm,nq,0,86400.0,1,1.0,latitude,longitude,cell_area,rad,g,r,cpp
327
328  do iq=1,nq
329     do ilay=1,nlayer
330        q(ilay,iq) = 0.
331     enddo
332  enddo
333 
334  do iq=1,nq
335     qsurf(iq) = 0.
336  enddo
337
338  firstcall = .true.
339  lastcall  = .false.
340
341  iter    = 1
342  Tstrat  = 150.0
343  dTstrat = 1000.0
344
345  ! ---------
346  ! Run model
347  ! ---------
348  !do
349  psurf = psurf_n
350
351     !    Create vertical profiles
352  call kcmprof_fn(nlayer,psurf,qsurf(1),tsurf,    &
353       tstrat,play,plev,zlay,temp,q(:,1),muvar(1))
354         
355
356  !write(*,*) 'BASE 2'
357  !write(*,*) nlayer,psurf,qsurf(1),tsurf,    &
358  !           tstrat
359  !write(*,*) play
360  !write(*,*) plev
361  !write(*,*) zlay
362  !write(*,*) temp
363  !write(*,*) q(:,1),muvar(1)
364
365         
366               
367     call iniaerosol
368     
369
370     
371
372     !    Run radiative transfer
373     call callcorrk(1,nlayer,q,nq,qsurf,                  &
374          albedo_wv,albedo_equivalent,                    &
375          emis,mu0,plev,play,temp,                        &
376          tsurf,fract,dist_star,aerosol,muvar,            &
377          dtlw,dtsw,fluxsurf_lw,fluxsurf_sw,              &
378          fluxsurfabs_sw,fluxtop_lw,                      &
379          fluxabs_sw,fluxtop_dn,OLR_nu,OSR_nu,GSR_nu,     &
380          int_dtaui,int_dtauv,                            &
381          tau_col,cloudfrac,totcloudfrac,                 &
382          .false.,firstcall,lastcall)
383
384     !write(*,*) 'BASE 3'
385     !write(*,*) 1,nlayer,'A',q,'B',nq,'C',qsurf,                      &
386     !     albedo_wv,'D',albedo_equivalent,'E',                    &
387     !     emis,'F',mu0,'G',plev,'H',play,'I',temp,'J',                        &
388     !     tsurf,'K',fract,'L',dist_star,'M',aerosol,'N',muvar,'O',            &
389     !     dtlw,'P',dtsw,'Q',fluxsurf_lw,'R',fluxsurf_sw,'S',              &
390     !     fluxsurfabs_sw,'T',fluxtop_lw,'U',                      &
391     !     fluxabs_sw,'V',fluxtop_dn,'W',OLR_nu,'X',OSR_nu,'Y',tau_col,'Z',    &
392     !     cloudfrac,'A1',totcloudfrac,'A2',.false.,'A3',firstcall,'A4',lastcall
393
394
395
396
397
398
399
400     !    Iterate stratospheric temperature
401     print*,'Tstrat = ',Tstrat
402     dTstrat = Tstrat
403     !Tstrat  = Tsurf*(0.2786*(psurf/100000.)**(-1.123))**0.25
404     ! skin temperature (gray approx.) using analytic pure H2 expression
405     !Tstrat  = (fluxabs_sw/(2*sigma))**0.25 ! skin temperature (gray approx.)
406     Tstrat  = (fluxtop_lw(1)/(2*sigma))**0.25 ! skin temperature (gray approx.)
407     dTstrat = dTstrat-Tstrat
408
409     !if(abs(dTstrat).lt.1.0)then
410     !   print*,'dTstrat = ',dTstrat
411     !   exit
412     !endif
413
414     !iter=iter+1
415     !if(iter.eq.100)then
416     !   print*,'Stratosphere failed to converge after'
417     !   print*,'100 iteration, aborting run.'
418     !   call abort
419     !endif
420
421  !end do
422
423
424  ! Run radiative transfer one last time to get OLR,OSR
425  firstcall=.false.
426  lastcall=.true.
427  call callcorrk(1,nlayer,q,nq,qsurf,                          &
428       albedo_wv,albedo_equivalent,emis,mu0,plev,play,temp,    &
429       tsurf,fract,dist_star,aerosol,muvar,                    &
430       dtlw,dtsw,fluxsurf_lw,fluxsurf_sw,fluxsurfabs_sw,       &
431       fluxtop_lw, fluxabs_sw,fluxtop_dn,OLR_nu,OSR_nu,GSR_nu, &
432       int_dtaui,int_dtauv,                                    &
433       tau_col,cloudfrac,totcloudfrac,                         &
434       .false.,firstcall,lastcall)
435
436
437     !write(*,*) 'BASE 4'
438     !write(*,*) 1,nlayer,'A',q,'B',nq,'C',qsurf,                      &
439     !     albedo_wv,'D',albedo_equivalent,'E',                    &
440     !     emis,'F',mu0,'G',plev,'H',play,'I',temp,'J',                        &
441     !     tsurf,'K',fract,'L',dist_star,'M',aerosol,'N',muvar,'O',            &
442     !     dtlw,'P',dtsw,'Q',fluxsurf_lw,'R',fluxsurf_sw,'S',              &
443     !     fluxsurfabs_sw,'T',fluxtop_lw,'U',                      &
444     !     fluxabs_sw,'V',fluxtop_dn,'W',OLR_nu,'X',OSR_nu,'Y',tau_col,'Z',    &
445     !     cloudfrac,'A1',totcloudfrac,'A2',.false.,'A3',firstcall,'A4',lastcall
446
447
448
449
450
451
452
453  ! Calculate total atmospheric energy
454  Eatmtot=0.0
455  !  call calcenergy_kcm(nlayer,tsurf,temp,play,plev,qsurf,&
456  !     q(:,1),muvar,Eatmtot)
457
458  ! ------------------------
459  ! Save data to ascii files
460  ! ------------------------
461
462  print*,'Saving profiles...'
463  open(115,file='profpres.out',form='formatted')
464  open(116,file='proftemp.out',form='formatted')
465  open(117,file='profztab.out',form='formatted')
466  open(118,file='profqvar.out',form='formatted')
467  open(119,file='profvvar.out',form='formatted')
468
469  write(115,*) psurf
470  write(116,*) tsurf
471  write(117,*) 0.0
472  write(118,*) qsurf(1)
473  write(119,*) qsurf(1)*(muvar(1)/mH2O)
474  do ilay=1,nlayer
475     vmr(ilay,1) = q(ilay,1)*(muvar(ilay+1)/mH2O)
476     write(115,*) play(ilay)
477     write(116,*) temp(ilay)
478     write(117,*) zlay(ilay)
479     write(118,*) q(ilay,1)
480     write(119,*) vmr(ilay,1)
481  enddo
482  close(115)
483  close(116)
484  close(117)
485  close(118)
486  close(119)
487
488  print*, tsurf,psurf,fluxtop_dn,fluxabs_sw,fluxtop_lw
489
490  print*,'Saving scalars...'
491  open(116,file='surf_vals.out')
492  write(116,*) tsurf,psurf,fluxtop_dn,         &
493       fluxabs_sw,fluxtop_lw
494  close(116)
495  open(111,file='ene_vals.out')
496  write(111,*) tsurf,psurf,Eatmtot,Tstrat
497  close(111)
498
499  print*,'Saving spectra...'
500  open(117,file='OLRnu.out')
501  do iw=1,L_NSPECTI
502     write(117,*) OLR_nu(1,iw)
503  enddo
504  close(117)
505
506  open(127,file='OSRnu.out')
507  do iw=1,L_NSPECTV
508     write(127,*) OSR_nu(1,iw)
509  enddo
510  close(127) 
511
512end program kcm1d
Note: See TracBrowser for help on using the repository browser.