/* * Convert from one equinox (or named coordinate system) to another. * The first 2 parameters may be numbers, such as "2000" or "1950", or * coordinate system names, like "J2000", "FK5", "GALACTIC", "ECLIPTIC", ... * Epoch is the besselian epoch in years. * If dflag is 1, the ra value was converted to hours by dividing by 15 */ int WorldCoords::convertEquinox(const char* fromEquinoxStr, const char* toEquinoxStr, double epoch, int dflag) { // check for numerical equinox double from_equinox = 0.; double to_equinox = 0.; if (getEquinox(fromEquinoxStr, from_equinox) == 0 && getEquinox(toEquinoxStr, to_equinox) == 0) return convertEquinox(from_equinox, to_equinox); // convert from one system to another int sys1 = wcscsys((char*)fromEquinoxStr); if (sys1 == -1) return error("bad equinox value: ", fromEquinoxStr); int sys2 = wcscsys((char*)toEquinoxStr); if (sys2 == -1) return error("bad equinox value: ", toEquinoxStr); double dtheta = ra_.val(); if (dflag) dtheta *= 15; // hours to degrees double dphi = dec_.val(); wcscon(sys1, sys2, from_equinox, to_equinox, &dtheta, &dphi, epoch); if (sys2 == WCS_J2000 || sys2 == WCS_B1950) dtheta /= 15; // degrees to hours ra_ = HMS(dtheta); dec_ = HMS(dphi); dec_.show_sign(1); return 0; }
/* * constructor - parse coordinates in string format as above, except that * equinoxStr may be a number or the system name, such as "GALACTIC" or "ECLIPTIC". */ WorldCoords::WorldCoords(const char* ra_str, const char* dec_str, const char* equinoxStr, int hflag) : status_(0), dec_(dec_str) { int dflag = 0; // set to 1 if ra was divided by 15 ra_ = HMS(ra_str, hflag, &dflag); if (ra_.isNull()) { status_ = 1; return; } if (dec_.isNull()) { status_ = 1; return; } dec_.show_sign(1); double equinox = 2000.; if (getEquinox(equinoxStr, equinox) == 0) { status_ = checkRange() || convertEquinox(equinox); } else { // hack - need to know if the RA value is in hours or deg status_ = convertEquinox(equinoxStr, "J2000", 0., dflag); } }
//============================================================================================ // Create a new DataTime forward elapsed from given data //============================================================================================ DateTime TimeComparer::DetermineBackwardsElapsed(const DateTime& dt, const PeriodData& pd) { PartialDateTime isoDt(dt, CalType::CalType_ISO); //add time Time tm; FixedDateTime fwdDate = isoDt.GetFixed() - tm.ConvertToFixed(HMS(pd.elapsedHours, pd.elapsedMinutes, pd.elapsedSeconds, pd.elapsedMilliseconds)); return DateTime(fwdDate); }
/* * Constructor - parse a free format string assumed to contain RA and DEC * * If hflag is 1 and the ra value is not in H:M:S and is not an integer, * convert to hours by dividing by 15. */ GaiaWorldCoords::GaiaWorldCoords( const char* ra_str, const char* dec_str, int check_range, double equinox, int hflag ) : WorldCoords(), check_range_( check_range ) { ra_ = HMS( ra_str, hflag ); dec_ = HMS( dec_str ); if ( ra_.isNull() ) { status_ = 1; return; } if ( dec_.isNull() ) { status_ = 1; return; } dec_.show_sign( 1 ); status_ = checkRange() || convertEquinox( equinox ); }
/* * convert from one equinox to another. */ int WorldCoords::convertEquinox(double from_equinox, double to_equinox) { if (from_equinox == to_equinox) return 0; double q0[2], q1[2]; q0[0] = ra_.val() * 15; // hours to degrees q0[1] = dec_.val(); if (prej_q(q0, q1, from_equinox, to_equinox)) { // was successful ra_ = HMS(q1[0]/15); // degrees to hours dec_ = HMS(q1[1]); dec_.show_sign(1); return 0; // OK } // error return char buf[126]; sprintf(buf, "could not convert equinox from %g to %g\n", from_equinox, to_equinox); return error(buf); }
/* * constructor - from string value, in format H:M:S.sss, hh, d.ddd, or * H M S... * If hflag is 1 and the value is not in H:M:S and is not an * integer (has a decimal point) convert to hours by dividing by 15. * If dflag is specified, it is set to 1 if the value was divided by 15. */ HMS::HMS(const char* s, int hflag, int* dflag) : show_sign_(0) { if (!s) { val_ = sec_ = 0.; hours_ = min_ = 0; return; } double hours = 0; int min = 0; double sec = 0.0; double val = 0.0; int n = sscanf(s, "%lf%*[: ]%d%*[: ]%lf", &hours, &min, &sec); if (n >= 2) { // note: on HP, scanf on "-0.0" returns "0.0", on sun, "-0.0" if (hours == 0.0 && strchr(s, '-')) hours = -0.0; *this = HMS(hours, min, sec); } else if (n == 1) { if (sscanf(s, "%lf", &val) == 1) { if (hflag && strchr(s, '.')) { *this = HMS(val/15.); if (dflag) *dflag = 1; } else *this = HMS(val); } else { *this = HMS(hours, 0, 0); } } else { val_ = HMS_NULL; // error } }
//======================================================================================== // Create a new DataTime forward elapsed from given data //========================================================================================= DateTime YearWeekDayTimeComparer::DetermineForwardElapsed(const DateTime& dt, const PeriodData& pd) { PartialDateTime isoDt(dt, CalType::CalType_ISO); int year = isoDt.GetYear() + pd.elapsedYears; PartialDateTime pDt(year, 1, 1, CalType::CalType_ISO); FixedDateTime fwdDate = calmath::ExtractDate(pDt.GetFixed()) + (pd.elapsedWeeks * 7) + pd.elapsedDays - 1; //add time Time tm; fwdDate += (tm.ExtractTime(dt.GetFixed()) + tm.ConvertToFixed(HMS(pd.elapsedHours, pd.elapsedMinutes, pd.elapsedSeconds, pd.elapsedMilliseconds))); return DateTime(fwdDate); }
int main(int argc,char *argv[]) { ibam data; int show_minimal=1; int show_bios=0; int show_seconds_left_battery_bios=0; int show_seconds_left_battery=0; int show_seconds_left_battery_adaptive=0; int show_percent_battery_bios=0; int show_percent_battery=0; int show_seconds_left_charge=0; int show_seconds_left_charge_adaptive=0; int show_percent_charge=0; int show_seconds_battery_total=0; int show_seconds_battery_total_adaptive=0; int show_seconds_charge_total=0; int show_seconds_charge_total_adaptive=0; int show_profile_logging=0; int show_credits=0; int do_second_correction=0; int show_soft_low_limit=0; int show_hard_low_limit=0; int readonly = 0; string home(getenv("HOME")); if(home!="") home+="/"; while(1) { int option_index=0; static struct option long_options[] = { {"bios",0,0,'b'}, {"help",0,0,'h'}, {"batterybios",0,0,0}, {"battery",0,0,1}, {"batteryadaptive",0,0,2}, {"percentbios",0,0,3}, {"percentbattery",0,0,4}, {"charge",0,0,5}, {"chargeadaptive",0,0,6}, {"percentcharge",0,0,7}, {"totalbattery",0,0,8}, {"totalbatteryadaptive",0,0,9}, {"totalcharge",0,0,10}, {"totalchargeadaptive",0,0,11}, {"plot",optional_argument,0,12}, {"plotderivations",optional_argument,0,13}, {"import",0,0,14}, {"correctseconds",0,0,'c'}, {"seconds",0,0,'s'}, {"readonly",0,0,'r'}, {"all",0,0,'a'}, {"version",0,0,'v'}, {"profile",0,0,15}, {"noprofile",0,0,16}, {"credits",0,0,17}, {"softlowlimit",optional_argument,0,18}, {"hardlowlimit",optional_argument,0,19}, {0,0,0,0} }; int c=getopt_long(argc,argv,"avbhcsr",long_options,&option_index); if(c==-1) break; switch(c) { case 0: show_seconds_left_battery_bios=1; break; case 1: show_seconds_left_battery=1; break; case 2: show_seconds_left_battery_adaptive=1; break; case 3: show_percent_battery_bios=1; break; case 4: show_percent_battery=1; break; case 5: show_seconds_left_charge=1; break; case 6: show_seconds_left_charge_adaptive=1; break; case 7: show_percent_charge=1; break; case 8: show_seconds_battery_total=1; break; case 9: show_seconds_battery_total_adaptive=1; break; case 10: show_seconds_charge_total=1; break; case 11: show_seconds_charge_total_adaptive=1; break; case 12: { string command; command=string("echo \"plot \\\"") +home +string(".ibam/battery.rc\\\" using 1:2 title \\\"Battery\\\" with lines,\\\"") +home +string(".ibam/charge.rc\\\" using 1:2 title \\\"Charge\\\" with lines"); if (optarg) { int n=atoi(optarg); if(n>IBAM_MAXIMAL_PROFILES) n=IBAM_MAXIMAL_PROFILES; int p=data.current_profile_number(); for(; n>=0; n--) { string batname=data.profile_filename(p,1); string chrname=data.profile_filename(p,2); ifstream batteryprofile(batname.c_str()); if(!batteryprofile.fail()) { command+=", \\\""+batname+"\\\" using 1:2 notitle with lines 5"; } else { ifstream chargeprofile(chrname.c_str()); if(!chargeprofile.fail()) { command+=", \\\""+chrname+"\\\" using 1:2 notitle with lines 6"; } } p--; if(p<0) p+=IBAM_MAXIMAL_PROFILES; } } command+="\" | gnuplot -persist"; system(command.c_str()); } break; case 13: { string command; command=string("echo \"plot \\\"") +home +string(".ibam/battery.rc\\\" using 1:2 title \\\"Battery\\\" with lines 1, \\\"") +home +string(".ibam/battery.rc\\\" using 1:(\\$2+\\$3) notitle with lines 3, \\\"") +home +string(".ibam/battery.rc\\\" using 1:(\\$2-\\$3) notitle with lines 3,\\\"") +home +string(".ibam/charge.rc\\\" using 1:2 title \\\"Charge\\\" with lines 2, \\\"") +home +string(".ibam/charge.rc\\\" using 1:(\\$2+\\$3) notitle with lines 4, \\\"") +home +string(".ibam/charge.rc\\\" using 1:(\\$2-\\$3) notitle with lines 4"); if (optarg) { int n=atoi(optarg); if(n>IBAM_MAXIMAL_PROFILES) n=IBAM_MAXIMAL_PROFILES; int p=data.current_profile_number(); for(; n>=0; n--) { string batname=data.profile_filename(p,1); string chrname=data.profile_filename(p,2); ifstream batteryprofile(batname.c_str()); if(!batteryprofile.fail()) { command+=", \\\""+batname+"\\\" using 1:2 notitle with lines 5"; } else { ifstream chargeprofile(chrname.c_str()); if(!chargeprofile.fail()) { command+=", \\\""+chrname+"\\\" using 1:2 notitle with lines 6"; } } p--; if(p<0) p+=IBAM_MAXIMAL_PROFILES; } } command+="\" | gnuplot -persist"; system(command.c_str()); } break; case 14: data.import(); break; case 15: data.set_profile_logging(1); break; case 16: data.set_profile_logging(0); break; case 17: show_credits=1; break; case 'c': do_second_correction=1; break; case 'b': show_bios=1; break; case 's': no_HMS=1; break; case 'r': readonly=1; break; case 'a': show_soft_low_limit=show_hard_low_limit=show_profile_logging=show_seconds_left_battery_bios=show_seconds_left_battery=show_seconds_left_battery_adaptive=show_percent_battery_bios=show_percent_battery=show_seconds_left_charge=show_seconds_left_charge_adaptive=show_percent_charge=show_seconds_battery_total=show_seconds_battery_total_adaptive=show_seconds_charge_total=show_seconds_charge_total_adaptive=1; break; case 'v': cerr << "IBAM-" << IBAM_VERSION << " (C) 2001-2008 Sebastian Ritterbusch" << endl; break; case 'h': cout << "IBAM-" << IBAM_VERSION << ", the Intelligent Battery Monitor" << endl; cout << "(C) 2001-2008 Sebastian Ritterbusch" << endl << endl; cout << "Usage: ibam [options]" << endl; cout << endl; cout << "Options:" << endl; cout << " -h, --help displays this message" << endl; cout << " -v, --version displays software version" << endl; cout << " -b, --bios show bios apm guesses" << endl; cout << " -s, --seconds displays times in seconds" << endl; cout << " -c, --correctseconds displays changes in seconds" << endl; cout << " -r, --readonly no files will be updated" << endl; cout << " -a, --all show ALL information" << endl; cout << " --battery show battery time" << endl; cout << " --batteryadaptive show adaptive battery time" << endl; cout << " --batterybios show bios battery time guess" << endl; cout << " --percentbattery show battery percentage" << endl; cout << " --percentbios show bios percentage" << endl; cout << " --charge show charge time" << endl; cout << " --chargeadaptive show adaptive charge time" << endl; cout << " --percentcharge show charge percentage" << endl; cout << " --totalbattery show total battery time" << endl; cout << " --totalbatteryadaptive show adaptive total battery" << endl; cout << " --totalcharge show total charge time" << endl; cout << " --totalchargeadaptive show adaptive total charge" << endl; cout << " --hardlowlimit[=lim] show user defined hard lower percentage limit" << endl; cout << " [and set it to value <lim> or disable <0> it]" << endl; cout << " --softlowlimit[=lim] show automatic lower percentage limit" << endl; cout << " [and lower it to value <lim> or diable <0> it]" << endl; cout << " --plot[=profiles] use gnuplot to plot battery and charge graphs" << endl; cout << " and plot the last <profiles> additional profiles" << endl; cout << " --plotderivations[=profiles] same as above plus standard derivations" << endl; cout << " --import import V0.1 data from current directory" << endl; cout << " --profile enable additional yet unused profiling" << endl; cout << " --noprofile disable additional profiling" << endl; cout << " --credits to everyone contributing to ibam"<<endl; cout << endl; break; case 18: show_soft_low_limit=1; if (optarg) { int n=atoi(optarg); data.set_soft_low_limit(n); } break; case 19: show_hard_low_limit=1; if (optarg) { int n=atoi(optarg); data.set_hard_low_limit(n); } break; } }; if(!data.valid()) { cerr << "No apm data available." << endl; return 0; } if(!readonly) { data.update_statistics(); data.save(); } if(show_minimal) { if(data.onBattery()) show_seconds_left_battery_adaptive=show_seconds_left_battery=1; else if(data.charging()) show_seconds_left_charge=show_seconds_left_charge_adaptive=1; else show_seconds_charge_total=show_seconds_battery_total=1; } if(show_bios) { if(data.seconds_left_battery_bios()>=0) show_seconds_left_battery_bios=1; else show_percent_battery_bios=1; } if(show_percent_battery_bios) cout << "Bios percentage: " << data.percent_battery_bios() << " %" << endl; if(show_percent_battery) cout << "Battery percentage: " << data.percent_battery() << " %" << endl; if(show_soft_low_limit && data.get_soft_low_limit()>0) cout << "Soft low percentage limit: " << data.get_soft_low_limit() << " %" << endl; if(show_hard_low_limit && data.get_hard_low_limit()>0) cout << "Hard low percentage limit: " << data.get_hard_low_limit() << " %" << endl; if(show_percent_charge) cout << "Charge percentage: " << data.percent_charge() << " %" << endl; if(show_seconds_left_battery_bios && data.seconds_left_battery_bios()>=0) cout << "Bios time left: " << HMS(data.seconds_left_battery_bios()) << endl; if(show_seconds_left_battery && !do_second_correction) cout << "Battery time left: " << HMS(data.seconds_left_battery()) << endl; if(show_seconds_left_battery && do_second_correction) cout << "Battery time left: " << HMS(data.seconds_left_battery()+data.seconds_battery_correction()) << endl; if(show_seconds_left_battery_adaptive && !do_second_correction) cout << "Adapted battery time left: " << HMS(data.seconds_left_battery_adaptive()) << endl; if(show_seconds_left_battery_adaptive && do_second_correction) cout << "Adapted battery time left: " << HMS(data.seconds_left_battery_adaptive()+data.seconds_battery_correction_adaptive()) << endl; if(show_seconds_left_charge && !do_second_correction) cout << "Charge time left: " << HMS(data.seconds_left_charge()) << endl; if(show_seconds_left_charge && do_second_correction) cout << "Charge time left: " << HMS(data.seconds_left_charge()+data.seconds_charge_correction()) << endl; if(show_seconds_left_charge_adaptive && !do_second_correction) cout << "Adapted charge time left: " << HMS(data.seconds_left_charge_adaptive()) << endl; if(show_seconds_left_charge_adaptive && do_second_correction) cout << "Adapted charge time left: " << HMS(data.seconds_left_charge_adaptive()+data.seconds_charge_correction_adaptive()) << endl; if(show_seconds_battery_total) cout << "Total battery time: " << HMS(data.seconds_battery_total()) << endl; if(show_seconds_battery_total_adaptive) cout << "Adapted total battery time: " << HMS(data.seconds_battery_total_adaptive()) << endl; if(show_seconds_charge_total) cout << "Total charge time: " << HMS(data.seconds_charge_total()) << endl; if(show_seconds_charge_total_adaptive) cout << "Adapted total charge time: " << HMS(data.seconds_charge_total_adaptive()) << endl; if(show_profile_logging) { if(data.profile_logging_setting()) { cout << "Profile logging enabled." << endl; cout << "Current file: " << data.profile_filename( data.current_profile_number(), data.current_profile_type()) << endl; } else cout << "Profile logging disabled." << endl; } if(show_credits) { cout << endl; cout << "Special thanks go to:" << endl << endl; cout << "Mohanty Mitrabhanu for his scientific paper mentioning ibam"<< endl; cout << "Dan Egnor for his sweetcode article" << endl; cout << "Martin Wuertele for the debian port" << endl; cout << "Seth Golub for code improvements" << endl; cout << "Misha Nasledov for the gkrellm2-patch" << endl; cout << "Matthew Richardson for the gentoo support" << endl; cout << "Florian Ragwitz for the PMU support" << endl; cout << "Matthias Grimm for the extended PMU support and pbbuttons.berlios.de" << endl; cout << "Peter Gaal for testing and the APM bugfix" << endl; cout << "Brad Sawatzky for the same APM bugfix" << endl; } return 0; }