示例#1
0
/***********************************************************************//**
 * @brief Save table column into FITS file
 *
 * @exception GException::fits_hdu_not_found
 *            Specified HDU not found in FITS file.
 * @exception GException::fits_error
 *            Error occured during writing of the column data.
 *
 * Save Bit (vector) column into FITS file by writing 8 Bits at once.
 ***************************************************************************/
void GFitsTableBitCol::save_column(void)
{
    // Continue only if a FITS file is connected and data have been loaded
    if (FPTR(m_fitsfile)->Fptr != NULL && m_colnum > 0 && m_data != NULL) {

        // Set any pending Bit
        set_pending();

        // Move to the HDU
        int status = 0;
        status     = __ffmahd(FPTR(m_fitsfile),
                              (FPTR(m_fitsfile)->HDUposition)+1, NULL,
                              &status);
        if (status != 0) {
            throw GException::fits_hdu_not_found(G_SAVE_COLUMN,
                              (FPTR(m_fitsfile)->HDUposition)+1,
                              status);
        }

        // Save data 8 Bits at once
        status = __ffpcn(FPTR(m_fitsfile), __TBYTE, m_colnum, 1, 1,
                         m_size, m_data, m_nulval, &status);
        if (status != 0) {
            throw GException::fits_error(G_SAVE_COLUMN, status);
        }

    } // endif: FITS file was connected

    // Return
    return;
}
示例#2
0
void init_pending_list(int index, long size, struct timeval time)
{
  pending_list * pending = &(rcvdb[index].pending);
  if (! pending->is_pending)
  {
    pending->is_pending = 1;
    pending->deadline = time;
    pending->last_write = time;
    pending->writes[0].size = size;
    pending->writes[0].delta = 0;
    pending->current_index = 0;
    pending->free_index = 1;

    set_pending(index, &write_fds);
  }
}
示例#3
0
void usignal::do_sigs()
{
	/*
	 * set off sig_pending before calling chksig ...
	 * otherwise user handling function might set and
	 * restore signals ... leading to a recursive call
	 * to do_sigs
	 */
	set_pending(0);

	chksig(SIGHUP);
	chksig(SIGINT);
	chksig(SIGQUIT);
	chksig(SIGALRM);
	chksig(SIGTERM);
	chksig(SIGUSR1);
	chksig(SIGUSR2);
}
示例#4
0
/***********************************************************************//**
 * @brief Column data access operator
 *
 * @param[in] row Row of column to access.
 * @param[in] inx Vector index in column row to access.
 *
 * Provides access to data in a column.
 ***************************************************************************/
bool& GFitsTableBitCol::operator()(const int& row, const int& inx)
{
    // If data are not available then load them now
    if (m_data == NULL) this->fetch_data();

    // Set any pending Bit
    set_pending();

    // Get Bit
    get_bit(row, inx);

    // Signal that a Bit is pending. We need this here since the non-const
    // operator allows changing the Bit after exiting the method, hence
    // we have to signal that the actual value of 'm_bit_value' could have
    // been modified and needs to be written back into the data array.
    m_bit_pending = true;

    // Return Bit
    return m_bit_value;
}
示例#5
0
/***********************************************************************//**
 * @brief Remove rows from column
 *
 * @param[in] row Row after which rows should be removed (0=first row).
 * @param[in] nrows Number of rows to be removed.
 *
 * @exception GException::fits_invalid_row
 *            Specified row is invalid.
 * @exception GException::fits_invalid_nrows
 *            Invalid number of rows specified.
 *
 * This method removes rows from a FITS table. This implies that the column
 * will be loaded into memory.
 ***************************************************************************/
