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!";
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);
GammaLib application base class.
Filename class interface definition.
Abstract FITS extension base class definition.
FITS file class interface definition.
Application parameter class.
Application parameter container class.
std::vector< GApplicationPar > m_pars
Parameters.
void load(const GFilename &filename)
Load parameters.
void save(const GFilename &filename)
Save parameters.
void clear(void)
Clear parameter container.
bool contains(const std::string &name) const
Check parameter exists.
int size(void) const
Return number of parameters in container.
GammaLib application interface definition.
void log_string(const GChatter &chatter, const std::string &string, const bool &linefeed=true)
Write string in log file.
GLog log
Application logger.
bool m_need_help
–help specified
double gCO2e(const std::string &country) const
Return application equivalent CO2 footprint (units: g CO2e)
void write_statistics(void)
Write application statistics.
void init_members(void)
Initialise class members.
std::vector< std::string > m_args
Command line arguments.
void set_log_chatter(void)
Set chattiness of logger.
void log_value(const GChatter &chatter, const std::string &name, const std::string &value)
Write parameter value in log file.
GApplication(void)
Void constructor.
std::string m_version
Application version.
void log_parameters(const GChatter &chatter)
Write application parameters in log file.
bool logTerse(void) const
Signal terse logging.
const bool & statistics(void) const
Signals if statistics will be written.
std::string m_parfile
Parameter filename.
GApplicationPars m_pars
Application parameters.
bool clobber(void) const
Return clobber.
std::string print(const GChatter &chatter=NORMAL) const
Print application.
void copy_members(const GApplication &app)
Copy class members.
const std::string & log_filename(void) const
Returns log filename.
std::time_t m_tstart
Calendar start time of execution.
bool has_par(const std::string &name) const
Signal if specified parameter exists.
void stamp(GFitsHDU &hdu) const
Stamp FITS header with provenance information.
void set_log_filename(void)
Set log filename from "logfile" parameter.
bool m_pars_loaded
Application parameters loaded.
GApplication * clone(void) const
Clone application.
void logFileClose(void)
Close log file.
std::string m_logfile
Log filename.
void log_trailer(void)
Write application trailer in log file.
void clear(void)
Clear application.
void logFileOpen(const bool &clobber=true)
Open log file.
std::string m_name
Application name.
double celapse(void) const
Return application elapsed time in CPU seconds.
bool logNormal(void) const
Signal normal logging.
const std::string & version(void) const
Return application version.
const GApplicationPars & pars(void) const
Return application parameters.
void log_header2(const GChatter &chatter, const std::string &header)
Write header 2 in log file.
void set_statistics(void)
Set statistics according to parent child status.
void free_members(void)
Delete class members.
void log_header3(const GChatter &chatter, const std::string &header)
Write header 3 in log file.
void log_header1(const GChatter &chatter, const std::string &header)
Write header 1 in log file.
bool m_statistics
Enable writing of statistics.
bool logDebug(void) const
Signal debug logging.
const std::string & par_filename(void) const
Returns parameter filename.
void log_header(void)
Write application header in log file.
double telapse(void) const
Return application elapsed time in calendar seconds.
~GApplication(void)
Destructor.
const std::string & name(void) const
Return application name.
bool logExplicit(void) const
Signal explicit logging.
GApplication & operator=(const GApplication &app)
Assignment operator.
bool logVerbose(void) const
Signal verbose logging.
double m_cstart
Clock start time of execution.
double m_celapse
Internal CPU seconds counter.
bool is_fits(void) const
Checks whether file is a FITS file.
std::string url(void) const
Return Uniform Resource Locator (URL)
Abstract FITS extension base class.
GFitsHeaderCard & card(const int &cardno)
Return header card.
Abstract interface for FITS table column.
virtual double real(const int &row, const int &inx=0) const =0
virtual std::string string(const int &row, const int &inx=0) const =0
Abstract interface for FITS table.
const int & nrows(void) const
Return number of rows in table.
int size(void) const
Return number of HDUs in FITS file.
void save(const bool &clobber=false)
Saves FITS file.
GFitsTable * table(const int &extno)
Get pointer to table HDU.
long int written_size(void) const
Return number of characters written through this logger.
void indent(const int &indent)
Set indentation.
bool is_open(void) const
Signal that log file is open.
void header3(const std::string &arg)
Write string as header enclosed by '===' into logger.
void open(const GFilename &filename, const bool &clobber=false)
Open log file.
void header2(const std::string &arg)
Write string as header framed by '-' characters into logger.
void close(void)
Close log file.
void chatter(const GChatter &chatter)
Set chattiness.
void header1(const std::string &arg)
Write string as header framed by '=' characters into logger.
void clear(void)
Clear object.
void cout(const bool &flag)
Set standard output stream (cout) flag.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
GFilename gamma_filename(const std::string &name)
Returns filename in .gamma directory.
std::string strdate(void)
Return current date.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
std::string left(const std::string &s, const int &n, const char &c=' ')
Left justify string to achieve a length of n characters.
std::string strip_whitespace(const std::string &arg)
Strip leading and trailing whitespace from string.
std::string host_country(const bool &force_query=false)
Return two-digit host country code.
std::string centre(const std::string &s, const int &n, const char &c=' ')
Centre string to achieve a length of n characters.
std::string fill(const std::string &s, const int &n)
Fill string with n strings of same type.