Main Page   Namespace List   Compound List   File List   Compound Members   File Members  

astroutil.h File Reference

Go to the source code of this file.

Compounds

struct  Cart
struct  Sphe

Defines

#define OreToDec(x, y, z)   (x)+(y)/60.+(z)/3600.
#define R_TERRA   6378.145e3F
#define PI   3.141592654F
#define PI2   (PI*2.F)
#define D2R   0.017453292F
#define R2D   57.29578122F
#define H2R   0.261799387F
#define J1900   2415020.0F
#define B1950   2433282.423F
#define J2000   2451545.0F
#define SECS2RADS   206264.806247096355F
#define J2   1.0822e-3
#define MinutesPerDay   (24.*60.0F)
#define CLUCE   2.997925e+5
#define EarthFlat   (1/298.25)
#define SiderealSolar   1.0027379093
#define SidRate   (PI2*SiderealSolar/SecondsPerDay)
#define GM   398600.0F
#define Epsilon   (D2R/3600)
#define SunRadius   695000
#define SunSemiMajorAxis   149598845.0
#define SQR(x)   ((x)*(x))

Typedefs

typedef Cart CARTES
typedef Sphe SPHER

Functions

void range (double *s, double m)
void sphcart (SPHER s, CARTES *c)
void car2sph (CARTES c, SPHER *s)
double GetJD (int An, int Me, int Gio, double utc)
double GetGMST (double J_D)
double Kepler (double MeanAnomaly, double Eccentricity)
void matrix_transpose (double a[3][3], double b[3][3])
void matrix_multiply (double a[3][3], double b[3][3], double c[3][3])
void calc_unit_vector (double a[3], double b[3])
void vector_cross_product (double a[3], double b[3], double c[3])
void vector_matrix_multiply (const double a[3], double b[3][3], double c[3])
double modulo (double a, double b)
void eqtogal (double ra, double dec, double *l, double *b)
void galtoeq (double l, double b, double *ra, double *dec)
void vector_dot_product (double a[3], double b[3], double *mod, double *angle)
double modulo_vet (double a[3])
int vector2radec (double *pos, double *ra, double *dec)
void Sfer2xyz (double ra, double dec, double *vector)
int InsideSAA (double lon, double lat)
void GetRockMat (const double pp[3], const double rock, const int orb, double ppr[3])

Variables

const double SecondsPerDay = 86400


Define Documentation

#define B1950   2433282.423F
 

Definition at line 13 of file astroutil.h.

#define CLUCE   2.997925e+5
 

Definition at line 21 of file astroutil.h.

#define D2R   0.017453292F
 

Definition at line 9 of file astroutil.h.

#define EarthFlat   (1/298.25)
 

Definition at line 23 of file astroutil.h.

#define Epsilon   (D2R/3600)
 

Definition at line 28 of file astroutil.h.

#define GM   398600.0F
 

Definition at line 26 of file astroutil.h.

#define H2R   0.261799387F
 

Definition at line 11 of file astroutil.h.

#define J1900   2415020.0F
 

Definition at line 12 of file astroutil.h.

#define J2   1.0822e-3
 

Definition at line 17 of file astroutil.h.

#define J2000   2451545.0F
 

Definition at line 14 of file astroutil.h.

#define MinutesPerDay   (24.*60.0F)
 

Definition at line 19 of file astroutil.h.

#define OreToDec x,
y,
     (x)+(y)/60.+(z)/3600.
 

Definition at line 4 of file astroutil.h.

#define PI   3.141592654F
 

Definition at line 7 of file astroutil.h.

#define PI2   (PI*2.F)
 

Definition at line 8 of file astroutil.h.

#define R2D   57.29578122F
 

Definition at line 10 of file astroutil.h.

#define R_TERRA   6378.145e3F
 

Definition at line 6 of file astroutil.h.

#define SECS2RADS   206264.806247096355F
 

Definition at line 15 of file astroutil.h.

#define SQR      ((x)*(x))
 

Definition at line 31 of file astroutil.h.

