Index: /branches/prototype-v0/zoo-project/zoo-kernel/ZOOMakefile.opts.in
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/ZOOMakefile.opts.in	(revision 899)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/ZOOMakefile.opts.in	(revision 900)
@@ -80,6 +80,6 @@
 MS_FILE=@MS_FILE@
 
-ZOO_CFLAGS=@GETTEXT_CFLAGS@ -I${ZRPATH}/../thirds/cgic206/ -I${ZRPATH}/zoo-kernel/
-ZOO_LDFLAGS=@GETTEXT_LDFLAGS@ @OPENSSL_LDFLAGS@ @UUID_LDFLAGS@
+ZOO_CFLAGS=-I${ZRPATH}/../thirds/cgic206/ -I${ZRPATH}/zoo-kernel/
+ZOO_LDFLAGS=@OPENSSL_LDFLAGS@ @UUID_LDFLAGS@
 
 JAVACFLAGS=@JAVA_CPPFLAGS@
@@ -119,6 +119,6 @@
 MONO_FILE=@MONO_FILE@
 
-CFLAGS=@SSH2_CPPFLAGS@ @GETTEXT_CFLAGS@ @PROJ_CPPFLAGS@ @RELY_ON_DB@ @DEB_DEF@ -fpic @OPENSSL_CFLAGS@ @UUID_CFLAGS@ ${FCGI_CFLAGS} ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
-LDFLAGS=-lzoo_service @SSH2_LDFLAGS@ @PROJ_LDFLAGS@ @DEFAULT_LIBS@ -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS}  ${FCGI_LDFLAGS} @OPENSSL_LDFLAGS@ @UUID_LDFLAGS@ ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS} ${MONO_LDFLAGS} ${RLDFLAGS} @GETTEXT_LDFLAGS@ @JSON_LDFLAGS@ @XSLT_LDFLAGS@
+CFLAGS=@SSH2_CPPFLAGS@ @PROJ_CPPFLAGS@ @RELY_ON_DB@ @DEB_DEF@ -fpic @OPENSSL_CFLAGS@ @UUID_CFLAGS@ ${FCGI_CFLAGS} ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
+LDFLAGS=-lzoo_service @SSH2_LDFLAGS@ @PROJ_LDFLAGS@ @DEFAULT_LIBS@ -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS}  ${FCGI_LDFLAGS} @OPENSSL_LDFLAGS@ @UUID_LDFLAGS@ ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS} ${MONO_LDFLAGS} ${RLDFLAGS} @JSON_LDFLAGS@ @XSLT_LDFLAGS@
 
 DATAROOTDIR=@datarootdir@/zoo-project
Index: /branches/prototype-v0/zoo-project/zoo-kernel/configure.ac
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/configure.ac	(revision 899)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/configure.ac	(revision 900)
@@ -114,10 +114,10 @@
 #============================================================================
 
-AC_ARG_WITH([gettext],
-    [AS_HELP_STRING([--with-gettext=PATH], [Specifies an alternative location for the openssl library])],
-    [GETTEXT_DIR="$withval"], [GETTEXT_DIR="/usr/"])
-
-GETTEXT_CFLAGS="-I$GETTEXT_DIR/include"
-GETTEXT_LDFLAGS="-L$GETTEXT_DIR/lib -lintl"
+#AC_ARG_WITH([gettext],
+#    [AS_HELP_STRING([--with-gettext=PATH], [Specifies an alternative location for the openssl library])],
+#    [GETTEXT_DIR="$withval"], [GETTEXT_DIR="/usr/"])
+
+#GETTEXT_CFLAGS="-I$GETTEXT_DIR/include"
+#GETTEXT_LDFLAGS="-L$GETTEXT_DIR/lib -lintl"
 #CFLAGS_SAVE="$CFLAGS"
 #CFLAGS="$GETTEXT_CFLAGS"
@@ -127,6 +127,6 @@
 #AC_CHECK_LIB(intl,
 #			[dgettext], [] , [AC_MSG_ERROR([could not find $i function in gettext library])])
