#!/bin/sh # Regenerates crates/resolved/src/solar_data.rs from LISIRD. # # The source is the TSIS-1 Hybrid Solar Reference Spectrum at 1 nm bandwidth, # which LISIRD serves sampled every 0.1 nm. Keeping every 10th row (integer # wavelengths) loses nothing: the spectrum is already smoothed to 1 nm. # Values are written in SI units (meters, W/m^2 per meter) to 6 significant # figures, well inside the data's 0.3 % uncertainty. set -eu url='https://lasp.colorado.edu/lisird/latis/dap/tsis1_hsrs_1nm.csv' out="$(dirname "$0")/../crates/resolved/src/solar_data.rs" tmp=$(mktemp) trap 'command rm -f "$tmp"' EXIT curl -fsS "$url" -o "$tmp" # Integer-nanometer rows only, as "wavelength_m irradiance_per_m". rows=$(awk -F, 'NR > 1 && $1 ~ /\.0$/ { printf "%.0fe-9 %.5e\n", $1, $2 * 1e9 }' "$tmp") count=$(printf '%s\n' "$rows" | wc -l) # One column of $rows as a Rust array body, six values per line. emit() { printf '%s\n' "$rows" | awk -v col="$1" ' { v[NR] = $col } END { for (i = 1; i <= NR; i++) { if ((i - 1) % 6 == 0) printf " "; printf "%s,", v[i]; if (i % 6 == 0 || i == NR) printf "\n"; else printf " "; } }' } { echo "//! The TSIS-1 Hybrid Solar Reference Spectrum: solar spectral irradiance at 1 AU." echo "//!" echo "//! @generated by scripts/fetch-solar-spectrum.sh on $(date -u +%Y-%m-%d) from" echo "//! <$url>. Do not edit by hand." echo "//!" echo "//! Coddington, O. M., et al. (2021). The TSIS-1 Hybrid Solar Reference Spectrum." echo "//! Geophysical Research Letters, 48, e2020GL091709." echo "//! " echo "" echo "/// Vacuum wavelength, in meters, every 1 nm from 202 to 2730 nm." echo "#[rustfmt::skip]" echo "pub(crate) static WAVELENGTH: [f64; $count] = [" emit 1 echo "];" echo "" echo "/// Solar spectral irradiance at 1 AU over a 1 nm band, in W/m^2 per meter of wavelength." echo "#[rustfmt::skip]" echo "pub(crate) static IRRADIANCE: [f64; $count] = [" emit 2 echo "];" } > "$out" echo "wrote $count samples to $out"