Commit b2540417 authored by Zhang Xin's avatar Zhang Xin
Browse files

Initial commit

parents
#include "ephcom_wrapper.hpp"
Ephcom::Ephcom(std::string& DE_filename){
this->infp = NULL;
this->ORIG = EPHCOM_EARTH;
this->init(DE_filename);
}
Ephcom::~Ephcom(){
if( infp != NULL ){
fclose(infp);
infp = NULL;
}
}
void Ephcom::init(std::string& DE_filename){
infp = NULL;
infp = fopen(DE_filename.c_str(),"r");
if( infp == NULL ){
std::cout << __FILE__ << ":"
<< __func__ << ":L:"
<< __LINE__ << ":"
<< " failed to open: "
<< DE_filename
<< std::endl;
} else {
std::cout << "Successfully loaded ephcom data from: " << DE_filename << std::endl;
}
ephcom_readbinary_header(infp, &(this->header));
this->coords.km = 1; // not AU, use kilometers
this->coords.seconds = 0; // Timescale is days, not seconds
this->coords.bary = 1; // Center is Solar System Barycenter
this->coords.coordtype = 0; // No correction for light travel time or relativistic effects from Sun.
}
/*
targ: one of the object, SUN, ..., MERCURY (see ephcom_wrapper.hpp)
jd : Julian date
pos : position of the object
vel : velocity of the object
*/
void Ephcom::getPosVel(int targ, double jd, double pos[3], double vel[3]){
if( (targ < EPHCOM_MERCURY) || (targ > EPHCOM_SUN) ){
std::cout << __FILE__ << ":"
<< __func__ << ":L:"
<< __LINE__ << ":"
<< "targ must >= EPHCOM_MERCURY and <= EPHCOM_SUN"
<< std::endl;
}
double res[6];
this->coords.et2[0] = jd;
this->coords.et2[1] = 0.0;
ephcom_readbinary_header(this->infp, &this->header);
double *datablock = (double *) malloc(this->header.ncoeff * sizeof(double));
if ( ephcom_get_coords(this->infp, &this->header, &this->coords, datablock) == 0 ) {
ephcom_pleph(&this->coords, targ, this->ORIG, res);
pos[0] = res[0];
pos[1] = res[1];
pos[2] = res[2];
vel[0] = res[3] / 86400; // convert to km/sec
vel[1] = res[4] / 86400;
vel[2] = res[5] / 86400;
} else {
std::cout << __FILE__ << ":"
<< __func__ << ":L:"
<< __LINE__ << ":"
<< "Coordinates not found for Julian date:"
<< jd
<< std::endl;
}
free(datablock);
}
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include "ephcom.h"
/*
#define EPHCOM_MERCURY 1
#define EPHCOM_VENUS 2
#define EPHCOM_EARTH 3
#define EPHCOM_MARS 4
#define EPHCOM_JUPITER 5
#define EPHCOM_SATURN 6
#define EPHCOM_URANUS 7
#define EPHCOM_NEPTUNE 8
#define EPHCOM_PLUTO 9
#define EPHCOM_MOON 10 // Moon, relative to Solar System center
#define EPHCOM_SUN 11
*/
#ifndef _EPHCOM_WRAPPER_HPP_
#define _EPHCOM_WRAPPER_HPP_
#define SUN EPHCOM_SUN // 太阳
#define MOON EPHCOM_MOON // 月球
#define PLUTO EPHCOM_PLUTO // 冥王星
#define NEPTUNE EPHCOM_NEPTUNE // 海王星
#define URANUS EPHCOM_URANUS // 天王星
#define SATURN EPHCOM_SATURN // 土星
#define JUPITER EPHCOM_JUPITER // 木星
#define MARS EPHCOM_MARS // 火星
#define EARTH EPHCOM_EARTH // 地球
#define VENUS EPHCOM_VENUS // 金星
#define MERCURY EPHCOM_MERCURY // 水星
class Ephcom{
private:
FILE *infp;
ephcom_Header header;
ephcom_Coords coords;
int ORIG; // origin used to calculation positions of Sun, Moon and planets. Default: EPHCOM_EARTH
public:
Ephcom(std::string& DE_filename);
~Ephcom();
void init(std::string& DE_filename);
// get position and velocity
/*
targ: one of the object, SUN, ..., MERCURY
jd : Julian date
pos : position of the object
vel : velocity of the object
*/
void getPosVel(int targ, double jd, double pos[3], double vel[3]);
};
#endif
#ifndef __EPHCOM_DLL_H
#define __EPHCOM_DLL_H
#ifdef USINGDLL
#if defined ( WIN32 )
// Visual C/C++, Borland, MinGW and Watcom
#if defined ( __VISUALC__ ) || defined ( _MSC_VER ) || defined ( __BORLANDC__ ) || defined ( __GNUC__ ) || defined ( __WATCOMC__ )
#define EPHCOMDLLEXPORT __declspec( dllexport )
#define EPHCOMDLLIMPORT __declspec( dllimport )
#else
#define EPHCOMDLLEXPORT
#define EPHCOMDLLIMPORT
#endif
#elif defined ( __CYGWIN__ )
#define EPHCOMDLLEXPORT __declspec( dllexport )
#define EPHCOMDLLIMPORT __declspec( dllimport )
#elif defined ( __GNUC__ ) && __GNUC__ > 3
// Follow ideas in http://gcc.gnu.org/wiki/Visibility for GCC version 4.x
// The following forces exported symbols specifically designated with
// EPHCOMDLLEXPORT to be visible.
#define EPHCOMDLLEXPORT __attribute__ ( ( visibility( "default" ) ) )
#define EPHCOMDLLIMPORT
#endif
#endif
// For an unknown compiler or static build we clear the macros
#ifndef EPHCOMDLLEXPORT
#define EPHCOMDLLEXPORT
#define EPHCOMDLLIMPORT
#endif
// The IMPEXP macros will always be set to DLLIMPORT (even for
// the static library, but DLLIMPORT is empty in this case), if
// cmake didn't set the corresponding macro xxxx_EXPORTS when the
// corresponding library is built (DLLIMPEXP is set to DLLEXPORT
// then)
#if defined ( gnulliver_EXPORTS )
#define GNULLIVERDLLIMPEXP EPHCOMDLLEXPORT
#define GNULLIVERDLLIMPEXP_DATA( type ) EPHCOMDLLEXPORT type
#else
#define GNULLIVERDLLIMPEXP EPHCOMDLLIMPORT
#define GNULLIVERDLLIMPEXP_DATA( type ) EPHCOMDLLIMPORT type
#endif
#if defined ( ephcom_EXPORTS )
#define EPHCOMDLLIMPEXP EPHCOMDLLEXPORT
#define EPHCOMDLLIMPEXP_DATA( type ) EPHCOMDLLEXPORT type
#else
#define EPHCOMDLLIMPEXP EPHCOMDLLIMPORT
#define EPHCOMDLLIMPEXP_DATA( type ) EPHCOMDLLIMPORT type
#endif
#if defined ( ephcomfc_EXPORTS )
#define EPHCOMFCDLLIMPEXP EPHCOMDLLEXPORT
#define EPHCOMFCDLLIMPEXP_DATA( type ) EPHCOMDLLEXPORT type
#else
#define EPHCOMFCDLLIMPEXP EPHCOMDLLIMPORT
#define EPHCOMFCDLLIMPEXP_DATA( type ) EPHCOMDLLIMPORT type
#endif
#endif // __EPHCOM_DLL_H
This diff is collapsed.
This diff is collapsed.
#include <iostream>
#include"StrayLight.h"
using namespace std;
int main()
{
double ju=2.4608437604166665e+06;//观测时的儒略时
//以下所有位置和方向均为赤道坐标系三维坐标
double sat[3] = {5873.752, -1642.066, 2896.744};//卫星所处位置
double ob[3]={0.445256,0.76061,-0.47246};//观测方向
//double py[3]={0.484277, 0.239253,0.841565};//某合理Y轴
double py1[3],py2[3];//未知的Y轴
ComposeY(ob,py1,py2);//计算Y轴
double E[7];//7谱段的辐照度
Init();//初始化
Calculate(ju,sat,ob,py1,E);//计算
Calculate(ju,sat,ob,py2,E);
return 0;
}
This diff is collapsed.
compile StrayLight.cpp and generate .so file:
Linux:
g++ -fPIC -shared StrayLight.cpp ephcom_wrapper.cpp ephcom.c gnulliver.c -o libstraylight.so
Mac:
g++ -fPIC -shared StrayLight.cpp ephcom_wrapper.cpp ephcom.c gnulliver.c -o libstraylight.dylib
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment