Opened 13 years ago

Last modified 8 years ago

#1302 new defect

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

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

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 (0)

Note: See TracTickets for help on using tickets.