Ticket #502: daynight2.diff

File daynight2.diff, 26.3 KB (added by akashihi, 12 years ago)
  • navit/layout.c

     
    1919
    2020#include <glib.h>
    2121#include <string.h>
     22#include <math.h>
    2223#include "item.h"
    2324#include "attr.h"
    2425#include "layout.h"
    2526#include "coord.h"
    2627#include "debug.h"
    2728
    28 
    2929struct layout * layout_new(struct attr *parent, struct attr **attrs)
    3030{
    3131        struct layout *l;
    3232        struct color def_color = {0xffff, 0xefef, 0xb7b7, 0xffff};
    33         struct attr *name_attr,*color_attr,*order_delta_attr,*font_attr;
     33        struct attr *name_attr,*color_attr,*order_delta_attr,*font_attr,*day_attr,*night_attr;
    3434
    3535        if (! (name_attr=attr_search(attrs, NULL, attr_name)))
    3636                return NULL;
     
    3939        if ((font_attr=attr_search(attrs, NULL, attr_font))) {
    4040                l->font = g_strdup(font_attr->u.str);
    4141        }
     42        if ((day_attr=attr_search(attrs, NULL, attr_daylayout))) {
     43                l->dayname = g_strdup(day_attr->u.str);
     44        }
     45        if ((night_attr=attr_search(attrs, NULL, attr_nightlayout))) {
     46                l->nightname = g_strdup(night_attr->u.str);
     47        }
    4248        if ((color_attr=attr_search(attrs, NULL, attr_color)))
    4349                l->color = *color_attr->u.color;
    4450        else
  • navit/layout.h

     
    7171        int interval;
    7272};
    7373
    74 struct layout { char *name; char *font; struct color color; GList *layers; GList *cursors; int order_delta; };
     74struct layout { char *name; char* dayname; char* nightname; char *font; struct color color; GList *layers; GList *cursors; int order_delta; };
    7575
    7676/* prototypes */
    7777struct layout *layout_new(struct attr *parent, struct attr **attrs);
  • navit/navit_shipped.xml

     
    340340            <map type="garmin" enabled="yes" data="/path/to/img" debug="4"/>
    341341        </mapset>
    342342
    343         <layout name="Car" color="#ffefb7" font="Liberation Sans">
     343        <layout name="Car" nightlayout="Car-dark" color="#ffefb7" font="Liberation Sans">
    344344
    345345            <cursor w="26" h="26">
    346346                <itemgra>
     
    19451945            </layer>
    19461946        </layout>
    19471947
    1948         <layout name="Car-dark" color="#011001">
     1948        <layout name="Car-dark" daylayout="Car" color="#011001">
    19491949
    19501950            <cursor w="26" h="26">
    19511951                <itemgra>
  • navit/Makefile.am

     
    4141        map_data.h mapset.h maptype.h menu.h messages.h navigation.h navit.h osd.h \
    4242        param.h phrase.h plugin.h point.h plugin_def.h projection.h popup.h route.h profile.h roadprofile.h search.h speech.h start_real.h \
    4343        transform.h track.h util.h vehicle.h vehicleprofile.h window.h xmlconfig.h zipfile.h \
    44         navit_nls.h
     44        navit_nls.h sunriset.c sunriset.h
    4545
    4646comma=,
    4747XSLTS=@XSLTS@
  • navit/attr_def.h

     
    224224ATTR(src)
    225225ATTR(path)
    226226ATTR(font)
     227ATTR(daylayout)
     228ATTR(nightlayout)
    227229ATTR(url_local)
    228230ATTR(gc_size)
    229231ATTR(gc_difficulty)
  • navit/sunriset.c

     
     1/*
     2
     3SUNRISET.C - computes Sun rise/set times, start/end of twilight, and
     4             the length of the day at any date and latitude
     5
     6Written as DAYLEN.C, 1989-08-16
     7
     8Modified to SUNRISET.C, 1992-12-01
     9
     10(c) Paul Schlyter, 1989, 1992
     11
     12Released to the public domain by Paul Schlyter, December 1992
     13
     14*/
     15
     16
     17#include <stdio.h>
     18#include <math.h>
     19#include <time.h>
     20
     21#include "sunriset.h"
     22
     23/* The "workhorse" function for sun rise/set times */
     24
     25int __sunriset__( time_t ts, double lon, double lat,
     26                  double altit, int upper_limb, double *trise, double *tset )
     27/***************************************************************************/
     28/* Note: year,month,date = calendar date, 1801-2099 only.             */
     29/*       Eastern longitude positive, Western longitude negative       */
     30/*       Northern latitude positive, Southern latitude negative       */
     31/*       The longitude value IS critical in this function!            */
     32/*       altit = the altitude which the Sun should cross              */
     33/*               Set to -35/60 degrees for rise/set, -6 degrees       */
     34/*               for civil, -12 degrees for nautical and -18          */
     35/*               degrees for astronomical twilight.                   */
     36/*         upper_limb: non-zero -> upper limb, zero -> center         */
     37/*               Set to non-zero (e.g. 1) when computing rise/set     */
     38/*               times, and to zero when computing start/end of       */
     39/*               twilight.                                            */
     40/*        *rise = where to store the rise time                        */
     41/*        *set  = where to store the set  time                        */
     42/*                Both times are relative to the specified altitude,  */
     43/*                and thus this function can be used to comupte       */
     44/*                various twilight times, as well as rise/set times   */
     45/* Return value:  0 = sun rises/sets this day, times stored at        */
     46/*                    *trise and *tset.                               */
     47/*               +1 = sun above the specified "horizon" 24 hours.     */
     48/*                    *trise set to time when the sun is at south,    */
     49/*                    minus 12 hours while *tset is set to the south  */
     50/*                    time plus 12 hours. "Day" length = 24 hours     */
     51/*               -1 = sun is below the specified "horizon" 24 hours   */
     52/*                    "Day" length = 0 hours, *trise and *tset are    */
     53/*                    both set to the time when the sun is at south.  */
     54/*                                                                    */
     55/**********************************************************************/
     56{
     57      int year, month, day;
     58      struct tm ymd;
     59      double  d,  /* Days since 2000 Jan 0.0 (negative before) */
     60      sr,         /* Solar distance, astronomical units */
     61      sRA,        /* Sun's Right Ascension */
     62      sdec,       /* Sun's declination */
     63      sradius,    /* Sun's apparent radius */
     64      t,          /* Diurnal arc */
     65      tsouth,     /* Time when Sun is at south */
     66      sidtime;    /* Local sidereal time */
     67
     68      int rc = 0; /* Return cde from function - usually 0 */
     69
     70      //Split ts to y/m/d
     71      gmtime_r(&ts,&ymd);
     72      year=ymd.tm_year+1900;
     73      month=ymd.tm_mon+1;
     74      day=ymd.tm_mday+1;
     75
     76      /* Compute d of 12h local mean solar time */
     77      d = days_since_2000_Jan_0(year,month,day) + 0.5 - lon/360.0;
     78
     79      /* Compute local sideral time of this moment */
     80      sidtime = revolution( GMST0(d) + 180.0 + lon );
     81
     82      /* Compute Sun's RA + Decl at this moment */
     83      sun_RA_dec( d, &sRA, &sdec, &sr );
     84
     85      /* Compute time when Sun is at south - in hours UT */
     86      tsouth = 12.0 - rev180(sidtime - sRA)/15.0;
     87
     88      /* Compute the Sun's apparent radius, degrees */
     89      sradius = 0.2666 / sr;
     90
     91      /* Do correction to upper limb, if necessary */
     92      if ( upper_limb )
     93            altit -= sradius;
     94
     95      /* Compute the diurnal arc that the Sun traverses to reach */
     96      /* the specified altitide altit: */
     97      {
     98            double cost;
     99            cost = ( sind(altit) - sind(lat) * sind(sdec) ) /
     100                  ( cosd(lat) * cosd(sdec) );
     101            if ( cost >= 1.0 )
     102                  rc = -1, t = 0.0;       /* Sun always below altit */
     103            else if ( cost <= -1.0 )
     104                  rc = +1, t = 12.0;      /* Sun always above altit */
     105            else
     106                  t = acosd(cost)/15.0;   /* The diurnal arc, hours */
     107      }
     108
     109      /* Store rise and set times - in hours UT */
     110      *trise = tsouth - t;
     111      *tset  = tsouth + t;
     112
     113      return rc;
     114}  /* __sunriset__ */
     115
     116
     117
     118/* The "workhorse" function */
     119
     120
     121double __daylen__( int year, int month, int day, double lon, double lat,
     122                   double altit, int upper_limb )
     123/**********************************************************************/
     124/* Note: year,month,date = calendar date, 1801-2099 only.             */
     125/*       Eastern longitude positive, Western longitude negative       */
     126/*       Northern latitude positive, Southern latitude negative       */
     127/*       The longitude value is not critical. Set it to the correct   */
     128/*       longitude if you're picky, otherwise set to to, say, 0.0     */
     129/*       The latitude however IS critical - be sure to get it correct */
     130/*       altit = the altitude which the Sun should cross              */
     131/*               Set to -35/60 degrees for rise/set, -6 degrees       */
     132/*               for civil, -12 degrees for nautical and -18          */
     133/*               degrees for astronomical twilight.                   */
     134/*         upper_limb: non-zero -> upper limb, zero -> center         */
     135/*               Set to non-zero (e.g. 1) when computing day length   */
     136/*               and to zero when computing day+twilight length.      */
     137/**********************************************************************/
     138{
     139      double  d,  /* Days since 2000 Jan 0.0 (negative before) */
     140      obl_ecl,    /* Obliquity (inclination) of Earth's axis */
     141      sr,         /* Solar distance, astronomical units */
     142      slon,       /* True solar longitude */
     143      sin_sdecl,  /* Sine of Sun's declination */
     144      cos_sdecl,  /* Cosine of Sun's declination */
     145      sradius,    /* Sun's apparent radius */
     146      t;          /* Diurnal arc */
     147
     148      /* Compute d of 12h local mean solar time */
     149      d = days_since_2000_Jan_0(year,month,day) + 0.5 - lon/360.0;
     150
     151      /* Compute obliquity of ecliptic (inclination of Earth's axis) */
     152      obl_ecl = 23.4393 - 3.563E-7 * d;
     153
     154      /* Compute Sun's position */
     155      sunpos( d, &slon, &sr );
     156
     157      /* Compute sine and cosine of Sun's declination */
     158      sin_sdecl = sind(obl_ecl) * sind(slon);
     159      cos_sdecl = sqrt( 1.0 - sin_sdecl * sin_sdecl );
     160
     161      /* Compute the Sun's apparent radius, degrees */
     162      sradius = 0.2666 / sr;
     163
     164      /* Do correction to upper limb, if necessary */
     165      if ( upper_limb )
     166            altit -= sradius;
     167
     168      /* Compute the diurnal arc that the Sun traverses to reach */
     169      /* the specified altitide altit: */
     170      {
     171            double cost;
     172            cost = ( sind(altit) - sind(lat) * sin_sdecl ) /
     173                  ( cosd(lat) * cos_sdecl );
     174            if ( cost >= 1.0 )
     175                  t = 0.0;                      /* Sun always below altit */
     176            else if ( cost <= -1.0 )
     177                  t = 24.0;                     /* Sun always above altit */
     178            else  t = (2.0/15.0) * acosd(cost); /* The diurnal arc, hours */
     179      }
     180      return t;
     181}  /* __daylen__ */
     182
     183
     184/* This function computes the Sun's position at any instant */
     185
     186void sunpos( double d, double *lon, double *r )
     187/******************************************************/
     188/* Computes the Sun's ecliptic longitude and distance */
     189/* at an instant given in d, number of days since     */
     190/* 2000 Jan 0.0.  The Sun's ecliptic latitude is not  */
     191/* computed, since it's always very near 0.           */
     192/******************************************************/
     193{
     194      double M,         /* Mean anomaly of the Sun */
     195             w,         /* Mean longitude of perihelion */
     196                        /* Note: Sun's mean longitude = M + w */
     197             e,         /* Eccentricity of Earth's orbit */
     198             E,         /* Eccentric anomaly */
     199             x, y,      /* x, y coordinates in orbit */
     200             v;         /* True anomaly */
     201
     202      /* Compute mean elements */
     203      M = revolution( 356.0470 + 0.9856002585 * d );
     204      w = 282.9404 + 4.70935E-5 * d;
     205      e = 0.016709 - 1.151E-9 * d;
     206
     207      /* Compute true longitude and radius vector */
     208      E = M + e * RADEG * sind(M) * ( 1.0 + e * cosd(M) );
     209      x = cosd(E) - e;
     210      y = sqrt( 1.0 - e*e ) * sind(E);
     211      *r = sqrt( x*x + y*y );              /* Solar distance */
     212      v = atan2d( y, x );                  /* True anomaly */
     213      *lon = v + w;                        /* True solar longitude */
     214      if ( *lon >= 360.0 )
     215            *lon -= 360.0;                   /* Make it 0..360 degrees */
     216}
     217
     218void sun_RA_dec( double d, double *RA, double *dec, double *r )
     219{
     220  double lon, obl_ecl;
     221  double xs, ys, zs;
     222  double xe, ye, ze;
     223 
     224  /* Compute Sun's ecliptical coordinates */
     225  sunpos( d, &lon, r );
     226 
     227  /* Compute ecliptic rectangular coordinates */
     228  xs = *r * cosd(lon);
     229  ys = *r * sind(lon);
     230  zs = 0; /* because the Sun is always in the ecliptic plane! */
     231
     232  /* Compute obliquity of ecliptic (inclination of Earth's axis) */
     233  obl_ecl = 23.4393 - 3.563E-7 * d;
     234 
     235  /* Convert to equatorial rectangular coordinates - x is unchanged */
     236  xe = xs;
     237  ye = ys * cosd(obl_ecl);
     238  ze = ys * sind(obl_ecl);
     239 
     240  /* Convert to spherical coordinates */
     241  *RA = atan2d( ye, xe );
     242  *dec = atan2d( ze, sqrt(xe*xe + ye*ye) );
     243     
     244}  /* sun_RA_dec */
     245
     246
     247/******************************************************************/
     248/* This function reduces any angle to within the first revolution */
     249/* by subtracting or adding even multiples of 360.0 until the     */
     250/* result is >= 0.0 and < 360.0                                   */
     251/******************************************************************/
     252
     253#define INV360    ( 1.0 / 360.0 )
     254
     255double revolution( double x )
     256/*****************************************/
     257/* Reduce angle to within 0..360 degrees */
     258/*****************************************/
     259{
     260      return( x - 360.0 * floor( x * INV360 ) );
     261}  /* revolution */
     262
     263double rev180( double x )
     264/*********************************************/
     265/* Reduce angle to within -180..+180 degrees */
     266/*********************************************/
     267{
     268      return( x - 360.0 * floor( x * INV360 + 0.5 ) );
     269}  /* revolution */
     270
     271
     272/*******************************************************************/
     273/* This function computes GMST0, the Greenwhich Mean Sidereal Time */
     274/* at 0h UT (i.e. the sidereal time at the Greenwhich meridian at  */
     275/* 0h UT).  GMST is then the sidereal time at Greenwich at any     */
     276/* time of the day.  I've generelized GMST0 as well, and define it */
     277/* as:  GMST0 = GMST - UT  --  this allows GMST0 to be computed at */
     278/* other times than 0h UT as well.  While this sounds somewhat     */
     279/* contradictory, it is very practical:  instead of computing      */
     280/* GMST like:                                                      */
     281/*                                                                 */
     282/*  GMST = (GMST0) + UT * (366.2422/365.2422)                      */
     283/*                                                                 */
     284/* where (GMST0) is the GMST last time UT was 0 hours, one simply  */
     285/* computes:                                                       */
     286/*                                                                 */
     287/*  GMST = GMST0 + UT                                              */
     288/*                                                                 */
     289/* where GMST0 is the GMST "at 0h UT" but at the current moment!   */
     290/* Defined in this way, GMST0 will increase with about 4 min a     */
     291/* day.  It also happens that GMST0 (in degrees, 1 hr = 15 degr)   */
     292/* is equal to the Sun's mean longitude plus/minus 180 degrees!    */
     293/* (if we neglect aberration, which amounts to 20 seconds of arc   */
     294/* or 1.33 seconds of time)                                        */
     295/*                                                                 */
     296/*******************************************************************/
     297
     298double GMST0( double d )
     299{
     300      double sidtim0;
     301      /* Sidtime at 0h UT = L (Sun's mean longitude) + 180.0 degr  */
     302      /* L = M + w, as defined in sunpos().  Since I'm too lazy to */
     303      /* add these numbers, I'll let the C compiler do it for me.  */
     304      /* Any decent C compiler will add the constants at compile   */
     305      /* time, imposing no runtime or code overhead.               */
     306      sidtim0 = revolution( ( 180.0 + 356.0470 + 282.9404 ) +
     307                          ( 0.9856002585 + 4.70935E-5 ) * d );
     308      return sidtim0;
     309}  /* GMST0 */
  • navit/navit.c

     
    6060#include "util.h"
    6161#include "messages.h"
    6262#include "vehicleprofile.h"
     63#include "sunriset.h"
    6364
    6465/**
    6566 * @defgroup navit the navit core instance. navit is the object containing nearly everything: A set of maps, one or more vehicle, a graphics object for rendering the map, a gui object for displaying the user interface, a route object, a navigation object and so on. Be warned that it is theoretically possible to have more than one navit object
     
    134135        GList *vehicleprofiles;
    135136        int pitch;
    136137        int follow_cursor;
     138        int prevTs;
    137139};
    138140
    139141struct gui *main_loop_gui;
     
    658660        center.x=co.x;
    659661        center.y=co.y;
    660662        center.pro = pro;
     663       
     664        this_->prevTs=0;
    661665
    662666        transform_setup(this_->trans, &center, zoom, (this_->orientation != -1) ? this_->orientation : 0);
    663667        for (;*attrs; attrs++) {
     
    20732077                profile(0,"return 1\n");
    20742078                return;
    20752079        }
     2080        navit_layout_switch(this_);
    20762081        if (this_->vehicle == nv && this_->tracking_flag)
    20772082                tracking=this_->tracking;
    20782083        if (tracking) {
     
    22502255        return this_->displaylist;
    22512256}
    22522257
     2258void
     2259navit_layout_switch(struct navit *n)
     2260{
     2261
     2262    int currTs=0;
     2263    struct attr iso8601_attr,geo_attr,layout_attr;
     2264    double trise,tset,trise_actual;
     2265    struct layout *l;
     2266   
     2267    if (navit_get_attr(n,attr_layout,&layout_attr,NULL)!=1) {
     2268        return; //No layout - nothing to switch
     2269    }
     2270    l=layout_attr.u.layout;
     2271   
     2272    if (l->dayname || l->nightname) {
     2273        //Ok, we know that we have profile to switch
     2274       
     2275        //Check that we aren't calculating too fast
     2276        if (vehicle_get_attr(n->vehicle->vehicle, attr_position_time_iso8601,&iso8601_attr,NULL)==1) {
     2277                currTs=iso8601_to_secs(iso8601_attr.u.str);
     2278        }
     2279        if (currTs-(n->prevTs)<60) {
     2280            //We've have to wait a little
     2281            return;
     2282        }
     2283       
     2284        if (vehicle_get_attr(n->vehicle->vehicle, attr_position_coord_geo,&geo_attr,NULL)!=1) {
     2285                //No position - no sun
     2286                return;
     2287        }
     2288        if (vehicle_get_attr(n->vehicle->vehicle, attr_position_valid, &geo_attr,NULL) && geo_attr.u.num==attr_position_valid_invalid) {
     2289                return; //No valid fix yet
     2290        }
     2291       
     2292        //We calculate sunrise anyway, cause it is need both for day and for night
     2293        if (__sunriset__(currTs,geo_attr.u.coord_geo->lat,geo_attr.u.coord_geo->lng,35,1,&trise,&tset)!=0) {
     2294                //near the pole sun never rises/sets, so we should never switch profiles
     2295                n->prevTs=currTs;
     2296                return;
     2297            }
     2298       
     2299        trise_actual=trise;
     2300       
     2301        if (l->dayname) {
     2302       
     2303            if ((HOURS(trise)*60+MINUTES(trise)==(currTs%86400)/60) ||
     2304                    (n->prevTs==0 && ((HOURS(trise)*60+MINUTES(trise)<(currTs%86400)/60)))) {
     2305                //The sun is rising now!
     2306                if (strcmp(l->name,l->dayname)) {
     2307                    navit_set_layout_by_name(n,l->dayname);
     2308                }
     2309            }
     2310        }
     2311        if (l->nightname) {
     2312            if (__sunriset__(currTs,geo_attr.u.coord_geo->lat,geo_attr.u.coord_geo->lng,-12,0,&trise,&tset)!=0) {
     2313                //near the pole sun never rises/sets, so we should never switch profiles
     2314                n->prevTs=currTs;
     2315                return;
     2316            }
     2317           
     2318            if (HOURS(tset)*60+MINUTES(tset)==((currTs%86400)/60)
     2319                || (n->prevTs==0 && (((HOURS(tset)*60+MINUTES(tset)<(currTs%86400)/60)) ||
     2320                        ((HOURS(trise_actual)*60+MINUTES(trise_actual)>(currTs%86400)/60))))) {
     2321                //Time to sleep
     2322                if (strcmp(l->name,l->nightname)) {
     2323                    navit_set_layout_by_name(n,l->nightname);
     2324                }
     2325            }   
     2326        }
     2327       
     2328        n->prevTs=currTs;
     2329    }
     2330}
     2331
     2332int
     2333navit_set_layout_by_name(struct navit *n,char *name)
     2334{
     2335    struct layout *l;
     2336    struct attr_iter iter;
     2337    struct attr layout_attr;
     2338
     2339    iter.u.list=0x00;
     2340
     2341    if (navit_get_attr(n,attr_layout,&layout_attr,&iter)!=1) {
     2342        return 0; //No layouts - nothing to do
     2343    }
     2344    if (iter.u.list==NULL) {
     2345        return 0;
     2346    }
     2347   
     2348    iter.u.list=g_list_first(iter.u.list);
     2349   
     2350    while(iter.u.list) {
     2351        l=(struct layout*)iter.u.list->data;
     2352        if (!strcmp(name,l->name)) {
     2353            layout_attr.u.layout=l;
     2354            layout_attr.type=attr_layout;
     2355            navit_set_attr(n,&layout_attr);
     2356            iter.u.list=g_list_first(iter.u.list);
     2357            return 1;
     2358        }
     2359        iter.u.list=g_list_next(iter.u.list);
     2360    }
     2361
     2362    iter.u.list=g_list_first(iter.u.list);
     2363    return 0;
     2364}
     2365
    22532366int
    22542367navit_block(struct navit *this_, int block)
    22552368{
  • navit/sunriset.h

     
     1extern const char* timezone_name;
     2extern long int timezone_offset;
     3
     4#define TMOD(x) ((x)<0?(x)+24:((x)>=24?(x)-24:(x)))
     5#define DAYSOFF(x) ((x)<0?"(-1) ":((x)>=24?"(+1) ":""))
     6
     7#define HOURS(h) ((int)(floor(h)))
     8#define MINUTES(h) ((int)(60*(h-floor(h))))
     9
     10#define ABS(x) ((x)<0?-(x):(x))
     11
     12/* A macro to compute the number of days elapsed since 2000 Jan 0.0 */
     13/* (which is equal to 1999 Dec 31, 0h UT)                           */
     14/* Dan R sez: This is some pretty fucking high magic. */
     15#define days_since_2000_Jan_0(y,m,d) \
     16    (367L*(y)-((7*((y)+(((m)+9)/12)))/4)+((275*(m))/9)+(d)-730530L)
     17
     18/* Some conversion factors between radians and degrees */
     19
     20#ifndef PI
     21 #define PI        3.1415926535897932384
     22#endif
     23
     24#define RADEG     ( 180.0 / PI )
     25#define DEGRAD    ( PI / 180.0 )
     26
     27/* The trigonometric functions in degrees */
     28
     29#define sind(x)  sin((x)*DEGRAD)
     30#define cosd(x)  cos((x)*DEGRAD)
     31#define tand(x)  tan((x)*DEGRAD)
     32
     33#define atand(x)    (RADEG*atan(x))
     34#define asind(x)    (RADEG*asin(x))
     35#define acosd(x)    (RADEG*acos(x))
     36#define atan2d(y,x) (RADEG*atan2(y,x))
     37
     38/* Following are some macros around the "workhorse" function __daylen__ */
     39/* They mainly fill in the desired values for the reference altitude    */
     40/* below the horizon, and also selects whether this altitude should     */
     41/* refer to the Sun's center or its upper limb.                         */
     42
     43
     44/* This macro computes the length of the day, from sunrise to sunset. */
     45/* Sunrise/set is considered to occur when the Sun's upper limb is    */
     46/* 50 arc minutes below the horizon (this accounts for the refraction */
     47/* of the Earth's atmosphere).                                        */
     48/* The original version of the program used the value of 35 arc mins, */
     49/* which is the accepted value in Sweden.                             */
     50#define day_length(year,month,day,lon,lat)  \
     51        __daylen__( year, month, day, lon, lat, -50.0/60.0, 1 )
     52
     53/* This macro computes the length of the day, including civil twilight. */
     54/* Civil twilight starts/ends when the Sun's center is 6 degrees below  */
     55/* the horizon.                                                         */
     56#define day_civil_twilight_length(year,month,day,lon,lat)  \
     57        __daylen__( year, month, day, lon, lat, -6.0, 0 )
     58
     59/* This macro computes the length of the day, incl. nautical twilight.  */
     60/* Nautical twilight starts/ends when the Sun's center is 12 degrees    */
     61/* below the horizon.                                                   */
     62#define day_nautical_twilight_length(year,month,day,lon,lat)  \
     63        __daylen__( year, month, day, lon, lat, -12.0, 0 )
     64
     65/* This macro computes the length of the day, incl. astronomical twilight. */
     66/* Astronomical twilight starts/ends when the Sun's center is 18 degrees   */
     67/* below the horizon.                                                      */
     68#define day_astronomical_twilight_length(year,month,day,lon,lat)  \
     69        __daylen__( year, month, day, lon, lat, -18.0, 0 )
     70
     71
     72/* This macro computes times for sunrise/sunset.                      */
     73/* Sunrise/set is considered to occur when the Sun's upper limb is    */
     74/* 35 arc minutes below the horizon (this accounts for the refraction */
     75/* of the Earth's atmosphere).                                        */
     76#define sun_rise_set(year,month,day,lon,lat,rise,set)  \
     77        __sunriset__( year, month, day, lon, lat, -35.0/60.0, 1, rise, set )
     78
     79/* This macro computes the start and end times of civil twilight.       */
     80/* Civil twilight starts/ends when the Sun's center is 6 degrees below  */
     81/* the horizon.                                                         */
     82#define civil_twilight(year,month,day,lon,lat,start,end)  \
     83        __sunriset__( year, month, day, lon, lat, -6.0, 0, start, end )
     84
     85/* This macro computes the start and end times of nautical twilight.    */
     86/* Nautical twilight starts/ends when the Sun's center is 12 degrees    */
     87/* below the horizon.                                                   */
     88#define nautical_twilight(year,month,day,lon,lat,start,end)  \
     89        __sunriset__( year, month, day, lon, lat, -12.0, 0, start, end )
     90
     91/* This macro computes the start and end times of astronomical twilight.   */
     92/* Astronomical twilight starts/ends when the Sun's center is 18 degrees   */
     93/* below the horizon.                                                      */
     94#define astronomical_twilight(year,month,day,lon,lat,start,end)  \
     95        __sunriset__( year, month, day, lon, lat, -18.0, 0, start, end )
     96
     97
     98/* Function prototypes */
     99
     100double __daylen__( int year, int month, int day, double lon, double lat,
     101                   double altit, int upper_limb );
     102
     103int __sunriset__( time_t ts, double lon, double lat,
     104                  double altit, int upper_limb, double *rise, double *set );
     105
     106void sunpos( double d, double *lon, double *r );
     107
     108void sun_RA_dec( double d, double *RA, double *dec, double *r );
     109
     110double revolution( double x );
     111
     112double rev180( double x );
     113
     114double GMST0( double d );
     115
  • navit/navit.h

     
    9797struct navigation *navit_get_navigation(struct navit *this_);
    9898struct displaylist *navit_get_displaylist(struct navit *this_);
    9999int navit_block(struct navit *this_, int block);
     100void navit_layout_switch(struct navit *n);
     101int navit_set_layout_by_name(struct navit *n, char* name);
    100102void navit_destroy(struct navit *this_);
    101103/* end of prototypes */
    102104#ifdef __cplusplus