Exemple #1
0
static void ensure_row_list_exists(fitstable_t* table) {
	if (!table->rows) {
		// how big are the rows?
		int rowsize = offset_of_column(table, bl_size(table->cols));
		table->rows = bl_new(1024, rowsize);
	}
}
Exemple #2
0
int fitstable_write_one_column(fitstable_t* table, int colnum,
                               int rowoffset, int nrows,
                               const void* src, int src_stride) {
	anbool flip = TRUE;
    off_t foffset = 0;
    off_t start = 0;
    int i;
    char* buf = NULL;
    fitscol_t* col;
	int off;

	off = offset_of_column(table, colnum);
	if (!in_memory(table)) {
		foffset = ftello(table->fid);
		// jump to row start...
		start = get_row_offset(table, rowoffset) + off;
		if (fseeko(table->fid, start, SEEK_SET)) {
			SYSERROR("Failed to fseeko() to the start of the file.");
			return -1;
		}
	}

    col = getcol(table, colnum);
    if (col->fitstype != col->ctype) {
		int sz = col->fitssize * col->arraysize * nrows;
        buf = malloc(sz);
        fits_convert_data(buf, col->fitssize * col->arraysize, col->fitstype,
                          src, src_stride, col->ctype,
                          col->arraysize, nrows);
        src = buf;
        src_stride = col->fitssize * col->arraysize;
    }

	if (in_memory(table)) {
		for (i=0; i<nrows; i++) {
			memcpy(((char*)bl_access(table->rows, rowoffset + i)) + off,
				   src, col->fitssize * col->arraysize);
			src = ((const char*)src) + src_stride;
		}
	} else {
		for (i=0; i<nrows; i++) {
			if (fseeko(table->fid, start + i * table->table->tab_w, SEEK_SET) ||
				fits_write_data_array(table->fid, src, col->fitstype, col->arraysize, flip)) {
				SYSERROR("Failed to write row %i of column %i", rowoffset+i, colnum);
				return -1;
			}
			src = ((const char*)src) + src_stride;
		}
	}
    free(buf);

	if (!in_memory(table)) {
		if (fseeko(table->fid, foffset, SEEK_SET)) {
			SYSERROR("Failed to restore file offset.");
			return -1;
		}
	}
    return 0;
}
bool condition_op_const::eval(record_type& rt, record& r){
	if (offset==-1){
		offset = offset_of_column(rt, lhs_table_name, lhs_column_name);
		if (offset==-1) throw string("Undefined column");
	}
	if (index==-1){
		index = index_of_column(rt, lhs_table_name, lhs_column_name);
		if (index==-1) throw string("Undefined column");
	}

	if (rt[index].type == column_type::INT){

		if (op=="<"){
			return AS_INT(r[offset]) < value.vInt;
		} else if (op=="="){
			return AS_INT(r[offset]) == value.vInt;
		} else if (op==">"){
			return AS_INT(r[offset]) > value.vInt;
		}

		throw string("unimplemented operators in condition_op_const");
	}
	else if(rt[index].type == column_type::FLOAT){

		if (op=="<"){
			return AS_FLOAT(r[offset]) < value.vFloat;
		} else if (op=="="){
			return AS_FLOAT(r[offset]) == value.vFloat;
		} else if (op==">"){
			return AS_FLOAT(r[offset]) > value.vFloat;
		}
		throw string("unimplemented operators in condition_op_const");
	}
	else if(rt[index].type == column_type::STRING){

		if (op=="<"){
			return (strncmp(AS_STRING(r[offset]), value.vString, 500) < 0);
		} else if (op=="="){
			return (strncmp(AS_STRING(r[offset]), value.vString, 500) == 0);
		} else if (op==">"){
			return (strncmp(AS_STRING(r[offset]), value.vString, 500) > 0);
		}

		throw string("unimplemented operators in condition_op_const");
	}
	//throw string("unimplemented datatypes in condition_op_const");

}
Exemple #4
0
int fitstable_read_structs(fitstable_t* tab, void* struc,
                           int strucstride, int offset, int N) {
    int i;
    void* tempdata = NULL;
    int highwater = 0;

    //printf("fitstable_read_structs: stride %i, offset %i, N %i\n",strucstride, offset, N);

    for (i=0; i<ncols(tab); i++) {
        void* dest;
        int stride;
        void* finaldest;
        int finalstride;
        fitscol_t* col = getcol(tab, i);
        if (col->col == -1)
            continue;
        if (!col->in_struct)
            continue;
        finaldest = ((char*)struc) + col->coffset;
        finalstride = strucstride;

        if (col->fitstype != col->ctype) {
            int NB = fitscolumn_get_size(col) * N;
            if (NB > highwater) {
                free(tempdata);
                tempdata = malloc(NB);
                highwater = NB;
            }
            dest = tempdata;
            stride = fitscolumn_get_size(col);
        } else {
            dest = finaldest;
            stride = finalstride;
        }

		if (in_memory(tab)) {
			int j;
			int off = offset_of_column(tab, i);
			int sz;
			if (!tab->rows) {
				ERROR("No data has been written to this fitstable");
				return -1;
			}
			if (offset + N > bl_size(tab->rows)) {
				ERROR("Number of data items requested exceeds number of rows: offset %i, n %i, nrows %zu", offset, N, bl_size(tab->rows));
				return -1;
			}

			//logverb("column %i: dest offset %i, stride %i, row offset %i, input offset %i, size %i (%ix%i)\n", i, (int)(dest - struc), stride, offset, off, fitscolumn_get_size(col), col->fitssize, col->arraysize);
			sz = fitscolumn_get_size(col);
			for (j=0; j<N; j++)
				memcpy(((char*)dest) + j * stride,
					   ((char*)bl_access(tab->rows, offset+j)) + off,
					   sz);
		} else {
			// Read from FITS file...
			qfits_query_column_seq_to_array(tab->table, col->col, offset, N, dest, stride);
		}

        if (col->fitstype != col->ctype) {
            fits_convert_data(finaldest, finalstride, col->ctype,
                              dest, stride, col->fitstype,
                              col->arraysize, N);
        }
    }
    free(tempdata);

    if (tab->postprocess_read_structs)
        return tab->postprocess_read_structs(tab, struc, strucstride, offset, N);

    return 0;
}
Exemple #5
0
int fitstable_get_struct_size(const fitstable_t* table) {
	int rowsize = offset_of_column(table, bl_size(table->cols));
	return rowsize;
}