source: soft/giet_vm/applications/rosenfeld/nrc2/src/nrio1f.c @ 807

Last change on this file since 807 was 772, checked in by meunier, 9 years ago
  • Ajout de l'application rosenfeld
  • Changement du nom du flag O_CREATE en O_CREAT
File size: 35.7 KB
Line 
1/* ---------------- */
2/* --- nriof1.c --- */
3/* ---------------- */
4
5/*
6 * Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved
7 * Univ Paris Sud XI, CNRS
8 *
9 * Distributed under the Boost Software License, Version 1.0
10 * see accompanying file LICENSE.txt or copy it at
11 * http://www.boost.org/LICENSE_1_0.txt
12 */
13
14#include <stdio.h>
15#include <stddef.h>
16#include <stdlib.h>
17
18#include "mypredef.h"
19#include "nrtype.h"
20#include "nrdef.h"
21#include "nrmacro.h"
22#include "nrkernel.h"
23
24#include "nralloc1.h"
25#include "nrio0.h"
26#include "nrio1.h"
27
28/*
29 * --------------------
30 * --- write_vector ---
31 * --------------------
32 */
33/* ------------------------------------------------------------------------------------ */
34IMAGE_EXPORT(void) write_si8vector(sint8 *v,long nl,long nh, char *format, char *filename)
35/* ------------------------------------------------------------------------------------ */
36{
37  long  k;
38  FILE *f;
39
40  f = fopen(filename, "wt");
41  if(f == NULL) { nrerror("Can't open file in write_si8vector"); }
42  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
43  fclose(f);
44}
45/* ------------------------------------------------------------------------------------ */
46IMAGE_EXPORT(void) write_ui8vector(uint8 *v,long nl,long nh, char *format, char *filename)
47/* ------------------------------------------------------------------------------------ */
48{
49  long  k;
50  FILE *f;
51
52  f = fopen(filename, "wt");
53  if(f == NULL) { nrerror("Can't open file in write_ui8vector"); }
54  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
55  fclose(f);
56}
57
58/* -------------------------------------------------------------------------------------- */
59IMAGE_EXPORT(void) write_si16vector(sint16 *v,long nl,long nh, char *format, char *filename)
60/* -------------------------------------------------------------------------------------- */
61{
62  long  k;
63  FILE *f;
64
65  f = fopen(filename, "wt");
66  if(f == NULL) { nrerror("Can't open file in write_si16vector"); }
67  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
68  fclose(f);
69}
70/* -------------------------------------------------------------------------------------- */
71IMAGE_EXPORT(void) write_ui16vector(uint16 *v,long nl,long nh, char *format, char *filename)
72/* -------------------------------------------------------------------------------------- */
73{
74  long  k;
75  FILE *f;
76
77  f = fopen(filename, "wt");
78  if(f == NULL) { nrerror("Can't open file in write_ui16vector"); }
79  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
80  fclose(f);
81}
82/* -------------------------------------------------------------------------------------- */
83IMAGE_EXPORT(void) write_si32vector(sint32 *v,long nl,long nh, char *format, char *filename)
84/* -------------------------------------------------------------------------------------- */
85{
86  long  k;
87  FILE *f;
88
89  f = fopen(filename, "wt");
90  if(f == NULL) { nrerror("Can't open file in write_si32vector"); }
91  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
92  fclose(f);
93}
94/* -------------------------------------------------------------------------------------- */
95IMAGE_EXPORT(void) write_ui32vector(uint32 *v,long nl,long nh, char *format, char *filename)
96/* -------------------------------------------------------------------------------------- */
97{
98  long  k;
99  FILE *f;
100
101  f = fopen(filename, "wt");
102  if(f == NULL) { nrerror("Can't open file in write_ui32vector"); }
103  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
104  fclose(f);
105}
106/* -------------------------------------------------------------------------------------- */
107IMAGE_EXPORT(void) write_si64vector(sint64 *v,long nl,long nh, char *format, char *filename)
108/* -------------------------------------------------------------------------------------- */
109{
110  long  k;
111  FILE *f;
112
113  f = fopen(filename, "wt");
114  if(f == NULL) { nrerror("Can't open file in write_si64vector"); }
115  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
116  fclose(f);
117}
118/* ------------------------------------------------------------------------------------- */
119IMAGE_EXPORT(void) write_i64vector(uint64 *v,long nl,long nh, char *format, char *filename)
120/* ------------------------------------------------------------------------------------- */
121{
122  long  k;
123  FILE *f;
124
125  f = fopen(filename, "wt");
126  if(f == NULL) { nrerror("Can't open file in write_ui64vector"); }
127  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
128  fclose(f);
129}
130/* -------------------------------------------------------------------------------------- */
131IMAGE_EXPORT(void) write_f32vector(float32 *v,long nl,long nh, char *format, char *filename)
132/* -------------------------------------------------------------------------------------- */
133{
134  long  k;
135  FILE *f;
136
137  f = fopen(filename, "wt");
138  if(f == NULL) { nrerror("Can't open file in write_f32vector"); }
139  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
140  fclose(f);
141}
142/* -------------------------------------------------------------------------------------- */
143IMAGE_EXPORT(void) write_f64vector(float64 *v,long nl,long nh, char *format, char *filename)
144/* -------------------------------------------------------------------------------------- */
145{
146  long  k;
147  FILE *f;
148
149  f = fopen(filename, "wt");
150  if(f == NULL) { nrerror("Can't open file in write_f64vector"); }
151  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
152  fclose(f);
153}
154/* ---------------------------------------------------------------------------------- */
155IMAGE_EXPORT(void) write_rgb8vector(rgb8 *v,long nl,long nh, char *format, char *filename)
156/* ---------------------------------------------------------------------------------- */
157{
158  long  k;
159  FILE *f;
160
161  f = fopen(filename, "wt");
162  if(f == NULL) { nrerror("Can't open file in write_rgb8vector"); }
163  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k].r, v[k].g, v[k].b); } fputc('\n', f);
164  fclose(f);
165}
166/* -------------------------------------------------------------------------------------- */
167IMAGE_EXPORT(void) write_rgbx8vector(rgbx8 *v,long nl,long nh, char *format, char *filename)
168/* -------------------------------------------------------------------------------------- */
169{
170  long  k;
171  FILE *f;
172
173  f = fopen(filename, "wt");
174  if(f == NULL) { nrerror("Can't open file in write_rgbx8vector"); }
175  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k].r, v[k].g, v[k].b); } fputc('\n', f);
176  fclose(f);
177}
178/*
179 * ----------------------
180 * --- write_vector_T ---
181 * ----------------------
182 */
183/* -------------------------------------------------------------------------------------- */
184IMAGE_EXPORT(void) write_si8vector_T(sint8 *v,long nl,long nh, char *format, char *filename)
185/* -------------------------------------------------------------------------------------- */
186{
187  long  k;
188  FILE *f;
189
190  f = fopen(filename, "wt");
191  if(f == NULL) { nrerror("Can't open file in write_si8vector"); }
192  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); fputc('\n', f); }
193  fclose(f);
194}
195/* -------------------------------------------------------------------------------------- */
196IMAGE_EXPORT(void) write_ui8vector_T(uint8 *v,long nl,long nh, char *format, char *filename)
197/* -------------------------------------------------------------------------------------- */
198{
199  long  k;
200  FILE *f;
201
202  f = fopen(filename, "wt");
203  if(f == NULL) { nrerror("Can't open file in write_ui8vector"); }
204  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); fputc('\n', f); }
205  fclose(f);
206}
207/* ---------------------------------------------------------------------------------------- */
208IMAGE_EXPORT(void) write_si16vector_T(sint16 *v,long nl,long nh, char *format, char *filename)
209/* ---------------------------------------------------------------------------------------- */
210{
211  long  k;
212  FILE *f;
213
214  f = fopen(filename, "wt");
215  if(f == NULL) { nrerror("Can't open file in write_si16vector"); }
216  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); fputc('\n', f); }
217  fclose(f);
218}
219/* -------------------------------------------------------------------------------------- */
220IMAGE_EXPORT(void) write_ui16vector_T(uint16 *v,long nl,long nh, char *format, char *filename)
221/* -------------------------------------------------------------------------------------- */
222{
223  long  k;
224  FILE *f;
225
226  f = fopen(filename, "wt");
227  if(f == NULL) { nrerror("Can't open file in write_ui16vector"); }
228  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); fputc('\n', f); }
229  fclose(f);
230}
231/* ---------------------------------------------------------------------------------------- */
232IMAGE_EXPORT(void) write_si32vector_T(sint32 *v,long nl,long nh, char *format, char *filename)
233/* ---------------------------------------------------------------------------------------- */
234{
235  long  k;
236  FILE *f;
237
238  f = fopen(filename, "wt");
239  if(f == NULL) { nrerror("Can't open file in write_si32vector"); }
240  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); fputc('\n', f); }
241  fclose(f);
242}
243/* ---------------------------------------------------------------------------------------- */
244IMAGE_EXPORT(void) write_ui32vector_T(uint32 *v,long nl,long nh, char *format, char *filename)
245/* ---------------------------------------------------------------------------------------- */
246{
247  long  k;
248  FILE *f;
249
250  f = fopen(filename, "wt");
251  if(f == NULL) { nrerror("Can't open file in write_ui32vector"); }
252  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); fputc('\n', f); }
253  fclose(f);
254}
255/* ---------------------------------------------------------------------------------------- */
256IMAGE_EXPORT(void) write_si64vector_T(sint64 *v,long nl,long nh, char *format, char *filename)
257/* ---------------------------------------------------------------------------------------- */
258{
259  long  k;
260  FILE *f;
261
262  f = fopen(filename, "wt");
263  if(f == NULL) { nrerror("Can't open file in write_si64vector"); }
264  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); fputc('\n', f); }
265  fclose(f);
266}
267/* ---------------------------------------------------------------------------------------- */
268IMAGE_EXPORT(void) write_ui64vector_T(uint64 *v,long nl,long nh, char *format, char *filename)
269/* ---------------------------------------------------------------------------------------- */
270{
271  long  k;
272  FILE *f;
273
274  f = fopen(filename, "wt");
275  if(f == NULL) { nrerror("Can't open file in write_ui64vector"); }
276  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); fputc('\n', f); }
277  fclose(f);
278}
279/* -------------------------------------------------------------------------------------- */
280IMAGE_EXPORT(void) write_rgb8vector_T(rgb8 *v,long nl,long nh, char *format, char *filename)
281/* -------------------------------------------------------------------------------------- */
282{
283  long  k;
284  FILE *f;
285
286  f = fopen(filename, "wt");
287  if(f == NULL) { nrerror("Can't open file in write_rgb8vector_T"); }
288  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k].r, v[k].g, v[k].b); fputc('\n', f); }
289  fclose(f);
290}
291/* ---------------------------------------------------------------------------------------- */
292IMAGE_EXPORT(void) write_rgbx8vector_T(rgbx8 *v,long nl,long nh, char *format, char *filename)
293/* ---------------------------------------------------------------------------------------- */
294{
295  long  k;
296  FILE *f;
297
298  f = fopen(filename, "wt");
299  if(f == NULL) { nrerror("Can't open file in write_rgbx8vector_T"); }
300  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k].r, v[k].g, v[k].b); fputc('\n', f); }
301  fclose(f);
302}
303
304/*
305 * ---------------------------
306 * --- write_vector_number ---
307 * ---------------------------
308 */
309/* --------------------------------------------------------------------------------------------- */
310IMAGE_EXPORT(void) write_si8vector_number(sint8 *v,long nl,long nh, char *format, char *filename)
311/* --------------------------------------------------------------------------------------------- */
312{
313  int  k;
314  FILE *f;
315
316  f = fopen(filename, "wt");
317  if(f == NULL) { nrerror("Can't open file in write_si8vector_number"); }
318  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
319  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
320  fclose(f);
321}
322/* ------------------------------------------------------------------------------------------- */
323IMAGE_EXPORT(void) write_ui8vector_number(uint8 *v,long nl,long nh, char *format, char *filename)
324/* ------------------------------------------------------------------------------------------- */
325{
326  int  k;
327  FILE *f;
328
329  f = fopen(filename, "wt");
330  if(f == NULL) { nrerror("Can't open file in write_ui8vector_number"); }
331  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
332  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
333  fclose(f);
334}
335/* --------------------------------------------------------------------------------------------- */
336IMAGE_EXPORT(void) write_si16vector_number(sint16 *v,long nl,long nh, char *format, char *filename)
337/* --------------------------------------------------------------------------------------------- */
338{
339  int  k;
340  FILE *f;
341
342  f = fopen(filename, "wt");
343  if(f == NULL) { nrerror("Can't open file in write_si16vector_number"); }
344  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
345  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
346  fclose(f);
347}
348/* ------------------------------------------------------------------------------------------- */
349IMAGE_EXPORT(void) write_ui16vector_number(uint16 *v,long nl,long nh, char *format, char *filename)
350/* ------------------------------------------------------------------------------------------- */
351{
352  int  k;
353  FILE *f;
354
355  f = fopen(filename, "wt");
356  if(f == NULL) { nrerror("Can't open file in write_ui16vector_number"); }
357  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
358  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
359  fclose(f);
360}
361/* --------------------------------------------------------------------------------------------- */
362IMAGE_EXPORT(void) write_si32vector_number(sint32 *v,long nl,long nh, char *format, char *filename)
363/* --------------------------------------------------------------------------------------------- */
364{
365  int  k;
366  FILE *f;
367
368  f = fopen(filename, "wt");
369  if(f == NULL) { nrerror("Can't open file in write_si32vector_number"); }
370  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
371  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
372  fclose(f);
373}
374/* ------------------------------------------------------------------------------------------- */
375IMAGE_EXPORT(void) write_ui32vector_number(uint32 *v,long nl,long nh, char *format, char *filename)
376/* ------------------------------------------------------------------------------------------- */
377{
378  int  k;
379  FILE *f;
380
381  f = fopen(filename, "wt");
382  if(f == NULL) { nrerror("Can't open file in write_ui32vector_number"); }
383  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
384  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
385  fclose(f);
386}
387/* --------------------------------------------------------------------------------------------- */
388IMAGE_EXPORT(void) write_si64vector_number(sint64 *v,long nl,long nh, char *format, char *filename)
389/* --------------------------------------------------------------------------------------------- */
390{
391  int  k;
392  FILE *f;
393
394  f = fopen(filename, "wt");
395  if(f == NULL) { nrerror("Can't open file in write_si64vector_number"); }
396  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
397  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
398  fclose(f);
399}
400/* ------------------------------------------------------------------------------------------- */
401IMAGE_EXPORT(void) write_ui64vector_number(uint64 *v,long nl,long nh, char *format, char *filename)
402/* ------------------------------------------------------------------------------------------- */
403{
404  int  k;
405  FILE *f;
406
407  f = fopen(filename, "wt");
408  if(f == NULL) { nrerror("Can't open file in write_ui64vector_number"); }
409  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
410  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
411  fclose(f);
412}
413/* --------------------------------------------------------------------------------------------- */
414IMAGE_EXPORT(void) write_f32vector_number(float32 *v,long nl,long nh, char *format, char *filename)
415/* --------------------------------------------------------------------------------------------- */
416{
417  int k;
418  FILE *f;
419
420  f = fopen(filename, "wt");
421  if(f == NULL) { nrerror("Can't open file in write_f32vector_number"); }
422  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
423  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
424  fclose(f);
425}
426/* --------------------------------------------------------------------------------------------- */
427IMAGE_EXPORT(void) write_f64vector_number(float64 *v,long nl,long nh, char *format, char *filename)
428/* --------------------------------------------------------------------------------------------- */
429{
430  int k;
431  FILE *f;
432
433  f = fopen(filename, "wt");
434  if(f == NULL) { nrerror("Can't open file in write_f32vector_number"); }
435  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
436  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
437  fclose(f);
438}
439/* ------------------------------------------------------------------------------------------- */
440IMAGE_EXPORT(void) write_rgb8vector_number(rgb8 *v,long nl,long nh, char *format, char *filename)
441/* ------------------------------------------------------------------------------------------- */
442{
443  int  k;
444  FILE *f;
445
446  f = fopen(filename, "wt");
447  if(f == NULL) { nrerror("Can't open file in write_rgb8vector_number"); }
448  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
449  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k].r, v[k].g, v[k].b); } fputc('\n', f);
450  fclose(f);
451}
452/* --------------------------------------------------------------------------------------------- */
453IMAGE_EXPORT(void) write_rgbx8vector_number(rgbx8 *v,long nl,long nh, char *format, char *filename)
454/* --------------------------------------------------------------------------------------------- */
455{
456  int  k;
457  FILE *f;
458
459  f = fopen(filename, "wt");
460  if(f == NULL) { nrerror("Can't open file in write_rgbx8vector_number"); }
461  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
462  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k].r, v[k].g, v[k].b); } fputc('\n', f);
463  fclose(f);
464}
465/*
466 * -----------------------------
467 * --- write_vector_T_number ---
468 * -----------------------------
469 */
470
471/* --------------------------------------------------------------------------------------------- */
472IMAGE_EXPORT(void) write_si8vector_T_number(sint8 *v,long nl,long nh, char *format, char *filename)
473/* --------------------------------------------------------------------------------------------- */
474{
475  int  k;
476  FILE *f;
477
478  f = fopen(filename, "wt");
479  if(f == NULL) { nrerror("Can't open file in write_si8vector"); }
480  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
481  fclose(f);
482}
483/* --------------------------------------------------------------------------------------------- */
484IMAGE_EXPORT(void) write_ui8vector_T_number(uint8 *v,long nl,long nh, char *format, char *filename)
485/* --------------------------------------------------------------------------------------------- */
486{
487  int  k;
488  FILE *f;
489
490  f = fopen(filename, "wt");
491  if(f == NULL) { nrerror("Can't open file in write_ui8vector"); }
492  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
493  fclose(f);
494}
495/* ----------------------------------------------------------------------------------------------- */
496IMAGE_EXPORT(void) write_si16vector_T_number(sint16 *v,long nl,long nh, char *format, char *filename)
497/* ----------------------------------------------------------------------------------------------- */
498{
499  int  k;
500  FILE *f;
501
502  f = fopen(filename, "wt");
503  if(f == NULL) { nrerror("Can't open file in write_si16vector"); }
504  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
505  fclose(f);
506}
507/* ----------------------------------------------------------------------------------------------- */
508IMAGE_EXPORT(void) write_ui16vector_T_number(uint16 *v,long nl,long nh, char *format, char *filename)
509/* ----------------------------------------------------------------------------------------------- */
510{
511  int  k;
512  FILE *f;
513
514  f = fopen(filename, "wt");
515  if(f == NULL) { nrerror("Can't open file in write_ui16vector"); }
516  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
517  fclose(f);
518}
519/* ----------------------------------------------------------------------------------------------- */
520IMAGE_EXPORT(void) write_si32vector_T_number(sint32 *v,long nl,long nh, char *format, char *filename)
521/* ----------------------------------------------------------------------------------------------- */
522{
523  int  k;
524  FILE *f;
525
526  f = fopen(filename, "wt");
527  if(f == NULL) { nrerror("Can't open file in write_si32vector"); }
528  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
529  fclose(f);
530}
531/* ------------------------------------------------------------------------------------------- */
532IMAGE_EXPORT(void) write_ui32vector_T_number(uint32 *v,long nl,long nh, char *format, char *filename)
533/* ------------------------------------------------------------------------------------------- */
534{
535  int  k;
536  FILE *f;
537
538  f = fopen(filename, "wt");
539  if(f == NULL) { nrerror("Can't open file in write_ui32vector_T_number"); }
540  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
541  fclose(f);
542}
543/* ----------------------------------------------------------------------------------------------- */
544IMAGE_EXPORT(void) write_si64vector_T_number(sint64 *v,long nl,long nh, char *format, char *filename)
545/* ----------------------------------------------------------------------------------------------- */
546{
547  int  k;
548  FILE *f;
549
550  f = fopen(filename, "wt");
551  if(f == NULL) { nrerror("Can't open file in write_i64vector"); }
552  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
553  fclose(f);
554}
555/* ----------------------------------------------------------------------------------------------- */
556IMAGE_EXPORT(void) write_ui64vector_T_number(uint64 *v,long nl,long nh, char *format, char *filename)
557/* ----------------------------------------------------------------------------------------------- */
558{
559  int  k;
560  FILE *f;
561
562  f = fopen(filename, "wt");
563  if(f == NULL) { nrerror("Can't open file in write_i64vector"); }
564  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
565  fclose(f);
566}
567/* ----------------------------------------------------------------------------------------------- */
568IMAGE_EXPORT(void) write_f32vector_T_number(float32 *v,long nl,long nh, char *format, char *filename)
569/* ----------------------------------------------------------------------------------------------- */
570{
571  int  k;
572  FILE *f;
573
574  f = fopen(filename, "wt");
575  if(f == NULL) { nrerror("Can't open file in write_f32vector"); }
576  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
577  fclose(f);
578}
579/* ----------------------------------------------------------------------------------------------- */
580IMAGE_EXPORT(void) write_f64vector_T_number(float64 *v,long nl,long nh, char *format, char *filename)
581/* ----------------------------------------------------------------------------------------------- */
582{
583  int  k;
584  FILE *f;
585
586  f = fopen(filename, "wt");
587  if(f == NULL) { nrerror("Can't open file in write_f64vector"); }
588  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
589  fclose(f);
590}
591/* ------------------------------------------------------------------------------------------- */
592IMAGE_EXPORT(void) write_rgb8vector_T_number(rgb8 *v,long nl,long nh, char *format, char *filename)
593/* ------------------------------------------------------------------------------------------- */
594{
595  int  k;
596  FILE *f;
597
598  f = fopen(filename, "wt");
599  if(f == NULL) { nrerror("Can't open file in write_rgb8vector_T"); }
600  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k].r, v[k].g, v[k].b); fputc('\n', f); }
601  fclose(f);
602}
603/* ----------------------------------------------------------------------------------------------- */
604IMAGE_EXPORT(void) write_rgbx8vector_T_number(rgbx8 *v,long nl,long nh, char *format, char *filename)
605/* ----------------------------------------------------------------------------------------------- */
606{
607  int  k;
608  FILE *f;
609
610  f = fopen(filename, "wt");
611  if(f == NULL) { nrerror("Can't open file in write_rgb8vector_T"); }
612  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k].r, v[k].g, v[k].b); fputc('\n', f); }
613  fclose(f);
614}
615
616/*
617 * --------------------
618 * --- fread_vector ---
619 * --------------------
620 */
621
622/* ---------------------------------------------------------------------- */
623IMAGE_EXPORT(void) fread_si8vector(char *filename, sint8 *v,long nl,long nh)
624/* ---------------------------------------------------------------------- */
625{
626  long ncol=nh-nl+1, nread;
627  FILE *f;
628
629  f = fopen(filename, "rb");
630  if(f == NULL) nrerror("Can't open file in fread_si8vector");
631
632  nread = fread(v+nl, sizeof(sint8), ncol, f);
633  if(nread != ncol) nrerror("fread_si8vector can't read the whole vector");
634  fclose(f);
635}
636/* ---------------------------------------------------------------------- */
637IMAGE_EXPORT(void) fread_ui8vector(char *filename, uint8 *v,long nl,long nh)
638/* ---------------------------------------------------------------------- */
639{
640  long ncol=nh-nl+1, nread;
641  FILE *f;
642
643  f = fopen(filename, "rb");
644  if(f == NULL) nrerror("Can't open file in fread_ui8vector");
645
646  nread = fread(v+nl, sizeof(uint8), ncol, f);
647  if(nread != ncol) nrerror("fread_ui8vector can't read the whole vector");
648  fclose(f);
649}
650/* ------------------------------------------------------------------------ */
651IMAGE_EXPORT(void) fread_si16vector(char *filename, sint16 *v,long nl,long nh)
652/* ------------------------------------------------------------------------ */
653{
654  long ncol=nh-nl+1, nread;
655  FILE *f;
656
657  f = fopen(filename, "rb");
658  if(f == NULL) nrerror("Can't open file in fread_si16vector");
659
660  nread = fread(v+nl, sizeof(int16), ncol, f);
661  if(nread != ncol) nrerror("fread_si16vector can't read the whole vector");
662  fclose(f);
663}
664/* ------------------------------------------------------------------------ */
665IMAGE_EXPORT(void) fread_ui16vector(char *filename, uint16 *v,long nl,long nh)
666/* ------------------------------------------------------------------------ */
667{
668  long ncol=nh-nl+1, nread;
669  FILE *f;
670
671  f = fopen(filename, "rb");
672  if(f == NULL) nrerror("Can't open file in fread_ui16vector");
673
674  nread = fread(v+nl, sizeof(int16), ncol, f);
675  if(nread != ncol) nrerror("fread_ui16vector can't read the whole vector");
676  fclose(f);
677}
678/* ------------------------------------------------------------------------ */
679IMAGE_EXPORT(void) fread_si32vector(char *filename, sint32 *v,long nl,long nh)
680/* ------------------------------------------------------------------------ */
681{
682  long ncol=nh-nl+1, nread;
683  FILE *f;
684
685  f = fopen(filename, "rb");
686  if(f == NULL) nrerror("Can't open file in fread_si32vector");
687
688  nread = fread(v+nl, sizeof(sint32), ncol, f);
689  if(nread != ncol) nrerror("fread_si32vector can't read the whole vector");
690  fclose(f);
691}
692/* ------------------------------------------------------------------------ */
693IMAGE_EXPORT(void) fread_ui32vector(char *filename, uint32 *v,long nl,long nh)
694/* ------------------------------------------------------------------------ */
695{
696  long ncol=nh-nl+1, nread;
697  FILE *f;
698
699  f = fopen(filename, "rb");
700  if(f == NULL) nrerror("Can't open file in fread_ui32vector");
701
702  nread = fread(v+nl, sizeof(uint32), ncol, f);
703  if(nread != ncol) nrerror("fread_ui32vector can't read the whole vector");
704  fclose(f);
705}
706/* ------------------------------------------------------------------------ */
707IMAGE_EXPORT(void) fread_si64vector(char *filename, sint64 *v,long nl,long nh)
708/* ------------------------------------------------------------------------ */
709{
710  long ncol=nh-nl+1, nread;
711  FILE *f;
712
713  f = fopen(filename, "rb");
714  if(f == NULL) nrerror("Can't open file in fread_si64vector");
715
716  nread = fread(v+nl, sizeof(sint64), ncol, f);
717  if(nread != ncol) nrerror("fread_si64vector can't read the whole vector");
718  fclose(f);
719}
720/* ------------------------------------------------------------------------ */
721IMAGE_EXPORT(void) fread_ui64vector(char *filename, uint64 *v,long nl,long nh)
722/* ------------------------------------------------------------------------ */
723{
724  long ncol=nh-nl+1, nread;
725  FILE *f;
726
727  f = fopen(filename, "rb");
728  if(f == NULL) nrerror("Can't open file in fread_ui64vector");
729
730  nread = fread(v+nl, sizeof(uint64), ncol, f);
731  if(nread != ncol) nrerror("fread_ui64vector can't read the whole vector");
732  fclose(f);
733}
734/* ------------------------------------------------------------------------ */
735IMAGE_EXPORT(void) fread_f32vector(char *filename, float32 *v,long nl,long nh)
736/* ------------------------------------------------------------------------ */
737{
738  long ncol=nh-nl+1, nread;
739  FILE *f;
740
741  f = fopen(filename, "rb");
742  if(f == NULL) nrerror("Can't open file in fread_f32vector");
743
744  nread = fread(v+nl, sizeof(float32), ncol, f);
745  if(nread != ncol) nrerror("fread_f32vector can't read the whole vector");
746  fclose(f);
747}
748/* ------------------------------------------------------------------------ */
749IMAGE_EXPORT(void) fread_f64vector(char *filename, float64 *v,long nl,long nh)
750/* ------------------------------------------------------------------------ */
751{
752  long ncol=nh-nl+1, nread;
753  FILE *f;
754
755  f = fopen(filename, "rb");
756  if(f == NULL) nrerror("Can't open file in fread_f64vector");
757
758  nread = fread(v+nl, sizeof(float64), ncol, f);
759  if(nread != ncol) nrerror("fread_f64vector can't read the whole vector");
760  fclose(f);
761}
762/* ---------------------------------------------------------------------- */
763IMAGE_EXPORT(void) fread_rgb8vector(char *filename, rgb8 *v,long nl,long nh)
764/* ---------------------------------------------------------------------- */
765{
766  long ncol=nh-nl+1, nread;
767  FILE *f;
768
769  f = fopen(filename, "rb");
770  if(f == NULL) nrerror("Can't open file in fread_rgb8vector");
771
772  nread = fread(v+nl, sizeof(float32), ncol, f);
773  if(nread != ncol) nrerror("fread_rgb8vector can't read the whole vector");
774  fclose(f);
775}
776/* ------------------------------------------------------------------------ */
777IMAGE_EXPORT(void) fread_rgbx8vector(char *filename, rgbx8 *v,long nl,long nh)
778/* ------------------------------------------------------------------------ */
779{
780  long ncol=nh-nl+1, nread;
781  FILE *f;
782
783  f = fopen(filename, "rb");
784  if(f == NULL) nrerror("Can't open file in fread_rgbx8vector");
785
786  nread = fread(v+nl, sizeof(float32), ncol, f);
787  if(nread != ncol) nrerror("fread_rgbx8vector can't read the whole vector");
788  fclose(f);
789}
790/* ------------------- */
791/* -- fwrite_vector -- */
792/* ------------------- */
793/* ---------------------------------------------------------------------- */
794IMAGE_EXPORT(void) fwrite_si8vector(sint8 *v,long nl,long nh,char *filename)
795/* ---------------------------------------------------------------------- */
796{
797  long  ncol = nh-nl+1;
798  FILE *f;
799
800  f = fopen(filename, "wb");
801  if(f == NULL) nrerror("Can't open file in fwrite_si8vector"); 
802  fwrite(v+nl, sizeof(sint8), ncol, f);
803  fclose(f);
804}
805/* ---------------------------------------------------------------------- */
806IMAGE_EXPORT(void) fwrite_ui8vector(uint8 *v,long nl,long nh,char *filename)
807/* ---------------------------------------------------------------------- */
808{
809  long  ncol = nh-nl+1;
810  FILE *f;
811
812  f = fopen(filename, "wb");
813  if(f == NULL) nrerror("Can't open file in fwrite_ui8vector"); 
814  fwrite(v+nl, sizeof(uint8), ncol, f);
815  fclose(f);
816}
817/* ------------------------------------------------------------------------ */
818IMAGE_EXPORT(void) fwrite_si16vector(sint16 *v,long nl,long nh,char *filename)
819/* ------------------------------------------------------------------------ */
820{
821  long  ncol = nh-nl+1;
822  FILE *f;
823
824  f = fopen(filename, "wb");
825  if(f == NULL) nrerror("Can't open file in fwrite_si16vector"); 
826  fwrite(v+nl, sizeof(sint16), ncol, f);
827  fclose(f);
828}
829/* ------------------------------------------------------------------------- */
830IMAGE_EXPORT(void) fwrite_ui16vector(uint16 *v,long nl,long nh,char *filename)
831/* ------------------------------------------------------------------------- */
832{
833  long  ncol = nh-nl+1;
834  FILE *f;
835
836  f = fopen(filename, "wb");
837  if(f == NULL) nrerror("Can't open file in fwrite_ui16vector"); 
838  fwrite(v+nl, sizeof(uint16), ncol, f);
839  fclose(f);
840}
841/* ------------------------------------------------------------------------ */
842IMAGE_EXPORT(void) fwrite_si32vector(sint32 *v,long nl,long nh,char *filename)
843/* ------------------------------------------------------------------------ */
844{
845  long  ncol = nh-nl+1;
846  FILE *f;
847
848  f = fopen(filename, "wb");
849  if(f == NULL) nrerror("Can't open file in fwrite_si32vector"); 
850  fwrite(v+nl, sizeof(sint32), ncol, f);
851  fclose(f);
852}
853/* ------------------------------------------------------------------------ */
854IMAGE_EXPORT(void) fwrite_ui32vector(uint32 *v,long nl,long nh,char *filename)
855/* ------------------------------------------------------------------------ */
856{
857  long  ncol = nh-nl+1;
858  FILE *f;
859
860  f = fopen(filename, "wb");
861  if(f == NULL) nrerror("Can't open file in fwrite_ui32vector"); 
862  fwrite(v+nl, sizeof(uint32), ncol, f);
863  fclose(f);
864}
865/* ------------------------------------------------------------------------ */
866IMAGE_EXPORT(void) fwrite_si64vector(sint64 *v,long nl,long nh,char *filename)
867/* ------------------------------------------------------------------------ */
868{
869  long  ncol = nh-nl+1;
870  FILE *f;
871
872  f = fopen(filename, "wb");
873  if(f == NULL) nrerror("Can't open file in fwrite_si64vector");
874  fwrite(v+nl, sizeof(sint64), ncol, f);
875  fclose(f);
876}
877/* ------------------------------------------------------------------------ */
878IMAGE_EXPORT(void) fwrite_ui64vector(uint64 *v,long nl,long nh,char *filename)
879/* ------------------------------------------------------------------------ */
880{
881  long  ncol = nh-nl+1;
882  FILE *f;
883
884  f = fopen(filename, "wb");
885  if(f == NULL) nrerror("Can't open file in fwrite_ui-'vector");
886  fwrite(v+nl, sizeof(uint64), ncol, f);
887  fclose(f);
888}
889/* ------------------------------------------------------------------------ */
890IMAGE_EXPORT(void) fwrite_f32vector(float32 *v,long nl,long nh,char *filename)
891/* ------------------------------------------------------------------------ */
892{
893  long  ncol = nh-nl+1;
894  FILE *f;
895
896  f = fopen(filename, "wb");
897  if(f == NULL) nrerror("Can't open file in f32write_vector"); 
898  fwrite(v+nl, sizeof(float32), ncol, f);
899  fclose(f);
900}
901/* ------------------------------------------------------------------------ */
902IMAGE_EXPORT(void) fwrite_f64vector(float64 *v,long nl,long nh,char *filename)
903/* ------------------------------------------------------------------------ */
904{
905  long  ncol = nh-nl+1;
906  FILE *f;
907
908  f = fopen(filename, "wb");
909  if(f == NULL) nrerror("Can't open file in f64write_vector"); 
910  fwrite(v+nl, sizeof(float64), ncol, f);
911  fclose(f);
912}
913/* ---------------------------------------------------------------------- */
914IMAGE_EXPORT(void) fwrite_rgb8vector(rgb8 *v,long nl,long nh,char *filename)
915/* ---------------------------------------------------------------------- */
916{
917  long  ncol = nh-nl+1;
918  FILE *f;
919
920  f = fopen(filename, "wb");
921  if(f == NULL) nrerror("Can't open file in write_rgb8vector"); 
922  fwrite(v+nl, sizeof(rgb8), ncol, f);
923  fclose(f);
924}
925/* ------------------------------------------------------------------------ */
926IMAGE_EXPORT(void) fwrite_rgbx8vector(rgbx8 *v,long nl,long nh,char *filename)
927/* ------------------------------------------------------------------------ */
928{
929  long  ncol = nh-nl+1;
930  FILE *f;
931
932  f = fopen(filename, "wb");
933  if(f == NULL) nrerror("Can't open file in write_rgbx8vector");
934  fwrite(v+nl, sizeof(rgbx8), ncol, f);
935  fclose(f);
936}
Note: See TracBrowser for help on using the repository browser.