00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <unistd.h>
00004 #include "hydroalloc_mem.h"
00005
00006
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
00021
00022
00023
00024
00025
00026
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
00046
00047
00048
00049
00050
00051
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
00080
00081
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 }