Index: /branches/ORCHIDEE_2_2/ORCHIDEE/src_sechiba/slowproc.f90
===================================================================
--- /branches/ORCHIDEE_2_2/ORCHIDEE/src_sechiba/slowproc.f90	(revision 8578)
+++ /branches/ORCHIDEE_2_2/ORCHIDEE/src_sechiba/slowproc.f90	(revision 8579)
@@ -64,4 +64,5 @@
   REAL(r_std), SAVE                                  :: slope_default = 0.1
 !$OMP THREADPRIVATE(slope_default)
+  REAL(r_std), PARAMETER                             :: aei_sw_default = 62.2 !! Default percentage for Area Equipped for Irrigation with Surface Water (unitless). Value of 62.2% is the mean of the GMIA v5 dataset of the FAO AQUASTAT (Siebert et al., 2010) used for the construction of the AEI_SW_pct.nc
   INTEGER, SAVE                                      :: printlev_loc        !! Local printlev in slowproc module
 !$OMP THREADPRIVATE(printlev_loc)
@@ -271,4 +272,51 @@
        CALL xios_orchidee_set_field_attr("woodharvest_interp",enabled=.FALSE.)
     ENDIF
+    
+    !! 6. Prepare for reading of irrigmap file
+    filename = 'IRRIGmap.nc'
+    CALL getin_p('IRRIGmap_FILE',filename)
+    name = filename(1:LEN_TRIM(FILENAME)-3)
+    CALL xios_orchidee_set_file_attr("irrigmap_file",name=name)
+    
+    IF (xios_interpolation .AND. do_irrigation .AND. &
+        irrig_map_dynamic_flag) THEN
+       ! IRRIGmap file will be read each year
+
+       ! Reading will be done
+       IF (printlev>=2) WRITE(numout,*) 'Reading of irrigmap file will be done later using XIOS. The filename is ', filename
+    ELSEIF (xios_interpolation .AND. do_irrigation .AND. &
+            restname_in=='NONE') THEN
+       ! IRRIGmap file will be read only once if no restart file exists
+
+       ! Reading will be done
+       IF (printlev>=2) WRITE(numout,*) 'Reading of irrigmap file will be done later using XIOS. The filename is ', filename
+    ELSE
+       ! No reading, deactivate irrigmap file
+       IF (printlev>=2) WRITE(numout,*) 'Reading of irrigmap file will not be done with XIOS.'
+       CALL xios_orchidee_set_file_attr("irrigmap_file",enabled=.FALSE.)
+       CALL xios_orchidee_set_field_attr("irrigmap_interp",enabled=.FALSE.)
+    ENDIF
+    
+    !! 7. Prepare for reading of aei_sw file
+    filename = 'AEI_SW_pct.nc'
+    CALL getin_p('AEI_SW_FILE',filename)
+    name = filename(1:LEN_TRIM(FILENAME)-3)
+    CALL xios_orchidee_set_file_attr("aei_sw_file",name=name)
+    
+    ! Set default values used by XIOS for the interpolation
+    lerr=xios_orchidee_setvar('aei_sw_default',aei_sw_default)
+    
+    IF (xios_interpolation .AND. do_irrigation .AND. &
+        select_source_irrig .AND. restname_in=='NONE') THEN
+       ! AEI_SW file will be read if no restart file exists
+
+       ! Reading will be done
+       IF (printlev>=2) WRITE(numout,*) 'Reading of aei_sw file will be done later using XIOS. The filename is ', filename
+    ELSE
+       ! No reading, deactivate aei_sw file
+       IF (printlev>=2) WRITE(numout,*) 'Reading of aei_sw file will not be done with XIOS.'
+       CALL xios_orchidee_set_file_attr("aei_sw_file",enabled=.FALSE.)
+       CALL xios_orchidee_set_field_attr("aei_sw_interp",enabled=.FALSE.)
+    ENDIF
 
     !! This part was introduced to prepare the reading of params_sp_mip.nc if spmipexp='maps'
@@ -278,5 +326,5 @@
     !! The corresponding part in context_input_orchidee.xml is also commented
     
