10 #define GSL_RANGE_CHECK_OFF
11 #include "gsl/gsl_matrix.h"
12 #include "gsl/gsl_linalg.h"
13 #include "gsl/gsl_blas.h"
16 #include "../../Magellan/lib/bcu_diag.h"
18 #include "mx/fileUtils.hpp"
26 int reconstruct_bcu39frames(std::string recmatname, std::string subdir,
int outMode=0)
32 std::vector<std::string> flist = mx::getFileNames(subdir,
"BCU39",
".fits");
33 sort(flist.begin(), flist.end());
37 long fpix[2]={1,1}, lpix[2];
40 rmat.rec_tech = REC_ATLAS;
44 std::vector<std::ofstream *> outs;
48 outs.resize(rmat.n_modes);
51 for(
int i=0;i<rmat.n_modes;i++)
54 fn <<
"mode_" << i <<
".dat";
55 outs[i] =
new std::ofstream;
56 outs[i]->open(fn.str().c_str());
69 lpix[0] =
sizeof(slopecomp_diagframe_pixels_slopes);
72 unsigned char * im39 =
new unsigned char[
sizeof(slopecomp_diagframe_pixels_slopes)];
74 float *slopes = (
float *) (im39+12832);
76 float sumvar, ho1, ho2;
77 double t0, t1, avdt = 0, avdtrec = 0;
79 float * svs =
new float[flist.size()];
83 for(
int i=0;i<flist.size();i++)
88 get_fits_im(im39, 1, fpix, lpix, &fptr1, flist[i].c_str());
89 fits_close_file(fptr1, &fstatus);
92 frameno = *( (uint32*) im39);
96 rmat.reconstruct(slopes);
100 rmat.calc_sumvar(&sumvar, 0, -1, 0);
101 rmat.calc_sumvar(&ho1, 2, 200,0);
102 rmat.calc_sumvar(&ho2, 200,-1, 0);
113 for(
int j=0;j<rmat.n_modes;++j)
115 (*outs[j]) << frameno <<
" " << rmat.amp[j] <<
"\n";
120 std::cout << frameno <<
" " << rmat.unit_conversion*rmat.reflection_gain*rmat.amp[0] <<
" " << rmat.unit_conversion*rmat.reflection_gain*rmat.amp[1] <<
" " <<
123 rmat.unit_conversion*rmat.reflection_gain*rmat.amp[100] <<
" " << rmat.unit_conversion*rmat.reflection_gain*rmat.amp[150] <<
"\n";
128 std::cerr <<
"Avg Rec Time: " << avdtrec/flist.size() <<
"\n";
129 std::cerr <<
"Avg Tot Time: " << avdt/flist.size() <<
"\n";
133 for(
int j=0;j<rmat.n_modes;++j)
143 int make_slopeims(std::string olist, std::string flist,
int nframes)
148 std::ifstream lutxin;
149 std::ifstream lutyin;
153 fitsfile * fptr1 = 0;
154 fitsfile * fptr2 = 0;
163 long fpix[2]={1,1}, lpix[2];
165 long naxes[3], out_fpix[3], out_lpix[3];
175 float * frame =
new float[6400];
176 for(
int i=0;i<6400;i++) frame[i] = 0;
183 fname = getenv(
"VISAO_ROOT");
184 fname +=
"/calib/ccd39/slopex";
186 lutxin.open(fname.c_str());
188 fname = getenv(
"VISAO_ROOT");
189 fname +=
"/calib/ccd39/slopey";
190 lutyin.open(fname.c_str());
192 for(
int i=0;i<6400;i++)
203 lpix[0] =
sizeof(slopecomp_diagframe_pixels_slopes);
206 unsigned char * im39 =
new unsigned char[
sizeof(slopecomp_diagframe_pixels_slopes)];
208 float *slopes = (
float *) (im39+12832);
214 fin.open(flist.c_str());
217 double t0, t1, avdt = 0, avdtrec = 0;
219 float * svs =
new float[nframes];
222 fits_create_file(&fptr2, olist.c_str(), &fstatus);
223 fits_create_img( fptr2, FLOAT_IMG, 3, naxes, &fstatus);
226 for(
int i=0;i<nframes;i++)
230 get_fits_im(im39, 1, fpix, lpix, &fptr1, fname.c_str());
231 fits_close_file(fptr1, &fstatus);
234 std::cout << *( (uint32*) im39) <<
"\n";
235 for(
int j=0;j<6400;j++)
239 frame[j] = slopes[lut_x[j]];
254 fits_write_subset(fptr2,TFLOAT , out_fpix, out_lpix, &frame[3200], &fstatus);
258 fits_close_file(fptr2, &fstatus);
265 int get_frameno(std::string flist,
int nframes)
272 fitsfile * fptr1 = 0;
276 long fpix[2]={1,1}, lpix[2];
278 lpix[0] =
sizeof(slopecomp_diagframe_pixels_slopes);
281 unsigned char * im39 =
new unsigned char[
sizeof(slopecomp_diagframe_pixels_slopes)];
283 fin.open(flist.c_str());
285 for(
int i=0;i<nframes;i++)
289 get_fits_im(im39, 1, fpix, lpix, &fptr1, fname.c_str());
290 fits_close_file(fptr1, &fstatus);
293 std::cout << *( (uint32*) im39) <<
"\n";
303 int main(
int argc,
char**argv)
309 getresuid(&euid_real, &euid_called, &suid);
313 struct sched_param schedpar;
315 schedpar.sched_priority = 90;
319 rv = sched_setscheduler(0, SCHED_FIFO, &schedpar);
323 std::cerr <<
"Setting scheduler priority to " << 90 <<
" failed. Errno says: " << strerror(errno) <<
".\n";
327 std::cerr <<
"Scheduler priority (RT_priority) set to " << 90 <<
".\n";
332 std::string recstr, flist;
346 std::cerr << recstr <<
"\n";
347 std::cerr << flist <<
"\n";
349 reconstruct_bcu39frames(recstr, flist,1);
fifo_list * global_fifo_list
The global fifo_list, for signal handling.
double get_curr_time(void)
Gets the current CLOCK_REALTIME time, returns it in seconds to double precision.
A structure to hold a list of fifo_channels.
Declarations for a class to manage a reconstructor matrix.
FIR digital filter class declarations.
int TimeToDie
Global set by SIGTERM.