Beispiel #1
0
int main(void){

double y,m,day,h,latit,longit;
float inlat,inlon,intz;
double tzone,d,lambda;
double obliq,alpha,delta,LL,equation,ha,hb,twx;
double twam,altmax,noont,settm,riset,twpm;
time_t sekunnit;
struct tm *p;

degs = 180.0/pi;
rads = pi/180.0;
//  get the date and time from the user
// read system date and extract the year

/** First get time **/
time(&sekunnit);

/** Next get localtime **/

 p=localtime(&sekunnit);

 y = p->tm_year;
 // this is Y2K compliant method
 y+= 1900;
 m = p->tm_mon + 1;

 day = p->tm_mday;

 h = 12;

 printf("year %4d month %2d\n",(int)y,(int)m);
 printf("Input latitude, longitude and timezone\n");
 scanf("%20f", &inlat);
 scanf("%20f", &inlon);
 scanf("%20f", &intz);
 latit = (double)inlat; longit = (double)inlon;
 tzone = (double)intz;

// testing
// m=6; day=10;

d = FNday(y, m, day, h);

//   Use FNsun to find the ecliptic longitude of the
//   Sun

lambda = FNsun(d);

//   Obliquity of the ecliptic

obliq = 23.439 * rads - .0000004 * rads * d;

//   Find the RA and DEC of the Sun

alpha = atan2(cos(obliq) * sin(lambda), cos(lambda));
delta = asin(sin(obliq) * sin(lambda));

// Find the Equation of Time
// in minutes
// Correction suggested by David Smith
LL = L - alpha;
if (L < pi) LL += 2.0*pi;
equation = 1440.0 * (1.0 - LL / pi/2.0);
ha = f0(latit,delta);
hb = f1(latit,delta);
twx = hb - ha;  // length of twilight in radians
twx = 12.0*twx/pi;              // length of twilight in hours
printf("ha= %.2f   hb= %.2f \n",ha,hb);
// Conversion of angle to hours and minutes //
daylen = degs*ha/7.5;
     if (daylen<0.0001) {daylen = 0.0;}
// arctic winter     //

riset = 12.0 - 12.0 * ha/pi + tzone - longit/15.0 + equation/60.0;
settm = 12.0 + 12.0 * ha/pi + tzone - longit/15.0 + equation/60.0;
noont = riset + 12.0 * ha/pi;
altmax = 90.0 + delta * degs - latit;
// Correction for S HS suggested by David Smith
// to express altitude as degrees from the N horizon
if (latit < delta * degs) altmax = 180.0 - altmax;

twam = riset - twx;     // morning twilight begin
twpm = settm + twx;     // evening twilight end

if (riset > 24.0) riset-= 24.0;
if (settm > 24.0) settm-= 24.0;

puts("\n Sunrise and set");
puts("===============");

printf("  year  : %d \n",(int)y);
printf("  month : %d \n",(int)m);
printf("  day   : %d \n\n",(int)day);
printf("Days since Y2K :  %d \n",(int)d);

printf("Latitude :  %3.1f, longitude: %3.1f, timezone: %3.1f \n",(float)latit,(float)longit,(float)tzone);
printf("Declination   :  %.2f \n",delta * degs);
printf("Daylength     : "); showhrmn(daylen); puts(" hours \n");
printf("Civil twilight: ");
showhrmn(twam); puts("");
printf("Sunrise       : ");
showhrmn(riset); puts("");

printf("Sun altitude ");
// Amendment by D. Smith
printf(" %.2f degr",altmax);
printf(" %s",latit>=0.0 ? "South" : "North");
printf(" at noontime "); showhrmn(noont); puts("");
printf("Sunset        : ");
showhrmn(settm);  puts("");
printf("Civil twilight: ");
showhrmn(twpm);  puts("\n");

return 0;
}
Beispiel #2
0
/**
 * Calculates all sun-related important times
 * depending on time of year and location
 * @param location Location to be used in calculation
 * @param GPS_INFO GPS_INFO for current date
 * @param CALCULATED_INFO CALCULATED_INFO (not yet used)
 * @param tzone Timezone
 * @return Always 0
 */
