source: trunk/WRF.COMMON/WRFV2/mars_lmd/libf/phymars/meso_physiq.F_old

Last change on this file was 11, checked in by aslmd, 14 years ago

spiga@svn-planeto:ajoute le modele meso-echelle martien

File size: 55.0 KB
Line 
1      SUBROUTINE meso_physiq(ngrid,nlayer,nq,
2     $            firstcall,lastcall,
3     $            wday_ini,
4     $            pday,ptime,ptimestep,
5     $            pplev,pplay,pphi,
6     $            pu,pv,pt,pq,
7     $            pw,
8     $            pdu,pdv,pdt,pdq,pdpsrf,tracerdyn,
9     $            wtsurf,wtsoil,wemis,wq2,wqsurf,wco2ice,
10     $            wecritphys,
11     $            output_tab2d, output_tab3d)
12
13
14
15      IMPLICIT NONE
16c=======================================================================
17c
18c       CAREFUL: THIS IS A VERSION TO BE USED WITH WRF !!!
19c
20c       ... CHECK THE ****WRF lines
21c
22c=======================================================================
23c
24c   subject:
25c   --------
26c
27c   Organisation of the physical parametrisations of the LMD
28c   martian atmospheric general circulation model.
29c
30c   The GCM can be run without or with tracer transport
31c   depending on the value of Logical "tracer" in file  "callphys.def"
32c   Tracers may be water vapor, ice OR chemical species OR dust particles
33c
34c   SEE comments in initracer.F about numbering of tracer species...
35c
36c   It includes:
37c
38c      1. Initialisation:
39c      1.5 Calculation of mean mass and cp, R and thermal conduction coeff.
40c      2. Calcul of the radiative tendencies : radiative transfer
41c         (longwave and shortwave) for CO2 and dust.
42c      3. Gravity wave and subgrid scale topography drag :
43c      4. Vertical diffusion (turbulent mixing):
44c      5. convective adjustment
45c      6.  TRACERS :
46c       6a. water and water ice
47c       6b. call for photochemistry when tracers are chemical species
48c       6c. other scheme for tracer (dust) transport (lifting, sedimentation)
49c       6d. updates (CO2 pressure variations, surface budget)
50c      7.  condensation and sublimation of carbon dioxide.
51c      8. Surface and sub-surface temperature calculations
52c      9. Writing output files :
53c           - "startfi", "histfi" (if it's time)
54c           - Saving statistics (if "callstats = .true.")
55c           - Dumping eof (if "calleofdump = .true.")
56c           - Output any needed variables in "diagfi"
57c      10. Diagnostic: mass conservation of tracers
58c
59c   author:
60c   -------
61c           Frederic Hourdin    15/10/93
62c           Francois Forget             1994
63c           Christophe Hourdin  02/1997
64c           Subroutine completly rewritten by F.Forget (01/2000)
65c           Introduction of the photochemical module: S. Lebonnois (11/2002)
66c           Introduction of the thermosphere module: M. Angelats i Coll (2002)
67c           Water ice clouds: Franck Montmessin (update 06/2003)
68c           WRF version: Aymeric Spiga (01-03/2007)
69c           
70c
71c
72c   arguments:
73c   ----------
74c
75c   input:
76c   ------
77c    ecri                  period (in dynamical timestep) to write output
78c    ngrid                 Size of the horizontal grid.
79c                          All internal loops are performed on that grid.
80c    nlayer                Number of vertical layers.
81c    nq                    Number of advected fields
82c    firstcall             True at the first call
83c    lastcall              True at the last call
84c    pday                  Number of days counted from the North. Spring
85c                          equinoxe.
86c    ptime                 Universal time (0<ptime<1): ptime=0.5 at 12:00 UT
87c    ptimestep             timestep (s)
88c    pplay(ngrid,nlayer)   Pressure at the middle of the layers (Pa)
89c    pplev(ngrid,nlayer+1) intermediate pressure levels (pa)
90c    pphi(ngrid,nlayer)    Geopotential at the middle of the layers (m2s-2)
91c    pu(ngrid,nlayer)      u component of the wind (ms-1)
92c    pv(ngrid,nlayer)      v component of the wind (ms-1)
93c    pt(ngrid,nlayer)      Temperature (K)
94c    pq(ngrid,nlayer,nq)   Advected fields
95c    pudyn(ngrid,nlayer)    \
96c    pvdyn(ngrid,nlayer)     \ Dynamical temporal derivative for the
97c    ptdyn(ngrid,nlayer)     / corresponding variables
98c    pqdyn(ngrid,nlayer,nq) /
99c    pw(ngrid,?)           vertical velocity
100c
101c
102c    ****WRF
103c       day_ini,tsurf,tsoil,emis,q2,qsurf,co2ice are inputs
104c               and locally saved variables
105c                       (no need to call phyetat0)
106c
107c
108c   output:
109c   -------
110c
111c    pdu(ngrid,nlayermx)        \
112c    pdv(ngrid,nlayermx)         \  Temporal derivative of the corresponding
113c    pdt(ngrid,nlayermx)         /  variables due to physical processes.
114c    pdq(ngrid,nlayermx)        /
115c    pdpsrf(ngrid)             /
116c    tracerdyn                 call tracer in dynamical part of GCM ?
117
118c
119c=======================================================================
120c
121c    0.  Declarations :
122c    ------------------
123
124#include "dimensions.h"
125#include "dimphys.h"
126#include "comgeomfi.h"
127#include "surfdat.h"
128#include "comdiurn.h"
129#include "callkeys.h"
130#include "comcstfi.h"
131#include "planete.h"
132#include "comsaison.h"
133#include "control.h"
134#include "dimradmars.h"
135#include "comg1d.h"
136#include "tracer.h"
137#include "nlteparams.h"
138
139#include "chimiedata.h"
140#include "watercap.h"
141#include "fisice.h"
142#include "param.h"
143#include "param_v3.h"
144#include "conc.h"
145
146#include "netcdf.inc"
147
148#include "slope.h"
149!!#include "wrf_output.h"
150
151
152
153c Arguments :
154c -----------
155
156c   inputs:
157c   -------
158      INTEGER ngrid,nlayer,nq
159      REAL ptimestep
160      REAL pplev(ngridmx,nlayer+1),pplay(ngridmx,nlayer)
161      REAL pphi(ngridmx,nlayer)
162      REAL pu(ngridmx,nlayer),pv(ngridmx,nlayer)
163      REAL pt(ngridmx,nlayer),pq(ngridmx,nlayer,nq)
164      REAL pw(ngridmx,nlayer) !Mars pvervel transmit par dyn3d
165      REAL zh(ngridmx,nlayermx)      ! potential temperature (K)
166      LOGICAL firstcall,lastcall
167c ****WRF
168      INTEGER wday_ini 
169      REAL wtsurf(ngridmx)      ! input only ay firstcall - output           
170      REAL wtsoil(ngridmx,nsoilmx)   
171      REAL wco2ice(ngridmx)             
172      REAL wemis(ngridmx)             
173      REAL wqsurf(ngridmx,nqmx)       
174      REAL wq2(ngridmx,nlayermx+1)
175      REAL wecritphys   
176c      REAL output_tau(ngridmx)
177c      REAL output_swsurf(ngridmx),output_lwsurf(ngridmx)
178c      REAL output_rice(ngridmx,nlayer)
179c
180c LE NOMBRE DE SORTIES EST CODE EN DUR
181c
182      REAL output_tab2d(ngridmx,10)
183      REAL output_tab3d(ngridmx,nlayer,1)
184     
185      REAL sl_ls, sl_lct, sl_lat, sl_tau, sl_alb, sl_the, sl_psi
186      REAL sl_fl0, sl_flu
187c ****WRF
188      REAL pday
189      REAL ptime
190      logical tracerdyn
191
192c   outputs:
193c   --------
194c     physical tendencies
195      REAL pdu(ngridmx,nlayer),pdv(ngridmx,nlayer)
196      REAL pdt(ngridmx,nlayer),pdq(ngridmx,nlayer,nq)
197      REAL pdpsrf(ngridmx)
198
199
200c Local saved variables:
201c ----------------------
202c     aerosol (dust or ice) extinction optical depth  at reference wavelength
203c     "longrefvis" set in dimradmars.h , for one of the "naerkind"  kind of
204c      aerosol optical properties  :
205      REAL aerosol(ngridmx,nlayermx,naerkind)
206
207      INTEGER day_ini  ! Initial date of the run (sol since Ls=0)
208      INTEGER icount     ! counter of calls to physiq during the run.
209      REAL tsurf(ngridmx)            ! Surface temperature (K)
210      REAL tsoil(ngridmx,nsoilmx)    ! sub-surface temperatures (K)
211      REAL co2ice(ngridmx)           ! co2 ice surface layer (kg.m-2) 
212      REAL albedo(ngridmx,2)         ! Surface albedo in each solar band
213      REAL emis(ngridmx)             ! Thermal IR surface emissivity
214      REAL dtrad(ngridmx,nlayermx)   ! Net atm. radiative heating rate (K.s-1)
215      REAL fluxrad(ngridmx)          ! Net radiative surface flux (W.m-2)
216      REAL capcal(ngridmx)           ! surface heat capacity (J m-2 K-1)
217      REAL fluxgrd(ngridmx)          ! surface conduction flux (W.m-2)
218      REAL qsurf(ngridmx,nqmx)       ! tracer on surface (e.g. kg.m-2)
219      REAL q2(ngridmx,nlayermx+1)    ! Turbulent Kinetic Energy
220      INTEGER ig_vl1                 ! Grid Point near VL1   (for diagnostic)
221
222      SAVE day_ini, icount
223      SAVE aerosol, tsurf,tsoil
224      SAVE co2ice,albedo,emis, q2
225      SAVE capcal,fluxgrd,dtrad,fluxrad, qsurf
226      SAVE ig_vl1
227
228      REAL stephan   
229      DATA stephan/5.67e-08/  ! Stephan Boltzman constant
230      SAVE stephan
231
232c Local variables :
233c -----------------
234      CHARACTER*80 fichier
235      INTEGER l,ig,ierr,igout,iq, tapphys
236      INTEGER iqmin                     ! Used if iceparty engaged
237
238      REAL fluxsurf_lw(ngridmx)      !incident LW (IR) surface flux (W.m-2)
239      REAL fluxsurf_sw(ngridmx,2)    !incident SW (solar) surface flux (W.m-2)
240      REAL fluxtop_lw(ngridmx)       !Outgoing LW (IR) flux to space (W.m-2)
241      REAL fluxtop_sw(ngridmx,2)     !Outgoing SW (solar) flux to space (W.m-2)
242c     for clear area (uncovered by clouds) :
243      REAL clsurf_lw(ngridmx)      !incident LW (IR) surface flux (W.m-2)
244      REAL clsurf_sw(ngridmx,2)    !incident SW (solar) surface flux (W.m-2)
245      REAL cltop_lw(ngridmx)       !Outgoing LW (IR) flux to space (W.m-2)
246      REAL cltop_sw(ngridmx,2)     !Outgoing SW (solar) flux to space (W.m-2)
247      REAL tauref(ngridmx)           ! Reference column optical depth at 700 Pa
248                                     ! (used if active=F)
249      REAL tau(ngridmx,naerkind)     ! Column dust optical depth at each point
250      REAL zls                       !  solar longitude (rad)
251      REAL zday                      ! date (time since Ls=0, in martian days)
252      REAL zzlay(ngridmx,nlayermx)   ! altitude at the middle of the layers
253      REAL zzlev(ngridmx,nlayermx+1) ! altitude at layer boundaries
254      REAL latvl1,lonvl1             ! Viking Lander 1 point (for diagnostic)
255
256
257c     Tendancies due to various processes:
258      REAL dqsurf(ngridmx,nqmx)
259      REAL zdtlw(ngridmx,nlayermx)     ! (K/s)
260      REAL zdtsw(ngridmx,nlayermx)     ! (K/s)
261      REAL cldtlw(ngridmx,nlayermx)     ! (K/s) LW heating rate for clear area
262      REAL cldtsw(ngridmx,nlayermx)     ! (K/s) SW heating rate for clear area
263      REAL zdtnirco2(ngridmx,nlayermx) ! (K/s)
264      REAL zdtnlte(ngridmx,nlayermx)   ! (K/s)
265      REAL zdtsurf(ngridmx)            ! (K/s)
266      REAL zdtcloud(ngridmx,nlayermx)
267      REAL zdvdif(ngridmx,nlayermx),zdudif(ngridmx,nlayermx)  ! (m.s-2)
268      REAL zdhdif(ngridmx,nlayermx), zdtsdif(ngridmx)         ! (K/s)
269      REAL zdvadj(ngridmx,nlayermx),zduadj(ngridmx,nlayermx)  ! (m.s-2)
270      REAL zdhadj(ngridmx,nlayermx)                           ! (K/s)
271      REAL zdtgw(ngridmx,nlayermx)                            ! (K/s)
272      REAL zdugw(ngridmx,nlayermx),zdvgw(ngridmx,nlayermx)    ! (m.s-2)
273      REAL zdtc(ngridmx,nlayermx),zdtsurfc(ngridmx)
274      REAL zdvc(ngridmx,nlayermx),zduc(ngridmx,nlayermx)
275
276      REAL zdqdif(ngridmx,nlayermx,nqmx), zdqsdif(ngridmx,nqmx)
277      REAL zdqsed(ngridmx,nlayermx,nqmx), zdqssed(ngridmx,nqmx)
278      REAL zdqdev(ngridmx,nlayermx,nqmx), zdqsdev(ngridmx,nqmx)
279      REAL zdqadj(ngridmx,nlayermx,nqmx)
280      REAL zdqc(ngridmx,nlayermx,nqmx)
281      REAL zdqcloud(ngridmx,nlayermx,nqmx)
282      REAL zdqscloud(ngridmx,nqmx)
283      REAL zdqchim(ngridmx,nlayermx,nqmx)
284      REAL zdqschim(ngridmx,nqmx)
285
286      REAL zdteuv(ngridmx,nlayermx)    ! (K/s)
287      REAL zdtconduc(ngridmx,nlayermx) ! (K/s)
288      REAL zdumolvis(ngridmx,nlayermx)
289      REAL zdvmolvis(ngridmx,nlayermx)
290      real zdqmoldiff(ngridmx,nlayermx,nqmx)
291
292c     Local variable for local intermediate calcul:
293      REAL zflubid(ngridmx)
294      REAL zplanck(ngridmx),zpopsk(ngridmx,nlayermx)
295      REAL zdum1(ngridmx,nlayermx)
296      REAL zdum2(ngridmx,nlayermx)
297      REAL ztim1,ztim2,ztim3, z1,z2
298      REAL ztime_fin
299      REAL zdh(ngridmx,nlayermx)
300      REAL pclc_min ! minimum of the cloud fraction over the whole domain
301      INTEGER length
302      PARAMETER (length=100)
303
304c local variables only used for diagnostic (output in file "diagfi" or "stats")
305c -----------------------------------------------------------------------------
306      REAL ps(ngridmx), zt(ngridmx,nlayermx)
307      REAL zu(ngridmx,nlayermx),zv(ngridmx,nlayermx)
308      REAL zq(ngridmx,nlayermx,nqmx)
309      REAL fluxtop_sw_tot(ngridmx), fluxsurf_sw_tot(ngridmx)
310      character*2 str2
311      character*5 str5
312      real zdtdif(ngridmx,nlayermx), zdtadj(ngridmx,nlayermx)
313      real reff(ngridmx,nlayermx) ! effective dust radius (used if doubleq=T)
314      real qtot1,qtot2 ! total aerosol mass
315      integer igmin, lmin
316      logical tdiag
317
318
319      REAL zplev(ngrid,nlayermx+1),zplay(ngrid,nlayermx)
320      real hco2(nqmx),tmean, zlocal(nlayermx)
321      real rho(ngridmx,nlayermx) ! density
322      real vmr(ngridmx,nlayermx) ! volume mixing ratio
323
324      REAL time_phys
325     
326c=======================================================================
327
328c 1. Initialisation:
329c -----------------
330 
331
332c     Initialisation only at first call
333c     ---------------------------------
334      IF(firstcall) THEN
335
336c        variables set to 0
337c        ~~~~~~~~~~~~~~~~~~
338         call zerophys(ngrid*nlayer*naerkind,aerosol)
339         call zerophys(ngrid*nlayer,dtrad)
340         call zerophys(ngrid,fluxrad)
341
342c ****WRF
343c
344c       No need to use startfi.nc
345c               > part of the job of phyetat0 is done in inifis
346c               > remaining initializations are passed here from the WRF variables
347c               > beware, some operations were done by phyetat0 (ex: tracers)
348c                       > if any problems, look in phyetat0
349c
350        tsurf(:)=wtsurf(:)
351                PRINT*,'check: tsurf ',tsurf(1),tsurf(ngridmx)
352        tsoil(:,:)=wtsoil(:,:)
353                PRINT*,'check: tsoil ',tsoil(1,1),tsoil(ngridmx,nsoilmx)
354        emis(:)=wemis(:)
355                PRINT*,'check: emis ',emis(1),emis(ngridmx)
356        q2(:,:)=wq2(:,:)
357                PRINT*,'check: q2 ',q2(1,1),q2(ngridmx,nlayermx+1)
358        qsurf(:,:)=wqsurf(:,:)
359                PRINT*,'check: qsurf ',qsurf(1,1),qsurf(ngridmx,nqmx)
360        co2ice(:)=wco2ice(:)
361                PRINT*,'check: co2 ',co2ice(1),co2ice(ngridmx)
362        day_ini=wday_ini
363
364c       artificially filling dyn3d/control.h is also required
365c       > iphysiq is put in WRF to be set easily (cf ptimestep)
366c       > day_step is simply deduced:
367c
368        day_step=daysec/ptimestep
369        PRINT*,'Call to LMD physics:',day_step,' per Martian day'
370c
371        ecritphy=wecritphys
372                !!PRINT*,ecri_phys 
373                !!PRINT*,float(ecri_phys) ...
374                !!renvoient tous deux des nombres absurdes
375                !!pourtant callkeys.h est inclus ...
376                !!
377                !!donc ecritphys est passe en argument ...
378        PRINT*,'Write LMD physics each:',ecritphy,' seconds'
379
380        iphysiq=ptimestep
381
382c
383c ****WRF
384
385
386         if (pday.ne.day_ini) then
387           write(*,*) "***ERROR Pb de synchronisation entre phys et dyn"
388           write(*,*) "jour dynamique: ",pday
389           write(*,*) "jour physique: ",day_ini
390           stop
391         endif
392
393         write (*,*) 'In physic day_ini =', day_ini
394
395       
396
397c        Initialize albedo and orbital calculation
398c        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
399         CALL surfini(ngrid,co2ice,qsurf,albedo)
400         CALL iniorbit(aphelie,periheli,year_day,peri_day,obliquit)
401
402c        initialisation soil
403c        ~~~~~~~~~~~~~~~~~~~
404         IF (callsoil) THEN
405            CALL soil(ngrid,nsoilmx,firstcall,inertiedat,
406     s          ptimestep,tsurf,tsoil,capcal,fluxgrd)
407         ELSE
408            PRINT*,'WARNING! Thermal conduction in the soil turned off'
409            DO ig=1,ngrid
410               capcal(ig)=1.e5
411               fluxgrd(ig)=0.
412            ENDDO
413         ENDIF
414         icount=1
415
416
417c        initialisation pour les traceurs
418c        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
419         tracerdyn=tracer
420         IF (tracer) THEN
421            CALL initracer(qsurf,co2ice)
422         ENDIF  ! end tracer
423
424c ****WRF
425c
426c nosense in mesoscale modeling
427c
428cc        Determining gridpoint near Viking Lander 1 (used for diagnostic only)
429cc        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
430c         if(ngrid.ne.1) then
431c           latvl1= 22.27
432c           lonvl1= -47.94
433c           ig_vl1= 1+ int( (1.5-(latvl1-90.)*jjm/180.)  -2 )*iim +
434c     &              int(1.5+(lonvl1+180)*iim/360.)
435c           write(*,*) 'Viking Lander 1 GCM point: lat,lon',
436c     &              lati(ig_vl1)*180/pi, long(ig_vl1)*180/pi
437c         end if
438c
439c ****WRF
440
441
442c        Initializing thermospheric parameters
443c        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
444         if (callthermos) call param_read
445
446c        Initializing R and Cp as constant
447
448         if (.not.callthermos .and. .not.photochem) then
449                 do l=1,nlayermx
450                  do ig=1,ngridmx
451                   rnew(ig,l)=r
452                   cpnew(ig,l)=cpp
453                   mmean(ig,l)=mugaz
454                   enddo
455                  enddo 
456         endif         
457                   
458      ENDIF        !  (end of "if firstcall")
459
460c    ------------------------------------------
461c    Initialisations at every physical timestep:
462c    ------------------------------------------
463c
464      IF (ngrid.NE.ngridmx) THEN
465         PRINT*,'STOP in PHYSIQ'
466         PRINT*,'Probleme de dimensions :'
467         PRINT*,'ngrid     = ',ngrid
468         PRINT*,'ngridmx   = ',ngridmx
469         STOP
470      ENDIF
471
472      zday=pday+ptime
473
474       
475
476c     Computing Solar Longitude (Ls) :
477c     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
478      if (season) then
479         PRINT*,'day',zday
480         CALL solarlong(zday,zls)
481      else
482         PRINT*,'day_ini',day_ini
483         call solarlong(float(day_ini),zls)
484      end if
485
486
487c     Initializing various variable
488c     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
489      call zerophys(ngrid*nlayer, pdv)
490      call zerophys(ngrid*nlayer, pdu)
491      call zerophys(ngrid*nlayer, pdt)
492      call zerophys(ngrid*nlayer*nq, pdq)
493      call zerophys(ngrid, pdpsrf)
494      call zerophys(ngrid, zflubid)
495      call zerophys(ngrid, zdtsurf)
496      call zerophys(ngrid*nq, dqsurf)
497      igout=ngrid/2+1
498
499c     computing geopotentiel at interlayer levels
500c     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
501c     ponderation des altitudes au niveau des couches en dp/p
502
503      DO l=1,nlayer
504         DO ig=1,ngrid
505            zzlay(ig,l)=pphi(ig,l)/g   
506         ENDDO
507      ENDDO
508      DO ig=1,ngrid
509         zzlev(ig,1)=0.
510         zzlev(ig,nlayer+1)=1.e7    ! dummy top of last layer above 10000 km...
511      ENDDO
512      DO l=2,nlayer
513         DO ig=1,ngrid
514            z1=(pplay(ig,l-1)+pplev(ig,l))/(pplay(ig,l-1)-pplev(ig,l))
515            z2=(pplev(ig,l)+pplay(ig,l))/(pplev(ig,l)-pplay(ig,l))
516            zzlev(ig,l)=(z1*zzlay(ig,l-1)+z2*zzlay(ig,l))/(z1+z2)
517         ENDDO
518      ENDDO
519
520
521!     Potential temperature calculation not the same in physiq and dynamic
522
523c     Computing potential temperature
524c     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
525      DO l=1,nlayer
526         DO ig=1,ngrid
527            zpopsk(ig,l)=(pplay(ig,l)/pplev(ig,1))**rcp
528            zh(ig,l)=pt(ig,l)/zpopsk(ig,l)
529         ENDDO
530      ENDDO
531
532c-----------------------------------------------------------------------
533c    1.5 Calculation of mean mass, cp, and R
534c    ---------------------------------------
535
536      if(photochem.or.callthermos) then
537         call concentrations(pplay,pt,pdt,pq,pdq,ptimestep)
538      endif
539c-----------------------------------------------------------------------
540c    2. Calcul of the radiative tendencies :
541c    ---------------------------------------
542
543
544      IF(callrad) THEN
545         IF( MOD(icount-1,iradia).EQ.0) THEN
546
547c          Local Solar zenith angle
548c          ~~~~~~~~~~~~~~~~~~~~~~~~
549       
550           CALL orbite(zls,dist_sol,declin)
551
552           IF(diurnal) THEN
553               ztim1=SIN(declin)
554               ztim2=COS(declin)*COS(2.*pi*(zday-.5))
555               ztim3=-COS(declin)*SIN(2.*pi*(zday-.5))
556
557               CALL solang(ngrid,sinlon,coslon,sinlat,coslat,
558     s         ztim1,ztim2,ztim3, mu0,fract)
559
560           ELSE
561               CALL mucorr(ngrid,declin, lati, mu0, fract,10000.,rad)
562           ENDIF
563
564
565       
566c          NLTE cooling from CO2 emission
567c          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
568
569           IF(callnlte) CALL nltecool(ngrid,nlayer,pplay,pt,zdtnlte)
570
571
572c          Find number of layers for LTE radiation calculations
573           IF(MOD(iphysiq*(icount-1),day_step).EQ.0) THEN         
574                CALL nlthermeq(ngrid,nlayer,pplev,pplay)
575           ENDIF       
576
577               
578c          Atmospheric dust opacity and aerosol distribution:
579c          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
580
581cc*****WRF
582         CALL meso_dustopacity(ngrid,nlayer,nq,
583     $          zday,pplay,pplev,zls,pq,
584     $      tauref,tau,aerosol)
585
586cc*****WRF
587
588       
589c          Calling main radiative transfer scheme
590c          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
591c          Transfer through dust and CO2, except NIR CO2 absorption
592
593c ----------
594c partie rajoutee par Franck, commentee pour l'instant
595c ----------
596c
597c           if (ngridmx.eq.1) pclc(1)=1. !TEST for 1D simulation
598c
599c           pclc_min=1.
600c           if (activice.and.naerkind.gt.1) then
601c             do ig=1,ngrid
602c               pclc_min=min(pclc_min,pclc(ig))
603c             enddo
604c           endif
605c
606c           IF(activice.and.naerkind.gt.1.and.pclc_min.lt.1) THEN
607c          Computing radiative tendencies accounting for a cloudy area (0< pclc(ngrid) <1)
608c          pclc is set in initracer (prescribed for the moment).
609c          two steps : 1/rad. tend. without clouds (aerosol(*,*,2)=0.)
610c          ~~~~~~~~~   2/rad. tend. with clouds
611c                      3/final tendencies=average of 1/ and 2/ weighted by the
612cloud area (pclc)
613c
614c
615c 1/
616c           call zerophys(nlayer*ngrid,aerosol(1,1,2))  !remettre
617c           CALL callradite(icount,ngrid,nlayer,aerosol,albedo,
618c     $     emis,mu0,pplev,pplay,pt,tsurf,fract,dist_sol,igout,
619c     $     cldtlw,cldtsw,clsurf_lw,clsurf_sw,cltop_lw,cltop_sw)
620c
621c 2/
622c           CALL h2oiceopacity(ngrid,nlayer,nq,pplay,pplev,pt,pq,
623c     $     tau,aerosol,zls,co2ice)
624c
625c           CALL callradite(icount,ngrid,nlayer,aerosol,albedo,
626c     $     emis,mu0,pplev,pplay,pt,tsurf,fract,dist_sol,igout,
627c     $     zdtlw,zdtsw,fluxsurf_lw,fluxsurf_sw,fluxtop_lw,fluxtop_sw)
628c
629c 3/
630c           do l=1,nlayer
631c             do ig=1,ngrid
632c             zdtlw(ig,l)=(1.-pclc(ig))*cldtlw(ig,l)+pclc(ig)*zdtlw(ig,l)
633c             zdtsw(ig,l)=(1.-pclc(ig))*cldtsw(ig,l)+pclc(ig)*zdtsw(ig,l)
634c             enddo
635c           enddo
636c           do ig=1,ngrid
637c             fluxsurf_lw(ig)=(1.-pclc(ig))*clsurf_lw(ig)+
638c     $        pclc(ig)*fluxsurf_lw(ig)
639c             fluxtop_lw(ig)=(1.-pclc(ig))*cltop_lw(ig)+
640c     $        pclc(ig)*fluxtop_lw(ig)
641c
642c             fluxsurf_sw(ig,1)=(1.-pclc(ig))*clsurf_sw(ig,1)+
643c     $        pclc(ig)*fluxsurf_sw(ig,1)
644c             fluxsurf_sw(ig,2)=(1.-pclc(ig))*clsurf_sw(ig,2)+
645c     $        pclc(ig)*fluxsurf_sw(ig,2)
646c
647c             fluxtop_sw(ig,1)=(1.-pclc(ig))*cltop_sw(ig,1)+
648c     $        pclc(ig)*fluxtop_sw(ig,1)
649c             fluxtop_sw(ig,2)=(1.-pclc(ig))*cltop_sw(ig,2)+
650c     $        pclc(ig)*fluxtop_sw(ig,2)
651c           enddo
652c
653c           ELSE
654c
655c          Atmospheric water ice opacity and particle distribution:
656c          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
657c
658c           if (activice.and.naerkind.gt.1)
659c     &      CALL h2oiceopacity(ngrid,nlayer,nq,pplay,pplev,pt,pq,
660c     &      tau,aerosol,zls,co2ice)
661c
662c
663c ----------
664c  fin partie rajoutee par Franck (plus ENDIF ci-dessous)
665c ----------
666
667           CALL callradite(icount,ngrid,nlayer,aerosol,albedo,
668     $     emis,mu0,pplev,pplay,pt,tsurf,fract,dist_sol,igout,
669     $     zdtlw,zdtsw,fluxsurf_lw,fluxsurf_sw,fluxtop_lw,fluxtop_sw)
670
671c ----------
672c           ENDIF ! end of condition on the cloudy fraction
673c ----------
674
675
676ccccc
677ccccc PARAM SLOPE
678ccccc
679
680c          Insolation (direct + scaterred) on a slope
681c          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
682
683           DO ig=1,ngrid 
684
685                DO l=1,2
686           
687                sl_ls = 180.*zls/pi
688                sl_lct = ptime*24. + 180.*long(ig)/pi/15.
689                sl_lat = 180.*lati(ig)/pi
690                sl_tau = tau(ig,1)
691                sl_alb = albedo(ig,l)
692                sl_the = theta_sl(ig)
693                sl_psi = psi_sl(ig)
694                sl_fl0 = fluxsurf_sw(ig,l)
695
696           if (ig .eq. 1) then
697                write(*,*) 'ls ', 'lct ' , 'lat ', 'tau ',
698     &                   'alb ', 'the ', 'psi ', 'fl0 '
699                write(*,*) sl_ls, sl_lct, sl_lat, sl_tau,
700     &                   sl_alb, sl_the, sl_psi, sl_fl0
701           endif
702                   
703                CALL param_slope(sl_ls, sl_lct, sl_lat,
704     &                   sl_tau, sl_alb,
705     &                   sl_the, sl_psi, sl_fl0, sl_flu)
706
707                fluxsurf_sw(ig,l) = sl_flu
708             ENDDO
709           ENDDO
710
711ccccc
712ccccc PARAM SLOPE
713ccccc
714
715
716c          CO2 near infrared absorption
717c          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
718           call zerophys(ngrid*nlayer,zdtnirco2)
719           if (callnirco2) then
720              call nirco2abs (ngrid,nlayer,pplay,dist_sol,
721     .                       mu0,fract,declin, zdtnirco2)
722           endif
723
724c          Net radiative surface flux (W.m-2)
725c          ~~~~~~~~~~~~~~~~~~~~~~~~~~
726           DO ig=1,ngrid
727               fluxrad(ig)=emis(ig)*fluxsurf_lw(ig)
728     $         +fluxsurf_sw(ig,1)*(1.-albedo(ig,1))
729     $         +fluxsurf_sw(ig,2)*(1.-albedo(ig,2))
730               zplanck(ig)=tsurf(ig)*tsurf(ig)
731               zplanck(ig)=emis(ig)*
732     $         stephan*zplanck(ig)*zplanck(ig)
733               fluxrad(ig)=fluxrad(ig)-zplanck(ig)
734           ENDDO
735
736c          Net atmospheric radiative heating rate (K.s-1)
737c          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
738           IF(callnlte) THEN
739              CALL blendrad(ngrid, nlayer, pplay,
740     &             zdtsw, zdtlw, zdtnirco2, zdtnlte, dtrad)
741           ELSE
742              DO l=1,nlayer
743                 DO ig=1,ngrid
744                    dtrad(ig,l)=zdtsw(ig,l)+zdtlw(ig,l)
745     &                          +zdtnirco2(ig,l)
746                  ENDDO
747              ENDDO
748           ENDIF
749
750
751
752        ENDIF ! mod(icount-1,iradia).eq.0
753
754
755c    Transformation of the radiative tendencies:
756c    -----------------------------------------------
757
758         DO l=1,nlayer
759            DO ig=1,ngrid
760               pdt(ig,l)=pdt(ig,l)+dtrad(ig,l)
761            ENDDO
762         ENDDO
763
764      ENDIF
765
766
767
768c-----------------------------------------------------------------------
769c    3. Gravity wave and subgrid scale topography drag :
770c    -------------------------------------------------
771
772
773      IF(calllott)THEN
774
775        CALL calldrag_noro(ngrid,nlayer,ptimestep,
776     &                 pplay,pplev,pt,pu,pv,zdtgw,zdugw,zdvgw)
777 
778        DO l=1,nlayer
779          DO ig=1,ngrid
780            pdv(ig,l)=pdv(ig,l)+zdvgw(ig,l)
781            pdu(ig,l)=pdu(ig,l)+zdugw(ig,l)
782            pdt(ig,l)=pdt(ig,l)+zdtgw(ig,l)
783          ENDDO
784        ENDDO
785      ENDIF
786
787c-----------------------------------------------------------------------
788c    4. Vertical diffusion (turbulent mixing):
789c    -----------------------------------------
790c
791      IF(calldifv) THEN
792
793
794         DO ig=1,ngrid
795            zflubid(ig)=fluxrad(ig)+fluxgrd(ig)
796         ENDDO
797
798         CALL zerophys(ngrid*nlayer,zdum1)
799         CALL zerophys(ngrid*nlayer,zdum2)
800         do l=1,nlayer
801            do ig=1,ngrid
802               zdh(ig,l)=pdt(ig,l)/zpopsk(ig,l)
803            enddo
804         enddo
805
806
807c        Calling vdif (Martian version WITH CO2 condensation)
808         CALL vdifc(ngrid,nlayer,nq,co2ice,zpopsk,
809     $        ptimestep,capcal,lwrite,
810     $        pplay,pplev,zzlay,zzlev,z0,
811     $        pu,pv,zh,pq,tsurf,emis,qsurf,
812     $        zdum1,zdum2,zdh,pdq,zflubid,
813     $        zdudif,zdvdif,zdhdif,zdtsdif,q2,
814     &        zdqdif,zdqsdif)
815
816         DO l=1,nlayer
817            DO ig=1,ngrid
818
819               pdv(ig,l)=pdv(ig,l)+zdvdif(ig,l)
820               pdu(ig,l)=pdu(ig,l)+zdudif(ig,l)
821               pdt(ig,l)=pdt(ig,l)+zdhdif(ig,l)*zpopsk(ig,l)
822
823               zdtdif(ig,l)=zdhdif(ig,l)*zpopsk(ig,l) ! for diagnostic only
824
825            ENDDO
826         ENDDO
827
828         DO ig=1,ngrid
829            zdtsurf(ig)=zdtsurf(ig)+zdtsdif(ig)
830         ENDDO
831
832         if(tracer) then
833           DO iq=1, nq
834            DO l=1,nlayer
835              DO ig=1,ngrid
836                 pdq(ig,l,iq)=pdq(ig,l,iq)+ zdqdif(ig,l,iq)
837              ENDDO
838            ENDDO
839           ENDDO
840           DO iq=1, nq
841              DO ig=1,ngrid
842                 dqsurf(ig,iq)=dqsurf(ig,iq) + zdqsdif(ig,iq)
843              ENDDO
844           ENDDO
845         end if
846
847      ELSE   
848         DO ig=1,ngrid
849            zdtsurf(ig)=zdtsurf(ig)+
850     s      (fluxrad(ig)+fluxgrd(ig))/capcal(ig)
851         ENDDO
852      ENDIF
853
854
855c-----------------------------------------------------------------------
856c   5. Dry convective adjustment:
857c   -----------------------------
858
859      IF(calladj) THEN
860
861         DO l=1,nlayer
862            DO ig=1,ngrid
863               zdh(ig,l)=pdt(ig,l)/zpopsk(ig,l)
864            ENDDO
865         ENDDO
866         CALL zerophys(ngrid*nlayer,zduadj)
867         CALL zerophys(ngrid*nlayer,zdvadj)
868         CALL zerophys(ngrid*nlayer,zdhadj)
869
870         CALL convadj(ngrid,nlayer,nq,ptimestep,
871     $                pplay,pplev,zpopsk,
872     $                pu,pv,zh,pq,
873     $                pdu,pdv,zdh,pdq,
874     $                zduadj,zdvadj,zdhadj,
875     $                zdqadj)
876
877         DO l=1,nlayer
878            DO ig=1,ngrid
879               pdu(ig,l)=pdu(ig,l)+zduadj(ig,l)
880               pdv(ig,l)=pdv(ig,l)+zdvadj(ig,l)
881               pdt(ig,l)=pdt(ig,l)+zdhadj(ig,l)*zpopsk(ig,l)
882
883               zdtadj(ig,l)=zdhadj(ig,l)*zpopsk(ig,l) ! for diagnostic only
884            ENDDO
885         ENDDO
886
887         if(tracer) then
888           DO iq=1, nq
889            DO l=1,nlayer
890              DO ig=1,ngrid
891                 pdq(ig,l,iq)=pdq(ig,l,iq)+ zdqadj(ig,l,iq)
892              ENDDO
893            ENDDO
894           ENDDO
895         end if
896      ENDIF
897
898c-----------------------------------------------------------------------
899c   6. Carbon dioxide condensation-sublimation:
900c   -------------------------------------------
901
902      IF(callcond) THEN
903         CALL newcondens(ngrid,nlayer,nq,ptimestep,
904     $              capcal,pplay,pplev,tsurf,pt,
905     $              pphi,pdt,pdu,pdv,zdtsurf,pu,pv,pq,pdq,
906     $              co2ice,albedo,emis,
907     $              zdtc,zdtsurfc,pdpsrf,zduc,zdvc,zdqc,
908     $              fluxsurf_sw)
909
910         DO l=1,nlayer
911           DO ig=1,ngrid
912             pdt(ig,l)=pdt(ig,l)+zdtc(ig,l)
913             pdv(ig,l)=pdv(ig,l)+zdvc(ig,l)
914             pdu(ig,l)=pdu(ig,l)+zduc(ig,l)
915           ENDDO
916         ENDDO
917         DO ig=1,ngrid
918            zdtsurf(ig) = zdtsurf(ig) + zdtsurfc(ig)
919            ps(ig)=pplev(ig,1) + pdpsrf(ig)*ptimestep
920         ENDDO
921
922         IF(tracer) THEN
923           DO iq=1, nq
924            DO l=1,nlayer
925              DO ig=1,ngrid
926                pdq(ig,l,iq)=pdq(ig,l,iq)+ zdqc(ig,l,iq)
927              ENDDO
928            ENDDO
929           ENDDO
930         END IF !(tracer)
931
932      ENDIF  !(callcond)
933
934c        print*,'condens ok'
935c-----------------------------------------------------------------------
936c   7. Specific parameterizations for tracers
937c:   -----------------------------------------
938
939      if(tracer) then
940
941c   7a. Water and ice
942c     ---------------
943
944c        ---------------------------------------
945c        Water ice condensation in the atmosphere
946c        ----------------------------------------
947         IF (water) THEN
948
949
950c--------------------sursis with g95
951           call watercloud(ngrid,nlayer, ptimestep,
952     &                pplev,pplay,pdpsrf,zzlev,zzlay, pt,pdt,
953     &                pq,pdq,zdqcloud,qsurf,zdqscloud,zdtcloud,
954     &                nq,naerkind,tau,icount,zls)
955c--------------------problem with g95
956
957           if (activice) then
958c Temperature variation due to latent heat release
959           DO l=1,nlayer
960             DO ig=1,ngrid
961               pdt(ig,l)=pdt(ig,l)+zdtcloud(ig,l)
962             ENDDO
963           ENDDO
964           endif
965
966           IF (iceparty) then
967             iqmin=nq-1
968           ELSE
969             iqmin=nq
970           ENDIF
971
972           DO iq=iqmin,nq
973             DO l=1,nlayer
974                DO ig=1,ngrid
975                   pdq(ig,l,iq)=pdq(ig,l,iq)+ zdqcloud(ig,l,iq)
976                ENDDO
977             ENDDO
978             DO ig=1,ngrid
979                dqsurf(ig,iq)= dqsurf(ig,iq) + zdqscloud(ig,iq)
980             ENDDO
981           ENDDO
982
983         END IF  ! (water)
984
985c   7b. Chemical species
986c     ------------------
987
988c        --------------
989c        photochemistry :
990c        --------------
991         IF(photochem .or. thermochem) then
992          call calchim(ptimestep,pplay,pplev,pt,pdt,dist_sol,mu0,
993     .      zzlay,zday,pq,pdq,zdqchim,zdqschim,zdqcloud,zdqscloud)
994           
995c Photochemistry includes condensation of H2O2
996
997           do iq=nqchem_min,nq
998            if (noms(iq).eq."h2o2") then
999             DO l=1,nlayer
1000               DO ig=1,ngrid
1001                    pdq(ig,l,iq)=pdq(ig,l,iq)+ zdqchim(ig,l,iq)
1002                    pdq(ig,l,iq)=pdq(ig,l,iq)+ zdqcloud(ig,l,iq)
1003               ENDDO
1004             ENDDO
1005            else
1006             DO l=1,nlayer
1007               DO ig=1,ngrid
1008                    pdq(ig,l,iq)=pdq(ig,l,iq)+ zdqchim(ig,l,iq)
1009               ENDDO
1010             ENDDO
1011            endif
1012           ENDDO
1013           do iq=nqchem_min,nq
1014            if (noms(iq).eq."h2o2") then
1015               DO ig=1,ngrid
1016                    dqsurf(ig,iq)= dqsurf(ig,iq) + zdqschim(ig,iq)
1017                    dqsurf(ig,iq)= dqsurf(ig,iq) + zdqscloud(ig,iq)
1018               ENDDO
1019            else
1020               DO ig=1,ngrid
1021                    dqsurf(ig,iq)= dqsurf(ig,iq) + zdqschim(ig,iq)
1022               ENDDO
1023            endif
1024           ENDDO
1025
1026         END IF  ! (photochem.or.thermochem)
1027c        print*,'photochem ok'
1028
1029c   7c. Aerosol particles
1030c     -------------------
1031
1032c        ----------
1033c        Dust devil :
1034c        ----------
1035         IF(callddevil) then
1036           call dustdevil(ngrid,nlayer,nq, pplev,pu,pv,pt, tsurf,q2,
1037     &                zdqdev,zdqsdev)
1038 
1039           if (dustbin.ge.1) then
1040              do iq=1,nq
1041                 DO l=1,nlayer
1042                    DO ig=1,ngrid
1043                       pdq(ig,l,iq)=pdq(ig,l,iq)+ zdqdev(ig,l,iq)
1044                    ENDDO
1045                 ENDDO
1046              enddo
1047              do iq=1,nq
1048                 DO ig=1,ngrid
1049                    dqsurf(ig,iq)= dqsurf(ig,iq) + zdqsdev(ig,iq)
1050                 ENDDO
1051              enddo
1052           endif  ! (test sur dustbin)
1053
1054         END IF
1055
1056c        -------------
1057c        Sedimentation :   acts also on water ice
1058c        -------------
1059         IF (sedimentation) THEN
1060           call zerophys(ngrid*nlayer*nq, zdqsed)
1061           call zerophys(ngrid*nq, zdqssed)
1062
1063           if(doubleq) then
1064            call callsedim2q(ngrid,nlayer, ptimestep,
1065     &                pplev,zzlev, pt,
1066     &                pq, pdq, zdqsed, zdqssed,nq)
1067           else
1068            call callsedim(ngrid,nlayer, ptimestep,
1069     &                pplev,zzlev, pt,
1070     &                pq, pdq, zdqsed, zdqssed,nq)
1071           end if
1072
1073
1074           DO iq=1, nq
1075             DO l=1,nlayer
1076               DO ig=1,ngrid
1077                    pdq(ig,l,iq)=pdq(ig,l,iq)+ zdqsed(ig,l,iq)
1078               ENDDO
1079             ENDDO
1080           ENDDO
1081           DO iq=1, nq
1082             DO ig=1,ngrid
1083                dqsurf(ig,iq)= dqsurf(ig,iq) + zdqssed(ig,iq)
1084             ENDDO
1085           ENDDO
1086         END IF   ! (sedimentation)
1087
1088c        print*,'sedim ok'
1089
1090c   7d. Updates
1091c     ---------
1092
1093        DO iq=1, nq
1094          DO ig=1,ngrid
1095
1096c       ---------------------------------
1097c       Updating tracer budget on surface
1098c       ---------------------------------
1099            qsurf(ig,iq)=qsurf(ig,iq)+ptimestep*dqsurf(ig,iq)
1100
1101          ENDDO  ! (ig)
1102        ENDDO    ! (iq)
1103
1104      END IF    ! (tracer)
1105
1106c        print*,'tracers ok'
1107
1108
1109c-----------------------------------------------------------------------
1110c   8.5 THERMOSPHERE CALCULATION
1111c-----------------------------------------------------------------------
1112
1113      if (callthermos) then
1114        call thermosphere(pplev,pplay,dist_sol,
1115     $     mu0,ptimestep,ptime,zday,tsurf,zzlev,zzlay,
1116     &     pt,pq,pu,pv,pdt,pdq,
1117     $     zdteuv,zdtconduc,zdumolvis,zdvmolvis,zdqmoldiff)
1118c           do iq=nqchem_min,nq
1119c           write(*,*) 'thermo iq,pq',iq,pq(690,1,iq)
1120c           enddo
1121
1122        DO l=1,nlayer
1123          DO ig=1,ngrid
1124            dtrad(ig,l)=dtrad(ig,l)+zdteuv(ig,l)
1125            pdt(ig,l)=pdt(ig,l)+zdtconduc(ig,l)
1126     &                         +zdteuv(ig,l)
1127            pdv(ig,l)=pdv(ig,l)+zdvmolvis(ig,l)
1128            pdu(ig,l)=pdu(ig,l)+zdumolvis(ig,l)
1129            DO iq=1, nq
1130              pdq(ig,l,iq)=pdq(ig,l,iq)+zdqmoldiff(ig,l,iq)
1131            ENDDO
1132          ENDDO
1133        ENDDO
1134
1135
1136      endif
1137c-----------------------------------------------------------------------
1138c   8. Surface  and sub-surface soil temperature
1139c-----------------------------------------------------------------------
1140c
1141c
1142c   Surface temperature incrementation :
1143c   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1144
1145      DO ig=1,ngrid
1146         tsurf(ig)=tsurf(ig)+ptimestep*zdtsurf(ig)
1147      ENDDO
1148
1149
1150c  Prescription piege froid au pole sud (Except at high obliquity !!)
1151c  temperature en surface = temperature equilibre de phases du CO2
1152       
1153      IF (tracer.AND.water.AND.ngridmx.NE.1) THEN
1154         if (caps.and.(obliquit.lt.27.)) then
1155           tsurf(ngrid)=1/(1/136.27-r/5.9e+5*alog(0.0095*ps(ngrid)))
1156         endif
1157c       -------------------------------------------------------------
1158c       Change of surface albedo (set to 0.4) in case of ground frost
1159c       everywhere except on the north permanent cap and in regions
1160c       covered by dry ice.
1161c              ALWAYS PLACE these lines after newcondens !!!
1162c       -------------------------------------------------------------
1163         do ig=1,ngrid
1164
1165c       -------------- Version originale Franck ------------
1166          if (co2ice(ig).eq.0.and.qsurf(ig,nqmx).gt.0.005) then
1167            if (.not.watercaptag(ig)) then
1168              albedo(ig,1)=0.4
1169              albedo(ig,2)=0.4
1170            endif
1171          endif
1172c       -------------- version Francois ---------------
1173c          if (co2ice(ig).eq.0.and.
1174c    &        ((qsurf(ig,nqmx).gt.0.005).or.(watercaptag(ig)))) then
1175c              albedo(ig,1)=max(0.4,albedodat(ig))
1176c              albedo(ig,2)=albedo(ig,1)
1177c          endif
1178c       ---------------------------------------------
1179         enddo  ! (ig)
1180      ENDIF  ! (tracer, water and 3D)
1181
1182c        print*,'tracer, water and 3D ok'
1183
1184c
1185c   soil temperatures and subsurface heat flux:
1186c   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1187      IF (callsoil) THEN
1188         CALL soil(ngrid,nsoilmx,.false.,inertiedat,
1189     s          ptimestep,tsurf,tsoil,capcal,fluxgrd)
1190      ENDIF
1191
1192c        print*,'soil ok'
1193
1194
1195
1196
1197
1198c-----------------------------------------------------------------------
1199c  9. Writing output files
1200c  ------------------------
1201
1202c    -------------------------------
1203c    Dynamical fields incrementation
1204c    -------------------------------
1205c (FOR OUTPUT ONLY : the actual model integration is performed in the dynamics)
1206
1207      DO l=1,nlayer
1208        DO ig=1,ngrid
1209          zt(ig,l)=pt(ig,l)  + pdt(ig,l)*ptimestep
1210          zu(ig,l)=pu(ig,l)  + pdu(ig,l)*ptimestep
1211          zv(ig,l)=pv(ig,l)  + pdv(ig,l)*ptimestep
1212        ENDDO
1213      ENDDO
1214      DO iq=1, nq
1215        DO l=1,nlayer
1216          DO ig=1,ngrid
1217            zq(ig,l,iq)=pq(ig,l,iq) +pdq(ig,l,iq)*ptimestep
1218          ENDDO
1219        ENDDO
1220      ENDDO
1221      DO ig=1,ngrid
1222          ps(ig)=pplev(ig,1) + pdpsrf(ig)*ptimestep !already in 7
1223      ENDDO
1224      DO l=1,nlayer
1225        DO ig=1,ngrid
1226             zplev(ig,l)=pplev(ig,l)/pplev(ig,1)*ps(ig)
1227             zplay(ig,l)=pplay(ig,l)/pplev(ig,1)*ps(ig)
1228        ENDDO
1229      ENDDO
1230      ! Density calculation
1231      DO l=1,nlayer
1232         DO ig=1,ngrid
1233            rho(ig,l) = zplay(ig,l)/(rnew(ig,l)*zt(ig,l))
1234         ENDDO
1235      ENDDO
1236
1237c     Sum of fluxes in solar spectral bands (for output only)
1238      DO ig=1,ngrid
1239             fluxtop_sw_tot(ig)=fluxtop_sw(ig,1) + fluxtop_sw(ig,2)
1240             fluxsurf_sw_tot(ig)=fluxsurf_sw(ig,1) + fluxsurf_sw(ig,2)
1241      ENDDO
1242c ******* TEMPORAIRE ************************************************
1243      ztim1 = 999
1244      DO l=1,nlayer
1245        DO ig=1,ngrid
1246           if (pt(ig,l).lt.ztim1) then
1247               ztim1 = pt(ig,l)
1248               igmin = ig
1249               lmin = l
1250           end if
1251        ENDDO
1252      ENDDO
1253      if(min(pt(igmin,lmin),zt(igmin,lmin)).lt.70.) then       
1254        write(*,*) 'stability WARNING :'
1255        write(*,*) 'pt, zt Tmin = ', pt(igmin,lmin), zt(igmin,lmin),
1256     &              'ig l =', igmin, lmin
1257      end if
1258c *******************************************************************
1259
1260c     --------------------
1261c     Output on the screen
1262c     --------------------
1263
1264
1265      IF (lwrite) THEN
1266         PRINT*,'Global diagnostics for the physics'
1267         PRINT*,'Variables and their increments x and dx/dt * dt'
1268         WRITE(*,'(a6,a10,2a15)') 'Ts','dTs','ps','dps'
1269         WRITE(*,'(2f10.5,2f15.5)')
1270     s   tsurf(igout),zdtsurf(igout)*ptimestep,
1271     s   pplev(igout,1),pdpsrf(igout)*ptimestep
1272         WRITE(*,'(a4,a6,5a10)') 'l','u','du','v','dv','T','dT'
1273         WRITE(*,'(i4,6f10.5)') (l,
1274     s   pu(igout,l),pdu(igout,l)*ptimestep,
1275     s   pv(igout,l),pdv(igout,l)*ptimestep,
1276     s   pt(igout,l),pdt(igout,l)*ptimestep,
1277     s   l=1,nlayer)
1278      ENDIF
1279
1280cc****WRF
1281cc      IF (ngrid.NE.1) THEN
1282c       PRINT*,'check - values after update at ngrid/2+1'
1283c         WRITE(*,'(a4,a6,2a10)') 'l','u','v','T'
1284c         WRITE(*,'(i4,3f10.5)') (l,
1285c     s   zu(igout,l),
1286c     s   zv(igout,l),
1287c     s   zt(igout,l),
1288c     s   l=1,nlayer)
1289c
1290cc****WRF
1291
1292
1293         print*,'Ls =',zls*180./pi,
1294     &   ' tauref(700 Pa,lat=0) =',tauref(ngrid/2)
1295c     &   ' tau(Viking1) =',tau(ig_vl1,1)
1296
1297
1298
1299ccc
1300ccc
1301ccc**************** WRF OUTPUT *********************
1302ccc
1303ccc
1304       
1305        do ig=1,ngrid       
1306
1307           ! output surface temperature
1308           ! ... it was updated above, and not below
1309           ! ... we directly output tsurf to WRF (and not tsurf+zdtsurf*ptimestep !)
1310           wtsurf(ig) = tsurf(ig)           
1311
1312           ! output co2ice
1313           wco2ice(ig) = co2ice(ig)         
1314!
1315! TAB2D
1316!           
1317           ! output dust opacity     
1318           output_tab2d(ig,1) = tauref(ig)   !! tau(ig,1)  !! when dust is transp.
1319           ! output visible ground flux
1320           output_tab2d(ig,2) = fluxsurf_sw_tot(ig)
1321           ! output IR ground flux
1322           output_tab2d(ig,3) = fluxsurf_lw(ig)
1323           ! output visible top flux
1324           output_tab2d(ig,4) = fluxtop_sw_tot(ig)
1325           ! output IR top flux
1326           output_tab2d(ig,5) = fluxtop_lw(ig)
1327!          ! output total mass of water vapor (kg/m2)
1328!          output_tab2d(ig,6) = mtot(ig)
1329!          ! output total mass of water ice (kg/m2)
1330!          output_tab2d(ig,7) = icetot(ig)
1331!          ! output mean ice radius (meter)
1332!          output_tab2d(ig,8) = rave(ig)
1333           !
1334           output_tab2d(ig,9) = 0.
1335           output_tab2d(ig,10) = 0.     
1336!
1337! TAB3D
1338!
1339!          if (tracer) then
1340            if (iceparty) then         
1341              ! output ice radius 
1342              DO l=1,nlayer
1343                output_tab3d(ig,l,1) = rice(ig,l) 
1344              ENDDO
1345            else
1346             DO l=1,nlayer
1347                output_tab3d(ig,l,1) = 0. 
1348              ENDDO           
1349            endif
1350!           endif
1351
1352        enddo
1353
1354ccc
1355ccc
1356ccc**************** WRF OUTPUT *********************
1357ccc
1358ccc
1359
1360
1361
1362
1363c        -------------------------------------------------------------------
1364c        Writing NetCDF file  "RESTARTFI" at the end of the run
1365c        -------------------------------------------------------------------
1366c        Remarque : On  stocke restarfi
1367c        juste avant que la dynamique ne le soit dans restart.
1368c        entre maintenant et l'ecriture de restart,
1369c        on aura itau = itau +1 et remise a jour de time.
1370c        (lastcall = .true. lorsque itau+1 = itaufin)
1371c        Donc on stocke  avec time = time + dtvr
1372
1373         IF(lastcall) THEN
1374            ztime_fin = ptime + ptimestep/(float(iphysiq)*daysec)
1375            write(*,*)'pour physdem ztime_fin =',ztime_fin
1376            call physdem1("restartfi.nc",long,lati,nsoilmx,nq,
1377     .              ptimestep,pday,
1378     .              ztime_fin,tsurf,tsoil,co2ice,emis,q2,qsurf,
1379     .              area,albedodat,inertiedat,zmea,zstd,zsig,
1380     .              zgam,zthe)
1381         ENDIF
1382
1383
1384
1385c        -----------------------------------------------------------------
1386c        Saving statistics :
1387c        -----------------------------------------------------------------
1388c        ("stats" stores and accumulates 8 key variables in file "stats.nc"
1389c        which can later be used to make the statistic files of the run:
1390c        "stats")          only possible in 3D runs !
1391
1392         
1393         IF (callstats) THEN
1394
1395
1396            call wstats(ngrid,"ps",
1397     .          "Surface pressure","K",2,ps)
1398            call wstats(ngrid,"tsurf",
1399     .          "Surface temperature","K",2,tsurf)
1400            call wstats(ngrid,"co2ice",
1401     .          "CO2 ice cover",
1402     .                  "kg.m-2",2,co2ice)
1403c            call wstats(ngrid,
1404c     .          "emis","Surface emissivity","w.m-1",2,
1405c     .                  emis)
1406             call wstats(ngrid,"fluxsurf_lw",
1407     .                 "Thermal IR radiative flux to surface","W.m-2",2,
1408     .                 fluxsurf_lw)
1409             call wstats(ngrid,"fluxsurf_sw",
1410     .                  "Solar radiative flux to surface","W.m-2",2,
1411     .                   fluxsurf_sw_tot)
1412             call wstats(ngrid,"fluxtop_lw",
1413     .                  "Thermal IR radiative flux to space","W.m-2",2,
1414     .                  fluxtop_lw)
1415             call wstats(ngrid,"fluxtop_sw",
1416     .                  "Solar radiative flux to space","W.m-2",2,
1417     .                  fluxtop_sw_tot)
1418            call wstats(ngrid,"dod",
1419     .          "Dust optical depth"," ",2,tauref)
1420
1421            call wstats(ngrid,"temp",
1422     .          "Atmospheric temperature","K",3,zt)
1423            call wstats(ngrid,"u",
1424     .          "Zonal (East-West) wind","m.s-1",3,zu)
1425            call wstats(ngrid,"v",
1426     .          "Meridional (North-South) wind",
1427     .                  "m.s-1",3,zv)
1428            call wstats(ngrid,"w",
1429     .          "Vertical (down-up) wind",
1430     .                  "m.s-1",3,pw)
1431            call wstats(ngrid,"rho",
1432     .          "Atmospheric density","none",3,rho)
1433             call wstats(ngrid,"q2",
1434     .          "Boundary layer eddy kinetic energy","m2.s-2",3,q2)
1435
1436           if (tracer) then
1437            if (water) then
1438               vmr=zq(1:ngridmx,1:nlayermx,nqmx)*mugaz/mmol(nqmx)
1439               call wstats(ngrid,"vmr_h2ovapor",
1440     .                    "H2O vapor volume mixing ratio","mol/mol",
1441     .                    3,vmr)
1442               if (iceparty) then
1443                  vmr=zq(1:ngridmx,1:nlayermx,nqmx-1)*mugaz/mmol(nqmx-1)
1444                  call wstats(ngrid,"vmr_h2oice",
1445     .                       "H2O ice volume mixing ratio","mol/mol",
1446     .                       3,vmr)
1447               endif
1448            endif
1449
1450             if (thermochem.or.photochem) then
1451                do iq=1,nq
1452                   if ((noms(iq).eq."o").or.(noms(iq).eq."co2").or.
1453     .               (noms(iq).eq."co").or.(noms(iq).eq."n2").or.
1454     .               (noms(iq).eq."h2").or.
1455     .               (noms(iq).eq."o3")) then
1456                        do l=1,nlayer
1457                          do ig=1,ngrid
1458                            vmr(ig,l)=zq(ig,l,iq)*mmean(ig,l)/mmol(iq)
1459                          end do
1460                        end do
1461                        call wstats(ngrid,"vmr_"//trim(noms(iq)),
1462     .                     "Volume mixing ratio","mol/mol",3,vmr)
1463                   endif
1464                enddo
1465             endif
1466           endif !tracer
1467
1468            IF(lastcall) THEN
1469              write (*,*) "Writing stats..."
1470              call mkstats(ierr)
1471            ENDIF
1472          ENDIF !if callstats
1473
1474cc ****WRF: desactivated
1475ccc        (Store EOF for Mars Climate database software)
1476cc         IF (calleofdump) THEN
1477cc            CALL eofdump(ngrid, nlayer, zu, zv, zt, rho, ps)
1478cc         ENDIF
1479cc ****WRF
1480
1481cc        ----------------------------------------------------------------------
1482cc        output in netcdf file "DIAGFI", containing any variable for diagnostic
1483cc        (output with  period "ecritphy", set in "run.def")
1484cc        ----------------------------------------------------------------------
1485cc        meso_WRITEDIAGFI can ALSO be called from any other subroutines
1486cc        for any variables !!
1487cc       call meso_WRITEDIAGFI(ngrid,"emis","Surface emissivity","w.m-1",2,
1488cc    .                  emis)
1489
1490cc        call meso_WRITEDIAGFI(ngrid,"xlon","2D projected longitude","rad",2,
1491cc     .                  long)
1492cc        call meso_WRITEDIAGFI(ngrid,"xlat","2D projected latitude","rad",2,
1493cc     .                  lati)
1494cc        call meso_WRITEDIAGFI(ngrid,"zplay","Layer altitudes","m",3,
1495cc     .                  zplay)
1496cc        call meso_WRITEDIAGFI(ngrid,"zplev","Level altitudes","m",3,
1497cc     .                  zplev)
1498c      call meso_WRITEDIAGFI(ngrid,"tsurf",
1499c     .  "Surface temperature","K",2,
1500c     .                  tsurf)
1501c      call meso_WRITEDIAGFI(ngrid,"ps",
1502c     .  "surface pressure","Pa",2,ps)
1503c      call meso_WRITEDIAGFI(ngrid,"co2ice","co2 ice thickness",
1504c     .  "kg.m-2",2,
1505c     .                  co2ice)
1506cc       call meso_WRITEDIAGFI(ngrid,"rho","density","none",3,rho)
1507c      call meso_WRITEDIAGFI(ngrid,"fluxsurf_lw",
1508c     .  "fluxsurf_lw","W.m-2",2,
1509c     .       fluxsurf_lw)
1510c      call meso_WRITEDIAGFI(ngrid,"fluxsurf_sw",
1511c     .  "fluxsurf_sw","W.m-2",2,
1512c     .       fluxsurf_sw_tot)
1513      call meso_WRITEDIAGFI(ngrid,"fluxtop_lw",
1514     .  "fluxtop_lw","W.m-2",2,
1515     .       fluxtop_lw)
1516      call meso_WRITEDIAGFI(ngrid,"fluxtop_sw",
1517     .  "fluxtop_sw","W.m-2",2,
1518     .       fluxtop_sw_tot)
1519c      call meso_WRITEDIAGFI(ngrid,"tauref",
1520c     .  "tauref"," ",2,tauref)
1521
1522cc        call meso_WRITEDIAGFI(ngrid,"temp","temperature","K",3,zt)
1523
1524      call meso_WRITEDIAGFI(ngrid,"zu",
1525     .  "Zonal wind","m.s-1",3,zu)
1526      call meso_WRITEDIAGFI(ngrid,"zv",
1527     .  "Meri. wind","m.s-1",3,zv)
1528      call meso_WRITEDIAGFI(ngrid,"zt",
1529     .  "Temperature","m.s-1",3,zt)
1530
1531c      call meso_WRITEDIAGFI(ngrid,"du","Td. Zonal wind","m.s-1",3,zu-pu)
1532c      call meso_WRITEDIAGFI(ngrid,"dv","Td. Meri. wind","m.s-1",3,zv-pv)
1533c      call meso_WRITEDIAGFI(ngrid,"dt","Td. Temperat.", "m.s-1",3,zt-pt)
1534
1535cc      TEMPORAIRE **************
1536c         do l=1, nlayer
1537c            write(*,*) 'lev', l, pplev(ngrid/2,l)
1538c            write(*,*) 'lay', l, pplay(ngrid/2,l)
1539c         end do
1540c            write(*,*) 'lev', nlayer+1, pplev(ngrid/2,nlayer+1)
1541c            stop
1542
1543
1544
1545cc        call meso_WRITEDIAGFI(ngrid,"u","Zonal wind","m.s-1",3,zu)
1546cc        call meso_WRITEDIAGFI(ngrid,"v","Meridional wind","m.s-1",3,zv)
1547cc       call meso_WRITEDIAGFI(ngrid,"w","Vertical wind","m.s-1",3,pw)
1548cc       call meso_WRITEDIAGFI(ngrid,"q2","q2","kg.m-3",3,q2)
1549cc       call meso_WRITEDIAGFI(ngridm,'Teta','T potentielle','K',3,zh)
1550cc       call meso_WRITEDIAGFI(ngridm,'Pression','Pression','Pa',3,pplay)
1551
1552cc       OUTPUT of tracer mass mixing ratio and surface value :   
1553cc       if (tracer) then
1554cc         (for photochemistry, outputs are done in calchim)
1555cc          do iq=1,nqmx
1556cc            write(str2(1:2),'(i2.2)') iq
1557cc            call meso_WRITEDIAGFI(ngridmx,'q'//str2,noms(iq),
1558cc    &                         'kg/kg',3,zq(1,1,iq))
1559cc            call meso_WRITEDIAGFI(ngridmx,'qsurf'//str2,noms(iq),
1560cc    &                     'kg.m-2',2,qsurf(1,iq))
1561cc          end do
1562cc        end if
1563cc ***************************************************
1564c
1565cc  Outputs for H2O
1566c       if (tracer) then
1567c        if (activice) then
1568cc         call meso_WRITEDIAGFI(ngridmx,'tauice','tau','SI',2,tau(1,2))
1569cc         call meso_WRITEDIAGFI(ngridmx,'sw_htrt','sw heat. rate',
1570cc     &                   'w.m-2',3,zdtsw)
1571cc         call meso_WRITEDIAGFI(ngridmx,'lw_htrt','lw heat. rate',
1572cc     &                   'w.m-2',3,zdtlw)
1573c        endif  !(activice)
1574c
1575c        if (water.and..not.photochem) then
1576c           iq=nq
1577cc          write(str2(1:2),'(i2.2)') iq
1578cc          call meso_WRITEDIAGFI(ngridmx,'dqs'//str2,'dqscloud',
1579cc     &                    'kg.m-2',2,zdqscloud(1,iq))
1580cc          call meso_WRITEDIAGFI(ngridmx,'dqch'//str2,'var chim',
1581cc     &                    'kg/kg',3,zdqchim(1,1,iq))
1582cc          call meso_WRITEDIAGFI(ngridmx,'dqd'//str2,'var dif',
1583cc     &                    'kg/kg',3,zdqdif(1,1,iq))
1584cc          call meso_WRITEDIAGFI(ngridmx,'dqa'//str2,'var adj',
1585cc     &                    'kg/kg',3,zdqadj(1,1,iq))
1586cc          call meso_WRITEDIAGFI(ngridmx,'dqc'//str2,'var c',
1587cc     &                    'kg/kg',3,zdqc(1,1,iq))
1588c        endif  !(water.and..not.photochem)
1589c
1590cc       if (iceparty) then
1591cc          iq=nq-1
1592cc          write(str2(1:2),'(i2.2)') iq
1593cc          call meso_WRITEDIAGFI(ngridmx,'q'//str2,'mix. ratio',
1594cc    &                     'kg/kg',3,zq(1,1,iq))
1595cc       endif  !(iceparty)
1596c       endif
1597c
1598cc  Outputs for dust tracers
1599c
1600cc ****WRF: careful, have to correct floating exception
1601c
1602c         if (tracer.and.(dustbin.ne.0)) then
1603c            call meso_WRITEDIAGFI(ngridmx,'tau','taudust','SI',2,tau(1,1))
1604c            if (doubleq) then
1605c               call meso_WRITEDIAGFI(ngridmx,'qsurf','qsurf',
1606c     &                         'kg.m-2',2,qsurf(1,1))
1607c               call meso_WRITEDIAGFI(ngridmx,'Nsurf','N particles',
1608c     &                         'N.m-2',2,qsurf(1,2))
1609c               call meso_WRITEDIAGFI(ngridmx,'dqsdev','ddevil lift',
1610c     &                         'kg.m-2.s-1',2,zdqsdev(1,1))
1611c               call meso_WRITEDIAGFI(ngridmx,'dqssed','sedimentation',
1612c     &                         'kg.m-2.s-1',2,zdqssed(1,1))
1613c               do  l=1,nlayer
1614c                  do ig=1, ngrid
1615c                     reff(ig,l)= ref_r0 *
1616c     &               (r3n_q*pq(ig,l,1)/max(pq(ig,l,2),0.01))**(1./3.)
1617c                     reff(ig,l)=min(max(reff(ig,l),1.e-10),500.e-6)
1618c                  end do
1619c               end do
1620c               call meso_WRITEDIAGFI(ngridmx,'reff','reff','m',3,reff)
1621c            else
1622c               do iq=1,dustbin
1623c                  write(str2(1:2),'(i2.2)') iq
1624c                  call meso_WRITEDIAGFI(ngridmx,'q'//str2,'mix. ratio',
1625c     &                            'kg/kg',3,zq(1,1,iq))
1626c                  call meso_WRITEDIAGFI(ngridmx,'qsurf'//str2,'qsurf',
1627c     &                            'kg.m-2',2,qsurf(1,iq))
1628c               end do
1629c            endif ! (doubleq)
1630c         end if  ! (tracer.and.(dustbin.ne.0))
1631c
1632c
1633c      ELSE     ! if(ngrid.eq.1)
1634c
1635c         print*,'Ls =',zls*180./pi,
1636c     &  '  tauref(700 Pa) =',tauref,' local tau =',tau(1,1)
1637cc      ----------------------------------------------------------------------
1638cc      Output in grads file "g1d" (ONLY when using testphys1d)
1639cc      (output at every X physical timestep)
1640cc      ----------------------------------------------------------------------
1641cc
1642cc        CALL writeg1d(ngrid,1,fluxsurf_lw,'Fs_ir','W.m-2')
1643cc        CALL writeg1d(ngrid,1,tsurf,'tsurf','K')
1644c         CALL writeg1d(ngrid,1,ps,'ps','Pa')
1645c         
1646c         CALL writeg1d(ngrid,nlayer,zt,'T','K')
1647cc        CALL writeg1d(ngrid,nlayer,pu,'u','m.s-1')
1648cc        CALL writeg1d(ngrid,nlayer,pv,'v','m.s-1')
1649cc        CALL writeg1d(ngrid,nlayer,pw,'w','m.s-1')
1650c
1651c         if(tracer) then
1652cc           CALL writeg1d(ngrid,1,tau,'tau','SI')
1653c            do iq=1,nq
1654c              CALL writeg1d(ngrid,nlayer,zq(1,1,iq),noms(iq),'kg/kg')
1655c            end do
1656c         end if
1657c
1658c         zlocal(1)=-log(pplay(1,1)/pplev(1,1))* Rnew(1,1)*zt(1,1)/g
1659c
1660c         do l=2,nlayer-1
1661c            tmean=zt(1,l)
1662c            if(zt(1,l).ne.zt(1,l-1))
1663c     &        tmean=(zt(1,l)-zt(1,l-1))/log(zt(1,l)/zt(1,l-1))
1664c              zlocal(l)= zlocal(l-1)
1665c     &        -log(pplay(1,l)/pplay(1,l-1))*rnew(1,l)*tmean/g
1666c         enddo
1667c         zlocal(nlayer)= zlocal(nlayer-1)-
1668c     &                   log(pplay(1,nlayer)/pplay(1,nlayer-1))*
1669c     &                   rnew(1,nlayer)*tmean/g
1670c
1671cc         if(tracer) then
1672cc         do l=2,nlayer
1673cc            do iq=1,nq
1674cc               hco2(iq)=zq(1,l,iq)/zq(1,l-1,iq)
1675cc               hco2(iq)=-(zlocal(l)-zlocal(l-1))/log(hco2(iq))/1000.
1676cc            enddo
1677cc            write(225,*) l,pt(1,l),(hco2(iq),iq=1,6)
1678cc            write(226,*) l,(hco2(iq),iq=7,13)
1679cc         enddo
1680cc         endif
1681c
1682c      END IF       ! if(ngrid.ne.1)
1683
1684
1685
1686      icount=icount+1
1687
1688      RETURN
1689      END
Note: See TracBrowser for help on using the repository browser.