QTime modCalcSidTime::computeSTtoLT( QTime st ) { KStarsDateTime dt0 = KStarsDateTime( Date->date(), QTime(0,0,0)); dms lst; lst.setH( st.hour(), st.minute(), st.second() ); dms gst = geo->LSTtoGST( lst ); return geo->UTtoLT(KStarsDateTime(Date->date(), dt0.GSTtoUT(gst))).time(); }
void KSPlanetBase::findPosition( const KSNumbers *num, const dms *lat, const dms *LST, const KSPlanetBase *Earth ) { // DEBUG edit findGeocentricPosition( num, Earth ); //private function, reimplemented in each subclass findPhase(); setAngularSize( asin(physicalSize()/Rearth/AU_KM)*60.*180./dms::PI ); //angular size in arcmin if ( lat && LST ) localizeCoords( num, lat, LST ); //correct for figure-of-the-Earth if ( hasTrail() ) { addToTrail( KStarsDateTime( num->getJD() ).toString( "yyyy.MM.dd hh:mm" ) + i18nc("Universal time", "UT") ); // TODO: Localize date/time format? if ( Trail.size() > TrailObject::MaxTrail ) clipTrail(); } findMagnitude(num); if ( type() == SkyObject::COMET ) { // Compute tail size KSComet *me = (KSComet *)this; double TailAngSize; // Convert the tail size in km to angular tail size (degrees) TailAngSize = asin(physicalSize()/Rearth/AU_KM)*60.0*180.0/dms::PI; // Find the apparent length as projected on the celestial sphere (the comet's tail points away from the sun) me->setTailAngSize( TailAngSize * fabs(sin( phase().radians() ))); } }
KSComet::KSComet( KStarsData *_kd, QString _s, QString imfile, long double _JD, double _q, double _e, dms _i, dms _w, dms _Node, double Tp ) : KSPlanetBase(_kd, _s, imfile), kd(_kd), JD(_JD), q(_q), e(_e), i(_i), w(_w), N(_Node) { setType( 9 ); //Comet //Find the Julian Day of Perihelion from Tp //Tp is a double which encodes a date like: YYYYMMDD.DDDDD (e.g., 19730521.33333 int year = int( Tp/10000.0 ); int month = int( (int(Tp) % 10000)/100.0 ); int day = int( int(Tp) % 100 ); double Hour = 24.0 * ( Tp - int(Tp) ); int h = int( Hour ); int m = int( 60.0 * ( Hour - h ) ); int s = int( 60.0 * ( 60.0 * ( Hour - h) - m ) ); JDp = KStarsDateTime( ExtDate( year, month, day ), QTime( h, m, s ) ).djd(); //compute the semi-major axis, a: a = q/(1.0-e); //Compute the orbital Period from Kepler's 3rd law: P = 365.2568984 * pow(a, 1.5); //period in days //If the name contains a "/", make this name2 and make name a truncated version without the leading "P/" or "C/" if ( name().contains( "/" ) ) { setLongName( name() ); setName( name().mid( name().find("/") + 1 ) ); } }
void modCalcJD::slotUpdateModJD() { long double julianDay, modjulianDay; modjulianDay = ModJDBox->text().toDouble(); julianDay = MJD0 + modjulianDay; showJd( julianDay ); DateTimeBox->setDateTime( KStarsDateTime( julianDay )); }
void modCalcJD::slotUpdateModJD() { long double julianDay, modjulianDay; modjulianDay = KGlobal::locale()->readNumber( ModJDBox->text() ); julianDay = MJD0 + modjulianDay; showJd( julianDay ); DateTimeBox->setDateTime( KStarsDateTime( julianDay ).dateTime() ); }
void modCalcJD::slotUpdateCalendar() { long double julianDay, modjulianDay; julianDay = KStarsDateTime(DateTimeBox->dateTime()).djd(); showJd( julianDay ); modjulianDay = julianDay - MJD0; showMjd(modjulianDay); }
void SkyObjItem::setPosition(SkyObject* so) { KStarsData *data = KStarsData::Instance(); KStarsDateTime ut = data->geo()->LTtoUT(KStarsDateTime(KDateTime::currentLocalDateTime())); SkyPoint sp = so->recomputeCoords(ut, data->geo()); //check altitude of object at this time. sp.EquatorialToHorizontal(data->lst(), data->geo()->lat()); double rounded_altitude = (int)(sp.alt().Degrees()/5.0)*5.0; m_Position = i18n("Now visible: About %1 degrees above the %2 horizon", rounded_altitude, KSUtils::toDirectionString( sp.az() ) ); }
QTime SkyObject::riseSetTime( const KStarsDateTime &dt, const GeoLocation *geo, bool rst ) { //this object does not rise or set; return an invalid time if ( checkCircumpolar(geo->lat()) ) return QTime( 25, 0, 0 ); //First of all, if the object is below the horizon at date/time dt, adjust the time //to bring it above the horizon KStarsDateTime dt2 = dt; SkyPoint p = recomputeCoords( dt, geo ); p.EquatorialToHorizontal( &(geo->GSTtoLST( dt.gst() )), geo->lat() ); if ( p.alt()->Degrees() < 0.0 ) { if ( p.az()->Degrees() < 180.0 ) { //object has not risen yet dt2 = dt.addSecs( 12.*3600. ); } else { //object has already set dt2 = dt.addSecs( -12.*3600. ); } } return geo->UTtoLT( KStarsDateTime( dt2.date(), riseSetTimeUT( dt2, geo, rst ) ) ).time(); }
KStarsDateTime KStarsDateTime::fromString( const QString &s ) { //DEBUG qDebug() << "Date string: " << s; KStarsDateTime dtResult = QDateTime::fromString( s, Qt::TextDate ); if ( dtResult.isValid() ) return dtResult; dtResult = QDateTime::fromString( s, Qt::ISODate ); if ( dtResult.isValid() ) return dtResult; //dtResult = QDateTime::fromString( s, QDateTime::RFCDate ); dtResult = QDateTime::fromString( s, Qt::RFC2822Date ); if ( dtResult.isValid() ) return dtResult; qWarning() << i18n( "Could not parse Date/Time string: " ) << s ; qWarning() << i18n( "Valid date formats: " ) ; qWarning() << " 1950-02-25 ; 1950-02-25T05:30:00" ; qWarning() << " 25 Feb 1950 ; 25 Feb 1950 05:30:00" ; qWarning() << " Sat Feb 25 1950 ; Sat Feb 25 05:30:00 1950"; return KStarsDateTime( QDateTime() ); //invalid }
void MoonPhaseCalendar::paintCell( QPainter *painter, int row, int col, const KColorScheme &colorScheme ) { double w = cellWidth - 1; double h = cellHeight - 1; QRectF cell = QRectF( 0, 0, w, h ); QString cellText; QPen pen; QColor cellBackgroundColor, cellTextColor; QFont cellFont = KGlobalSettings::generalFont(); bool workingDay = false; int cellWeekDay, pos; //Calculate the position of the cell in the grid pos = numDayColumns * ( row - 1 ) + col; //Calculate what day of the week the cell is cellWeekDay = col + calendar()->weekStartDay(); if ( cellWeekDay > numDayColumns ) { cellWeekDay -= numDayColumns; } //See if cell day is normally a working day if ( KGlobal::locale()->workingWeekStartDay() <= KGlobal::locale()->workingWeekEndDay() ) { workingDay = cellWeekDay >= KGlobal::locale()->workingWeekStartDay() && cellWeekDay <= KGlobal::locale()->workingWeekEndDay(); } else { workingDay = cellWeekDay >= KGlobal::locale()->workingWeekStartDay() || cellWeekDay <= KGlobal::locale()->workingWeekEndDay(); } if( row == 0 ) { //We are drawing a header cell //If not a normal working day, then use "do not work today" color if ( workingDay ) { cellTextColor = palette().color(QPalette::WindowText); } else { KColorScheme colorScheme(palette().currentColorGroup(), KColorScheme::Window); cellTextColor = colorScheme.foreground(KColorScheme::NegativeText).color(); } cellBackgroundColor = palette().color(QPalette::Window); //Set the text to the short day name and bold it cellFont.setBold( true ); cellText = calendar()->weekDayName( cellWeekDay, KCalendarSystem::ShortDayName ); } else { //We are drawing a day cell //Calculate the date the cell represents QDate cellDate = dateFromPos( pos ); bool validDay = calendar()->isValid( cellDate ); // Draw the day number in the cell, if the date is not valid then we don't want to show it if ( validDay ) { cellText = calendar()->dayString( cellDate, KCalendarSystem::ShortFormat ); } else { cellText = ""; } if( ! validDay || calendar()->month( cellDate ) != calendar()->month( date() ) ) { // we are either // ° painting an invalid day // ° painting a day of the previous month or // ° painting a day of the following month or cellBackgroundColor = palette().color(backgroundRole()); cellTextColor = colorScheme.foreground(KColorScheme::InactiveText).color(); } else { //Paint a day of the current month // Background Colour priorities will be (high-to-low): // * Selected Day Background Colour // * Customized Day Background Colour // * Normal Day Background Colour // Background Shape priorities will be (high-to-low): // * Customized Day Shape // * Normal Day Shape // Text Colour priorities will be (high-to-low): // * Customized Day Colour // * Day of Pray Colour (Red letter) // * Selected Day Colour // * Normal Day Colour //Determine various characteristics of the cell date bool selectedDay = ( cellDate == date() ); bool currentDay = ( cellDate == QDate::currentDate() ); bool dayOfPray = ( calendar()->dayOfWeek( cellDate ) == KGlobal::locale()->weekDayOfPray() ); //Default values for a normal cell cellBackgroundColor = palette().color( backgroundRole() ); cellTextColor = palette().color( foregroundRole() ); // If we are drawing the current date, then draw it bold and active if ( currentDay ) { cellFont.setBold( true ); cellTextColor = colorScheme.foreground(KColorScheme::ActiveText).color(); } // if we are drawing the day cell currently selected in the table if ( selectedDay ) { // set the background to highlighted cellBackgroundColor = palette().color( QPalette::Highlight ); cellTextColor = palette().color( QPalette::HighlightedText ); } //If the cell day is the day of religious observance, then always color text red unless Custom overrides if ( dayOfPray ) { KColorScheme colorScheme(palette().currentColorGroup(), selectedDay ? KColorScheme::Selection : KColorScheme::View); cellTextColor = colorScheme.foreground(KColorScheme::NegativeText).color(); } } } //Draw the background if (row == 0) { painter->setPen( cellBackgroundColor ); painter->setBrush( cellBackgroundColor ); painter->drawRect( cell ); } else if (cellBackgroundColor != palette().color(backgroundRole())) { QStyleOptionViewItemV4 opt; opt.initFrom(this); opt.rect = cell.toRect(); if (cellBackgroundColor != palette().color(backgroundRole())) { opt.palette.setBrush(QPalette::Highlight, cellBackgroundColor); opt.state |= QStyle::State_Selected; } if (false && opt.state & QStyle::State_Enabled) { opt.state |= QStyle::State_MouseOver; } else { opt.state &= ~QStyle::State_MouseOver; } opt.showDecorationSelected = true; opt.viewItemPosition = QStyleOptionViewItemV4::OnlyOne; style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, this); } if( row != 0 ) { // Paint the moon phase QDate cellDate = dateFromPos( pos ); if( calendar()->isValid( cellDate ) ) { int iPhase = computeMoonPhase( KStarsDateTime( cellDate, QTime(0, 0, 0) ) ); QRect drawRect = cell.toRect(); painter->drawPixmap( ( drawRect.width() - MoonImageSize )/2, 12 + (( drawRect.height() - 12 ) - MoonImageSize)/2, m_Images[ iPhase ] ); // FIXME: Using hard coded fon // + painter // painter->drawPixmap( ( drawRect.width() - MoonImageSize )/2, // 12 + (( drawRect.height() - 12 ) - MoonImageSize)/2, // m_Images[ iPhase ] ); // FIXME: Using hard coded fontsize // kDebug() << "Drew moon image " << iPhase; } } //Draw the text painter->setPen( cellTextColor ); painter->setFont( cellFont ); painter->drawText( cell, (row == 0) ? Qt::AlignCenter : (Qt::AlignTop | Qt::AlignHCenter), cellText, &cell ); //Draw the base line if (row == 0) { painter->setPen( palette().color(foregroundRole()) ); painter->drawLine( QPointF( 0, h ), QPointF( w, h ) ); } // If the day cell we just drew is bigger than the current max cell sizes, // then adjust the max to the current cell /* if ( cell.width() > d->maxCell.width() ) d->maxCell.setWidth( cell.width() ); if ( cell.height() > d->maxCell.height() ) d->maxCell.setHeight( cell.height() ); */ }
QTime SkyObject::transitTime( const KStarsDateTime &dt, const GeoLocation *geo ) { return geo->UTtoLT( KStarsDateTime( dt.date(), transitTimeUT( dt, geo ) ) ).time(); }
void modCalcVlsr::processLines( QTextStream &istream ) { // we open the output file // QTextStream istream(&fIn); QString outputFileName; outputFileName = OutputFileBoxBatch->url().toLocalFile(); QFile fOut( outputFileName ); fOut.open(QIODevice::WriteOnly); QTextStream ostream(&fOut); QString line; QChar space = ' '; int i = 0; long double jd0; SkyPoint spB; double sra, cra, sdc, cdc; dms raB, decB, latB, longB; QString epoch0B; double vhB, vgB, vtB, vlsrB, heightB; double vtopo[3]; QTime utB; QDate dtB; KStarsDateTime dt0B; while ( ! istream.atEnd() ) { line = istream.readLine(); line.trimmed(); //Go through the line, looking for parameters QStringList fields = line.split( ' ' ); i = 0; // Read Ut and write in ostream if corresponds if(UTCheckBatch->isChecked() ) { utB = QTime::fromString( fields[i] ); i++; } else utB = UTBoxBatch->time(); if ( AllRadioBatch->isChecked() ) ostream << KGlobal::locale()->formatTime( utB ) << space; else if(UTCheckBatch->isChecked() ) ostream << KGlobal::locale()->formatTime( utB ) << space; // Read date and write in ostream if corresponds if(DateCheckBatch->isChecked() ) { dtB = QDate::fromString( fields[i] ); i++; } else dtB = DateBoxBatch->date(); if ( AllRadioBatch->isChecked() ) ostream << KGlobal::locale()->formatDate( dtB, KLocale::LongDate ).append(space); else if(DateCheckBatch->isChecked() ) ostream << KGlobal::locale()->formatDate( dtB, KLocale::LongDate ).append(space); // Read RA and write in ostream if corresponds if(RACheckBatch->isChecked() ) { raB = dms::fromString( fields[i],false); i++; } else raB = RABoxBatch->createDms(false); if ( AllRadioBatch->isChecked() ) ostream << raB.toHMSString() << space; else if(RACheckBatch->isChecked() ) ostream << raB.toHMSString() << space; // Read DEC and write in ostream if corresponds if(DecCheckBatch->isChecked() ) { decB = dms::fromString( fields[i], true); i++; } else decB = DecBoxBatch->createDms(); if ( AllRadioBatch->isChecked() ) ostream << decB.toDMSString() << space; else if(DecCheckBatch->isChecked() ) ostream << decB.toDMSString() << space; // Read Epoch and write in ostream if corresponds if(EpochCheckBatch->isChecked() ) { epoch0B = fields[i]; i++; } else epoch0B = EpochBoxBatch->text(); if ( AllRadioBatch->isChecked() ) ostream << epoch0B << space; else if(EpochCheckBatch->isChecked() ) ostream << epoch0B << space; // Read vlsr and write in ostream if corresponds if(InputVelocityCheckBatch->isChecked() ) { vlsrB = fields[i].toDouble(); i++; } else vlsrB = InputVelocityComboBatch->currentText().toDouble(); if ( AllRadioBatch->isChecked() ) ostream << vlsrB << space; else if(InputVelocityCheckBatch->isChecked() ) ostream << vlsrB << space; // Read Longitude and write in ostream if corresponds if (LongCheckBatch->isChecked() ) { longB = dms::fromString( fields[i],true); i++; } else longB = LongitudeBoxBatch->createDms(true); if ( AllRadioBatch->isChecked() ) ostream << longB.toDMSString() << space; else if (LongCheckBatch->isChecked() ) ostream << longB.toDMSString() << space; // Read Latitude if (LatCheckBatch->isChecked() ) { latB = dms::fromString( fields[i], true); i++; } else latB = LatitudeBoxBatch->createDms(true); if ( AllRadioBatch->isChecked() ) ostream << latB.toDMSString() << space; else if (LatCheckBatch->isChecked() ) ostream << latB.toDMSString() << space; // Read height and write in ostream if corresponds if(ElevationCheckBatch->isChecked() ) { heightB = fields[i].toDouble(); i++; } else heightB = ElevationBoxBatch->text().toDouble(); if ( AllRadioBatch->isChecked() ) ostream << heightB << space; else if(ElevationCheckBatch->isChecked() ) ostream << heightB << space; // We make the first calculations spB = SkyPoint (raB, decB); dt0B.setFromEpoch(epoch0B); vhB = spB.vHeliocentric(vlsrB, dt0B.djd()); jd0 = KStarsDateTime(dtB,utB).djd(); vgB = spB.vGeocentric(vlsrB, jd0); geoPlace->setLong( longB ); geoPlace->setLat( latB ); geoPlace->setHeight( heightB ); dms gsidt = KStarsDateTime(dtB,utB).gst(); geoPlace->TopocentricVelocity(vtopo, gsidt); spB.ra().SinCos(sra, cra); spB.dec().SinCos(sdc, cdc); vtB = vgB - (vtopo[0]*cdc*cra + vtopo[1]*cdc*sra + vtopo[2]*sdc); ostream << vhB << space << vgB << space << vtB << endl; } fOut.close(); }
KStarsDateTime modCalcEquinox::findSolstice( int year, bool Summer ) { //Find the moment when the Sun reaches maximum declination //First find three points which bracket the maximum (i.e., x2 > x1,x3) //Start at June 16th, which will always be approaching the solstice long double jd1,jd2,jd3,jd4; double y2(0.0),y3(0.0), y4(0.0); int month = 6; if ( ! Summer ) month = 12; jd3 = KStarsDateTime( QDate( year, month, 16 ), QTime(0,0,0) ).djd(); KSNumbers num( jd3 ); KSSun Sun; Sun.findPosition( &num ); y3 = Sun.dec().Degrees(); int sgn = 1; if ( ! Summer ) sgn = -1; //find minimum if the winter solstice is sought do { jd3 += 1.0; num.updateValues( jd3 ); Sun.findPosition( &num ); y2 = y3; Sun.findPosition( &num ); y3 = Sun.dec().Degrees(); } while ( y3*sgn > y2*sgn ); //Ok, now y2 is larger(smaller) than both y3 and y1. jd2 = jd3 - 1.0; jd1 = jd3 - 2.0; //Choose a new starting jd2 that follows the golden ratio: // a/b = 1.618; a+b = 2...a = 0.76394 jd2 = jd1 + 0.76394; num.updateValues( jd2 ); Sun.findPosition( &num ); y2 = Sun.dec().Degrees(); while ( jd3 - jd1 > 0.0005 ) { //sub-minute pecision jd4 = jd1 + jd3 - jd2; num.updateValues( jd4 ); Sun.findPosition( &num ); y4 = Sun.dec().Degrees(); if ( y4*sgn > y2*sgn ) { //make jd4 the new center if ( jd4 > jd2 ) { jd1 = jd2; jd2 = jd4; y2 = y4; } else { jd3 = jd2; y3 = y2; jd2 = jd4; y2 = y4; } } else { //make jd4 a new endpoint if ( jd4 > jd2 ) { jd3 = jd4; y3 = y4; } else { jd1 = jd4; } } } return KStarsDateTime( jd2 ); }
void KStars::setLocalTime(int yr, int mth, int day, int hr, int min, int sec) { data()->changeDateTime( data()->geo()->LTtoUT( KStarsDateTime( QDate(yr, mth, day), QTime(hr,min,sec) ) ) ); }
void modCalcAltAz::slotDateTimeChanged(const QDateTime &dt) { KStarsDateTime ut = geoPlace->LTtoUT( KStarsDateTime( dt ) ); LST = geoPlace->GSTtoLST( ut.gst() ); }
KStarsDateTime modCalcAzel::getDateTime (void) { return KStarsDateTime( datBox->date() , timBox->time() ); }
void modCalcDayLength::updateAlmanac( const QDate &d, GeoLocation *geo ) { //Determine values needed for the Almanac long double jd0 = KStarsDateTime(d, QTime(8,0,0)).djd(); KSNumbers num(jd0); //Sun KSSun Sun; Sun.findPosition(&num); QTime ssTime = Sun.riseSetTime(jd0 , geo, false ); QTime srTime = Sun.riseSetTime(jd0 , geo, true ); QTime stTime = Sun.transitTime(jd0 , geo); dms ssAz = Sun.riseSetTimeAz(jd0, geo, false); dms srAz = Sun.riseSetTimeAz(jd0, geo, true); dms stAlt = Sun.transitAltitude(jd0, geo); //In most cases, the Sun will rise and set: if ( ssTime.isValid() ) { ssAzString = ssAz.toDMSString(); stAltString = stAlt.toDMSString(); srAzString = srAz.toDMSString(); ssTimeString = QLocale().toString( ssTime ); srTimeString = QLocale().toString( srTime ); stTimeString = QLocale().toString( stTime ); QTime daylength = lengthOfDay(ssTime,srTime); daylengthString = QLocale().toString( daylength); //...but not always! } else if ( stAlt.Degrees() > 0. ) { ssAzString = i18n("Circumpolar"); stAltString = stAlt.toDMSString(); srAzString = i18n("Circumpolar"); ssTimeString = "--:--"; srTimeString = "--:--"; stTimeString = QLocale().toString( stTime ); daylengthString = "24:00"; } else if (stAlt.Degrees() < 0. ) { ssAzString = i18n("Does not rise"); stAltString = stAlt.toDMSString(); srAzString = i18n("Does not set"); ssTimeString = "--:--"; srTimeString = "--:--"; stTimeString = QLocale().toString( stTime ); daylengthString = "00:00"; } //Moon KSMoon Moon; QTime msTime = Moon.riseSetTime( jd0 , geo, false ); QTime mrTime = Moon.riseSetTime( jd0 , geo, true ); QTime mtTime = Moon.transitTime(jd0 , geo); dms msAz = Moon.riseSetTimeAz(jd0, geo, false); dms mrAz = Moon.riseSetTimeAz(jd0, geo, true); dms mtAlt = Moon.transitAltitude(jd0, geo); //In most cases, the Moon will rise and set: if ( msTime.isValid() ) { msAzString = msAz.toDMSString(); mtAltString = mtAlt.toDMSString(); mrAzString = mrAz.toDMSString(); msTimeString = QLocale().toString( msTime ); mrTimeString = QLocale().toString( mrTime ); mtTimeString = QLocale().toString( mtTime ); //...but not always! } else if ( mtAlt.Degrees() > 0. ) { msAzString = i18n("Circumpolar"); mtAltString = mtAlt.toDMSString(); mrAzString = i18n("Circumpolar"); msTimeString = "--:--"; mrTimeString = "--:--"; mtTimeString = QLocale().toString( mtTime ); } else if ( mtAlt.Degrees() < 0. ) { msAzString = i18n("Does not rise"); mtAltString = mtAlt.toDMSString(); mrAzString = i18n("Does not rise"); msTimeString = "--:--"; mrTimeString = "--:--"; mtTimeString = QLocale().toString( mtTime ); } //after calling riseSetTime Phase needs to reset, setting it before causes Phase to set nan Moon.findPosition(&num); Moon.findPhase(0); lunarphaseString = Moon.phaseName()+" ("+QString::number( int( 100*Moon.illum() ) )+"%)"; //Fix length of Az strings if ( srAz.Degrees() < 100.0 ) srAzString = ' '+srAzString; if ( ssAz.Degrees() < 100.0 ) ssAzString = ' '+ssAzString; if ( mrAz.Degrees() < 100.0 ) mrAzString = ' '+mrAzString; if ( msAz.Degrees() < 100.0 ) msAzString = ' '+msAzString; }
void modCalcJD::processLines( QTextStream &istream, int inputData ) { QFile fOut( OutputFileBatch->url().toLocalFile() ); fOut.open(QIODevice::WriteOnly); QTextStream ostream(&fOut); QString line; long double jd(0); double mjd(0); KStarsDateTime dt; while ( ! istream.atEnd() ) { line = istream.readLine(); line = line.trimmed(); QStringList data = line.split( ' ', QString::SkipEmptyParts ); if ( inputData == 0 ) { //Parse date & time //Is the first field parseable as a date or date&time? if ( data[0].length() > 10 ) dt = KStarsDateTime::fromString( data[0] ); else dt = KStarsDateTime( QDate::fromString( data[0] ), QTime(0,0,0) ); //DEBUG kDebug() << data[0]; if ( dt.isValid() ) kDebug() << dt.toString(); if ( dt.isValid() ) { //Try to parse the second field as a time if ( data.size() > 1 ) { QString s = data[1]; if ( s.length() == 4 ) s = '0'+s; QTime t = QTime::fromString( s ); if ( t.isValid() ) dt.setTime( t ); } } else { //Did not parse the first field as a date; try it as a time QTime t = QTime::fromString( data[0] ); if ( t.isValid() ) { dt.setTime( t ); //Now try the second field as a date if ( data.size() > 1 ) { QDate d = QDate::fromString( data[1] ); if ( d.isValid() ) dt.setDate( d ); else dt.setDate( QDate::currentDate() ); } } } if ( dt.isValid() ) { //Compute JD and MJD jd = dt.djd(); mjd = jd - MJD0; } } else if ( inputData == 1 ) {//Parse Julian day bool ok(false); jd = data[0].toDouble(&ok); if ( ok ) { dt.setDJD( jd ); mjd = jd - MJD0; } } else if ( inputData == 2 ) {//Parse Modified Julian day bool ok(false); mjd = data[0].toDouble(&ok); if ( ok ) { jd = mjd + MJD0; dt.setDJD( jd ); } } //Write to output file ostream << KGlobal::locale()->formatDateTime( dt, KLocale::LongDate ) << " " << QString::number( jd, 'f', 2 ) << " " << QString::number( mjd, 'f', 2 ) << endl; } fOut.close(); }
KStarsDateTime modCalcDayLength::getDateTime (void) { return KStarsDateTime( datBox->date() , QTime(8,0,0) ); }
void modCalcAzel::processLines( QTextStream &istream ) { // we open the output file // QTextStream istream(&fIn); QString outputFileName; outputFileName = OutputLineEditBatch->text(); QFile fOut( outputFileName ); fOut.open(IO_WriteOnly); QTextStream ostream(&fOut); QString line; QString space = " "; int i = 0; long double jd0, jdf; dms LST; SkyPoint sp; dms raB, decB, latB, longB, azB, elB; double epoch0B; QTime utB; ExtDate dtB; while ( ! istream.eof() ) { line = istream.readLine(); line.stripWhiteSpace(); //Go through the line, looking for parameters QStringList fields = QStringList::split( " ", line ); i = 0; // Read Ut and write in ostream if corresponds if(utCheckBatch->isChecked() ) { utB = QTime::fromString( fields[i] ); i++; } else utB = utBoxBatch->time(); if ( allRadioBatch->isChecked() ) ostream << utB.toString() << space; else if(utCheckBatch->isChecked() ) ostream << utB.toString() << space; // Read date and write in ostream if corresponds if(dateCheckBatch->isChecked() ) { dtB = ExtDate::fromString( fields[i] ); i++; } else dtB = dateBoxBatch->date(); if ( allRadioBatch->isChecked() ) ostream << dtB.toString().append(space); else if(dateCheckBatch->isChecked() ) ostream << dtB.toString().append(space); // Read Longitude and write in ostream if corresponds if (longCheckBatch->isChecked() ) { longB = dms::fromString( fields[i],TRUE); i++; } else longB = longBoxBatch->createDms(TRUE); if ( allRadioBatch->isChecked() ) ostream << longB.toDMSString() << space; else if (longCheckBatch->isChecked() ) ostream << longB.toDMSString() << space; // Read Latitude if (latCheckBatch->isChecked() ) { latB = dms::fromString( fields[i], TRUE); i++; } else latB = latBoxBatch->createDms(TRUE); if ( allRadioBatch->isChecked() ) ostream << latB.toDMSString() << space; else if (latCheckBatch->isChecked() ) ostream << latB.toDMSString() << space; // Read Epoch and write in ostream if corresponds if(epochCheckBatch->isChecked() ) { epoch0B = fields[i].toDouble(); i++; } else epoch0B = getEpoch( epochBoxBatch->text() ); if ( allRadioBatch->isChecked() ) ostream << epoch0B << space; else if(epochCheckBatch->isChecked() ) ostream << epoch0B << space; // We make the first calculations KStarsDateTime dt; dt.setFromEpoch( epoch0B ); jdf = KStarsDateTime(dtB,utB).djd(); jd0 = dt.djd(); LST = KStarsDateTime(dtB,utB).gst().Degrees() + longB.Degrees(); // Equatorial coordinates are the input coords. if (!horInputCoords) { // Read RA and write in ostream if corresponds if(raCheckBatch->isChecked() ) { raB = dms::fromString( fields[i],FALSE); i++; } else raB = raBoxBatch->createDms(FALSE); if ( allRadioBatch->isChecked() ) ostream << raB.toHMSString() << space; else if(raCheckBatch->isChecked() ) ostream << raB.toHMSString() << space; // Read DEC and write in ostream if corresponds if(decCheckBatch->isChecked() ) { decB = dms::fromString( fields[i], TRUE); i++; } else decB = decBoxBatch->createDms(); if ( allRadioBatch->isChecked() ) ostream << decB.toDMSString() << space; else if(decCheckBatch->isChecked() ) ostream << decB.toDMSString() << space; sp = SkyPoint (raB, decB); sp.apparentCoord(jd0, jdf); sp.EquatorialToHorizontal( &LST, &latB ); ostream << sp.az()->toDMSString() << space << sp.alt()->toDMSString() << endl; // Input coords are horizontal coordinates } else { if(azCheckBatch->isChecked() ) { azB = dms::fromString( fields[i],FALSE); i++; } else azB = azBoxBatch->createDms(); if ( allRadioBatch->isChecked() ) ostream << azB.toHMSString() << space; else if(raCheckBatch->isChecked() ) ostream << azB.toHMSString() << space; // Read DEC and write in ostream if corresponds if(elCheckBatch->isChecked() ) { elB = dms::fromString( fields[i], TRUE); i++; } else elB = decBoxBatch->createDms(); if ( allRadioBatch->isChecked() ) ostream << elB.toDMSString() << space; else if(elCheckBatch->isChecked() ) ostream << elB.toDMSString() << space; sp.setAz(azB); sp.setAlt(elB); sp.HorizontalToEquatorial( &LST, &latB ); ostream << sp.ra()->toHMSString() << space << sp.dec()->toDMSString() << endl; } } fOut.close(); }
QTime modCalcSidTime::computeLTtoST( QTime lt ) { KStarsDateTime utdt = geo->LTtoUT( KStarsDateTime( Date->date(), lt ) ); dms st = geo->GSTtoLST( utdt.gst() ); return QTime( st.hour(), st.minute(), st.second() ); }