7 print('usage: %s <coefficients.txt>' % sys
.argv
[0])
15 return d
.rstrip('0').rstrip('.')
22 with
open(sys
.argv
[1]) as fin
:
24 if l
.startswith(('#', 'c/s')): continue
28 assert(ldata
[1] == 'n' and ldata
[2] == 'm')
29 years
= get_values(ldata
)
30 elif ldata
[0] in ('g', 'h'):
33 data
[ldata
[0],n
,m
] = list(get_values(ldata
))
34 data
[ldata
[0]+'_delta',n
,m
] = ldata
[len(ldata
)-1],
35 max_n
= max(max_n
, n
, m
)
37 raise ValueError('data line in unknown format!')
39 with
open('../thgeomagdata.h','w') as fout
:
40 fout
.write('''// generated by geomag/igrf2c.py
42 #ifndef thgeomagdata_h
43 #define thgeomagdata_h
46 for gh
in ('g', 'h', 'g_delta', 'h_delta'):
53 suffix
= '[%d]' % len(years
)
54 yy
= range(0,len(years
))
55 fout
.write('static const double thgeomag_%sNM%s[%d][%d] = {\n' %
56 (gh
[0].upper(),suffix
,max_n
+1,max_n
+1))
58 if not isdelta
: fout
.write('{\n')
59 for n
in range(0,max_n
+1):
61 for m
in range(0,max_n
+1):
62 fout
.write('%s, ' % (iround(data
[gh
,n
,m
][y
]) if (gh
,n
,m
) in data
else '0'))
64 if not isdelta
: fout
.write('},\n')
68 '''#define thgeomag_maxmindex %d
69 #define thgeomag_step %d
70 #define thgeomag_minyear %d
71 #define thgeomag_maxdeg %d
75 ''' % (len(years
)-1, float(years
[1])-float(years
[0]), float(years
[0]), max_n
))
77 print('OK: ../thgeomagdata.h created')