예제 #1
0
 private static string FormatFilename(string loc, Position pos, UTCDate dt)
 {
     string dt_s = String.Format("{0:0000}-{1:00}-{2:00}",
                                 dt.Year, dt.Month, dt.Day);
     string tm_s = String.Format("{0:00}-{1:00}-{2:00}",
                                 dt.Hour, dt.Minute, dt.Second);
     string loc_s = loc;
     if (loc == String.Empty) {
         string latdir_s = (pos.LatitudeDegree.Direction
                 == PositionDirection.North) ? "N" : "S";
         string lat_s = String.Format("{0}{1:00}-{2:00}-{3:00}",
                                      latdir_s,
                                      pos.LatitudeDegree.Deg,
                                      pos.LatitudeDegree.Min,
                                      pos.LatitudeDegree.Sec);
         string londir_s = (pos.LongitudeDegree.Direction
                 == PositionDirection.East) ? "E" : "W";
         string lon_s = String.Format("{0}{1:00}-{2:00}-{3:00}",
                                      londir_s,
                                      pos.LongitudeDegree.Deg,
                                      pos.LongitudeDegree.Min,
                                      pos.LongitudeDegree.Sec);
         loc_s = String.Format("{0} {1}", lat_s, lon_s);
     }
     string s = String.Format("{0} - {1} {2}", loc_s, dt_s, tm_s);
     return s;
 }
예제 #2
0
        private static UTCDate? FindPoint(Position pos, 
		                                  UTCDate? nudt, UTCDate bound, 
		                                  double target, double inc)
        {
            if (nudt != null) {
                UTCDate udt_s = nudt.Value;

                // invariant delta < delta_p ensures convergence
                double delta_p = double.MaxValue;
                double delta = delta_p / 2;

                UTCDate udt = udt_s;
                while (WithinBound(bound, udt, inc) && (delta < delta_p)) {
                    udt = udt.AddSeconds(inc);

                    delta_p = delta;
                    delta = Math.Abs(Compute(pos, udt) - target);
                    inc = (inc > 0 ? 1 : -1) * Math.Max(3, (delta * 150));

                    if (delta < 0.01) {
                        return udt;
                    }
                }
            }
            return null;
        }
예제 #3
0
        private KeyValuePair<Point?, double?> FindPointSlopeAtHour(Position pos,
		                                                          UTCDate dt)
        {
            UTCDate[] dts = new UTCDate[] {dt.AddHours(-1), dt, dt.AddHours(1)};
            List<Point?> pts = FindPoints(pos, dts);

            Point? prev = pts[0];
            Point? point = pts[1];
            Point? next = pts[2];
            double? slope = null;

            Point? a = null;
            Point? b = null;
            if (point != null) {
                if ((prev != null) && (next != null)) {
                    a = new Nullable<Point>(prev.Value);
                    b = new Nullable<Point>(next.Value);
                } else if ((prev == null) && (next != null)) {
                    a = new Nullable<Point>(point.Value);
                    b = new Nullable<Point>(next.Value);
                } else if ((prev != null) && (next == null)) {
                    a = new Nullable<Point>(prev.Value);
                    b = new Nullable<Point>(point.Value);
                }
            }

            if ((a != null) && (b != null)) {
                slope = ComputeSlope(a.Value, b.Value);
            }
            return new KeyValuePair<Point?,double?>(point, slope);
        }
예제 #4
0
        public static void GenerateBitmap(int dim, string path)
        {
            string loc = "Equator";

            // loc: Equator
            Position pos = new Position(Position.LATITUDE_POS,
                                        0, 0, 0,
                                        Position.LONGITUDE_POS,
                                        0, 0, 0);
            // time: Now
            DateTime dt = DateTime.Now;
            UTCDate udt = new UTCDate(0, null,
                                     dt.Year, dt.Month, dt.Day,
                                     dt.Hour, dt.Minute, dt.Second);

            // set up constants
            Colors colors = new Colors();
            string font_face = "Arial";

            // generate base image
            GraphBitmap grbit = new GraphBitmap(true, dim, colors, font_face);
            Bitmap bitmap_plain = grbit.RenderBaseImage(pos, udt);

            // render current day
            Bitmap bitmap = grbit.RenderCurrentDay(bitmap_plain, pos, udt);

            // render caption
            CaptionInfo ci = new CaptionInfo(loc, pos, udt);
            bitmap = grbit.RenderCaption(ci);

            // save
            grbit.SaveBitmap(bitmap, path);
        }
