コード例 #1
0
ファイル: qtuistyle.cpp プロジェクト: bawNg/quassel
void QtUiStyle::generateSettingsQss() const {
  QFile settingsQss(Quassel::configDirPath() + "settings.qss");
  if(!settingsQss.open(QFile::WriteOnly|QFile::Truncate)) {
    qWarning() << "Could not open" << settingsQss.fileName() << "for writing!";
    return;
  }
  QTextStream out(&settingsQss);

  out << "// Style settings made in Quassel's configuration dialog\n"
      << "// This file is automatically generated, do not edit\n";

  // ChatView
  ///////////
  QtUiStyleSettings fs("Fonts");
  if(fs.value("UseCustomChatViewFont").toBool())
    out << "\n// ChatView Font\n"
        << "ChatLine { " << fontDescription(fs.value("ChatView").value<QFont>()) << "; }\n";

  QtUiStyleSettings s("Colors");
  if(s.value("UseChatViewColors").toBool()) {
    out << "\n// Custom ChatView Colors\n"

        // markerline is special in that it always used to use a gradient, so we keep this behavior even with the new implementation
        << "Palette { marker-line: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 " << color("MarkerLine", s) << ", stop: 0.1 transparent); }\n"
        << "ChatView { background: " << color("ChatViewBackground", s) << "; }\n\n"
        << "ChatLine[label=\"highlight\"] {\n"
        << "  foreground: " << color("Highlight",s) << ";\n"
        << "  background: " << color("HighlightBackground", s) << ";\n"
        << "}\n\n"
        << "ChatLine::timestamp { foreground: " << color("Timestamp", s) << "; }\n\n"

        << msgTypeQss("plain", "ChannelMsg", s)
        << msgTypeQss("notice", "ServerMsg", s)
        << msgTypeQss("action", "ActionMsg", s)
        << msgTypeQss("nick", "CommandMsg", s)
        << msgTypeQss("mode", "CommandMsg", s)
        << msgTypeQss("join", "CommandMsg", s)
        << msgTypeQss("part", "CommandMsg", s)
        << msgTypeQss("quit", "CommandMsg", s)
        << msgTypeQss("kick", "CommandMsg", s)
        << msgTypeQss("kill", "CommandMsg", s)
        << msgTypeQss("server", "ServerMsg", s)
        << msgTypeQss("info", "ServerMsg", s)
        << msgTypeQss("error", "ErrorMsg", s)
        << msgTypeQss("daychange", "ServerMsg", s)
        << msgTypeQss("topic", "CommandMsg", s)
        << msgTypeQss("netsplit-join", "CommandMsg", s)
        << msgTypeQss("netsplit-quit", "CommandMsg", s)
        << "\n";
  }

  if(s.value("UseSenderColors").toBool()) {
    out << "\n// Sender Colors\n"
        << "ChatLine::sender#plain[sender=\"self\"] { foreground: " << color("SenderSelf", s) << "; }\n\n";

    for(int i = 0; i < 16; i++)
      out << senderQss(i, s);
  }

  // ItemViews
  ////////////

  UiStyleSettings uiFonts("Fonts");
  if(uiFonts.value("UseCustomItemViewFont").toBool()) {
    QString fontDesc = fontDescription(uiFonts.value("ItemView").value<QFont>());
    out << "\n// ItemView Font\n"
        << "ChatListItem { " << fontDesc << "; }\n"
        << "NickListItem { " << fontDesc << "; }\n\n";
  }

  UiStyleSettings uiColors("Colors");
  if(uiColors.value("UseBufferViewColors").toBool()) {
    out << "\n// BufferView Colors\n"
        << "ChatListItem { foreground: " << color("DefaultBuffer", uiColors) << "; }\n"
        << chatListItemQss("inactive", "InactiveBuffer", uiColors)
        << chatListItemQss("channel-event", "ActiveBuffer", uiColors)
        << chatListItemQss("unread-message", "UnreadBuffer", uiColors)
        << chatListItemQss("highlighted", "HighlightedBuffer", uiColors);
  }

  if(uiColors.value("UseNickViewColors").toBool()) {
    out << "\n// NickView Colors\n"
        << "NickListItem[type=\"category\"] { foreground: " << color("DefaultBuffer", uiColors) << "; }\n"
        << "NickListItem[type=\"user\"] { foreground: " << color("OnlineNick", uiColors) << "; }\n"
        << "NickListItem[type=\"user\", state=\"away\"] { foreground: " << color("AwayNick", uiColors) << "; }\n";
  }

  settingsQss.close();
}
コード例 #2
0
ファイル: clobber_parse_options.cpp プロジェクト: Dthird/CBMC
int clobber_parse_optionst::doit()
{
  if(cmdline.isset("version"))
  {
    std::cout << CBMC_VERSION << std::endl;
    return 0;
  }

  register_language(new_ansi_c_language);
  register_language(new_cpp_language);

  //
  // command line options
  //

  optionst options;
  get_command_line_options(options);

  eval_verbosity();

  goto_functionst goto_functions;

  if(get_goto_program(options, goto_functions))
    return 6;
    
  label_properties(goto_functions);

  if(cmdline.isset("show-properties"))
  {
    const namespacet ns(symbol_table);
    show_properties(ns, get_ui(), goto_functions);
    return 0;
  }

  if(set_properties(goto_functions))
    return 7;
    
  // do instrumentation

  try
  {
    const namespacet ns(symbol_table);
    
    std::ofstream out("simulator.c");
    
    if(!out)
      throw std::string("failed to create file simulator.c");
    
    dump_c(goto_functions, true, ns, out);
    
    status() << "instrumentation complete; compile and execute simulator.c" << eom;
    
    return 0;
  }
  
  catch(const std::string error_msg)
  {
    error() << error_msg << messaget::eom;
    return 8;
  }

  catch(const char *error_msg)
  {
    error() << error_msg << messaget::eom;
    return 8;
  }

  #if 0                                         
  // let's log some more statistics
  debug() << "Memory consumption:" << messaget::endl;
  memory_info(debug());
  debug() << eom;
  #endif
}
コード例 #3
0
ファイル: extr_adim.cpp プロジェクト: sunpho84/sunpho
void plot_funz_ml(const char *out_path,const char *title,const char *xlab,const char *ylab,bvec &X,bvec &Y,bvec &par,double X_phys,double (*fun)(double,double,double,double,double,double),boot &chiral_extrap_cont)
{
  //setup the plot
  grace out(out_path);
  out.plot_size(800,600);
  out.plot_title(combine("Chiral extrapolation of %s",title).c_str());
  out.axis_label(xlab,ylab);
  
  if(fun!=NULL)
    {
      //plot the function with error
      int npoint=100;
      double X_pol[npoint];
      bvec Y_pol(npoint,nboot,njack);
      for(int ipoint=0;ipoint<npoint;ipoint++) X_pol[ipoint]=0.0599/(npoint-1)*ipoint+0.0001;
      for(int ib=0;ib<nbeta;ib++)
	{
	  bvec Y_pol(npoint,nboot,njack);
	  for(int ipoint=0;ipoint<npoint;ipoint++)
	    for(int iboot=plot_iboot=0;iboot<nboot+1;plot_iboot=iboot++)
	      Y_pol.data[ipoint].data[iboot]=fun(par[0][iboot],par[1][iboot],par[2][iboot],par[3][iboot],X_pol[ipoint],lat[ib][iboot]);
	  
	  out.set(1,set_fill_color[ib]);
	  out.polygon(X_pol,Y_pol);
	  out.new_set();
	  out.set(1,set_color[ib]);
	  out.set_line_size(2);
	  out.ave_line(X_pol,Y_pol);
	  out.new_set();
	}
      //plot continuum curve
      for(int ipoint=0;ipoint<npoint;ipoint++)
	for(int iboot=plot_iboot=0;iboot<nboot+1;plot_iboot=iboot++)
	  Y_pol.data[ipoint]=fun(par[0][iboot],par[1][iboot],par[2][iboot],par[3][iboot],X_pol[ipoint],0);
      //out.set(1,"magenta");
      //out.polygon(X_pol,Y_pol);
      //out.new_set();
      out.set(1,"magenta");
      out.set_line_size(3);
      out.ave_line(X_pol,Y_pol);
      out.new_set();
    }
  
  //plot the original data with error  
  for(int ib=0;ib<nbeta;ib++)
    {
      out.set(4,"none",set_symbol[ib],set_color[ib],"filled");
      out.set_legend(set_legend_fm[ib]);
      out.set_line_size(2);
      out.fout<<"@type xydy"<<endl;
      for(int iens=0;iens<nens;iens++) if(ibeta[iens]==ib) out.fout<<X[iens].med()<<" "<<Y.data[iens]<<endl;
      out.new_set();
    }
  
  //plot the extrapolated point with error
  out.set(4,"none","circle","indigo","filled");
  out.set_line_size(3);
  out.set_legend("Physical point");
  out.print_graph(X_phys,chiral_extrap_cont);
  out.new_set();
}
コード例 #4
0
ファイル: qmail-smtpd.c プロジェクト: kp-org/eQmail
void err_bmf() { out("553 sorry, your envelope sender is in my badmailfrom list (#5.7.1)\r\n"); }
コード例 #5
0
void UnitTestOutputLog::testUnit()
{
  // Make cout and cerr available as log stream targets.
  stk::register_log_ostream(std::cout, "cout");
  stk::register_log_ostream(std::cerr, "cerr");

  // Test registration, binding, rebinding and unregistration
  {
    std::ostringstream log1;
    std::ostringstream log2;
    
    std::ostream out(std::cout.rdbuf());

    stk::register_ostream(out, "out");

    CPPUNIT_ASSERT(stk::is_registered_ostream("out"));
    
    stk::register_log_ostream(log1, "log1");
    stk::register_log_ostream(log2, "log2");

    stk::bind_output_streams("out>log1");

    out << "stk::bind_output_streams(\"out>log1\");" << std::endl;

    stk::bind_output_streams("out>+log2");
    out << "stk::bind_output_streams(\"out>+log2\");" << std::endl;
    
    stk::bind_output_streams("out>-log1");
    out << "stk::bind_output_streams(\"out>-log1\");" << std::endl;

    stk::bind_output_streams("out>-log2");
    out << "stk::bind_output_streams(\"out>-log2\");" << std::endl;

    std::ostringstream log1_result;
    log1_result << "stk::bind_output_streams(\"out>log1\");" << std::endl
                << "stk::bind_output_streams(\"out>+log2\");" << std::endl;
    
    std::ostringstream log2_result;
    log2_result << "stk::bind_output_streams(\"out>+log2\");" << std::endl
                << "stk::bind_output_streams(\"out>-log1\");" << std::endl;
    
    CPPUNIT_ASSERT_EQUAL(log1_result.str(), log1.str());
    CPPUNIT_ASSERT_EQUAL(log2_result.str(), log2.str());

    stk::unregister_log_ostream(log1);
    stk::unregister_log_ostream(log2);
    stk::unregister_ostream(out);

    CPPUNIT_ASSERT_EQUAL(out.rdbuf(), std::cout.rdbuf());
  }

  // Test logging to a file
  {
    std::ostream out(std::cout.rdbuf());

    stk::register_ostream(out, "out");

    stk::bind_output_streams("log=\"logfile\" out>log");

    CPPUNIT_ASSERT_EQUAL(std::string("logfile"), stk::get_log_path("log")); 
    
    out << "This is a test" << std::endl;

    stk::bind_output_streams("log=\"\"");
    
    stk::unregister_ostream(out);

    std::ostringstream log_result;
    log_result << "This is a test";
    
    std::ifstream log_stream("logfile");
    std::string log_string;
    getline(log_stream, log_string);
    CPPUNIT_ASSERT_EQUAL(log_result.str(), log_string);
  }

  // Test results of unregistration of an output stream bound as a log stream
  {
    std::ostringstream default_log;
    std::ostream out(default_log.rdbuf());
    std::ostream pout(std::cout.rdbuf());

    stk::register_ostream(out, "out");
    stk::register_ostream(pout, "pout");

    //  Constructing the log streams after the registered output stream is not exception safe.
    std::ostringstream log;
    stk::register_log_ostream(log, "log");

    // As a result, this try catch block must be represent to ensure the that unregistration
    // happens correctly.
    try {  
      stk::bind_output_streams("out>pout pout>log");

      out << "This is to out" << std::endl;
      pout << "This is to pout" << std::endl;

      std::ostringstream log_result;
      log_result << "This is to out" << std::endl
                 << "This is to pout" << std::endl;
    
      CPPUNIT_ASSERT_EQUAL(log_result.str(), log.str());

      throw std::exception();
    }
    catch (...) {
    }

    stk::unregister_log_ostream(log);
    stk::unregister_ostream(pout);
    stk::unregister_ostream(out);

    out << "This is to out" << std::endl;

    std::ostringstream log_result;
    log_result << "This is to out" << std::endl;
    CPPUNIT_ASSERT_EQUAL(log_result.str(), default_log.str());
  }

  // Test exception of registration with existing name
  {
    std::ostringstream log1;
    std::ostringstream log2;
    
    std::ostream out(std::cout.rdbuf());
    std::ostream pout(std::cout.rdbuf());

    stk::register_ostream(out, "out");
    CPPUNIT_ASSERT_THROW(stk::register_ostream(pout, "out"), std::runtime_error);

    CPPUNIT_ASSERT_EQUAL(&out, stk::get_ostream_ostream("out"));

    stk::register_log_ostream(log1, "log");
    
    CPPUNIT_ASSERT_THROW(stk::register_log_ostream(log2, "log"), std::runtime_error);

    CPPUNIT_ASSERT_THROW(stk::bind_output_streams("badout>log"), std::runtime_error);
    
    CPPUNIT_ASSERT_THROW(stk::bind_output_streams("out>badlog"), std::runtime_error);

    stk::unregister_log_ostream(log1);
    stk::unregister_ostream(out);
  }
}
コード例 #6
0
ファイル: qmail-smtpd.c プロジェクト: kp-org/eQmail
void die_control() { logit("unable to read controls"); out("421 unable to read controls (#4.3.0)\r\n"); flush(); _exit(1); }
コード例 #7
0
ファイル: qmail-smtpd.c プロジェクト: kp-org/eQmail
void straynewline() { logit("bad newlines"); out("451 See http://pobox.com/~djb/docs/smtplf.html.\r\n"); flush(); _exit(1); }
コード例 #8
0
ファイル: example.cpp プロジェクト: EnjoyHacking/stsc
int main() {
    //std::vector<int> items = {1,2,3,4,5,6,7,8,9,10};

    std::string filename("sampleEmbedding_200.txt");
    //std::string filename("iris.data");
    std::vector< std::vector<double> > items = load_data(filename);

    // generate similarity matrix
    unsigned int size = items.size();
    Eigen::MatrixXd m = Eigen::MatrixXd::Zero(size,size);
    std::cout << "------------" << std::endl;

    for (unsigned int i=0; i < size; i++) {
        for (unsigned int j=0; j < size; j++) {
            // generate similarity
            //int d = items[i] - items[j];
	    double d = eculidean_distance(items[i], items[j]);
            int similarity = exp(-d*d / 1);
            m(i,j) = similarity;
            m(j,i) = similarity;
        }
    }

    // the number of eigenvectors to consider. This should be near (but greater) than the number of clusters you expect. Fewer dimensions will speed up the clustering
    int numDims = size;

    // do eigenvalue decomposition
    SpectralClustering* c = new SpectralClustering(m, numDims);

    // whether to use auto-tuning spectral clustering or kmeans spectral clustering
    bool autotune = false;

    std::vector<std::vector<int> > clusters;
    if (autotune) {
        // auto-tuning clustering
        clusters = c->clusterRotate();
    } else {
        // how many clusters you want
        int numClusters = 10;
        clusters = c->clusterKmeans(numClusters);
    }

    // output clustered items
    // items are ordered according to distance from cluster centre
    for (unsigned int i=0; i < clusters.size(); i++) {
        std::cout << "Cluster " << i << ": " << "Item ";
        std::copy(clusters[i].begin(), clusters[i].end(), std::ostream_iterator<int>(std::cout, ", "));
        std::cout << std::endl;
    }
	std::map<int, int> sampleid_to_clusterid;
    for (unsigned int i = 0; i < clusters.size(); i++) {
    	for (unsigned int j = 0; j < clusters[i].size(); j++){
		sampleid_to_clusterid.insert(std::make_pair(clusters[i][j], i));
	}
    }
    
    std::string output_filename("sample_assignment.txt");

    std::ofstream out(output_filename.c_str(), std::ios::out);
    if(!out) {
    	std::cerr << "Can't open output file " << output_filename << std::endl;
    	return 0;
    }
    std::map<int, int>::iterator it;
    for(it = sampleid_to_clusterid.begin(); it != sampleid_to_clusterid.end(); it++) {
    	out << it->second << std::endl;
    }
    out.close();
   
}
コード例 #9
0
ファイル: mainwindow.cpp プロジェクト: NOOBS-DevTeam/Appendix
//Запуск программы юзера
void MainWindow::on_run_triggered()
{
    if (n) //Если вкадки открыты
    {
        QString format,compiler;
        switch (tabs[cur_tab]->getLang())
        {
        case CPP:
            format = "cpp";
            compiler = "g++ temp.cpp";
            break;
        case PAS:
            format = "pas";
            compiler = "fpc temp.pas";
            break;
        case APX:
            format = "apx";
            compiler = "apx temp.apx";
            break;
        }

        QString str = tabs[cur_tab]->toPlainText();

        //Запись текста таба во временный файл
        QFile("temp."+format).remove();
        std::ofstream out(std::string("temp."+format.toStdString()).c_str());
        out << str.toStdString();
        out << "\n";
        out.close();

        if (tabs[cur_tab]->getLang()==APX)
        {
            //Запуск интерпретатора (если апх)
            switchRun();
            cp->start(compiler);
            cp->waitForStarted();
        }
        else
        {
            //Компилируем
            comp_in_progress = true;
            cp->start(compiler);
            cp->waitForFinished();
            comp_in_progress = false;

            if (cp->exitCode())
                ui->textEdit->append(allErrors);
            allErrors = "";

            if (!cp->exitCode()) //Если успешно скомпилилось
            {
			#ifdef Q_OS_UNIX
                switchRun();
                cp->start(cur_lang==CPP?"./a.out":"./temp.out");
                cp->waitForStarted();
                QFile(cur_lang==CPP?"./a.out":"./temp.out").remove();//Для Linux
            #endif
            #ifdef Q_OS_WIN
                switchRun();
                cp->start(cur_lang==CPP?"a.exe":"temp.exe");
                cp->waitForStarted();
                QFile(cur_lang==CPP?"a.exe":"temp.exe").remove();//Для Windows
            #endif
            }
        }
    }
    else
        QMessageBox::warning(ui->tabWidget,"Error","Возможно вы не открыли/создали ни одного файла",QMessageBox::Yes,QMessageBox::Yes);
}
コード例 #10
0
ファイル: task41-fracdec.c プロジェクト: hitme/USACO
main () {
	
	int an,ad;
	int rm;
	char *p;
    int i,j,k,c;
	int hl,sz,lp,pl;
	
	//clock_t st,ed,*pt;
    
	fin  = fopen ("fracdec.in", "r");
	fout = fopen ("fracdec.out", "w");
	//fout = stdout;
	
    fscanf (fin, "%d %d", &an,&ad);
	//scanf ("%d %d", &an,&ad);
	
	sprintf(ret,"%d",an/ad);
	hl=strlen(ret);
	lp=pl=0;//big trouble without init
	if(an%ad==0){
		strcpy(ret+hl,".0");
	}else{
		ret[hl]='.';
		p=ret+hl+1;
		for(i=0;i<mxn-hl-10;i++){
			rm=an%ad;
			if(!ql[rm])ql[rm]=i+1;
			else{
				lp=ql[rm]-1;
				pl=i-lp;
				*p='\0';
				break;
			}
			rm*=10;
			*p++=rm/ad+'0';
			an=rm%ad;
			if(an==0){
				*p='\0';break;
			}
		}
	}
	
	if(pl){
		*p='\0';
		p=ret+hl+1;
		i=lp;k=pl;
#if 0 //tle
	if(i==mxn-hl-10){
		*p='\0';
		p=ret+hl+1;
		sz=mxn-hl-10;
		for(k=1;k<ad&&k<sz/2;k++){
			for(i=0;i<k;i++){
				j=i+k;
				while(j<sz-k){
					if(strncmp(p+i,p+j,k)!=0)break;
					j+=k;
				}
				if(j>=sz-k)break;
			}
			if(i<k)break;
		}
#endif
		printf("%d %d\n",i,k);
		p[i+k+1]=')';
		p[i+k+2]='\0';
		for(j=i+k;j>i;j--){
			p[j]=p[j-1];
		}
		p[i]='(';
    }
	
	out();
    exit (0);
}
コード例 #11
0
ファイル: hd61102.cpp プロジェクト: TheProjecter/pockemul
void	CHD61102::save_internal(QFile *file){
    QDataStream out(file);

    out.writeRawData("HD61102STA", 10);					//header
    out.writeRawData((char*)&info,sizeof(info));		//reg
}
コード例 #12
0
ファイル: ofxPDSPMonoFader.cpp プロジェクト: npisanti/ofxPDSP
pdsp::Patchable& ofxPDSPMonoFader::out_signal() {
    return out("signal");
}
コード例 #13
0
ファイル: main.cpp プロジェクト: ilri/odktools
int main(int argc, char *argv[])
{
    QString title;
    title = title + "********************************************************************* \n";
    title = title + " * Create from XML                                                   * \n";
    title = title + " * This tool create a SQL DDL script file from a XML schema file     * \n";
    title = title + " * created by ODKToMySQL.                                            * \n";
    title = title + " *                                                                   * \n";
    title = title + " * This tool is usefull when dealing with multiple versions of an    * \n";
    title = title + " * ODK survey that were combined into a common XML schema using      * \n";
    title = title + " * compareCreateXML.                                                 * \n";
    title = title + " ********************************************************************* \n";

    TCLAP::CmdLine cmd(title.toUtf8().constData(), ' ', "2.0");

    TCLAP::ValueArg<std::string> inputArg("i","input","Input create XML file",true,"","string");
    TCLAP::ValueArg<std::string> outputArg("o","output","Output SQL file",false,"./create.sql","string");

    for (int i = 1; i < argc; i++)
    {
        command = command + argv[i] + " ";
    }

    cmd.add(inputArg);
    cmd.add(outputArg);

    //Parsing the command lines
    cmd.parse( argc, argv );

    //Getting the variables from the command
    QString input = QString::fromUtf8(inputArg.getValue().c_str());
    QString output = QString::fromUtf8(outputArg.getValue().c_str());
    idx = 0;

    if (input != output)
    {
        if (QFile::exists(input))
        {
            //Openning and parsing input file A
            QDomDocument docA("input");
            QFile fileA(input);
            if (!fileA.open(QIODevice::ReadOnly))
            {
                log("Cannot open input file");
                return 1;
            }
            if (!docA.setContent(&fileA))
            {
                log("Cannot parse input file");
                fileA.close();
                return 1;
            }
            fileA.close();

            QDomElement rootA = docA.documentElement();

            if (rootA.tagName() == "XMLSchemaStructure")
            {
                QFile file(output);
                if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
                {
                    log("Cannot create output file");
                    return 1;
                }

                QDateTime date;
                date = QDateTime::currentDateTime();

                QTextStream out(&file);

                out << "-- Code generated by createFromXML" << "\n";
                out << "-- " + command << "\n";
                out << "-- Created: " + date.toString("ddd MMMM d yyyy h:m:s ap")  << "\n";
                out << "-- by: createFromXML Version 1.0" << "\n";
                out << "-- WARNING! All changes made in this file might be lost when running createFromXML again" << "\n\n";

                QDomNode lkpTables = docA.documentElement().firstChild();
                QDomNode tables = docA.documentElement().firstChild().nextSibling();
                if (!lkpTables.isNull())
                {
                    procLKPTables(lkpTables.firstChild(),out);
                }
                if (!tables.isNull())
                {
                    procTables(tables.firstChild(),out);
                }
            }
            else
            {
                log("Input document is not a XML create file");
                return 1;
            }
        }
        else
        {
            log("Input file does not exists");
            return 1;
        }
    }
    else
    {
        log("Fatal: Input files and output file are the same.");
        return 1;
    }

    return 0;
}
コード例 #14
0
void SdpSolverInternal::init() {
  // Call the init method of the base class
  FunctionInternal::init();

  calc_p_ = getOption("calc_p");
  calc_dual_ = getOption("calc_dual");
  print_problem_ = getOption("print_problem");

  // Find aggregate sparsity pattern
  Sparsity aggregate = input(SDP_SOLVER_G).sparsity();
  for (int i=0;i<n_;++i) {
    aggregate = aggregate + input(SDP_SOLVER_F)(ALL, Slice(i*m_, (i+1)*m_)).sparsity();
  }

  // Detect block diagonal structure in this sparsity pattern
  std::vector<int> p;
  std::vector<int> r;
  nb_ = aggregate.stronglyConnectedComponents(p, r);
  block_boundaries_.resize(nb_+1);
  std::copy(r.begin(), r.begin()+nb_+1, block_boundaries_.begin());

  block_sizes_.resize(nb_);
  for (int i=0;i<nb_;++i) {
    block_sizes_[i]=r[i+1]-r[i];
  }

  // Make a mapping function from dense blocks to inversely-permuted block diagonal P
  std::vector< SX > full_blocks;
  for (int i=0;i<nb_;++i) {
    full_blocks.push_back(SX::sym("block", block_sizes_[i], block_sizes_[i]));
  }

  Pmapper_ = SXFunction(full_blocks, blkdiag(full_blocks)(lookupvector(p, p.size()),
                                                         lookupvector(p, p.size())));
  Pmapper_.init();

  if (nb_>0) {
    // Make a mapping function from (G, F) -> (G[p, p]_j, F_i[p, p]j)
    SX G = SX::sym("G", input(SDP_SOLVER_G).sparsity());
    SX F = SX::sym("F", input(SDP_SOLVER_F).sparsity());

    std::vector<SX> in;
    in.push_back(G);
    in.push_back(F);
    std::vector<SX> out((n_+1)*nb_);
    for (int j=0;j<nb_;++j) {
      out[j] = G(p, p)(Slice(r[j], r[j+1]), Slice(r[j], r[j+1]));
    }
    for (int i=0;i<n_;++i) {
      SX Fi = F(ALL, Slice(i*m_, (i+1)*m_))(p, p);
      for (int j=0;j<nb_;++j) {
        out[(i+1)*nb_+j] = Fi(Slice(r[j], r[j+1]), Slice(r[j], r[j+1]));
      }
    }
    mapping_ = SXFunction(in, out);
    mapping_.init();
  }

  // Output arguments
  setNumOutputs(SDP_SOLVER_NUM_OUT);
  output(SDP_SOLVER_X) = DMatrix::zeros(n_, 1);
  output(SDP_SOLVER_P) = calc_p_? DMatrix(Pmapper_.output().sparsity(), 0) : DMatrix();
  output(SDP_SOLVER_DUAL) = calc_dual_? DMatrix(Pmapper_.output().sparsity(), 0) : DMatrix();
  output(SDP_SOLVER_COST) = 0.0;
  output(SDP_SOLVER_DUAL_COST) = 0.0;
  output(SDP_SOLVER_LAM_X) = DMatrix::zeros(n_, 1);
  output(SDP_SOLVER_LAM_A) = DMatrix::zeros(nc_, 1);

}
コード例 #15
0
ファイル: qmail-smtpd.c プロジェクト: kp-org/eQmail
void die_alarm() { logit("timeout"); out("451 timeout (#4.4.2)\r\n"); flush(); _exit(1); }
コード例 #16
0
ファイル: 24点问题.cpp プロジェクト: alannet/example
void main() 
{ 
int p,q,r,s; 
int k,m,n; 
int temp,wap; 
int num,j; 


cout<<"请输入四个数:"<<endl; 
for(j=1;j<NUM;j++) 
cin>>array[j]; 
for(p=1;p<NUM;p++) 
for(q=1;q<NUM;q++) 
for(r=1;r<NUM;r++) 
for(s=1;s<NUM;s++) 
{//sssssssssssssssssssssssssssssssssssssssssssss 
if(q!=p&&r!=p&&r!=q&&s!=p&&s!=q&&s!=r) 
{a=array[p];b=array[q];c=array[r];d=array[s];} 
else continue; 
for(k=1;k<NUM;k++) 
{ 
switch(k) 
{//k 
case 1: 
num=a+b;break; 
case 2: 
if(a>=b) 
num=a-b; 
else continue;break; 
case 3: 
num=a*b;break; 
case 4: 
if(a>=b&&b!=0&&a%b==0) 
num=a/b; 
else continue;break; 
} 
wap=num; 
for(m=1;m<NUM;m++) 
{//m 
num=wap; 
switch(m)//###################### 
{ 
case 1: 
if(k==3) 
{ 
if(a*b+c*d==GAME) 
output(k,m,3); 
if((c>=d&&d!=0&&c%d==0)&&(a*b+c/d==GAME)) 
output(k,m,4); 
} 
if(k==4) 
{ 
if(a/b+c*d==GAME) 
output(k,m,3); 
if((c>=d&&d!=0&&c%d==0)&&(a/b+c/d==GAME)) 
output(k,m,4); 
} 
num=num+c; 
break; 
case 2: 
if(k==3) 
{ 
if(a*b>=c*d&&(a*b-c*d==GAME)) 
output(k,m,3); 
if((c>=d&&d!=0&&c%d==0&&a*b>=c/d)&&(a*b-c/d==GAME)) 
output(k,m,4); 
} 
if(k==4) 
{ 
if(a/b>=c*d&&(a/b-c*d==GAME)) 
output(k,m,3); 
if((c>=d&&d!=0&&(c%d==0))&&a/b>c/d&&(a/b-c/d==GAME)) 
output(k,m,4); 
} 
if(num>=c) 
num=num-c; 
else continue; 
break; 
case 3: 
num=num*c;break; 
case 4: 
if(num>=c&&c!=0&&num%c==0) 
num=num/c; 
else continue;break; 
}//############################# 
temp=num; 
for(n=1;n<NUM;n++) 
{//n 
num=temp; 
switch(n) 
{ 
case 1: 
num=num+d;break; 
case 2: 
if(num>=d) 
num=num-d; 
else continue;break; 
case 3: 
num=num*d;break; 
case 4: 
if(num>=d&&d!=0&&num%d==0) 
num=num/d; 
else continue;break; 
} 
if(num==GAME) 
{ 
out(k,m,n); 
//goto END; 
} 
}///n 
}///m 
}///k 
}//sssssssssssssssssssssssssssssssssssssssssssssssssssssss 
//END:; 
if(!degree) 
cout<<"对不起,这四个数无解。"<<endl; 
} 
コード例 #17
0
ファイル: qmail-smtpd.c プロジェクト: kp-org/eQmail
void die_nomem() { out("421 out of memory (#4.3.0)\r\n"); flush(); _exit(1); }
コード例 #18
0
int main ( void )

/******************************************************************************/
/*
  Purpose:

    MAIN is the main program for FEM1D_PMETHOD.

  Discussion:

    FEM1D_PMETHOD implements the P-version of the finite element method.

    Program to solve the one dimensional problem:

      - d/dX (P dU/dX) + Q U  =  F

    by the finite-element method using a sequence of polynomials
    which satisfy the boundary conditions and are orthogonal
    with respect to the inner product:

      (U,V)  =  Integral (-1 to 1) P U' V' + Q U V dx

    Here U is an unknown scalar function of X defined on the
    interval [-1,1], and P, Q and F are given functions of X.

    The boundary values are U(-1) = U(1)=0.

    Sample problem #1:

      U=1-x^4,        P=1, Q=1, F=1.0+12.0*x^2-x^4

    Sample problem #2:

      U=cos(0.5*pi*x), P=1, Q=0, F=0.25*pi*pi*cos(0.5*pi*x)

    The program should be able to get the exact solution for
    the first problem, using NP = 2.

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    04 July 2013

  Author:

    Original FORTRAN77 version by Max Gunzburger, Teresa Hodge.
    C version by John Burkardt.

  Local Parameters:

    Local, double A[NP+1], the squares of the norms of the
    basis functions.

    Local, double ALPHA[NP], BETA[NP], the basis function 
    recurrence coefficients.

    Local, double F[NP+1].
    F contains the basis function coefficients that form the
    representation of the solution U.  That is,
      U(X)  =  SUM (I=0 to NP) F(I) * BASIS(I)(X)
    where "BASIS(I)(X)" means the I-th basis function
    evaluated at the point X.

    Local, int NP.
    The highest degree polynomial to use.

    Local, int NPRINT.
    The number of points at which the computed solution
    should be printed out at the end of the computation.

    Local, int PROBLEM, indicates the problem being solved.
    1, U=1-x^4, P=1, Q=1, F=1.0+12.0*x^2-x^4.
    2, U=cos(0.5*pi*x), P=1, Q=0, F=0.25*pi*pi*cos(0.5*pi*x).

    Local, int QUAD_NUM, the order of the quadrature rule.

    Local, double QUAD_W[QUAD_NUM], the quadrature weights.

    Local, double QUAD_X[QUAD_NUM], the quadrature abscissas.
*/
{
# define NP 2
# define QUAD_NUM 10

  double a[NP+1];
  double alpha[NP];
  double beta[NP];
  double f[NP+1];
  int nprint = 10;
  int problem = 2;
  double quad_w[QUAD_NUM];
  double quad_x[QUAD_NUM];

  timestamp ( );
  printf ( "\n" );
  printf ( "FEM1D_PMETHOD\n" );
  printf ( "  C version\n" );
  printf ( "\n" );
  printf ( "  Solve the two-point boundary value problem\n" );
  printf ( "\n" );
  printf ( "  - d/dX (P dU/dX) + Q U  =  F\n" );
  printf ( "\n" );
  printf ( "  on the interval [-1,1], with\n" );
  printf ( "  U(-1) = U(1) = 0.\n" );
  printf ( "\n" );
  printf ( "  The P method is used, which represents U as\n" );
  printf ( "  a weighted sum of orthogonal polynomials.\n" );
  printf ( "\n" );
  printf ( "  Highest degree polynomial to use is %d\n", NP );
  printf ( "  Number of points to be used for output = %d\n", nprint );

  if ( problem == 1 )
  {
    printf ( "\n" );
    printf ( "  Problem #1:\n" );
    printf ( "  U=1-x^4,\n" );
    printf ( "  P=1,\n" );
    printf ( "  Q=1,\n" );
    printf ( "  F=1 + 12 * x^2 - x^4\n" );
  }
  else if ( problem == 2 )
  {
    printf ( "\n" );
    printf ( "  Problem #2:\n" );
    printf ( "  U=cos(0.5*pi*x),\n" );
    printf ( "  P=1,\n" );
    printf ( "  Q=0,\n" );
    printf ( "  F=0.25*pi*pi*cos(0.5*pi*x)\n" );
  }
/*
  Get quadrature abscissas and weights for interval [-1,1].
*/
  quad ( QUAD_NUM, quad_w, quad_x );
/*
  Compute the constants for the recurrence relationship
  that defines the basis functions.
*/
  alpbet ( a, alpha, beta, NP, problem, QUAD_NUM, quad_w, quad_x );
/*
  Test the orthogonality of the basis functions.
*/
  ortho ( a, alpha, beta, NP, problem, QUAD_NUM, quad_w, quad_x );
/*
  Solve for the solution of the problem, in terms of coefficients
  of the basis functions.
*/
  sol ( a, alpha, beta, f, NP, problem, QUAD_NUM, quad_w, quad_x );
/*
  Print out the solution, evaluated at each of the NPRINT points.
*/
  out ( alpha, beta, f, NP, nprint );
/*
  Compare the computed and exact solutions.
*/
  exact ( alpha, beta, f, NP, nprint, problem, QUAD_NUM, quad_w, quad_x );
/*
  Terminate.
*/
  printf ( "\n" );
  printf ( "FEM1D_PMETHOD\n" );
  printf ( "  Normal end of execution.\n" );
  printf ( "\n" );
  timestamp ( );

  return 0;
# undef NP
# undef QUAD_NUM
}
コード例 #19
0
ファイル: qmail-smtpd.c プロジェクト: kp-org/eQmail
void die_ipme() { logit("unable to figure out my IP addresses"); out("421 unable to figure out my IP addresses (#4.3.0)\r\n"); flush(); _exit(1); }
コード例 #20
0
ファイル: BinaryDataGenerator.cpp プロジェクト: robojan/EMGL
void BinaryDataGenerator::SaveCharmap(const CharMap &charmap, bool compress,
	enum OutputFormat format, const wxString &filePath)
{
	// Try opening the file for writing
	wxFFileOutputStream file(filePath);
	if (!file.IsOk()) {
		wxLogError(_("Could not open the file for writing"));
		return;
	}
	wxDataOutputStream out(file);
	out.BigEndianOrdered(false);
	out.UseBasicPrecisions();

	int numCodePages = charmap.GetCountCodePages();
	int headerSize = sizeof(wxUint32) + sizeof(wxInt16) + 2 * sizeof(wxUint8) + numCodePages * sizeof(wxUint32);
	int codePageBaseSize = sizeof(wxUint32) * 2 + 16;

	wxASSERT(numCodePages <= UINT8_MAX);
	if(compress) wxLogDebug("Compression not supported yet");
	// TODO: add compression
	// Write header
	wxUint32 magic = 'EMGF';
	wxUint8 flags = format;
	if (compress) flags |= FLAG_COMPRESSED;
	int ascender = 0;
	int ascenderDiv = 0;
	out.Write32(magic);
	file.SeekO(sizeof(wxInt16), wxFromCurrent);
	out.Write8(flags);
	out.Write8((wxUint8)numCodePages);

	wxUint32 *codepagePtrs = new wxUint32[numCodePages];
	wxUint32 **glyphPtrs = new wxUint32*[numCodePages];

	// Write codepages
	file.SeekO(headerSize);
	std::list<CodePage *>::const_iterator it = charmap.CBegin();
	for (int i = 0; i < numCodePages; i++) {
		wxASSERT(it != charmap.CEnd());
		codepagePtrs[i] = file.TellO();
		out.Write32((*it)->GetRangeStart());
		out.Write32((*it)->GetRangeEnd());
		const wxString &name = (*it)->GetName();
		for (unsigned int j = 0; j < 16; ++j) {
			out.Write8(j < name.Length() ? name.ToAscii()[j] : '\0');
		}
		glyphPtrs[i] = new wxUint32[(*it)->GetSize()];
		file.SeekO(sizeof(wxUint32) * (*it)->GetSize(), wxFromCurrent);
	}
	// Write glyphs
	it = charmap.CBegin();
	for (int i = 0; i < numCodePages; i++) {
		wxASSERT(it != charmap.CEnd());
		for (unsigned int j = 0; j < (*it)->GetSize(); j++) {
			const CharMapEntry *entry = (*it)->GetCharMapEntry((*it)->GetRangeStart() + j);
			if (entry == NULL) {
				glyphPtrs[i][j] = 0;
				continue;
			}
			LoadFont(entry->GetFamily(), entry->GetStyle(), entry->GetSize(), entry->GetEncodingID());
			wxUint32 glyph;
			if (!m_loadedFont.IsOk() || (glyph = m_loadedFont.GetGlyphIndex(entry->GetCode())) == 0)
			{
				wxLogWarning("Could not load glyph with code %u", (*it)->GetRangeStart() + j);
				glyphPtrs[i][j] = 0;
				continue;
			}
			wxPoint advance = m_loadedFont.GetGlyphAdvance(glyph);
			wxPoint bitmapTL = m_loadedFont.GetGlyphBitmapTL(glyph);
			int bitmapWidth, bitmapHeight;
			int bitmapSize = m_loadedFont.GetGlyphBitmap(glyph, NULL, &bitmapWidth, &bitmapHeight);
			if (bitmapSize < 0) {
				wxLogWarning("Error while getting bitmap for glyph with code %u", (*it)->GetRangeStart() + j);
				glyphPtrs[i][j] = 0;
				continue;
			}
			wxUint8 *bitmap = new wxUint8[bitmapSize];
			int result = m_loadedFont.GetGlyphBitmap(glyph, bitmap, &bitmapWidth, &bitmapHeight);
			wxASSERT(result == bitmapSize);

			bitmapSize = ConvertToFormat(bitmap, bitmapSize, format);

			if (compress) {
				CompressBitmap(&bitmap, &bitmapSize,  bitmapWidth * bitmapHeight, format);
			}

			ascender += m_loadedFont.GetAscender();
			ascenderDiv++;

			glyphPtrs[i][j] = file.TellO();
			out.Write16((wxInt16)advance.x);
			out.Write16((wxInt16)advance.y);
			out.Write16((wxInt16)bitmapTL.x);
			out.Write16((wxInt16)bitmapTL.y);
			out.Write16((wxUint16)bitmapWidth);
			out.Write16((wxUint16)bitmapHeight);
			out.Write32(bitmapSize);
			file.Write(bitmap, bitmapSize & ~(1<<31));
			delete[] bitmap;
		}
	}
	// Write glyph pointers
	it = charmap.CBegin();
	for (int i = 0; i < numCodePages; i++) {
		wxASSERT(it != charmap.CEnd());
		file.SeekO(codepagePtrs[i] + codePageBaseSize);
		for (unsigned int j = 0; j < (*it)->GetSize(); j++) {
			out.Write32(glyphPtrs[i][j]);
		}
		delete[] glyphPtrs[i];
		file.Sync();
	}
	delete[] glyphPtrs;
	
	// Write codepage pointers
	file.SeekO(headerSize - numCodePages * sizeof(wxUint32));
	for (int i = 0; i < numCodePages; i++) {
		out.Write32(codepagePtrs[i]);
	}
	delete[] codepagePtrs;
	delete[] glyphPtrs;

	// Write font wide parameters
	file.SeekO(sizeof(wxUint32));
	ascender = ascenderDiv > 0 ? ascender / ascenderDiv : 0;
	wxASSERT(ascender >= INT16_MIN && ascender <= INT16_MAX);
	out.Write16(ascender);

	file.Close();
}
コード例 #21
0
ファイル: qmail-smtpd.c プロジェクト: kp-org/eQmail
void err_size() { out("552 sorry, that message size exceeds my databytes limit (#5.3.4)\r\n"); }
コード例 #22
0
ファイル: mMultiObj.cpp プロジェクト: benmyb/OFEC_v0.4.2
void mMultiObj::outputResult()
{
	stringstream ss;
	ss<<Global::g_arg[param_workingDir]<<"Result/"<<m_fileName.str()<<"PF.txt";
    ofstream out(ss.str().c_str());
	for(int i=0;i<mvvv_obj.size();i++)
	{
		for(int j=0;j<mvvv_obj[0].size();j++)
		{
			for(int z=0;z<mvvv_obj[0][0].size();z++)
				out<<mvvv_obj[i][j][z]<<" ";
			out<<endl;
		}
		out<<endl;
		out<<"*******************************************"<<endl;
	}
	out.close();
	out.clear();
	ss.str("");
	ss<<Global::g_arg[param_workingDir]<<"Result/"<<m_fileName.str()<<"PS.txt";
	out.open(ss.str().c_str());
	for(int i=0;i<mvvv_point.size();i++)
	{
		for(int j=0;j<mvvv_point[0].size();j++)
		{
			for(int z=0;z<mvvv_point[0][0].size();z++)
				out<<mvvv_point[i][j][z]<<" ";
			out<<endl;
		}
		out<<endl;
		out<<"*******************************************"<<endl;
	}
	out.close();
	out.clear();
	ss.str("");

	if(mvv_distance.size()>0)
	{
		ss<<Global::g_arg[param_workingDir]<<"Result/"<<m_fileName.str()<<"distance.txt";
		out.open(ss.str().c_str());
		vector<double> sum;
		int max=mvv_distance[0].size();
		for(int i=1;i<mvv_distance.size();i++)
			if(max<mvv_distance[i].size())
				max=mvv_distance[i].size();
		for(int i=0;i<mvv_distance.size();i++)
		{
			if(mvv_distance[i].size()<max)
			{
				int size=mvv_distance[i].size();
				double evals=mvv_distance[i][size-2];
				double temp=mvv_distance[i][size-1];
				for(int j=size;j<max;j+=2)
				{
					mvv_distance[i].push_back(evals);
					mvv_distance[i].push_back(temp);
				}
			}
		}
		sum.resize(max,0);
		for(int i=0;i<max-1;i+=2)
		{
			for(int j=0;j<mvv_distance.size();j++)
			{
				sum[i]+=mvv_distance[j][i];
				sum[i+1]+=mvv_distance[j][i+1];
			}
			sum[i]/=mvv_distance.size();
			sum[i+1]/=mvv_distance.size();
		}
		for(int i=0;i<max-1;i+=2)
			out<<sum[i]<<" "<<sum[i+1]<<endl;
		out.close();
		out.clear();
	}

	ss.str("");
	out.clear();
	ss << Global::g_arg[param_workingDir] << "Result/" << m_fileName.str() << "suc.txt";
	out.open(ss.str().c_str());
	int maxNumrun = MAX_NUM_RUN;
	double peakRate = 0;
	for (int i = 0; i < maxNumrun; ++i) {
		int j;
		for (j = 0; j < m_fpsr[i].size(); ++j) {
			if (m_fpsr[i][j] == false) break;
		}
		if (j == m_fpsr[i].size()) m_suc++;
		double rate = 0;
		for (j = 0; j < m_fpsr[i].size(); ++j) {
			if (m_fpsr[i][j] == true) rate += 1;
		}
		peakRate += rate / m_fpsr[i].size();
	}
	out << m_suc*1.0 / maxNumrun<<" "<< peakRate/ maxNumrun;
	out.close();
	
}
コード例 #23
0
ファイル: qmail-smtpd.c プロジェクト: kp-org/eQmail
void err_nogateway()
{
  out("553 sorry, that domain isn't in my list of allowed rcpthosts");
  tls_nogateway();
  out(" (#5.7.1)\r\n");
}
コード例 #24
0
ファイル: os4.c プロジェクト: 593141477/v9-cpu
sys_write(fd, char *p, n) { int i; for (i=0; i<n; i++) out(fd, p[i]); return i; }
コード例 #25
0
ファイル: GraphicsEngineImp.cpp プロジェクト: Edaenge/NDYGFX
void GraphicsEngineImp::DebugDummyFunction(Vector3* arr) //**tillman**
{
	//Transform the points from world space to light’s homogeneous space.

	//View matrix
	D3DXVECTOR3 lookAt = D3DXVECTOR3(0, 0, 0);
	D3DXVECTOR3 pos = D3DXVECTOR3(-50, 50, -50);
	D3DXVECTOR3 posToLookAt = lookAt - pos; //Pos --> lookAt
	D3DXVECTOR3 dir;
	D3DXVECTOR3 up = D3DXVECTOR3(0, 1, 0);
	D3DXVec3Normalize(&dir, &posToLookAt); 
	lookAt = pos + dir;

	D3DXMATRIX lightViewMatrix;
	D3DXMatrixLookAtLH(&lightViewMatrix, &pos, &lookAt, &up); 

	//for(int i = 0; i < 30; i++)
	for(int i = 0; i < 24; i++)
	{
		D3DXVECTOR4 vertex = D3DXVECTOR4(arr[i].x, arr[i].y, arr[i].z, 1.0f);
		
		// Transform the point from world space to Light Camera Space.
		D3DXVec4Transform(&vertex, &vertex, &lightViewMatrix);
			
		arr[i].x = vertex.x;
		arr[i].y = vertex.y;
		arr[i].z = vertex.z;


		
	}
	
	// This next section of code calculates the min and max values for the orthographic projection.
	D3DXVECTOR3 vLightCameraOrthographicMin = D3DXVECTOR3(9999, 9999, 9999);
	D3DXVECTOR3 vLightCameraOrthographicMax = D3DXVECTOR3(-9999, -9999, -9999);

	D3DXVECTOR3 element = D3DXVECTOR3(0, 0, 0);
	//for(int i = 1; i < 10; i++)
	for(int i = 0; i < 8; i++)
	{
		//if(i != 5)
		//{
			element = D3DXVECTOR3(arr[i].x, arr[i].y, arr[i].z);
			// Find the closest point.
			D3DXVec3Minimize (&vLightCameraOrthographicMin, &element, &vLightCameraOrthographicMin );
			D3DXVec3Maximize (&vLightCameraOrthographicMax, &element, &vLightCameraOrthographicMax );
		//}
	}






	D3DXVECTOR3 minValue = D3DXVECTOR3(9999, 9999, 9999);
	D3DXVECTOR3 maxValue = D3DXVECTOR3(-9999, -9999, -9999);
	element = maxValue;
	//for(int index = 1; index < 10; index++) 
	for(int i = 0; i < 8; i++)
	{
		//if(index != 5)
		//{
			element = D3DXVECTOR3(arr[i].x, arr[i].y, arr[i].z);
			D3DXVec3Minimize(&minValue, &minValue, &element);
			D3DXVec3Maximize(&maxValue, &maxValue, &element);
		//}
	}

	float nearPlane = minValue.z;
	float farPlane = maxValue.z;

	//Create orthographics projection.
	// Craete the orthographic projection for this cascade.
	D3DXMATRIX lightProjMatrix;

	D3DXMatrixOrthoOffCenterLH( &lightProjMatrix, 
		vLightCameraOrthographicMin.x, 
		vLightCameraOrthographicMax.x, 
		vLightCameraOrthographicMin.y, 
		vLightCameraOrthographicMax.y, 
		nearPlane, farPlane);






	//test
	D3DXMATRIX inverseLightViewMatrix;
	D3DXMatrixIdentity(&inverseLightViewMatrix);
	D3DXMatrixInverse(&inverseLightViewMatrix, NULL, &lightViewMatrix);
	D3DXVECTOR4 minV = D3DXVECTOR4(minValue, 1.0f);
	D3DXVECTOR4 maxV = D3DXVECTOR4(maxValue, 1.0f);

	//for(int i = 2; i < 30; i++)

	for(int i = 0; i < 24; i++)
	{
		D3DXVECTOR4 vertex = D3DXVECTOR4(arr[i].x, arr[i].y, arr[i].z, 1.0f);

		// Transform the point from world space to Light Camera Space.
		D3DXVec4Transform(&vertex, &vertex, &inverseLightViewMatrix);

		arr[i].x = vertex.x;
		arr[i].y = vertex.y;
		arr[i].z = vertex.z;
	}

	D3DXVec4Transform(&minV, &minV, &inverseLightViewMatrix);
	D3DXVec4Transform(&maxV, &maxV, &inverseLightViewMatrix);

	
	ofstream out("Media/CSMDebug.obj");
	stringstream buffer;
	buffer	<< "# This file uses centimeters as units for non-parametric coordinates. \n"
			<< "mtllib CSMDebug.mtl \n"
			<< "g default \n";
	
	//for(int i = 1; i < 30; i++)
	for(int i = 0; i < 24; i++)
	{
		//if(i % 5 != 0)
		{
			buffer << "v " << arr[i].x << " " << arr[i].y << " " << arr[i].z << "\n";
		}
	}
	//for(int i = 1; i < 30; i++)
	for(int i = 0; i < 24; i++)
	{
		//if(i % 5 != 0)
		{
			buffer << "vt 0 0\n";
		}
	}
		//for(int i = 1; i < 30; i++)
	for(int i = 0; i < 24; i++)
	{
		//if(i % 5 != 0)
		{
			buffer << "vn 1 0 0\n";
		}
	}
	for(int i = 0; i < 3; i++)
	{
		buffer << "usemtl initialShadingGroup" + MaloW::convertNrToString(i + 1) + "\n";
		string nr1 = MaloW::convertNrToString(i * 8 + 1);
		string nr2 = MaloW::convertNrToString(i * 8 + 2);
		string nr3 = MaloW::convertNrToString(i * 8 + 3);
		buffer << "f " << nr1 << "/" << nr1 << "/" << nr1 << " " << nr2 << "/" << nr2 << "/" << nr2 << " " << nr3 << "/" << nr3 << "/" << nr3 << "\n";
		string nr4 = MaloW::convertNrToString(i * 8 + 2);
		string nr5 = MaloW::convertNrToString(i * 8 + 3);
		string nr6 = MaloW::convertNrToString(i * 8 + 4);
		buffer << "f " << nr4 << "/" << nr4 << "/" << nr4 << " " << nr5 << "/" << nr5 << "/" << nr5 << " " << nr6 << "/" << nr6 << "/" << nr6 << "\n";
		
		//TOP
		nr4 = MaloW::convertNrToString(i * 8 + 1);
		nr5 = MaloW::convertNrToString(i * 8 + 5);
		nr6 = MaloW::convertNrToString(i * 8 + 6);
		buffer << "f " << nr4 << "/" << nr4 << "/" << nr4 << " " << nr5 << "/" << nr5 << "/" << nr5 << " " << nr6 << "/" << nr6 << "/" << nr6 << "\n";
		nr4 = MaloW::convertNrToString(i * 8 + 1);
		nr5 = MaloW::convertNrToString(i * 8 + 6);
		nr6 = MaloW::convertNrToString(i * 8 + 2);
		buffer << "f " << nr4 << "/" << nr4 << "/" << nr4 << " " << nr5 << "/" << nr5 << "/" << nr5 << " " << nr6 << "/" << nr6 << "/" << nr6 << "\n";

		//BOTTOM
		nr4 = MaloW::convertNrToString(i * 8 + 3);
		nr5 = MaloW::convertNrToString(i * 8 + 7);
		nr6 = MaloW::convertNrToString(i * 8 + 8);
		buffer << "f " << nr4 << "/" << nr4 << "/" << nr4 << " " << nr5 << "/" << nr5 << "/" << nr5 << " " << nr6 << "/" << nr6 << "/" << nr6 << "\n";
		nr4 = MaloW::convertNrToString(i * 8 + 3);
		nr5 = MaloW::convertNrToString(i * 8 + 8);
		nr6 = MaloW::convertNrToString(i * 8 + 4);
		buffer << "f " << nr4 << "/" << nr4 << "/" << nr4 << " " << nr5 << "/" << nr5 << "/" << nr5 << " " << nr6 << "/" << nr6 << "/" << nr6 << "\n";

		//LEFT SIDE
		nr4 = MaloW::convertNrToString(i * 8 + 3);
		nr5 = MaloW::convertNrToString(i * 8 + 7);
		nr6 = MaloW::convertNrToString(i * 8 + 5);
		buffer << "f " << nr4 << "/" << nr4 << "/" << nr4 << " " << nr5 << "/" << nr5 << "/" << nr5 << " " << nr6 << "/" << nr6 << "/" << nr6 << "\n";
		nr4 = MaloW::convertNrToString(i * 8 + 3);
		nr5 = MaloW::convertNrToString(i * 8 + 5);
		nr6 = MaloW::convertNrToString(i * 8 + 1);
		buffer << "f " << nr4 << "/" << nr4 << "/" << nr4 << " " << nr5 << "/" << nr5 << "/" << nr5 << " " << nr6 << "/" << nr6 << "/" << nr6 << "\n";

		//RIGHT SIDE
		nr4 = MaloW::convertNrToString(i * 8 + 2);
		nr5 = MaloW::convertNrToString(i * 8 + 6);
		nr6 = MaloW::convertNrToString(i * 8 + 8);
		buffer << "f " << nr4 << "/" << nr4 << "/" << nr4 << " " << nr5 << "/" << nr5 << "/" << nr5 << " " << nr6 << "/" << nr6 << "/" << nr6 << "\n";
		nr4 = MaloW::convertNrToString(i * 8 + 2);
		nr5 = MaloW::convertNrToString(i * 8 + 8);
		nr6 = MaloW::convertNrToString(i * 8 + 4);
		buffer << "f " << nr4 << "/" << nr4 << "/" << nr4 << " " << nr5 << "/" << nr5 << "/" << nr5 << " " << nr6 << "/" << nr6 << "/" << nr6 << "\n";

	}
	out << buffer.str().c_str() << endl;
	out.close();

	//arr[0] = Vector3(minV.x, minV.y, minV.z);
	//arr[1] = Vector3(maxV.x, maxV.y, maxV.z);

}
コード例 #26
0
ファイル: server.cpp プロジェクト: OspreyHub/ATCD
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  int ec = 0;
  try {
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    int max_run = 0;
    int server_num = 0;
    int init_delay_secs = 0;
    const ACE_TCHAR *ior_file_name = ACE_TEXT ("");
    ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("d:m:n:o:?"));
    int c;

    while ((c = get_opts ()) != -1)
      switch (c)
        {
        case 'd':
          init_delay_secs = ACE_OS::atoi (get_opts.opt_arg ());
          break;
        case 'm':
          max_run = ACE_OS::atoi (get_opts.opt_arg ());
          break;
        case 'n':
          server_num = ACE_OS::atoi (get_opts.opt_arg ());
          break;
        case 'o':
          ior_file_name = get_opts.opt_arg ();
          break;
        case '?':
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("usage: %s ")
                      ACE_TEXT ("-d <seconds to delay before initializing POA> ")
                      ACE_TEXT ("-n Number of the server\n"),
                      argv[0]));
          return 1;
          break;
        }

    ACE_OS::sleep (init_delay_secs);

    CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
    PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in());

    PortableServer::POAManager_var mgr = root_poa->the_POAManager();

    ACE_CString poa_name = ACE_CString("TestObject_") + toStr (server_num);

    PortableServer::POA_var test_poa = createPOA(root_poa.in(), poa_name.c_str ());

    Test_i *impl = new Test_i(orb.in());
    PortableServer::Servant_var<Test_i> test_servant = impl;

    PortableServer::ObjectId_var object_id =
      PortableServer::string_to_ObjectId("test_object");

    //
    // Activate the servant with the test POA,
    // obtain its object reference, and get a
    // stringified IOR.
    //
    test_poa->activate_object_with_id(object_id.in(), test_servant.in());

    //
    // Create binding between "TestService" and
    // the test object reference in the IOR Table.
    // Use a TAO extension to get the non imrified poa
    // to avoid forwarding requests back to the ImR.

    TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*>(test_poa.in());
    obj = tpoa->id_to_reference_i(object_id.in(), false);
    CORBA::String_var test_ior = orb->object_to_string(obj.in());
    obj = orb->resolve_initial_references("IORTable");
    IORTable::Table_var table = IORTable::Table::_narrow(obj.in());
    table->bind(poa_name.c_str (), test_ior.in());

    if (ACE_OS::strlen (ior_file_name) > 0)
      {
        obj = test_poa->id_to_reference (object_id.in ());
        test_ior = orb->object_to_string (obj.in ());
        FILE *f = ACE_OS::fopen (ior_file_name, ACE_TEXT ("w"));
        ACE_OS::fprintf (f, "%s", test_ior.in ());
        ACE_OS::fclose (f);
      }

    //
    // This server is now ready to run.
    // This version does not create an IOR
    // file as demonstrated in the
    // Developer's Guide.  It assumes that
    // users create IORs for the client using
    // the tao_imr utility.
    //
    //
    // Stop discarding requests.
    //
    mgr->activate();

    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("Started Server <%C> pid = %d\n"),
                poa_name.c_str(), ACE_OS::getpid ()));

    ACE_CString pid_file = "server.pid";
    {
      ofstream out(pid_file.c_str (), ios_base::app);
      out << ACE_OS::getpid () << endl;
      out.close ();
    }
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("Server <%C> pid = %d closed pidfile\n"),
                poa_name.c_str(), ACE_OS::getpid ()));

    if (max_run > 0)
      {
        ACE_Time_Value tv (max_run,0);
        orb->run (tv);
      }
    else
      {
        orb->run ();
      }
    ec = impl->exit_code ();
    root_poa->destroy(1,1);
    orb->destroy();

    //    ACE_OS::unlink (pid_file.c_str ());

  }
  catch(const CORBA::Exception& ex) {
    ex._tao_print_exception (ACE_TEXT ("Server main()"));
    return 1;
  }

  return ec;
}
コード例 #27
0
int main()
{

	std::ifstream in( BINARY_DIR "/input.txt", std::ios::in | std::ios::binary );

	if( !in.is_open() )
	{
		std::cerr << "Unable to open input.txt";
		return 1;
	}

	std::map<uint32_t, size_t> size_by_types;

	messages_counter counter;
	messages_counter::time_counter_t curr_time_messages_by_types;
	uint32_t curr_time = 0;

	while( !in.eof() )
	{
		binary_reader::market_message message( in );

		if( message.eof() )
		{
			break;
		}

		if( size_by_types[ message.type() ] + message.size() > MAX_BUFF_SIZE )
		{
			continue;
		}

		if( message.time() != curr_time )
		{
			counter.merge( curr_time_messages_by_types );

			size_by_types.clear();
			curr_time_messages_by_types.clear();
			curr_time = message.time();
		}

		curr_time_messages_by_types[ message.type() ]++;
		size_by_types[ message.type() ] += message.size();
	}

	in.close();

	counter.merge( curr_time_messages_by_types );

	std::ofstream out( BINARY_DIR "/output.txt", std::ios::binary );

	try
	{
		counter.output_avg( out );
	}
	catch( std::logic_error &error )
	{
		std::cerr << error.what();
	}

	out.close();
}
コード例 #28
0
int main()
{
   
  cout  << setiosflags(ios::uppercase);
  /*
  ofstream out("GAUSS.out");
  out   << setiosflags(ios::uppercase);
  ofstream dout("GAUSSMOD.out");
  dout  << setiosflags(ios::uppercase);
  */

  mp_init();
  cout << "+++ Precision = " << mpipl << " +++" << endl;
 

  double s_in, h_in , b1_in, b2_in, db, g_in, dpi, x1_in, x2_in;
  int N, Nb, m, Control;

  dpi = 4.0 * atan(1.0);
  
  mp_real pi = mppic; // pi aus der Bibliothek !!!
  mp_real pi2 = pi * pi;
  static mp_real factor;
  
  mp_real b, b1, b2, bstep, g, x0, s, h, x1, x2;

  /* Parameter als doubles einlesen */
  cin >> b1_in >> b2_in >> Nb;
  cin >> g_in >> Control;
  cin >> s_in >> h_in >> N;
  cin >> x1_in >> x2_in >> m;

  /* Konversion: double -> mp_real */
  b1  = mp_real(b1_in);
  b2  = mp_real(b2_in);
  g  = mp_real(g_in);
  s  = mp_real(s_in);
  h  = mp_real(h_in);
  x1 = mp_real(x1_in);
  x2 = mp_real(x2_in);
//  a  = 1/(mp_real(2.0)*b1);

  bstep = (b2 - b1)/mp_real(Nb);


  /* Vorfaktor */
//  factor = mp_real(2.0)*b/power(pi,mp_real(1.5));
//  factor *= exp(mp_real(0.25) * pi2 * b * b);
  
  //dfactor = 2.0 * (b_in/pow(dpi,1.5)) * exp(b_in*b_in*dpi*dpi*.25);

  cout << "*** Parameter ***" << endl; 
  cout << "b1     = " << b1 ;
  cout << "b2     = " << b2 ;
  cout << "bstep  = " << bstep ;
  //cout << "a      = " << a;
  cout << "g      = " << g;
  cout << "h      = " << h;
  cout << "N      = " << N << endl;
  cout << '\v' ;
  cout << "x1     = " << x1;
  cout << "x2     = " << x2;
  cout << "m      = " << m << endl;
  
  cout << "xmax   = " << h * N << endl;
  
//  cout << "dfaktor = " <<dfactor << endl;
//  cout << "Faktor = " <<factor << endl;


  /* Datendatei */

  String data = "GAUSSMOD-N" ;
  data = data + N + "-xb" + x2_in + "-beta" + strdup(fix3(g_in)) + ".out"; 
  ofstream dout(data());
  
  
  
  mp_real mp_E2_Gauss, mp_E2_Gausstheo, mp_Reg, mp_Regtheo, mp_ModGauss, step;
  mp_real mp_diffrel, mp_diffrelreg;
  double E2, E2_Gauss, E2_Gausstheo, Reg, Reg_theod, ModGauss, diffrel, x0d;
  double diffrelreg;
  
  step = (x2 -x1)/mp_real(m);


  if(Control == 1)
    {
	cout << "*** Begin: Read Data ***" << endl; 
      for(int j = 0; j <= m; j++)
	{
	  x0 = x1 + j * step; 
	  mp_E2_Gauss = mpe2gauss(x0,g);
	  mp_E2_Gausstheo = mpe2gausstheo(x0,g);
	  mp_real mpdeltarel = abs(mp_E2_Gauss - mp_E2_Gausstheo)/abs(mp_E2_Gausstheo);
	  mpdeltarel *= mp_real(100.0);
	  
	  x0d = dble(x0);
	  E2 = e2(x0d);
	  E2_Gauss        = dble(mp_E2_Gauss);
	  E2_Gausstheo    = dble(mp_E2_Gausstheo);
	  double deltarel = dble(mpdeltarel);
	  cout << x0 << mp_E2_Gausstheo << mp_E2_Gauss << mpdeltarel << endl;;

	  (ostream&) dout << x0d << '\t' << E2 << '\t' << E2_Gausstheo <<'\t' << E2_Gauss << '\t' << deltarel << endl;
      	}
      cout << "*** End: Read Data ***" << endl; 
    }



  cout << "*** Begin: Regularisation Scan ***" << endl;
  for(int i = 0; i <= Nb; i++)
  {
      b = b1 + i * bstep;
      db = dble(b);
      factor = mp_real(2.0)*b/power(pi,mp_real(1.5));
      factor *= exp(mp_real(0.25) * pi2 * b * b);

      /* RegDatei */
      String reg = "GAUSSREG-N" ;
      reg = reg + N + "-xb" + x2_in + "-beta" + strdup(fix3(g_in)) + "-b" + strdup(fix3(db)) + ".out"; 
      ofstream out(reg());
      
      cout << " +++ i = " << i << ",  " << " b = " << db << " +++ " << endl;
      cout << '\v' ;
      
  for(int jj = 0; jj <= m; jj++)
    {
      x0 = x1 + jj * step;
      s = x0;
      mp_Reg = mptrapez(mpkern,x0,b,g,s,h,N);
      mp_Reg *= factor;
  
      mp_Regtheo  = Regtheo(x0,b,g); //reine Regularisierte
      mp_ModGauss = GaussDichte(x0,g); //Gaussdichte als Modell
      
      
      mp_diffrel = abs(mp_Reg - mp_Regtheo)/abs(mp_Regtheo);
      mp_diffrel *= mp_real(100.0);
      
      mp_diffrelreg  = abs(mp_Reg - mp_ModGauss)/abs(mp_ModGauss);
      mp_diffrelreg *= mp_real(100.0);

      Reg_theod  = dble(mp_Regtheo);
      Reg        = dble(mp_Reg);
      ModGauss   = dble(mp_ModGauss);
      diffrel    = dble(mp_diffrel);
      diffrelreg = dble(mp_diffrelreg);
      x0d        = dble(x0);

      cout << x0 << mp_Reg << mp_Regtheo << mp_ModGauss << mp_diffrel << mp_diffrelreg<< endl;


      (ostream&) out << x0d << '\t' << ModGauss << '\t' << Reg << '\t' << Reg_theod<< '\t' << diffrel <<'\t' << diffrelreg << endl;
      
    }
  }
  cout << "*** End: Regularisation Scan ***" << endl;
  return 0;
}
コード例 #29
0
ファイル: cloner.cpp プロジェクト: pooyadavoodi/mongo
        void operator()( DBClientCursorBatchIterator &i ) {
            Lock::GlobalWrite lk;
            DurTransaction txn;
            context.relocked();

            bool createdCollection = false;
            Collection* collection = NULL;

            while( i.moreInCurrentBatch() ) {
                if ( numSeen % 128 == 127 /*yield some*/ ) {
                    collection = NULL;
                    time_t now = time(0);
                    if( now - lastLog >= 60 ) {
                        // report progress
                        if( lastLog )
                            log() << "clone " << to_collection << ' ' << numSeen << endl;
                        lastLog = now;
                    }
                    mayInterrupt( _mayBeInterrupted );
                    dbtempreleaseif t( _mayYield );
                }

                if ( isindex == false && collection == NULL ) {
                    collection = context.db()->getCollection( to_collection );
                    if ( !collection ) {
                        massert( 17321,
                                 str::stream()
                                 << "collection dropped during clone ["
                                 << to_collection << "]",
                                 !createdCollection );
                        createdCollection = true;
                        collection = context.db()->createCollection( &txn, to_collection );
                        verify( collection );
                    }
                }

                BSONObj tmp = i.nextSafe();

                /* assure object is valid.  note this will slow us down a little. */
                const Status status = validateBSON(tmp.objdata(), tmp.objsize());
                if (!status.isOK()) {
                    out() << "Cloner: skipping corrupt object from " << from_collection
                          << ": " << status.reason();
                    continue;
                }

                ++numSeen;

                BSONObj js = tmp;
                if ( isindex ) {
                    verify(nsToCollectionSubstring(from_collection) == "system.indexes");
                    js = fixindex(context.db()->name(), tmp);
                    indexesToBuild->push_back( js.getOwned() );
                    continue;
                }

                verify(nsToCollectionSubstring(from_collection) != "system.indexes");

                StatusWith<DiskLoc> loc = collection->insertDocument( &txn, js, true );
                if ( !loc.isOK() ) {
                    error() << "error: exception cloning object in " << from_collection
                            << ' ' << loc.toString() << " obj:" << js;
                }
                uassertStatusOK( loc.getStatus() );
                if ( logForRepl )
                    logOp("i", to_collection, js);

                getDur().commitIfNeeded();

                RARELY if ( time( 0 ) - saveLast > 60 ) {
                    log() << numSeen << " objects cloned so far from collection " << from_collection;
                    saveLast = time( 0 );
                }
            }
        }
