150 const std::string& version,
196 const std::string& version,
213 for (
int i = 0; i < argc; ++i) {
223 if (
m_args[1] ==
"--help") {
414 double celapse = (double(clock()) -
m_cstart) / (
double)CLOCKS_PER_SEC;
471 const double ef_total = 4.68;
472 const double ef_electricity = 2.43;
473 const double ef_other = ef_total - ef_electricity;
474 const double ef_kWh = 108.0;
477 static bool has_data =
true;
478 static std::vector<std::string> code;
479 static std::vector<double> ef;
480 static std::string last_code =
"";
481 static double last_ef = 0.0;
488 if (!country.empty()) {
494 if (has_data && code.empty()) {
500 GFilename filename(
"$GAMMALIB/share/refdata/emission-factors.fits");
506 filename =
GFilename(
"$TEST_SRCDIR/refdata/emission-factors.fits");
513 GFits fits(filename);
519 int num = table->
nrows();
533 for (
int i = 0; i < num; ++i) {
536 std::string val_code = ptr_code->
string(i,0);
537 double val_ef = ptr_ef->
real(i,0);
540 code.push_back(val_code);
541 ef.push_back(val_ef);
544 if (val_code == country) {
545 last_code = val_code;
562 double val_ef = ef_kWh;
566 if (country == last_code) {
572 int size = code.size();
573 for (
int i = 0; i < size; ++i) {
574 if (code[i] == country) {
584 double cpu_hours =
celapse() / 3600.0;
587 double eff_ef = ef_other + ef_electricity * val_ef / ef_kWh;
590 gCO2e = eff_ef * cpu_hours;
601 double cpu_hours =
celapse() / 3600.0;
604 gCO2e = ef_total * cpu_hours;
696 return (chatter > 0);
714 return (chatter > 1);
732 return (chatter > 2);
749 return (chatter > 3);
797 const int header_width = 80;
831 log <<
"Application \"" <<
m_name <<
"\" terminated after ";
832 log << telapse <<
" wall clock seconds, consuming ";
833 log << celapse <<
" seconds of CPU time and generating a carbon";
834 log <<
" footprint of " << gCO2e <<
" g eCO2.";
835 if (gCO2e >= 1000.0) {
836 log <<
" Please watch your carbon footprint.";
839 log <<
" This was rather quick and economic!";
841 if (telapse > 86400.0) {
842 log <<
" Hope it was worth waiting ...";
862 const std::string&
string,
863 const bool& linefeed)
870 if (chattiness >= chatter) {
893 const std::string& name,
894 const std::string& value)
901 if (chattiness >= chatter) {
903 log << value << std::endl;
922 const std::string& name,
930 if (chattiness >= chatter) {
932 log << value << std::endl;
951 const std::string& name,
959 if (chattiness >= chatter) {
961 log << value << std::endl;
979 const std::string& header)
986 if (chattiness >= chatter) {
1006 const std::string& header)
1013 if (chattiness >= chatter) {
1032 const std::string& header)
1039 if (chattiness >= chatter) {
1064 if (chattiness >= chatter) {
1079 log << name <<
"[not queried]" << std::endl;
1107 hdu.
card(
"CREATOR", creator,
"Program which created the file");
1124 for (
int i = 0; i < fits.
size(); ++i) {
1143 GFits fits(filename);
1171 result.append(
"=== GApplication ===");
1178 for (
int i = 0; i <
m_args.size(); ++i) {
1309 bool parent = (
running() < 1);
1325 int chatter =
m_pars[
"chatter"].integer();
1331 else if (chatter > 4) {
1358 if (
m_pars[
"logfile"].is_valid()) {
1386 if (access(filename.
url().c_str(), R_OK) != 0) {
1390 #pragma omp critical(GApplication_write_statistics)
1395 FILE* fptr = fopen(filename.
url().c_str(),
"w");
1397 fprintf(fptr,
"Date,"
1402 "Wall clock seconds,"
1413 #pragma omp critical(GApplication_write_statistics)
1418 lock.l_type = F_WRLCK;
1419 lock.l_whence = SEEK_SET;
1422 lock.l_pid = getpid();
1423 int fd = open(filename.
url().c_str(), O_WRONLY);
1427 fcntl(fd, F_SETLKW, &lock);
1431 FILE* fptr = fopen(filename.
url().c_str(),
"a");
1438 fprintf(fptr,
"%s,%s,%s,%s,%s,%e,%e,%e\n",
1449 lock.l_type = F_UNLCK;
1450 fcntl(fd, F_SETLK, &lock);
GApplication(void)
Void constructor.
bool logTerse(void) const
Signal terse logging.
void set_log_chatter(void)
Set chattiness of logger.
Application parameter container class.
void open(const GFilename &filename, const bool &clobber=false)
Open log file.
void header1(const std::string &arg)
Write string as header framed by '=' characters into logger.
void log_header3(const GChatter &chatter, const std::string &header)
Write header 3 in log file.
void log_value(const GChatter &chatter, const std::string &name, const std::string &value)
Write parameter value in log file.
GFitsTable * table(const int &extno)
Get pointer to table HDU.
void write_statistics(void)
Write application statistics.
~GApplication(void)
Destructor.
const std::string & name(void) const
Return application name.
void header2(const std::string &arg)
Write string as header framed by '-' characters into logger.
void set_log_filename(void)
Set log filename from "logfile" parameter.
void copy_members(const GApplication &app)
Copy class members.
double m_celapse
Internal CPU seconds counter.
std::time_t m_tstart
Calendar start time of execution.
const bool & statistics(void) const
Signals if statistics will be written.
bool is_open(void) const
Signal that log file is open.
GApplication * clone(void) const
Clone application.
Abstract FITS extension base class.
const std::string & log_filename(void) const
Returns log filename.
bool has_par(const std::string &name) const
Signal if specified parameter exists.
std::vector< GApplicationPar > m_pars
Parameters.
std::string strdate(void)
Return current date.
void logFileClose(void)
Close log file.
void chatter(const GChatter &chatter)
Set chattiness.
double m_cstart
Clock start time of execution.
const std::string & par_filename(void) const
Returns parameter filename.
void log_header2(const GChatter &chatter, const std::string &header)
Write header 2 in log file.
std::string m_logfile
Log filename.
void header3(const std::string &arg)
Write string as header enclosed by '===' into logger.
void log_header(void)
Write application header in log file.
void log_string(const GChatter &chatter, const std::string &string, const bool &linefeed=true)
Write string in log file.
FITS file class interface definition.
std::string strip_whitespace(const std::string &arg)
Strip leading and trailing whitespace from string.
double celapse(void) const
Return application elapsed time in CPU seconds.
void stamp(GFitsHDU &hdu) const
Stamp FITS header with provenance information.
void cout(const bool &flag)
Set standard output stream (cout) flag.
std::string centre(const std::string &s, const int &n, const char &c= ' ')
Centre string to achieve a length of n characters.
void log_trailer(void)
Write application trailer in log file.
GApplication & operator=(const GApplication &app)
Assignment operator.
bool logExplicit(void) const
Signal explicit logging.
virtual std::string string(const int &row, const int &inx=0) const =0
void init_members(void)
Initialise class members.
Abstract FITS extension base class definition.
void clear(void)
Clear application.
bool logNormal(void) const
Signal normal logging.
std::vector< std::string > m_args
Command line arguments.
int size(void) const
Return number of parameters in container.
void save(const bool &clobber=false)
Saves FITS file.
void log_header1(const GChatter &chatter, const std::string &header)
Write header 1 in log file.
bool clobber(void) const
Return clobber.
Abstract interface for FITS table column.
std::string left(const std::string &s, const int &n, const char &c= ' ')
Left justify string to achieve a length of n characters.
GammaLib application base class.
double telapse(void) const
Return application elapsed time in calendar seconds.
void close(void)
Close log file.
void set_statistics(void)
Set statistics according to parent child status.
Abstract interface for FITS table.
void free_members(void)
Delete class members.
bool m_pars_loaded
Application parameters loaded.
void save(const GFilename &filename)
Save parameters.
bool is_fits(void) const
Checks whether file is a FITS file.
std::string m_version
Application version.
GFilename gamma_filename(const std::string &name)
Returns filename in .gamma directory.
std::string print(const GChatter &chatter=NORMAL) const
Print application.
bool m_need_help
–help specified
const std::string & version(void) const
Return application version.
void logFileOpen(const bool &clobber=true)
Open log file.
const int & nrows(void) const
Return number of rows in table.
void log_parameters(const GChatter &chatter)
Write application parameters in log file.
const GApplicationPars & pars(void) const
Return application parameters.
GLog log
Application logger.
GApplicationPars m_pars
Application parameters.
std::string url(void) const
Return Uniform Resource Locator (URL)
std::string host_country(const bool &force_query=false)
Return two-digit host country code.
virtual double real(const int &row, const int &inx=0) const =0
bool logDebug(void) const
Signal debug logging.
long int written_size(void) const
Return number of characters written through this logger.
int size(void) const
Return number of HDUs in FITS file.
Application parameter class.
bool logVerbose(void) const
Signal verbose logging.
GammaLib application interface definition.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
std::string m_name
Application name.
bool m_statistics
Enable writing of statistics.
std::string fill(const std::string &s, const int &n)
Fill string with n strings of same type.
GFitsHeaderCard & card(const int &cardno)
Return header card.
void indent(const int &indent)
Set indentation.
double gCO2e(const std::string &country) const
Return application equivalent CO2 footprint (units: g CO2e)
std::string m_parfile
Parameter filename.
Filename class interface definition.
void load(const GFilename &filename)
Load parameters.
bool contains(const std::string &name) const
Check parameter exists.
void clear(void)
Clear object.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
void clear(void)
Clear parameter container.