예제 #5
0
        /**
         * Randomized testing of dst status.
         */
        public void TestIsDST(int tz, DaylightTime dst)
        {
            DateTime lower = dst.Start;
            DateTime upper = dst.End;

            DateTime year_lower = new DateTime(lower.Year, 1, 1, 0, 0, 0);
            DateTime year_upper = new DateTime(upper.Year, 12, 31, 23, 59, 59);

            DateTime dt_pre = Rand.GetDateTime(year_lower, lower);
            DateTime dt_in = Rand.GetDateTime(lower, upper);
            DateTime dt_post = Rand.GetDateTime(upper, year_upper);

            UTCDate dst_pre = new UTCDate(tz, dst,
                                          dt_pre.Year, dt_pre.Month, dt_pre.Day,
                                          dt_pre.Hour, dt_pre.Minute, dt_pre.Second);
            UTCDate dst_in = new UTCDate(tz, dst,
                                         dt_in.Year, dt_in.Month, dt_in.Day,
                                         dt_in.Hour, dt_in.Minute, dt_in.Second);
            UTCDate dst_post = new UTCDate(tz, dst,
                                           dt_post.Year, dt_post.Month, dt_post.Day,
                                           dt_post.Hour, dt_post.Minute, dt_post.Second);

            Assert.IsFalse(dst_pre.IsDST);
            Assert.IsTrue(dst_in.IsDST);
            Assert.IsFalse(dst_post.IsDST);
        }
예제 #6
0
        public static string FormatTimeLong(UTCDate udt, bool secs)
        {
            string fmt = "HH':'mm':'ss";
            string fmt_long = "HH':'mm':'ss' 'dd'.'MM'.'yyyy";
            if (!secs) {
                fmt = "HH':'mm";
            }

            DateTime dst = udt.ExtractLocal();
            string dst_s = dst.ToString(fmt);

            DateTime std = UTCDate.ResolveDST(dst, udt.DST);
            string std_s = std.ToString(fmt_long);

            string local_s = string.Format("{0} ST", dst_s);
            if (udt.HasDST) {
                local_s = string.Format("{0} DST  [{1} ST]", dst_s, std_s);
            }

            DateTime utc = UTCDate.ResolveTimezone(std, udt.Timezone);
            string utc_s = utc.ToString(fmt_long);

            string s = string.Format("{0}  [{1} UTC]", local_s, utc_s);

            return s;
        }
예제 #7
0
 public static string FormatDiagramDate(UTCDate dt)
 {
     DateTime date = dt.ExtractLocal();
     Month month = (Month) Enum.ToObject(typeof(Month), date.Month-1);
     string month_s = month.ToString().Substring(0, 3);
     return string.Format("{0} {1}", month_s, date.Day);
 }
예제 #8
0
 public static string FormatTime(UTCDate? udt)
 {
     string tm_s = "-----";
     if (udt != null) {
         tm_s = FormatTime(udt.Value);
     }
     return tm_s;
 }
예제 #9
0
        public void Update(UTCDate date)
        {
            this.date = date;

            NullifyFinalizedBitmap();

            RePaint();
        }
예제 #10
0
 public static string FormatMaybeTime(UTCDate? udt)
 {
     string s = "##:##";
     if (udt != null) {
         s = Formatter.FormatTime(udt.Value);
     }
     return s;
 }
예제 #11
0
 public static string FormatMaybeTimeLong(UTCDate? udt, bool secs)
 {
     string s = "##:##";
     if (udt != null) {
         s = Formatter.FormatTimeLong(udt.Value, secs);
     }
     return s;
 }
예제 #12
0
 public static string FormatCaptionTime(UTCDate udt, CaptionInfo ci)
 {
     string dst_s = string.Empty;
     if (udt.HasDST) {
         dst_s = udt.IsDST ? " DST" : " ST";
     }
     return string.Format("time: {0}{1}", udt.PrintTime(), dst_s);
 }
