Esempio n. 1
0
void Ui::deposit(Account* const& account) {
  double amount = 0;
  std::string description = "";
  Date* date = new Date();
  std::string polar;

  std::cout << "\n***\n";
  std::cout << "* MAKE A NEW DEPOSIT\n";
  std::cout << "**********\n\n";

  std::cout << "Please enter amount to deposit.\n";
  amount = getUserInput();

  std::cout << "Do you want to describe your deposit (Y/N)?\n";
  polar = getUserInput("polar");

  if (polar == "no") {
    account->deposit(amount, description, date);
    return;
  }

  std::cout << "Please describe your deposit.\n";
  description = getUserInput("description");

  std::cout << "Please enter the date.\n";
  date->setDate();
  account->deposit(amount, description, date);
}
Esempio n. 2
0
void Ui::withdraw(Account* const& account) {
  double amount = 0;
  std::string description = "";
  Date* date = new Date();
  std::string polar;

  std::cout << "\n***\n";
  std::cout << "* MAKE A NEW WITHDRAWAL\n";
  std::cout << "**********\n\n";

  std::cout << "Please enter amount to withdraw.\n";
  amount = getUserInput();

  std::cout << "Do you want to describe your withdrawal (Y/N)?\n";
  polar = getUserInput("polar");

  if (polar == "no") {
    account->withdraw(amount, description, date);
    return;
  }

  std::cout << "Please describe your withdrawal.\n";
  description = getUserInput("description");

  std::cout << "Please enter the date.\n";
  date->setDate();
  account->withdraw(amount, description, date);
}
int main()
{
    char input;
    
    cout << "========= R E S T A U R A N T S   I N   C U P E R T I N O =========";
    
    listHead *restaurants = new listHead(hashSize);

    readFile(restaurants);
    
    restaurants->getHashPtr()->printHashTableSequence();
    

    // Display menu
    displayMenu();
    
    // Get user's input
    input = getUserInput();
    
    // While the user does not want to quit...
    while (input != 'q')
    {
        // Call appropriate operation
        operationManager(restaurants, input);
        
        // Get user's input
        input = getUserInput();
    }

    saveToFile(restaurants);
    
    cout << "\n======================== T H A N K  Y O U =========================";
}
Esempio n. 4
0
std::string Ui::createAccount() {
  std::string username;
  std::string password = "******";
  std::string repassword = "******";

  std::cout << "\n***\n";
  std::cout << "* ACCOUNT CREATION\n";
  std::cout << "**********\n\n";

  std::cout << "Please enter new username.\n";
  username = getUserInput("username");

  while (password != repassword) {
    std::cout << "Please enter a password.\n";
    password = getUserInput("password");

    std::cout << "Please reenter password.\n";
    repassword = getUserInput("password");

    if (password != repassword) {
      std::cout << "The password does not match.\n\n";
    }
  }
  if (Account::create(username, password)) {
    return username;
  }
  return "";
}
    bool ThreePointTouchScreenCalibrator::calibrate(TouchScreenCalibration*& calibrationResults) {

      Point p1Panel,p2Panel,p3Panel,p1Touch,p2Touch,p3Touch;

      // register as an event subscriber with the touch screen

      _clicked=true;

      _ts.TouchScreenReadyEventSender.insertSubscriber(TouchScreenReadyEventSourceSlot::bind(this,&ThreePointTouchScreenCalibrator::onTouchScreenReady));

      // point 1 is at 25%,50%, 2 is at 75%,25% and 3 is at 75%,75%

      getUserInput(25,50,p1Panel,p1Touch);
      getUserInput(75,25,p2Panel,p2Touch);
      getUserInput(75,75,p3Panel,p3Touch);

      // deregister our interest in clicks

      _ts.TouchScreenReadyEventSender.removeSubscriber(TouchScreenReadyEventSourceSlot::bind(this,&ThreePointTouchScreenCalibrator::onTouchScreenReady));

      // given the three points, expected and raw, we can do the mapping

      calibrationResults=new ThreePointTouchScreenCalibration(p1Panel,p2Panel,p3Panel,p1Touch,p2Touch,p3Touch);
      return true;
    }
