[GRASS-SVN] r36801 - grass-addons/raster/r.soils.texture

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Apr 19 22:52:03 EDT 2009


Author: hamish
Date: 2009-04-19 22:52:03 -0400 (Sun, 19 Apr 2009)
New Revision: 36801

Modified:
   grass-addons/raster/r.soils.texture/description.html
   grass-addons/raster/r.soils.texture/local_include.h
   grass-addons/raster/r.soils.texture/main.c
Log:
run grass_indent.sh on code

Modified: grass-addons/raster/r.soils.texture/description.html
===================================================================
--- grass-addons/raster/r.soils.texture/description.html	2009-04-20 02:45:48 UTC (rev 36800)
+++ grass-addons/raster/r.soils.texture/description.html	2009-04-20 02:52:03 UTC (rev 36801)
@@ -29,8 +29,10 @@
 <p>Sanesi G., 2000 - “Elementi di pedologia” - Edagricole, Bologna</p>
 <p>Texture AutoLookup (TAL) ver 4.2, 2002 </p>
 <p>Van Rossum G. - 2005 - “Manuale di riferimento di python” - Ed. Italiana, Fred L. Drake, Jr., editor</p>
-<p>WATTON J. D., 1997 - “Comparing C, Fortran, Lisp, java, python, perl, scheme (guile), and tcl using a</p>
-<p>floating point numerical test - point inside polygon”. Applied mathematics and computer technology center alcoa technical center. Distribution documents.</p>
+<p>WATTON J. D., 1997 - “Comparing C, Fortran, Lisp, java, python, perl,
+scheme (guile), and tcl using a floating point numerical test - point inside
+polygon”. Applied mathematics and computer technology center alcoa technical
+center. Distribution documents.</p>
 <p>
 <br><br>
 </p>

Modified: grass-addons/raster/r.soils.texture/local_include.h
===================================================================
--- grass-addons/raster/r.soils.texture/local_include.h	2009-04-20 02:45:48 UTC (rev 36800)
+++ grass-addons/raster/r.soils.texture/local_include.h	2009-04-20 02:52:03 UTC (rev 36801)
@@ -1,3 +1,4 @@
+
 /****************************************************************************
  *
  * MODULE:       r.soils.texture
@@ -16,23 +17,26 @@
 #define MAX_POINT 15
 #define MAX_LABEL 50
 
-/*///////List element prototipe///////////////////////////////*/     
-struct TextureTriangleCoord {
-         int numVertex; // polygons vertex of texture triangle 
-         float xSand[MAX_POINT], yClay[MAX_POINT]; // coordinate vector polygons in triangle 
-         int codeTexture; // code for identify textural type
-	     struct TextureTriangleCoord *PointToNext; //pointer to next element
-         }; 
- 
-struct label_struct {
-		int id;
-		char etichetta[1024];
-		};
+/*///////List element prototipe/////////////////////////////// */
+struct TextureTriangleCoord
+{
+    int numVertex;		// polygons vertex of texture triangle 
+    float xSand[MAX_POINT], yClay[MAX_POINT];	// coordinate vector polygons in triangle 
+    int codeTexture;		// code for identify textural type
+    struct TextureTriangleCoord *PointToNext;	//pointer to next element
+};
+
+struct label_struct
+{
+    int id;
+    char etichetta[1024];
+};
+
 /*
  * function prototype 
  */
 
-struct TextureTriangleCoord *ReadTriangle(int *, char *); //read texture file criteria (es. USDA.DAT)
-int ReadList(struct TextureTriangleCoord *, int *, float, float); //read all list of texture criteria
-int DefineTexture (int numVert, float *xSand, float *yClay, float SandVal, float ClayVal, int codeTxt); /*define texture for each point*/
-void reclassTexture(char *SchemeName, char *result); //reclass texture file with label
+struct TextureTriangleCoord *ReadTriangle(int *, char *);	//read texture file criteria (es. USDA.DAT)
+int ReadList(struct TextureTriangleCoord *, int *, float, float);	//read all list of texture criteria
+int DefineTexture(int numVert, float *xSand, float *yClay, float SandVal, float ClayVal, int codeTxt);	/*define texture for each point */
+void reclassTexture(char *SchemeName, char *result);	//reclass texture file with label