-!!$    !! 6. Prepare for reading of soil parameter files
+!!$    !! 8. Prepare for reading of soil parameter files
 !!$
 !!$    ! Get the file name from run.def file and set file attributes accordingly
@@ -4727,5 +4775,5 @@
     ! for irrigated_new case :
 
-    REAL(r_std), DIMENSION(nbpt)                     :: irrigref_frac    !! irrigation fractions re-dimensioned
+    REAL(r_std), DIMENSION(nbpt)                         :: irrigref_frac    !! irrigation fractions re-dimensioned
     REAL(r_std), DIMENSION(nbpt)                         :: airrig           !! Availability of the soilcol interpolation
     REAL(r_std)                          :: vmin, vmax       !! min/max values to use for the renormalization
@@ -4756,5 +4804,5 @@
   !_ ================================================================================================================================
 
-    IF (printlev_loc >= 5) PRINT *,'  In slowproc_read irrigmap_new'
+    IF (printlev_loc >= 5) PRINT *,'  In slowproc_readirrigmap_dyn'
 
     !
@@ -4771,38 +4819,54 @@
     variablename = 'irrig'
 
-    IF (printlev_loc >= 1) WRITE(numout,*) "slowproc_read irrigmap_new: Read and interpolate " &
-         // TRIM(filename) // " for variable " // TRIM(variablename)
-
-    ! Assigning values to vmin, vmax
-    vmin = 1.
-    vmax = 1.
-
-    variabletypevals = -un
-
-    !! Variables for interpweight
-    ! Type of calculation of cell fractions
-    fractype = 'default'
-    ! Name of the longitude and latitude in the input file
-    lonname = 'lon'
-    latname = 'lat'
-    ! Should negative values be set to zero from input file?
-    nonegative = .TRUE.
-    ! Type of mask to apply to the input data (see header for more details)
-    maskingtype = 'nomask'
-    ! Values to use for the masking
-    maskvals = (/ 0.05, 0.05 , un /)
-    ! Name of the variable with the values for the mask in the input file (only if maskkingtype='var') (here not used)
-    namemaskvar = ''
-
-    CALL interpweight_2Dcont(nbpt, 0, 0, lalo, resolution, neighbours,        &
-      contfrac, filename, variablename, lonname, latname, vmin, vmax, nonegative, maskingtype,        &
-      maskvals, namemaskvar, -1, fractype, 0., 0.,                                 &
-      irrigref_frac, airrig)
-
-    IF (printlev_loc >= 5) WRITE(numout,*)'  slowproc_read after interpweight_2Dcont'
+    IF (xios_interpolation) THEN
+       IF (printlev_loc >= 1) WRITE(numout,*) "slowproc_readirrigmap_dyn: Use XIOS to read and interpolate " &
+            // TRIM(filename) // " for variable " // TRIM(variablename)
+
+       CALL xios_orchidee_recv_field('irrigmap_interp',irrigref_frac)
+
+       airrig = 1.0
+    ELSE
+
+       IF (printlev_loc >= 1) WRITE(numout,*) "slowproc_readirrigmap_dyn: Read and interpolate " &
+            // TRIM(filename) // " for variable " // TRIM(variablename)
+
+       ! Assigning values to vmin, vmax
+       vmin = 1.
+       vmax = 1.
+
+       variabletypevals = -un
+
+       !! Variables for interpweight
+       ! Type of calculation of cell fractions
+       fractype = 'default'
+       ! Name of the longitude and latitude in the input file
+       lonname = 'lon'
+       latname = 'lat'
+       ! Should negative values be set to zero from input file?
+       nonegative = .TRUE.
+       ! Type of mask to apply to the input data (see header for more details)
+       maskingtype = 'nomask'
+       ! Values to use for the masking
+       maskvals = (/ 0.05, 0.05 , un /)
+       ! Name of the variable with the values for the mask in the input file (only if maskkingtype='var') (here not used)
+       namemaskvar = ''
+
+       CALL interpweight_2Dcont(nbpt, 0, 0, lalo, resolution, neighbours,        &
+	 contfrac, filename, variablename, lonname, latname, vmin, vmax, nonegative, maskingtype,        &
+	 maskvals, namemaskvar, -1, fractype, 0., 0.,                                 &
+	 irrigref_frac, airrig)
+
+       IF (printlev_loc >= 5) WRITE(numout,*)'  slowproc_readirrigmap_dyn after interpweight_2Dcont'
+
+    ENDIF
+    
+    ! Write diagnostics
+    CALL xios_orchidee_send_field("interp_diag_irrigmap_frac",irrigref_frac)
 
     IF (printlev_loc >= 5) THEN
-      WRITE(numout,*)'  slowproc_read irrigmap_new before updating loop nbpt:', nbpt
+      WRITE(numout,*)'  slowproc_readirrigmap_dyn before updating loop nbpt:', nbpt
     END IF
+    
+    ! Transform form percentage (irrigref_frac) to area (irrigmap_new)
     irrigmap_new(:) = zero
     irrigref_frac(:) = irrigref_frac(:)/100.
@@ -4810,8 +4874,8 @@
     DO ib=1,nbpt
       IF (irrigref_frac(ib) < 1. .AND. irrigref_frac(ib) > 0.005 ) THEN
-        irrigmap_new(ib) = irrigref_frac(ib) * resolution(ib,1)*resolution(ib,2)*contfrac(ib)
+        irrigmap_new(ib) = irrigref_frac(ib) * area(ib) * contfrac(ib)
       ELSEIF (irrigref_frac(ib) > 1.) THEN
-        irrigmap_new(ib) = resolution(ib,1)*resolution(ib,2)*contfrac(ib)
-      !ELSE  THEN irrigated_new= zero. ALready set, put to lisibility
+        irrigmap_new(ib) = area(ib)*contfrac(ib)
+      !ELSE  THEN irrigated_new= zero. Already set, put to lisibility
       ENDIF
     ENDDO
@@ -4820,5 +4884,5 @@
     !CALL xios_orchidee_send_field("airrig",airrig)
 
-    IF (printlev_loc >= 3) WRITE(numout,*) '  slowproc_read irrigmap_new ended'
+    IF (printlev_loc >= 3) WRITE(numout,*) '  slowproc_readirrigmap_dyn ended'
 
   END SUBROUTINE slowproc_readirrigmap_dyn
@@ -4872,5 +4936,5 @@
     ! for irrigated_new case :
 
-    REAL(r_std), DIMENSION(nbpt)                     :: irrigref_frac    !! irrigation fractions re-dimensioned
+    REAL(r_std), DIMENSION(nbpt)                         :: irrigref_frac    !! irrigation fractions re-dimensioned (0-100, percentage)
     REAL(r_std), DIMENSION(nbpt)                         :: airrig           !! Availability of the soilcol interpolation
     REAL(r_std)                          :: vmin, vmax       !! min/max values to use for the renormalization
@@ -4901,5 +4965,5 @@
   !_ ================================================================================================================================
 
-    IF (printlev_loc >= 5) PRINT *,'  In slowproc_read irrigmap_new'
+    IF (printlev_loc >= 5) PRINT *,'  In slowproc_read_aeisw_map'
 
     !
@@ -4916,34 +4980,48 @@
     variablename = 'aeisw_pct'
 
