Index: trunk/zoo-project/zoo-services/gdal/translate/Makefile
===================================================================
--- trunk/zoo-project/zoo-services/gdal/translate/Makefile	(revision 367)
+++ trunk/zoo-project/zoo-services/gdal/translate/Makefile	(revision 369)
@@ -4,6 +4,6 @@
 CC=gcc
 
-cgi-env/service.zo: service.c
-	g++ ${CFLAGS} -shared -fpic -o cgi-env/service.zo ./service.c ${GDAL_LIBS} ${MACOS_LD_FLAGS}
+cgi-env/translate_service.zo: service.c
+	g++ ${CFLAGS} -shared -fpic -o cgi-env/translate_service.zo ./service.c ${GDAL_LIBS} ${MACOS_LD_FLAGS}
 
 clean:
Index: trunk/zoo-project/zoo-services/gdal/translate/cgi-env/Gdal_Translate.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/gdal/translate/cgi-env/Gdal_Translate.zcfg	(revision 367)
+++ trunk/zoo-project/zoo-services/gdal/translate/cgi-env/Gdal_Translate.zcfg	(revision 369)
@@ -6,5 +6,5 @@
  statusSupported = true
  serviceType = C
- serviceProvider = gdal_service.zo
+ serviceProvider = translate_service.zo
  <MetaData>
    title = My Demo
@@ -13,5 +13,5 @@
   [Format]
    Title = Format of the output data
-   Abstract = Select the output format.
+   Abstract = Select the output format by usig short name of the format (use gda-config --formats for list of available formats on your platform).
    minOccurs = 0
    maxOccurs = 1
@@ -19,6 +19,15 @@
     DataType = string
     <Default>
-     value = demo.tif
+     value = GTiff
     </Default>
+   </LiteralData>
+  [GCP]
+   Title = Ground Point Control
+   Abstract = Ground Point Control in the form : pixel,line,eating,northing(,elev).
+   minOccurs = 0
+   maxOccurs = unbounded
+   <LiteralData>
+    DataType = string
+    <Default />
    </LiteralData>
   [InputDSN]
@@ -29,8 +38,7 @@
    <LiteralData>
     DataType = string
-    <Default>
-    </Default>	
+    <Default />
    </LiteralData>
-  [OutputDataSourceName]
+  [OutputDSN]
    Title = The output data source name
    Abstract = The output data source name to use as source for convertion.
@@ -39,10 +47,9 @@
    <LiteralData>
     DataType = string
-    <Default>
-    </Default>	
+    <Default />
    </LiteralData>
  </DataInputs>
  <DataOutputs>
-  [OutputedDataSourceName]
+  [Result]
    Title = The resulting converted file
    Abstract = The file name resulting of the convertion
Index: trunk/zoo-project/zoo-services/gdal/translate/makefile.vc
===================================================================
--- trunk/zoo-project/zoo-services/gdal/translate/makefile.vc	(revision 367)
+++ trunk/zoo-project/zoo-services/gdal/translate/makefile.vc	(revision 369)
@@ -16,7 +16,7 @@
 !ENDIF
 
-cgi-env/gdal_service.zo: service.c
-	$(CPP) -DWIN32 -DZOO_SERVICE -DNEED_STRCASESTR -I$(GDAL_DIR)/frmts/ $(CFLAGS) /c service.c
-	link /dll /out:cgi-env/gdal_service.zo  $(FILES) ./service.obj $(LDFLAGS)
+cgi-env/translate_service.zo: service.c
+	$(CPP)  /D_CRT_NONSTDC_NO_DEPRECATE -DWIN32 -DZOO_SERVICE -I$(GDAL_DIR)/frmts/ $(CFLAGS) /c service.c
+	link /dll /out:cgi-env/gdal_service.zo  $(FILES) ./service.obj $(LDFLAGS) /FORCE:MULTIPLE
 
 clean:
