Index: XIOS/trunk/doc/XIOS_reference_guide.lyx
===================================================================
--- XIOS/trunk/doc/XIOS_reference_guide.lyx	(revision 1181)
+++ XIOS/trunk/doc/XIOS_reference_guide.lyx	(revision 1182)
@@ -3437,4 +3437,36 @@
 
 \begin_layout Subsection*
+check_if_active: 
+\emph on
+bool
+\end_layout
+
+\begin_layout Standard
+Fortran:
+\end_layout
+
+\begin_layout LyX-Code
+LOGICAL :: check_if_active
+\end_layout
+
+\begin_layout Standard
+Define whether XIOS will automatically check if the field is active at current
+ timestep when sending data from the model.
+ Enabling this behavior can sometimes improve the performances by avoiding
+ unneeded data processing.
+ This attribute is optional, the default value is 
+\begin_inset Flex Strong
+status collapsed
+
+\begin_layout Plain Layout
+false
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Subsection*
 field_ref: 
 \emph on
Index: XIOS/trunk/doc/XIOS_user_guide.lyx
===================================================================
--- XIOS/trunk/doc/XIOS_user_guide.lyx	(revision 1181)
+++ XIOS/trunk/doc/XIOS_user_guide.lyx	(revision 1182)
@@ -188,5 +188,5 @@
 \begin_layout Plain Layout
 
-! Context initialization ommited, see the corresponding section of this
+! Context initialization omitted, see the corresponding section of this
  user manual and of the reference manual
 \end_layout
@@ -293,5 +293,5 @@
 \begin_layout Plain Layout
 
-! Context initialization ommited, see the corresponding section of this
+! Context initialization omitted, see the corresponding section of this
  user manual and of the reference manual
 \end_layout
@@ -476,5 +476,5 @@
 \begin_layout Plain Layout
 
-! Context initialization ommited, see the corresponding section of this
+! Context initialization omitted, see the corresponding section of this
  user manual and of the reference manual
 \end_layout
@@ -524,5 +524,5 @@
 \begin_layout Plain Layout
 
-! Context initialization ommited, see the corresponding section of this
+! Context initialization omitted, see the corresponding section of this
  user manual and of the reference manual
 \end_layout
@@ -788,5 +788,5 @@
 \begin_layout Plain Layout
 
-! Context initialization ommited, see the corresponding section of this
+! Context initialization omitted, see the corresponding section of this
  user manual and of the reference manual
 \end_layout
@@ -1330,5 +1330,5 @@
 \begin_layout Plain Layout
 
-        		<!-- Content of the file ommited for now -->
+        		<!-- Content of the file omitted for now -->
 \end_layout
 
@@ -1428,5 +1428,5 @@
 \begin_layout Plain Layout
 
-! Context and calendar initializations ommited, see the corresponding section
+! Context and calendar initializations omitted, see the corresponding section
  of this user manual and of the reference manual
 \end_layout
@@ -1953,5 +1953,5 @@
 \begin_layout Plain Layout
 
-        		<!-- Content of the file ommited for now -->
+        		<!-- Content of the file omitted for now -->
 \end_layout
 
@@ -2195,5 +2195,5 @@
 \begin_layout Plain Layout
 
-			<grid id="grid_A"><!-- Definition ommited --></grid>
+			<grid id="grid_A"><!-- Definition omitted --></grid>
 \end_layout
 
@@ -2457,5 +2457,5 @@
 \begin_layout Plain Layout
 
-! Context, calendar and grid initializations ommited, see the corresponding
+! Context, calendar and grid initializations omitted, see the corresponding
  section of this user manual and of the reference manual
 \end_layout
@@ -2736,5 +2736,5 @@
 \begin_layout Plain Layout
 
-			<grid id="grid_A"><!-- Definition ommited --></grid>
+			<grid id="grid_A"><!-- Definition omitted --></grid>
 \end_layout
 
@@ -3199,5 +3199,5 @@
 \begin_layout Plain Layout
 
-			<grid id="grid_A"><!-- Definition ommited --></grid>
+			<grid id="grid_A"><!-- Definition omitted --></grid>
 \end_layout
 
@@ -3309,5 +3309,5 @@
 \begin_layout Plain Layout
 
-			<grid id="grid_A"><!-- Definition ommited --></grid>
+			<grid id="grid_A"><!-- Definition omitted --></grid>
 \end_layout
 
@@ -3460,5 +3460,5 @@
 \begin_layout Plain Layout
 
-			<grid id="grid_A"><!-- Definition ommited --></grid>
+			<grid id="grid_A"><!-- Definition omitted --></grid>
 \end_layout
 
@@ -3609,5 +3609,5 @@
 \begin_layout Plain Layout
 
-			<grid id="grid_A"><!-- Definition ommited --></grid>
+			<grid id="grid_A"><!-- Definition omitted --></grid>
 \end_layout
 
@@ -3801,5 +3801,5 @@
 \begin_layout Plain Layout
 
-			<grid id="grid_A"><!-- Definition ommited --></grid>
+			<grid id="grid_A"><!-- Definition omitted --></grid>
 \end_layout
 
@@ -3942,5 +3942,5 @@
 \begin_layout Plain Layout
 
-			<grid id="grid_A"><!-- Definition ommited --></grid>
+			<grid id="grid_A"><!-- Definition omitted --></grid>
 \end_layout
 
@@ -4082,5 +4082,5 @@
 \begin_layout Plain Layout
 
-			<grid id="grid_A"><!-- Definition ommited --></grid>
+			<grid id="grid_A"><!-- Definition omitted --></grid>
 \end_layout
 
@@ -4278,5 +4278,5 @@
 \begin_layout Plain Layout
 
-			<grid id="grid_A"><!-- Definition ommited --></grid>
+			<grid id="grid_A"><!-- Definition omitted --></grid>
 \end_layout
 
@@ -4457,5 +4457,5 @@
 \begin_layout Plain Layout
 
-			<grid id="grid_A"><!-- Definition ommited --></grid>
+			<grid id="grid_A"><!-- Definition omitted --></grid>
 \end_layout
 
@@ -4564,4 +4564,470 @@
 , the requested data will never be available and a deadlock could occur.
  In practice, XIOS will detect the problem and throw an error.