Modified: grass-addons/raster/r.soils.texture/main.c
===================================================================
--- grass-addons/raster/r.soils.texture/main.c	2009-04-20 02:45:48 UTC (rev 36800)
+++ grass-addons/raster/r.soils.texture/main.c	2009-04-20 02:52:03 UTC (rev 36801)
@@ -1,3 +1,4 @@
+
 /****************************************************************************
  *
  * MODULE:       r.soils.texture
@@ -21,8 +22,8 @@
 #include <grass/gis.h>
 #include <grass/glocale.h>
 #include "local_include.h"
- 
 
+
 /* 
  * global function declaration 
  */
@@ -30,35 +31,42 @@
 extern FCELL f_f(FCELL);
 extern DCELL f_d(DCELL);
 
-CELL c_calc(CELL c_sand, CELL c_clay, struct TextureTriangleCoord *punt_lista, int *numPoly)
+CELL c_calc(CELL c_sand, CELL c_clay, struct TextureTriangleCoord *punt_lista,
+	    int *numPoly)
 {
-    /* 				 */			
+    /*                           */
     CELL out;
     int polygons;
-    polygons=*numPoly;
-    out=ReadList(punt_lista, &polygons, c_sand, c_clay);
+
+    polygons = *numPoly;
+    out = ReadList(punt_lista, &polygons, c_sand, c_clay);
     return out;
 }
 
-FCELL f_calc(FCELL f_sand, FCELL f_clay, struct TextureTriangleCoord *punt_lista, int *numPoly  )
+FCELL f_calc(FCELL f_sand, FCELL f_clay,
+	     struct TextureTriangleCoord * punt_lista, int *numPoly)
 {
-   /* 				*/
+    /*                           */
     FCELL out;
     int polygons;
-    polygons=*numPoly;
-    out=ReadList(punt_lista, &polygons, f_sand, f_clay);
+
+    polygons = *numPoly;
+    out = ReadList(punt_lista, &polygons, f_sand, f_clay);
     return out;
 }
 
-DCELL d_calc(DCELL d_sand, DCELL d_clay, struct TextureTriangleCoord *punt_lista, int *numPoly )
+DCELL d_calc(DCELL d_sand, DCELL d_clay,
+	     struct TextureTriangleCoord * punt_lista, int *numPoly)
 {
-    /* 				*/
+    /*                          */
     DCELL out;
     int polygons;
-    polygons=*numPoly;
-    out=ReadList(punt_lista, &polygons, d_sand, d_clay);
+
+    polygons = *numPoly;
+    out = ReadList(punt_lista, &polygons, d_sand, d_clay);
     return out;
 }
+
 /*
  * main function
  * it copies raster inputSand raster file, calling the appropriate function for each
@@ -66,59 +74,59 @@
  */
 int main(int argc, char *argv[])
 {
-    struct Cell_head cellhd;					/* it stores region information, and header information of rasters */
-    char *SandName, *ClayName, *SchemeName;		/* inputSand raster name */
-    char *result;								/* output raster name */
-    char *mapsetSand, *mapsetClay;				/* mapset name */
-    void *inrastSand, *inrastClay;				/* input buffer */
-    unsigned char *outrast;						/* output buffer */
+    struct Cell_head cellhd;	/* it stores region information, and header information of rasters */
+    char *SandName, *ClayName, *SchemeName;	/* inputSand raster name */
+    char *result;		/* output raster name */
+    char *mapsetSand, *mapsetClay;	/* mapset name */
+    void *inrastSand, *inrastClay;	/* input buffer */
+    unsigned char *outrast;	/* output buffer */
     int nrows, ncols;
     int row, col;
-    int infdSand, infdClay, outfd;				/* file descriptor */
+    int infdSand, infdClay, outfd;	/* file descriptor */
     int verbose;
     int polygons;
-    RASTER_MAP_TYPE data_type_Sand, data_type_Clay, data_type;		/* type of the map (CELL/DCELL/...) */
+    RASTER_MAP_TYPE data_type_Sand, data_type_Clay, data_type;	/* type of the map (CELL/DCELL/...) */
 
-    struct GModule *module;						/* GRASS module for parsing arguments */
+    struct GModule *module;	/* GRASS module for parsing arguments */
 
     struct Option *inputSand, *inputClay, *inputTextureScheme, *output;	/* options */
-    struct Flag *flag1;							/* flags */
-	
+    struct Flag *flag1;		/* flags */
+
     struct TextureTriangleCoord *punt_lista;
 
-    
+
     /* initialize GIS environment */
     G_gisinit(argv[0]);		/* reads grass env, stores program name to G_program_name() */
 
     /* initialize module */
     module = G_define_module();
-    module->description = _("Define soil texture from sand and clay grid."); //D
+    module->description = _("Define soil texture from sand and clay grid.");	//D
 
-    /* Define the different options for SAND file*/
+    /* Define the different options for SAND file */
     inputSand = G_define_option();
     inputSand->key = "SAND";
     inputSand->type = TYPE_STRING;
     inputSand->required = YES;
-    inputSand->gisprompt   = "old,cell,raster";
+    inputSand->gisprompt = "old,cell,raster";
     inputSand->description = _("Name of an input SAND layer");
 
-    /* Define the different options for CLAY file*/
+    /* Define the different options for CLAY file */
     inputClay = G_define_option();
     inputClay->key = "CLAY";
     inputClay->type = TYPE_STRING;
     inputClay->required = YES;
-    inputClay->gisprompt   = "old,cell,raster";
+    inputClay->gisprompt = "old,cell,raster";
     inputClay->description = _("Name of an input CLAY layer");
-    
-    /*Define the texture file scheme: USDA, FAO, International or other scheme*/
+
+    /*Define the texture file scheme: USDA, FAO, International or other scheme */
     inputTextureScheme = G_define_option();
     inputTextureScheme->key = "scheme";
     inputTextureScheme->type = TYPE_STRING;
     inputTextureScheme->required = YES;
     inputTextureScheme->gisprompt = "old_file,file,input";
-    inputTextureScheme->answer ="";
+    inputTextureScheme->answer = "";
     inputTextureScheme->description = "Text file with texture scheme ";
-    
+
     output = G_define_option();
     output->key = "output";
     output->type = TYPE_STRING;
@@ -132,8 +140,9 @@
     /* stores options and flags to variables */
     SandName = inputSand->answer;
     ClayName = inputClay->answer;
-    SchemeName= inputTextureScheme->answer;
+    SchemeName = inputTextureScheme->answer;
     result = output->answer;
+
 /*************************************control sand file*****************************/
     /* returns NULL if the map was not found in any mapset, 
      * mapset name otherwise */
@@ -143,7 +152,7 @@
 
     if (G_legal_filename(result) < 0)
 	G_fatal_error(_("[%s] is an illegal name"), result);
-    
+
     /* determine the input map type (CELL/FCELL/DCELL) */
     data_type_Sand = G_raster_map_type(SandName, mapsetSand);
 
@@ -155,18 +164,19 @@
     /* controlling, if we can open inputSand raster */
     if (G_get_cellhd(SandName, mapsetSand, &cellhd) < 0)
 	G_fatal_error(_("Cannot read file header of [%s]"), SandName);
+
 /*********************************control clay file **********************************/
- 
+
     /* returns NULL if the map was not found in any mapset, 
      * mapset name otherwise */
     mapsetClay = G_find_cell2(ClayName, "");
-;
+    ;
     if (mapsetClay == NULL)
 	G_fatal_error(_("cell file [%s] not found"), ClayName);
 
     if (G_legal_filename(result) < 0)
 	G_fatal_error(_("[%s] is an illegal name"), result);
-    
+
     /* determine the input map type (CELL/FCELL/DCELL) */
     data_type_Clay = G_raster_map_type(ClayName, mapsetClay);
 
@@ -182,55 +192,56 @@
 /**************************************************************************************/
     /* Allocate input buffer */
     inrastSand = G_allocate_raster_buf(data_type_Sand);
-    inrastClay= G_allocate_raster_buf(data_type_Clay);
-    
+    inrastClay = G_allocate_raster_buf(data_type_Clay);
+
     /* Allocate output buffer, use input Sand map data_type */
     nrows = G_window_rows();
     ncols = G_window_cols();
     outrast = G_allocate_raster_buf(data_type_Sand);
-    data_type=data_type_Sand;
+    data_type = data_type_Sand;
     /* controlling, if we can write the raster */
     if ((outfd = G_open_raster_new(result, data_type)) < 0)
 	G_fatal_error(_("Could not open <%s>"), result);
-	
-    punt_lista=ReadTriangle(&polygons,SchemeName);//read texture criteria file (es USDA.DAT) and buil a list
+
+    punt_lista = ReadTriangle(&polygons, SchemeName);	//read texture criteria file (es USDA.DAT) and buil a list
     CELL c_sand, c_clay, c;
     FCELL f_sand, f_clay, f;
     DCELL d_sand, d_clay, d;
+
     /* for each row */
     for (row = 0; row < nrows; row++) {
-		if (verbose)
+	if (verbose)
 	    G_percent(row, nrows, 2);
 
 	/* read input Sand map */
-		if (G_get_raster_row(infdSand, inrastSand, row, data_type_Sand) < 0)
-	    	G_fatal_error(_("Could not read from <%s>"), SandName);
-	    
-		if (G_get_raster_row(infdClay, inrastClay, row, data_type_Sand) < 0)
-	    	G_fatal_error(_("Could not read from <%s>"), ClayName);
-	    
+	if (G_get_raster_row(infdSand, inrastSand, row, data_type_Sand) < 0)
+	    G_fatal_error(_("Could not read from <%s>"), SandName);
+
+	if (G_get_raster_row(infdClay, inrastClay, row, data_type_Sand) < 0)
+	    G_fatal_error(_("Could not read from <%s>"), ClayName);
+
 	/* process the data */
-		for (col = 0; col < ncols; col++) {
+	for (col = 0; col < ncols; col++) {
 	    /* use different function for each data type */
-	    	switch (data_type) {
-	    		case CELL_TYPE:
-				c_sand = ((CELL *) inrastSand)[col];
-				c_clay = ((CELL *) inrastClay)[col];
-				c = c_calc(c_sand, c_clay, punt_lista, &polygons);	/* calculate */
-				((CELL *) outrast)[col] = c;
-				break;
-	    		case FCELL_TYPE:
-				f_sand = ((FCELL *) inrastSand)[col];
-				f_clay = ((FCELL *) inrastClay)[col];
-				f = f_calc(f_sand, f_clay, punt_lista, &polygons);	/* calculate */
-				((FCELL *) outrast)[col] = f;
-				break;
-	    		case DCELL_TYPE:
-				d_sand = ((DCELL *) inrastSand)[col];
-				d_clay = ((DCELL *) inrastClay)[col];
-				d = d_calc(d_sand, d_clay, punt_lista, &polygons);	/* calculate */
-				((DCELL *) outrast)[col] = d;
-				break;
+	    switch (data_type) {
+	    case CELL_TYPE:
+		c_sand = ((CELL *) inrastSand)[col];
+		c_clay = ((CELL *) inrastClay)[col];
+		c = c_calc(c_sand, c_clay, punt_lista, &polygons);	/* calculate */
+		((CELL *) outrast)[col] = c;
+		break;
+	    case FCELL_TYPE:
+		f_sand = ((FCELL *) inrastSand)[col];
+		f_clay = ((FCELL *) inrastClay)[col];
+		f = f_calc(f_sand, f_clay, punt_lista, &polygons);	/* calculate */
+		((FCELL *) outrast)[col] = f;
+		break;
+	    case DCELL_TYPE:
+		d_sand = ((DCELL *) inrastSand)[col];
+		d_clay = ((DCELL *) inrastClay)[col];
+		d = d_calc(d_sand, d_clay, punt_lista, &polygons);	/* calculate */
+		((DCELL *) outrast)[col] = d;
+		break;
 	    }
 	}
 
@@ -238,7 +249,7 @@
 	if (G_put_raster_row(outfd, outrast, data_type) < 0)
 	    G_fatal_error(_("Cannot write to <%s>"), result);
     }
-    
+
     /* memory cleanup */
     G_free(inrastSand);
     G_free(inrastClay);
@@ -249,9 +260,9 @@
     G_close_cell(infdClay);
     G_close_cell(outfd);
 
-    reclassTexture(SchemeName,result);
-    
-    G_message("Soil texture file generated with name:<%s>",result);
+    reclassTexture(SchemeName, result);
+
+    G_message("Soil texture file generated with name:<%s>", result);
     return 0;
 }
 
@@ -259,149 +270,152 @@
 
 
 
-struct TextureTriangleCoord *ReadTriangle(int *numPoly, char *SchemeName )     
+struct TextureTriangleCoord *ReadTriangle(int *numPoly, char *SchemeName)
 {
-	/*//////////// Declare Read Poly texture structure ////////////////////////////*/
-	struct TextureTriangleCoord Triangle, *pTxt, *paus;    
-	pTxt=&Triangle; //pointer to struct
-	/*//////////////////////////////////////////////////////////////////////////////*/
-	int i,j,polygons;                
-	FILE* fp_dat;
+    /*//////////// Declare Read Poly texture structure //////////////////////////// */
+    struct TextureTriangleCoord Triangle, *pTxt, *paus;
 
-	
-	fp_dat=fopen(SchemeName,"r");
-	if (fp_dat==NULL){
-		printf("Could not read from <%s>", SchemeName);
+    pTxt = &Triangle;		//pointer to struct
+    /*////////////////////////////////////////////////////////////////////////////// */
+    int i, j, polygons;
+    FILE *fp_dat;
+
+
+    fp_dat = fopen(SchemeName, "r");
+    if (fp_dat == NULL) {
+	printf("Could not read from <%s>", SchemeName);
+    }
+
+    fscanf(fp_dat, "%d", numPoly);
+    polygons = *numPoly;
+
+    if (polygons == 0) {
+	pTxt = NULL;		/*break if no polygons */
+    }
+    else {
+	pTxt = (struct TextureTriangleCoord *)malloc(sizeof(struct TextureTriangleCoord));	/*first struct PolygonCoord */
+	fscanf(fp_dat, "%d", &pTxt->codeTexture);
+	fscanf(fp_dat, "%d", &pTxt->numVertex);
+
+	for (j = 0; j < (pTxt->numVertex); j++) {	//fill sand array with coord. polygons array        
+	    fscanf(fp_dat, "%f", &pTxt->xSand[j]);
 	}
-	
-	fscanf(fp_dat,"%d",numPoly);
-	polygons=*numPoly;
-	
-	if (polygons==0)	{
-		pTxt=NULL; /*break if no polygons*/
+	for (j = 0; j < (pTxt->numVertex); j++) {	//fill clay array with coord. polygons array          
+	    fscanf(fp_dat, "%f", &pTxt->yClay[j]);
 	}
-	else
-	{
-		pTxt=(struct TextureTriangleCoord *)malloc(sizeof(struct TextureTriangleCoord)); /*first struct PolygonCoord*/
-		fscanf(fp_dat,"%d",&pTxt->codeTexture);
-		fscanf(fp_dat,"%d",&pTxt->numVertex);
-		
-		for(j=0;j<(pTxt->numVertex);j++) {     //fill sand array with coord. polygons array        
-			fscanf(fp_dat,"%f",&pTxt->xSand[j]);
-		}		
-		for(j=0;j<(pTxt->numVertex);j++) {     //fill clay array with coord. polygons array          
-			fscanf(fp_dat,"%f",&pTxt->yClay[j]);
-		}	
-		paus=pTxt;
-				
-				  
-		for(i=2;i<=polygons;i++)	
-		{
-			paus->PointToNext=(struct TextureTriangleCoord *)malloc(sizeof(struct TextureTriangleCoord));	
-			paus=paus->PointToNext;
-			fscanf(fp_dat,"%d",&paus->codeTexture);
-			fscanf(fp_dat,"%d",&paus->numVertex); 
-			for(j=0;j<(paus->numVertex);j++) {     //fill sand array with coord. polygons array        
-				fscanf(fp_dat,"%f",&paus->xSand[j]); 	
-			}
-			for(j=0;j<(paus->numVertex);j++) {     //fill clay array with coord. polygons array          
-				fscanf(fp_dat,"%f",&paus->yClay[j]);
-			}                                                                           
-		}
-				
-		paus->PointToNext=NULL;	
+	paus = pTxt;
+
+
+	for (i = 2; i <= polygons; i++) {
+	    paus->PointToNext =
+		(struct TextureTriangleCoord *)
+		malloc(sizeof(struct TextureTriangleCoord));
+	    paus = paus->PointToNext;
+	    fscanf(fp_dat, "%d", &paus->codeTexture);
+	    fscanf(fp_dat, "%d", &paus->numVertex);
+	    for (j = 0; j < (paus->numVertex); j++) {	//fill sand array with coord. polygons array        
+		fscanf(fp_dat, "%f", &paus->xSand[j]);
+	    }
+	    for (j = 0; j < (paus->numVertex); j++) {	//fill clay array with coord. polygons array          
+		fscanf(fp_dat, "%f", &paus->yClay[j]);
+	    }
 	}
-	fclose (fp_dat);
-	return (pTxt);
+
+	paus->PointToNext = NULL;
+    }
+    fclose(fp_dat);
+    return (pTxt);
 }
 
 
-int ReadList(struct TextureTriangleCoord *pTxt, int  *numPoly,float SandVal, float ClayVal )
+int ReadList(struct TextureTriangleCoord *pTxt, int *numPoly, float SandVal,
+	     float ClayVal)
 {
-	int polygons,textureOUT;
-	textureOUT=0;
-	polygons=*numPoly;
-	while(pTxt!=NULL && textureOUT==0) {
-		textureOUT=DefineTexture (pTxt->numVertex, pTxt->xSand, pTxt->yClay, SandVal, ClayVal, pTxt->codeTexture);
-		pTxt=pTxt->PointToNext;
-	}
+    int polygons, textureOUT;
 
-	return textureOUT;
+    textureOUT = 0;
+    polygons = *numPoly;
+    while (pTxt != NULL && textureOUT == 0) {
+	textureOUT =
+	    DefineTexture(pTxt->numVertex, pTxt->xSand, pTxt->yClay, SandVal,
+			  ClayVal, pTxt->codeTexture);
+	pTxt = pTxt->PointToNext;
+    }
+
+    return textureOUT;
 }
 
 
-int DefineTexture (int numVert, float *xSand, float *yClay, float SandVal, float ClayVal, int codeTxt)   
+int DefineTexture(int numVert, float *xSand, float *yClay, float SandVal,
+		  float ClayVal, int codeTxt)
 {
-	int i, j, textureVER=0;
+    int i, j, textureVER = 0;
 
-	for (i = 0, j = numVert-1; i < numVert; j = i++) {
-		if ((((yClay[i] <= ClayVal) && (ClayVal < yClay[j])) || ((yClay[j] <= ClayVal) && (ClayVal < yClay[i]))) &&
-				     (SandVal < (xSand[j] - xSand[i]) * (ClayVal - yClay[i]) / (yClay[j] - yClay[i]) + xSand[i]))
-			textureVER = !textureVER;               
-	}
+    for (i = 0, j = numVert - 1; i < numVert; j = i++) {
+	if ((((yClay[i] <= ClayVal) && (ClayVal < yClay[j])) ||
+	     ((yClay[j] <= ClayVal) && (ClayVal < yClay[i]))) &&
+	    (SandVal <
+	     (xSand[j] - xSand[i]) * (ClayVal - yClay[i]) / (yClay[j] -
+							     yClay[i]) +
+	     xSand[i]))
+	    textureVER = !textureVER;
+    }
 
-	if (textureVER == 1)
-	{
-		textureVER=codeTxt;
-	}
-	else       {
-		textureVER=0;
-	}
-	return textureVER;
-           
-      
+    if (textureVER == 1) {
+	textureVER = codeTxt;
+    }
+    else {
+	textureVER = 0;
+    }
+    return textureVER;
+
+
 }
 
 
 
-void reclassTexture(char *SchemeName, char *result) /*reclass texture file with label in scheme file*/
+void reclassTexture(char *SchemeName, char *result)
+{				/*reclass texture file with label in scheme file */
 
-{
-	
-	int control,i;
-	char c,command[1024];
-	
+    int control, i;
+    char c, command[1024];
 
-	struct label_struct label, *plabel;
-	struct Categories pcats;
 
-	FILE* fp_dat;
-	fp_dat=fopen(SchemeName,"r");
+    struct label_struct label, *plabel;
+    struct Categories pcats;
 
-	plabel=&label;
+    FILE *fp_dat;
 
-	if (G_read_cats (result, G_mapset(), &pcats) < 0) /*read raster category file*/
-		G_fatal_error (("%s: %s in %s - can't read category file"),G_program_name(), result, G_mapset());
-	
-	if (fp_dat==NULL)
-	{
-		G_fatal_error(_("Could not open <%s>"), SchemeName);
-	}
+    fp_dat = fopen(SchemeName, "r");
 
-	fscanf(fp_dat,"%d",&control);
+    plabel = &label;
 
-	while(c!='#') 
-	{
-		fscanf(fp_dat,"%c",&c);
-	}
+    if (G_read_cats(result, G_mapset(), &pcats) < 0)	/*read raster category file */
+	G_fatal_error(("%s: %s in %s - can't read category file"),
+		      G_program_name(), result, G_mapset());
 
-	sprintf(command,"NULL");
-	G_set_cat(0, command,&pcats); /*set a category label. The label is copied into the cats structure for category n.*/
+    if (fp_dat == NULL) {
+	G_fatal_error(_("Could not open <%s>"), SchemeName);
+    }
 
+    fscanf(fp_dat, "%d", &control);
 
-	for(i=1;i<=control;i++)
-	{
-		fscanf(fp_dat,"%s",&plabel->etichetta);
-		sprintf(command,"%s",plabel->etichetta);
-		G_set_cat(i, command,&pcats);
-	}
+    while (c != '#') {
+	fscanf(fp_dat, "%c", &c);
+    }
 
-	G_write_cats(result,&pcats);
+    sprintf(command, "NULL");
+    G_set_cat(0, command, &pcats);	/*set a category label. The label is copied into the cats structure for category n. */
 
-	fclose (fp_dat);
-	/*return (0);*/
-}
 
+    for (i = 1; i <= control; i++) {
+	fscanf(fp_dat, "%s", &plabel->etichetta);
+	sprintf(command, "%s", plabel->etichetta);
+	G_set_cat(i, command, &pcats);
+    }
 
+    G_write_cats(result, &pcats);
 
-
+    fclose(fp_dat);
+    /*return (0); */
+}



More information about the grass-commit mailing list