Referenced by InsideSAA(), eqtogal(), and galtoeq().

#define SidRate   (PI2*SiderealSolar/SecondsPerDay)
 

Definition at line 25 of file astroutil.h.

#define SiderealSolar   1.0027379093
 

Definition at line 24 of file astroutil.h.

#define SunRadius   695000
 

Definition at line 29 of file astroutil.h.

#define SunSemiMajorAxis   149598845.0
 

Definition at line 30 of file astroutil.h.


Typedef Documentation

typedef struct Cart CARTES
 

typedef struct Sphe SPHER
 


Function Documentation

double GetGMST double    J_D
 

Definition at line 23 of file astroutil.cxx.

Referenced by main().

00024 {
00025         double M,T,T1,Tempo_Siderale_0,Tempo_Siderale_Ora,Tempo_Siderale_Loc;
00026         double Ora_Un_Dec=modf(J_D-0.5,&M)*24;  J_D-=Ora_Un_Dec/24; 
00027         T = ((J_D) - J2000) / 36525.;
00028         T1 = (24110.54841 + 8640184.812866 * T + 0.0093103 * T * T)/86400.0;
00029         Tempo_Siderale_0 = modf(T1,&M) * 24.;
00030         Tempo_Siderale_Ora = Tempo_Siderale_0 + Ora_Un_Dec * 1.00273790935;
00031         if (Tempo_Siderale_Ora < 0.) Tempo_Siderale_Ora = Tempo_Siderale_Ora + 24.;
00032         if (Tempo_Siderale_Ora >= 24.) Tempo_Siderale_Ora = Tempo_Siderale_Ora - 24.;
00033         Tempo_Siderale_Loc = Tempo_Siderale_Ora*15.;
00034         return Tempo_Siderale_Loc;
00035 }   /* Calcolo_Tempo_Siderale */

double GetJD int    An,
int    Me,
int    Gio,
double    utc
 

Definition at line 5 of file astroutil.cxx.

Referenced by main().

00006 {
00007         int A,B,D;
00008         double J_D;
00009         long int C;
00010 
00011         if (Me > 2);
00012         else {
00013                 An = An - 1;
00014                 Me = Me + 12;
00015                 }
00016         A = (An / 100); B = 2 - A + (A / 4);
00017         C = (long int)(365.25 * An); if (An < 0) C = C - 1;
00018         D = (int)(30.6001 * (Me + 1));
00019         J_D = B + C + D + Gio + 1720994.5+ utc / 24.;
00020         return J_D;
00021 }   /* Giorno_Giuliano */

void GetRockMat const double    pp[3],
const double    rock,
const int    orb,
double    ppr[3]
 

Definition at line 318 of file astroutil.cxx.

Referenced by main().

00319 {
00320            //rock down for even orbits, up for odd orbits
00321     double rock_sign = -1. + 2.*(orb - 2*(orb/2));
00322         double sinrock = sin(rock_sign*rock*D2R);
00323     double cosrock = cos(rock_sign*rock*D2R);
00324         double rockmat[3][3];
00325         double cost = pp[0]/sqrt(pp[0]*pp[0]+pp[1]*pp[1]);
00326     double sint = -pp[1]/sqrt(pp[0]*pp[0]+pp[1]*pp[1]);
00327     rockmat[0][0]=cosrock*cost*cost+sint*sint;
00328         rockmat[1][0]=(1.-cosrock)*cost*sint;
00329         rockmat[2][0]=-sinrock*cost;
00330     rockmat[0][1]=(1.-cosrock)*cost*sint;
00331         rockmat[1][1]=cosrock*sint*sint+cost*cost;
00332         rockmat[2][1]=sinrock*sint;
00333     rockmat[0][2]=sinrock*cost;
00334         rockmat[1][2]=-sinrock*sint;
00335         rockmat[2][2]=cosrock;
00336         
00337 
00338     ppr[0]=rockmat[0][0]*pp[0]+rockmat[0][1]*pp[1]+rockmat[0][2]*pp[2];
00339     ppr[1]=rockmat[1][0]*pp[0]+rockmat[1][1]*pp[1]+rockmat[1][2]*pp[2];
00340         ppr[2]=rockmat[2][0]*pp[0]+rockmat[2][1]*pp[1]+rockmat[2][2]*pp[2];
00341 }

int InsideSAA double    lon,
double    lat
 

Definition at line 274 of file astroutil.cxx.

Referenced by main().

00275 {
00276         double perim[7][2] = {{-88.,-30.},{-88.,-12.},{-55.,-0.1},{-32.,-0.1},{-7,-12},
00277     {50.,-25},{50.,-30.}};
00278         double longmin=-88;
00279         double longmax=50.;
00280         double latmin=-30;
00281         double latmax=-0.1;
00282         double diffx[7],diffy[7],diffd[7];
00283         if((lon>=longmin)&&(lon<=longmax)&&(lat>=latmin)&&(lat<=latmax)){
00284         for (int i=0;i<6;i++){
00285                         diffx[i]=perim[i+1][0]-perim[i][0];
00286                         diffy[i]=perim[i+1][1]-perim[i][1];
00287                         //cout<<i<<"  "<<diffx[i]<<endl;
00288         }
00289         diffx[6]=perim[0][0]-perim[6][0];
00290         diffy[6]=perim[0][1]-perim[6][1];
00291 
00292         for (i=0;i<7;i++){
00293                         diffd[i]=sqrt(SQR(diffx[i])+SQR(diffy[i]));
00294                         //cout<<diffd[i]<<endl;
00295         }
00296         double xnew[7],ynew[7];
00297         int inside[7];
00298         int xtemp[7],txtemp=0,tins=0;
00299         for (i=0;i<7;i++){
00300                         xnew[i]=((lon-perim[i][0])*diffx[i]+(lat-perim[i][1])*diffy[i])/diffd[i];
00301                         ynew[i]=(lat-perim[i][1])*diffx[i]-(lon-perim[i][0])*diffy[i];
00302                         xtemp[i]=((xnew[i] >=0.)&&(xnew[i]<=diffd[i]));
00303                         inside[i]=(xtemp[i] == 1) && (ynew[i]<0.);
00304                         txtemp+=xtemp[i];
00305                         tins+=inside[i];
00306                         //cout<<diffd[i]<<endl;
00307         }
00308         int insaa=(txtemp==tins)&&(txtemp >0);
00309         //cout<<insaa<<" "<<txtemp<<"  "<<tins<<endl;
00310 
00311         return insaa;
00312         }
00313         else
00314                 return 0;
00315 }

double Kepler double    MeanAnomaly,
double    Eccentricity
 

Definition at line 38 of file astroutil.cxx.

Referenced by main().

00039 {
00040 double E;              /* Eccentric Anomaly                    */
00041 double Error;
00042 double TrueAnomaly;
00043  
00044     E = MeanAnomaly;    /* Initial guess */
00045     do
00046         {
00047         Error = (E - Eccentricity*sin(E) - MeanAnomaly)
00048                 / (1. - Eccentricity*cos(E));
00049         E -= Error;
00050         }
00051    while (fabs(Error) >= 0.000001);
00052  
00053     if (fabs(E-PI) < 0.000001)
00054         TrueAnomaly = PI;
00055       else
00056         TrueAnomaly = 2.*atan(sqrt((1.+Eccentricity)/(1.-Eccentricity))
00057                                 *tan(E/2.));
00058     if (TrueAnomaly < 0)
00059         TrueAnomaly += PI2;
00060  
00061     return TrueAnomaly;
00062 }

void Sfer2xyz double    ra,
double    dec,
double *    vector
 

Definition at line 264 of file astroutil.cxx.

00265 {
00266 
00267    vector[0] = cos (dec*D2R) * cos ( ra*D2R);
00268    vector[1] = cos (dec*D2R) * sin ( ra*D2R);
00269    vector[2] = sin (dec*D2R);
00270 
00271    return;
00272 }

void calc_unit_vector double    a[3],
double    b[3]
 

