From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 12871 invoked from network); 2 Jun 2021 17:24:09 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 2 Jun 2021 17:24:09 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1622654649; b=0WzMW7aJ8hZnxldnSvAAbR+K2U5XCGZrzYzZNj9fKojcZkWMj06gOYdTTXQ3+uFeO9OCeXAedB I1bHgLUj0hjm7PWvcwAM2AEyFrH51sEQmhG8MtUPuwM2Z2GSOsp/z7swoxTpEpMaBywmpmugBs SSz7/EhNDfcw83YQS+76XfgwjEhRERj64w1Pg1fkPkJclq+89m16jhRQ6ribR19fGZVJ4PeJ6f 73xI0kLXkBMzaJfI0NreLFC7DGmCypPejDjRquyEyL0iGnyMhkfrhQkq7tCjI/d+0zKR/F+WWe JTWo9srffLaW5QECkH5gkZdrgsC3qcxpdxhF9dVFeP5L+w==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (esa07.ucs.mun.ca) smtp.remote-ip=134.153.136.27; dmarc=none header.from=mun.ca; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1622654649; bh=HqZ9VO4D7mpSQTJOZzpAEKgxF2KgVl43v2CktUMaAUs=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:MIME-Version:Message-ID:Date:In-Reply-To: Subject:To:From:References:DKIM-Signature; b=BqqNkR5OZIHljx8Q/kxMcWAXDiYfX4m6xaP7ksVMNEN6NbzwgLds1M6uFQGJs1h7nb/O6062Sj 2c/g82HMb2z0/88guey6KGe/zywOIInAZPhMcDhJmhMx5mtO4BSqo56fYNtO8BHIy1PuLPAgie WmZZLgi5CQO58JBkjxk3yKWnj/eM43iaV4+GCrLXNPai6093K3276w8DzaSfsuCHc+8pNWT9Ds NkRB6EBvrItRfTTCZ6y0SWNTW/dFHfXRSFjsY1bojkCHiiGzqk7PNKb4E5Bf3YhLQ9wibfi9cl WQ9QYmIbXmU159Dx6ysEFRAmUMXaNcR779r0AgmFk+J7DA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:MIME-Version:Message-ID: Date:In-reply-to:Subject:To:From:References:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=N+EAJLTn1lcUxYb4kK3kZty+FZwIiyyYgkzaWMVsY5s=; b=tTC3I8Fl3ur4NJtmKKQlnZ5f/x d66Ioc0OhB10GO8LinST46RC8p7o0seqvSW53/V6nGz6B6V6P0mh0o4X+zK94S/zbB8O7Lk2hU+hk /qKPWHjTHvHONq1owTrOiX7Z8t9Rs3280MhfHH9g2xk1ZM0cKWTO8hCugGITfhXL7S7IwB18bVsL8 wm/tsAExGfktkziP+b9zxSrukC7pUy0Z4Hpej+CuSkXVxNC7Z5rVPCP4Avuy7T7y3Vrr4T8gFDo0D lfe++E71fK7Yt/F4Cn6VGA7ToxR3ZESnPXhlAhEXkSLpTbhnCLW04/W19hKAnDzgP1c+XU0F+Pkwz EeExEVhA==; Received: from authenticated user by zero.zsh.org with local id 1loUbA-0002w4-Ia; Wed, 02 Jun 2021 17:24:08 +0000 Authentication-Results: zsh.org; iprev=pass (esa07.ucs.mun.ca) smtp.remote-ip=134.153.136.27; dmarc=none header.from=mun.ca; arc=none Received: from esa07.ucs.mun.ca ([134.153.136.27]:41957) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1loUab-0002Dm-Th; Wed, 02 Jun 2021 17:23:35 +0000 IronPort-SDR: X4wqiRxOBYfNM9ojzRzVf8/gMWHbFAyp7Abeht8GWeHjn4EEPI7yDzsnZA54VNBxIC9h0LqAGI mFdRv0lKjAuawTce0kfx11Ebu/rsIvBnaNrBASEUWmouT5AFQfZLkze0bV7g/eeMrJd42f2X3A y0FuH43bghag5Q4L+ekncMp3gJHyue1ZowNEHHK6lV03LiCNA/yNaC512qr9gG+pkc5seo+VJ3 XcvRiLhHzumQke5XE1P/F6fSNBmBzAeONa/amI8gwSFUlZ9Ko7xOHiO0RZUmsn+j1xXUs6oCDZ pU0= IronPort-HdrOrdr: =?us-ascii?q?A9a23=3AHeW0Yayq0aYP8MZ6B/pNKrPwKL1zdoMgy1?= =?us-ascii?q?knxilNoH1uA66lfq+V/cjzuSWYtB8wXzU6lcmEKO2cRxrnm6KdgrNhXotKPj?= =?us-ascii?q?OHhILAFugL0WKh+Vbd8kbFmdK1u50NT4FDEtHqSVB1gcHmiTPTL+od?= X-IronPort-AV: E=Sophos;i="5.83,242,1616466600"; d="scan'208";a="57700891" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from cpe00fc8db7a323-cm00fc8db7a320.cpe.net.cable.rogers.com (HELO pyrope.local) ([174.117.202.255]) by smtp07.ucs.mun.ca with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2021 14:53:29 -0330 References: <20210602170052.jsrzn5374lxpxmwg@chazelas.org> User-agent: mu4e 1.5.6; emacs 27.2 From: Roger Mason To: zsh-users@zsh.org Subject: Re: zpasesopts problem In-reply-to: <20210602170052.jsrzn5374lxpxmwg@chazelas.org> Date: Wed, 02 Jun 2021 14:53:27 -0230 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Seq: 26761 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Hello, Stephane Chazelas writes: > 2021-06-02 13:44:44 -0230, Roger Mason: > > You're not showing the full script, so we don't know what $argv > contains at the time zparseopts is being invoked. > > I'd recommend you add a > > typeset -p argv > > before the zparseopts call. > > My guess would be that you're expecting $argv to be: > > typeset -a argv=( --symbol Si --rmt 1.55 --nocc 7 --vstates 1112 ) > > but it's not, possibly because you've called "shift" too many > times or with the wrong number as argument. Here is the full script. It is rather long. #!/usr/local/bin/zsh action=$1 ELKVER=elk-7.1.14 case $action in printall) printbools="true" printfloats="true" printints="true" printtexts="true" ;; printbools) printbools="true" ;; printfloats) printfloats="true" ;; printints) printints="true" ;; printtexts) printtexts="true" ;; names) nams="true" ;; values) vals="true" ;; naval) nvl="true" ;; run) run="true" ;; *) run="true" ;; esac if [[ $nams == true ]];then names=($(awk '/! default values !/{flag=1;next}/! read from elk.in !/{flag=0}flag' \ $HOME/Software/Elk/$ELKVER-omp-fft/src/readinput.f90 \ | awk '!/!/' \ | awk '!/^if/'| awk '!/^allocate/' | awk '!/:/' \ | awk '{gsub(/ /,""); print}' \ | sed 's/[(]/_/g;s/:/_/g;s/)//g;s/,_/all_/g;s/,\([0-9]\)/_\1/g' | sort \ | awk '{gsub(/=/," "); print}' | sed 's/\.\([0-9][0-9]*\)d/\.\1e/g;s/\.d/\.e/g;s|45\.e0\*pi/180\.e0|0\.e0|g' \ | awk '{print $1}')) # b=('--'${^tmp}) # c=$(printf '%s ' $b) echo "Variable names:" echo "$names" fi if [[ $vals == true ]];then # These are all the default values corresponding to the options. values=($(awk '/! default values !/{flag=1;next}/! read from elk.in !/{flag=0}flag' \ ~/Software/Elk/$ELKVER-omp-fft/src/readinput.f90 \ | awk '!/!/' | awk '!/^if/'| awk '!/^allocate/' | awk '!/:/' \ | awk '{gsub(/ /,""); print}' | sed 's/[(]/_/g;s/:/_/g;s/)//g;s/,_/all_/g;s/,\([0-9]\)/_\1/g' | sort \ | awk '{gsub(/=/," "); print}' | sed 's/\.\([0-9][0-9]*\)d/\.\1e/g;s/\.d/\.e/g;s|45\.e0\*pi/180\.e0|0\.e0|g' \ | awk '{print $2}')) # b=('--'${^tmp}) # c=$(printf '%s ' $b) echo "Variable values:" echo "$values" fi # This lists names & values together. if [[ $nvl == true ]];then # These are all the default values corresponding to the options. naval=($(awk '/! default values !/{flag=1;next}/! read from elk.in !/{flag=0}flag' \ ~/Software/Elk/$ELKVER-omp-fft/src/readinput.f90 \ | awk '!/!/' | awk '!/^if/'| awk '!/^allocate/' | awk '!/:/' \ | awk '{gsub(/ /,""); print}' | sed 's/[(]/_/g;s/:/_/g;s/)//g;s/,_/all_/g;s/,\([0-9]\)/_\1/g' | sort \ | awk '{gsub(/=/," "); print}' | sed 's/\.\([0-9][0-9]*\)d/\.\1e/g;s/\.d/\.e/g;s|45\.e0\*pi/180\.e0|0\.e0|g' \ | awk '{printf "%s\\t\\t%s\\n",$1, $2}')) # b=('--'${^tmp}) # c=$(printf '%s ' $b) echo "Variable names & values:" echo "$naval" fi # Booleans only. elkbools=($(awk '/! default values !/{flag=1;next}/! read from elk.in !/{flag=0}flag' \ ~/Software/Elk/$ELKVER-omp-fft/src/readinput.f90 \ | awk '!/!/' | awk '!/^if/'| awk '!/^allocate/' | awk '!/:/' \ | awk '{gsub(/ /,""); print}' | sed 's/[(]/_/g;s/:/_/g;s/)//g;s/,_/all_/g;s/,\([0-9]\)/_\1/g' | sort \ | awk '{gsub(/=/," "); print}' | awk '{if ($2==".false." || $2==".true.") {print "-"$1":" }}')) # These need special handling b/c they are groups of settings. There is probably a way to get them from readinput.f90. # In addition they should be near the beginning of the elk.in so subsequent settings can override them. elkbools=(-lowq: "${elkbools[@]}") elkbools=(-highq: "${elkbools[@]}") elkbools=(-vhighq: "${elkbools[@]}") elkbools=(-uhighq: "${elkbools[@]}") if [[ $printbools == true ]];then echo "$elkbools" fi # Floats only. elkfloats=($(awk '/! default values !/{flag=1;next}/! read from elk.in !/{flag=0}flag' \ ~/Software/Elk/$ELKVER-omp-fft/src/readinput.f90 \ | awk '!/!/' | awk '!/^if/'| awk '!/^allocate/' | awk '!/:/' \ | awk '{gsub(/ /,""); print}' | sed 's/[(]/_/g;s/:/_/g;s/)//g;s/,_/all_/g;s/,\([0-9]\)/_\1/g' | sort \ | awk '{gsub(/=/," "); print}' | awk '$2 ~ /[0-9]+(\.)[0-9]*/ {print "-"$1":"}')) if [[ $printfloats == true ]];then echo "$elkfloats" fi # Integers only. elkints=($(awk '/! default values !/{flag=1;next}/! read from elk.in !/{flag=0}flag' \ ~/Software/Elk/$ELKVER-omp-fft/src/readinput.f90 \ | awk '!/!/' | awk '!/^if/'| awk '!/^allocate/' | awk '!/:/' | awk '!/xct/' \ | awk '{gsub(/ /,""); print}' | sed 's/[(]/_/g;s/:/_/g;s/)//g;s/,_/all_/g;s/,\([0-9]\)/_\1/g' | sort \ | awk '{gsub(/=/," "); print}' | awk '$2 ~ /[0-9][0-9]*/' | awk '$2 !~ /\./ {print "-"$1":"}')) if [[ $printints == true ]];then echo "$elkints" fi # Text only. Read as a string between \A\z. # tasks is a list of integers that is not handled by elkints. They should be on separate lines. # The newlines can be entered explicitly like this: '0\n 21'. # ngridk is handled similarly, but using spaces vs \n. elktexts=(-tasks: "${elktexts[@]}") #elktexts=(-ngridk: "${elktexts[@]}") elktexts+=($(awk '/! default values !/{flag=1;next}/! read from elk.in !/{flag=0}flag' \ ~/Software/Elk/$ELKVER-omp-fft/src/readinput.f90 \ | awk '!/!/' | awk '!/^if/'| awk '!/^allocate/' | awk '!/:/' \ | awk '{gsub(/ /,""); print}' | sed 's/[(]/_/g;s/:/_/g;s/)//g;s/,_/all_/g;s/,\([0-9]\)/_\1/g' | sort \ | awk '{gsub(/=/," "); print}' | awk '$2 ~ /^\A[0-9][0-9]*\z/ {print "-"$1":"}')) #elktexts=("${elktexts[@]}" -ngridk:) if [[ $printtexts == true ]];then echo "$elktexts" fi # ngridk. Needs special handling b/c it is an array. For some reason # I could not get text like '1 1 1' to load into postgresql correctly. zparseopts -D -E -A intarrays - -ngridk: -xctype: zparseopts -D -E -A elkbools - $elkbools zparseopts -D -E -A elkfloats - $elkfloats zparseopts -D -E -A elkints - $elkints zparseopts -D -E -A elktexts - $elktexts # This accumulates most of the options that are used in elk.in OPTSELK="" kx=1;ky=1;kz=1 # Defaults for key value in "${(@kv)intarrays}"; do k=$(echo $key | tr -d '-') ${k}=${intarrays[$key]} 2>/dev/null # Discard error message: command not found: if [[ $k == ngridk ]];then # extract kx,ky & kz for later use in postgres. kx=$(echo "${value}" | awk '{print $1}') ky=$(echo "${value}" | awk '{print $2}') kz=$(echo "${value}" | awk '{print $3}') fi OPTSELK+="$k\n $value\n\n" done # echo "k = $k kx = $kx ky = $ky kz = $kz" # exit 10 # If given on the command line, the command line versions will be used, otherwise the program defaults are used. # Loop over the option names and set values to override the defaults. for key value in "${(@kv)elkbools}"; do k=$(echo $key | tr -d '-') ${k}=${elkbools[$key]} 2>/dev/null # Discard error message: command not found: OPTSELK+="$k\n $value\n\n" done #echo $OPTSELK for key value in "${(@kv)elkfloats}"; do k=$(echo $key | tr -d '-') ${k}=${elkfloats[$key]} 2>/dev/null # Discard error message: command not found: if [[ $k == sc ]];then # sc is used internally in the elk code vs elk.in. k=$(echo $k | sed 's/sc/scale/g') # Should work on sc1, sc2 & sc3. fi if [[ $k == nempty0 ]];then # nempty0 is used internally in the elk code vs elk.in. k=$(echo $k | sed 's/nempty0/nempty/g') # Remove 0 fi OPTSELK+="$k\n $value\n\n" done # echo "$OPTSELK" # exit 10 for key value in "${(@kv)elkints}"; do k=$(echo $key | tr -d '-') ${k}=${elkints[$key]} 2>/dev/null # Discard error message: command not found: OPTSELK+="$k\n $value\n\n" done for key value in "${(@kv)elktexts}"; do k=$(echo $key | tr -d '-') ${k}=${elktexts[$key]} 2>/dev/null # Discard error message: command not found: OPTSELK+="$k\n $value\n\n" done #echo $OPTSELK # Other options This ensures that spsource is set in the species array # even when not specified on the command line. # zparseopts -D -E -A species - -spsource: -Z: -symbol: -name: -mass: -rmt: -nocc: -vstates: # zparseopts -D -E -A species -spsource: # spsource=${species[--spsource]:-/home/rmason/Software/Elk/$ELKVER/species/} # species[--spsource]=${spsource} # Z=${species[--Z]:-14} # species[--Z]=${Z} # symbol=${species[--symbol]:-Si} # species[--symbol]=${symbol} # name=${species[--name]:-silicon} # species[--name]=${name} # mass=${species[--mass]:-28.0855} # species[--mass]=${mass} # rmt=${species[--rmt]:-1.55} # species[--rmt]=${rmt} # nocc=${species[--nocc]:-1} # species[--nocc]=${nocc} # vstates=${species[--vstates]:-"1 0 1 1"} # species[--vstates]=${vstates} # Supercell options zparseopts -D -E -A scopts -sx: -sy: -sz: -dry: sx=${scopts[--sx]:-1} sy=${scopts[--sy]:-1} sz=${scopts[--sz]:-1} dry=${scopts[--dry]:-no} # does not need to be retained for DB. scopts[--sx]=${sx} scopts[--sy]=${sy} scopts[--sz]=${sz} # echo "sx = $sx sy = $sy sz = $sz" # exit 1 # Sbatch options zparseopts -D -E -A sbopts -nodes: -mpitasks: -cppt: -memper: -time: -nodelist: time=${sbopts[--time]:-00:30:00} nnodes=${sbopts[--nodes]:-1} # number of nodes mpitasks=${sbopts[--mpitasks]:-1} # number of MPI tasks cpuper=${sbopts[--cppt]:-1} # cpus-per-task memper=${sbopts[--mem]:-250} # memory per CPU nodelist=${sbopts[--nodelist]:-} # no default so it does not need the re-insertion used for the others below. sbopts[--nodes]=$nnodes sbopts[--mpitasks]=$mpitasks sbopts[--cpuper]=$cpuper sbopts[--memper]=$memper sbopts[--time]=$time # Composition arguments # NB: compositions with Al won't be charge balanced. zparseopts -D -E -A comopts -xti: -xal: # Composition arguments xti=${comopts[--xti]-0} xal=${comopts[--xal]-0} comopts[--xti]=$xti comopts[--xal]=$xal # Job control options. If submit = no, the job is created along with # the input tarball but nothing is sent to $target or submitted to # slurm. Not stored in DB b/c if the job wasn't run there won't be a # DB entry for the results. zparseopts -D -E -A jbcopts - -submit: submit=${jbcopts[--submit]:-yes} # echo "Job submit = $submit" # exit 3 if [[ ${dry} == yes ]];then submit=no scd="-d" fi # echo "submit = $submit dry = $scd" # exit 10 # PostgreSQL options zparseopts -D -E -A pgopts - -db: db=${pgopts[--db]:-elk} pgopts[--db]=$db # Tar options zparseopts -D -E -A taropts -tar: tar=${taropts[--tar]:-zf} # No tasks? if [[ ! ${elktexts[--tasks]+x} ]];then echo "The '--tasks' setting is mandatory." exit 1 fi # Species options typeset -p argv zparseopts -D -E -A species - -spsource: spsource=${species[--spsource]:-/home/rmason/Software/Elk/$ELKVER/species/} # If spsource = SpeciesGenerated, parse these options too. if [[ $spsource == SpeciesGenerated ]];then zparseopts -D -E - -symbol+:=chemsyms -rmt+:=rmts -nocc+:=noccs -vstate+:=vstates echo "Parsing species options." function addspecies() { ADDSPECIES+="species\n" ADDSPECIES+=" $Z\n" ADDSPECIES+=" '$symbol' '$name'\n" ADDSPECIES+=" $mass\n" ADDSPECIES+=" $rmt\n" ADDSPECIES+=" $nocc\n" ADDSPECIES+=" $states\n" } # This could be relaxed so that only the desired quantities need be # specified. In that case the defaults need to be given in the case # statements, somehow. Ugly. if [[ ${#chemsyms} -ne ${#rmts} ]] || [[ ${#chemsyms} -ne ${#noccs} ]] || [[ ${#chemsyms} -ne ${#vstates} ]];then echo "The numbers of chemical chemsyms, RMTs, occupation numbers and valence states do not match." echo "#chemsyms = ${#chemsyms}, #rmts = ${#rmts}, #noccs = ${#noccs}, #vstates = ${#vstates}" echo "Check your command line. Exiting." exit -1 fi # Additional species information to override the defaults. ADDSPECIES="" typeset -A helper helper=($(seq 1 ${#chemsyms})) echo "helper = $helper" for item in ${(@v)helper} do echo "${chemsyms[$item]} ${rmts[$item]} ${noccs[$item]} ${vstates[$item]}" case ${chemsyms[$item]} in Si) name=silicon mass=28.0855 Z=14 symbol=${chemsyms[$item]} rmt=${rmts[$item]} nocc=${noccs[$item]} states=${vstates[$item]} addspecies ;; O) name=oxygen mass=15.9994 Z=8 symbol=${chemsyms[$item]} rmt=${rmts[$item]} nocc=${noccs[$item]} states=${vstates[$item]} addspecies ;; Ti) name=titanium mass=47.867 Z=22 symbol=${chemsyms[$item]} rmt=${rmts[$item]} nocc=${noccs[$item]} states=${vstates[$item]} addspecies ;; Al) name=aluminium mass=26.981538 Z=13 symbol=${chemsyms[$item]} rmt=${rmts[$item]} nocc=${noccs[$item]} states=${vstates[$item]} addspecies ;; *) echo "${chemsyms[$item]} is not currently in the list of elements." echo "Add it to the script or check your command line. Exiting." exit -2 ;; esac done fi And the output from typset -p argv is: typeset -a argv=( filmperthite --spsource SpeciesGenerated Si --rmt 1.55 \ --nocc 7 --vstates 1112 ) So, the argument to --symbol is not being recognised. Thanks, Roger