-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnmfluxtoaero
executable file
·82 lines (65 loc) · 2 KB
/
nmfluxtoaero
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
from pylab import *
import pylab
from optparse import OptionParser
import sys
import re
def srint_array(arr, colnumber=5, precision=6, number=14, type='e'):
""" Creates a string with the array in the formatted way:
arr : the array
colnumber : the number of printed columns
precision :
number
type: e, f, g, i
"""
output = ""
prefix = '\t\t\t'
islogger = False
formatstr = "%i.%i" % (number, precision)
formatstr = '%'+formatstr+type
size = len(arr)
tbl = [formatstr for i in range(colnumber)]
colformat = '\t'.join(tbl)
for i in range(int(size/colnumber)):
output += prefix
output += colformat % tuple(arr[i*colnumber:(i+1)*colnumber])
output += "\n"
reste = size % colnumber
if reste != 0:
colfort = '\t'.join([formatstr for i in range(reste)])
output += prefix + colfort % tuple(arr[-reste:])
output += "\n"
return output
parser = OptionParser()
parser.add_option("-f", "--file", dest="filename", help="The input file ", type="string")
parser.add_option("-o", "--outfile", dest="outname", help="The output file", type="string")
(options, args) = parser.parse_args()
filename = options.filename
if(not filename):
if(len(args)):
print "Dans les args : "
filename = args[0]
else:
print "Pas de fichiers"
sys.exit()
data = pylab.loadtxt(filename)
wavelength = data[:, 0]
flux = data[:, 1]
# we suppose that the energy is decreasing. ie the wavelength is increasing
energy = 1239.842/wavelength
# print srint_array(wavelength,type="f")
# print srint_array(energy,type="f")
# print srint_array(flux)
result = "\t<continuum>\n"
result += "\t\t<Egrid>\n"
result += srint_array(energy, type="f")
result += "\t\t</Egrid>\n"
result += "\t\t<PhotFlux>\n"
result += srint_array(flux)
result += "\t\t</PhotFlux>\n"
result += "\t</continuum>\n"
if(not options.outname):
print result
else:
outf = open(options.outname, "w")
outf.writelines(result)