/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/hydrotrend/hydroalloc_mem.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <unistd.h>
00004 #include "hydroalloc_mem.h"
00005 
00006 /*      FUNCTION ALLOCATE_1D FILE */
00007 FILE **allocate_1d_F(int nrows){
00008         FILE **i;
00009 
00010         i=(FILE**)malloc(nrows*sizeof(FILE*));
00011         if (!i){
00012                 perror("allocate_1d_F");
00013                 exit(-1);
00014         }
00015         return i;
00016 }
00017 
00018 
00019 /************************************************/
00020 /***...for allocating a 1D "matrix" of whatever!***/
00021 /*NOTE: I'll need to typecast the result of this to whatever
00022   is being turned into a matrix.  e.g., double, struct, etc!*/
00023 
00024 /* note that sizeof(void*) is the same as sizeof(double*) is the 
00025    same as sizeof(float*), etc.  A pointer always has the same 
00026    size (the size of the memory address.) */
00027    
00028 void* matrixalloc1D(int max_width, long size)
00029 {
00030    
00031    void *atemp;
00032 
00033    atemp = (void *) malloc( max_width*size );
00034    if ( !atemp ) {
00035       perror("matrixalloc_1");
00036       sleep(5);
00037       exit(1);
00038    }
00039            
00040    return atemp;
00041 }
00042 
00043 
00044 /************************************************/
00045 /***...for allocating a 2D matrix of whatever!***/
00046 /*NOTE: I'll need to typecast the result of this to whatever
00047   is being turned into a matrix.  e.g., double, struct, etc!*/
00048 
00049 /* note that sizeof(void*) is the same as sizeof(double*) is the 
00050    same as sizeof(float*), etc.  A pointer always has the same 
00051    size (the size of the memory address.) */
00052    
00053 void** matrixalloc2D(int max_width, int max_length, long size)
00054 {
00055    int i;
00056    
00057    void **atemp;
00058 
00059    atemp = (void **) malloc( max_width*sizeof(void*) );
00060    if ( !atemp ) {
00061       perror("matrixalloc_2");
00062       sleep(5);
00063       exit(1);
00064    }
00065    
00066    for(i=0; i<max_width; ++i) {
00067       atemp[i] = (void *) malloc( max_length*size );
00068       if ( !atemp[i] ) {
00069          perror("matrixalloc_3");
00070          sleep(5);
00071          exit(1);
00072       }
00073    }
00074          
00075    return atemp;
00076 }
00077   
00078 /************************************************/
00079 /***...for allocating a 3D matrix of whatever!***/
00080 /*NOTE: I'll need to typecast the result of this to whatever
00081   is being turned into a matrix.  e.g., double, struct, etc!*/
00082 
00083 void*** matrixalloc3D(int max_width, int max_length, int max_height, long size)
00084 {
00085    int i, j;
00086    
00087    void ***atemp;
00088 
00089    atemp = (void ***) malloc( max_width*sizeof(void*) );
00090    if ( !atemp ) {
00091       perror("matrixalloc_4");
00092       sleep(5);
00093       exit(1);
00094    }
00095    
00096    for(i=0; i<max_width; ++i) {
00097       atemp[i] = (void **) malloc( max_length*sizeof(void*) );
00098       if ( !atemp[i] ) {
00099          perror("matrixalloc_5");
00100          sleep(5);
00101          exit(1);
00102       }
00103    }
00104 
00105    for(i=0; i<max_width; ++i)
00106       for(j=0; j<max_length; ++j) {
00107          atemp[i][j] = (void *) malloc( max_height*size );
00108          if ( !atemp[i][j] ) {
00109             perror("matrixalloc_6");
00110             sleep(5);
00111             exit(1);
00112          }
00113    }         
00114    return atemp;
00115 }

Generated on Fri Jan 4 18:04:13 2008 for sedflux by  doxygen 1.5.2