/**************************************************************************************** * free_array.c * * WRITTEN BY DANIEL GOTTAS OF THE METEOROLOGICAL APPLICATIONS * * AND ASSESSMENT DIVISION OF NOAA'S ENVIRONMENTAL TECHNOLOGY LAB * * (released on 3/6/95) * * * * Free_array frees memory allocated by dynamic_array using free. * * * * INCLUDE: * * #include "array4d.h" * * * * SYNTAX: * * void free_array(int DIM1,int DIM2,int DIM3,int DIM4,void *POINTER) * * * * INPUT: * * DIM1 = number of elements in the 1st dimension of the array * * DIM2 = number of elements in the 2nd dimension of the array * * DIM3 = number of elements in the 3rd dimension of the array * * DIM4 = number of elements in the 4th dimension of the array * * POINTER = a single pointer storing the first address of the * * memory block to be freed. * * * * OUTPUT: * * none * * * * USAGE: * * Pass free_array the size of all four dimensions (substituting zeros * * for those dimensions not used) and the starting address of the memory * * block to be freed. For example, to free memory for the 4D double floating * * point array data[i][j][k][l], call freee_array as follows: * * "free_array(i,j,k,l,(double *)data)". * * * ****************************************************************************************/ #include #include "array4d.h" void free_array(int i,int j,int k,int l,void *start_address) { int x=0,y=0,z=0; union p_vars point; int dim_cnt=0; if(i) dim_cnt++; // if i is non zero step count if(j) dim_cnt++; // if j is non zero step count if(k) dim_cnt++; // if k is non zero step count if(l) dim_cnt++; // if l is non zero step count if(dim_cnt==1) // free 1D pointers { point.dim1=(void *)start_address; free(point.dim1); } if(dim_cnt==2) // free 2D pointers { point.dim2=(void **)start_address; for(x=0;x