Index: trunk/zoo-project/zoo-kernel/service_internal_saga.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_saga.c	(revision 790)
+++ trunk/zoo-project/zoo-kernel/service_internal_saga.c	(revision 917)
@@ -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, 