Definition at line 107 of file astroutil.cxx.

Referenced by main().

00108 {
00109    double sqr_root;
00110    sqr_root = sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]);
00111    b[0] = a[0] / sqr_root;
00112    b[1] = a[1] / sqr_root;
00113    b[2] = a[2] / sqr_root;
00114 }/* end calc_unit_vector() */

void car2sph CARTES    c,
SPHER   s
 

Definition at line 201 of file astroutil.cxx.

00202 {
00203         double rho = c.x*c.x + c.y*c.y;
00204 
00205         if (rho > 1e-35) {      /* standard case: off axis */
00206             s->l = atan2(c.y, c.x);
00207             range (&(s->l), 2*PI2);
00208             s->b = atan2(c.z, sqrt(rho));
00209             s->r = sqrt(rho + c.z*c.z);
00210         } else {                /* degenerate case; avoid math error */
00211             s->l = 0.0;
00212             if (c.z == 0.0)
00213                         s->b = 0.0;
00214             else
00215                         s->b = (c.z > 0.0) ? PI2/2. : -PI2/2.;
00216             s->r = fabs(c.z);
00217         }
00218 }

void eqtogal double    ra,
double    dec,
double *    l,
double *    b
 

Definition at line 141 of file astroutil.cxx.

00142 {
00143 
00144         double Xe,Ye,Ze;
00145         
00146         double RotM[3][3] = {{-0.0548755604, 0.4941094279, -0.8676661490},{ -0.8734370902, -0.4448296300, -0.1980763734}, {-0.4838350155, 0.7469822445, 0.4559837762}};
00147         double Pos[3];
00148         double Gal[3];
00149 
00150         Pos[0]=Xe=cos(dec*D2R)*cos(ra*D2R);
00151         Pos[1]=Ye=cos(dec*D2R)*sin(ra*D2R);
00152         Pos[2]=Ze=sin(dec*D2R);
00153   
00154         vector_matrix_multiply(Pos, RotM, Gal);
00155 
00156         *l=atan2(Gal[1],Gal[0])*R2D;
00157         *b=atan(Gal[2]/sqrt(SQR(Gal[0])+SQR(Gal[1])))*R2D;
00158 
00159 }

void galtoeq double    l,
double    b,
double *    ra,
double *    dec
 

Definition at line 161 of file astroutil.cxx.

00162 {
00163 
00164         double Xe,Ye,Ze;
00165         
00166         double RotM[3][3] = {{-0.0548755604, 0.4941094279, -0.8676661490},{ -0.8734370902, -0.4448296300, -0.1980763734}, {-0.4838350155, 0.7469822445, 0.4559837762}};
00167         double Pos[3];
00168         double Gal[3];
00169         double Tra[3][3];
00170         matrix_transpose(RotM,Tra);
00171         Pos[0]=Xe=cos(b*D2R)*cos(l*D2R);
00172         Pos[1]=Ye=cos(b*D2R)*sin(l*D2R);
00173         Pos[2]=Ze=sin(b*D2R);
00174   
00175         vector_matrix_multiply(Pos, Tra, Gal);
00176 
00177         *ra=atan2(Gal[1],Gal[0])*R2D;
00178         *dec=atan(Gal[2]/sqrt(SQR(Gal[0])+SQR(Gal[1])))*R2D;
00179         if(*ra<0.)*ra+=360;
00180 
00181 }

void matrix_multiply double    a[3][3],
double    b[3][3],
double    c[3][3]
 

Definition at line 91 of file astroutil.cxx.

00092 {
00093    int i, j, k;
00094    double sum;
00095 
00096    for(i=0; i<3; i++) {
00097       for(k=0; k<3; k++) {
00098         sum = 0;
00099         for(j=0; j<3; j++) {
00100            sum += a[i][j] * b[j][k];
00101         }/* end for j */
00102         c[i][k] = sum;
00103       }/* end for k */
00104    }/* end for i */
00105 }/* end matrix_multiply() */

void matrix_transpose double    a[3][3],
double    b[3][3]
 

