| 1 | #include <stdio.h>
|
|---|
| 2 | #include <string.h>
|
|---|
| 3 | #include <stdlib.h>
|
|---|
| 4 | #include <math.h>
|
|---|
| 5 | #include "diag.h"
|
|---|
| 6 | #include "geometry.h"
|
|---|
| 7 | #include "init.h"
|
|---|
| 8 |
|
|---|
| 9 | extern char line[]; /* parsing buf. (init) */
|
|---|
| 10 | extern char axisdev_filename[256], reflectivity_filename[256];
|
|---|
| 11 |
|
|---|
| 12 | float ct_Focal_mean; /* focal dist. (mean) (cm) */
|
|---|
| 13 | float ct_PSpread_mean; /* pt. spread fn. (mean) (cm) */
|
|---|
| 14 | float ct_BlackSpot_rad; /* black spot radius (cm) */
|
|---|
| 15 | float ct_RMirror; /* rad. of single mirror (cm) */
|
|---|
| 16 | int ct_NMirrors=0; /* number of mirrors */
|
|---|
| 17 | float ct_CameraWidth; /* camera width (cm) */
|
|---|
| 18 | int ct_NPixels; /* number of pixels */
|
|---|
| 19 | float ct_PixelWidth; /* pixel width (cm) */
|
|---|
| 20 |
|
|---|
| 21 | mirror *ct_data=NULL; /* ptr to mirror data */
|
|---|
| 22 |
|
|---|
| 23 | int nReflectivity=0; /* elements in refl. table */
|
|---|
| 24 | float *Reflectivity[2]; /* reflectivity table */
|
|---|
| 25 | float *AxisDeviation[2]; /* axis deviation table */
|
|---|
| 26 |
|
|---|
| 27 | /* Prototypes */
|
|---|
| 28 | static void ReadMirrorTable(FILE *geofile);
|
|---|
| 29 | static void ReadReflectivity(char *datname);
|
|---|
| 30 | static void ReadAxisDev(char *datname);
|
|---|
| 31 |
|
|---|
| 32 | static void ReadMirrorTable(FILE *geofile)
|
|---|
| 33 | { int i; /* Mirror index */
|
|---|
| 34 |
|
|---|
| 35 | if ((ct_data=(mirror *)malloc(sizeof(mirror)*ct_NMirrors)) == NULL)
|
|---|
| 36 | FatalError(MIRR_ALLOC_FTL, ct_NMirrors);
|
|---|
| 37 | Log(MIRR_ALLOC_LOG, ct_NMirrors);
|
|---|
| 38 | Log(MIRR_TABLE_LOG);
|
|---|
| 39 |
|
|---|
| 40 | Log(READ_ASCII_LOG);
|
|---|
| 41 | for (i=0; i<ct_NMirrors; i++)
|
|---|
| 42 | {
|
|---|
| 43 | if (12 != fscanf(geofile, "%d %f %f %f %f %f %f %f %f %f %f %f",
|
|---|
| 44 | &ct_data[i].i, &ct_data[i].f,
|
|---|
| 45 | &ct_data[i].sx, &ct_data[i].sy,
|
|---|
| 46 | &ct_data[i].x, &ct_data[i].y, &ct_data[i].z,
|
|---|
| 47 | &ct_data[i].theta, &ct_data[i].phi,
|
|---|
| 48 | &ct_data[i].xn, &ct_data[i].yn, &ct_data[i].zn))
|
|---|
| 49 | break;
|
|---|
| 50 |
|
|---|
| 51 | }
|
|---|
| 52 | if (i < ct_NMirrors)
|
|---|
| 53 | FatalError(MIRR_FEW___FTL, i);
|
|---|
| 54 |
|
|---|
| 55 | } /* end of ReadMirrorTable */
|
|---|
| 56 |
|
|---|
| 57 | static void ReadReflectivity(char *datname)
|
|---|
| 58 | {
|
|---|
| 59 | FILE *datfile = fopen(datname, "r");
|
|---|
| 60 | int current = 0;
|
|---|
| 61 |
|
|---|
| 62 | if (datfile == NULL)
|
|---|
| 63 | FatalError(RFLF_ERROR_FTL, datname);
|
|---|
| 64 | else
|
|---|
| 65 | printf("Reading file %s\n", datname);
|
|---|
| 66 |
|
|---|
| 67 | while (fgets(line, LINE_MAX_LENGTH, datfile))
|
|---|
| 68 | {
|
|---|
| 69 | if (line[0] == '#') continue;
|
|---|
| 70 |
|
|---|
| 71 | if (nReflectivity == 0)
|
|---|
| 72 | {
|
|---|
| 73 | nReflectivity = atoi(line);
|
|---|
| 74 | if (nReflectivity)
|
|---|
| 75 | {
|
|---|
| 76 | if ((Reflectivity[0] =
|
|---|
| 77 | (float *) malloc(sizeof(float) * nReflectivity)) == NULL ||
|
|---|
| 78 | (Reflectivity[1] =
|
|---|
| 79 | (float *) malloc(sizeof(float) * nReflectivity)) == NULL)
|
|---|
| 80 | FatalError(REFL_ALLOC_FTL, nReflectivity);
|
|---|
| 81 | }
|
|---|
| 82 | }
|
|---|
| 83 | else if (2 == sscanf(line, "%f %f", &Reflectivity[0][current],
|
|---|
| 84 | &Reflectivity[1][current]))
|
|---|
| 85 | {
|
|---|
| 86 | current++;
|
|---|
| 87 | if (current >= nReflectivity) break;
|
|---|
| 88 | }
|
|---|
| 89 | }
|
|---|
| 90 | fclose(datfile);
|
|---|
| 91 |
|
|---|
| 92 | nReflectivity = current;
|
|---|
| 93 |
|
|---|
| 94 | } /* end of ReadReflectivity */
|
|---|
| 95 |
|
|---|
| 96 | static void ReadAxisDev(char *datname)
|
|---|
| 97 | { FILE *datfile = fopen(datname, "r");
|
|---|
| 98 | int current = 0;
|
|---|
| 99 |
|
|---|
| 100 | if (datfile == NULL)
|
|---|
| 101 | FatalError(AXIS_ERROR_FTL, datname);
|
|---|
| 102 | else
|
|---|
| 103 | printf("Reading file %s\n", axisdev_filename);
|
|---|
| 104 |
|
|---|
| 105 | if ((AxisDeviation[0]=
|
|---|
| 106 | (float *) malloc(sizeof(float) * ct_NMirrors)) == NULL
|
|---|
| 107 | || (AxisDeviation[1]=
|
|---|
| 108 | (float *) malloc(sizeof(float) * ct_NMirrors)) == NULL)
|
|---|
| 109 | FatalError(AXIS_ALLOC_FTL, ct_NMirrors);
|
|---|
| 110 | while (fgets(line, LINE_MAX_LENGTH, datfile))
|
|---|
| 111 | { if (line[0] == '#') continue;
|
|---|
| 112 | if (2==sscanf(line, "%f %f",
|
|---|
| 113 | &AxisDeviation[0][current], &AxisDeviation[1][current]));
|
|---|
| 114 | { current++;
|
|---|
| 115 | if (current >= ct_NMirrors) break; }}
|
|---|
| 116 | fclose(datfile);
|
|---|
| 117 |
|
|---|
| 118 | if (current != ct_NMirrors)
|
|---|
| 119 | FatalError(AXIS_FEW___FTL, current, ct_NMirrors);
|
|---|
| 120 | } /* end of ReadAxisDev */
|
|---|
| 121 |
|
|---|
| 122 | void GeometrySwitch(FILE *geofile)
|
|---|
| 123 | { char *value_ptr = NULL; /* ptr at parm value */
|
|---|
| 124 | int switch_end = FALSE; /* bool to exit loop */
|
|---|
| 125 | extern char whites[]; /* white chars (init) */
|
|---|
| 126 | extern int ParseLine(FILE *parfile, /* FILE with parms */
|
|---|
| 127 | const char *token_list[], /* array w/tokens */
|
|---|
| 128 | int tokens, /* nr of tokens */
|
|---|
| 129 | char **value_ptr); /* ptr->parm val. */
|
|---|
| 130 |
|
|---|
| 131 | /* Initialise arrays */
|
|---|
| 132 | Reflectivity[0] = AxisDeviation[0] = NULL;
|
|---|
| 133 |
|
|---|
| 134 | do
|
|---|
| 135 | { switch(ParseLine(geofile, ctparms, ARRAY_SZ(ctparms), &value_ptr))
|
|---|
| 136 | { case type:
|
|---|
| 137 | if (1 != atoi(value_ptr))
|
|---|
| 138 | FatalError(TYPE_ERROR_FTL);
|
|---|
| 139 | break;
|
|---|
| 140 | case focal_distance:
|
|---|
| 141 | Log(LOG__FLOAT_LOG, "focal distance (average, cm)",
|
|---|
| 142 | ct_Focal_mean = (float) atof(value_ptr));
|
|---|
| 143 | break;
|
|---|
| 144 | case focal_std: /* not implemented. */
|
|---|
| 145 | break;
|
|---|
| 146 | case point_spread:
|
|---|
| 147 | Log(LOG__FLOAT_LOG, "point spread fn. sigma (average, cm)",
|
|---|
| 148 | ct_PSpread_mean = (float) atof(value_ptr));
|
|---|
| 149 | break;
|
|---|
| 150 | case point_std: /* not implemented */
|
|---|
| 151 | break;
|
|---|
| 152 | case adjustment_dev: /* not implemented */
|
|---|
| 153 | break;
|
|---|
| 154 | case black_spot:
|
|---|
| 155 | Log(LOG__FLOAT_LOG, "radius of black spot (cm)",
|
|---|
| 156 | ct_BlackSpot_rad = (float) atof(value_ptr));
|
|---|
| 157 | break;
|
|---|
| 158 | case n_mirrors:
|
|---|
| 159 | Log(LOG__INT___LOG, "number of mirrors",
|
|---|
| 160 | ct_NMirrors = atoi(value_ptr));
|
|---|
| 161 | break;
|
|---|
| 162 | case r_mirror:
|
|---|
| 163 | Log(LOG__FLOAT_LOG, "single mirror radius (cm)",
|
|---|
| 164 | ct_RMirror = (float) atof(value_ptr));
|
|---|
| 165 | break;
|
|---|
| 166 | case camera_width:
|
|---|
| 167 | Log(LOG__FLOAT_LOG, "camera radius (cm)",
|
|---|
| 168 | ct_CameraWidth = (float) atof(value_ptr));
|
|---|
| 169 | break;
|
|---|
| 170 | case n_pixels:
|
|---|
| 171 | Log(LOG__INT___LOG, "number of pixels",
|
|---|
| 172 | ct_NPixels = atoi(value_ptr));
|
|---|
| 173 | break;
|
|---|
| 174 | case pixel_width:
|
|---|
| 175 | Log(LOG__FLOAT_LOG, "pixel width (cm)",
|
|---|
| 176 | ct_PixelWidth = (float) atof(value_ptr));
|
|---|
| 177 | break;
|
|---|
| 178 | case n_centralpixels:
|
|---|
| 179 | /* this parameter is for camera, not for reflector */
|
|---|
| 180 | break;
|
|---|
| 181 | case n_gappixels:
|
|---|
| 182 | /* this parameter is for camera, not for reflector */
|
|---|
| 183 | break;
|
|---|
| 184 | case refl_file:
|
|---|
| 185 | ReadReflectivity(value_ptr);
|
|---|
| 186 | break;
|
|---|
| 187 | case axisdev_file:
|
|---|
| 188 | ReadAxisDev(value_ptr);
|
|---|
| 189 | break;
|
|---|
| 190 | case define_mirrors:
|
|---|
| 191 | if (ct_NMirrors) ReadMirrorTable(geofile);
|
|---|
| 192 | else FatalError(MIRR_NSPEC_FTL);
|
|---|
| 193 | switch_end = TRUE;
|
|---|
| 194 | break;
|
|---|
| 195 | default: switch_end = TRUE;
|
|---|
| 196 | break; }}
|
|---|
| 197 | while (!switch_end);
|
|---|
| 198 | fclose(geofile);
|
|---|
| 199 |
|
|---|
| 200 | if (strlen(reflectivity_filename) == 0)
|
|---|
| 201 | strcpy(reflectivity_filename, REFLECTIVITY_FILE);
|
|---|
| 202 | if (Reflectivity[0] == NULL) ReadReflectivity(reflectivity_filename);
|
|---|
| 203 |
|
|---|
| 204 | if (strlen(axisdev_filename) == 0)
|
|---|
| 205 | strcpy(axisdev_filename, AXISDEVIATION_FILE);
|
|---|
| 206 | if (AxisDeviation[0]== NULL) ReadAxisDev(axisdev_filename);
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 | } /* end of GeometrySwitch */
|
|---|
| 210 |
|
|---|