Need help to link this code to file such that it reads parameters from.the file
automatically and calculates. Also, need the code to run a loop so every after
8 lines such that procedure repeats and hence obtain values for the follwing
repeated parameters.
#include <iostream> //For the use of cout and cin
#include <cmath>
#include <string>
#include <fstream>
#define pi 3.141592654 // DEFINE the constant PI
#define GM 623.236 // Gravitational constant. DEFINE it because it
is a Constant that will NEVER CHANGE in this program
using namespace std; //To use endl When using cout Functions
int main()
{
double tk; //The time
double toe; //Ephemerides reference epoch in seconds within the week
double t, Mo;
double Mk; // The mean anomaly
double Deltan; // Mean motion difference
double e; // Eccentricity
double Ek; // The eccentric anomaly
double Vk; // The true anomaly
double Uk; // The argument of latitude
double w; // Argument of perigee
double Cuc, Cus; // Latitude argument correction
double Crc, Crs; // Orbital radius correction
double Cic, Cis; // Inclination correction
double Ik; // The inclination
double rk; // The radial distance
double Io; // Inclination at reference epoch
double i; // Rate of inclination angle(idot)
double LA; // Longitude of the ascending node
double a; //Semi-major axis
double R1,R2; // R1 and R3 are the rotation matrices
double X,Y,Z; // Coordinates
double Xk,Yk ,Zk, wE, S, So, idot, l, m, n, p, q, r; //Used to temporarily
hold certain variable, e.g idot WILL hold i,So=OMEGA,w=Omega,
double A,B,C,D,E; //Used to hold various results of the
calculations
double
prn,e_year,e_month,e_day,e_hr,e_min,e_sec,sv_clock_bias,sv_cloc_drift,clock_drift_rate;
double
l2_codes_channel,gpsweek,l2p_dataflag,sv_accuracy,sv_health,total_grp_delay,issue_of_data_clock,fit_interval,iode;
double roota;
//this is the part that fails to run as expected
//linking file to soure code
ifstream readFile;
readFile.open("Navigation.10N");
if(! readFile)
{
cout<<"unable to open file"<<endl;
exit(1); // terminate with error
}
while(readFile)
{
readFile>>prn>>e_year>>e_month>>e_day>>e_hr>>e_min>>e_sec>>sv_clock_bias>>sv_cloc_drift>>clock_drift_rate;
readFile>> iode>>Crs>>Deltan>>Mo;
readFile>>Cuc>>e>>Cus>> roota;
readFile>>toe>>Cic>>So>>Cis;
readFile>>Io>>Crc>>w>>S;
readFile>>i>>l2_codes_channel>>gpsweek>>l2p_dataflag;
readFile>>sv_accuracy>>sv_health>>total_grp_delay>>issue_of_data_clock;
readFile>>t>>fit_interval;
//to thos part.... cant figure the problem
/* Compute the time tk from the ephemerides reference epoch toe (t and
toe are expressed in seconds in the GPS week)*/
cout<<" VALUE OF t = "<<t<<endl;
cout<<" VALUE OF toe = "<<toe<<endl;
A = t - toe;
if (A > 302400){
tk = A-604800;
}else if (A < -302400){
tk = A + 604800;
}else {
tk = A;
}
cout<<"HENCE tk = "<<tk<<endl<<endl;
// Compute the mean anomaly for tk:
cout<< "VALUE OF Deltan = "<<Deltan<<endl;
cout<< "VALUE OF Mo = "<<Mo<<endl;
cout<< "VALUE OF a = "<<a<<endl;
Mk = Mo + (((sqrt(GM)/sqrt(a*a*a))+Deltan)*tk);
cout<<"HENCE Mk = "<< Mk<<endl<<endl;
//Solve (iteratively) the Kepler equation for the eccentric anomaly Ek:
cout<<"VALUE OF e = "<<e<<endl;
Mk = Ek;
//loop: B = Ek-(Ek-e*sin(Ek))/(1-e*cos(Ek));
for(C=abs(Mk-B);C > 0.000005;C= abs(Mk-B)){ //Loop to iteratively
SOLVE Kepler
B = Ek-(e*sin(Ek));
}
B = Mk;
// Compute the true anomaly vk:
Vk = atan ((sqrt(1-(e*e))* sin(Ek))/(cos((Ek)-e)));
cout<<"HENCE Vk = "<< Vk <<endl<<endl;
/* Compute the argument of latitude uk from the argument of perigee
w, true anomaly vk and corrections cuc and cus: */
cout<<" VALUE OF Cuc = "<<Cuc<<endl;
cout<<" VALUE OF Cus = "<<Cus<<endl;
cout<<" VALUE OF w = "<<w<<endl;
Uk = (w + Vk + Cuc*(cos(2*(w + Vk))) + Cus*(sin(2*(w + Vk))));
cout<<"HENCE Uk = "<<Uk<<endl<<endl;
// Compute the radial distance rk, considering corrections crc and crs:
cout<<" VALUE OF Crc = "<<Crc<<endl;
cout<<" VALUE OF Crs = "<<Crs<<endl;
rk = a* ((1-(e*cos(Ek))) + Crc*(cos(2*(w + Vk))) + Crs*(sin(2*(w + Vk))));
cout<<"HENCE rk = "<<rk<<endl<<endl;
/*Compute the inclination ik of the orbital plane from the inclinationio at
reference time toe, and
corrections cic and cis:*/
cout<<"VALUE OF Cic"<<Cic<<endl;
cout<<"VALUE OF Cis"<<Cis<<endl;
cout<<"VALUE OF io"<<Io<<endl;
cout<<"VALUE OF i"<<i<<endl;
Ik = Io + (i*tk) + Cic*(cos(2*(w + Vk))) + Cis*(sin(2*(w + Vk)));
cout<<"HENCE ik = "<<Ik<<endl<<endl;
/* Compute the longitude of the ascending node LA */
cout<<"VALUE OF So = "<<So<<endl;
cout<<"VALUE OF wE = "<<wE<<endl;
cout<<"VALUE OF S = "<<S<<endl;
LA = So + (S-wE)*tk - (wE*toe);
cout<<"HENCE LA = "<<LA<<endl<<endl;
Xk = rk*cos(Uk);
Yk = rk*sin(Uk);
cout<<" HENCE Xk="<<Xk<<endl<<endl;
cout<<"HENCE Yk="<<Xk<<endl<<endl;
// computation of coordinates of points
//compute the X coordinate
l = Xk*cos(LA);
m = Yk*sin(LA);
n = cos(Ik);
X = (l-(m*n));
cout<<"HENCE CORDINATE X = "<<X<<endl;
// compute the coordinates of Y
p = Xk*sin(LA);
q = Yk*cos(LA);
r = cos(Ik);
Y = (p+(q*r));
cout<<"HENCE CORDINATE Y = "<<Y<<endl;
// compute the Z value
Z = Yk*sin(Ik);
cout<<"HENCE CORDINATE Z = "<<Z<<endl;
return 0;
}
}
And file ( Navigation.10n from.which i get values looks like this
9 10 1 5 2 0 0.0 9.810924530029D-05 2.273736754432D-12 0.000000000000D+00
4.300000000000D+01 5.162500000000D+01 4.433756112310D-09 3.289760320408D-01
2.775341272354D-06 2.063383429777D-02 6.351619958878D-06 5.153614496231D+03
1.800000000000D+05-2.253800630569D-07-1.295551401808D+00-5.960464477539D-08
9.787015591684D-01 2.687187500000D+02 1.525590850297D+00-8.579285933124D-09
2.914407111040D-10 1.000000000000D+00 1.565000000000D+03 0.000000000000D+00
2.000000000000D+00 0.000000000000D+00-5.587935447693D-09 4.300000000000D+01
1.728300000000D+05
21 10 1 5 2 0 0.0-3.195740282536D-05-2.387423592154D-12 0.000000000000D+00
8.900000000000D+01 5.321875000000D+01 5.505943630367D-09 1.970215147141D-01
2.965331077576D-06 1.578241400421D-02 6.997957825661D-06 5.153715517044D+03
1.800000000000D+05 5.960464477539D-08 1.891577239510D+00 2.309679985046D-07
9.326610139206D-01 2.297812500000D+02-2.536106763964D+00-8.795009204579D-09
3.192990143713D-10 1.000000000000D+00 1.565000000000D+03 0.000000000000D+00
2.000000000000D+00 0.000000000000D+00-1.210719347000D-08 8.900000000000D+01
1.728900000000D+05
14 10 1 5 2 0 0.0-3.751832991838D-06 4.547473508865D-12 0.000000000000D+00
1.700000000000D+01 2.056250000000D+01 3.757656521477D-09-2.866359461205D+00
1.167878508568D-06 5.043098120950D-03 1.081824302673D-05 5.153696205139D+03
1.800000000000D+05 4.470348358154D-08-2.268831142267D+00-6.891787052155D-08
9.872796294851D-01 1.838125000000D+02-2.095497188315D+00-7.599602268224D-09
-6.035965707914D-11 1.000000000000D+00 1.565000000000D+03 0.000000000000D+00
2.000000000000D+00 0.000000000000D+00-8.847564458847D-09 1.700000000000D+01
1.729200000000D+05
Help will be much appreciated
Thanks in advance
Also u can email directly to [email protected]
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/4446c896-8524-4d07-b71f-0c841a3e8112%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.