diff options
| author | Joseph Herlant <herlantj@gmail.com> | 2018-05-25 22:06:51 -0700 |
|---|---|---|
| committer | Joseph Herlant <aerostitch@users.noreply.github.com> | 2018-05-25 22:17:50 -0700 |
| commit | 8a76acb966f7059caf9d72c853175bd923b1e9d7 (patch) | |
| tree | 1735178f7a0718831b88d2c36ea18a9955de3224 /navit/sunriset.c | |
| parent | 032f15287b472f1a4b5349533f3e5b468684b281 (diff) | |
| download | navit-8a76acb966f7059caf9d72c853175bd923b1e9d7.tar.gz | |
cleanup:global:Use astyle to reformat everything
Diffstat (limited to 'navit/sunriset.c')
| -rw-r--r-- | navit/sunriset.c | 300 |
1 files changed, 149 insertions, 151 deletions
diff --git a/navit/sunriset.c b/navit/sunriset.c index 122d14b32..1b1b51929 100644 --- a/navit/sunriset.c +++ b/navit/sunriset.c @@ -53,55 +53,55 @@ int __sunriset__( int year, int month, int day, double lon, double lat, /* */ /**********************************************************************/ { - double d, /* Days since 2000 Jan 0.0 (negative before) */ - sr, /* Solar distance, astronomical units */ - sRA, /* Sun's Right Ascension */ - sdec, /* Sun's declination */ - sradius, /* Sun's apparent radius */ - t, /* Diurnal arc */ - tsouth, /* Time when Sun is at south */ - sidtime; /* Local sidereal time */ - - int rc = 0; /* Return cde from function - usually 0 */ - - /* Compute d of 12h local mean solar time */ - d = days_since_2000_Jan_0(year,month,day) + 0.5 - lon/360.0; - - /* Compute local sideral time of this moment */ - sidtime = revolution( GMST0(d) + 180.0 + lon ); - - /* Compute Sun's RA + Decl at this moment */ - sun_RA_dec( d, &sRA, &sdec, &sr ); - - /* Compute time when Sun is at south - in hours UT */ - tsouth = 12.0 - rev180(sidtime - sRA)/15.0; - - /* Compute the Sun's apparent radius, degrees */ - sradius = 0.2666 / sr; - - /* Do correction to upper limb, if necessary */ - if ( upper_limb ) - altit -= sradius; - - /* Compute the diurnal arc that the Sun traverses to reach */ - /* the specified altitide altit: */ - { - double cost; - cost = ( sind(altit) - sind(lat) * sind(sdec) ) / - ( cosd(lat) * cosd(sdec) ); - if ( cost >= 1.0 ) - rc = -1, t = 0.0; /* Sun always below altit */ - else if ( cost <= -1.0 ) - rc = +1, t = 12.0; /* Sun always above altit */ - else - t = acosd(cost)/15.0; /* The diurnal arc, hours */ - } - - /* Store rise and set times - in hours UT */ - *trise = tsouth - t; - *tset = tsouth + t; - - return rc; + double d, /* Days since 2000 Jan 0.0 (negative before) */ + sr, /* Solar distance, astronomical units */ + sRA, /* Sun's Right Ascension */ + sdec, /* Sun's declination */ + sradius, /* Sun's apparent radius */ + t, /* Diurnal arc */ + tsouth, /* Time when Sun is at south */ + sidtime; /* Local sidereal time */ + + int rc = 0; /* Return cde from function - usually 0 */ + + /* Compute d of 12h local mean solar time */ + d = days_since_2000_Jan_0(year,month,day) + 0.5 - lon/360.0; + + /* Compute local sideral time of this moment */ + sidtime = revolution( GMST0(d) + 180.0 + lon ); + + /* Compute Sun's RA + Decl at this moment */ + sun_RA_dec( d, &sRA, &sdec, &sr ); + + /* Compute time when Sun is at south - in hours UT */ + tsouth = 12.0 - rev180(sidtime - sRA)/15.0; + + /* Compute the Sun's apparent radius, degrees */ + sradius = 0.2666 / sr; + + /* Do correction to upper limb, if necessary */ + if ( upper_limb ) + altit -= sradius; + + /* Compute the diurnal arc that the Sun traverses to reach */ + /* the specified altitide altit: */ + { + double cost; + cost = ( sind(altit) - sind(lat) * sind(sdec) ) / + ( cosd(lat) * cosd(sdec) ); + if ( cost >= 1.0 ) + rc = -1, t = 0.0; /* Sun always below altit */ + else if ( cost <= -1.0 ) + rc = +1, t = 12.0; /* Sun always above altit */ + else + t = acosd(cost)/15.0; /* The diurnal arc, hours */ + } + + /* Store rise and set times - in hours UT */ + *trise = tsouth - t; + *tset = tsouth + t; + + return rc; } /* __sunriset__ */ @@ -127,48 +127,48 @@ double __daylen__( int year, int month, int day, double lon, double lat, /* and to zero when computing day+twilight length. */ /**********************************************************************/ { - double d, /* Days since 2000 Jan 0.0 (negative before) */ - obl_ecl, /* Obliquity (inclination) of Earth's axis */ - sr, /* Solar distance, astronomical units */ - slon, /* True solar longitude */ - sin_sdecl, /* Sine of Sun's declination */ - cos_sdecl, /* Cosine of Sun's declination */ - sradius, /* Sun's apparent radius */ - t; /* Diurnal arc */ - - /* Compute d of 12h local mean solar time */ - d = days_since_2000_Jan_0(year,month,day) + 0.5 - lon/360.0; - - /* Compute obliquity of ecliptic (inclination of Earth's axis) */ - obl_ecl = 23.4393 - 3.563E-7 * d; - - /* Compute Sun's position */ - sunpos( d, &slon, &sr ); - - /* Compute sine and cosine of Sun's declination */ - sin_sdecl = sind(obl_ecl) * sind(slon); - cos_sdecl = sqrt( 1.0 - sin_sdecl * sin_sdecl ); - - /* Compute the Sun's apparent radius, degrees */ - sradius = 0.2666 / sr; - - /* Do correction to upper limb, if necessary */ - if ( upper_limb ) - altit -= sradius; - - /* Compute the diurnal arc that the Sun traverses to reach */ - /* the specified altitide altit: */ - { - double cost; - cost = ( sind(altit) - sind(lat) * sin_sdecl ) / - ( cosd(lat) * cos_sdecl ); - if ( cost >= 1.0 ) - t = 0.0; /* Sun always below altit */ - else if ( cost <= -1.0 ) - t = 24.0; /* Sun always above altit */ - else t = (2.0/15.0) * acosd(cost); /* The diurnal arc, hours */ - } - return t; + double d, /* Days since 2000 Jan 0.0 (negative before) */ + obl_ecl, /* Obliquity (inclination) of Earth's axis */ + sr, /* Solar distance, astronomical units */ + slon, /* True solar longitude */ + sin_sdecl, /* Sine of Sun's declination */ + cos_sdecl, /* Cosine of Sun's declination */ + sradius, /* Sun's apparent radius */ + t; /* Diurnal arc */ + + /* Compute d of 12h local mean solar time */ + d = days_since_2000_Jan_0(year,month,day) + 0.5 - lon/360.0; + + /* Compute obliquity of ecliptic (inclination of Earth's axis) */ + obl_ecl = 23.4393 - 3.563E-7 * d; + + /* Compute Sun's position */ + sunpos( d, &slon, &sr ); + + /* Compute sine and cosine of Sun's declination */ + sin_sdecl = sind(obl_ecl) * sind(slon); + cos_sdecl = sqrt( 1.0 - sin_sdecl * sin_sdecl ); + + /* Compute the Sun's apparent radius, degrees */ + sradius = 0.2666 / sr; + + /* Do correction to upper limb, if necessary */ + if ( upper_limb ) + altit -= sradius; + + /* Compute the diurnal arc that the Sun traverses to reach */ + /* the specified altitide altit: */ + { + double cost; + cost = ( sind(altit) - sind(lat) * sin_sdecl ) / + ( cosd(lat) * cos_sdecl ); + if ( cost >= 1.0 ) + t = 0.0; /* Sun always below altit */ + else if ( cost <= -1.0 ) + t = 24.0; /* Sun always above altit */ + else t = (2.0/15.0) * acosd(cost); /* The diurnal arc, hours */ + } + return t; } /* __daylen__ */ @@ -182,56 +182,55 @@ void sunpos( double d, double *lon, double *r ) /* computed, since it's always very near 0. */ /******************************************************/ { - double M, /* Mean anomaly of the Sun */ - w, /* Mean longitude of perihelion */ - /* Note: Sun's mean longitude = M + w */ - e, /* Eccentricity of Earth's orbit */ - E, /* Eccentric anomaly */ - x, y, /* x, y coordinates in orbit */ - v; /* True anomaly */ - - /* Compute mean elements */ - M = revolution( 356.0470 + 0.9856002585 * d ); - w = 282.9404 + 4.70935E-5 * d; - e = 0.016709 - 1.151E-9 * d; - - /* Compute true longitude and radius vector */ - E = M + e * RADEG * sind(M) * ( 1.0 + e * cosd(M) ); - x = cosd(E) - e; - y = sqrt( 1.0 - e*e ) * sind(E); - *r = sqrt( x*x + y*y ); /* Solar distance */ - v = atan2d( y, x ); /* True anomaly */ - *lon = v + w; /* True solar longitude */ - if ( *lon >= 360.0 ) - *lon -= 360.0; /* Make it 0..360 degrees */ + double M, /* Mean anomaly of the Sun */ + w, /* Mean longitude of perihelion */ + /* Note: Sun's mean longitude = M + w */ + e, /* Eccentricity of Earth's orbit */ + E, /* Eccentric anomaly */ + x, y, /* x, y coordinates in orbit */ + v; /* True anomaly */ + + /* Compute mean elements */ + M = revolution( 356.0470 + 0.9856002585 * d ); + w = 282.9404 + 4.70935E-5 * d; + e = 0.016709 - 1.151E-9 * d; + + /* Compute true longitude and radius vector */ + E = M + e * RADEG * sind(M) * ( 1.0 + e * cosd(M) ); + x = cosd(E) - e; + y = sqrt( 1.0 - e*e ) * sind(E); + *r = sqrt( x*x + y*y ); /* Solar distance */ + v = atan2d( y, x ); /* True anomaly */ + *lon = v + w; /* True solar longitude */ + if ( *lon >= 360.0 ) + *lon -= 360.0; /* Make it 0..360 degrees */ } -void sun_RA_dec( double d, double *RA, double *dec, double *r ) -{ - double lon, obl_ecl; - double xs, ys; - double xe, ye, ze; - - /* Compute Sun's ecliptical coordinates */ - sunpos( d, &lon, r ); - - /* Compute ecliptic rectangular coordinates */ - xs = *r * cosd(lon); - ys = *r * sind(lon); - /* No zs, because the Sun is always in the ecliptic plane! */ - - /* Compute obliquity of ecliptic (inclination of Earth's axis) */ - obl_ecl = 23.4393 - 3.563E-7 * d; - - /* Convert to equatorial rectangular coordinates - x is unchanged */ - xe = xs; - ye = ys * cosd(obl_ecl); - ze = ys * sind(obl_ecl); - - /* Convert to spherical coordinates */ - *RA = atan2d( ye, xe ); - *dec = atan2d( ze, sqrt(xe*xe + ye*ye) ); - +void sun_RA_dec( double d, double *RA, double *dec, double *r ) { + double lon, obl_ecl; + double xs, ys; + double xe, ye, ze; + + /* Compute Sun's ecliptical coordinates */ + sunpos( d, &lon, r ); + + /* Compute ecliptic rectangular coordinates */ + xs = *r * cosd(lon); + ys = *r * sind(lon); + /* No zs, because the Sun is always in the ecliptic plane! */ + + /* Compute obliquity of ecliptic (inclination of Earth's axis) */ + obl_ecl = 23.4393 - 3.563E-7 * d; + + /* Convert to equatorial rectangular coordinates - x is unchanged */ + xe = xs; + ye = ys * cosd(obl_ecl); + ze = ys * sind(obl_ecl); + + /* Convert to spherical coordinates */ + *RA = atan2d( ye, xe ); + *dec = atan2d( ze, sqrt(xe*xe + ye*ye) ); + } /* sun_RA_dec */ @@ -248,7 +247,7 @@ double revolution( double x ) /* Reduce angle to within 0..360 degrees */ /*****************************************/ { - return( x - 360.0 * floor( x * INV360 ) ); + return( x - 360.0 * floor( x * INV360 ) ); } /* revolution */ double rev180( double x ) @@ -256,7 +255,7 @@ double rev180( double x ) /* Reduce angle to within -180..+180 degrees */ /*********************************************/ { - return( x - 360.0 * floor( x * INV360 + 0.5 ) ); + return( x - 360.0 * floor( x * INV360 + 0.5 ) ); } /* revolution */ @@ -286,15 +285,14 @@ double rev180( double x ) /* */ /*******************************************************************/ -double GMST0( double d ) -{ - double sidtim0; - /* Sidtime at 0h UT = L (Sun's mean longitude) + 180.0 degr */ - /* L = M + w, as defined in sunpos(). Since I'm too lazy to */ - /* add these numbers, I'll let the C compiler do it for me. */ - /* Any decent C compiler will add the constants at compile */ - /* time, imposing no runtime or code overhead. */ - sidtim0 = revolution( ( 180.0 + 356.0470 + 282.9404 ) + +double GMST0( double d ) { + double sidtim0; + /* Sidtime at 0h UT = L (Sun's mean longitude) + 180.0 degr */ + /* L = M + w, as defined in sunpos(). Since I'm too lazy to */ + /* add these numbers, I'll let the C compiler do it for me. */ + /* Any decent C compiler will add the constants at compile */ + /* time, imposing no runtime or code overhead. */ + sidtim0 = revolution( ( 180.0 + 356.0470 + 282.9404 ) + ( 0.9856002585 + 4.70935E-5 ) * d ); - return sidtim0; + return sidtim0; } /* GMST0 */ |
