| 54 |
|
|
| 55 |
|
static const char ROW_DONE[] = "ROW FINISHED\n"; |
| 56 |
|
|
| 57 |
< |
// Get format identifier |
| 58 |
< |
const char * |
| 59 |
< |
formstr(int f) |
| 60 |
< |
{ |
| 61 |
< |
switch (f) { |
| 62 |
< |
case 'a': return("ascii"); |
| 63 |
< |
case 'f': return("float"); |
| 64 |
< |
case 'd': return("double"); |
| 65 |
< |
case 'c': return(NCSAMP==3 ? COLRFMT : SPECFMT); |
| 66 |
< |
} |
| 67 |
< |
return("unknown"); |
| 68 |
< |
} |
| 69 |
< |
|
| 70 |
< |
// Our default data share function |
| 71 |
< |
RdataShare * |
| 72 |
< |
defDataShare(const char *name, RCOutputOp op, size_t siz) |
| 73 |
< |
{ |
| 74 |
< |
return new RdataShareMap(name, RSDOflags[op], siz); |
| 75 |
< |
} |
| 76 |
< |
|
| 77 |
< |
// Allocate rcontrib accumulator |
| 78 |
< |
RcontribMod * |
| 57 |
> |
// allocate rcontrib accumulator |
| 58 |
> |
static RcontribMod * |
| 59 |
|
NewRcMod(const char *prms, const char *binexpr, int ncbins) |
| 60 |
|
{ |
| 61 |
+ |
if (binexpr && !*binexpr) binexpr = NULL; |
| 62 |
|
if (!prms) prms = ""; |
| 63 |
|
if ((ncbins > 1) & !binexpr) { |
| 64 |
|
error(USER, "missing bin expression"); |
| 93 |
|
return mp; |
| 94 |
|
} |
| 95 |
|
|
| 96 |
< |
// Free an RcontribMod |
| 96 |
> |
// Free an RcontribMod (public for RcontribSimulManager constructor) |
| 97 |
|
void |
| 98 |
|
FreeRcMod(void *p) |
| 99 |
|
{ |
| 103 |
|
efree(p); |
| 104 |
|
} |
| 105 |
|
|
| 106 |
+ |
// Get format identifier |
| 107 |
+ |
const char * |
| 108 |
+ |
formstr(int f) |
| 109 |
+ |
{ |
| 110 |
+ |
switch (f) { |
| 111 |
+ |
case 'a': return("ascii"); |
| 112 |
+ |
case 'f': return("float"); |
| 113 |
+ |
case 'd': return("double"); |
| 114 |
+ |
case 'c': return(NCSAMP==3 ? COLRFMT : SPECFMT); |
| 115 |
+ |
} |
| 116 |
+ |
return("unknown"); |
| 117 |
+ |
} |
| 118 |
+ |
|
| 119 |
+ |
// Standard file data share function |
| 120 |
+ |
RdataShare * |
| 121 |
+ |
fileDataShare(const char *name, RCOutputOp op, size_t siz) |
| 122 |
+ |
{ |
| 123 |
+ |
if (op == RCOrecover && access(name, R_OK|W_OK) < 0) { |
| 124 |
+ |
sprintf(errmsg, "cannot recover from '%s'", name); |
| 125 |
+ |
error(SYSTEM, errmsg); |
| 126 |
+ |
return NULL; |
| 127 |
+ |
} |
| 128 |
+ |
RdataShare * rds = new RdataShareFile(name, RSDOflags[op], |
| 129 |
+ |
siz*(op != RCOforce)); |
| 130 |
+ |
|
| 131 |
+ |
if (!rds || (op == RCOforce && rds->Resize(siz) < siz)) { |
| 132 |
+ |
delete rds; |
| 133 |
+ |
sprintf(errmsg, "cannot create %lu byte output file '%s'", |
| 134 |
+ |
(unsigned long)siz, name); |
| 135 |
+ |
error(SYSTEM, errmsg); |
| 136 |
+ |
return NULL; |
| 137 |
+ |
} |
| 138 |
+ |
return rds; |
| 139 |
+ |
} |
| 140 |
+ |
|
| 141 |
+ |
// Memory-mapped data share function |
| 142 |
+ |
RdataShare * |
| 143 |
+ |
mapDataShare(const char *name, RCOutputOp op, size_t siz) |
| 144 |
+ |
{ |
| 145 |
+ |
if (op == RCOrecover && access(name, R_OK|W_OK) < 0) { |
| 146 |
+ |
sprintf(errmsg, "cannot recover from '%s'", name); |
| 147 |
+ |
error(SYSTEM, errmsg); |
| 148 |
+ |
return NULL; |
| 149 |
+ |
} |
| 150 |
+ |
RdataShare * rds = new RdataShareMap(name, RSDOflags[op], |
| 151 |
+ |
siz*(op != RCOforce)); |
| 152 |
+ |
|
| 153 |
+ |
if (!rds || (op == RCOforce && rds->Resize(siz) < siz)) { |
| 154 |
+ |
delete rds; |
| 155 |
+ |
sprintf(errmsg, "cannot create %lu byte output map '%s'", |
| 156 |
+ |
(unsigned long)siz, name); |
| 157 |
+ |
error(SYSTEM, errmsg); |
| 158 |
+ |
return NULL; |
| 159 |
+ |
} |
| 160 |
+ |
return rds; |
| 161 |
+ |
} |
| 162 |
+ |
|
| 163 |
|
// Set output format ('f', 'd', or 'c') |
| 164 |
|
bool |
| 165 |
|
RcontribSimulManager::SetDataFormat(int ty) |
| 417 |
|
if (rd < 0) |
| 418 |
|
return -1; |
| 419 |
|
if (rd >= op->nRows) { |
| 420 |
< |
if (remWarnings >= 0) { |
| 420 |
> |
if (remWarnings > 0) { |
| 421 |
|
sprintf(errmsg, "recovered output '%s' is complete", |
| 422 |
|
op->GetName()); |
| 423 |
|
error(WARNING, --remWarnings ? errmsg : "etc..."); |
| 434 |
|
} |
| 435 |
|
rowsDone.NewBitMap(outList->nRows); // create row completion map |
| 436 |
|
rowsDone.ClearBits(0, rInPos, true); |
| 437 |
< |
return rInPos; |
| 437 |
> |
return nrDone = rInPos; |
| 438 |
|
} |
| 439 |
|
|
| 440 |
|
// Create header in open write-only channel |
| 469 |
|
sprintf(hdr+begData, "%s%d\n", NCOMPSTR, NCSAMP); |
| 470 |
|
begData += strlen(hdr+begData); |
| 471 |
|
if (NCSAMP > 3) { |
| 472 |
< |
sprintf(hdr+begData, "%s %f %f %f %f\n", WLSPLTSTR, |
| 472 |
> |
sprintf(hdr+begData, "%s %g %g %g %g\n", WLSPLTSTR, |
| 473 |
|
WLPART[0], WLPART[1], WLPART[2], WLPART[3]); |
| 474 |
|
begData += strlen(hdr+begData); |
| 475 |
|
} |
| 554 |
|
return -1; |
| 555 |
|
} |
| 556 |
|
// check #columns |
| 557 |
< |
if (((cp = findArgs(hdr, "NCOLS=", begData)) && atoi(cp)*esiz != rowBytes) || |
| 558 |
< |
!rcp->xres | (rowBytes > esiz)) { |
| 559 |
< |
sprintf(errmsg, "expected NCOLS=%d in '%s'", |
| 522 |
< |
int(rowBytes/esiz), GetName()); |
| 557 |
> |
if ((cp = findArgs(hdr, "NCOLS=", begData)) ? (atoi(cp)*esiz != rowBytes) |
| 558 |
> |
: (!rcp->xres | (rowBytes > esiz))) { |
| 559 |
> |
sprintf(errmsg, "expected NCOLS=%d in '%s'", int(rowBytes/esiz), GetName()); |
| 560 |
|
error(USER, errmsg); |
| 561 |
|
return -1; |
| 562 |
|
} |
| 598 |
|
return false; |
| 599 |
|
|
| 600 |
|
rowsDone.ClearBits(r, rInPos-r, false); |
| 601 |
< |
rInPos = r; |
| 601 |
> |
nrDone = rInPos = r; |
| 602 |
|
return true; |
| 603 |
|
} |
| 604 |
|
|
| 757 |
|
error(WARNING, "redundant call to UpdateRowsDone()"); |
| 758 |
|
return false; |
| 759 |
|
} |
| 760 |
< |
int nDone = GetRowFinished(); |
| 761 |
< |
if (nDone <= r) |
| 760 |
> |
GetRowFinished(); |
| 761 |
> |
if (nrDone <= r) |
| 762 |
|
return true; // nothing to update, yet |
| 763 |
|
for (RcontribOutput *op = outList; op; op = op->next) |
| 764 |
< |
if (!op->SetRowsDone(nDone)) |
| 764 |
> |
if (!op->SetRowsDone(nrDone)) |
| 765 |
|
return false; |
| 766 |
|
return true; // up-to-date |
| 767 |
|
} |