Ignore:
Timestamp:
Jun 14, 2016, 5:23:56 PM (8 years ago)
Author:
meunier
Message:
  • Improved scripts for simulations and graphes
  • Continued to clean up the lib nrc2 (from nrio2x.x to nrmem1.c)
  • Added a version (Fast - Parmerge - No stats)
File:
1 edited

Legend:

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

    r772 r823  
    2525#include "nrio2x.h"
    2626
    27 /* ------------------------------ */
    28 /* --- display_matrix_endline --- */
    29 /* ------------------------------ */
    3027/* ----------------------- */
    3128/* --- write_trimatrix --- */
    3229/* ----------------------- */
    3330
    34 /* ----------------------------------------------------------------------------------------------------------------- */
    35 IMAGE_EXPORT(void) write_btrimatrix(byte **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
    36 /* ----------------------------------------------------------------------------------------------------------------- */
    37 {
    38   int i,j;
    39  
    40   FILE *f;
    41 
    42   f = fopen(filename, "wt");
    43   if(f == NULL) {
    44     nrerror("Can't open file in write_btrimatrix");
    45   }
    46 
    47   for(i=i0; i<=i1; i++) {
    48     for(j=j0; j<=j1; j++) {
    49       fprintf(f, format, m[i][j]);
    50     }
    51     fputc('\n', f);
    52     j1 += step;
    53   }
    54   fputc('\n', f);
    55 
    56   fclose(f);
    57 }
    58 
    59 /* -------------------------------------------------------------------------------------------------------------------- */
    60 IMAGE_EXPORT(void) write_i16trimatrix(int16 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
    61 /* -------------------------------------------------------------------------------------------------------------------- */
    62 {
    63   int i,j;
    64  
    65   FILE *f;
    66 
    67   f = fopen(filename, "wt");
    68   if(f == NULL) {
    69     nrerror("Can't open file in write_i16trimatrix");
    70   }
    71 
    72   for(i=i0; i<=i1; i++) {
    73     for(j=j0; j<=j1; j++) {
    74       fprintf(f, format, m[i][j]);
    75     }
    76     fputc('\n', f);
    77     j1 += step;
    78   }
    79   fputc('\n', f);
    80 
    81   fclose(f);
    82 }
    83 /* ---------------------------------------------------------------------------------------------------------------------- */
    84 IMAGE_EXPORT(void) write_ui16trimatrix(uint16 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
    85 /* ---------------------------------------------------------------------------------------------------------------------- */
    86 {
    87   int i,j;
    88  
    89   FILE *f;
    90 
    91   f = fopen(filename, "wt");
    92   if(f == NULL) {
    93     nrerror("Can't open file in write_ui16trimatrix");
    94   }
    95 
    96   for(i=i0; i<=i1; i++) {
    97     for(j=j0; j<=j1; j++) {
    98       fprintf(f, format, m[i][j]);
    99     }
    100     fputc('\n', f);
    101     j1 += step;
    102   }
    103   fputc('\n', f);
    104 
    105   fclose(f);
    106 }
    107 /* ---------------------------------------------------------------------------------------------------------------- */
    108 IMAGE_EXPORT(void) write_itrimatrix(int **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
    109 /* ---------------------------------------------------------------------------------------------------------------- */
    110 {
    111   int i,j;
    112  
    113   FILE *f;
    114 
    115   f = fopen(filename, "wt");
    116   if(f == NULL) {
    117     nrerror("Can't open file in write_itrimatrix");
    118   }
    119 
    120   for(i=i0; i<=i1; i++) {
    121     for(j=j0; j<=j1; j++) {
    122       fprintf(f, format, m[i][j]);
    123     }
    124     fputc('\n', f);
    125     j1 += step;
    126   }
    127   fputc('\n', f);
    128 
    129   fclose(f);
    130 }
    131 /* ------------------------------------------------------------------------------------------------------------------------ */
    132 IMAGE_EXPORT(void) write_i32trimatrix(int32 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
    133 /* ------------------------------------------------------------------------------------------------------------------------ */
    134 {
    135   int i,j;
    136  
    137   FILE *f;
    138 
    139   f = fopen(filename, "wt");
    140   if(f == NULL) {
    141     nrerror("Can't open file in write_i32trimatrix");
    142   }
    143 
    144   for(i=i0; i<=i1; i++) {
    145     for(j=j0; j<=j1; j++) {
    146       fprintf(f, format, m[i][j]);
    147     }
    148     fputc('\n', f);
    149     j1 += step;
    150   }
    151   fputc('\n', f);
    152 
    153   fclose(f);
    154 }
    155 /* ---------------------------------------------------------------------------------------------------------------------- */
    156 IMAGE_EXPORT(void) write_f32trimatrix(float32 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
    157 /* ---------------------------------------------------------------------------------------------------------------------- */
    158 {
    159   int i,j;
    160  
    161   FILE *f;
    162 
    163   f = fopen(filename, "wt");
    164   if(f == NULL) {
    165     nrerror("Can't open file in write_f32trimatrix");
    166   }
    167 
    168   for(i=i0; i<=i1; i++) {
    169     for(j=j0; j<=j1; j++) {
    170       fprintf(f, format, m[i][j]);
    171     }
    172     fputc('\n', f);
    173     j1 += step;
    174   }
    175   fputc('\n', f);
    176 
    177   fclose(f);
    178 }
    179 /* ---------------------------------------------------------------------------------------------------------------------- */
    180 IMAGE_EXPORT(void) write_f64trimatrix(float64 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
    181 /* ---------------------------------------------------------------------------------------------------------------------- */
    182 {
    183   int i,j;
    184  
    185   FILE *f;
    186 
    187   f = fopen(filename, "wt");
    188   if(f == NULL) {
    189     nrerror("Can't open file in write_f64trimatrix");
    190   }
    191 
    192   for(i=i0; i<=i1; i++) {
    193     for(j=j0; j<=j1; j++) {
    194       fprintf(f, format, m[i][j]);
    195     }
    196     fputc('\n', f);
    197     j1 += step;
    198   }
    199   fputc('\n', f);
    200 
    201   fclose(f);
    202 }
     31#undef write_type_trimatrix
     32#define write_type_trimatrix(t) \
     33void short_name(t,write_,trimatrix)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t step, char * format, char * filename) \
     34{                                                                \
     35    FILE * f = fopen(filename, "wt");                            \
     36    if (f == NULL) {                                             \
     37        nrerror("Can't open file %s in %s", filename, __func__); \
     38    }                                                            \
     39    for (int32_t i = i0; i <= i1; i++) {                         \
     40        for (int32_t j = j0; j <= j1; j++) {                     \
     41            fprintf(f, format, m[i][j]);                         \
     42        }                                                        \
     43        fprintf(f, "\n");                                        \
     44        j1 += step;                                              \
     45    }                                                            \
     46    fprintf(f, "\n");                                            \
     47    fclose(f);                                                   \
     48}
     49
     50write_type_trimatrix(int8_t);
     51write_type_trimatrix(uint8_t);
     52write_type_trimatrix(int16_t);
     53write_type_trimatrix(uint16_t);
     54write_type_trimatrix(int32_t);
     55write_type_trimatrix(uint32_t);
     56write_type_trimatrix(int64_t);
     57write_type_trimatrix(uint64_t);
     58write_type_trimatrix(float);
     59write_type_trimatrix(double);
     60
     61
    20362/* ---------------------------- */
    20463/* --- write_matrix_endline --- */
    20564/* ---------------------------- */
    206 /* ------------------------------------------------------------------------------------------------------------ */
    207 IMAGE_EXPORT(void) write_bmatrix_endline(byte **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    208 /* ------------------------------------------------------------------------------------------------------------ */
    209 {
    210   int i,j;
    211   //int n = (i1-i0+1) * (j1-j0+1);
    212   byte *p = &m[i0][j0];
    213 
    214   FILE *f;
    215 
    216   f = fopen(filename, "wt");
    217   if(f == NULL) {
    218     nrerror("Can't open file in write_bmatrix_endline");
    219   }
    220 
    221   for(i=i0; i<=i1; i++) {
    222     for(j=j0; j<=j1; j++) {
    223       fprintf(f, format, *p++);
    224     }
    225     fputc('\n', f);
    226   }
    227   fclose(f);
    228 }
    229 /* ---------------------------------------------------------------------------------------------------------------- */
    230 IMAGE_EXPORT(void) write_i16matrix_endline(int16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    231 /* ---------------------------------------------------------------------------------------------------------------- */
    232 {
    233   int i,j;
    234   //int n = (i1-i0+1) * (j1-j0+1);
    235   int16 *p = &m[i0][j0];
    236 
    237   FILE *f;
    238 
    239   f = fopen(filename, "wt");
    240   if(f == NULL) {
    241     nrerror("Can't open file in write_i16matrix_endline");
    242   }
    243 
    244   for(i=i0; i<=i1; i++) {
    245     for(j=j0; j<=j1; j++) {
    246       fprintf(f, format, *p++);
    247     }
    248     fputc('\n', f);
    249   }
    250   fclose(f);
    251 }
    252 /* ------------------------------------------------------------------------------------------------------------------ */
    253 IMAGE_EXPORT(void) write_ui16matrix_endline(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    254 /* ------------------------------------------------------------------------------------------------------------------ */
    255 {
    256   int i,j;
    257   //int n = (i1-i0+1) * (j1-j0+1);
    258   uint16 *p = &m[i0][j0];
    259 
    260   FILE *f;
    261 
    262   f = fopen(filename, "wt");
    263   if(f == NULL) {
    264     nrerror("Can't open file in write_ui16matrix_endline");
    265   }
    266 
    267   for(i=i0; i<=i1; i++) {
    268     for(j=j0; j<=j1; j++) {
    269       fprintf(f, format, *p++);
    270     }
    271     fputc('\n', f);
    272   }
    273   fclose(f);
    274 }
    275 /* ---------------------------------------------------------------------------------------------------------------- */
    276 IMAGE_EXPORT(void) write_i32matrix_endline(int32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    277 /* ---------------------------------------------------------------------------------------------------------------- */
    278 {
    279   int i,j;
    280   //int n = (i1-i0+1) * (j1-j0+1);
    281   int32 *p = &m[i0][j0];
    282 
    283   FILE *f;
    284 
    285   f = fopen(filename, "wt");
    286   if(f == NULL) {
    287     nrerror("Can't open file in write_i32matrix_endline");
    288   }
    289 
    290   for(i=i0; i<=i1; i++) {
    291     for(j=j0; j<=j1; j++) {
    292       fprintf(f, format, *p++);
    293     }
    294     fputc('\n', f);
    295   }
    296   fclose(f);
    297 }
    298 /* ------------------------------------------------------------------------------------------------------------------ */
    299 IMAGE_EXPORT(void) write_ui32matrix_endline(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    300 /* ------------------------------------------------------------------------------------------------------------------ */
    301 {
    302   int i,j;
    303   //int n = (i1-i0+1) * (j1-j0+1);
    304   uint32 *p = &m[i0][j0];
    305 
    306   FILE *f;
    307 
    308   f = fopen(filename, "wt");
    309   if(f == NULL) {
    310     nrerror("Can't open file in write_ui32matrix_endline");
    311   }
    312 
    313   for(i=i0; i<=i1; i++) {
    314     for(j=j0; j<=j1; j++) {
    315       fprintf(f, format, *p++);
    316     }
    317     fputc('\n', f);
    318   }
    319   fclose(f);
    320 }
    321 /* ---------------------------------------------------------------------------------------------------------------- */
    322 IMAGE_EXPORT(void) write_i64matrix_endline(int64 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    323 /* ---------------------------------------------------------------------------------------------------------------- */
    324 {
    325   int i,j;
    326   //int n = (i1-i0+1) * (j1-j0+1);
    327   int64 *p = &m[i0][j0];
    328 
    329   FILE *f;
    330 
    331   f = fopen(filename, "wt");
    332   if(f == NULL) {
    333     nrerror("Can't open file in write_i64matrix_endline");
    334   }
    335 
    336   for(i=i0; i<=i1; i++) {
    337     for(j=j0; j<=j1; j++) {
    338       fprintf(f, format, *p++);
    339     }
    340     fputc('\n', f);
    341   }
    342   fclose(f);
    343 }
    344 /* ------------------------------------------------------------------------------------------------------------ */
    345 IMAGE_EXPORT(void) write_imatrix_endline(int **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    346 /* ------------------------------------------------------------------------------------------------------------ */
    347 {
    348   int i,j;
    349   //int n = (i1-i0+1) * (j1-j0+1);
    350   int *p = &m[i0][j0];
    351 
    352   FILE *f;
    353 
    354   f = fopen(filename, "wt");
    355   if(f == NULL) {
    356     nrerror("Can't open file in write_imatrix_endline");
    357   }
    358 
    359   for(i=i0; i<=i1; i++) {
    360     for(j=j0; j<=j1; j++) {
    361       fprintf(f, format, *p++);
    362     }
    363     fputc('\n', f);
    364   }
    365   fclose(f);
    366 }
     65
     66#undef write_type_matrix_endline
     67#define write_type_matrix_endline(t) \
     68void short_name(t,write_,matrix_endline)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * filename) \
     69{                                                                \
     70    t * p = &m[i0][j0];                                          \
     71    FILE * f = fopen(filename, "wt");                            \
     72    if (f == NULL) {                                             \
     73        nrerror("Can't open file %s in %s", filename, __func__); \
     74    }                                                            \
     75    for (int32_t i = i0; i <= i1; i++) {                         \
     76        for (int32_t j = j0; j <= j1; j++) {                     \
     77            fprintf(f, format, *p++);                            \
     78        }                                                        \
     79        fprintf(f, "\n");                                        \
     80    }                                                            \
     81    fprintf(f, "\n");                                            \
     82    fclose(f);                                                   \
     83}
     84
     85write_type_matrix_endline(int8_t);
     86write_type_matrix_endline(uint8_t);
     87write_type_matrix_endline(int16_t);
     88write_type_matrix_endline(uint16_t);
     89write_type_matrix_endline(int32_t);
     90write_type_matrix_endline(uint32_t);
     91write_type_matrix_endline(int64_t);
     92write_type_matrix_endline(uint64_t);
     93write_type_matrix_endline(float);
     94write_type_matrix_endline(double);
     95
     96
    36797/* ------------------------------ */
    36898/* --- write_imatrix_endline0 --- */
    36999/* ------------------------------ */
    370 /* -------------------------------------------------------------------------------------------------------------- */
    371 IMAGE_EXPORT(void) write_bmatrix_endline0(byte **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    372 /* -------------------------------------------------------------------------------------------------------------- */
    373 {
    374   int i,j, n;
    375  
    376   FILE *f;
    377 
    378   f = fopen(filename, "wt");
    379   if(f == NULL) {
    380     nrerror("Can't open file in write_bmatrix_endline0");
    381   }
    382 
    383   for(i=i0; i<=i1; i++) {
    384     n = m[i][j0];
    385     for(j=j0; j<=j0+n; j++) {
    386       fprintf(f, format, m[i][j]);
    387     }
    388     fputc('\n', f);
    389   }
    390   fclose(f);
    391 }
    392 /* ----------------------------------------------------------------------------------------------------------------- */
    393 IMAGE_EXPORT(void) write_i16matrix_endline0(int16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    394 /* ----------------------------------------------------------------------------------------------------------------- */
    395 {
    396   int i,j, n;
    397  
    398   FILE *f;
    399 
    400   f = fopen(filename, "wt");
    401   if(f == NULL) {
    402     nrerror("Can't open file in write_i16matrix_endline0");
    403   }
    404 
    405   for(i=i0; i<=i1; i++) {
    406     n = m[i][j0];
    407     for(j=j0; j<=j0+n; j++) {
    408       fprintf(f, format, m[i][j]);
    409     }
    410     fputc('\n', f);
    411   }
    412   fclose(f);
    413 }
    414 /* ------------------------------------------------------------------------------------------------------------------- */
    415 IMAGE_EXPORT(void) write_ui16matrix_endline0(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    416 /* ------------------------------------------------------------------------------------------------------------------- */
    417 {
    418   int i,j, n;
    419  
    420   FILE *f;
    421 
    422   f = fopen(filename, "wt");
    423   if(f == NULL) {
    424     nrerror("Can't open file in write_ui16matrix_endline0");
    425   }
    426 
    427   for(i=i0; i<=i1; i++) {
    428     n = m[i][j0];
    429     for(j=j0; j<=j0+n; j++) {
    430       fprintf(f, format, m[i][j]);
    431     }
    432     fputc('\n', f);
    433   }
    434   fclose(f);
    435 }
    436 /* ----------------------------------------------------------------------------------------------------------------- */
    437 IMAGE_EXPORT(void) write_i32matrix_endline0(int32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    438 /* ----------------------------------------------------------------------------------------------------------------- */
    439 {
    440   int i,j, n;
    441  
    442   FILE *f;
    443 
    444   f = fopen(filename, "wt");
    445   if(f == NULL) {
    446     nrerror("Can't open file in write_i32matrix_endline0");
    447   }
    448 
    449   for(i=i0; i<=i1; i++) {
    450     n = m[i][j0];
    451     for(j=j0; j<=j0+n; j++) {
    452       fprintf(f, format, m[i][j]);
    453     }
    454     fputc('\n', f);
    455   }
    456   fclose(f);
    457 }
    458 /* ----------------------------------------------------------------------------------------------------------------- */
    459 IMAGE_EXPORT(void) write_i64matrix_endline0(int64 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    460 /* ----------------------------------------------------------------------------------------------------------------- */
    461 {
    462   int i,j;
    463   int64 n;
    464  
    465   FILE *f;
    466 
    467   f = fopen(filename, "wt");
    468   if(f == NULL) {
    469     nrerror("Can't open file in write_i64matrix_endline0");
    470   }
    471 
    472   for(i=i0; i<=i1; i++) {
    473     n = m[i][j0];
    474     for(j=j0; j<=j0+n; j++) {
    475       fprintf(f, format, m[i][j]);
    476     }
    477     fputc('\n', f);
    478   }
    479   fclose(f);
    480 }
    481 /* ------------------------------------------------------------------------------------------------------------------- */
    482 IMAGE_EXPORT(void) write_ui32matrix_endline0(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    483 /* ------------------------------------------------------------------------------------------------------------------- */
    484 {
    485   int i,j, n;
    486  
    487   FILE *f;
    488 
    489   f = fopen(filename, "wt");
    490   if(f == NULL) {
    491     nrerror("Can't open file in write_ui32matrix_endline0");
    492   }
    493 
    494   for(i=i0; i<=i1; i++) {
    495     n = m[i][j0];
    496     for(j=j0; j<=j0+n; j++) {
    497       fprintf(f, format, m[i][j]);
    498     }
    499     fputc('\n', f);
    500   }
    501   fclose(f);
    502 }
    503 /* ------------------------------------------------------------------------------------------------------------- */
    504 IMAGE_EXPORT(void) write_imatrix_endline0(int **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    505 /* ------------------------------------------------------------------------------------------------------------- */
    506 {
    507   int i,j, n;
    508  
    509   FILE *f;
    510 
    511   f = fopen(filename, "wt");
    512   if(f == NULL) {
    513     nrerror("Can't open file in write_imatrix_endline0");
    514   }
    515 
    516   for(i=i0; i<=i1; i++) {
    517     n = m[i][j0];
    518     for(j=j0; j<=j0+n; j++) {
    519       fprintf(f, format, m[i][j]);
    520     }
    521     fputc('\n', f);
    522   }
    523   fclose(f);
    524 }
     100
     101#undef write_type_matrix_endline0
     102#define write_type_matrix_endline0(t) \
     103void short_name(t,write_,matrix_endline0)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * filename) \
     104{                                                                \
     105    FILE * f = fopen(filename, "wt");                            \
     106    if (f == NULL) {                                             \
     107        nrerror("Can't open file %s in %s", filename, __func__); \
     108    }                                                            \
     109    for (int32_t i = i0; i <= i1; i++) {                         \
     110        int32_t n = (int32_t) m[i][j0];                          \
     111        for (int32_t j = j0; j <= j0 + n; j++) {                 \
     112            fprintf(f, format, m[i][j]);                         \
     113        }                                                        \
     114        fprintf(f, "\n");                                        \
     115    }                                                            \
     116    fprintf(f, "\n");                                            \
     117    fclose(f);                                                   \
     118}
     119
     120write_type_matrix_endline0(int8_t);
     121write_type_matrix_endline0(uint8_t);
     122write_type_matrix_endline0(int16_t);
     123write_type_matrix_endline0(uint16_t);
     124write_type_matrix_endline0(int32_t);
     125write_type_matrix_endline0(uint32_t);
     126write_type_matrix_endline0(int64_t);
     127write_type_matrix_endline0(uint64_t);
     128write_type_matrix_endline0(float);
     129write_type_matrix_endline0(double);
     130
     131
     132
    525133/* ------------------------------ */
    526134/* --- write_imatrix_endline1 --- */
    527135/* ------------------------------ */
    528 /* -------------------------------------------------------------------------------------------------------------- */
    529 IMAGE_EXPORT(void) write_bmatrix_endline1(byte **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    530 /* -------------------------------------------------------------------------------------------------------------- */
    531 {
    532   int i,j, n;
    533  
    534   FILE *f;
    535 
    536   f = fopen(filename, "wt");
    537   if(f == NULL) {
    538     nrerror("Can't open file in write_bmatrix_endline1");
    539   }
    540 
    541   for(i=i0; i<=i1; i++) {
    542     n = m[i][j0-1];
    543     for(j=j0; j<=j0+n-1; j++) {
    544       fprintf(f, format, m[i][j]);
    545     }
    546     fputc('\n', f);
    547   }
    548   fclose(f);
    549 }
    550 /* ----------------------------------------------------------------------------------------------------------------- */
    551 IMAGE_EXPORT(void) write_i16matrix_endline1(int16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    552 /* ----------------------------------------------------------------------------------------------------------------- */
    553 {
    554   int i,j, n;
    555  
    556   FILE *f;
    557 
    558   f = fopen(filename, "wt");
    559   if(f == NULL) {
    560     nrerror("Can't open file in write_i16matrix_endline0");
    561   }
    562 
    563   for(i=i0; i<=i1; i++) {
    564     n = m[i][j0-1];
    565     for(j=j0; j<=j0+n-1; j++) {
    566       fprintf(f, format, m[i][j]);
    567     }
    568     fputc('\n', f);
    569   }
    570   fclose(f);
    571 }
    572 /* ------------------------------------------------------------------------------------------------------------------- */
    573 IMAGE_EXPORT(void) write_ui16matrix_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    574 /* ------------------------------------------------------------------------------------------------------------------- */
    575 {
    576   int i,j, n;
    577  
    578   FILE *f;
    579 
    580   f = fopen(filename, "wt");
    581   if(f == NULL) {
    582     nrerror("Can't open file in write_ui16matrix_endline0");
    583   }
    584 
    585   for(i=i0; i<=i1; i++) {
    586     n = m[i][j0-1];
    587     for(j=j0; j<=j0+n-1; j++) {
    588       fprintf(f, format, m[i][j]);
    589     }
    590     fputc('\n', f);
    591   }
    592   fclose(f);
    593 }
    594 /* ----------------------------------------------------------------------------------------------------------------- */
    595 IMAGE_EXPORT(void) write_i32matrix_endline1(int32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    596 /* ----------------------------------------------------------------------------------------------------------------- */
    597 {
    598   int i,j, n;
    599  
    600   FILE *f;
    601 
    602   f = fopen(filename, "wt");
    603   if(f == NULL) {
    604     nrerror("Can't open file in write_i32matrix_endline0");
    605   }
    606 
    607   for(i=i0; i<=i1; i++) {
    608     n = m[i][j0-1];
    609     for(j=j0; j<=j0+n-1; j++) {
    610       fprintf(f, format, m[i][j]);
    611     }
    612     fputc('\n', f);
    613   }
    614   fclose(f);
    615 }
    616 /* ------------------------------------------------------------------------------------------------------------------- */
    617 IMAGE_EXPORT(void) write_ui32matrix_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    618 /* ------------------------------------------------------------------------------------------------------------------- */
    619 {
    620   int i,j, n;
    621  
    622   FILE *f;
    623 
    624   f = fopen(filename, "wt");
    625   if(f == NULL) {
    626     nrerror("Can't open file in write_ui32matrix_endline0");
    627   }
    628 
    629   for(i=i0; i<=i1; i++) {
    630     n = m[i][j0-1];
    631     for(j=j0; j<=j0+n-1; j++) {
    632       fprintf(f, format, m[i][j]);
    633     }
    634     fputc('\n', f);
    635   }
    636   fclose(f);
    637 }
    638 /* ----------------------------------------------------------------------------------------------------------------- */
    639 IMAGE_EXPORT(void) write_i64matrix_endline1(int64 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    640 /* ----------------------------------------------------------------------------------------------------------------- */
    641 {
    642   int i,j;
    643   int64 n;
    644  
    645   FILE *f;
    646 
    647   f = fopen(filename, "wt");
    648   if(f == NULL) {
    649     nrerror("Can't open file in write_i64matrix_endline0");
    650   }
    651 
    652   for(i=i0; i<=i1; i++) {
    653     n = m[i][j0-1];
    654     for(j=j0; j<=j0+n-1; j++) {
    655       fprintf(f, format, m[i][j]);
    656     }
    657     fputc('\n', f);
    658   }
    659   fclose(f);
    660 }
    661 /* ------------------------------------------------------------------------------------------------------------- */
    662 IMAGE_EXPORT(void) write_imatrix_endline1(int **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    663 /* ------------------------------------------------------------------------------------------------------------- */
    664 {
    665   int i,j, n;
    666  
    667   FILE *f;
    668 
    669   f = fopen(filename, "wt");
    670   if(f == NULL) {
    671     nrerror("Can't open file in write_imatrix_endline0");
    672   }
    673 
    674   for(i=i0; i<=i1; i++) {
    675     n = m[i][j0-1];
    676     for(j=j0; j<=j0+n-1; j++) {
    677       fprintf(f, format, m[i][j]);
    678     }
    679     fputc('\n', f);
    680   }
    681   fclose(f);
    682 }
     136
     137#undef write_type_matrix_endline1
     138#define write_type_matrix_endline1(t) \
     139void short_name(t,write_,matrix_endline1)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * filename) \
     140{                                                                \
     141    FILE * f = fopen(filename, "wt");                            \
     142    if (f == NULL) {                                             \
     143        nrerror("Can't open file %s in %s", filename, __func__); \
     144    }                                                            \
     145    for (int32_t i = i0; i <= i1; i++) {                         \
     146        int32_t n = (int32_t) m[i][j0 - 1];                      \
     147        for (int32_t j = j0; j <= j0 + n - 1; j++) {             \
     148            fprintf(f, format, m[i][j]);                         \
     149        }                                                        \
     150        fprintf(f, "\n");                                        \
     151    }                                                            \
     152    fprintf(f, "\n");                                            \
     153    fclose(f);                                                   \
     154}
     155
     156write_type_matrix_endline1(int8_t);
     157write_type_matrix_endline1(uint8_t);
     158write_type_matrix_endline1(int16_t);
     159write_type_matrix_endline1(uint16_t);
     160write_type_matrix_endline1(int32_t);
     161write_type_matrix_endline1(uint32_t);
     162write_type_matrix_endline1(int64_t);
     163write_type_matrix_endline1(uint64_t);
     164write_type_matrix_endline1(float);
     165write_type_matrix_endline1(double);
     166
     167
    683168/* ------------------------------------- */
    684169/* --- write_imatrix_number_endline0 --- */
    685170/* ------------------------------------- */
    686 /* --------------------------------------------------------------------------------------------------------------------- */
    687 IMAGE_EXPORT(void) write_bmatrix_number_endline0(byte **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    688 /* --------------------------------------------------------------------------------------------------------------------- */
    689 {
    690   int i,j, n;
    691  
    692   FILE *f;
    693 
    694   f = fopen(filename, "wt");
    695   if(f == NULL) {
    696     nrerror("Can't open file in write_bmatrix_number_endline0");
    697   }
    698 
    699   for(i=i0; i<=i1; i++) {
    700     fprintf(f, "[%3d] ", i);
    701     n = m[i][j0];
    702     for(j=j0; j<=j0+n; j++) {
    703       fprintf(f, format, m[i][j]);
    704     }
    705     fputc('\n', f);
    706   }
    707   fclose(f);
    708 }
    709 /* ------------------------------------------------------------------------------------------------------------------------- */
    710 IMAGE_EXPORT(void) write_i16matrix_number_endline0(int16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    711 /* ------------------------------------------------------------------------------------------------------------------------ */
    712 {
    713   int i,j, n;
    714  
    715   FILE *f;
    716 
    717   f = fopen(filename, "wt");
    718   if(f == NULL) {
    719     nrerror("Can't open file in write_i16matrix_number_endline0");
    720   }
    721 
    722   for(i=i0; i<=i1; i++) {
    723     fprintf(f, "[%3d] ", i);
    724     n = m[i][j0];
    725     for(j=j0; j<=j0+n; j++) {
    726       fprintf(f, format, m[i][j]);
    727     }
    728     fputc('\n', f);
    729   }
    730   fclose(f);
    731 }
    732 /* -------------------------------------------------------------------------------------------------------------------------- */
    733 IMAGE_EXPORT(void) write_ui16matrix_number_endline0(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    734 /* -------------------------------------------------------------------------------------------------------------------------- */
    735 {
    736   int i,j, n;
    737  
    738   FILE *f;
    739 
    740   f = fopen(filename, "wt");
    741   if(f == NULL) {
    742     nrerror("Can't open file in write_ui16matrix_number_endline0");
    743   }
    744 
    745   for(i=i0; i<=i1; i++) {
    746     fprintf(f, "[%3d] ", i);
    747     n = m[i][j0];
    748     for(j=j0; j<=j0+n; j++) {
    749       fprintf(f, format, m[i][j]);
    750     }
    751     fputc('\n', f);
    752   }
    753   fclose(f);
    754 }
    755 /* ------------------------------------------------------------------------------------------------------------------------ */
    756 IMAGE_EXPORT(void) write_i32matrix_number_endline0(int32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    757 /* ------------------------------------------------------------------------------------------------------------------------ */
    758 {
    759   int i,j, n;
    760  
    761   FILE *f;
    762 
    763   f = fopen(filename, "wt");
    764   if(f == NULL) {
    765     nrerror("Can't open file in write_i32matrix_number_endline0");
    766   }
    767 
    768   for(i=i0; i<=i1; i++) {
    769     fprintf(f, "[%3d] ", i);
    770     n = m[i][j0];
    771     for(j=j0; j<=j0+n; j++) {
    772       fprintf(f, format, m[i][j]);
    773     }
    774     fputc('\n', f);
    775   }
    776   fclose(f);
    777 }
    778 /* -------------------------------------------------------------------------------------------------------------------------- */
    779 IMAGE_EXPORT(void) write_ui32matrix_number_endline0(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    780 /* -------------------------------------------------------------------------------------------------------------------------- */
    781 {
    782   int i,j, n;
    783  
    784   FILE *f;
    785 
    786   f = fopen(filename, "wt");
    787   if(f == NULL) {
    788     nrerror("Can't open file in write_ui32matrix_number_endline0");
    789   }
    790 
    791   for(i=i0; i<=i1; i++) {
    792     fprintf(f, "[%3d] ", i);
    793     n = m[i][j0];
    794     for(j=j0; j<=j0+n; j++) {
    795       fprintf(f, format, m[i][j]);
    796     }
    797     fputc('\n', f);
    798   }
    799   fclose(f);
    800 }
    801 /* ------------------------------------------------------------------------------------------------------------------------ */
    802 IMAGE_EXPORT(void) write_i64matrix_number_endline0(int64 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    803 /* ------------------------------------------------------------------------------------------------------------------------ */
    804 {
    805   int i,j;
    806   int64 n;
    807  
    808   FILE *f;
    809 
    810   f = fopen(filename, "wt");
    811   if(f == NULL) {
    812     nrerror("Can't open file in write_i64matrix_number_endline0");
    813   }
    814 
    815   for(i=i0; i<=i1; i++) {
    816     fprintf(f, "[%3d] ", i);
    817     n = m[i][j0];
    818     for(j=j0; j<=j0+n; j++) {
    819       fprintf(f, format, m[i][j]);
    820     }
    821     fputc('\n', f);
    822   }
    823   fclose(f);
    824 }
    825 /* -------------------------------------------------------------------------------------------------------------------- */
    826 IMAGE_EXPORT(void) write_imatrix_number_endline0(int **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    827 /* -------------------------------------------------------------------------------------------------------------------- */
    828 {
    829   int i,j, n;
    830  
    831   FILE *f;
    832 
    833   f = fopen(filename, "wt");
    834   if(f == NULL) {
    835     nrerror("Can't open file in write_imatrix_number_endline0");
    836   }
    837 
    838   for(i=i0; i<=i1; i++) {
    839     fprintf(f, "[%3d] ", i);
    840     n = m[i][j0];
    841     for(j=j0; j<=j0+n; j++) {
    842       fprintf(f, format, m[i][j]);
    843     }
    844     fputc('\n', f);
    845   }
    846   fclose(f);
    847 }
     171
     172#undef write_type_matrix_number_endline0
     173#define write_type_matrix_number_endline0(t) \
     174void short_name(t,write_,matrix_number_endline0)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * filename) \
     175{                                                                \
     176    FILE * f = fopen(filename, "wt");                            \
     177    if (f == NULL) {                                             \
     178        nrerror("Can't open file %s in %s", filename, __func__); \
     179    }                                                            \
     180    for (int32_t i = i0; i <= i1; i++) {                         \
     181        fprintf(f, "[%3d] ", i);                                 \
     182        int32_t n = (int32_t) m[i][j0];                          \
     183        for (int32_t j = j0; j <= j0 + n; j++) {                 \
     184            fprintf(f, format, m[i][j]);                         \
     185        }                                                        \
     186        fprintf(f, "\n");                                        \
     187    }                                                            \
     188    fprintf(f, "\n");                                            \
     189    fclose(f);                                                   \
     190}
     191
     192write_type_matrix_number_endline0(int8_t);
     193write_type_matrix_number_endline0(uint8_t);
     194write_type_matrix_number_endline0(int16_t);
     195write_type_matrix_number_endline0(uint16_t);
     196write_type_matrix_number_endline0(int32_t);
     197write_type_matrix_number_endline0(uint32_t);
     198write_type_matrix_number_endline0(int64_t);
     199write_type_matrix_number_endline0(uint64_t);
     200write_type_matrix_number_endline0(float);
     201write_type_matrix_number_endline0(double);
     202
     203
    848204/* ------------------------------------- */
    849205/* --- write_imatrix_number_endline1 --- */
    850206/* ------------------------------------- */
    851 /* --------------------------------------------------------------------------------------------------------------------- */
    852 IMAGE_EXPORT(void) write_bmatrix_number_endline1(byte **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    853 /* --------------------------------------------------------------------------------------------------------------------- */
    854 {
    855   int i,j, n;
    856  
    857   FILE *f;
    858 
    859   f = fopen(filename, "wt");
    860   if(f == NULL) {
    861     nrerror("Can't open file in write_bmatrix_number_endline1");
    862   }
    863 
    864   for(i=i0; i<=i1; i++) {
    865     fprintf(f, "[%3d] ", i);
    866     n = m[i][j0-1];
    867     for(j=j0; j<=j0+n-1; j++) {
    868       fprintf(f, format, m[i][j]);
    869     }
    870     fputc('\n', f);
    871   }
    872   fclose(f);
    873 }
    874 /* ------------------------------------------------------------------------------------------------------------------------ */
    875 IMAGE_EXPORT(void) write_i16matrix_number_endline1(int16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    876 /* ------------------------------------------------------------------------------------------------------------------------ */
    877 {
    878   int i,j, n;
    879  
    880   FILE *f;
    881 
    882   f = fopen(filename, "wt");
    883   if(f == NULL) {
    884     nrerror("Can't open file in write_i16matrix_number_endline0");
    885   }
    886 
    887   for(i=i0; i<=i1; i++) {
    888     fprintf(f, "[%3d] ", i);
    889     n = m[i][j0-1];
    890     for(j=j0; j<=j0+n-1; j++) {
    891       fprintf(f, format, m[i][j]);
    892     }
    893     fputc('\n', f);
    894   }
    895   fclose(f);
    896 }
    897 /* -------------------------------------------------------------------------------------------------------------------------- */
    898 IMAGE_EXPORT(void) write_ui16matrix_number_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    899 /* -------------------------------------------------------------------------------------------------------------------------- */
    900 {
    901   int i,j, n;
    902  
    903   FILE *f;
    904 
    905   f = fopen(filename, "wt");
    906   if(f == NULL) {
    907     nrerror("Can't open file in write_ui16matrix_number_endline0");
    908   }
    909 
    910   for(i=i0; i<=i1; i++) {
    911     fprintf(f, "[%3d] ", i);
    912     n = m[i][j0-1];
    913     for(j=j0; j<=j0+n-1; j++) {
    914       fprintf(f, format, m[i][j]);
    915     }
    916     fputc('\n', f);
    917   }
    918   fclose(f);
    919 }
    920 /* ------------------------------------------------------------------------------------------------------------------------ */
    921 IMAGE_EXPORT(void) write_i32matrix_number_endline1(int32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    922 /* ------------------------------------------------------------------------------------------------------------------------ */
    923 {
    924   int i,j, n;
    925  
    926   FILE *f;
    927 
    928   f = fopen(filename, "wt");
    929   if(f == NULL) {
    930     nrerror("Can't open file in write_i32matrix_number_endline0");
    931   }
    932 
    933   for(i=i0; i<=i1; i++) {
    934     fprintf(f, "[%3d] ", i);
    935     n = m[i][j0-1];
    936     for(j=j0; j<=j0+n-1; j++) {
    937       fprintf(f, format, m[i][j]);
    938     }
    939     fputc('\n', f);
    940   }
    941   fclose(f);
    942 }
    943 /* -------------------------------------------------------------------------------------------------------------------------- */
    944 IMAGE_EXPORT(void) write_ui32matrix_number_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    945 /* -------------------------------------------------------------------------------------------------------------------------- */
    946 {
    947   int i,j, n;
    948  
    949   FILE *f;
    950 
    951   f = fopen(filename, "wt");
    952   if(f == NULL) {
    953     nrerror("Can't open file in write_ui32matrix_number_endline0");
    954   }
    955 
    956   for(i=i0; i<=i1; i++) {
    957     fprintf(f, "[%3d] ", i);
    958     n = m[i][j0-1];
    959     for(j=j0; j<=j0+n-1; j++) {
    960       fprintf(f, format, m[i][j]);
    961     }
    962     fputc('\n', f);
    963   }
    964   fclose(f);
    965 }
    966 /* ------------------------------------------------------------------------------------------------------------------------ */
    967 IMAGE_EXPORT(void) write_i64matrix_number_endline1(int64 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    968 /* ------------------------------------------------------------------------------------------------------------------------ */
    969 {
    970   int i,j;
    971   int64 n;
    972  
    973   FILE *f;
    974 
    975   f = fopen(filename, "wt");
    976   if(f == NULL) {
    977     nrerror("Can't open file in write_i64matrix_number_endline0");
    978   }
    979 
    980   for(i=i0; i<=i1; i++) {
    981     fprintf(f, "[%3d] ", i);
    982     n = m[i][j0-1];
    983     for(j=j0; j<=j0+n-1; j++) {
    984       fprintf(f, format, m[i][j]);
    985     }
    986     fputc('\n', f);
    987   }
    988   fclose(f);
    989 }
    990 /* -------------------------------------------------------------------------------------------------------------------- */
    991 IMAGE_EXPORT(void) write_imatrix_number_endline1(int **m,long i0, long i1, long j0, long j1, char *format, char *filename)
    992 /* -------------------------------------------------------------------------------------------------------------------- */
    993 {
    994   int i,j, n;
    995  
    996   FILE *f;
    997 
    998   f = fopen(filename, "wt");
    999   if(f == NULL) {
    1000     nrerror("Can't open file in write_imatrix_number_endline0");
    1001   }
    1002 
    1003   for(i=i0; i<=i1; i++) {
    1004     fprintf(f, "[%3d] ", i);
    1005     n = m[i][j0-1];
    1006     for(j=j0; j<=j0+n-1; j++) {
    1007       fprintf(f, format, m[i][j]);
    1008     }
    1009     fputc('\n', f);
    1010   }
    1011   fclose(f);
    1012 }
     207
     208#undef write_type_matrix_number_endline1
     209#define write_type_matrix_number_endline1(t) \
     210void short_name(t,write_,matrix_number_endline1)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * filename) \
     211{                                                                \
     212    FILE * f = fopen(filename, "wt");                            \
     213    if (f == NULL) {                                             \
     214        nrerror("Can't open file %s in %s", filename, __func__); \
     215    }                                                            \
     216    for (int32_t i = i0; i <= i1; i++) {                         \
     217        fprintf(f, "[%3d] ", i);                                 \
     218        int32_t n = (int32_t) m[i][j0 - 1];                      \
     219        for (int32_t j = j0; j <= j0 + n - 1; j++) {             \
     220            fprintf(f, format, m[i][j]);                         \
     221        }                                                        \
     222        fprintf(f, "\n");                                        \
     223    }                                                            \
     224    fprintf(f, "\n");                                            \
     225    fclose(f);                                                   \
     226}
     227
     228write_type_matrix_number_endline1(int8_t);
     229write_type_matrix_number_endline1(uint8_t);
     230write_type_matrix_number_endline1(int16_t);
     231write_type_matrix_number_endline1(uint16_t);
     232write_type_matrix_number_endline1(int32_t);
     233write_type_matrix_number_endline1(uint32_t);
     234write_type_matrix_number_endline1(int64_t);
     235write_type_matrix_number_endline1(uint64_t);
     236write_type_matrix_number_endline1(float);
     237write_type_matrix_number_endline1(double);
     238
     239
    1013240/* ---------------------- */
    1014241/* -- fwrite_trimatrix -- */
    1015242/* ---------------------- */
    1016 /* ---------------------------------------------------------------------------------------------------- */
    1017 IMAGE_EXPORT(void) fwrite_btrimatrix(byte **m,long i0,long i1,long j0, long j1, long step, char *filename)
    1018 /* ---------------------------------------------------------------------------------------------------- */
    1019 {
    1020   long  i, ncol = j1-j0+1;
    1021   FILE *f;
    1022 
    1023   f = fopen(filename, "wb");
    1024   if(f == NULL) nrerror("Can't open file in fwrite_btrimatrix");
    1025 
    1026   for(i=i0; i<=i1; i++) {
    1027     fwrite(m[i]+j0, sizeof(byte), ncol, f);
    1028     ncol += step;
    1029   }
    1030   fclose(f);
    1031 }
    1032 /* ------------------------------------------------------------------------------------------------------- */
    1033 IMAGE_EXPORT(void) fwrite_i16trimatrix(int16 **m,long i0,long i1,long j0, long j1, long step, char *filename)
    1034 /* ------------------------------------------------------------------------------------------------------- */
    1035 {
    1036   long  i, ncol = j1-j0+1;
    1037   FILE *f;
    1038 
    1039   f = fopen(filename, "wb");
    1040   if(f == NULL) nrerror("Can't open file in fwrite_i16trimatrix");
    1041 
    1042   for(i=i0; i<=i1; i++) {
    1043     fwrite(m[i]+j0, sizeof(int16), ncol, f);
    1044     ncol += step;
    1045   }
    1046   fclose(f);
    1047 }
    1048 /* --------------------------------------------------------------------------------------------------------- */
    1049 IMAGE_EXPORT(void) fwrite_ui16trimatrix(uint16 **m,long i0,long i1,long j0, long j1, long step, char *filename)
    1050 /* --------------------------------------------------------------------------------------------------------- */
    1051 {
    1052   long  i, ncol = j1-j0+1;
    1053   FILE *f;
    1054 
    1055   f = fopen(filename, "wb");
    1056   if(f == NULL) nrerror("Can't open file in fwrite_ui16trimatrix");
    1057 
    1058   for(i=i0; i<=i1; i++) {
    1059     fwrite(m[i]+j0, sizeof(uint16), ncol, f);
    1060     ncol += step;
    1061   }
    1062   fclose(f);
    1063 }
    1064 /* ------------------------------------------------------------------------------------------------------- */
    1065 IMAGE_EXPORT(void) fwrite_i32trimatrix(int32 **m,long i0,long i1,long j0, long j1, long step, char *filename)
    1066 /* ------------------------------------------------------------------------------------------------------- */
    1067 {
    1068   long  i, ncol = j1-j0+1;
    1069   FILE *f;
    1070 
    1071   f = fopen(filename, "wb");
    1072   if(f == NULL) nrerror("Can't open file in fwrite_i32trimatrix");
    1073 
    1074   for(i=i0; i<=i1; i++) {
    1075     fwrite(m[i]+j0, sizeof(int32), ncol, f);
    1076     ncol += step;
    1077   }
    1078   fclose(f);
    1079 }
    1080 /* --------------------------------------------------------------------------------------------------------- */
    1081 IMAGE_EXPORT(void) fwrite_f32trimatrix(float32 **m,long i0,long i1,long j0, long j1, long step, char *filename)
    1082 /* --------------------------------------------------------------------------------------------------------- */
    1083 {
    1084   long  i, ncol = j1-j0+1;
    1085   FILE *f;
    1086 
    1087   f = fopen(filename, "wb");
    1088   if(f == NULL) nrerror("Can't open file in fwrite_f32trimatrix");
    1089 
    1090   for(i=i0; i<=i1; i++) {
    1091     fwrite(m[i]+j0, sizeof(float32), ncol, f);
    1092     ncol += step;
    1093   }
    1094   fclose(f);
    1095 }
    1096 /* --------------------------------------------------------------------------------------------------------- */
    1097 IMAGE_EXPORT(void) fwrite_f64trimatrix(float64 **m,long i0,long i1,long j0, long j1, long step, char *filename)
    1098 /* --------------------------------------------------------------------------------------------------------- */
    1099 {
    1100   long  i, ncol = j1-j0+1;
    1101   FILE *f;
    1102 
    1103   f = fopen(filename, "wb");
    1104   if(f == NULL) nrerror("Can't open file in fwrite_f64trimatrix");
    1105 
    1106   for(i=i0; i<=i1; i++) {
    1107     fwrite(m[i]+j0, sizeof(float64), ncol, f);
    1108   }
    1109   fclose(f);
    1110 }
     243
     244#undef fwrite_type_trimatrix
     245#define fwrite_type_trimatrix(t) \
     246void short_name(t,fwrite_,trimatrix)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t step, char * filename) \
     247{                                                                \
     248    int32_t ncol = j1 - j0 + 1;                                  \
     249    FILE * f = fopen(filename, "wb");                            \
     250    if (f == NULL) {                                             \
     251        nrerror("Can't open file %s in %s", filename, __func__); \
     252    }                                                            \
     253    for (int32_t i = i0; i <= i1; i++) {                         \
     254        fwrite(m[i] + j0, sizeof(t), ncol, f);                   \
     255        ncol += step;                                            \
     256    }                                                            \
     257    fclose(f);                                                   \
     258}
     259
     260fwrite_type_trimatrix(int8_t);
     261fwrite_type_trimatrix(uint8_t);
     262fwrite_type_trimatrix(int16_t);
     263fwrite_type_trimatrix(uint16_t);
     264fwrite_type_trimatrix(int32_t);
     265fwrite_type_trimatrix(uint32_t);
     266fwrite_type_trimatrix(int64_t);
     267fwrite_type_trimatrix(uint64_t);
     268fwrite_type_trimatrix(float);
     269fwrite_type_trimatrix(double);
     270
     271
     272
    1111273
    1112274/* --------------------- */
    1113275/* -- fread_trimatrix -- */
    1114276/* --------------------- */
    1115 /* --------------------------------------------------------------------------------------------------- */
    1116 IMAGE_EXPORT(void) fread_btrimatrix(char *filename, byte **m,long i0,long i1,long j0, long j1, long step)
    1117 /* --------------------------------------------------------------------------------------------------- */
    1118 {
    1119   long  i, ncol = j1-j0+1, nread;
    1120   FILE *f;
    1121 
    1122   f = fopen(filename, "rb");
    1123   if(f == NULL) nrerror("Can't open file in fread_btrimatrix");
    1124 
    1125   for(i=i0; i<=i1; i++) {
    1126     nread = fread(m[i]+j0, sizeof(byte), ncol, f);
    1127     if(nread != ncol) nrerror("fread_btrimatrix : can't read data");
    1128     ncol += step;
    1129   }
    1130   fclose(f);
    1131 }
    1132 /* ------------------------------------------------------------------------------------------------------ */
    1133 IMAGE_EXPORT(void) fread_i16trimatrix(char *filename, int16 **m,long i0,long i1,long j0, long j1, long step)
    1134 /* ------------------------------------------------------------------------------------------------------ */
    1135 {
    1136   long  i, ncol = j1-j0+1, nread;
    1137   FILE *f;
    1138 
    1139   f = fopen(filename, "rb");
    1140   if(f == NULL) nrerror("Can't open file in fread_i16trimatrix");
    1141 
    1142   for(i=i0; i<=i1; i++) {
    1143     nread = fread(m[i]+j0, sizeof(int16), ncol, f);
    1144     if(nread != ncol) nrerror("fread_i16trimatrix : can't read data");
    1145     ncol += step;
    1146   }
    1147   fclose(f);
    1148 }
    1149 /* -------------------------------------------------------------------------------------------------------- */
    1150 IMAGE_EXPORT(void) fread_ui16trimatrix(char *filename, uint16 **m,long i0,long i1,long j0, long j1, long step)
    1151 /* -------------------------------------------------------------------------------------------------------- */
    1152 {
    1153   long  i, ncol = j1-j0+1, nread;
    1154   FILE *f;
    1155 
    1156   f = fopen(filename, "rb");
    1157   if(f == NULL) nrerror("Can't open file in fread_ui16trimatrix");
    1158 
    1159   for(i=i0; i<=i1; i++) {
    1160     nread = fread(m[i]+j0, sizeof(uint16), ncol, f);
    1161     if(nread != ncol) nrerror("fread_ui16trimatrix : can't read data");
    1162     ncol += step;
    1163   }
    1164   fclose(f);
    1165 }
    1166 /* -------------------------------------------------------------------------------------------------- */
    1167 IMAGE_EXPORT(void) fread_itrimatrix(char *filename, int **m,long i0,long i1,long j0, long j1, long step)
    1168 /* -------------------------------------------------------------------------------------------------- */
    1169 {
    1170   long  i, ncol = j1-j0+1, nread;
    1171   FILE *f;
    1172 
    1173   f = fopen(filename, "rb");
    1174   if(f == NULL) nrerror("Can't open file in fread_itrimatrix");
    1175 
    1176   for(i=i0; i<=i1; i++) {
    1177     nread = fread(m[i]+j0, sizeof(int), ncol, f);
    1178     if(nread != ncol) nrerror("fread_itrimatrix : can't read data");
    1179     ncol += step;
    1180   }
    1181   fclose(f);
    1182 }
    1183 /* ------------------------------------------------------------------------------------------------------ */
    1184 IMAGE_EXPORT(void) fread_i32trimatrix(char *filename, int32 **m,long i0,long i1,long j0, long j1, long step)
    1185 /* ------------------------------------------------------------------------------------------------------ */
    1186 {
    1187   long  i, ncol = j1-j0+1, nread;
    1188   FILE *f;
    1189 
    1190   f = fopen(filename, "rb");
    1191   if(f == NULL) nrerror("Can't open file in fread_i32trimatrix");
    1192 
    1193   for(i=i0; i<=i1; i++) {
    1194     nread = fread(m[i]+j0, sizeof(byte), ncol, f);
    1195     if(nread != ncol) nrerror("fread_i32trimatrix : can't read data");
    1196     ncol += step;
    1197   }
    1198   fclose(f);
    1199 }
    1200 /* -------------------------------------------------------------------------------------------------------- */
    1201 IMAGE_EXPORT(void) fread_f32trimatrix(char *filename, float32 **m,long i0,long i1,long j0, long j1, long step)
    1202 /* -------------------------------------------------------------------------------------------------------- */
    1203 {
    1204   long  i, ncol = j1-j0+1, nread;
    1205   FILE *f;
    1206 
    1207   f = fopen(filename, "rb");
    1208   if(f == NULL) nrerror("Can't open file in fread_f32trimatrix");
    1209 
    1210   for(i=i0; i<=i1; i++) {
    1211     nread = fread(m[i]+j0, sizeof(byte), ncol, f);
    1212     if(nread != ncol) nrerror("fread_f32trimatrix : can't read data");
    1213     ncol += step;
    1214   }
    1215   fclose(f);
    1216 }
    1217 /* -------------------------------------------------------------------------------------------------------- */
    1218 IMAGE_EXPORT(void) fread_f64trimatrix(char *filename, float64 **m,long i0,long i1,long j0, long j1, long step)
    1219 /* -------------------------------------------------------------------------------------------------------- */
    1220 {
    1221   long  i, ncol = j1-j0+1, nread;
    1222   FILE *f;
    1223 
    1224   f = fopen(filename, "rb");
    1225   if(f == NULL) nrerror("Can't open file in fread_f64trimatrix");
    1226 
    1227   for(i=i0; i<=i1; i++) {
    1228     nread = fread(m[i]+j0, sizeof(byte), ncol, f);
    1229     if(nread != ncol) nrerror("fread_f64trimatrix : can't read data");
    1230     ncol += step;
    1231   }
    1232   fclose(f);
    1233 }
     277
     278#undef fread_type_trimatrix
     279#define fread_type_trimatrix(t) \
     280void short_name(t,fread_,trimatrix)(char * filename, t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t step) \
     281{                                                                \
     282    int32_t ncol = j1 - j0 + 1;                                  \
     283    FILE * f = fopen(filename, "rb");                            \
     284    if (f == NULL) {                                             \
     285        nrerror("Can't open file %s in %s", filename, __func__); \
     286    }                                                            \
     287    for (int32_t i = i0; i <= i1; i++) {                         \
     288        fread(m[i] + j0, sizeof(t), ncol, f);    \
     289        ncol += step;                                            \
     290    }                                                            \
     291    fclose(f);                                                   \
     292}
     293
     294fread_type_trimatrix(int8_t);
     295fread_type_trimatrix(uint8_t);
     296fread_type_trimatrix(int16_t);
     297fread_type_trimatrix(uint16_t);
     298fread_type_trimatrix(int32_t);
     299fread_type_trimatrix(uint32_t);
     300fread_type_trimatrix(int64_t);
     301fread_type_trimatrix(uint64_t);
     302fread_type_trimatrix(float);
     303fread_type_trimatrix(double);
     304
     305
     306// Local Variables:
     307// tab-width: 4
     308// c-basic-offset: 4
     309// c-file-offsets:((innamespace . 0)(inline-open . 0))
     310// indent-tabs-mode: nil
     311// End:
     312
     313// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
     314
Note: See TracChangeset for help on using the changeset viewer.