Esempio n. 6
0
Account* Ui::loadAccount(const std::string& username) {
  Account* account;

  if (username.length() == 0) {
    std::string username;
    std::string actualPassword;
    std::string password;

    std::cout << "\n***\n";
    std::cout << "* LOAD ACCOUNT\n";
    std::cout << "**********\n\n";

    std::cout << "Please enter the username of the account.\n";
    username = getUserInput("username");
    if (!Account::validate(username)) {
      return nullptr;
    }

    std::cout << "Please enter password.\n";
    password = getUserInput("password");
    if (!Account::authenticate(username, password)) {
      return nullptr;
    }
     account = Account::load(username);
  }
  else {
    account = Account::load(username);
  }
  return account;
}
Esempio n. 7
0
static char* InputUserPassword(KonohaContext *kctx, const char *message)
{
	char buff[BUFSIZ] = {0};

	const char *file = PLATAPI shortFilePath((getThisFileName(kctx)));
	char cid[64] = {0};
	file2CId(file, cid);

//	char hostname[BUFSIZ] = {0};
//	gethostname(hostname, BUFSIZ);
//	struct addrinfo *res;
//	struct in_Addr addr;
//	int err;
//	if((err = getaddrinfo(hostname, NULL, NULL, &res)) != 0) {
//		PLATAPI syslog_i(5/*LOG_NOTICE*/, "{\"Method\": \"DScriptError\", \"CId\": \"%s\", \"Body\": \"error %d\"}", cid, err);
//		exit(1);
//	}
//	addr.s_Addr = ((struct sockaddr_in *)(res->ai_Addr))->sin_Addr.s_Addr;
//	char host[16] = {0};
//	memcpy(host, inet_ntoa(addr), 16);
//	freeaddrinfo(res);

	const char host[] = "127.0.0.1"; // TODO get localhost IP
	int port = 8090; // TODO random port scan

	PLATAPI LoggerModule.syslog_i(5/*LOG_NOTICE*/, "{\"Method\": \"DScriptPassword\", \"CId\": \"%s\", \"Body\": \"%s\", \"Ip\": \"%s:%d\"}" , cid, message, host, port);
	getUserInput(kctx, buff, cid, host, port);
	size_t len = strlen(buff) + 1;
	char *p = malloc(len);
	if(p != NULL) {
		memcpy(p, buff, len);
	}
	return p;
}
int main (int argc, char* argv[])
{
	//create an array of processes called queue.
	ticks = 0;
	loop = 0;
	queue q;
	createQueue(q);
	while (loop == 0)
	{
		ticks++;
		printf("%d",ticks);
		int i;
		for (i = 1; i < getQueueSize(q); i++)
		{
			if (ticks - q.items[i].timeStamp > ticks)
			{
				if (getQueueSize(q) > 0)
				{
					scheduleProcess(q);
				}
			}	
		}
		getUserInput(q);
		if (ticks % 10 == 0)
		{
			for (i = 1; i < getQueueSize(q); i++)
			{
				q.items[i].priority = q.items[i].priority + 1;
			}			
		}
		
	}
}
Esempio n. 9
0
File: gol.c Progetto: brugalter/gol
int main()