-AC_SUBST([GETTEXT_CFLAGS])
-AC_SUBST([GETTEXT_LDFLAGS])
+#AC_SUBST([GETTEXT_CFLAGS])
+#AC_SUBST([GETTEXT_LDFLAGS])
 
 #============================================================================
@@ -1049,4 +1049,8 @@
         [SAGAPATH="$withval"], [SAGAPATH=""])
 
+AC_ARG_WITH([saga-version],
+        [AS_HELP_STRING([--with-saga-version=VERSION], [Specifies the SAGA-GIS version number])],
+        [SAGAVERS="$withval"], [SAGAVERS="2"])
+
 if test -z "$SAGAPATH"
 then
@@ -1064,5 +1068,5 @@
 	WX_ISSUE="-D_WX_WXCRTVARARG_H_"
 	SAGA_DEFS="-D_SAGA_LINUX -D_TYPEDEF_BYTE -D_TYPEDEF_WORD -DMODULE_LIBRARY_PATH=\\\"$SAGAPATH/lib/saga\\\""
-	SAGA_CPPFLAGS=" -fPIC -I$SAGAPATH/include/saga/saga_core/saga_api/ `$WXCFG --unicode=yes --static=no --cxxflags` -D_SAGA_UNICODE $SAGA_DEFS $WX_ISSUE"
+	SAGA_CPPFLAGS="-DSAGA_VERSION=${SAGAVERS} -fPIC -I$SAGAPATH/include/saga/saga_core/saga_api/ `$WXCFG --unicode=yes --static=no --cxxflags` -D_SAGA_UNICODE $SAGA_DEFS $WX_ISSUE"
 	SAGA_LDFLAGS="-fPIC `$WXCFG --unicode=yes --static=no --libs` -lsaga_api"
 	SAGA_ENABLED="-DUSE_SAGA"
@@ -1075,8 +1079,16 @@
 	LIBS_SAVE="$LIBS"
 	LIBS="$SAGA_LDFLAGS"
-	AC_CHECK_HEADERS([module_library.h],
-			[], [AC_MSG_ERROR([could not find header file $i related to SAGA-GIS])])
-	AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include "module_library.h"],[SG_Get_Module_Library_Manager();]])],
-		[AC_MSG_RESULT([checking for SG_Get_Module_Library_Manager... yes])],[AC_MSG_ERROR([checking for SG_Get_Module_Library_Manager... failed])])
+        if test "$SAGAVERS" == "2"; then
+        AC_CHECK_HEADERS([module_library.h],
+                        [], [AC_MSG_ERROR([could not find header file $i related to SAGA-GIS])])
+        AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include "module_library.h"],[SG_Get_Module_Library_Manager();]])],
+                [AC_MSG_RESULT([checking for SG_Get_Module_Library_Manager... yes])],[AC_MSG_ERROR([checking for SG_Get_Module_Library_Manager... failed])])
+        else
+        AC_CHECK_HEADERS([tool_library.h],
+                        [], [AC_MSG_ERROR([could not find header file $i related to SAGA-GIS])])
+        AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include "tool_library.h"],[SG_Get_Tool_Library_Manager();]])],
+                [AC_MSG_RESULT([checking for SG_Get_Tool_Library_Manager... yes])],[AC_MSG_ERROR([checking for SG_Get_Tool_Library_Manager... failed])])
+        fi
+	
 	LIBS="$LIBS_SAVE"
 	AC_LANG_POP([C++])
Index: /branches/prototype-v0/zoo-project/zoo-kernel/response_print.h
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/response_print.h	(revision 899)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/response_print.h	(revision 900)
@@ -81,5 +81,5 @@
 #ifndef WIN32
 //#include <locale.h>
-#include <xlocale.h> // knut: this appears to be a non-standard header file that has been removed in newer versions of glibc; it may be sufficient to include <locale.h> (see above) 
+#include <locale.h> // knut: this appears to be a non-standard header file that has been removed in newer versions of glibc; it may be sufficient to include <locale.h> (see above) 
 #endif
 #include "ulinet.h"
