Doxygen Source Code Documentation
vardata.h File Reference
Go to the source code of this file.
Defines | |
| #define | FILL_STRING "_" |
Functions | |
| int | vardata (const struct ncvar *, size_t[], int, int, const struct fspec *) |
Variables | |
| char * | progname |
Define Documentation
|
|
Definition at line 11 of file vardata.h. Referenced by printbval(), printdval(), printfval(), printival(), and printsval(). |
Function Documentation
|
||||||||||||||||||||||||
|
Definition at line 704 of file vardata.c. References fspec::brief_data_cmnts, fspec::data_lang, error(), get_fmt(), init_epsilons(), LANG_C, LANG_F, left, ncvar::name, NC_CHECK, nc_get_vara_double(), nc_get_vara_float(), nc_get_vara_int(), nc_get_vara_schar(), nc_get_vara_short(), nc_get_vara_text(), ncvar::ndims, pr_bvals(), pr_dvals(), pr_fvals(), pr_ivals(), pr_svals(), pr_tvals(), Printf, set_indent(), ncvar::type, and upcorner(). Referenced by do_ncdump().
00711 {
00712 size_t cor[NC_MAX_DIMS]; /* corner coordinates */
00713 size_t edg[NC_MAX_DIMS]; /* edges of hypercube */
00714 size_t add[NC_MAX_DIMS]; /* "odometer" increment to next "row" */
00715 #define VALBUFSIZ 1000
00716 double vals[VALBUFSIZ] ; /* aligned buffer */
00717
00718 int gulp = VALBUFSIZ;
00719
00720 int id;
00721 int ir;
00722 size_t nels;
00723 size_t ncols;
00724 size_t nrows;
00725 int vrank = vp->ndims;
00726 static int initeps = 0;
00727
00728 /* printf format used to print each value */
00729 char *fmt = get_fmt(ncid, varid, vp->type);
00730
00731 if (!initeps) { /* make sure epsilons get initialized */
00732 init_epsilons();
00733 initeps = 1;
00734 }
00735
00736 nels = 1;
00737 for (id = 0; id < vrank; id++) {
00738 cor[id] = 0;
00739 edg[id] = 1;
00740 nels *= vdims[id]; /* total number of values for variable */
00741 }
00742
00743 if (vrank <= 1) {
00744 Printf("\n %s = ", vp->name);
00745 set_indent ((int)strlen(vp->name) + 4);
00746 } else {
00747 Printf("\n %s =\n ", vp->name);
00748 set_indent (2);
00749 }
00750
00751 if (vrank < 1) {
00752 ncols = 1;
00753 } else {
00754 ncols = vdims[vrank-1]; /* size of "row" along last dimension */
00755 edg[vrank-1] = vdims[vrank-1];
00756 for (id = 0; id < vrank; id++)
00757 add[id] = 0;
00758 if (vrank > 1)
00759 add[vrank-2] = 1;
00760 }
00761 nrows = nels/ncols; /* number of "rows" */
00762
00763 for (ir = 0; ir < nrows; ir++) {
00764 /*
00765 * rather than just printing a whole row at once (which might exceed
00766 * the capacity of MSDOS platforms, for example), we break each row
00767 * into smaller chunks, if necessary.
00768 */
00769 size_t corsav;
00770 int left = (int)ncols;
00771 boolean lastrow;
00772
00773 if (vrank > 0) {
00774 corsav = cor[vrank-1];
00775 if (fsp->brief_data_cmnts != false
00776 && vrank > 1
00777 && left > 0) { /* print brief comment with indices range */
00778 Printf("// %s(",vp->name);
00779 switch (fsp->data_lang) {
00780 case LANG_C:
00781 /* print brief comment with C variable indices */
00782 for (id = 0; id < vrank-1; id++)
00783 Printf("%lu,", (unsigned long)cor[id]);
00784 if (vdims[vrank-1] == 1)
00785 Printf("0");
00786 else
00787 Printf(" 0-%lu", (unsigned long)vdims[vrank-1]-1);
00788 break;
00789 case LANG_F:
00790 /* print brief comment with Fortran variable indices */
00791 if (vdims[vrank-1] == 1)
00792 Printf("1");
00793 else
00794 Printf("1-%lu ", (unsigned long)vdims[vrank-1]);
00795 for (id = vrank-2; id >=0 ; id--) {
00796 Printf(",%lu", (unsigned long)(1 + cor[id]));
00797 }
00798 break;
00799 }
00800 Printf(")\n ");
00801 set_indent(4);
00802 }
00803 }
00804 lastrow = (boolean)(ir == nrows-1);
00805 while (left > 0) {
00806 size_t toget = left < gulp ? left : gulp;
00807 if (vrank > 0)
00808 edg[vrank-1] = toget;
00809 switch(vp->type) {
00810 case NC_CHAR:
00811 NC_CHECK(
00812 nc_get_vara_text(ncid, varid, cor, edg, (char *)vals) );
00813 pr_tvals(vp, toget, fmt, left > toget, lastrow,
00814 (char *) vals, fsp, cor);
00815 break;
00816 case NC_BYTE:
00817 NC_CHECK(
00818 nc_get_vara_schar(ncid, varid, cor, edg, (signed char *)vals) );
00819 pr_bvals(vp, toget, fmt, left > toget, lastrow,
00820 (signed char *) vals, fsp, cor);
00821 break;
00822 case NC_SHORT:
00823 NC_CHECK(
00824 nc_get_vara_short(ncid, varid, cor, edg, (short *)vals) );
00825 pr_svals(vp, toget, fmt, left > toget, lastrow,
00826 (short *) vals, fsp, cor);
00827 break;
00828 case NC_INT:
00829 NC_CHECK(
00830 nc_get_vara_int(ncid, varid, cor, edg, (int *)vals) );
00831 pr_ivals(vp, toget, fmt, left > toget, lastrow,
00832 (int *) vals, fsp, cor);
00833 break;
00834 case NC_FLOAT:
00835 NC_CHECK(
00836 nc_get_vara_float(ncid, varid, cor, edg, (float *)vals) );
00837 pr_fvals(vp, toget, fmt, left > toget, lastrow,
00838 (float *) vals, fsp, cor);
00839 break;
00840 case NC_DOUBLE:
00841 NC_CHECK(
00842 nc_get_vara_double(ncid, varid, cor, edg, (double *)vals) );
00843 pr_dvals(vp, toget, fmt, left > toget, lastrow,
00844 (double *) vals, fsp, cor);
00845 break;
00846 default:
00847 error("vardata: bad type");
00848 }
00849 left -= toget;
00850 if (vrank > 0)
00851 cor[vrank-1] += toget;
00852 }
00853 if (vrank > 0)
00854 cor[vrank-1] = corsav;
00855 if (ir < nrows-1)
00856 if (!upcorner(vdims,vp->ndims,cor,add))
00857 error("vardata: odometer overflowed!");
00858 set_indent(2);
00859 }
00860
00861 return 0;
00862 }
|
Variable Documentation
|
|
|