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

Last change on this file since 486 was 366, checked in by rwordsworth, 13 years ago

OSR output bugs fixed.
Improvements to kcm for pure H2 atmospheres.

  • Property svn:executable set to *
File size: 8.5 KB
Line 
1program kcm1d
2
3  use radinc_h,      only: NAERKIND
4  use radcommon_h,   only: L_NSPECTI, L_NSPECTV, sigma
5  use watercommon_h, only: mH2O
6  use ioipsl_getincom
7
8  implicit none
9
10!==================================================================
11!     
12!     Purpose
13!     -------
14!     Run the universal model radiative transfer once in a 1D column.
15!     Useful for climate evolution studies etc.
16!     
17!     It can be compiled with a command like (e.g. for 25 layers):
18!                                  "makegcm -p std -d 25 kcm1d"
19!     It requires the files "callphys.def", "gases.def"
20!     "traceur.def", and "run.def" with a line "INCLUDEDEF=callphys.def"
21!
22!     Authors
23!     -------
24!     R. Wordsworth
25!
26!==================================================================
27
28#include "dimensions.h"
29#include "dimphys.h"
30#include "callkeys.h"
31#include "comcstfi.h"
32#include "planete.h"
33#include "comsaison.h"
34#include "control.h"
35#include "advtrac.h"
36
37! --------------------------------------------------------------
38!  Declarations
39! --------------------------------------------------------------
40
41  integer nlayer,nlevel,nq
42  integer ilay,ilev,iq,iw,iter
43  real play(nlayermx)     ! Pressure at the middle of the layers [Pa]
44  real zlay(nlayermx)     ! Altitude at middle of the layers [km]
45  real plev(nlayermx+1)   ! Intermediate pressure levels [Pa]
46  real temp(nlayermx)     ! temperature at the middle of the layers [K]
47  real q(nlayermx,nqmx)   ! tracer mixing ratio [kg/kg]
48  real vmr(nlayermx,nqmx) ! tracer mixing ratio [mol/mol]
49  real qsurf(nqmx)        ! tracer surface budget [kg/kg] ????
50  real psurf,psurf_n,tsurf     
51
52  real emis, albedo
53
54  real cpp3D(nlayermx)   ! specific heat capacity at const. pressure
55  real rcp3D(nlayermx)   ! R / specific heat capacity
56  real muvar(nlayermx+1)
57
58  real dtsw(nlayermx) ! heating rate (K/s) due to SW
59  real dtlw(nlayermx) ! heating rate (K/s) due to LW
60  real fluxsurf_lw   ! incident LW flux to surf (W/m2)
61  real fluxtop_lw    ! outgoing LW flux to space (W/m2)
62  real fluxsurf_sw   ! incident SW flux to surf (W/m2)
63  real fluxabs_sw    ! SW flux absorbed by planet (W/m2)
64  real fluxtop_dn    ! incident top of atmosphere SW flux (W/m2)
65     
66! not used
67  real reffrad(nlayermx,naerkind)
68  real nueffrad(nlayermx,naerkind)
69  real cloudfrac(nlayermx)
70  real totcloudfrac
71  real tau_col
72
73  real dTstrat
74  real aerosol(nlayermx,naerkind) ! aerosol tau (kg/kg)
75  real OLR_nu(L_NSPECTI)
76  real GSR_nu(L_NSPECTV)
77  real Eatmtot
78
79  integer ierr
80  logical firstcall,lastcall
81
82! --------------
83! Initialisation
84! --------------
85
86  pi=2.E+0*asin(1.E+0)
87
88  reffrad(:,:)  = 0.0
89  nueffrad(:,:) = 0.0
90  cloudfrac(:)  = 0.0
91  totcloudfrac  = 0.0
92
93!  Load parameters from "run.def"
94! -------------------------------
95
96! check if 'run1d.def' file is around (otherwise reading parameters
97! from callphys.def via getin() routine won't work.)
98  open(90,file='run.def',status='old',form='formatted',&
99       iostat=ierr)
100  if (ierr.ne.0) then
101     write(*,*) 'Cannot find required file "run.def"'
102     write(*,*) '  (which should contain some input parameters'
103     write(*,*) '   along with the following line:'
104     write(*,*) '   INCLUDEDEF=callphys.def'
105     write(*,*) '   )'
106     write(*,*) ' ... might as well stop here ...'
107     stop
108  else
109     close(90)
110  endif
111
112  nlayer=nlayermx
113  nlevel=nlayer+1
114
115  psurf_n=100000. ! default value for psurf
116  print*,'Dry surface pressure (Pa)?'
117  call getin("psurf",psurf_n)
118  write(*,*) " psurf = ",psurf_n
119     
120  tsurf=300.0 ! default value for tsurf
121  print*,'Surface temperature (K)?'
122  call getin("tref",tsurf)
123  write(*,*) " tsurf = ",tsurf
124
125  g=10.0 ! default value for g
126  print*,'Gravity ?'
127  call getin("g",g)
128  write(*,*) " g = ",g
129 
130  periastr = 1.0
131  apoastr  = 1.0
132  print*,'Periastron (AU)?'
133  call getin("periastr",periastr)
134  write(*,*) "periastron = ",periastr
135  dist_star = periastr
136  fract     = 0.5
137  print*,'Apoastron (AU)?'
138  call getin("apoastr",apoastr)
139  write(*,*) "apoastron = ",apoastr
140 
141  periastr = periastr*149.598 ! AU to Mkm
142  apoastr  = apoastr*149.598  ! AU to Mk
143
144  albedo=0.2 ! default value for albedo
145  print*,'Albedo of bare ground?'
146  call getin("albedo",albedo)
147  write(*,*) " albedo = ",albedo
148
149  emis=1.0 ! default value for emissivity
150  PRINT *,'Emissivity of bare ground ?'
151  call getin("emis",emis)
152  write(*,*) " emis = ",emis
153
154  pceil=100.0 ! Pascals
155  PRINT *,'Ceiling pressure (Pa) ?'
156  call getin("pceil",pceil)
157  write(*,*) " pceil = ", pceil
158
159  mugaz=0.
160  cpp=0.
161
162  call su_gases
163  call calc_cpp_mugaz
164
165
166  call inifis(1,llm,0,86400.0,1.0,0.0,0.0,1.0,rad,g,r,cpp)
167
168! Tracer initialisation
169! ---------------------
170  if (tracer) then
171     ! load tracer names from file 'traceur.def'
172     open(90,file='traceur.def',status='old',form='formatted',&
173          iostat=ierr)
174     if (ierr.eq.0) then
175        write(*,*) "kcm1d: Reading file traceur.def"
176        ! read number of tracers:
177        read(90,*,iostat=ierr) nq
178        if (ierr.ne.0) then
179           write(*,*) "kcm1d: error reading number of tracers"
180           write(*,*) "   (first line of traceur.def) "
181           stop
182        else
183           ! check that the number of tracers is indeed nqmx
184           if (nq.ne.nqmx) then
185              write(*,*) "kcm1d: error, wrong number of tracers:"
186              write(*,*) "nq=",nq," whereas nqmx=",nqmx
187              stop
188           endif
189        endif
190       
191        do iq=1,nq
192           ! minimal version, just read in the tracer names, 1 per line
193           read(90,*,iostat=ierr) tnom(iq)
194           if (ierr.ne.0) then
195              write(*,*) 'kcm1d: error reading tracer names...'
196              stop
197           endif
198        enddo !of do iq=1,nq
199     endif
200  !endif
201 
202  call initracer()
203
204  endif
205
206
207  do iq=1,nqmx
208     do ilay=1,nlayer
209        q(ilay,iq) = 0.
210     enddo
211  enddo
212 
213  do iq=1,nqmx
214     qsurf(iq) = 0.
215  enddo
216
217  firstcall = .true.
218  lastcall  = .false.
219
220  iter    = 1
221  Tstrat  = 60.0
222  dTstrat = 1000.0
223
224! ---------
225! Run model
226! ---------
227  do
228     psurf = psurf_n
229
230!    Create vertical profiles
231     call kcmprof_fn(psurf,qsurf(1),tsurf,    &
232          tstrat,play,plev,zlay,temp,q(:,1),muvar(1))
233
234!    Run radiative transfer
235     call callcorrk(ngridmx,nlayer,q,nqmx,qsurf,      &
236          albedo,emis,mu0,plev,play,temp,                    &
237          tsurf,fract,dist_star,aerosol,cpp3D,muvar,         &
238          dtlw,dtsw,fluxsurf_lw,fluxsurf_sw,fluxtop_lw,    &
239          fluxabs_sw,fluxtop_dn,reffrad,tau_col,  &
240          cloudfrac,totcloudfrac,.false.,firstcall,lastcall)
241 
242!    Iterate stratospheric temperature
243     print*,'Tstrat = ',Tstrat
244     dTstrat = Tstrat
245     !Tstrat  = Tsurf*(0.2786*(psurf/100000.)**(-1.123))**0.25
246     ! skin temperature (gray approx.) using analytic pure H2 expression
247     !Tstrat  = (fluxabs_sw/(2*sigma))**0.25 ! skin temperature (gray approx.)
248     Tstrat  = (fluxtop_lw/(2*sigma))**0.25 ! skin temperature (gray approx.)
249     dTstrat = dTstrat-Tstrat
250
251     if(abs(dTstrat).lt.1.0)then
252        print*,'dTstrat = ',dTstrat
253        exit
254     endif
255
256     iter=iter+1
257     if(iter.eq.100)then
258        print*,'Stratosphere failed to converge after'
259        print*,'100 iteration, aborting run.'
260        call abort
261     endif
262
263  end do
264
265! Calculate total atmospheric energy
266  Eatmtot=0.0
267!  call calcenergy_kcm(tsurf,temp,play,plev,qsurf,&
268!     q(:,1),muvar,Eatmtot)
269
270! ------------------------
271! Save data to ascii files
272! ------------------------
273
274  print*,'Saving profiles...'
275  open(115,file='profpres.out',form='formatted')
276  open(116,file='proftemp.out',form='formatted')
277  open(117,file='profztab.out',form='formatted')
278  open(118,file='profqvar.out',form='formatted')
279  open(119,file='profvvar.out',form='formatted')
280
281  write(115,*) psurf
282  write(116,*) tsurf
283  write(117,*) 0.0
284  write(118,*) qsurf(1)
285  write(119,*) qsurf(1)*(muvar(1)/mH2O)
286  do ilay=1,nlayer
287     vmr(ilay,1) = q(ilay,1)*(muvar(ilay+1)/mH2O)
288     write(115,*) play(ilay)
289     write(116,*) temp(ilay)
290     write(117,*) zlay(ilay)
291     write(118,*) q(ilay,1)
292     write(119,*) vmr(ilay,1)
293  enddo
294  close(115)
295  close(116)
296  close(117)
297  close(118)
298  close(119)
299
300  print*,'Saving scalars...'
301  open(116,file='surf_vals.out')
302  write(116,*) tsurf,psurf,fluxtop_dn,         &
303       fluxabs_sw,fluxtop_lw
304  close(116)
305  open(111,file='ene_vals.out')
306  write(111,*) tsurf,psurf,Eatmtot,Tstrat
307  close(111)
308
309  print*,'Saving spectra...'
310  open(117,file='OLRnu.out')
311  do iw=1,L_NSPECTI
312     write(117,*) OLR_nu(iw)
313  enddo
314  close(117)
315 
316  open(127,file='GSRnu.out')
317  do iw=1,L_NSPECTV
318     write(127,*) GSR_nu(iw)
319  enddo
320  close(127) 
321
322end program kcm1d
Note: See TracBrowser for help on using the repository browser.