コード例 #30
0
ファイル: BinFilter.cpp プロジェクト: eimix/trunk
CC_FILE_ERROR BinFilter::saveToFile(ccHObject* root, const char* filename)
{
	if (!root || !filename)
		return CC_FERR_BAD_ARGUMENT;

	QFile out(filename);
	if (!out.open(QIODevice::WriteOnly))
		return CC_FERR_WRITING;

	//About BIN versions:
	//- 'original' version (file starts by the number of clouds - no header)
	//- 'new' evolutive version, starts by 4 bytes ("CCB2") + save the current ccObject version

	//header
	char firstBytes[5] = "CCB2";
	if (out.write(firstBytes,4)<0)
		return CC_FERR_WRITING;

	// Current BIN file version
	uint32_t binVersion = (uint32_t)s_currentObjVersion;
	if (out.write((char*)&binVersion,4)<0)
		return CC_FERR_WRITING;

	CC_FILE_ERROR result = CC_FERR_NO_ERROR;

	//we check if all linked entities are in the sub tree we are going to save
	//(such as vertices for a mesh!)
	ccHObject::Container toCheck;
	toCheck.push_back(root);
	while (!toCheck.empty())
	{
		ccHObject* currentObject = toCheck.back();
		assert(currentObject);
		toCheck.pop_back();

		//we check objects that have links to other entities (meshes, polylines, etc.)
		std::vector<const ccHObject*> dependencies;
		if (currentObject->isKindOf(CC_MESH))
		{
			ccGenericMesh* mesh = static_cast<ccGenericMesh*>(currentObject);
			if (mesh->getAssociatedCloud())
				dependencies.push_back(mesh->getAssociatedCloud());
			if (mesh->getMaterialSet())
				dependencies.push_back(mesh->getMaterialSet());
		}
		else if (currentObject->isKindOf(CC_POLY_LINE))
		{
			CCLib::GenericIndexedCloudPersist* cloud = static_cast<ccPolyline*>(currentObject)->getAssociatedCloud();
			//TODO: dirty!
			dependencies.push_back(dynamic_cast<ccPointCloud*>(cloud));
		}
		else if (currentObject->isA(CC_2D_LABEL))
		{
			cc2DLabel* label = static_cast<cc2DLabel*>(currentObject);
			for (unsigned i=0;i<label->size();++i)
			{
				const cc2DLabel::PickedPoint& pp = label->getPoint(i);
				if (dependencies.empty() || pp.cloud != dependencies.back())
					dependencies.push_back(pp.cloud);
			}
		}

		while (!dependencies.empty())
		{
			if (!root->find(dependencies.back()->getUniqueID()))
			{
				ccLog::Warning(QString("Dependency broken: entity '%1' must also be in selection in order to save '%2'").arg(dependencies.back()->getName()).arg(currentObject->getName()));
				result = CC_FERR_BROKEN_DEPENDENCY_ERROR;
			}
			dependencies.pop_back();
		}

		for (unsigned i=0;i<currentObject->getChildrenNumber();++i)
			toCheck.push_back(currentObject->getChild(i));
	}

	if (result == CC_FERR_NO_ERROR)
		if (!root->toFile(out))
			result = CC_FERR_CONSOLE_ERROR;

	out.close();

	return result;
}