Index: trunk/zoo-project/zoo-services/gdal/translate/service.c
===================================================================
--- trunk/zoo-project/zoo-services/gdal/translate/service.c	(revision 367)
+++ trunk/zoo-project/zoo-services/gdal/translate/service.c	(revision 369)
@@ -33,13 +33,11 @@
 #include "gdal_priv.h"
 #include "ogr_spatialref.h"
-#include "vrtdataset.h"
+#include "vrt/vrtdataset.h"
 
 #include "service.h"
 
-
 CPL_CVSID("$Id$");
 
 extern "C" {
-
 
   static void AttachMetadata( GDALDatasetH, char ** );
@@ -50,9 +48,10 @@
   /************************************************************************/
 
+#ifdef WIN32
+__declspec(dllexport)
+#endif
   int Gdal_Translate(maps*& conf,maps*& inputs,maps*& outputs)
   {
-    
-    fprintf(stderr,"STARTING GDAL TRANSLATE\n");
-    fflush(stderr);
+
 
     GDALDatasetH	hDataset, hOutDS;
@@ -97,5 +96,4 @@
     /* ----------------------------------------------------------------- */
     GDALAllRegister();
-
     /* ----------------------------------------------------------------- */
     /* Extract Format, InputDSN, OutputDSN parameters                    */
@@ -124,11 +122,11 @@
     tmpMap=getMapFromMaps(inputs,"InputDSN","value");
     if(tmpMap!=NULL){
-      pszSource=(char*)malloc(sizeof(char)*(strlen(dataPath)+strlen(tmpMap->value)+4));
-      sprintf((char*)pszSource,"%s/%s.tif",dataPath,tmpMap->value);
+      pszSource=(char*)CPLMalloc(sizeof(char)*(strlen(dataPath)+strlen(tmpMap->value)+4));
+      sprintf((char*)pszSource,"%s/%s",dataPath,tmpMap->value);
     }
     tmpMap=NULL;
     tmpMap=getMapFromMaps(inputs,"OutputDSN","value");
     if(tmpMap!=NULL){
-      pszDest=(char*)malloc(sizeof(char)*(strlen(tempPath)+strlen(tmpMap->value)+4));
+      pszDest=(char*)CPLMalloc(sizeof(char)*(strlen(tempPath)+strlen(tmpMap->value)+4));
       char *ext=new char[4];
       ext="tif";
@@ -168,10 +166,94 @@
 	  break;
 	}
-	fprintf(stderr,"%s\n\n",t);
-	fprintf(stderr,"%f - %f - %f - %f\n\n",dfULX,dfULY,dfLRX,dfLRY);
 	t=strtok(NULL,",");
 	cnt++;
       }
     }