+\end_layout
+
+\begin_layout Section
+How to check whether a field is active or not
+\end_layout
+
+\begin_layout Standard
+Since XIOS allows modifying the output and input files at runtime, it is
+ sometimes useful to be able to dynamically query whether a field is active
+ or not from the model (for example to avoid computing a field that would
+ not be used anyway for the current run).
+\begin_inset Newline newline
+\end_inset
+
+
+\begin_inset Newline newline
+\end_inset
+
+This can be done using the 
+\begin_inset Flex Code
+status open
+
+\begin_layout Plain Layout
+xios_field_is_active
+\end_layout
+
+\end_inset
+
+ function.
+ The following code sample shows how this function could be used in a model:
+\end_layout
+
+\begin_layout Standard
+\begin_inset listings
+lstparams "language=Fortran,breaklines=true,tabsize=2,frame=tb,postbreak={\raisebox{0ex}[0ex][0ex]{\ensuremath{\rcurvearrowse\space}}}"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+IF (xios_field_is_active("field_A")) THEN
+\end_layout
+
+\begin_layout Plain Layout
+
+	! Computation of field_A
+\end_layout
+
+\begin_layout Plain Layout
+
+	! ...
+\end_layout
+
+\begin_layout Plain Layout
+
+\end_layout
+
+\begin_layout Plain Layout
+
+	CALL xios_send_field("field_A", field_A)
+\end_layout
+
+\begin_layout Plain Layout
+
+ENDIF
+\end_layout
+
+\end_inset
+
+Note that this function takes into account the possible data dependencies
+ that can exist between fields.
+ That is, a field will be considered active if it used to compute another
+ active field even if it is not directly used in any files.
+\begin_inset Newline newline
+\end_inset
+
+
+\begin_inset Newline newline
+\end_inset
+
+The 
+\begin_inset Flex Code
+status open
+
+\begin_layout Plain Layout
+xios_field_is_active
+\end_layout
+
+\end_inset
+
+ function accepts an optional boolean argument 
+\begin_inset Flex Code
+status open
+
+\begin_layout Plain Layout
+at_current_timestep
+\end_layout
+
+\end_inset
+
+ which defaults to 
+\series bold
+false
+\series default
+ if omitted.
+ Setting it to 
+\series bold
+true
+\series default
+ allows checking if an input field is active at the current timestep, taking
+ into account the data sampling and temporal operations.
+\begin_inset Newline newline
+\end_inset
+
+
+\begin_inset Newline newline
+\end_inset
+
+Considering the following configuration file:
+\begin_inset listings
+lstparams "language=XML,breaklines=true,tabsize=2,frame=tb,postbreak={\raisebox{0ex}[0ex][0ex]{\ensuremath{\rcurvearrowse\space}}}"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+<?xml version="1.0"?>
+\end_layout
+
+\begin_layout Plain Layout
+
+<simulation>
+\end_layout
+
+\begin_layout Plain Layout
+
+	<context id="test">
+\end_layout
+
+\begin_layout Plain Layout
+
+		<calendar type="Gregorian" timestep="1h" />
+\end_layout
+
+\begin_layout Plain Layout
+
+\end_layout
+
+\begin_layout Plain Layout
+
+		<grid_definition>
+\end_layout
+
+\begin_layout Plain Layout
+
+			<grid id="grid_A"><!-- Definition omitted --></grid>
+\end_layout
+
+\begin_layout Plain Layout
+
+		</grid_definition>
+\end_layout
+
+\begin_layout Plain Layout
+
+\end_layout
+
+\begin_layout Plain Layout
+
+		<field_definition>
+\end_layout
+
+\begin_layout Plain Layout
+
+        	<field id="field_A" grid_ref="grid_A" operation="instant" />
+\end_layout
+
+\begin_layout Plain Layout
+
+        	<field id="field_B" grid_ref="grid_A" operation="instant" />
+\end_layout
+
+\begin_layout Plain Layout
+
+        	<field id="field_C" grid_ref="grid_A" operation="instant">field_A
+ + field_B</field>
+\end_layout
+
+\begin_layout Plain Layout
+
+		</field_definition>
+\end_layout
+
+\begin_layout Plain Layout
+
+\end_layout
+
+\begin_layout Plain Layout
+
+		<file_definition>
+\end_layout
+
+\begin_layout Plain Layout
+
+			<file name="output" output_freq="10ts">
+\end_layout
+
+\begin_layout Plain Layout
+
+        		<field field_ref="field_C" />
+\end_layout
+
+\begin_layout Plain Layout
+
+			</file>
+\end_layout
+
+\begin_layout Plain Layout
+
+		</file_definition>
+\end_layout
+
+\begin_layout Plain Layout
+
+	</context>
+\end_layout
+
+\begin_layout Plain Layout
+
+</simulation>
+\end_layout
+
+\end_inset
+
+With this configuration file, calling 
+\begin_inset Flex Code
+status open
+
+\begin_layout Plain Layout
+xios_field_is_active(
+\begin_inset Quotes eld
+\end_inset
+
+field_A
+\begin_inset Quotes erd
+\end_inset
+
+)
+\end_layout
+
+\end_inset
+
+ or
+\begin_inset Newline newline
+\end_inset
+
+
+\begin_inset Flex Code
+status open
+
+\begin_layout Plain Layout
+xios_field_is_active(
+\begin_inset Quotes eld
+\end_inset
+
+field_B
+\begin_inset Quotes erd
+\end_inset
+
+)
+\end_layout
+
+\end_inset
+
+ always returns 
+\series bold
+true
+\series default
+ because 
+\begin_inset Quotes eld
+\end_inset
+
+field_A
+\begin_inset Quotes erd
+\end_inset
+
+ and 
+\begin_inset Quotes eld
+\end_inset
+
+field_B
+\begin_inset Quotes erd
+\end_inset
+
+ are needed to compute 
+\begin_inset Quotes eld
+\end_inset
+
+field_C
+\begin_inset Quotes erd
+\end_inset
+
+ which is outputted.
+ Since 
+\begin_inset Quotes eld
+\end_inset
+
+field_C
+\begin_inset Quotes erd
+\end_inset
+
+ is outputted every 10 timesteps, setting the 
+\begin_inset Flex Code
+status open
+
+\begin_layout Plain Layout
+at_current_timestep
+\end_layout
+
+\end_inset
+
+ argument to 
+\series bold
+true
+\series default
+ would make a difference.
+ Calling 
+\begin_inset Flex Code
+status open
+
+\begin_layout Plain Layout
+xios_field_is_active(
+\begin_inset Quotes eld
+\end_inset
+
+field_A
+\begin_inset Quotes erd
+\end_inset
+
+, .true.)
+\end_layout
+
+\end_inset
+
+ would return 
+\series bold
+true
+\series default
+ only every 10 timesteps as there is no need to provide 
+\begin_inset Quotes eld
+\end_inset
+
+field_A
+\begin_inset Quotes erd
+\end_inset
+
+ (respectively 
+\begin_inset Quotes eld
+\end_inset
+
+field_B
+\begin_inset Quotes erd
+\end_inset
+
+) at timesteps for which 
+\begin_inset Quotes eld
+\end_inset
+
+field_C
+\begin_inset Quotes erd
+\end_inset
+
+ is not written to file.
+\begin_inset Newline newline
+\end_inset
+
+
+\begin_inset Newline newline
+\end_inset
+
+Additionally, it possible to set the field attribute 
+\series bold
+check_if_active
+\series default
+ to 
+\begin_inset Quotes eld
+\end_inset
+
+
+\series bold
+\emph on
+true
+\series default
+\emph default
+
+\begin_inset Quotes erd
+\end_inset
+
+ so that XIOS internally check if a field is active before sending any data.
+ For example, defining the following field:
+\end_layout
+
+\begin_layout Standard
+\begin_inset listings
+lstparams "language=XML,breaklines=true,tabsize=2,frame=tb,postbreak={\raisebox{0ex}[0ex][0ex]{\ensuremath{\rcurvearrowse\space}}}"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+<field_definition>
+\end_layout
+
+\begin_layout Plain Layout
+
+	<field id="field_A" grid_ref="grid_A" operation="instant" check_if_active
+\series bold
+="true"
+\series default
+ />
+\end_layout
+
+\begin_layout Plain Layout
+
+</field_definition>
+\end_layout
+
+\end_inset
+
+has the same effect as if all calls to 
+\begin_inset Flex Code
+status open
+
+\begin_layout Plain Layout
+xios_send_field("field_A", field_A)
+\end_layout
+
+\end_inset
+
+ were replaced by:
+\end_layout
+
+\begin_layout Standard
+\begin_inset listings
+lstparams "language=XML,breaklines=true,tabsize=2,frame=tb,postbreak={\raisebox{0ex}[0ex][0ex]{\ensuremath{\rcurvearrowse\space}}}"
+inline false
+status open
+
+\begin_layout Plain Layout
+
+IF (xios_field_is_active("field_A"), .true.) THEN
+\end_layout
+
+\begin_layout Plain Layout
+
+	CALL xios_send_field("field_A", field_A)
+\end_layout
+
+\begin_layout Plain Layout
+
+ENDIF
+\end_layout
+
+\end_inset
+
+
 \end_layout
 
@@ -4661,5 +5127,5 @@
 \begin_layout Plain Layout
 
-			<grid id="grid_A"><!-- Definition ommited --></grid>
+			<grid id="grid_A"><!-- Definition omitted --></grid>
 \end_layout
 
@@ -4876,5 +5342,5 @@
 \begin_layout Plain Layout
 
-	<!-- Actual context(s) used by the simulation ommited -->
+	<!-- Actual context(s) used by the simulation omitted -->
 \end_layout
 
