Click here to Skip to main content
15,893,564 members
Articles / Programming Languages / C# 4.0

Solar Calculator - Calculate Sunrise, Sunset, and Maximum Solar Radiation

Rate me:
Please Sign up or sign in to vote.
4.79/5 (33 votes)
10 Jan 2011CPOL2 min read 137.8K   4.4K   80  
A C# assembly for calculating Sunrise, Sunset, and Maximum Solar Radiation
// SunCalculator.cs - Calculator for calculating SunRise, SunSet and
// maximum solar radiation of a specific date and time.
//
// Patrick Kalkman  pkalkie@gmail.com
//
// (C) Patrick Kalkman http://www.semanticarchitecture.net
//
using System;
using Astronomy;

namespace ConsoleCalculator
{
   class Program
   {
      static void Main(string[] args)
      {
         const Double LongituteUtrechtNetherlands = 5.127869;
         const Double LatitudeUtrechtNetherlands = 52.108192;

         SunCalculator sunCalculator = new SunCalculator(LongituteUtrechtNetherlands, LatitudeUtrechtNetherlands, 15, false);
         
         //Calculate the sunrise for the city Utrecht in the Netherlands 
         DateTime startDateTime = new DateTime(2010, 1, 1);
         DateTime endDateTime = new DateTime(2010, 3, 31);
         DateTime dateTime = startDateTime;
         while (dateTime < endDateTime)
         {
            DateTime sunRise = sunCalculator.CalculateSunRise(dateTime);
            Console.WriteLine("On {0:MM/dd/yyyy} the sun rises at {1:t}", dateTime, sunRise);
            dateTime = dateTime.AddDays(1);
         }
         Console.ReadLine();
      }
   }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect http://www.simpletechture.nl
Netherlands Netherlands
Patrick Kalkman is a senior Software Architect with more than 20 years professional development experience. He works for SimpleTechture where he helps teams develop state of the art web applications.

Patrick enjoys writing his blog. It discusses agile software development. Patrick can be reached at patrick@simpletechture.nl.

Published Windows 8 apps:


Published Windows Phone apps:


Awards:

Best Mobile article of March 2012
Best Mobile article of June 2012

Comments and Discussions