Merge ../libgpiv-omp into fft-omp
[libgpiv.git] / lib / utils_alloc.c
blob7730f42e616c86ab27be945e895aa442b37288f3
1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 c-style: "K&R" -*- */
3 /*
4 libgpiv - library for Particle Image Velocimetry
6 Copyright (C) 2007, 2008 Gerber van der Graaf
8 This file is part of libgpiv.
9 Libgpiv is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software Foundation,
21 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 -------------------------------------------------------------------------------
26 FILENAME: l_utils.c
27 LIBRARY: libgpiv:
28 EXTERNAL FUNCTIONS:
32 LAST MODIFICATION DATE: $Id: utils_alloc.c,v 1.3 2008-09-25 13:19:53 gerber Exp $
33 --------------------------------------------------------------------------- */
35 #include <gpiv.h>
37 #define GPIV_END 1 /* Used by vector */
42 gfloat **
43 gpiv_matrix (long nr,
44 long nc
46 /*-----------------------------------------------------------------------------
47 * DESCRIPTION:
48 * Allocates memory for 2-dimensional matrix of gfloat data
50 *---------------------------------------------------------------------------*/
52 long i;
53 gfloat **m;
56 m = (gfloat **) g_malloc0 (nr * sizeof (gfloat *));
57 m[0] = (gfloat *) g_malloc0 (nr * nc * sizeof (gfloat));
58 for (i = 1; i < nr; i++) {
59 m[i] = m[0] + i * nc;
63 return m;
68 void
69 gpiv_free_matrix (gfloat **m
71 /*-----------------------------------------------------------------------------
72 * DESCRIPTION:
73 * Frees memory for 2-dimensional array of float data
75 *---------------------------------------------------------------------------*/
77 g_return_if_fail (m[0] != NULL); /* gpiv_error ("m not allocated"); */
78 g_free (m[0]);
79 g_free (m);
80 m = NULL;
85 gfloat **
86 gpiv_matrix_index (const long nrl,
87 const long nrh,
88 const long ncl,
89 const long nch
91 /*-----------------------------------------------------------------------------
92 * DESCRIPTION:
93 * Allocates memory for 2-dimensional matrix of float data
94 * with subscript range v[nrl..nrh][ncl..nch]
96 * INPUTS:
97 * long nrl: lowest row index number
98 * nrh: highest row index number
99 * ncl: lowest column index number
100 * nch highest column index number
102 * OUTPUTS:
104 * RETURNS:
105 * 2-dimensional array
106 *---------------------------------------------------------------------------*/
108 long i, nrows = nrh - nrl + 1, ncolumns = nch - ncl + 1;
109 gfloat **m;
112 m = (gfloat **) g_malloc0 ((size_t) ((nrows + GPIV_END) *
113 sizeof (gfloat *)));
114 if (!m) gpiv_error ("gpiv_matrix_index: allocation failure");
115 m += GPIV_END;
116 m -= nrl;
118 m[nrl] =(gfloat *) g_malloc0 ((size_t) ((nrows * ncolumns + GPIV_END) *
119 sizeof (gfloat)));
120 if (!m[nrl]) gpiv_error ("gpiv_matrix_index: allocation failure");
121 m[nrl] += GPIV_END;
122 m[nrl] -= ncl;
124 for (i=nrl+1; i <= nrh; i++) {
125 m[i] = m[i-1] + ncolumns;
129 return m;
134 void
135 gpiv_free_matrix_index (gfloat **m,
136 const long nrl,
137 const long nrh,
138 const long ncl,
139 const long nch
141 /*-----------------------------------------------------------------------------
142 * DESCRIPTION:
143 * Frees memory for 2-dimensional array of float data
144 * with subscript range v[nrl..nrh][ncl..nch]
146 * INPUTS:
147 * m: matrix
148 * nrl: lowest row index number
149 * long nrh: highest row index number
150 * long ncl: lowest column index number
151 * long nch: highest column index number
153 * OUTPUTS:
154 * m: NULL pointer
156 * RETURNS:
157 *---------------------------------------------------------------------------*/
159 g_return_if_fail (m[0] != NULL); /* gpiv_error ("m not allocated"); */
160 g_free (m[nrl]+ncl-GPIV_END);
161 g_free (m+nrl-GPIV_END);
162 m = NULL;
167 guchar **
168 gpiv_ucmatrix (const long nr,
169 const long nc
171 /*-----------------------------------------------------------------------------
172 * DESCRIPTION:
173 * Allocates memory for 2-dimensional matrix of guchar data
175 * INPUTS:
176 * nr: row index
177 * nc: column index
179 * OUTPUTS:
181 * RETURNS:
182 * matrix
183 *---------------------------------------------------------------------------*/
185 long i;
186 guchar **m;
189 m = (guchar **) g_malloc0 (nr * sizeof (guchar*));
190 m[0] = (guchar *) g_malloc0 (nr * nc * sizeof (guchar));
191 for (i = 1; i < nr; i++) {
192 m[i] = m[0] + i * nc;
196 return m;
201 void
202 gpiv_free_ucmatrix (guchar **m
204 /*-----------------------------------------------------------------------------
205 * DESCRIPTION:
206 * Frees memory for 2-dimensional array of guchar data
208 * INPUTS:
209 * m: matrix
211 * OUTPUTS:
213 * RETURNS:
214 * m: NULL pointer
215 *---------------------------------------------------------------------------*/
217 g_return_if_fail (m[0] != NULL); /* gpiv_error ("m not allocated"); */
218 g_free (m[0]);
219 g_free (m);
220 m = NULL;
225 guint8 **
226 gpiv_matrix_guint8 (const long nr,
227 const long nc
229 /*-----------------------------------------------------------------------------
230 * DESCRIPTION:
231 * allocate a guint8 matrix with subscript range m[0..nr][0..nc]
233 * INPUTS:
234 * nr: number of rows
235 * nc: number of columns
237 * OUTPUTS:
239 * RETURNS:
240 * matrix
241 *---------------------------------------------------------------------------*/
243 long i;
244 guint8 **m;
247 m = (guint8 **) g_malloc0 (nr * sizeof (guint8*));
248 m[0] = (guint8 *) g_malloc0 (nr * nc * sizeof (guint8));
249 for (i = 1; i < nr; i++) {
250 m[i] = m[0] + i * nc;
254 return m;
259 void
260 gpiv_free_matrix_guint8 (guint8 **m
262 /*-----------------------------------------------------------------------------
263 * DESCRIPTION:
264 * free a guint8 matrix allocated by gpiv_matrix_guint8
266 * INPUTS:
267 * m: matrix
269 * OUTPUTS:
270 * m: NULL pointer
272 * RETURNS:
273 *---------------------------------------------------------------------------*/
275 g_return_if_fail (m[0] != NULL); /* gpiv_error ("m not allocated"); */
276 g_free (m[0]);
277 g_free (m);
278 m = NULL;
283 guint16 **
284 gpiv_matrix_guint16 (const long nr,
285 const long nc
287 /*-----------------------------------------------------------------------------
288 * DESCRIPTION:
289 * allocate a guint16 matrix with subscript range m[0..nr][0..nc]
291 * INPUTS:
292 * nr: number of rows
293 * nc: number of columns
295 * OUTPUTS:
297 * RETURNS:
298 * matrix
299 *---------------------------------------------------------------------------*/
301 long i;
302 guint16 **m;
305 m = (guint16 **) g_malloc0 (nr * sizeof (guint16*));
306 m[0] = (guint16 *) g_malloc0 (nr * nc * sizeof (guint16));
307 for (i = 1; i < nr; i++) {
308 m[i] = m[0] + i * nc;
312 return m;
317 void
318 gpiv_free_matrix_guint16 (guint16 **m
320 /*-----------------------------------------------------------------------------
321 * DESCRIPTION:
322 * free a guint16 matrix allocated by gpiv_matrix_guint16
324 * INPUTS:
325 * m: matrix
327 * OUTPUTS:
328 * m: NULL pointer
330 * RETURNS:
331 *---------------------------------------------------------------------------*/
333 g_return_if_fail (m[0] != NULL); /* gpiv_error ("m not allocated"); */
334 g_free (m[0]);
335 g_free (m);
336 m = NULL;
341 gint **
342 gpiv_imatrix_index (const long nrl,
343 const long nrh,
344 const long ncl,
345 const long nch
347 /*-----------------------------------------------------------------------------
348 * DESCRIPTION:
349 * Allocates memory for 2-dimensional matrix of integer data
350 * with subscript range v[nrl..nrh][ncl..nch]
352 * INPUTS:
353 * m: matrix
354 * nrl: lowest row index number
355 * nrh: highest row index number
356 * ncl: lowest column index number
357 * nch: highest column index number
359 * OUTPUTS:
361 * RETURNS:
362 * matrix
363 *---------------------------------------------------------------------------*/
365 long i, nrows = nrh - nrl + 1, ncolumns = nch - ncl + 1;
366 gint **m;
369 m = (gint **) g_malloc0 ((size_t) ((nrows + GPIV_END)*
370 sizeof (gint*)));
371 m += GPIV_END;
372 m -= nrl;
373 m[nrl] = (gint *) g_malloc0 ((size_t) ((nrows * ncolumns + GPIV_END)*
374 sizeof (gint)));
375 m[nrl] += GPIV_END;
376 m[nrl] -= ncl;
378 for (i = nrl + 1; i <= nrh; i++) {
379 m[i] = m[i-1] + ncolumns;
383 return m;
388 void
389 gpiv_free_imatrix_index (gint **m,
390 const long nrl,
391 const long nrh,
392 const long ncl,
393 const long nch
395 /*-----------------------------------------------------------------------------
396 * DESCRIPTION:
397 * Frees memory for 2-dimensional array of integer data
398 * with subscript range v[nrl..nrh][ncl..nch]
400 * INPUTS:
401 * m: matrix
402 * nrl: lowest row index number
403 * nrh: highest row index number
404 * ncl: lowest column index number
405 * nch: highest column index number
407 * OUTPUTS:
408 * m: NULL pointer
410 * RETURNS:
411 *---------------------------------------------------------------------------*/
413 g_return_if_fail (m[0] != NULL); /* gpiv_error ("m not allocated"); */
414 g_free (m[nrl]+ncl - GPIV_END);
415 g_free (m+nrl - GPIV_END);
416 m = NULL;
421 gint **
422 gpiv_imatrix (const long nr,
423 const long nc)
425 /*-----------------------------------------------------------------------------
426 * DESCRIPTION:
427 * Allocates memory for 2-dimensional matrix of integer data
428 * unappreciated, use gpiv_imatrix_index instead
430 * INPUTS:
431 * nr: lowest row index number
432 * nc: lowest column index number
434 * OUTPUTS:
436 * RETURNS:
437 * matrix
438 *---------------------------------------------------------------------------*/
440 long i;
441 gint **m;
444 m = (gint **) g_malloc0 (nr * sizeof (gint*));
445 m[0] = (gint *) g_malloc0 (nr * nc * sizeof (gint));
446 for (i = 1; i < nr; i++) {
447 m[i] = m[0] + i * nc;
451 return m;
456 void
457 gpiv_free_imatrix (gint **m
459 /*-----------------------------------------------------------------------------
460 * DESCRIPTION:
461 * Frees memory for 2-dimensional array of integer data
462 * unappreciated, use gpiv_free_imatrix_index instead
464 * INPUTS:
465 * m: matrix
467 * OUTPUTS:
468 * m: NULL pointer
470 * RETURNS:
471 *---------------------------------------------------------------------------*/
473 g_return_if_fail (m[0] != NULL); /* gpiv_error ("m not allocated"); */
474 g_free (m[0]);
475 g_free (m);
476 m = NULL;
481 double **
482 gpiv_double_matrix (const glong nr,
483 const glong nc
485 /*-----------------------------------------------------------------------------
486 * DESCRIPTION:
487 * allocate a contiguous 2-dimensional double matrix
488 * of nr x nc
490 * INPUTS:
491 * nr: number of rows
492 * nc: number of columns
494 * OUTPUTS:
496 * RETURNS:
497 * matrix
498 *---------------------------------------------------------------------------*/
500 double **m;
501 gint i;
504 m = (double **) g_malloc0 (nr * sizeof (double *));
505 m[0] = (double *) g_malloc0 (nr * nc * sizeof (double));
506 for (i = 1; i < nr; i++) {
507 m[i] = m[0] + i * nc;
511 return m;
516 void
517 gpiv_free_double_matrix (double **m
519 /*-----------------------------------------------------------------------------
520 * DESCRIPTION:
521 * free a double matrix allocated by gpiv_double_matrix()
523 * INPUTS:
524 * m: matrix
526 * OUTPUTS:
527 * m: NULL pointer
529 * RETURNS:
530 *---------------------------------------------------------------------------*/
532 g_return_if_fail (m[0] != NULL); /* gpiv_error ("m not allocated"); */
533 g_free (m[0]);
534 g_free (m);
535 m = NULL;
539 #ifndef USE_FFTW3
540 fftw_real **
541 gpiv_fftw_real_matrix (glong nr,
542 glong nc
544 /*-----------------------------------------------------------------------------
545 * DESCRIPTION:
546 * allocate a contiguous 2-dimensional fftw_real matrix
547 * of nr x nc
549 * INPUTS:
550 * nr: number of rows
551 * nc: number of columns
553 * OUTPUTS:
555 * RETURNS:
556 * matrix
557 *---------------------------------------------------------------------------*/
559 fftw_real **m;
560 gint i;
563 m = (fftw_real **) g_malloc0 (nr * sizeof (fftw_real *));
564 m[0] = (fftw_real *) g_malloc0 (nr * nc * sizeof (fftw_real));
565 for (i = 1; i < nr; i++) {
566 m[i] = m[0] + i * nc;
570 return m;
575 void
576 gpiv_free_fftw_real_matrix (fftw_real **m
578 /*-----------------------------------------------------------------------------
579 * DESCRIPTION:
580 * free a gdouble matrix allocated by gpiv_fftw_real_matrix()
582 * INPUTS:
583 * m: matrix
585 * OUTPUTS:
586 * m: NULL pointer
588 * RETURNS:
589 *---------------------------------------------------------------------------*/
591 g_return_if_fail (m[0] != NULL); /* gpiv_error ("m not allocated"); */
592 g_free (m[0]);
593 g_free (m);
594 m = NULL;
596 #endif /* USE_FFTW3 */
600 fftw_complex **
601 gpiv_fftw_complex_matrix (const long nr,
602 const long nc
604 /*-----------------------------------------------------------------------------
605 * DESCRIPTION:
606 * allocate a contiguous 2-dimensional fftw_complex matrix
607 * of nr x nc
609 * INPUTS:
610 * nr: number of rows
611 * nc: number of columns
613 * OUTPUTS:
615 * RETURNS:
616 * matrix
617 *---------------------------------------------------------------------------*/
619 fftw_complex **m;
620 gint i;
624 * allocate pointers to rows
626 m = (fftw_complex **) fftw_malloc (nr * sizeof (fftw_complex *));
627 m[0] = (fftw_complex *) fftw_malloc (nr * nc * sizeof (fftw_complex));
628 for (i = 1; i < nr; i++) {
629 m[i] = m[0] + i * nc;
633 return m;
638 void
639 gpiv_free_fftw_complex_matrix (fftw_complex **m
641 /*-----------------------------------------------------------------------------
642 * DESCRIPTION:
643 * free a fftw_complex matrix allocated by gpiv_fftw_complex_matrix()
645 * INPUTS:
646 * m: matrix
648 * OUTPUTS:
649 * m: NULL pointer
651 * RETURNS:
652 *---------------------------------------------------------------------------*/
654 g_return_if_fail (m[0] != NULL); /* gpiv_error ("m not allocated"); */
655 fftw_free (m[0]);
656 fftw_free (m);
657 m = NULL;
662 float *
663 gpiv_vector (const long nl
665 /*-----------------------------------------------------------------------------
666 * DESCRIPTION:
667 * Allocates memory for a 1-dimensional vector of float data
669 * INPUTS:
670 * nl: vector length
672 * OUTPUTS:
674 * RETURNS:
675 * vector
676 *---------------------------------------------------------------------------*/
678 float *v;
681 v = (float *)g_malloc0 ((size_t) (nl * sizeof (float)));
682 /* v = (float *)g_malloc0 (gsize * nl * sizeof (float))); */
685 return v;
690 void
691 gpiv_free_vector (float *v
693 /*-----------------------------------------------------------------------------
694 * DESCRIPTION:
695 * frees memory for a 1-dimensional vector of float data
697 * INPUTS:
698 * vector: vector of 1-dimensional float data
700 * OUTPUTS:
701 * vector: NULL pointer
703 * RETURNS:
704 *---------------------------------------------------------------------------*/
706 g_return_if_fail (v != NULL); /* gpiv_error ("v not allocated"); */
707 g_free (v);
708 v = NULL;
713 float *
714 gpiv_vector_index (const long nl,
715 const long nh
717 /*-----------------------------------------------------------------------------
718 * DESCRIPTION:
719 * Allocates memory for a 1-dimensional vector of float data
720 * with subscript range v[nl..nh]
722 * INPUTS:
723 * nl: lowest index number
724 * nh: highest index number
726 * OUTPUTS:
728 * RETURNS:
729 * vector
730 *---------------------------------------------------------------------------*/
732 float *v;
734 v = (float *)g_malloc0 ((size_t) ((nh + 1 - nl + GPIV_END)
735 * sizeof (float)));
738 return v - nl;
743 void
744 gpiv_free_vector_index (float *v,
745 const long nl,
746 const long nh
748 /*-----------------------------------------------------------------------------
749 * DESCRIPTION:
750 * frees memory for a 1-dimensional vector of float data
751 * with subscript range v[nrl..nrh][ncl..nch]
753 * INPUTS:
754 * vector: vector of 1-dimensional float data
755 * nl: lowest index number
756 * nh: highest index number
758 * OUTPUTS:
759 * vector: NULL pointer
761 * RETURNS:
762 *---------------------------------------------------------------------------*/
764 g_return_if_fail (v != NULL); /* gpiv_error ("v not allocated"); */
765 g_free (v + nl);
766 v = NULL;
771 gdouble *
772 gpiv_dvector (const glong nl
774 /*-----------------------------------------------------------------------------
775 * DESCRIPTION:
776 * Allocates memory for a 1-dimensional vector of double data
778 * INPUTS:
779 * nl: vector length
781 * OUTPUTS:
783 * RETURNS:
784 * vector
785 *---------------------------------------------------------------------------*/
787 gdouble *v;
790 v = (gdouble *)g_malloc0 ((size_t) (nl * sizeof (gdouble)));
793 return v;
798 void
799 gpiv_free_dvector (gdouble *v
801 /*-----------------------------------------------------------------------------
802 * DESCRIPTION:
803 * frees memory for a 1-dimensional vector of double data
805 * INPUTS:
806 * vector: vector of 1-dimensional float data
808 * OUTPUTS:
809 * vector: NULL pointer
811 * RETURNS:
812 *---------------------------------------------------------------------------*/
814 g_return_if_fail (v != NULL); /* gpiv_error ("v not allocated"); */
815 g_free (v);
816 v = NULL;
821 gdouble *
822 gpiv_dvector_index (const long nl,
823 const long nh
825 /*-----------------------------------------------------------------------------
826 * DESCRIPTION:
827 * Allocates memory for a 1-dimensional vector of double data
828 * with subscript range v[nl..nh]
830 * INPUTS:
831 * nl: lowest index number
832 * nh: highest index number
834 * OUTPUTS:
836 * RETURNS:
837 * vector
838 *---------------------------------------------------------------------------*/
840 gdouble *v;
843 v = (gdouble *)g_malloc0 ((size_t) ((nh + 1 -nl + GPIV_END) *
844 sizeof (gdouble)));
847 return v - nl;
852 void
853 gpiv_free_dvector_index (gdouble *v,
854 const long nl,
855 const long nh
857 /*-----------------------------------------------------------------------------
858 * DESCRIPTION:
859 * frees memory for a 1-dimensional vector of double data
860 * with subscript range v[nrl..nrh][ncl..nch]
862 * INPUTS:
863 * vector: vector of 1-dimensional float data
864 * nl: lowest index number
865 * nh: highest index number
867 * OUTPUTS:
868 * vector: NULL pointer
870 * RETURNS:
871 *---------------------------------------------------------------------------*/
873 g_return_if_fail (v != NULL); /* gpiv_error ("v not allocated"); */
874 g_free (v + nl);
875 v = NULL;
880 long *
881 gpiv_nulvector (const long nl
883 /*-----------------------------------------------------------------------------
884 * DESCRIPTION:
885 * Allocates memory for a 1-dimensional vector of long data
887 * INPUTS:
888 * nl: vector length
890 * OUTPUTS:
892 * RETURNS:
893 * vector
894 *---------------------------------------------------------------------------*/
896 long *v;
899 v = (long *)g_malloc0 ((size_t) (nl * sizeof (long)));
902 return v;
907 void
908 gpiv_free_nulvector (long *v
910 /*-----------------------------------------------------------------------------
911 * DESCRIPTION:
912 * frees memory for a 1-dimensional vector of long data
914 * INPUTS:
915 * vector: vector of 1-dimensional float data
917 * OUTPUTS:
918 * vector: NULL pointer
920 * RETURNS:
921 *---------------------------------------------------------------------------*/
923 g_return_if_fail (v != NULL); /* gpiv_error ("v not allocated"); */
924 g_free (v);
925 v = NULL;
930 long *
931 gpiv_nulvector_index (const long nl,
932 const long nh
934 /*-----------------------------------------------------------------------------
935 * DESCRIPTION:
936 * Allocates memory for a 1-dimensional vector of long data
937 * with subscript range v[nl..nh]
939 * INPUTS:
940 * nl: lowest index number
941 * nh: highest index number
943 * OUTPUTS:
945 * RETURNS:
946 * vector
947 *---------------------------------------------------------------------------*/
949 long *v;
952 v = (long *)g_malloc0 ((size_t) ((nh + 1 - nl + GPIV_END) *
953 sizeof (long)));
956 return v - nl;
961 void
962 gpiv_free_nulvector_index (long *v,
963 const long nl,
964 const long nh)
965 /*-----------------------------------------------------------------------------
966 * DESCRIPTION:
967 * frees memory for a 1-dimensional vector of long data
968 * with subscript range v[nrl..nrh][ncl..nch]
970 * INPUTS:
971 * vector: vector of 1-dimensional float data
972 * nl: lowest index number
973 * nh: highest index number
975 * OUTPUTS:
976 * vector: NULL pointer
978 * RETURNS:
979 *---------------------------------------------------------------------------*/
981 g_return_if_fail (v != NULL); /* gpiv_error ("v not allocated"); */
982 g_free (v + nl);
983 v = NULL;
988 unsigned long *
989 gpiv_ulvector (const long nl
991 /*-----------------------------------------------------------------------------
992 * DESCRIPTION:
993 * Allocates memory for a 1-dimensional vector of unsigned long data
995 * INPUTS:
996 * nl: vector length
998 * OUTPUTS:
1000 * RETURNS:
1001 * vector
1002 *---------------------------------------------------------------------------*/
1004 unsigned long *v;
1007 v = (unsigned long *)g_malloc0 ((size_t) (nl * sizeof (long)));
1008 if (!v); gpiv_error ("gpiv_ulvector: allocation failure");
1011 return v;
1016 void
1017 gpiv_free_ulvector (unsigned long *v
1019 /*-----------------------------------------------------------------------------
1020 * DESCRIPTION:
1021 * frees memory for a 1-dimensional vector of unsigned long data
1023 * INPUTS:
1024 * vector: vector of 1-dimensional float data
1026 * OUTPUTS:
1027 * vector: NULL pointer
1029 * RETURNS:
1030 *---------------------------------------------------------------------------*/
1032 g_return_if_fail (v != NULL); /* gpiv_error ("v not allocated"); */
1033 g_free (v);
1034 v = NULL;
1039 unsigned long *
1040 gpiv_ulvector_index (const long nl,
1041 const long nh
1043 /*-----------------------------------------------------------------------------
1044 * DESCRIPTION:
1045 * Allocates memory for a 1-dimensional vector of unsigned long data
1046 * with subscript range v[nl..nh]
1048 * INPUTS:
1049 * nl: lowest index number
1050 * nh: highest index number
1052 * OUTPUTS:
1054 * RETURNS:
1055 * vector
1056 *---------------------------------------------------------------------------*/
1058 unsigned long *v;
1061 v = (unsigned long *)g_malloc0 ((size_t) ((nh + 1 - nl + GPIV_END) *
1062 sizeof (long)));
1063 if (!v); gpiv_error ("gpiv_ulvector_index: allocation failure");
1066 return v - nl;
1071 void
1072 gpiv_free_ulvector_index (unsigned long *v,
1073 const long nl,
1074 const long nh
1076 /*-----------------------------------------------------------------------------
1077 * DESCRIPTION:
1078 * frees memory for a 1-dimensional vector of unsigned long data
1079 * with subscript range v[nrl..nrh][ncl..nch]
1081 * INPUTS:
1082 * vector: vector of 1-dimensional float data
1083 * nl: lowest index number
1084 * nh: highest index number
1086 * OUTPUTS:
1087 * vector: NULL pointer
1089 * RETURNS:
1090 *---------------------------------------------------------------------------*/
1092 g_return_if_fail (v != NULL); /* gpiv_error ("v not allocated"); */
1093 g_free (v + nl);
1094 v = NULL;
1099 gint *
1100 gpiv_ivector (const long nl
1102 /*-----------------------------------------------------------------------------
1103 * DESCRIPTION:
1104 * Allocates memory for a 1-dimensional vector of integer data
1106 * INPUTS:
1107 * nl: vector length
1109 * OUTPUTS:
1111 * RETURNS:
1112 * vector
1113 *---------------------------------------------------------------------------*/
1115 gint *v;
1118 v = (gint *) g_malloc0 ((size_t) (nl * sizeof (gint)));
1119 if (!v) gpiv_error ("gpiv_ivector: allocation failure");
1122 return v;
1127 void
1128 gpiv_free_ivector (gint *v
1130 /*-----------------------------------------------------------------------------
1131 * DESCRIPTION:
1132 * frees memory for a 1-dimensional vector of integer data
1134 * INPUTS:
1135 * vector: vector of 1-dimensional float data
1137 * OUTPUTS:
1138 * vector: NULL pointer
1140 * RETURNS:
1141 *---------------------------------------------------------------------------*/
1143 g_return_if_fail (v != NULL); /* gpiv_error ("v not allocated"); */
1144 g_free (v);
1145 v = NULL;
1150 gint *
1151 gpiv_ivector_index (const long nl,
1152 const long nh
1154 /*-----------------------------------------------------------------------------
1155 * DESCRIPTION:
1156 * Allocates memory for a 1-dimensional vector of integer data
1157 * with subscript range v[nl..nh]
1159 * INPUTS:
1160 * nl: lowest index number
1161 * nh: highest index number
1163 * OUTPUTS:
1165 * RETURNS:
1166 * vector
1167 *---------------------------------------------------------------------------*/
1169 gint *v;
1172 v = (gint *)g_malloc0 ((size_t) ((nh + 1 - nl + GPIV_END)*sizeof (gint)));
1173 if (!v) gpiv_error ("gpiv_ivector_index: allocation failure");
1176 return v - nl;
1181 void
1182 gpiv_free_ivector_index (gint *v,
1183 const long nl,
1184 const long nh
1186 /*-----------------------------------------------------------------------------
1187 * DESCRIPTION:
1188 * frees memory for a 1-dimensional vector of integer data
1189 * with subscript range v[nrl..nrh][ncl..nch]
1191 * INPUTS:
1192 * vector: vector of 1-dimensional float data
1193 * nl: lowest index number
1194 * nh: highest index number
1196 * OUTPUTS:
1197 * vector: NULL pointer
1199 * RETURNS:
1200 *---------------------------------------------------------------------------*/
1202 g_return_if_fail (v != NULL); /* gpiv_error ("v not allocated"); */
1203 g_free (v + nl);
1204 v = NULL;
1209 gboolean *
1210 gpiv_gbolvector (const glong nl
1212 /*-----------------------------------------------------------------------------
1213 * DESCRIPTION:
1214 * Allocates memory for a 1-dimensional vector of gboolean data
1216 * INPUTS:
1217 * nl: vector length
1219 * OUTPUTS:
1221 * RETURNS:
1222 * vector
1223 *---------------------------------------------------------------------------*/
1225 gboolean *v;
1228 v = (gboolean *)g_malloc0 ((size_t) (nl * sizeof (gboolean)));
1231 return v;
1236 void
1237 gpiv_free_gbolvector (gboolean *v
1239 /*-----------------------------------------------------------------------------
1240 * DESCRIPTION:
1241 * frees memory for a 1-dimensional vector of gboolean data
1243 * INPUTS:
1244 * vector: vector of 1-dimensional boolean data
1246 * OUTPUTS:
1247 * vector: NULL pointer
1249 * RETURNS:
1250 *---------------------------------------------------------------------------*/
1252 g_return_if_fail (v != NULL); /* gpiv_error ("v not allocated"); */
1253 g_free (v);
1254 v = NULL;
1259 #undef GPIV_END