예제 #13
0
        public Bitmap RenderBaseImage(Position pos, UTCDate udt)
        {
            bitmap = new Bitmap(dimensions, titleheight+dimensions+captionheight);

            grapher = new Grapher(0, titleheight, dimensions, titleheight+dimensions,
                                  colors, font_face);

            using (Graphics g = Graphics.FromImage(bitmap)) {

                // paint backdrop coordinate system
                grapher.PaintBackdrop(g);

                // plot milestone dates
                int[] days = new int[] {
                     1, 1,    4, 2,    6, 3,    5, 4,    5, 5,     4, 6,
                    21, 6,   21, 7,   20, 8,   19, 9,   19, 10,   18, 11,   21, 12,
                };

                for (int i=0, j=1; j<days.Length; i+=2, j+=2) {
                    UTCDate udt_n = udt.SetDate(days[i], days[j]);

                    // first half
                    Color color = colors.YearFstHalf;
                    if (udt_n.HasDST)
                        color = udt_n.IsDST ? colors.YearFstHalfDst : colors.YearFstHalfStd;
                    // second half
                    if (udt_n >= udt.SetDate(7, 6)) {
                        color = colors.YearSndHalf;
                        if (udt_n.HasDST)
                            color = udt_n.IsDST ? colors.YearSndHalfDst : colors.YearSndHalfStd;
                    }

                    grapher.PlotMilestoneDay(g, color, pos, udt_n);
                }

                // plot analemma curves
                for (int i = 0; i < 24; i++) {
                    grapher.PlotAnalemma(g,
                                         colors.YearFstHalf, colors.YearSndHalf,
                                         colors.YearFstHalfStd, colors.YearFstHalfDst,
                                         colors.YearSndHalfStd, colors.YearSndHalfDst,
                                         pos, udt.SetHour(i));
                }

                // print milestone day labels
                grapher.PrintMilestoneDayLabels(g);

                // print analemma labels
                for (int i = 0; i < 24; i++) {
                    grapher.PrintAnalemmaLabel(g, colors.GraphFg,
                                               pos, udt.SetHour(i));
                }
            }

            return this.bitmap;
        }
예제 #14
0
 private static bool WithinBound(UTCDate bound, UTCDate cur, double inc)
 {
     bool within = false;
     if (inc > 0) {
         within = cur <= bound;
     } else {
         within = bound <= cur;
     }
     return within;
 }
예제 #15
0
        public void ReRender(Position pos, UTCDate date)
        {
            this.position = pos;
            this.date = date;

            NullifyBaseImageBitmap();
            NullifyFinalizedBitmap();

            RePaint();
        }
예제 #16
0
 private List<Point?> FindPoints(Position pos, UTCDate[] dts)
 {
     List<Point?> pts = new List<Nullable<Point>>();
     foreach (UTCDate dt in dts)
     {
         SolarPosition sp = Orbit.CalcSolarPosition(pos, dt);
         Point? pt = FindPoint(sp.Azimuth, sp.Elevation);
         pts.Add(pt);
     }
     return pts;
 }
예제 #17
0
        public SolarPosition(Position pos, UTCDate dt, 
							 double jc, double eqtime, double decl, 
							 double az, double el)
        {
            this.pos = pos;
            this.dt = dt;
            this.jc = jc;
            this.eqtime = eqtime;
            this.decl = decl;
            this.az = az;
            this.el= el;
        }
예제 #18
0
        public SolarTimes(Position pos, UTCDate dt, 
		                  double jc, double eqtime, double decl, 
		                  UTCDate? sunrise, UTCDate noon, UTCDate? sunset)
        {
            this.pos = pos;
            this.dt = dt;
            this.jc = jc;
            this.eqtime = eqtime;
            this.decl = decl;
            this.sunrise = sunrise;
            this.noon = noon;
            this.sunset = sunset;
        }
예제 #19
0
        public CaptionInfo(string loc, Position pos, UTCDate udt)
        {
            this.loc = loc;
            this.pos = pos;
            this.dst = udt.GetDST();
            this.udt = udt;
            this.sp = Orbit.CalcSolarPosition(pos, udt);
            this.st = Orbit.CalcSolarTimes(pos, udt);

            SolarTimes st_ss = PointFinder.FindDawnDusk(pos, udt);
            this.dawn = st_ss.Sunrise;
            this.dusk = st_ss.Sunset;
        }