Index: /branches/prototype-v0/zoo-project/zoo-kernel/service.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/service.c	(revision 899)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/service.c	(revision 900)
@@ -25,5 +25,5 @@
 #include "service.h"
 
- // knut: time utilities required for new log function (logMessage)
+// knut: time utilities required for new log function (logMessage)
 #include <ctime>
 #include <chrono>
Index: /branches/prototype-v0/zoo-project/zoo-kernel/service_internal.h
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/service_internal.h	(revision 899)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/service_internal.h	(revision 900)
@@ -81,5 +81,5 @@
 #endif
 #ifndef WIN32
-#include <xlocale.h>
+#include <locale.h>
 #endif
 
Index: /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_saga.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_saga.c	(revision 899)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_saga.c	(revision 900)
@@ -30,5 +30,5 @@
 #include <api_core.h>
 #include <data_manager.h>
-#include <module_library.h>
+#include <saga_api.h>
 #define _ZOO_SAGA
 #include "service_internal_saga.h"
@@ -237,5 +237,7 @@
 	return false;
       }
-      return( param->Set_Value(SG_Get_Data_Manager().Find(&fileName)) );
+      fprintf(stderr,"%s %s\n",carg->name,carg->value);
+      fflush(stderr);
+      return( param->Set_Value(SG_Get_Data_Manager().Find(&fileName,false)) );
     }
     else
@@ -250,5 +252,5 @@
 	    SG_Get_Data_Manager().Add(&fileName);
 	  }
-	  param->asList()->Add_Item(SG_Get_Data_Manager().Find(&fileName));
+	  param->asList()->Add_Item(SG_Get_Data_Manager().Find(&fileName,false));
 	}
       }
@@ -327,8 +329,16 @@
 	    inmap=getMap(argument,(CSG_String(param->Get_Identifier())+"_MIN").b_str());
 	    if(inmap!=NULL)
+#if SAGA_MAJOR_VERSION == 2	      
 	      param->asRange()->Set_LoVal(strtod(inmap->value,NULL));
+#else
+	      param->asRange()->Set_Min(strtod(inmap->value,NULL));
+#endif	    
 	    inmap=getMap(argument,(CSG_String(param->Get_Identifier())+"_MAX").b_str());
 	    if(inmap!=NULL)
+#if SAGA_MAJOR_VERSION == 2	      
 	      param->asRange()->Set_HiVal(strtod(inmap->value,NULL));	    
+#else
+	      param->asRange()->Set_Max(strtod(inmap->value,NULL));
+#endif	    
 	  }
 	  if(inmap==NULL){
@@ -386,7 +396,19 @@
 	    else if( param->is_DataObject_List() )
 	      {
-		for(int i=0; i<param->asList()->Get_Count(); i++)
+		for(int i=0; i<
+#if SAGA_MAJOR_VERSION == 2
+		      param->asList()->Get_Count()
+#else
+		      param->asList()->Get_Data_Count()
+#endif		      
+		      ; i++)
 		  {
-		    CSG_Data_Object *pObject = param->asList()->asDataObject(i);
+		    CSG_Data_Object *pObject =
+#if SAGA_MAJOR_VERSION == 2		      
+		      param->asList()->asDataObject(i)
+#else
+		      param->asList()->Get_Data(i)
+#endif		      
+		      ;
 		    
 		    if( pObject->is_Modified() && SG_File_Exists(pObject->Get_File_Name()) )
@@ -439,5 +461,5 @@
 			}
 		    }
-		  
+#if SAGA_MAJOR_VERSION == 2		  
 		  int nFileNames = param->asList()->Get_Count() <= fileNames.Get_Count() ? fileNames.Get_Count() : fileNames.Get_Count() - 1;
 		  for(int i=0; i<param->asList()->Get_Count(); i++)
@@ -458,4 +480,25 @@
 				  CSG_String(param->asList()->asDataObject(i)->Get_File_Name()).b_str());
 		    }
