48 #include <sys/types.h>
52 #include <configure.hpp>
68 char varname[MAX_NC_VARS][MAX_NC_NAME];
69 nc_type datatype[MAX_NC_VARS];
70 int varndims[MAX_NC_VARS];
71 int vardim[MAX_NC_VARS][MAX_NC_DIMS];
72 int natts[MAX_NC_VARS];
73 unsigned char vardecomp[MAX_NC_VARS];
74 char dimname[MAX_NC_DIMS][MAX_NC_NAME];
75 long dimsize[MAX_NC_DIMS];
76 long dimfullsize[MAX_NC_DIMS];
77 long dimstart[MAX_NC_DIMS];
78 long dimend[MAX_NC_DIMS];
79 unsigned char varmiss[MAX_NC_VARS];
80 unsigned char varmissval[MAX_NC_VARS][8];
85 int process_file(
char *,
unsigned char,
struct fileinfo *,
char *,
int *,
int *,
86 int,
int,
void *[],
int,
unsigned char,
unsigned char);
87 int process_vars(
struct fileinfo *,
struct fileinfo *,
unsigned char,
int *,
88 int,
int,
int,
void *[],
unsigned char,
unsigned char);
89 int flush_decomp(
struct fileinfo *,
int,
int,
void *[],
unsigned char);
90 void print_debug(
struct fileinfo *,
unsigned char);
91 char *nc_type_to_str(nc_type);
93 static unsigned char _first_;
96 unsigned char verbose = 0;
97 unsigned char appendnc = 0;
98 unsigned char removein = 0;
101 int headerpad = 16384;
102 int format = NC_NOCLOBBER;
103 unsigned char missing = 0;
105 int outputarg = (-1);
108 struct fileinfo *ncoutfile;
109 char outfilename[2048], *strptr;
111 char infilename[2048];
112 unsigned char infileerror = 0;
113 unsigned char infileerrors = 0;
117 void *varbuf[NC_MAX_VARS];
124 for (
a = 1;
a < argc;
a++) {
125 if (!strcmp(argv[
a],
"-v"))
127 else if (!strcmp(argv[
a],
"-vv"))
129 else if (!strcmp(argv[
a],
"-a"))
131 else if (!strcmp(argv[
a],
"-r"))
133 else if (!strcmp(argv[
a],
"-n")) {
136 nstart = atoi(argv[
a]);
141 }
else if (!strcmp(argv[
a],
"-e")) {
144 nend = atoi(argv[
a]);
149 }
else if (!strcmp(argv[
a],
"-h")) {
152 headerpad = atoi(argv[
a]);
157 }
else if (!strcmp(argv[
a],
"-64"))
158 format = (NC_NOCLOBBER | NC_64BIT_OFFSET);
159 else if (!strcmp(argv[
a],
"-n4"))
160 format = (NC_NOCLOBBER | NC_NETCDF4 | NC_CLASSIC_MODEL);
161 else if (!strcmp(argv[
a],
"-m"))
168 if (outputarg == (-1)) {
172 if (argc - 1 > outputarg) inputarg = outputarg + 1;
173 snprintf(outfilename,
sizeof(outfilename),
"%s", argv[outputarg]);
174 outlen = strlen(outfilename);
176 strptr = outfilename + outlen - 5;
177 if (!strcmp(strptr,
".0000")) outfilename[outlen - 5] =
'\0';
184 if ((ncoutfile = (
struct fileinfo *)malloc(
sizeof(
struct fileinfo))) ==
186 fprintf(stderr,
"Error: cannot allocate enough memory!\n");
190 if (stat(outfilename, &statbuf) == 0) {
191 fprintf(stderr,
"Error: output file seems to exist already!\n");
195 if ((ncoutfile->ncfid = nccreate(outfilename, NC_NETCDF4)) == (-1)) {
196 fprintf(stderr,
"Error: cannot create the output netCDF file!\n");
200 ncsetfill(ncoutfile->ncfid, NC_NOFILL);
204 if ((ncoutfile->ncfid = ncopen(outfilename, NC_WRITE)) == (-1)) {
206 "Error: cannot open the output netCDF file for appending!\n");
212 for (f = 0; f < NC_MAX_VARS; f++) varbuf[f] = NULL;
215 if (inputarg == (-1)) {
217 for (
r = 0;
r < nrecs;
r++) {
218 if (verbose) printf(
"record = %d\n",
r);
220 for (
a = nstart;
a <= nend;
a++) {
221 snprintf(infilename,
sizeof(infilename),
"%s.%04d", outfilename,
a);
223 if (
a == nstart &&
r == 0)
224 printf(
" n files to go... ");
226 printf(
" %d files to go... ", nend - nstart + 1 - f);
227 printf(
"processing \"%s\"\n", infilename);
229 if (stat(infilename, &statbuf) != 0)
continue;
230 infileerror = process_file(infilename, appendnc, ncoutfile,
231 outfilename, &nfiles, &nrecs,
r, f, varbuf,
232 headerpad, verbose, missing);
233 if (infileerror) infileerrors = 1;
236 if (f == nfiles ||
a == nend) {
238 printf(
" Write variables from previous %d files\n", f);
239 flush_decomp(ncoutfile, nfiles,
r, varbuf, verbose);
246 for (
r = 0;
r < nrecs;
r++) {
247 if (verbose) printf(
"record = %d\n",
r);
249 for (
a = nstart;
a < nend;
a++) {
250 snprintf(infilename,
sizeof(infilename),
"%s.%04d", outfilename,
a);
252 if (
a == nstart &&
r == 0)
253 printf(
" n files to go... ");
255 printf(
" %d files to go... ", nend -
a);
256 printf(
"processing \"%s\"\n", infilename);
258 infileerror = process_file(infilename, appendnc, ncoutfile,
259 outfilename, &nfiles, &nrecs,
r, f, varbuf,
260 headerpad, verbose, missing);
261 if (infileerror) infileerrors = 1;
262 if (
a == nstart && nfiles > 0) nend = nstart + nfiles;
265 if (f == nfiles ||
a == (nend - 1)) {
267 printf(
" Write variables from previous %d files\n", f);
268 flush_decomp(ncoutfile, nfiles,
r, varbuf, verbose);
278 for (
r = 0;
r < nrecs;
r++) {
279 if (verbose) printf(
"record = %d\n",
r);
281 for (
a = inputarg;
a < argc;
a++) {
284 printf(
" 1 file to go... ");
286 printf(
" %d files to go... ", argc -
a);
287 printf(
"processing \"%s\"\n", argv[
a]);
290 process_file(argv[
a], appendnc, ncoutfile, outfilename, &nfiles,
291 &nrecs,
r, f, varbuf, headerpad, verbose, missing);
292 if (infileerror) infileerrors = 1;
295 if (f == nfiles ||
a == (argc - 1)) {
297 printf(
" Write variables from previous %d files\n", f);
298 flush_decomp(ncoutfile, nfiles,
r, varbuf, verbose);
306 for (f = 0; f < NC_MAX_VARS; f++) {
307 if (varbuf[f] != NULL) free(varbuf[f]);
309 ncclose(ncoutfile->ncfid);
314 if (inputarg == (-1)) {
316 for (
a = nstart;
a <= nend;
a++) {
317 if (++f > nfiles)
break;
318 snprintf(infilename,
sizeof(infilename),
"%s.%04d", outfilename,
a);
319 if (verbose) printf(
"Removing \"%s\"\n", infilename);
325 for (
a = inputarg;
a < argc;
a++) {
326 if (verbose) printf(
"Removing \"%s\"\n", argv[
a]);
331 fprintf(stderr,
"Warning: output file may be incomplete!\n");
332 return (infileerrors);
337 printf(
"mppnccombine 2.1.7 - (written by Hans.Vahlenkamp@noaa.gov)\n\n");
339 "Usage: mppnccombine [-v] [-a] [-r] [-n #] [-e #] [-h #] [-64] [-m]\n");
340 printf(
" output.nc [input ...]\n\n");
341 printf(
" -v Print some progress information.\n");
343 " -a Append to an existing netCDF file (not heavily tested...).\n");
345 " -r Remove the \".####\" decomposed files after a successful "
348 " -n # Input filename extensions start with number #### instead of "
351 " -e # Ending number #### of a specified range of input filename "
354 " Files within the range do not have to be consecutively "
357 " -h # Add a specified number of bytes of padding at the end of the "
359 printf(
" -64 Create netCDF output files with the 64-bit offset format.\n");
361 " -m Initialize output variables with a \"missing_value\" from the "
363 printf(
" of the first input file instead of the default 0 value.\n\n");
365 "mppnccombine joins together an arbitrary number of netCDF input files, "
368 "containing parts of a decomposed domain, into a unified netCDF output "
371 "An output file must be specified and it is assumed to be the first "
374 "argument. If the output file already exists, then it will not be "
377 "unless the option is chosen to append to it. If no input files are "
380 "then their names will be based on the name of the output file plus the "
383 "numeric extension \".0000\", which will increment by 1. There is an "
386 "starting the filename extensions with an arbitrary number instead of 0. "
389 "is an option for specifying an end to the range of filename extension "
392 "files within the range do not have to be consecutively numbered. If "
394 printf(
"files are specified then names will be used verbatim.\n\n");
396 "A value of 0 is returned if execution completed successfully; a value "
398 printf(
"otherwise.\n");
404 int process_file(
char *ncname,
unsigned char appendnc,
405 struct fileinfo *ncoutfile,
char *outncname,
int *nfiles,
406 int *nrecs,
int r,
int f,
void *varbuf[],
int headerpad,
407 unsigned char verbose,
unsigned char missing) {
408 struct fileinfo *ncinfile;
417 char attname[MAX_NC_NAME];
418 unsigned char ncinfileerror = 0;
421 if ((ncinfile = (
struct fileinfo *)malloc(
sizeof(
struct fileinfo))) == NULL) {
422 fprintf(stderr,
"Error: cannot allocate enough memory!\n");
427 if ((ncinfile->ncfid = ncopen(ncname, NC_NOWRITE)) == (-1)) {
428 fprintf(stderr,
"Error: cannot open input file \"%s\"\n", ncname);
434 if (ncattget(ncinfile->ncfid, NC_GLOBAL,
"NumFilesInSet", (
void *)&nfiles2) ==
438 "Error: missing the \"NumFilesInSet\" global attribute!\n");
440 }
else if (*nfiles == (-1)) {
442 "Warning: missing the \"NumFilesInSet\" global attribute.\n");
448 if (ncinquire(ncinfile->ncfid, &(ncinfile->ndims), &(ncinfile->nvars),
449 &(ncinfile->ngatts), &(ncinfile->recdim)) == (-1)) {
450 fprintf(stderr,
"Error: cannot read the file's metadata!\n");
451 ncclose(ncinfile->ncfid);
457 for (d = 0; d < ncinfile->ndims; d++) {
458 if ((ncdiminq(ncinfile->ncfid, d, ncinfile->dimname[d],
459 &(ncinfile->dimsize[d]))) == (-1)) {
460 fprintf(stderr,
"Error: cannot read dimension #%d's metadata!\n", d);
461 ncclose(ncinfile->ncfid);
465 ncinfile->dimfullsize[d] = ncinfile->dimsize[d];
466 ncinfile->dimstart[d] = 1;
467 ncinfile->dimend[d] = (-1);
472 ncoutfile->nvars = ncinfile->nvars;
473 ncoutfile->recdim = ncinfile->recdim;
477 for (v = 0; v < ncinfile->nvars; v++) {
478 if ((ncvarinq(ncinfile->ncfid, v, ncinfile->varname[v],
479 &(ncinfile->datatype[v]), &(ncinfile->varndims[v]),
480 ncinfile->vardim[v], &(ncinfile->natts[v]))) == (-1)) {
481 fprintf(stderr,
"Error: cannot read variable #%d's metadata!\n", v);
482 ncclose(ncinfile->ncfid);
488 if ((dimid = ncdimid(ncinfile->ncfid, ncinfile->varname[v])) != (-1)) {
489 if (ncattget(ncinfile->ncfid, v,
"domain_decomposition",
490 (
void *)decomp) != (-1)) {
491 ncinfile->dimfullsize[dimid] = decomp[1] - decomp[0] + 1;
492 ncinfile->dimstart[dimid] = decomp[2] - (decomp[0] - 1);
493 ncinfile->dimend[dimid] = decomp[3] - (decomp[0] - 1);
495 ncinfile->dimfullsize[dimid] = ncinfile->dimsize[dimid];
496 ncinfile->dimstart[dimid] = 1;
497 ncinfile->dimend[dimid] = (-1);
503 for (v = 0; v < ncinfile->nvars; v++) {
505 ncinfile->vardecomp[v] = 0;
506 for (d = 0; d < ncinfile->varndims[v]; d++) {
507 if (ncinfile->dimend[ncinfile->vardim[v][d]] != (-1)) {
508 ncinfile->vardecomp[v] = 1;
515 ncoutfile->varndims[v] = ncinfile->varndims[v];
516 for (d = 0; d < ncinfile->ndims; d++)
517 ncoutfile->dimfullsize[d] = ncinfile->dimfullsize[d];
518 for (d = 0; d < ncinfile->varndims[v]; d++)
519 ncoutfile->vardim[v][d] = ncinfile->vardim[v][d];
520 ncoutfile->vardecomp[v] = ncinfile->vardecomp[v];
521 strcpy(ncoutfile->varname[v], ncinfile->varname[v]);
522 ncoutfile->varmiss[v] = 0;
528 if (verbose) printf(
" Creating output \"%s\"\n", outncname);
531 for (d = 0; d < ncinfile->ndims; d++) {
532 if (d == ncinfile->recdim)
533 ncdimdef(ncoutfile->ncfid, ncinfile->dimname[d], NC_UNLIMITED);
535 ncdimdef(ncoutfile->ncfid, ncinfile->dimname[d],
536 ncinfile->dimfullsize[d]);
540 for (v = 0; v < ncinfile->nvars; v++) {
541 ncvardef(ncoutfile->ncfid, ncinfile->varname[v], ncinfile->datatype[v],
542 ncinfile->varndims[v], ncinfile->vardim[v]);
543 for (n = 0; n < ncinfile->natts[v]; n++) {
544 ncattname(ncinfile->ncfid, v, n, attname);
546 if (!strcmp(attname,
"missing_value")) {
547 ncoutfile->varmiss[v] = 1;
548 ncattget(ncinfile->ncfid, v,
"missing_value",
549 (
void *)(ncoutfile->varmissval[v]));
552 if (!strcmp(attname,
"domain_decomposition"))
555 if (ncattcopy(ncinfile->ncfid, v, attname, ncoutfile->ncfid, v) ==
558 "Error: cannot copy variable \"%s\"'s attributes!\n",
559 ncinfile->varname[v]);
568 for (n = 0; n < ncinfile->ngatts; n++) {
569 ncattname(ncinfile->ncfid, NC_GLOBAL, n, attname);
570 if (!strcmp(attname,
"NumFilesInSet"))
572 else if (!strcmp(attname,
"filename"))
573 ncattput(ncoutfile->ncfid, NC_GLOBAL, attname, NC_CHAR,
574 strlen(outncname), (
void *)outncname);
576 if (ncattcopy(ncinfile->ncfid, NC_GLOBAL, attname, ncoutfile->ncfid,
577 NC_GLOBAL) == (-1)) {
578 fprintf(stderr,
"Error: cannot copy the file's global attributes!\n");
585 nc__enddef(ncoutfile->ncfid, headerpad, 4, 0, 4);
589 ncinfileerror = process_vars(ncinfile, ncoutfile, appendnc, nrecs,
r, *nfiles,
590 f, varbuf, verbose, missing);
593 ncclose(ncinfile->ncfid);
595 return (ncinfileerror);
599 int process_vars(
struct fileinfo *ncinfile,
struct fileinfo *ncoutfile,
600 unsigned char appendnc,
int *nrecs,
int r,
int nfiles,
int f,
601 void *varbuf[],
unsigned char verbose,
unsigned char missing) {
602 int v, d, i,
j, k, l,
b, s;
605 long instart[MAX_NC_DIMS], outstart[MAX_NC_DIMS];
606 long count[MAX_NC_DIMS];
608 long long recfullsize;
610 int imax, jmax, kmax, lmax;
611 int imaxfull, jmaxfull, kmaxfull, lmaxfull;
612 int imaxjmaxfull, imaxjmaxkmaxfull;
613 int offset, ioffset, joffset, koffset, loffset;
614 long long varbufsize;
618 *nrecs = ncinfile->dimsize[ncinfile->recdim];
619 else if (ncinfile->dimsize[ncinfile->recdim] != *nrecs) {
621 "Error: different number of records than the first input file!\n");
626 for (v = 0; v < ncinfile->nvars; v++) {
627 if (verbose > 1) printf(
" variable = %s\n", ncinfile->varname[v]);
637 for (d = 0; d < ncinfile->varndims[v]; d++) {
638 if (ncinfile->vardim[v][d] == ncinfile->recdim) {
642 count[d] = ncinfile->dimsize[ncinfile->vardim[v][d]];
645 outstart[d] = ncinfile->dimstart[ncinfile->vardim[v][d]] - 1;
646 recfullsize *= ncinfile->dimfullsize[ncinfile->vardim[v][d]];
649 printf(
" dim %d: instart=%ld outstart=%ld count=%ld\n", d,
650 instart[d], outstart[d], count[d]);
656 if ((dimid = ncdimid(ncinfile->ncfid, ncinfile->varname[v])) != (-1)) {
657 if (ncinfile->recdim == dimid) {
658 if (f != 0)
continue;
668 if (varrecdim == (-1))
continue;
671 if (ncinfile->vardecomp[v] != 1 && f > 0)
continue;
674 if (ncinfile->vardecomp[v] != 1 && appendnc)
continue;
678 if ((values = malloc(nctypelen(ncinfile->datatype[v]) * recsize)) == NULL) {
680 "Error: cannot allocate %lld bytes for decomposed variable "
681 "\"%s\"'s values!\n",
682 nctypelen(ncinfile->datatype[v]) * recsize, ncinfile->varname[v]);
687 if (varrecdim != (-1)) instart[varrecdim] = outstart[varrecdim] =
r;
688 if (ncvarget(ncinfile->ncfid, v, instart, count, values) == (-1)) {
689 fprintf(stderr,
"Error: cannot read variable \"%s\"'s values!\n",
690 ncinfile->varname[v]);
695 if (ncinfile->vardecomp[v] != 1) {
697 printf(
" writing %lld bytes to file\n",
698 nctypelen(ncinfile->datatype[v]) * recsize);
699 if (ncvarput(ncoutfile->ncfid, v, outstart, count, values) == (-1)) {
700 fprintf(stderr,
"Error: cannot write variable \"%s\"'s values!\n",
701 ncinfile->varname[v]);
709 varbufsize = nctypelen(ncinfile->datatype[v]) * recfullsize;
711 printf(
" allocating %lld bytes for full domain\n", varbufsize);
712 if ((varbuf[v] = calloc(varbufsize, 1)) == NULL) {
714 "Error: cannot allocate %lld bytes for entire variable "
715 "\"%s\"'s values!\n",
716 varbufsize, ncinfile->varname[v]);
719 if (missing && ncoutfile->varmiss[v])
switch (ncinfile->datatype[v]) {
722 for (s = 0; s < recfullsize; s++)
723 *((
unsigned char *)(varbuf[v]) + s) =
724 *((
unsigned char *)(ncoutfile->varmissval[v]));
727 for (s = 0; s < recfullsize; s++)
728 *((
short *)(varbuf[v]) + s) =
729 *((
short *)(ncoutfile->varmissval[v]));
732 for (s = 0; s < recfullsize; s++)
733 *((
int *)(varbuf[v]) + s) =
734 *((
int *)(ncoutfile->varmissval[v]));
737 for (s = 0; s < recfullsize; s++)
738 *((
float *)(varbuf[v]) + s) =
739 *((
float *)(ncoutfile->varmissval[v]));
742 for (s = 0; s < recfullsize; s++)
743 *((
double *)(varbuf[v]) + s) =
744 *((
double *)(ncoutfile->varmissval[v]));
748 if (varbuf[v] == NULL) {
749 fprintf(stderr,
"Internal memory usage error!\n");
753 printf(
" writing %lld bytes to memory\n",
754 nctypelen(ncinfile->datatype[v]) * recsize);
756 imax = ncinfile->dimsize[ncinfile->vardim[v][ncinfile->varndims[v] - 1]];
757 if (ncinfile->varndims[v] > 1) {
758 dimid = ncinfile->vardim[v][ncinfile->varndims[v] - 2];
759 if (dimid == ncinfile->recdim)
762 jmax = ncinfile->dimsize[dimid];
765 if (ncinfile->varndims[v] > 2) {
766 dimid = ncinfile->vardim[v][ncinfile->varndims[v] - 3];
767 if (dimid == ncinfile->recdim)
770 kmax = ncinfile->dimsize[dimid];
773 if (ncinfile->varndims[v] > 3) {
774 dimid = ncinfile->vardim[v][ncinfile->varndims[v] - 4];
775 if (dimid == ncinfile->recdim)
778 lmax = ncinfile->dimsize[dimid];
782 printf(
" imax=%d jmax=%d kmax=%d lmax=%d\n", imax, jmax, kmax,
786 ncinfile->dimfullsize[ncinfile->vardim[v][ncinfile->varndims[v] - 1]];
787 if (ncinfile->varndims[v] > 1)
790 ->dimfullsize[ncinfile->vardim[v][ncinfile->varndims[v] - 2]];
793 if (ncinfile->varndims[v] > 2)
796 ->dimfullsize[ncinfile->vardim[v][ncinfile->varndims[v] - 3]];
799 if (ncinfile->varndims[v] > 3) {
800 if (ncinfile->vardim[v][ncinfile->varndims[v] - 4] != ncinfile->recdim)
803 ->dimfullsize[ncinfile->vardim[v][ncinfile->varndims[v] - 4]];
809 printf(
" imaxfull=%d jmaxfull=%d kmaxfull=%d lmaxfull=%d\n",
810 imaxfull, jmaxfull, kmaxfull, lmaxfull);
811 imaxjmaxfull = imaxfull * jmaxfull;
812 imaxjmaxkmaxfull = imaxfull * jmaxfull * kmaxfull;
814 ioffset = outstart[ncinfile->varndims[v] - 0 - 1];
815 if (ncinfile->varndims[v] > 1)
816 joffset = outstart[ncinfile->varndims[v] - 1 - 1];
819 if (ncinfile->varndims[v] > 2)
820 koffset = outstart[ncinfile->varndims[v] - 2 - 1];
823 if (ncinfile->varndims[v] > 3)
824 loffset = outstart[ncinfile->varndims[v] - 3 - 1];
827 if (varrecdim != (-1)) {
828 switch (ncinfile->varndims[v]) {
844 printf(
" ioffset=%d joffset=%d koffset=%d loffset=%d\n",
845 ioffset, joffset, koffset, loffset);
846 switch (ncinfile->datatype[v]) {
849 if (verbose > 1) printf(
" start copying byte/char\n");
851 for (l = 0; l < lmax; l++)
852 for (k = 0; k < kmax; k++)
853 for (
j = 0;
j < jmax;
j++)
854 for (i = 0; i < imax; i++) {
855 offset = (i + ioffset) + (
j + joffset) * imaxfull +
856 (k + koffset) * imaxjmaxfull +
857 (l + loffset) * imaxjmaxkmaxfull;
858 *((
unsigned char *)(varbuf[v]) + offset) =
859 *((
unsigned char *)values + (
b++));
861 if (verbose > 1) printf(
" end copying byte/char\n");
864 if (verbose > 1) printf(
" start copying short\n");
866 for (l = 0; l < lmax; l++)
867 for (k = 0; k < kmax; k++)
868 for (
j = 0;
j < jmax;
j++)
869 for (i = 0; i < imax; i++) {
870 offset = (i + ioffset) + (
j + joffset) * imaxfull +
871 (k + koffset) * imaxjmaxfull +
872 (l + loffset) * imaxjmaxkmaxfull;
873 *((
short *)(varbuf[v]) + offset) = *((
short *)values + (
b++));
875 if (verbose > 1) printf(
" end copying short\n");
878 if (verbose > 1) printf(
" start copying int\n");
880 for (l = 0; l < lmax; l++)
881 for (k = 0; k < kmax; k++)
882 for (
j = 0;
j < jmax;
j++)
883 for (i = 0; i < imax; i++) {
884 offset = (i + ioffset) + (
j + joffset) * imaxfull +
885 (k + koffset) * imaxjmaxfull +
886 (l + loffset) * imaxjmaxkmaxfull;
887 *((
int *)(varbuf[v]) + offset) = *((
int *)values + (
b++));
889 if (verbose > 1) printf(
" end copying int\n");
892 if (verbose > 1) printf(
" start copying float\n");
894 for (l = 0; l < lmax; l++)
895 for (k = 0; k < kmax; k++)
896 for (
j = 0;
j < jmax;
j++)
897 for (i = 0; i < imax; i++) {
898 offset = (i + ioffset) + (
j + joffset) * imaxfull +
899 (k + koffset) * imaxjmaxfull +
900 (l + loffset) * imaxjmaxkmaxfull;
901 *((
float *)(varbuf[v]) + offset) = *((
float *)values + (
b++));
903 if (verbose > 1) printf(
" end copying float\n");
906 if (verbose > 1) printf(
" start copying double\n");
908 for (l = 0; l < lmax; l++)
909 for (k = 0; k < kmax; k++)
910 for (
j = 0;
j < jmax;
j++)
911 for (i = 0; i < imax; i++) {
912 offset = (i + ioffset) + (
j + joffset) * imaxfull +
913 (k + koffset) * imaxjmaxfull +
914 (l + loffset) * imaxjmaxkmaxfull;
915 *((
double *)(varbuf[v]) + offset) =
916 *((
double *)values + (
b++));
918 if (verbose > 1) printf(
" end copying double\n");
931 int flush_decomp(
struct fileinfo *ncoutfile,
int nfiles,
int r,
void *varbuf[],
932 unsigned char verbose) {
934 long outstart[MAX_NC_DIMS];
935 long count[MAX_NC_DIMS];
939 printf(
" nvars=%d\n", ncoutfile->nvars);
943 for (v = 0; v < ncoutfile->nvars; v++) {
944 if (ncoutfile->vardecomp[v] == 0)
continue;
945 if (verbose > 1) printf(
" v=%d (%s)\n", v, ncoutfile->varname[v]);
947 for (d = 0; d < ncoutfile->varndims[v]; d++) {
949 if (ncoutfile->vardim[v][d] == ncoutfile->recdim) {
953 count[d] = ncoutfile->dimfullsize[ncoutfile->vardim[v][d]];
956 printf(
" d=%d: outstart=%ld count=%ld\n", d, outstart[d],
959 if (varrecdim != (-1)) outstart[varrecdim] =
r;
960 if (varrecdim == (-1) &&
r > 0)
continue;
961 if (verbose > 1) printf(
" writing to disk\n");
962 if (ncvarput(ncoutfile->ncfid, v, outstart, count, varbuf[v]) == (-1)) {
963 fprintf(stderr,
"Error: cannot write variable \"%d\"'s values!\n", v);
int mppnccombine(int argc, char *argv[])