void GFitsTableBitCol::remove(const int& row, const int& nrows)
{
    // Make sure that row is valid
    if (row < 0 || row >= m_length) {
        throw GException::fits_invalid_row(G_REMOVE, row, m_length-1);
    }
    
    // Make sure that we don't remove beyond the limit
    if (nrows < 0 || nrows > m_length-row) {
        throw GException::fits_invalid_nrows(G_REMOVE, nrows, m_length-row);
    }
    
    // Continue only if there are rows to be removed
    if (nrows > 0) {
    
        // If data are not available then load them now
        if (m_data == NULL) fetch_data();

        // Set any pending Bit
        set_pending();

        // Compute new column length
        int length = m_length - nrows;
        
        // Compute total number of Bits in column
        m_bits = m_number * length;

        // Compute number of Bytes and Bits per row
        m_bytes_per_row = (m_number > 0) ? ((m_number-1) / 8) + 1 : 0;
        m_bits_per_row  = m_bytes_per_row * 8;

        // Compute length of memory array
        m_size = m_bytes_per_row * length;
        
        // If we have rows remaining then allocate new data to hold
        // the column
        if (m_size > 0) {
        
            // Allocate new data to hold the column
            unsigned char* new_data = new unsigned char[m_size];

            // Compute the number of elements before the removal point,
            // the number of elements that get removed, and the total
            // number of elements after the removal point
            int n_before = m_bytes_per_row * row;
            int n_remove = m_bytes_per_row * nrows;
            int n_after  = m_bytes_per_row * (length - row);

            // Copy data
            unsigned char* src = m_data;
            unsigned char* dst = new_data;
            for (int i = 0; i < n_before; ++i) {
                *dst++ = *src++;
            }
            src += n_remove;
            for (int i = 0; i < n_after; ++i) {
                *dst++ = *src++;
            }
        
            // Free old data
            if (m_data != NULL) delete [] m_data;
            
            // Set pointer to new data and store length
            m_data   = new_data;
            m_length = length;
        
        } // endif: there are still elements after removal
        
        // ... otherwise just remove all data
        else {

            // Free old data
            if (m_data != NULL) delete [] m_data;

            // Set pointer to new data and store length
            m_data   = NULL;
            m_length = length;
        }
    
    } // endfor: there were rows to be removed

    // Return
    return;
}
示例#6
0
/***********************************************************************//**
 * @brief Insert rows in column
 *
 * @param[in] row Row after which rows should be inserted (0=first row).
 * @param[in] nrows Number of rows to be inserted.
 *
 * @exception GException::fits_invalid_row
 *            Specified row is invalid.
 *
 * Inserts rows into a FITS table. This implies that the column will be
 * loaded into memory.
 ***************************************************************************/
void GFitsTableBitCol::insert(const int& row, const int& nrows)
{
    // Make sure that row is valid
    if (row < 0 || row > m_length) {
        throw GException::fits_invalid_row(G_INSERT, row, m_length);
    }
    
    // Continue only if there are rows to be inserted
    if (nrows > 0) {
    
        // If we have no rows yet then simply set the length to the
        // number of rows to be inserted
        if (m_length == 0) {
            m_length = nrows;
            m_size   = m_number * m_length;
            alloc_data();
            init_data();
        }
        
        // ... otherwise fetch data, allocate new data and copy over
        // the existing items
        else {

            // If data are not available then load them now
            if (m_data == NULL) fetch_data();

            // Set any pending Bit
            set_pending();

            // Compute new column length
            int length = m_length + nrows;

            // Compute total number of Bits in column
            m_bits = m_number * length;

            // Compute number of Bytes and Bits per row
            m_bytes_per_row = (m_number > 0) ? ((m_number-1) / 8) + 1 : 0;
            m_bits_per_row  = m_bytes_per_row * 8;

            // Compute length of memory array
            m_size = m_bytes_per_row * length;
        
            // Allocate new data to hold the column
            unsigned char* new_data = new unsigned char[m_size];

            // Compute the number of elements before the insertion point,
            // the number of elements that get inserted, and the total
            // number of elements after the insertion point
            int n_before = m_bytes_per_row * row;
            int n_insert = m_bytes_per_row * nrows;
            int n_after  = m_bytes_per_row * (m_length - row);

            // Copy and initialise data
            unsigned char* src = m_data;
            unsigned char* dst = new_data;
            for (int i = 0; i < n_before; ++i) {
                *dst++ = *src++;
            }
            for (int i = 0; i < n_insert; ++i) {
                *dst++ = 0;
            }
            for (int i = 0; i < n_after; ++i) {
                *dst++ = *src++;
            }
        
            // Free old data
            if (m_data != NULL) delete [] m_data;
            
            // Set pointer to new data and store length
            m_data   = new_data;
            m_length = length;
        
        } // endelse: there were already data
    
    } // endfor: there were rows to be inserted

    // Return
    return;
}