Opened 14 years ago

Last modified 9 years ago

#1302 new defect

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

Reported by: vargay Owned by: grass-dev@…
Priority: normal Milestone: 6.4.6
Component: Raster Version: 6.4.0
Keywords: r.out.ascii Cc:
CPU: x86-32 Platform: MSWindows XP

Description (last modified by neteler)

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

Change History (3)

comment:1 by martinl, 14 years ago

Keywords: r.out.ascii added

comment:2 by neteler, 12 years ago

Description: modified (diff)
Milestone: 6.4.16.4.4

comment:3 by neteler, 9 years ago

Milestone: 6.4.46.4.6
Note: See TracTickets for help on using tickets.