| 52 |
|
uint32 ac; // accumulation count |
| 53 |
|
}; |
| 54 |
|
|
| 55 |
+ |
// Get format identifier |
| 56 |
+ |
const char * |
| 57 |
+ |
formstr(int f) |
| 58 |
+ |
{ |
| 59 |
+ |
switch (f) { |
| 60 |
+ |
case 'a': return("ascii"); |
| 61 |
+ |
case 'f': return("float"); |
| 62 |
+ |
case 'd': return("double"); |
| 63 |
+ |
case 'c': return(NCSAMP==3 ? COLRFMT : SPECFMT); |
| 64 |
+ |
} |
| 65 |
+ |
return("unknown"); |
| 66 |
+ |
} |
| 67 |
+ |
|
| 68 |
|
// Our default data share function |
| 69 |
|
RdataShare * |
| 70 |
|
defDataShare(const char *name, RCOutputOp op, size_t siz) |
| 76 |
|
RcontribMod * |
| 77 |
|
NewRcMod(const char *prms, const char *binexpr, int ncbins) |
| 78 |
|
{ |
| 66 |
– |
if (ncbins <= 0) return NULL; |
| 79 |
|
if (!prms) prms = ""; |
| 80 |
< |
if (!binexpr & (ncbins > 1)) { |
| 81 |
< |
error(INTERNAL, "missing bin expression"); |
| 80 |
> |
if ((ncbins > 1) & !binexpr) { |
| 81 |
> |
error(USER, "missing bin expression"); |
| 82 |
|
return NULL; |
| 83 |
|
} |
| 84 |
< |
if (ncbins == 1) { // shouldn't have bin expression? |
| 85 |
< |
if (binexpr && strcmp(binexpr, "0")) |
| 74 |
< |
error(WARNING, "ignoring non-zero expression for single bin"); |
| 75 |
< |
prms = ""; |
| 76 |
< |
binexpr = NULL; |
| 77 |
< |
} |
| 84 |
> |
if (ncbins < 1) ncbins = 1; |
| 85 |
> |
|
| 86 |
|
RcontribMod * mp = (RcontribMod *)ecalloc(1, sizeof(RcontribMod) + |
| 87 |
|
sizeof(DCOLORV)*(NCSAMP*ncbins-1) + |
| 88 |
|
strlen(prms)+1); |
| 89 |
|
|
| 90 |
< |
mp->params = strcpy((char *)(mp->cbin + ncbins*NCSAMP), prms); |
| 83 |
< |
if (binexpr) { |
| 90 |
> |
if (binexpr) { // check bin expression |
| 91 |
|
mp->binv = eparse(const_cast<char *>(binexpr)); |
| 92 |
< |
CHECK(mp->binv->type==NUM, WARNING, "constant bin expression"); |
| 92 |
> |
if (mp->binv->type == NUM) { // constant expression (0)? |
| 93 |
> |
if ((int)(evalue(mp->binv) + .5) > 0) { |
| 94 |
> |
sprintf(errmsg, "illegal positive constant for bin (%s)", |
| 95 |
> |
binexpr); |
| 96 |
> |
error(USER, errmsg); |
| 97 |
> |
} |
| 98 |
> |
if (ncbins > 1) { |
| 99 |
> |
sprintf(errmsg, "bad bin count (%d should be 1)", ncbins); |
| 100 |
> |
error(USER, errmsg); |
| 101 |
> |
} |
| 102 |
> |
epfree(mp->binv, true); |
| 103 |
> |
mp->binv = NULL; |
| 104 |
> |
prms = ""; |
| 105 |
> |
ncbins = 1; |
| 106 |
> |
} |
| 107 |
|
} |
| 108 |
+ |
mp->params = strcpy((char *)(mp->cbin + ncbins*NCSAMP), prms); |
| 109 |
|
mp->nbins = ncbins; |
| 110 |
|
return mp; |
| 111 |
|
} |
| 210 |
|
RcontribSimulManager::AddModifier(const char *modn, const char *outspec, |
| 211 |
|
const char *prms, const char *binval, int bincnt) |
| 212 |
|
{ |
| 213 |
< |
if (!modn | !outspec | (bincnt <= 0) || !*modn | !*outspec) { |
| 213 |
> |
if (!modn | !outspec || !*modn | !*outspec) { |
| 214 |
|
error(WARNING, "ignoring bad call to AddModifier()"); |
| 215 |
|
return false; |
| 216 |
|
} |
| 217 |
|
if (!nChan) { // initial call? |
| 218 |
|
if ((xres < 0) | (yres <= 0)) { |
| 219 |
< |
error(INTERNAL, "xres, yres must be set before first modifier"); |
| 219 |
> |
error(USER, "xres, yres must be set before first modifier"); |
| 220 |
|
return false; |
| 221 |
|
} |
| 222 |
|
if (!SetDataFormat(dtyp)) |
| 223 |
|
return false; |
| 224 |
|
nChan = NCSAMP; |
| 225 |
|
} else if (nChan != NCSAMP) { |
| 226 |
< |
error(INTERNAL, "number of spectral channels must be fixed"); |
| 226 |
> |
error(USER, "number of spectral channels must be fixed"); |
| 227 |
|
return false; |
| 228 |
|
} |
| 229 |
|
if (Ready()) { |
| 246 |
|
const int binndx = hasFormat(outspec, "diouxX"); |
| 247 |
|
int bin0 = 0; |
| 248 |
|
char fnbuf[512]; |
| 249 |
< |
if (!modndx | (modndx > binndx)) |
| 249 |
> |
if (!modndx || (binndx > 0) & (modndx > binndx)) |
| 250 |
|
sprintf(fnbuf, outspec, bin0, modn); |
| 251 |
|
else |
| 252 |
|
sprintf(fnbuf, outspec, modn, bin0); |
| 275 |
|
mp->opl = op; // first (maybe only) output channel |
| 276 |
|
if (modndx) // remember modifier if part of name |
| 277 |
|
op->omod = lp->key; |
| 278 |
< |
if (binndx > 0) { // append output image/bin list |
| 278 |
> |
if (binndx) { // append output image/bin list |
| 279 |
|
op->rowBytes += dsiz; |
| 280 |
|
op->obin = bin0; |
| 281 |
|
for (bincnt = 1; bincnt < mp->nbins; bincnt++) { |
| 282 |
< |
if (!modndx | (modndx > binndx)) |
| 282 |
> |
if (!modndx || (binndx > 0) & (modndx > binndx)) |
| 283 |
|
sprintf(fnbuf, outspec, bin0+bincnt, modn); |
| 284 |
|
else |
| 285 |
|
sprintf(fnbuf, outspec, modn, bin0+bincnt); |
| 298 |
|
op->rowBytes += dsiz; |
| 299 |
|
} |
| 300 |
|
} else // else send all results to this channel |
| 301 |
< |
op->rowBytes += bincnt*dsiz; |
| 301 |
> |
op->rowBytes += mp->nbins*dsiz; |
| 302 |
|
return true; |
| 303 |
|
} |
| 304 |
|
|