{
    srand((unsigned int) time(NULL));
    int grid[ROWS][COLS];
    initGrid(ROWS, COLS, grid);
    printGrid(ROWS, COLS, grid);

    int i, g;

    g = getUserInput();
    for(i = 0; i < g; i++)
    {
        generation++;
        proccessGeneration(ROWS, COLS, grid);
        printGrid(ROWS, COLS, grid);
        sleep(99999);
        putchar('\n');
    }



    return 0;

}
Esempio n. 10
0
std::string Ui::accountMenu() {
  std::cout << "This is the account options menu. ";
  std::cout << "Please choose from the following options:\n\n";
  std::cout << "1) Update account information.\n";
  std::cout << "2) Show withdrawals.\n";
  std::cout << "3) Show deposits.\n";
  std::cout << "4) Make a new withdrawal\n";
  std::cout << "5) Make a new deposit\n";
  std::cout << "6) Go back to main menu\n";

  int nChoices = 6;
  int userChose = getUserInput(nChoices);

  switch (userChose) {
  case 1:
    return "updateAccount";
  case 2:
    return "getWithdrawals";
  case 3:
    return "getDeposits";
  case 4:
    return "withdraw";
  case 5:
    return "deposit";
  case 6:
    return "quitAccountMenu";
  }
}
Esempio n. 11
0
int main(void) {
  printf("Hello, please input a base 10 number that you would like converted to base 2: ");
  unsigned long long int baseTen = getUserInput();
  printf("Number %llu converted to base 2 = ", baseTen);
  convert(baseTen);
  printf("\n");

  return 0;
}
Esempio n. 12
0
int playerMove()
{
    int random;
    printf("1. Attack\n");
    printf("2. Heal\n");
    printf("Selection: ");
    random = getUserInput(2);
    return random;
}
Esempio n. 13
0
int main()
{
	getUserInput();
	findMST();
	int i = 0;
	printf("最小生成树上节点相邻的情况为:\n");
	for (; i < totalNum; ++i){//打印最小生成树情况
		if(MST[i].parent != MST[i].node)
			printf("边%d (%c, %c) 权值:%.2f\n", i, i + 65,  MST[i].parent + 65, MST[i].cost);
	}
	system("pause");
	return 0;
}
Esempio n. 14
0
void Ui::deleteAccount() {
  std::string username;
  std::string actualPassword;
  std::string password;

  std::cout << "\n***\n";
  std::cout << "* ACCOUNT DELETION\n";
  std::cout << "**********\n\n";

  std::cout << "Please enter the username of the account to be deleted.\n";
  username = getUserInput("username");
  if (!Account::validate(username)) {
    return;
  }

  std::cout << "Please enter password.\n";
  password = getUserInput("password");
  if (!Account::authenticate(username, password)) {
    return;
  }

  Account::remove(username);
}
Esempio n. 15
0
void Ui::updateAccount(Account* const& account) {
  std::string firstName;
  std::string lastName;
  std::string polar = "no";
  std::string username = account->getUsername();
  std::string oldPassword;
  std::string newPassword = "******";
  std::string renewPassword = "******";

  std::cout << "\n***\n";
  std::cout << "* UPDATE ACCOUNT INFORMATION\n";
  std::cout << "**********\n\n";

  while (polar == "no") {
    std::cout << "Please enter your first name.\n";
    firstName = getUserInput("all");

    std::cout << "Please enter your last name.\n";
    lastName = getUserInput("all");

    std::cout << "Your full name is " << firstName << ' ' << lastName;
    std::cout << ". Is this correct (Y/N)?\n";
    polar = getUserInput("polar");
  }

  std::cout << "Do you want to change your password (Y/N)?\n";
  polar = getUserInput("polar");
  if (polar == "no") {
    account->update(firstName, lastName);
    return;
  }

  std::cout << "Please enter password.\n";
  oldPassword = getUserInput("password");
  if (!Account::authenticate(username, oldPassword)) {
    return;
  }

  while (newPassword != renewPassword) {
    std::cout << "Please enter a new password.\n";
    newPassword = getUserInput("password");

    std::cout << "Please reenter password.\n";
    renewPassword = getUserInput("password");

    if (newPassword != renewPassword) {
      std::cout << "The password does not match.\n\n";
    }
  }
  account->update(firstName, lastName, newPassword);
}
Esempio n. 16
0
File: mancala.c Progetto: wfei/hw
// The function is to process a player's move from displaying the board, getting
// user input to dealing with user input.
// It takes player, board array and gameNum as parameter. 
// gameNum is used to record how many turns the user and computer have played.
void playerToMove(int player,Hole board[],int* gameNum){
    char userInput;
    int playerDone = 0;
    int i = 0;
    do{
	if ((player == 1 && i > 0) || player == 0)
	    displayBoard(board);
	userInput = getUserInput(player, gameNum, playerDone, board);
	playerDone = pieceToMove(player, userInput, board);
	if(checkEndGame(board) == 0)
	    break;
	i++;
	
    }while (playerDone);
   
	
} //end of playerToMove
Esempio n. 17
0
int main(){
    std::vector<std::string> words;
	std::cout << "Quit by entering \"q\"" << std::endl;

    while(1){

		words = getUserInput();

		words = sort(words);
		for(unsigned int i = 0; i < words.size(); i++){
			std::cout << words[i] + " ";
		}
		std::cout << std::endl;
	}

    return 0;
    
}
Esempio n. 18
0
int main(int argc,char* argv[])
{
  signal(SIGINT, sig_handler);
  signal(SIGTERM, sig_handler);
  signal(SIGQUIT, sig_handler);
  signal(SIGTSTP, sig_handler);
  int isExit = 0;
  do {
    char rawInput[255];
    isExit = getUserInput(rawInput);
    if(isExit == 1) break;
    
    if (isExit == 0)
      tokenizeInput(rawInput);

  } while(isExit = 1);
  return 0;
}
Esempio n. 19
0
int main(int argc, char const *argv[])
{
	srand((unsigned int) time(NULL)); //Takes the current time and uses it as a seed for the random number generator
	int grid[ROWS][COLS]; //Make grid
	initGrid(ROWS, COLS, grid); //Initialize grid
	printGrid(ROWS, COLS, grid); //Print grid to screen

	int i, g;
	g = getUserInput();

	for (i = 0; i < g; i++)
	{
		generation++;
		processGeneration(ROWS, COLS, grid);
		printGrid(ROWS, COLS, grid);
		sleep(100);
	}
	return 0;
}
Esempio n. 20
0
File: mancala.c Progetto: wfei/hw
// The function is to process a player's move from displaying the board, getting
// user input to dealing with user input.
// It takes player, board array and gameNum as parameter. 
// gameNum is used to record how many turns the user and computer have played.
void playerToMove(int player,Hole board[],int gameNum){
    char userInput;
    int playerDone = 0;
    do{
	displayBoard(board);
	userInput = getUserInput(player, gameNum, playerDone, board);
	playerDone = pieceToMove(player, userInput, board);
	if(checkEndGame(board) == 0)
	    break;
	
    }while (playerDone);
    //displayBoard(board);
    //printf("---------------------------------------------------\n sepertat");

    /* if(oneGameDone){ */
    /* 	printf("-----------------------------------------------------\n"); */
    /* 	displayBoard(board); */
    /* } */
	
} //end of playerToMove
Esempio n. 21
0
int main(void)
{
	int iChoice = 0;

	// size console window to 100x40
	if(!initConsole())
	{
		// show error box
		showError("Error", "Console Window could not be initialized.\nExiting program.");
		
		return EXIT_FAILURE;
	}	

	// LogIn / Register Menu
	showStartScreen();

	do
	{
		// choose between LogIn and Register
		getUserInput("%i", &iChoice, "\tChoose: ", "\n\tYour input is invalid. Please choose again.\n");
	}
	while(iChoice != 1 && iChoice != 2);
	
	// LogIn / Register
	if(iChoice == 1)
	{
		// loop until valid login
		while(!showLogin());
	}
	else
	{
		// loop until valid registration
		while(!showRegister());
	}

	// loop until user quits manually
	while(startApplication());

	return EXIT_SUCCESS;
}
Esempio n. 22
0
bool AudioApp::Start()
{
	// While a windows quit message has not been posted.
	while(mMessage.message != WM_QUIT)
	{
		// Get waiting windows messages.
		if(PeekMessage( &mMessage, 0, 0, 0, PM_REMOVE ))
		{
			// Dispatch messages.
            TranslateMessage( &mMessage );
            DispatchMessage( &mMessage );
		}
		else
		{
			// Tick the game timer, and update the player.
			mGameTimer->tick();
			mPlayer->update();

			// React to any user input.
			getUserInput();

			// Update the monster object, and check player-monster proximity.
			mMonster->update(mPlayer, mGameTimer->getDeltaTime());
			checkMonsterDistance();

			// Play and update ambience sounds.
			mAmbience->play();
			mBatAmbience->play();
			mRockSlide->update(mPlayer, mGameTimer->getDeltaTime());
			mBatFlock->update(mPlayer, mGameTimer->getDeltaTime());

		}

	}

	// If application has exited the loop, shutdown the application.
	ShutDown();

	return true;
}
int main(int argc, char* argv[])
{
  //SUGGESTION = 18; //Does not work
  int theNumber; //Local variable of main
  theNumber = 20;
  printf("Todays number is 30, not %d\n", theNumber);
  printf("Tomorrow's number is 31, not %d\n", theNumber);

  int todaysNumber;
  todaysNumber = 30;
  printf("Todays number is %d, not %d\n", todaysNumber, theNumber);
  printf("Tomorrow's number is %d, not %d\n", todaysNumber+1, theNumber);
  
  todaysNumber = getUserInput();
  printf("Todays number is %d, not %d\n", todaysNumber, theNumber);
  printf("Tomorrow's number is %d, not %d\n", todaysNumber+1, theNumber);
  
  return 0;

  
  
}
Esempio n. 24
0
/*
* Takes in the following parameters
* File - The file to en-/decode
* Key - file containing the key used for en-/decoding the file
*/
int main (int argc, char **argv) {
	
	// Check if the program was started with two parameters (file and key)
	if (argc == 3){
		FileContainer files;
		int securityDistance;
		
		if (checkFiles(argv) != 0) {
			files = openAndReadKey(argv[2]);
			char action = getUserInput();
			int choice = encodeOrDecode(action);

			switch (encodeOrDecode(action)) {
			case 0:
				printMessage(TYPE_INFO, CHOICE_EXIT);
				free(files.key);
				exit(0);
			case 1:
				securityDistance = getWantedSecLvl();
				
				printMessage(TYPE_INFO, INFO_ENCODING_START);
				encodeFile(files, argv[1], securityDistance);
				printMessage(TYPE_INFO, INFO_ENCODING_END);
				break;
			case 2:
				printMessage(TYPE_INFO, INFO_DECODING_START);
				decodeFile(files, argv[1]);
				printMessage(TYPE_INFO, INFO_DECODING_END);
				break;
			default:
				break;
			}
		}
	} else {
		printMessage(TYPE_ERROR, ERROR_PARAMETERS);
	}

	return 0;
}
Esempio n. 25
0
std::string Ui::mainMenu() {
  std::cout << "This is the Checking Account App. ";
  std::cout << "Please choose from the following options:\n\n";
  std::cout << "1) Create new account.\n";
  std::cout << "2) Delete an existing account.\n";
  std::cout << "3) Load an existing account.\n";
  std::cout << "4) Quit\n\n";

  int nChoices = 4;
  int userChose = getUserInput(nChoices);

  switch (userChose) {
  case 1:
    return "createAccount";
  case 2:
    return "deleteAccount";
  case 3:
    return "loadAccount";
  case 4:
    return "quit";
  }
}
Esempio n. 26
0
static int InputUserApproval(KonohaContext *kctx, const char *message, const char *yes, const char *no, int defval)
{
	char buff[BUFSIZ] = {0};
	const char *ykey = defval ? "Y" : "y";
	const char *nkey = defval ? "n" : "N";
	if(message == NULL || message[0] == '\0') message = "Do you approve?";
	if(yes == NULL || yes[0] == '\0') yes = "yes";
	if(no == NULL || no[0] == '\0') no = "no";

	const char *file = PLATAPI shortFilePath((getThisFileName(kctx)));
	char cid[64] = {0};
	file2CId(file, cid);

//	char hostname[BUFSIZ] = {0};
//	gethostname(hostname, BUFSIZ);
//	struct addrinfo *res;
//	struct in_Addr addr;
//	int err;
//	if((err = getaddrinfo(hostname, NULL, NULL, &res)) != 0) {
//		PLATAPI syslog_i(5/*LOG_NOTICE*/, "{\"Method\": \"DScriptError\", \"CId\": \"%s\", \"Body\": \"error %d\"}", cid, err);
//		exit(1);
//	}
//	addr.s_Addr = ((struct sockaddr_in *)(res->ai_Addr))->sin_Addr.s_Addr;
//	char host[16] = {0};
//	memcpy(host, inet_ntoa(addr), 16);
//	freeaddrinfo(res);

	const char host[] = "127.0.0.1"; // TODO get localhost IP
	int port = 8090; // TODO random port scan

	PLATAPI LoggerModule.syslog_i(5/*LOG_NOTICE*/, "{\"Method\": \"DScriptApproval\", \"CId\": \"%s\", \"Body\": \"%s (%s %s, %s %s): \", \"Ip\": \"%s:%d\"}" , cid, message, yes, ykey, no, nkey, host, port);
	getUserInput(kctx, buff, cid, host, port);
	if(defval) {
		return ((buff[0] == 'N' || buff[0] == 'n') && buff[1] == 0) ? false : true;
	}
	else {
		return ((buff[0] == 'Y' || buff[0] == 'y') && buff[1] == 0) ? false : true;
	}
}
Esempio n. 27
0
int main(){
	/*Declare variables*/
	char *comp = "4";
	char *promptString = "Please enter a value: ";
	char *userInputReturn = (char *)malloc(BUFFERSIZE);
	int i = 0;

	/*initialize the unit testing framework*/
	cunit_init();

	/*Get user input*/
	userInputReturn = getUserInput(promptString);

	/*Replace first \n with null terminator for later comparison*/
	userInputReturn[strcspn(userInputReturn,"\n")] = '\0';

	/*Make comparison and place \n back to userInputReturn variable*/
	i = strcmp(comp, userInputReturn);
	userInputReturn[strcspn(userInputReturn,"\n")] = '\n';
	assert_eq("Input not in correct format", i, 0);

	return 0;
}
Esempio n. 28
0
void run() {
	displayTitle();
	displayIntroMessage();

	outputFlagContainer *outputFlags = malloc(sizeof(outputFlagContainer));

	while(true) {
		displayPreGameMenu();

		outputFlags = getUserInput(outputFlags);
		if (outputFlags->HELP) {
			displayHelpMessage();
		} else if (outputFlags->YES || outputFlags->PLAY) {
			gameloop(outputFlags);
		} else if (outputFlags->QUIT || outputFlags->NO) {
			displayQuitMessage();
			break;
		} else {
			displayBadInputMessage();
		}
	}

	free(outputFlags);
}
Esempio n. 29
0
int main( int argc, char *argv[] ) {

  char seqChar[MAXSEQLENGTH];
  int seqNum[MAXSEQLENGTH+1];  

  DBL_TYPE pf;
  int complexity = 3;
  int length, tmpLength;
  char inputFile[ MAXLINE];
  int vs;
  char sampleFile[MAXLINE];
  //permAvgPairs stores the expected value of each 
  //class of base pairs, grouped by permutation or complex, respectively

  int inputFileSpecified;
  FILE *F_sample = NULL; // ppairs file
  int index;

  strcpy( inputFile, "");
  nupack_sample = 1;
  nupack_num_samples = 10;
  struct timeval rand_time;

  gettimeofday(&rand_time,0);
  nupack_random_seed = (rand_time.tv_sec)*1000000 + rand_time.tv_usec;

  inputFileSpecified = ReadCommandLineNPK( argc, argv, inputFile);

  if(NupackShowHelp) {
    printf("Usage: sample [OPTIONS] PREFIX\n");
    printf("Randomly sample unpseudoknotted structures from the equilibrium distribution\n");
    printf("Example: sample -multi -T 25 -material dna -samples 100 example\n");
    PrintNupackThermoHelp();
    PrintNupackUtilitiesHelp();
    exit(1);
  }

  if( !inputFileSpecified ) {
    printf("Enter output file prefix: ");
    scanf("%s", inputFile);
    strcat(inputFile,".in"); // Here, .in is just a placeholder
  }

  if(!inputFileSpecified ||
     !ReadInputFile( inputFile, seqChar, &vs, NULL, NULL, NULL) ) {
       if (inputFileSpecified==0) getUserInput( seqChar, &vs, NULL, NULL);
       else abort();
  }

  strncpy(sampleFile,inputFile,strlen(inputFile)-3);
  sampleFile[strlen(inputFile)-3] = '\0';
  strcat(sampleFile,".sample");

  header( argc, argv, "sample", sampleFile);
  printInputs( argc, argv, seqChar, vs, NULL, NULL,sampleFile);


  tmpLength = length = strlen( seqChar);
  convertSeq(seqChar, seqNum, tmpLength);
  int ns1,ns2;
  getSequenceLength(seqChar, &ns1);
  getSequenceLengthInt(seqNum, &ns2);

  init_genrand(nupack_random_seed);

  pairPr = NULL;
  if (complexity != 3) {
    printf("Sampling supported only for complexity = 3. Exiting\n");
    exit(1);
  }

  nupack_sample_list = (char **)calloc(nupack_num_samples, sizeof(char *));
  printf("Number of Samples = %i\n",nupack_num_samples);
  for(index = 0 ; index < nupack_num_samples ; index++) {
    nupack_sample_list[index] = (char *) calloc(tmpLength+1,sizeof(char));
  }

  printf("Started Calculation\n");
  pf = pfuncFull(seqNum, complexity, DNARNACOUNT, DANGLETYPE, TEMP_K - ZERO_C_IN_KELVIN, 0,
      SODIUM_CONC, MAGNESIUM_CONC, USE_LONG_HELIX_FOR_SALT_CORRECTION);
  printf("Finished Calculation\n");


  

  
  if ((F_sample = fopen(sampleFile,"a")) == NULL) {
    printf("Error opening file %s!\n",sampleFile);
    exit(1);
  }

  // Print the free energy to the output file
  fprintf(F_sample,"%s Free energy: %.8Le kcal/mol\n",
          COMMENT_STRING,-kB*TEMP_K*logl(pf));
  fprintf(F_sample,"%s Number of Samples: %i\n",COMMENT_STRING,nupack_num_samples);

  // Put newline for stylistic reasons
  fprintf(F_sample,"\n");


  for(index = 0 ; index < nupack_num_samples ; index++) {
    fprintf(F_sample, "%s\n",nupack_sample_list[index]);
    free(nupack_sample_list[index]);
    nupack_sample_list[index] = NULL;
  }
  free(nupack_sample_list);

#ifdef GC_DEBUG
  CHECK_LEAKS();
#endif
  return 0;
}
Esempio n. 30
0
int main( int argc, char *argv[] ) {
  
  //This function will calculate the all structures within a fixed
  //range of the "algorithmic" mfe.  The algorithmic mfe is the
  //minimum free energy of a structure, ignoring symmetry corrections.
  
  //The output is a list of the structures, including the difference
  //from the algorithmic mfe, followed by the symmetry factor and the
  //corrected energies, after adjusting for symmetries.  The list is
  //sorted by the corrected energies.
  
  char seq[ MAXSEQLENGTH];
  int seqNum[ MAXSEQLENGTH+1];
  int isNicked[ MAXSEQLENGTH];
  int nNicks = 0;
  
  int nicks[MAXSTRANDS];
  int nickIndex;
  int **etaN;	
  int complexity = 3;
  int length, tmpLength;
  float gap = -1;
  int i;
  int vs;
  char outFile[MAXLINE];
  int inputFileSpecified;
  FILE *fp;
  
  dnaStructures mfeStructs = {NULL, 0, 0, 0, NAD_INFINITY}; 
  //this struct will store
  //all the structures within the given range
  
  char inputFile[ MAXLINE];
  strcpy( inputFile, "");
  
  inputFileSpecified = ReadCommandLineNPK( argc, argv, inputFile);
  
  if(NupackShowHelp) {
    printf("Usage: subopt [OPTIONS] PREFIX\n");
    printf("Calculate and store all structures within the specified energy gap\n");
    printf("of the MFE structure.\n");
    printf("Example: subopt -multi -T 25 -material dna example\n");
    PrintNupackThermoHelp();
    PrintNupackUtilitiesHelp();
    exit(1);
  }

  if( !inputFileSpecified ) {
    printf("Enter output file prefix: ");
    scanf("%s", inputFile);
    strcat(inputFile,".in"); // Here, .in is just a placeholder
  }
  
  if( !inputFileSpecified ||
     !ReadInputFile( inputFile, seq, &vs, &gap, NULL, NULL) ) {
       if (inputFileSpecified==0) getUserInput( seq, &vs, &gap, NULL);
       else abort();
     }
  strncpy(outFile,inputFile,strlen(inputFile)-3);
  outFile[strlen(inputFile)-3] = '\0';
  strcat(outFile,".subopt");
  
  header( argc, argv, "subopt", outFile);
  printInputs( argc, argv, seq, vs, &gap, NULL, outFile);
  
  // Add newline for stylistic reasons
  fp = fopen(outFile,"a");
  fprintf(fp,"\n");
  fclose(fp);
  
  if( !DO_PSEUDOKNOTS ) {
    complexity = 3;
  }
  else {
    complexity = 5;
  }
  
  tmpLength = length = strlen( seq);
  convertSeq(seq, seqNum, tmpLength);

  mfeFullWithSym_SubOpt( seqNum, tmpLength, &mfeStructs, complexity, 
                        DNARNACOUNT, DANGLETYPE, 
                        TEMP_K - ZERO_C_IN_KELVIN,
			 vs, (DBL_TYPE) gap, 0, SODIUM_CONC, MAGNESIUM_CONC,
			 USE_LONG_HELIX_FOR_SALT_CORRECTION);

  //the rest is for printing purposes
  
  for( i = 0; i < tmpLength; i++) {
    isNicked[i] = 0;
    if( seq[i] == '+') {
      length--;
      isNicked[ i - nNicks++ -1] = 1;
    } 
  }
  
  //initialize nicks
  for( i = 0; i < MAXSTRANDS; i++) {
    nicks[i] = -1;
  }
  
  nickIndex = 0;
  for( i = 0; i < length; i++) {
    if( isNicked[i])
      nicks[ nickIndex++] = i;
  }
  
  //overkill, but convenient
  etaN = (int**) malloc( (length*(length+1)/2 + (length+1))*sizeof( int*));
  InitEtaN( etaN, nicks, length);
  
  PrintDnaStructures( &mfeStructs, etaN, nicks, vs, outFile);
  
  clearDnaStructures( &mfeStructs);
  
  return 0;
}