00001 #include <stdio.h>
00002 #ifndef max
00003 #define max(a,b) ((a) > (b) ? (a) : (b))
00004 #endif
00005 #ifndef min
00006 #define min(a,b) ((a) < (b) ? (a) : (b))
00007 #endif
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 double polyval(int n, double *c, double x) {
00020 double poly;
00021 poly = c[n];
00022 while (n) poly = poly*x + c[--n];
00023 return poly;
00024 }
00025
00026 int max_arr(int *arr, int n) {
00027 int i, tmp;
00028 tmp = arr[0];
00029 for (i=1; i < n; i++) {
00030 tmp = max(tmp, arr[i]);
00031 }
00032 return tmp;
00033 }
00034 int min_arr(int *arr, int n) {
00035 int i, tmp;
00036 tmp = arr[0];
00037 for (i=1; i < n; i++) {
00038 tmp = min(tmp, arr[i]);
00039 }
00040 return tmp;
00041 }
00042
00043
00044 int read_guess(char *guessfile, int nrdtot, int *m, double **fnua,
00045 double **fwa, double **pa, double **bga, int *ma, int verbose) {
00046
00047 FILE *gfile;
00048 int ma1, i, n, status, ip;
00049
00050 gfile = fopen (guessfile, "r");
00051 if (!gfile) {
00052 fprintf (stderr, "Error: unable to open guess table %s\n", guessfile);
00053 return 1;
00054 }
00055 fscanf(gfile, "%d %d ", &nrdtot, &ma1);
00056 for (i=0; i < 4; i++) fscanf(gfile,"%d", &(m[i]));
00057 if (verbose) {
00058 printf("guessfile = %s \n", guessfile);
00059 printf("nrdtot = %d ma = %d \n",nrdtot,ma1);
00060 printf("m \n");
00061 for (i=0; i < 4; i++) printf("%d", (m[i]));
00062 printf("\n\n");
00063 }
00064 *fnua = (double*) malloc(ma1 * nrdtot * sizeof(double));
00065 *fwa = (double*) malloc(ma1 * nrdtot * sizeof(double));
00066 *pa = (double*) malloc(ma1 * nrdtot * sizeof(double));
00067 *bga = (double*) malloc(ma1 * nrdtot * sizeof(double));
00068
00069 for (i=0; i < nrdtot; i++) {
00070 for (n=0; n < ma1; n++) fscanf(gfile,"%lf", &(*fnua)[i*ma1 + n]);
00071 if (fscanf == NULL) {
00072 fprintf (stderr, "Problem reading in fnua\n");
00073 return 1;
00074 }
00075 }
00076 for (i=0; i < nrdtot; i++) {
00077 for (n=0; n < ma1; n++) fscanf(gfile,"%lf", &(*fwa)[i*ma1 + n]);
00078 if (fscanf == NULL) {
00079 fprintf (stderr, "Problem reading in fwa\n");
00080 return 1;
00081 }
00082 }
00083 for (i=0; i < nrdtot; i++) {
00084 for (n=0; n < ma1; n++) fscanf(gfile,"%lf", &(*pa)[i*ma1 + n]);
00085 if (fscanf == NULL) {
00086 fprintf (stderr, "Problem reading in pa\n");
00087 return 1;
00088 }
00089 }
00090 for (i=0; i < nrdtot; i++) {
00091 for (n=0; n < ma1; n++) fscanf(gfile,"%lf", &(*bga)[i*ma1 + n]);
00092 if (fscanf == NULL) {
00093 fprintf (stderr, "Problem reading in bga\n");
00094 return 1;
00095 }
00096 }
00097 if(verbose) {
00098 printf("fnua\n");
00099 for (i=0; i < nrdtot; i++) {
00100 for (n=0; n < ma1; n++) printf("%12.5f", (*fnua)[i*ma1 + n]);
00101 printf("\n");
00102 }
00103 printf("\n, \n");
00104 printf("fwa\n");
00105 for (i=0; i < nrdtot; i++) {
00106 for (n=0; n < ma1; n++) printf("%12.5f", (*fwa)[i*ma1 + n]);
00107 printf("\n");
00108 }
00109 printf("\n, \n");
00110 printf("pa\n");
00111 for (i=0; i < nrdtot; i++) {
00112 for (n=0; n < ma1; n++) printf("%12.5f", (*pa)[i*ma1 + n]);
00113 printf("\n");
00114 }
00115 printf("\n, \n");
00116 printf("bga\n");
00117 for (i=0; i < nrdtot; i++) {
00118 for (n=0; n < ma1; n++) printf("%12.5f", (*bga)[i*ma1 + n]);
00119 printf("\n");
00120 }
00121 }
00122 *ma = ma1;
00123 return 0;
00124 }
00125 int make_table(double *fnua, double *fwa, double *pa, double *bga,
00126 double *fnu, double *width, double *amp, double *bkg,
00127 int *m, int nk, double dk, int nrdtot, int kbmin,
00128 int kbmax, int ma, int verbose) {
00129 int i, j, m1, m2, m3, m4, n, ma1;
00130 double logk;
00131 ma1 = ma;
00132 m1 = m[0] - 1;
00133 m2 = m[1] - 1;
00134 m3 = m[2] - 1;
00135 m4 = m[3] - 1;
00136
00137 for (i=0; i < nrdtot; i++) {
00138 for (j = kbmin-1; j <= kbmax-1; j++) {
00139 logk= log(dk * (j+1));
00140 fnu[i * nk + j] = polyval(m1, &(fnua[i*ma1]), logk);
00141 }
00142
00143 for (j = kbmin-1; j <= kbmax-1; j++) {
00144 logk= log(dk * (j+1));
00145 width[i * nk + j] = polyval(m2, &(fwa[i*ma1]), logk);
00146 }
00147
00148 for (j = kbmin-1; j <= kbmax-1; j++) {
00149 logk= log(dk * (j+1));
00150 amp[i * nk + j] = polyval(m3, &(pa[i*ma1]), logk);
00151 }
00152
00153 for (j = kbmin-1; j <= kbmax-1; j++) {
00154 logk= log(dk * (j+1));
00155 bkg[i * nk + j] = polyval(m4, &(bga[i*ma1]), logk);
00156 }
00157 }
00158
00159
00160 for (i=0; i < nrdtot; i++) {
00161 for (j = kbmin-1; j <= kbmax-1; j++) {
00162 fnu[i*nk + j] = exp(fnu[i*nk + j]);
00163 }
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197 return 0;
00198 }