This is a golang port of the perth-3 tide calculation algorithm: https://github.com/asbjorn-christensen/GridWetData/blob/master/fortran_sources/perth3.f, further algorithms will follow The tool currently works with DTU-16 files from the danish technical university.
To calculate the current tide for a specific point and time you first need to download and extract the DTU-16 constituent file from the DTU ftp: ftp://ftp.space.dtu.dk/pub/DTU16/OCEAN_TIDE/PERTH3/fort.30.gz
either use the precompiled tool createconstituentdb
or substitute the command with go run ./cmd/createconstituentdb/main.go
to create constituent database with precalculated data for each constituent
createconstituentdb ./fort.30 ./dtu16.nc
after creating the tide database you can use the tool calculatetides
or go run ./cmd/calculatetides/main.go
calculatetides -constituentdb ./dtu16.nc -tstart "1985-01-01T00:00:00.000Z" -tend "1985-01-01T01:00:00.000Z" "37.010503,-8.962977"
this will calculate the height of the tide at a specific point and time, the time must be in RFC3339 format
Currently LAT and MSS for the point is not yet calculated to get a correct relative tide height above the LAT datum at the point, but will follow.
If you want to run the original tool, you can copy the fort.30 file into the same folder as the gettide1.f file and build the tool with the Makefile in the folder (gfortran must be installed)
Tides..., how do they work and how can this tool "predict" the tides at a specific location and time. The explanation you got in school about the moon attracting a body of water is just one very small part of the whole truth.
This simplified model would lead to no tides at the poles and enormous tides at the aequator which in reality is not not the case, quite contrary the poles do experience massive tides. The model would also only work if we would have no landmass that reflects or hinders the tidal wave, thats for example the case on the water planet from interstellar, but here on earth not the reality. So here on earth tides are not only created and effected by the gravity of the moon and other celestial bodies but also landmasses and ocean topography which reflect, amplify or dampen the waves. So the better model would be a huge bathtub which is shaken plus some gravity sources always in motion.
tide heights for the m2 constituent at a specific time[1]
But how are we able to predict tides in all this chaos? The key is to observe with the help of satellites and tide stations all changes in ocean height for a really long time, subtract, waves, surges and minor changes due to temperature and extract the different curves, frequencies and heights for every point on earth which add up to the curve describing the tide at the given point. This curve is called a tidal constituent. Multiple curves which make up the tide curve on a specific point are called tidal constituents. These curves all have specific names like P1, O2, M2, K2 and are calculated and distributed by different universities or meterological institutions. The constituent files for a specific tide constituent include the amplitude
values of a constituent file, amplitude and phase angle at t=0
Now a bit of math on how we can determine the height of the tide at a specific point at a specific date.
First of all, every constituent has a specific phase shift, so we have to normalize the curve, to get the height of the shifted sinoid curve at a
$$hcos_{c}(lat,lon) = A_{c}(lat,lon)cos(\omega_{c}(lat,lon)\frac{\pi}{180})$$
$$hsin_{c}(lat,lon) = A_{c}(lat,lon)sin(\omega_{c}(lat,lon)\frac{\pi}{180})$$
this leads to the following equation (also known as trigonometric identity):
this will give us the amplitude of the cosinus component
for amplitude=2 and phase=90deg hcos (red), hsin(blue) and resulting curve shifted by 90degrees (purple)
Now things get a bit more complex. With this base equation we now get the
the argument
With all of these equations and information we now can formulate the equation to get the calculated height
$$h(lat,lon, t) = \sum_{c=P1,O1,...}{hcos_c(lat,lon)*F(t)cos(ARG_c(t)+U_c(t)\frac{\pi}{180})+hsin_c(lat,lon)*F(t)sin(ARG_c(t)+U_c(t)\frac{\pi}{180})}$$
Ok, now to get the tide height for display, for this we need to know some oceanographic datums, in our case the LAT the lat is the lowest astronomical tide, meaning the lowest a tide can get only depending on the tide equation, don't taking local phenomenon like storm surges, wind, etc into account (HAT is the highest astronomical tide). Maps for navigation typically denote all depths relative to the LAT, meaning if the tide is at its lowest possible and the map is blue at your position you still have water under the keel :D. To calculate the
and
All tide heights are also displayed relative to the LAT, so the final equation to get the final tide height relative to the mean water level
The explanation for computation of the node corrections and arguments will follow :)