int main() {
    std::string filename{"TRCFileWithNANs.trc"};

    // There are two ways to read the file:
    // (1) Use the specific adapter to read the file. This requires you to know
    //     the format of the file. Use a TRCFileAdapter to read TRC file.
    // (2) Use the generic FileAdapter to read the file and let it take care
    //     of picking the right Adapter for the given file format.

    // First method. Knowing that the file is a TRC file, use the TRCFileAdapter
    // directly to read the flie.
    OpenSim::TRCFileAdapter trcfileadapter{};
    auto table1 = trcfileadapter.read(filename);

    // Second method. Use the generic FileAdapter. The result is a collection
    // of tables. For a TRC file, this collection will contain just one table. 
    // This table will be an AbstractDataTable. It will have to be casted to the
    //  concrete type to access the data.
    auto& abstable2 = OpenSim::FileAdapter::readFile(filename).at("markers");
    auto table2 = static_cast<OpenSim::TimeSeriesTableVec3*>(abstable2.get());

    // From this point on, both table1 and table2 represent the same type of
    // DataTable and so both support the same operations. Below code 
    // demonstrates operations on only table1 but they are applicable to table2
    // as well.

    // Metadata of the table.
    std::cout << table1.
                 getTableMetaData().
                 getValueForKey("DataRate").
                 getValue<std::string>() << std::endl;

    std::cout << table1.
                 getTableMetaData().
                 getValueForKey("Units").
                 getValue<std::string>() << std::endl;

    // Column labels of the table.
    auto& labels = table1.
                   getDependentsMetaData().
                   getValueArrayForKey("labels");
    for(size_t i = 0; i < labels.size(); ++i)
        std::cout << labels[i].getValue<std::string>() << "\t";
    std::cout << std::endl;

    // Dimensions of the table.
    std::cout << table1.getNumRows() << "\t"
              << table1.getNumColumns() << std::endl;

    // Individual rows of the table.
    for(size_t i = 0; i < table1.getNumRows(); ++i)
        std::cout << table1.getRowAtIndex(i) << std::endl;

    // See documentation for TimeSeriesTable for full set of operations
    // possible for table1 and table2.

    return 0;
}
예제 #2
0
파일: Relation.cpp 프로젝트: raull/CS236
string Relation::toFinalString(Queries query){
	stringstream result;
	if(rows.size()>0){
		result << query.toString() << " Yes(" << rows.size() << ")\n";
		for(int i=0; i<rows.size(); i++){
			for(int j=0; j<schema.size(); j++){
				if(j==0){
					result << "  " << schema[j].getTokensValue() << "=" << getRowAtIndex(i).elements[j].getTokensValue();
				}
				else{
					result << ", " << schema[j].getTokensValue() << "=" << getRowAtIndex(i).elements[j].getTokensValue();
				}
			}
			if(schema.size()>0){
				result << "\n";
			}
		}
	}
	else{
		result << query.toString() << " No\n";
	}
	return result.str();
}
예제 #3
0
파일: Relation.cpp 프로젝트: raull/CS236
string Relation::toString(){
	stringstream result;
	result << "Relation:" << name << "\nSchema:\n(";
	for(int i=0; i<schema.size(); i++){
		if(i != schema.size() - 1)
			result << schema[i].getTokensValue() << ", ";
		else
			result << schema[i].getTokensValue() << ")";
	}
	for(int i=0; i<rows.size(); i++){
		result << "\n" << getRowAtIndex(i).toString();
	}
	result << "\n";
	return result.str();
}