Definition at line 68 of file astroutil.cxx.

Referenced by galtoeq().

00069 {
00070    int i, j;
00071    double temp[3][3];
00072 
00073    /* This loop transposes the matrix into a temporary matrix */
00074    for(i=0; i<3; i++) {
00075       for(j=0; j<3; j++) {
00076          temp[j][i] = a[i][j];
00077       }/* end for j */
00078    }/* end for i */
00079 
00080    /* And then we assign the temporary matrix to the destination matrix */
00081    /* This step is necessary in case the original and destination matrix
00082       are the same variable */
00083    for(i=0; i<3; i++) {
00084       for(j=0; j<3; j++) {
00085          b[j][i] = temp[j][i];
00086       }/* end for j */
00087    }/* end for i */
00088 
00089 }/* end matrix_transpose() */

double modulo double    a,
double    b
 

Definition at line 131 of file astroutil.cxx.

00132 {
00133 
00134    if ((a - floor(a/b)*b) >= 0.0) return(a - floor(a/b)*b);
00135    else return(a - floor(a/b)*b + b);
00136 }/* fine modulo() */

double modulo_vet double    a[3]
 

Definition at line 220 of file astroutil.cxx.

Referenced by vector_dot_product().

00221 {
00222         return sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);
00223 }

void range double *    v,
double    r
 

Definition at line 14 of file EarthOrbit.cxx.

00015     {
00016         while((*s)>=m) (*s)-=m;
00017         while((*s)<0) (*s)+=m;
00018     }

void sphcart SPHER    s,
CARTES   c
 

int vector2radec double *    pos,
double *    ra,
double *    dec
 

Definition at line 232 of file astroutil.cxx.

00233 {
00234    double xyproj;
00235 
00236    xyproj = sqrt (pow (pos[0], 2.0) + pow (pos[1], 2.0));
00237    if ((xyproj == 0.0) && (pos[2] == 0))
00238    {
00239       *ra = 0.0;
00240       *dec = 0.0;
00241       return 1;
00242    }
00243     else if (xyproj == 0.0)
00244    {
00245       *ra = 0.0;
00246       if (pos[2] < 0.0)
00247       *dec = -90.0;
00248        else
00249          *dec = 90.0;
00250       return 2;
00251    }
00252     else
00253    {
00254       *ra = atan2 (pos[1], pos[0]) * SECS2RADS / 54000.0;
00255       *dec = atan2 (pos[2], xyproj) * SECS2RADS / 3600.0;
00256 
00257       if (*ra < 0.0)
00258          *ra += 24.0;
00259    }
00260    return 0;
00261 }

void vector_cross_product double    a[3],
double    b[3],
double    c[3]
 

Definition at line 116 of file astroutil.cxx.

00117 {
00118    c[0] = a[1]*b[2] - a[2]*b[1];
00119    c[1] = a[2]*b[0] - a[0]*b[2];
00120    c[2] = a[0]*b[1] - a[1]*b[0];
00121 }/* end vector_cross_product() */

void vector_dot_product double    a[3],
double    b[3],
double *    mod,
double *    angle
 

Definition at line 225 of file astroutil.cxx.

00226 {
00227         *mod = a[0]*b[0]+a[1]*b[1]+a[2]*b[2];
00228         *angle=R2D*acos(*mod/(modulo_vet(a)*modulo_vet(b)));
00229 
00230 }

void vector_matrix_multiply const double    a[3],
double    b[3][3],
double    c[3]
 

Definition at line 123 of file astroutil.cxx.

Referenced by eqtogal(), galtoeq(), and main().

00124 {
00125    int i;
00126    for (i=0;i<=2;i++) {
00127       c[i] = a[0]*b[0][i] + a[1]*b[1][i] + a[2]*b[2][i];
00128    }/* end for */
00129 }/* end vector_matrix_multiply() */


Variable Documentation

const double SecondsPerDay = 86400
 

Definition at line 20 of file astroutil.h.


Generated on Wed Aug 14 10:09:35 2002 for astro by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001