设置DG
SOLPS-ITER Workflow
image.png- 解释lns的功能
#! /usr/bin/env ksh
# VERSION : 05.03.98 19:38
[ "$1" = '' ] && { \
echo "Usage: lns <Varid>"
echo " This will link the files to the Sonnet directory:"
echo " <Varid>.str --> struct.snn"
echo " <Varid>.trg --> targets.snn"
echo " equilibrium file --> equilibr.snn"
echo " to the Carre directory:"
echo " <Varid>.str --> dg.str"
echo " <Varid>.trg --> dg.trg"
echo " <Varid>.dgo --> dg.dgo"
echo " equilibrium file --> dg.equ"
echo " to the uinp directory:"
echo " <Varid>.dgo --> uinput.dg"
echo " <Varid>.trg --> uinput.trg"
echo " and to the baserun directory:"
echo " <Varid>.dgo --> param.dg"
exit 4
}
lns 功能
- link to sonnet、carre、uinp、baserun文件
- 主要包含structure信息,trg信息,磁平衡信息和dgo信息
-
ksh
image.png
-
[ "$DEVICE" = '' ] && {
print -u2 -n -- "No DEVICE selected. Please provide a device name\n "
read u
export DEVICE=$u
}
-
如果环境变量${DEVICE}不存在,从键盘读取变量名,并将结果导出
image.png
-
https://www.oreilly.com/library/view/korn-shell-unix/0201675234/0201675234_ch09lev1sec3.html
[ "$SOLPS_CENTRAL" = 'yes' ] && DEVICE=$DEVICE/$USER
# SOLPS_CENTRAL 没有被定义
CLASSDIR=${DG}/device/$DEVICE
# equal to /modules/modules/DivGeo/HL-2M
[ -d "$CLASSDIR" ] || {
print -u2 -n -- "The directory $CLASSDIR does not exist. Create it? (y/n) "
# 判断文件夹是否存在,如果不存在,则:
while true; do {
read u
{ case $u in
(y|Y) mkdir -p "$CLASSDIR" || {
print -u2 -- "Unable to create the directory. Check the permissions in ${CLASSDIR}%/*"
break 2
}; break;;
(n|N) break 2;;
( * ) print -u2 -n -- "Please answer with either y or n: ";;
esac; }
}; done
}
# 创建文件夹,创建完毕退出case
- 如果不存在一直做,读取输入的信息。如果信息是y|Y,这创建文件夹,随后退出
-
非法字符过滤,并且提示
image.png
-
- case架构
{ case $u in
(y|Y) mkdir -p "$CLASSDIR" || {}
}
-
|| 的用法
image.png
-
-
break n 跳出第n层循环; continue 跳出当前循环
image.png
-
-
print -u2 -n
image.png
image.png
-
https://osr507doc.xinuos.com/en/OSUserG/_The_print_command_Korn_shell_only.html
image.png
image.png
ln -sf `pwd`/"$1".str ${DG}/device/$DEVICE/struct.snn
ln -sf `pwd`/"$1".trg ${DG}/device/$DEVICE/targets.snn
ln -sf `pwd`/"$1".dgo uinput.dg
ln -sf `pwd`/"$1".trg uinput.trg
ln -sf `pwd`/"$1".str dg.str
ln -sf `pwd`/"$1".trg dg.trg
ln -sf `pwd`/"$1".dgo dg.dgo
ln -sf `pwd`/"$1".dgo param.dg
e=`cat $1.trg | grep '# equil' | cut -f3 -d' '`
-
1 . ln的用法
image.png
image.png
-
获取路径信息
image.png
-
-
cut -f3 -d ' ' :以空格为分割符,显示第三列数据
image.png
-
# check in case we are doing a limiter configuration
# and must fetch the real equilibrium from the .dgo file
typeset -i z
NAME=/tmp/lns.$USER.`date +%Y%m%d%H%M%S`
# 创建文件文件名
-
type -i z
image.png
-
-
date +%Y%m%d%H%M%S
image.png
-
cat $1.dgo | grep 'lm_equ' | wc -l > $NAME
z=`cat $NAME`
[ $z -gt 0 ] && {
l=`cat $1.dgo | grep 'lm_equ' | cut -f4 -d' '`
[ -s $l ] && {
echo Linking to limiter equilibrium $l
e=$l
} || {
echo Limiter equilibrium file $l not found!
}
}
#
rm $NAME
-
若如果是limiter configuration
image.png
-
-
判断是否存在lm_equ,判定是否为限制器位型
image.png
-
- 获取限制器位型的名称,将限制的位型连接到对应的磁平衡
- [ expresion] &&{ } || {}
-
cut 中会出现 空格field
image.png
-
case $e in
( '' ) echo "$1.trg is in old format - no information on the equilibrium there"
[ -r default.equ ] && { \
ln -sf `pwd`/default.equ ${DG}/device/$DEVICE/equilibr.snn
ln -sf `pwd`/default.equ dg.equ
echo '-- the default equilibrium file is used';
} || echo '*** No default equilibrium file found (!!!)';;
( /* ) ln -sf $e ${DG}/device/$DEVICE/equilibr.snn
ln -sf $e dg.equ;;
( ../* ) (d=`dirname $e`; f=`basename $e`; cd $d;
ln -sf `pwd`/$f ${DG}/device/$DEVICE/equilibr.snn
ln -sf `pwd`/$f dg.equ);;
( ./* ) (d=`dirname $e`; f=`basename $e`; cd $d;
ln -sf `pwd`/$f ${DG}/device/$DEVICE/equilibr.snn
ln -sf `pwd`/$f dg.equ);;
( * ) ln -sf `pwd`/$e ${DG}/device/$DEVICE/equilibr.snn
ln -sf `pwd`/$e dg.equ;;
esac
-
- 判断磁平衡文件所在位置
- 如果文件不可读,采用默认磁平衡(当前版本不支持)
- 中括号的用法
https://www.runoob.com/w3cnote/linux-shell-brackets-features.html
-
[ ] test 命令
image.png
-
-
dirname和basename获得路径和文件名
image.png
-
- 若文件不在当前位置,先进入目标路径在进行强制软连接
-
htop使用简介
image.png
image.png
image.png
-
-
虚拟内存的含义
image.png
-
carre
#! /usr/bin/env ksh
# VERSION : 20.07.2000 14:15
script=`basename $0`
# 获得当前脚本的文件名(carre)
-
特殊变量的含义
image.png
-
https://www.cnblogs.com/fhefh/archive/2011/04/15/2017613.html
stty erase ^H
# 修改终端命令行的相关设置
-
stty erase ^H
image.png
-
Usage="
This is a script to call the \"carre\" grid generator.
It makes standard links to the necessary files, calls \"carre\", calls the grid convertor
\"traduit\", and moves the resulting grid to the standard place with a new name.
Usage:
$script { <stem> | - }
The input files are:
<stem>.inp the configuration file for carre
<stem>.vrq the equilibrium data in \"TdeV\" format
<stem>.str the \"structures\" file
<stem>.fld the product of R*Btor
If \"-\" is specified, then the input files are assumed to exist or to be created
via fcrr from dg output.
The script prints the output filename after successful grid conversion to B2 format.
The directories for the input files and for the grids can be specified in the
environmental variables CARRE_INPUTDIR and CARRE_GRIDDIR (default is the current directory).
If the variable CARRE_STOREDIR is set, then all the input data (i.e., the control file, the
equilibrium file, and the structures file) are saved in a directory
\$CARRE_STOREDIR/\$DEVICE/<grid number>. If this directory does not exist, it is created.
Error messages and tracing data from carre (\"Grid\") and traduit (\"Convert\") can be found in
the files carre.log and traduit.log, respectively.
"
没有输入参数,显示提示信息
- inp carre 的位型文件
- vrq 磁平衡文件
- str structures文件
- fld R*Btor
- 通过fcrr装换文件格式
- 如果CARRE_STOREDIR 被设置,所有的输入文件(i.e. 控制文件,磁平衡和结构,被保存在文件夹){DEVICE}/<grid number>,如果文件不存在,则,创建文件
-
-
ssd ${DEVICE}中的文件,及其对应你的内容
image.png
- *.dg:整个dg相关的DG生成的文件
- *.dgo:structure相关的位置坐标,以及不同element对应的温度,XP,s三角网格相关的参数
- *.str:structure分组及其位置坐标
- *.trg:靶板位置,contour等极和对应的分区信息
- equilibr.snn:磁平衡文件
- struct.snn:link to str
- targets.snn:link to trg
- *.sno:b2 mesh
- templates: triangles mesh
- *.equ: equilibrium file
-
基本文件读写
[ -z "$1" ] && { /bin/echo -e "$Usage"; exit 4; }
-
判定字符串是否为空
image.png
-
- 如果不含输入参量,显示提示信息$Usage 并且推出,显示状态符为 4
solpstop=`climb_and_look_for SOLPSTOP`
[ -s $solpstop ] && {
SOLPSTOP="`cat $solpstop`"
}
# 变量$solpstop 存在,且非空
[ "$SOLPS_DEBUG" = '' ] || {
export EXT_DEBUG=".debug"
}
climb_and_look_for
#! /bin/tcsh -f
###eval '(exit $?0)' && eval 'exec tcsh $0 ${1+"$@"}' && eval 'exec tcsh $0 $argv:q'
###! /bin/tcsh
if ("X$1X" == "X-rX") then
-
判断第一个参数是否为零
image.png
-
https://unix.stackexchange.com/questions/136628/bash-script-x1-x
set REL_FLAG=1
shift
-
shift 对输入参数进行队列推动
image.png
-
else
set REL_FLAG=0
endif
set DIR=$PWD
set REL=""
set target=$1
-
kron shell 赋值
image.png
-
loop:
if(-e $DIR/$target) goto endloop
if ("$DIR" == "/") then
goto endloop
endif
set DIR=`dirname $DIR`
set REL="../"$REL
goto loop
endloop:
- loop:类fortran 循环??
if($REL_FLAG == 0) then
echo $DIR/$target
else
echo $REL$target
endif
-
总体结果
image.png
-
- 判断是否存在输入参数(支持多个输入参数),获得当前路径和输入参数信息;判断输入参数是否在当前路径是否存在;如果存在给出路径;如果不存在给出非法路径
CARRE_PATH=$SOLPSTOP/modules/Carre/builds/$HOST_NAME.$COMPILER$EXT_DEBUG
-
指定carre 的路径
image.png
-
/bin/echo -e "CARRE_PATH : $CARRE_PATH"
[ "$DEVICE" = '' ] && {
print -u2 -n -- "No DEVICE selected. Please provide a device name\n "
read u
export DEVICE=$u
}
- 指定CARRE_PATH和DEVICE路径
[ "$SOLPS_CENTRAL" = 'yes' ] && DEVICE=$DEVICE/$USER
# griddir=${CARRE_GRIDDIR-$SOLPSTOP/src/Sonnet/output/ascii/${Model_Class-iter}}
# griddir=${CARRE_GRIDDIR-$SOLPSTOP/src/Sonnet/output/ascii/${DEVICE-iter}}
export CARRE_TOPDIR=$SOLPSTOP/modules/Carre
- 没找到对应位置,dg是 c写的
dgdir=${CARRE_GRIDDIR-$DG/device/${DEVICE-iter}}
-
dgdir
image.png
image.png
image.png
-
griddir=${CARRE_GRIDDIR-$SOLPSTOP/modules/Carre/meshes/${DEVICE-iter}}
-
carre/mesh信息
image.png
image.png
-
-
2.*.geo
image.png
class=$DEVICE
indir=${CARRE_STOREDIR-.}
stordir=$griddir
[ -n "$CARRE_STOREDIR" ] && stordir="$CARRE_STOREDIR/${DEVICE-iter}"
grid_stem=$class.carre
endings="dgo equ str trg"
/bin/echo -e "Store directory: $stordir"
/bin/echo -e "Grid directory: $griddir"
/bin/echo -e "Input directory: $indir\n"
[ "$1" = '-' ] && {
[ -r $indir/dg.str ] && {
/bin/echo -e "Standard linking - the input files are assumed to exist in \"$indir\""
q=p
qqs=c
grid_stem=`ls -ls $indir/dg.str | awk '{print $NF}' | xargs basename | sed 's:\.str$::'`
} || {
/bin/echo -e "Linking error - the input files were not found in \"$indir\""
# 获取文件名,不包含后缀
-
ls -ls 显示大小信息
image.png
-
/bin/echo -e "Use (I)nput command to provide correct input directory"
q=i
qqs=c
}
} || { \
u="$indir/$1"
[ -r $u.vrq ] && [ -r $u.str ] && [ -r $u.fld ] & { \
ln -sf $u.vrq rzpsi.dat
ln -sf $u.str structure.dat
ln -sf $u.fld btor.dat
ln -sf $u.inp carre.dat
# 创建DEVICE.vrq/str/fld/inp与rzpsi.dat、structure.dat、btor.dat、carre.dat的关系
q=g
qqs=s
} || {
/bin/echo -e "Files $u.vrq, $u.str, and $u.fld must be present!"
exit 8
}
}
while true
do {
/bin/echo -e "Help, Prepare, Grid, Save, Convert, sTore, Next, Remove, Input, Output, Quit ? ($q)\c"
while true; do {
read u
{ case "${u:-$q}" in
# 带默认参量默认值的
( h|H ) # help:
/bin/echo -e "
Prepare (p) apply fcrr to create Carre input files from DG output
fcrr
image.png Grid (g) apply Carre to create a grid
Save (s) save Carre output as the configuration file (carre.dat)
Convert (c) convert the Carre grid to the format suitable for B2 and DG
Store (t) store the B2 grid in the storage directory.
If CARRE_STOREDIR is set, the carre input files are also stored.
Next (n) specify a new stem for the input files.
If \"-\" is specified, then the Carre input files from the input directory
are used. Otherwise, <stem>.vrq, <stem>.str, <stem>.fld, and <stem>.inp
are used as the equilibrium, structures, toroidal field, and configuration
files for Carre.
This must be specified each time when you change the input directory.
Remove (r) remove the specified B2 grid(s) from the storage directory.
The list consists of the grid numbers (with leading zeros) separated by
a white space.
The stored input data (if any) for the specified grids are also removed.
Input (i) specify a new directory for the input files (input directory).
If the specified directory does not exist and the CARRE_STOREDIR is set,
then the input directory is looked for in \$CARRE_STOREDIR/\$DEVICE
and \$CARRE_STOREDIR
Output (o) specify a new storage directory for the grids
Quit (q) quit $script
"; break;;
( p|P )
- p:使用fcrr从DG输出,创建carre输入文件
- g:使用carre创建网格
- s: 保存carre输出作为位型文件(carre.dat)
- c: 将carre网格转化为B2和DG的网格
- t:把B2 格点保存到存储文件夹,如果CARRE_STOREDIR设置了,则carre的输出也被保存
- 为新的输入文件创建一个新的枝干如果指定“-”,则从carre的输入文件获取,否则vrq(rzpsi)、str(structures)、fld()、inp(configuration)
- r: 删除b2网格,列表包含格点数通过白色区域分开
- i: 创建一个新的文件夹,对于输入文件
- o:创建新的输出文件夹
-
退出脚本
image.png
-
https://wiki.jikexueyuan.com/project/13-questions-of-shell/eight.html
# prepare input from DG output:
[ "$DEVICE" = '' ] && { [ -L $indir/dg.trg ] && { \
# [ - L ] 文件是否存在,且是一个连接文件
class=`lln $indir/dg.trg`# 只保留文件路径部分
class=${class%/*} # 只保留最后一个‘/’左侧的部分(右删除)
class=${class##*/} # 保留最后一个‘/’右侧部分(左删除)
} }
lln
#! /usr/bin/env ksh
# VERSION : 11.08.99 14:56
MaxDepth=${MAX_LN_DEPTH:-12}
GREP=grep # /usr/bin/grep
CUT=cut # /usr/bin/cut
LLN="$0"
LS=/bin/ls
pwd=/bin/pwd
# 调用/usr/bin/ 下的工具
Name="${0##*/}"
Usage="
Usage: $Name [<options>] [<list>]
Options:
-h print this screen
-e print the last name in the chain of symbolic links
-m<length> max. length of the chain (default $MaxDepth)
-- end of the options list (allows filenames starting with -)
<list> list of files. If empty, then all the files in the current directory
If no -e option specified, print the filename to which the file is linked symbolically"
unset mode
while true; do {
{ case "$1" in
( -- ) shift; break;;
( -h ) print -- "$Usage"; exit;;
( -e ) mode=${1#-};;
( -m* ) MaxDepth=${1#-m};;
( * ) break;;
esac; }
shift
}; done
[ $# = 0 ] && set \*
{ case "$mode" in
( e ) for f in "$@"; do (
dd=${f%/*}
[ "$dd" = "$f" ] || cd "$dd"
ll=${f##*/}
[ -L "$ll" ] && {
l="$ll"
((i=$MaxDepth+1))
until { ((i=i-1)); [ "$i" = 0 ]; }; do {
l=`lln $l`
l=${l# }
d="${l%/*}"
[ "$l" = "$d" ] &&{
d=
} || {
[ -d "$d" ] && [ -x "$d" ] || {
print -u2 -- "$f : link lost in $d"
l=
break
}
}
[ -L "$l" ] || {
{ case "$l" in
( /* ) ;;
( ./* ) l="$PWD/${l#./}";;
( */* ) ll=`(cd "$d"; $pwd)`
lll="$l" #!!!
l="${ll%/}/${l##*/}"
;;
( * ) ;;
esac; }
break
} && {
l="${l##*/}"
}
[ -n "$d" ] && {
cd "$d" || {
print -u2 -- "$f : link lost in $d"
l=
break
}
}
}; done
}
[ -n "$l" ] && {
[ -L "$l" ] && {
print -u2 -- "$f : link too deep (max. $MaxDepth)"
} || {
print -- "$l"
}
}
); done;;
( * ) for f in "$@"; do {
[ -L "$f" ] && {
l="`$LS -l \"$f\" | $GREP ' ->' | $CUT -f2 -d\>`"
l="${l# }"
[ -n "$l" ] && print -- "$l"
}
}; done;;
esac; }
[ "$class" = 'baserun' ] && {
print -u2 -n -- "No DEVICE selected. Please provide a device name\n "
read u
export DEVICE=$u
class=$DEVICE
}
griddir=${CARRE_GRIDDIR-$SOLPSTOP/modules/Carre/meshes/${DEVICE-iter}}
[ -n "$CARRE_STOREDIR" ] && stordir="$CARRE_STOREDIR/$class"
# [ -n ] 存在
/bin/echo -e "class = $class\ngriddir = $griddir\nindir = $indir\ngrid_stem = $grid_stem"
[ -n $class ] && { # 文件是否存在
[ -r $class.aux ] && ln -sf $class.aux dg.aux
}
rm -f selptx.inf carre.dat structure.dat rzpsi.dat btor.dat 2>/dev/null
# 将中间文件删除,且不显示错误信息
$CARRE_PATH/fcrr.exe; q=g; break;;
调用fcrr (将DG数据转化为carre输出)
image.png program fcrr
c
c version : 05.02.99 13:41
c
c======================================================================
c*** Converts the dg data into the input files for Carre
c======================================================================
c implicit none
c
INTEGER, PARAMETER :: R8 = SELECTED_REAL_KIND (14)
INTEGER, PARAMETER :: R4 = SELECTED_REAL_KIND (6)
INTEGER, PARAMETER :: I4 = SELECTED_INT_KIND (8)
c version : 05.02.99 13:35
c
integer nnstr,nmstr,nsgmx,nrgnx,ntrgx,ngpr,ngpz,nxptm
parameter (nsgmx=6, nrgnx=6, ntrgx=4, nxptm=2)
parameter (ngpr=1025,ngpz=1025, nnstr=60, nmstr=1000)
integer(kind=I4) repart,nrelax,nxpt,
, nsgm,nptseg(nsgmx),nrgn,npr(nrgnx),ntrg,
, nstr,lstr(nnstr),nclstr,
, nr,nz,
, lm_cnfg
logical ldgv2
real(kind=R4) lm_pntrt,lm_grcln
real(kind=R8)
, deltr1(nrgnx),deltrn(nrgnx),deltp1(nsgmx),deltpn(nsgmx),
, xstr(nmstr),ystr(nmstr),xptcntr(3,nxptm),xlpcntr(3),
, rbtor,relax,rlcept,pasmin,xpttol,pntrat,tgarde(ntrgx)
real(kind=R8) pfm(ngpr,ngpz),rgr(ngpr),zgr(ngpz)
common/fcrcom/pfm,rgr,zgr,
, relax,pasmin,rlcept,pntrat,
, deltp1,deltr1,deltpn,deltrn,tgarde,
, xstr,ystr,rbtor,
, xptcntr,xlpcntr,xpttol,
, lm_pntrt,lm_grcln,
i repart,nrelax,nxpt,
, nsgm,nptseg,nrgn,npr,ntrg,
, nstr,lstr,nclstr,nr,nz,
, lm_cnfg,
l ldgv2
c
c*** nnstr : maximum number of structures to be imported from dg
c*** nmstr : maximum number of nodes in all the structures
c*** nsgmx : maximum number of "segments of separatrices" (Carre)
c*** nrgnx : maximum number of "regions" (Carre)
c*** ntrgx : maximum number of "targets" (Carre)
c*** ngpr : maximum number of rows in pfm matrix
c*** ngpz : maximum number of columns in pfm matrix
c*** nxptm : maximum number of pre-defined x-points
c*** nsgm : actual number of "segments of separatrices" (Carre)
c*** nrgn : actual number of "regions" (Carre)
c*** nptseg: number of "grid points" on each "segment of separatrices"
c*** deltp : first and last steps in point distribution on "segment"
c*** npr : number of "flux surfaces" in each "region"
c*** deltr : first and last steps in surface distribution in "region"
c*** ntrg : number of targets
c*** tgarde: guard length in front of targets
c*** nstr : number of the structures imported from dg
c*** lstr : array containing their lengths
c*** nclstr: number of closed structures (they come first)
c*** xstr,
c*** ystr : coordinates of the structure nodes
c*** rbtor : product of the major radius by the toroidal field
c*** pfm : poloidal magnetic flux table
c*** rgr : R values for pfm
c*** zgr : Z values for pfm
c*** nr : actual number of rows in pfm matrix
c*** nz : actual number of columns in pfm matrix
c*** repart,
c*** nrelax,
c*** relax,
c*** pasmin,
c*** rlcept,
c*** pntrat : scalar parameters for Carre
c*** nxpt : actual number of pre-defined x-points
c*** xptcntr: coordinates of the x-points
c*** xlpcntr: coordinates of the o-point
c*** xpttol : tolerance parameter for distinguishing the x-points
c*** ldgv2 : true if the input from DG v.2.0 or later
c version : 11.11.80
real(kind=R8) finish,promp(2)
logical immed,fixkey
common/impcon/finish,promp,jmess,mimp,mess,
, keylen,lfin,lena,mfrm,immed,fixkey
logical ex
character*14 chtrg,chstr,chequ,chaux,chdgo,
, chcfld,chcequ,chcstr,chccrr,chcslp
data chtrg , chstr , chequ , chaux , chdgo /
/ 'dg.trg','dg.str','dg.equ','dg.aux','dg.dgo'/,
, chcfld , chcequ , chcstr , chccrr /
/ 'btor.dat' ,'rzpsi.dat','structure.dat','carre.dat'/,
, chcslp /
/ 'selptx.inf'/
external fcraxn,fcrtrn,fcrdgi
c======================================================================
c
inquire(file=chtrg,exist=ex)
if(.not.ex) then
write(*,*) 'fcrr: the file ',chtrg,' must be present!'
end if
inquire(file=chstr,exist=ex)
if(.not.ex) then
write(*,*) 'fcrr: the file ',chstr,' must be present!'
end if
inquire(file=chequ,exist=ex)
if(.not.ex) then
write(*,*) 'fcrr: the file ',chequ,' must be present!'
end if
c
immed=.false.
keylen=8
mimp=1
lena=8
c
c*** Read the data
c
open(1,file=chtrg)
call fcrchktp(1)
call import(fcrtrn)
close(1)
open(1,file=chstr)
call fcrstri(1)
close(1)
open(1,file=chdgo)
call import(fcrdgi)
close(1)
open(1,file=chequ)
call fcrfldi(1)
close(1)
inquire(file=chaux,exist=ex)
if(ex) then
open(1,file=chaux)
call import(fcraxn)
close(1)
end if
c
c*** ... make the necessary transformations
c
call fcrprp
c
c*** ... and produce the files to be read by carre
c
call fcrequo(chcequ)
call fcrstro(chcstr)
call fcrcrro(chccrr)
call fcrfldo(chcfld)
call fcrslpo(chcslp)
c======================================================================
end
( g|G ) # create the grid:
# carre.exe; q=s; break;;
$CARRE_PATH/carre.exe 2>carre.log; q=$qqs; break;;
carre
PROGRAM CARRE
c======================================================================
c
c version : 1.01.99 15:49
c
c======================================================================
cank -- The comments are translated from French, sorry for errors!
*.. Ce programme permet de trouver la localisation des points X
* pour un tokamak. Il parametrise ensuite les separatrices qui passent
* par ces points X et il les trace ainsi que les structures reelles.
* Une maille curviligne orthogonale alignee sur les surfaces de flux
* est alors construite.
c*** This program builds an orthogonal curvilinear mesh aligned to the
c*** flux surfaces. It finds the localisation of the X-points,
c*** parametrises the separatrices passing through them, and traces
c*** them together with the real structures.
c======================================================================
IMPLICIT NONE
c a modifier pour generaliser la geometrie:
c modifier argsep et maille pour utiliser un critere plus general que
c la droite ou la gauche dans la designation des separatrices.
c Aussi, distribuer les points de facon proportionelle, et les ortho-
c gonaliser par relaxation, avec une protection de proximite.
c a faire:
c 1. permettre l'imposition de points fixes ou de coins
* variables.
cank-970702: moved dimensions to the CARREDIM.F
c
INTEGER, PARAMETER :: R8 = SELECTED_REAL_KIND (14)
INTEGER, PARAMETER :: R4 = SELECTED_REAL_KIND (6)
INTEGER, PARAMETER :: I4 = SELECTED_INT_KIND (8)
c version : 07.07.97 20:52
c
integer nxmax, nymax , npstmx, npnimx, npxmx , strumx, nivmx,
. nbdmx, gradmx, npmamx, nrmamx, nregmx
parameter (nxmax=1025, nymax=1025, npstmx=360, npnimx=5000,
. npxmx=4 , strumx=60 , nivmx=8 , nbdmx=8 ,
. gradmx=100, npmamx=500 , nrmamx=200, nregmx=6)
c
c======================================================================
c*** gradmx : max. number of points with zero gradients (x/o)
c*** nxmax, nymax: max. grid dimensions for equilibrium data (psi)
c*** npstmx : max. number of points in a structure
c*** strumx : max. number of structures
c*** npxmx : max. number of the x-points to be treated
c*** nivmx : max. number of the level lines
c*** npmamx : max. number of the poloidal mesh points
c*** nrmamx : max. number of the radial mesh points
c*** nregmx : max. number of regions
c*** npnimx : max. number of points in tracing curves
c*** nbdmx : max. number of divertor plate structures
c***
c======================================================================
c version : 03.04.97 19:58
c
character sellan*20
common/comlan/sellan
character*33 ::
. git_version_Carre = '3.0.7'
REAL(kind=R8) cstlin,zero,eps_Xpt,rmax,zmax
common /geom/ eps_Xpt
PARAMETER (cstlin=0.00, zero=0.)
INTEGER i, j, nx, ny, nstruc, npstru(strumx),
. ii(gradmx), jj(gradmx), iptx(npxmx), jptx(npxmx),
. npx, npxtot,ptsep(4,npxmx),
. nptot(4,npxmx), indplq(4,npxmx),inddef(nbdmx),
. nbdef, nivtot(nivmx), nbniv,ptxint,nreg,
. np1(nregmx), npr(nregmx), ierror,iflag,limcfg,
. itmp,ireg,
. modif,nprsb(nregmx)
REAL(kind=R8) x(nxmax), y(nymax), psi(nxmax,nymax),
. psidx(nxmax,nymax), psidy(nxmax,nymax),
. xstruc(npstmx,strumx), ystruc(npstmx,strumx),
. pointx(gradmx), pointy(gradmx),
. ptx(npxmx), pty(npxmx), xpto, ypto, fctpx(npxmx),
. separx(npnimx,4,npxmx), separy(npnimx,4,npxmx),
. nivx(npnimx,nivmx),nivy(npnimx,nivmx),distnv(5,nivmx),
. xn(npnimx),yn(npnimx),xmail(npmamx,nrmamx,nregmx),
. ymail(npmamx,nrmamx,nregmx),a00(nxmax,nymax,3),
. a10(nxmax,nymax,3),a01(nxmax,nymax,3),a11(nxmax,nymax,3),
. pntrat,distxo,gdpsi(nrmamx,nregmx),racpsi(nrmamx,nregmx),
. a(nregmx),
. gdr(nrmamx,nregmx),
. r(nrmamx,nregmx),ra(nrmamx,nregmx),rho(nrmamx,nregmx),
. somort(nrmamx,nregmx),somortp(nrmamx,nregmx),
. gdsomortp(nregmx),xmini,
. xmaxi,ymini,ymaxi,somortpur(nrmamx,nregmx),
. somortpurp(nrmamx,nregmx),gdsomortpurp(nregmx),
. sompropo(nrmamx,nregmx),sompropop(nrmamx,nregmx),
. gdsompropop(nregmx),
. somvarr(nrmamx,nregmx),somvarrp(nrmamx,nregmx),
. gdsomvarrp(nregmx),
. somtot(nrmamx,nregmx),somtotp(nrmamx,nregmx),
. gdsomtotp(nregmx),segt(nrmamx,nregmx),
. tgarde(4)
LOGICAL racord
character lign80*80,nomstr(strumx)*80
REAL(kind=R8) stp0, stpmin
PARAMETER (stpmin=0.0001_R8)
*..Procedures
*
INTRINSIC MIN,index
EXTERNAL pltini,pltend,cadre,motifs,DERIVE,cntour,GRAD0,
. SELPTX,SPTRIS,ARGSEP,FRTIER,MAILLE,trace,trace2,entete
, ,trc_stk_in,trc_stk_out
c======================================================================
c.. nxmax,nymax: maximum number of the data points in x and y
c.. gradmx: maximum number of points where the gradient vanishes
c.. npxmx : maximum number of the X-points
c.. nbdmx : maximum number of structures being the divertor targets
c.. strumx: maximum number of structures
c.. npstmx: maximum number of points per structure
c.. npnimx: maximum number of tracing points on a curve
c.. nivmx : maximum number of limiting level lines
c.. npmamx: maximum number of grid points in poloidal direction
c.. nrmamx: maximum number of grid points in radial direction
c.. nregmx: maximum number of regions
c.. cstlin: a linear constant added along y to artificially disconnect
c the X-points. Set to 0 for connected double-nulls
c
c.. nx,ny : number of data points in x and y
c.. x,y : tables of coordinates of the data points
c.. psi : psi values at each data point
c.. psidx,psidy: values of psi derivatives in x and y
c at each data point
c.. nstruc: number of structures
c.. npstru: number of points per structure
c.. xstruc,ystruc: coordinates of the structure points
c (point index, structure index)
c.. npxtot: number of the points where the gradient vanishes
c.. pointx,pointy: coordinates of the points where the gradient
c vanishes
c.. ii,jj : x and y indices of the cells where the gradient vanishes
c.. npx : number of the X-points
c.. ptx,pty: X-point coordinates
c.. iptx,jptx: x and y indices of the cells containing the X-points
c.. xpto,ypto: coordinates of the O-point
c.. racord: determines whether the X-points are connected
c.. fctpx: the psi values at each X- or O-point
c.. separx,separy: coordinates of the points of the parametrised
c separatrices (point index, branch index, X-point index)
c.. nptot : number of parametrisation points for each separatrix
c (separatrix index, point index)
c.. ptsep : separatrix pointer, used as index
c (separatrix index, point index)
c.. ptxint: index of the internal X-point in the case of disconnected
c double-null
c.. nbdef : number of the divertor plates
c.. inddef: table of indices of the divertor plates
c.. indplq: table of the structure indices (0 means not a target)
c (separatrix index, X-point index)
c.. nbniv : number of the limiting level lines
c.. nivx,nivy: coordinates of the points of the parametrised
c limiting level lines (point index, curve index)
c.. nivtot: number of points for each parametrised limiting level line
c.. distnv: distance along a plate between the separatrix strike-point
c and a limiting level line
c (distance selector [1=real, 2=psi], curve index)
c.. nreg : number of the grid regions depending on the configuration
c.. np1 : numbers of the grid points in poloidal direction
c (region index)
c.. npr : numbers of the grid points in radial direction
c (region index)
c.. xmail,ymail: grid point coordinates
c (poloidal, radial, region)
c.. xn,yn : working array for coordinates along a parametrised curve
c.. nrelax: maximum number of iterations in the relaxation procedure
c of construction of the orthogonal grid
c.. relax : relaxation parameter
c.. stpmin: minimum tolerable distance between any two grid points
c in the course of relaxation
c.. rlcept: convergence criterion in the relaxation procedure
c.. limcfg: indicates when a limiter configuration is considered (when
c nonzero). This variable is assigned the index of the
c limiter
c N.B.: When the limiter configuration is selected, npx is set equal
c to 1 and the coordinates of the X-point correspond to the
c innermost point of the limiter.
c MAJOR AND MINOR RADIUS
c gdr: major radius (intersection of the poloidal surfaces with
c the outer midplane)
c r: minor radius
c a: minor radius for the separatrix
c ra: difference between the separatrix minor radius and the minor
c radius of a level line
c rho: ratio between the minor radius of the separatrix and the
c minor radius of a level line
c sensspe: direction corresponding to the fictitious plate used for
c computing the radii.
c
C GLOBAL MESH QUALITY
* the following variables allow for quantification of the mesh quality (mailrg)
c somort: (sum of the orthogonality criteria from ort1) value which takes
c into account the local mesh orthogonality, the spacing and size
c of consecutive cells as well as the poloidal distribution of
c points (nppol) between a level line and the previous level line
c somortp: (advanced sum of the orthogonality criteria) value which
c corresponds to somort at the end of the iterations when using ort2,
c divided by nppol.
* the iterations work correctly even with the second level line thus not only
* the instruction works because the function approaches zero but it also is not
* causing the zig-zag deformation
* (in any case, if this were the case, one would systematically see it so it is
* more the geometry, the geography as well as the length of the plates and the
* level lines become the main suspects)
c gdsomortp: (large advanced sum of orthogonalities) this value corresponds
c to the set of somortp values on a single level line, divided by
c nppol (the goal is to have a quality index for the region)
* gdsomortp does not have much meaning and can be misleading about the quality
* of the level line. It can be used to compare the influence of each component
* of the ort function.
C INFLUENCE OF THE TRUE ORTHOGONALITY ON CLORT
c ortpur: (pure orthogonality) this value only takes into account the orthogonality criterion
* ortpur can take values a million times larger that the sum of all three
* criteria so there must be some attenuation in the calculation of ort.
c propo: (proportionality) this value only takes into account the proportionality criterion
c varr: (variance) this value only takes into account the criterion for the
c variation in cell length for groups of three contiguous mesh cells on
c the same level line
c tot: (total) corresponds to the sum of ortpur, propo and varr.
c We only check that tot = ort
c somortpur, sompropo, somvarr, somtot: correspond to the sums of ortpur,
c propo, varr and tot along a level line during the first displacement of
c the nodes.
c somortpurp, sompropop, somvarrp, somtotp: correspond to the sums of
c ortpur, propo, varr and tot along a level line after the iterations.
c gdsomortpurp, gdsompropop, gdsomvarr, gdsomtotp: correspond to the sum,
c over all level lines of the same region, of somortpur, sompropo, somvarr
c and somtotpt.
C CORRECTION OF THE DEFORMATIONS
c segt: (segment) this variable is meant for automatic following
c of the magnification
c it corresponds to the total length along the level line (l(nppol))
c modif: interruptor for jumping the step of modifying the node
c displacements (user choice)
c rr : answer to the redefinition (if choix = 1)
c pra : first answer
c sra: second answer
c tra: third answer
c the third letter indicates the position of the segment: a first, b second,
c c third, ...
c coefa,coefb,...: iteration coefficient to multiply a segment
c of length ipol(1)-ipol(2) by a value usually between 1 and 1.03
c (user choice)
c choix: choice from the user for the correction of deformations
c =1 if all points are displaced simultaneously
c =2 if points are displaced by fragmentation,
c =3 if the coefficients are those entered in the program,
c =4 if points are displace by fragmentation with magnification
c deci: decision from the user
c AUTOMATIC MAGNIFICATION
c lsp : length of the perfect segment. corresponds to the size and part
c of the level line fragment that is to be represented in the zoom, it
c serves as a reference in the computation instructions.
c ls : length of the segment. corresponds to the size of the level line
c segment for each computed nppol index.
c idep: starting point
c iarr: arrival point
c tpr : temporary value. keeps the arrival point value from the previous
c segment to make it the starting point for the next segment.
c deltay: difference between ymaxi and ymini
c deltax: difference between xmaxi and xmini
c deldelta(x or y): difference between the two delta values
c disdelta(x or y): dispersion of delta, corresponds to the magnification
c of the sides on the smallest axis
c rpt(ratio): number of points in the separatrix segment (=npimx)
c rptd(ratio by two): first half of the points from the separatrix segment
c rptt(ratio by three): first third of the points from the separatrix segment
c rptq: first quarter of the points from the separatrix segment
c======================================================================
*
*..1.0 Initialisation des variables par defaut et de la bibliotheque
* graphique
*
call defaut
CALL pltini
CALL cadre
CALL motifs
*
*..2.0 Open the data files
*
OPEN(UNIT=7, FILE='rzpsi.dat', STATUS='old')
OPEN(UNIT=8, FILE='structure.dat', STATUS='old')
OPEN(UNIT=9, FILE='carre.dat', STATUS='unknown')
OPEN(UNIT=10,FILE='carre.out',STATUS='unknown')
open(unit=11,status='scratch')
c
c 2.1 specify output format
write(10,*)'output format: carre70; version : ', git_version_Carre
*
*..3.0 Read the data
101 CONTINUE
*..Read the values of x
100 format(a)
iflag=-1
rewind(7)
rewind(8)
rewind(9)
rewind(10)
call entete(7,'$r',iflag)
read(7,100)lign80
i=index(lign80,'=')
call rdfrin(11,lign80(i+1:80),nx,ierror)
READ(7,*) (x(i), i=1, nx)
*..Read the values of y
call entete(7,'$z',iflag)
read(7,100)lign80
i=index(lign80,'=')
call rdfrin(11,lign80(i+1:80),ny,ierror)
READ(7,*) (y(i), i=1, ny)
stp0 = min(max(abs(x(nx)-x(1))/1000.,
, abs(y(ny)-y(1))/1000.,10.*stpmin),100.*stpmin)
rmax = 0.0
do i = 1, nx-1
rmax = max(rmax, (x(i+1)-x(i))**2)
enddo
zmax = 0.0
do i = 1, ny-1
zmax = max(zmax, (y(i+1)-y(i))**2)
enddo
eps_Xpt = sqrt(rmax+zmax)
*..Read the values of psi
call entete(7,'$psi',iflag)
READ(7,*) ((psi(i,j), i=1, nx), j=1, ny)
DO 5 j=1,ny
DO 4 i=1,nx
psi(i,j) = psi(i,j) + MIN(cstlin*(y(j)-y(ny/2)),zero)
4 CONTINUE
5 CONTINUE
c---
c ceci sert a modifier la symetrie haut-bas de psi, de facon ad hoc.
c write(6,*)'facteur de symetrie haut-bas'
c read(5,*)a00(1,1,1)
c do j=1,ny/2
c do i=1,nx
c xpto=psi(i,j)
c ypto=psi(i,ny-j+1)
c psi(i,j)=0.5*((1.+a00(1,1,1))*xpto+(1.-a00(1,1,1))*ypto)
c psi(i,ny-j+1)=0.5*((1.+a00(1,1,1))*ypto+(1.-a00(1,1,1))*xpto)
c enddo
c enddo
c---
close(unit=7)
*
*..3.1 Read the structures.
nstruc=0
call listru(8,nstruc,npstru,nomstr,xstruc,ystruc,npstmx,strumx)
*
*..4.0 Calculate the first partial derivatives in x and y and store
* them in arrays psidx and psidy
CALL DERIVE(nx,ny,x,y,psi,psidx,psidy)
*
*..5.0 Plot the level lines for psidx=0 and psidy=0
*
CALL cntour(psidx,psidy,nx,ny,x(1),x(nx),y(1),y(ny))
c
c interpolation coefficients for psi and its derivatives
call inipsi(psi,psidx,psidy,x,y,nxmax,nymax,nx,ny,a00,a10,a01,a11)
*
*..6.0 Determine the points where the derivatives in x and y vanish
*
CALL GRAD0(nxmax,nymax,nx,ny,x,y,gradmx,pointx,
. pointy,ii,jj,npxtot,a00,a10,a01,a11)
*
*..7.0 Select the X-points of interest
*
cank-970702: moved dimensions to the included file
CALL SELPTX(npxtot,npx,pointx,pointy,ii,jj,ptx,
. pty,iptx,jptx,xpto,ypto,racord,limcfg)
*
*..8.0 Parametrise the separatrices
*
IF (npx.GT.0 .and. limcfg.eq.0) THEN
c
CALL SPTRIS(nx,ny,x,y,psi,npx,ptx,pty,
. iptx,jptx,fctpx,separx,separy,nptot,
. nstruc,npstru,xstruc,ystruc,indplq,inddef,nbdef,
. a00,a10,a01,a11)
*
*..9.0 Arrange the separatrices
*
CALL ARGSEP(npx,ptx,pty,fctpx,separx,separy,indplq,nptot,npnimx,
. ptsep,racord,ptxint,ypto,nbdef,inddef)
ELSEIF(LIMCFG.NE.0) THEN
*
* 13. Identify the limiter
*
call limfnd(xpto,ypto,nivx,nivy,stp0,stpmin,distnv,nivtot,
. nbniv,nx,ny,x,y,psi,npx,ptx,pty,fctpx,
. nstruc,npstru,xstruc,ystruc,indplq,inddef,nbdef,
. a00,a10,a01,a11)
do itmp=1,4
ptsep(itmp,1) = 0
enddo
ENDIF
if(npx.gt.0) then
*
*..10.0 Find the level lines in more detail
*
c<<<
write(0,*) '=== carre *..10.0 - before frtier'
write(0,'(a5,1p,8e12.4)') ' ptx:',ptx(1:npx)
write(0,'(a5,1p,8e12.4)') ' pty:',pty(1:npx)
if(limcfg.eq.0) then
write(0,*) 'nptot(4,nxpoints)'
write(0,'(1x,16i5)') ((nptot(i,j),i=1,4),j=1,npx)
write(0,*) 'Strike points (presumably)'
write(0,'(a3,1p,8e12.4)') ' x:',
- ((separx(nptot(i,j),i,j),i=1,4),j=1,npx)
write(0,'(a3,1p,8e12.4)') ' y:',
- ((separy(nptot(i,j),i,j),i=1,4),j=1,npx)
c>>>
call trc_stk_in('carre','*..10.0')
CALL FRTIER(nx,ny,x,y,psi,nstruc,
. npstru,xstruc,ystruc,inddef,nbdef,npx,separx,
. separy,nptot,ptsep,racord,nivx,nivy,nivtot,
. nbniv,stp0,stpmin,
. distnv,ptxint,a00,a10,a01,a11)
call trc_stk_out
endif
call trace2(x(1),x(nx),y(1),y(ny),separx,separy,
_ ptsep,npx,nptot,
_ nstruc,npstru,xstruc,ystruc,
_ nivx,nivy,nivtot,nbniv)
*
*..11.0 Grid the regions
*
modif=0
CALL MAILLE(nx,ny,x,y,psi,npx,xpto,ypto,racord,
. separx,separy,ptsep,nptot,distnv,ptxint,nstruc,npstru,
. xstruc,ystruc,inddef,nreg,xn,yn,xmail,ymail,
. np1,npr,ptx,pty,nivx,nivy,nivtot,nbniv,
. a00,a10,a01,a11,fctpx,limcfg,gdpsi,racpsi,
. a,gdr,r,ra,rho,somort,somortp,
. gdsomortp,somortpur,somortpurp,gdsomortpurp,
. sompropo,
. sompropop,gdsompropop,somvarr,somvarrp,gdsomvarrp,
. somtot,somtotp,gdsomtotp,segt,ireg,modif,xmini,xmaxi,
. ymini,ymaxi,distxo,pntrat,nprsb,tgarde)
c*
c* WARNINGS CALCULATION AND OUTPUT
c*
c if (npx.EQ.1) CALL WARNINGS(separx,separy,nivx,nivy,
c & distnv(1,2),xpto,ypto)
*
*..12.0 Plot the structures, the separatrices, and the limiting level
* lines for each region, together with the resulting grid
*
if (modif.eq.0) call endpag
call trace(x(1),x(nx),y(1),y(ny),separx,separy,ptsep,npx,nptot,
. nstruc,npstru,xstruc,ystruc,nivx,nivy,nivtot,nbniv,
. np1,npr,xmail,ymail,nreg,.false.)
call endpag
ENDIF
*
*.. Close the graphics
*
111 CALL pltend
STOP
END
end carre
( s|S ) # save the control data:
cp carre.out carre.dat;
/bin/echo -e "Saved grid settings in carre.dat file"
q=c; break;;
## 保存carre.dat
( c|C ) # convert:
/bin/echo -e "carre.out\n4" | $CARRE_PATH/traduit.exe 2>traduit.log; mv traduit.out traduit.sno ;
/bin/echo -e "carre.out\n2" | $CARRE_PATH/traduit.exe 2>traduit.log;
q=t; break;;
#
( t|T ) # store the grid:
[ -r traduit.out ] && {
[ -d "$griddir" ] || {
/bin/echo -e "The directory \"$griddir\" does not exist. Create it (y/n)? \c"
read u; case "$u" in
( y|Y ) /bin/echo -e mkdir "$griddir"
mkdir -p "$griddir" || break;; # mkdir -p 递归创建目录,携家带口
( * ) /bin/echo -e break
break;;
esac
}
/bin/echo -e dir OK
typeset -i n
n=1
set -- $griddir/$grid_stem.v[0-9][0-9][0-9].geo
[ -f $1 ] && {
m=`ls $griddir/$grid_stem.v[0-9][0-9][0-9].geo | tail -1`
# m=`echo $griddir/$grid_stem.v[0-9][0-9][0-9].geo | awk '{print $NF}'`
m=${m#*/$grid_stem.v}
m=${m%.geo}
/bin/echo -e "Last grid number found is : $m"
n=`echo $m | sed -r -e 's:^0{1,}::'`
n=n+1
m=$n
} || {
m=1
}
[ ${#m} -lt 2 ] && m=00$m || {
[ ${#m} -lt 3 ] && m=0$m
}
touch CARRE.HISTORY
echo $user `date +%Y-%m-%d_%H:%M:%S` >> CARRE.HISTORY
ls -ls dg.??? | cut -d ' ' -f 9- >> CARRE.HISTORY
mv -f traduit.sno $dgdir/$grid_stem.v$m.sno && \
/bin/echo -e "The grid in DG format is stored as $dgdir/$grid_stem.v$m.sno"
for ext in $endings; do
filename=`lln dg.$ext`
cp $filename $dgdir/`basename $filename`
/bin/echo -e "dg.$ext copied to $dgdir" && \
/bin/echo -e "dg.$ext copied to $dgdir" >> CARRE.HISTORY
done
modelname=`echo $filename | sed -e 's\trg\dg\' `
cp $modelname $dgdir/`basename $modelname`
/bin/echo -e "DG model `basename $modelname` copied to $dgdir" && \
/bin/echo -e "DG model `basename $modelname` copied to $dgdir" >> CARRE.HISTORY
mv -f traduit.out $griddir/$grid_stem.v$m.geo && \
/bin/echo -e "The grid in B2.5 format is stored as $griddir/$grid_stem.v$m.geo"
[ -x ctrans ] && {
ctrans -d ps.mono gmeta > $griddir/$grid_stem.v$m.ps && \
/bin/echo -e "You can view the grid in PostScript format as $griddir/$grid_stem.v$m.ps"
}
/bin/echo -e "The grid is stored as $griddir/$grid_stem.v$m".geo >> CARRE.HISTORY
[ -n "$stordir" ] && {
[ -d "$stordir" ] || {
[ -a "$stordir" ] && {
/bin/echo -e "Name collision: there is already a file named $stordir"
/bin/echo -e " ==> the directory cannot be created"
} || {
/bin/echo -e "The directory \"$stordir\" does not exist. Create it (y/n)? \c"
read u; case "$u" in
( y|Y ) /bin/echo -e mkdir "$stordir"
mkdir -p "$stordir";;
( * ) ;;
esac
}
}
[ -d "$stordir" ] && {
s="$stordir/$grid_stem.v$m"
u=y
[ -d "$s" ] && {
/bin/echo -e "The directory \"$s\" already exists. Use it (y/n)? \c"
read u; case "$u" in
( y|Y ) ;;
( * ) u=;;
esac
}
[ -n "$u" ] && {
[ -d "$s" ] || mkdir -p "$s"
cp carre.dat structure.dat rzpsi.dat btor.dat "$s" && \
/bin/echo -e "carre.dat, structure.dat, rzpsi.dat, and btor.dat copied to $s" && \
/bin/echo -e "carre.dat, structure.dat, rzpsi.dat, and btor.dat copied to $s" >> CARRE.HISTORY
}
}
}
q=q; true
} || { /bin/echo -e "No traduit.out. Convert the grid first."; q=c; }
echo "=======================================================================================" >> CARRE.HISTORY
break;;
( n|N ) # next job:
/bin/echo -e "Input the new stem: \c"; read u
[ -n "$u" ] && {
[ "$u" = '-' ] && {
[ -r $indir/rzpsi.dat ] && [ -r $indir/structure.dat ] && [ -r $indir/btor.dat ] && {
ln -sf $indir/rzpsi.dat $indir/structure.dat $indir/btor.dat . && q=g
[ -r $indir/carre.dat ] && {
ln -sf $indir/carre.dat .
true
} || {
rm -f carre.dat 2>/dev/null
true
}
} || {
print -- "If you specify \"-\" as the stem, the following files must be present in the input directory:"
print -- " rzpsi.dat structure.dat btor.dat"
}
} || {
u="$indir/$u"
[ -r $u.vrq ] && [ -r $u.str ] && [ -r $u.fld ] & {
ln -sf $u.vrq rzpsi.dat
ln -sf $u.str structure.dat
ln -sf $u.fld btor.dat
ln -sf $u.inp carre.dat
q=g
true
} || {
/bin/echo -e "Files $u.vrq, $u.str, and $u.fld must be present in the input directory"
}
}
}; break;;
( r|R ) # remove the grid(s):
/bin/echo -e "Input the list of grid numbers to be REMOVED:"; read u
[ -n "$u" ] && {
uu=
vv=
ww=
for n in $u; do
uu="$uu $griddir/$grid_stem.v$n.geo"
vv="$vv $griddir/$grid_stem.v$n.ps"
ww="$ww $dgdir/$grid_stem.v$n.sno"
done
ls -l $uu $vv $ww
/bin/echo -e "Do you wish to remove this grid(s)? (y/n): \c"; read u
case "$u" in
( y|Y ) rm -f $uu $vv $ww
for f in $uu; do {
n=${f#$griddir/$grid_stem.v}
n=${n%.geo}
[ -d "$stordir/$grid_stem.v$n" ] && rm -r "$stordir/$grid_stem.v$n"
}; done ;;
( * ) ;;
esac
}; break;;
( i|I ) # input files:
/bin/echo -e "Specify the new input directory: \c"; read u
[ -n "$u" ] && {
indir="$u"; /bin/echo -e "$indir"
[ -d $u ] && {
indir="$u"
} || {
[ -n "$stordir" ] && {
indir="$stordir/$u"
[ -d "$indir" ] || {
indir="$CARRE_STOREDIR/$u"
[ -d "$indir" ] || indir=
}
}
}
[ -n "$indir" ] && {
/bin/echo -e "The input directory is now `(cd $indir && pwd)`"; q=n; true
[ -r $u/dg.str ] && {
grid_stem=`ls -ls $u/dg.str | awk '{print $NF}' | xargs basename | sed 's:\.str$::'`
q=p
} || {
/bin/echo -e "Cannot find dg.str file in $u"
q=i
}
} || {
/bin/echo -e "Cannot find directory: $u"; q=i
}
}; break;;
( o|O ) # output directory:
/bin/echo -e "Specify the new grid directory: \c"; read u
[ -n "$u" ] && {
[ -d $u ] && {
griddir="$u"; /bin/echo -e "The grid directory is now $griddir"; q=t
} || {
/bin/echo -e "No such directory: $u\nCreate it? (y/n) \c"; read uu
case "$uu" in
( y|Y ) s=$u; ss=$u
while true; do
case "$s" in
( */* ) w="${s%/*}"
[ -z "$w" ] && {
/bin/echo -e "Wrong directory specification: no $s"
q=o; break 2
}; s="$w"
[ -d "$s" ] && break
ss="$s $ss";;
( * ) break;;
esac
done
/bin/echo -e "Creating $ss"
mkdir -p $ss && {
griddir="$u"; q=t
/bin/echo -e "The grid directory is now $griddir"
} || {
/bin/echo -e "Unable to create $u"; q=o
/bin/echo -e "The grid directory is still $griddir"
};;
( * ) ;;
esac
}
}; break;;
( q|Q ) # quit:
break 2;;
( * )
/bin/echo -e 'Illegal response.'
/bin/echo -e 'Please use letters capitalized in the list or press ENTER for default'
continue;;
esac;}
}; done
}; done
stty sane
网友评论