void CMoodMgr::createSong(int type)
{
	int fileSize=0, transfer, encryption, id, numDays, popularity; //arguement added
	char songName[128], albumName[128], artistName[128], date[128], webLink[128];
	double duration, price;

	getInputString("Song Name: ", songName);
	getInputString("Album Name: ", albumName);
	getInputString("Artist Name: ", artistName);
	getInputInt("File Size: ", &fileSize);
	getInputInt("Transfer (1=Streamable, 2=Downloadable, 3=Both) : ", &transfer);
	getInputString("Date: ", date);
	getInputInt("Popularity (0=Lowest to 100=Highest) : ", &popularity);

	if (type == SONG_SECURE) {
		getInputDouble("Duration: ", &duration);
		getInputInt("Encryption (1=SECURE_1, 2=SECURE_2, 3=SECURE_3): ", &encryption);
		getInputInt("ID: ", &id);

		CSecureSongInfo secureSong;

		secureSong.setSongName(songName);	
		secureSong.setAlbumName(albumName);
		secureSong.setArtistName(artistName);
		secureSong.setFileSize(fileSize);
		secureSong.setTransfer(transfer);
		secureSong.setDate(date);
		secureSong.setPopularity(popularity);  //added line of code
		secureSong.setDuration(duration);
		secureSong.setEncryption(encryption);
		secureSong.setId(id);

		songList.add(&secureSong);
	}
	else if (type == SONG_PROMO) {
		getInputDouble("Price: ", &price);
		getInputString("WebLink: ", webLink);
		getInputInt("Promotion Length: ", &numDays);

		CPromoSongInfo promoSong;

		promoSong.setSongName(songName);
		promoSong.setAlbumName(albumName);
		promoSong.setArtistName(artistName);
		promoSong.setFileSize(fileSize);
		promoSong.setTransfer(transfer);
		promoSong.setDate(date);
		promoSong.setPopularity(popularity);
		promoSong.setPrice(price);
		promoSong.setWebLink(webLink);
		promoSong.setNumDays(numDays);

		songList.add(&promoSong);
	}
	
	cout << endl;
}
示例#2
0
void CGUIInputText::processRender(const GsRect<float> &RectDispCoordFloat)
{
	// Transform to the display coordinates
	GsRect<float> displayRect = mRect;
	displayRect.transform(RectDispCoordFloat);
	SDL_Rect lRect = displayRect.SDLRect();

    if(!mEnabled)
        return;

    SDL_Surface *blitsfc = gVideoDriver.getBlitSurface();

    if( mReleased )
    {
        drawRect( blitsfc, &lRect, 1, 0x00BBBBBB, 0x00CFCFCF );
    }
    else if( mPressed )
    {
        drawRect( blitsfc, &lRect, 1, 0x00BBBBBB, 0x00DFDFDF );
    }
    else if( mHovered )
    {
        drawRect( blitsfc, &lRect, 1, 0x00BBBBBB, 0x00EFEFEF );
    }
    else
    {
        drawRect( blitsfc, &lRect, 1, 0x00BBBBBB, 0x00FFFFFF );
    }

    // Now lets draw the text of the list control
    GsFont &Font = gGraphics.getFont(mFontID);

    Font.drawFontCentered( blitsfc, getInputString(), lRect.x, lRect.w, lRect.y, lRect.h,false );
}
void CGUIInputText::drawNoStyle(SDL_Rect& lRect)
{
	if(!mEnabled)
		return;

	SDL_Surface *blitsfc = g_pVideoDriver->getBlitSurface();

	if( mButtonUp )
	{
		drawRect( blitsfc, &lRect, 1, 0x00BBBBBB, 0x00CFCFCF );
	}
	else if( mButtonDown )
	{
		drawRect( blitsfc, &lRect, 1, 0x00BBBBBB, 0x00DFDFDF );
	}
	else if( mHovered )
	{
		drawRect( blitsfc, &lRect, 1, 0x00BBBBBB, 0x00EFEFEF );
	}
	else
	{
		drawRect( blitsfc, &lRect, 1, 0x00BBBBBB, 0x00FFFFFF );
	}

	// Now lets draw the text of the list control
	CFont &Font = g_pGfxEngine->getFont(mFontID);

	Font.drawFontCentered( blitsfc, getInputString(), lRect.x, lRect.w, lRect.y, lRect.h,false );
}
void CGUIInputText::drawGalaxyStyle(SDL_Rect& lRect)
{
	if(!mEnabled)
		return;

	SDL_Surface *blitsfc = g_pVideoDriver->getBlitSurface();

	// Now lets draw the text of the list control
	CFont &Font = g_pGfxEngine->getFont(mFontID);

	SDL_PixelFormat *format = g_pVideoDriver->getBlitSurface()->format;


	const Uint32 oldcolor = Font.getFGColor();


	Uint32 newcolor;

	if(mHovered || mButtonDown)
		newcolor = SDL_MapRGB( format, 84, 234, 84);
	else
		newcolor = SDL_MapRGB( format, 38, 134, 38);

	Font.setupColor( newcolor );

	drawEmptyRect( blitsfc, &lRect, newcolor);

	Font.drawFont( blitsfc, getInputString(), lRect.x+24, lRect.y+2, false );

	Font.setupColor( oldcolor );
}
示例#5
0
void SimManager::_get_options() {
	getInputInt(&_input, "print_reduced_conf_every", &_print_reduced_conf_every, 0);
	getInputInt(&_input, "print_energy_every", &_print_energy_every, 0);
	getInputInt(&_input, "restart_step_counter", &_restart_step_counter, 0);
	getInputLLInt(&_input, "steps", &_steps, 1);
	if(getInputInt(&_input, "seed", &_seed, 0) == KEY_NOT_FOUND) _seed = time(NULL);
	getInputString(&_input, "conf_file", _conf_file, 1);
}
void CMoodMgr::output()
{
	char fileName[128];
	getInputString("Enter file name: ", fileName, true, "mood.dat");
	cout << endl;

	ofstream file;
	file.open (fileName, ios::out | ios::trunc); 
	songList.output(file);
	file.close();
}
示例#7
0
/// indefinitely loops over user input expecting commands
int loop(teasafe::TeaSafe &theBfs)
{
    std::string currentPath("/");
    while (1) {
        std::string commandStr;
        std::cout<<"ts$> ";
        commandStr = getInputString(theBfs, currentPath);
        try {
            parse(theBfs, commandStr, currentPath);
        } catch (...) {
            std::cout<<"Some error occurred!"<<std::endl;
        }
    }
    return 0;
}
示例#8
0
int main() {
	//Set up to ignore SIGINT and SIGQUIT
	struct sigaction newact, oldact;
	newact.sa_handler = SIG_IGN;
	sigaction(SIGINT, &newact, &oldact);
	sigaction(SIGQUIT, &newact, &oldact);

	while(1) {
		char* prompt = setPromptString();
		printf("%s", prompt);

		char* input_string = getInputString();

		//Initialize array to hold commands
		size_t commands_alloc_size = COMMANDS_INITIAL_SIZE;
		int num_commands = 0;
		command* commands = malloc(sizeof(command) * commands_alloc_size);

		fillCommandArray(input_string, &commands, &num_commands, &commands_alloc_size);

		bool wasShellCommand = handleShellCommand(commands[0]);

		if (wasShellCommand == false) {
			int** fds = createPipes(num_commands);

			for (int i = 0; i < num_commands; ++i) {
				pid_t fork_pid = fork();
				if (fork_pid == -1) {
					perror("Fork failed");
					exit(1);
				}
				//Child process
				else if (fork_pid == 0) {
					sigaction(SIGINT, &oldact, NULL);
					sigaction(SIGQUIT, &oldact, NULL);
					executeCommand(fds, num_commands, commands[i], i);
				}
			}

			//Clean up the shell process
			closeAllPipes(fds, num_commands);
			waitForAllChildProcesses(num_commands);
			freeCommandArray(commands, num_commands);
		}
	}
	
	return 0;
}
void CGUIInputText::drawVorticonStyle(SDL_Rect& lRect)
{

	if(!mEnabled)
		return;


	SDL_Surface *blitsfc = g_pVideoDriver->getBlitSurface();

	// Now lets draw the text of the list control
	CFont &Font = g_pGfxEngine->getFont(mFontID);

	Font.drawFont( blitsfc, getInputString(), lRect.x+24, lRect.y, false );

	drawTwirl(lRect);
}
示例#10
0
void SimManager::init() {
	srand48(_seed);
	srand(_seed);

	ifstream conf_input(_conf_file);
	if(conf_input.good() == false) _IO.die("Can't read configuration file '%s'", _conf_file);

	// here we handle the SIGTERM signal;
	signal (SIGTERM, gbl_terminate);
	signal (SIGABRT, gbl_terminate);
	signal (SIGINT, gbl_terminate);

	char time_scale[256];
	getInputString(&_input, "time_scale", time_scale, 1);
	if(strcmp(time_scale, "linear") == 0) _time_scale = TS_LIN;
	else if(strcmp(time_scale, "log_lin") == 0) _time_scale = TS_LOG_LIN;
	else _IO.die("Time scale '%s' not supported", time_scale);

	char line[512];
	conf_input.getline(line, 512);
	int res = sscanf(line, "t = %lld", &_start_step);
	if(res != 1) _IO.die("The first line of the configuration file is not correct, aborting");
	if(_restart_step_counter != 0) _start_step = 0;

	// init time_scale_manager
	initTimeScale(&_time_scale_manager, _time_scale);

	int tmp;
	getInputInt(&_input, "print_conf_interval", &tmp, 1);
	setTSInterval(&_time_scale_manager, tmp);

	if(_time_scale == TS_LOG_LIN) {
		getInputInt(&_input, "print_conf_ppc", &tmp, 1);
		setTSPPC(&_time_scale_manager, tmp);
	}
	// end

	setTSInitialStep(&_time_scale_manager, _start_step);

	_IO.init();
	_backend->init(conf_input);

	_max_steps = _start_step + _steps;
}
void InputText::processRender(const GsRect<float> &RectDispCoordFloat)
{
    if(!mEnabled)
        return;

    // Transform to the display coordinates
    GsRect<float> displayRect = mRect;
    displayRect.transform(RectDispCoordFloat);
    SDL_Rect lRect = displayRect.SDLRect();

    SDL_Surface *blitsfc = gVideoDriver.getBlitSurface();

    // Now lets draw the text of the list control
    GsFont &Font = gGraphics.getFont(mFontID);

    Font.drawFont( blitsfc, getInputString(), lRect.x+24, lRect.y, false );

    drawTwirl(lRect);
}
示例#12
0
文件: reader_cip.c 项目: gorhan/LFOS
/** problem reading method of reader */
static
SCIP_DECL_READERREAD(readerReadCip)
{  /*lint --e{715}*/

   CIPINPUT cipinput;
   SCIP_Real objscale;
   SCIP_Real objoffset;
   SCIP_Bool initialconss;
   SCIP_Bool dynamicconss;
   SCIP_Bool dynamiccols;
   SCIP_Bool dynamicrows;
   SCIP_Bool initialvar;
   SCIP_Bool removablevar;
   SCIP_RETCODE retcode;

   if( NULL == (cipinput.file = SCIPfopen(filename, "r")) )
   {
      SCIPerrorMessage("cannot open file <%s> for reading\n", filename);
      SCIPprintSysError(filename);
      return SCIP_NOFILE;
   }

   cipinput.len = 131071;
   SCIP_CALL( SCIPallocBufferArray(scip, &(cipinput.strbuf), cipinput.len) );

   cipinput.linenumber = 0;
   cipinput.section = CIP_START;
   cipinput.haserror = FALSE;
   cipinput.endfile = FALSE;
   cipinput.readingsize = 65535;

   SCIP_CALL( SCIPcreateProb(scip, filename, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );

   SCIP_CALL( SCIPgetBoolParam(scip, "reading/initialconss", &initialconss) );
   SCIP_CALL( SCIPgetBoolParam(scip, "reading/dynamiccols", &dynamiccols) );
   SCIP_CALL( SCIPgetBoolParam(scip, "reading/dynamicconss", &dynamicconss) );
   SCIP_CALL( SCIPgetBoolParam(scip, "reading/dynamicrows", &dynamicrows) );

   initialvar = !dynamiccols;
   removablevar = dynamiccols;

   objscale = 1.0;
   objoffset = 0.0;

   while( cipinput.section != CIP_END && !cipinput.haserror )
   {
      /* get next input string */
      SCIP_CALL( getInputString(scip, &cipinput) );

      if( cipinput.endfile )
         break;

      switch( cipinput.section )
      {
      case CIP_START:
         getStart(scip, &cipinput);
         break;
      case CIP_STATISTIC:
         SCIP_CALL( getStatistics(scip, &cipinput) );
         break;
      case CIP_OBJECTIVE:
         SCIP_CALL( getObjective(scip, &cipinput, &objscale, &objoffset) );
         break;
      case CIP_VARS:
         retcode = getVariable(scip, &cipinput, initialvar, removablevar, objscale);

         if( retcode == SCIP_READERROR )
         {
            cipinput.haserror = TRUE;
            goto TERMINATE;
         }
         SCIP_CALL(retcode);

         break;
      case CIP_FIXEDVARS:
         retcode = getFixedVariable(scip, &cipinput);

         if( retcode == SCIP_READERROR )
         {
            cipinput.haserror = TRUE;
            goto TERMINATE;
         }
         SCIP_CALL(retcode);

         break;
      case CIP_CONSTRAINTS:
         retcode = getConstraint(scip, &cipinput, initialconss, dynamicconss, dynamicrows);

         if( retcode == SCIP_READERROR )
         {
            cipinput.haserror = TRUE;
            goto TERMINATE;
         }
         SCIP_CALL(retcode);

         break;
      default:
         SCIPerrorMessage("invalid CIP state\n");
         SCIPABORT();
         return SCIP_INVALIDDATA;  /*lint !e527*/
      } /*lint !e788*/ 
   }

   if( !SCIPisZero(scip, objoffset) && !cipinput.haserror )
   {
      SCIP_VAR* objoffsetvar;

      objoffset *= objscale;
      SCIP_CALL( SCIPcreateVar(scip, &objoffsetvar, "objoffset", objoffset, objoffset, 1.0, SCIP_VARTYPE_CONTINUOUS,
         TRUE, TRUE, NULL, NULL, NULL, NULL, NULL) );
      SCIP_CALL( SCIPaddVar(scip, objoffsetvar) );
      SCIP_CALL( SCIPreleaseVar(scip, &objoffsetvar) );
      SCIPdebugMessage("added variables <objoffset> for objective offset of <%g>\n", objoffset);
   }

   if( cipinput.section != CIP_END && !cipinput.haserror )
   {
      SCIPerrorMessage("unexpected EOF\n");
   }

 TERMINATE:
   /* close file stream */
   SCIPfclose(cipinput.file);

   SCIPfreeBufferArray(scip, &cipinput.strbuf);

   if( cipinput.haserror )
      return SCIP_READERROR;

   /* successfully parsed cip format */
   *result = SCIP_SUCCESS;
   return SCIP_OKAY;
}
void CMoodMgr::editSong()
{
	int i;
	int length = songList.length();

	if (length == 0) {
		displayMessage("The song list is empty.");
		return;
	}
	
	getInputInt("Enter song number you wish to edit: ", &i);
	if ((i < 1) || (i > length)) { // Note: first song is displayed as #1
		displayMessage("You must enter a song number from 1 to ", true, length);
		cout << endl;
		return;
	}

	i = i - 1;  // adjustment, see above

	int fileSize=0, transfer, encryption, id, numDays, popularity;
	char songName[128], albumName[128], artistName[128], date[128], webLink[128];
	double duration, price;

	CSongInfo *pSong;
	CSecureSongInfo *pSecure;
	CPromoSongInfo *pPromo;

	pSong = songList.get(i);
	int type = pSong->getType();

	if (type == SONG_SECURE) {
		pSecure = (CSecureSongInfo *)songList.get(i);

		getInputString("Song Name: ", songName, true, pSecure->getSongName());
		getInputString("Album Name: ", albumName, true, pSecure->getAlbumName());
		getInputString("Artist Name: ", artistName, true, pSecure->getArtistName());
		getInputInt("File Size: ", &fileSize, true, pSecure->getFileSize());
		getInputInt("Transfer (1=Streamable, 2=Downloadable, 3=Both: ", &transfer, true, pSecure->getTransfer());
		getInputString("Date: ", date, true, pSecure->getDate());
		getInputInt("Popularity (0=Lowest to 100=Highest) : ", &popularity, true, pSecure->getPopularity());
		getInputDouble("Duration: ", &duration, true, pSecure->getDuration());
		getInputInt("Encryption (1=SECURE_1, 2=SECURE_2, 3=SECURE_3): ", &encryption, true, pSecure->getEncryption());
		getInputInt("ID: ", &id, true, pSecure->getId());

		pSecure->setSongName(songName);	
		pSecure->setAlbumName(albumName);
		pSecure->setArtistName(artistName);
		pSecure->setFileSize(fileSize);
		pSecure->setTransfer(transfer);
		pSecure->setDate(date);
		pSecure->setPopularity(popularity);
		pSecure->setDuration(duration);
		pSecure->setEncryption(encryption);
		pSecure->setId(id);
	}
	else if (type == SONG_PROMO) {
		pPromo = (CPromoSongInfo *)songList.get(i);

		getInputString("Song Name: ", songName, true, pPromo->getSongName());
		getInputString("Album Name: ", albumName, true, pPromo->getAlbumName());
		getInputString("Artist Name: ", artistName, true, pPromo->getArtistName());
		getInputInt("File Size: ", &fileSize, true, pPromo->getFileSize());
		getInputInt("Transfer (1=Streamable, 2=Downloadable, 3=Both: ", &transfer, true, pPromo->getTransfer());
		getInputString("Date: ", date, true, pPromo->getDate());
		getInputInt("Popularity (0=Lowest to 100=Highest) : ", &popularity, true, pPromo->getPopularity());
		getInputDouble("Price: ", &price, true, pPromo->getPrice());
		getInputString("WebLink: ", webLink, true, pPromo->getWebLink());
		getInputInt("Promotion Length: ", &numDays, true, pPromo->getNumDays());

		pPromo->setSongName(songName);
		pPromo->setAlbumName(albumName);
		pPromo->setArtistName(artistName);
		pPromo->setFileSize(fileSize);
		pPromo->setTransfer(transfer);
		pPromo->setDate(date);
		pPromo->setPopularity(popularity);
		pPromo->setPrice(price);
		pPromo->setWebLink(webLink);
		pPromo->setNumDays(numDays);
	}
	
	cout << endl;
}
示例#14
0
	bool process(void)
	{
		uint32_t argc;
		const char **argv = getInputString(argc);

		if ( argv )
		{
			if ( strcmp(argv[0],"scan") == 0 )
			{
				if ( mMode == CM_SCAN )
				{
					printf("Pausing block-chain scan at block #%d\r\n", mLastBlockScan );
					mMode = CM_NONE;
				}
				else
				{
					printf("Scanning block-chain re-started from block %d up to a maximum of %d blocks..\r\n", mLastBlockScan, mMaxBlock);
					mMode = CM_SCAN;
				}
			}
			else if ( strcmp(argv[0],"exit") == 0 ||  strcmp(argv[0],"bye") == 0 || strcmp(argv[0],"quit") == 0  )
			{
				mMode = CM_EXIT;
			}
			else if ( strcmp(argv[0],"stop_scan") == 0 )
			{
				if ( mFinishedScanning )
				{
					printf("Already finished scanning the block-chain headers.  Found %d blocks.\r\n", mLastBlockScan );
				}
				else
				{
					stopScanning();
				}
			}
			else if ( strcmp(argv[0],"help") == 0 )
			{
				help();
			}
			else if ( strcmp(argv[0],"max_blocks") == 0 )
			{
				if ( argc >= 2 )
				{
					mMaxBlock = atoi(argv[1]);
					if ( mMaxBlock < 1 ) mMaxBlock = 1;
					printf("Maximum block scan set to %d\r\n", mMaxBlock );
				}
			}
			else if ( strcmp(argv[0],"by_day") == 0 )
			{
				mStatResolution = SR_DAY;
				printf("Will accumulate statistics on a per-day basis.\r\n");
				if ( !mProcessTransactions )
				{
					printf("Note: You must enable 'statistics' for this to take effect.\r\n");
				}
			}
			else if ( strcmp(argv[0],"by_month") == 0 )
			{
				mStatResolution = SR_MONTH;
				printf("Will accumulate statistics on a monthly basis.\r\n");
				if ( !mProcessTransactions )
				{
					printf("Note: You must enable 'statistics' for this to take effect.\r\n");
				}
			}
			else if ( strcmp(argv[0],"by_year") == 0 )
			{
				mStatResolution = SR_YEAR;
				printf("Will accumulate statistics on an annual basis.\r\n");
				if ( !mProcessTransactions )
				{
					printf("Note: You must enable 'statistics' for this to take effect.\r\n");
				}
			}
			else if ( strcmp(argv[0],"record_addresses") == 0 )
			{
				mRecordAddresses = mRecordAddresses ? false : true;
				printf("record_addresses set to %s\r\n", mRecordAddresses ? "true" : "false");
			}
			else if ( strcmp(argv[0],"adr") == 0 )
			{
				if ( argc == 1 )
				{
					printf("You must supply an address to output.\r\n");
				}
				else
				{
					for (uint32_t i=1; i<argc; i++)
					{
						const char *adr = argv[i];
						mBlockChain->printAddress(adr);
					}
				}
			}
			else if ( strcmp(argv[0],"process") == 0 )
			{
				if ( mMode == CM_PROCESS )
				{
					printf("Pausing processing block-chain blocks at block #%d of %d\r\n", mProcessBlock, mBlockChain->getBlockCount() );
					mMode = CM_NONE;
				}
				else
				{
					if ( !mFinishedScanning )
					{
						stopScanning();
					}
					mProcessBlock = 0;
					mMode = CM_PROCESS;
					printf("Beginning processing of %d blocks : Gathering Statistics=%s\r\n", 
					mBlockChain->getBlockCount(), 
					mProcessTransactions ? "true":"false");
				}
			}
			else if ( strcmp(argv[0],"statistics") == 0 )
			{
				mProcessTransactions = mProcessTransactions ? false : true;
				if ( mProcessTransactions )
				{
					printf("Block Processing will gather statistics.\r\n");
					printf("*** WARNING : This will consume an enormous amount of memory! ***\r\n");
				}
				else
				{
					printf("Block processing will not gather statistics.\r\n");
				}
			}
			else if ( strcmp(argv[0],"load_record") == 0 )
			{
				if ( mAddresses )
				{
					mAddresses->release();
					mAddresses = NULL;
				}
				printf("Loading previously recorded addresses from file 'BlockChainAddresses.bin\r\n");
				mAddresses = createBlockChainAddresses("BlockChainAddresses.bin");
			}
			else if ( strcmp(argv[0],"min_balance") == 0 )
			{
				if ( argc == 1 )
				{
					printf("No minimum balance specified, defaulting to 1btc.\r\n");
				}
				else
				{
					mMinBalance = (uint32_t)atoi(argv[1]);
					if ( mMinBalance < 1 )
					{
						mMinBalance = 1;
					}
					else
					{
						if ( mMinBalance > 1000000 )
						{
							mMinBalance = 1000000;
						}
					}
					printf("Minimum balance set to %d bitcoins.\r\n", mMinBalance );
				}
			}
			else if ( strcmp(argv[0],"top_balance") == 0 )
			{
				uint32_t tcount = 100;
				if ( argc >= 2 )
				{
					tcount = atoi(argv[1]);
					if ( tcount < 1 )
					{
						tcount = 1;
					}
				}
				printf("Printing the most valuable %d bitcoin addresses with a balance of more than %d bitcoins.\r\n", tcount, mMinBalance );
				mBlockChain->printTopBalances(tcount,mMinBalance);
			}
			else if ( strcmp(argv[0],"oldest") == 0 )
			{
				uint32_t tcount = 100;
				if ( argc >= 2 )
				{
					tcount = atoi(argv[1]);
					if ( tcount < 1 )
					{
						tcount = 1;
					}
				}
				printf("Printing the %d oldest bitcoin addresses with a balance of more than %d bitcoins.\r\n", tcount, mMinBalance );
				mBlockChain->printOldest(tcount,mMinBalance);
			}
			else if ( strcmp(argv[0],"zombie") == 0 )
			{
				uint32_t zdays = 365;
				if ( argc >=2 )
				{
					zdays = atoi(argv[1]);
					if ( zdays < 1 )
					{
						zdays = 1;
					}
				}
				printf("Generating Zombie Count for addresses older than %d days with a balance of more than %d bitcoins.\r\n", zdays, mMinBalance );
				mBlockChain->zombieReport(zdays,mMinBalance);
			}
			else if ( strcmp(argv[0],"by_day") == 0 )
			{
				mStatResolution = SR_DAY;
				printf("Gathering statistics every day.\r\n");
			}
			else if ( strcmp(argv[0],"by_month") == 0 )
			{
				mStatResolution = SR_MONTH;
				printf("Gathering statistics every month.\r\n");
			}
			else if ( strcmp(argv[0],"by_year") == 0 )
			{
				mStatResolution = SR_YEAR;
				printf("Gathering statistics every year.\r\n");
			}
			else if ( strcmp(argv[0],"counts") == 0 )
			{
				mBlockChain->reportCounts();
			}
			else if ( strcmp(argv[0],"block") == 0 )
			{
				if ( argc == 1 )
				{
					if ( mCurrentBlock )
					{
						mBlockChain->printBlock(mCurrentBlock);
						mCurrentBlock = mBlockChain->readBlock(mCurrentBlock->blockIndex+1);
					}
				}
				else
				{
					for (uint32_t i=1; i<argc; i++)
					{
						uint32_t index = (uint32_t)atoi(argv[i]);
						mCurrentBlock = getBlock(index);
						if ( mCurrentBlock )
						{
							mBlockChain->printBlock(mCurrentBlock);
						}
					}
				}
			}
		}
		switch ( mMode )
		{
			case CM_PROCESS:
				if ( mProcessBlock < mBlockChain->getBlockCount() )
				{
					mCurrentBlock = mBlockChain->readBlock(mProcessBlock);
					if ( mCurrentBlock && mProcessTransactions )
					{

						if ( mLastTime == 0 )
						{
							mLastTime = mCurrentBlock->timeStamp;
							mSatoshiTime = mCurrentBlock->timeStamp;
						}
						else
						{
							uint32_t currentTime = mCurrentBlock->timeStamp;
							time_t tnow(currentTime);
							struct tm beg;
							beg = *localtime(&tnow);
							time_t tbefore(mLastTime);
							struct tm before;
							before = *localtime(&tbefore);
							bool getStats = false;
							switch ( mStatResolution )
							{
								case SR_DAY:
									if ( beg.tm_yday != before.tm_yday )
									{
										getStats = true;
									}
									break;
								case SR_MONTH:
									if ( beg.tm_mon != before.tm_mon )
									{
										getStats = true;
									}
									break;
								case SR_YEAR:
									if ( beg.tm_year != before.tm_year )
									{
										getStats = true;
									}
									break;
							}
							if ( getStats )
							{
								const char *months[12] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
								printf("Gathering statistics for %s %d, %d to %s %d, %d\r\n", 
									months[before.tm_mon], before.tm_mday, before.tm_year+1900,
									months[beg.tm_mon], beg.tm_mday, beg.tm_year+1900);
								mBlockChain->gatherStatistics(mLastTime,(uint32_t)zombieDate,mRecordAddresses);
								mLastTime = currentTime;
							}
						}
						mBlockChain->processTransactions(mCurrentBlock);  // process transactions into individual addresses
					}
					mProcessBlock++;
					if ( (mProcessBlock%10000) == 0 )
					{
						printf("Processed block #%d of %d total.\r\n", mProcessBlock, mBlockChain->getBlockCount() );
					}
				}
				else
				{
					printf("Finished processing all blocks in the blockchain.\r\n");
					mBlockChain->reportCounts();
					if ( mProcessTransactions )
					{
						printf("Gathering final statistics.\r\n");
						mBlockChain->gatherStatistics(mLastTime,(uint32_t)zombieDate,mRecordAddresses);
						printf("Saving statistics to file 'stats.csv\r\n");
						mBlockChain->saveStatistics(mRecordAddresses);
					}
					mMode = CM_NONE;
					mProcessBlock = 0;
				}
				break;
			case CM_SCAN:
				{
					bool ok = mBlockChain->readBlockHeaders(mMaxBlock,mLastBlockScan);
					if ( !ok )
					{
						mFinishedScanning = true;
						mMode = CM_NONE; // done scanning.
						mLastBlockScan = mBlockChain->buildBlockChain();
						printf("Finished scanning block headers. Built block-chain with %d blocks found..\r\n", mLastBlockScan);
						printf("To resolve transactions you must execute the 'process' command.\r\n");
						printf("To gather statistics so you can ouput balances of individual addresses, you must execute the 'statistics' command prior to running the process command.\r\n");
					}
				}
				break;
		}
		return mMode != CM_EXIT;
	}
示例#15
0
SimManager::SimManager(IOManager &IO, const char *input_file) :
	_IO(IO), _print_reduced_conf_every(0), _print_energy_every(1000), _restart_step_counter(false) {
	_start_step = _cur_step = _steps = 0;
	_IO = IO;

	// variable to terminate the program; it is checked in the main
	// loop; if set to 1, the mayn cycle will exit;
	//void (*termhandler)(int);

	loadInputFile(&_input, input_file);
	if(_input.state == ERROR) _IO.die("Caught an error while opening the input file");

	char backend_opt[256], backend_prec[256], sim_type[256];
	getInputString(&_input, "backend", backend_opt, 1);

	if(getInputString(&_input, "backend_precision", backend_prec, 0) == KEY_NOT_FOUND) {
		_IO.log(_IO.LOG_INFO, "Backend precision not speficied, using double");
		sprintf(backend_prec, "%s", "double");
	}
	else _IO.log(_IO.LOG_INFO, "Backend precision: %s", backend_prec);

	if(getInputString(&_input, "sim_type", sim_type, 0) == KEY_NOT_FOUND) {
		_IO.log(_IO.LOG_INFO, "Simulation type not specified, using MD");
		sprintf(sim_type, "%s", "MD");
	}
	else _IO.log(_IO.LOG_INFO, "Simulation type: %s", sim_type);

	// I know that this is really ugly but I couldn't find a better way
	if(!strcmp(sim_type, "MD")) {
		if(!strcmp(backend_opt, "CPU")) {
			if(!strcmp(backend_prec, "double")) _backend = new MD_CPUBackend<double>(&_IO);
			else if(!strcmp(backend_prec, "float")) _backend = new MD_CPUBackend<float>(&_IO);
			else _IO.die("Backend precision '%s' is not supported", backend_prec);
		}
#ifndef NOCUDA
		else if(!strcmp(backend_opt, "CUDA")) {
			// what's the list type we want to use?
			char list_type[256];

			// LR_double4 is defined in CUDAUtils.h
			if(!strcmp(backend_prec, "double")) {
				if(getInputString(&_input, "CUDA_list", list_type, 0) == KEY_NOT_FOUND || !strcmp("no", list_type))
					_backend = new MD_CUDABackend<double, LR_double4, CUDANoList<double, LR_double4> >(&_IO);
				else if(!strcmp("verlet", list_type))
					_backend = new MD_CUDABackend<double, LR_double4, CUDASimpleVerletList<double, LR_double4> >(&_IO);
				else _IO.die("CUDA_list '%s' is not supported", list_type);
			}
			else if(!strcmp(backend_prec, "float")) {
				if(getInputString(&_input, "CUDA_list", list_type, 0) == KEY_NOT_FOUND || !strcmp("no", list_type))
					_backend = new MD_CUDABackend<float, float4, CUDANoList<float, float4> >(&_IO);
				else if(!strcmp("verlet", list_type))
					_backend = new MD_CUDABackend<float, float4, CUDASimpleVerletList<float, float4> >(&_IO);
				else _IO.die("CUDA_list '%s' is not supported", list_type);
			}
			else if(!strcmp(backend_prec, "mixed")) {
				if(getInputString(&_input, "CUDA_list", list_type, 0) == KEY_NOT_FOUND || !strcmp("no", list_type))
					_backend = new CUDAMixedBackend<CUDANoList<float, float4> >(&_IO);
				else if(!strcmp("verlet", list_type))
					_backend = new CUDAMixedBackend<CUDASimpleVerletList<float, float4> >(&_IO);
				else _IO.die("CUDA_list '%s' is not supported", list_type);
			}
			else _IO.die("Backend precision '%s' is not supported", backend_prec);
		}
#endif
		else _IO.die("Backend '%s' not supported", backend_opt);
	}
	else if(!strcmp(sim_type, "MC")) {
		if(!strcmp(backend_opt, "CPU")) {
			if(!strcmp(backend_prec, "double")) _backend = new MC_CPUBackend<double>(&_IO);
			else if(!strcmp(backend_prec, "float")) _backend = new MC_CPUBackend<float>(&_IO);
			else _IO.die("Backend precision '%s' is not supported", backend_prec);
		}
#ifndef NOCUDA
		else if(!strcmp(backend_opt, "CUDA")) {
			// what's the list type we want to use?
			char list_type[256];

			// LR_double4 is defined in CUDAUtils.h
			if(!strcmp(backend_prec, "double")) {
				if(getInputString(&_input, "CUDA_list", list_type, 0) == KEY_NOT_FOUND || !strcmp("no", list_type))
					_backend = new MC_CUDABackend<double, LR_double4, CUDANoList<double, LR_double4> >(&_IO);
				else if(!strcmp("verlet", list_type))
					_backend = new MC_CUDABackend<double, LR_double4, CUDASimpleVerletList<double, LR_double4> >(&_IO);
				else _IO.die("CUDA_list '%s' is not supported", list_type);
			}
			else if(!strcmp(backend_prec, "float")) {
				if(getInputString(&_input, "CUDA_list", list_type, 0) == KEY_NOT_FOUND || !strcmp("no", list_type))
					_backend = new MC_CUDABackend<float, float4, CUDANoList<float, float4> >(&_IO);
				else if(!strcmp("verlet", list_type))
					_backend = new MC_CUDABackend<float, float4, CUDASimpleVerletList<float, float4> >(&_IO);
				else _IO.die("CUDA_list '%s' is not supported", list_type);
			}
			else _IO.die("Backend precision '%s' is not supported", backend_prec);
		}
#endif
		else _IO.die("Backend '%s' not supported", backend_opt);
	}
	else _IO.die("Simulation type '%s' not supported", sim_type);
}