Changeset 7606 for trunk/projects/slim-curve/src/main/c/EcfUtil.c
- Timestamp:
- 01/28/11 14:37:06 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/projects/slim-curve/src/main/c/EcfUtil.c
r7594 r7606 206 206 207 207 ARRAY ALLOCATION ROUTINES 208 208 http://www.nr.com/public-domain.html 209 209 *********************************************************************/ 210 210 … … 217 217 int data_size = nrows * ncols * sizeof(float); 218 218 unsigned char *raw = malloc(row_size + data_size); 219 if (NULL == raw) 219 float **row = (float **) raw; 220 float *data = (float *) (row + nrows); 221 int i; 222 223 if (NULL == raw) 220 224 { 221 225 return NULL; 222 226 } 223 float **row = (float **) raw; 224 float *data = (float *) (row + nrows); 225 int i; 226 for (i = 0; i < nrows; ++i) 227 228 for (i = 0; i < nrows; ++i) 227 229 { 228 230 row[i] = data; … … 242 244 } 243 245 246 float ***GCI_ecf_matrix_array(long nblocks, long nrows, long ncols) 247 /* allocate a float matrix array with range 248 marr[0..nblocks][0..nrows][0..ncols] */ 249 { 250 long i; 251 float ***marr; 252 253 /* allocate pointers to blocks */ 254 if ((marr = (float ***) malloc(nblocks * sizeof(float **))) == NULL) 255 return NULL; 256 257 /* allocate blocks (= pointers to rows) and set pointers to them */ 258 if ((marr[0] = (float **) malloc(nblocks * nrows * sizeof(float *))) 259 == NULL) { 260 free(marr); 261 return NULL; 262 } 263 264 for (i=1; i<nblocks; i++) 265 marr[i] = marr[i-1] + nrows; 266 267 /* allocate rows (= pointers to column entries) and set pointers to them */ 268 if ((marr[0][0] = (float *)malloc(nblocks * nrows * ncols * sizeof(float))) 269 == NULL) { 270 free(marr[0]); 271 free(marr); 272 return NULL; 273 } 274 275 /* This sneaky loop does the whole lot! For note that 276 marr[block][row] = marr[0][block*nrows + row] */ 277 for (i=1; i < nblocks * nrows; i++) 278 marr[0][i] = marr[0][i-1] + ncols; 279 280 return marr; 281 } 282 283 284 void GCI_ecf_free_matrix_array(float ***marr) 285 { 286 if (marr != NULL) { 287 free(marr[0][0]); 288 free(marr[0]); 289 free(marr); 290 } 291 } 244 292 245 293 /********************************************************************
Note: See TracChangeset
for help on using the changeset viewer.