+
+    tmpMap=NULL;
+    tmpMap=getMapFromMaps(inputs,"GCP","value");
+    if(tmpMap!=NULL){
+      map* length=getMapFromMaps(inputs,"GCP","length");
+      int len=0;
+      if(length){
+	len=atoi(length->value);
+	int i;
+	maps* currentMaps=getMaps(inputs,"GCP");
+	for(i=0;i<len;i++){
+	  char* endptr = NULL;
+	  /* -gcp pixel line easting northing [elev] */
+	  
+	  nGCPCount++;
+	  pasGCPs = (GDAL_GCP *) 
+	    realloc( pasGCPs, sizeof(GDAL_GCP) * nGCPCount );
+	  GDALInitGCPs( 1, pasGCPs + nGCPCount - 1 );
+
+	  map* currentMap=getMapArray(currentMaps->content,"value",i);
+
+	  char* tmpV=strdup(currentMap->value);
+	  char *res=strtok(tmpV,",");
+	  int j=0;
+	  while(res!=NULL){
+	    switch(j){
+	    case 0:
+	      pasGCPs[nGCPCount-1].dfGCPPixel = CPLAtofM(res);
+	      break;
+	    case 1:
+	      pasGCPs[nGCPCount-1].dfGCPLine = CPLAtofM(res);
+	      break;
+	    case 2:
+	      pasGCPs[nGCPCount-1].dfGCPX = CPLAtofM(res);
+	      break;
+	    case 3:
+	      pasGCPs[nGCPCount-1].dfGCPY = CPLAtofM(res);
+	      break;
+	    case 4:
+	      if(res!=NULL && (strtod(res, &endptr) != 0.0 || res[0] == '0'))
+		if (endptr && *endptr == 0)
+		  pasGCPs[nGCPCount-1].dfGCPZ = CPLAtofM(res);
+	      break;
+	    }
+	    res=strtok(NULL,",");
+	    j++;
+	  }
+	}
+      }else{
+	char* endptr = NULL;
+	/* -gcp pixel line easting northing [elev] */
+	
+	nGCPCount++;
+	pasGCPs = (GDAL_GCP *) 
+	  realloc( pasGCPs, sizeof(GDAL_GCP) * nGCPCount );
+	GDALInitGCPs( 1, pasGCPs + nGCPCount - 1 );
+	
+	char* tmpV=strdup(tmpMap->value);
+	char *res=strtok(tmpV,",");
+	int j=0;
+	while(res!=NULL){
+	  switch(j){
+	  case 0:
+	    pasGCPs[nGCPCount-1].dfGCPPixel = CPLAtofM(res);
+	    break;
+	  case 1:
+	    pasGCPs[nGCPCount-1].dfGCPLine = CPLAtofM(res);
+	    break;
+	  case 2:
+	    pasGCPs[nGCPCount-1].dfGCPX = CPLAtofM(res);
+	    break;
+	  case 3:
+	    pasGCPs[nGCPCount-1].dfGCPY = CPLAtofM(res);
+	    break;
+	  case 4:
+	    if(res!=NULL && (CPLStrtod(res, &endptr) != 0.0 || res[0] == '0'))
+	      if (endptr && *endptr == 0)
+		pasGCPs[nGCPCount-1].dfGCPZ = CPLAtofM(res);
+	    break;
+	  }	    
+	  res=strtok(NULL,",");
+	  j++;
+	}
+      }
+    }
+
     tmpMap=NULL;
     tmpMap=getMapFromMaps(inputs,"SRS","value");
@@ -180,10 +262,12 @@
       if( oOutputSRS.SetFromUserInput( tmpMap->value ) != OGRERR_NONE )
 	{
-	  fprintf( stderr, "Failed to process SRS definition: %s\n", 
+	  char *msg=(char*)CPLMalloc(100*sizeof(char));
+	  sprintf( msg, "Failed to process SRS definition: %s\n", 
 		   tmpMap->value );
-	    /**
-	     * Avoiding GDALDestroyDriverManager() call
-	     */
-	  exit( 1 );
+	  setMapInMaps(conf,"lenv","message",msg);
+	  /**
+	   * Avoiding GDALDestroyDriverManager() call
+	   */
+	  return SERVICE_FAILED;
 	}
       oOutputSRS.exportToWkt( &pszOutputSRS );
@@ -213,6 +297,4 @@
 	}
     }
-    fprintf(stderr,"==%s %s %s %==\n",pszFormat,pszSource,pszDest);
-    fflush(stderr);
 
     if( pszDest == NULL ){
@@ -242,13 +324,11 @@
     
     if( hDataset == NULL ){
-        fprintf( stderr,
-                 "GDALOpen failed - %d\n%s\n",
-                 CPLGetLastErrorNo(), CPLGetLastErrorMsg() );
-	fflush(stderr);
-	/**
-	 * Avoiding GDALDestroyDriverManager() call
-	 */
-        exit( 1 );
-      }
+      char *msg=(char*) CPLMalloc(1024*sizeof(char));
+      sprintf( msg,
+	       "GDALOpen failed - %d\n%s\n",
+	       CPLGetLastErrorNo(), CPLGetLastErrorMsg() );
+      setMapInMaps(conf,"lenv","message",msg);
+      return SERVICE_FAILED;
+    }
 
     /* ----------------------------------------------------------------- */
