38 #include "naco_recipe.h"
46 #define RECIPE_STRING "naco_util_spc_argon"
48 #ifndef NACO_SPC_ARGON_SIZE
49 #define NACO_SPC_ARGON_SIZE 80
56 NACO_RECIPE_DEFINE(naco_util_spc_argon, 0,
57 "Generate FITS table with argon lines",
58 "The input frame(s) must be tagged "
59 NACO_SPC_ARGON_ASCII
".\n"
60 "The file must comprise two columns:"
61 "the 1st with the line wavelength [Angstrom],\n"
62 "the 2nd with the line intensity.\n"
64 "The default input ASCII-file is in the catalogs/ "
65 "directory of the NACO source-code distribution.");
67 static IRPLIB_UTIL_SET_ROW(naco_util_spc_argon_set_row);
68 static IRPLIB_UTIL_CHECK(naco_util_spc_argon_check);
70 static unsigned nzero = 0;
91 static int naco_util_spc_argon(cpl_frameset * framelist,
92 const cpl_parameterlist * parlist)
94 irplib_framelist * allframes = NULL;
95 irplib_framelist * rawframes = NULL;
96 cpl_frameset * useframes = NULL;
97 cpl_table *
self = NULL;
100 if (cpl_error_get_code())
return cpl_error_get_code();
109 bug_if(allframes == NULL);
112 skip_if (rawframes == NULL);
117 bug_if(allframes == NULL);
125 bug_if (cpl_table_new_column(
self, NACO_SPC_LAB_WAVE, CPL_TYPE_DOUBLE));
126 bug_if (cpl_table_new_column(
self, NACO_SPC_LAB_INTENS, CPL_TYPE_DOUBLE));
128 bug_if(cpl_table_set_column_unit(
self, NACO_SPC_LAB_WAVE,
"micron"));
131 NACO_SPC_ARGON_SIZE,
'#', NULL,
132 NACO_SPC_ARGON, parlist, RECIPE_STRING,
133 NULL, NULL, NULL,
"NACO", naco_pipe_id,
134 naco_util_spc_argon_set_row,
135 naco_util_spc_argon_check));
138 cpl_table_delete(
self);
139 cpl_frameset_delete(useframes);
143 return cpl_error_get_code();
160 cpl_boolean naco_util_spc_argon_set_row(cpl_table *
self,
163 const cpl_frame * rawframe,
164 const cpl_parameterlist * parlist)
169 #define FORMAT "%lg %lg"
176 bug_if(
self == NULL);
177 bug_if(line == NULL);
179 bug_if(rawframe == NULL);
180 bug_if(parlist == NULL);
182 nvals = sscanf(line, FORMAT, &wlen, &intens);
184 error_if (nvals != 2, CPL_ERROR_BAD_FILE_FORMAT,
185 "Line with length=%u has %d not 2 items formatted: %s",
186 (
unsigned)strlen(line), nvals, FORMAT);
188 error_if (wlen <= 0.0, CPL_ERROR_BAD_FILE_FORMAT,
189 "Non-positive wavelength %g in line %s", wlen, line);
191 error_if (intens < 0.0, CPL_ERROR_BAD_FILE_FORMAT,
192 "Negative intensity %g in line %s", intens, line);
196 bug_if(cpl_table_set_double(
self, NACO_SPC_LAB_WAVE, irow, wlen));
197 bug_if(cpl_table_set_double(
self, NACO_SPC_LAB_INTENS, irow, intens));
199 if (intens <= 0.0) nzero++;
219 cpl_error_code naco_util_spc_argon_check(cpl_table *
self,
220 const cpl_frameset * useframes,
221 const cpl_parameterlist * parlist)
224 cpl_propertylist * reflist = cpl_propertylist_new();
228 bug_if(
self == NULL);
229 bug_if(parlist == NULL);
232 bug_if(cpl_propertylist_append_bool(reflist, NACO_SPC_LAB_WAVE, 0));
234 bug_if(cpl_table_sort(
self, reflist));
236 cpl_msg_info(cpl_func,
"Created table of %d argon lines (%u with zero "
237 "intensity) from %d file(s)", (
int)cpl_table_get_nrow(
self),
238 nzero, (
int)cpl_frameset_get_size(useframes));
242 cpl_propertylist_delete(reflist);
244 return cpl_error_get_code();
cpl_frameset * irplib_frameset_cast(const irplib_framelist *self)
Create a CPL frameset from an irplib_framelist.
int naco_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
cpl_error_code irplib_dfs_table_convert(cpl_table *self, cpl_frameset *allframes, const cpl_frameset *useframes, int maxlinelen, char commentchar, const char *product_name, const char *procatg, const cpl_parameterlist *parlist, const char *recipe_name, const cpl_propertylist *mainlist, const cpl_propertylist *extlist, const char *remregexp, const char *instrume, const char *pipe_id, cpl_boolean(*table_set_row)(cpl_table *, const char *, int, const cpl_frame *, const cpl_parameterlist *), cpl_error_code(*table_check)(cpl_table *, const cpl_frameset *, const cpl_parameterlist *))
Create a DFS product with one table from one or more (ASCII) file(s)
void irplib_framelist_empty(irplib_framelist *self)
Erase all frames from a framelist.
irplib_framelist * irplib_framelist_extract(const irplib_framelist *self, const char *tag)
Extract the frames with the given tag from a framelist.
void irplib_framelist_delete(irplib_framelist *self)
Deallocate an irplib_framelist with its frames and properties.
irplib_framelist * irplib_framelist_cast(const cpl_frameset *frameset)
Create an irplib_framelist from a cpl_framelist.
int irplib_framelist_get_size(const irplib_framelist *self)
Get the size of a framelist.