-    IF (printlev_loc >= 1) WRITE(numout,*) "slowproc_read_aeisw_map: Read and interpolate " &
-         // TRIM(filename) // " for variable " // TRIM(variablename)
-
-    ! Assigning values to vmin, vmax
-    vmin = 1.
-    vmax = 1.
-
-    variabletypevals = -un
-
-    !! Variables for interpweight
-    ! Type of calculation of cell fractions
-    fractype = 'default'
-    ! Name of the longitude and latitude in the input file
-    lonname = 'lon'
-    latname = 'lat'
-    ! Should negative values be set to zero from input file?
-    nonegative = .TRUE.
-    ! Type of mask to apply to the input data (see header for more details)
-    maskingtype = 'mabove'
-    ! Values to use for the masking
-    maskvals = (/ 0.05, 0.05 , un /)
-    ! Name of the variable with the values for the mask in the input file (only if maskkingtype='var') (here not used)
-    namemaskvar = ''
-
-    CALL interpweight_2Dcont(nbpt, 0, 0, lalo, resolution, neighbours,        &
-      contfrac, filename, variablename, lonname, latname, vmin, vmax, nonegative, maskingtype,        &
-      maskvals, namemaskvar, -1, fractype, 0., 0.,                                 &
-      irrigref_frac, airrig)
-
-    IF (printlev_loc >= 5) WRITE(numout,*)'  slowproc_read after interpweight_2Dcont'
+    IF (xios_interpolation) THEN
+       IF (printlev_loc >= 1) WRITE(numout,*) "slowproc_read_aeisw_map: Use XIOS to read and interpolate " &
+            // TRIM(filename) // " for variable " // TRIM(variablename)
+
+       CALL xios_orchidee_recv_field('aei_sw_interp',irrigref_frac)
+
+       airrig = 1.0
+    ELSE
+
+       IF (printlev_loc >= 1) WRITE(numout,*) "slowproc_read_aeisw_map: Read and interpolate " &
+            // TRIM(filename) // " for variable " // TRIM(variablename)
+
+       ! Assigning values to vmin, vmax
+       vmin = 1.
+       vmax = 1.
+
+       variabletypevals = -un
+
+       !! Variables for interpweight
+       ! Type of calculation of cell fractions
+       fractype = 'default'
+       ! Name of the longitude and latitude in the input file
+       lonname = 'lon'
+       latname = 'lat'
+       ! Should negative values be set to zero from input file?
+       nonegative = .TRUE.
+       ! Type of mask to apply to the input data (see header for more details)
+       maskingtype = 'mabove'
+       ! Values to use for the masking
+       maskvals = (/ 0.05, 0.05 , un /)
+       ! Name of the variable with the values for the mask in the input file (only if maskkingtype='var') (here not used)
+       namemaskvar = ''
+
+       CALL interpweight_2Dcont(nbpt, 0, 0, lalo, resolution, neighbours,        &
+	 contfrac, filename, variablename, lonname, latname, vmin, vmax, nonegative, maskingtype,        &
+	 maskvals, namemaskvar, -1, fractype, aei_sw_default, aei_sw_default,                                 &
+	 irrigref_frac, airrig)
+
+       IF (printlev_loc >= 5) WRITE(numout,*)'  slowproc_read_aeisw_map after interpweight_2Dcont'
+       
+    END IF
+    
+    ! Write diagnostics
+    CALL xios_orchidee_send_field("interp_diag_aeiswmap_frac",irrigref_frac) ! irrigref_frac here has a different meaning than in subroutine slowproc_readirrigmap_dyn
 
     IF (printlev_loc >= 5) THEN
Index: /branches/ORCHIDEE_2_2/ORCHIDEE/src_xml/context_input_orchidee.xml
===================================================================
--- /branches/ORCHIDEE_2_2/ORCHIDEE/src_xml/context_input_orchidee.xml	(revision 8578)
+++ /branches/ORCHIDEE_2_2/ORCHIDEE/src_xml/context_input_orchidee.xml	(revision 8579)
@@ -89,4 +89,12 @@
     <file id="woodharvest_file" mode="read" output_freq="1y" cyclic="true">
       <field id="woodharvest_read"  name="woodharvest" domain_ref="dom_file_woodharvest" operation="instant"  freq_offset="1ts"/>
+    </file>
+    
+    <file id="irrigmap_file" mode="read" output_freq="1y" cyclic="true">
+      <field id="irrigmap_read"  name="irrig" domain_ref="dom_file_irrigmap" operation="instant"  freq_offset="1ts" > (this &gt; 101) ? $missing_value : this </field>
+    </file>
+    
+    <file id="aei_sw_file" mode="read" output_freq="1y" cyclic="true">
+      <field id="aei_sw_read"  name="aeisw_pct" domain_ref="dom_file_aei_sw" operation="instant"  freq_offset="1ts" > (this &gt; 101) ? $missing_value : this </field>
     </file>
     
@@ -176,4 +184,10 @@
 
       <field id="woodharvest_interp"  field_ref="woodharvest_read"  domain_ref="dom_from_woodharvest" read_access="true" enabled="true" />
