GRASS Programmer's Manual  6.4.2(2012)
imagery/alloc.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <grass/imagery.h>
00004 
00005 
00006 void *I_malloc(size_t n)
00007 {
00008     void *b;
00009 
00010     b = G_malloc(n);
00011 
00012     return b;
00013 }
00014 
00015 
00016 void *I_realloc(void *b, size_t n)
00017 {
00018     b = G_realloc(b, n);
00019 
00020     return b;
00021 }
00022 
00023 
00024 int I_free(void *b)
00025 {
00026     if ((char *)b != NULL)
00027         G_free(b);
00028 
00029     return 0;
00030 }
00031 
00032 
00033 double **I_alloc_double2(int a, int b)
00034 {
00035     double **x;
00036     int i;
00037 
00038     x = (double **)I_malloc((a + 1) * sizeof(double *));
00039 
00040     for (i = 0; i < a; i++) {
00041         int n;
00042 
00043         x[i] = (double *)I_malloc(b * sizeof(double));
00044 
00045         for (n = 0; n < b; n++)
00046             x[i][n] = 0;
00047     }
00048     x[a] = NULL;
00049 
00050     return x;
00051 }
00052 
00053 
00054 int *I_alloc_int(int a)
00055 {
00056     int *x;
00057     int i;
00058 
00059     x = (int *)I_malloc(a * sizeof(int));
00060 
00061     for (i = 0; i < a; i++)
00062         x[i] = 0;
00063 
00064     return x;
00065 }
00066 
00067 int **I_alloc_int2(int a, int b)
00068 {
00069     int **x;
00070     int i, n;
00071 
00072     x = (int **)I_malloc((a + 1) * sizeof(int *));
00073 
00074     for (i = 0; i < a; i++) {
00075         x[i] = (int *)I_malloc(b * sizeof(int));
00076 
00077         for (n = 0; n < b; n++)
00078             x[i][n] = 0;
00079     }
00080     x[a] = NULL;
00081 
00082     return x;
00083 }
00084 
00085 
00086 int I_free_int2(int **x)
00087 {
00088     int i;
00089 
00090     if (x != NULL) {
00091         for (i = 0; x[i] != NULL; i++)
00092             G_free(x[i]);
00093         G_free(x);
00094     }
00095 
00096     return 0;
00097 }
00098 
00099 
00100 int I_free_double2(double **x)
00101 {
00102     int i;
00103 
00104     if (x != NULL) {
00105         for (i = 0; x[i] != NULL; i++)
00106             G_free(x[i]);
00107         G_free(x);
00108     }
00109 
00110     return 0;
00111 }
00112 
00113 
00114 double ***I_alloc_double3(int a, int b, int c)
00115 {
00116     double ***x;
00117     int i, n;
00118 
00119     x = (double ***)G_malloc((a + 1) * sizeof(double **));
00120 
00121     for (i = 0; i < a; i++) {
00122         x[i] = I_alloc_double2(b, c);
00123         if (x[i] == NULL) {
00124             for (n = 0; n < i; n++)
00125                 G_free(x[n]);
00126             G_free(x);
00127 
00128             return (double ***)NULL;
00129         }
00130     }
00131     x[a] = NULL;
00132 
00133     return x;
00134 }
00135 
00136 
00137 int I_free_double3(double ***x)
00138 {
00139     int i;
00140 
00141     if (x != NULL) {
00142         for (i = 0; x[i] != NULL; i++)
00143             I_free_double2(x[i]);
00144         G_free(x);
00145     }
00146 
00147     return 0;
00148 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines