Peano
Loading...
Searching...
No Matches
MSISEtoCSV.py
Go to the documentation of this file.
1from sys import argv
2from os.path import splitext
3
4if len(argv) != 2 or argv[1] == "help":
5 print("\tpositional argument: filepath to MSISE data")
6 quit(0)
7try:
8 with open(argv[1], "r") as f:
9 replacedLines = []
10 for line in f:
11 replacedLine = ""
12 lastAlphaNum = True
13 for c in line:
14 if c == " " and lastAlphaNum:
15 replacedLine += ";"
16 lastAlphaNum = False
17 elif c == " " and not lastAlphaNum:
18 pass
19 else:
20 replacedLine += c
21 lastAlphaNum = True
22 replacedLines.append(replacedLine)
23
24 CSVFilename = splitext(argv[1])[0] + ".csv"
25 try:
26 with open(CSVFilename, "w") as csv:
27 for line in replacedLines:
28 csv.write(line)
29 except OSError:
30 print(f"Could not create CSV file at {CSVFilename}.")
31
32 print(
33 "NOTE: The separator ';' might not be inserted in the head line between 'Heden(cm-3)' and 'Arden(cm-3)'. This does not influence the csv file for usage in ExaHyPE 2."
34 )
35
36except OSError:
37 print(
38 f'Could not open file at {argv[1]}. For help, use first positional argument "help".'
39 )