mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-30 16:10:44 +08:00
Modified index passed for last row when printing with annotations, in support of fixing https://github.com/Unidata/netcdf-c/issues/181
This commit is contained in:
parent
6e8176f1ab
commit
ac9f02d01a
9
gdb.txt
9
gdb.txt
@ -1,5 +1,10 @@
|
|||||||
break main
|
break main
|
||||||
break do_ncdump
|
break do_ncdump
|
||||||
break annotate
|
break vardata.c:484quit
|
||||||
break vardata.c:310 if 'vp->name == "land_tile_fractions"'
|
break vardata.c:308
|
||||||
|
command
|
||||||
|
print cor[vrank-1]+iel+1
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
run -f f -v land_tile_fractions gh181_check_me_out.nc
|
run -f f -v land_tile_fractions gh181_check_me_out.nc
|
||||||
|
@ -46,11 +46,11 @@ set_max_len(int len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Output a string that should not be split across lines. If it would
|
* Output a string that should not be split across lines. If it would
|
||||||
* make current line too long, first output a newline and current
|
* make current line too long, first output a newline and current
|
||||||
* (nested group) indentation, then continuation indentation, then
|
* (nested group) indentation, then continuation indentation, then
|
||||||
* output string. If string ends with a newline to force short line,
|
* output string. If string ends with a newline to force short line,
|
||||||
* reset indentation after output.
|
* reset indentation after output.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
@ -98,19 +98,19 @@ lput2(
|
|||||||
/* chars); saved between calls */
|
/* chars); saved between calls */
|
||||||
int len_prefix = strlen (CDL_COMMENT_PREFIX);
|
int len_prefix = strlen (CDL_COMMENT_PREFIX);
|
||||||
bool_t make_newline;
|
bool_t make_newline;
|
||||||
|
|
||||||
size_t len1 = strlen(cp); /* length of input string */
|
size_t len1 = strlen(cp); /* length of input string */
|
||||||
|
|
||||||
assert (len1 > 0);
|
assert (len1 > 0);
|
||||||
|
|
||||||
/* (1) Single space or newline/indent sequence, as needed. */
|
/* (1) Single space or newline/indent sequence, as needed. */
|
||||||
|
|
||||||
linep = linep + 1 + len1; /* new line position, without newline */
|
linep = linep + 1 + len1; /* new line position, without newline */
|
||||||
/* add 1 extra for preceding space */
|
/* add 1 extra for preceding space */
|
||||||
|
|
||||||
make_newline = (wrap && (first_item || linep > max_line_len + 2));
|
make_newline = (wrap && (first_item || linep > max_line_len + 2));
|
||||||
/* NEVER new line in no-wrap mode */
|
/* NEVER new line in no-wrap mode */
|
||||||
|
|
||||||
if (make_newline) { /* start new line, if needed */
|
if (make_newline) { /* start new line, if needed */
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
indent_out(); /* same exact indentation as pr_att */
|
indent_out(); /* same exact indentation as pr_att */
|
||||||
@ -164,8 +164,8 @@ print_any_val(
|
|||||||
const void *valp /* pointer to the value */
|
const void *valp /* pointer to the value */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (varp->has_fillval &&
|
if (varp->has_fillval &&
|
||||||
(*(varp->tinfo->val_equals))((const nctype_t *)varp->tinfo,
|
(*(varp->tinfo->val_equals))((const nctype_t *)varp->tinfo,
|
||||||
(const void*)varp->fillvalp, valp) ) {
|
(const void*)varp->fillvalp, valp) ) {
|
||||||
sbuf_cpy(sb, FILL_STRING);
|
sbuf_cpy(sb, FILL_STRING);
|
||||||
} else {
|
} else {
|
||||||
@ -235,7 +235,7 @@ pr_any_att_vals(
|
|||||||
sbuf_free(sb);
|
sbuf_free(sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prints brief annotation for a row of data values
|
* Prints brief annotation for a row of data values
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
@ -243,7 +243,7 @@ annotate_brief(
|
|||||||
const ncvar_t *vp, /* variable */
|
const ncvar_t *vp, /* variable */
|
||||||
const size_t *cor, /* corner coordinates */
|
const size_t *cor, /* corner coordinates */
|
||||||
size_t vdims[] /* variable dimension sizes */
|
size_t vdims[] /* variable dimension sizes */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int vrank = vp->ndims;
|
int vrank = vp->ndims;
|
||||||
int id;
|
int id;
|
||||||
@ -290,7 +290,7 @@ annotate(
|
|||||||
{
|
{
|
||||||
int vrank = vp->ndims;
|
int vrank = vp->ndims;
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
/* print indices according to data_lang */
|
/* print indices according to data_lang */
|
||||||
/* printf(" // %s(", vp->name); */
|
/* printf(" // %s(", vp->name); */
|
||||||
printf(" // ");
|
printf(" // ");
|
||||||
@ -409,7 +409,7 @@ upcorner(
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print data values for variable varid.
|
/* Print data values for variable varid.
|
||||||
*
|
*
|
||||||
* Recursive to handle possibility of variables with multiple
|
* Recursive to handle possibility of variables with multiple
|
||||||
* unlimited dimensions, for which the CDL syntax requires use of "{"
|
* unlimited dimensions, for which the CDL syntax requires use of "{"
|
||||||
@ -417,7 +417,7 @@ upcorner(
|
|||||||
* in a simple linear list of values.
|
* in a simple linear list of values.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
print_rows(
|
print_rows(
|
||||||
int level, /* 0 at top-level, incremented for each recursive level */
|
int level, /* 0 at top-level, incremented for each recursive level */
|
||||||
int ncid, /* netcdf id */
|
int ncid, /* netcdf id */
|
||||||
int varid, /* variable id */
|
int varid, /* variable id */
|
||||||
@ -427,7 +427,7 @@ print_rows(
|
|||||||
size_t edg[], /* edges of hypercube */
|
size_t edg[], /* edges of hypercube */
|
||||||
void *vals, /* allocated buffer for ncols values in a row */
|
void *vals, /* allocated buffer for ncols values in a row */
|
||||||
int marks_pending /* number of pending closing "}" record markers */
|
int marks_pending /* number of pending closing "}" record markers */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int rank = vp->ndims;
|
int rank = vp->ndims;
|
||||||
size_t ncols = rank > 0 ? vdims[rank - 1] : 1; /* number of values in a row */
|
size_t ncols = rank > 0 ? vdims[rank - 1] : 1; /* number of values in a row */
|
||||||
@ -455,11 +455,11 @@ print_rows(
|
|||||||
local_cor[level] = 0;
|
local_cor[level] = 0;
|
||||||
local_edg[level] = 1;
|
local_edg[level] = 1;
|
||||||
for(i = 0; i < d0 - 1; i++) {
|
for(i = 0; i < d0 - 1; i++) {
|
||||||
print_rows(level + 1, ncid, varid, vp, vdims,
|
print_rows(level + 1, ncid, varid, vp, vdims,
|
||||||
local_cor, local_edg, vals, 0);
|
local_cor, local_edg, vals, 0);
|
||||||
local_cor[level] += 1;
|
local_cor[level] += 1;
|
||||||
}
|
}
|
||||||
print_rows(level + 1, ncid, varid, vp, vdims,
|
print_rows(level + 1, ncid, varid, vp, vdims,
|
||||||
local_cor, local_edg, vals, marks_pending);
|
local_cor, local_edg, vals, marks_pending);
|
||||||
free(local_edg);
|
free(local_edg);
|
||||||
free(local_cor);
|
free(local_cor);
|
||||||
@ -492,25 +492,25 @@ print_rows(
|
|||||||
/* determine if this is the last row */
|
/* determine if this is the last row */
|
||||||
lastrow = true;
|
lastrow = true;
|
||||||
for(j = 0; j < rank - 1; j++) {
|
for(j = 0; j < rank - 1; j++) {
|
||||||
if (cor[j] != vdims[j] - 1) {
|
if (cor[j] != vdims[j] - 1) {
|
||||||
lastrow = false;
|
lastrow = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (formatting_specs.full_data_cmnts) {
|
if (formatting_specs.full_data_cmnts) {
|
||||||
for (j = 0; j < marks_pending; j++) {
|
for (j = 0; j < marks_pending; j++) {
|
||||||
sbuf_cat(sb, "}");
|
sbuf_cat(sb, "}");
|
||||||
}
|
}
|
||||||
printf("%s", sbuf_str(sb));
|
printf("%s", sbuf_str(sb));
|
||||||
lastdelim (0, lastrow);
|
lastdelim (0, lastrow);
|
||||||
annotate (vp, cor, d0);
|
annotate (vp, cor, d0-1);
|
||||||
} else {
|
} else {
|
||||||
for (j = 0; j < marks_pending; j++) {
|
for (j = 0; j < marks_pending; j++) {
|
||||||
sbuf_cat(sb, "}");
|
sbuf_cat(sb, "}");
|
||||||
}
|
}
|
||||||
lput(sbuf_str(sb));
|
lput(sbuf_str(sb));
|
||||||
lastdelim2 (0, lastrow);
|
lastdelim2 (0, lastrow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sbuf_free(sb);
|
sbuf_free(sb);
|
||||||
return NC_NOERR;
|
return NC_NOERR;
|
||||||
@ -578,7 +578,7 @@ vardata(
|
|||||||
}
|
}
|
||||||
nrows = nels/ncols; /* number of "rows" */
|
nrows = nels/ncols; /* number of "rows" */
|
||||||
vals = emalloc(ncols * vp->tinfo->size);
|
vals = emalloc(ncols * vp->tinfo->size);
|
||||||
|
|
||||||
NC_CHECK(print_rows(level, ncid, varid, vp, vdims, cor, edg, vals, marks_pending));
|
NC_CHECK(print_rows(level, ncid, varid, vp, vdims, cor, edg, vals, marks_pending));
|
||||||
free(vals);
|
free(vals);
|
||||||
free(cor);
|
free(cor);
|
||||||
@ -753,7 +753,7 @@ vardatax(
|
|||||||
}
|
}
|
||||||
nrows = nels/ncols; /* number of "rows" */
|
nrows = nels/ncols; /* number of "rows" */
|
||||||
vals = emalloc(ncols * vp->tinfo->size);
|
vals = emalloc(ncols * vp->tinfo->size);
|
||||||
|
|
||||||
for (ir = 0; ir < nrows; ir++) {
|
for (ir = 0; ir < nrows; ir++) {
|
||||||
size_t corsav = 0;
|
size_t corsav = 0;
|
||||||
bool_t lastrow;
|
bool_t lastrow;
|
||||||
@ -767,16 +767,16 @@ vardatax(
|
|||||||
edg[vrank-1] = ncols;
|
edg[vrank-1] = ncols;
|
||||||
NC_CHECK(nc_get_vara(ncid, varid, cor, edg, vals) );
|
NC_CHECK(nc_get_vara(ncid, varid, cor, edg, vals) );
|
||||||
/* Test if we should treat array of chars as a string */
|
/* Test if we should treat array of chars as a string */
|
||||||
if(vp->type == NC_CHAR &&
|
if(vp->type == NC_CHAR &&
|
||||||
(vp->fmt == 0 || STREQ(vp->fmt,"%s") || STREQ(vp->fmt,""))) {
|
(vp->fmt == 0 || STREQ(vp->fmt,"%s") || STREQ(vp->fmt,""))) {
|
||||||
pr_tvalsx(vp, ncols, 0, lastrow, (char *) vals);
|
pr_tvalsx(vp, ncols, 0, lastrow, (char *) vals);
|
||||||
} else {
|
} else {
|
||||||
pr_any_valsx(vp, ncols, 0, lastrow, vals);
|
pr_any_valsx(vp, ncols, 0, lastrow, vals);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vrank > 0)
|
if (vrank > 0)
|
||||||
cor[vrank-1] += ncols;
|
cor[vrank-1] += ncols;
|
||||||
|
|
||||||
if (vrank > 0)
|
if (vrank > 0)
|
||||||
cor[vrank-1] = corsav;
|
cor[vrank-1] = corsav;
|
||||||
if (ir < nrows-1)
|
if (ir < nrows-1)
|
||||||
|
Loading…
Reference in New Issue
Block a user