source: soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc2x.c @ 772

Last change on this file since 772 was 772, checked in by meunier, 8 years ago
  • Ajout de l'application rosenfeld
  • Changement du nom du flag O_CREATE en O_CREAT
File size: 20.6 KB
Line 
1/* ------------------- */
2/* --- nralloc2X.c --- */
3/* ------------------- */
4
5/*
6 * Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved
7 * Univ Paris Sud XI, CNRS
8 *
9*/
10
11/*
12* 2002/06/11 ajout des fonctions endline
13*/
14#include <stdio.h>
15#include <stddef.h>
16#include <stdlib.h>
17#include <malloc.h>
18#include <math.h> // fabs
19// #include <memory.h> // memcpy
20
21#include "mypredef.h"
22#include "nrtype.h"
23#include "nrdef.h"
24#include "nrmacro.h"
25#include "nrkernel.h"
26
27#include "nralloc1.h"
28#include "nralloc2.h"
29#include "nralloc2x.h"
30//#include "nrarith.h"
31
32/* ----------------------------------------------------------------------- */
33IMAGE_EXPORT(si16Point**) si16Pmatrix(long nrl, long nrh, long ncl, long nch)
34/* ----------------------------------------------------------------------- */
35{
36    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
37    si16Point **m;
38   
39    /* allocate pointers to rows */
40    m=(si16Point **) malloc((size_t)((nrow+NR_END)*sizeof(si16Point*)));
41    if (!m) nrerror("allocation failure 1 in si16Pmatrix()");
42    m += NR_END;
43    m -= nrl;
44   
45    /* allocate rows and set pointers to them */
46    m[nrl]=(si16Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(si16Point)));
47    if (!m[nrl]) nrerror("allocation failure 2 in si16Pmatrix()");
48    m[nrl] += NR_END;
49    m[nrl] -= ncl;
50   
51    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
52   
53    /* return pointer to array of pointers to rows */
54    return m;
55}
56/* ----------------------------------------------------------------------- */
57IMAGE_EXPORT(ui16Point**) ui16Pmatrix(long nrl, long nrh, long ncl, long nch)
58/* ----------------------------------------------------------------------- */
59{
60    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
61    ui16Point **m;
62   
63    /* allocate pointers to rows */
64    m=(ui16Point **) malloc((size_t)((nrow+NR_END)*sizeof(ui16Point*)));
65    if (!m) nrerror("allocation failure 1 in ui16Pmatrix()");
66    m += NR_END;
67    m -= nrl;
68   
69    /* allocate rows and set pointers to them */
70    m[nrl]=(ui16Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(ui16Point)));
71    if (!m[nrl]) nrerror("allocation failure 2 in ui16Pmatrix()");
72    m[nrl] += NR_END;
73    m[nrl] -= ncl;
74   
75    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
76   
77    /* return pointer to array of pointers to rows */
78    return m;
79}
80/* ----------------------------------------------------------------------- */
81IMAGE_EXPORT(si32Point**) si32Pmatrix(long nrl, long nrh, long ncl, long nch)
82/* ----------------------------------------------------------------------- */
83{
84    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
85    si32Point **m;
86   
87    /* allocate pointers to rows */
88    m=(si32Point **) malloc((size_t)((nrow+NR_END)*sizeof(si32Point*)));
89    if (!m) nrerror("allocation failure 1 in si32Pmatrix()");
90    m += NR_END;
91    m -= nrl;
92   
93    /* allocate rows and set pointers to them */
94    m[nrl]=(si32Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(si32Point)));
95    if (!m[nrl]) nrerror("allocation failure 2 in si32Pmatrix()");
96    m[nrl] += NR_END;
97    m[nrl] -= ncl;
98   
99    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
100   
101    /* return pointer to array of pointers to rows */
102    return m;
103}
104/* ----------------------------------------------------------------------- */
105IMAGE_EXPORT(ui32Point**) ui32Pmatrix(long nrl, long nrh, long ncl, long nch)
106/* ----------------------------------------------------------------------- */
107{
108    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
109    ui32Point **m;
110   
111    /* allocate pointers to rows */
112    m=(ui32Point **) malloc((size_t)((nrow+NR_END)*sizeof(ui32Point*)));
113    if (!m) nrerror("allocation failure 1 in ui32Pmatrix()");
114    m += NR_END;
115    m -= nrl;
116   
117    /* allocate rows and set pointers to them */
118    m[nrl]=(ui32Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(ui32Point)));
119    if (!m[nrl]) nrerror("allocation failure 2 in ui32Pmatrix()");
120    m[nrl] += NR_END;
121    m[nrl] -= ncl;
122   
123    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
124   
125    /* return pointer to array of pointers to rows */
126    return m;
127}
128/* ---------------------------------------------------------------------- */
129IMAGE_EXPORT(f32Point**) f32Pmatrix(long nrl, long nrh, long ncl, long nch)
130/* --------------------------------------------------------------------- */
131{
132    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
133    f32Point **m;
134   
135    /* allocate pointers to rows */
136    m=(f32Point **) malloc((size_t)((nrow+NR_END)*sizeof(f32Point*)));
137    if (!m) nrerror("allocation failure 1 in f32Pmatrix()");
138    m += NR_END;
139    m -= nrl;
140   
141    /* allocate rows and set pointers to them */
142    m[nrl]=(f32Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(f32Point)));
143    if (!m[nrl]) nrerror("allocation failure 2 in f32Pmatrix()");
144    m[nrl] += NR_END;
145    m[nrl] -= ncl;
146   
147    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
148   
149    /* return pointer to array of pointers to rows */
150    return m;
151}
152/* ------------------------------------------------------------------------- */
153IMAGE_EXPORT(si16Triplet**) si16Tmatrix(long nrl, long nrh, long ncl, long nch)
154/* ------------------------------------------------------------------------- */
155{
156    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
157    si16Triplet **m;
158   
159    /* allocate pointers to rows */
160    m=(si16Triplet **) malloc((size_t)((nrow+NR_END)*sizeof(si16Triplet*)));
161    if (!m) nrerror("allocation failure 1 in si16Tmatrix()");
162    m += NR_END;
163    m -= nrl;
164   
165    /* allocate rows and set pointers to them */
166    m[nrl]=(si16Triplet *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(si16Triplet)));
167    if (!m[nrl]) nrerror("allocation failure 2 in si16Tmatrix()");
168    m[nrl] += NR_END;
169    m[nrl] -= ncl;
170   
171    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
172   
173    /* return pointer to array of pointers to rows */
174    return m;
175}
176/* ----------------------------------------------------------------------- */
177IMAGE_EXPORT(ui16Triplet**) ui16Tmatrix(long nrl, long nrh, long ncl, long nch)
178/* ----------------------------------------------------------------------- */
179{
180    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
181    ui16Triplet **m;
182   
183    /* allocate pointers to rows */
184    m=(ui16Triplet **) malloc((size_t)((nrow+NR_END)*sizeof(ui16Triplet*)));
185    if (!m) nrerror("allocation failure 1 in ui16Tmatrix()");
186    m += NR_END;
187    m -= nrl;
188   
189    /* allocate rows and set pointers to them */
190    m[nrl]=(ui16Triplet *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(ui16Triplet)));
191    if (!m[nrl]) nrerror("allocation failure 2 in ui16Tmatrix()");
192    m[nrl] += NR_END;
193    m[nrl] -= ncl;
194   
195    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
196   
197    /* return pointer to array of pointers to rows */
198    return m;
199}
200/* ----------------------------------------------------------------------- */
201IMAGE_EXPORT(si32Triplet**) si32Tmatrix(long nrl, long nrh, long ncl, long nch)
202/* ----------------------------------------------------------------------- */
203{
204    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
205    si32Triplet **m;
206   
207    /* allocate pointers to rows */
208    m=(si32Triplet**) malloc((size_t)((nrow+NR_END)*sizeof(si32Triplet*)));
209    if (!m) nrerror("allocation failure 1 in si32Tmatrix()");
210    m += NR_END;
211    m -= nrl;
212   
213    /* allocate rows and set pointers to them */
214    m[nrl]=(si32Triplet*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(si32Triplet)));
215    if (!m[nrl]) nrerror("allocation failure 2 in si32Tmatrix()");
216    m[nrl] += NR_END;
217    m[nrl] -= ncl;
218   
219    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
220   
221    /* return pointer to array of pointers to rows */
222    return m;
223}
224/* ----------------------------------------------------------------------- */
225IMAGE_EXPORT(ui32Triplet**) ui32Tmatrix(long nrl, long nrh, long ncl, long nch)
226/* ----------------------------------------------------------------------- */
227{
228    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
229    ui32Triplet **m;
230   
231    /* allocate pointers to rows */
232    m=(ui32Triplet **) malloc((size_t)((nrow+NR_END)*sizeof(ui32Triplet*)));
233    if (!m) nrerror("allocation failure 1 in ui32Tmatrix()");
234    m += NR_END;
235    m -= nrl;
236   
237    /* allocate rows and set pointers to them */
238    m[nrl]=(ui32Triplet *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(ui32Triplet)));
239    if (!m[nrl]) nrerror("allocation failure 2 in ui32Tmatrix()");
240    m[nrl] += NR_END;
241    m[nrl] -= ncl;
242   
243    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
244   
245    /* return pointer to array of pointers to rows */
246    return m;
247}
248/* ---------------------------------------------------------------------- */
249IMAGE_EXPORT(f32Triplet**) f32Tmatrix(long nrl, long nrh, long ncl, long nch)
250/* --------------------------------------------------------------------- */
251{
252    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
253    f32Triplet **m;
254   
255    /* allocate pointers to rows */
256    m=(f32Triplet **) malloc((size_t)((nrow+NR_END)*sizeof(f32Triplet*)));
257    if (!m) nrerror("allocation failure 1 in f32Tmatrix()");
258    m += NR_END;
259    m -= nrl;
260   
261    /* allocate rows and set pointers to them */
262    m[nrl]=(f32Triplet *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(f32Triplet)));
263    if (!m[nrl]) nrerror("allocation failure 2 in f32Tmatrix()");
264    m[nrl] += NR_END;
265    m[nrl] -= ncl;
266   
267    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
268   
269    /* return pointer to array of pointers to rows */
270    return m;
271}
272/* ---------------------------------------------------------------------------------- */
273IMAGE_EXPORT(void) free_si16Pmatrix(si16Point **m, long nrl, long nrh, long ncl, long nch)
274/* ---------------------------------------------------------------------------------- */
275/* free an si16Point matrix allocated by si16Pmatrix() */
276{
277    free((FREE_ARG) (m[nrl]+ncl-NR_END));
278    free((FREE_ARG) (m+nrl-NR_END));
279}
280/* ---------------------------------------------------------------------------------- */
281IMAGE_EXPORT(void) free_ui16Pmatrix(ui16Point **m, long nrl, long nrh, long ncl, long nch)
282/* ---------------------------------------------------------------------------------- */
283/* free an ui16Point matrix allocated by ui16Pmatrix() */
284{
285    free((FREE_ARG) (m[nrl]+ncl-NR_END));
286    free((FREE_ARG) (m+nrl-NR_END));
287}
288/* ------------------------------------------------------------------------------------ */
289IMAGE_EXPORT(void) free_si32Pmatrix(si32Point **m, long nrl, long nrh, long ncl, long nch)
290/* ------------------------------------------------------------------------------------ */
291{
292    free((FREE_ARG) (m[nrl]+ncl-NR_END));
293    free((FREE_ARG) (m+nrl-NR_END));
294}
295/* ------------------------------------------------------------------------------------ */
296IMAGE_EXPORT(void) free_ui32Pmatrix(ui32Point **m, long nrl, long nrh, long ncl, long nch)
297/* ------------------------------------------------------------------------------------ */
298{
299    free((FREE_ARG) (m[nrl]+ncl-NR_END));
300    free((FREE_ARG) (m+nrl-NR_END));
301}
302/* ---------------------------------------------------------------------------------- */
303IMAGE_EXPORT(void) free_f32Pmatrix(f32Point **m, long nrl, long nrh, long ncl, long nch)
304/* ---------------------------------------------------------------------------------- */
305/* free an f32Point matrix allocated by f32Pmatrix() */
306{
307    free((FREE_ARG) (m[nrl]+ncl-NR_END));
308    free((FREE_ARG) (m+nrl-NR_END));
309}
310/* -------------------------------------------------------------------------------------- */
311IMAGE_EXPORT(void) free_si16Tmatrix(si16Triplet **m, long nrl, long nrh, long ncl, long nch)
312/* -------------------------------------------------------------------------------------- */
313/* free an si16Point matrix allocated by si16Pmatrix() */
314{
315    free((FREE_ARG) (m[nrl]+ncl-NR_END));
316    free((FREE_ARG) (m+nrl-NR_END));
317}
318/* ---------------------------------------------------------------------------------- */
319IMAGE_EXPORT(void) free_ui16Tmatrix(ui16Triplet **m, long nrl, long nrh, long ncl, long nch)
320/* ---------------------------------------------------------------------------------- */
321/* free an ui16Point matrix allocated by ui16Pmatrix() */
322{
323    free((FREE_ARG) (m[nrl]+ncl-NR_END));
324    free((FREE_ARG) (m+nrl-NR_END));
325}
326/* ------------------------------------------------------------------------------------ */
327IMAGE_EXPORT(void) free_si32Tmatrix(si32Triplet **m, long nrl, long nrh, long ncl, long nch)
328/* ------------------------------------------------------------------------------------ */
329{
330    free((FREE_ARG) (m[nrl]+ncl-NR_END));
331    free((FREE_ARG) (m+nrl-NR_END));
332}
333/* -------------------------------------------------------------------------------------- */
334IMAGE_EXPORT(void) free_ui32Tmatrix(ui32Triplet **m, long nrl, long nrh, long ncl, long nch)
335/* -------------------------------------------------------------------------------------- */
336{
337    free((FREE_ARG) (m[nrl]+ncl-NR_END));
338    free((FREE_ARG) (m+nrl-NR_END));
339}
340/* ------------------------------------------------------------------------------------ */
341IMAGE_EXPORT(void) free_f32Tmatrix(f32Triplet **m, long nrl, long nrh, long ncl, long nch)
342/* ------------------------------------------------------------------------------------ */
343/* free an f32Point matrix allocated by f32Pmatrix() */
344{
345    free((FREE_ARG) (m[nrl]+ncl-NR_END));
346    free((FREE_ARG) (m+nrl-NR_END));
347}
348
349/* ----------------- */
350/* --- trimatrix --- */
351/* ----------------- */
352/* ---------------------------------------------------------------------------- */
353IMAGE_EXPORT(byte**) btrimatrix(long nrl, long nrh, long ncl, long nch, long step)
354/* ---------------------------------------------------------------------------- */
355/* allocate an byte triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
356{
357    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
358    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
359    byte **m;
360   
361    /* allocate pointers to rows */
362    m=(byte **) malloc((size_t)((nrow+NR_END)*sizeof(byte*)));
363    if (!m) nrerror("allocation failure 1 in btrimatrix()");
364    m += NR_END;
365    m -= nrl;
366   
367   
368    /* allocate rows and set pointers to them */
369    m[nrl]=(byte *) malloc((size_t)((n+NR_END)*sizeof(byte)));
370    if (!m[nrl]) nrerror("allocation failure 2 in btrimatrix()");
371    m[nrl] += NR_END;
372    m[nrl] -= ncl;
373   
374    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
375   
376    /* return pointer to array of pointers to rows */
377    return m;
378}
379/* --------------------------------------------------------------------------------- */
380IMAGE_EXPORT(sint16**) si16trimatrix(long nrl, long nrh, long ncl, long nch, long step)
381/* --------------------------------------------------------------------------------- */
382/* allocate an i16 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
383{
384    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
385    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
386    sint16 **m;
387   
388    /* allocate pointers to rows */
389    m=(sint16 **) malloc((size_t)((nrow+NR_END)*sizeof(sint16*)));
390    if (!m) nrerror("allocation failure 1 in i16trimatrix()");
391    m += NR_END;
392    m -= nrl;
393   
394   
395    /* allocate rows and set pointers to them */
396    m[nrl]=(int16*) malloc((size_t)((n+NR_END)*sizeof(int16)));
397    if (!m[nrl]) nrerror("allocation failure 2 in i16trimatrix()");
398    m[nrl] += NR_END;
399    m[nrl] -= ncl;
400   
401    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
402   
403    /* return pointer to array of pointers to rows */
404    return m;
405}
406/* --------------------------------------------------------------------------------- */
407IMAGE_EXPORT(uint16**) ui16trimatrix(long nrl, long nrh, long ncl, long nch, long step)
408/* --------------------------------------------------------------------------------- */
409/* allocate an i16 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
410{
411    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
412    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
413    uint16 **m;
414   
415    /* allocate pointers to rows */
416    m=(uint16 **) malloc((size_t)((nrow+NR_END)*sizeof(uint16*)));
417    if (!m) nrerror("allocation failure 1 in ui16trimatrix()");
418    m += NR_END;
419    m -= nrl;
420   
421   
422    /* allocate rows and set pointers to them */
423    m[nrl]=(uint16*) malloc((size_t)((n+NR_END)*sizeof(uint16)));
424    if (!m[nrl]) nrerror("allocation failure 2 in i16trimatrix()");
425    m[nrl] += NR_END;
426    m[nrl] -= ncl;
427   
428    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
429   
430    /* return pointer to array of pointers to rows */
431    return m;
432}
433/* --------------------------------------------------------------------------------- */
434IMAGE_EXPORT(sint32**) si32trimatrix(long nrl, long nrh, long ncl, long nch, long step)
435/* --------------------------------------------------------------------------------- */
436/* allocate an i32 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
437{
438    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
439    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
440    sint32 **m;
441   
442    /* allocate pointers to rows */
443    m=(sint32 **) malloc((size_t)((nrow+NR_END)*sizeof(sint32*)));
444    if (!m) nrerror("allocation failure 1 in si32trimatrix()");
445    m += NR_END;
446    m -= nrl;
447   
448   
449    /* allocate rows and set pointers to them */
450    m[nrl]=(sint32*) malloc((size_t)((n+NR_END)*sizeof(sint32)));
451    if (!m[nrl]) nrerror("allocation failure 2 in si32trimatrix()");
452    m[nrl] += NR_END;
453    m[nrl] -= ncl;
454   
455    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
456   
457    /* return pointer to array of pointers to rows */
458    return m;
459}
460/* -------------------------------------------------------------------------------- */
461IMAGE_EXPORT(uint32**) i32trimatrix(long nrl, long nrh, long ncl, long nch, long step)
462/* -------------------------------------------------------------------------------- */
463/* allocate an i32 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
464{
465    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
466    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
467    uint32 **m;
468   
469    /* allocate pointers to rows */
470    m=(uint32 **) malloc((size_t)((nrow+NR_END)*sizeof(uint32*)));
471    if (!m) nrerror("allocation failure 1 in ui32trimatrix()");
472    m += NR_END;
473    m -= nrl;
474   
475   
476    /* allocate rows and set pointers to them */
477    m[nrl]=(uint32*) malloc((size_t)((n+NR_END)*sizeof(uint32)));
478    if (!m[nrl]) nrerror("allocation failure 2 in i32trimatrix()");
479    m[nrl] += NR_END;
480    m[nrl] -= ncl;
481   
482    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
483   
484    /* return pointer to array of pointers to rows */
485    return m;
486}
487/* --------------------------------------------------------------------------------- */
488IMAGE_EXPORT(float32**) f32trimatrix(long nrl, long nrh, long ncl, long nch, long step)
489/* --------------------------------------------------------------------------------- */
490/* allocate an f32 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
491{
492    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
493    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
494    float32 **m;
495   
496    /* allocate pointers to rows */
497    m=(float32 **) malloc((size_t)((nrow+NR_END)*sizeof(float32*)));
498    if (!m) nrerror("allocation failure 1 in f32trimatrix()");
499    m += NR_END;
500    m -= nrl;
501   
502   
503    /* allocate rows and set pointers to them */
504    m[nrl]=(float32*) malloc((size_t)((n+NR_END)*sizeof(float32)));
505    if (!m[nrl]) nrerror("allocation failure 2 in f32trimatrix()");
506    m[nrl] += NR_END;
507    m[nrl] -= ncl;
508   
509    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
510   
511    /* return pointer to array of pointers to rows */
512    return m;
513}
514/* --------------------------------------------------------------------------------- */
515IMAGE_EXPORT(float64**) f64trimatrix(long nrl, long nrh, long ncl, long nch, long step)
516/* --------------------------------------------------------------------------------- */
517/* allocate an f64 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
518{
519    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
520    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
521    float64 **m;
522   
523    /* allocate pointers to rows */
524    m=(float64 **) malloc((size_t)((nrow+NR_END)*sizeof(float64*)));
525    if (!m) nrerror("allocation failure 1 in f64trimatrix()");
526    m += NR_END;
527    m -= nrl;
528   
529   
530    /* allocate rows and set pointers to them */
531    m[nrl]=(float64*) malloc((size_t)((n+NR_END)*sizeof(float64)));
532    if (!m[nrl]) nrerror("allocation failure 2 in f64trimatrix()");
533    m[nrl] += NR_END;
534    m[nrl] -= ncl;
535   
536    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
537   
538    /* return pointer to array of pointers to rows */
539    return m;
540}
Note: See TracBrowser for help on using the repository browser.