9 |
|
#include <stdlib.h> |
10 |
|
#include <string.h> |
11 |
|
#include <fcntl.h> |
12 |
+ |
#include "rtio.h" |
13 |
+ |
#include "platform.h" |
14 |
|
#include "resolu.h" |
15 |
< |
#include "rtprocess.h" |
15 |
> |
#include "paths.h" |
16 |
|
#include "rmatrix.h" |
17 |
|
|
18 |
|
static char rmx_mismatch_warn[] = "WARNING: data type mismatch\n"; |
113 |
|
rmx_load_ascii(RMATRIX *rm, FILE *fp) |
114 |
|
{ |
115 |
|
int i, j, k; |
116 |
< |
#ifdef _WIN32 |
115 |
< |
_setmode(fileno(fp), _O_TEXT); |
116 |
< |
#endif |
116 |
> |
|
117 |
|
for (i = 0; i < rm->nrows; i++) |
118 |
|
for (j = 0; j < rm->ncols; j++) |
119 |
|
for (k = 0; k < rm->ncomp; k++) |
134 |
|
} |
135 |
|
for (i = 0; i < rm->nrows; i++) |
136 |
|
for (j = 0; j < rm->ncols; j++) { |
137 |
< |
if (fread(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
137 |
> |
if (getbinary(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
138 |
|
return(0); |
139 |
|
for (k = rm->ncomp; k--; ) |
140 |
|
rmx_lval(rm,i,j,k) = val[k]; |
154 |
|
} |
155 |
|
for (i = 0; i < rm->nrows; i++) |
156 |
|
for (j = 0; j < rm->ncols; j++) { |
157 |
< |
if (fread(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
157 |
> |
if (getbinary(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
158 |
|
return(0); |
159 |
|
for (k = rm->ncomp; k--; ) |
160 |
|
rmx_lval(rm,i,j,k) = val[k]; |
195 |
|
|
196 |
|
if (inspec == NULL) { /* reading from stdin? */ |
197 |
|
inspec = "<stdin>"; |
198 |
< |
#ifdef _WIN32 |
198 |
> |
#if defined(_WIN32) || defined(_WIN64) |
199 |
|
_setmode(fileno(stdin), _O_BINARY); |
200 |
|
#endif |
201 |
|
} else if (inspec[0] == '!') { |
202 |
|
if ((fp = popen(inspec+1, "r")) == NULL) |
203 |
|
return(NULL); |
204 |
< |
#ifdef _WIN32 |
204 |
> |
#if defined(_WIN32) || defined(_WIN64) |
205 |
|
_setmode(fileno(fp), _O_BINARY); |
206 |
|
#endif |
207 |
|
} else { |
216 |
|
return(NULL); |
217 |
|
dnew = rmx_from_cmatrix(cm); |
218 |
|
cm_free(cm); |
219 |
+ |
dnew->dtype = DTascii; |
220 |
|
return(dnew); |
221 |
|
} |
222 |
|
/* else open it ourselves */ |
254 |
|
dnew->info = dinfo.info; |
255 |
|
switch (dinfo.dtype) { |
256 |
|
case DTascii: |
257 |
+ |
#if defined(_WIN32) || defined(_WIN64) |
258 |
+ |
_setmode(fileno(fp), _O_TEXT); |
259 |
+ |
#endif |
260 |
|
if (!rmx_load_ascii(dnew, fp)) |
261 |
|
goto loaderr; |
262 |
|
dnew->dtype = DTascii; /* should leave double? */ |
304 |
|
rmx_write_ascii(const RMATRIX *rm, FILE *fp) |
305 |
|
{ |
306 |
|
int i, j, k; |
307 |
< |
#ifdef _WIN32 |
304 |
< |
_setmode(fileno(fp), _O_TEXT); |
305 |
< |
#endif |
307 |
> |
|
308 |
|
for (i = 0; i < rm->nrows; i++) { |
309 |
|
for (j = 0; j < rm->ncols; j++) { |
310 |
|
for (k = 0; k < rm->ncomp; k++) |
330 |
|
for (j = 0; j < rm->ncols; j++) { |
331 |
|
for (k = rm->ncomp; k--; ) |
332 |
|
val[k] = (float)rmx_lval(rm,i,j,k); |
333 |
< |
if (fwrite(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
333 |
> |
if (putbinary(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
334 |
|
return(0); |
335 |
|
} |
336 |
|
return(1); |
350 |
|
for (j = 0; j < rm->ncols; j++) { |
351 |
|
for (k = rm->ncomp; k--; ) |
352 |
|
val[k] = rmx_lval(rm,i,j,k); |
353 |
< |
if (fwrite(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
353 |
> |
if (putbinary(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
354 |
|
return(0); |
355 |
|
} |
356 |
|
return(1); |
387 |
|
|
388 |
|
if ((rm == NULL) | (fp == NULL)) |
389 |
|
return(0); |
390 |
+ |
#ifdef getc_unlocked |
391 |
+ |
flockfile(fp); |
392 |
+ |
#endif |
393 |
|
/* complete header */ |
394 |
|
if (rm->info) |
395 |
|
fputs(rm->info, fp); |
434 |
|
return(0); |
435 |
|
} |
436 |
|
ok &= (fflush(fp) == 0); |
437 |
+ |
#ifdef getc_unlocked |
438 |
+ |
funlockfile(fp); |
439 |
+ |
#endif |
440 |
|
rmx_free(mydm); |
441 |
|
return(ok); |
442 |
|
} |