/* xml.c *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * * Part of: SExtractor * * Author: E.BERTIN (IAP) * * Contents: XML logging. * * Last modify: 14/07/2006 * *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include #include #include "define.h" #include "globals.h" #include "fits/fitscat.h" #include "field.h" #include "key.h" #include "prefs.h" #include "xml.h" extern time_t thetimet,thetimet2; /* from makeit.c */ extern pkeystruct key[]; /* from preflist.h */ extern char keylist[][32]; /* from preflist.h */ xmlstruct *xmlstack = NULL; int nxml=0, nxmlmax=0; /****** init_xml ************************************************************ PROTO int init_xml(void) PURPOSE Initialize a set of meta-data kept in memory before being written to the XML file INPUT Number of image extensions. OUTPUT RETURN_OK if everything went fine, RETURN_ERROR otherwise. NOTES -. AUTHOR E. Bertin (IAP) VERSION 03/07/2006 ***/ int init_xml(int next) { QMALLOC(xmlstack, xmlstruct, next); nxml = 0; nxmlmax = next; return EXIT_SUCCESS; } /****** end_xml ************************************************************ PROTO int end_xml(void) PURPOSE Free the set of meta-data kept in memory. INPUT -. OUTPUT RETURN_OK if everything went fine, RETURN_ERROR otherwise. NOTES -. AUTHOR E. Bertin (IAP) VERSION 12/07/2006 ***/ int end_xml(void) { free(xmlstack); return EXIT_SUCCESS; } /****** update_xml *********************************************************** PROTO int update_xml(void) PURPOSE Update a set of meta-data kept in memory before being written to the XML file INPUT -. OUTPUT RETURN_OK if everything went fine, RETURN_ERROR otherwise. NOTES -. AUTHOR E. Bertin (IAP) VERSION 11/07/2006 ***/ int update_xml(sexcatstruct *sexcat, picstruct *dfield, picstruct *field, picstruct *dwfield, picstruct *wfield) { xmlstruct *x; if (nxml >= nxmlmax) error(EXIT_FAILURE, "*Internal Error*: too many extensions in XML stack", ""); x = &xmlstack[nxml++]; x->currext = sexcat->currext; x->ndetect = sexcat->ndetect; x->ntotal = sexcat->ntotal; strcpy(x->ext_date, sexcat->ext_date); strcpy(x->ext_time, sexcat->ext_time); x->ext_elapsed = sexcat->ext_elapsed; strcpy(x->ident[0], dfield->ident); strcpy(x->ident[1], field->ident); x->backmean[0] = dfield->backmean; x->backmean[1] = field->backmean; x->backsig[0] = dfield->backsig; x->backsig[1] = field->backsig; x->sigfac[0] = dfield->sigfac; x->sigfac[1] = field->sigfac; x->thresh[0] = dfield->dthresh; x->thresh[1] = field->thresh; x->pixscale[0] = dfield->pixscale; x->pixscale[1] = field->pixscale; x->epoch[0] = dfield->epoch; x->epoch[1] = field->epoch; return EXIT_SUCCESS; } /****** write_xml ************************************************************ PROTO int write_xml(char *filename) PURPOSE Save meta-data to an XML file/stream. INPUT XML file name. OUTPUT RETURN_OK if everything went fine, RETURN_ERROR otherwise. NOTES -. AUTHOR E. Bertin (IAP) VERSION 14/07/2006 ***/ int write_xml(char *filename) { FILE *file; if (!(file = fopen(prefs.xml_name, "w"))) return RETURN_ERROR; write_xml_header(file); write_vo_fields(file); fprintf(file, " \n"); if (prefs.cat_type == FITS_LDAC || prefs.cat_type == FITS_TPX || prefs.cat_type == FITS_10) fprintf(file, " ", prefs.cat_type == FITS_10? 1:2, prefs.cat_name[0] == '/'? "file://" : "file:", prefs.cat_name); fprintf(file, " \n"); fprintf(file, " \n"); write_xml_meta(file, (char *)NULL); fprintf(file, "\n"); fprintf(file, "\n"); fclose(file); return RETURN_OK; } /****** write_xml_header ****************************************************** PROTO int write_xml_header(FILE *file) PURPOSE Save an XML-VOtable header to an XML file/stream INPUT file or stream pointer. OUTPUT RETURN_OK if everything went fine, RETURN_ERROR otherwise. NOTES -. AUTHOR E. Bertin (IAP) VERSION 14/07/2006 ***/ int write_xml_header(FILE *file) { char *filename, *rfilename; /* A short, "relative" version of the filename */ filename = prefs.image_name[prefs.nimage_name>1? 1:0]; if (!(rfilename = strrchr(filename, '/'))) rfilename = filename; else rfilename++; fprintf(file, "\n"); fprintf(file, "\n", prefs.xsl_name); fprintf(file, "\n"); fprintf(file, "produced by %s\n", BANNER); fprintf(file, "\n"); fprintf(file, "\n", BANNER, rfilename); fprintf(file, " Catalog of sources extracted with %s" "\n", BANNER); fprintf(file, " \n"); fprintf(file, " \n", prefs.epoch, prefs.coosys); fprintf(file, " \n", rfilename); fprintf(file, " Table of sources detected in image\n"); fprintf(file, " \n", BANNER); return RETURN_OK; } /****** write_xml_meta ******************************************************** PROTO int write_xml_meta(FILE *file, char *error) PURPOSE Save meta-data to an XML-VOTable file or stream INPUT Pointer to the output file (or stream), Pointer to an error msg (or NULL). OUTPUT RETURN_OK if everything went fine, RETURN_ERROR otherwise. NOTES -. AUTHOR E. Bertin (IAP) VERSION 14/07/2006 ***/ int write_xml_meta(FILE *file, char *error) { char *pspath,*psuser, *pshost, *str; struct tm *tm; int n; /* Processing date and time if msg error present */ if (error) { thetimet2 = time(NULL); tm = localtime(&thetimet2); sprintf(prefs.sdate_end,"%04d-%02d-%02d", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday); sprintf(prefs.stime_end,"%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec); prefs.time_diff = difftime(thetimet2, thetimet); } /* Username */ psuser = pspath = pshost = NULL; #ifdef HAVE_GETENV if (!(psuser=getenv("USERNAME"))) /* Cygwin,... */ psuser = getenv("LOGNAME"); /* Linux,... */ pspath = getenv("PWD"); pshost = getenv("HOSTNAME"); #endif fprintf(file, " \n"); fprintf(file, " %s meta-data\n", BANNER); fprintf(file, " \n"); fprintf(file, " \n", BANNER); fprintf(file, " \n", MYVERSION); fprintf(file, " \n", WEBSITE); fprintf(file, " \n", "Emmanuel Bertin"); fprintf(file, " \n", "1996A&AS..117..393B"); fprintf(file, " \n", prefs.nthreads); fprintf(file, " \n", prefs.sdate_end); fprintf(file, " \n", prefs.stime_end); fprintf(file, " \n", prefs.time_diff); fprintf(file, " \n", psuser); fprintf(file, " \n", pshost); fprintf(file, " \n", pspath); fprintf(file, " 1) fprintf(file, ",%s", prefs.image_name[1]); fprintf(file, "\"/>\n"); if (error) { fprintf(file, "\n \n"); fprintf(file, " \n"); fprintf(file, " \n"); fprintf(file," \n", error); fprintf(file, " \n"); fprintf(file, " \n\n"); } /* Meta-data for each extension */ fprintf(file, "
\n"); fprintf(file, " Data gathered by %s for every FITS" " extension\n", BANNER); fprintf(file, " \n"); fprintf(file, " \n", nxmlmax); fprintf(file, " \n"); fprintf(file, " \n", nxml); fprintf(file, " \n"); fprintf(file, " \n"); fprintf(file, " \n"); fprintf(file, " \n"); fprintf(file, " \n"); fprintf(file, " \n"); fprintf(file, " \n"); fprintf(file, " \n", prefs.nimage_name); fprintf(file, " \n", prefs.nimage_name); fprintf(file, " \n", prefs.nimage_name); fprintf(file, " \n", prefs.nimage_name); fprintf(file, " \n", prefs.nimage_name); fprintf(file, " \n", prefs.nimage_name); fprintf(file, " \n"); for (n=0; n1) fprintf(file, " \n" " " "\n" " \n" " " "\n" " \n", xmlstack[n].currext, xmlstack[n].ext_date, xmlstack[n].ext_time, xmlstack[n].ext_elapsed, xmlstack[n].ndetect, xmlstack[n].ntotal, xmlstack[n].ident[0], xmlstack[n].ident[1], xmlstack[n].backmean[0], xmlstack[n].backmean[1], xmlstack[n].backsig[0], xmlstack[n].backsig[1], xmlstack[n].sigfac[0], xmlstack[n].sigfac[1], xmlstack[n].thresh[0], xmlstack[n].thresh[1], xmlstack[n].pixscale[0], xmlstack[n].pixscale[1], xmlstack[n].epoch[0], xmlstack[n].epoch[1]); else fprintf(file, " \n" " " "\n" " \n" " \n" " \n", xmlstack[n].currext, xmlstack[n].ext_date, xmlstack[n].ext_time, xmlstack[n].ext_elapsed, xmlstack[n].ndetect, xmlstack[n].ntotal, xmlstack[n].ident[0], xmlstack[n].backmean[0], xmlstack[n].backsig[0], xmlstack[n].sigfac[0], xmlstack[n].thresh[0], xmlstack[n].pixscale[0], xmlstack[n].epoch[0]); fprintf(file, " \n"); fprintf(file, "
%d%s%s%.0f%d%d%s,%s%g %g%g %g%g %g%g %g%g %g%f %f
%d%s%s%.0f%d%d%s%g%g%g%g%g%f
\n"); /* Warnings */ fprintf(file, " \n"); fprintf(file, " %s warnings (limited to the last %d)\n", BANNER, WARNING_NMAX); fprintf(file, " \n"); fprintf(file, " \n"); fprintf(file, " \n"); fprintf(file, " \n"); for (str = warning_history(); *str; str = warning_history()) fprintf(file, " \n", str, str+11, str+22); fprintf(file, " \n"); fprintf(file, "
%10.10s%8.8s%s
\n"); /* Configuration file */ fprintf(file, " \n"); fprintf(file, " %s configuration\n", BANNER); fprintf(file, " \n"); fprintf(file, " \n", prefs.prefs_name); if (!error) { fprintf(file, " \n", key[findkeys("CATALOG_TYPE",keylist, FIND_STRICT)].keylist[prefs.cat_type]); fprintf(file, " \n", prefs.cat_name); fprintf(file, " \n", prefs.param_name); fprintf(file, " \n", key[findkeys("DETECT_TYPE", keylist, FIND_STRICT)].keylist[prefs.detect_type]); fprintf(file, " \n", prefs.ext_minarea); fprintf(file, " 1) fprintf(file, ",%s", key[findkeys("THRESH_TYPE", keylist, FIND_STRICT)].keylist[prefs.thresh_type[1]]); fprintf(file, "\"/>\n"); fprintf(file, " 1) fprintf(file, " %g", prefs.dthresh[1]); fprintf(file, "\"/>\n"); fprintf(file, " 1) fprintf(file, " %g", prefs.thresh[1]); fprintf(file, "\"/>\n"); fprintf(file, " \n", prefs.filter_flag? 'T':'F'); fprintf(file, " \n", prefs.filter_name); if (prefs.nfilter_thresh) { fprintf(file, " 1) fprintf(file, " %g", prefs.filter_thresh[1]); fprintf(file, "\"/>\n"); } fprintf(file, " \n", prefs.deblend_nthresh); fprintf(file, " \n", prefs.deblend_mincont); fprintf(file, " \n", prefs.clean_flag? 'T':'F'); fprintf(file, " \n", prefs.clean_param); fprintf(file, " \n", key[findkeys("MASK_TYPE", keylist, FIND_STRICT)].keylist[prefs.mask_type]); fprintf(file, " 1) fprintf(file, ",%s", key[findkeys("WEIGHT_TYPE", keylist, FIND_STRICT)].keylist[prefs.weight_type[1]]); fprintf(file, "\"/>\n"); fprintf(file, " 1) fprintf(file, " %g", prefs.weight_thresh[1]); fprintf(file, "\"/>\n"); if ((prefs.weight_type[0] != WEIGHT_NONE && prefs.weight_type[0] != WEIGHT_FROMBACK) || (prefs.weight_type[1] != WEIGHT_NONE && prefs.weight_type[1] != WEIGHT_FROMBACK)) { fprintf(file, " \n"); } fprintf(file, " \n", prefs.weightgain_flag? 'T':'F'); if (prefs.nimaflag) { fprintf(file, " \n"); fprintf(file, " \n"); } fprintf(file, " \n"); fprintf(file, " \n"); fprintf(file, " \n"); fprintf(file, " \n"); fprintf(file, " \n"); fprintf(file, " \n", prefs.satur_level); fprintf(file, " \n", prefs.mag_zeropoint); fprintf(file, " \n", prefs.mag_gamma); fprintf(file, " \n", prefs.gain); fprintf(file, " \n", prefs.pixel_scale); fprintf(file, " \n", prefs.seeing_fwhm); fprintf(file, " \n", prefs.nnw_name); fprintf(file, " \n"); fprintf(file, " \n"); fprintf(file, " \n", key[findkeys("BACKPHOTO_TYPE", keylist, FIND_STRICT)].keylist[prefs.pback_type]); fprintf(file, " \n", prefs.pback_size); fprintf(file, " \n", prefs.backfthresh); fprintf(file, " \n"); fprintf(file, " \n"); fprintf(file, " \n", prefs.clean_stacksize); fprintf(file, " \n", prefs.mem_pixstack); fprintf(file, " \n", prefs.mem_bufsize); fprintf(file, " \n", prefs.assoc_name); if (prefs.nassoc_data) { fprintf(file, " \n"); } if (prefs.nassoc_param) { fprintf(file, " \n"); } fprintf(file, " \n", prefs.assoc_radius); fprintf(file, " \n", key[findkeys("ASSOC_TYPE", keylist, FIND_STRICT)].keylist[prefs.assoc_type]); fprintf(file, " \n", key[findkeys("ASSOCSELEC_TYPE", keylist, FIND_STRICT)].keylist[prefs.assocselec_type]); fprintf(file, " \n", key[findkeys("VERBOSE_TYPE", keylist, FIND_STRICT)].keylist[prefs.verbose_type]); fprintf(file, " \n", prefs.fitsunsigned_flag? 'T':'F'); fprintf(file, " \n", prefs.psf_name[0]); fprintf(file, " \n", prefs.psf_npsfmax); fprintf(file, " \n", key[findkeys("PSFDISPLAY_TYPE", keylist, FIND_STRICT)].keylist[prefs.psfdisplay_type]); fprintf(file, " \n", prefs.som_name); } fprintf(file, " \n"); fprintf(file, "
\n"); return RETURN_OK; } /****** write_xmlerror ****************************************************** PROTO int write_xmlerror(char *error) PURPOSE Save meta-data to a simplified XML file in case of a catched error INPUT a character string. OUTPUT RETURN_OK if everything went fine, RETURN_ERROR otherwise. NOTES -. AUTHOR E. Bertin (IAP) VERSION 14/07/2006 ***/ void write_xmlerror(char *filename, char *error) { FILE *file; if (!(file = fopen(filename, "w"))) return; write_xml_header(file); fprintf(file, " \n"); write_xml_meta(file, error); fprintf(file, "\n"); fprintf(file, "
\n"); fclose(file); return; }