68 const char * xsh_config_file,
69 const char * xsh_config_tag,
70 const char * meas_coord_file)
72 cpl_table * conf_tab = NULL;
74 int morder,sizearraywavelengths, DS_size,adim;
76 int morder_min, morder_max;
77 struct xs_3 xs_model, *p_xs_3;
86 coord *msp_coord = NULL;
92 p_all_par=&all_par[0];
93 sizearraywavelengths=
countlines(meas_coord_file);
96 xsh_msg(
"%d \n",sizearraywavelengths);
98 xsh_msg(
"tag=%s",xsh_config_tag);
112 if (p_xs_3->
arm==0) {
123 else if (p_xs_3->
arm==1) {
134 else if (p_xs_3->
arm==2) {
146 printf(
"Arm not set. \n");
158 DS_size = sizearraywavelengths;
167 for(ii=0;ii<sizearraywavelengths;ii++) {
168 p_wlarray[ii]=msp_coord[ii].
wave*1e-6;
175 flux_tot+=msp_coord[ii].
flux;
179 for(ii=0;ii<sizearraywavelengths;ii++) {
180 msp_coord[ii].
flux=msp_coord[ii].
flux*(double)(tot)/flux_tot;
183 printf (
"Before anneal: \n");
184 for (ii=0;ii<adim;ii++) {
185 printf(
"%d %s %lf \n", aname[ii], (p_all_par+aname[ii])->name, abest[ii]);
192 for (jj=0;jj<DS_size;jj++) {
198 printf(
"check %d %lf %lf %d %d %lf %lf %lf %lf %d\n",
202 msp_coord[jj].
order);
233 measfile=fopen(datname,
"r");
235 if(measfile ==NULL ){
236 printf(
"Cannot open the measured coords file\n");
239 while(fscanf(measfile,
"%64d %64lf %64lf %64d %64lf %64d %64lf %64d\n",
240 &meas_coord[feat_cnt].counter,
241 &meas_coord[feat_cnt].
y,
242 &meas_coord[feat_cnt].
x,
243 &meas_coord[feat_cnt].
arm,
244 &meas_coord[feat_cnt].flux,
245 &meas_coord[feat_cnt].slit_pos,
246 &meas_coord[feat_cnt].wave,
247 &meas_coord[feat_cnt].
order) != EOF ){
251 if (feat_cnt != sizearraywavelengths) {
252 printf(
"Number of spectral features is not equal to the number of wavelengths and slit posn's supplied! \n %d != %d \n",feat_cnt, sizearraywavelengths);
267 if((myfile=fopen((
char*)filename,
"r"))==NULL){
268 printf(
"Cannot open file %s for reading.\n",filename);
274 c = fgets(oneline, 200, myfile);
277 strncpy(firstchar,oneline,1);
278 if(strncmp(firstchar,comment,1))
cpl_table * xsh_model_anneal_reduce(const char *xsh_config_file, const char *xsh_config_tag, const char *meas_coord_file)
The actual anneal computation takes place here.
int xsh_model_readfits(double *abest, double *amin, double *amax, int *aname, const char *xs_config_file, const char *xs_config_tag, struct xs_3 *p_xs_3, ann_all_par *p_all_par)
void xsh_ref_ind_read(int arm, DOUBLE **ref_ind_T, DOUBLE temper)
Load the refractive index coeffs for a given arm and temperature.
void xsh_3_detpix(struct xs_3 *p_xs_3)
Takes the physical x,y position at the detector array and converts this to a pixel position.
void xsh_3_eval(DOUBLE lambda, int morder, DOUBLE **ref_ind, struct xs_3 *p_xs_3)
Compute the physical x,y position at the detector array for a given wavelength, order and parameter c...
void xsh_showmatrix(mat A)
Show matrix.
DOUBLE * xsh_alloc1Darray(int asize)
allocates memory for an array of doubles
int xsh_free2Darray(double **ccdtemp, int asize)
free memory for a 2D array of doubles
void xsh_3_init(struct xs_3 *p_xs_3)
Pre-compute a number of non-wavelength dependent secondary parameters required by the model.
double ** xsh_alloc2Darray(int asize, int bsize)
allocates memory for a 2D array of doubles
cpl_table * xsh_model_anneal_comp(ann_all_par *p_all_par, int nparam, double *abest, double *amin, double *amax, int *aname, struct xs_3 *p_xs_3, int DS_size, coord *msp_coord, DOUBLE *p_wlarray, DOUBLE **ref_ind, int maxit)
Use the simulated annealing algorithm to adjust the model parameters so that the metric (mean Euclide...
#define xsh_msg(...)
Print a message on info level.
void get_meas_coordinates(int sizearraywavelengths, coord *meas_coord, char *datname)
int countlines(const char *filename)
#define XSH_CALLOC(POINTER, TYPE, SIZE)