Skip to content

Commit

Permalink
Modified index passed for last row when printing with annotations, in…
Browse files Browse the repository at this point in the history
… support of fixing #181
  • Loading branch information
WardF committed Dec 31, 2015
1 parent 6e8176f commit ac9f02d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 35 deletions.
9 changes: 7 additions & 2 deletions gdb.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
break main
break do_ncdump
break annotate
break vardata.c:310 if 'vp->name == "land_tile_fractions"'
break vardata.c:484quit
break vardata.c:308
command
print cor[vrank-1]+iel+1
end


run -f f -v land_tile_fractions gh181_check_me_out.nc
66 changes: 33 additions & 33 deletions ncdump/vardata.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ set_max_len(int len) {
}


/*
/*
* Output a string that should not be split across lines. If it would
* make current line too long, first output a newline and current
* (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.
*/
void
Expand Down Expand Up @@ -98,19 +98,19 @@ lput2(
/* chars); saved between calls */
int len_prefix = strlen (CDL_COMMENT_PREFIX);
bool_t make_newline;

size_t len1 = strlen(cp); /* length of input string */

assert (len1 > 0);

/* (1) Single space or newline/indent sequence, as needed. */

linep = linep + 1 + len1; /* new line position, without newline */
/* add 1 extra for preceding space */

make_newline = (wrap && (first_item || linep > max_line_len + 2));
/* NEVER new line in no-wrap mode */

if (make_newline) { /* start new line, if needed */
printf ("\n");
indent_out(); /* same exact indentation as pr_att */
Expand Down Expand Up @@ -164,8 +164,8 @@ print_any_val(
const void *valp /* pointer to the value */
)
{
if (varp->has_fillval &&
(*(varp->tinfo->val_equals))((const nctype_t *)varp->tinfo,
if (varp->has_fillval &&
(*(varp->tinfo->val_equals))((const nctype_t *)varp->tinfo,
(const void*)varp->fillvalp, valp) ) {
sbuf_cpy(sb, FILL_STRING);
} else {
Expand Down Expand Up @@ -235,15 +235,15 @@ pr_any_att_vals(
sbuf_free(sb);
}

/*
/*
* Prints brief annotation for a row of data values
*/
static void
annotate_brief(
const ncvar_t *vp, /* variable */
const size_t *cor, /* corner coordinates */
size_t vdims[] /* variable dimension sizes */
)
)
{
int vrank = vp->ndims;
int id;
Expand Down Expand Up @@ -290,7 +290,7 @@ annotate(
{
int vrank = vp->ndims;
int id;

/* print indices according to data_lang */
/* printf(" // %s(", vp->name); */
printf(" // ");
Expand Down Expand Up @@ -409,15 +409,15 @@ upcorner(
return ret;
}

/* Print data values for variable varid.
/* Print data values for variable varid.
*
* Recursive to handle possibility of variables with multiple
* unlimited dimensions, for which the CDL syntax requires use of "{"
* and "}" in data section to disambiguate the size of nested records
* in a simple linear list of values.
*/
static int
print_rows(
print_rows(
int level, /* 0 at top-level, incremented for each recursive level */
int ncid, /* netcdf id */
int varid, /* variable id */
Expand All @@ -427,7 +427,7 @@ print_rows(
size_t edg[], /* edges of hypercube */
void *vals, /* allocated buffer for ncols values in a row */
int marks_pending /* number of pending closing "}" record markers */
)
)
{
int rank = vp->ndims;
size_t ncols = rank > 0 ? vdims[rank - 1] : 1; /* number of values in a row */
Expand Down Expand Up @@ -455,11 +455,11 @@ print_rows(
local_cor[level] = 0;
local_edg[level] = 1;
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[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);
free(local_edg);
free(local_cor);
Expand Down Expand Up @@ -492,25 +492,25 @@ print_rows(
/* determine if this is the last row */
lastrow = true;
for(j = 0; j < rank - 1; j++) {
if (cor[j] != vdims[j] - 1) {
if (cor[j] != vdims[j] - 1) {
lastrow = false;
break;
}
}
}
if (formatting_specs.full_data_cmnts) {
for (j = 0; j < marks_pending; j++) {
for (j = 0; j < marks_pending; j++) {
sbuf_cat(sb, "}");
}
printf("%s", sbuf_str(sb));
lastdelim (0, lastrow);
annotate (vp, cor, d0);
}
printf("%s", sbuf_str(sb));
lastdelim (0, lastrow);
annotate (vp, cor, d0-1);
} else {
for (j = 0; j < marks_pending; j++) {
for (j = 0; j < marks_pending; j++) {
sbuf_cat(sb, "}");
}
lput(sbuf_str(sb));
lastdelim2 (0, lastrow);
}
}
lput(sbuf_str(sb));
lastdelim2 (0, lastrow);
}
}
sbuf_free(sb);
return NC_NOERR;
Expand Down Expand Up @@ -578,7 +578,7 @@ vardata(
}
nrows = nels/ncols; /* number of "rows" */
vals = emalloc(ncols * vp->tinfo->size);

NC_CHECK(print_rows(level, ncid, varid, vp, vdims, cor, edg, vals, marks_pending));
free(vals);
free(cor);
Expand Down Expand Up @@ -753,7 +753,7 @@ vardatax(
}
nrows = nels/ncols; /* number of "rows" */
vals = emalloc(ncols * vp->tinfo->size);

for (ir = 0; ir < nrows; ir++) {
size_t corsav = 0;
bool_t lastrow;
Expand All @@ -767,16 +767,16 @@ vardatax(
edg[vrank-1] = ncols;
NC_CHECK(nc_get_vara(ncid, varid, cor, edg, vals) );
/* 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,""))) {
pr_tvalsx(vp, ncols, 0, lastrow, (char *) vals);
} else {
pr_any_valsx(vp, ncols, 0, lastrow, vals);
}

if (vrank > 0)
cor[vrank-1] += ncols;

if (vrank > 0)
cor[vrank-1] = corsav;
if (ir < nrows-1)
Expand Down

0 comments on commit ac9f02d

Please sign in to comment.