@@ -259,7 +339,8 @@
         && GDALGetRasterCount(hDataset) == 0 )
       {
-        fprintf( stderr,
+	char *msg=(char*) CPLMalloc(1024*sizeof(char));
+        sprintf( msg,
                  "Input file contains subdatasets. Please, select one of them for reading.\n" );
-	fflush(stderr);
+	setMapInMaps(conf,"lenv","message",msg);
         GDALClose( hDataset );
 	/**
@@ -288,5 +369,5 @@
         
         bSubCall = bOldSubCall;
-        CPLFree( pszSubDest );
+        free( pszSubDest );
 
         GDALClose( hDataset );
@@ -310,5 +391,5 @@
 
     if( !bQuiet )
-      printf( "Input file size is %d, %d\n", nRasterXSize, nRasterYSize );
+      fprintf( stderr, "Input file size is %d, %d\n", nRasterXSize, nRasterYSize );
 
     if( anSrcWin[2] == 0 && anSrcWin[3] == 0 ){
@@ -375,5 +456,5 @@
                      "rotated.  This configuration is not supported.\n" );
             GDALClose( hDataset );
-            CPLFree( panBandList );
+            free( panBandList );
 	    fflush(stderr);
 	    /**
@@ -439,6 +520,6 @@
         int	iDr;
         
-        printf( "Output driver `%s' not recognised.\n", pszFormat );
-        printf( "The following format drivers are configured and support output:\n" );
+	char* msg=(char*) CPLMalloc(4096*sizeof(char));
+	sprintf(msg,"Output driver `%s' not recognised.\nThe following format drivers are configured and support output:\n",pszFormat);
         for( iDr = 0; iDr < GDALGetDriverCount(); iDr++ )
 	  {
@@ -449,13 +530,15 @@
                                         NULL ) != NULL )
 	      {
-                printf( "  %s: %s\n",
+		fprintf(stderr,msg);
+		char *tmp=strdup(msg);
+                sprintf( msg,"%s  %s: %s\n",tmp,
                         GDALGetDriverShortName( hDriver  ),
                         GDALGetDriverLongName( hDriver ) );
+		free(tmp);
 	      }
 	  }
-        printf( "\n" );
-        
+	setMapInMaps(conf,"lenv","message",msg);
         GDALClose( hDataset );
-        CPLFree( panBandList );
+        free( panBandList );
 	fflush(stderr);
 	/**
@@ -463,5 +546,5 @@
 	 */
         CSLDestroy( papszCreateOptions );
-        exit( 1 );
+        return 4;
       }
 
@@ -472,10 +555,13 @@
     /*   virtual input source to copy from.                              */
     /* ----------------------------------------------------------------- */
+    int bSpatialArrangementPreserved = (
+           anSrcWin[0] == 0 && anSrcWin[1] == 0
+        && anSrcWin[2] == GDALGetRasterXSize(hDataset)
+        && anSrcWin[3] == GDALGetRasterYSize(hDataset)
+        && pszOXSize == NULL && pszOYSize == NULL );
+
     if( eOutputType == GDT_Unknown 
         && !bScale && CSLCount(papszMetadataOptions) == 0 && bDefBands 
-        && anSrcWin[0] == 0 && anSrcWin[1] == 0 
-        && anSrcWin[2] == GDALGetRasterXSize(hDataset)
-        && anSrcWin[3] == GDALGetRasterYSize(hDataset) 
-        && pszOXSize == NULL && pszOYSize == NULL 
+        && bSpatialArrangementPreserved
         && nGCPCount == 0 && !bGotBounds
         && pszOutputSRS == NULL && !bSetNoData
@@ -484,5 +570,5 @@
         
         hOutDS = GDALCreateCopy( hDriver, pszDest, hDataset, 
-                                 bStrict, papszCreateOptions, 
+                                 FALSE, (char**)0, 
                                  pfnProgress, NULL );
 
@@ -492,5 +578,5 @@
         GDALClose( hDataset );
 
-        CPLFree( panBandList );
+        free( panBandList );
 
         if( !bSubCall )
@@ -501,15 +587,18 @@
 	     */
 	  }
+	fprintf(stderr,"==%s %s %s %d==\n",pszFormat,pszSource,pszDest,__LINE__);
+	fflush(stderr);
 
         CSLDestroy( papszCreateOptions );
-	outputs=(maps*)malloc(sizeof(maps*));
-	outputs->name="OutputedPolygon";
-	outputs->content=createMap("value",(char*)pszDest);
-	outputs->next=NULL;
-	
+	fprintf(stderr,"==%s %s %s %d==\n",pszFormat,pszSource,pszDest,__LINE__);
+	fflush(stderr);
+	//outputs=(maps*)CPLMalloc(sizeof(maps*));
+	//outputs->name="OutputedPolygon";
+	//outputs->content=createMap("value",(char*)pszDest);
+	//outputs->next=NULL;
+	dumpMaps(outputs);
+	setMapInMaps(outputs,"Result","value",(char*)pszDest);
 	return SERVICE_SUCCEEDED;
       }
