Exemple #1
0
int ebcdic_format(const u_char *buf, size_t len, u_char *dst)
{
   u_int i = 0;
   
   /* some sanity checks */
   if (len == 0 || buf == NULL) {
      strncpy(dst, "", 1);
      return 0;
   }
   
   /* convert from ebcdic to ascii */
   for(i = 0; i < len; i++)
      dst[i] = (char) EBCDIC_to_ASCII[(u_int8)buf[i]];
   
   return ascii_format(dst, len, dst);
}
Exemple #2
0
/***********************************************************************//**
 * @brief Print column information
 *
 * @param[in] chatter Chattiness (defaults to NORMAL).
 * @return String containing column information.
 *
 * @todo Format and cfitsio information is mainly for debugging. This could
 * vanish in a more stable version of the code, or it could be compiled-in
 * conditionally using a debug option. Alternatively, a higher chatter level
 * may be required to see this information.
 ***************************************************************************/
std::string GFitsTableCol::print(const GChatter& chatter) const
{
    // Initialise result string
    std::string result;

    // Continue only if chatter is not silent
    if (chatter != SILENT) {

        // Append formatted column name. Optionally add units
        if (unit().length() > 0) {
            result.append(gammalib::parformat(name()+" ("+unit()+")"));
        }
        else {
            result.append(gammalib::parformat(name()));
        }

        // Append column number. This will be "-" if the column does not exist
        // in the FITS file.
        if (m_colnum > 0) {
            result.append(gammalib::right(gammalib::str(m_colnum),4)+" ");
        }
        else {
            result.append(gammalib::right("[-]",4)+" ");
        }

        // Append loading information
        if (is_loaded()) {
            result.append("[loaded]     ");
        }
        else {
            result.append("[not loaded] ");
        }

        // Append format information
        result.append("["+tform_binary()+","+ascii_format()+"]");

        // Append dimensions (if available)
        if (!dim().empty()) {
    
            // Build TDIM string
            std::string value = "("+gammalib::str(dim()[0]);
            for (int k = 1; k < dim().size(); ++k) {
                value += ","+gammalib::str(dim()[k]);
            }
            value += ")";
        
            // Append
            result.append(" "+value);
        }

        // Append cfitsio information
        if (is_variable()) {
            result.append(" repeat=" + gammalib::str(repeat()));
            result.append(" width="  + gammalib::str(width()));
            result.append(" number=" + gammalib::str(number()));
            result.append(" length=" + gammalib::str(length()));
            result.append(" size="   + gammalib::str(m_size));
            result.append(" varlen=");
            if (m_varlen > 0) {
                result.append(gammalib::str(m_varlen));
            }
            else {
                result.append("undetermined");
            }
        }
        else {
            result.append(" repeat=" + gammalib::str(repeat()));
            result.append(" width="  + gammalib::str(width()));
            result.append(" number=" + gammalib::str(number()));
            result.append(" length=" + gammalib::str(length()));
            result.append(" size="   + gammalib::str(m_size));
        }

    } // endif: chatter was not silent

    // Compile option: print content
    #if defined(G_PRINT_CONTENT)
    if (chatter != SILENT) {

        // Fetch data if necessary
        if (!is_loaded()) fetch_data();

        // Loop over all rows
        for (int row = 0; row < length(); ++row) {
            result.append("\n");
            if (is_variable()) {
                result.append("start=");
                result.append(gammalib::str(m_rowstart[row]));
                result.append(":");
            }
            for (int inx = 0; inx < elements(row); ++inx) {
                result.append(" "+string(row, inx));
            }
        }
        if (is_variable()) {
            result.append("\nend=");
            result.append(gammalib::str(m_rowstart[length()]));
        }
    }
    #endif

    // Return result
    return result;
}