@@ -33,7 +33,7 @@ type epochData struct {
3333 coeffs * []float64
3434}
3535
36- // NewCoeffsData - returns an initialized IGRF SHC data structure.
36+ // Returns an initialized IGRF SHC data structure.
3737func NewCoeffsData () (* IGRFcoeffs , error ) {
3838 igrf := IGRFcoeffs {data : & map [string ]* epochData {}}
3939 if err := igrf .readCoeffs (); err != nil {
@@ -42,7 +42,8 @@ func NewCoeffsData() (*IGRFcoeffs, error) {
4242 return & igrf , nil
4343}
4444
45- // Coeffs - returns two sets of SHC coeffs for the given `date`, as well as for `date` plus one year. Also returns the maximal spherical harmonic degree.
45+ // Returns two sets of SH coeffs for the given `date`,
46+ // as well as for `date` plus one year. Also returns the maximal spherical harmonic degree.
4647func (igrf * IGRFcoeffs ) Coeffs (date float64 ) (* []float64 , * []float64 , int , error ) {
4748 max_column := len (* igrf .epochs )
4849 min_epoch := (* igrf .epochs )[0 ]
@@ -65,6 +66,10 @@ func (igrf *IGRFcoeffs) Coeffs(date float64) (*[]float64, *[]float64, int, error
6566 return coeffs_start , coeffs_end , nmax , nil
6667}
6768
69+ // Computes a set of SH coeffs and the maximal spherical harmonic degree
70+ // for a given `date` and `start_epoch`, `end_epoch`.
71+ //
72+ // `date` must be less than the maximal possible epoch.
6873func (igrf * IGRFcoeffs ) interpolateCoeffs (start_epoch , end_epoch string , date float64 ) (* []float64 , int ) {
6974 factor , err := findDateFactor (start_epoch , end_epoch , date )
7075 if err != nil {
@@ -116,6 +121,10 @@ func (igrf *IGRFcoeffs) interpolateCoeffs(start_epoch, end_epoch string, date fl
116121 return & values , nmax
117122}
118123
124+ // Computes a set of SH coeffs and the maximal spherical harmonic degree
125+ // for a given `date` and `start_epoch`, `end_epoch`.
126+ //
127+ // `date` is beyond than the maximal possible epoch.
119128func (igrf * IGRFcoeffs ) extrapolateCoeffs (start_epoch , end_epoch string , date float64 ) * []float64 {
120129 dte1 , _ := strconv .ParseFloat (start_epoch , 32 )
121130 factor := date - dte1
@@ -145,6 +154,8 @@ func (igrf *IGRFcoeffs) extrapolateCoeffs(start_epoch, end_epoch string, date fl
145154 return & values
146155}
147156
157+ // Calculates start and end epochs for a given date,
158+ // default `interval` is used for borders and for multiplicity
148159func (igrf * IGRFcoeffs ) findEpochs (date float64 ) (string , string ) {
149160 max_column := len (* igrf .epochs )
150161 min_epoch := (* igrf .epochs )[0 ]
@@ -162,6 +173,7 @@ func (igrf *IGRFcoeffs) findEpochs(date float64) (string, string) {
162173 return start_epoch , end_epoch
163174}
164175
176+ // The main function that populates the existing `IGRFcoeffs` structure.
165177func (igrf * IGRFcoeffs ) readCoeffs () error {
166178 line_provider := coeffsLineProvider ()
167179
@@ -189,6 +201,7 @@ func (igrf *IGRFcoeffs) readCoeffs() error {
189201 return nil
190202}
191203
204+ // Finds lines with epochs, parses these lines and returns arrays of epochs: names and floats.
192205func getEpochs (reader <- chan string ) (* []string , * []float64 , error ) {
193206 cs_re := regexp .MustCompile (`^c/s.*` )
194207 for line := range reader {
@@ -202,6 +215,7 @@ func getEpochs(reader <-chan string) (*[]string, *[]float64, error) {
202215 return nil , nil , errors .New ("Unable to get epochs." )
203216}
204217
218+ // Parses the header of the coeffs. Usually it's the first two non-comment lines.
205219func parseHeader (line1 , line2 string ) ([]string , []float64 ) {
206220 line1_data := space_re .Split (line1 , - 1 )
207221 line2_data := space_re .Split (line2 , - 1 )
@@ -236,6 +250,7 @@ func parseHeader(line1, line2 string) ([]string, []float64) {
236250 return names , epochs [shift :]
237251}
238252
253+ // Parses lines with coefficients and populates the `IGRFcoeffs` structure.
239254func (igrf * IGRFcoeffs ) getCoeffsForEpochs (provider <- chan string ) error {
240255 var i int = 0
241256 for line := range provider {
@@ -250,6 +265,7 @@ func (igrf *IGRFcoeffs) getCoeffsForEpochs(provider <-chan string) error {
250265 return nil
251266}
252267
268+ // Populates the corresponding fields inside the `IGRFcoeffs` structure with actual coeffs.
253269func (igrf * IGRFcoeffs ) loadCoeffs (line_num int , line_coeffs * []float64 ) {
254270 for index , coeff := range * line_coeffs {
255271 epoch := (* igrf .epochs )[index ]
@@ -258,7 +274,7 @@ func (igrf *IGRFcoeffs) loadCoeffs(line_num int, line_coeffs *[]float64) {
258274 }
259275}
260276
261- // nMaxForEpoch - returns max spherical harmonic degree for a certain epoch
277+ // Returns max spherical harmonic degree for a certain epoch.
262278func nMaxForEpoch (epoch string ) (int , error ) {
263279 // this is hardcoded
264280 var nmax int
0 commit comments