예제 #20
0
        public const double NAUTICAL_TWIGHLIGHT = -12.0; /**< elevation angle (deg) */

        #endregion Fields

        #region Methods

        /**
         * Calculate solar position for location and date.
         * @param dt datetime in UTC
         * @return solar positions in degrees
         */
        public static SolarPosition CalcSolarPosition(Position pos, UTCDate dt)
        {
            double jc = JulianDate.CalcJulianCentury(dt.Year, dt.Month, dt.Day,
                                                     dt.Hour, dt.Minute, dt.Second);
            double eqtime = CalcEquationOfTime(jc);
            double decl = CalcSunDeclination(jc);
            double hour_ang = CalcHourAngle(eqtime, pos.Longitude,
                                            dt.Hour, dt.Minute, dt.Second);
            double zenith = CalcSolarZenithAngle(pos.Latitude, decl, hour_ang);

            // calculate end products
            double azimuth = CalcAzimuth(pos.Latitude, zenith, decl, hour_ang);
            double elevation = CalcSolarElevation(zenith);

            return new SolarPosition(pos, dt, jc, eqtime, decl, azimuth, elevation);
        }
예제 #21
0
        public static SolarTimes FindDawnDusk(Position pos, UTCDate udt)
        {
            UTCDate? dawn_s, dusk_s;
            SolarTimes st = Orbit.CalcSolarTimes(pos, udt);

            dawn_s = st.Sunrise;
            dusk_s = st.Sunset;

            // set wide bounds
            UTCDate lower = st.Noon.AtStartOfUTCDay().AddDays(-1);
            UTCDate upper = lower.AddDays(3);

            dawn_s = FindPoint(pos, dawn_s, lower, Orbit.CIVIL_TWIGHLIGHT, -1);
            dusk_s = FindPoint(pos, dusk_s, upper, Orbit.CIVIL_TWIGHLIGHT, 1);

            return new SolarTimes(pos, udt, 0, 0, 0, dawn_s, st.Noon, dusk_s);
        }
예제 #22
0
        /**
         * Calculate solar sunrise, noon and sunset.
         * @param dt datetime in UTC
         * @return solar times in UTC
         */
        public static SolarTimes CalcSolarTimes(Position pos, UTCDate dt)
        {
            // reset time to start of day as solar times are given in increments
            // from the beginning of the day
            dt = dt.AtStartOfUTCDay();

            double jc = JulianDate.CalcJulianCentury(dt.Year, dt.Month, dt.Day,
                                                     dt.Hour, dt.Minute, dt.Second);
            double solar_noon = CalcSolarNoon(jc, pos.Longitude);
            UTCDate d_noon = dt.AddMinutes(solar_noon);

            UTCDate? d_rise;
            try {
                double sunrise = CalcSunriseSunset(true, solar_noon, jc,
                                                   pos.Longitude, pos.Latitude);
                d_rise = dt.AddMinutes(sunrise);
            } catch (ArgumentException) {
                d_rise = null;
            }

            UTCDate? d_set;
            try {
                double sunset = CalcSunriseSunset(false, solar_noon, jc,
                                                  pos.Longitude, pos.Latitude);
                d_set = dt.AddMinutes(sunset);
            } catch (ArgumentException) {
                d_set = null;
            }

            // <diag>
            double jd = JulianDate.CalcJulianDay(jc)
                - 0.5 + solar_noon / 1440.0;
            double jc_noon = JulianDate.CalcJulianCentury(jd);

            double eqtime = CalcEquationOfTime(jc_noon);
            double decl = CalcSunDeclination(jc_noon);
            // </diag>

            return new SolarTimes(pos, dt, jc, eqtime, decl, d_rise, d_noon, d_set);
        }
예제 #23
0
파일: Plot.cs 프로젝트: numerodix/solarbeam
        public void PlotAnalemma(Graphics g, 
		                         Color col_fst, Color col_snd,
		                         Color col_fst_std, Color col_fst_dst, 
		                         Color col_snd_std, Color col_snd_dst,
		                         Position pos, UTCDate udt)
        {
            UTCDate dt = new UTCDate(udt.Timezone, udt.DST,
                                     udt.Year, 1, 1,
                                     udt.Hour, 0, 0);

            using (SolidBrush br_fst = new SolidBrush(col_fst))
            using (SolidBrush br_snd = new SolidBrush(col_snd))
            using (SolidBrush br_fst_std = new SolidBrush(col_fst_std))
            using (SolidBrush br_fst_dst = new SolidBrush(col_fst_dst))
            using (SolidBrush br_snd_std = new SolidBrush(col_snd_std))
            using (SolidBrush br_snd_dst = new SolidBrush(col_snd_dst)) {
                double step = Math.Max(1, GetResolutionStep(yeardays));
                for (double cursor = 0; cursor < yeardays; cursor+=step)
                {
                    UTCDate dt_new = dt.AddDays(cursor);

                    SolarPosition sp = Orbit.CalcSolarPosition(pos, dt_new);

                    // first half
                    Brush br = br_fst;
                    if (dt_new.HasDST)
                        br = dt_new.IsDST ? br_fst_dst : br_fst_std;
                    // second half
                    if (cursor >= yeardays / 2) {
                        br = br_snd;
                        if (dt_new.HasDST)
                            br = dt_new.IsDST ? br_snd_dst : br_snd_std;
                    }

                    PlotPoint(g, br, sp.Azimuth, sp.Elevation);
                }
            }
        }
