Ejemplo n.º 1
0
double pyne::half_life(int nuc)
{
  // Find the nuclide's half life in s
  std::map<int, double>::iterator nuc_iter, nuc_end;

  nuc_iter = half_life_map.find(nuc);
  nuc_end = half_life_map.end();

  // First check if we already have the nuc in the map
  if (nuc_iter != nuc_end)
    return (*nuc_iter).second;

  // Next, fill up the map with values from the 
  // nuc_data.h5, if the map is empty.
  if (half_life_map.empty())
  {
    _load_atomic_decay();
    return half_life(nuc);
  };

  // Finally, if none of these work, 
  // assume the value is stable
  double hl = 1.0 / 0.0;
  half_life_map[nuc] = hl;
  return hl;
};
Ejemplo n.º 2
0
double pyne::half_life(std::string nuc)
{
  int nuc_zz = nucname::zzaaam(nuc);
  return half_life(nuc_zz);
};
Ejemplo n.º 3
0
double pyne::half_life(char * nuc)
{
  int nuc_zz = nucname::zzaaam(nuc);
  return half_life(nuc_zz);
};
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
	time_t startTime;
	bool started_flag = false;
	bool drinks_disabled_flag = false;
	bool metric_flag = false;
	
	//This is the variable that holds the current amount of caffeine
	//so basicly the whole program is centred around changing this
	//variable. Change with caution!
	double caffeineAmount  = 0.0;
	double caffeineTotal   = 0.0;
	double addCaffeine     = 0.0;
	double amountRemaining = 0.0;
	
	display_heading("Eternal Caffeine v2.0 <copyleft. 2015-2016>\n");
	
	if(argc > 1){ //if any arguments are give at all
		printf("I don't know what `%s' is but here is the help menu.\n", argv[1]);
		usage();
		exit(EXIT_SUCCESS);
	}
	
	puts("Enter help for usage.\n\n");
	
	
	
	
	FILE *drinkfile = fopen(DRINK_PATH_CURRENT, "r");
	
	if(drinkfile == NULL){ //try the install path
		drinkfile = fopen(DRINK_PATH_INSTALL, "r");
	}
	
	const unsigned int DRINK_COUNT = count_lines(drinkfile); //we must count the number of entries so we know how much to allocate
	struct drink drink_table[DRINK_COUNT];
	
	if(DRINK_COUNT == 0 || drinkfile == NULL){
		puts("No drinks found! Disabling drinks feature...");
		drinks_disabled_flag = true;
	} else {
		load_drinks(drinkfile, drink_table, drinks_disabled_flag);
		fclose(drinkfile);
	}
	
	
	
	char command[INPUT_MAX];
	while(IM_ETERNAL){
		printf("command");
		input_str(command);
		
		if( string_compare(command, "help") ){
			
			usage();
		
		} else if ( string_compare(command, "start") || string_compare(command, "update") ){
			
			if(started_flag){
				//do halflife before add new amount
				caffeineAmount = half_life(caffeineAmount,
				                           time_elapsed(startTime),
				                           HALFLIFE_OF_CAFFEINE);
			} else {
				started_flag = true;
			}
			
			startTime      = time(NULL);
			
			//add new amount
			addCaffeine    = update(drink_table, DRINK_COUNT, drinks_disabled_flag, metric_flag);
			caffeineAmount = caffeineAmount + addCaffeine;
			caffeineTotal  = caffeineTotal + addCaffeine;
			
			printf("Caffeine amount is now %.02lfmg\n", caffeineAmount);
			
		} else if( string_compare(command, "report") ){
			
			if(! started_flag ){
				puts("You have not started yet. Enter the start command!!!");
				continue;
			}
			
			amountRemaining = half_life(caffeineAmount,
			                            time_elapsed(startTime),
			                            HALFLIFE_OF_CAFFEINE);
			
			give_report(amountRemaining, caffeineTotal);
		
		} else if( string_compare(command, "quit") ){
			
			putchar('\n');
			exit(EXIT_SUCCESS);
		
		} else if( string_compare(command, "metric") ){
			metric_flag = !metric_flag; //toggle
			
			printf("Metric is now ");
			if(metric_flag){
				printf("on.\n");
			}else{
				printf("off.\n");
			}
			
		} else if( string_compare(command, "wipe") ){
			
			addCaffeine = caffeineAmount = caffeineTotal = 0.0;
			metric_flag = started_flag = false;
			
			puts("All values have been reset.");
			
		} else {
			
			puts("Command unknown. Enter help for usage.");
			continue;
			
		}
		
	}
	
	
	
	return EXIT_SUCCESS;
}