• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

modcalcvlsr.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           modcalcvlsr.cpp  -  description
00003                              -------------------
00004     begin                : sun mar 13 2005
00005     copyright            : (C) 2005 by Pablo de Vicente
00006     email                : p.devicente@wanadoo.es
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "modcalcvlsr.h"
00019 
00020 #include "modcalcvlsr.moc"
00021 #include "ksnumbers.h"
00022 #include "dms.h"
00023 #include "dmsbox.h"
00024 #include "skypoint.h"
00025 #include "geolocation.h"
00026 #include "kstars.h"
00027 #include "kstarsdata.h"
00028 #include "kstarsdatetime.h"
00029 #include "libkdeedu/extdate/extdatetimeedit.h"
00030 
00031 #include <qdatetimeedit.h>  //need for QTimeEdit
00032 #include <qcheckbox.h>
00033 #include <qradiobutton.h>
00034 #include <qstring.h>
00035 #include <qtextstream.h>
00036 #include <kfiledialog.h>
00037 #include <kmessagebox.h>
00038 
00039 
00040 modCalcVlsr::modCalcVlsr(QWidget *parentSplit, const char *name) : modCalcVlsrDlg (parentSplit,name) {
00041 
00042     showCurrentDateTime();
00043     initGeo();
00044     showLongLat();
00045     raBox->setDegType(FALSE);
00046     show();
00047 }
00048 
00049 modCalcVlsr::~modCalcVlsr(){
00050     delete geoPlace;
00051 }
00052 
00053 SkyPoint modCalcVlsr::getEquCoords (void)
00054 {
00055     dms raCoord, decCoord;
00056 
00057     raCoord = raBox->createDms(FALSE);
00058     decCoord = decBox->createDms();
00059 
00060     SkyPoint sp = SkyPoint (raCoord, decCoord);
00061 
00062     return sp;
00063 }
00064 
00065 double modCalcVlsr::getVLSR (void)
00066 {
00067     double vlsr = vlsrBox->text().toDouble();
00068     return vlsr;
00069 }
00070 
00071 double modCalcVlsr::getVhel (void)
00072 {
00073     double vh = vHelioBox->text().toDouble();
00074     return vh;
00075 }
00076 
00077 double modCalcVlsr::getVgeo (void)
00078 {
00079     double vg = vGeoBox->text().toDouble();
00080     return vg;
00081 }
00082 
00083 double modCalcVlsr::getVtopo (void)
00084 {
00085     double vt = vTopoBox->text().toDouble();
00086     return vt;
00087 }
00088 
00089 
00090 KStarsDateTime modCalcVlsr::getDateTime (void)
00091 {
00092     return KStarsDateTime( datBox->date() , timBox->time() );
00093 }
00094 
00095 double modCalcVlsr::getEpoch (QString eName)
00096 {
00097     bool ok = false;
00098     double epoch = eName.toDouble(&ok);
00099     if ( ok )
00100         return epoch;
00101     else {
00102         kdDebug() << i18n( "Could not parse epoch string; assuming J2000" ) << endl;
00103         return 2000.0;
00104     }
00105 }
00106 
00107 dms modCalcVlsr::getLongitude(void)
00108 {
00109     dms longitude;
00110     longitude = longBox->createDms();
00111     return longitude;
00112 }
00113 
00114 dms modCalcVlsr::getLatitude(void)
00115 {
00116     dms latitude;
00117     latitude = latBox->createDms();
00118     return latitude;
00119 }
00120 
00121 double modCalcVlsr::getHeight(void)
00122 {
00123     bool ok = false;
00124     double height = heightBox->text().toDouble(&ok);
00125     if (ok) 
00126         return height;
00127     else {
00128         kdDebug() << i18n( "Could not parse height string; assuming 0" ) << endl;
00129         return 0.0;
00130     }
00131 
00132 }
00133 
00134 void modCalcVlsr::getGeoLocation (void)
00135 {
00136     geoPlace->setLong( getLongitude() );
00137     geoPlace->setLat(  getLatitude() );
00138     geoPlace->setHeight( getHeight() );
00139 
00140 }
00141 
00142 void modCalcVlsr::showCurrentDateTime (void)
00143 {
00144     KStars *ks = (KStars*) parent()->parent()->parent();
00145 
00146     KStarsDateTime dt = ks->data()->geo()->LTtoUT( KStarsDateTime::currentDateTime() );
00147 
00148     datBox->setDate( dt.date() );
00149     timBox->setTime( dt.time() );
00150     dateBoxBatch->setDate( dt.date() );
00151     utBoxBatch->setTime( dt.time() );
00152 }
00153 
00154 // SIRVE para algo?
00155 void modCalcVlsr::initGeo(void)
00156 {
00157     KStars *ks = (KStars*) parent()->parent()->parent(); // QSplitter->AstroCalc->KStars
00158     geoPlace = new GeoLocation( ks->geo() );
00159 }
00160 
00161 
00162 
00163 void modCalcVlsr::showLongLat(void)
00164 {
00165 
00166     KStars *ks = (KStars*) parent()->parent()->parent(); // QSplitter->AstroCalc->KStars
00167     longBox->show( ks->geo()->lng() );
00168     latBox->show( ks->geo()->lat() );
00169     longBoxBatch->show( ks->geo()->lng() );
00170     latBoxBatch->show( ks->geo()->lat() );
00171 }
00172 
00173 void modCalcVlsr::showVlsr (const double vlsr )
00174 {
00175     vlsrBox->setText( KGlobal::locale()->formatNumber( vlsr ) );
00176 }
00177 
00178 void modCalcVlsr::showHelVel (const double vhel )
00179 {
00180     vHelioBox->setText( KGlobal::locale()->formatNumber( vhel ) );
00181 }
00182 
00183 void modCalcVlsr::showGeoVel (const double vgeo )
00184 {
00185     vGeoBox->setText( KGlobal::locale()->formatNumber( vgeo ) );
00186 }
00187 
00188 void modCalcVlsr::showTopoVel (const double vtop )
00189 {
00190     vTopoBox->setText( KGlobal::locale()->formatNumber( vtop ) );
00191 }
00192 
00193 void modCalcVlsr::showEpoch( const KStarsDateTime &dt )
00194 {
00195     double epochN = dt.epoch();
00196 //  Localization
00197 //  epochName->setText(KGlobal::locale()->formatNumber(epochN,3));
00198     epochName->setText( KGlobal::locale()->formatNumber( epochN ) );
00199     
00200 }
00201 
00202 void modCalcVlsr::slotClearCoords()
00203 {
00204 
00205     raBox->clearFields();
00206     decBox->clearFields();
00207     longBox->clearFields();
00208     latBox->clearFields();
00209     epochName->setText("");
00210     vlsrBox->setText("");
00211     vHelioBox->setText("");
00212     vGeoBox->setText("");
00213     vTopoBox->setText("");
00214 
00215     datBox->setDate(ExtDate::currentDate());
00216     timBox->setTime(QTime(0,0,0));
00217 
00218 }
00219 
00220 void modCalcVlsr::slotComputeVelocities()
00221 {
00222     SkyPoint sp = getEquCoords();
00223     getGeoLocation();
00224 
00225 
00226     double epoch0 = getEpoch( epochName->text() );
00227     KStarsDateTime dt0;
00228     dt0.setFromEpoch(epoch0);
00229     KStarsDateTime dt1 = getDateTime();
00230     double vst[3];
00231     dms gsidt = dt1.gst();
00232     geoPlace->TopocentricVelocity(vst, gsidt);
00233 
00234     if ( radioVlsr->isChecked() ) {
00235     
00236         double vlsr = getVLSR();
00237         double vhelio = sp.vHeliocentric(vlsr, dt0.djd() );
00238         showHelVel( vhelio );
00239 
00240         double vg = sp.vGeocentric(vhelio, dt1.djd());
00241         showGeoVel( vg );
00242 
00243         showTopoVel ( sp.vTopocentric(vg, vst) );
00244         
00245     } else if (radioVhelio->isChecked() ) {
00246         
00247         double vhel = getVhel();
00248         double vlsr = sp.vHelioToVlsr(vhel, dt0.djd() );
00249         showVlsr(vlsr);
00250 
00251         double vg = sp.vGeocentric(vhel, dt1.djd());
00252         showGeoVel( vg );
00253 
00254         showTopoVel ( sp.vTopocentric(vg, vst) );
00255 
00256     } else if (radioVgeo->isChecked() ) {
00257 
00258         double vgeo = getVgeo();
00259         double vhel = sp.vGeoToVHelio(vgeo, dt1.djd() );
00260         showHelVel(vhel) ;
00261 
00262         double vlsr = sp.vHelioToVlsr(vhel, dt0.djd() );
00263         showVlsr(vlsr);
00264 
00265 
00266         showTopoVel ( sp.vTopocentric(vgeo, vst) );
00267 
00268     } else {
00269         double vtopo = getVtopo();
00270         double vgeo = sp.vTopoToVGeo(vtopo, vst);
00271         showGeoVel( vgeo );
00272 
00273         double vhel = sp.vGeoToVHelio(vgeo, dt1.djd() );
00274         showHelVel(vhel) ;
00275 
00276         double vlsr = sp.vHelioToVlsr(vhel, dt0.djd() );
00277         showVlsr(vlsr);
00278     }
00279 
00280 }
00281 
00282 void modCalcVlsr::slotUtChecked(){
00283     if ( utCheckBatch->isChecked() )
00284         utBoxBatch->setEnabled( false );
00285     else {
00286         utBoxBatch->setEnabled( true );
00287     }
00288 }
00289 
00290 void modCalcVlsr::slotDateChecked(){
00291     if ( dateCheckBatch->isChecked() )
00292         dateBoxBatch->setEnabled( false );
00293     else {
00294         dateBoxBatch->setEnabled( true );
00295     }
00296 }
00297 
00298 void modCalcVlsr::slotRaChecked(){
00299     if ( raCheckBatch->isChecked() ) {
00300         raBoxBatch->setEnabled( false );
00301     }
00302     else {
00303         raBoxBatch->setEnabled( true );
00304     }
00305 }
00306 
00307 void modCalcVlsr::slotDecChecked(){
00308     if ( decCheckBatch->isChecked() ) {
00309         decBoxBatch->setEnabled( false );
00310     }
00311     else {
00312         decBoxBatch->setEnabled( true );
00313     }
00314 }
00315 
00316 void modCalcVlsr::slotEpochChecked(){
00317     if ( epochCheckBatch->isChecked() )
00318         epochBoxBatch->setEnabled( false );
00319     else 
00320         epochBoxBatch->setEnabled( true );
00321 }
00322 
00323 void modCalcVlsr::slotLongChecked(){
00324     if ( longCheckBatch->isChecked() )
00325         longBoxBatch->setEnabled( false );
00326     else 
00327         longBoxBatch->setEnabled( true );
00328 }
00329 
00330 void modCalcVlsr::slotLatChecked(){
00331     if ( latCheckBatch->isChecked() )
00332         latBoxBatch->setEnabled( false );
00333     else {
00334         latBoxBatch->setEnabled( true );
00335     }
00336 }
00337 
00338 void modCalcVlsr::slotHeightChecked(){
00339     if ( heightCheckBatch->isChecked() )
00340         heightBoxBatch->setEnabled( false );
00341     else {
00342         heightBoxBatch->setEnabled( true );
00343     }
00344 }
00345 
00346 void modCalcVlsr::slotVlsrChecked(){
00347     if ( vlsrCheckBatch->isChecked() )
00348         vlsrBoxBatch->setEnabled( false );
00349     else {
00350         vlsrBoxBatch->setEnabled( true );
00351     }
00352 }
00353 
00354 void modCalcVlsr::slotInputFile() {
00355     QString inputFileName;
00356     inputFileName = KFileDialog::getOpenFileName( );
00357     InputLineEditBatch->setText( inputFileName );
00358 }
00359 
00360 void modCalcVlsr::slotOutputFile() {
00361     QString outputFileName;
00362     outputFileName = KFileDialog::getSaveFileName( );
00363     OutputLineEditBatch->setText( outputFileName );
00364 }
00365 
00366 void modCalcVlsr::slotRunBatch() {
00367     QString inputFileName;
00368 
00369     inputFileName = InputLineEditBatch->text();
00370 
00371     // We open the input file and read its content
00372 
00373     if ( QFile::exists(inputFileName) ) {
00374         QFile f( inputFileName );
00375         if ( !f.open( IO_ReadOnly) ) {
00376             QString message = i18n( "Could not open file %1.").arg( f.name() );
00377             KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
00378             inputFileName = "";
00379             return;
00380         }
00381 
00382 //      processLines(&f);
00383         QTextStream istream(&f);
00384         processLines(istream);
00385 //      readFile( istream );
00386         f.close();
00387     } else  {
00388         QString message = i18n( "Invalid file: %1" ).arg( inputFileName );
00389         KMessageBox::sorry( 0, message, i18n( "Invalid file" ) );
00390         inputFileName = "";
00391         InputLineEditBatch->setText( inputFileName );
00392         return;
00393     }
00394 }
00395 
00396 void modCalcVlsr::processLines( QTextStream &istream ) {
00397 
00398     // we open the output file
00399 
00400 //  QTextStream istream(&fIn);
00401     QString outputFileName;
00402     outputFileName = OutputLineEditBatch->text();
00403     QFile fOut( outputFileName );
00404     fOut.open(IO_WriteOnly);
00405     QTextStream ostream(&fOut);
00406 
00407     QString line;
00408     QString space = " ";
00409     int i = 0;
00410     long double jd0;
00411     SkyPoint spB;
00412     double sra, cra, sdc, cdc;
00413     dms raB, decB, latB, longB;
00414     double epoch0B, vhB, vgB, vtB, vlsrB, heightB;
00415     double vtopo[3];
00416     QTime utB;
00417     ExtDate dtB;
00418     KStarsDateTime dt0B;
00419 
00420     while ( ! istream.eof() ) {
00421         line = istream.readLine();
00422         line.stripWhiteSpace();
00423 
00424         //Go through the line, looking for parameters
00425 
00426         QStringList fields = QStringList::split( " ", line );
00427 
00428         i = 0;
00429 
00430         // Read Ut and write in ostream if corresponds
00431         
00432         if(utCheckBatch->isChecked() ) {
00433             utB = QTime::fromString( fields[i] );
00434             i++;
00435         } else
00436             utB = utBoxBatch->time();
00437         
00438         if ( allRadioBatch->isChecked() )
00439             ostream << utB.toString() << space;
00440         else
00441             if(utCheckBatch->isChecked() )
00442                 ostream << utB.toString() << space;
00443             
00444         // Read date and write in ostream if corresponds
00445         
00446         if(dateCheckBatch->isChecked() ) {
00447              dtB = ExtDate::fromString( fields[i] );
00448              i++;
00449         } else
00450             dtB = dateBoxBatch->date();
00451         if ( allRadioBatch->isChecked() )
00452             ostream << dtB.toString().append(space);
00453         else
00454             if(dateCheckBatch->isChecked() )
00455                 ostream << dtB.toString().append(space);
00456         
00457         // Read RA and write in ostream if corresponds
00458 
00459         if(raCheckBatch->isChecked() ) {
00460             raB = dms::fromString( fields[i],FALSE);
00461             i++;
00462         } else
00463             raB = raBoxBatch->createDms(FALSE);
00464 
00465         if ( allRadioBatch->isChecked() )
00466             ostream << raB.toHMSString() << space;
00467         else
00468             if(raCheckBatch->isChecked() )
00469                 ostream << raB.toHMSString() << space;
00470 
00471         // Read DEC and write in ostream if corresponds
00472 
00473         if(decCheckBatch->isChecked() ) {
00474             decB = dms::fromString( fields[i], TRUE);
00475             i++;
00476         } else
00477             decB = decBoxBatch->createDms();
00478 
00479         if ( allRadioBatch->isChecked() )
00480             ostream << decB.toDMSString() << space;
00481         else
00482             if(decCheckBatch->isChecked() )
00483                 ostream << decB.toDMSString() << space;
00484 
00485         // Read Epoch and write in ostream if corresponds
00486     
00487         if(epochCheckBatch->isChecked() ) {
00488             epoch0B = fields[i].toDouble();
00489             i++;
00490         } else
00491             epoch0B = getEpoch( epochBoxBatch->text() );
00492 
00493         if ( allRadioBatch->isChecked() )
00494             ostream << epoch0B << space;
00495         else
00496             if(epochCheckBatch->isChecked() )
00497                 ostream << epoch0B << space;
00498 
00499         // Read vlsr and write in ostream if corresponds
00500     
00501         if(vlsrCheckBatch->isChecked() ) {
00502             vlsrB = fields[i].toDouble();
00503             i++;
00504         } else
00505             vlsrB = getEpoch( epochBoxBatch->text() );
00506 
00507         if ( allRadioBatch->isChecked() )
00508             ostream << vlsrB << space;
00509         else
00510             if(vlsrCheckBatch->isChecked() )
00511                 ostream << vlsrB << space;
00512         
00513         // Read Longitude and write in ostream if corresponds
00514         
00515         if (longCheckBatch->isChecked() ) {
00516             longB = dms::fromString( fields[i],TRUE);
00517             i++;
00518         } else
00519             longB = longBoxBatch->createDms(TRUE);
00520         
00521         if ( allRadioBatch->isChecked() )
00522             ostream << longB.toDMSString() << space;
00523         else
00524             if (longCheckBatch->isChecked() )
00525                 ostream << longB.toDMSString() << space;
00526         
00527         // Read Latitude
00528 
00529 
00530         if (latCheckBatch->isChecked() ) {
00531             latB = dms::fromString( fields[i], TRUE);
00532             i++;
00533         } else
00534             latB = latBoxBatch->createDms(TRUE);
00535         if ( allRadioBatch->isChecked() )
00536             ostream << latB.toDMSString() << space;
00537         else
00538             if (latCheckBatch->isChecked() )
00539                 ostream << latB.toDMSString() << space;
00540         
00541         // Read height and write in ostream if corresponds
00542     
00543         if(heightCheckBatch->isChecked() ) {
00544             heightB = fields[i].toDouble();
00545             i++;
00546         } else
00547             heightB = getEpoch( epochBoxBatch->text() );
00548 
00549         if ( allRadioBatch->isChecked() )
00550             ostream << heightB << space;
00551         else
00552             if(heightCheckBatch->isChecked() )
00553                 ostream << heightB << space;
00554         
00555         // We make the first calculations
00556 
00557         spB = SkyPoint (raB, decB);
00558         dt0B.setFromEpoch(epoch0B);
00559         vhB = spB.vHeliocentric(vlsrB, dt0B.djd());
00560         jd0 = KStarsDateTime(dtB,utB).djd();
00561         vgB = spB.vGeocentric(vlsrB, jd0); 
00562         geoPlace->setLong( longB );
00563         geoPlace->setLat(  latB );
00564         geoPlace->setHeight( heightB );
00565         dms gsidt = KStarsDateTime(dtB,utB).gst();
00566         geoPlace->TopocentricVelocity(vtopo, gsidt);
00567         spB.ra()->SinCos(sra, cra);
00568         spB.dec()->SinCos(sdc, cdc);
00569         vtB = vgB - (vtopo[0]*cdc*cra + vtopo[1]*cdc*sra + vtopo[2]*sdc);
00570 
00571         ostream << vhB << space << vgB << space << vtB << endl;
00572 
00573     }
00574 
00575 
00576     fOut.close();
00577 }

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal