--- ray/src/util/rsensor.c 2013/10/16 04:35:50 2.13 +++ ray/src/util/rsensor.c 2015/04/23 23:54:08 2.16 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rsensor.c,v 2.13 2013/10/16 04:35:50 greg Exp $"; +static const char RCSid[] = "$Id: rsensor.c,v 2.16 2015/04/23 23:54:08 greg Exp $"; #endif /* @@ -15,7 +15,7 @@ static const char RCSid[] = "$Id: rsensor.c,v 2.13 201 #define DEGREE (PI/180.) -#define MAXNT 180 /* maximum number of theta divisions */ +#define MAXNT 181 /* maximum number of theta divisions */ #define MAXNP 360 /* maximum number of phi divisions */ extern char *progname; /* global argv[0] */ @@ -209,6 +209,7 @@ load_sensor( { int warnedneg; char linebuf[8192]; + int last_pos_val = 0; int nelem = 1000; float *sarr = (float *)malloc(sizeof(float)*nelem); FILE *fp; @@ -269,7 +270,8 @@ load_sensor( error(WARNING, errmsg); } sarr[i] = .0; - } + } else if (i > ntp[0]*(ntp[1]+1) && sarr[i] > FTINY) + last_pos_val = i; ++i; } if (i == ntp[0]*(ntp[1]+1)) @@ -288,9 +290,13 @@ load_sensor( error(USER, errmsg); } } - nelem = i; + /* truncate zero region */ + ntp[0] = (last_pos_val + ntp[1])/(ntp[1]+1) - 1; + nelem = (ntp[0]+1)*(ntp[1]+1); fclose(fp); errmsg[0] = '\0'; /* sanity checks */ + if (!last_pos_val) + sprintf(errmsg, "no positive sensor values in file '%s'", sfile); if (ntp[0] <= 0) sprintf(errmsg, "no data in sensor file '%s'", sfile); else if (fabs(sarr[ntp[1]+1]) > FTINY) @@ -305,8 +311,8 @@ load_sensor( sfile); else if (sarr[ntp[0]*(ntp[1]+1)] <= FTINY) sprintf(errmsg, - "maximum theta must be positive in sensor file '%s'", - sfile); + "maximum theta (%f) must be positive in sensor file '%s'", + sarr[ntp[0]*(ntp[1]+1)], sfile); if (errmsg[0]) error(USER, errmsg); return((float *)realloc((void *)sarr, sizeof(float)*nelem)); @@ -398,9 +404,8 @@ init_ptable( tvals[i] = 1. - ( (1.-frac)*cos(thdiv[t]) + frac*cos(thdiv[t+1]) ); /* offset b/c sensor values are centered */ - if ((t < sntp[0]-1) & (frac >= 0.5)) { - if ((frac -= 0.5) < 0) - frac = 0; + if ((t < sntp[0]-1) & (!t | (frac >= 0.5))) { + frac -= 0.5; } else { frac += 0.5; --t; @@ -425,6 +430,9 @@ init_ptable( } pvals[i*(nphi+1) + nphi] = phdiv[sntp[1]]; } + /* duplicate final row */ + memcpy(pvals+ntheta*(nphi+1), pvals+(ntheta-1)*(nphi+1), + sizeof(*pvals)*(nphi+1)); tvals[0] = .0f; tvals[ntheta] = (float)tsize; }