int SunEphemeris::CalcSunTimes(const GEOPOINT &location,
                               const NMEA_INFO &GPS_INFO,
                               const DERIVED_INFO &CALCULATED_INFO,
                               const double tzone)
{
    //    float intz;
    double d,lambda;
    double obliq,alpha,delta,LL,equation,ha,hb,twx;
    int y, m, day, h;

    // testing

    // JG Removed simulator conditional code, since GPS_INFO now set up
    // from system time.

    m = GPS_INFO.Month;
    y = GPS_INFO.Year;
    day = GPS_INFO.Day;
    h = ((int)GPS_INFO.Time)/3600;
    h = (h % 24);

    d = FNday(y, m, day, (float) h);

    // Use FNsun to find the ecliptic longitude of the Sun
    lambda = FNsun(d);

    // Obliquity of the ecliptic
    obliq = 23.439 * DEG_TO_RAD - .0000004 * DEG_TO_RAD * d;

    //   Find the RA and DEC of the Sun
    alpha = atan2(cos(obliq) * sin(lambda), cos(lambda));
    delta = asin(sin(obliq) * sin(lambda));

    // Find the Equation of Time in minutes
    // Correction suggested by David Smith
    LL = L - alpha;
    if (L < PI) LL += 2.0*PI;
    equation = 1440.0 * (1.0 - LL / PI/2.0);
    ha = f0(location.Latitude,delta);
    hb = f1(location.Latitude,delta);
    twx = hb - ha;  // length of twilight in radians
    twx = 12.0*twx/PI;              // length of twilight in hours

    //  printf("ha= %.2f   hb= %.2f \n",ha,hb);

    // Conversion of angle to hours and minutes //
    daylen = RAD_TO_DEG*ha/7.5;
    if (daylen<0.0001) {
        daylen = 0.0;
    }
    // arctic winter     //

    riset = 12.0 - 12.0 * ha/PI + tzone - location.Longitude/15.0 + equation/60.0;
    settm = 12.0 + 12.0 * ha/PI + tzone - location.Longitude/15.0 + equation/60.0;
    noont = riset + 12.0 * ha/PI;
    altmax = 90.0 + delta * RAD_TO_DEG - location.Latitude;

    // Correction for S HS suggested by David Smith
    // to express altitude as degrees from the N horizon
    if (location.Latitude < delta * RAD_TO_DEG) {
        altmax = 180.0 - altmax;
    }

    twam = riset - twx;     // morning twilight begin
    twpm = settm + twx;     // evening twilight end

    if (riset > 24.0) riset-= 24.0;
    if (settm > 24.0) settm-= 24.0;

    /*
        puts("\n Sunrise and set");
        puts("===============");

        printf("  year  : %d \n",(int)y);
        printf("  month : %d \n",(int)m);
        printf("  day   : %d \n\n",(int)day);
        printf("Days since Y2K :  %d \n",(int)d);

        printf("Latitude :  %3.1f, longitude: %3.1f, timezone: %3.1f \n",(float)latit,(float)longit,(float)tzone);
        printf("Declination   :  %.2f \n",delta * RAD_TO_DEG);
        printf("Daylength     : "); showhrmn(daylen); puts(" hours \n");
        printf("Civil twilight: ");
        showhrmn(twam); puts("");
        printf("Sunrise       : ");
        showhrmn(riset); puts("");

        printf("Sun altitude ");
        // Amendment by D. Smith
        printf(" %.2f degr",altmax);
        printf(latit>=0.0 ? " South" : " North");
        printf(" at noontime "); showhrmn(noont); puts("");
        printf("Sunset        : ");
        showhrmn(settm);  puts("");
        printf("Civil twilight: ");
        showhrmn(twpm);  puts("\n");
    */
    // QUESTION TB: why not just void?

    return 0;
}