I wrote a little program to help people figure out top-of-the-atmosphere insolation year-round all over the globe. You can modify it for more specific purposes. It is written mostly in *awk* – the best programming language for processing columnated data tables.

```
#!/usr/bin/bash
# Zoe Phin, 2019/10/30
awk '
function asin(x) { return atan2(x, sqrt(1-x*x)) }
function rad(x) { return x*PI/180 }
function abs(x) { if (x<0) x=-1*x; return x }
function color(n) { return sprintf("\033[0;%sm", n) }
BEGIN {
PI = atan2(0,-1)
TSI = 1361; YEAR = 365.2422; TILT = 23.45; ECC = 0.017
VEQ = 79.915; PHA = 2.013 # Vernal Equinox & Perihelion Adjustment
for (day = 0; day < 365; day++) {
for (lat = 85; lat >= -85; lat -= 10) {
printf "%03d ", day+1
if (lat < 0) { printf "%02dS ", 0-lat }
else { printf "%02dN ", lat }
for (hour = -12; hour <= 11; hour++) {
dh = day + hour/24
ORB = 1-ECC*cos(2*PI*(dh-PHA)/YEAR)
DEC = asin(sin(rad(TILT)*sin(2*PI*(dh-VEQ)/YEAR)))
LAT = rad(lat); LON=rad(15*hour)
INS = (sin(LAT)*sin(DEC)+cos(LAT)*cos(DEC)*cos(LON))
if (INS<0) { INS = 0 } else { INS = TSI/ORB*INS }
c = color(36) # Cyan
if (INS > 315) { c = color(34) } # Blue
if (INS > 500) { c = color(32) } # Green
if (INS > 700) { c = color(33) } # Orange
if (INS > 1000) { c = color(31) } # Red
printf "%s%4d\033[0m ", c, INS
avg += INS/24
}
area = 2*PI*abs((sin(rad(lat+5)))-sin(rad(lat-5)))
contrib = avg*area/(4*PI)
dayavg += contrib
printf "| %3d %.2f %2d\n", avg, area, contrib
avg = 0
}
printf "Day Global Average: %.3f\n", dayavg
annavg += dayavg/365
dayavg = 0
}
print "Annual Global Average: "annavg
}'
```

Copy above text to a new text file. Save it as toa.sh (for example). Make it executable and run it:

```
> chmod +x toa.sh
> ./toa.sh
```

The beginning output should look like this:

The first column is the day #. Second column is the latitude. The next 24 columns are hours, starting from midnight. The 3rd to last column is the average insolation for the latitude. The 2nd to last column is the surface area weight of the latitude for a sphere with radius 1. The vertical total for this column should add up to 4π. The last column is just the previous two columns multiplied with each other and then divided by 4π. The vertical sum of this column adds up to the Day Global Average.

The last line is the average for the whole year

`Annual Global Average: 339.926`

Now here is something really neat. I animated a whole year!

Enjoy! -Zoe

Edit: I don’t like how wordpress makes things complicated. To see the animation in full size, right click **here**, and select “Open in New Tab”.