/*--------------------------------------------------------------------------- File name : jitter_cfg.c Author : Nicolas Devillard Created on : September 1999 Description : jitter configuration handling tools *--------------------------------------------------------------------------*/ /* $Id: jitter_cfg.c,v 1.8 2001/07/31 08:55:10 ndevilla Exp $ $Author: ndevilla $ $Date: 2001/07/31 08:55:10 $ $Revision: 1.8 $ */ /*--------------------------------------------------------------------------- Includes ---------------------------------------------------------------------------*/ #include "jitter_cfg.h" /*--------------------------------------------------------------------------- Function codes ---------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------- Function : jitter_cfg_create() In : void Out : pointer to allocated base jitter_config structure Job : allocate memory for a jitter_config struct Notice : only the main (base) structure is allocated ---------------------------------------------------------------------------*/ jitter_config * jitter_cfg_create(void) { return calloc(1, sizeof(jitter_config)); } /*--------------------------------------------------------------------------- Function : jitter_cfg_destroy() In : jitter_config to deallocate Out : void Job : deallocate all memory associated with a jitter_config Notice : ---------------------------------------------------------------------------*/ void jitter_cfg_destroy(jitter_config * jc) { int i ; if (jc==NULL) return ; /* Free all plane names */ if (jc->nframes>0) { for (i=0 ; inframes ; i++) { if (jc->input_list[i]!=NULL) free(jc->input_list[i]); } /* Free main list of pointers */ free(jc->input_list); /* Free list of frame types */ free(jc->frametype); } /* Free sky background measurements */ if (jc->sky_background!=NULL) free(jc->sky_background); /* Free cross-correlation measurements */ if (jc->xcorr_x != NULL) free(jc->xcorr_x); if (jc->xcorr_y != NULL) free(jc->xcorr_y); if (jc->xcorr_errx != NULL) free(jc->xcorr_errx); if (jc->xcorr_erry != NULL) free(jc->xcorr_erry); if (jc->xcorr_dist != NULL) free(jc->xcorr_dist); if (jc->xcorr_estx != NULL) free(jc->xcorr_estx); if (jc->xcorr_esty != NULL) free(jc->xcorr_esty); if (jc->xcorr_ok != NULL) free(jc->xcorr_ok); /* Free cross-correlation objects */ if (jc->xcorrobj_x!=NULL) free(jc->xcorrobj_x); if (jc->xcorrobj_y!=NULL) free(jc->xcorrobj_y); /* Free main struct */ free(jc); return ; } /* * This function only converts an integer into a character string... */ char * jitter_algo(int s) { static char status[15] ; switch (s) { case ALGO_NOTREACHED: strcpy(status, "not reached"); break ; case ALGO_OK: strcpy(status, "Ok"); break ; case ALGO_SKIPPED: strcpy(status, "skipped"); break ; case ALGO_FAILED: strcpy(status, "failed"); break ; default: strcpy(status, "unknown"); break ; } return status ; } /*--------------------------------------------------------------------------- Function : jitter_cfg_dump() In : jitter_config, file name to dump jitter_config in Out : void Job : dump a jitter_config structure into a file Notice : provide a NULL file name to dump to stderr instead. if the provided file name corresponds to something that cannot be opened, the config will be dumped to stderr anyway... ---------------------------------------------------------------------------*/ #define IBOOL(i) ((i)? "yes" : "no") #define IFTYP(i) (((i)==FRAME_OBJ) ? "obj" : "sky") void jitter_cfg_dump( jitter_config * cfg, char * filename ) { FILE * dm ; int i ; if (cfg==NULL) return ; if (filename==NULL) { dm = stderr ; } else { /* Open the file for dumping */ dm = fopen(filename, "w") ; if (dm==NULL) { e_error("cannot create file [%s]: ", filename); e_error("dumping config to stderr"); dm = stderr ; } } fprintf(dm, "#\n" "# jitter_config from pid [%ld]\n" "#\n" "\n" "[AlgorithmStatus]\n" "Load = %s ;\n" "Cosmetics = %s ;\n" "SkyEngine = %s ;\n" "ObjectAcq = %s ;\n" "OffsetAcq = %s ;\n" "ShiftAndAdd = %s ;\n" "PostProc = %s ;\n" "Save = %s ;\n" "\n", (long)getpid(), jitter_algo(cfg->status_load), jitter_algo(cfg->status_cosmetics), jitter_algo(cfg->status_skyengine), jitter_algo(cfg->status_objacq), jitter_algo(cfg->status_offacq), jitter_algo(cfg->status_saa), jitter_algo(cfg->status_postproc), jitter_algo(cfg->status_save)) ; fprintf(dm, "[Frames]\n" "FileList = %s ;\n" "NFrames = %d ;\n" "NObj = %d ;\n" "ContainsSky = %s ;\n" "\n", cfg->frames_filelist, cfg->nframes, cfg->nobj, IBOOL(cfg->contains_sky)); for (i=0 ; inframes ; i++) { fprintf(dm, "Frame:%02d = %s (%s)\n", i+1, cfg->input_list[i], IFTYP(cfg->frametype[i])); } fprintf(dm, "\n" "[CalibrationData]\n" "Dark = %s ;\n" "FlatField = %s ;\n" "BadPixelMap = %s ;\n" "\n", cfg->dark_subtraction ? cfg->dark_filename : "none", cfg->flatfield_division ? cfg->flatfield_filename : "none", cfg->badpixels_replacement ? cfg->badpixels_filename : "none"); if (cfg->sky_estimate) { fprintf(dm, "[SkyEngine]\n" "EstimateSky = yes ;\n" "OutputDiff = %s ;\n" "\n" "[SkyCombine]\n" "MinNumberOfFrames = %d ;\n" "RejectHalfWidth = %d ;\n" "RejectMin = %d ;\n" "RejectMax = %d ;\n" "\n", IBOOL(cfg->sky_outputdiff), cfg->sky_minnumofframes, cfg->sky_rejhalfwidth, cfg->sky_rejmin, cfg->sky_rejmax); } else { fprintf(dm, "[SkyEngine]\n" "EstimateSky = no ;\n" "\n"); } if (cfg->saa_apply) { fprintf(dm, "[ShiftAndAdd]\n" "Activate = yes ;\n"); switch (cfg->saa_objacq_source) { case OBJACQ_AUTO: fprintf(dm, "ObjectSource = auto ;\n" "AutoDetectImage = %s ;\n" "AutoThreshold = %g ;\n" "AutoMinPoints = %d ;\n" "AutoMaxPoints = %d ;\n" "AutoOutputObjects = %s ;\n", cfg->saa_autodetectimage==DETIM_DIFF ? "diff" : cfg->saa_autodetectimage==DETIM_FIRST ? "first" : "unknown", cfg->saa_autothreshold, cfg->saa_autominpts, cfg->saa_automaxpts, IBOOL(cfg->saa_outputobjs)); break; case OBJACQ_FILE: fprintf(dm, "ObjectSource = file ;\n" "ObjectFileName = %s ;\n", cfg->saa_objacq_filename); break; } switch(cfg->saa_offinput) { case OFFSIN_HEADER: fprintf(dm, "OffsetInput = header ;\n" "OffsetXKeyword = %s ;\n" "OffsetYKeyword = %s ;\n", cfg->saa_off_xkey, cfg->saa_off_ykey); break; case OFFSIN_FILE: fprintf(dm, "OffsetInput = file ;\n" "OffsetInputFile = %s ;\n", cfg->saa_off_filename); break ; case OFFSIN_AUTO: fprintf(dm, "OffsetInput = auto ;\n"); break ; } if (cfg->saa_off_refine) { fprintf(dm, "OffsetRefine = yes ;\n" "OffsetSearchSizeX = %d ;\n" "OffsetSearchSizeY = %d ;\n" "OffsetMeasureSizeX = %d ;\n" "OffsetMeasureSizeY = %d ;\n", cfg->saa_off_sx, cfg->saa_off_sy, cfg->saa_off_hx, cfg->saa_off_hy); } else { fprintf(dm, "OffsetRefine = no ;\n"); } if (cfg->xcorr_nobj>0) { fprintf(dm, "[XCorrObjects]\n" "Computed = yes ;\n" "NObjects = %d ;\n", cfg->xcorr_nobj); for (i=0 ; ixcorr_nobj ; i++) { fprintf(dm, "XCorrObj:%02d = %d, %d ;\n", i+1, cfg->xcorrobj_x[i], cfg->xcorrobj_y[i]); } fprintf(dm, "\n"); } else { fprintf(dm, "[XCorrObjects]\n" "Computed = no ;\n"); } if (cfg->xcorr_x!=NULL) { fprintf(dm, "[AppliedOffsets]\n" "Computed = yes ;\n" "NOffsets = %d ;\n" "\n", cfg->nobj); for (i=0 ; inobj ; i++) { fprintf(dm, "Offset:%02d = %5.2f %5.2f %5.2f %5.2f %g\n", i+1, cfg->xcorr_x[i], cfg->xcorr_errx[i], cfg->xcorr_y[i], cfg->xcorr_erry[i], cfg->xcorr_dist[i]) ; } fprintf(dm, "\n"); } else { fprintf(dm, "[AppliedOffsets]\n" "Computed = no ;\n" "\n"); } fprintf(dm, "AverageRejectMin = %d ;\n" "AverageRejectMax = %d ;\n", cfg->saa_filt_lo, cfg->saa_filt_hi); } else { fprintf(dm, "[ShiftAndAdd]\n" "Activate = no\n" "\n"); } fprintf(dm, "[PostProcessing]\n" "Activate = %s ;\n" "RowSubtractMedian = %s ;\n" "StartViewer = %s ;\n" "StartCommand = %s ;\n" "ProduceStatusReport = %s ;\n" "ProduceQCReport = %s ;\n" "\n", IBOOL(cfg->postproc_active), IBOOL(cfg->postproc_rowmediansub), IBOOL(cfg->postproc_startviewer), cfg->postproc_viewer, IBOOL(cfg->postproc_statusreport), IBOOL(cfg->postproc_qcreport)); fprintf(dm, "[Output]\n" "BaseName = %s ;\n" "\n", cfg->output_basename); fprintf(dm, "# end of file\n"); if (dm!=stderr) fclose(dm); return ; } #undef IBOOL #undef IFTYP