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

# /Users/fpy/titan-1-5-MBARI/Mers/Models/CCA/Io/Mof/CCATextToBin.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 //
    00009 // Organization:        Model-based Embedded and Robotic Systems Group
    00010 //                                      Massachusetts Institute of Technology
    00011 //
    00013
    00014 #include "MOFReader.h"
    00015
    00016 using namespace Mers::Models::CCA::Io::Mof;
    00017 using Mers::Models::CCA::CCAModel;
    00018 using std::string;
    00019
    00025 void printUse(char const * programName)
    00026 {
    00027         printf("Use:\n\t%s <CCA File Name> [<Binary CCA File Name>]\n", programName);
    00028         printf("\n\tDefaults to \"<CCA File Name>b.cca\" if optional second\n\tparameter is not provided\n");
    00029 }
    00030
    00037 int main(int argc, char * argv[])
    00038 {
    00039         CCAModel * mdl = NULL;
    00040         string sIn, sOut;
    00041         MOFReader::CCAFileType saveFileType = MOFReader::CCABinaryLatest;
    00042
    00043         if(argc < 2 || argc > 3){
    00044                 if(argc == 0)
    00045                         printUse("CCATextToBin");
    00046                 else
    00047                         printUse(argv[0]);
    00048                 return 1;
    00049         }
    00050
    00051         sIn = argv[1];
    00052
    00053         if(argc == 3){
    00054                 sOut = argv[2];
    00055         }else{ // argc == 2
    00056                 unsigned int period;
    00057
    00058                 sOut = sIn;
    00059                 period = sOut.find_last_of('.');
    00060                 if(period == sOut.npos){
    00061                   sOut += "b.cca";
    00062                 }else{
    00063                   sOut.insert(period, 1, 'b');
    00064                 }
    00065         }
    00066
    00067         printf("Loading %s\n", sIn.c_str());
    00068         if(MOFReader::loadMOF(sIn.c_str(), mdl)){
    00069                 if(mdl)
    00070                         delete mdl;
    00071                 mdl = NULL;
    00072                 printf("Failed to load %s\n\n", sIn.c_str());
    00073                 if(argc == 0)
    00074                         printUse("CCATextToBin");
    00075                 else
    00076                         printUse(argv[0]);
    00077                 return 2;
    00078         }
    00079
    00080         printf("Saving to %s in the %s format\n", sOut.c_str(),
    00081                 MOFReader::ccaFileTypeToString(saveFileType));
    00082         if(MOFReader::saveCCAModel(sOut.c_str(), saveFileType, *mdl)){
    00083                 if(mdl)
    00084                         delete mdl;
    00085                 mdl = NULL;
    00086                 printf("Failed to save %s\n\n", sOut.c_str());
    00087                 if(argc == 0)
    00088                         printUse("CCATextToBin");
    00089                 else
    00090                         printUse(argv[0]);
    00091                 return 3;
    00092         }
    00093
    00094         if(mdl)
    00095                 delete mdl;
    00096         mdl = NULL;
    00097         return 0;
    00098 }
    00099