source: branches/ORCHIDEE_2_2/ORCHIDEE/src_oasisdriver/orchideeoasis.f90 @ 6393

Last change on this file since 6393 was 6319, checked in by josefine.ghattas, 5 years ago

Improvment for the ESM CO2 configuration:

  • Separate variable fco2_lu into 3 parts: fco2_lu, fco2_wh and fco2_ha
  • Move calculation of co2_flux from dt_sechiba time-step to daily time-step (in the part for do_slow)
  • Removed co2_flux and fco2_lu from stomate_intialize argument list. These variables were never used in the intialization phase.
  • Add co2_flux, and fco2_wh, fco2_ha to restart file
  • Corrected output unit for nee to be consistent with LMDZ and stomate output variables. It is now in kgC/m2/s.
  • Corrected output for znetco2
  • Added fCO2_fWoodharvest and fCO2_fHarvest as new possible tracers in LMDZ (intersurf).
  • Added diagnostic output for fCO2_fWoodharvest and fCO2_fHarvest
  1. Cadule
File size: 40.4 KB
Line 
1! =================================================================================================================================
2! PROGRAM       : orchideedriveroasis
3!
4! CONTACT       : jan.polcher@lmd.jussieu.fr
5!
6! LICENCE      : IPSL (2016)
7! This software is governed by the CeCILL licence see ORCHIDEE/ORCHIDEE_CeCILL.LIC
8!
9!>\BRIEF      This is the main program for the driver which gets the forcing data from OASIS. It is used as an interface
10!!            for WRF for instance. It allows to have another domain decomposition than the atmosphere. Particularly useful
11!!            for coupling to atmospheric models not decomposed by the "apple method".
12!!
13!!\n DESCRIPTION: This program only organises the data and calls sechiba_main after having received the data from OASIS.
14!!                The main work for the OASIS interface is done in orchoasis_tools.f90 module.
15!!                Call the various modules to get the forcing data and provide it to SECHIBA. The only complexity
16!!                is setting-up the domain decomposition and distributing the grid information.
17!!                The code is parallel from tip to toe using the domain decomposition inherited from LMDZ.
18!!
19!! RECENT CHANGE(S): None
20!!
21!! REFERENCE(S) :
22!!
23!! SVN          :
24!! $HeadURL:  $
25!! $Date:  $
26!! $Revision: $
27!! \n
28!_ ================================================================================================================================
29PROGRAM orchideeoasis
30  !---------------------------------------------------------------------
31  !-
32  !-
33  !---------------------------------------------------------------------
34  USE defprec
35  USE netcdf
36  !
37  !
38  USE ioipsl_para
39  USE mod_orchidee_para
40  !
41  USE grid
42  USE timer
43
44  USE globgrd
45  USE orchoasis_tools
46  !
47  USE sechiba
48  USE control
49  USE ioipslctrl
50  !
51  USE mod_oasis
52  !-
53  IMPLICIT NONE
54  !-
55  INCLUDE 'mpif.h'
56  !-
57  CHARACTER(LEN=80) :: gridfilename
58  CHARACTER(LEN=8)  :: model_guess
59  INTEGER(i_std)    :: iim_glo, jjm_glo, file_id
60  !-
61  INTEGER(i_std)    :: nbseg
62  REAL(r_std), ALLOCATABLE, DIMENSION(:,:) :: lon_glo, lat_glo, area_glo
63  REAL(r_std), ALLOCATABLE, DIMENSION(:,:) :: mask_glo
64  INTEGER(i_std), ALLOCATABLE, DIMENSION(:,:) :: maskinv_glo
65  REAL(r_std), ALLOCATABLE, DIMENSION(:,:,:,:) :: corners_glo
66  REAL(r_std), ALLOCATABLE, DIMENSION(:,:,:) :: corners_lon, corners_lat
67  INTEGER(i_std) :: nbindex_g, kjpindex
68  INTEGER(i_std), ALLOCATABLE, DIMENSION(:) :: kindex, kindex_g
69  !
70  ! Variables for the global grid available on all procs and used
71  ! to fill the ORCHIDEE variable on the root_proc
72  !
73  REAL(r_std), ALLOCATABLE, DIMENSION(:,:)    :: lalo_glo
74  REAL(r_std), ALLOCATABLE, DIMENSION(:)      :: contfrac_glo
75  CHARACTER(LEN=20)                           :: calendar
76  !-
77  !- Variables local to each processors.
78  !-
79  INTEGER(i_std) :: i, j, ik, nbdt, first_point
80  INTEGER(i_std) :: itau, itau_offset, itau_sechiba
81  REAL(r_std)    :: date0, date0_shifted, dt, julian, julian0
82  INTEGER(i_std) :: rest_id, rest_id_stom
83  INTEGER(i_std) ::  hist_id, hist2_id, hist_id_stom, hist_id_stom_IPCC
84  REAL(r_std), ALLOCATABLE, DIMENSION(:,:) :: lalo_loc
85  INTEGER(i_std) :: iim, jjm
86  REAL(r_std), ALLOCATABLE, DIMENSION(:,:) :: lon, lat
87  !-
88  !- input fields
89  !-
90  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: u             !! Lowest level wind speed
91  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: v             !! Lowest level wind speed
92  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: zlev_uv       !! Height of first layer
93  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: zlev_tq       !! Height of first layer
94  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: qair          !! Lowest level specific humidity
95  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: precip_rain   !! Rain precipitation
96  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: precip_snow   !! Snow precipitation
97  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: lwdown        !! Down-welling long-wave flux
98  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: swdown        !! Downwelling surface short-wave flux
99  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: sinang        !! cosine of solar zenith angle
100  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: temp_air      !! Air temperature in Kelvin
101  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: epot_air      !! Air potential energy
102  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: ccanopy       !! CO2 concentration in the canopy
103  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: petAcoef      !! Coeficients A from the PBL resolution
104  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: peqAcoef      !! One for T and another for q
105  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: petBcoef      !! Coeficients B from the PBL resolution
106  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: peqBcoef      !! One for T and another for q
107  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: cdrag         !! Cdrag
108  REAL(r_std), ALLOCATABLE, DIMENSION (:)             :: pb            !! Lowest level pressure
109  !-
110  !- output fields
111  !-
112  REAL(r_std), ALLOCATABLE, DIMENSION (:)            :: z0            !! Surface roughness
113  REAL(r_std), ALLOCATABLE, DIMENSION (:)            :: coastalflow   !! Diffuse flow of water into the ocean (m^3/dt)
114  REAL(r_std), ALLOCATABLE, DIMENSION (:)            :: riverflow     !! Largest rivers flowing into the ocean (m^3/dt)
115  REAL(r_std), ALLOCATABLE, DIMENSION (:)            :: tsol_rad      !! Radiative surface temperature
116  REAL(r_std), ALLOCATABLE, DIMENSION (:)            :: vevapp        !! Total of evaporation
117  REAL(r_std), ALLOCATABLE, DIMENSION (:)            :: temp_sol_new  !! New soil temperature
118  REAL(r_std), ALLOCATABLE, DIMENSION (:)            :: qsurf         !! Surface specific humidity
119  REAL(r_std), ALLOCATABLE, DIMENSION (:,:)          :: albedo        !! Albedo
120  REAL(r_std), ALLOCATABLE, DIMENSION (:)            :: fluxsens      !! Sensible chaleur flux
121  REAL(r_std), ALLOCATABLE, DIMENSION (:)            :: fluxlat       !! Latent chaleur flux
122  REAL(r_std), ALLOCATABLE, DIMENSION (:)            :: emis          !! Emissivity
123  REAL(r_std), ALLOCATABLE, DIMENSION (:)            :: netco2        !! netco2flux: Sum CO2 flux over PFTs
124  REAL(r_std), ALLOCATABLE, DIMENSION (:)            :: carblu        !! fco2_lu: Land Cover Change CO2 flux
125  REAL(r_std), ALLOCATABLE, DIMENSION (:)            :: carbwh        !! fco2_wh: Wood harvest CO2 flux
126  REAL(r_std), ALLOCATABLE, DIMENSION (:)            :: carbha        !! fco2_ha: Crop harvest CO2 flux
127  REAL(r_std), ALLOCATABLE, DIMENSION (:,:)          :: veget         !! Fraction of vegetation type (unitless, 0-1)
128  REAL(r_std), ALLOCATABLE, DIMENSION (:,:)          :: lai           !! Leaf area index (m^2 m^{-2}
129  REAL(r_std), ALLOCATABLE, DIMENSION (:,:)          :: height        !! Vegetation Height (m)
130  !-
131  !- Declarations for OASIS
132  !-
133  CHARACTER(LEN=6)   :: comp_name = 'orchid'
134  INTEGER(i_std) :: loc_size, glo_size ! number of pes used
135  INTEGER(i_std) :: loc_rank, glo_rank ! rank of current pe
136  INTEGER(i_std) :: localComm, LOCAL_OASIS_COMM  ! local MPI communicator and Initialized
137  INTEGER(i_std) :: comp_id    ! component identification
138  INTEGER(i_std) :: ierror, flag, oasis_info
139  CHARACTER(LEN=3) :: chout
140  CHARACTER(LEN=4) :: oasis_gridname
141  CHARACTER(LEN=30) :: diagfilename
142  !-
143  !-
144  !-
145  REAL(r_std) :: atmco2
146  REAL(r_std), ALLOCATABLE, DIMENSION (:)  :: u_tq, v_tq, swnet
147  LOGICAL :: lrestart_read = .TRUE. !! Logical for _restart_ file to read
148  LOGICAL :: lrestart_write = .FALSE. !! Logical for _restart_ file to write'
149  !
150  ! Time  variables
151  !
152  LOGICAL, PARAMETER :: timemeasure=.TRUE.
153  REAL(r_std) :: waitput_cputime=0.0, waitget_cputime=0.0, orchidee_cputime=0.0
154  REAL(r_std) :: waitput_walltime=0.0, waitget_walltime=0.0, orchidee_walltime=0.0
155  !
156  ! Print point
157  !
158!!  REAL(r_std), DIMENSION(2) :: testpt=(/44.8,-25.3/)
159!!  REAL(r_std), DIMENSION(2) :: testpt=(/44.8,-18.3/)
160!!  REAL(r_std), DIMENSION(2) :: testpt=(/-60.25,-5.25/)
161!!  REAL(r_std), DIMENSION(2) :: testpt=(/46.7,10.3/)
162!!  REAL(r_std), DIMENSION(2) :: testpt=(/0.25,49.25/)
163  ! Case when no ouput is desired.
164  REAL(r_std), DIMENSION(2) :: testpt=(/9999.99,9999.99/)
165  INTEGER(i_std) :: ktest
166  !
167  !-
168  !---------------------------------------------------------------------------------------
169  !-
170  !- Define MPI communicator and set-up OASIS
171  !-
172  !---------------------------------------------------------------------------------------
173  !-
174  !
175  CALL oasis_init_comp(comp_id, comp_name, ierror)
176  CALL oasis_get_localcomm (LOCAL_OASIS_COMM, ierror)
177  !
178  ! Set parallel processing in ORCHIDEE
179  !
180  CALL Init_orchidee_para(LOCAL_OASIS_COMM) 
181  !====================================================================================
182  !
183  ! Start timer now that the paralelisation is started.
184  !
185  IF ( timemeasure ) THEN
186     CALL init_timer
187     CALL start_timer(timer_global)
188     CALL start_timer(timer_mpi)
189  ENDIF
190  !-
191  !
192  !---------------------------------------------------------------------------------------
193  !-
194  !-  Print some diagnostics for this main of ORCHIDEE
195  !-
196  !---------------------------------------------------------------------------------------
197  !-
198  CALL MPI_COMM_RANK(MPI_COMM_WORLD, glo_rank, ierror)
199  CALL MPI_COMM_RANK(LOCAL_OASIS_COMM, loc_rank, ierror)
200  CALL MPI_COMM_SIZE(MPI_COMM_WORLD, glo_size, ierror)
201  CALL MPI_COMM_SIZE(LOCAL_OASIS_COMM, loc_size, ierror)
202  !-
203  !
204  WRITE (numout,*) '-----------------------------------------------------------'
205  WRITE (numout,*) '-------------------- comp_name= ',comp_name,'  ---------------'
206  WRITE (numout,*) '-----------------------------------------------------------'
207  WRITE (numout,*) TRIM(comp_name), ' Running with reals compiled as kind =',r_std
208  WRITE (numout,*) 'I am component ', TRIM(comp_name), ' local rank :', loc_rank, &
209       &           " Global rank :", glo_rank
210  WRITE (numout,*) 'CPUs we are using for the main :', loc_size, ' Global number :', glo_size
211  WRITE (numout,*) 'Local and global MPI communicators :', LOCAL_OASIS_COMM,  MPI_COMM_WORLD
212  WRITE (numout,*) '----------------------------------------------------------'
213  CALL flush(numout)
214  !
215  !---------------------------------------------------------------------------------------
216  !-
217  !- Start the getconf processes
218  !-
219  !---------------------------------------------------------------------------------------
220  !-
221!!  CALL getin_name("run.def")
222  !-
223  !Config Key   = GRID_FILE
224  !Config Desc  = Name of file containing the forcing data
225  !Config If    = [-]
226  !Config Def   = grid_file.nc
227  !Config Help  = This is the name of the file from which we will read
228  !Config         or write into it the description of the grid from
229  !Config         the forcing file.
230  !Config         compliant.
231  !Config Units = [FILE]
232  !-
233  gridfilename='grid_file.nc'
234  CALL getin_p('GRID_FILE', gridfilename)
235  !-
236  !- Get some basic variables from the run.def
237  !-
238  atmco2=350.
239  CALL getin_p('ATM_CO2',atmco2)
240  !---------------------------------------------------------------------------------------
241  !-
242  !- Get the grid on all processors.
243  !-
244  !---------------------------------------------------------------------------------------
245  !-
246  !
247  CALL globgrd_getdomsz(gridfilename, iim_glo, jjm_glo, nbindex_g, model_guess, file_id)
248  nbseg = 4
249  !
250  !-
251  !- Allocation of memory
252  !- variables over the entire grid (thus in x,y)
253  ALLOCATE(lon_glo(iim_glo, jjm_glo))
254  ALLOCATE(lat_glo(iim_glo, jjm_glo))
255  ALLOCATE(mask_glo(iim_glo, jjm_glo))
256  ALLOCATE(area_glo(iim_glo, jjm_glo))
257  ALLOCATE(corners_glo(iim_glo, jjm_glo, nbseg, 2))
258  !
259  ! Gathered variables
260  ALLOCATE(kindex_g(nbindex_g))
261  ALLOCATE(contfrac_glo(nbindex_g))
262  !-
263  !-
264  !-
265  CALL globgrd_getgrid(file_id, iim_glo, jjm_glo, nbindex_g, model_guess, &
266       &               lon_glo, lat_glo, mask_glo, area_glo, corners_glo,&
267       &               kindex_g, contfrac_glo, calendar)
268  !-
269  !- Set the calendar and get some information
270  !-
271  CALL ioconf_calendar(calendar)
272  CALL ioget_calendar(one_year, one_day)
273  !-
274  !- get the time period for the run
275  !-
276  CALL orchoasis_time(date0, dt, nbdt)
277  !-
278  !- lalo needs to be created before going into the parallel region
279  !-
280  ALLOCATE(lalo_glo(nbindex_g,2))
281  DO ik=1,nbindex_g
282     !
283     j = ((kindex_g(ik)-1)/iim_glo)+1
284     i = (kindex_g(ik)-(j-1)*iim_glo)
285     !
286     IF ( i > iim_glo .OR. j > jjm_glo ) THEN
287        WRITE(100+mpi_rank,*) "Error in the indexing (ik, kindex, i, j) : ", ik, kindex(ik), i, j
288        STOP "ERROR in orchideeoasis"
289     ENDIF
290     !
291     lalo_glo(ik,1) = lat_glo(i,j)
292     lalo_glo(ik,2) = lon_glo(i,j)
293     !
294  ENDDO
295  !
296  WRITE(100+mpi_rank,*) "Rank", mpi_rank, " Before parallel region All land points : ",  nbindex_g
297  WRITE(100+mpi_rank,*) "Rank", mpi_rank, " from ", iim_glo, " point in Lon. and ", jjm_glo, "in Lat."
298  !-
299  !---------------------------------------------------------------------------------------
300  !-
301  !- Initialise the ORCHIDEE domain on the procs (longitude, latitude, indices)
302  !-
303  !---------------------------------------------------------------------------------------
304  !-
305  !- init_data_para also transfers kindex_g to index_g (the variable used in ORCHIDEE)
306  !-
307  CALL grid_set_glo(iim_glo, jjm_glo, nbindex_g)
308  CALL grid_allocate_glo(nbseg)
309  ! Copy the list of indexes of land points into index_g used by ORCHIDEE and then broacast to all
310  ! processors
311  CALL bcast(nbindex_g)
312  IF ( is_root_prc) index_g = kindex_g
313  CALL bcast(index_g)
314  !
315  WRITE(numout,*) "Rank", mpi_rank, "Into Init_orchidee_data_para_driver with ", nbindex_g,index_g(1)
316  !
317  CALL Init_orchidee_data_para_driver(nbindex_g,index_g)
318  CALL init_ioipsl_para 
319  !
320  WRITE(numout,*) "Rank", mpi_rank, "After init_data_para global size : ",  nbp_glo, SIZE(index_g), iim_g, iim_glo, jjm_g, jjm_glo
321  WRITE(numout,'("After init_data_para local : ij_nb, jj_nb",2I4)') iim_glo, jj_nb
322  !
323  ! Allocate grid on the local processor
324  !
325  IF ( model_guess == "regular") THEN
326     CALL grid_init (nbp_loc, nbseg, regular_lonlat, "ForcingGrid")
327  ELSE IF ( model_guess == "WRF") THEN
328     CALL grid_init (nbp_loc, nbseg, regular_xy, "WRFGrid")
329  ELSE
330     CALL ipslerr(3, "orchideeoasis", "The grid found in the GRID_FILE is not supported by ORCHIDEE", "", "")
331  ENDIF
332  !
333  ! Transfer the global grid variables to the ORCHIDEE version on the root proc
334  ! *_glo -> *_g
335  ! Variables *_g were allocated with the CALL init_grid
336  !
337  IF ( is_root_prc) THEN
338     !
339     lalo_g(:,:) = lalo_glo(:,:)
340     lon_g(:,:) = lon_glo(:,:)
341     lat_g(:,:) = lat_glo(:,:)
342     !
343  ENDIF
344  !-
345  !
346  ! Set the local dimensions of the fields
347  !
348  iim = iim_glo
349  jjm = jj_nb
350  kjpindex = nbp_loc
351  !
352  WRITE(numout,*) mpi_rank, "DIMENSIONS of grid on processor : iim, jjm, kjpindex = ", iim, jjm, kjpindex
353  !
354  !  Allocate the local arrays we need :
355  !
356  ALLOCATE(lon(iim,jjm), lat(iim,jjm))
357  ALLOCATE(kindex(kjpindex))
358  !
359  lon=lon_glo(:,jj_para_begin(mpi_rank):jj_para_end(mpi_rank))
360  lat=lat_glo(:,jj_para_begin(mpi_rank):jj_para_end(mpi_rank))
361  !
362  !
363  ! Redistribute the indeces on all procs (apple distribution of land points)
364  !
365  CALL bcast(lon_g)
366  CALL bcast(lat_g)
367  CALL scatter(index_g, kindex) 
368  !
369  !
370  ! Apply the offset needed so that kindex refers to the index of the land point
371  ! on the current region, i.e. the local lon lat domain.
372  !
373  kindex(1:kjpindex)=kindex(1:kjpindex)-(jj_begin-1)*iim_glo
374  !
375  ! This routine transforms the global grid into a series of polygons for all land
376  ! points identified by index_g.
377  !
378  CALL grid_stuff(nbindex_g, iim_g, jjm_g, lon_g, lat_g, index_g, contfrac_glo)
379  !
380  ! Distribute the global lalo to the local processor level lalo
381  !
382  ALLOCATE(lalo_loc(kjpindex,2))
383  CALL scatter(lalo_glo, lalo_loc)
384  lalo(:,:) = lalo_loc(:,:)
385  !
386  !-
387  !---------------------------------------------------------------------------------------
388  !-
389  !- Allocate the space for the per processor coupling variables
390  !-
391  !---------------------------------------------------------------------------------------
392  !-
393  ALLOCATE(zlev_tq(kjpindex), zlev_uv(kjpindex))
394  ALLOCATE(u(kjpindex), v(kjpindex), pb(kjpindex))
395  ALLOCATE(temp_air(kjpindex))
396  ALLOCATE(qair(kjpindex))
397  ALLOCATE(precip_rain(kjpindex), precip_snow(kjpindex))
398  ALLOCATE(swdown(kjpindex), lwdown(kjpindex), sinang(kjpindex))
399  !
400  ALLOCATE(epot_air(kjpindex), ccanopy(kjpindex), cdrag(kjpindex), swnet(kjpindex))
401  !
402  ALLOCATE(petAcoef(kjpindex), peqAcoef(kjpindex), petBcoef(kjpindex), peqBcoef(kjpindex))
403  ALLOCATE(u_tq(kjpindex), v_tq(kjpindex))
404  !
405  ALLOCATE(vevapp(kjpindex), fluxsens(kjpindex), fluxlat(kjpindex), coastalflow(kjpindex), riverflow(kjpindex))
406  ALLOCATE(netco2(kjpindex), carblu(kjpindex))
407  ALLOCATE(carbwh(kjpindex), carbha(kjpindex))
408  ALLOCATE(tsol_rad(kjpindex), temp_sol_new(kjpindex), qsurf(kjpindex))
409  ALLOCATE(albedo(kjpindex,2), emis(kjpindex), z0(kjpindex))
410  ALLOCATE(veget(kjpindex,nvm))
411  ALLOCATE(lai(kjpindex,nvm))
412  ALLOCATE(height(kjpindex,nvm))
413  !
414  WRITE(numout,*) "Rank", mpi_rank, "Domain size per proc !:", iim_glo, jjm_glo, kjpindex, SIZE(kindex)
415  WRITE(numout,*) "Rank", mpi_rank, "In parallel region land index starts at : ", kindex(1)
416  !
417  CALL orchoasis_time(date0, dt, nbdt)
418  !
419  CALL control_initialize
420  dt_sechiba = dt
421  !
422  itau = 0
423  !
424  CALL ioipslctrl_restini(itau, date0, dt, rest_id, rest_id_stom, itau_offset, date0_shifted)
425  !
426  ! Get the date of the first time step
427  !
428  julian = date0 + 0.5*(dt/one_day)
429  CALL ju2ymds (julian, year, month, day, sec)
430  !
431  in_julian = itau2date(itau, date0, dt)
432  CALL ymds2ju (year,1,1,zero, julian0)
433  julian_diff = in_julian-julian0
434
435  CALL xios_orchidee_init( MPI_COMM_ORCH,                    &
436       date0,    year,    month,           day, julian_diff, &
437       lon,      lat,     soilth_lev)
438  !
439  itau_sechiba = itau + itau_offset
440  !
441  WRITE(numout,*) "orchoasis_history :", iim, jjm, SHAPE(lon)
442  !- Initialize IOIPSL sechiba output files
443  CALL ioipslctrl_history(iim, jjm, lon, lat,  kindex, kjpindex, itau_sechiba, &
444       date0, dt, hist_id, hist2_id, hist_id_stom, hist_id_stom_IPCC)
445  WRITE(numout,*) "HISTORY : Define for ", itau, date0, dt
446  !
447  !-
448  !-
449  !---------------------------------------------------------------------------------------
450  !-
451  !- Send the grid to OASIS ... only on the root processor
452  !-
453  !---------------------------------------------------------------------------------------
454  !-
455  IF ( is_root_prc ) THEN
456     !
457     ! TOCOMPLETE - Put here OASIS grid, corner, areas and mask writing calls !
458     !
459     oasis_gridname = model_guess(1:4)
460     CALL oasis_start_grids_writing(flag)
461     !
462     CALL oasis_write_grid(oasis_gridname, iim_glo, jjm_glo, lon_glo, lat_glo)
463     !
464     ALLOCATE(corners_lon(iim_glo, jjm_glo, nbseg), corners_lat(iim_glo, jjm_glo, nbseg))
465     corners_lon(:,:,:) = corners_glo(:,:,:,1)
466     corners_lat(:,:,:) = corners_glo(:,:,:,2)
467     CALL oasis_write_corner(oasis_gridname, iim_glo, jjm_glo, nbseg, corners_lon, corners_lat)
468     !
469     ALLOCATE(maskinv_glo(iim_glo, jjm_glo))
470     DO i=1,iim_glo
471        DO j=1,jjm_glo
472           IF (mask_glo(i,j) == 0) THEN
473              maskinv_glo(i,j) = 1
474           ELSE
475              maskinv_glo(i,j) = 0
476           ENDIF
477        ENDDO
478     ENDDO
479     CALL oasis_write_mask(oasis_gridname, iim_glo, jjm_glo, maskinv_glo)
480     !
481     CALL oasis_write_area(oasis_gridname, iim_glo, jjm_glo, area_glo)
482     !
483     CALL oasis_terminate_grids_writing()
484     !
485     IF (model_guess == "WRF") THEN
486        oasis_gridname = "twrf"
487        !
488        CALL oasis_start_grids_writing(flag)
489        !
490        CALL oasis_write_grid(oasis_gridname, iim_glo, jjm_glo, lon_glo, lat_glo)
491        !
492        CALL oasis_write_corner(oasis_gridname, iim_glo, jjm_glo, nbseg, corners_lon, corners_lat)
493        !
494        CALL oasis_write_mask(oasis_gridname, iim_glo, jjm_glo, maskinv_glo)
495        !
496        CALL oasis_write_area(oasis_gridname, iim_glo, jjm_glo, area_glo)
497        !
498        CALL oasis_terminate_grids_writing()
499     ENDIF
500     DEALLOCATE(corners_lon, corners_lat)
501     !
502  ENDIF
503  !
504  call flush(numout)
505  !-
506  !---------------------------------------------------------------------------------------
507  !-
508  !- Declare the variables to be exchanged through OASIS
509  !-
510  !---------------------------------------------------------------------------------------
511  !-
512  CALL orchoasis_defvar(mpi_rank, kjpindex)
513  !
514  !-
515  !---------------------------------------------------------------------------------------
516  !-
517  !- Get a first set of forcing data
518  !-
519  !---------------------------------------------------------------------------------------
520  !-
521  itau = 0
522  julian = date0 + (itau+0.5)*(dt/one_day)
523  CALL ju2ymds (julian, year, month, day, sec)
524  !-
525  !---------------------------------------------------------------------------------------
526  !-
527  !- Going into the time loop
528  !-
529  !---------------------------------------------------------------------------------------
530  !-
531  !
532  DO itau=1,nbdt
533     !
534     julian = date0 + (itau-0.5)*(dt/one_day)
535     ! Needed for STOMATE but should be taken from the arguments of SECHIBA
536     in_julian = itau2date(itau, date0, dt)
537     !
538     CALL ju2ymds (julian, year, month, day, sec)
539     CALL ymds2ju (year,1,1,zero, julian0)
540     julian_diff = in_julian-julian0
541     !
542     !
543     IF ( itau == nbdt ) lrestart_write = .TRUE.
544     !
545     !---------------------------------------------------------------------------------------
546     !-
547     !- Get the variables from OASIS
548     !-
549     !---------------------------------------------------------------------------------------
550     !
551     ! OASIS get call are blocking so they need to be done once all is finsihed
552     !
553     CALL orchoasis_getvar(itau-1, dt, kjpindex, kindex - (ii_begin - 1), &
554          &                zlev_tq, zlev_uv, temp_air, qair, &
555          &                precip_rain, precip_snow, swnet, lwdown, sinang, u, v, pb, cdrag)
556     !
557     CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, temp_air, "RECEIVED Air temperature")
558     CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, qair, "RECEIVED Air humidity")
559     CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, precip_rain*one_day, "RECEIVED Rainfall")
560     CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, precip_snow*one_day, "RECEIVED Snowfall")
561     CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, swnet, "RECEIVED net solar")
562     CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, lwdown, "RECEIVED lwdown")
563     CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, u, "RECEIVED East-ward wind")
564     CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, v, "RECEIVED North-ward wind")
565     CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, pb, "RECEIVED surface pressure")
566     CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, zlev_uv, "RECEIVED UV height")
567     CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, zlev_tq, "RECEIVED TQ height")
568     CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, sinang, "RECEIVED sinang")
569     !
570     !
571     ! Adaptation of the forcing data to SECHIBA's needs
572     !
573     ! Contrary to what the documentation says, ORCHIDEE expects surface pressure in hPa.
574     pb(:) = pb(:)/100.
575     epot_air(:) = cp_air*temp_air(:)+cte_grav*zlev_tq(:)
576     ccanopy(:) = atmco2 
577     !
578     petBcoef(:) = epot_air(:)
579     peqBcoef(:) = qair(:)
580     petAcoef(:) = zero
581     peqAcoef(:) = zero
582     !
583     CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, z0, &
584          &                    "Z0 before compute", ktest)
585     !
586     ! Interpolate the wind (which is at hight zlev_uv) to the same height
587     ! as the temperature and humidity (at zlev_tq).
588     !
589     u_tq(:) = u(:)*LOG(zlev_tq(:)/z0(:))/LOG(zlev_uv(:)/z0(:))
590     v_tq(:) = v(:)*LOG(zlev_tq(:)/z0(:))/LOG(zlev_uv(:)/z0(:))
591     !
592     CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, u_tq, "USED East-ward wind")
593     !
594     IF ( itau .NE. 1 ) THEN
595        IF ( timemeasure ) THEN
596           waitget_cputime = waitget_cputime + Get_cpu_Time(timer_global)
597           waitget_walltime = waitget_walltime + Get_real_Time(timer_global)
598           CALL stop_timer(timer_global)
599           CALL start_timer(timer_global)
600        ENDIF
601     ENDIF
602     !
603     !---------------------------------------------------------------------------------------
604     !-
605     !- IF first time step : Call to SECHIBA_initialize to set-up ORCHIDEE before doing an actual call
606     !- which will provide the first fluxes.
607     !-
608     !---------------------------------------------------------------------------------------
609     !
610     itau_sechiba = itau+itau_offset
611     !
612     ! Update the calendar in xios by sending the new time step
613     CALL xios_orchidee_update_calendar(itau_sechiba)
614     !
615     IF ( itau == 1 ) THEN
616        !
617        IF ( timemeasure ) THEN
618           WRITE(numout,*) '------> CPU Time for start-up of main : ',Get_cpu_Time(timer_global)
619           WRITE(numout,*) '------> Real Time for start-up of main : ',Get_real_Time(timer_global)
620           CALL stop_timer(timer_global)
621           CALL start_timer(timer_global)
622        ENDIF
623        !
624        CALL sechiba_initialize( &
625             itau_sechiba, iim*jjm,      kjpindex,      kindex,                    &
626             lalo_loc,     contfrac,     neighbours,    resolution,  zlev_tq,       &
627             u_tq,         v_tq,         qair,          temp_air,                  &
628             petAcoef,     peqAcoef,     petBcoef,      peqBcoef,                  &
629             precip_rain,  precip_snow,  lwdown,        swnet,       swdown,       &
630             pb,           rest_id,      hist_id,       hist2_id,                   &
631             rest_id_stom, hist_id_stom, hist_id_stom_IPCC,                         &
632             coastalflow,  riverflow,    tsol_rad,      vevapp,      qsurf,        &
633             z0,           albedo,       fluxsens,      fluxlat,     emis,         &
634             temp_sol_new, cdrag)
635        CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, temp_sol_new, "Init temp_sol_new")
636        !
637        ! Use the obtained albedo to diagnose the Downward Solar
638        !
639        swdown(:) = swnet(:)/(1.-(albedo(:,1)+albedo(:,2))/2.)
640        !
641        lrestart_read = .FALSE.
642        !
643        CALL histwrite_p(hist_id, 'LandPoints',  itau+1, (/ REAL(kindex) /), kjpindex, kindex)
644        CALL histwrite_p(hist_id, 'Areas',  itau+1, area, kjpindex, kindex)
645        CALL histwrite_p(hist_id, 'Contfrac',  itau+1, contfrac, kjpindex, kindex)
646        !
647        IF ( timemeasure ) THEN
648           WRITE(numout,*) '------> CPU Time for set-up of ORCHIDEE : ',Get_cpu_Time(timer_global)
649           WRITE(numout,*) '------> Real Time for set-up of ORCHIDEE : ',Get_real_Time(timer_global)
650           CALL stop_timer(timer_global)
651           CALL start_timer(timer_global)
652        ENDIF
653        !
654     ENDIF
655     !
656     !---------------------------------------------------------------------------------------
657     !-
658     !- Call to SECHIBA 
659     !-
660     !---------------------------------------------------------------------------------------
661     !
662     CALL sechiba_main (itau_sechiba, iim*jjm, kjpindex, kindex, &
663          & lrestart_read, lrestart_write, &
664          & lalo_loc, contfrac, neighbours, resolution, &
665          ! First level conditions
666          & zlev_tq, u_tq, v_tq, qair, temp_air, epot_air, ccanopy, &
667          ! Variables for the implicit coupling
668          & cdrag, petAcoef, peqAcoef, petBcoef, peqBcoef, &
669          ! Rain, snow, radiation and surface pressure
670          & precip_rain ,precip_snow, lwdown, swnet, swdown, sinang, pb, &
671          ! Output : Fluxes
672          & vevapp, fluxsens, fluxlat, coastalflow, riverflow, &
673          ! CO2 fluxes
674          & netco2, carblu, carbwh, carbha, &
675          ! Surface temperatures and surface properties
676          & tsol_rad, temp_sol_new, qsurf, albedo, emis, z0, &
677          ! Vegeation, lai and vegetation height
678          & veget, lai, height, &
679          ! File ids
680          & rest_id, hist_id, hist2_id, rest_id_stom, hist_id_stom, hist_id_stom_IPCC)
681     !
682     ! Use the obtained albedo to diagnose the Downward Solar
683     !
684     swdown(:) = swnet(:)/(1.-(albedo(:,1)+albedo(:,2))/2.)
685     !
686     CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, temp_sol_new, "Produced temp_sol_new")
687     CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, fluxsens, "Produced fluxsens")
688     CALL orchoasis_printpoint(julian, testpt(1), testpt(2), kjpindex, lalo_loc, fluxlat, "Produced fluxlat")
689     !
690     IF ( timemeasure ) THEN
691        orchidee_cputime = orchidee_cputime + Get_cpu_Time(timer_global)
692        orchidee_walltime = orchidee_walltime + Get_real_Time(timer_global)
693        CALL stop_timer(timer_global)
694        CALL start_timer(timer_global)
695     ENDIF
696     !
697     !---------------------------------------------------------------------------------------
698     ! Send the ORCHIDEE output back to the driver
699     !---------------------------------------------------------------------------------------
700     !
701     CALL orchoasis_putvar(itau, dt, kjpindex, kindex - (ii_begin - 1),&
702          &                vevapp, fluxsens, fluxlat, coastalflow, riverflow, &
703          &                netco2, carblu, tsol_rad, temp_sol_new, qsurf, albedo, emis, z0)
704     !
705     IF ( timemeasure ) THEN
706        waitput_cputime = waitput_cputime + Get_cpu_Time(timer_global)
707        waitput_walltime = waitput_walltime + Get_real_Time(timer_global)
708        CALL stop_timer(timer_global)
709        CALL start_timer(timer_global)
710     ENDIF
711     !
712     !---------------------------------------------------------------------------------------
713     !-
714     !- Write diagnostics
715     !-
716     !---------------------------------------------------------------------------------------
717     !
718     !---------------------------------------------------------------------------------------
719     !-
720     !- Write diagnostics
721     !-
722     !---------------------------------------------------------------------------------------
723     !
724     CALL xios_orchidee_send_field("LandPoints" ,(/ ( REAL(ik), ik=1,kjpindex ) /))
725     CALL xios_orchidee_send_field("Areas", area)
726     CALL xios_orchidee_send_field("Contfrac",contfrac)
727     CALL xios_orchidee_send_field("evap",vevapp*one_day/dt_sechiba)
728     CALL xios_orchidee_send_field("evap_alma",vevapp/dt_sechiba)
729     CALL xios_orchidee_send_field("coastalflow",coastalflow/dt_sechiba)
730     CALL xios_orchidee_send_field("riverflow",riverflow/dt_sechiba)
731     CALL xios_orchidee_send_field("temp_sol_C",temp_sol_new-ZeroCelsius)
732     CALL xios_orchidee_send_field("temp_sol_K",temp_sol_new)
733     CALL xios_orchidee_send_field("fluxsens",fluxsens)
734     CALL xios_orchidee_send_field("fluxlat",fluxlat)
735     CALL xios_orchidee_send_field("tair",temp_air)
736     CALL xios_orchidee_send_field("qair",qair)
737     CALL xios_orchidee_send_field("swnet",swnet)
738     CALL xios_orchidee_send_field("swdown",swdown)
739     ! zpb in hPa, output in Pa
740     CALL xios_orchidee_send_field("Psurf",pb*100.)
741     !
742     IF ( .NOT. almaoutput ) THEN
743        !
744        !  ORCHIDEE INPUT variables
745        !
746        CALL histwrite_p (hist_id, 'swdown',   itau_sechiba, swdown,   kjpindex, kindex)
747        CALL histwrite_p (hist_id, 'tair',     itau_sechiba, temp_air, kjpindex, kindex)
748        CALL histwrite_p (hist_id, 'qair',     itau_sechiba, qair, kjpindex, kindex)
749        CALL histwrite_p (hist_id, 'evap',     itau_sechiba, vevapp, kjpindex, kindex)
750        CALL histwrite_p (hist_id, 'coastalflow',itau_sechiba, coastalflow, kjpindex, kindex)
751        CALL histwrite_p (hist_id, 'riverflow',itau_sechiba, riverflow, kjpindex, kindex)
752        !
753        CALL histwrite_p (hist_id, 'temp_sol', itau_sechiba, temp_sol_new, kjpindex, kindex)
754        CALL histwrite_p (hist_id, 'tsol_max', itau_sechiba, temp_sol_new, kjpindex, kindex)
755        CALL histwrite_p (hist_id, 'tsol_min', itau_sechiba, temp_sol_new, kjpindex, kindex)
756        CALL histwrite_p (hist_id, 'fluxsens', itau_sechiba, fluxsens, kjpindex, kindex)
757        CALL histwrite_p (hist_id, 'fluxlat',  itau_sechiba, fluxlat,  kjpindex, kindex)
758        CALL histwrite_p (hist_id, 'swnet',    itau_sechiba, swnet,    kjpindex, kindex)
759        CALL histwrite_p (hist_id, 'alb_vis',  itau_sechiba, albedo(:,1), kjpindex, kindex)
760        CALL histwrite_p (hist_id, 'alb_nir',  itau_sechiba, albedo(:,2), kjpindex, kindex)
761        !
762        IF ( hist2_id > 0 ) THEN
763           CALL histwrite_p (hist2_id, 'swdown',   itau_sechiba, swdown, kjpindex, kindex)
764           CALL histwrite_p (hist2_id, 'tair',     itau_sechiba, temp_air, kjpindex, kindex)
765           CALL histwrite_p (hist2_id, 'qair',     itau_sechiba, qair, kjpindex, kindex)
766           !
767           CALL histwrite_p (hist2_id, 'evap',     itau_sechiba, vevapp, kjpindex, kindex)
768           CALL histwrite_p (hist2_id, 'coastalflow',itau_sechiba, coastalflow, kjpindex, kindex)
769           CALL histwrite_p (hist2_id, 'riverflow',itau_sechiba, riverflow, kjpindex, kindex)
770           !
771           CALL histwrite_p (hist2_id, 'temp_sol', itau_sechiba, temp_sol_new, kjpindex, kindex)
772           CALL histwrite_p (hist2_id, 'tsol_max', itau_sechiba, temp_sol_new, kjpindex, kindex)
773           CALL histwrite_p (hist2_id, 'tsol_min', itau_sechiba, temp_sol_new, kjpindex, kindex)
774           CALL histwrite_p (hist2_id, 'fluxsens', itau_sechiba, fluxsens, kjpindex, kindex)
775           CALL histwrite_p (hist2_id, 'fluxlat',  itau_sechiba, fluxlat,  kjpindex, kindex)
776           CALL histwrite_p (hist2_id, 'swnet',    itau_sechiba, swnet,    kjpindex, kindex)
777           !
778           CALL histwrite_p (hist2_id, 'alb_vis',  itau_sechiba, albedo(:,1), kjpindex, kindex)
779           CALL histwrite_p (hist2_id, 'alb_nir',  itau_sechiba, albedo(:,2), kjpindex, kindex)
780        ENDIF
781     ELSE
782        !
783        ! Input variables
784        !
785        CALL histwrite_p (hist_id, 'SinAng', itau_sechiba, sinang, kjpindex, kindex)
786        CALL histwrite_p (hist_id, 'LWdown', itau_sechiba, lwdown, kjpindex, kindex)
787        CALL histwrite_p (hist_id, 'SWdown', itau_sechiba, swdown, kjpindex, kindex)
788        CALL histwrite_p (hist_id, 'Tair', itau_sechiba, temp_air, kjpindex, kindex)
789        CALL histwrite_p (hist_id, 'Qair', itau_sechiba, qair, kjpindex, kindex)
790        CALL histwrite_p (hist_id, 'SurfP', itau_sechiba, pb, kjpindex, kindex)
791        CALL histwrite_p (hist_id, 'Windu', itau_sechiba, u_tq, kjpindex, kindex)
792        CALL histwrite_p (hist_id, 'Windv', itau_sechiba, v_tq, kjpindex, kindex)
793        !
794        CALL histwrite_p (hist_id, 'Evap', itau_sechiba, vevapp, kjpindex, kindex)
795        CALL histwrite_p (hist_id, 'SWnet',    itau_sechiba, swnet, kjpindex, kindex)
796        CALL histwrite_p (hist_id, 'Qh', itau_sechiba, fluxsens, kjpindex, kindex)
797        CALL histwrite_p (hist_id, 'Qle',  itau_sechiba, fluxlat, kjpindex, kindex)
798        CALL histwrite_p (hist_id, 'AvgSurfT', itau_sechiba, temp_sol_new, kjpindex, kindex)
799        CALL histwrite_p (hist_id, 'RadT', itau_sechiba, temp_sol_new, kjpindex, kindex)
800        !
801        ! There is a mess with the units passed to the coupler. To be checked with Marc
802        !
803        IF ( river_routing ) THEN
804           CALL histwrite_p (hist_id, 'CoastalFlow',itau_sechiba, coastalflow, kjpindex, kindex)
805           CALL histwrite_p (hist_id, 'RiverFlow',itau_sechiba, riverflow, kjpindex, kindex)
806        ENDIF
807        !
808        IF ( hist2_id > 0 ) THEN
809           CALL histwrite_p (hist2_id, 'Evap', itau_sechiba, vevapp, kjpindex, kindex)
810           CALL histwrite_p (hist2_id, 'SWnet',    itau_sechiba, swnet, kjpindex, kindex)
811           CALL histwrite_p (hist2_id, 'Qh', itau_sechiba, fluxsens, kjpindex, kindex)
812           CALL histwrite_p (hist2_id, 'Qle',  itau_sechiba, fluxlat, kjpindex, kindex)
813           CALL histwrite_p (hist2_id, 'AvgSurfT', itau_sechiba, temp_sol_new, kjpindex, kindex)
814           CALL histwrite_p (hist2_id, 'RadT', itau_sechiba, temp_sol_new, kjpindex, kindex)
815        ENDIF
816     ENDIF
817     !
818     !
819     !
820  ENDDO
821  !
822  !-
823  !---------------------------------------------------------------------------------------
824  !-
825  !- Get time and close IOIPSL, OASIS and MPI
826  !-
827  !---------------------------------------------------------------------------------------
828  !-
829  !
830  CALL histclo
831  IF(is_root_prc) THEN
832     CALL restclo
833     CALL getin_dump
834     !-
835     DEALLOCATE(maskinv_glo)
836     !
837  ENDIF
838  !-
839  !- Deallocate all variables and reset init flags
840  !-
841  CALL orchideeoasis_clear()
842  !
843  WRITE(numout,*) "MPI finalized"
844  !-
845  IF ( timemeasure ) THEN
846     WRITE(numout,*) '------> Total CPU Time waiting to get forcing : ',waitget_cputime
847     WRITE(numout,*) '------> Total Real Time waiting to get forcing : ',waitget_walltime
848     WRITE(numout,*) '------> Total CPU Time for ORCHIDEE : ', orchidee_cputime
849     WRITE(numout,*) '------> Total Real Time for ORCHIDEE : ', orchidee_walltime
850     WRITE(numout,*) '------> Total CPU Time waiting to put fluxes : ',waitput_cputime
851     WRITE(numout,*) '------> Total Real Time waiting to put fluxes : ',waitput_walltime
852     WRITE(numout,*) '------> Total without MPI : CPU Time  : ', Get_cpu_Time(timer_mpi)
853     WRITE(numout,*) '------> Total without MPI : Real Time : ', Get_real_Time(timer_mpi)
854     CALL stop_timer(timer_global)
855     CALL stop_timer(timer_mpi)
856  ENDIF
857  !-
858  CALL oasis_terminate(ierror)
859  !
860  WRITE(numout,*) "OASIS terminated"
861  !-
862  !-
863CONTAINS
864 
865!! ================================================================================================================================
866!! SUBROUTINE   : orchideeoasis_clear
867!!
868!>\BRIEF         Clear orchideeoasis
869!!
870!! DESCRIPTION  :  Deallocate memory and reset initialization variables to there original values
871!!
872!_ ================================================================================================================================
873
874  SUBROUTINE orchideeoasis_clear
875
876    !- Deallocate all variables existing on all procs (list still incomplete)
877
878    IF ( ALLOCATED(lon_glo) ) DEALLOCATE(lon_glo)
879    IF ( ALLOCATED(lat_glo) ) DEALLOCATE(lat_glo)
880    IF ( ALLOCATED(mask_glo) ) DEALLOCATE(mask_glo)
881    IF ( ALLOCATED(area_glo) ) DEALLOCATE(area_glo)
882    IF ( ALLOCATED(corners_glo) ) DEALLOCATE(corners_glo)
883    IF ( ALLOCATED(kindex_g) ) DEALLOCATE(kindex_g)
884    IF ( ALLOCATED(contfrac_glo) ) DEALLOCATE(contfrac_glo)
885    IF ( ALLOCATED(lalo_glo) ) DEALLOCATE(lalo_glo)
886    IF ( ALLOCATED(lon) ) DEALLOCATE(lon)
887    IF ( ALLOCATED(lat) ) DEALLOCATE(lat)
888    IF ( ALLOCATED(kindex) ) DEALLOCATE(kindex)
889    IF ( ALLOCATED(lalo_loc) ) DEALLOCATE(lalo_loc)
890    IF ( ALLOCATED(zlev_tq) ) DEALLOCATE(zlev_tq)
891    IF ( ALLOCATED(zlev_uv) ) DEALLOCATE(zlev_uv)
892    IF ( ALLOCATED(u) ) DEALLOCATE(u)
893    IF ( ALLOCATED(v) ) DEALLOCATE(v)
894    IF ( ALLOCATED(pb) ) DEALLOCATE(pb)
895    IF ( ALLOCATED(temp_air) ) DEALLOCATE(temp_air)
896    IF ( ALLOCATED(qair) ) DEALLOCATE(qair)
897    IF ( ALLOCATED(precip_rain) ) DEALLOCATE(precip_rain)
898    IF ( ALLOCATED(precip_snow) ) DEALLOCATE(precip_snow)
899    IF ( ALLOCATED(swdown) ) DEALLOCATE(swdown)
900    IF ( ALLOCATED(swnet) ) DEALLOCATE(swnet)
901    IF ( ALLOCATED(lwdown) ) DEALLOCATE(lwdown)
902    IF ( ALLOCATED(sinang) ) DEALLOCATE(sinang)
903    IF ( ALLOCATED(epot_air) ) DEALLOCATE(epot_air)
904    IF ( ALLOCATED(ccanopy) ) DEALLOCATE(ccanopy)
905    IF ( ALLOCATED(cdrag) ) DEALLOCATE(cdrag)
906    IF ( ALLOCATED(swnet) ) DEALLOCATE(swnet)
907    IF ( ALLOCATED(petAcoef) ) DEALLOCATE(petAcoef)
908    IF ( ALLOCATED(peqAcoef) ) DEALLOCATE(peqAcoef)
909    IF ( ALLOCATED(petBcoef) ) DEALLOCATE(petBcoef)
910    IF ( ALLOCATED(peqBcoef) ) DEALLOCATE(peqBcoef)
911    IF ( ALLOCATED(u_tq) ) DEALLOCATE(u_tq)
912    IF ( ALLOCATED(v_tq) ) DEALLOCATE(v_tq)
913    IF ( ALLOCATED(vevapp) ) DEALLOCATE(vevapp)
914    IF ( ALLOCATED(fluxsens) ) DEALLOCATE(fluxsens)
915    IF ( ALLOCATED(fluxlat) ) DEALLOCATE(fluxlat)
916    IF ( ALLOCATED(coastalflow) ) DEALLOCATE(coastalflow)
917    IF ( ALLOCATED(riverflow) ) DEALLOCATE(riverflow)
918    IF ( ALLOCATED(netco2) ) DEALLOCATE(netco2)
919    IF ( ALLOCATED(carblu) ) DEALLOCATE(carblu)
920    IF ( ALLOCATED(carbwh) ) DEALLOCATE(carbwh)
921    IF ( ALLOCATED(carbha) ) DEALLOCATE(carbha)
922    IF ( ALLOCATED(tsol_rad) ) DEALLOCATE(tsol_rad)
923    IF ( ALLOCATED(temp_sol_new) ) DEALLOCATE(temp_sol_new)
924    IF ( ALLOCATED(qsurf) ) DEALLOCATE(qsurf)
925    IF ( ALLOCATED(albedo) ) DEALLOCATE(albedo)
926    IF ( ALLOCATED(emis) ) DEALLOCATE(emis)
927    IF ( ALLOCATED(z0) ) DEALLOCATE(z0)
928
929    CALL sechiba_clear()
930    WRITE(numout,*) "Memory deallocated"
931
932  END SUBROUTINE orchideeoasis_clear
933
934END PROGRAM orchideeoasis
935
Note: See TracBrowser for help on using the repository browser.