// CONSTRUCTOR DPC_table::DPC_table( DPC_datastream_supplier *DS_Supplier, DPM_run *Run, DPM_table *Table_spec, DPM_time_constraints *ParentTimeConstraints ) throw (std::invalid_argument) { DPM_time_constraints *my_time_constraints; DPM_time_constraints total_time_constraints; DPM_var *column_var; //const char *actual_units; int n_columns, n_datastreams; int colix; // ############################################################### // Initialize this table object. // ############################################################### if ( !DS_Supplier ) { throw std::invalid_argument("DS_Supplier is NULL"); } if ( !Run ) { throw std::invalid_argument("DPM_run is NULL"); } if ( !Table_spec ) { throw std::invalid_argument("DPM_table is NULL"); } table_spec = Table_spec; view_data = NULL; run = Run; // ############################################################### // Determine our time constraints. // ############################################################### // Combine the time constraints levied by the table specification // and those levied by the parent-page. The combined time constraints // will be levied on each of the subordinate columns. my_time_constraints = table_spec->getTimeConstraints(); if (ParentTimeConstraints != NULL) { total_time_constraints = *my_time_constraints + *ParentTimeConstraints; } else { total_time_constraints = *my_time_constraints; } // ####################################################### // Create the necessary DataStreams, one for each column . // ####################################################### // Get information about the variable(s) for this table. n_columns = Table_spec->NumberOfColumns(); for ( colix = 0 ; colix < n_columns ; colix ++ ) { DataStream * ds; DPC_column_info * column_info; DPM_column * column = Table_spec->getColumn( colix ); const char * actual_units; column_var = column->getVar(); const char * column_var_name = column_var->getName(); const char * column_var_units = column_var->AttributeValue("units"); const char * column_var_from_units = column_var->AttributeValue("from_units"); UCFn *time_conversion = NULL; int dsix = -1; if ( strcmp( column_var_name, run->getTimeName() ) == 0 ) { if ((column_var_units != NULL) && (strcmp( column_var_units, default_time_units) != 0)) { // Convert seconds to whatever the user requested. Unit *to_unit; Unit *from_unit; try { to_unit = new Unit(column_var_units); } catch (Unit::CONVERSION_ERROR) { to_unit = NULL; std::cerr << "ERROR: Unable to convert values to invalid units: \"" << column_var_units << "\"." << std::endl; } from_unit = new Unit(default_time_units); if (to_unit && from_unit) { try { time_conversion = from_unit->Conversion_to(to_unit); actual_units = column_var_units; } catch (Unit::CONVERSION_ERROR) { std::cerr << "ERROR: Unable to convert from \"" << from_unit << "\" to \"" << to_unit << "\" because they are incompatible." << std::endl; time_conversion = new UCFn( default_time_units, default_time_units, 1.0, 0.0); actual_units = default_time_units; } } else { time_conversion = new UCFn( default_time_units, default_time_units, 1.0, 0.0); actual_units = default_time_units; } } else { time_conversion = new UCFn( default_time_units, default_time_units, 1.0, 0.0); actual_units = default_time_units; } } else { ds = DS_Supplier->getDataStream( column_var_name, column_var_units, column_var_from_units, Run, &total_time_constraints ); if (ds == NULL) { std::cerr << "ERROR: Unable to create a DataStream for :" << std::endl << " Var name = \"" << column_var_name << "\"" << std::endl << " Run Directory = \"" << run->getDir() << "\"" << std::endl; std::cerr.flush(); throw std::invalid_argument("ERROR: Bogus Table."); } datastream_list.push_back( ds ); actual_units = ds->getUnit().c_str(); dsix = datastream_list.size() - 1; } column_info = new DPC_column_info( column_var, actual_units, dsix, time_conversion); column_info_list.push_back( column_info ); } n_datastreams = (int)datastream_list.size(); if ( n_datastreams == 0 ) { throw (std::logic_error("DataStreamList is empty.")); } dsData = new DPC_datum[n_datastreams]; end_of_stream = new bool[n_datastreams]; synchronized_values = new double[n_datastreams]; begin(); }