[GRASS-SVN] r30870 - grass/branches/releasebranch_6_3/raster/r.in.mat

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Apr 5 11:06:45 EDT 2008


Author: hamish
Date: 2008-04-05 11:06:45 -0400 (Sat, 05 Apr 2008)
New Revision: 30870

Modified:
   grass/branches/releasebranch_6_3/raster/r.in.mat/main.c
Log:
backport fixes from HEAD (including 64bit support- trac bug #22)

Modified: grass/branches/releasebranch_6_3/raster/r.in.mat/main.c
===================================================================
--- grass/branches/releasebranch_6_3/raster/r.in.mat/main.c	2008-04-05 14:57:41 UTC (rev 30869)
+++ grass/branches/releasebranch_6_3/raster/r.in.mat/main.c	2008-04-05 15:06:45 UTC (rev 30870)
@@ -52,20 +52,20 @@
     int machine_endianness, file_endianness, endian_mismatch;  /* 0=little, 1=big */
     int data_format; /* 0=double  1=float  2=32bit signed int  5=8bit unsigned int (ie text) */
     int data_type;   /* 0=numbers  1=text */
-    long format_block;  /* combo of endianness, 0, data_format, and type */
-    static long realflag = 0;  /* 0=only real values used */
+    int format_block;  /* combo of endianness, 0, data_format, and type */
+    int realflag = 0;  /* 0=only real values used */
     /* should type be specifically uint32 ??? */
 
-    char array_name[65];
+    char array_name[65];  /* 65 = 64 + null-terminator */
     int name_len;
-    long mrows, ncols;  /* text/data/map array dimensions*/
+    int mrows, ncols;  /* text/data/map array dimensions*/
 
     int *pval_i;	/* for misc use */
     float *pval_f;	/* for misc use */
     double *pval_d;	/* for misc use */
     char c, *buff;	/* for misc use */
 
-    char map_name[65], map_title[1024];
+    char map_name[65], map_title[1024];  /* 65 = 64 + null-terminator */
     double map_name_d[1024];  /* I'm not sure why you'd save char strings as double, but whatever */
 
     int have_name, have_data, have_title, have_n, have_s, have_e, have_w;
@@ -77,10 +77,7 @@
     struct History history;
 
     struct Option *inputfile, *outputfile;
-
-    /* please, remove before GRASS 7 released */
-    struct Flag *verbose;
-
+    struct Flag *verbose; /* remove for GRASS 7 */
     struct GModule *module;
 
     int cf;
@@ -106,7 +103,7 @@
     outputfile = G_define_option() ;
     outputfile->key	= "output";
     outputfile->type       = TYPE_STRING;
-    outputfile->required   = YES;
+    outputfile->required   = NO;
     outputfile->gisprompt  = "new,cell,raster" ;
     outputfile->description= _("Name for the output raster map (override)");
 
@@ -120,6 +117,12 @@
 	exit(EXIT_FAILURE);
 
 
+    /* remove for GRASS 7  */
+    if(verbose->answer) {
+	putenv("GRASS_VERBOSE=3");
+	G_warning(_("The '-v' flag is superseded and will be removed "
+		    "in future. Please use '--verbose' instead."));
+    }
 
   /******  SETUP  ****************************************************/
     /* Check Endian State of Host Computer*/
@@ -141,7 +144,7 @@
     have_n = have_s = have_e = have_w = 0;
 
     /* Check Endian State of File */
-    fread(&format_block, sizeof(long), 1, fp1);
+    fread(&format_block, sizeof(int), 1, fp1);
     fseek(fp1, 0, SEEK_SET);  /* frewind() */
 
     file_endianness = format_block / 1000;  /* 0=little, 1=big */
@@ -158,12 +161,12 @@
 
 
   /******  READ MAP  ****************************************************/
-    G_message(_("Reading MAT-File..."));
+    G_verbose_message(_("Reading MAT-File..."));
 
     while (!feof(fp1)) {
 
 	/* scan for needed array variables */
-	fread(&format_block, sizeof(long), 1, fp1);
+	fread(&format_block, sizeof(int), 1, fp1);
 
 	if(feof(fp1))
 	    break;
@@ -181,19 +184,19 @@
 
 
 	/* 4 byte number of rows & columns */
-	fread(&mrows, sizeof(long), 1, fp1);
-	fread(&ncols, sizeof(long), 1, fp1);
+	fread(&mrows, sizeof(int), 1, fp1);
+	fread(&ncols, sizeof(int), 1, fp1);
 	if(mrows < 1 || ncols < 1)
 	    G_fatal_error(_("Array contains no data"));
 
 	/* 4 byte real/imag flag   0=real vals only */
-	fread(&realflag, sizeof(long), 1, fp1);
+	fread(&realflag, sizeof(int), 1, fp1);
 	if(realflag != 0)
 	    G_fatal_error(_("Array contains imaginary data"));
 
 
 	/* length of array_name+1 */
-	fread(&name_len, sizeof(long), 1, fp1);
+	fread(&name_len, sizeof(int), 1, fp1);
 	if(name_len < 1)
 	    G_fatal_error(_("Invalid array name"));
 
@@ -205,11 +208,11 @@
 	}
 
 	G_debug(3, "array name     = [%s]", array_name);
-	G_debug(3, "  format block = [%04ld]", format_block);
+	G_debug(3, "  format block = [%04d]", format_block);
 	G_debug(3, "  data format  = [%d]", data_format);
 	G_debug(3, "  data type    = [%d]", data_type);
-	G_debug(3, "  rows         = [%ld]", mrows);
-	G_debug(3, "  cols         = [%ld]", ncols);
+	G_debug(3, "  rows         = [%d]", mrows);
+	G_debug(3, "  cols         = [%d]", ncols);
 
 	if(strcmp(array_name, "map_name") == 0) {
 	    have_name = 1;
@@ -314,7 +317,7 @@
 	} /* endif map_data */
 
 	else {
-	    G_warning(_("Skipping unknown array '%s'"), array_name);
+	    G_important_message(_("Skipping unknown array '%s'"), array_name);
 	    switch (data_format) {
 	    /*   0=double	1=float   2=32bit signed int   5=8bit unsigned int(text)   */
 	      case 0: 
@@ -333,7 +336,7 @@
 	    }
 	}
 
-	G_debug(3, "Read array '%s' [%ld,%ld] format=%d type=%d\n", 
+	G_debug(3, "Read array '%s' [%d,%d] format=%d type=%d\n", 
 	    array_name, ncols, mrows, data_format, data_type);
 
     } /* while !EOF */
@@ -345,8 +348,25 @@
 
 
     /* set map name */
-    strncpy(map_name, outfile, 61);
-    
+    if(have_name) {
+	if(outfile) {
+	    if( 0 != strcmp(outfile, map_name) )
+		G_message(_("Setting map name to <%s> which overrides <%s>"),
+			outfile, map_name);
+	    strncpy(map_name, outfile, 61);
+	}
+    }
+    else {
+	if(outfile) {
+	    G_verbose_message(_("Setting map name to <%s>"), outfile);
+	    strncpy(map_name, outfile, 61);
+	}
+	else {
+	    G_message(_("No 'map_name' array found; using <MatFile>"));
+	    strcpy(map_name, "MatFile");
+	}
+    }
+
     G_strip(map_name);  /* remove leading and trailing whitespace */
     if(G_legal_filename(map_name) != 1)
 	G_fatal_error(_("<%s> is an illegal file name"), map_name);
@@ -373,20 +393,27 @@
     if(buff)  G_fatal_error(buff);
     G_set_window(&region);
 
-    /* please, remove before GRASS 7 released */
-    if(verbose->answer) 
-        G_warning(_("The '-v' flag is superseded and will be removed "
-                    "in future. Please use '--verbose' instead."));
-    
+    G_verbose_message("");
+    G_verbose_message(_("Map <%s> bounds set to:"), map_name);
+    G_verbose_message(_("northern edge=%f"), region.north);
+    G_verbose_message(_("southern edge=%f"), region.south);
+    G_verbose_message(_("eastern edge=%f"), region.east);
+    G_verbose_message(_("western edge=%f"), region.west);
+    G_verbose_message(_("nsres=%f"), region.ns_res);
+    G_verbose_message(_("ewres=%f"), region.ew_res);
+    G_verbose_message(_("rows=%d"), region.rows);
+    G_verbose_message(_("cols=%d"), region.cols);
+    G_verbose_message("");
+
     /* prep memory */
-    raster =  G_allocate_raster_buf(map_type);
+    raster = G_allocate_raster_buf(map_type);
 
     cf = G_open_raster_new(map_name, map_type);
     if (cf < 0)
-	G_fatal_error (_("Unable to create raster map <%s>"), outfile);
+	G_fatal_error(_("Unable to create raster map <%s>"), outfile);
 
     /* write new raster map*/
-    G_message(_("Writing new raster map..."));
+    G_verbose_message(_("Writing new raster map..."));
 
     mrows = region.rows;
     ncols = region.cols;
@@ -436,7 +463,7 @@
 
 	if( 1 != G_put_raster_row(cf, raster, map_type) ) {
 	    G_close_cell(cf);
-	    G_fatal_error(_("Failed writing raster map <%s> row %d"), raster, row);
+	    G_fatal_error(_("Writing raster map, row %d"), row);
 	}
 
  	G_percent(row, mrows, 5);
@@ -459,7 +486,9 @@
     G_command_history(&history);
     G_write_history(map_name, &history);
 
-    return 0;
+    G_done_msg("");
+
+    exit(EXIT_SUCCESS);
 }
 
 



More information about the grass-commit mailing list