Code:
if __name__ == "__main__":
Version="V01"
tpath = None;
fbase = None
fdata = None;
fstmod = None;
frestore = None;
ftag = None;
nlay = None;
param = None;
intp = None;
std = None;
tol = None;
nxz = None;
nxp = None;
nzp = None;
npop = None;
varp = None;
varpint = None;
varpfrc = None;
sigma = None;
maxiter = None;
dtau = None;
mdacc = None;
mindist = None;
maxitertp = None;
vrb = None;
tpf = None;
tee = None;
long_opts= [
"tpath=",
"fbase=",
"fdata=",
"fstmod=",
"frestore=",
"ftag=",
"tee=",
"nxz=",
"npop=",
"varp=",
"sigma=",
"maxiter=",
"dtau=",
"mdacc=",
"mindist=",
"maxitertp=",
"tpf=",
"vrb=",
"usage",
"example",
"help"]
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 == "--usage":
print_usage()
sys.exit()
elif opt == "--example":
print_example()
sys.exit()
elif opt == "--help":
print_help()
sys.exit()
elif opt == "--tpath":
tpath = val
elif opt == "--fbase":
fbase = val.split('.base')[0];
elif opt == "--fdata":
fdata = val.split('.dat')[0];
elif opt == "--fstmod":
fstmod = val.split('.cmod')[0];
elif opt == "--frestore":
frestore = val
elif opt == "--ftag":
ftag = val
elif opt == "--nxz":
nxp = val.split('x')[0];
nzp = val.split('x')[1];
elif opt == "--npop":
npop = val
elif opt == "--varp":
varpint = val.split('.')[0]
varpfrc = val.split('.')[1]
elif opt == "--sigma":
sigma = val
elif opt == "--maxiter":
maxiter = val
elif opt == "--dtau":
dtau = val
elif opt == "--mdacc":
mdacc = val
elif opt == "--mindist":
mindist = val
elif opt == "--maxitertp":
maxitertp = val
elif opt == "--vrb":
vrb = val
elif opt == "--tpf":
tpf = val
elif opt == "--tee":
tee = val
else:
print "\n ERROR: Unrecognised argument,",opt
print ""
sys.exit(-1)
# -------------------------------------------------------------------
# Check for any errors that might occur
# -------------------------------------------------------------------
if npop == 0:
print "\n ERROR: npop not set"
print " Set npop using the --npop directive\n"
sys.exit(-1)
if not isinstance(fstmod,types.NoneType) and not isinstance(frestore,types.NoneType):
print "\n ERROR: Cannot have both --fstmod and --frestore directives"
print " Set only one of them\n"
sys.exit(-1)
if not isinstance(frestore,types.NoneType) and isinstance(ftag,types.NoneType):
print "\n ERROR: The --frestore directive requires --ftag"
print " Set ftag using the --ftag directive\n"
sys.exit(-1)
# ---------------------------------------------------------------
# SET DEFAULT VALUES IF DIRECTIVES NOT SET
# ---------------------------------------------------------------
print "\nSETTING DEFAULT ARGUMENTS ...\n"
if isinstance(fbase,types.NoneType):
basefile_count = 0
file_name = ""
for root, subFolders, files in os.walk(os.getcwd()):
for file in files:
fbase = file
if file.find('.base') != -1 :
file_name = file
basefile_count = basefile_count + 1
if basefile_count > 1:
print "\nERROR: %s base files exist" %(basefile_count)
print " Set the base file using the --fbase directive\n"
sys.exit(-1)
fbase = file_name.split('.base')[0];
# -------------------------------------------------------------------
if isinstance(fdata,types.NoneType):
basefile_count = 0
file_name = ""
for root, subFolders, files in os.walk(os.getcwd()):
for file in files:
fdata = file
if file.find('.dat') != -1 :
file_name = file
basefile_count = basefile_count + 1
if basefile_count > 1:
print "\nERROR: %s data files exist"%(basefile_count)
print " Set the data file using the --fdata directive\n"
sys.exit(-1)
fbase = file_name.split('.')[0];
# ---------------------------------------------------------------
if (isinstance(tpath,types.NoneType)):
tpath = "/nethome/chrisd/"
if (isinstance(sigma,types.NoneType)):
sigma = 1.0
if (isinstance(maxiter,types.NoneType)):
maxiter = 200
if (isinstance(dtau,types.NoneType)):
dtau = 0.03
if (isinstance(mdacc,types.NoneType)):
mdacc = 0.3
if (isinstance(mindist,types.NoneType)):
mindist = 0.05
if (isinstance(maxitertp,types.NoneType)):
maxitertp = 25
if (isinstance(vrb,types.NoneType)):
vrb = "medium"
if (isinstance(nlay,types.NoneType)):
nlay = 1
if (isinstance(param,types.NoneType)):
param = "P"
if (isinstance(intp,types.NoneType)):
intp = "LIN"
if (isinstance(std,types.NoneType)):
std = "on"
if (isinstance(tol,types.NoneType)):
tol = 0.0
# -------------------------------------------------------------------
# PRINT COMMAND LINE ARGUMENTS
# -------------------------------------------------------------------
print "\nCOMMAND LINE ARGUMENTS:\n"
if (not isinstance(tpath,types.NoneType)):
print " -tpath = %s\n"%(tpath)
if (not isinstance(fbase,types.NoneType)):
print " -fbase = %s\n"%(fbase)
if (not isinstance(fdata,types.NoneType)):
print " -fdata = %s\n"%(fdata)
if (not isinstance(fstmod,types.NoneType)):
print " -fstmod = %s\n"%(fstmod)
if (not isinstance(frestore,types.NoneType)):
print " -frestore = %s\n"%(frestore)
if (not isinstance(ftag,types.NoneType)):
print " -ftag = %s\n"%(ftag)
if (not isinstance(nxz,types.NoneType)):
print " -nxz = %s\n"%(nxz)
if (not isinstance(npop,types.NoneType)):
print " -npop = %s\n"%(npop)
if (not isinstance(varp,types.NoneType)):
print " -varp = %s\n"%(varp)
if (not isinstance(sigma,types.NoneType)):
print " -sigma = %s\n"%(sigma)
if (not isinstance(maxiter,types.NoneType)):
print " -maxiter = %s\n"%(maxiter)
if (not isinstance(dtau,types.NoneType)):
print " -dtau = %s\n"%(dtau)
if (not isinstance(mdacc,types.NoneType)):
print " -mdacc = %s\n"%(mdacc)
if (not isinstance(mindist,types.NoneType)):
print " -mindist = %s\n"%(mindist)
if (not isinstance(maxitertp,types.NoneType)):
print " -maxitertp = %s\n"%(maxitertp)
if (not isinstance(vrb,types.NoneType)):
print " -vrb = %s\n"%(vrb)
# -------------------------------------------------------------------
# PRINT DEFAULTED VALUES
# -------------------------------------------------------------------
print "\nDEFAULTED ARGUMENTS:\n"
if (isinstance(fbase,types.NoneType)):
print " -fbase = %s\n"%(fbase)
if (isinstance(fdata,types.NoneType)):
print " -fdata = %s\n"%(fdata)
if (isinstance(sigma,types.NoneType)):
print " -sigma = %s\n"%(sigma)
if (isinstance(maxiter,types.NoneType)):
print " -maxiter = %s\n"%(maxiter)
if (isinstance(vrb,types.NoneType)):
print " -vrb = %s\n"%(vrb)
if (isinstance(dtau,types.NoneType)):
print " -dtau = %s\n"%(dtau)
if (isinstance(mdacc,types.NoneType)):
print " -mdacc = %s\n"%(mdacc)
if (isinstance(mindist,types.NoneType)):
print " -mindist = %s\n"%(mindist)
if (isinstance(maxitertp,types.NoneType)):
print " -maxitertp = %s\n"%(maxitertp)
if (isinstance(nlay,types.NoneType)):
print " -nlay = %s\n"%(nlay)
if (isinstance(param,types.NoneType)):
print " -param = %s\n"%(param)
if (isinstance(intp,types.NoneType)):
print " -intp = %s\n"%(intp)
if (isinstance(std,types.NoneType)):
print " -std = %s\n"%(std)
if (isinstance(tol,types.NoneType)):
print " -tol = %s\n"%(tol)