示例#1
0
文件: ctbin.cpp 项目: adonath/ctools
/***********************************************************************//**
 * @brief Save counts map(s) in XML format.
 *
 * Save the counts map(s) into FITS files and write the file path information
 * into a XML file. The filename of the XML file is specified by the
 * m_outfile member, the filename(s) of the counts map(s) are built by
 * prepending the prefix given by the m_prefix member to the input counts
 * map(s) filenames. Any path present in the input filename will be stripped,
 * i.e. the counts map(s) will be written in the local working directory
 * (unless a path is specified in the m_prefix member).
 ***************************************************************************/
void ctbin::save_xml(void)
{
    // Get output filename and prefix
    m_outfile = (*this)["outfile"].filename();
    m_prefix  = (*this)["prefix"].string();

    // Loop over all observation in the container
    for (int i = 0; i < m_obs.size(); ++i) {

        // Get CTA observation
        GCTAObservation* obs = dynamic_cast<GCTAObservation*>(&m_obs[i]);

        // Handle only CTA observations
        if (obs != NULL) {

            // Set event output file name
            std::string outfile = set_outfile_name(m_infiles[i]);

            // Store output file name in observation
            obs->eventfile(outfile);

            // Save event list
            save_counts_map(obs, outfile);

        } // endif: observation was a CTA observations

    } // endfor: looped over observations

    // Save observations in XML file
    m_obs.save(m_outfile);

    // Return
    return;
}
int main(int argc, char *argv[])
{
  if (argc <= 1) {
    printf("usage: %s $FILE", argv[0]);
    return 0;
  }

  char infile[strlen(argv[1])+1];
  strcpy(infile, argv[1]);

  set_outfile_name(argv[1]);

  FILE* fp_read;
  FILE* fp_write;

  if ((fp_read = fopen(infile, "r")) == NULL)
  {
    perror("fopen failed");
    return 1;
  }

  int linecount;
  char buf[bufSize];

  linecount = 0;
  fp_write = rtn_write_fp(fp_write);

  while (fgets(buf, sizeof(buf), fp_read) != NULL)
  {
    if((linecount % max_linecount) == 0 && linecount != 0){
      fp_write = rtn_write_fp(fp_write);
    }

    buf[21] = '\0';
    char *token = strtok(buf+6, "\"");

    fputs(token, fp_write);
    fputs("\n", fp_write);

    linecount += 1;
  }

  fclose(fp_read);
  fclose(fp_write);

  return 0;
}
示例#3
0
/***********************************************************************//**
 * @brief Save model map(s) in XML format.
 *
 * Save the model map(s) into FITS files and write the file path information
 * into a XML file. The filename of the XML file is specified by the
 * m_outfile member, the filename(s) of the model map(s) are built by
 * prepending the prefix given by the m_prefix member to the input model
 * map(s) filenames. Any path present in the input filename will be stripped,
 * i.e. the model map(s) will be written in the local working directory
 * (unless a path is specified in the m_prefix member).
 ***************************************************************************/
void ctmodel::save_xml(void)
{
    // Get output filename and prefix
    m_outfile = (*this)["outfile"].filename();
    m_prefix  = (*this)["prefix"].string();

    // Issue warning if output filename has no .xml suffix
    std::string suffix = gammalib::tolower(m_outfile.substr(m_outfile.length()-4,4));
    if (suffix != ".xml") {
        log << "*** WARNING: Name of observation definition output file \""+
            m_outfile+"\"" << std::endl;
        log << "*** WARNING: does not terminate with \".xml\"." << std::endl;
        log << "*** WARNING: This is not an error, but might be misleading."
            " It is recommended" << std::endl;
        log << "*** WARNING: to use the suffix \".xml\" for observation"
            " definition files." << std::endl;
    }

    // Loop over all observation in the container
    for (int i = 0; i < m_obs.size(); ++i) {

        // Get CTA observation
        GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]);

        // Handle only CTA observations
        if (obs != NULL) {

            // Set event output file name
            std::string outfile = set_outfile_name(m_infiles[i]);

            // Store output file name in observation
            obs->eventfile(outfile);

            // Save event list
            save_model_map(obs, outfile);

        } // endif: observation was a CTA observations

    } // endfor: looped over observations

    // Save observations in XML file
    m_obs.save(m_outfile);

    // Return
    return;
}