Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LAMBERT Jean-charles
uns_projects
Commits
966834ea
Commit
966834ea
authored
Jun 22, 2017
by
LAMBERT Jean-charles
Browse files
give simulation latest time
parent
cac55717
Changes
1
Hide whitespace changes
Inline
Side-by-side
py/mains/uns_final_time.py
0 → 100755
View file @
966834ea
#!/usr/bin/env python
from
__future__
import
print_function
import
sys
#sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path
from
simulations.cmovie
import
*
import
argparse
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# commandLine, parse the command line
def
commandLine
():
dbname
=
None
# help
parser
=
argparse
.
ArgumentParser
(
description
=
"Display simulation final time"
,
formatter_class
=
argparse
.
ArgumentDefaultsHelpFormatter
)
# options
parser
.
add_argument
(
'simname'
,
help
=
'Simulation name'
)
parser
.
add_argument
(
'--save'
,
help
=
'Save file'
,
dest
=
'save'
,
action
=
'store_true'
,
default
=
False
)
parser
.
add_argument
(
'--filename'
,
help
=
'Filename to save final time, if None uses simulation directory'
,
default
=
None
)
parser
.
add_argument
(
'--dbname'
,
help
=
'UNS database file name'
,
default
=
dbname
)
parser
.
add_argument
(
'--verbose'
,
help
=
'verbose mode on'
,
dest
=
"verbose"
,
action
=
"store_true"
,
default
=
False
)
#parser.add_argument('--no-verbose',help='verbose mode off', dest="verbose", action="store_false", default=True)
# parse
args
=
parser
.
parse_args
()
# start main funciton
process
(
args
)
# -----------------------------------------------------
# process, is the core function
def
process
(
args
):
sql3
=
UnsSimu
(
args
.
simname
)
#sql3.printInfo(simname)
r
=
sql3
.
getInfo
(
args
.
simname
)
if
(
r
):
snap_list
=
sql3
.
getSnapshotList
()
latest
=
snap_list
[
-
1
]
print
(
"Latest snapshot [%s]
\n
"
%
(
latest
),
file
=
sys
.
stderr
)
s
=
CSnapshot
(
latest
)
ok
=
s
.
nextFrame
(
"I"
)
ok
,
t
=
s
.
getData
(
"time"
)
if
ok
:
print
(
"Latest time [%f]
\n
"
%
(
t
),
file
=
sys
.
stderr
)
if
args
.
save
:
filename
=
args
.
filename
if
args
.
filename
is
None
:
#simulation dir
filename
=
r
[
'dir'
]
+
"/final_time.txt"
print
(
"Save to <%s>
\n
"
%
(
filename
),
file
=
sys
.
stderr
)
index
=
(
latest
.
split
(
"/"
)[
-
1
]).
split
(
"_"
)[
-
1
]
try
:
f
=
open
(
filename
,
"w"
)
f
.
write
(
"simname %s
\n
"
%
(
args
.
simname
))
f
.
write
(
"last_file %s
\n
"
%
(
latest
))
f
.
write
(
"last_index %s
\n
"
%
(
index
))
f
.
write
(
"last_time %f
\n
"
%
(
t
))
f
.
close
()
except
:
print
(
"
\n\n
Unable to save in <%s>, aborting....
\n
"
%
(
filename
))
sys
.
exit
()
# -----------------------------------------------------
# main program
if
__name__
==
'__main__'
:
commandLine
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment