31 |
|
if (!dnew) |
32 |
|
return(NULL); |
33 |
|
|
34 |
< |
dnew->dtype = DTdouble; |
34 |
> |
dnew->dtype = DTrmx_native; |
35 |
|
dnew->nrows = nr; |
36 |
|
dnew->ncols = nc; |
37 |
|
dnew->ncomp = n; |
51 |
|
if ((rm->nrows <= 0) | (rm->ncols <= 0) | (rm->ncomp <= 0)) |
52 |
|
return(0); |
53 |
|
rm->mtx = (double *)malloc(rmx_array_size(rm)); |
54 |
< |
rm->pflags |= RMF_OURMEM; |
54 |
> |
rm->pflags |= RMF_FREEMEM; |
55 |
|
return(rm->mtx != NULL); |
56 |
|
} |
57 |
|
|
77 |
|
free(rm->info); |
78 |
|
rm->info = NULL; |
79 |
|
} |
80 |
– |
if (rm->mtx && rm->pflags & RMF_OURMEM) { |
80 |
|
#ifdef MAP_FILE |
81 |
< |
if (rm->mapped) { |
82 |
< |
munmap(rm->mapped, rmx_mapped_size(rm)); |
83 |
< |
rm->mapped = NULL; |
84 |
< |
} else |
81 |
> |
if (rm->mapped) { |
82 |
> |
munmap(rm->mapped, rmx_mapped_size(rm)); |
83 |
> |
rm->mapped = NULL; |
84 |
> |
} else |
85 |
|
#endif |
86 |
< |
free(rm->mtx); |
87 |
< |
rm->pflags &= ~RMF_OURMEM; |
86 |
> |
if (rm->pflags & RMF_FREEMEM) { |
87 |
> |
free(rm->mtx); |
88 |
> |
rm->pflags &= ~RMF_FREEMEM; |
89 |
|
} |
90 |
|
rm->mtx = NULL; |
91 |
|
} |
225 |
|
static int |
226 |
|
rmx_load_double(double *drp, const RMATRIX *rm, FILE *fp) |
227 |
|
{ |
228 |
+ |
if (DTrmx_native != DTdouble) |
229 |
+ |
return(0); |
230 |
|
if (getbinary(drp, sizeof(*drp)*rm->ncomp, rm->ncols, fp) != rm->ncols) |
231 |
|
return(0); |
232 |
|
if (rm->pflags & RMF_SWAPIN) |
340 |
|
int i; |
341 |
|
#ifdef MAP_FILE |
342 |
|
long pos; /* map memory for file > 1MB if possible */ |
343 |
< |
if ((rm->dtype == DTdouble) & !(rm->pflags & RMF_SWAPIN) && |
344 |
< |
rmx_array_size(rm) >= 1L<<20 && |
343 |
> |
if ((rm->dtype == DTrmx_native) & !(rm->pflags & RMF_SWAPIN) & |
344 |
> |
(rmx_array_size(rm) >= 1L<<20) && |
345 |
|
(pos = ftell(fp)) >= 0 && !(pos % sizeof(double))) { |
346 |
|
rm->mapped = mmap(NULL, rmx_array_size(rm)+pos, PROT_READ|PROT_WRITE, |
347 |
|
MAP_PRIVATE, fileno(fp), 0); |
348 |
|
if (rm->mapped != MAP_FAILED) { |
349 |
+ |
if (rm->pflags & RMF_FREEMEM) |
350 |
+ |
free(rm->mtx); |
351 |
|
rm->mtx = (double *)rm->mapped + pos/sizeof(double); |
352 |
< |
rm->pflags |= RMF_OURMEM; |
352 |
> |
rm->pflags &= ~RMF_FREEMEM; |
353 |
|
return(1); |
354 |
|
} /* else fall back on reading into memory */ |
355 |
|
rm->mapped = NULL; |
438 |
|
(dnew->cexp[1] != 1.f) | (dnew->cexp[2] != 1.f)) { |
439 |
|
double cmlt[MAXCSAMP]; |
440 |
|
int i; |
437 |
– |
cmlt[0] = 1./dnew->cexp[0]; |
438 |
– |
cmlt[1] = 1./dnew->cexp[1]; |
439 |
– |
cmlt[2] = 1./dnew->cexp[2]; |
441 |
|
if (dnew->ncomp > MAXCSAMP) { |
442 |
|
fprintf(stderr, "Excess spectral components in: %s\n", |
443 |
|
inspec); |
444 |
|
rmx_free(dnew); |
445 |
|
return(NULL); |
446 |
|
} |
447 |
+ |
cmlt[0] = 1./dnew->cexp[0]; |
448 |
+ |
cmlt[1] = 1./dnew->cexp[1]; |
449 |
+ |
cmlt[2] = 1./dnew->cexp[2]; |
450 |
|
for (i = dnew->ncomp; i-- > 3; ) |
451 |
< |
cmlt[i] = cmlt[1]; |
451 |
> |
cmlt[i] = cmlt[1]; /* XXX hack! */ |
452 |
|
rmx_scale(dnew, cmlt); |
453 |
|
setcolor(dnew->cexp, 1.f, 1.f, 1.f); |
454 |
|
} |
595 |
|
return(rmx_write_ascii(dp, nc, len, fp)); |
596 |
|
case DTfloat: |
597 |
|
return(rmx_write_float(dp, nc*len, fp)); |
598 |
< |
case DTdouble: |
598 |
> |
case DTrmx_native: |
599 |
|
return(putbinary(dp, sizeof(*dp)*nc, len, fp) == len); |
600 |
|
case DTrgbe: |
601 |
|
case DTxyze: |
619 |
|
#ifdef getc_unlocked |
620 |
|
flockfile(fp); |
621 |
|
#endif |
622 |
< |
if (dtype == DTdouble) /* write all at once? */ |
622 |
> |
if (dtype == DTrmx_native) /* write all at once? */ |
623 |
|
ok = rmx_write_data(rm->mtx, rm->ncomp, |
624 |
|
rm->nrows*rm->ncols, dtype, fp); |
625 |
|
else /* else row by row */ |
695 |
|
rsrc->info = NULL; rsrc->mapped = NULL; rsrc->mtx = NULL; |
696 |
|
return(1); |
697 |
|
} |
694 |
– |
if (rdst->pflags & RMF_OURMEM) { |
698 |
|
#ifdef MAP_FILE /* just matrix data -- leave metadata */ |
699 |
< |
if (rdst->mapped) |
700 |
< |
munmap(rdst->mapped, rmx_mapped_size(rdst)); |
701 |
< |
else |
699 |
> |
if (rdst->mapped) |
700 |
> |
munmap(rdst->mapped, rmx_mapped_size(rdst)); |
701 |
> |
else |
702 |
|
#endif |
703 |
< |
if (rdst->mtx) |
704 |
< |
free(rdst->mtx); |
702 |
< |
} |
703 |
> |
if (rdst->pflags & RMF_FREEMEM) |
704 |
> |
free(rdst->mtx); |
705 |
|
rdst->mapped = rsrc->mapped; |
706 |
|
rdst->mtx = rsrc->mtx; |
707 |
< |
if (rsrc->pflags & RMF_OURMEM) |
708 |
< |
rdst->pflags |= RMF_OURMEM; |
707 |
> |
if (rsrc->pflags & RMF_FREEMEM) |
708 |
> |
rdst->pflags |= RMF_FREEMEM; |
709 |
|
else |
710 |
< |
rdst->pflags &= ~RMF_OURMEM; |
710 |
> |
rdst->pflags &= ~RMF_FREEMEM; |
711 |
|
rsrc->mapped = NULL; rsrc->mtx = NULL; |
712 |
|
return(1); |
713 |
|
} |