source: branches/publications/ORCHIDEE_GLUC_r6545/src_oasisdriver/orchideeoasis.f90 @ 6737

Last change on this file since 6737 was 4719, checked in by albert.jornet, 7 years ago

Merge: from revisions [4491:4695/trunk/ORCHIDEE]

Merge done in [4671:4718/perso/albert.jornet/MICT_MERGE]

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