[GRASS-dev] [GRASS GIS] #1302: r.out.ascii with "-m" (MODFLOW) option produce larger fields for negative values

GRASS GIS trac at osgeo.org
Wed Mar 9 08:32:20 EST 2011


#1302: r.out.ascii with "-m" (MODFLOW) option produce larger fields for negative
values
--------------------+-------------------------------------------------------
 Reporter:  vargay  |       Owner:  grass-dev@…              
     Type:  defect  |      Status:  new                      
 Priority:  normal  |   Milestone:  6.4.1                    
Component:  Raster  |     Version:  6.4.0                    
 Keywords:          |    Platform:  MSWindows XP             
      Cpu:  x86-32  |  
--------------------+-------------------------------------------------------
 Hi,

 The  r.out.ascii  with "-m" (MODFLOW) option produce larger fields for
 negative values.


 The error is probabely due to the format specification in the   fprintf
 statements in the file   formspecific.c:

 ******************************************************************
 /* write MODFLOW ASCII ARRAY */
 int write_MODFLOW(int fd,
                   FILE * fp,
                   int nrows, int ncols, int out_type, int dp, int width)

 ******

             else if (out_type == FCELL_TYPE) {
                 if (G_is_null_value(ptr, out_type))
                     *((FCELL *) ptr) = 0;
                 fprintf(fp, "%*.*e", dp + 6, dp - 1, *((FCELL *) ptr));
             }
             else if (out_type == DCELL_TYPE) {
                 if (G_is_null_value(ptr, out_type))
                     *((DCELL *) ptr) = 0;
                 fprintf(fp, "%*.*e", dp + 6, dp - 1, *((DCELL *) ptr));
             }
 ******************************************************************


 For demonstrating the problem, see the next simple test program
 (I use MINGW gcc 4.5.2 for compiling):

 ******************************************************************
 #include <stdio.h>
 void main(void) {
  int dp, i;
  double DCELL;
  dp = 5;

  DCELL = 125.55;
  printf("\n[");
  for(i=0;i<5;i++) printf("%*.*e", dp + 6, dp - 1, DCELL);
  printf("]");

  DCELL = -125.55;
  printf("\n[");
  for(i=0;i<5;i++) printf("%*.*e", dp + 6, dp - 1, DCELL);
  printf("]\n");
 }
 ******************************************************************

 Running the above test  program, the result is:

 [1.2555e+0021.2555e+0021.2555e+0021.2555e+0021.2555e+002]
 [-1.2555e+002-1.2555e+002-1.2555e+002-1.2555e+002-1.2555e+002]

 Changing the format specification as follow:

     printf("%*.*e", dp + 7, dp - 1, DCELL);

 the result became suitable:

 [ 1.2555e+002 1.2555e+002 1.2555e+002 1.2555e+002 1.2555e+002]
 [-1.2555e+002-1.2555e+002-1.2555e+002-1.2555e+002-1.2555e+002]


 Sincerely   Zoltan

-- 
Ticket URL: <http://trac.osgeo.org/grass/ticket/1302>
GRASS GIS <http://grass.osgeo.org>



More information about the grass-dev mailing list