Changes in / [1:3]


Ignore:
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • /sunpos.lua

    r1 r3  
    1  
     1local math, os = math, os 
     2-- local timeutils = require "timeutils" 
     3module (...) 
    24 
    35-- 
     
    2123local function fractyear (date) 
    2224    return (2*math.pi/365.25) * (date.yday + fractday (date)) 
     25end 
     26 
     27local function solartime(date) 
     28    return 
    2329end 
    2430 
     
    4854 
    4955-- sun zenith angle 
    50 local function sunzenithangle (date, place) 
     56function sunzenithangle (date, place) 
    5157    local d = sundeclin (date) 
    5258    local sha = solarhourangle (date, place) 
     
    5763 
    5864-- solar elevation (degrees) 
    59 local function sunelevation (date, place) 
     65function sunelevation (date, place) 
    6066    return 90 - math.deg(sunzenithangle (date, place)) 
    6167end 
    6268 
    63 local function sunazimuthangle (date, place) 
     69function sunazimuthangle (date, place) 
    6470    local d = sundeclin (date) 
    6571    local sza = sunzenithangle (date, place) 
     
    6874end 
    6975 
    70  
    71  
    72 -- 
    73 testdate = {yday=319,hour=10,min=35,sec=0} 
    74 testplace= {latitude = 48+49/60, longitude=2+17/60+23/3600} 
    75 print ('g =',fractyear (testdate)) 
    76 print ('D =',sundeclin (testdate)) 
    77 print ('TC =',timecorrection (testdate)) 
    78 print ('SHA =',math.deg(solarhourangle (testdate, testplace))) 
    79 print ('SZA =',math.deg(sunzenithangle (testdate, testplace))) 
    80 print ('elev =',sunelevation (testdate, testplace)) 
    81 print ('AZ =',math.deg(sunazimuthangle(testdate, testplace))) 
    82  
    83 print ('elev local = ',sunelevation (os.date('*t'), {longitude=77.05, latitude=-12.05})) 
  • /timeutils.lua

    r1 r3  
    1  
     1local type = type 
    22local os = os 
    33 
     
    77function lastmidnight (time) 
    88    local d = os.date('*t', time) 
    9     return os.time ({year=d.year, month=d.month, day=d.day}) 
     9    return os.time ({year=d.year, month=d.month, day=d.day, hour=0}) 
    1010end 
    1111 
     
    1616end 
    1717 
     18function localtoUTC(time, timezone) 
     19    time = time or os.time() 
     20    if type(time) == "table" then 
     21        time = os.time(time) 
     22    end 
     23 
     24    local d = os.date('*t', time) 
     25    if d.isdst then timezone = timezone+1 end 
     26    d = os.date('*t', time - timezone*3600) 
     27    return d 
     28end 
Note: See TracChangeset for help on using the changeset viewer.