예제 #24
0
        public static void SetDetails(string location, Position pos, UTCDate udt)
        {
            SetValue(registry[Id.DETAIL_LOCATION], location);
            SetValue(registry[Id.DETAIL_POSITION], Formatter.FormatPosition(pos));
            SetValue(registry[Id.DETAIL_TIMEZONE], Formatter.FormatTimezone(udt.Timezone,
                                                                            udt.Timezone + udt.GetDST()));
            SetValue(registry[Id.DETAIL_DATE], udt.PrintDate());
            SetValue(registry[Id.DETAIL_TIME], Formatter.FormatTimeLong(udt, true));

            SolarPosition sp = Orbit.CalcSolarPosition(pos, udt);
            SetValue(registry[Id.DETAIL_ELEVATION], Formatter.FormatAngle(sp.Elevation));
            SetValue(registry[Id.DETAIL_AZIMUTH], Formatter.FormatAngle(sp.Azimuth));

            SolarTimes st_ss = Orbit.CalcSolarTimes(pos, udt);
            SetValue(registry[Id.DETAIL_SUNRISE], Formatter.FormatMaybeTimeLong(st_ss.Sunrise, false));
            SetValue(registry[Id.DETAIL_SOLARNOON], Formatter.FormatTimeLong(st_ss.Noon, false));
            SetValue(registry[Id.DETAIL_SUNSET], Formatter.FormatMaybeTimeLong(st_ss.Sunset, false));
            SetValue(registry[Id.DETAIL_SOLARDAYLENGTH], Formatter.FormatDayLength(st_ss, sp));

            SolarTimes st_dd = PointFinder.FindDawnDusk(pos, udt);
            SetValue(registry[Id.DETAIL_DAWN], Formatter.FormatMaybeTimeLong(st_dd.Sunrise, false));
            SetValue(registry[Id.DETAIL_DUSK], Formatter.FormatMaybeTimeLong(st_dd.Sunset, false));
            SetValue(registry[Id.DETAIL_DAYLENGTH], Formatter.FormatDayLength(st_dd, sp));
        }
예제 #25
0
 public static string FormatCaptionDate(UTCDate udt)
 {
     return string.Format("date: {0}", udt.PrintDate());
 }
예제 #26
0
 public static string FormatTime(UTCDate udt)
 {
     DateTime dt_local = udt.ExtractLocal();
     string fmt = "HH':'mm";
     return dt_local.ToString(fmt);
 }
예제 #27
0
 private static double Compute(Position pos, UTCDate udt)
 {
     SolarPosition sp = Orbit.CalcSolarPosition(pos, udt);
     return sp.Elevation;
 }
예제 #28
0
 public static string FormatTxtFilename(string loc, Position pos, UTCDate dt)
 {
     return FormatFilename(loc, pos, dt) + Constants.TextFileExtension;
 }
예제 #29
0
        /**
         * Clone current date, but set time to null.
         */
        public UTCDate AtStartOfUTCDay()
        {
            // build a Date with null time
            // set tz and dst to nil to prevent time adjustments, this time is
            // given as utc
            // but we cannot return this, the timezone setting is invalid
            UTCDate new_udt = new UTCDate(0, null,
                                         this.Year, this.Month, this.Day,
                                         0, 0, 0);

            // use manufactured Date to extract correct DateTime object,
            // then build another Date with the right DateTime and timezone
            return new UTCDate(tz, dst, new_udt.ExtractUTC());
        }
예제 #30
0
 public DSTStatus GetDSTStatus(UTCDate udt)
 {
     DSTStatus dst_s = DSTStatus.NoDST;
     if (udt.HasDST) {
         switch (udt.IsDST) {
         case true:
             dst_s = DSTStatus.Daylight; break;
         case false:
             dst_s = DSTStatus.Standard; break;
         }
     }
     return dst_s;
 }