00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <string.h>
00026 #include <glib.h>
00027 #include <utils/utils.h>
00028
00029
00030
00031
00032
00033 void itoa(int n,char s[])
00034 {
00035 int c, i, j, sign;
00036
00037 if((sign = n) < 0 )
00038 n = -n;
00039 i = 0;
00040 do {
00041 s[i++] = n % 10 + '0';
00042 } while ((n /= 10) > 0);
00043 if ( sign < 0 )
00044 s[i++] = '-';
00045 s[i] = '\0';
00046
00047 for( i=0, j=strlen(s)-1; i<j; i++, j--) {
00048 c = s[i];
00049 s[i] = s[j];
00050 s[j] = c;
00051 }
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 #include <stdio.h>
00068 #include <stddef.h>
00069 #include <stdlib.h>
00070 #define NR_END 1
00071 #define FREE_ARG char*
00072
00073 #ifdef NOTDEFINED
00074
00075 void nrerror(char error_text[])
00076
00077 {
00078 fprintf(stderr,"Numerical Recipes run-time error...\n");
00079 fprintf(stderr,"%s\n",error_text);
00080 fprintf(stderr,"...now exiting to system...\n");
00081 eh_exit(1);
00082 }
00083
00084 #endif
00085
00086 float **matrix(long nrl, long nrh, long ncl, long nch)
00087
00088 {
00089 long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
00090 float **m;
00091
00092 eh_require( nch-ncl>0 );
00093 eh_require( nrh-nrl>0 );
00094
00095
00096
00097
00098
00099 m = eh_new( float* , nrow+NR_END );
00100 if (!m) eh_error("allocation failure 1 in matrix()");
00101 m += NR_END;
00102 m -= nrl;
00103
00104
00105
00106
00107
00108 m[nrl] = eh_new( float , nrow*ncol+NR_END );
00109
00110 if (!m[nrl]) eh_error("allocation failure 2 in matrix()");
00111 m[nrl] += NR_END;
00112 m[nrl] -= ncl;
00113
00114 for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
00115
00116
00117 return m;
00118 }
00119
00120 double **new_dmatrix( long n_rows , long n_cols )
00121 {
00122 int i;
00123 double **m;
00124
00125 eh_require( n_rows>0 );
00126 eh_require( n_cols>0 );
00127
00128 m = eh_new( double* , n_rows );
00129
00130 m[0] = eh_new( double , n_rows*n_cols );
00131
00132 for ( i=1 ; i<n_rows ; i++ )
00133 m[i] = m[i-1]+n_cols;
00134
00135 return m;
00136 }
00137
00138 float ***f3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
00139
00140 {
00141 long i,j,nrow=nrh-nrl+1,ncol=nch-ncl+1,ndep=ndh-ndl+1;
00142 float ***t;
00143
00144 eh_require( ndh-ndl>0 );
00145 eh_require( nch-ncl>0 );
00146 eh_require( nrh-nrl>0 );
00147
00148
00149
00150
00151
00152 t = eh_new( float** , nrow+NR_END );
00153 if (!t) eh_error("allocation failure 1 in f3tensor()");
00154 t += NR_END;
00155 t -= nrl;
00156
00157
00158
00159
00160
00161 t[nrl]=eh_new( float* , nrow*ncol+NR_END );
00162
00163 if (!t[nrl]) eh_error("allocation failure 2 in f3tensor()");
00164 t[nrl] += NR_END;
00165 t[nrl] -= ncl;
00166
00167
00168
00169
00170
00171 t[nrl][ncl]=eh_new( float , nrow*ncol*ndep+NR_END );
00172
00173 if (!t[nrl][ncl]) eh_error("allocation failure 3 in f3tensor()");
00174 t[nrl][ncl] += NR_END;
00175 t[nrl][ncl] -= ndl;
00176
00177 for(j=ncl+1;j<=nch;j++) t[nrl][j]=t[nrl][j-1]+ndep;
00178 for(i=nrl+1;i<=nrh;i++) {
00179 t[i]=t[i-1]+ncol;
00180 t[i][ncl]=t[i-1][ncl]+ncol*ndep;
00181 for(j=ncl+1;j<=nch;j++) t[i][j]=t[i][j-1]+ndep;
00182 }
00183
00184
00185 return t;
00186 }
00187
00188 double ***new_d3tensor( long n_rows , long n_cols , long n_dep )
00189 {
00190 int i, j;
00191 double ***t;
00192
00193 t = eh_new( double** , n_rows );
00194
00195 t[0] = eh_new( double* , n_rows*n_cols );
00196
00197 t[0][0] = eh_new( double , n_rows*n_cols*n_dep );
00198
00199 for ( j=1 ; j<n_cols ; j++ )
00200 t[0][j] = t[0][j-1]+n_dep;
00201
00202 for ( i=1 ; i<n_rows ; i++ )
00203 {
00204 t[i] = t[i-1]+n_cols;
00205 t[i][0] = t[i-1][0]+n_cols*n_dep;
00206 for ( j=1 ; j<n_cols ; j++ )
00207 t[i][j]=t[i][j-1]+n_dep;
00208 }
00209
00210 return t;
00211 }
00212
00213 void free_matrix(float **m, long nrl, long nrh, long ncl, long nch)
00214
00215 {
00216 eh_free_mem((FREE_ARG) (m[nrl]+ncl-NR_END));
00217 eh_free_mem((FREE_ARG) (m+nrl-NR_END));
00218 }
00219
00220 void free_dmatrix( double **m )
00221 {
00222 if ( m )
00223 {
00224 eh_free( m[0] );
00225 eh_free( m );
00226 }
00227 }
00228
00229 void free_f3tensor(float ***t, long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
00230
00231 {
00232 eh_free_mem((FREE_ARG) (t[nrl][ncl]+ndl-NR_END));
00233 eh_free_mem((FREE_ARG) (t[nrl]+ncl-NR_END));
00234 eh_free_mem((FREE_ARG) (t+nrl-NR_END));
00235 }
00236
00237 void free_d3tensor( double ***t )
00238 {
00239 if ( t )
00240 {
00241 if ( t[0] )
00242 {
00243 eh_free( t[0][0] );
00244 eh_free( t[0] );
00245 }
00246 eh_free( t );
00247 }
00248 }
00249