| 1 |
|
| 2 |
try: |
| 3 |
from cStringIO import StringIO |
| 4 |
import __builtin__ |
| 5 |
except ImportError: |
| 6 |
from io import StringIO |
| 7 |
import builtins as __builtin__ |
| 8 |
from auto import parseC |
| 9 |
from auto import parseB |
| 10 |
from auto import parseS |
| 11 |
from auto import parseBandS |
| 12 |
from auto import parseH |
| 13 |
from auto import bifDiag |
| 14 |
import os |
| 15 |
from auto import AUTOutil |
| 16 |
import sys |
| 17 |
import glob |
| 18 |
import shutil |
| 19 |
|
| 20 |
SIMPLE=0 |
| 21 |
EXPERT=1 |
| 22 |
|
| 23 |
|
| 24 |
from auto import AUTOExceptions |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
def command(f,*args,**kw): |
| 30 |
|
| 31 |
|
| 32 |
class cmd(object): |
| 33 |
if len(args) == 2: |
| 34 |
type = args[0] |
| 35 |
shortName = args[1] |
| 36 |
alias = kw.get("alias",[]) |
| 37 |
fun = staticmethod(f) |
| 38 |
__doc__ = f.__doc__ |
| 39 |
def __init__(self,*args,**kw): |
| 40 |
self.args = args |
| 41 |
self.kw = kw |
| 42 |
|
| 43 |
|
| 44 |
def __call__(self): |
| 45 |
return self.fun(*self.args,**self.kw) |
| 46 |
def undo(self): |
| 47 |
raise Exception("Undo undefined for this command") |
| 48 |
return cmd |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
def macro(command_list): |
| 56 |
for command in command_list: |
| 57 |
command() |
| 58 |
commandMacro = command(macro) |
| 59 |
|
| 60 |
|
| 61 |
def info(s): |
| 62 |
sys.stdout.write(s) |
| 63 |
|
| 64 |
|
| 65 |
def interact(command,*args): |
| 66 |
if not os.path.exists(command): |
| 67 |
command = command + '.exe' |
| 68 |
fullcmd = " ".join([command]+list(args)) |
| 69 |
if os.spawnv(os.P_WAIT,command, (os.path.basename(command),) + args) != 0: |
| 70 |
raise AUTOExceptions.AUTORuntimeError("Error running %s"%fullcmd) |
| 71 |
info("Finished running: " + fullcmd + "\n") |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
def clean(): |
| 78 |
"""Clean the current directory. |
| 79 |
|
| 80 |
Type FUNC() to clean the current directory. This command will |
| 81 |
delete all files of the form fort.*, *.*~, *.o, and *.exe. |
| 82 |
""" |
| 83 |
toclean = (glob.glob("fort.*") + glob.glob("*.o") + glob.glob("*.exe")+ |
| 84 |
glob.glob("*.*~")) |
| 85 |
|
| 86 |
files = [] |
| 87 |
for f in toclean: |
| 88 |
if f not in files: |
| 89 |
files.append(f) |
| 90 |
for f in files: |
| 91 |
os.remove(f) |
| 92 |
info("Deleting fort.* *.o *.exe *.*~ ... done\n") |
| 93 |
commandClean = command(clean,alias=['cl']) |
| 94 |
|
| 95 |
|
| 96 |
def copydemo(name): |
| 97 |
"""Copy a demo into the current directory. |
| 98 |
|
| 99 |
Type FUNC('xxx') to copy all files from auto/07p/demos/xxx to the |
| 100 |
current user directory. Here 'xxx' denotes a demo name; e.g., |
| 101 |
'abc'. To avoid the overwriting of existing |
| 102 |
files, always run demos in a clean work directory. |
| 103 |
""" |
| 104 |
demodir = os.path.join(os.environ["AUTO_DIR"],"demos",name) |
| 105 |
for f in glob.glob(os.path.join(demodir,"*")): |
| 106 |
if os.path.isdir(f): |
| 107 |
subdir = f[len(demodir)+len(os.sep):] |
| 108 |
try: |
| 109 |
os.remove(subdir) |
| 110 |
except OSError: |
| 111 |
pass |
| 112 |
try: |
| 113 |
os.mkdir(subdir) |
| 114 |
except OSError: |
| 115 |
pass |
| 116 |
for f2 in glob.glob(os.path.join(f,"*")): |
| 117 |
try: |
| 118 |
shutil.copy(f2, subdir) |
| 119 |
except IOError: |
| 120 |
pass |
| 121 |
try: |
| 122 |
shutil.copy(f, ".") |
| 123 |
except IOError: |
| 124 |
pass |
| 125 |
if (os.path.exists(os.path.join(demodir,"c.%s.1"%name)) and |
| 126 |
not os.path.exists(os.path.join(demodir,"c.%s"%name))): |
| 127 |
shutil.copy("c.%s.1"%name,"c.%s"%name) |
| 128 |
info("Copying demo %s ... done\n"%name) |
| 129 |
commandCopyDemo = command(copydemo,SIMPLE,"demo") |
| 130 |
|
| 131 |
|
| 132 |
def demo(name,runner=None): |
| 133 |
"""Copy a demo into the current directory and load it. |
| 134 |
|
| 135 |
Type FUNC('xxx') to copy all files from auto/07p/demos/xxx to the |
| 136 |
current user directory. Here 'xxx' denotes a demo name; e.g., |
| 137 |
'abc'. To avoid the overwriting of existing |
| 138 |
files, always run demos in a clean work directory. NOTE: This |
| 139 |
command automatically performs the load command as well. |
| 140 |
""" |
| 141 |
runner = withrunner(runner) |
| 142 |
lst = [commandCopyDemo(name)] |
| 143 |
slash = name.rfind("/") |
| 144 |
if slash != -1: |
| 145 |
name = name[slash+1:] |
| 146 |
lst.append(commandRunnerLoadName(name,runner)) |
| 147 |
return macro(lst) |
| 148 |
commandCopyAndLoadDemo = command(demo,alias=['dm']) |
| 149 |
|
| 150 |
|
| 151 |
def df(): |
| 152 |
"""Clear the current directory of fort files. |
| 153 |
|
| 154 |
Type FUNC() to clean the current directory. This command will |
| 155 |
delete all files of the form fort.*. |
| 156 |
""" |
| 157 |
toclean = glob.glob("fort.*") |
| 158 |
for f in toclean: |
| 159 |
os.remove(f) |
| 160 |
info("Deleting fort.* ... done\n") |
| 161 |
commandDeleteFortFiles = command(df,alias=['deletefort']) |
| 162 |
|
| 163 |
|
| 164 |
def us(name,templates=None): |
| 165 |
"""Convert user-supplied data files. |
| 166 |
|
| 167 |
Type FUNC('xxx') to convert a user-supplied data file 'xxx.dat' to |
| 168 |
AUTO format. The converted file is called 's.dat'. The original |
| 169 |
file is left unchanged. AUTO automatically sets the period in |
| 170 |
PAR(11). Other parameter values must be set in 'STPNT'. (When |
| 171 |
necessary, PAR(11) may also be redefined there.) The |
| 172 |
constants-file file 'c.xxx' must be present, as the AUTO-constants |
| 173 |
'NTST' and 'NCOL' are used to define the new mesh. For examples |
| 174 |
of using the 'userData' command see demos 'lor' and 'pen' (where |
| 175 |
it has the old name 'fc'). |
| 176 |
|
| 177 |
Note: this technique has been obsoleted by the 'dat' AUTO constant. |
| 178 |
""" |
| 179 |
info("Starting conversion of %s.dat : \n"%name) |
| 180 |
if glob.glob("%s.f90"%name) == []: |
| 181 |
if glob.glob("%s.f"%name) == []: |
| 182 |
equation_file="%s.c"%name |
| 183 |
else: |
| 184 |
equation_file="%s.f"%name |
| 185 |
else: |
| 186 |
equation_file="%s.f90"%name |
| 187 |
cfile = applyTemplate(name,"constants",templates) |
| 188 |
datfile = "%s.dat"%name |
| 189 |
info("(Required files : %s, %s, %s)\n"%(equation_file,cfile, |
| 190 |
datfile)) |
| 191 |
import runAUTO |
| 192 |
fconrun = runAUTO.runAUTO(makefile="$AUTO_DIR/cmds/cmds.make fcon") |
| 193 |
fconrun.config(e=name) |
| 194 |
fconrun.runMakefile(name) |
| 195 |
if os.path.exists(cfile): |
| 196 |
shutil.copy(cfile,"fort.2") |
| 197 |
if os.path.exists(datfile): |
| 198 |
shutil.copy(datfile,"fort.3") |
| 199 |
interact("./fcon") |
| 200 |
sfile = applyTemplate("dat","solution",templates) |
| 201 |
if os.path.exists("fort.8"): |
| 202 |
if os.path.exists(sfile): |
| 203 |
os.remove(sfile) |
| 204 |
os.rename("fort.8",sfile) |
| 205 |
info("Conversion done : converted file saved as %s\n"%sfile) |
| 206 |
files = glob.glob("fcon*") + ["fort.2", "fort.3"] |
| 207 |
for f in files: |
| 208 |
os.remove(f) |
| 209 |
commandUserData = command(us,alias=['userdata']) |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
def applyTemplate(text,template,templates=None): |
| 216 |
if templates is None: |
| 217 |
templates = {} |
| 218 |
templates["equation"] = "EQUATION_NAME=%s" |
| 219 |
templates["constants"] = "c.%s" |
| 220 |
templates["bifurcationDiagram"] = "b.%s" |
| 221 |
templates["solution"] = "s.%s" |
| 222 |
templates["diagnostics"] = "d.%s" |
| 223 |
templates["homcont"] = "h.%s" |
| 224 |
|
| 225 |
if text is None: |
| 226 |
return None |
| 227 |
elif type(text) in [type(""), type(1), type(1.0)]: |
| 228 |
rval = templates[template]%text |
| 229 |
tmp = glob.glob(rval) |
| 230 |
if len(tmp) > 0: |
| 231 |
rval = "" |
| 232 |
for x in tmp: |
| 233 |
rval = rval + x + " " |
| 234 |
rval = rval.strip() |
| 235 |
return rval |
| 236 |
else: |
| 237 |
return text |
| 238 |
|
| 239 |
|
| 240 |
def filenameTemplate(name=None,templates=None): |
| 241 |
name1={} |
| 242 |
name1["constants"] = applyTemplate(name,"constants",templates) |
| 243 |
name1["bifurcationDiagram"] = applyTemplate(name,"bifurcationDiagram",templates) |
| 244 |
name1["solution"] = applyTemplate(name,"solution",templates) |
| 245 |
name1["diagnostics"] = applyTemplate(name,"diagnostics",templates) |
| 246 |
return name1 |
| 247 |
|
| 248 |
|
| 249 |
def relabel(name1=None,name2=None,templates=None): |
| 250 |
"""Relabel data files. |
| 251 |
|
| 252 |
Type y=FUNC(x) to return the python object x, with the solution |
| 253 |
labels sequentially relabelled starting at 1, as a new object y. |
| 254 |
|
| 255 |
Type FUNC('xxx') to relabel s.xxx and b.xxx. Backups of the |
| 256 |
original files are saved. |
| 257 |
|
| 258 |
Type FUNC('xxx','yyy') to relabel the existing data-files s.xxx and b.xxx, |
| 259 |
and save them to s.yyy and b.yyy; d.xxx is copied to d.yyy. |
| 260 |
""" |
| 261 |
|
| 262 |
typen = type(name1) |
| 263 |
if type(name1) == type(""): |
| 264 |
name1 = filenameTemplate(name1,templates) |
| 265 |
name2 = filenameTemplate(name2,templates) |
| 266 |
if typen != type("") and typen != type(None): |
| 267 |
data = name1.relabel() |
| 268 |
info("Relabeling done\n") |
| 269 |
return data |
| 270 |
n1b = name1["bifurcationDiagram"] |
| 271 |
n1s = name1["solution"] |
| 272 |
n1d = name1["diagnostics"] |
| 273 |
if n1b is None and n1s is None and n1d is None: |
| 274 |
n1b, n1s, n1d = "fort.7", "fort.8", "fort.9" |
| 275 |
if name2["bifurcationDiagram"] is None: |
| 276 |
n2b = n1b+'~~' |
| 277 |
n2s = n1s+'~~' |
| 278 |
n2d = n1d+'~~' |
| 279 |
else: |
| 280 |
n2b = name2["bifurcationDiagram"] |
| 281 |
n2s = name2["solution"] |
| 282 |
n2d = name2["diagnostics"] |
| 283 |
from auto.relabel import relabel |
| 284 |
relabel(n1b,n1s,n2b,n2s) |
| 285 |
if os.access(n2b,os.F_OK): |
| 286 |
if name2["bifurcationDiagram"] is None: |
| 287 |
|
| 288 |
if os.access(n1b+'~',os.F_OK): |
| 289 |
os.remove(n1b+'~') |
| 290 |
os.rename(n1b,n1b+'~') |
| 291 |
os.rename(n2b,n1b) |
| 292 |
if os.access(n1s+'~',os.F_OK): |
| 293 |
os.remove(n1s+'~') |
| 294 |
os.rename(n1s,n1s+'~') |
| 295 |
os.rename(n2s,n1s) |
| 296 |
elif os.path.exists(n1d): |
| 297 |
shutil.copy(n1d, n2d) |
| 298 |
info("Relabeling succeeded\n") |
| 299 |
info("Relabeling done\n") |
| 300 |
commandRelabel = command(relabel,SIMPLE,"relabel",alias=['rl']) |
| 301 |
|
| 302 |
|
| 303 |
def merge(name1=None,name2=None,templates=None): |
| 304 |
"""Merge branches in data files. |
| 305 |
|
| 306 |
Type y=FUNC(x) to return the python object x, with its branches |
| 307 |
merged into continuous curves, as a new object y. |
| 308 |
|
| 309 |
Type FUNC('xxx') to merge branches in s.xxx, b.xxx, and d.xxx. Backups |
| 310 |
of the original files are saved. |
| 311 |
|
| 312 |
Type FUNC('xxx','yyy') to merge branches in the existing data-files |
| 313 |
s.xxx, b.xxx, and d.xxx and save them to s.yyy, b.yyy, and d.yyy. |
| 314 |
""" |
| 315 |
|
| 316 |
ntype = type(name1) |
| 317 |
if type(name1) == type(""): |
| 318 |
name1 = filenameTemplate(name1,templates) |
| 319 |
name2 = filenameTemplate(name2,templates) |
| 320 |
if ntype != type("") and ntype != type(None): |
| 321 |
data = name1.merge() |
| 322 |
info("Merge done\n") |
| 323 |
return data |
| 324 |
n1b = name1["bifurcationDiagram"] |
| 325 |
n1s = name1["solution"] |
| 326 |
n1d = name1["diagnostics"] |
| 327 |
if n1b is None and n1s is None and n1d is None: |
| 328 |
n1b, n1s, n1d = "fort.7", "fort.8", "fort.9" |
| 329 |
bd = bifDiag.bifDiag(n1b,n1s,n1d) |
| 330 |
bd = bd.merge() |
| 331 |
if name2["bifurcationDiagram"] is None: |
| 332 |
n2b = n1b+'~~' |
| 333 |
n2s = n1s+'~~' |
| 334 |
n2d = n1d+'~~' |
| 335 |
else: |
| 336 |
n2b = name2["bifurcationDiagram"] |
| 337 |
n2s = name2["solution"] |
| 338 |
n2d = name2["diagnostics"] |
| 339 |
bd.writeFilename(n2b,n2s,n2d) |
| 340 |
if os.access(n2b,os.F_OK): |
| 341 |
if name2["bifurcationDiagram"] is None: |
| 342 |
|
| 343 |
for [n1,n2] in [[n1b,n2b],[n1s,n2s],[n1d,n2d]]: |
| 344 |
if os.access(n1+'~',os.F_OK): |
| 345 |
os.remove(n1+'~') |
| 346 |
os.rename(n1,n1+'~') |
| 347 |
os.rename(n2,n1) |
| 348 |
info("Merging succeeded\n") |
| 349 |
info("Merging done\n") |
| 350 |
commandMergeBranches = command(merge,SIMPLE,"merge",alias=['mb']) |
| 351 |
|
| 352 |
|
| 353 |
def subtract(name1,name2,col,branch=1,point=1,templates=None): |
| 354 |
"""Subtract branches in data files. |
| 355 |
|
| 356 |
Type z=FUNC(x,y,ref) to return the python object x, where, |
| 357 |
using interpolation, the first branch in y is subtracted from all |
| 358 |
branches in x, as a new object z. |
| 359 |
Use 'ref' (e.g., 'PAR(1)') as the reference column in y |
| 360 |
(only the first monotonically increasing or decreasing part is used). |
| 361 |
|
| 362 |
Type FUNC('xxx','yyy','ref') to subtract, using interpolation, the first |
| 363 |
branch in b.yyy from all branches in b.xxx, and save the result in b.xxx. |
| 364 |
A Backup of the original file is saved. |
| 365 |
|
| 366 |
Use optional arguments branch=m, and point=n, to denote the branch and |
| 367 |
first point on that branch within y or 'b.yyy', where m,n are in |
| 368 |
{1,2,3,...}. |
| 369 |
""" |
| 370 |
ntype = type(name1) |
| 371 |
if type(name1) == type(""): |
| 372 |
name1 = filenameTemplate(name1,templates) |
| 373 |
name2 = filenameTemplate(name2,templates) |
| 374 |
if ntype != type(""): |
| 375 |
sub = name1.subtract(name2[branch-1],col,point) |
| 376 |
info("Subtracting done\n") |
| 377 |
return sub |
| 378 |
else: |
| 379 |
n1b = name1["bifurcationDiagram"] |
| 380 |
bd1 = bifDiag.bifDiag(n1b) |
| 381 |
n2b = name2["bifurcationDiagram"] |
| 382 |
if n1b == n2b: |
| 383 |
bd2 = bd1 |
| 384 |
else: |
| 385 |
bd2 = bifDiag.bifDiag(n2b) |
| 386 |
sub = bd1.subtract(bd2[branch-1],col,point) |
| 387 |
shutil.copy(n1b,n1b+'~') |
| 388 |
sub.writeFilename(n1b,'') |
| 389 |
info("Subtracting done\n") |
| 390 |
commandSubtractBranches = command(subtract,SIMPLE,"subtract",alias=['sb']) |
| 391 |
|
| 392 |
|
| 393 |
def append(name1,name2=None,templates=None): |
| 394 |
"""Append data files. |
| 395 |
|
| 396 |
Type FUNC(x,'xxx') to append bifurcation diagram x |
| 397 |
to the data-files b.xxx, s.xxx, and d.xxx. This is equivalent to |
| 398 |
the command |
| 399 |
save(x+load('xxx'),'xxx') |
| 400 |
|
| 401 |
Type FUNC('xxx',x) to append existing data-files s.xxx, b.xxx, |
| 402 |
and d.xxx to bifurcation diagram x. This is equivalent to |
| 403 |
the command |
| 404 |
x=load('xxx')+x |
| 405 |
|
| 406 |
Type FUNC('xxx') to append the output-files fort.7, fort.8, |
| 407 |
fort.9, to existing data-files s.xxx, b.xxx, and d.xxx. |
| 408 |
|
| 409 |
Type FUNC('xxx','yyy') to append existing data-files s.xxx, b.xxx, |
| 410 |
and d.xxx to data-files s.yyy, b.yyy, and d.yyy. |
| 411 |
""" |
| 412 |
parsed1=None |
| 413 |
parsed2=None |
| 414 |
if isinstance(name1, bifDiag.bifDiag): |
| 415 |
parsed1=name1 |
| 416 |
name1=name2 |
| 417 |
name2=None |
| 418 |
if isinstance(name1, bifDiag.bifDiag): |
| 419 |
parsed2=name1 |
| 420 |
else: |
| 421 |
name1 = filenameTemplate(name1,templates) |
| 422 |
name2 = filenameTemplate(name2,templates) |
| 423 |
if parsed1 or parsed2: |
| 424 |
n = None |
| 425 |
if not parsed1 or not parsed2: |
| 426 |
nb = name1["bifurcationDiagram"] |
| 427 |
ns = name1["solution"] |
| 428 |
nd = name1["diagnostics"] |
| 429 |
if parsed2: |
| 430 |
if not parsed1: |
| 431 |
parsed1 = bifDiag.bifDiag(nb,ns,nd) |
| 432 |
info("Appending from %s, %s and %s ... done\n"%(nb,ns,nd)) |
| 433 |
parsed2.extend(parsed1) |
| 434 |
return |
| 435 |
if parsed1: |
| 436 |
parsed1.writeFilename(nb,ns,nd,append=True) |
| 437 |
info("Appending to %s, %s and %s ... done\n"%(nb,ns,nd)) |
| 438 |
return |
| 439 |
i = 7 |
| 440 |
for s in ["bifurcationDiagram","solution","diagnostics"]: |
| 441 |
n1 = name1[s] |
| 442 |
n2 = name2[s] |
| 443 |
if n2 is None: |
| 444 |
n2 = n1 |
| 445 |
n1 = "fort."+str(i) |
| 446 |
i = i+1 |
| 447 |
try: |
| 448 |
f1 = open(n1,"rb") |
| 449 |
f2 = open(n2,"ab") |
| 450 |
while 1: |
| 451 |
buf = f1.read(1024*1024) |
| 452 |
if len(buf) == 0: |
| 453 |
break |
| 454 |
f2.write(buf) |
| 455 |
f1.close() |
| 456 |
f2.close() |
| 457 |
info("Appending %s to %s ... done\n"%(n1,n2)) |
| 458 |
except IOError: |
| 459 |
info("Appending %s to %s: %s\n"%(n1,n2,sys.exc_info()[1])) |
| 460 |
commandAppend = command(append,SIMPLE,"append",alias=['ap']) |
| 461 |
|
| 462 |
|
| 463 |
def dirfilenames(name1,name2,name3,name4): |
| 464 |
"""Convert arguments to directories and names for copy() and move()""" |
| 465 |
dir1 = "" |
| 466 |
dir2 = "" |
| 467 |
if os.path.isdir(name1): |
| 468 |
dir1 = name1 |
| 469 |
name1 = name2 |
| 470 |
if name4 is not None: |
| 471 |
dir2 = name3 |
| 472 |
name2 = name4 |
| 473 |
elif name3 is not None: |
| 474 |
name2 = name3 |
| 475 |
elif os.path.isdir(name2): |
| 476 |
dir2 = name2 |
| 477 |
if name3 is not None: |
| 478 |
name2 = name3 |
| 479 |
else: |
| 480 |
name2 = name1 |
| 481 |
return dir1,name1,dir2,name2 |
| 482 |
|
| 483 |
def copy(name1,name2,name3=None,name4=None,templates=None): |
| 484 |
"""Copy data files. |
| 485 |
|
| 486 |
Type FUNC(name1,name2) or |
| 487 |
FUNC(name1,name2,name3) or |
| 488 |
FUNC(name1,name2,name3,name4). |
| 489 |
|
| 490 |
Copy the data-files dir1/c.xxx, dir1/b.xxx, dir1/s.xxx, and dir1/d.xxx |
| 491 |
to dir2/c.yyy, dir2/b.yyy, dir2/s.yyy, and dir2/d.yyy. |
| 492 |
|
| 493 |
The values of dir1/?.xxx and dir2/?.yyy are as follows, depending on |
| 494 |
whether name1 is a directory or name2 is a directory: |
| 495 |
|
| 496 |
FUNC(name1,name2) |
| 497 |
no directory names: ./?.name1 and ./?.name2 |
| 498 |
name1 is a directory: name1/?.name2 and ./?.name2 |
| 499 |
name2 is a directory: ./?.name1 and name2/?.name1 |
| 500 |
|
| 501 |
FUNC(name1,name2,name3) |
| 502 |
name1 is a directory: name1/?.name2 and ./?.name3 |
| 503 |
name2 is a directory: ./?.name1 and name2/?.name3 |
| 504 |
|
| 505 |
FUNC(name1,name2,name3,name4) |
| 506 |
name1/?.name2 and name3/?.name4 |
| 507 |
""" |
| 508 |
|
| 509 |
dir1, name1, dir2, name2 = dirfilenames(name1,name2,name3,name4) |
| 510 |
names1 = filenameTemplate(name1,templates) |
| 511 |
names2 = filenameTemplate(name2,templates) |
| 512 |
done = False |
| 513 |
for s in ["bifurcationDiagram","solution","diagnostics","constants"]: |
| 514 |
n1 = os.path.join(dir1,names1[s]) |
| 515 |
n2 = os.path.join(dir2,names2[s]) |
| 516 |
if os.path.exists(n1): |
| 517 |
shutil.copy(n1,n2) |
| 518 |
info("Copying %s to %s ... done\n"%(n1,n2)) |
| 519 |
done = True |
| 520 |
if not done: |
| 521 |
raise AUTOExceptions.AUTORuntimeError( |
| 522 |
"Copying: no files found for %s and %s"%( |
| 523 |
os.path.join(dir1,"[bsdc]."+name1), |
| 524 |
os.path.join(dir2,"[bsdc]."+name2))) |
| 525 |
commandCopyDataFiles = command(copy,alias=['cp']) |
| 526 |
|
| 527 |
|
| 528 |
def save(name1,name2=None,templates=None): |
| 529 |
"""Save data files. |
| 530 |
|
| 531 |
Type FUNC(x,'xxx') to save bifurcation diagram x |
| 532 |
to the files b.xxx, s.xxx, d.xxx. |
| 533 |
Existing files with these names will be overwritten. |
| 534 |
If x is a solution, a list of solutions, or does not contain any |
| 535 |
bifurcation diagram or diagnostics data, then only the file s.xxx |
| 536 |
is saved to. |
| 537 |
|
| 538 |
Type FUNC('xxx') to save the output-files fort.7, fort.8, fort.9, |
| 539 |
to b.xxx, s.xxx, d.xxx. Existing files with these names will be |
| 540 |
overwritten. |
| 541 |
""" |
| 542 |
parsed = None |
| 543 |
if not name2 is None: |
| 544 |
parsed = name1 |
| 545 |
name1 = name2 |
| 546 |
name1 = filenameTemplate(name1,templates) |
| 547 |
for s in ["bifurcationDiagram","solution","diagnostics"]: |
| 548 |
n1 = name1[s] |
| 549 |
if os.path.exists(n1): |
| 550 |
shutil.copy(n1,n1+'~') |
| 551 |
|
| 552 |
if parsed: |
| 553 |
n1b = name1["bifurcationDiagram"] |
| 554 |
n1s = name1["solution"] |
| 555 |
n1d = name1["diagnostics"] |
| 556 |
if (type(parsed) == type([]) and |
| 557 |
isinstance(parsed[0], parseB.AUTOBranch)): |
| 558 |
parsed = bifDiag.bifDiag(parsed) |
| 559 |
if (isinstance(parsed,bifDiag.bifDiag) and |
| 560 |
len(parsed) > 0 and len(parsed[0]) > 0): |
| 561 |
parsed.writeFilename(n1b,n1s,n1d) |
| 562 |
msg = "Saving to %s and %s ... done\n"%(n1b,n1s) |
| 563 |
for d in parsed: |
| 564 |
if hasattr(d,"diagnostics"): |
| 565 |
msg = "Saving to %s, %s, and %s ... done\n"%(n1b,n1s,n1d) |
| 566 |
break |
| 567 |
else: |
| 568 |
if (type(parsed) == type([]) and |
| 569 |
isinstance(parsed[0], parseS.AUTOSolution)): |
| 570 |
parsed = parseS.parseS(parsed) |
| 571 |
parsed.writeFilename(n1s) |
| 572 |
msg = "Saving to %s ... done\n"%(n1s) |
| 573 |
info(msg) |
| 574 |
return |
| 575 |
|
| 576 |
i = 7 |
| 577 |
for s in ["bifurcationDiagram","solution","diagnostics"]: |
| 578 |
n1 = name1[s] |
| 579 |
forti = "fort." + str(i) |
| 580 |
i = i + 1 |
| 581 |
if os.path.exists(forti): |
| 582 |
shutil.copy(forti,n1) |
| 583 |
info("Saving %s as %s ... done\n"%(forti,n1)) |
| 584 |
commandCopyFortFiles = command(save,SIMPLE,"save",alias=['sv']) |
| 585 |
|
| 586 |
|
| 587 |
def delete(name,templates=None): |
| 588 |
"""Delete data files. |
| 589 |
|
| 590 |
Type FUNC('xxx') to delete the data-files d.xxx, b.xxx, and s.xxx. |
| 591 |
""" |
| 592 |
|
| 593 |
name = filenameTemplate(name,templates) |
| 594 |
n1b = name["bifurcationDiagram"] |
| 595 |
n1s = name["solution"] |
| 596 |
n1d = name["diagnostics"] |
| 597 |
if os.path.exists(n1b): |
| 598 |
os.remove(n1b) |
| 599 |
info("Deleting %s ... done\n"%n1b) |
| 600 |
if os.path.exists(n1s): |
| 601 |
os.remove(n1s) |
| 602 |
info("Deleting %s ... done\n"%n1s) |
| 603 |
if os.path.exists(n1d): |
| 604 |
os.remove(n1d) |
| 605 |
info("Deleting %s ... done\n"%n1d) |
| 606 |
commandDeleteDataFiles = command(delete,alias=['dl']) |
| 607 |
|
| 608 |
|
| 609 |
def deleteLabel(codes=None,name1=None,name2=None,templates=None, |
| 610 |
keepTY=0,keep=0): |
| 611 |
if hasattr(codes,'deleteLabel'): |
| 612 |
origlen=len(codes()) |
| 613 |
new = codes.deleteLabel(name1,keepTY=keepTY,keep=keep,copy=1) |
| 614 |
newlen=len(new()) |
| 615 |
info("Deleted %d labels, and kept %d.\n"%(origlen-newlen, newlen)) |
| 616 |
return new |
| 617 |
name1 = filenameTemplate(name1,templates) |
| 618 |
if name1["solution"] is None: |
| 619 |
changedb='fort.7' |
| 620 |
changeds='fort.8' |
| 621 |
else: |
| 622 |
changedb=name1["bifurcationDiagram"] |
| 623 |
changeds=name1["solution"] |
| 624 |
bs=bifDiag.bifDiag(changedb,changeds) |
| 625 |
origlen=len(bs()) |
| 626 |
bs.deleteLabel(codes,keepTY=keepTY,keep=keep) |
| 627 |
newlen=len(bs()) |
| 628 |
if name2 is None: |
| 629 |
origb=changedb+'~' |
| 630 |
origs=changeds+'~' |
| 631 |
try: |
| 632 |
os.remove(origb) |
| 633 |
except: |
| 634 |
pass |
| 635 |
try: |
| 636 |
os.remove(origs) |
| 637 |
except: |
| 638 |
pass |
| 639 |
os.rename(changedb,origb) |
| 640 |
os.rename(changeds,origs) |
| 641 |
bs.writeFilename(changedb,changeds) |
| 642 |
else: |
| 643 |
name2 = filenameTemplate(name2,templates) |
| 644 |
bs.writeFilename(name2["bifurcationDiagram"],name2["solution"]) |
| 645 |
info("Deleted %d labels, and kept %d.\n"%(origlen-newlen, newlen)) |
| 646 |
|
| 647 |
def dsp(typenames=None,name1=None,name2=None,templates=None): |
| 648 |
"""Delete special points. |
| 649 |
|
| 650 |
Type FUNC(x,list) to delete the special points in list from |
| 651 |
the Python object x, which must be a solution list or a bifurcation diagram. |
| 652 |
Type FUNC(list,'xxx') to delete from the data-files b.xxx, and s.xxx. |
| 653 |
Type FUNC(list,'xxx','yyy') to save to b.yyy and s.yyy instead of ?.xxx. |
| 654 |
Type FUNC(list) to delete from fort.7 and fort.8. |
| 655 |
list is a label number or type name code, or a list of those, |
| 656 |
such as 1, or [2,3], or 'UZ' or ['BP','LP'], or it can be None or |
| 657 |
omitted to mean the special points ['BP','LP','HB','PD','TR','EP','MX'] |
| 658 |
Alternatively a boolean user-defined function f that takes a solution |
| 659 |
can be specified for list, such as |
| 660 |
def f(s): |
| 661 |
return s["PAR(9)"]<0 |
| 662 |
where all solutions are deleted that satisfy the given condition, or |
| 663 |
def f(s1,s2): |
| 664 |
return abs(s1["L2-NORM"] - s2["L2-NORM"]) < 1e-4 |
| 665 |
where all solutions are compared with each other and s2 is deleted if |
| 666 |
the given condition is satisfied, which causes pruning of solutions |
| 667 |
that are close to each other. |
| 668 |
|
| 669 |
Type information is NOT kept in the bifurcation diagram. |
| 670 |
""" |
| 671 |
return deleteLabel(typenames,name1,name2,templates) |
| 672 |
commandDeleteSpecialPoints = command(dsp) |
| 673 |
|
| 674 |
|
| 675 |
def ksp(typenames=None,name1=None,name2=None,templates=None): |
| 676 |
"""Keep special points. |
| 677 |
|
| 678 |
Type FUNC(x,list) to only keep the special points in list in |
| 679 |
the Python object x, which must be a solution list or a bifurcation diagram. |
| 680 |
Type FUNC(list,'xxx') to keep them in the data-files b.xxx and s.xxx. |
| 681 |
Type FUNC(list,'xxx','yyy') to save to b.yyy and s.yyy instead of ?.xxx. |
| 682 |
Type FUNC(list) to keep them in fort.7 and fort.8. |
| 683 |
list is a label number or type name code, or a list of those, |
| 684 |
such as 1, or [2,3], or 'UZ' or ['BP','LP'], or it can be None or |
| 685 |
omitted to mean ['BP','LP','HB','PD','TR','EP','MX'], deleting 'UZ' and |
| 686 |
regular points. |
| 687 |
Alternatively a boolean user-defined function f that takes a solution |
| 688 |
can be specified for list, such as |
| 689 |
def f(s): |
| 690 |
return s["PAR(9)"]<0 |
| 691 |
where only solutions are kept that satisfy the given condition. |
| 692 |
|
| 693 |
Type information is NOT kept in the bifurcation diagram. |
| 694 |
""" |
| 695 |
return deleteLabel(typenames,name1,name2,templates,keep=1) |
| 696 |
commandKeepSpecialPoints = command(ksp) |
| 697 |
|
| 698 |
|
| 699 |
def dlb(typenames=None,name1=None,name2=None,templates=None): |
| 700 |
"""Delete special labels. |
| 701 |
|
| 702 |
Type FUNC(x,list) to delete the special points in list from |
| 703 |
the Python object x, which must be a solution list or a bifurcation diagram. |
| 704 |
Type FUNC(list,'xxx') to delete from the data-files b.xxx and s.xxx. |
| 705 |
Type FUNC(list,'xxx','yyy') to save to b.yyy and s.yyy instead of ?.xxx. |
| 706 |
Type FUNC(list) to delete from fort.7 and fort.8. |
| 707 |
list is a label number or type name code, or a list of those, |
| 708 |
such as 1, or [2,3], or 'UZ' or ['BP','LP'], or it can be None or |
| 709 |
omitted to mean the special points ['BP','LP','HB','PD','TR','EP','MX'] |
| 710 |
Alternatively a boolean user-defined function f that takes a solution |
| 711 |
can be specified for list, such as |
| 712 |
def f(s): |
| 713 |
return s["PAR(9)"] < 0 |
| 714 |
where all solutions are deleted that satisfy the given condition, or |
| 715 |
def f(s1,s2): |
| 716 |
return abs(s1["L2-NORM"] - s2["L2-NORM"]) < 1e-4 |
| 717 |
where all solutions are compared with each other and s2 is deleted if |
| 718 |
the given condition is satisfied, which causes pruning of solutions |
| 719 |
that are close to each other. |
| 720 |
|
| 721 |
Type information is kept in the bifurcation diagram for plotting. |
| 722 |
""" |
| 723 |
return deleteLabel(typenames,name1,name2,templates,keepTY=1) |
| 724 |
commandDeleteLabels = command(dlb) |
| 725 |
|
| 726 |
|
| 727 |
def klb(typenames=None,name1=None,name2=None,templates=None): |
| 728 |
"""Keep special labels. |
| 729 |
|
| 730 |
Type FUNC(x,list) to only keep the special points in list in |
| 731 |
the Python object x, which must be a solution list or a bifurcation diagram. |
| 732 |
Type FUNC(list,'xxx') to keep them in the data-files b.xxx and s.xxx. |
| 733 |
Type FUNC(list,'xxx','yyy') to save to b.yyy and s.yyy instead of ?.xxx. |
| 734 |
Type FUNC(list) to keep them in fort.7 and fort.8. |
| 735 |
list is a label number or type name code, or a list of those, |
| 736 |
such as 1, or [2,3], or 'UZ' or ['BP','LP'], or it can be None or |
| 737 |
omitted to mean ['BP','LP','HB','PD','TR','EP','MX'], deleting 'UZ' and |
| 738 |
regular points. |
| 739 |
Alternatively a boolean user-defined function f that takes a solution |
| 740 |
can be specified for list, such as |
| 741 |
def f(s): |
| 742 |
return s["PAR(9)"]<0 |
| 743 |
where only solutions are kept that satisfy the given condition. |
| 744 |
|
| 745 |
Type information is kept in the bifurcation diagram for plotting. |
| 746 |
""" |
| 747 |
return deleteLabel(typenames,name1,name2,templates,keepTY=1,keep=1) |
| 748 |
commandKeepLabels = command(klb) |
| 749 |
|
| 750 |
|
| 751 |
def expandData(cmd,name=None,templates=None): |
| 752 |
name = filenameTemplate(name,templates) |
| 753 |
n1b = name["bifurcationDiagram"] |
| 754 |
n1s = name["solution"] |
| 755 |
if n1s is None: |
| 756 |
n1s = "fort.8" |
| 757 |
n1b = "fort.7" |
| 758 |
if os.path.exists(n1b): |
| 759 |
shutil.copy(n1b,n1b+'~') |
| 760 |
if os.path.exists(n1s): |
| 761 |
shutil.copy(n1s,"fort.28") |
| 762 |
if os.path.exists(n1s+'~'): |
| 763 |
os.remove(n1s+'~') |
| 764 |
os.rename(n1s,n1s+'~') |
| 765 |
interact(os.path.expandvars("$AUTO_DIR/bin/%s"%cmd)) |
| 766 |
os.rename("fort.38",n1s) |
| 767 |
if os.path.exists("fort.28"): |
| 768 |
os.remove("fort.28") |
| 769 |
if cmd == "double": |
| 770 |
info("Solution doubling done.\n") |
| 771 |
else: |
| 772 |
info("Solution tripling done.\n") |
| 773 |
|
| 774 |
def double(name=None,templates=None): |
| 775 |
"""Double a solution. |
| 776 |
|
| 777 |
Type FUNC() to double the solution in 'fort.7' and 'fort.8'. |
| 778 |
|
| 779 |
Type FUNC('xxx') to double the solution in b.xxx and s.xxx. |
| 780 |
""" |
| 781 |
expandData("double",name,templates) |
| 782 |
commandDouble = command(double,alias=['db']) |
| 783 |
|
| 784 |
|
| 785 |
def move(name1,name2,name3=None,name4=None,templates=None): |
| 786 |
"""Move data-files to a new name. |
| 787 |
|
| 788 |
Type FUNC(name1,name2) or |
| 789 |
FUNC(name1,name2,name3) or |
| 790 |
FUNC(name1,name2,name3,name4) |
| 791 |
|
| 792 |
Move the data-files dir1/b.xxx, dir1/s.xxx, and dir1/d.xxx, |
| 793 |
to dir2/b.yyy, dir2/s.yyy, and dir2/d.yyy, and copy the constants |
| 794 |
file dir1/c.xxx to dir2/c.yyy. |
| 795 |
|
| 796 |
The values of dir1/?.xxx and dir2/?.yyy are as follows, depending on |
| 797 |
whether name1 is a directory or name2 is a directory: |
| 798 |
|
| 799 |
FUNC(name1,name2) |
| 800 |
no directory names: ./?.name1 and ./?.name2 |
| 801 |
name1 is a directory: name1/?.name2 and ./?.name2 |
| 802 |
name2 is a directory: ./?.name1 and name2/?.name1 |
| 803 |
|
| 804 |
FUNC(name1,name2,name3) |
| 805 |
name1 is a directory: name1/?.name2 and ./?.name3 |
| 806 |
name2 is a directory: ./?.name1 and name2/?.name3 |
| 807 |
|
| 808 |
FUNC(name1,name2,name3,name4) |
| 809 |
name1/?.name2 and name3/?.name4 |
| 810 |
""" |
| 811 |
dir1, name1, dir2, name2 = dirfilenames(name1,name2,name3,name4) |
| 812 |
names1 = filenameTemplate(name1,templates) |
| 813 |
names2 = filenameTemplate(name2,templates) |
| 814 |
done = False |
| 815 |
for s in ["bifurcationDiagram","solution","diagnostics","constants"]: |
| 816 |
n1 = os.path.join(dir1,names1[s]) |
| 817 |
n2 = os.path.join(dir2,names2[s]) |
| 818 |
if s == "constants": |
| 819 |
try: |
| 820 |
shutil.copy(n1,n2) |
| 821 |
info("Copying %s to %s ... done\n"%(n1,n2)) |
| 822 |
done = True |
| 823 |
except IOError: |
| 824 |
pass |
| 825 |
continue |
| 826 |
if os.path.exists(n1): |
| 827 |
if os.path.exists(n2): |
| 828 |
os.remove(n2) |
| 829 |
os.rename(n1,n2) |
| 830 |
info("Renaming %s as %s ... done\n"%(n1,n2)) |
| 831 |
done = True |
| 832 |
if not done: |
| 833 |
raise AUTOExceptions.AUTORuntimeError( |
| 834 |
"Renaming: no files found for %s and %s"%( |
| 835 |
os.path.join(dir1,"[bsdc]."+name1), |
| 836 |
os.path.join(dir2,"[bsdc]."+name2))) |
| 837 |
commandMoveFiles = command(move,alias=['mv']) |
| 838 |
|
| 839 |
|
| 840 |
def cn(name,templates=None): |
| 841 |
"""Get the current continuation constants. |
| 842 |
|
| 843 |
Type FUNC('xxx') to get a parsed version of the constants file |
| 844 |
c.xxx. |
| 845 |
|
| 846 |
This is equivalent to the command |
| 847 |
loadbd('xxx').c |
| 848 |
""" |
| 849 |
name = filenameTemplate(name,templates) |
| 850 |
data = parseC.parseC(name["constants"]) |
| 851 |
info("Parsed file: %s\n"%name["constants"]) |
| 852 |
return data |
| 853 |
commandParseConstantsFile = command(cn,alias=['constantsget']) |
| 854 |
|
| 855 |
|
| 856 |
def hcn(name,templates=None): |
| 857 |
"""Get the current HomCont continuation constants. |
| 858 |
|
| 859 |
Type FUNC('xxx') to get a parsed version of the HomCont file |
| 860 |
h.xxx. |
| 861 |
""" |
| 862 |
name = filenameTemplate(name,templates) |
| 863 |
data = parseH.parseH(name["homcont"]) |
| 864 |
info("Parsed file: %s\n"%name["homcont"]) |
| 865 |
return data |
| 866 |
commandParseHomcontFile = command(hcn) |
| 867 |
|
| 868 |
|
| 869 |
def sl(name=None,templates=None): |
| 870 |
"""Parse solution file: |
| 871 |
|
| 872 |
Type FUNC('xxx') to get a parsed version of the solution file |
| 873 |
s.xxx. |
| 874 |
|
| 875 |
This is equivalent to the command |
| 876 |
loadbd('xxx')() |
| 877 |
""" |
| 878 |
name = filenameTemplate(name,templates) |
| 879 |
n1s = name["solution"] or "fort.8" |
| 880 |
try: |
| 881 |
data = parseS.parseS(n1s) |
| 882 |
except IOError: |
| 883 |
raise AUTOExceptions.AUTORuntimeError(sys.exc_info()[1]) |
| 884 |
if isinstance(n1s, str): |
| 885 |
info("Parsed file: %s\n"%n1s) |
| 886 |
return data |
| 887 |
commandParseSolutionFile = command(sl,alias=['solutionget']) |
| 888 |
|
| 889 |
|
| 890 |
def dg(name=None,templates=None): |
| 891 |
"""Parse a bifurcation diagram. |
| 892 |
|
| 893 |
Type FUNC('xxx') to get a parsed version of the diagram file b.xxx. |
| 894 |
|
| 895 |
This is equivalent to the command loadbd('xxx') but without the |
| 896 |
solutions in s.xxx and without the diagnostics in d.xxx. |
| 897 |
""" |
| 898 |
name = filenameTemplate(name,templates) |
| 899 |
n1b = name["bifurcationDiagram"] |
| 900 |
if n1b is None: |
| 901 |
n1b = "fort.7" |
| 902 |
try: |
| 903 |
data = parseB.parseB(n1b) |
| 904 |
except IOError: |
| 905 |
raise AUTOExceptions.AUTORuntimeError(sys.exc_info()[1]) |
| 906 |
info("Parsed file: %s\n"%n1b) |
| 907 |
return data |
| 908 |
commandParseDiagramFile = command(dg,alias=['diagramget']) |
| 909 |
|
| 910 |
|
| 911 |
def bt(name=None,templates=None): |
| 912 |
"""Parse both bifurcation diagram and solution. |
| 913 |
|
| 914 |
Type FUNC('xxx') to get a parsed version of the diagram file b.xxx |
| 915 |
and solution file s.xxx. |
| 916 |
|
| 917 |
This is equivalent to the command loadbd('xxx') but without the |
| 918 |
diagnostics in d.xxx. |
| 919 |
""" |
| 920 |
name = filenameTemplate(name,templates) |
| 921 |
n1b = name["bifurcationDiagram"] |
| 922 |
n1s = name["solution"] |
| 923 |
if n1b is None: |
| 924 |
n1b = "fort.7" |
| 925 |
n1s = "fort.8" |
| 926 |
data = parseBandS.parseBandS(n1b,n1s) |
| 927 |
output_names = n1b + " and " + n1s |
| 928 |
info("Parsed files: %s\n"%output_names) |
| 929 |
return data |
| 930 |
commandParseDiagramAndSolutionFile = command(bt,alias=['diagramandsolutionget']) |
| 931 |
|
| 932 |
|
| 933 |
def queryDiagnostic(diagnostic,name=None,templates=None): |
| 934 |
name = filenameTemplate(name,templates) |
| 935 |
n1d = name["diagnostics"] |
| 936 |
if n1d is None: |
| 937 |
n1d = "fort.9" |
| 938 |
try: |
| 939 |
f = open(n1d) |
| 940 |
except TypeError: |
| 941 |
for branch in n1d: |
| 942 |
if hasattr(branch,"diagnostics"): |
| 943 |
for s in str(branch.diagnostics).splitlines(): |
| 944 |
if diagnostic in s: |
| 945 |
info(s+"\n") |
| 946 |
info("\n") |
| 947 |
return |
| 948 |
for s in f: |
| 949 |
if diagnostic in s: |
| 950 |
info(s) |
| 951 |
f.close() |
| 952 |
info("\n") |
| 953 |
commandQueryDiagnostic = command(queryDiagnostic,alias=None) |
| 954 |
|
| 955 |
|
| 956 |
def branchpoint(name=None,templates=None): |
| 957 |
"""Print the ``branch-point function''. |
| 958 |
|
| 959 |
Type FUNC(x) to list the value of the ``branch-point function'' |
| 960 |
in the diagnostics of the bifurcation diagram object x. |
| 961 |
This function vanishes at a branch point. |
| 962 |
|
| 963 |
Type FUNC() to list the value of the ``branch-point function'' |
| 964 |
in the output-file fort.9. |
| 965 |
|
| 966 |
Type FUNC('xxx') to list the value of the ``branch-point function'' |
| 967 |
in the info file 'd.xxx'. |
| 968 |
""" |
| 969 |
queryDiagnostic("BP",name,templates) |
| 970 |
commandQueryBranchPoint = command(branchpoint,alias=['bp','br']) |
| 971 |
|
| 972 |
|
| 973 |
def eigenvalue(name=None,templates=None): |
| 974 |
"""Print eigenvalues of Jacobian (algebraic case). |
| 975 |
|
| 976 |
Type FUNC(x) to list the eigenvalues of the Jacobian |
| 977 |
in the diagnostics of the bifurcation diagram object x. |
| 978 |
(Algebraic problems.) |
| 979 |
|
| 980 |
Type FUNC() to list the eigenvalues of the Jacobian |
| 981 |
in fort.9. |
| 982 |
|
| 983 |
Type FUNC('xxx') to list the eigenvalues of the Jacobian |
| 984 |
in the info file 'd.xxx'. |
| 985 |
""" |
| 986 |
queryDiagnostic("Eigenvalue",name,templates) |
| 987 |
commandQueryEigenvalue = command(eigenvalue,alias=['ev','eg']) |
| 988 |
|
| 989 |
|
| 990 |
def floquet(name=None,templates=None): |
| 991 |
"""Print the Floquet multipliers. |
| 992 |
|
| 993 |
Type FUNC(x) to list the Floquet multipliers |
| 994 |
in the diagnostics of the bifurcation diagram object x. |
| 995 |
(Differential equations.) |
| 996 |
|
| 997 |
Type FUNC() to list the Floquet multipliers |
| 998 |
in the output-file fort.9. |
| 999 |
|
| 1000 |
Type FUNC('xxx') to list the Floquet multipliers |
| 1001 |
in the info file 'd.xxx'. |
| 1002 |
""" |
| 1003 |
queryDiagnostic("Mult",name,templates) |
| 1004 |
commandQueryFloquet = command(floquet,alias=['fl']) |
| 1005 |
|
| 1006 |
|
| 1007 |
def hopf(name=None,templates=None): |
| 1008 |
"""Print the value of the ``Hopf function''. |
| 1009 |
|
| 1010 |
Type FUNC(x) to list the value of the ``Hopf function'' |
| 1011 |
in the diagnostics of the bifurcation diagram object x. |
| 1012 |
This function vanishes at a Hopf bifurcation point. |
| 1013 |
|
| 1014 |
Type FUNC() to list the value of the ``Hopf function'' |
| 1015 |
in the output-file fort.9. |
| 1016 |
|
| 1017 |
Type FUNC('xxx') to list the value of the ``Hopf function'' |
| 1018 |
in the info file 'd.xxx'. |
| 1019 |
""" |
| 1020 |
queryDiagnostic("Hopf",name,templates) |
| 1021 |
commandQueryHopf = command(hopf,alias=['hp','hb']) |
| 1022 |
|
| 1023 |
|
| 1024 |
def iterations(name=None,templates=None): |
| 1025 |
"""Print the number of Newton interations. |
| 1026 |
|
| 1027 |
Type FUNC(x) to list the number of Newton iterations per |
| 1028 |
continuation step in the diagnostics of the bifurcation diagram |
| 1029 |
object x. |
| 1030 |
|
| 1031 |
Type FUNC() to list the number of Newton iterations per |
| 1032 |
continuation step in fort.9. |
| 1033 |
|
| 1034 |
Type FUNC('xxx') to list the number of Newton iterations per |
| 1035 |
continuation step in the info file 'd.xxx'. |
| 1036 |
""" |
| 1037 |
queryDiagnostic("Iterations",name,templates) |
| 1038 |
commandQueryIterations = command(iterations,alias=['it']) |
| 1039 |
|
| 1040 |
|
| 1041 |
def limitpoint(name=None,templates=None): |
| 1042 |
"""Print the value of the ``limit point function''. |
| 1043 |
|
| 1044 |
Type FUNC(x) to list the value of the ``limit point function'' |
| 1045 |
in the diagnostics of the bifurcation diagram object x. |
| 1046 |
This function vanishes at a limit point (fold). |
| 1047 |
|
| 1048 |
Type FUNC() to list the value of the ``limit point function'' |
| 1049 |
in the output-file fort.9. |
| 1050 |
|
| 1051 |
Type FUNC('xxx') to list the value of the ``limit point function'' |
| 1052 |
in the info file 'd.xxx'. |
| 1053 |
""" |
| 1054 |
queryDiagnostic("Fold",name,templates) |
| 1055 |
commandQueryLimitpoint = command(limitpoint,alias=['lm','lp']) |
| 1056 |
|
| 1057 |
|
| 1058 |
def note(name=None,templates=None): |
| 1059 |
"""Print notes in info file. |
| 1060 |
|
| 1061 |
Type FUNC(x) to show any notes |
| 1062 |
in the diagnostics of the bifurcation diagram |
| 1063 |
object x. |
| 1064 |
|
| 1065 |
Type FUNC() to show any notes |
| 1066 |
in the output-file fort.9. |
| 1067 |
|
| 1068 |
Type FUNC('xxx') to show any notes |
| 1069 |
in the info file 'd.xxx'. |
| 1070 |
""" |
| 1071 |
queryDiagnostic("NOTE",name,templates) |
| 1072 |
commandQueryNote = command(note,alias=['nt']) |
| 1073 |
|
| 1074 |
|
| 1075 |
def secondaryperiod(name=None,templates=None): |
| 1076 |
"""Print value of ``secondary-periodic bif. fcn''. |
| 1077 |
|
| 1078 |
Type FUNC(x) to list the value of the |
| 1079 |
``secondary-periodic bifurcation function'' |
| 1080 |
in the diagnostics of the bifurcation diagram object x. |
| 1081 |
This function vanishes at period-doubling and torus bifurcations. |
| 1082 |
|
| 1083 |
Type FUNC() to list the value of the |
| 1084 |
``secondary-periodic bifurcation function'' |
| 1085 |
in the output-file 'fort.9. |
| 1086 |
|
| 1087 |
Type FUNC('xxx') to list the value of the |
| 1088 |
``secondary-periodic bifurcation function'' |
| 1089 |
in the info file 'd.xxx'. |
| 1090 |
""" |
| 1091 |
queryDiagnostic("SPB",name,templates) |
| 1092 |
commandQuerySecondaryPeriod = command(secondaryperiod,alias=['sp','sc']) |
| 1093 |
|
| 1094 |
|
| 1095 |
def stepsize(name=None,templates=None): |
| 1096 |
"""Print continuation step sizes. |
| 1097 |
|
| 1098 |
Type FUNC(x) to list the continuation step size for each |
| 1099 |
continuation step in the diagnostics of the bifurcation diagram |
| 1100 |
object x. |
| 1101 |
|
| 1102 |
Type FUNC() to list the continuation step size for each |
| 1103 |
continuation step in 'fort.9'. |
| 1104 |
|
| 1105 |
Type FUNC('xxx') to list the continuation step size for each |
| 1106 |
continuation step in the info file 'd.xxx'. |
| 1107 |
""" |
| 1108 |
queryDiagnostic("Step",name,templates) |
| 1109 |
commandQueryStepsize = command(stepsize,alias=['ss','st']) |
| 1110 |
|
| 1111 |
|
| 1112 |
def triple(name=None,templates=None): |
| 1113 |
"""Triple a solution. |
| 1114 |
|
| 1115 |
Type FUNC() to triple the solution in 'fort.8'. |
| 1116 |
|
| 1117 |
Type FUNC('xxx') to triple the solution in s.xxx. |
| 1118 |
""" |
| 1119 |
return expandData("triple",name,templates) |
| 1120 |
commandTriple = command(triple,alias=['tr']) |
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
def ls(dir=None): |
| 1128 |
"""List the current directory. |
| 1129 |
|
| 1130 |
Type 'FUNC' to run the system 'ls' command in the current directory. This |
| 1131 |
command will accept whatever arguments are accepted by the Unix command |
| 1132 |
'ls'. |
| 1133 |
""" |
| 1134 |
cmd = "ls" |
| 1135 |
if os.name in ["nt", "dos"]: |
| 1136 |
path = os.environ["PATH"].split(os.pathsep) |
| 1137 |
cmd = "dir" |
| 1138 |
for s in path: |
| 1139 |
if os.path.exists(os.path.join(s,"ls.exe")): |
| 1140 |
cmd = "ls" |
| 1141 |
break |
| 1142 |
if dir is not None: |
| 1143 |
cmd = "%s %s"%(cmd,dir) |
| 1144 |
if sys.stdout is sys.__stdout__: |
| 1145 |
sys.stdout.flush() |
| 1146 |
os.system(cmd) |
| 1147 |
else: |
| 1148 |
info(AUTOutil.getstatusoutput(cmd, shell=True)[1]+'\n') |
| 1149 |
commandLs = command(ls) |
| 1150 |
|
| 1151 |
|
| 1152 |
def quit(): |
| 1153 |
"""Quit the AUTO CLUI.""" |
| 1154 |
if isinstance(__builtin__.quit,str): |
| 1155 |
sys.exit() |
| 1156 |
else: |
| 1157 |
__builtin__.quit() |
| 1158 |
commandQuit = command(quit,alias=['q']) |
| 1159 |
|
| 1160 |
|
| 1161 |
def shell(cmd): |
| 1162 |
"""Run a shell command. |
| 1163 |
|
| 1164 |
Type FUNC('xxx') to run the command 'xxx' in the Unix shell and display |
| 1165 |
the results in the AUTO command line user interface. |
| 1166 |
""" |
| 1167 |
sys.stdout.flush() |
| 1168 |
os.system(cmd) |
| 1169 |
commandShell = command(shell) |
| 1170 |
|
| 1171 |
|
| 1172 |
def wait(): |
| 1173 |
"""Wait for the user to enter a key. |
| 1174 |
|
| 1175 |
Type 'FUNC()' to have the AUTO interface wait |
| 1176 |
until the user hits any key (mainly used in scripts). |
| 1177 |
""" |
| 1178 |
print("Hit <return> to continue") |
| 1179 |
raw_input() |
| 1180 |
commandWait = command(wait) |
| 1181 |
|
| 1182 |
|
| 1183 |
def cat(f=None): |
| 1184 |
"""Print the contents of a file |
| 1185 |
|
| 1186 |
Type 'FUNC xxx' to list the contents of the file 'xxx'. |
| 1187 |
""" |
| 1188 |
if f is not None: |
| 1189 |
f = open(f,"r") |
| 1190 |
for line in f: |
| 1191 |
info(line) |
| 1192 |
f.close() |
| 1193 |
else: |
| 1194 |
line = sys.stdin.readline() |
| 1195 |
while line != "": |
| 1196 |
info(line) |
| 1197 |
line = sys.stdin.readline() |
| 1198 |
commandCat = command(cat) |
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
def withrunner(runner=None): |
| 1208 |
return runner |
| 1209 |
|
| 1210 |
|
| 1211 |
def cd(dir=None,runner=None): |
| 1212 |
"""Change directories. |
| 1213 |
|
| 1214 |
Type 'FUNC xxx' to change to the directory 'xxx'. This command |
| 1215 |
understands both shell variables and home directory expansion. |
| 1216 |
""" |
| 1217 |
runner = withrunner(runner) |
| 1218 |
if dir is None or dir == '': |
| 1219 |
dir = os.path.expanduser("~") |
| 1220 |
try: |
| 1221 |
dir = os.path.expanduser(dir) |
| 1222 |
dir = os.path.expandvars(dir) |
| 1223 |
os.chdir(dir) |
| 1224 |
except: |
| 1225 |
print("Directory '%s' not found"%(dir,)) |
| 1226 |
runner.config(dir=os.getcwd()) |
| 1227 |
commandCd = command(cd) |
| 1228 |
|
| 1229 |
|
| 1230 |
def configure(runner=None,templates=None,data=None,**kw): |
| 1231 |
"""Load files into the AUTO runner or return modified solution data. |
| 1232 |
|
| 1233 |
Type result=FUNC([options]) to modify the AUTO runner. |
| 1234 |
|
| 1235 |
The type of the result is a solution object. |
| 1236 |
|
| 1237 |
There are many possible options: |
| 1238 |
\\begin{verbatim} |
| 1239 |
Long name Short name Description |
| 1240 |
------------------------------------------- |
| 1241 |
equation e The equations file |
| 1242 |
constants c The AUTO constants file |
| 1243 |
homcont h The Homcont parameter file |
| 1244 |
solution s The restart solution file |
| 1245 |
NDIM,IPS,etc AUTO constants. |
| 1246 |
BR,PT,TY,LAB Solution constants. |
| 1247 |
\\end{verbatim} |
| 1248 |
Options which are not explicitly set retain their previous value. |
| 1249 |
For example one may type: s=FUNC(e='ab',c='ab.1') to use 'ab.c' as |
| 1250 |
the equations file and c.ab.1 as the constants file. |
| 1251 |
|
| 1252 |
You can also specify AUTO Constants, e.g., DS=0.05, or IRS=2. |
| 1253 |
Special values for DS are '+' (forwards) and '-' (backwards). |
| 1254 |
Example: s = FUNC(s,DS='-') changes s.c['DS'] to -s.c['DS']. |
| 1255 |
""" |
| 1256 |
|
| 1257 |
def applyRunnerConfigResolveAbbreviation(**kw): |
| 1258 |
abbrev = {} |
| 1259 |
for key in ["equation", "constants", "solution", "homcont"]: |
| 1260 |
abbrev[key[0]] = key |
| 1261 |
abbrev[key] = key |
| 1262 |
for key in list(kw): |
| 1263 |
|
| 1264 |
if (key in abbrev and key != abbrev[key] and |
| 1265 |
abbrev[key] in kw): |
| 1266 |
del kw[abbrev[key]] |
| 1267 |
for key,value in list(kw.items()): |
| 1268 |
if key in abbrev: |
| 1269 |
|
| 1270 |
del kw[key] |
| 1271 |
if AUTOutil.isiterable(value): |
| 1272 |
kw[abbrev[key]] = value |
| 1273 |
else: |
| 1274 |
if key[0] == 'e': |
| 1275 |
kw['e'] = value |
| 1276 |
kw[abbrev[key]] = applyTemplate(value,abbrev[key],templates) |
| 1277 |
return kw |
| 1278 |
|
| 1279 |
def applyRunnerConfigResolveFilenames(**kw): |
| 1280 |
exception = None |
| 1281 |
objectdict = {"constants": parseC.parseC, |
| 1282 |
"homcont": parseH.parseH, |
| 1283 |
"solution": parseS.parseS} |
| 1284 |
for key in ["constants", "homcont", "solution"]: |
| 1285 |
if key in kw: |
| 1286 |
value = kw[key] |
| 1287 |
elif data is not None: |
| 1288 |
value = applyTemplate(data,key,templates) |
| 1289 |
else: |
| 1290 |
value = None |
| 1291 |
if value is not None and not AUTOutil.isiterable(value): |
| 1292 |
try: |
| 1293 |
kw[key] = objectdict[key](value) |
| 1294 |
except IOError: |
| 1295 |
if key in kw: |
| 1296 |
|
| 1297 |
exception = sys.exc_info()[1] |
| 1298 |
if key != "solution": |
| 1299 |
raise AUTOExceptions.AUTORuntimeError(exception) |
| 1300 |
|
| 1301 |
kw[key] = None |
| 1302 |
if data is not None and "e" not in kw and not AUTOutil.isiterable(data): |
| 1303 |
kw["e"] = data |
| 1304 |
kw["equation"] = applyTemplate(data,"equation",templates) |
| 1305 |
if "e" in kw: |
| 1306 |
eq = kw["e"] |
| 1307 |
for ext in [".f90",".f",".c"]: |
| 1308 |
if os.path.exists(eq+ext): |
| 1309 |
return kw, exception |
| 1310 |
raise AUTOExceptions.AUTORuntimeError( |
| 1311 |
"No equations file found for: '%s'"%eq) |
| 1312 |
return kw, exception |
| 1313 |
|
| 1314 |
runner = withrunner(runner) |
| 1315 |
if "info" in kw: |
| 1316 |
info = kw["info"] |
| 1317 |
del kw["info"] |
| 1318 |
else: |
| 1319 |
info = globals()["info"] |
| 1320 |
kw = applyRunnerConfigResolveAbbreviation(**kw) |
| 1321 |
kw, exception = applyRunnerConfigResolveFilenames(**kw) |
| 1322 |
if data is not None and AUTOutil.isiterable(data): |
| 1323 |
if hasattr(data,"load"): |
| 1324 |
|
| 1325 |
if "equation" in kw: |
| 1326 |
del kw["equation"] |
| 1327 |
solution = data.load(**kw) |
| 1328 |
c = solution.c |
| 1329 |
kw = {"equation": applyTemplate(c.get("e", ""), "equation", |
| 1330 |
templates), |
| 1331 |
"solution": solution, "constants": c, |
| 1332 |
"homcont": c.get("homcont")} |
| 1333 |
else: |
| 1334 |
|
| 1335 |
kw["solution"] = data |
| 1336 |
solution = runner.load(**kw) |
| 1337 |
if exception is not None and runner.options["constants"]["IRS"]: |
| 1338 |
raise AUTOExceptions.AUTORuntimeError(exception) |
| 1339 |
info("Runner configured\n") |
| 1340 |
return solution |
| 1341 |
commandRunnerConfig = command(configure,alias=None) |
| 1342 |
|
| 1343 |
|
| 1344 |
def load(data=None,runner=None,templates=None,**kw): |
| 1345 |
"""Load files into the AUTO runner or return modified solution data. |
| 1346 |
|
| 1347 |
Type result=FUNC([options]) to modify the AUTO runner. |
| 1348 |
Type result=FUNC(data,[options]) to return possibly |
| 1349 |
modified solution data. |
| 1350 |
|
| 1351 |
The type of the result is a solution object. |
| 1352 |
|
| 1353 |
FUNC(data,[options]) returns a solution in the following way for |
| 1354 |
different types of data: |
| 1355 |
|
| 1356 |
* A solution: load returns the solution data, with AUTO constants |
| 1357 |
modified by options. |
| 1358 |
|
| 1359 |
* A bifurcation diagram or a solution list: |
| 1360 |
returns the solution specified by |
| 1361 |
the AUTO constant IRS, or if IRS is not specified, the last solution |
| 1362 |
in s. |
| 1363 |
|
| 1364 |
* A string: AUTO uses the solution in the file 's.s' together with the |
| 1365 |
constants in the files 'c.s', and 'h.s'. Not all of these |
| 1366 |
files need to be present. |
| 1367 |
|
| 1368 |
* A Python list array or a numpy array representing a solution, |
| 1369 |
returns a solution with the given contents. Such an array must be given |
| 1370 |
column-wise, as [[t0, ..., tn], [x0, ..., xn], [y0, ..., yn], ...], |
| 1371 |
or for a point solution as [x, y, z, ...]. |
| 1372 |
|
| 1373 |
There are many possible options: |
| 1374 |
\\begin{verbatim} |
| 1375 |
Long name Short name Description |
| 1376 |
------------------------------------------- |
| 1377 |
equation e The equations file |
| 1378 |
constants c The AUTO constants file |
| 1379 |
homcont h The Homcont parameter file |
| 1380 |
solution s The restart solution file |
| 1381 |
NDIM,IPS,etc AUTO constants. |
| 1382 |
BR,PT,TY,LAB Solution constants. |
| 1383 |
\\end{verbatim} |
| 1384 |
If data is not specified or data is a string then options which |
| 1385 |
are not explicitly set retain their previous value. |
| 1386 |
For example one may type: s=FUNC(e='ab',c='ab.1') to use 'ab.c' as |
| 1387 |
the equations file and c.ab.1 as the constants file. |
| 1388 |
|
| 1389 |
Type s=FUNC('name') to load all files with base 'name'. |
| 1390 |
This does the same thing as running |
| 1391 |
s=FUNC(e='name',c='name,h='name',s='name'). |
| 1392 |
|
| 1393 |
You can also specify AUTO Constants, e.g., DS=0.05, or IRS=2. |
| 1394 |
Special values for DS are '+' (forwards) and '-' (backwards). |
| 1395 |
Example: s = FUNC(s,DS='-') changes s.c['DS'] to -s.c['DS']. |
| 1396 |
""" |
| 1397 |
runner = withrunner(runner) |
| 1398 |
return configure(runner,templates,data,**kw) |
| 1399 |
commandRunnerLoadName = command(load,SIMPLE,"loadname",alias=['ld']) |
| 1400 |
|
| 1401 |
|
| 1402 |
def loadbd(name=None,templates=None,**kw): |
| 1403 |
"""Load bifurcation diagram files. |
| 1404 |
|
| 1405 |
Type b=FUNC([options]) to load output files or output data. |
| 1406 |
There are three possible options: |
| 1407 |
\\begin{verbatim} |
| 1408 |
Long name Short name Description |
| 1409 |
------------------------------------------- |
| 1410 |
bifurcationdiagram b The bifurcation diagram file |
| 1411 |
solution s The solution file or list of solutions |
| 1412 |
diagnostics d The diagnostics file |
| 1413 |
\\end{verbatim} |
| 1414 |
|
| 1415 |
Type FUNC('name') to load all files with base 'name'. |
| 1416 |
This does the same thing as running |
| 1417 |
FUNC(b='name',s='name,d='name'). |
| 1418 |
plot(b) will then plot the 'b' and 's' components. |
| 1419 |
|
| 1420 |
Returns a bifurcation diagram object representing the files in b. |
| 1421 |
""" |
| 1422 |
def __applyBsdConfigResolveAbbreviation(**kw): |
| 1423 |
abbrev = {} |
| 1424 |
for key in ["bifurcationDiagram", "solution", "diagnostics"]: |
| 1425 |
abbrev[key[0]] = key |
| 1426 |
abbrev[key] = key |
| 1427 |
for key in list(kw): |
| 1428 |
|
| 1429 |
if (key in abbrev and key != abbrev[key] and |
| 1430 |
abbrev[key] in kw): |
| 1431 |
del kw[abbrev[key]] |
| 1432 |
for key,value in list(kw.items()): |
| 1433 |
if key in abbrev: |
| 1434 |
|
| 1435 |
del kw[key] |
| 1436 |
if type(value) in [type(""),type(1),type(1.0)]: |
| 1437 |
kw[abbrev[key]] = applyTemplate(value,abbrev[key],templates) |
| 1438 |
else: |
| 1439 |
kw[abbrev[key]] = value |
| 1440 |
return kw |
| 1441 |
|
| 1442 |
if name is not None: |
| 1443 |
if AUTOutil.isiterable(name): |
| 1444 |
lst = ["bifurcationDiagram"] |
| 1445 |
else: |
| 1446 |
lst = ["bifurcationDiagram", "solution", "diagnostics"] |
| 1447 |
for key in lst: |
| 1448 |
if key not in kw: |
| 1449 |
kw[key] = name |
| 1450 |
if name is None and kw == {}: |
| 1451 |
bname, sname, dname = "fort.7", "fort.8", "fort.9" |
| 1452 |
else: |
| 1453 |
dict = __applyBsdConfigResolveAbbreviation(**kw) |
| 1454 |
bname = dict.get("bifurcationDiagram") |
| 1455 |
sname = dict.get("solution") |
| 1456 |
dname = dict.get("diagnostics") |
| 1457 |
|
| 1458 |
data = bifDiag.bifDiag(bname,sname,dname) |
| 1459 |
info("Parsed output data\n") |
| 1460 |
return data |
| 1461 |
commandParseOutputFiles = command(loadbd,SIMPLE,"loadbd",alias=['bd']) |
| 1462 |
|
| 1463 |
|
| 1464 |
def pr(parameter=None,runner=None): |
| 1465 |
"""Print continuation parameters. |
| 1466 |
|
| 1467 |
Type FUNC() to print all the parameters. |
| 1468 |
Type FUNC('xxx') to return the parameter 'xxx'. |
| 1469 |
These commands are equivalent to the commands |
| 1470 |
print s.c |
| 1471 |
print s.c['xxx'] |
| 1472 |
where s is a solution. |
| 1473 |
""" |
| 1474 |
runner = withrunner(runner) |
| 1475 |
if parameter is None: |
| 1476 |
info(str(runner.options["constants"])) |
| 1477 |
else: |
| 1478 |
return runner.options["constants"][parameter] |
| 1479 |
commandRunnerPrintFort2 = command(pr,alias=['printconstant','pc']) |
| 1480 |
|
| 1481 |
|
| 1482 |
def hpr(parameter=None,runner=None): |
| 1483 |
"""Print HomCont continuation parameters. |
| 1484 |
|
| 1485 |
Type FUNC() to print all the HomCont parameters. |
| 1486 |
Type FUNC('xxx') to return the HomCont parameter 'xxx'. |
| 1487 |
These commands are equivalent to the commands |
| 1488 |
print s.c |
| 1489 |
print s.c['xxx'] |
| 1490 |
where s is a solution. |
| 1491 |
""" |
| 1492 |
runner = withrunner(runner) |
| 1493 |
if parameter is None: |
| 1494 |
info(str(runner.options["homcont"])) |
| 1495 |
else: |
| 1496 |
return runner.options["homcont"][parameter] |
| 1497 |
commandRunnerPrintFort12 = command(hpr) |
| 1498 |
|
| 1499 |
|
| 1500 |
def ch(entry=None,value=None,runner=None,**kw): |
| 1501 |
"""Modify continuation constants. |
| 1502 |
|
| 1503 |
Type FUNC('xxx',yyy) to change the constant 'xxx' to have |
| 1504 |
value yyy. |
| 1505 |
This is equivalent to the command |
| 1506 |
s=load(s,xxx=yyy) |
| 1507 |
where s is a solution. |
| 1508 |
""" |
| 1509 |
runner = withrunner(runner) |
| 1510 |
if entry is not None: |
| 1511 |
runner.options["constants"][entry] = value |
| 1512 |
info("%s changed to %s\n"%(entry,value)) |
| 1513 |
else: |
| 1514 |
configure(runner,None,info=lambda s:None,**kw) |
| 1515 |
info(str(kw)+'\n') |
| 1516 |
commandRunnerConfigFort2 = command(ch,SIMPLE,"changeConstants", |
| 1517 |
alias=['changeconstant','cc']) |
| 1518 |
|
| 1519 |
|
| 1520 |
def hch(entry=None,value=None,runner=None,**kw): |
| 1521 |
"""Modify HomCont continuation constants. |
| 1522 |
|
| 1523 |
Type FUNC('xxx',yyy) to change the HomCont constant 'xxx' to have |
| 1524 |
value yyy. |
| 1525 |
This is equivalent to the command |
| 1526 |
s=load(s,xxx=yyy) |
| 1527 |
where s is a solution. |
| 1528 |
""" |
| 1529 |
runner = withrunner(runner) |
| 1530 |
if entry is not None: |
| 1531 |
runner.options["homcont"][entry] = value |
| 1532 |
info("%s changed to %s\n"%(entry,value)) |
| 1533 |
else: |
| 1534 |
configure(runner,None,info=lambda s:None,**kw) |
| 1535 |
info(str(kw)+'\n') |
| 1536 |
commandRunnerConfigFort12 = command(hch,SIMPLE,"changeConstantsHomCont") |
| 1537 |
|
| 1538 |
|
| 1539 |
def run(data=None,sv=None,ap=None,runner=None,templates=None,**kw): |
| 1540 |
"""Run AUTO. |
| 1541 |
|
| 1542 |
Type r=FUNC([data],[options]) to run AUTO from solution data with the given |
| 1543 |
AUTO constants or file keyword options. |
| 1544 |
|
| 1545 |
The results are stored in the bifurcation diagram r which you can |
| 1546 |
later print with ``print r'', obtain branches from via r[0], r[1], ..., |
| 1547 |
and obtain solutions from via r(3), r(5), r('LP2'), where 3 and 5 |
| 1548 |
are label numbers, and 'LP2' refers to the second LP label. |
| 1549 |
|
| 1550 |
FUNC(data) runs AUTO in the following way for different types of data: |
| 1551 |
|
| 1552 |
* A solution: AUTO starts from solution data, with AUTO constants data.c. |
| 1553 |
|
| 1554 |
* A bifurcation diagram: AUTO start from the solution specified by |
| 1555 |
the AUTO constant IRS, or if IRS is not specified, the last solution |
| 1556 |
in data, data()[-1], with AUTO constants data()[-1].c. |
| 1557 |
|
| 1558 |
* A string: AUTO uses the solution in the file 's.data' together with the |
| 1559 |
constants in the files 'c.data', and 'h.data'. Not all of these |
| 1560 |
files need to be present. |
| 1561 |
|
| 1562 |
If no solution data is specified, then the global values from the |
| 1563 |
'load' command are used instead, where |
| 1564 |
options which are not explicitly set retain their previous value. |
| 1565 |
|
| 1566 |
Keyword argument options can be AUTO constants, such as DS=0.05, |
| 1567 |
or ISW=-1, or specify a constant or solution file. These override |
| 1568 |
the constants in s.c, where applicable. See ``load'': |
| 1569 |
FUNC(s,options) is equivalent to FUNC(load(s,options)) |
| 1570 |
|
| 1571 |
Example: given a bifurcation diagram bd, with a branch point |
| 1572 |
solution, switch branches and stop at the first Hopf bifurcation: |
| 1573 |
hb = FUNC(bd('BP1'),ISW=-1,STOP='HB1') |
| 1574 |
|
| 1575 |
Special keyword arguments are 'sv' and 'ap'; 'sv' is also an AUTO |
| 1576 |
constant: |
| 1577 |
FUNC(bd('BP1'),ISW=-1,STOP='HB1',sv='hb',ap='all') |
| 1578 |
saves to the files b.hb, s.hb and d.hb, and appends to b.all, |
| 1579 |
s.all, and d.all. |
| 1580 |
""" |
| 1581 |
runner = withrunner(runner) |
| 1582 |
if sv is not None: |
| 1583 |
kw['sv'] = sv |
| 1584 |
load(data,runner,templates,info=lambda msg:None,**kw) |
| 1585 |
res = runner.run() |
| 1586 |
sv = runner.options["constants"].get("sv") |
| 1587 |
runner.options["constants"]['sv'] = None |
| 1588 |
if sv is not None and sv != '': |
| 1589 |
name = filenameTemplate(sv,templates) |
| 1590 |
bname = name["bifurcationDiagram"] |
| 1591 |
sname = name["solution"] |
| 1592 |
dname = name["diagnostics"] |
| 1593 |
info("Saving to %s, %s, and %s ... done\n"%(bname,sname,dname)) |
| 1594 |
if ap is not None: |
| 1595 |
append(sv,ap) |
| 1596 |
elif ap is not None: |
| 1597 |
append(ap) |
| 1598 |
return res |
| 1599 |
commandRun = command(run,SIMPLE,"run",alias=['r','rn']) |
| 1600 |
|
| 1601 |
|
| 1602 |
def rundemo(demo,equation="all",runner=None): |
| 1603 |
runner = withrunner(runner) |
| 1604 |
runner.config(equation=equation) |
| 1605 |
runner.runDemo(demo) |
| 1606 |
commandRunDemo = command(rundemo,alias=None) |
| 1607 |
|
| 1608 |
|
| 1609 |
def runMakefileWithSetup(equation=None,fort2=None,fort3=None,runner=None): |
| 1610 |
runner = withrunner(runner) |
| 1611 |
if fort2 is not None: |
| 1612 |
runner.config(fort2=fort2) |
| 1613 |
if fort3 is not None: |
| 1614 |
runner.config(fort3=fort3) |
| 1615 |
|
| 1616 |
|
| 1617 |
runner.runMakefileWithSetup(equation) |
| 1618 |
commandRunMakefileWithSetup = command(runMakefileWithSetup,alias=None) |
| 1619 |
|
| 1620 |
|
| 1621 |
def runMakefile(equation=None,runner=None): |
| 1622 |
runner = withrunner(runner) |
| 1623 |
runner.runMakefile(equation) |
| 1624 |
commandRunMakefile = command(runMakefile,alias=None) |
| 1625 |
|
| 1626 |
|
| 1627 |
def runExecutableWithSetup(executable=None,fort2=None,fort3=None,runner=None): |
| 1628 |
runner = withrunner(runner) |
| 1629 |
if fort2 is not None: |
| 1630 |
runner.config(fort2=fort2) |
| 1631 |
if fort3 is not None: |
| 1632 |
runner.config(fort3=fort3) |
| 1633 |
|
| 1634 |
|
| 1635 |
runner.runExecutableWithSetup(executable) |
| 1636 |
commandRunExecutableWithSetup = command(runExecutableWithSetup,alias=None) |
| 1637 |
|
| 1638 |
|
| 1639 |
def runExecutable(executable=None,fort2=None,fort3=None,runner=None): |
| 1640 |
runner = withrunner(runner) |
| 1641 |
runner.runExecutable(executable) |
| 1642 |
commandRunExecutable = command(runExecutable,alias=None) |
| 1643 |
|
| 1644 |
|
| 1645 |
def runCommandWithSetup(command=None,fort2=None,fort3=None,runner=None): |
| 1646 |
runner = withrunner(runner) |
| 1647 |
if fort2 is not None: |
| 1648 |
runner.config(fort2=fort2) |
| 1649 |
if fort3 is not None: |
| 1650 |
runner.config(fort3=fort3) |
| 1651 |
|
| 1652 |
|
| 1653 |
runner.runCommandWithSetup(command) |
| 1654 |
commandRunCommandWithSetup = command(runCommandWithSetup,alias=None) |
| 1655 |
|
| 1656 |
|
| 1657 |
def runCommand(command=None,runner=None): |
| 1658 |
runner = withRunner(runner) |
| 1659 |
runner.runCommand(command) |
| 1660 |
commandRunCommand = command(runCommand,alias=None) |
| 1661 |
|
| 1662 |
|
| 1663 |
def plot3(name=None,r3b=False): |
| 1664 |
"""3D plotting of data. |
| 1665 |
|
| 1666 |
Type FUNC(x) to run the graphics program PLAUT04 for the graphical |
| 1667 |
inspection of bifurcation diagram or solution data in x. |
| 1668 |
|
| 1669 |
Type FUNC('xxx') to run the graphics program PLAUT04 for the graphical |
| 1670 |
inspection of the data-files b.xxx and s.xxx. |
| 1671 |
|
| 1672 |
Type FUNC() to run the graphics program PLAUT04 for the graphical |
| 1673 |
inspection of the output-files 'fort.7' and 'fort.8'. |
| 1674 |
|
| 1675 |
Type FUNC(...,r3b=True) to run PLAUT04 in restricted three body |
| 1676 |
problem mode. |
| 1677 |
""" |
| 1678 |
cmd = os.path.join(os.path.expandvars("$AUTO_DIR"),"bin") |
| 1679 |
cmd = os.path.join(cmd, "plaut04") |
| 1680 |
arg = [] |
| 1681 |
if r3b: |
| 1682 |
arg = ["-r3b"] |
| 1683 |
if name is not None: |
| 1684 |
if type(name) == type(""): |
| 1685 |
arg.append(name) |
| 1686 |
else: |
| 1687 |
d = name |
| 1688 |
for f in ["fort.7","fort.8","fort.9"]: |
| 1689 |
if os.path.exists(f): |
| 1690 |
os.remove(f) |
| 1691 |
if isinstance(d,bifDiag.bifDiag): |
| 1692 |
d.writeFilename("fort.7","fort.8","fort.9") |
| 1693 |
elif isinstance(d,parseBandS.parseBandS): |
| 1694 |
d.writeFilename("fort.7","fort.8") |
| 1695 |
elif isinstance(d,parseB.parseB): |
| 1696 |
d.writeFilename("fort.7") |
| 1697 |
elif isinstance(d,parseS.parseS): |
| 1698 |
d.writeFilename("fort.8") |
| 1699 |
elif isinstance(d,parseB.AUTOBranch): |
| 1700 |
d.writeFilename("fort.7") |
| 1701 |
elif isinstance(d,parseS.AUTOSolution): |
| 1702 |
d.writeFilename("fort.8") |
| 1703 |
sys.stdout.flush() |
| 1704 |
if not os.path.exists(cmd): |
| 1705 |
cmd = cmd + '.exe' |
| 1706 |
if sys.stdout is sys.__stdout__: |
| 1707 |
os.spawnv(os.P_NOWAIT,cmd,[os.path.basename(cmd)] + arg) |
| 1708 |
else: |
| 1709 |
|
| 1710 |
|
| 1711 |
cwd = os.getcwd() |
| 1712 |
os.chdir(os.path.dirname(cmd)) |
| 1713 |
os.spawnv(os.P_NOWAIT,cmd,[os.path.basename(cmd), cwd] + arg) |
| 1714 |
|
| 1715 |
os.chdir(cwd) |
| 1716 |
import time |
| 1717 |
time.sleep(2) |
| 1718 |
|
| 1719 |
commandPlotter3D = command(plot3,alias=['p3']) |
| 1720 |
|
| 1721 |
|
| 1722 |
try: |
| 1723 |
try: |
| 1724 |
from Tkinter import Tk, TclError |
| 1725 |
except ImportError: |
| 1726 |
from tkinter import Tk, TclError |
| 1727 |
plotterimported = False |
| 1728 |
try: |
| 1729 |
import readline |
| 1730 |
import atexit |
| 1731 |
except: |
| 1732 |
pass |
| 1733 |
import select |
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
def handleevents(): |
| 1738 |
while select.select([sys.stdin],[],[],0.02) == ([], [], []): |
| 1739 |
_root.dooneevent() |
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
def plot(name=None,templates=None,**kw): |
| 1746 |
"""Plotting of data. |
| 1747 |
|
| 1748 |
Type FUNC(x) to run the graphics program PyPLAUT for the graphical |
| 1749 |
inspection of bifurcation diagram or solution data in x. |
| 1750 |
|
| 1751 |
Type FUNC('xxx') to run the graphics program PyPLAUT for the graphical |
| 1752 |
inspection of the data-files b.xxx and s.xxx. |
| 1753 |
|
| 1754 |
Type FUNC() to run the graphics program for the graphical |
| 1755 |
inspection of the output-files 'fort.7' and 'fort.8'. |
| 1756 |
|
| 1757 |
Values also present in the file autorc, such as |
| 1758 |
color_list="black green red blue orange" can be provided as |
| 1759 |
keyword arguments, as well as hide=True which hides the |
| 1760 |
on-screen plot. |
| 1761 |
|
| 1762 |
The return value, for instance, p for p=plot(x) will be the handle |
| 1763 |
for the graphics window. |
| 1764 |
It has p.config() and p.savefig() methods that allow you to configure |
| 1765 |
and save the plot. When plotting, see help(p.config) and help(p.savefig) |
| 1766 |
for details. |
| 1767 |
""" |
| 1768 |
|
| 1769 |
options = kw |
| 1770 |
if type(name) == type("") or name is None: |
| 1771 |
name = filenameTemplate(name,templates) |
| 1772 |
parsed = None |
| 1773 |
else: |
| 1774 |
parsed = name |
| 1775 |
|
| 1776 |
global plotterimported, windowPlotter |
| 1777 |
if not plotterimported: |
| 1778 |
from auto.graphics import windowPlotter |
| 1779 |
plotterimported = True |
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
for k in list(options): |
| 1789 |
if k[:8] != 'grapher_': |
| 1790 |
v = options[k] |
| 1791 |
del options[k] |
| 1792 |
options['grapher_'+k] = v |
| 1793 |
|
| 1794 |
|
| 1795 |
root = None |
| 1796 |
if not options.get('grapher_hide'): |
| 1797 |
try: |
| 1798 |
root=Tk() |
| 1799 |
root.withdraw() |
| 1800 |
except TclError: |
| 1801 |
sys.stderr.write(str(sys.exc_info()[1])+"\n") |
| 1802 |
options['grapher_hide'] = True |
| 1803 |
if 'auto.graphics.grapher_mpl' in sys.modules: |
| 1804 |
sys.stderr.write("Disabling on-screen plots, but you can still use savefig\n") |
| 1805 |
else: |
| 1806 |
sys.stderr.write("Disabling plots, off-screen plots require Matplotlib\n") |
| 1807 |
return windowPlotter.WindowPlotter2D(root,disabled=True,**options) |
| 1808 |
if sys.platform == "cygwin": |
| 1809 |
try: |
| 1810 |
readline.set_pre_input_hook(handleevents) |
| 1811 |
global _root |
| 1812 |
_root=root |
| 1813 |
except: |
| 1814 |
pass |
| 1815 |
if parsed: |
| 1816 |
nb, ns = None, None |
| 1817 |
if isinstance(parsed,bifDiag.bifDiag): |
| 1818 |
nb = parsed |
| 1819 |
ns = parsed() |
| 1820 |
elif isinstance(parsed,parseBandS.parseBandS): |
| 1821 |
nb = parsed.diagram.branches |
| 1822 |
ns = parsed.solution |
| 1823 |
elif isinstance(parsed,parseB.parseB): |
| 1824 |
nb = parsed.branches |
| 1825 |
elif isinstance(parsed,parseS.parseS): |
| 1826 |
ns = parsed |
| 1827 |
elif isinstance(parsed,parseB.AUTOBranch): |
| 1828 |
nb = parseB.parseBR([parsed]) |
| 1829 |
elif isinstance(parsed,parseS.AUTOSolution): |
| 1830 |
ns = parseS.parseS([parsed]) |
| 1831 |
if nb: |
| 1832 |
options["grapher_bifurcation_diagram"] = nb |
| 1833 |
if ns: |
| 1834 |
options["grapher_solution"] = ns |
| 1835 |
else: |
| 1836 |
n1b = name["bifurcationDiagram"] |
| 1837 |
n1s = name["solution"] |
| 1838 |
if n1b is None: |
| 1839 |
n1b = "fort.7" |
| 1840 |
n1s = "fort.8" |
| 1841 |
try: |
| 1842 |
n1b = parseB.parseBR(n1b) |
| 1843 |
n1b = bifDiag.bifDiag(n1b,n1s,constants=n1b[0].c) |
| 1844 |
except IOError: |
| 1845 |
n1b = bifDiag.bifDiag(n1b,n1s) |
| 1846 |
options["grapher_bifurcation_diagram"] = n1b |
| 1847 |
options["grapher_solution"] = n1b() |
| 1848 |
handle = windowPlotter.WindowPlotter2D(root,**options) |
| 1849 |
if (not options.get('grapher_hide') or |
| 1850 |
'auto.graphics.grapher_mpl' not in sys.modules): |
| 1851 |
handle.update() |
| 1852 |
try: |
| 1853 |
def plotterquit(): |
| 1854 |
try: |
| 1855 |
handle.destroy() |
| 1856 |
except KeyError: |
| 1857 |
pass |
| 1858 |
atexit.register(plotterquit) |
| 1859 |
except: |
| 1860 |
pass |
| 1861 |
info("Created plot\n") |
| 1862 |
return handle |
| 1863 |
|
| 1864 |
except: |
| 1865 |
print("\n-------------------------------------------------------------") |
| 1866 |
print("Could not import plotting modules, plotting will be disabled.") |
| 1867 |
print("This is probably because Tkinter is not enabled in your Python installation.") |
| 1868 |
print("-------------------------------------------------------------\n") |
| 1869 |
def plot(name=None,templates=None,**kw): |
| 1870 |
"""2D plotting of data. |
| 1871 |
|
| 1872 |
Plotting of data has been disabled in the AUTO-07P CLUI. |
| 1873 |
This is probably because the Python interpretor cannot |
| 1874 |
load the Tkinter module. |
| 1875 |
""" |
| 1876 |
info("2D plotting has been disabled\n") |
| 1877 |
commandPlotter = command(plot,SIMPLE,"plot",alias=['pl','p2']) |
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
def autohelp(command_string=""): |
| 1884 |
outputString = "" |
| 1885 |
|
| 1886 |
_aliases = {} |
| 1887 |
parser = AUTOutil.getAUTORC() |
| 1888 |
if parser.has_section("AUTO_command_aliases"): |
| 1889 |
for option in parser.options("AUTO_command_aliases"): |
| 1890 |
cmd = parser.get("AUTO_command_aliases",option) |
| 1891 |
if cmd not in _aliases: |
| 1892 |
_aliases[cmd] = [] |
| 1893 |
_aliases[cmd].append(option) |
| 1894 |
from auto import AUTOCommands |
| 1895 |
if _aliases == {}: |
| 1896 |
|
| 1897 |
for key in AUTOCommands.__dict__: |
| 1898 |
cmd = getattr(AUTOCommands,key) |
| 1899 |
|
| 1900 |
if hasattr(cmd,"fun") and cmd.alias is not None: |
| 1901 |
_aliases[key] = [cmd.fun.__name__] + cmd.alias |
| 1902 |
|
| 1903 |
command_list = [] |
| 1904 |
|
| 1905 |
|
| 1906 |
for key in AUTOCommands.__dict__: |
| 1907 |
if key in _aliases: |
| 1908 |
command_list.append(key) |
| 1909 |
|
| 1910 |
return_value = {} |
| 1911 |
if not isinstance(command_string, str): |
| 1912 |
try: |
| 1913 |
outputString += command_string.__doc__+'\n' |
| 1914 |
except TypeError: |
| 1915 |
pass |
| 1916 |
info(outputString) |
| 1917 |
return return_value |
| 1918 |
if len(command_string) == 0: |
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
command_list.sort() |
| 1927 |
outputString += " ALIASES DESCRIPTION\n" |
| 1928 |
for cmd in command_list: |
| 1929 |
return_value[cmd] = {} |
| 1930 |
return_value[cmd]["aliases"] = [] |
| 1931 |
aliases = "" |
| 1932 |
for key in _aliases[cmd]: |
| 1933 |
aliases = aliases + key + " " |
| 1934 |
return_value[cmd]["aliases"].append(key) |
| 1935 |
doc = getattr(AUTOCommands,cmd).__doc__ |
| 1936 |
if doc is not None: |
| 1937 |
outputString += " %-25s"%aliases |
| 1938 |
doc = doc.splitlines() |
| 1939 |
return_value[cmd]["description"] = doc[0] |
| 1940 |
outputString += doc[0] |
| 1941 |
outputString += "\n" |
| 1942 |
|
| 1943 |
from auto import interactiveBindings |
| 1944 |
execlist = [{'name' : 'auto', 'alias' : 'ex', |
| 1945 |
'fn' : interactiveBindings.AUTOInteractiveConsole.ex}, |
| 1946 |
{'name' : 'demofile', 'alias' : 'dmf', |
| 1947 |
'fn' : interactiveBindings.AUTOInteractiveConsole.dmf}] |
| 1948 |
for cmdprop in execlist: |
| 1949 |
cmd = cmdprop['name'] |
| 1950 |
return_value[cmd] = {} |
| 1951 |
return_value[cmd]["aliases"] = [cmd,cmdprop['alias']] |
| 1952 |
aliases = cmd + " " + cmdprop['alias'] |
| 1953 |
doc = cmdprop["fn"].__doc__ |
| 1954 |
outputString += " %-25s"%aliases |
| 1955 |
doc = doc.splitlines() |
| 1956 |
return_value[cmd]["description"] = doc[0] |
| 1957 |
outputString += doc[0] |
| 1958 |
outputString += "\n" |
| 1959 |
|
| 1960 |
outputString += "\n" |
| 1961 |
else: |
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
try: |
| 1970 |
doc = getattr(AUTOCommands,command_string).__doc__ |
| 1971 |
return_value["name"] = command_string |
| 1972 |
except: |
| 1973 |
doc = getattr(AUTOCommands,_aliases[command_string]).__doc__ |
| 1974 |
return_value["name"] = _aliases[command_string] |
| 1975 |
doc = doc.replace("FUNC",command_string) |
| 1976 |
return_value["short description"] = doc.splitlines()[0] |
| 1977 |
return_value["long description"] = "\n".join(doc.split("\n")[1:]) |
| 1978 |
|
| 1979 |
|
| 1980 |
doc = doc.replace("\\begin{verbatim}","") |
| 1981 |
doc = doc.replace("\\end{verbatim}","") |
| 1982 |
doc = doc + "\n" |
| 1983 |
|
| 1984 |
if not command_string in command_list: |
| 1985 |
|
| 1986 |
for cmd in _aliases: |
| 1987 |
if command_string in _aliases[cmd]: |
| 1988 |
command_string = cmd |
| 1989 |
break |
| 1990 |
doc = doc + "Command name: "+command_string+"\n" |
| 1991 |
return_value["aliases"] = [] |
| 1992 |
doc = doc + "Aliases: " |
| 1993 |
if command_string in _aliases: |
| 1994 |
for key in _aliases[command_string]: |
| 1995 |
doc = doc + key + " " |
| 1996 |
return_value["aliases"].append(key) |
| 1997 |
outputString += doc+"\n" |
| 1998 |
info(outputString) |
| 1999 |
return return_value |
| 2000 |
commandHelp = command(autohelp) |
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
def man(command_string=""): |
| 2007 |
"""Get help on the AUTO commands. |
| 2008 |
|
| 2009 |
Type 'FUNC' to list all commands with a online help. |
| 2010 |
Type 'FUNC xxx' to get help for command 'xxx'. |
| 2011 |
""" |
| 2012 |
autohelp(command_string) |
| 2013 |
commandInteractiveHelp = command(man) |
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
|
| 2019 |
def printFunc(printFnc,text): |
| 2020 |
printFnc(text) |
| 2021 |
info(text) |
| 2022 |
commandPrintFunc = command(printFunc) |
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
def gui(type="simple"): |
| 2027 |
"""Show AUTOs graphical user interface. |
| 2028 |
|
| 2029 |
Type FUNC() to start AUTOs graphical user interface. |
| 2030 |
|
| 2031 |
NOTE: This command is not implemented yet. |
| 2032 |
""" |
| 2033 |
try: |
| 2034 |
from Tkinter import Tk |
| 2035 |
except ImportError: |
| 2036 |
from tkinter import Tk |
| 2037 |
from auto.graphics import AUTOgui, Pmw |
| 2038 |
|
| 2039 |
root = Tk() |
| 2040 |
root.withdraw() |
| 2041 |
guic = AUTOgui.AUTOgui(type) |
| 2042 |
info("GUI created\n") |
| 2043 |
return guic |
| 2044 |
commandCreateGUI = command(gui) |
| 2045 |
|
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
|
| 2051 |
|
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
|
| 2060 |
def splabs(s,typename,templates=None): |
| 2061 |
"""Return special labels |
| 2062 |
|
| 2063 |
Type FUNC('xxx',typename) to get a list of labels with the specified |
| 2064 |
typename, where typename can be one of |
| 2065 |
'EP', 'MX', 'BP', 'LP', 'UZ', 'HB', 'PD', 'TR', or 'RG'. |
| 2066 |
This is equivalent to the command |
| 2067 |
load('xxx')(typename) |
| 2068 |
which gives a list of the solutions themselves; |
| 2069 |
load('xxx')(typename).getLabels() |
| 2070 |
returns the list of labels. |
| 2071 |
|
| 2072 |
Or use FUNC(s,typename) where s is a parsed solution from sl(). |
| 2073 |
This is equivalent to the command |
| 2074 |
s(typename).getLabels() |
| 2075 |
""" |
| 2076 |
labels = [] |
| 2077 |
for solution in sl(s,templates=templates): |
| 2078 |
if solution['Type name'] == typename: |
| 2079 |
labels.append(solution['Label']) |
| 2080 |
return labels |
| 2081 |
commandSpecialPointLabels = command(splabs) |
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
def test(): |
| 2088 |
from auto import runAUTO |
| 2089 |
import sys |
| 2090 |
|
| 2091 |
def printfunc(text): |
| 2092 |
stdout.write(text+"\n") |
| 2093 |
|
| 2094 |
stdout = sys.stdout |
| 2095 |
f = StringIO() |
| 2096 |
def getinfo(s): |
| 2097 |
f.write(s) |
| 2098 |
def noinfo(s): |
| 2099 |
pass |
| 2100 |
global info |
| 2101 |
|
| 2102 |
runner = runAUTO.runAUTO( |
| 2103 |
makefile="", |
| 2104 |
demos_dir=os.path.join(os.environ["AUTO_DIR"],"python")) |
| 2105 |
|
| 2106 |
clean = commandRunDemo("wav","clean",runner) |
| 2107 |
first = commandRunDemo("wav","first",runner) |
| 2108 |
second = commandRunDemo("wav","second",runner) |
| 2109 |
tmacro = commandMacro((clean,first,first)) |
| 2110 |
printer = commandPrintFunc(printfunc,"Hello World") |
| 2111 |
quiet = commandRunnerConfig(runner,log=f) |
| 2112 |
verbose = commandRunnerConfig(runner,log=None) |
| 2113 |
changedir = commandCd("wav",runner) |
| 2114 |
constants = commandParseConstantsFile("wav") |
| 2115 |
changeup = commandCd("..",runner) |
| 2116 |
|
| 2117 |
verbose() |
| 2118 |
clean() |
| 2119 |
first() |
| 2120 |
tmacro() |
| 2121 |
quiet() |
| 2122 |
second() |
| 2123 |
stdout.write(f.getvalue()+"\n") |
| 2124 |
printer() |
| 2125 |
verbose() |
| 2126 |
clean() |
| 2127 |
changedir() |
| 2128 |
constants() |
| 2129 |
changeup() |
| 2130 |
|
| 2131 |
if __name__ == "__main__": |
| 2132 |
test() |