示例#1
0
文件: main.cpp 项目: Delan60/poacpp
int main(int argc, char **argv) {
    if( argc <= 1 ){
        cerr << "Missing input file "<< argv[0] <<" [infile]" << endl;
        return -1;
    }
    string fileName = argv[1];
    vector<SequenceRead>* gfaReads;
    string ctg_seg = "";
    if (argc > 2) {
        fileName = argv[2];
        GfaParser* gfaParser = new GfaParser;
        gfaReads = gfaParser->parseGfaFormat(fileName);
        ctg_seg = gfaParser->segments[0].sequence;
        fileName = argv[1];
    }
    InputParser* parser = InputParserFactory::instantiateParser(fileName);
    vector<pair<string, string>> data = argc > 2 ? parser->parseInputWithGfa(fileName, gfaReads) : parser->parseInput(fileName);

    POAGraph *poaGraph = new POAGraph(ctg_seg, "contig");
    for (auto it = gfaReads->begin(); it!=gfaReads->end(); ++it) {
        cout << it->readName << endl << "Num of nodes: " << poaGraph->numberOfNodes << endl;
        BandwidthAlignment *alignment = new BandwidthAlignment(it->read, poaGraph, it->firstNode, it->lastNode, poaGraph->numberOfNodes);
        alignment->align();
        poaGraph->incorporateSequenceAlignment(alignment, it->read, it->readName);
        delete alignment;
    }

    auto alignments = poaGraph->generateAlignmentStrings();
    delete poaGraph;
//    for (auto pair : alignments) {
//        cout << pair.first << "\t" << pair.second << endl;
//    }
    return 0;
}
void InputConverterOPEquilibria::convert(std::istream& i, std::ostream& o)
{
  InputParser p;
  p.parse(i, pcd.mcs());
  
  writeProgram(o, pcd.mcs());
}
示例#3
0
文件: Shell.cpp 项目: kanbang/Colt
bool Shell::mainLoop(std::istream &in, Environment &env) const
{
	InputParser iParser;
	ShellCommand::Args args;
	
	const Shell *oldShell = env.shell();
	env.shell() = this;
	
	bool success = true;
	do {
		if(env.interactive()) cout << endl << "dbxml> ";
		env.lineNo() += iParser.parse(in, args);
		string command = args.empty() ? string("") : args.front();
		try {
			ShellCommand *cmd = findCommand(command);
			if (cmd)
				cmd->execute(args, env);
			else if(!args.empty()) {
				throw CommandException("Unknown command");
			}
		}
		//catches XmlException
		catch(exception &e) {
			cerr << env.streamName() << ":" << env.lineNo() <<
				": " << command << " failed, ";
			cerr << e.what() << endl;
			success = false;
			if(!env.interactive() && !env.ignoreErrors())
				env.quit() = true;
		}
		catch(...) {
			cerr << env.streamName() << ":" << env.lineNo() <<
				": " << command << " failed" << endl;
			success = false;
			if(!env.interactive() && !env.ignoreErrors())
				env.quit() = true;
		}
	} while(!env.quit() && !in.eof() && !env.sigBlock().isInterrupted());
	
	env.shell() = oldShell;
	return success;
}
示例#4
0
void debugLots() {
	lots.clear();
	debugOffset = 0.005;
	vector<Polygon> debugBlocks;
	Polygon p;
	p.vertices.push_back(Vector3d(0.398803, 0.363752, 0));
	p.vertices.push_back(Vector3d(0.407103, 0.352854, 0));
	p.vertices.push_back(Vector3d(0.414602, 0.357363, 0));
	p.vertices.push_back(Vector3d(0.408383, 0.371349, 0));
	p.vertices.push_back(Vector3d(0.401586, 0.36584, 0));
	debugBlocks.push_back(p);
	lg = LotGenerator(debugBlocks,
									parser.get(LOT_EDGE_MAX_WIDTH)*wMult,
									0, //area
									parser.get(LOT_SPLIT_DEVIANCE),
									is);
	lg.getLots(lots);
	gotLots = true;
	debug = true;
	stage = CS_BUILDINGS;
}
void InputReader::parseFile(istream& fin, InputParser& parser)
{
    string line;
    string token;

    // ... reset input file

    fin.clear();
    fin.seekg(0);
    section = -1;

    // ... read each line from input file

    for (;;)
    {
        if ( errcount >= MAXERRS ) break;
        getline(fin, line, '\n');
        if (fin.fail())
        {
            if ( fin.eof() ) break;    // end of file reached - normal termination
        }

        // ... remove any comment from input line

        trimLine(line);

        // ... read 1st token from input line

        sin.clear();                   // clear string stream status flags
        sin.str(line);                 // assign input line to string stream
        sin >> token;                  // read 1st token from string stream

        // ... skip blank lines

        if ( sin.fail() || token[0] == '\0' ) continue;
        try
        {
            // ... see if at start of new input section

            if ( token[0] == '[' ) findSection(token);

            // ... otherwise parse input line of data

            else parser.parseLine(line, section);
        }
        catch (InputError& e)
        {
            errcount++;
            if ( section >= 0 )
            {
                parser.network->msgLog << e.msg << " at following line of " <<
                    sections[section] << "] section:\n";
            }
            else
            {
                parser.network->msgLog << e.msg << " at following line of file:\n";
            }
            parser.network->msgLog << line << "\n";
        }
        catch (...)
        {
            errcount++;
        }
    }

    // ... throw general input file exception if errors were found

    if ( errcount > 0 ) throw InputError(InputError::ERRORS_IN_INPUT_DATA, "");
}
示例#6
0
int main(int argc, char** argv) {

    string ModelConf, FileOut;

    try {

        // get the name of the current directory
        char dir[255];
        getcwd(dir,255);
        
        // set filenames
        options_description desc("Allowed (positional) options");
        string inputFile(dir), outputFile(dir);
        inputFile += "/tests/StandardModel.conf";
        outputFile += "/tests/LEP2test.root";
        desc.add_options()
            ("modconf", value<string>()->default_value(inputFile), 
                "model config filename (1st)")
            ("rootfile", value<string>()->default_value(outputFile), 
                "output root filename (2nd)")
            ("help", "help message")
            ;
        positional_options_description pd;
        pd.add("modconf", 1);
        pd.add("rootfile", 1);
        variables_map vm;
        store(command_line_parser(argc, argv).options(desc).positional(pd).run(), vm);
        notify(vm);
        if (vm.count("help")) {
            cout << desc << endl;
            return EXIT_SUCCESS;
        }
        ModelConf = vm["modconf"].as<string > ();
        FileOut = vm["rootfile"].as<string>();
        cout << "# set " << ModelConf << " for the model config file" << endl;
        cout << "# set " << FileOut << " for the output file" << endl;
        
        // read parameters
        InputParser myInputParser;
        std::vector<ModelParameter> ModPars;
        std::vector<Observable> Obs;
        std::vector<Observable2D> Obs2D;
        std::vector<CorrelatedGaussianObservables> CGO;
        std::vector<ModelParaVsObs> ParaObs;
        std::map<string, double> DP;
        cout << "# Model: " 
             << myInputParser.ReadParameters(ModelConf, ModPars, Obs, Obs2D, CGO, ParaObs)
             << endl;
        for (std::vector<ModelParameter>::iterator it = ModPars.begin(); it < ModPars.end(); it++)
            DP[it->name] = it->ave;
        if (!myInputParser.getMyModel()->Init(DP)) {
            cout << "parameter(s) missing in model initialization" << endl;
            exit(EXIT_FAILURE);
        }
        
        //////////////////////////////////////////////////////////////////////

        // TEST for inputs
        //cout << "Mz = " << myInputParser.getMyModel()->getMz() << endl;
        
        ZFitterWrapper* ZF = new ZFitterWrapper(*myInputParser.getMyModel());
        ZF->FlagInfo();
        
        // TESTs
        //ZF->printIntermediateResults();
        //ZF->printInputs();
        //ZF->printConstants();
        
        ZFMw* myZFMw = new ZFMw(*ZF);
        cout << "Mw = " << myZFMw->computeThValue() << " " << endl << endl;
        
        //////////////////////////////////////////////////////////////////////        
        // Differential cross sections

        const double cos_theta[11] = {-1.0, -0.8, -0.6, -0.4, -0.2, 0.0,  
                                      0.2, 0.4, 0.6, 0.8, 1.0};
        ZFDsigmaQuarksLEP2* myZFDsigmaQuarks[11];
        ZFDsigmaMuLEP2* myZFDsigmaMu[11];
        ZFDsigmaTauLEP2* myZFDsigmaTau[11];
        cout << "sqrt{s} cos(theta) dsigma(q)/dcos_theta dsigma(mu)/dcos_theta dsigma(tau)/dcos_theta"
             << endl;
        for (int i=0; i<11; i++) {
            myZFDsigmaQuarks[i] = new ZFDsigmaQuarksLEP2(*ZF,200.0,cos_theta[i]);
            myZFDsigmaMu[i] = new ZFDsigmaMuLEP2(*ZF,200.0,cos_theta[i]);
            myZFDsigmaTau[i] = new ZFDsigmaTauLEP2(*ZF,200.0,cos_theta[i]);        
            cout << " 200.0  " << setw(6) <<  cos_theta[i]
                 << setw(20) << myZFDsigmaQuarks[i]->computeThValue() 
                 << setw(20) << myZFDsigmaMu[i]->computeThValue() 
                 << setw(20) << myZFDsigmaTau[i]->computeThValue()
                 << endl;
        }
        cout << endl;
        
        //////////////////////////////////////////////////////////////////////

        // LEP2 CM energies
        const double sqrt_s[12] = {130.0, 136.0, 161.0, 172.0, 183.0, 189.0, 
                                   192.0, 196.0, 200.0, 202.0, 205.0, 207.0};
        // LEP2 CM energies for heavy flavors
        const double sqrt_s_HF[10] = {133.0, 167.0, 183.0, 189.0, 192.0, 
                                      196.0, 200.0, 202.0, 205.0, 207.0};
        
        ZFsigmaQuarksLEP2* myZFsigmaQuarks[12];
        ZFsigmaMuLEP2* myZFsigmaMu[12];
        ZFsigmaTauLEP2* myZFsigmaTau[12];
        ZFAFBmuLEP2* myZFAFBmu[12];
        ZFAFBtauLEP2* myZFAFBtau[12];
        cout << "sqrt{s} sigma(q) sigma(mu) sigma(tau) A_FB(mu) A_FB(tau)"
             << endl;
        for (int i=0; i<12; i++) {
            myZFsigmaQuarks[i] = new ZFsigmaQuarksLEP2(*ZF,sqrt_s[i]);
            myZFsigmaMu[i] = new ZFsigmaMuLEP2(*ZF,sqrt_s[i]);
            myZFsigmaTau[i] = new ZFsigmaTauLEP2(*ZF,sqrt_s[i]);
            myZFAFBmu[i] = new ZFAFBmuLEP2(*ZF,sqrt_s[i]);
            myZFAFBtau[i] = new ZFAFBtauLEP2(*ZF,sqrt_s[i]);
            cout << setw(6) << sqrt_s[i]
                 << setw(10) << myZFsigmaQuarks[i]->computeThValue() 
                 << setw(10) << myZFsigmaMu[i]->computeThValue() 
                 << setw(10) << myZFsigmaTau[i]->computeThValue()
                 << setw(10) << myZFAFBmu[i]->computeThValue() 
                 << setw(10) << myZFAFBtau[i]->computeThValue()
                 << endl;
            //ZF->CutInfo();// TEST
        }
        cout << endl;

        //////////////////////////////////////////////////////////////////////
       
        const int INTF_NEW = 2;
        ZF->setFlag("INTF",INTF_NEW); // with ISR/FSR interference contribution
        cout << "Flag update: INTF=2" << endl << endl;
        
        ZFRbottomLEP2* myZFRbottom[10];
        ZFAFBbottomLEP2* myZFAFBbottom[10];
        ZFRcharmLEP2* myZFRcharm[10];
        ZFAFBcharmLEP2* myZFAFBcharm[10];        
        cout << "sqrt{s}    R_b     A_FB(b)     R_c     A_FB(c)" << endl;
        for (int i=0; i<10; i++) {
           myZFRbottom[i] = new ZFRbottomLEP2(*ZF,sqrt_s_HF[i]);
           myZFAFBbottom[i] = new ZFAFBbottomLEP2(*ZF,sqrt_s_HF[i]);
           myZFRcharm[i] = new ZFRcharmLEP2(*ZF,sqrt_s_HF[i]);
           myZFAFBcharm[i] = new ZFAFBcharmLEP2(*ZF,sqrt_s_HF[i]);
           cout << setw(6) << sqrt_s_HF[i]
                << setw(10) << myZFRbottom[i]->computeThValue() 
                << setw(10) << myZFAFBbottom[i]->computeThValue() 
                << setw(10) << myZFRcharm[i]->computeThValue() 
                << setw(10) << myZFAFBcharm[i]->computeThValue()
                << endl;
        }
        cout << endl;
        
        //////////////////////////////////////////////////////////////////////        
        cout << "Test finished" << endl;
        return EXIT_SUCCESS;
    } catch (const runtime_error& e) {
        cerr << e.what() << endl;
        return EXIT_FAILURE;
    }
}
示例#7
0
文件: main.cpp 项目: Quenii/cu-hw-gps
int main(int argc, char *argv[])
{
    opt::options_description visibleOptions("Allowed options");
    visibleOptions.add_options()
        ("help,h","Display this help message.")
        ("output,o",opt::value<string>(),"Write output to specified file.")
        ("undef,u","Generate an undefines file.")
        ("version,v","Show version information.");
    opt::options_description options("All program options");
    options.add(visibleOptions);
    options.add_options()("input",opt::value<vector<string> >(),"Input...");
    opt::positional_options_description pos;
    pos.add("input",-1);
    
    opt::variables_map vm;
    opt::store(opt::command_line_parser(argc,argv).options(options).positional(pos).run(),vm);
    opt::notify(vm);

    if(vm.count("help"))
    {
        cout<<"Usage: "<<argv[0]<<" [OPTION]... [FILE]..."<<endl
            <<"Generate Verilog include file from XML variable"<<endl
            <<"definitions file."<<endl
            <<endl<<visibleOptions<<endl
            <<"If supplied, input is read from the listed files."<<endl
            <<"By default, input is taken from stdin and output"<<endl
            <<"is written to stdout."<<endl;
        return 0;
    }
    else if(vm.count("version"))
    {
        cout<<PACKAGE_STRING<<endl
            <<"Compiled "<<__DATE__<<" "<<__TIME__<<"."<<endl
            <<endl
            <<"Report bugs to "<<PACKAGE_BUGREPORT<<"."<<endl;
        return 0;
    }

    //Parse input files.
    map<string,MacroEntry*> vars;
    vector<string> verilog;
    int errorCount=0;
    if(vm.count("input"))
    {
        vector<string> inputFiles=vm["input"].as<vector<string> >();
        for(vector<string>::iterator i=inputFiles.begin();
            i!=inputFiles.end();
            i++)
        {
            InputParser in(*i);
            errorCount+=in.Parse(vars,verilog);
        }
    }
    else
    {
        InputParser in;
        errorCount+=in.Parse(vars,verilog);
    }

    //Print output file.
    if(errorCount==0)
    {
        ofstream outFile;
        ostream *out=NULL;
        if(!vm.count("output"))out=&cout;
        else
        {
            outFile.open(vm["output"].as<string>().c_str());
            if(outFile.good())out=&outFile;
            else cerr<<"Error: unable to open output file '"
                     <<vm["output"].as<string>()<<"'."<<endl;
        }
        if(out!=NULL)
        {
            int errorCount=0;

            string output;
            output="//Generated by "+string(PACKAGE_STRING)+", compiled on "+string(__DATE__)+" "+string(__TIME__)+".\n";
            output+="//This file has been automatically generated.\n";
            output+="//Edit contents with extreme caution.\n\n";

            if(!vm.count("undef") && verilog.size()>0)
            {
                for(vector<string>::iterator i=verilog.begin();
                    i!=verilog.end();
                    i++)
                {
                    output+=(*i)+"\n";
                }
                output+="\n";
            }

            map<string,Expression*> expList;
            for(map<string,MacroEntry*>::iterator i=vars.begin();
                i!=vars.end();
                i++)
            {
                expList[(*i).first]=(*i).second->expression;
            }

            boost::regex newline("\\n");
            for(map<string,MacroEntry*>::iterator i=vars.begin();
                i!=vars.end();
                i++)
            {
                string variable=(*i).first;
                MacroEntry *entry=(*i).second;

                if(vm.count("undef"))
                {
                    output+="`ifdef "+variable+"\n";
                    output+=" `undef "+variable+"\n";
                    output+="`endif\n";
                    output+="\n";
                }
                else
                {
                    if(!entry->print)continue;
                    try
                    {
                        if(entry->comments!="")
                        {
                            output+="//";
                            output+=boost::regex_replace(entry->comments,newline,"\\n//");
                            output+="\n";
                        }
                        output+="`ifndef "+variable+"\n";
                        output+=" `define "+variable+" "+entry->expression->Value(expList)+"\n";
                        output+="`endif\n";
                        output+="\n";
                    }
                    catch(Expression::ExpressionError &e)
                    {
                        errorCount++;
                        e.SetVariable(variable);
                        cerr<<e.what()<<endl;
                    }
                }
            }

            if(errorCount==1)cerr<<"Found 1 error."<<endl;
            else if(errorCount>0)cerr<<"Found "<<errorCount<<" errors."<<endl;
            else (*out)<<output;

            if(vm.count("output"))outFile.close();
        }
    }
    else
    {
        if(errorCount==1)cerr<<"Found 1 error."<<endl;
        else if(errorCount>0)cerr<<"Found "<<errorCount<<" errors."<<endl;
    }

    //Cleanup expressions.
    for(map<string,MacroEntry*>::iterator i=vars.begin();
        i!=vars.end();
        i++)
    {
        delete (*i).second;
    }
    
    return errorCount!=0;
}
示例#8
0
void keyboard(unsigned char key, int x, int y) {
	if(key == ' ') {
		roadsystem.generate(1);
	}
	if(key == 'x') {
		roadsystem.generate(100);
	}
	if(key == 'z') {
		roadsystem.generate(1000);
	}
	if(key == 'q') {
		roadsystem.printStats();
	}
	if(key == 'i') {
		scale *= 1.1;
	}
	if(key == 'k') {
		scale /= 1.1;
	}
	/*
	if(key == 'u') {
		wMult += 0.05;
		debugLots();
	}
	if(key == 'j') {
		wMult -= 0.05;
		debugLots();
	}
	*/
	if(key == 'd') {
		if(stage >= CS_ROADS) {
			printf("dumping roads to roads.mel...");
			roadsystem.dumpRoads();
			printf("done!\n");
		}
	}
	if(key == 'f') {
		if(stage >= CS_LOTS) {
			printf("dumping blocks to blocks.obj...");
			roadsystem.dumpPolygons();
			printf("done!\n");
		}
	}
	if(key == 'g') {
		if(stage >= CS_BUILDINGS) {
			printf("dumping lots to lots.obj...");
			dumpLots();
			printf("done!\n");
		}
	}
	/*
	if(key == 'f') {
		printf("debugging\n");
		debugLots();
	}
	*/
	if(key == 'p') {
		switch(stage) {
		case(CS_ROADS):
			printf("extracting blocks...");
			roadsystem.getPolygons();
			blocks.clear();
			roadsystem.extractPolygons(blocks);
			gotBlocks = true;
			printf("done!\n");
			stage = CS_LOTS;
			printf("-------------------------------------\n");
			printf("Lot Subdivision\n");
			printf("(p) to generate lots\n");
			printf("(f) to dump blocks to blocks.obj\n");
			printf("(d) to dump roads to roads.mel\n");
			printf("The code likes to blow up at this stage :(\n");
			printf("If it does, just restart the program\n");
			break;
		case(CS_LOTS):
			lg = LotGenerator(blocks,
							  parser.get(LOT_EDGE_MAX_WIDTH),
							  parser.get(LOT_MIN_AREA),
							  parser.get(LOT_SPLIT_DEVIANCE),
							  is);
			lg.getLots(lots);
			gotLots = true;
			printf("Done subdividing blocks!\n");
			stage = CS_BUILDINGS;
			printf("-------------------------------------\n");
			printf("Building Generation\n");
			printf("(p) to generate buildings\n");
			printf("(g) to dump lots to lots.obj\n");
			printf("(f) to dump blocks to blocks.obj\n");
			printf("(d) to dump roads to roads.mel\n");
			printf("output will be written to outputFile.obj\n");
			break;
		case(CS_BUILDINGS):
			printf("generating buildings...");
			bg = BuildingGenerator(lots);
			bg.getBuildings(parser.get(BUILDING_MAX_HEIGHT), is);
			bg.generateObjFile();
			printf("done!\n");
			printf("(p) to quit\n");
			printf("(g) to dump lots to lots.obj\n");
			printf("(f) to dump blocks to blocks.obj\n");
			printf("(d) to dump roads to roads.mel\n");
			stage = CS_DONE;
			break;
		case(CS_DONE):
			exit(0);
			break;
		}
	}
	glutPostRedisplay();
}