From 77a64411e72b589db8ae4337fc148b61e9ad1f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20P=2E?= Date: Sun, 28 Jul 2024 12:54:41 +0200 Subject: [PATCH] Add some Earth-related functions + bool in jd --- doxygen.conf => Doxyfile | 0 src/earth.h | 73 ++++++++++++++++++++++++++++++++++++++++ src/julianday.h | 20 ++++++++--- 3 files changed, 88 insertions(+), 5 deletions(-) rename doxygen.conf => Doxyfile (100%) create mode 100644 src/earth.h diff --git a/doxygen.conf b/Doxyfile similarity index 100% rename from doxygen.conf rename to Doxyfile diff --git a/src/earth.h b/src/earth.h new file mode 100644 index 0000000..68e4d01 --- /dev/null +++ b/src/earth.h @@ -0,0 +1,73 @@ +/** @file earth.h + @brief Functions related to Earth's properties + + From "Astronomical Algorithms", Chapter 10 _The Earth's Globe_ +*/ +#include +#include + +/** +* @struct +* A representation of the Earth +* with some geometrical properties +*/ +struct Earth { + double a; /*!< The Earth's equatorial radius in km */ + double f; /*!< The Earth's flattening */ + double b; /*!< The Earth's polar radius in km */ + double e; /*!< The eccentricity of Earth's meridian */ +}; + +/** +* @struct +* Representation of geographical +* latitude +*/ +struct Latitude { + short degrees; + short arcmins; + double arcsecs; +}; +/** +* @struct +* Representation of a location +* on the Earth's surface +*/ +struct Location { + struct Latitude lat; /*!< The location's geographical latitude */ + double h; /*!< Observer's height above sea level in m */ + double r_sin_phi_p; /*!< Earth's radius times sin(geocentric latitude) */ + double r_cos_phi_p; /*!< Earth's radius times cos(geocentric latitude) */ +}; + +struct Earth set_earth_values(struct Earth * earth); +double lat_to_dec(struct Latitude lat); +struct Latitude dec_to_lat(double dec_lat); +struct Location set_location_params(struct Location * loc); +/** +* @fn +* Initializes an Earth structure +* @param *earth The Earth struct pointer +*/ +struct Earth set_earth_values(struct Earth * earth) { + earth->a = 6378.14; + earth->f = 1 / 298.257; + double f = earth->f; + earth->b = earth->a * (1 - earth->f); + earth->e = sqrt(2*f - f*f); + + return *earth; +} +/** +* @fn +* Convert Latitude to decimal degrees +* @param lat The Latitude struct (sessagesimal) +* @returns The converted Latitude number +*/ +double lat_to_dec(struct Latitude lat) { + double dec_minutes = (double)lat.arcmins / 60.0; + double dec_seconds = lat.arcsecs / 3600; + + return lat.degrees + dec_minutes + dec_seconds; +} + diff --git a/src/julianday.h b/src/julianday.h index 15feabc..4bedb05 100644 --- a/src/julianday.h +++ b/src/julianday.h @@ -3,8 +3,8 @@ From "Astronomical Algorithms", Chapter 7 */ - #include +#include #include #include #include @@ -25,8 +25,7 @@ struct Date date_from_jd(double jd); struct Date set_month_str(struct Date *date); int date_diff (struct Date first, struct Date second); short get_week_day(struct Date date); -// TODO refactor to Bool... -char is_leap_year(short year); +bool is_leap_year(short year); short unsigned get_year_day(struct Date date); /** @@ -98,7 +97,13 @@ struct Date date_from_jd(double jd) { return date; } - +/** +* @fn +* Sets the English name for the month in +* a Date struct +* @param The Date struct where the month string +* should be set +*/ struct Date set_month_str(struct Date *date) { char* test; @@ -149,6 +154,8 @@ struct Date set_month_str(struct Date *date) { } /** * Returns the date difference in days +* @param first The first Date (smaller) +* @param second The second Date (larger) */ int date_diff(struct Date first, struct Date second) { double jd_first = jd(first); @@ -158,6 +165,7 @@ int date_diff(struct Date first, struct Date second) { } /** * Returns the week day as a number +* @param date The Date struct to find the week day from */ short get_week_day(struct Date date) { // Day should be taken at Oh @@ -169,12 +177,14 @@ short get_week_day(struct Date date) { /** * Checks whether a given year is * a leap year (Gregorian only!!) +* @param year The year to check */ -char is_leap_year(short year) { +bool is_leap_year(short year) { return (year % 4) == 0; } /** * Returns the day number in the given year + * @param date The Date struct to use */ short unsigned get_year_day(struct Date date) { short k = is_leap_year(date.year) ? 1 : 2;