[GRASS-dev] [GRASS GIS] #1302: r.out.ascii with "-m" (MODFLOW) option produce larger fields for negative values
GRASS GIS
trac at osgeo.org
Mon Aug 20 15:16:57 PDT 2012
#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.4
Component: Raster | Version: 6.4.0
Keywords: r.out.ascii | Platform: MSWindows XP
Cpu: x86-32 |
-------------------------+--------------------------------------------------
Changes (by neteler):
* milestone: 6.4.1 => 6.4.4
Old 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
New 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
--
--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1302#comment:2>
GRASS GIS <http://grass.osgeo.org>
More information about the grass-dev
mailing list