Exemplo n.º 1
0
void xmlLogger::log(char *type, char *key, long value)
{
#if USE_PC_LOGGER
  /** Algorithm: */
  /** Check to see if logging is enabled. */
  if(m_logging_enabled)
  {
    /** Open a new tag, and write the key and value pair to it. */
    openTag(type);
    writeTagAttr(key, value);
    /** Write the current time in ms to the tag and then close it. */
    writeTagAttr("time", getTime());
    closeTag();
  }
#endif
}
Exemplo n.º 2
0
void xmlLogger::log(char *type, int f1, int f2, int f3, int f4)
{
#if USE_PC_LOGGER
  /** Algorithm: */
  /** Check to see if logging is enabled. */
  if(m_logging_enabled)
  {
    /** Open a new tag, then log each of the floating point arguments to it. */
    openTag(type);
    /** Write all three arguments to the tag. */
    writeTagAttr("arg1", f1);
    writeTagAttr("arg2", f2);
    writeTagAttr("arg3", f3);
    writeTagAttr("arg4", f4);
    /** Add the time and then close the tag. */
    writeTagAttr("time", getTime());
    closeTag();
  }
#endif
}
Exemplo n.º 3
0
void xmlLogger::log(char *type)
{
#if USE_PC_LOGGER
  /** Algorithm: */
  /** Check to see if logging is enabled. */
  if(m_logging_enabled)
  {
    /** Open a new tag, write the current time to it, and close it. */
    openTag(type);
    writeTagAttr("time", getTime());
    closeTag();
  }
#endif
}
Exemplo n.º 4
0
void xmlLogger::logData(char *type, void *data, int length)
{
#if USE_PC_LOGGER
  /** Algorithm: */
  /** Check to see if logging is enabled. */
  if(m_logging_enabled)
  {
    /** Open a new tag and then log the data stream to it.  The tag will be automatically
    * closed afterwards. */
    openTag(type);
    writeTagAttr("time", getTime());
    writeTagData(data, length);
  }
#endif
}
Exemplo n.º 5
0
void xmlLogger::log(char *type, char *key, char *value)
{
#if USE_PC_LOGGER
  /** Algorithm: */
  /** Check to see if logging is enabled. */
  if(m_logging_enabled)
  {
    /** Open a new tag, and write the key and value pair to it. */
    openTag(type);
    if(value == NULL)
    {
      char emptyquotes[3] = "\"\"";
      writeTagAttr(key, emptyquotes);
    }
    else
    {
      writeTagAttr(key, value);
    }
    /** Write the current time in ms to the tag and then close it. */
    writeTagAttr("time", getTime());
    closeTag();
  }
#endif
}
Exemplo n.º 6
0
void xmlLogger::startSession()
{
#if USE_PC_LOGGER
  /** Algorithm: */
  /** Open up a new tag to enclose the session. */
  openTag("session");
  
  /** Get the current system date and time and log it in the session tag. */
  struct tm *t = (struct tm*)malloc(sizeof(struct tm));
  time_t now = time(NULL);
  t = localtime(&now);
  char str[32];
  snprintf(str, 32, "%02d:%02d:%02d %02d/%02d/%04d", t->tm_hour, t->tm_min, t->tm_sec,
           t->tm_mday + 1, t->tm_mon + 1, t->tm_year + 1900);
  writeTagAttr("date", str);
#endif
}
Exemplo n.º 7
0
void write_phcx(char* fileName, phcx* cand) {
    FILE* file;
    int indent;
    int i, block, s;
    int sb, si, bin;
    int p, d, a, j;
    int count;
    char *attr[64];
    char content[1024];

    double max, min;

    for (i = 0; i < 64; i++)
        attr[i] = (char*) malloc(1024);

    indent = 0;

    file = fopen(fileName, "w");
    fprintf(file, "<?xml version='1.0'?>\n");
    openTag(file, &indent, "phcf"); // <phcf>
    openTag(file, &indent, "head"); // <head>
    writeTag(file, &indent, "SourceID", cand->header.sourceID);
    writeTag(file, &indent, "Telescope", cand->header.telescope);

    openTag(file, &indent, "Coordinate"); // <Coordinate>
    strcpy(attr[0], "units");
    strcpy(attr[1], "degrees");
    sprintf(content, "%lf", cand->header.ra);
    writeTagAttr(file, &indent, "RA", attr, 1, content);
    sprintf(content, "%lf", cand->header.dec);
    writeTagAttr(file, &indent, "Dec", attr, 1, content);
    writeTag(file, &indent, "Epoch", "J2000");
    closeTag(file, &indent, "Coordinate"); //</Coordinate>

    strcpy(attr[0], "units");
    strcpy(attr[1], "MHz");
    sprintf(content, "%lf", cand->header.centreFreq);
    writeTagAttr(file, &indent, "CentreFreq", attr, 1, content);
    sprintf(content, "%lf", cand->header.bandwidth);
    writeTagAttr(file, &indent, "BandWidth", attr, 1, content);
    sprintf(content, "%lf", cand->header.mjdStart);
    writeTag(file, &indent, "MjdStart", content);
    strcpy(attr[0], "units");
    strcpy(attr[1], "seconds");
    sprintf(content, "%lf", cand->header.observationLength);
    writeTagAttr(file, &indent, "ObservationLength", attr, 1, content);
    for (i = 0; i < cand->nextrakey; i++) {
        strcpy(content,cand->extravalue[i]);
        strcpy(attr[0],cand->extrakey[i]);
        writeTagAttr(file, &indent, "Extra", attr, 1, content);
    }
    closeTag(file, &indent, "head"); //</head>


    for (s = 0; s < cand->nsections; s++) {
        phcx_section* section = cand->sections + s;
        strcpy(attr[0], "name");
        strcpy(attr[1], section->name);
        openTagAttr(file, &indent, "Section", attr, 1);
        openTag(file, &indent, "BestValues");
        strcpy(attr[0], "units");
        strcpy(attr[1], "seconds");
        sprintf(content, "%16.14lf", section->bestTopoPeriod);
        writeTagAttr(file, &indent, "TopoPeriod", attr, 1, content);
        sprintf(content, "%16.14lf", section->bestBaryPeriod);
        writeTagAttr(file, &indent, "BaryPeriod", attr, 1, content);
        sprintf(content, "%lf", section->bestDm);
        writeTag(file, &indent, "Dm", content);
        strcpy(attr[1], "m/s/s");
        sprintf(content, "%lf", section->bestAccn);
        writeTagAttr(file, &indent, "Accn", attr, 1, content);
        strcpy(attr[1], "m/s/s/s");
        sprintf(content, "%lf", section->bestJerk);
        writeTagAttr(file, &indent, "Jerk", attr, 1, content);

        sprintf(content, "%lf", section->bestSnr);
        writeTag(file, &indent, "Snr", content);

        sprintf(content, "%lf", section->bestWidth);
        writeTag(file, &indent, "Width", content);

        closeTag(file, &indent, "BestValues");
        sprintf(content, "%lf", section->tsamp);
        writeTag(file, &indent, "SampleRate", content);

        if (section->subints != NULL) {
            maxmin(section->subints, section->nsubints, section->nbins, &max, &min);
            strcpy(attr[0], "nBins");
            sprintf(attr[1], "%d", section->nbins);
            strcpy(attr[2], "nSub");
            sprintf(attr[3], "%d", section->nsubints);
            strcpy(attr[4], "format");
            strcpy(attr[5], "02X");
            strcpy(attr[6], "min");
            sprintf(attr[7], "%lf", min);
            strcpy(attr[8], "max");
            sprintf(attr[9], "%lf", max);


            openTagAttr(file, &indent, "SubIntegrations", attr, 5);
            hexprint(section->subints, section->nsubints, section->nbins, max, min, file);
            closeTag(file, &indent, "SubIntegrations");
        }

        if (section->subbands != NULL) {
            maxmin(section->subbands, section->nsubbands, section->nbins, &max, &min);
            strcpy(attr[0], "nBins");
            sprintf(attr[1], "%d", section->nbins);
            strcpy(attr[2], "nSub");
            sprintf(attr[3], "%d", section->nsubbands);
            strcpy(attr[4], "format");
            strcpy(attr[5], "02X");
            strcpy(attr[6], "min");
            sprintf(attr[7], "%lf", min);
            strcpy(attr[8], "max");
            sprintf(attr[9], "%lf", max);



            openTagAttr(file, &indent, "SubBands", attr, 5);
            hexprint(section->subbands, section->nsubbands, section->nbins, max, min, file);
            closeTag(file, &indent, "SubBands");
        }
        if (section->pulseProfile != NULL) {

            maxmin(&(section->pulseProfile), 1, section->nbins, &max, &min);
            strcpy(attr[0], "nBins");
            sprintf(attr[1], "%d", section->nbins);
            strcpy(attr[2], "format");
            strcpy(attr[3], "02X");
            strcpy(attr[4], "min");
            sprintf(attr[5], "%lf", min);
            strcpy(attr[6], "max");
            sprintf(attr[7], "%lf", max);


            openTagAttr(file, &indent, "Profile", attr, 4);
            hexprint(&(section->pulseProfile), 1, section->nbins, max, min, file);
            closeTag(file, &indent, "Profile");
        }
        if (section->snrBlock.block != NULL) {
            openTag(file, &indent, "SnrBlock");
            strcpy(attr[0], "nVals");
            sprintf(attr[1], "%d", section->snrBlock.nperiod);
            strcpy(attr[2], "format");
            strcpy(attr[3], "16.12f");
            openTagAttr(file, &indent, "PeriodIndex", attr, 2);
            for (i = 0; i < section->snrBlock.nperiod; i++) {
                fprintf(file, "%1.12f\n", section->snrBlock.periodIndex[i]);
            }
            closeTag(file, &indent, "PeriodIndex");

            strcpy(attr[0], "nVals");
            sprintf(attr[1], "%d", section->snrBlock.ndm);
            strcpy(attr[2], "format");
            strcpy(attr[3], "6.4f");
            openTagAttr(file, &indent, "DmIndex", attr, 2);
            for (i = 0; i < section->snrBlock.ndm; i++) {
                fprintf(file, "%6.4f\n", section->snrBlock.dmIndex[i]);
            }
            closeTag(file, &indent, "DmIndex");

            strcpy(attr[0], "nVals");
            sprintf(attr[1], "%d", section->snrBlock.naccn);
            strcpy(attr[2], "format");
            strcpy(attr[3], "6.4f");
            openTagAttr(file, &indent, "AccnIndex", attr, 2);
            for (i = 0; i < section->snrBlock.naccn; i++) {
                fprintf(file, "%6.4f\n", section->snrBlock.accnIndex[i]);
            }
            closeTag(file, &indent, "AccnIndex");

            strcpy(attr[0], "nVals");
            sprintf(attr[1], "%d", section->snrBlock.njerk);
            strcpy(attr[2], "format");
            strcpy(attr[3], "6.4f");
            openTagAttr(file, &indent, "JerkIndex", attr, 2);
            for (i = 0; i < section->snrBlock.njerk; i++) {
                fprintf(file, "%6.4f\n", section->snrBlock.jerkIndex[i]);
            }
            closeTag(file, &indent, "JerkIndex");

            max = -1e200;
            min = 1e200;
            for (d = 0; d < section->snrBlock.ndm; d++) {
                for (p = 0; p < section->snrBlock.nperiod; p++) {
                    for (a = 0; a < section->snrBlock.naccn; a++) {
                        for (j = 0; j < section->snrBlock.njerk; j++) {
                            if (section->snrBlock.block[d][p][a][j] > max)max = section->snrBlock.block[d][p][a][j];
                            if (section->snrBlock.block[d][p][a][j] < min)min = section->snrBlock.block[d][p][a][j];

                        }
                    }
                }
            }

            strcpy(attr[0], "format");
            sprintf(attr[1], "02X");
            strcpy(attr[2], "min");
            sprintf(attr[3], "%lf", min);
            strcpy(attr[4], "max");
            sprintf(attr[5], "%lf", max);
            openTagAttr(file, &indent, "DataBlock", attr, 3);
            count = 0;
            for (d = 0; d < section->snrBlock.ndm; d++) {
                for (p = 0; p < section->snrBlock.nperiod; p++) {
                    for (a = 0; a < section->snrBlock.naccn; a++) {
                        for (j = 0; j < section->snrBlock.njerk; j++) {
                            i = (int) (255*(section->snrBlock.block[d][p][a][j] - min) / (max - min) + 0.5);
                            fprintf(file, "%02X", i);
                            count++;
                            if (count == 40) {
                                fprintf(file, "\n");
                                count = 0;
                            }
                        }
                    }
                }
            }

            closeTag(file, &indent, "DataBlock");


            closeTag(file, &indent, "SnrBlock");
        }
        for (i = 0; i < section->nextrakey; i++) {
            strcpy(content,section->extravalue[i]);
            strcpy(attr[0],"key");
            strcpy(attr[1],section->extrakey[i]);

            writeTagAttr(file, &indent, "SecExtra", attr, 1, content);
        }

        closeTag(file, &indent, "Section");




    }
    closeTag(file, &indent, "phcf");

    fclose(file);

}