void relationRecon(char *fileName)
/* Do relationship based reconstruction. */
{
char **words;
long start, end;
struct sqlConnection *conn = sqlConnect(database);
struct sqlResult *sr;
char **row;
FILE *f = mustOpen(fileName, "w");
int lineCount;
int i;
char query[256];

start = clock1000();
words = loadWords();
end = clock1000();
printf("Time to load words: %4.3f\n", 0.001*(end-start));
start = clock1000();

lineCount = sqlTableSize(conn, "lineSize");
for (i=0; i<lineCount; ++i)
    {
    sprintf(query, "select * from lineWords where line = %d", i);
    sr = sqlQuery(conn, query);
    while ((row = sqlNextRow(sr)) != NULL)
	fileOutput(f,words[sqlUnsigned(row[1])]);
    sqlFreeResult(&sr);
    }
end = clock1000();
printf("Time to relation reconstruct file: %4.3f\n", 0.001*(end-start));
sqlDisconnect(&conn);
}
Exemplo n.º 2
0
Reference<Bitmap> StreamerSDL::loadBitmap(std::istream & input) {
	// Save the bitmap to a file temporarily.
	static TemporaryDirectory tempDir("StreamerSDL");

	FileName fileName(tempDir.getPath());
	do {
		fileName.setFile(StringUtils::createRandomString(16) + ".bmp");
	} while(FileUtils::isFile(fileName));

	std::ofstream fileOutput(fileName.getPath().c_str(), std::ios_base::binary);
	if(!fileOutput.good()) {
		fileOutput.close();
		FileUtils::remove(fileName);
		return nullptr;
	}
	fileOutput << input.rdbuf();
	fileOutput.close();

	SDL_Surface * surface = SDL_LoadBMP(fileName.getPath().c_str());
	if (surface == nullptr) {
		FileUtils::remove(fileName);
		return nullptr;
	}
	auto bitmap = BitmapUtils::createBitmapFromSDLSurface(surface);
	SDL_FreeSurface(surface);

	FileUtils::remove(fileName);

	return bitmap;
}
Exemplo n.º 3
0
// save the world
void MenuBar::do_world_save( const char* filename ) {
	
	ofstream fileOutput( filename );
	
	// if we can't open a new file (access permissions, etc), then bail
	if(!fileOutput.is_open()) {
		parent->error( TextUtils::format("Could not open %s for writing\n", filename).c_str() );
		return;	
	}
	
	string text = parent->getModel()->toString();
	
	fileOutput.write( text.c_str(), text.size() );
	fileOutput.close();
	
}
Exemplo n.º 4
0
void l1menu::ReducedSample::saveToFile( const std::string& filename ) const
{
	// Open the file. Parameters are filename, write ability and create, rw-r--r-- permissions.
	int fileDescriptor = open( filename.c_str(), O_WRONLY | O_CREAT, 0644 );
	if( fileDescriptor==0 ) throw std::runtime_error( "ReducedSample save to file - couldn't open file" );
	::UnixFileSentry fileSentry( fileDescriptor ); // Use this as an exception safe way of closing the output file

	// Setup the protobuf file handlers
	google::protobuf::io::FileOutputStream fileOutput( fileDescriptor );

	// I want the magic number and file format identifier uncompressed, so
	// I'll write those before switching to using gzipped output.
	{ // Block to make sure codedOutput is destructed before the gzip version is created
		google::protobuf::io::CodedOutputStream codedOutput( &fileOutput );

		// Write a magic number at the start of all files
		codedOutput.WriteString( pImple_->FILE_FORMAT_MAGIC_NUMBER );
		// Write an integer that specifies what version of the file format I'm using. I
		// have no intention of changing the format but I might as well keep the option
		// open.
		codedOutput.WriteVarint32( 1 );
	}

	google::protobuf::io::GzipOutputStream gzipOutput( &fileOutput );
	google::protobuf::io::CodedOutputStream codedOutput( &gzipOutput );

	// Write the size of the header message into the file...
	codedOutput.WriteVarint64( pImple_->protobufSampleHeader.ByteSize() );
	// ...and then write the header
	pImple_->protobufSampleHeader.SerializeToCodedStream( &codedOutput );

	// Now go through each of the runs and do the same for those
	for( const auto& pRun : pImple_->protobufRuns )
	{
		codedOutput.WriteVarint64( pRun->ByteSize() );
		pRun->SerializeToCodedStream( &codedOutput );
	}

}
int main_FileCopy ()
{
	std::ifstream fileInput("RepeatArray.cpp",std::ios::binary);
	std::ofstream fileOutput("testing.txt",std::ios::binary);
	char line[10]={};
	
    int filesize;
    struct stat  results;
    
    if (stat("RepeatArray.cpp", &results) == 0)
	{ 
       filesize= results.st_size;
	}
    else
	{ 
		printf("Error\n"); 
	}

	printf("size of file %d\n",filesize);
	
	const int chunk=10;
	
	int size = filesize;
	while(size>chunk)
	{
	
	fileInput.read(line,chunk);	
	fileOutput.write(line,chunk) ;	
	size =size-chunk;
	}

	fileInput.read(line,size);		
	fileOutput.write(line,size);

	fileInput.close();
	fileOutput.close();
  return 0;
}
void commaRecon(char *fileName)
/* Do comma based reconstruction. */
{
char **words;
long start, end;
struct sqlConnection *conn = sqlConnect(database);
struct sqlResult *sr;
char **row;
FILE *f = mustOpen(fileName, "w");

start = clock1000();
words = loadWords();
end = clock1000();
printf("Time to load words: %4.3f\n", 0.001*(end-start));
start = clock1000();

sr = sqlQuery(conn, "SELECT * from commaLine");
while ((row = sqlNextRow(sr)) != NULL)
    {
    int wordCount = sqlUnsigned(row[1]);
    int i;
    char *s = row[2],*e;
    int wordIx;
    for (i=0; i<wordCount; ++i)
	{
	e = strchr(s,',');
	*e++ = 0;
	wordIx = sqlUnsigned(s);
	s = e;
	fileOutput(f,words[wordIx]);
	}
    }
end = clock1000();
printf("Time to comma reconstruct file: %4.3f\n", 0.001*(end-start));
sqlDisconnect(&conn);
}
Exemplo n.º 7
0
int 
plotCellWave(int argc, char *argv[])
{
  Overture::start(argc,argv);  // initialize Overture

  cout << "Type: `plotCellWave fileName [file.cmd]' to read the show file called fileName \n";
  cout << "       and optionally start reading a command file \n";

  aString nameOfShowFile, commandFileName;
  nameOfShowFile="";
  if( argc > 1 )
  {
    nameOfShowFile=argv[1];
    int l=nameOfShowFile.length()-1;
    if( l>2 && nameOfShowFile(l-3,l)==".cmd" )
    {
      commandFileName=nameOfShowFile;
      nameOfShowFile="";
    }
    else if( argc>2 )
      commandFileName=argv[2];
  }
  
  bool done=FALSE;
    
// create a Graphics Interface
  GenericGraphicsInterface & ps 
    = *Overture::getGraphicsInterface("CellWave visualization",TRUE); 
  GraphicsParameters psp;       // create an object that is used to pass parameters
  aString movieFileName;
    
  // By default start saving the command file called "plotStuff.cmd"
  aString logFile="out_plotCellWave.cmd";
  ps.saveCommandFile(logFile);
  cout << "User commands are being saved in the file `" << (const char *)logFile << "'\n";

  // read from a command file if given
  if( commandFileName!="" )
    ps.readCommandFile(commandFileName);

  checkArrays("plotStuff: before loop");
  aString *sequenceName = NULL;

  // this loop is used to look at more than one file
  while( !done )
  {
    // cout << ">> Enter the name of the show file:" << endl;
    // cin >> nameOfShowFile;
    if( nameOfShowFile=="" )
      ps.inputString(nameOfShowFile,">> Enter the name of the show file:");

    ShowFileReader showFileReader(nameOfShowFile);

    int numberOfFrames=showFileReader.getNumberOfFrames();
    int numberOfSolutions = max(1,numberOfFrames);
    int numberOfComponents;
    int numberOfSequences=showFileReader.getNumberOfSequences();
    if( numberOfSequences>0 )
    {
      delete [] sequenceName;
      sequenceName = new aString[numberOfSequences];
      showFileReader.getSequenceNames(sequenceName,numberOfSequences);
    }
    

    CompositeGrid cg;  

    // set up a function for contour plotting:
    Range all;
    realCompositeGridFunction u;

    char buff[120];
    aString answer,answer2;
    aString menu0[]= { "!plotStuff",
		       "contour",
		       "line plot",
		       "probe plot",
		       "stream lines",
		       "grid",
		       ">sequence",
		       "<next",
		       "previous",
		       ">choose a component", 
		       "<>choose a solution", 
		       "<next component",
		       "previous component", 
		       "derived types",
		       "movie",
		       "movie and save",
		       ">plot bounds",
		       "set plot bounds",
		       "use default plot bounds",
		       "<check mappings with grid",
		       "erase",
		       "redraw",
		       "open a new file",
		       "file output",
		       "help",
		       "exit",
		       "" };
    aString help[]= { 
       "contour                    : plot contours (surfaces)",
       "line plot                  : plot line cut across solution field",
       "probe plot                 : plot timehistory of field at probe locations",
       "stream lines               : draw stream lines",
       "grid                       : plot the grid",
       "sequence                   : plot a sequence that has been saved in the show file",
       "next                       : plot the next solution of all items on the screen",
       "previous                   : plot the previous solution of all items on the screen" ,
       "choose a component         : plot a different component of all items on the screen", 
       "choose a solution          : plot a different solution of all items on the screen", 
       "next component             : plot the next component of all items on the screen",
       "previous component         : plot the previous component of all items on the screen", 
       "derived types              : define new quantities such as vorticity, derivatives etc.",
       "movie                      : plot the next `n' solutions",
       "movie and save             : plot the next `n' solutions and save each as a postscript file",
       "set plot bounds            : specify fixed bounds for plotting. Useful for movies.",
       "use default plot bounds    : let plotStuff determine the plotting bounds",
       "check mappings with grid   : call the checkMapping routine",
       "erase                      : erase everything",
       "redraw                     : force a redraw (useful to call from command files)",
       "open a new file            : open a new show file to read",
       "file output                : output solutions to a file (ascii)",
       "help",
       "exit",
       "" };

    int plotOptions = 0;
    bool plotNewFunction = FALSE;
    bool plotNewComponent= FALSE;
    bool movieMode=FALSE;
    int numberOfMovieFrames=numberOfFrames;
    int solutionNumber=1;
    int component = 0;
    int numberOfHeaderComments;
    
    const aString *headerComment; // This array holds the comments that should go in the plot
    showFileReader.getASolution(solutionNumber,cg,u);
    headerComment=showFileReader.getHeaderComments(numberOfHeaderComments);
    numberOfComponents=u.getComponentDimension(0);
    const int numberOfComponents0=numberOfComponents;
    
    // this next class knows how to form derived quantities such as vorticity, derivatives etc.
    DerivedFunctions derivedFunctions(showFileReader);

    // create the real menu by adding in the component names, these will appear as a 
    // cascaded menu

    int chooseAComponentMenuItem;  // menu[chooseAComponentMenuItem]=">choose a component"
    int chooseASolutionMenuItem;  
    int numberOfSolutionMenuItems=0;
    int chooseASequenceMenuItem;  
    int numberOfSequenceMenuItems=0;
    const int maxMenuSolutions=25;  // cascade solution menu if there are more than this many solutions
    const int maximumNumberOfSolutionsInTheMenu=400;  // stride through the solutions if there are more
                                                      // than this many solutions.
    int solutionIncrement=1;                          // Here is the stride.

    const int maxMenuSequences=25;  // cascade sequence menu if there are more than this many sequences
    const int maximumNumberOfSequencesInTheMenu=400;  // stride through the sequences if there are more
                                                      // than this many sequences.
    int sequenceIncrement=1;                          // Here is the stride.

    aString *menu=NULL;
    buildMainMenu( menu0,
		   menu,
                   u,
                   sequenceName,
                   numberOfSolutions,
                   numberOfComponents,
                   numberOfSequences,
		   chooseAComponentMenuItem,
		   chooseASolutionMenuItem,
		   numberOfSolutionMenuItems,
		   chooseASequenceMenuItem,
		   numberOfSequenceMenuItems,
		   maxMenuSolutions,
		   maximumNumberOfSolutionsInTheMenu,
                   solutionIncrement,
		   maxMenuSequences,
		   maximumNumberOfSequencesInTheMenu,
		   sequenceIncrement );


    psp.set(GI_TOP_LABEL,headerComment[0]);  // set title
    psp.set(GI_TOP_LABEL_SUB_1,headerComment[1]);  
    psp.set(GI_TOP_LABEL_SUB_2,headerComment[2]);  
    if( cg.numberOfDimensions()==1 )
      psp.set(GI_COLOUR_LINE_CONTOURS,TRUE);
    
    // set default prompt
    ps.appendToTheDefaultPrompt("plotCellWave>");

    int menuItem=-1;
    for( int it=0; ; it++)
    {
      checkArrays("plotCellWave: in for(;;)");

      if( it==0 && numberOfFrames<=0 )
        answer="grid";
      else
        menuItem=ps.getMenuItem(menu,answer);
      if( answer=="grid" )
      {
	PlotIt::plot(ps, cg, psp);   // plot the composite grid
	if( psp.getObjectWasPlotted() ) 
	  plotOptions |= 1;

	if( false )
	{
	  for( int grid=0; grid<cg.numberOfComponentGrids(); grid++ )
	    cg[grid].displayComputedGeometry();
	}
      }
      else if( answer=="contour" )
      {
	PlotIt::contour(ps, u, psp);  // contour/surface plots
	if( psp.getObjectWasPlotted() & 1 ) 
	  plotOptions |= 2;
	if( psp.getObjectWasPlotted() & 2 )  // grid was also plotted
	  plotOptions |= 1;
      }
      else if( answer=="line plot" )
      {
	printf(" -- ERROR: line plot not available yet. --\n");

	int oldPBGG = ps.getPlotTheBackgroundGrid();
	int oldKAR  = ps.getKeepAspectRatio();
	const GridCollection & gc = *(u.gridCollection);
	RealArray xBound(2,3);
	PlotIt::getPlotBounds(gc,psp,xBound);
	
	// plot solution on lines that cut the 2D grid
	//contourCuts(gi, uGCF,psp );
	PlotIt::contourCuts(ps, u,  psp );
	
	// Restore plotbackgroundgrid and keepAspectRatio after this call
	ps.setPlotTheBackgroundGrid(oldPBGG);
	
	psp.keepAspectRatio=oldKAR;
	ps.setKeepAspectRatio(psp.keepAspectRatio); 

	// the boundingbox is messed up (set for 1D) after this call
	ps.setGlobalBound(xBound);
	
	// erase the labels and replot them
	ps.eraseLabels(psp);

	// replot the 3D object
	//plotObject = TRUE;
	//plotContours = TRUE;

	//PlotIt::contour(ps, u, psp);  // contour/surface plots
	//if( psp.getObjectWasPlotted() & 1 ) 
	//  plotOptions |= 2;
	//if( psp.getObjectWasPlotted() & 2 )  // grid was also plotted
	//  plotOptions |= 1;
      }
      else if( answer=="probe plot" )
      {
	printf(" -- ERROR: probe plot not available yet. --\n");
	//	PlotIt::contour(ps, u, psp);  // contour/surface plots
	//if( psp.getObjectWasPlotted() & 1 ) 
	//  plotOptions |= 2;
	//if( psp.getObjectWasPlotted() & 2 )  // grid was also plotted
	//  plotOptions |= 1;
      }
      else if( answer=="stream lines" )
      {
	PlotIt::streamLines(ps, u, psp);  // streamlines
	if( psp.getObjectWasPlotted() ) 
	  plotOptions |= 4;
      }
      else if( answer=="derived types" )
      {
        if( numberOfComponents>0 )
	{
	  aString *componentNames = new aString [numberOfComponents];
	  for( int n=0; n<numberOfComponents; n++ )
	    componentNames[n]=u.getName(n);
	  
	  derivedFunctions.update(ps,numberOfComponents,componentNames);
          delete [] componentNames;

          derivedFunctions.getASolution(solutionNumber,cg,u);

          numberOfComponents=numberOfComponents0+derivedFunctions.numberOfDerivedTypes();
	  buildMainMenu( menu0,
			 menu,
			 u,
			 sequenceName,
			 numberOfSolutions,
			 numberOfComponents, 
			 numberOfSequences,
			 chooseAComponentMenuItem,
			 chooseASolutionMenuItem,
			 numberOfSolutionMenuItems,
			 chooseASequenceMenuItem,
			 numberOfSequenceMenuItems,
			 maxMenuSolutions,
			 maximumNumberOfSolutionsInTheMenu,
			 solutionIncrement,
			 maxMenuSequences,
			 maximumNumberOfSequencesInTheMenu,
			 sequenceIncrement );


	}
	else
	{
	  printf("ERROR: no components are available\n");
	}
      }
      else if( menuItem > chooseASequenceMenuItem && menuItem <= chooseASequenceMenuItem+numberOfSequenceMenuItems )
      {
        // plot a sequence
	int sequenceNumber=menuItem-chooseASequenceMenuItem;
        if( numberOfSequences>maxMenuSequences )
	{
          // adjust the sequence number when there are many sequences since we add in extra menu items
          // into the list.
          int extra = 1+ sequenceNumber/maxMenuSequences;  
          extra=1+ (sequenceNumber-extra)/maxMenuSequences;
          sequenceNumber-=extra;
          // printf("menuItem-chooseASequenceMenuItem=%i, extra=%i sequenceNumber=%i\n",
          //     menuItem-chooseASequenceMenuItem,extra,sequenceNumber);
	}
        sequenceNumber=(sequenceNumber-1)*sequenceIncrement;

        assert( sequenceNumber>=0 && sequenceNumber<numberOfSequences );
	aString name;
	realArray time,value;
	const int maxComponentName1=25, maxComponentName2=1;
	aString componentName1[maxComponentName1], componentName2[maxComponentName2];
	  
	showFileReader.getSequence(sequenceNumber,name,time,value,
				   componentName1,maxComponentName1,
				   componentName2,maxComponentName2);
	// printf("sequence %i: name=%s\n",sequenceNumber,(const char*)name);
        // display(value,"value");
	
	  
	ps.erase();
	psp.set(GI_PLOT_THE_OBJECT_AND_EXIT,FALSE);
	psp.set(GI_TOP_LABEL_SUB_1,"");
	psp.set(GI_TOP_LABEL_SUB_2,"");
        Range all;
	PlotIt::plot(ps, time, value(all,all,value.getBase(2)), name, "t", componentName1, psp);
	psp.set(GI_PLOT_THE_OBJECT_AND_EXIT,TRUE);
	ps.erase();

      }
      else if( answer=="next" )
      {
	solutionNumber = (solutionNumber % numberOfSolutions) +1;
	plotNewFunction=TRUE;
      }
      else if( answer=="previous" )
      {
	solutionNumber = ((solutionNumber-2+numberOfSolutions) % numberOfSolutions) +1;
	plotNewFunction=TRUE;
      }
      else if( answer=="next component" )
      {
	component= (component+1) % numberOfComponents;
	plotNewComponent=TRUE;
      }
      else if( answer=="previous component" )
      {
	component= (component-1+numberOfComponents) % numberOfComponents;
	plotNewComponent=TRUE;
      }
      else if( menuItem > chooseAComponentMenuItem && menuItem <= chooseAComponentMenuItem+numberOfComponents )
      {
	component=menuItem-chooseAComponentMenuItem-1 + u.getComponentBase(0);
	plotNewComponent=TRUE;
	// cout << "chose component number=" << component << endl;
      }
      else if( answer=="choose a component" )
      { // *** not used *** Make a menu with the component names. If there are no names then use the component numbers
	aString *menu2 = new aString[numberOfComponents+1];
	for( int i=0; i<numberOfComponents; i++ )
	{
	  menu2[i]=u.getName(u.getComponentBase(0)+i);
	  if( menu2[i] == "" || menu2[i]==" " )
	    menu2[i]=sPrintF(buff,"component%i",u.getComponentBase(0)+i);
	}
	menu2[numberOfComponents]="";   // null string terminates the menu
	component = ps.getMenuItem(menu2,answer2);
	component+=u.getComponentBase(0);
	delete [] menu2;
	plotNewComponent=TRUE;
      }
      else if( menuItem > chooseASolutionMenuItem && menuItem <= chooseASolutionMenuItem+numberOfSolutionMenuItems )
      {
	solutionNumber=menuItem-chooseASolutionMenuItem;
        if( numberOfSolutions>maxMenuSolutions )
	{
          // adjust the solution number when there are many solutions since we add in extra menu items
          // into the list.
          int extra = 1+ solutionNumber/maxMenuSolutions;  
          extra=1+ (solutionNumber-extra)/maxMenuSolutions;
          solutionNumber-=extra;
          // printf("menuItem-chooseASolutionMenuItem=%i, extra=%i solutionNumber=%i\n",
          //     menuItem-chooseASolutionMenuItem,extra,solutionNumber);
	}
        solutionNumber=(solutionNumber-1)*solutionIncrement+1;
	
	plotNewFunction=TRUE;
      }
      else if( answer=="choose a solution" )
      { // ***** not used ****  Make a menu with the solution Names
	aString *menu2 = new aString[numberOfFrames+1];
	for( int i=0; i<numberOfFrames; i++ )
	  menu2[i]=sPrintF(buff,"solution%i",i);
	menu2[numberOfFrames]="";   // null string terminates the menu
	solutionNumber = ps.getMenuItem(menu2,answer2)+1;
	delete [] menu2;
	plotNewFunction=TRUE;
      }
      else if( answer=="movie" || answer=="movie and save" )
      {
	movieMode=TRUE;
	numberOfMovieFrames=numberOfFrames;
	ps.inputString(answer2,sPrintF(buff,"Enter the number of frames (total=%i)",numberOfFrames));
	if( answer2 !="" && answer2!=" ")
	{
	  sScanF(answer2,"%i",&numberOfMovieFrames);
	  printf("number of frames = %i \n",numberOfMovieFrames);
	}
        if( answer=="movie and save" )
	{
	  ps.inputString(answer2,"Enter basic name for the ppm files (default=plot)");
	  if( answer2 !="" && answer2!=" ")
	    movieFileName=answer2;
          else
	    movieFileName="plot";
          ps.outputString(sPrintF(buff,"pictures will be named %s0.ppm, %s1.ppm, ...",
            (const char*)movieFileName,(const char*)movieFileName));
	}
	
      }
      else if( answer=="set plot bounds" )
      {
        RealArray xBound(2,3);
	xBound=0.;
        xBound(1,Range(0,2))=1.;
        if( cg.numberOfDimensions()==2 )
  	  ps.inputString(answer2,sPrintF(buff,"Enter bounds xa,xb, ya,yb "));
        else
  	  ps.inputString(answer2,sPrintF(buff,"Enter bounds xa,xb, ya,yb, za,zb "));
        if( answer2!="" )
 	  sScanF(answer2,"%e %e %e %e %e %e",&xBound(0,0),&xBound(1,0),&xBound(0,1),&xBound(1,1),
              &xBound(0,2),&xBound(1,2));
	
        ps.resetGlobalBound(ps.getCurrentWindow());
	ps.setGlobalBound(xBound);
	
	psp.set(GI_PLOT_BOUNDS,xBound); // set plot bounds
	psp.set(GI_USE_PLOT_BOUNDS,TRUE);  // use the region defined by the plot bounds
      }
      else if( answer=="use default plot bounds" )
      {
        psp.set(GI_USE_PLOT_BOUNDS,FALSE);  // use the region defined by the plot bounds
      }
      else if( answer=="check mappings with grid" )
      {
	for( int grid=0; grid<cg.numberOfComponentGrids(); grid++ )
	{
	  if( cg[grid].mapping().mapPointer==NULL )
	  {
	    cout << "ERROR: This grid has no mappings! \n";
	    break;
	  }
	  cg[grid].mapping().checkMapping();
	}
      }
      else if( answer=="erase" )
      {
	ps.erase();
	plotOptions=0;
      }
      else if( answer=="redraw" )
      { // force a redraw -- add to command files to force the drawing of the screen
	ps.redraw(TRUE);
      }
      else if( answer=="open a new file" )
      {
        nameOfShowFile=""; // do this so we prompt for a new name
	break;
      }
      else if( answer=="file output" )
      {
        fileOutput(ps, u);
      }
      else if( answer=="exit" )
      {
        done=TRUE;
	break;
      }
      else if( answer=="help" )
      {
	for( int i=0; help[i]!=""; i++ )
	   ps.outputString(help[i]);
      }
      else
      {
        cout << "unknown response, answer=[" << answer << "]\n";
	ps.stopReadingCommandFile();
      }
      if( movieMode )
      { // ************** Movie Mode *******************
	psp.set(GI_PLOT_THE_OBJECT_AND_EXIT,TRUE);
	for( int frame=1; frame<=numberOfMovieFrames; frame++ )
	{
          if( answer=="movie and save" )
	  { // save a ppm file
            psp.set(GI_HARD_COPY_TYPE,GraphicsParameters::ppm);
            ps.outputString(sPrintF(buff,"Saving file %s%i.ppm",(const char*)movieFileName,frame-1));
	    ps.hardCopy(    sPrintF(buff,            "%s%i.ppm",(const char*)movieFileName,frame-1),psp);
            psp.set(GI_HARD_COPY_TYPE,GraphicsParameters::postScript);
	  }

	  solutionNumber = (solutionNumber+numberOfSolutions) % numberOfSolutions +1;

          // showFileReader.getASolution(solutionNumber,cg,u);
          derivedFunctions.getASolution(solutionNumber,cg,u);

          headerComment=showFileReader.getHeaderComments(numberOfHeaderComments);
          numberOfComponents=u.getComponentDimension(0);

	  psp.set(GI_TOP_LABEL,headerComment[0]);  // set title
	  psp.set(GI_TOP_LABEL_SUB_1,headerComment[1]);  
	  psp.set(GI_TOP_LABEL_SUB_2,headerComment[2]);  
	  ps.erase();
	  if( plotOptions & 1 )
	    PlotIt::plot(ps, cg, psp );
	  if( plotOptions & 2 )
	    PlotIt::contour(ps, u, psp );
	  if( plotOptions & 4 )
	    PlotIt::streamLines(ps, u, psp ); 

	  ps.redraw(TRUE);   // *****
	}
	if( answer=="movie and save" )
	{ // save a ppm file
          psp.set(GI_HARD_COPY_TYPE,GraphicsParameters::ppm);
	  ps.outputString(sPrintF(buff,"Saving file %s%i.ppm",(const char*)movieFileName,numberOfMovieFrames));
	  ps.hardCopy(    sPrintF(buff,            "%s%i.ppm",(const char*)movieFileName,numberOfMovieFrames),psp);
	  psp.set(GI_HARD_COPY_TYPE,GraphicsParameters::postScript);
	}

	psp.set(GI_PLOT_THE_OBJECT_AND_EXIT,FALSE);
	movieMode=FALSE;
      }      
      else if( plotNewFunction || plotNewComponent )
      {
	if( plotNewFunction )
	{
          // showFileReader.getASolution(solutionNumber,cg,u);
          derivedFunctions.getASolution(solutionNumber,cg,u);

          headerComment=showFileReader.getHeaderComments(numberOfHeaderComments);
          numberOfComponents=u.getComponentDimension(0);

	  psp.set(GI_TOP_LABEL,headerComment[0]);  // set title
	  psp.set(GI_TOP_LABEL_SUB_1,headerComment[1]);  
	  psp.set(GI_TOP_LABEL_SUB_2,headerComment[2]);  
	  plotNewFunction=FALSE;
	}
	if( plotNewComponent )
	{
	  psp.set(GI_COMPONENT_FOR_CONTOURS,component);
	  plotNewComponent=FALSE;
	}
	psp.set(GI_PLOT_THE_OBJECT_AND_EXIT,TRUE);
	ps.erase();
	if( plotOptions & 1 )
	  PlotIt::plot(ps, cg, psp );
	if( plotOptions & 2 )
	  PlotIt::contour(ps, u, psp );
	if( plotOptions & 4 )
	  PlotIt::streamLines(ps, u, psp );

	psp.set(GI_PLOT_THE_OBJECT_AND_EXIT,FALSE);
      }
    } // end for(;;)

    delete [] menu;
    ps.unAppendTheDefaultPrompt(); // reset defaultPrompt

    if( true )
    {
      for( int grid=0; grid<cg.numberOfComponentGrids(); grid++ )
	cg[grid].displayComputedGeometry();
    }
  } // end while not done
  
  
  delete [] sequenceName;


  Overture::finish();          
  return 0;
}
Exemplo n.º 8
0
std::string PragmaParser::substitutePragmas(const std::string& OldFile)
{
   INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Substituting pragma in " + OldFile);
   THROW_ASSERT(boost::filesystem::exists(boost::filesystem::path(OldFile)), "Input file \"" + OldFile + "\" does not exist");

   boost::filesystem::path old_path(OldFile);
   std::string FileName = Param->getOption<std::string>(OPT_output_temporary_directory) + STR_CST_pragma_prefix + boost::lexical_cast<std::string>(file_counter) + "_" + GetLeafFileName(old_path);
   boost::filesystem::ofstream fileOutput(FileName.c_str(), std::ios::out);

   file_counter++;
   level = 0;
   unsigned line_number = 0;

   // Get a stream from the input file
   std::ifstream instream(OldFile.c_str());
   // Test if the file has been correctly opened
   THROW_ASSERT(instream.is_open(), "INPUT FILE ERROR: Could not open input file: " + OldFile);
   while (!instream.eof())
   {
      std::string input_line;
      getline (instream,input_line);
      INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "Read line <" + input_line + ">");
      std::string output_line = input_line;

      /// search for function name
      if (search_function)
      {
         std::string::size_type notwhite = output_line.find_first_of("(");
         if (notwhite != std::string::npos)
         {
            std::string Token = input_line;
            Token.erase(notwhite);
            name_function += Token;

            notwhite = name_function.find_last_not_of(" \t\r\n");
            name_function.erase(notwhite+1);
            notwhite = name_function.find_last_of(" \t\n*>");
            name_function.erase(0, notwhite+1);
            INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Found function " + name_function);

            ///Pragma associated with called are added by pragma_analysis
            if (level == 0)
              PM->AddFunctionDefinitionPragmas(name_function, FunctionPragmas);

            name_function.clear();
            search_function = false;
            FunctionPragmas.clear();
         }
         else
            name_function += input_line + " ";
      }
      if (input_line.find("#pragma") != std::string::npos)
      {
         INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Found a pragma");
         output_line = input_line;
         char const* delims = " \t\r\n";
         // trim leading whitespace
         std::string::size_type notwhite = output_line.find_first_not_of(delims);
         output_line.erase(0,notwhite);
         // trim trailing whitespace
         notwhite = output_line.find_last_not_of(delims);
         output_line.erase(notwhite+1);

         analyze_pragma(output_line);
      }

      /// print out the new pragma line
      fileOutput << output_line << std::endl;

      /// manage nesting levels
      bool found = false;
      for(unsigned int i = 0; i < input_line.size(); i++)
      {
         if (input_line[i] == '{')
         {
            level++;
            INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Found {: Current level " + boost::lexical_cast<std::string>(level));
            if (!found)
            {
               for(std::list<std::string>::iterator it = FloatingPragmas.begin(); it != FloatingPragmas.end(); it++)
                  OpenPragmas[level].push_back(*it);
               FloatingPragmas.clear();
            }
            found = true;
         }
         if (input_line[i] == '}')
         {
            if (OpenPragmas.count(level))
            {
               for(std::list<std::string>::iterator open_pragma = OpenPragmas[level].begin(); open_pragma != OpenPragmas[level].end(); open_pragma++)
                  fileOutput << std::string(STR_CST_pragma_function_end) + "(\"" << *open_pragma << "\");" << std::endl;
               OpenPragmas[level].clear();
            }
            level--;
            INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Found }: Current level " + boost::lexical_cast<std::string>(level));
         }
      }

      /// increment line number
      line_number++;
   }

   fileOutput.close();
   INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Substituted pragma in " + OldFile);
   return FileName;
}