-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetValues
executable file
·603 lines (531 loc) · 14.2 KB
/
getValues
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
#!/bin/bash
#
# Returns values based on input arguments. The first argument is the absolute
# /path/to/folder of the pertinient data, the second is the name of a function below.
max=$3
gvUpStp=$4 # Step at which to change Y2 convergence test value.
d1=$5 # Allowed difference between Y2 values before gvUpStep.
d2=$6 # Allowed difference between Y2 values at or after gvUpStep.
function notDone
{ # Returns 1 if a run needs to be started or restarted, otherwise returns empty.
# Conditions are: if no growth rate convergence and less than "max" steps
# (set below,) or if fort.50 not present. Set neverRestart to false to enable.
neverRestart=false
[ ! $max ] && max=200000
if [ "$neverRestart" != "true" ]; then
if [ -f fort.50 ]; then
if [ "$(Y2)" = "0" ] && [ $(stepsCompleted) -lt $max ]; then
notDone=1
fi
else
notDone=1
fi
fi
echo $notDone
}
function stepsCompleted
{
if [ -f fort.23a ]; then
steps=$(cat fort.23a | wc -l)
elif [ -f fort.23 ]; then
steps=$(cat fort.23 | wc -l)
else
steps=-1
fi
echo $steps
}
function isRunning
{
[ $(qstat -f | grep Job_Name | cut -c 16- | grep `basename $(pwd)`) ] && echo true;
}
function jVec
{
for folder in `ls`; do
if [ -f $folder/fort.50 ]; then
j=${folder##*j}; jVec="$jVec $j"
fi
done
echo $jVec | sed 's/ /\n/g' | sort -gu
}
function MVec
{
for folder in `ls`; do
if [ -f $folder/fort.50 ]; then
M=${folder%%j*}; M=${M##*M}; MVec="$MVec $M"
fi
done
echo $MVec | sed 's/ /\n/g' | sort -gu
}
function mVec
{
for folder in `ls`; do
if [ -f $folder/fort.50 ]; then
m=${folder%%M*}; m=${m##*m}; mVec="$mVec $m"
fi
done
echo $mVec | sed 's/ /\n/g' | sort -gu
}
function qVec
{
for folder in `ls`; do
if [ -f $folder/fort.50 ]; then
q=${folder%%m*}; q=${q##*q}; qVec="$qVec $q"
fi
done
echo $qVec | sed 's/ /\n/g' | sort -gu
}
function nVec
{
for folder in `ls`; do
if [ -f $folder/fort.50 ]; then
n=${folder%%q*}; n=${n##*n}; nVec="$nVec $n"
fi
done
echo $nVec | sed 's/ /\n/g' | sort -gu
}
function jmax
{
jmax=`grep -w jmax fact | cut -c 22-25`
echo $jmax
}
function jtotp
{
exp=`grep -w jtotp fact | cut -c 29-31`
base=`grep -w jtotp fact | cut -c 18-27`
jtotp=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $jtotp
}
function omegaMax
{
exp=`grep -w omega\ max fact | cut -c 29-32`
base=`grep -w omega\ max fact | cut -c 18-27`
omegaMax=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $omegaMax
}
function etot
{
exp=`grep -w etot fact | cut -c 29-32`
base=`grep -w etot fact | cut -c 18-27`
etot=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $etot
}
function tjeans
{
exp=`grep -w tjeans: fact | cut -c 24-27`
base=`grep -w tjeans: fact | cut -c 16-22`
tjeans=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $tjeans
}
function tsound
{
exp=`grep -w tsound: fact | cut -c 24-27`
base=`grep -w tsound: fact | cut -c 16-22`
tsound=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $tsound
}
function starMass
{
exp=`grep -w star/disk: polyout | cut -c 24-26`
base=`grep -w star/disk: polyout | cut -c 16-22`
starMass=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $starMass
}
function TW
{
exp=`grep -w t/\|w\| polyout | cut -c 36-38`
base=`grep -w t/\|w\| polyout | cut -c 28-34`
TW=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $TW
}
function rInOut
{
exp=`grep -w r-/r+: polyout | cut -c 24-26`
base=`grep -w r-/r+: polyout | cut -c 16-22`
rInOut=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $rInOut
}
function rPlusR0
{
exp=`grep -w r+/r0: polyout | cut -c 24-26`
base=`grep -w r+/r0: polyout | cut -c 16-22`
rPlusR0=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $rPlusR0
}
function rMinusR0
{
exp=`grep -w r-/ro: polyout | cut -c 24-26`
base=`grep -w r-/ro: polyout | cut -c 16-22`
rMinusR0=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $rMinusR0
}
function rhomax
{
exp=`grep -w rhomax: polyout | cut -c 24-26`
base=`grep -w rhomax: polyout | cut -c 16-22`
rhomax=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $rhomax
}
function qMinusR0
{
exp=`grep -w Q-/r0: polyout | cut -c 25-27`
base=`grep -w Q-/r0: polyout | cut -c 17-23`
qMinusR0=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $qMinusR0
}
function qPlusR0
{
exp=`grep -w Q+/r0: polyout | cut -c 28-30`
base=`grep -w Q+/r0: polyout | cut -c 20-26`
qPlusR0=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $qPlusR0
}
function rLambdaR0
{
exp=`grep -w rvortmax/r0: polyout | cut -c 28-30`
base=`grep -w rvortmax/r0: polyout | cut -c 20-26`
rLambdaR0=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $rLambdaR0
}
function MIRP
{
exp=`grep -w MIRP: polyout | cut -c 24-26`
base=`grep -w MIRP: polyout | cut -c 16-22`
MIRP=`echo "scale=8; ($base/1)*10^(0$exp)" | bc`
echo $MIRP
}
function eta
{
exp=`grep -w eta: polyout | cut -c 24-26`
base=`grep -w eta: polyout | cut -c 16-22`
eta=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $eta
}
function p
{
printf '%.4f' `grep -w \ \ \ \ \ p: polyout | cut -c 16-26`
}
function tauzero
{
exp=`grep -w tauzero: polyout | cut -c 24-26`
base=`grep -w tauzero: polyout | cut -c 16-22`
tauzero=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $tauzero
}
function sqrtTau
{
printf '%.4f' `grep -w sqrtTau: polyout | cut -c 16-26`
}
function omegazero
{
exp=`grep -w omegazero: polyout | cut -c 28-30`
base=`grep -w omegazero: polyout | cut -c 20-26`
omegazero=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $omegazero
}
function jeansfreq
{
exp=`grep -w jeans\ freq: polyout | cut -c 28-30`
base=`grep -w jeans\ freq: polyout | cut -c 20-26`
jeansfreq=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $jeansfreq
}
function cfreqzero
{
exp=`grep -w c\ freq\ zero: polyout | cut -c 28-30`
base=`grep -w c\ freq\ zero: polyout | cut -c 20-26`
cfreqzero=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $cfreqzero
}
function keplerfreq
{
exp=`grep -w kepler\ freq: polyout | cut -c 28-30`
base=`grep -w kepler\ freq: polyout | cut -c 20-26`
keplerfreq=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $keplerfreq
}
function virialError
{
exp=`grep -w virial\ error polyout | cut -c 36-39`
base=`grep -w virial\ error polyout | cut -c 28-34`
virialError=`echo "scale=8; ($base/1)*10^(0$exp)" | bc`
echo $virialError
}
function mass
{
exp=`grep -w mass: polyout | cut -c 18-21`
base=`grep -w mass: polyout | cut -c 10-16`
mass=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $mass
}
function oneMinusRInR0
{
exp=`grep -w 1\ -\ r-/r0: polyout | cut -c 26-29`
base=`grep -w 1\ -\ r-/r0: polyout | cut -c 18-24`
oneMinusRInR0=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $oneMinusRInR0
}
function r0
{
exp=`grep -w \ \ \ \ \ r0: polyout | cut -c 21-24`
base=`grep -w \ \ \ \ \ r0: polyout | cut -c 13-19`
r0=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
echo $r0
}
function checkConvergence
{ # Y2 is the mode growth rate, and is used to determine whether frequency-based
# values are valid and whether to restart upon completion.
# check for inputs or set defaults
[ ! $gvUpStp ] && gvUpStp=100000
[ ! $d1 ] && d1=.001
[ ! $d2 ] && d2=.01
if [ $(stepsCompleted) -lt $gvUpStp ]; then d=$d1
else d=$d2; fi
# screen for NaNs, convert to testable values
test1=`grep -w y2_1: fort.50 | cut -c 24-26`
if [ "$test1" = "NaN" ]; then n1=-999999
else
exp1=$test1
base1=`grep -w y2_1: fort.50 | cut -c 16-22`
yn1=`echo "scale=10; ($base1/1)*10^(0$exp1)" | bc`
fi
test2=`grep -w y2_2: fort.50 | cut -c 24-26`
if [ "$test2" = "NaN" ]; then n2=-888888
else
exp2=$test2
base2=`grep -w y2_2: fort.50 | cut -c 16-22`
yn2=`echo "scale=10; ($base2/1)*10^(0$exp2)" | bc`
fi
test3=`grep -w y2_3: fort.50 | cut -c 24-26`
if [ "$test3" = "NaN" ]; then n3=-777777
else
exp3=$test3
base3=`grep -w y2_3: fort.50 | cut -c 16-22`
yn3=`echo "scale=10; ($base3/1)*10^(0$exp3)" | bc`
fi
# calculate differences between y2 values
y2_12diff=$(echo "scale=10; sqrt(($yn1-($yn2))^2)" | bc);
y2_13diff=$(echo "scale=10; sqrt(($yn1-($yn3))^2)" | bc);
y2_23diff=$(echo "scale=10; sqrt(($yn2-($yn3))^2)" | bc);
# find smallest two differences and average them
if [ "$(echo "$y2_12diff < $y2_13diff" | bc)" = "1" ]; then
diff2=$y2_12diff
growthRate=`echo "scale=4; ($yn1 + $yn2)/2" | bc`
radius1=true
radius2=true
radius3=$NULL
else
diff2=$y2_13diff
growthRate=`echo "scale=4; ($yn1 + $yn3)/2" | bc`
radius1=true
radius2=$NULL
radius3=true
fi
if [ "$(echo "$y2_23diff < $diff2" | bc)" = "1" ]; then
diff2=$y2_23diff
growthRate=`echo "scale=4; ($yn2 + $yn3)/2" | bc`
radius1=$NULL
radius2=true
radius3=true
fi
# test if average is less than specified requirement
if [ "$(echo "$diff2 < $d" | bc)" != "1" ]; then
growthRate=0
stable=true
fi
}
function Y2
{
checkConvergence
echo $growthRate
}
function Y1
{
checkConvergence
if [ $stable ]; then avg="NaN"
else
#New method:
exp=`grep -w y1\ avg: fort.50 | cut -c 24-26`
base=`grep -w y1\ avg: fort.50 | cut -c 16-22`
avg=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
#Old method using Y2 radii (obsolete:)
if [ ]; then #BEGIN COMMENTBLOCK
# get values from correct radii
if [ $radius1 ]; then
exp=`grep -w y1_1: fort.50 | cut -c 24-26`
base=`grep -w y1_1: fort.50 | cut -c 16-22`
n1=`echo "scale=10; ($base/1)*10^(0$exp)" | bc`
fi
if [ $radius2 ]; then
exp=`grep -w y1_2: fort.50 | cut -c 24-26`
base=`grep -w y1_2: fort.50 | cut -c 16-22`
n2=`echo "scale=10; ($base/1)*10^(0$exp)" | bc`
fi
if [ $radius3 ]; then
exp=`grep -w y1_3: fort.50 | cut -c 24-26`
base=`grep -w y1_3: fort.50 | cut -c 16-22`
n3=`echo "scale=10; ($base/1)*10^(0$exp)" | bc`
fi
# average them
if [ $radius1 ] && [ $radius2 ]; then
avg=`echo "scale=4; ($n1 + $n2)/2" | bc`
elif [ $radius1 ] && [ $radius3 ]; then
avg=`echo "scale=4; ($n1 + $n3)/2" | bc`
elif [ $radius2 ] && [ $radius3 ]; then
avg=`echo "scale=4; ($n2 + $n3)/2" | bc`
fi
fi #END COMMENTBLOCK
fi
echo $avg
}
function RcoR0
{
checkConvergence
if [ $stable ]; then avg="NaN"
else
# get values from correct radii
if [ $radius1 ]; then
exp=`grep -w Rco/R01: fort.50 | cut -c 26-28`
base=`grep -w Rco/R01: fort.50 | cut -c 18-24`
n1=`echo "scale=10; ($base/1)*10^(0$exp)" | bc`
fi
if [ $radius2 ]; then
exp=`grep -w Rco/R02: fort.50 | cut -c 26-28`
base=`grep -w Rco/R02: fort.50 | cut -c 18-24`
n2=`echo "scale=10; ($base/1)*10^(0$exp)" | bc`
fi
if [ $radius3 ]; then
exp=`grep -w Rco/R03: fort.50 | cut -c 26-28`
base=`grep -w Rco/R03: fort.50 | cut -c 18-24`
n3=`echo "scale=10; ($base/1)*10^(0$exp)" | bc`
fi
# average them
if [ $radius1 ] && [ $radius2 ]; then
avg=`echo "scale=4; ($n1 + $n2)/2" | bc`
elif [ $radius1 ] && [ $radius3 ]; then
avg=`echo "scale=4; ($n1 + $n3)/2" | bc`
elif [ $radius2 ] && [ $radius3 ]; then
avg=`echo "scale=4; ($n2 + $n3)/2" | bc`
fi
fi
echo $avg
}
function rPhiR0
{
if [ "$(Y2)" = "0" ]; then rPhiR0="NaN"; else
exp=`grep -w drho\ min/ro: fort.50 | cut -c 29-31`
base=`grep -w drho\ min/ro: fort.50 | cut -c 20-27`
rPhiR0=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
fi
echo $rPhiR0
}
function rGammaR0
{
if [ "$(Y2)" = "0" ]; then rGammaR0="NaN"; else
exp=`grep -w R\ torque1: fort.50 | cut -c 27-29`
base=`grep -w R\ torque1: fort.50 | cut -c 19-25`
rGammaR0=`echo "scale=4; ($base/1)*10^(0$exp)" | bc`
fi
echo $rGammaR0
}
function RilrR0
{
checkConvergence
if [ $stable ]; then avg="NaN"
else
# get values from correct radii
if [ $radius1 ]; then
exp=`grep -w lindin1: fort.50 | cut -c 24-26`
base=`grep -w lindin1: fort.50 | cut -c 16-22`
n1=`echo "scale=10; ($base/1)*10^(0$exp)" | bc`
fi
if [ $radius2 ]; then
exp=`grep -w lindin2: fort.50 | cut -c 24-26`
base=`grep -w lindin2: fort.50 | cut -c 16-22`
n2=`echo "scale=10; ($base/1)*10^(0$exp)" | bc`
fi
if [ $radius3 ]; then
exp=`grep -w lindin3: fort.50 | cut -c 24-26`
base=`grep -w lindin3: fort.50 | cut -c 16-22`
n3=`echo "scale=10; ($base/1)*10^(0$exp)" | bc`
fi
# average them
if [ $radius1 ] && [ $radius2 ]; then
avg=`echo "scale=4; ($n1 + $n2)/2" | bc`
elif [ $radius1 ] && [ $radius3 ]; then
avg=`echo "scale=4; ($n1 + $n3)/2" | bc`
elif [ $radius2 ] && [ $radius3 ]; then
avg=`echo "scale=4; ($n2 + $n3)/2" | bc`
fi
fi
echo $avg
}
function mTorqueMd
{ # returns first occurence in file
if [ "$(Y2)" = "0" ]; then mTorqueMd="NaN"; else
exp=`grep -m 1 M\ torque/M fort.50 | cut -c 29-31`
base=`grep -m 1 M\ torque/M fort.50 | cut -c 21-27`
mTorqueMd=`echo "scale=4; ($base/1*1)*10^(0$exp)" | bc`
fi
echo $mTorqueMd
}
function jTorqueJ1
{
if [ "$(Y2)" = "0" ]; then jTorqueJ1="NaN"; else
exp=`grep -w Jtorque/J1: fort.50 | cut -c 27-29`
base=`grep -w Jtorque/J1: fort.50 | cut -c 19-25`
jTorqueJ1=`echo "scale=4; ($base/1*1)*10^(0$exp)" | bc`
fi
echo $jTorqueJ1
}
function lindoutAvg
{
checkConvergence
if [ $stable ]; then avg="NaN"
else
# get values from correct radii
if [ $radius1 ]; then
exp=`grep -w lindout1: fort.50 | cut -c 27-29`
base=`grep -w lindout1: fort.50 | cut -c 19-25`
n1=`echo "scale=10; ($base/1)*10^(0$exp)" | bc`
fi
if [ $radius2 ]; then
exp=`grep -w lindout2: fort.50 | cut -c 27-29`
base=`grep -w lindout2: fort.50 | cut -c 19-25`
n2=`echo "scale=10; ($base/1)*10^(0$exp)" | bc`
fi
if [ $radius3 ]; then
exp=`grep -w lindout3: fort.50 | cut -c 27-29`
base=`grep -w lindout3: fort.50 | cut -c 19-25`
n3=`echo "scale=10; ($base/1)*10^(0$exp)" | bc`
fi
# average them
if [ $radius1 ] && [ $radius2 ]; then
avg=`echo "scale=4; ($n1 + $n2)/2" | bc`
elif [ $radius1 ] && [ $radius3 ]; then
avg=`echo "scale=4; ($n1 + $n3)/2" | bc`
elif [ $radius2 ] && [ $radius3 ]; then
avg=`echo "scale=4; ($n2 + $n3)/2" | bc`
fi
fi
echo $avg
}
function radstarMinus
{
grep radstarMinus: fort.50 | awk '{ printf "%g", $2; }'
}
function radstar
{
#Below is THE BEST way to get a value that I've found.
#Printed number must be in 2nd column; columns may be
#delimited by any number of spaces.
grep radstar: fort.50 | awk '{ printf "%g", $2; }'
#A space in the name (i.e. "M torque/M1") will break it.
#This can be fixed by adding a sed command as follows:
#grep -m 1 M\ torque/M1: fort.50 | sed s@M\ torque/M1:@@ | awk '{ printf "%g", $1 }'
}
function radstarPlus
{
grep radstarPlus: fort.50 | awk '{ printf "%g", $2; }'
}
cd $1
echo `$2`