| 9 |
|
|
| 10 |
|
#define _USE_MATH_DEFINES |
| 11 |
|
#include <stdlib.h> |
| 12 |
+ |
#include <string.h> |
| 13 |
|
#include <math.h> |
| 14 |
|
#include "rtio.h" |
| 15 |
|
#include "resolu.h" |
| 342 |
|
MIGRATION *mig; |
| 343 |
|
int i, n; |
| 344 |
|
/* finish header */ |
| 345 |
+ |
fprintf(ofp, "SYMMETRY=%d\n", !single_plane_incident * inp_coverage); |
| 346 |
+ |
fprintf(ofp, "IO_SIDES= %d %d\n", input_orient, output_orient); |
| 347 |
|
fputformat(BSDFREP_FMT, ofp); |
| 348 |
|
fputc('\n', ofp); |
| 349 |
|
/* write each DSF */ |
| 363 |
|
} |
| 364 |
|
putint(-1, 4, ofp); /* terminator */ |
| 365 |
|
/* write each migration matrix */ |
| 366 |
< |
for (mig = mig_list; mig != NULL; mig = mig_list->next) { |
| 366 |
> |
for (mig = mig_list; mig != NULL; mig = mig->next) { |
| 367 |
> |
int zerocnt = 0; |
| 368 |
|
putint(mig->rbfv[0]->ord, 4, ofp); |
| 369 |
|
putint(mig->rbfv[1]->ord, 4, ofp); |
| 370 |
+ |
/* write out as sparse data */ |
| 371 |
|
n = mtx_nrows(mig) * mtx_ncols(mig); |
| 372 |
< |
for (i = 0; i < n; i++) |
| 373 |
< |
putflt(mig->mtx[i], ofp); |
| 372 |
> |
for (i = 0; i < n; i++) { |
| 373 |
> |
if (zerocnt >= 0xff) { |
| 374 |
> |
putint(zerocnt, 1, ofp); zerocnt = 0; |
| 375 |
> |
} |
| 376 |
> |
if (mig->mtx[i] != 0) { |
| 377 |
> |
putint(zerocnt, 1, ofp); zerocnt = 0; |
| 378 |
> |
putflt(mig->mtx[i], ofp); |
| 379 |
> |
} else |
| 380 |
> |
++zerocnt; |
| 381 |
> |
} |
| 382 |
> |
putint(zerocnt, 1, ofp); |
| 383 |
|
} |
| 384 |
|
putint(-1, 4, ofp); /* terminator */ |
| 385 |
|
putint(-1, 4, ofp); |
| 390 |
|
} |
| 391 |
|
} |
| 392 |
|
|
| 393 |
+ |
/* Check header line for critical information */ |
| 394 |
+ |
static int |
| 395 |
+ |
headline(char *s, void *p) |
| 396 |
+ |
{ |
| 397 |
+ |
char fmt[32]; |
| 398 |
+ |
|
| 399 |
+ |
if (!strncmp(s, "SYMMETRY=", 9)) { |
| 400 |
+ |
inp_coverage = atoi(s+9); |
| 401 |
+ |
single_plane_incident = !inp_coverage; |
| 402 |
+ |
return(0); |
| 403 |
+ |
} |
| 404 |
+ |
if (!strncmp(s, "IO_SIDES=", 9)) { |
| 405 |
+ |
sscanf(s+9, "%d %d", &input_orient, &output_orient); |
| 406 |
+ |
return(0); |
| 407 |
+ |
} |
| 408 |
+ |
if (formatval(fmt, s) && strcmp(fmt, BSDFREP_FMT)) |
| 409 |
+ |
return(-1); |
| 410 |
+ |
return(0); |
| 411 |
+ |
} |
| 412 |
+ |
|
| 413 |
|
/* Read a BSDF mesh interpolant from the given binary stream */ |
| 414 |
|
int |
| 415 |
|
load_bsdf_rep(FILE *ifp) |
| 425 |
|
return(0); |
| 426 |
|
} |
| 427 |
|
#endif |
| 428 |
< |
if (checkheader(ifp, BSDFREP_FMT, NULL) <= 0) { |
| 428 |
> |
input_orient = output_orient = 0; |
| 429 |
> |
single_plane_incident = -1; |
| 430 |
> |
if (getheader(ifp, headline, NULL) < 0 || single_plane_incident < 0 | |
| 431 |
> |
!input_orient | !output_orient) { |
| 432 |
|
fprintf(stderr, "%s: missing/bad format for BSDF interpolant\n", |
| 433 |
|
progname); |
| 434 |
|
return(0); |
| 484 |
|
goto memerr; |
| 485 |
|
newmig->rbfv[0] = from_rbf; |
| 486 |
|
newmig->rbfv[1] = to_rbf; |
| 487 |
< |
/* read matrix coefficients */ |
| 488 |
< |
for (i = 0; i < n; i++) |
| 489 |
< |
newmig->mtx[i] = getflt(ifp); |
| 487 |
> |
memset(newmig->mtx, 0, sizeof(float)*n); |
| 488 |
> |
for (i = 0; ; ) { /* read sparse data */ |
| 489 |
> |
int zc = getint(1, ifp) & 0xff; |
| 490 |
> |
if (zc == 0xff) { |
| 491 |
> |
i += 0xff; |
| 492 |
> |
continue; |
| 493 |
> |
} |
| 494 |
> |
if ((i += zc) >= n) |
| 495 |
> |
break; |
| 496 |
> |
newmig->mtx[i++] = getflt(ifp); |
| 497 |
> |
} |
| 498 |
|
if (feof(ifp)) |
| 499 |
|
goto badEOF; |
| 500 |
|
/* insert in edge lists */ |