Ignore:
Timestamp:
Jun 1, 2016, 10:25:43 AM (8 years ago)
Author:
meunier
Message:

In rosenfeld:

  • Updated nrio0, nrio1, nrio2, nrio1f, nrio2f, nrio1x, nrbool1, nrbool2 and nralloc1 in the nrc2 lib in order to use macro-typed functions
  • Updated the simulation script to include performance evaluation with random images, and a script to generate graphs
  • Updated the clock.h to use 64-bit integers, which potentially breaks the printing on the giet
File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/rosenfeld/nrc2/src/nrio1f.c

    r772 r822  
    1616#include <stdlib.h>
    1717
     18#include "nrc_os_config.h"
    1819#include "mypredef.h"
    1920#include "nrtype.h"
     
    3132 * --------------------
    3233 */
    33 /* ------------------------------------------------------------------------------------ */
    34 IMAGE_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 /* ------------------------------------------------------------------------------------ */
    46 IMAGE_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);
     34
     35#undef write_type_vector
     36#define write_type_vector(t) \
     37void short_name(t,write_,vector)(t * v, int32_t nl, int32_t nh, char * format, char * filename) \
     38{                                                                  \
     39    FILE * f = fopen(filename, "wt");                              \
     40    if (f == NULL) {                                               \
     41        nrerror("Can't open file %s in %s\n", filename, __func__); \
     42    }                                                              \
     43    for (int32_t k = nl; k <= nh; k++) {                           \
     44        fprintf(f, format, v[k]);                                  \
     45    }                                                              \
     46    fprintf(f, "\n");                                              \
     47    fclose(f);                                                     \
     48}
     49
     50write_type_vector(int8_t);
     51write_type_vector(uint8_t);
     52write_type_vector(int16_t);
     53write_type_vector(uint16_t);
     54write_type_vector(int32_t);
     55write_type_vector(uint32_t);
     56write_type_vector(int64_t);
     57write_type_vector(uint64_t);
     58write_type_vector(float);
     59write_type_vector(double);
     60
     61
     62/* ---------------------------------------------------------------------------------- */
     63void write_rgb8vector(rgb8 * v,int32_t nl, int32_t nh, char * format, char * filename)
     64/* ---------------------------------------------------------------------------------- */
     65{
     66    FILE * f = fopen(filename, "wt");
     67    if (f == NULL) {
     68        nrerror("Can't open file %s in %s\n", filename, __func__); \
     69    }
     70    for (int32_t k = nl; k <= nh; k++) {
     71        fprintf(f, format, v[k].r, v[k].g, v[k].b);
     72    }
     73    fprintf(f, "\n");
     74    fclose(f);
    5675}
    5776
    5877/* -------------------------------------------------------------------------------------- */
    59 IMAGE_EXPORT(void) write_si16vector(sint16 *v,long nl,long nh, char *format, char *filename)
     78void write_rgbx8vector(rgbx8 * v, int32_t nl, int32_t nh, char * format, char * filename)
    6079/* -------------------------------------------------------------------------------------- */
    6180{
    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 /* -------------------------------------------------------------------------------------- */
    71 IMAGE_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 /* -------------------------------------------------------------------------------------- */
    83 IMAGE_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 /* -------------------------------------------------------------------------------------- */
    95 IMAGE_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 /* -------------------------------------------------------------------------------------- */
    107 IMAGE_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 /* ------------------------------------------------------------------------------------- */
    119 IMAGE_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 /* -------------------------------------------------------------------------------------- */
    131 IMAGE_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 /* -------------------------------------------------------------------------------------- */
    143 IMAGE_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 /* ---------------------------------------------------------------------------------- */
    155 IMAGE_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 /* -------------------------------------------------------------------------------------- */
    167 IMAGE_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 }
     81    FILE * f = fopen(filename, "wt");
     82    if (f == NULL) {
     83        nrerror("Can't open file %s in %s\n", filename, __func__); \
     84    }
     85    for (int32_t k = nl; k <= nh; k++) {
     86        fprintf(f, format, v[k].r, v[k].g, v[k].b);
     87    }
     88    fprintf(f, "\n");
     89    fclose(f);
     90}
     91
     92
    17893/*
    17994 * ----------------------
     
    18196 * ----------------------
    18297 */
     98
     99#undef write_type_vector_T
     100#define write_type_vector_T(t) \
     101void short_name(t,write_,vector_T)(t * v, int32_t nl, int32_t nh, char * format, char * filename) \
     102{                                                                  \
     103    FILE * f = fopen(filename, "wt");                              \
     104    if (f == NULL) {                                               \
     105        nrerror("Can't open file %s in %s\n", filename, __func__); \
     106    }                                                              \
     107    for (int32_t k = nl; k <= nh; k++) {                           \
     108        fprintf(f, format, v[k]);                                  \
     109        fprintf(f, "\n");                                          \
     110    }                                                              \
     111    fclose(f);                                                     \
     112}
     113
     114write_type_vector_T(int8_t);
     115write_type_vector_T(uint8_t);
     116write_type_vector_T(int16_t);
     117write_type_vector_T(uint16_t);
     118write_type_vector_T(int32_t);
     119write_type_vector_T(uint32_t);
     120write_type_vector_T(int64_t);
     121write_type_vector_T(uint64_t);
     122write_type_vector_T(float);
     123write_type_vector_T(double);
     124
     125
     126/* ---------------------------------------------------------------------------------- */
     127void write_rgb8vector_T(rgb8 * v,int32_t nl, int32_t nh, char * format, char * filename)
     128/* ---------------------------------------------------------------------------------- */
     129{
     130    FILE * f = fopen(filename, "wt");
     131    if (f == NULL) {
     132        nrerror("Can't open file %s in %s\n", filename, __func__); \
     133    }
     134    for (int32_t k = nl; k <= nh; k++) {
     135        fprintf(f, format, v[k].r, v[k].g, v[k].b);
     136        fprintf(f, "\n");
     137    }
     138    fclose(f);
     139}
     140
    183141/* -------------------------------------------------------------------------------------- */
    184 IMAGE_EXPORT(void) write_si8vector_T(sint8 *v,long nl,long nh, char *format, char *filename)
     142void write_rgbx8vector_T(rgbx8 * v, int32_t nl, int32_t nh, char * format, char * filename)
    185143/* -------------------------------------------------------------------------------------- */
    186144{
    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 /* -------------------------------------------------------------------------------------- */
    196 IMAGE_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 /* ---------------------------------------------------------------------------------------- */
    208 IMAGE_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 /* -------------------------------------------------------------------------------------- */
    220 IMAGE_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 /* ---------------------------------------------------------------------------------------- */
    232 IMAGE_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 /* ---------------------------------------------------------------------------------------- */
    244 IMAGE_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 /* ---------------------------------------------------------------------------------------- */
    256 IMAGE_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 /* ---------------------------------------------------------------------------------------- */
    268 IMAGE_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 /* -------------------------------------------------------------------------------------- */
    280 IMAGE_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 /* ---------------------------------------------------------------------------------------- */
    292 IMAGE_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 }
     145    FILE * f = fopen(filename, "wt");
     146    if (f == NULL) {
     147        nrerror("Can't open file %s in %s\n", filename, __func__); \
     148    }
     149    for (int32_t k = nl; k <= nh; k++) {
     150        fprintf(f, format, v[k].r, v[k].g, v[k].b);
     151        fprintf(f, "\n");
     152    }
     153    fclose(f);
     154}
     155
    303156
    304157/*
     
    307160 * ---------------------------
    308161 */
     162
     163// @QM : fprintf(f, format, k, k, k); ?
     164#undef write_type_vector_number
     165#define write_type_vector_number(t) \
     166void short_name(t,write_,vector_number)(t * v, int32_t nl, int32_t nh, char * format, char * filename) \
     167{                                                                  \
     168    FILE * f = fopen(filename, "wt");                              \
     169    if (f == NULL) {                                               \
     170        nrerror("Can't open file %s in %s\n", filename, __func__); \
     171    }                                                              \
     172    for (int32_t k = nl; k <= nh; k++) {                           \
     173        fprintf(f, format, k);                                     \
     174    }                                                              \
     175    fprintf(f, "\n");                                              \
     176    for (int32_t k = nl; k <= nh; k++) {                           \
     177        fprintf(f, format, v[k]);                                  \
     178    }                                                              \
     179    fprintf(f, "\n");                                              \
     180    fclose(f);                                                     \
     181}
     182
     183write_type_vector_number(int8_t);
     184write_type_vector_number(uint8_t);
     185write_type_vector_number(int16_t);
     186write_type_vector_number(uint16_t);
     187write_type_vector_number(int32_t);
     188write_type_vector_number(uint32_t);
     189write_type_vector_number(int64_t);
     190write_type_vector_number(uint64_t);
     191write_type_vector_number(float);
     192write_type_vector_number(double);
     193
     194
     195/* ------------------------------------------------------------------------------------------- */
     196void write_rgb8vector_number(rgb8 * v, int32_t nl, int32_t nh, char * format, char * filename)
     197/* ------------------------------------------------------------------------------------------- */
     198{
     199    FILE * f = fopen(filename, "wt");
     200    if (f == NULL) {
     201        nrerror("Can't open file %s in %s\n", filename, __func__);
     202    }
     203    for (int32_t k = nl; k <= nh; k++) {
     204        fprintf(f, "%3d", k);
     205    }
     206    fprintf(f, "\n");
     207    for (int32_t k = nl; k <= nh; k++) {
     208        fprintf(f, format, v[k].r, v[k].g, v[k].b);
     209    }
     210    fprintf(f, "\n");
     211    fclose(f);
     212}
     213
     214
    309215/* --------------------------------------------------------------------------------------------- */
    310 IMAGE_EXPORT(void) write_si8vector_number(sint8 *v,long nl,long nh, char *format, char *filename)
     216void write_rgbx8vector_number(rgbx8 * v, int32_t nl, int32_t nh, char * format, char * filename)
    311217/* --------------------------------------------------------------------------------------------- */
    312218{
    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 /* ------------------------------------------------------------------------------------------- */
    323 IMAGE_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 /* --------------------------------------------------------------------------------------------- */
    336 IMAGE_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 /* ------------------------------------------------------------------------------------------- */
    349 IMAGE_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 /* --------------------------------------------------------------------------------------------- */
    362 IMAGE_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 /* ------------------------------------------------------------------------------------------- */
    375 IMAGE_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 /* --------------------------------------------------------------------------------------------- */
    388 IMAGE_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 /* ------------------------------------------------------------------------------------------- */
    401 IMAGE_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 /* --------------------------------------------------------------------------------------------- */
    414 IMAGE_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 /* --------------------------------------------------------------------------------------------- */
    427 IMAGE_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 /* ------------------------------------------------------------------------------------------- */
    440 IMAGE_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 /* --------------------------------------------------------------------------------------------- */
    453 IMAGE_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 }
     219    FILE * f = fopen(filename, "wt");
     220    if (f == NULL) {
     221        nrerror("Can't open file %s in %s\n", filename, __func__);
     222    }
     223    for (int32_t k = nl; k <= nh; k++) {
     224        fprintf(f, "%3d", k);
     225    }
     226    fprintf(f, "\n");
     227    for (int32_t k = nl; k <= nh; k++) {
     228        fprintf(f, format, v[k].r, v[k].g, v[k].b);
     229    }
     230    fprintf(f, "\n");
     231    fclose(f);
     232}
     233
     234
    465235/*
    466236 * -----------------------------
     
    469239 */
    470240
     241#undef write_type_vector_T_number
     242#define write_type_vector_T_number(t) \
     243void short_name(t,write_,vector_T_number)(t * v, int32_t nl, int32_t nh, char * format, char * filename) \
     244{                                                                  \
     245    FILE * f = fopen(filename, "wt");                              \
     246    if (f == NULL) {                                               \
     247        nrerror("Can't open file %s in %s\n", filename, __func__); \
     248    }                                                              \
     249    for (int32_t k = nl; k <= nh; k++) {                           \
     250        fprintf(f, "%3d", k);                                      \
     251        fprintf(f, format, v[k]);                                  \
     252        fprintf(f, "\n");                                          \
     253    }                                                              \
     254    fclose(f);                                                     \
     255}
     256
     257write_type_vector_T_number(int8_t);
     258write_type_vector_T_number(uint8_t);
     259write_type_vector_T_number(int16_t);
     260write_type_vector_T_number(uint16_t);
     261write_type_vector_T_number(int32_t);
     262write_type_vector_T_number(uint32_t);
     263write_type_vector_T_number(int64_t);
     264write_type_vector_T_number(uint64_t);
     265write_type_vector_T_number(float);
     266write_type_vector_T_number(double);
     267
     268
     269/* ------------------------------------------------------------------------------------------- */
     270void write_rgb8vector_T_number(rgb8 * v, int32_t nl, int32_t nh, char * format, char * filename)
     271/* ------------------------------------------------------------------------------------------- */
     272{
     273    FILE * f = fopen(filename, "wt");
     274    if (f == NULL) {
     275        nrerror("Can't open file %s in %s\n", filename, __func__);
     276    }
     277    for (int32_t k = nl; k <= nh; k++) {
     278        fprintf(f, "%3d", k);
     279        fprintf(f, format, v[k].r, v[k].g, v[k].b);
     280        fprintf(f, "\n");
     281    }
     282    fclose(f);
     283}
     284
     285
    471286/* --------------------------------------------------------------------------------------------- */
    472 IMAGE_EXPORT(void) write_si8vector_T_number(sint8 *v,long nl,long nh, char *format, char *filename)
     287void write_rgbx8vector_T_number(rgbx8 * v, int32_t nl, int32_t nh, char * format, char * filename)
    473288/* --------------------------------------------------------------------------------------------- */
    474289{
    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 /* --------------------------------------------------------------------------------------------- */
    484 IMAGE_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 /* ----------------------------------------------------------------------------------------------- */
    496 IMAGE_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 /* ----------------------------------------------------------------------------------------------- */
    508 IMAGE_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 /* ----------------------------------------------------------------------------------------------- */
    520 IMAGE_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 /* ------------------------------------------------------------------------------------------- */
    532 IMAGE_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 /* ----------------------------------------------------------------------------------------------- */
    544 IMAGE_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 /* ----------------------------------------------------------------------------------------------- */
    556 IMAGE_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 /* ----------------------------------------------------------------------------------------------- */
    568 IMAGE_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 /* ----------------------------------------------------------------------------------------------- */
    580 IMAGE_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 /* ------------------------------------------------------------------------------------------- */
    592 IMAGE_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 /* ----------------------------------------------------------------------------------------------- */
    604 IMAGE_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 }
     290    FILE * f = fopen(filename, "wt");
     291    if (f == NULL) {
     292        nrerror("Can't open file %s in %s\n", filename, __func__);
     293    }
     294    for (int32_t k = nl; k <= nh; k++) {
     295        fprintf(f, "%3d", k);
     296        fprintf(f, format, v[k].r, v[k].g, v[k].b);
     297        fprintf(f, "\n");
     298    }
     299    fclose(f);
     300}
     301
     302
    615303
    616304/*
     
    620308 */
    621309
    622 /* ---------------------------------------------------------------------- */
    623 IMAGE_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 /* ---------------------------------------------------------------------- */
    637 IMAGE_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 /* ------------------------------------------------------------------------ */
    651 IMAGE_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 /* ------------------------------------------------------------------------ */
    665 IMAGE_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 /* ------------------------------------------------------------------------ */
    679 IMAGE_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 /* ------------------------------------------------------------------------ */
    693 IMAGE_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 /* ------------------------------------------------------------------------ */
    707 IMAGE_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 /* ------------------------------------------------------------------------ */
    721 IMAGE_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 /* ------------------------------------------------------------------------ */
    735 IMAGE_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 /* ------------------------------------------------------------------------ */
    749 IMAGE_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 /* ---------------------------------------------------------------------- */
    763 IMAGE_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 /* ------------------------------------------------------------------------ */
    777 IMAGE_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 }
     310#undef fread_type_vector
     311#define fread_type_vector(t) \
     312void short_name(t,fread_,vector)(char * filename, t * v, int32_t nl, int32_t nh) \
     313{                                                                  \
     314    int32_t ncol = nh - nl + 1;                                    \
     315    int32_t nread;                                                 \
     316    FILE * f = fopen(filename, "rb");                              \
     317    if (f == NULL) {                                               \
     318        nrerror("Can't open file %s in %s\n", filename, __func__); \
     319    }                                                              \
     320                                                                   \
     321    nread = fread(v + nl, sizeof(t), ncol, f);                     \
     322    if (nread != ncol) {                                           \
     323        nrerror("%s can't read the whole vector", __func__);       \
     324    }                                                              \
     325    fclose(f);                                                     \
     326}
     327
     328fread_type_vector(int8_t);
     329fread_type_vector(uint8_t);
     330fread_type_vector(int16_t);
     331fread_type_vector(uint16_t);
     332fread_type_vector(int32_t);
     333fread_type_vector(uint32_t);
     334fread_type_vector(int64_t);
     335fread_type_vector(uint64_t);
     336fread_type_vector(float);
     337fread_type_vector(double);
     338fread_type_vector(rgb8);
     339fread_type_vector(rgbx8);
     340
     341
    790342/* ------------------- */
    791343/* -- fwrite_vector -- */
    792344/* ------------------- */
    793 /* ---------------------------------------------------------------------- */
    794 IMAGE_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 /* ---------------------------------------------------------------------- */
    806 IMAGE_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 /* ------------------------------------------------------------------------ */
    818 IMAGE_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 /* ------------------------------------------------------------------------- */
    830 IMAGE_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 /* ------------------------------------------------------------------------ */
    842 IMAGE_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 /* ------------------------------------------------------------------------ */
    854 IMAGE_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 /* ------------------------------------------------------------------------ */
    866 IMAGE_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 /* ------------------------------------------------------------------------ */
    878 IMAGE_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 /* ------------------------------------------------------------------------ */
    890 IMAGE_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 /* ------------------------------------------------------------------------ */
    902 IMAGE_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 /* ---------------------------------------------------------------------- */
    914 IMAGE_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 /* ------------------------------------------------------------------------ */
    926 IMAGE_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 }
     345
     346#undef fwrite_type_vector
     347#define fwrite_type_vector(t) \
     348void short_name(t,fwrite_,vector)(t * v, int32_t nl, int32_t nh, char * filename) \
     349{                                                                  \
     350    int32_t ncol = nh - nl + 1;                                    \
     351    FILE * f = fopen(filename, "rb");                              \
     352    if (f == NULL) {                                               \
     353        nrerror("Can't open file %s in %s\n", filename, __func__); \
     354    }                                                              \
     355    fwrite(v + nl, sizeof(t), ncol, f);                            \
     356    fclose(f);                                                     \
     357}
     358
     359fwrite_type_vector(int8_t);
     360fwrite_type_vector(uint8_t);
     361fwrite_type_vector(int16_t);
     362fwrite_type_vector(uint16_t);
     363fwrite_type_vector(int32_t);
     364fwrite_type_vector(uint32_t);
     365fwrite_type_vector(int64_t);
     366fwrite_type_vector(uint64_t);
     367fwrite_type_vector(float);
     368fwrite_type_vector(double);
     369fwrite_type_vector(rgb8);
     370fwrite_type_vector(rgbx8);
     371
     372
     373
     374// Local Variables:
     375// tab-width: 4
     376// c-basic-offset: 4
     377// c-file-offsets:((innamespace . 0)(inline-open . 0))
     378// indent-tabs-mode: nil
     379// End:
     380
     381// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     382
Note: See TracChangeset for help on using the changeset viewer.