mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-05 00:41:19 -05:00
50846fe90a
This allows writable files to be located in the "correct" location for each platform rather than in the directory of the executable which, in general, is not recommended or allowed in some cases. A preprocessor macro WSJT_STANDARD_FILE_LOCATIONS is used to switch be tween old and new functionality, currently it is on by default. It can be turned off by defining it to a false value (0) or more simply with cmake-gui setting the option with the same name. JTAlert can only work with the old non-standard file locations until Laurie VK3AMA chooses to support the new file locations. Even if the above is not enabled; the QSettings file is written to a user specific location so it will be shared by all instances of the program (i.e. across upgrades). See below for multiple concurrent instance support changes. Added a command line parser module for Fortran. Added 'lib/options.f90' to facilitate more complex argument passing to jt9 to cover explicit file locations. Changed the way multiple concurrent instances are handled. This is to allow the program to be run multiple times from the same installation directory. A new wsjtx command line optional argument is available "-r" or "--rig" which enables multiple concurrent instance support. The parameter of the new option is a unique name signifying a rig or equivalent. The name is used as the shared memory segment key and in window titles. The name is also used to access unique settings files and writable data files like ALL.TXT and log files. No attempt has been made to share these files between concurrent instances. If "-r" or "--rig" is used without a parameter it still enables multiple concurrent instance support for that instance. All instances must use a unique parameter, one of which may be empty. The rig name is appended the QCoreApplication::applicationName() for convenient usage like window titles. Set non Qt locale to "C". This ensures that C library functions give consistent results whatever the system locale is set to. QApplication follows the system locale as before. Thus using QApplication and its descendants like widgets and QString for all user visible formating will give correct l10n and using C/C++ library will give consistent formatting across locales. Added top level C++ exception handling to main.cpp. Because the new transceiver framework uses exceptions internally, the main function now handles any exceptions that aren't caught. Retired devsetup, replaced with Configuration. Configuration is a class that encapsulates most of the configuration behavior. Because rig configuration is so closely coupled with rig operation, Configuration serves as a proxy for access to the rig control functions. See Configuration.hpp for more details of the Configuration interface. Menu changes. Various checkable menu actions moved from main menu to the Configuration dialog. The whole settings menu has been retired with the single "Settings..." action moved to the file menu for consistency on Mac where it appears as "Preferences" in line with Mac guidelines. New data models for data used by the application. ADIF amateur band parameters, free text message macros, spot working frequencies and, station information (station descriptions and transverter offsets per band) each implement the QAbstractItemModel interface allowing them to be used directly with Qt view widgets (Bands.hpp, FrequencyList.hpp and, StationList.hpp). Configuration manages maintenance of an instance of all but the former of the above models. The ADIF band model is owned by Configuration but requires no user maintenance as it is immutable. Band combo box gets more functionality. This widget is now an editable QComboBox with some extra input capabilities. The popup list is still the list of spot working frequencies, now showing the actual frequency decorated with the band name. This allows multiple spot frequencies on a band if required. The line edit allows direct frequency entry in mega-Hertz with a completer built in to suggest the available spot working frequencies. It also allows band name entry where the first available spot working frequency is selected. Recognized band names are those that are defined by the ADIF specification and can be found in in the implementation of the ADIF bands model (Bands.cpp). If an out of band frequency is chosen, the line edit shows a warning red background and the text "OOB". Out of band is only defined by the ADIF band limits which in general are wider than any entities regulations. Qt 5.2 now supports default audio i/p and o/p devices. These devices are placeholders for whatever the user defines as the default device. Because of this they need special treatment as the actual device used is chosen at open time behind the scenes. Close-down behavior is simplified. The close-down semantics were broken such that some objects were not being shut down cleanly, this required amendments to facilitate correct close down of threads. User font selection added to Configuration UI. Buttons to set the application font and the font for the band and Rx frequency activity widgets have been added to the Configuration UI to replace the file based font size control. Free text macros now selected directly. The free text line edit widgets are now editable combo boxes that have the current free text macro definitions as their popup list. The old context menu to do this has been retired. Astronomical data window dynamically formatted and has font a chooser. This window is now autonomous, has its own font chooser and, dynamically resizes to cover the contents. Double click to Tx enabled now has its own widget in the status bar. QDir used for portable path and file name handling throughout. The "Monitor", "Decode", "Enable Tx" and, "Tune" buttons are now checkable. Being checkable allows these buttons control their own state and rendering. Calls to PSK Reporter interface simplified. In mainwindow.cpp the calls to this interface are rationalized to just 3 locations. Manipulation of ALL.TXT simplified. Moved, where possible, to common functions. Elevated frequency types to be Qt types. Frequency and FrequencyDelta defined as Qt types in their meta-type system (Radio.hpp). They are integral types for maximum accuracy. Re-factored rig control calls in mainwindow.cpp. The new Configuration proxy access to rig control required many changes (mostly simplifications) to the MainWindow rig control code. Some common code has been gathered in member functions like qsy(), monitor(), band_changed() and auto_tx_mode(). Rig control enhancements. The rig control for clients interface is declared as an abstract interface (See Transceiver.hpp). Concrete implementations of this interface are provided for the Hamlib rig control library, DX Lab Suite Commander via a TCP/IP command channel, Ham Radio Deluxe also via a TCP/IP command channel and, OmniRig via its Windows COM server interface. Concrete Transceiver implementations are expected to be moved to a separate thread after construction since many operations are blocking and not suitable for running in a GUI thread. To facilitate this all instantiation of concrete Transceiver instances are handled by Configuration using a factory class (TransceiverFactory) for configuration parameter based instantiation. Various common functionality shared by different rig interface implementations are factored out into helper base classes that implement or delegate parts of the Transceiver interface. They are TransceiverBase which caches state to minimize expensive rig commands, it also maps the Transceiver interface into a more convenient form for implementation (template methods). PollingTransceiver that provides a state polling mechanism that only reports actual changes. EmulateSplitTransceiver that provides split operation by QSYing on PTT state changes. EmulateSplitTransceiver can be used with any implementation as it follows the GoF Decorator pattern and can wrap any Transceiver implementation. OmniRigTransceiver is derived directly from TransceiverBase since it doesn't require polling due to its asynchronous nature. OmniRigTransceiver is only built on Windows as it is a COM server client. To build it you must first install the OmniRig client on the development machine (http://www.dxatlas.com/omnirig/). DXLabSuiteCommanderTransceiver derives from PollingTransceiver since it is a synchronous communications channel. No third party library is required for this interface. HRDTransceiver also derives from PollingTransceiver. The HRD interface library has been reverse engineered to provide functionality with all available versions of HRD. No third party libraries are required. HamlibTransceiver likewise derives from PollingTransceiver since the Hamlib asynchronous interface is non-functional. Although this class will interface with the release version of Hamlib (1.2.15.3); for correct operation on most rigs it needs to run with the latest master branch code of Hamlib. During development many changes to Hamlib have been submitted and accepted, hence this requirement. Hamlib source can be obtained from git://git.code.sf.net/p/hamlib/code and at the time of writing he master branch was at SHA 6e4432. The Hamlib interface directly calls the "C" interface and the modified rigclass.{h,cpp} files have been retired. There is a rig type selection of "None" which may be used for non-CAT rigs, this is actually a connection to the dummy Hamlib device. PollingTransvceiver derives from TransceiverBase and TransceiverBase derives from the Transceiver interface. Each interface implementation offers some possibility of PTT control via a different serial port than the CAT port. We also support PTT control directly via a second serial port. This is done by delegating to a dummy Hamlib instance which is only used for PTT control. This means that DXLabSuiteCommanderTransceiver, HRDTransceiver and OmniRigTransceiver always wrap a dummy HamlibTransceiver instance. The factory class TransceiverFactory manages all these constructional complexities. Serial port selection combo boxes are now editable with a manually entered value being saved to the settings file. This allows a non-standard port device to be used without having to edit the settings file manually. For TCP/IP network CAT interfaces; the network address and port may be specified allowing the target device to be located on a different machine from the one running wsjtx if required. The default used when the address field is left blank is the correct one for normal usage on the local host. Selecting a polling interval of zero is no longer possible, this is because the rig control capability can no longer support one way connection. This is in line with most other CAT control software. In the Configuration dialog there are options to select split mode control by the software and mode control by the software. For the former "None", "Rig" and "Fake it" are available, for the latter "None", "USB" and, "Data" are available. Because tone generation is implicitly linked to split mode operation; it is no longer possible to have the software in split mode and the rig not or vice versa. This may mean some rigs cannot be used in split mode and therefore not in dual JT65+JT9 until issues with CAT control with that rig are resolved. Single mode with VOX keying and no CAT control are still possible so even the most basic transceiver setup is supported as before. Configuration now supports a frequency offset suitable for transverter operation. The station details model (StationList.hpp) includes a column to store an offset for each band if required. CMake build script improvements. The CMakeLists.txt from the 'lib' directory has been retired with its contents merged into the top level CMakeLists.txt. Install target support has been greatly improved with the Release build configuration now building a fully standalone installation on Mac and Windows. The Debug configuration still builds an installation that has environment dependencies for external libraries, which is desirable for testing and debugging. Package target support is largely complete for Mac, Windows and, Linux, it should be possible to build release installers directly from CMake/CPack. Cmake FindXXXX.cmake modules have been added to improve the location of fftw-3 and Hamlib packages. Version numbers are now stored in Versions.cmake and work in concert with automatic svn revision lookup during build. The version string becomes 'rlocal'± if there are any uncommitted changes in the build source tree. Moved resource like files to Qt resources. Because location of resource files (when they cannot go into the installation directory because of packaging rules) is hard to standardize. I have used the Qt resource system for all ancillary data files. Some like kvasd.dat are dumped out to the temp (working directory) because they are accessed by an external program, others like the audio samples are copied out so they appear in the data directory under the default save directory. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3929 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
519 lines
16 KiB
C
519 lines
16 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <math.h>
|
|
|
|
#define RADS 0.0174532925199433
|
|
#define DEGS 57.2957795130823
|
|
#define TPI 6.28318530717959
|
|
#define PI 3.1415927
|
|
|
|
/* ratio of earth radius to astronomical unit */
|
|
#define ER_OVER_AU 0.0000426352325194252
|
|
|
|
/* all prototypes here */
|
|
|
|
double getcoord(int coord);
|
|
void getargs(int argc, char *argv[], int *y, int *m, double *tz, double *glong, double *glat);
|
|
double range(double y);
|
|
double rangerad(double y);
|
|
double days(int y, int m, int dn, double hour);
|
|
double days_(int *y, int *m, int *dn, double *hour);
|
|
void moonpos(double, double *, double *, double *);
|
|
void sunpos(double , double *, double *, double *);
|
|
double moontransit(int y, int m, int d, double timezone, double glat, double glong, int *nt);
|
|
double atan22(double y, double x);
|
|
double epsilon(double d);
|
|
void equatorial(double d, double *lon, double *lat, double *r);
|
|
void ecliptic(double d, double *lon, double *lat, double *r);
|
|
double gst(double d);
|
|
void topo(double lst, double glat, double *alp, double *dec, double *r);
|
|
double alt(double glat, double ha, double dec);
|
|
void libration(double day, double lambda, double beta, double alpha, double *l, double *b, double *p);
|
|
void illumination(double day, double lra, double ldec, double dr, double sra, double sdec, double *pabl, double *ill);
|
|
int daysinmonth(int y, int m);
|
|
int isleap(int y);
|
|
void tmoonsub_(double *day, double *glat, double *glong, double *moonalt,
|
|
double *mrv, double *l, double *b, double *paxis);
|
|
|
|
static const char
|
|
*usage = " Usage: tmoon date[yyyymm] timz[+/-h.hh] long[+/-dddmm] lat[+/-ddmm]\n"
|
|
"example: tmoon 200009 0 -00155 5230\n";
|
|
|
|
/*
|
|
getargs() gets the arguments from the command line, does some basic error
|
|
checking, and converts arguments into numerical form. Arguments are passed
|
|
back in pointers. Error messages print to stderr so re-direction of output
|
|
to file won't leave users blind. Error checking prints list of all errors
|
|
in a command line before quitting.
|
|
*/
|
|
void getargs(int argc, char *argv[], int *y, int *m, double *tz,
|
|
double *glong, double *glat) {
|
|
|
|
int date, latitude, longitude;
|
|
int mflag = 0, yflag = 0, longflag = 0, latflag = 0, tzflag = 0;
|
|
int longminflag = 0, latminflag = 0, dflag = 0;
|
|
|
|
/* if not right number of arguments, then print example command line */
|
|
|
|
if (argc !=5) {
|
|
fprintf(stderr, usage);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
date = atoi(argv[1]);
|
|
*y = date / 100;
|
|
*m = date - *y * 100;
|
|
*tz = (double) atof(argv[2]);
|
|
longitude = atoi(argv[3]);
|
|
latitude = atoi(argv[4]);
|
|
*glong = RADS * getcoord(longitude);
|
|
*glat = RADS * getcoord(latitude);
|
|
|
|
/* set a flag for each error found */
|
|
|
|
if (*m > 12 || *m < 1) mflag = 1;
|
|
if (*y > 2500) yflag = 1;
|
|
if (date < 150001) dflag = 1;
|
|
if (fabs((float) *glong) > 180 * RADS) longflag = 1;
|
|
if (abs(longitude) % 100 > 59) longminflag = 1;
|
|
if (fabs((float) *glat) > 90 * RADS) latflag = 1;
|
|
if (abs(latitude) % 100 > 59) latminflag = 1;
|
|
if (fabs((float) *tz) > 12) tzflag = 1;
|
|
|
|
/* print all the errors found */
|
|
|
|
if (dflag == 1) {
|
|
fprintf(stderr, "date: dates must be in form yyyymm, gregorian, and later than 1500 AD\n");
|
|
}
|
|
if (yflag == 1) {
|
|
fprintf(stderr, "date: too far in future - accurate from 1500 to 2500\n");
|
|
}
|
|
if (mflag == 1) {
|
|
fprintf(stderr, "date: month must be in range 0 to 12, eg - August 2000 is entered as 200008\n");
|
|
}
|
|
if (tzflag == 1) {
|
|
fprintf(stderr, "timz: must be in range +/- 12 hours, eg -6 for Chicago\n");
|
|
}
|
|
if (longflag == 1) {
|
|
fprintf(stderr, "long: must be in range +/- 180 degrees\n");
|
|
}
|
|
if (longminflag == 1) {
|
|
fprintf(stderr, "long: last two digits are arcmin - max 59\n");
|
|
}
|
|
if (latflag == 1) {
|
|
fprintf(stderr, " lat: must be in range +/- 90 degrees\n");
|
|
}
|
|
if (latminflag == 1) {
|
|
fprintf(stderr, " lat: last two digits are arcmin - max 59\n");
|
|
}
|
|
|
|
/* quits if one or more flags set */
|
|
|
|
if (dflag + mflag + yflag + longflag + latflag + tzflag + longminflag + latminflag > 0) {
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
returns coordinates in decimal degrees given the
|
|
coord as a ddmm value stored in an integer.
|
|
*/
|
|
double getcoord(int coord) {
|
|
int west = 1;
|
|
double glg, deg;
|
|
if (coord < 0) west = -1;
|
|
glg = fabs((double) coord/100);
|
|
deg = floor(glg);
|
|
glg = west* (deg + (glg - deg)*100 / 60);
|
|
return(glg);
|
|
}
|
|
|
|
/*
|
|
days() takes the year, month, day in the month and decimal hours
|
|
in the day and returns the number of days since J2000.0.
|
|
Assumes Gregorian calendar.
|
|
*/
|
|
double days(int y, int m, int d, double h) {
|
|
int a, b;
|
|
double day;
|
|
|
|
/*
|
|
The lines below work from 1900 march to feb 2100
|
|
a = 367 * y - 7 * (y + (m + 9) / 12) / 4 + 275 * m / 9 + d;
|
|
day = (double)a - 730531.5 + hour / 24;
|
|
*/
|
|
|
|
/* These lines work for any Gregorian date since 0 AD */
|
|
if (m ==1 || m==2) {
|
|
m +=12;
|
|
y -= 1;
|
|
}
|
|
a = y / 100;
|
|
b = 2 - a + a/4;
|
|
day = floor(365.25*(y + 4716)) + floor(30.6001*(m + 1))
|
|
+ d + b - 1524.5 - 2451545 + h/24;
|
|
return(day);
|
|
}
|
|
double days_(int *y0, int *m0, int *d0, double *h0)
|
|
{
|
|
return days(*y0,*m0,*d0,*h0);
|
|
}
|
|
|
|
/*
|
|
Returns 1 if y a leap year, and 0 otherwise, according
|
|
to the Gregorian calendar
|
|
*/
|
|
int isleap(int y) {
|
|
int a = 0;
|
|
if(y % 4 == 0) a = 1;
|
|
if(y % 100 == 0) a = 0;
|
|
if(y % 400 == 0) a = 1;
|
|
return(a);
|
|
}
|
|
|
|
/*
|
|
Given the year and the month, function returns the
|
|
number of days in the month. Valid for Gregorian
|
|
calendar.
|
|
*/
|
|
int daysinmonth(int y, int m) {
|
|
int b = 31;
|
|
if(m == 2) {
|
|
if(isleap(y) == 1) b= 29;
|
|
else b = 28;
|
|
}
|
|
if(m == 4 || m == 6 || m == 9 || m == 11) b = 30;
|
|
return(b);
|
|
}
|
|
|
|
/*
|
|
moonpos() takes days from J2000.0 and returns ecliptic coordinates
|
|
of moon in the pointers. Note call by reference.
|
|
This function is within a couple of arcminutes most of the time,
|
|
and is truncated from the Meeus Ch45 series, themselves truncations of
|
|
ELP-2000. Returns moon distance in earth radii.
|
|
Terms have been written out explicitly rather than using the
|
|
table based method as only a small number of terms is
|
|
retained.
|
|
*/
|
|
void moonpos(double d, double *lambda, double *beta, double *rvec) {
|
|
double dl, dB, dR, L, D, M, M1, F, e, lm, bm, rm, t;
|
|
|
|
t = d / 36525;
|
|
|
|
L = range(218.3164591 + 481267.88134236 * t) * RADS;
|
|
D = range(297.8502042 + 445267.1115168 * t) * RADS;
|
|
M = range(357.5291092 + 35999.0502909 * t) * RADS;
|
|
M1 = range(134.9634114 + 477198.8676313 * t - .008997 * t * t) * RADS;
|
|
F = range(93.27209929999999 + 483202.0175273 * t - .0034029*t*t)*RADS;
|
|
e = 1 - .002516 * t;
|
|
|
|
dl = 6288774 * sin(M1);
|
|
dl += 1274027 * sin(2 * D - M1);
|
|
dl += 658314 * sin(2 * D);
|
|
dl += 213618 * sin(2 * M1);
|
|
dl -= e * 185116 * sin(M);
|
|
dl -= 114332 * sin(2 * F) ;
|
|
dl += 58793 * sin(2 * D - 2 * M1);
|
|
dl += e * 57066 * sin(2 * D - M - M1) ;
|
|
dl += 53322 * sin(2 * D + M1);
|
|
dl += e * 45758 * sin(2 * D - M);
|
|
dl -= e * 40923 * sin(M - M1);
|
|
dl -= 34720 * sin(D) ;
|
|
dl -= e * 30383 * sin(M + M1) ;
|
|
dl += 15327 * sin(2 * D - 2 * F) ;
|
|
dl -= 12528 * sin(M1 + 2 * F);
|
|
dl += 10980 * sin(M1 - 2 * F);
|
|
lm = rangerad(L + dl / 1000000 * RADS);
|
|
|
|
dB = 5128122 * sin(F);
|
|
dB += 280602 * sin(M1 + F);
|
|
dB += 277693 * sin(M1 - F);
|
|
dB += 173237 * sin(2 * D - F);
|
|
dB += 55413 * sin(2 * D - M1 + F);
|
|
dB += 46271 * sin(2 * D - M1 - F);
|
|
dB += 32573 * sin(2 * D + F);
|
|
dB += 17198 * sin(2 * M1 + F);
|
|
dB += 9266 * sin(2 * D + M1 - F);
|
|
dB += 8822 * sin(2 * M1 - F);
|
|
dB += e * 8216 * sin(2 * D - M - F);
|
|
dB += 4324 * sin(2 * D - 2 * M1 - F);
|
|
bm = dB / 1000000 * RADS;
|
|
|
|
dR = -20905355 * cos(M1);
|
|
dR -= 3699111 * cos(2 * D - M1);
|
|
dR -= 2955968 * cos(2 * D);
|
|
dR -= 569925 * cos(2 * M1);
|
|
dR += e * 48888 * cos(M);
|
|
dR -= 3149 * cos(2 * F);
|
|
dR += 246158 * cos(2 * D - 2 * M1);
|
|
dR -= e * 152138 * cos(2 * D - M - M1) ;
|
|
dR -= 170733 * cos(2 * D + M1);
|
|
dR -= e * 204586 * cos(2 * D - M);
|
|
dR -= e * 129620 * cos(M - M1);
|
|
dR += 108743 * cos(D);
|
|
dR += e * 104755 * cos(M + M1);
|
|
dR += 79661 * cos(M1 - 2 * F);
|
|
rm = 385000.56 + dR / 1000;
|
|
|
|
*lambda = lm;
|
|
*beta = bm;
|
|
/* distance to Moon must be in Earth radii */
|
|
*rvec = rm / 6378.14;
|
|
}
|
|
|
|
/*
|
|
topomoon() takes the local siderial time, the geographical
|
|
latitude of the observer, and pointers to the geocentric
|
|
equatorial coordinates. The function overwrites the geocentric
|
|
coordinates with topocentric coordinates on a simple spherical
|
|
earth model (no polar flattening). Expects Moon-Earth distance in
|
|
Earth radii. Formulas scavenged from Astronomical Almanac 'low
|
|
precision formulae for Moon position' page D46.
|
|
*/
|
|
|
|
void topo(double lst, double glat, double *alp, double *dec, double *r) {
|
|
double x, y, z, r1;
|
|
x = *r * cos(*dec) * cos(*alp) - cos(glat) * cos(lst);
|
|
y = *r * cos(*dec) * sin(*alp) - cos(glat) * sin(lst);
|
|
z = *r * sin(*dec) - sin(glat);
|
|
r1 = sqrt(x*x + y*y + z*z);
|
|
*alp = atan22(y, x);
|
|
*dec = asin(z / r1);
|
|
*r = r1;
|
|
}
|
|
|
|
/*
|
|
moontransit() takes date, the time zone and geographic longitude
|
|
of observer and returns the time (decimal hours) of lunar transit
|
|
on that day if there is one, and sets the notransit flag if there
|
|
isn't. See Explanatory Supplement to Astronomical Almanac
|
|
section 9.32 and 9.31 for the method.
|
|
*/
|
|
|
|
double moontransit(int y, int m, int d, double tz, double glat, double glong, int *notransit) {
|
|
double hm, ht, ht1, lon, lat, rv, dnew, lst;
|
|
int itcount;
|
|
|
|
ht1 = 180 * RADS;
|
|
ht = 0;
|
|
itcount = 0;
|
|
*notransit = 0;
|
|
do {
|
|
ht = ht1;
|
|
itcount++;
|
|
dnew = days(y, m, d, ht * DEGS/15) - tz/24;
|
|
lst = gst(dnew) + glong;
|
|
/* find the topocentric Moon ra (hence hour angle) and dec */
|
|
moonpos(dnew, &lon, &lat, &rv);
|
|
equatorial(dnew, &lon, &lat, &rv);
|
|
topo(lst, glat, &lon, &lat, &rv);
|
|
hm = rangerad(lst - lon);
|
|
ht1 = rangerad(ht - hm);
|
|
/* if no convergence, then no transit on that day */
|
|
if (itcount > 30) {
|
|
*notransit = 1;
|
|
break;
|
|
}
|
|
}
|
|
while (fabs(ht - ht1) > 0.04 * RADS);
|
|
return(ht1);
|
|
}
|
|
|
|
/*
|
|
Calculates the selenographic coordinates of either the sub Earth point
|
|
(optical libration) or the sub-solar point (selen. coords of centre of
|
|
bright hemisphere). Based on Meeus chapter 51 but neglects physical
|
|
libration and nutation, with some simplification of the formulas.
|
|
*/
|
|
void libration(double day, double lambda, double beta, double alpha, double *l, double *b, double *p) {
|
|
double i, f, omega, w, y, x, a, t, eps;
|
|
t = day / 36525;
|
|
i = 1.54242 * RADS;
|
|
eps = epsilon(day);
|
|
f = range(93.2720993 + 483202.0175273 * t - .0034029 * t * t) * RADS;
|
|
omega = range(125.044555 - 1934.1361849 * t + .0020762 * t * t) * RADS;
|
|
w = lambda - omega;
|
|
y = sin(w) * cos(beta) * cos(i) - sin(beta) * sin(i);
|
|
x = cos(w) * cos(beta);
|
|
a = atan22(y, x);
|
|
*l = a - f;
|
|
|
|
/* kludge to catch cases of 'round the back' angles */
|
|
if (*l < -90 * RADS) *l += TPI;
|
|
if (*l > 90 * RADS) *l -= TPI;
|
|
*b = asin(-sin(w) * cos(beta) * sin(i) - sin(beta) * cos(i));
|
|
|
|
/* pa pole axis - not used for Sun stuff */
|
|
x = sin(i) * sin(omega);
|
|
y = sin(i) * cos(omega) * cos(eps) - cos(i) * sin(eps);
|
|
w = atan22(x, y);
|
|
*p = rangerad(asin(sqrt(x*x + y*y) * cos(alpha - w) / cos(*b)));
|
|
}
|
|
|
|
/*
|
|
Takes: days since J2000.0, eq coords Moon, ratio of moon to sun distance,
|
|
eq coords Sun
|
|
Returns: position angle of bright limb wrt NCP, percentage illumination
|
|
of Sun
|
|
*/
|
|
void illumination(double day , double lra, double ldec, double dr, double sra, double sdec, double *pabl, double *ill) {
|
|
double x, y, phi, i;
|
|
(void)day;
|
|
y = cos(sdec) * sin(sra - lra);
|
|
x = sin(sdec) * cos(ldec) - cos(sdec) * sin(ldec) * cos (sra - lra);
|
|
*pabl = atan22(y, x);
|
|
phi = acos(sin(sdec) * sin(ldec) + cos(sdec) * cos(ldec) * cos(sra-lra));
|
|
i = atan22(sin(phi) , (dr - cos(phi)));
|
|
*ill = 0.5*(1 + cos(i));
|
|
}
|
|
|
|
/*
|
|
sunpos() takes days from J2000.0 and returns ecliptic longitude
|
|
of Sun in the pointers. Latitude is zero at this level of precision,
|
|
but pointer left in for consistency in number of arguments.
|
|
This function is within 0.01 degree (1 arcmin) almost all the time
|
|
for a century either side of J2000.0. This is from the 'low precision
|
|
fomulas for the Sun' from C24 of Astronomical Alamanac
|
|
*/
|
|
void sunpos(double d, double *lambda, double *beta, double *rvec) {
|
|
double L, g, ls, bs, rs;
|
|
|
|
L = range(280.461 + .9856474 * d) * RADS;
|
|
g = range(357.528 + .9856003 * d) * RADS;
|
|
ls = L + (1.915 * sin(g) + .02 * sin(2 * g)) * RADS;
|
|
bs = 0;
|
|
rs = 1.00014 - .01671 * cos(g) - .00014 * cos(2 * g);
|
|
*lambda = ls;
|
|
*beta = bs;
|
|
*rvec = rs;
|
|
}
|
|
|
|
/*
|
|
this routine returns the altitude given the days since J2000.0
|
|
the hour angle and declination of the object and the latitude
|
|
of the observer. Used to find the Sun's altitude to put a letter
|
|
code on the transit time, and to find the Moon's altitude at
|
|
transit just to make sure that the Moon is visible.
|
|
*/
|
|
double alt(double glat, double ha, double dec) {
|
|
return(asin(sin(dec) * sin(glat) + cos(dec) * cos(glat) * cos(ha)));
|
|
}
|
|
|
|
/* returns an angle in degrees in the range 0 to 360 */
|
|
double range(double x) {
|
|
double a, b;
|
|
b = x / 360;
|
|
a = 360 * (b - floor(b));
|
|
if (a < 0)
|
|
a = 360 + a;
|
|
return(a);
|
|
}
|
|
|
|
/* returns an angle in rads in the range 0 to two pi */
|
|
double rangerad(double x) {
|
|
double a, b;
|
|
b = x / TPI;
|
|
a = TPI * (b - floor(b));
|
|
if (a < 0)
|
|
a = TPI + a;
|
|
return(a);
|
|
}
|
|
|
|
/*
|
|
gets the atan2 function returning angles in the right
|
|
order and range
|
|
*/
|
|
double atan22(double y, double x) {
|
|
double a;
|
|
|
|
a = atan2(y, x);
|
|
if (a < 0) a += TPI;
|
|
return(a);
|
|
}
|
|
|
|
/*
|
|
returns mean obliquity of ecliptic in radians given days since
|
|
J2000.0.
|
|
*/
|
|
double epsilon(double d) {
|
|
double t = d/ 36525;
|
|
return((23.4392911111111 - (t* (46.8150 + 0.00059*t)/3600)) *RADS);
|
|
}
|
|
|
|
/*
|
|
replaces ecliptic coordinates with equatorial coordinates
|
|
note: call by reference destroys original values
|
|
R is unchanged.
|
|
*/
|
|
void equatorial(double d, double *lon, double *lat, double * r) {
|
|
double eps, ceps, seps, l, b;
|
|
(void)r;
|
|
|
|
l = *lon;
|
|
b = * lat;
|
|
eps = epsilon(d);
|
|
ceps = cos(eps);
|
|
seps = sin(eps);
|
|
*lon = atan22(sin(l)*ceps - tan(b)*seps, cos(l));
|
|
*lat = asin(sin(b)*ceps + cos(b)*seps*sin(l));
|
|
}
|
|
|
|
/*
|
|
replaces equatorial coordinates with ecliptic ones. Inverse
|
|
of above, but used to find topocentric ecliptic coords.
|
|
*/
|
|
void ecliptic(double d, double *lon, double *lat, double * r) {
|
|
double eps, ceps, seps, alp, dec;
|
|
(void)r;
|
|
|
|
alp = *lon;
|
|
dec = *lat;
|
|
eps = epsilon(d);
|
|
ceps = cos(eps);
|
|
seps = sin(eps);
|
|
*lon = atan22(sin(alp)*ceps + tan(dec)*seps, cos(alp));
|
|
*lat = asin(sin(dec)*ceps - cos(dec)*seps*sin(alp));
|
|
}
|
|
|
|
/*
|
|
returns the siderial time at greenwich meridian as
|
|
an angle in radians given the days since J2000.0
|
|
*/
|
|
double gst( double d) {
|
|
double t = d / 36525;
|
|
double theta;
|
|
theta = range(280.46061837 + 360.98564736629 * d + 0.000387933 * t * t);
|
|
return(theta * RADS);
|
|
}
|
|
|
|
void tmoonsub_(double *day, double *glat, double *glong, double *moonalt,
|
|
double *mrv, double *l, double *b, double *paxis)
|
|
{
|
|
double mlambda, mbeta;
|
|
double malpha, mdelta;
|
|
double lst, mhr;
|
|
double tlambda, tbeta, trv;
|
|
|
|
lst = gst(*day) + *glong;
|
|
|
|
/* find Moon topocentric coordinates for libration calculations */
|
|
|
|
moonpos(*day, &mlambda, &mbeta, mrv);
|
|
malpha = mlambda;
|
|
mdelta = mbeta;
|
|
equatorial(*day, &malpha, &mdelta, mrv);
|
|
topo(lst, *glat, &malpha, &mdelta, mrv);
|
|
mhr = rangerad(lst - malpha);
|
|
*moonalt = alt(*glat, mhr, mdelta);
|
|
|
|
/* Optical libration and Position angle of the Pole */
|
|
|
|
tlambda = malpha;
|
|
tbeta = mdelta;
|
|
trv = *mrv;
|
|
ecliptic(*day, &tlambda, &tbeta, &trv);
|
|
libration(*day, tlambda, tbeta, malpha, l, b, paxis);
|
|
}
|