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

Last change on this file since 364 was 305, checked in by rwordsworth, 14 years ago

Several new files added as part of the climate evolution model
(main program kcm.F90). Some general cleanup in physiq.F90 and
callcorrk.F90. Bugs in dust radiative transfer and H2 Rayleigh
scattering corrected.

  • Property svn:executable set to *
File size: 8.3 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  call inifis(1,llm,0,86400.0,1.0,0.0,0.0,1.0,rad,g,r,cpp)
166
167! Tracer initialisation
168! ---------------------
169  if (tracer) then
170     ! load tracer names from file 'traceur.def'
171     open(90,file='traceur.def',status='old',form='formatted',&
172          iostat=ierr)
173     if (ierr.eq.0) then
174        write(*,*) "kcm1d: Reading file traceur.def"
175        ! read number of tracers:
176        read(90,*,iostat=ierr) nq
177        if (ierr.ne.0) then
178           write(*,*) "kcm1d: error reading number of tracers"
179           write(*,*) "   (first line of traceur.def) "
180           stop
181        else
182           ! check that the number of tracers is indeed nqmx
183           if (nq.ne.nqmx) then
184              write(*,*) "kcm1d: error, wrong number of tracers:"
185              write(*,*) "nq=",nq," whereas nqmx=",nqmx
186              stop
187           endif
188        endif
189       
190        do iq=1,nq
191           ! minimal version, just read in the tracer names, 1 per line
192           read(90,*,iostat=ierr) tnom(iq)
193           if (ierr.ne.0) then
194              write(*,*) 'rcm1d: error reading tracer names...'
195              stop
196           endif
197        enddo !of do iq=1,nq
198     endif
199  endif
200 
201  call initracer()
202
203  do iq=1,nqmx
204     do ilay=1,nlayer
205        q(ilay,iq) = 0.
206     enddo
207  enddo
208 
209  do iq=1,nqmx
210     qsurf(iq) = 0.
211  enddo
212
213  firstcall = .true.
214  lastcall  = .false.
215
216  iter    = 1
217  Tstrat  = 200.0
218  dTstrat = 1000.0
219
220! ---------
221! Run model
222! ---------
223  do
224     psurf = psurf_n
225
226!    Create vertical profiles
227     call kcmprof_fn(psurf,qsurf(1),tsurf,    &
228          tstrat,play,plev,zlay,temp,q(:,1),muvar(1))
229
230
231     !if(1.eq.2)then
232
233!    Run radiative transfer
234     call callcorrk(ngridmx,nlayer,q,nqmx,qsurf,      &
235          albedo,emis,mu0,plev,play,temp,                    &
236          tsurf,fract,dist_star,aerosol,cpp3D,muvar,         &
237          dtlw,dtsw,fluxsurf_lw,fluxsurf_sw,fluxtop_lw,    &
238          fluxabs_sw,fluxtop_dn,reffrad,tau_col,  &
239          cloudfrac,totcloudfrac,.false.,firstcall,lastcall)
240 
241!    Iterate stratospheric temperature
242     print*,'Tstrat = ',Tstrat
243     dTstrat = Tstrat
244     Tstrat  = (fluxabs_sw/(2*sigma))**0.25 ! skin temperature (gray approx.)
245     dTstrat = dTstrat-Tstrat
246
247     !endif
248
249     !dTstrat = 0
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  call calcenergy_kcm(tsurf,temp,play,plev,qsurf,&
267     q(:,1),muvar,Eatmtot)
268
269! ------------------------
270! Save data to ascii files
271! ------------------------
272
273  print*,'Saving profiles...'
274  open(115,file='profpres.out',form='formatted')
275  open(116,file='proftemp.out',form='formatted')
276  open(117,file='profztab.out',form='formatted')
277  open(118,file='profqvar.out',form='formatted')
278  open(119,file='profvvar.out',form='formatted')
279
280  write(115,*) psurf
281  write(116,*) tsurf
282  write(117,*) 0.0
283  write(118,*) qsurf(1)
284  write(119,*) qsurf(1)*(muvar(1)/mH2O)
285  do ilay=1,nlayer
286     vmr(ilay,1) = q(ilay,1)*(muvar(ilay+1)/mH2O)
287     write(115,*) play(ilay)
288     write(116,*) temp(ilay)
289     write(117,*) zlay(ilay)
290     write(118,*) q(ilay,1)
291     write(119,*) vmr(ilay,1)
292  enddo
293  close(115)
294  close(116)
295  close(117)
296  close(118)
297  close(119)
298
299  print*,'Saving scalars...'
300  open(116,file='surf_vals.out')
301  write(116,*) tsurf,psurf,fluxtop_dn,         &
302       fluxabs_sw,fluxtop_lw
303  close(116)
304  open(111,file='ene_vals.out')
305  write(111,*) tsurf,psurf,Eatmtot,Tstrat
306  close(111)
307
308  print*,'Saving spectra...'
309  open(117,file='OLRnu.out')
310  do iw=1,L_NSPECTI
311     write(117,*) OLR_nu(iw)
312  enddo
313  close(117)
314 
315  open(127,file='GSRnu.out')
316  do iw=1,L_NSPECTV
317     write(127,*) GSR_nu(iw)
318  enddo
319  close(127) 
320
321end program kcm1d
Note: See TracBrowser for help on using the repository browser.