Back to index

radiance  4R0+20100331
sun.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: sun.c,v 2.5 2009/06/06 20:18:32 greg Exp $";
00003 #endif
00004 /*
00005  *           SOLAR CALCULATIONS
00006  *
00007  *               3/31/87
00008  *
00009  */
00010 
00011 #include  <math.h>
00012 
00013 #ifdef M_PI
00014 #define  PI   M_PI
00015 #else
00016 #define  PI   3.141592653589793
00017 #endif
00018 
00019 double  s_latitude = 0.66;  /* site latitude (radians) */
00020 double  s_longitude = 2.13; /* site longitude (radians) */
00021 double  s_meridian = 2.0944;       /* standard meridian (radians) */
00022 
00023 
00024 int
00025 jdate(        /* Julian date (days into year) */
00026        int month,
00027        int day
00028 )
00029 {
00030        static short  mo_da[12] = {0,31,59,90,120,151,181,212,243,273,304,334};
00031        
00032        return(mo_da[month-1] + day);
00033 }
00034 
00035 
00036 double
00037 stadj(        /* solar time adjustment from Julian date */
00038        int  jd
00039 )
00040 {
00041        return( 0.170 * sin( (4*PI/373) * (jd - 80) ) -
00042               0.129 * sin( (2*PI/355) * (jd - 8) ) +
00043               12 * (s_meridian - s_longitude) / PI );
00044 }
00045 
00046 
00047 double
00048 sdec(         /* solar declination angle from Julian date */
00049        int  jd
00050 )
00051 {
00052        return( 0.4093 * sin( (2*PI/368) * (jd - 81) ) );
00053 }
00054 
00055 
00056 double
00057 salt(  /* solar altitude from solar declination and solar time */
00058        double sd,
00059        double st
00060 )
00061 {
00062        return( asin( sin(s_latitude) * sin(sd) -
00063                      cos(s_latitude) * cos(sd) * cos(st*(PI/12)) ) );
00064 }
00065 
00066 
00067 double
00068 sazi(  /* solar azimuth from solar declination and solar time */
00069        double sd,
00070        double st
00071 )
00072 {
00073        return( -atan2( cos(sd)*sin(st*(PI/12)),
00074                      -cos(s_latitude)*sin(sd) -
00075                      sin(s_latitude)*cos(sd)*cos(st*(PI/12)) ) );
00076 }