Skip to content

The days are getting shorter – Perl Script to Calculate Sunrise and Sunset

October 11, 2008

Hi Everyone;

I made a great perl script to calculate sunrise and sunset times in Toronto for the whole year with a graphical output. I wrote this in my dead-time during a work order tonight… so I hope you enjoy it as much as I enjoyed making it.

Notes:

  • my brother’s birthday, which is right around the corner is day 286.  That’s a g33ky number.
  • Here’s a day-of-the-year number calendar .
  • does not account for Daylight Savings Time changes
  • the output is in decimal form (.1 hours is about 6 minutes)

How to understand the output

————-***********************————–      Day: 286 , sunrise: 7.46371983255512 , sunset: 18.6748421708946 

  •  
    • The —– is darkness (night)
    • The ******* is sunlight (day)
    • sunrise 7.46371….  is the time local to toronto at GMT -4 (7.46 = 7 oclock + (.46 * 60 minutes) = 7:27am

 

Sample output.  If you scroll through enough lines, an “hourglass” shape starts to appear:

# ./sun.pl
----------------******************----------------      Day: 1 , sunrise: 8.8499964506844 , sunset: 17.8363243941365 
----------------******************----------------      Day: 2 , sunrise: 8.85157917721863 , sunset: 17.8505635052382 
---------------*******************----------------      Day: 3 , sunrise: 8.85247026342554 , sunset: 17.8653183755327 
---------------*******************----------------      Day: 4 , sunrise: 8.85266811641787 , sunset: 17.8805734993673 
---------------*******************----------------      Day: 5 , sunrise: 8.85217187255689 , sunset: 17.8963130190473 
---------------*******************----------------      Day: 6 , sunrise: 8.8509813847397 , sunset: 17.9125207658933 
---------------*******************----------------      Day: 7 , sunrise: 8.84909720761213 , sunset: 17.9291803019326 

Here’s the perl code to support it.  A lot of it was based on http://www.adventist.org/sun/sun.pm .  Obviously, i did a lot of reworking of the ideas into my own script.  Click MORE for a special suprise (and the code)

Perl code below entire output for 1 year… enjoy your scroll-down (see the hourglass shape?):

# ./sun.pl
----------------******************----------------      Day: 1 , sunrise: 8.8499964506844 , sunset: 17.8363243941365 
----------------******************----------------      Day: 2 , sunrise: 8.85157917721863 , sunset: 17.8505635052382 
---------------*******************----------------      Day: 3 , sunrise: 8.85247026342554 , sunset: 17.8653183755327 
---------------*******************----------------      Day: 4 , sunrise: 8.85266811641787 , sunset: 17.8805734993673 
---------------*******************----------------      Day: 5 , sunrise: 8.85217187255689 , sunset: 17.8963130190473 
---------------*******************----------------      Day: 6 , sunrise: 8.8509813847397 , sunset: 17.9125207658933 
---------------*******************----------------      Day: 7 , sunrise: 8.84909720761213 , sunset: 17.9291803019326 
---------------*******************----------------      Day: 8 , sunrise: 8.8465205808661 , sunset: 17.9462749619951 
---------------*******************----------------      Day: 9 , sunrise: 8.84325341078829 , sunset: 17.9637878959815 
---------------*******************----------------      Day: 10 , sunrise: 8.83929825023163 , sunset: 17.9817021110803 
---------------*******************----------------      Day: 11 , sunrise: 8.83465827718451 , sunset: 18.0000005137127 
---------------*******************----------------      Day: 12 , sunrise: 8.82933727211527 , sunset: 18.0186659509979 
---------------*******************----------------      Day: 13 , sunrise: 8.8233395942673 , sunset: 18.0376812515357 
---------------*******************----------------      Day: 14 , sunrise: 8.81667015708018 , sunset: 18.0570292653203 
---------------*******************----------------      Day: 15 , sunrise: 8.80933440290657 , sunset: 18.0766929026087 
---------------*******************----------------      Day: 16 , sunrise: 8.80133827719204 , sunset: 18.0966551715826 
---------------*******************----------------      Day: 17 , sunrise: 8.79268820227645 , sunset: 18.116899214657 
---------------*******************----------------      Day: 18 , sunrise: 8.78339105097045 , sunset: 18.1374083433047 
---------------*******************----------------      Day: 19 , sunrise: 8.77345412005081 , sunset: 18.1581660712814 
---------------*******************----------------      Day: 20 , sunrise: 8.76288510381048 , sunset: 18.1791561461516 
---------------*******************----------------      Day: 21 , sunrise: 8.75169206778994 , sunset: 18.2003625790336 
---------------*******************----------------      Day: 22 , sunrise: 8.73988342280556 , sunset: 18.2217696724939 
---------------********************---------------      Day: 23 , sunrise: 8.72746789938188 , sunset: 18.243362046541 
---------------********************---------------      Day: 24 , sunrise: 8.71445452268357 , sunset: 18.2651246626811 
---------------********************---------------      Day: 25 , sunrise: 8.70085258803331 , sunset: 18.2870428460122 
---------------********************---------------      Day: 26 , sunrise: 8.68667163709145 , sunset: 18.3091023053487 
---------------********************---------------      Day: 27 , sunrise: 8.67192143476285 , sunset: 18.3312891513783 
---------------********************---------------      Day: 28 , sunrise: 8.65661194688846 , sunset: 18.353589912869 
---------------********************---------------      Day: 29 , sunrise: 8.64075331876779 , sunset: 18.3759915509492 
---------------********************---------------      Day: 30 , sunrise: 8.6243558545518 , sunset: 18.3984814714999 
---------------********************---------------      Day: 31 , sunrise: 8.60742999753545 , sunset: 18.4210475357014 
---------------********************---------------      Day: 32 , sunrise: 8.58998631137356 , sunset: 18.4436780687885 
---------------********************---------------      Day: 33 , sunrise: 8.57203546223436 , sunset: 18.4663618670729 
---------------********************---------------      Day: 34 , sunrise: 8.55358820190029 , sunset: 18.4890882032975 
---------------********************---------------      Day: 35 , sunrise: 8.53465535181793 , sunset: 18.5118468303937 
--------------*********************---------------      Day: 36 , sunrise: 8.5152477880949 , sunset: 18.5346279837139 
--------------*********************---------------      Day: 37 , sunrise: 8.49537642743562 , sunset: 18.5574223818171 
--------------*********************---------------      Day: 38 , sunrise: 8.47505221400403 , sunset: 18.580221225886 
--------------*********************---------------      Day: 39 , sunrise: 8.45428610719691 , sunset: 18.6030161978561 
--------------*********************---------------      Day: 40 , sunrise: 8.43308907030896 , sunset: 18.6257994573375 
--------------*********************---------------      Day: 41 , sunrise: 8.41147206006696 , sunset: 18.6485636374115 
--------------*********************---------------      Day: 42 , sunrise: 8.389446017009 , sunset: 18.6713018393812 
--------------*********************---------------      Day: 43 , sunrise: 8.36702185668104 , sunset: 18.6940076265556 
--------------*********************---------------      Day: 44 , sunrise: 8.34421046162402 , sunset: 18.7166750171475 
--------------*********************---------------      Day: 45 , sunrise: 8.32102267412058 , sunset: 18.7392984763571 
--------------*********************---------------      Day: 46 , sunrise: 8.29746928967229 , sunset: 18.7618729077191 
--------------**********************--------------      Day: 47 , sunrise: 8.27356105117488 , sunset: 18.7843936437809 
--------------**********************--------------      Day: 48 , sunrise: 8.24930864376165 , sunset: 18.8068564361836 
--------------**********************--------------      Day: 49 , sunrise: 8.22472269028209 , sunset: 18.8292574452069 
--------------**********************--------------      Day: 50 , sunrise: 8.19981374738528 , sunset: 18.8515932288444 
--------------**********************--------------      Day: 51 , sunrise: 8.17459230217629 , sunset: 18.8738607314639 
--------------**********************--------------      Day: 52 , sunrise: 8.14906876941498 , sunset: 18.8960572721111 
--------------**********************--------------      Day: 53 , sunrise: 8.12325348922736 , sunset: 18.9181805325064 
--------------**********************--------------      Day: 54 , sunrise: 8.09715672529944 , sunset: 18.9402285447849 
--------------**********************--------------      Day: 55 , sunrise: 8.07078866352529 , sunset: 18.9621996790235 
--------------**********************--------------      Day: 56 , sunrise: 8.04415941108124 , sunset: 18.984092630597 
--------------**********************--------------      Day: 57 , sunrise: 8.0172789958994 , sunset: 19.0059064074018 
-------------***********************--------------      Day: 58 , sunrise: 7.99015736651472 , sunset: 19.0276403169821 
-------------***********************--------------      Day: 59 , sunrise: 7.96280439225984 , sunset: 19.0492939535899 
-------------***********************--------------      Day: 60 , sunrise: 7.9352298637849 , sunset: 19.0708671852091 
-------------***********************--------------      Day: 61 , sunrise: 7.90744349387849 , sunset: 19.0923601405674 
-------------***********************--------------      Day: 62 , sunrise: 7.87945491856845 , sunset: 19.1137731961619 
-------------***********************--------------      Day: 63 , sunrise: 7.85127369848098 , sunset: 19.1351069633154 
-------------***********************--------------      Day: 64 , sunrise: 7.82290932043911 , sunset: 19.1563622752845 
-------------***********************--------------      Day: 65 , sunrise: 7.7943711992807 , sunset: 19.1775401744328 
-------------***********************--------------      Day: 66 , sunrise: 7.76566867987897 , sunset: 19.1986418994837 
-------------***********************--------------      Day: 67 , sunrise: 7.73681103934769 , sunset: 19.2196688728621 
-------------************************-------------      Day: 68 , sunrise: 7.70780748941566 , sunset: 19.2406226881361 
-------------************************-------------      Day: 69 , sunrise: 7.67866717895492 , sunset: 19.261505097565 
-------------************************-------------      Day: 70 , sunrise: 7.64939919664834 , sunset: 19.2823179997582 
-------------************************-------------      Day: 71 , sunrise: 7.62001257378288 , sunset: 19.3030634274504 
-------------************************-------------      Day: 72 , sunrise: 7.59051628715571 , sunset: 19.3237435353947 
-------------************************-------------      Day: 73 , sunrise: 7.56091926208093 , sunset: 19.3443605883754 
-------------************************-------------      Day: 74 , sunrise: 7.53123037548551 , sunset: 19.3649169493395 
-------------************************-------------      Day: 75 , sunrise: 7.50145845908276 , sunset: 19.3854150676466 
-------------************************-------------      Day: 76 , sunrise: 7.47161230261388 , sunset: 19.4058574674352 
-------------************************-------------      Day: 77 , sunrise: 7.44170065714683 , sunset: 19.4262467361023 
------------*************************-------------      Day: 78 , sunrise: 7.41173223842348 , sunset: 19.446585512893 
------------*************************-------------      Day: 79 , sunrise: 7.38171573024546 , sunset: 19.4668764775952 
------------*************************-------------      Day: 80 , sunrise: 7.35165978789063 , sunset: 19.4871223393366 
------------*************************-------------      Day: 81 , sunrise: 7.32157304155099 , sunset: 19.5073258254765 
------------*************************-------------      Day: 82 , sunrise: 7.29146409978445 , sunset: 19.5274896705895 
------------*************************-------------      Day: 83 , sunrise: 7.26134155297207 , sunset: 19.5476166055342 
------------*************************-------------      Day: 84 , sunrise: 7.23121397677301 , sunset: 19.5677093466018 
------------*************************-------------      Day: 85 , sunrise: 7.20108993556992 , sunset: 19.5877705847388 
------------*************************-------------      Day: 86 , sunrise: 7.17097798589653 , sunset: 19.6078029748389 
------------*************************-------------      Day: 87 , sunrise: 7.14088667984032 , sunset: 19.6278091250989 
------------**************************------------      Day: 88 , sunrise: 7.11082456841248 , sunset: 19.6477915864319 
------------**************************------------      Day: 89 , sunrise: 7.08080020487758 , sunset: 19.6677528419361 
------------**************************------------      Day: 90 , sunrise: 7.05082214803551 , sunset: 19.687695296413 
------------**************************------------      Day: 91 , sunrise: 7.02089896544695 , sunset: 19.7076212659309 
------------**************************------------      Day: 92 , sunrise: 6.99103923659549 , sunset: 19.7275329674333 
------------**************************------------      Day: 93 , sunrise: 6.96125155597724 , sunset: 19.7474325083868 
------------**************************------------      Day: 94 , sunrise: 6.93154453611005 , sunset: 19.7673218764696 
------------**************************------------      Day: 95 , sunrise: 6.90192681045271 , sunset: 19.7872029292979 
------------**************************------------      Day: 96 , sunrise: 6.87240703622618 , sunset: 19.8070773841917 
------------**************************------------      Day: 97 , sunrise: 6.84299389712613 , sunset: 19.8269468079815 
-----------***************************------------      Day: 98 , sunrise: 6.81369610591782 , sunset: 19.8468126068568 
-----------***************************------------      Day: 99 , sunrise: 6.78452240690235 , sunset: 19.8666760162625 
-----------***************************------------      Day: 100 , sunrise: 6.75548157824383 , sunset: 19.8865380908454 
-----------***************************------------      Day: 101 , sunrise: 6.72658243414614 , sunset: 19.9063996944589 
-----------***************************------------      Day: 102 , sunrise: 6.69783382686729 , sunset: 19.9262614902337 
-----------***************************------------      Day: 103 , sunrise: 6.66924464855909 , sunset: 19.9461239307217 
-----------***************************------------      Day: 104 , sunrise: 6.6408238329193 , sunset: 19.9659872481261 
-----------***************************------------      Day: 105 , sunrise: 6.61258035664256 , sunset: 19.9858514446289 
-----------***************************------------      Day: 106 , sunrise: 6.58452324065629 , sunset: 20.0057162828302 
-----------***************************------------      Day: 107 , sunrise: 6.55666155112614 , sunset: 20.025581276315 
-----------****************************-----------      Day: 108 , sunrise: 6.52900440021659 , sunset: 20.045445680365 
-----------****************************-----------      Day: 109 , sunrise: 6.50156094658974 , sunset: 20.0653084828354 
-----------****************************-----------      Day: 110 , sunrise: 6.47434039562675 , sunset: 20.0851683952186 
-----------****************************-----------      Day: 111 , sunrise: 6.44735199935341 , sunset: 20.105023843916 
-----------****************************-----------      Day: 112 , sunrise: 6.42060505605353 , sunset: 20.124872961746 
-----------****************************-----------      Day: 113 , sunrise: 6.39410890955054 , sunset: 20.144713579714 
-----------****************************-----------      Day: 114 , sunrise: 6.36787294813947 , sunset: 20.1645432190741 
-----------****************************-----------      Day: 115 , sunrise: 6.34190660314908 , sunset: 20.1843590837131 
-----------****************************-----------      Day: 116 , sunrise: 6.31621934711511 , sunset: 20.2041580528919 
-----------****************************-----------      Day: 117 , sunrise: 6.29082069154426 , sunset: 20.223936674377 
-----------****************************-----------      Day: 118 , sunrise: 6.26572018424832 , sunset: 20.2436911580015 
----------*****************************-----------      Day: 119 , sunrise: 6.24092740622862 , sunset: 20.2634173696925 
----------*****************************-----------      Day: 120 , sunrise: 6.21645196808908 , sunset: 20.2831108260061 
----------*****************************-----------      Day: 121 , sunrise: 6.19230350595843 , sunset: 20.3027666892128 
----------*****************************-----------      Day: 122 , sunrise: 6.16849167690055 , sunset: 20.322379762975 
----------*****************************-----------      Day: 123 , sunrise: 6.14502615379309 , sunset: 20.3419444886629 
----------*****************************-----------      Day: 124 , sunrise: 6.12191661965475 , sunset: 20.3614549423533 
----------*****************************-----------      Day: 125 , sunrise: 6.09917276140259 , sunset: 20.380904832558 
----------*****************************-----------      Day: 126 , sunrise: 6.0768042630213 , sunset: 20.4002874987302 
----------*****************************-----------      Day: 127 , sunrise: 6.05482079812766 , sunset: 20.4195959105935 
----------*****************************-----------      Day: 128 , sunrise: 6.0332320219147 , sunset: 20.4388226683441 
----------*****************************-----------      Day: 129 , sunrise: 6.01204756246177 , sunset: 20.4579600037694 
----------*****************************-----------      Day: 130 , sunrise: 5.99127701139863 , sunset: 20.4769997823327 
----------******************************----------      Day: 131 , sunrise: 5.97092991391393 , sunset: 20.4959335062667 
----------******************************----------      Day: 132 , sunrise: 5.95101575810002 , sunset: 20.5147523187192 
----------******************************----------      Day: 133 , sunrise: 5.93154396363086 , sunset: 20.5334470089941 
----------******************************----------      Day: 134 , sunrise: 5.91252386977037 , sunset: 20.5520080189241 
----------******************************----------      Day: 135 , sunrise: 5.89396472271424 , sunset: 20.570425450413 
----------******************************----------      Day: 136 , sunrise: 5.87587566227001 , sunset: 20.5886890741775 
----------******************************----------      Day: 137 , sunrise: 5.85826570788634 , sunset: 20.6067883397193 
----------******************************----------      Day: 138 , sunrise: 5.841143744045 , sunset: 20.6247123865488 
----------******************************----------      Day: 139 , sunrise: 5.82451850503494 , sunset: 20.6424500566794 
----------******************************----------      Day: 140 , sunrise: 5.80839855913256 , sunset: 20.6599899084051 
----------******************************----------      Day: 141 , sunrise: 5.7927922922173 , sunset: 20.6773202313674 
----------******************************----------      Day: 142 , sunrise: 5.77770789085818 , sunset: 20.6944290629118 
----------******************************----------      Day: 143 , sunrise: 5.76315332491129 , sunset: 20.7113042057247 
----------******************************----------      Day: 144 , sunrise: 5.74913632967576 , sunset: 20.7279332467368 
---------*******************************----------      Day: 145 , sunrise: 5.73566438766051 , sunset: 20.7443035772684 
---------*******************************----------      Day: 146 , sunrise: 5.72274471002168 , sunset: 20.760402414385 
---------*******************************----------      Day: 147 , sunrise: 5.71038421773563 , sunset: 20.7762168234223 
---------*******************************----------      Day: 148 , sunrise: 5.69858952257896 , sunset: 20.7917337416305 
---------*******************************----------      Day: 149 , sunrise: 5.68736690799426 , sunset: 20.8069400028793 
---------*******************************----------      Day: 150 , sunrise: 5.67672230992384 , sunset: 20.8218223633545 
---------*******************************----------      Day: 151 , sunrise: 5.66666129770235 , sunset: 20.8363675281705 
---------*******************************----------      Day: 152 , sunrise: 5.6571890551011 , sunset: 20.8505621788097 
---------*******************************----------      Day: 153 , sunrise: 5.64831036162509 , sunset: 20.8643930012955 
---------*******************************----------      Day: 154 , sunrise: 5.64002957416549 , sunset: 20.8778467149954 
---------*******************************----------      Day: 155 , sunrise: 5.63235060911511 , sunset: 20.8909101019398 
---------*******************************----------      Day: 156 , sunrise: 5.62527692505752 , sunset: 20.9035700365411 
---------*******************************----------      Day: 157 , sunrise: 5.61881150614158 , sunset: 20.9158135155846 
---------*******************************----------      Day: 158 , sunrise: 5.61295684625598 , sunset: 20.9276276883603 
---------*******************************----------      Day: 159 , sunrise: 5.60771493411686 , sunset: 20.9389998868004 
---------*******************************----------      Day: 160 , sunrise: 5.60308723938235 , sunset: 20.9499176554802 
---------*******************************----------      Day: 161 , sunrise: 5.599074699905 , sunset: 20.9603687813395 
---------*******************************----------      Day: 162 , sunrise: 5.59567771023115 , sunset: 20.9703413229815 
---------*******************************----------      Day: 163 , sunrise: 5.59289611145116 , sunset: 20.9798236394016 
---------*******************************----------      Day: 164 , sunrise: 5.59072918249953 , sunset: 20.9888044180028 
---------*******************************----------      Day: 165 , sunrise: 5.58917563299846 , sunset: 20.9972727017564 
---------*******************************----------      Day: 166 , sunrise: 5.5882335977292 , sunset: 21.0052179153688 
---------*******************************----------      Day: 167 , sunrise: 5.58790063280881 , sunset: 21.0126298903212 
---------*******************************----------      Day: 168 , sunrise: 5.58817371363835 , sunset: 21.0194988886547 
---------*******************************----------      Day: 169 , sunrise: 5.58904923468022 , sunset: 21.0258156253822 
---------*******************************----------      Day: 170 , sunrise: 5.59052301110917 , sunset: 21.031571289415 
---------*******************************----------      Day: 171 , sunrise: 5.59259028237002 , sunset: 21.0367575629032 
---------*******************************----------      Day: 172 , sunrise: 5.59524571766303 , sunset: 21.0413666388998 
---------*******************************----------      Day: 173 , sunrise: 5.59848342336348 , sunset: 21.0453912372695 
---------*******************************----------      Day: 174 , sunrise: 5.60229695237016 , sunset: 21.0488246187757 
---------*******************************----------      Day: 175 , sunrise: 5.60667931536199 , sunset: 21.0516605972924 
---------*******************************----------      Day: 176 , sunrise: 5.61162299393019 , sunset: 21.0538935501006 
---------*******************************----------      Day: 177 , sunrise: 5.61711995553869 , sunset: 21.0555184262434 
---------*******************************----------      Day: 178 , sunrise: 5.62316167025332 , sunset: 21.0565307529264 
---------*******************************----------      Day: 179 , sunrise: 5.62973912916745 , sunset: 21.0569266399651 
---------*******************************----------      Day: 180 , sunrise: 5.63684286443899 , sunset: 21.0567027822929 
---------*******************************----------      Day: 181 , sunrise: 5.64446297084478 , sunset: 21.0558564605577 
---------*******************************----------      Day: 182 , sunrise: 5.65258912874533 , sunset: 21.0543855398471 
---------*******************************----------      Day: 183 , sunrise: 5.66121062834681 , sunset: 21.0522884665943 
---------*******************************----------      Day: 184 , sunrise: 5.67031639513577 , sunset: 21.0495642637266 
---------*******************************----------      Day: 185 , sunrise: 5.6798950163591 , sunset: 21.0462125241308 
---------*******************************----------      Day: 186 , sunrise: 5.68993476841286 , sunset: 21.0422334025167 
---------*******************************----------      Day: 187 , sunrise: 5.70042364500153 , sunset: 21.0376276057701 
---------*******************************----------      Day: 188 , sunrise: 5.7113493859254 , sunset: 21.0323963818919 
---------*******************************----------      Day: 189 , sunrise: 5.72269950635263 , sunset: 21.0265415076257 
---------*******************************----------      Day: 190 , sunrise: 5.73446132643249 , sunset: 21.0200652748847 
---------*******************************----------      Day: 191 , sunrise: 5.74662200110645 , sunset: 21.012970476085 
---------*******************************----------      Day: 192 , sunrise: 5.75916854997719 , sunset: 21.0052603885035 
---------*******************************----------      Day: 193 , sunrise: 5.77208788709803 , sunset: 20.9969387577713 
---------*******************************----------      Day: 194 , sunrise: 5.78536685055042 , sunset: 20.9880097806216 
---------*******************************----------      Day: 195 , sunrise: 5.79899223168238 , sunset: 20.9784780870037 
---------*******************************----------      Day: 196 , sunrise: 5.81295080388595 , sunset: 20.9683487216767 
---------*******************************----------      Day: 197 , sunrise: 5.82722935080138 , sunset: 20.9576271253938 
---------*******************************----------      Day: 198 , sunrise: 5.84181469383999 , sunset: 20.9463191157827 
---------*******************************----------      Day: 199 , sunrise: 5.85669371892932 , sunset: 20.9344308680256 
---------*******************************----------      Day: 200 , sunrise: 5.87185340238933 , sunset: 20.9219688954359 
---------*******************************----------      Day: 201 , sunrise: 5.8872808358607 , sunset: 20.9089400300263 
----------******************************----------      Day: 202 , sunrise: 5.90296325021279 , sunset: 20.8953514031528 
----------******************************----------      Day: 203 , sunrise: 5.91888803836894 , sunset: 20.8812104263193 
----------******************************----------      Day: 204 , sunrise: 5.93504277699623 , sunset: 20.8665247722158 
----------******************************----------      Day: 205 , sunrise: 5.95141524701523 , sunset: 20.8513023560597 
----------******************************----------      Day: 206 , sunrise: 5.96799345289483 , sunset: 20.835551317305 
----------******************************----------      Day: 207 , sunrise: 5.98476564070467 , sunset: 20.8192800017724 
----------******************************----------      Day: 208 , sunrise: 6.00172031490741 , sunset: 20.8024969442541 
----------******************************----------      Day: 209 , sunrise: 6.01884625387951 , sunset: 20.7852108516349 
----------******************************----------      Day: 210 , sunrise: 6.03613252415777 , sunset: 20.7674305865686 
----------******************************----------      Day: 211 , sunrise: 6.05356849341525 , sunset: 20.7491651517429 
----------******************************----------      Day: 212 , sunrise: 6.07114384217593 , sunset: 20.7304236747571 
----------******************************----------      Day: 213 , sunrise: 6.08884857428552 , sunset: 20.7112153936375 
----------******************************----------      Day: 214 , sunrise: 6.10667302615842 , sunset: 20.691549643004 
----------******************************----------      Day: 215 , sunrise: 6.1246078748284 , sunset: 20.6714358409028 
----------******************************----------      Day: 216 , sunrise: 6.14264414483211 , sunset: 20.6508834763098 
----------*****************************-----------      Day: 217 , sunrise: 6.16077321396115 , sunset: 20.629902097311 
----------*****************************-----------      Day: 218 , sunrise: 6.17898681791938 , sunset: 20.6085012999587 
----------*****************************-----------      Day: 219 , sunrise: 6.19727705392583 , sunset: 20.5866907178007 
----------*****************************-----------      Day: 220 , sunrise: 6.21563638330609 , sunset: 20.5644800120759 
----------*****************************-----------      Day: 221 , sunrise: 6.23405763311584 , sunset: 20.5418788625681 
----------*****************************-----------      Day: 222 , sunrise: 6.25253399684312 , sunset: 20.5188969591056 
----------*****************************-----------      Day: 223 , sunrise: 6.27105903423467 , sunset: 20.4955439936958 
----------*****************************-----------      Day: 224 , sunrise: 6.28962667029452 , sunset: 20.4718296532764 
----------*****************************-----------      Day: 225 , sunrise: 6.30823119350116 , sunset: 20.4477636130698 
----------*****************************-----------      Day: 226 , sunrise: 6.3268672532913 , sunset: 20.4233555305217 
----------*****************************-----------      Day: 227 , sunrise: 6.34552985685648 , sunset: 20.3986150398045 
----------*****************************-----------      Day: 228 , sunrise: 6.36421436529799 , sunset: 20.3735517468672 
-----------****************************-----------      Day: 229 , sunrise: 6.38291648918653 , sunset: 20.3481752250115 
-----------****************************-----------      Day: 230 , sunrise: 6.40163228356903 , sunset: 20.3224950109724 
-----------****************************-----------      Day: 231 , sunrise: 6.42035814246661 , sunset: 20.2965206014845 
-----------****************************-----------      Day: 232 , sunrise: 6.43909079290343 , sunset: 20.270261450311 
-----------****************************-----------      Day: 233 , sunrise: 6.45782728850726 , sunset: 20.2437269657159 
-----------****************************-----------      Day: 234 , sunrise: 6.4765650027189 , sunset: 20.2169265083587 
-----------****************************-----------      Day: 235 , sunrise: 6.49530162164633 , sunset: 20.1898693895903 
-----------****************************-----------      Day: 236 , sunrise: 6.51403513659832 , sunset: 20.1625648701302 
-----------****************************-----------      Day: 237 , sunrise: 6.5327638363291 , sunset: 20.1350221591061 
-----------****************************-----------      Day: 238 , sunrise: 6.55148629902516 , sunset: 20.1072504134355 
-----------****************************-----------      Day: 239 , sunrise: 6.57020138406162 , sunset: 20.0792587375311 
-----------***************************------------      Day: 240 , sunrise: 6.58890822355535 , sunset: 20.0510561833121 
-----------***************************------------      Day: 241 , sunrise: 6.60760621373853 , sunset: 20.0226517505027 
-----------***************************------------      Day: 242 , sunrise: 6.62629500617588 , sunset: 19.9940543872022 
-----------***************************------------      Day: 243 , sunrise: 6.64497449884579 , sunset: 19.9652729907097 
-----------***************************------------      Day: 244 , sunrise: 6.66364482710337 , sunset: 19.9363164085874 
-----------***************************------------      Day: 245 , sunrise: 6.68230635454398 , sunset: 19.907193439948 
-----------***************************------------      Day: 246 , sunrise: 6.70095966378033 , sunset: 19.8779128369516 
-----------***************************------------      Day: 247 , sunrise: 6.71960554714837 , sunset: 19.8484833064982 
-----------***************************------------      Day: 248 , sunrise: 6.73824499735231 , sunset: 19.8189135121033 
-----------***************************------------      Day: 249 , sunrise: 6.75687919805968 , sunset: 19.7892120759428 
------------**************************------------      Day: 250 , sunrise: 6.77550951445498 , sunset: 19.7593875810569 
------------**************************------------      Day: 251 , sunrise: 6.79413748375856 , sunset: 19.7294485737002 
------------**************************------------      Day: 252 , sunrise: 6.81276480571747 , sunset: 19.6994035658285 
------------**************************------------      Day: 253 , sunrise: 6.83139333307131 , sunset: 19.6692610377104 
------------**************************------------      Day: 254 , sunrise: 6.85002506199801 , sunset: 19.6390294406562 
------------**************************------------      Day: 255 , sunrise: 6.86866212253991 , sunset: 19.6087171998523 
------------**************************------------      Day: 256 , sunrise: 6.88730676901245 , sunset: 19.578332717294 
------------**************************------------      Day: 257 , sunrise: 6.90596137039446 , sunset: 19.5478843748075 
------------**************************------------      Day: 258 , sunrise: 6.92462840069934 , sunset: 19.5173805371531 
------------**************************------------      Day: 259 , sunrise: 6.9433104293256 , sunset: 19.4868295552012 
------------*************************-------------      Day: 260 , sunrise: 6.96201011138329 , sunset: 19.4562397691754 
------------*************************-------------      Day: 261 , sunrise: 6.98073017799369 , sunset: 19.4256195119532 
------------*************************-------------      Day: 262 , sunrise: 6.99947342655737 , sunset: 19.3949771124183 
------------*************************-------------      Day: 263 , sunrise: 7.01824271098698 , sunset: 19.3643208988586 
------------*************************-------------      Day: 264 , sunrise: 7.03704093189852 , sunset: 19.3336592024009 
------------*************************-------------      Day: 265 , sunrise: 7.05587102675619 , sunset: 19.3030003604784 
------------*************************-------------      Day: 266 , sunrise: 7.07473595996483 , sunset: 19.272352720322 
------------*************************-------------      Day: 267 , sunrise: 7.09363871290319 , sunset: 19.2417246424708 
------------*************************-------------      Day: 268 , sunrise: 7.11258227389263 , sunset: 19.2111245042942 
------------*************************-------------      Day: 269 , sunrise: 7.13156962809313 , sunset: 19.1805607035188 
-------------************************-------------      Day: 270 , sunrise: 7.15060374732188 , sunset: 19.1500416617549 
-------------************************-------------      Day: 271 , sunrise: 7.1696875797861 , sunset: 19.1195758280139 
-------------************************-------------      Day: 272 , sunrise: 7.18882403972513 , sunset: 19.0891716822111 
-------------************************-------------      Day: 273 , sunrise: 7.2080159969544 , sunset: 19.0588377386452 
-------------************************-------------      Day: 274 , sunrise: 7.22726626630591 , sunset: 19.028582549449 
-------------************************-------------      Day: 275 , sunrise: 7.24657759695966 , sunset: 18.9984147080012 
-------------************************-------------      Day: 276 , sunrise: 7.26595266166066 , sunset: 18.9683428522927 
-------------************************-------------      Day: 277 , sunrise: 7.28539404581713 , sunset: 18.9383756682383 
-------------************************-------------      Day: 278 , sunrise: 7.3049042364759 , sunset: 18.9085218929247 
-------------************************-------------      Day: 279 , sunrise: 7.32448561117234 , sunset: 18.878790317785 
-------------************************-------------      Day: 280 , sunrise: 7.34414042665198 , sunset: 18.8491897916908 
-------------***********************--------------      Day: 281 , sunrise: 7.36387080746292 , sunset: 18.8197292239492 
-------------***********************--------------      Day: 282 , sunrise: 7.3836787344193 , sunset: 18.7904175871955 
-------------***********************--------------      Day: 283 , sunrise: 7.4035660329359 , sunset: 18.7612639201677 
-------------***********************--------------      Day: 284 , sunrise: 7.42353436123781 , sunset: 18.7322773303522 
-------------***********************--------------      Day: 285 , sunrise: 7.44358519844725 , sunset: 18.7034669964848 
-------------***********************--------------      Day: 286 , sunrise: 7.46371983255512 , sunset: 18.6748421708946 
-------------***********************--------------      Day: 287 , sunrise: 7.48393934828253 , sunset: 18.6464121816745 
-------------***********************--------------      Day: 288 , sunrise: 7.50424461484317 , sunset: 18.6181864346634 
-------------***********************--------------      Day: 289 , sunrise: 7.52463627361635 , sunset: 18.5901744152212 
-------------***********************--------------      Day: 290 , sunrise: 7.54511472574453 , sunset: 18.562385689781 
--------------**********************--------------      Day: 291 , sunrise: 7.56568011967106 , sunset: 18.5348299071572 
--------------**********************--------------      Day: 292 , sunrise: 7.58633233863544 , sunset: 18.5075167995915 
--------------**********************--------------      Day: 293 , sunrise: 7.60707098814719 , sunset: 18.4804561835144 
--------------**********************--------------      Day: 294 , sunrise: 7.62789538346103 , sunset: 18.4536579600011 
--------------**********************--------------      Day: 295 , sunrise: 7.64880453707979 , sunset: 18.4271321148972 
--------------**********************--------------      Day: 296 , sunrise: 7.6697971463134 , sunset: 18.4008887185925 
--------------**********************--------------      Day: 297 , sunrise: 7.69087158092617 , sunset: 18.3749379254146 
--------------**********************--------------      Day: 298 , sunrise: 7.71202587090769 , sunset: 18.3492899726182 
--------------**********************--------------      Day: 299 , sunrise: 7.73325769440478 , sunset: 18.3239551789425 
--------------**********************--------------      Day: 300 , sunrise: 7.75456436585728 , sunset: 18.2989439427077 
--------------*********************---------------      Day: 301 , sunrise: 7.77594282438125 , sunset: 18.2742667394218 
--------------*********************---------------      Day: 302 , sunrise: 7.79738962244926 , sunset: 18.2499341188685 
--------------*********************---------------      Day: 303 , sunrise: 7.8189009149184 , sunset: 18.2259567016447 
--------------*********************---------------      Day: 304 , sunrise: 7.84047244846201 , sunset: 18.202345175117 
--------------*********************---------------      Day: 305 , sunrise: 7.86209955146305 , sunset: 18.1791102887657 
--------------*********************---------------      Day: 306 , sunrise: 7.88377712443099 , sunset: 18.1562628488832 
--------------*********************---------------      Day: 307 , sunrise: 7.90549963100764 , sunset: 18.1338137125973 
--------------*********************---------------      Day: 308 , sunrise: 7.92726108962899 , sunset: 18.1117737811845 
--------------*********************---------------      Day: 309 , sunrise: 7.94905506591465 , sunset: 18.0901539926448 
--------------*********************---------------      Day: 310 , sunrise: 7.97087466585744 , sunset: 18.0689653135045 
--------------*********************---------------      Day: 311 , sunrise: 7.99271252988956 , sunset: 18.0482187298199 
--------------*********************---------------      Day: 312 , sunrise: 8.01456082790182 , sunset: 18.0279252373509 
---------------********************---------------      Day: 313 , sunrise: 8.03641125529565 , sunset: 18.0080958308787 
---------------********************---------------      Day: 314 , sunrise: 8.05825503014779 , sunset: 17.9887414926435 
---------------********************---------------      Day: 315 , sunrise: 8.08008289156762 , sunset: 17.9698731798775 
---------------********************---------------      Day: 316 , sunrise: 8.10188509932869 , sunset: 17.9515018114176 
---------------********************---------------      Day: 317 , sunrise: 8.1236514348527 , sunset: 17.9336382533766 
---------------********************---------------      Day: 318 , sunrise: 8.14537120362587 , sunset: 17.9162933038666 
---------------********************---------------      Day: 319 , sunrise: 8.16703323912227 , sunset: 17.8994776767619 
---------------********************---------------      Day: 320 , sunrise: 8.18862590830842 , sunset: 17.8832019845028 
---------------********************---------------      Day: 321 , sunrise: 8.21013711879765 , sunset: 17.8674767199411 
---------------********************---------------      Day: 322 , sunrise: 8.23155432771856 , sunset: 17.8523122372363 
---------------********************---------------      Day: 323 , sunrise: 8.25286455235688 , sunset: 17.8377187318214 
---------------********************---------------      Day: 324 , sunrise: 8.27405438262166 , sunset: 17.8237062194577 
---------------********************---------------      Day: 325 , sunrise: 8.29510999538063 , sunset: 17.8102845144126 
---------------*******************----------------      Day: 326 , sunrise: 8.3160171706994 , sunset: 17.797463206799 
---------------*******************----------------      Day: 327 , sunrise: 8.3367613100107 , sunset: 17.7852516391252 
---------------*******************----------------      Day: 328 , sunrise: 8.3573274562276 , sunset: 17.7736588821118 
---------------*******************----------------      Day: 329 , sunrise: 8.37770031580417 , sunset: 17.7626937098456 
---------------*******************----------------      Day: 330 , sunrise: 8.39786428273404 , sunset: 17.7523645743454 
---------------*******************----------------      Day: 331 , sunrise: 8.41780346446282 , sunset: 17.7426795796293 
---------------*******************----------------      Day: 332 , sunrise: 8.43750170967854 , sunset: 17.7336464553806 
---------------*******************----------------      Day: 333 , sunrise: 8.4569426379259 , sunset: 17.7252725303206 
---------------*******************----------------      Day: 334 , sunrise: 8.47610967097883 , sunset: 17.7175647054084 
---------------*******************----------------      Day: 335 , sunrise: 8.49498606588633 , sunset: 17.7105294269933 
---------------*******************----------------      Day: 336 , sunrise: 8.51355494959373 , sunset: 17.7041726600607 
---------------*******************----------------      Day: 337 , sunrise: 8.53179935502349 , sunset: 17.6984998617164 
---------------*******************----------------      Day: 338 , sunrise: 8.549702258485 , sunset: 17.6935159550647 
---------------*******************----------------      Day: 339 , sunrise: 8.56724661826766 , sunset: 17.6892253036433 
---------------*******************----------------      Day: 340 , sunrise: 8.58441541425596 , sunset: 17.6856316865815 
---------------*******************----------------      Day: 341 , sunrise: 8.60119168839234 , sunset: 17.6827382746569 
---------------*******************----------------      Day: 342 , sunrise: 8.61755858580019 , sunset: 17.6805476074258 
---------------*******************----------------      Day: 343 , sunrise: 8.63349939636853 , sunset: 17.6790615716056 
---------------*******************----------------      Day: 344 , sunrise: 8.64899759658909 , sunset: 17.6782813808895 
---------------*******************----------------      Day: 345 , sunrise: 8.66403689142868 , sunset: 17.6782075573683 
---------------*******************----------------      Day: 346 , sunrise: 8.67860125601398 , sunset: 17.6788399147337 
----------------******************----------------      Day: 347 , sunrise: 8.69267497689967 , sunset: 17.6801775434314 
----------------******************----------------      Day: 348 , sunrise: 8.7062426926914 , sunset: 17.6822187979228 
----------------******************----------------      Day: 349 , sunrise: 8.71928943379191 , sunset: 17.684961286206 
----------------******************----------------      Day: 350 , sunrise: 8.73180066104485 , sunset: 17.6884018617368 
----------------******************----------------      Day: 351 , sunrise: 8.74376230305193 , sunset: 17.692536617871 
----------------******************----------------      Day: 352 , sunrise: 8.75516079194993 , sunset: 17.6973608849413 
----------------******************----------------      Day: 353 , sunrise: 8.76598309744058 , sunset: 17.7028692300589 
----------------******************----------------      Day: 354 , sunrise: 8.77621675888058 , sunset: 17.7090554597134 
----------------******************----------------      Day: 355 , sunrise: 8.78584991525199 , sunset: 17.7159126252257 
----------------******************----------------      Day: 356 , sunrise: 8.79487133284913 , sunset: 17.7234330310835 
----------------******************----------------      Day: 357 , sunrise: 8.80327043053668 , sunset: 17.7316082461722 
----------------******************----------------      Day: 358 , sunrise: 8.81103730245204 , sunset: 17.7404291178857 
----------------******************----------------      Day: 359 , sunrise: 8.81816273804688 , sunset: 17.7498857890828 
----------------******************----------------      Day: 360 , sunrise: 8.82463823938283 , sunset: 17.7599677178296 
----------------******************----------------      Day: 361 , sunrise: 8.83045603561994 , sunset: 17.7706636998474 
----------------******************----------------      Day: 362 , sunrise: 8.83560909465888 , sunset: 17.7819618935611 
----------------******************----------------      Day: 363 , sunrise: 8.84009113191978 , sunset: 17.7938498476257 
----------------******************----------------      Day: 364 , sunrise: 8.84389661626498 , sunset: 17.806314530785 
----------------******************----------------      Day: 365 , sunrise: 8.84702077309245 , sunset: 17.8193423639007 

 

OK.  Here’s the code.  RIP and enjoy.

#!/usr/bin/perl

use POSIX;
sub sr_main
{
        ($rs, $rise, $set) = sunriset($year, $month, $day, $lon, $lat);
        return $rs, $rise, $set;
}
sub sunriset
{
        # GLOBAL variable definitions
        local($pi) = 3.1415926535897932384;
        local($radeg) = 180.0 / $pi;           
        local($degrad) = $pi / 180.0;
        local($inv360) = 1.0 / 360.0;
        # Passed variables
        local($year)            = $_[0]; local($month)  = $_[1];
        local($day)             = $_[2]; local($lon)    = $_[3];
        local($lat)             = $_[4]; local($altit)  = -35.0/60.0;
        local($upper_limb)      = 1;
        # Return Values:
                local($rc)    = 0;
                local($trise) = $_[7];
                local($tset)  = $_[8];

        local($d);      # Days since 2000 Jan 0.0
        local($sr);     # Solar distance
        local($sra);    # Sun's right ascension
        local($sdec);   # Sun's declination
        local($sradius);# Sun's apparent radius
        local($t);      # diurnam arc;
        local($tsouth); # time when Sun is at south
        local($sidtime);# local sidereal time
        $d = days_since_2000_Jan_0($year, $month, $day) + 0.5 - $lon/360.0;
        $sidtime = revolution(GMST0($d) + 180.0 + $lon);
        ($sra, $sdec, $sr) = sun_RA_dec($d, $sr);
        $tsouth = 12.0 - rev180($sidtime - $sra) / 15.0;
        $sradius = 0.2666 / $sr;
        if($upper_limb)
        { $altit -= $sradius; }
        $cost = (sind($altit) - sind($lat) * sind($sdec)) / (cosd($lat) * cosd($sdec));
        if($cost >= 1.0)
        { $rc = -1, $t = 0.0; }
        elsif($cost <= -1.0)
        { $rc = +1; $t = 12.0; }
        else { $t = acosd($cost) / 15.0; }
        $trise = $tsouth - $t;
        $tset = $tsouth + $t;
        return $rc, $trise, $tset;
}
sub sunpos
{
        ## Input variables
        local($d) = $_[0];
       
        ## Return variables
        local($lon);
        local($r);
        ## Local declerations
        local($M, $w, $e, $E, $x, $y, $v);
        $M = revolution(356.0470 + 0.9856002585 * $d);
        $w = 282.9404 + 4.70935E-5 * $d;
        $e = 0.016709 - 1.151E-9 * $d;
        $E = $M + $e * $radeg * sind($M) * (1.0 + $e * cosd($M));
        $x = cosd($E) - $e;
        $y = sqrt(1.0 - $e * $e) * sind($E);
        $r = sqrt($x * $x + $y * $y);  
        $v = atan2d($y, $x);
        $lon = $v + $w;
        if( $lon >= 360.0 ) { $lon -= 360.0; }
        return $lon, $r;
}
sub sun_RA_dec
{
        ## Input variables
        local($d) = $_[0];
        ## Return Variables
        local($RA, $dec);
        local($r) = $_[1];
        ## Local reserved variables
        local($lon, $obl_ecl, $x, $y, $z);
        ($lon, $r) = sunpos($d);
        $x = $r * cosd($lon);
        $y = $r * sind($lon);
        $obl_ecl = 23.4393 - 3.563E-7 * $d;
        $z = $y * sind($obl_ecl);
        $y = $y * cosd($obl_ecl);
        $RA = atan2d($y, $x);
        $dec = atan2d($z, sqrt($x * $x + $y * $y));
        return $RA, $dec, $r;
}
sub revolution
{ return ($_[0] - 360.0 * floor($_[0] * $inv360)); }
sub rev180
{ return ($_[0] - 360.0 * floor($_[0] * $inv360 + 0.5)); }
sub GMST0
{
 return revolution((180.0 + 356.0470 + 282.9404) +
                    (0.9856002585 + 4.70935E-5) * $_[0]);
}
sub days_since_2000_Jan_0
{
        my($y) = $_[0]; my($m) = $_[1]; my($d) = $_[2];
        return (367 * ($y) - ((7 * (($y) + ((($m) + 9) / 12))) /4) +
        ((275 * ($m)) / 9) + ($d) - 730530);
}
sub sind { return sin($_[0] * $degrad); }
sub cosd { return cos($_[0] * $degrad); }
sub tand { return tan($_[0] * $degrad); }
sub atand { return ($radeg * atan($_[0])); }
sub asind { return ($radeg * asin($_[0])); }
sub acosd { return ($radeg * acos($_[0])); }
sub atan2d { return ($radeg * atan2($_[0], $_[1])); }
#1;
#($rs,$sunrise,$sunset)=sunriset($year, $month, $day, $latitude, $logitude);
#print "Sunrise: ".$sunrise."\n";

$year=2008;
$month=1;
#$day=11;
$lat="+43.6667";
$lon="-79.4";
$counter=1;
while ($counter < 366)
{
$day=$counter;
        ($rs, $rise, $set)=sr_main;
#print $rs;
#print $rise;
$prettycounter=0;
$lines=(24-($set-$rise));
for ($lines; $lines >= 0; $lines--) {
print "-";
$prettycounter++;
}
$stars=($set-$rise)*2;
for ($stars; $stars >= 0; $stars--) {
print "*";
$prettycounter++;
}
$lines=(24-($set-$rise));
for ($lines; $lines >= 0; $lines--) {
print "-";
$prettycounter++;
}
if ($prettycounter<50) { print "-"; };

print "\tDay: $counter , sunrise: ".($rise-4)." , sunset: ".($set-4)."  ";
print "\n";
$counter++;
}
#
Advertisements
One Comment leave one →
  1. srikanth permalink
    February 17, 2011 11:14 am

    perl is great

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: