39 #include "visir_recipe.h"
45 #define RECIPE_STRING "visir_util_img_std_cat"
51 static cpl_error_code visir_util_img_std_cat_save(cpl_frameset *,
52 const cpl_parameterlist *,
55 static cpl_error_code visir_util_img_std_cat_parse(
const char*,
char *,
56 double *,
double *,
char *,
59 VISIR_RECIPE_DEFINE(visir_util_img_std_cat, 0,
60 "Convert ASCII-file(s) to a FITS standard star catalog",
61 "This recipe generates a FITS standard star catalog for "
62 "imaging from one or \n"
64 "Each line in the text file must have 45 fields separated "
66 "The first field is the star name, e.g. 'HD108903' which "
67 "will be stored in a \n"
68 "table column labeled 'STARS'.\n"
69 "The 3 next fields are the RA (hh mm ss) which will be "
70 "stored in degrees in \n"
71 "a table column labeled 'RA' - all three are non-negative "
72 "and hh and mm are \n"
74 "The 3 next fields are the DEC (dd mm ss) which will be "
75 "stored in degrees in \n"
76 "a table column labeled 'DEC' - all three are non-negative, "
78 "integer, while dd has either a '+' or a '-' prepended "
80 "The next field is the spectral type which will be "
82 "table column labeled 'SP_TYPE'.\n"
83 "The 31 next fields are the JY values for the 31 supported "
85 "The 6 next fields are the JY values for the 6 supported "
87 "All JY values must be positive.\n"
88 "For each filter the JY value is stored in a table column "
91 "The 37 filter names are hard-coded in the recipe.\n"
93 "Lines beginning with a hash (#) are treated as comments.\n"
95 "The ASCII-input should be tagged " VISIR_IMG_LINES_ASCII
97 "files will currently be processed regardless.\n");
118 static int visir_util_img_std_cat(cpl_frameset * framelist,
119 const cpl_parameterlist * parlist)
124 cpl_table * tab = NULL;
127 const char * filters[]
128 = {
"MV",
"N_BAND",
"SIC",
"PAH1_1",
"PAH1",
"ARIII",
"SIV_1",
"SIV",
129 "PAH2_1",
"SIV_2",
"PAH2",
"PAH2_2",
"NEII_1",
"NEII",
"NEII_2",
130 "J7_9",
"J8_9",
"J9_8",
"J12_1",
"J12_2",
"B8_7",
"B9_7",
"B10_7",
131 "B11_7",
"B12_4",
"Q0",
"QH2",
"Q1",
"Q2",
"Q3",
"Q4",
"Q7",
"Q8",
132 "AGPM_12_4",
"4QPM_10_5",
"4QPM_11_3",
"N_SW_spec",
133 "H2S4_spec",
"ARIII_spec",
"NEII_2_spec",
"H2S3_spec",
"H2S1_spec",
135 const int nfilters =
sizeof(filters) /
sizeof(filters[0]);
136 double jys[nfilters];
137 const double max_radius = VISIR_STAR_MAX_RADIUS;
145 if (cpl_error_get_code())
return cpl_error_get_code();
151 tab = cpl_table_new(nrows);
152 skip_if (cpl_table_new_column(tab,
"STARS", CPL_TYPE_STRING));
153 skip_if (cpl_table_new_column(tab,
"SP_TYPE", CPL_TYPE_STRING));
154 skip_if (cpl_table_new_column(tab,
"RA", CPL_TYPE_DOUBLE));
155 skip_if (cpl_table_new_column(tab,
"DEC", CPL_TYPE_DOUBLE));
157 for (j=0 ; j<nfilters ; j++)
158 skip_if (cpl_table_new_column(tab, filters[j], CPL_TYPE_DOUBLE));
161 for (i=0; i < cpl_frameset_get_size(framelist); i++) {
162 const cpl_frame * frame = cpl_frameset_get_position_const(framelist, i);
165 const char * filename = cpl_frame_get_filename(frame);
170 skip_if (filename == NULL);
171 in = fopen(filename,
"r");
173 cpl_msg_error(cpl_func,
"Could not open the %d. file: %s", i+1,
178 while (fgets(line, 1024, in) != NULL) {
180 if (line[0] !=
'#') {
183 if (visir_util_img_std_cat_parse(line, sname, &ra, &dec,
184 stype, jys, nfilters)) {
185 cpl_msg_error(cpl_func,
"Unparsable line %d in %d. file "
186 "%s", jrow, i+1, filename);
192 skip_if (cpl_table_set_size(tab, nrows));
194 skip_if (cpl_table_set_string(tab,
"STARS", irow, sname));
195 skip_if (cpl_table_set_string(tab,
"SP_TYPE", irow, stype));
196 skip_if (cpl_table_set_double(tab,
"RA", irow, ra));
197 skip_if (cpl_table_set_double(tab,
"DEC", irow, dec));
198 for (j=0 ; j<nfilters ; j++)
199 skip_if(cpl_table_set_double(tab, filters[j], irow,
208 cpl_msg_warning(cpl_func,
"No usable lines in file %s", filename);
216 skip_if (cpl_table_set_size(tab, nrows));
218 mindist = visir_star_dist_min(cpl_table_get_data_double(tab,
"RA"),
219 cpl_table_get_data_double(tab,
"DEC"), nrows,
222 if (mindist < max_radius)
223 cpl_msg_warning(cpl_func,
"The pair of closest stars is %s (%d) and %s "
224 "(%d) with the distance: %g",
225 cpl_table_get_string(tab,
"STARS", iloc1), iloc1,
226 cpl_table_get_string(tab,
"STARS", iloc2), iloc2,
229 cpl_msg_info(cpl_func,
"The pair of closest stars is %s (%d) and %s "
230 "(%d) with the distance: %g",
231 cpl_table_get_string(tab,
"STARS", iloc1), iloc1,
232 cpl_table_get_string(tab,
"STARS", iloc2), iloc2,
236 cpl_msg_info(cpl_func,
"Saving the table with %d rows and %d filters",
239 skip_if (visir_util_img_std_cat_save(framelist, parlist, tab));
244 cpl_table_delete(tab);
246 return cpl_error_get_code();
263 static cpl_error_code visir_util_img_std_cat_parse(
const char * line,
264 char * sname,
double * pra,
265 double * pdec,
char *stype,
266 double * jys,
int njys)
269 const char * format =
"%s %d %d %lg %c%d %d %lg %s %lg %lg %lg %lg %lg %lg "
270 "%lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg "
271 "%lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg %lg";
285 nvals = sscanf(line, format,
286 sname, &ra1, &ra2, &ra3, &isign, &dec1, &dec2,
287 &dec3, stype, &(jys[0]), &(jys[1]), &(jys[2]),
288 &(jys[3]), &(jys[4]), &(jys[5]), &(jys[6]),
289 &(jys[7]), &(jys[8]), &(jys[9]), &(jys[10]),
290 &(jys[11]), &(jys[12]), &(jys[13]), &(jys[14]),
291 &(jys[15]), &(jys[16]), &(jys[17]), &(jys[18]),
292 &(jys[19]), &(jys[20]), &(jys[21]), &(jys[22]),
293 &(jys[23]), &(jys[24]), &(jys[25]), &(jys[26]),
294 &(jys[27]), &(jys[28]), &(jys[29]), &(jys[30]),
295 &(jys[31]), &(jys[32]), &(jys[33]), &(jys[34]),
296 &(jys[35]), &(jys[36]), &(jys[37]), &(jys[38]),
297 &(jys[39]), &(jys[40]), &(jys[41]));
299 if (nvals != njys+9) {
300 cpl_msg_error(cpl_func,
"Line with length=%u has %d not %d items "
301 "formatted: %s", (
unsigned)strlen(line), nvals, njys+9,
303 cpl_ensure_code(0, CPL_ERROR_BAD_FILE_FORMAT);
306 return visir_star_convert(line, ra1, ra2, ra3, isign, dec1, dec2,
307 dec3, jys, njys, pra, pdec);
321 cpl_error_code visir_util_img_std_cat_save(cpl_frameset * set,
322 const cpl_parameterlist * parlist,
323 const cpl_table * tab)
325 cpl_propertylist * applist = cpl_propertylist_new();
328 bug_if(cpl_propertylist_append_string(applist,
"INSTRUME",
"VISIR"));
331 VISIR_IMA_STD_CAT_PROCATG,
332 applist, NULL, visir_pipe_id,
333 RECIPE_STRING CPL_DFS_FITS));
337 cpl_propertylist_delete(applist);
339 return cpl_error_get_code();
cpl_error_code irplib_dfs_save_table(cpl_frameset *allframes, const cpl_parameterlist *parlist, const cpl_frameset *usedframes, const cpl_table *table, const cpl_propertylist *tablelist, const char *recipe, const char *procat, const cpl_propertylist *applist, const char *remregexp, const char *pipe_id, const char *filename)
Save a table as a DFS-compliant pipeline product.
int visir_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.