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