source: tags/ORCHIDEE_2_1/ORCHIDEE/src_oasisdriver/orchideeoasis.f90

Last change on this file was 5573, checked in by josefine.ghattas, 6 years ago

Do not use t2m/q2m coming from the atmospheric model anymore and instead use temp_air and qair from first atmpospheric model layer. t2m/q2m were previously used only in diffuco_trans_co2 and in stomate_initialize. Also removed diagnostic variables t2m and q2m. See ticket #372

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