-    fprintf(stderr,"==%s %s %s %==\n",pszFormat,pszSource,pszDest);
-    fflush(stderr);
 
     /* ----------------------------------------------------------------- */
@@ -528,6 +617,4 @@
                           ? atof(pszOYSize)/100*anSrcWin[3] : atoi(pszOYSize)));
       }
-    fprintf(stderr,"==%s %s %s %==\n",pszFormat,pszSource,pszDest);
-    fflush(stderr);
 
     /* ================================================================= */
@@ -595,5 +682,5 @@
 
         GDALDeinitGCPs( nGCPCount, pasGCPs );
-        CPLFree( pasGCPs );
+        free( pasGCPs );
       }
 
@@ -617,5 +704,5 @@
 
         GDALDeinitGCPs( nGCPs, pasGCPs );
-        CPLFree( pasGCPs );
+        free( pasGCPs );
       }
 
@@ -625,6 +712,4 @@
     poVDS->SetMetadata( ((GDALDataset*)hDataset)->GetMetadata() );
     AttachMetadata( (GDALDatasetH) poVDS, papszMetadataOptions );
-    fprintf(stderr,"Transfer generally applicable metadata.\n");
-    fflush(stderr);
 
     /* ----------------------------------------------------------------- */
@@ -664,5 +749,5 @@
                 fprintf(stderr, "Error : band %d has no color table\n", panBandList[0]);
                 GDALClose( hDataset );
-                CPLFree( panBandList );
+                free( panBandList );
 		fflush(stderr);
 		/**
@@ -760,10 +845,7 @@
     /*      Write to the output file using CopyCreate().                 */
     /* ----------------------------------------------------------------- */
-    fprintf(stderr,"DEBUG pszDest %s\n",pszDest);
     hOutDS = GDALCreateCopy( hDriver, pszDest, (GDALDatasetH) poVDS,
                              bStrict, papszCreateOptions, 
                              pfnProgress, NULL );
-    fprintf(stderr,"DEBUG pszDest %s\n",pszDest);
-    fflush(stderr);
 
     if( hOutDS != NULL )
@@ -773,10 +855,10 @@
     
     GDALClose( (GDALDatasetH) poVDS );
-        
+         
     GDALClose( hDataset );
-
-    CPLFree( panBandList );
+   
+    free( panBandList );
     
-    CPLFree( pszOutputSRS );
+    free( pszOutputSRS );
 
     if( !bSubCall )
@@ -791,8 +873,5 @@
     CSLDestroy( papszCreateOptions );
     
-    outputs=(maps*)malloc(sizeof(maps*));
-    outputs->name="OutputedPolygon";
-    outputs->content=createMap("value",(char*)pszDest);
-    outputs->next=NULL;
+    setMapInMaps(outputs,"Result","value",(char*)pszDest);
 
     return SERVICE_SUCCEEDED;
@@ -817,5 +896,5 @@
         pszValue = CPLParseNameValue( papszMetadataOptions[i], &pszKey );
         GDALSetMetadataItem(hDS,pszKey,pszValue,NULL);
-        CPLFree( pszKey );
+        free( pszKey );
       }
 
