ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rsensor.c
(Generate patch)

Comparing ray/src/util/rsensor.c (file contents):
Revision 2.15 by greg, Thu Apr 23 23:34:18 2015 UTC vs.
Revision 2.17 by greg, Fri Apr 24 19:17:12 2015 UTC

# Line 209 | Line 209 | load_sensor(
209   {
210          int     warnedneg;
211          char    linebuf[8192];
212 +        int     last_pos_val = 0;
213          int     nelem = 1000;
214          float   *sarr = (float *)malloc(sizeof(float)*nelem);
215          FILE    *fp;
# Line 262 | Line 263 | load_sensor(
263                          cp = fskip(cp);
264                          if (cp == NULL)
265                                  break;
266 <                        if (i && sarr[i] < .0) {
266 >                        if (sarr[i] < .0) {
267                                  if (!warnedneg++) {
268                                          sprintf(errmsg,
269                  "Negative value(s) in sensor file '%s' (ignored)\n", sfile);
270                                          error(WARNING, errmsg);
271                                  }
272                                  sarr[i] = .0;
273 <                        }
273 >                        } else if (sarr[i] > FTINY && i > ntp[0]*(ntp[1]+1))
274 >                                last_pos_val = i;
275                          ++i;
276                  }
277 <                if (i == ntp[0]*(ntp[1]+1))
277 >                if (i == ntp[0]*(ntp[1]+1))     /* empty line? */
278                          break;
279                  if (ntp[0] > 1 && sarr[ntp[0]*(ntp[1]+1)] <=
280                                          sarr[(ntp[0]-1)*(ntp[1]+1)]) {
# Line 288 | Line 290 | load_sensor(
290                          error(USER, errmsg);
291                  }
292          }
293 <        nelem = i;
293 >                                                /* truncate zero region */
294 >        ntp[0] = (last_pos_val + ntp[1])/(ntp[1]+1) - 1;
295 >        nelem = (ntp[0]+1)*(ntp[1]+1);
296          fclose(fp);
297          errmsg[0] = '\0';                       /* sanity checks */
298 <        if (ntp[0] <= 0)
299 <                sprintf(errmsg, "no data in sensor file '%s'", sfile);
298 >        if (!last_pos_val)
299 >                sprintf(errmsg, "no positive sensor values in file '%s'", sfile);
300          else if (fabs(sarr[ntp[1]+1]) > FTINY)
301                  sprintf(errmsg, "minimum theta must be 0 in sensor file '%s'",
302                                  sfile);
# Line 303 | Line 307 | load_sensor(
307                  sprintf(errmsg,
308                          "maximum phi must be positive in sensor file '%s'",
309                                  sfile);
306        else if (sarr[ntp[0]*(ntp[1]+1)] <= FTINY)
307                sprintf(errmsg,
308                        "maximum theta must be positive in sensor file '%s'",
309                                sfile);
310          if (errmsg[0])
311                  error(USER, errmsg);
312          return((float *)realloc((void *)sarr, sizeof(float)*nelem));
# Line 366 | Line 366 | init_ptable(
366          psize = PI*tsize/maxtheta;
367          if (sntp[0]*sntp[1] < samptot)  /* don't overdo resolution */
368                  samptot = sntp[0]*sntp[1];
369 <        ntheta = (int)(sqrt((double)samptot*tsize/psize) + 0.5);
369 >        ntheta = (int)(sqrt((double)samptot*tsize/psize)*sntp[0]/sntp[1]) + 1;
370          if (ntheta > MAXNT)
371                  ntheta = MAXNT;
372          nphi = samptot/ntheta;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines