- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Executives/DeductiveController/Observation/DOCMain.cpp

    00001
    00002 //
    00003 // Copyright (c) 2004           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00010
    00011 #include "DiscreteObservationConverter.h"
    00012
    00014
    00015 using namespace Mers::Executives::DeductiveController::Observation;
    00016 using std::cerr;
    00017 using std::cout;
    00018 using std::endl;
    00019 using std::ifstream;
    00020
    00022
    00023 void printUse(const char * progName)
    00024 {
    00025         // Print our usage information.
    00026         cerr << "Use: " << progName << " <sensor file> <conversion file>" << endl;
    00027 }
    00028
    00030
    00031 int main(int argc, const char * argv[])
    00032 {
    00033         // Make sure we have the right arguments.
    00034         if(argc < 3) {
    00035                 printUse(argv[0]);
    00036                 return -1;
    00037         }
    00038
    00039         // Our sensor data
    00040         char ** sensorNameData;
    00041         int * sensorInstanceData;
    00042         int numSensors;
    00043
    00044         // Open our sensor data file.
    00045         ifstream sensorFile(argv[1]);
    00046         if(!sensorFile) {
    00047                 cerr << "Error with the file " << argv[1] << endl;
    00048                 return 1;
    00049         }
    00050
    00051         // Load the number of sensors.
    00052         sensorFile >> numSensors;
    00053
    00054         cout << "Loading " << numSensors << " sensors." << endl;
    00055
    00056         // Make sure it worked.
    00057         if(!sensorFile) {
    00058                 cerr << "Error loading number of sensors" << endl;
    00059                 return 1;
    00060         }
    00061
    00062         // allocate sensor data.
    00063         sensorNameData = new char * [numSensors];
    00064         sensorInstanceData = new int[numSensors];
    00065
    00066         // Load our sensor data.
    00067         for(int i = 0; i < numSensors && sensorFile; ++i) {
    00068                 // Read a sensor
    00069                 char temp[512];
    00070                 char c;
    00071
    00072                 // Load word
    00073                 sensorFile.get(c);
    00074                 for(; (c == ' ' || c == '\n' || c == '\t') && sensorFile;
    00075                         sensorFile.get(c)){
    00076                 }
    00077
    00078                 int j = 0;
    00079                 for(; j < 512 && c != ' ' && c != '\n' && c != '\t' && sensorFile;
    00080                         ++j, sensorFile.get(c)) {
    00081                         temp[j] = c;
    00082                 }
    00083                 temp[j] = '\0';
    00084
    00085                 // copy our name
    00086                 sensorNameData[i] = Mers::Utils::Lang::CharUtils::strdupnew(temp);
    00087
    00088                 // load number of instances
    00089                 sensorFile >> sensorInstanceData[i];
    00090
    00091                 cout << "Loaded '" << sensorNameData[i] << "' with " << sensorInstanceData[i]
    00092                         << " instances." << endl;
    00093         }
    00094         cout << "Finished loading sensors" << endl;
    00095
    00096         // Conversion object.
    00097         DiscreteObservationConverter doConv(argv[2]);
    00098
    00099         // Initialize
    00100         doConv.initialize(sensorNameData, sensorInstanceData, numSensors);
    00101
    00102         cout << "Loaded Conversion:" << endl;
    00103
    00104         // Print our class
    00105         doConv.print(cout);
    00106
    00107         return 0;
    00108 }
    00109