| 77 |
|
NewRcMod(const char *prms, const char *binexpr, int ncbins) |
| 78 |
|
{ |
| 79 |
|
if (!prms) prms = ""; |
| 80 |
< |
if (!binexpr & (ncbins > 1)) { |
| 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")) |
| 86 |
< |
error(WARNING, "ignoring non-zero expression for single bin"); |
| 87 |
< |
prms = ""; |
| 88 |
< |
binexpr = NULL; |
| 89 |
< |
ncbins = 1; |
| 90 |
< |
} |
| 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); |
| 96 |
< |
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 |
|
} |