Skip to content

Commit

Permalink
Merge pull request #275 from 0cole/mppnccombine_bf_fix
Browse files Browse the repository at this point in the history
Added fix for blocking factor of 0 in mppnccombine
  • Loading branch information
rem1776 authored Feb 12, 2024
2 parents c4894a3 + 5fc772a commit 65c34e7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
43 changes: 21 additions & 22 deletions postprocessing/mppnccombine/mppnccombine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,29 +1004,28 @@ int process_vars(struct fileinfo *ncinfile, struct fileinfo *ncoutfile,
recdimsize=ncinfile->dimsize[ncinfile->recdim];

/* Check the number of records */
if (*nrecs==1)
{
*nrecs=recdimsize;

if ((*bf) >= 1)
{
if ((*bf) > (*nrecs)) {
fprintf(stderr, "blocking factor (k) > total records (%d). Setting blocking factor to %d.\n",
*nrecs, *nrecs);
*bf = *nrecs;
}
if (((*nrecs) % (*bf)) != 0) *nblocks = (int)((*nrecs)/(*bf)) + 1;
else *nblocks = (int)((*nrecs)/(*bf));
}
else
{
/* bf was set to zero, so we do full buffering */
*bf = min(MAX_BF,*nrecs); // we use the maximum blocking factor in our capacity
/* normally we'll have one block, unless we hit MAX_BF */
*nblocks = (int)((*nrecs)/(*bf));
}
if (verbose) fprintf(stderr, "blocking factor=%d, num. blocks=%d, num. records=%d\n",*bf,*nblocks, *nrecs);
if (*nrecs==1) {
*nrecs=recdimsize;

/* adjust bf */
if ((*bf) >= 1) {
if ((*bf) > (*nrecs)) {
fprintf(stderr, "blocking factor (k) > total records (%d). Setting blocking factor to %d.\n",
*nrecs, *nrecs);
*bf = *nrecs;
}
}
else {
/* bf was set to zero, so we do full buffering */
*bf = min(MAX_BF,*nrecs); // we use the maximum blocking factor in our capacity
/* normally we'll have one block, unless we hit MAX_BF */
}
/* find nblocks */
if (((*nrecs) % (*bf)) != 0) *nblocks = (int)((*nrecs)/(*bf)) + 1;
else *nblocks = (int)((*nrecs)/(*bf));

if (verbose) fprintf(stderr, "blocking factor=%d, num. blocks=%d, num. records=%d\n",*bf,*nblocks, *nrecs);
}
else
if (recdimsize != *nrecs)
{
Expand Down
13 changes: 13 additions & 0 deletions t/Test02-mppnccombine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,16 @@ load test_utils
run_and_check [ -e mppnccombine_output.nc ]
ncdump -h mppnccombine_output.nc
}

@test "mppnccombine combines with blocking factor 0" {

generate_all_from_ncl_num mppnccombine Test02-input

#Combine the files into 1
mppnccombine \
-k 0 \
mppnccombine_output.nc \
mppnccombine.nc.????
run_and_check [ -e mppnccombine_output.nc ]
ncdump -h mppnccombine_output.nc
}

0 comments on commit 65c34e7

Please sign in to comment.