Code:
#! /usr/bin/python
import getopt
import popen2
import sys
import types
import os
__author__="user"
__date__ ="$20-Nov-2010 17:43:52$"
def print_info():
print ""
print "-------------------------------------------------------------"
print ""
print "SCRIPT: ../Scripts/tsimplex.csh"
print ""
print "VERSION: %s"%(Version)
print ""
print "CREATED BY: CHRISTOPHER DIMECH"
print ""
print "PURPOSE: Runs Tommy tsimplex"
print ""
print "USAGE:"
print ""
print " $s"%(print_usage(1))
print ""
print "WHERE:"
print ""
print " (O) fout.cmod Best sound speed model found"
print " (O) fout.back Backup file for "
print " (O) fout.expl Exploration file"
print " (O) fout.log Log file with misfit values"
print " (I) tpath Path to TOMMY tsimplex"
print " (I) fbase.base Model dimensions file"
print " (I) fdata.dat Travel times file"
print " (I) fstmod.cmod Starting Sound Speed Model"
print " (I) frestore.back Restore population from a backup file"
print " (I) ftag Appends a tag to the output file names"
print " (I) nxz Model size to invert, e.g. 3x2"
print " (I) varp Sound speed variation allowed"
print " (I) sigma0 "
print " (I) maxiter Number of iterations to perform"
print " (I) vrb Verbosity level for log file"
print " vrb options = none, low, medium, high"
print " (I) -tpf Create a tommy parameter file"
print " (I) -tee "
print " (I) -usage Details of the arguments"
print " (I) -help Details on using this script"
print ""
print "EXAMPLES:"
print ""
print "-------------------------------------------------------------"
print ""
def print_usage(asstring=0):
arg1="../Scripts/tsimplex.csh"
arg2="[-tpath=] [-base=fbase.base] [-data=fdata.dat]"
arg3="[-fstmod=fstmod.vmod] [-restore=frestore.back -ftag=]"
arg4="-nxz= -varp= -sigma= [-vrb=vrb] -tpf [-tee] [-usage] [-help]"
# usage="$arg1 $arg2 $arg3 $arg4"
usage="%s %s %s %s"%(arg1,arg2,arg3,arg4)
if asstring == 0:
print usage
else:
return usage
if __name__ == "__main__":
x = "ls -lrt"
os.system(x)
Version="V03"
tpath = None
fbase = None
fdata = None
fstmod = None
frestore = None
ftag = None
fsr = None
frc = None
frestoretag = None
nxz = None
varp = None
sigma = None
maxiter = None
dtau = None
mdacc = None
mindist = None
maxitertp = None
vrb = None
tpf = None
tee = None
usage = None
eg = None
help = None
info = None
long_opts = ['tpath',
'fbase',
'fdata',
'fstmod',
'frestore',
'frestoretag',
'nxz',
'varp',
'sigma',
'maxiter',
'dtau',
'mdacc',
'mindist',
'maxitertp',
'vrb',
'tpf',
'tee',
'usage',
'eg',
'help',
'info']
try:
optlist, args = getopt.getopt(sys.argv[1:], "", long_opts)
except getopt.GetoptError, err:
# print help information and exit:
print str(err) # will print something like "option -a not recognized"
print_usage()
sys.exit(2)
for opt, val in optlist:
if opt == "--help":
print_info()
sys.exit()
elif opt == "--eg":
print_usage()
sys.exit()
elif opt == "--info":
print_info()
sys.exit()
elif opt == "--usage":
print_usage()
sys.exit()
elif opt == "--tpath":
tpath = val
print " -tpath = tpath"
print " -tpath = ",val
print ""
elif opt == "--fbase":
fbase = val.split('.base')[0]
print " -fbase = fbase.base"
print " -fbase = ",val
print ""
elif opt == "--fdata":
fdata = val.split('.dat')[0]
print " -fdata = fdata.dat"
print " -fdata = ",val
print ""
elif opt == "--fstmod":
fstmod = val.split('.cmod')[0]
print " -fstmod = fstmod.cmod"
print " -fstmod = ",val
print ""
elif opt == "--frestore":
frestore = val
print " -frestore = frestore.back"
print " -frestore = ",val
print ""
elif opt == "--ftag":
ftag = val
print " -ftag = ftag"
print " -ftag = ",val
print ""
elif opt == "--nxz":
nxp = val.split('x')[0]
nzp = val.split('x')[1]
print " -nxz = nxz"
print " -nxz = ",val
print ""
elif opt == "--varp":
varpint = val.split('.')[0]
varpfrc = val.split('.')[1]
print " -varp = varp"
print " -varp = ",val
print ""
elif opt == "--sigma":
sigma = val
print " -sigma = sigma"
print " -sigma = ",val
print ""
elif opt == "--maxiter":
maxiter = val
print " -maxiter = maxiter"
print " -maxiter = ",val
print ""
elif opt == "--dtau":
dtau = val
print " -dtau = dtau"
print " -dtau = ",val
print ""
elif opt == "--mdacc":
mdacc = val
print " -mdacc = mdacc"
print " -mdacc = ",val
print ""
elif opt == "--mindist":
mindist = val
print " -mindist = mindist"
print " -mindist = ",val
print ""
elif opt == "--maxitertp":
maxitertp = val
print " -maxitertp = maxitertp"
print " -maxitertp = ",val
print ""
elif opt == "--vrb":
vrb = val
print " -vrb = vrb"
print " -vrb = ",val
print ""
elif opt == "--tpf":
tpf = val
print " -tpf"
print ""
elif opt == "--tee":
tee = val
print " -tee (Create tommy parameter file)"
print ""
else:
print ""
print "ERROR: Unrecognised argument,",opt
print ""
sys.exit(-1)
# -------------------------------------------------------------------
# USER HAS NOT ASKED FOR INFORMATION ABOUT THE USE OF THIS SCRIPT
# 1. Exit script if argument not recognized
# 2. Set appropriate defaults if options not set
# -------------------------------------------------------------------