+
+      <field id="irrigmap_tmp"   field_ref="irrigmap_read"  domain_ref="dom_from_irrigmap"  />
+      <field id="irrigmap_interp"  field_ref="irrigmap_tmp" read_access="true" enabled="true" > this == $missing_value ? 0 : this </field>
+
+      <field id="aei_sw_tmp"   field_ref="aei_sw_read"  domain_ref="dom_from_aei_sw"  />
+      <field id="aei_sw_interp"  field_ref="aei_sw_tmp" read_access="true" enabled="true" > this == $missing_value ? $aei_sw_default : this </field>
       
     </field_group>
@@ -275,4 +289,12 @@
     </domain>
     
+    <domain id="dom_from_irrigmap" domain_ref="domain_landpoints">
+      <interpolate_domain order="1" renormalize="true" detect_missing_value="true" />
+    </domain>
+    
+    <domain id="dom_from_aei_sw" domain_ref="domain_landpoints">
+      <interpolate_domain order="1" renormalize="true" detect_missing_value="true" />
+    </domain>
+    
     <domain id="dom_file_soil" type="rectilinear">
       <!-- generate_rectilinear_domain bounds_lon_start="-180" bounds_lon_end="180" bounds_lat_start="-90" bounds_lat_end="90"/-->
@@ -313,4 +335,12 @@
 
     <domain id="dom_file_woodharvest" type="rectilinear">
+      <generate_rectilinear_domain/>
+    </domain>
+
+    <domain id="dom_file_irrigmap" type="rectilinear">
+      <generate_rectilinear_domain/>
+    </domain>
+
+    <domain id="dom_file_aei_sw" type="rectilinear">
       <generate_rectilinear_domain/>
     </domain>
@@ -371,4 +401,5 @@
     <variable id="albbg_nir_default" type="double">xxx</variable>
     <variable id="bulk_default" type="double">xxx</variable>
+    <variable id="aei_sw_default" type="double">xxx</variable>
     
   </variable_definition>
Index: /branches/ORCHIDEE_2_2/ORCHIDEE/src_xml/field_def_orchidee.xml
===================================================================
--- /branches/ORCHIDEE_2_2/ORCHIDEE/src_xml/field_def_orchidee.xml	(revision 8578)
+++ /branches/ORCHIDEE_2_2/ORCHIDEE/src_xml/field_def_orchidee.xml	(revision 8579)
@@ -391,4 +391,6 @@
     <field id="interp_avail_areftemp" name="interp_avail_areftemp" long_name="Availability of data for the reftemp interpolation (negative values if no data found)" unit="1" operation="once" freq_offset="0ts"/>
     <field id="interp_diag_woodharvest" name="interp_diag_woodharvest" long_name="woodharvest read from file" operation="once" freq_offset="0ts"/>
+    <field id="interp_diag_irrigmap_frac" name="interp_diag_irrigmap_frac" long_name="irrigmap_frac read from file" unit="%" operation="once" freq_offset="0ts"/>
+    <field id="interp_diag_aeiswmap_frac" name="interp_diag_aeiswmap_frac" long_name="aeiswmap_frac read from file" unit="%" operation="once" freq_offset="0ts"/>
 
 
Index: /branches/ORCHIDEE_2_2/ORCHIDEE/src_xml/file_def_orchidee.xml
===================================================================
--- /branches/ORCHIDEE_2_2/ORCHIDEE/src_xml/file_def_orchidee.xml	(revision 8578)
+++ /branches/ORCHIDEE_2_2/ORCHIDEE/src_xml/file_def_orchidee.xml	(revision 8579)
@@ -755,4 +755,6 @@
       <field field_ref="interp_diag_reftemp" level="1"/>
       <field field_ref="interp_diag_woodharvest" level="1"/>
+      <field field_ref="interp_diag_irrigmap_frac" level="1"/>
+      <field field_ref="interp_diag_aeiswmap_frac" level="1"/>
       <!--      <field field_ref="interp_diag_lai" grid_ref="grid_from_lai" level="1"/> -->
       
