Hello!
In my work (Climate sciences) we often use netCDF files. I’m wondering about the best way to handle the possible types in these files and how it affect the function that will use the extracted arrays inside those netCDF files.
The problem comes from the fact that the data inside the netCDF files can be either Float32 or Float64. My extraction function will fetch the data and put everything into AxisArrays (and then a custom type ClimGrid
containing the metadata from the netCDF files). Hence, this means that the data inside the AxisArrays are sometimes Float32 and sometimes Float64, depending on the file.
My question is thus: what should I do for functions that are acting on the data? Should I create 2 functions, one with Float32 as argument and one with Float64 as the argument?
e.g.
foo(x::Float32)
foo(x::Float64)
Or perhaps should I just promote everything to Float64 (but this is costly, we are speaking about arrays of size 365 x 1068 x 510
for a single year of data and this can easily extends to 60-70 years.
I guess that there is an more easier answer involving “parametric” approach, but I must admit that I’m slightly lost with this approach.
Any hint or examples would be greatly appreciated!