+#else
+		  int nFileNames = param->asList()->Get_Data_Count() <= fileNames.Get_Count() ? fileNames.Get_Count() : fileNames.Get_Count() - 1;
+		  for(int i=0; i<param->asList()->Get_Data_Count(); i++)
+		    {
+		      if( i < nFileNames )
+			{
+			  param->asList()->Get_Data(i)->Save(fileNames[i]);
+			}
+		      else
+			{
+			  param->asList()->Get_Data(i)->Save(CSG_String::Format(SG_T("%s_%0*d"),
+										    fileNames[fileNames.Get_Count() - 1].c_str(),
+										    SG_Get_Digit_Count(param->asList()->Get_Data_Count()),
+										    1 + i - nFileNames
+										    ));
+			}
+		      setMapArray(cMaps->content,"generated_file",i,
+				  CSG_String(param->asList()->Get_Data(i)->Get_File_Name()).b_str());
+		    }
+		  
+#endif		  
 		}
 	    }
@@ -477,5 +520,9 @@
   int res=SERVICE_FAILED;
 
+#if SAGA_MAJOR_VERSION == 2  
   CSG_Module_Library * library=SG_Get_Module_Library_Manager().Get_Library(CSG_String(lib_name),true);
+#else
+  CSG_Tool_Library * library=SG_Get_Tool_Library_Manager().Get_Library(CSG_String(lib_name),true);
+#endif  
   if( library == NULL){
     char tmp[255];
@@ -486,5 +533,9 @@
   }
 
+#if SAGA_MAJOR_VERSION == 2  
   CSG_Module * module=library->Get_Module(atoi(module_name));
+#else
+  CSG_Tool * module=library->Get_Tool(atoi(module_name));
+#endif  
   if(module == NULL){
     char tmp[255];
@@ -985,6 +1036,12 @@
   SG_Set_UI_Callback(Get_Callback(watcher));
 
+#if SAGA_MAJOR_VERSION == 2  
   int n = SG_Get_Module_Library_Manager().Add_Directory(wxT(MODULE_LIBRARY_PATH),false);
-  if( SG_Get_Module_Library_Manager().Get_Count() <= 0 ){
+  if( SG_Get_Module_Library_Manager().Get_Count() <= 0 )
+#else
+  int n = SG_Get_Tool_Library_Manager().Add_Directory(wxT(MODULE_LIBRARY_PATH),false);
+  if( SG_Get_Tool_Library_Manager().Get_Count() <= 0 )
+#endif
+  {
     setMapInMaps(*main_conf,"lenv","message","Could not load any SAGA tool library");
     res=SERVICE_FAILED;
@@ -995,5 +1052,9 @@
 
   // Load the SAGA-GIS library corresponding to the serviceProvider
+#if SAGA_MAJOR_VERSION == 2  
   CSG_Module_Library * library=SG_Get_Module_Library_Manager().Get_Library(CSG_String(serviceProvider->value),true);
+#else
+  CSG_Tool_Library * library=SG_Get_Tool_Library_Manager().Get_Library(CSG_String(serviceProvider->value),true);
+#endif
   if( library == NULL){
     char tmp[255];
@@ -1005,5 +1066,9 @@
   
   // Load the SAGA-GIS module corresponding to the service name from the library
+#if SAGA_MAJOR_VERSION == 2  
   CSG_Module * module=library->Get_Module(atoi(s->name));
+#else
+  CSG_Tool * module=library->Get_Tool(atoi(s->name));
+#endif
   if(module == NULL){
     char tmp[255];
@@ -1017,5 +1082,4 @@
   // Load all the parameters defined for the module
   CSG_Parameters * params=module->Get_Parameters();
-  int pc=params->Get_Count();
   if(!params){
     char tmp[255];
@@ -1026,4 +1090,5 @@
     return res;
   }
+  int pc=params->Get_Count();
 
   // Loop over each inputs to transform raster files to grid when needed, 
