#include "lane/GM_SubLibrary.hpp"
void GM_CartesianToSpherical(GMtype_CoordCartesian CoordCartesian, GMtype_CoordSpherical *CoordSpherical)
{
/*This function converts a point from Cartesian coordinates into spherical coordinates*/
double X, Y, Z;
X = CoordCartesian.x;
Y = CoordCartesian.y;
Z = CoordCartesian.z;
CoordSpherical->r = sqrt(X * X + Y * Y + Z * Z);
CoordSpherical->phig = RAD2DEG(asin(Z / (CoordSpherical->r)));
CoordSpherical->lambda = RAD2DEG(atan2(Y, X));
} /*GM_CartesianToSpherical*/
void GM_CORD (GMtype_CoordGeodetic location, GMtype_Date *date, GMtype_Ellipsoid Ellip, GMtype_Data g0d, GMtype_Data g1d, GMtype_Data h1d, GMtype_CoordDipole *CoordDipole)
{
/*This function can be used in a wrapper file to call all of the necessary functions to convert from geocentric coordinates to geomagnetic coordinates for a given time*/
GMtype_CoordSpherical CoordSpherical, DipoleSpherical;
GMtype_CoordCartesian CoordCartesian, DipoleCartesian;
GMtype_Model Model;
GMtype_Pole Pole;
GM_DateToYear(date);
GM_GeodeticToSpherical(Ellip, location, &CoordSpherical);
GM_SphericalToCartesian(CoordSpherical, &CoordCartesian);
GM_TimeAdjustCoefs(*date, g0d, g1d, h1d, &Model);
GM_PoleLocation(Model, &Pole);
GM_EarthCartToDipoleCartCD(Pole, CoordCartesian, &DipoleCartesian);
GM_CartesianToSpherical(DipoleCartesian, &DipoleSpherical);
CoordDipole->phi = DipoleSpherical.phig;
CoordDipole->lambda = DipoleSpherical.lambda;
} /*GM_CORD*/
int GM_DateToYear(GMtype_Date *CalendarDate)
{
/*This function converts a Date into Decimal years. It was taken from the WMM SubLibrary on the NGDC website*/
int temp = 0; /*Total number of days */
int MonthDays[13];
int ExtraDay = 0;
int i;
if((CalendarDate->Year%4 == 0 && CalendarDate->Year%100 != 0) || CalendarDate->Year%400 == 0)
ExtraDay = 1;
MonthDays[0] = 0;
MonthDays[1] = 31;
MonthDays[2] = 28 + ExtraDay;
MonthDays[3] = 31;
MonthDays[4] = 30;
MonthDays[5] = 31;
MonthDays[6] = 30;
MonthDays[7] = 31;
MonthDays[8] = 31;
MonthDays[9] = 30;
MonthDays[10] = 31;
MonthDays[11] = 30;
MonthDays[12] = 31;
for(i = 1; i <= CalendarDate->Month; i++)
temp+=MonthDays[i-1];
temp+=CalendarDate->Day;
CalendarDate->DayNumber = temp;
CalendarDate->DecimalYear = CalendarDate->Year + (temp-1)/(365.0 + ExtraDay);
return TRUE;
} /*GM_DateToYear*/
void GM_EarthCartToDipoleCartCD(GMtype_Pole Pole, GMtype_CoordCartesian EarthCoord, GMtype_CoordCartesian *DipoleCoords)
{
/*This function converts from Earth centered cartesian coordinates to dipole centered cartesian coordinates*/
double X, Y, Z, CosPhi, SinPhi, CosLambda, SinLambda;
CosPhi = cos(DEG2RAD(Pole.phi));
SinPhi = sin(DEG2RAD(Pole.phi));
CosLambda = cos(DEG2RAD(Pole.lambda));
SinLambda = sin(DEG2RAD(Pole.lambda));
X = EarthCoord.x;
Y = EarthCoord.y;
Z = EarthCoord.z;
/*These equations are taken from a document by Wallace H. Campbell*/
DipoleCoords->x = X * CosPhi * CosLambda + Y * CosPhi * SinLambda - Z * SinPhi;
DipoleCoords->y = -X * SinLambda + Y * CosLambda;
DipoleCoords->z = X * SinPhi * CosLambda + Y * SinPhi * SinLambda + Z * CosPhi;
} /*GM_EarthCartToDipoleCartCD*/
void GM_GeodeticToSpherical(GMtype_Ellipsoid Ellip, GMtype_CoordGeodetic CoordGeodetic, GMtype_CoordSpherical *CoordSpherical)
{
double CosLat, SinLat, rc, xp, zp; /*all local variables */
/*
** Convert geodetic coordinates, (defined by the WGS-84
** reference ellipsoid), to Earth Centered Earth Fixed Cartesian
** coordinates, and then to spherical coordinates.
*/
CosLat = cos(DEG2RAD(CoordGeodetic.phi));
SinLat = sin(DEG2RAD(CoordGeodetic.phi));
/* compute the local radius of curvature on the WGS-84 reference ellipsoid */
rc = Ellip.a / sqrt(1.0 - Ellip.epssq * SinLat * SinLat);
/* compute ECEF Cartesian coordinates of specified point (for longitude=0) */
xp = (rc + CoordGeodetic.HeightAboveEllipsoid) * CosLat;
zp = (rc*(1.0 - Ellip.epssq) + CoordGeodetic.HeightAboveEllipsoid) * SinLat;
/* compute spherical radius and angle lambda and phi of specified point */
CoordSpherical->r = sqrt(xp * xp + zp * zp);
CoordSpherical->phig = RAD2DEG(asin(zp / CoordSpherical->r)); /* geocentric latitude */
CoordSpherical->lambda = CoordGeodetic.lambda; /* longitude */
} /*GM_GeodeticToSpherical*/
void GM_GetUserInput(GMtype_CoordGeodetic *location, GMtype_Date *date)
{
/*This function is used in the GMCORD program to get the users input data through the console*/
char buffer[20];
int flag; /*This is a loop control that allows the program to check the validity of the users input*/
flag = 1;
while(flag == 1)
{
printf("ENTER the geographic decimal latitude (+ North; - South)? ");
fgets(buffer, 20, stdin);
sscanf(buffer, "%lf", &location->phi);
flag = 0;
if(location->phi <-90 || location->phi > 90)
{
printf("Input must be in decimal degrees, between -90 and 90\n");
flag = 1;
}
strcpy(buffer, "");
}
flag = 1;
while(flag == 1)
{
printf("ENTER the geographic longitude (+ East; - West)? ");
fgets(buffer, 20, stdin);
sscanf(buffer, "%lf", &location->lambda);
flag = 0;
if(location->lambda < -180 || location->lambda > 360)
{
printf("Input must be in decimal degrees, between -180 and 360\n");
flag = 1;
}
strcpy(buffer, "");
}
flag = 1;
while(flag == 1)
{
printf("ENTER the analysis year (1900 to 2015)? ");
fgets(buffer, 20, stdin);
sscanf(buffer, "%d", &date->Year);
flag = 0;
if(date->Year < 1900 || date->Year > 2015)
{
printf("Input must be in integer years between 1900 and 2015\n");
flag = 1;
}
strcpy(buffer, "");
}
flag = 1;
while(flag == 1)
{
printf("Month number (1 to 12)? ");
fgets(buffer, 20, stdin);
sscanf(buffer, "%d", &date->Month);
flag = 0;
if(date->Month < 1 || date->Month > 12)
{
printf("Input must be an integer from 1 to 12.\n");
flag = 1;
}
strcpy(buffer, "");
}
flag = 1;
while(flag == 1)
{
printf("Day in month (1 to 31)? ");
fgets(buffer, 20, stdin);
sscanf(buffer, "%d", &date->Day);
flag = 0;
if(date->Day < 1 || date->Day > 31)
{
printf("Input must be an integer from 1 to 31.\n");
flag = 1;
}
strcpy(buffer, "");
}
} /*GM_GetUserInput*/
void GM_PoleLocation(GMtype_Model Model, GMtype_Pole *Pole)
{
/*This function finds the location of the north magnetic pole in spherical coordinates. The equations are
**from Wallace H. Campbell's Introduction to Geomagnetic Fields*/
Pole->phi = RAD2DEG(-atan(sqrt(Model.h1 * Model.h1 + Model.g1 * Model.g1)/Model.g0));
Pole->lambda = RAD2DEG(atan(Model.h1/Model.g1));
} /*GM_PoleLocation*/
void GM_PrintUserData(GMtype_CoordGeodetic location, GMtype_Date date, GMtype_CoordDipole DipLocation)
{
/*This function prints the users data to the console*/
printf("Centered Geomagnetic Dipole location at %lf, %lf:\n", location.phi, location.lambda);
if(DipLocation.phi >= 0)
printf("\t+%.2lf deg geomag lat. ", DipLocation.phi);
else
printf("\t%.2lf deg geomag lat. ", DipLocation.phi);
if(DipLocation.lambda >= 0)
printf("and +%.2lf deg E. geomag long.\n", DipLocation.lambda);
else
printf("and %.2lf deg E. geomag long.\n", DipLocation.lambda);
} /*GM_PrintUserData*/
void GM_ScanIGRF(GMtype_Data *G0, GMtype_Data *G1, GMtype_Data *H1)
{
/*This function scans inputs G
奋斗奋斗再奋斗的ajie
- 粉丝: 1199
- 资源: 2908
最新资源
- 单个IO口检测多个按键
- 汇川EASY32x固件6.3.0.0
- 高分成品毕业设计《基于SSM(Spring、Spring MVC、MyBatis)+MySQL开发个人财务管理系统》+源码+论文+说明文档+数据库
- 高分成品毕业设计《基于SSM(Spring、Spring MVC、MyBatis)+MySQL开发B2C电子商务平台》+源码+论文+说明文档+数据库
- HKJC_3in1_TR_PROD_L3.0R1An_Build10229.apk
- 高分成品毕业设计《基于SSM(Spring、Spring MVC、MyBatis)+MySQL开发高校实验室资源综合管理系统》+源码+论文+说明文档+数据库
- 高分成品毕业设计《基于SSM(Spring、Spring MVC、MyBatis)+MySQL开发校医务系统》+源码+论文+说明文档+数据库
- 硕博士毕业率历史数据(2003-2022年).xlsx
- 高分成品毕业设计《基于SSM(Spring、Spring MVC、MyBatis)+MySQL开发供电公司安全生产考试系统》+源码+论文+说明文档+数据库
- 本科生毕业设计.doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