forked from PmagPy/PmagPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_methods.py
executable file
·53 lines (50 loc) · 1.4 KB
/
extract_methods.py
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
#!/usr/bin/env python
import string,sys,pmag
def main():
"""
NAME
extract_methods.py
DESCRIPTION
reads in a magic table and creates a file with method codes
SYNTAX
extract_methods.py [command line options]
OPTIONS
-h: prints the help message and quits.
-f FILE: specify magic format input file, default is magic_measurements.txt
-F FILE: specify method code output file, default is magic_methods.txt
"""
citation='This study'
args=sys.argv
outfile='magic_methods.txt'
infile='magic_measurements.txt'
#
# get command line arguments
#
dir_path='.'
if '-WD' in args:
ind=args.index("-WD")
dir_path=args[ind+1]
if "-h" in args:
print main.__doc__
sys.exit()
if '-F' in args:
ind=args.index("-F")
outfile=args[ind+1]
if '-f' in args:
ind=args.index("-f")
infile=args[ind+1]
infile=dir_path+'/'+infile
outfile=dir_path+'/'+outfile
data,file_type=pmag.magic_read(infile)
MethRecs=[]
methods=[]
for rec in data:
meths=rec['magic_method_codes'].split(":")
for meth in meths:
if meth not in methods:
MethRec={}
methods.append(meth)
MethRec['magic_method_code']=meth
MethRecs.append(MethRec)
pmag.magic_write(outfile,MethRecs,'magic_methods')
main()