From dcf5015af13cc9d1d2cc1251829d170cbb31335d Mon Sep 17 00:00:00 2001 From: Gerber van der Graaf Date: Tue, 28 Sep 2010 16:51:19 +0200 Subject: [PATCH] Simplified usage by requiring 'FNAME' in the 'process' string --- man/gpiv_series.1 | 29 +++++++++++------------------ src/misc/series_mpi.py | 39 ++++++++++++++++----------------------- src/misc/series_ser.py | 21 +++++++-------------- 3 files changed, 34 insertions(+), 55 deletions(-) diff --git a/man/gpiv_series.1 b/man/gpiv_series.1 index 3d317bc..e1980c0 100644 --- a/man/gpiv_series.1 +++ b/man/gpiv_series.1 @@ -15,20 +15,18 @@ gpiv_series \- Script for (parallel) processing a series of numbered files. [\fB-n\fR | \fB-\-none\fR] [\fB-p\fR | \fB-\-print\fR] [\fB-\-pad\fR] -[\fb-s\fR | \fb-\-subst_fname\fR] \fB"\fR\fIprocess\fR \-key1 ...\fB"\fR .SH DESCRIPTION -\fBgpiv_series\fP processes a series of numbered files. If no parameters are -defined at the command line, standard parameters will be used that are -defined in the script. Principally, any program or script may be -invoked by \fBgpiv_series\fP. "\fIProcess\fR" is a string which -represents the name of the program to be executed, including -eventually command line options and arguments. The file to be -processed, as constructed from \fB-b\fR, \fB-i\fR and \fB-l\fR, -will be appended to the "\fIprocess\fR" string. If the program has to be feeded -with \-f "filename", write \-f at the end of the string. Instead of appending the -filename to the "\fIprocess\fR" string, there is also a way substitute all occurences FNAME. +\fBgpiv_series\fP processes a series of numbered files. If no +parameters are defined at the command line, standard parameters will +be used that are defined in the script. Principally, any program or +script may be invoked by \fBgpiv_series\fP. "\fIProcess\fR" is a +string which represents the name of the program or script to be +executed, including the required string "\fIFNAME\fR" and eventually +command line options and arguments. The filename to be constructed from +\fB-b\fR, \fB-i\fR and \fB-l\fR, will substitute all occurrences of +"\fIFNAME\fR" in the "\fIprocess\fR" string. When using the parallelised version, mpipython is invoked and the script may be launched with mpirun. The script needs that all input files @@ -42,12 +40,12 @@ This program does not use the parameter resources from libgpiv. \fB-a\fR | \fB--arg_n\fR If the process needs the current number in its argument list instead of prepending/appending it to the \fIFILE\fR, the number will be -put before (\fB-f\fR) filename in the "\fR\fIprocess\fR" string. +put before (\fB-f\fR) \fIFNAME\fR in the "\fR\fIprocess\fR" string. .TP \fB-b\fR | \fB-\-basename\fR \fIFILE\fR The \fIFILE\fR has to be given without its extension. \fIFILE\fR represents -the file name without its number. It is supposed that the leading or ending +the filename without its number. It is supposed that the leading or ending number in the filename is the counter that will be applied by \fBgpiv_series\fR when processing. @@ -92,11 +90,6 @@ Prints the process to be performed on each file to stdout. Padding a number with \fIN\fR zero's when combining with the filename. .TP -\fb-s\fR | \fb-\-subst_fname\fR -Substitutes all occurences \"FNAME\" in the "\fIprocess\fR" string by the actual -file basename. The \fB-a\fR | \fB--arg_n\fR will be useless for this case. - -.TP .SH SEE ALSO gpivtools diff --git a/src/misc/series_mpi.py b/src/misc/series_mpi.py index d2fbfc6..f7456dd 100644 --- a/src/misc/series_mpi.py +++ b/src/misc/series_mpi.py @@ -57,10 +57,6 @@ parser.add_option("-p", "--print", help="prints process parameters/variables to stdout") parser.add_option("--pad", type='int', dest="pad0", default=0, help="padding number with zero's (default: 0)", metavar="N") -parser.add_option("-s", "--subst_fname", - action="store_true", dest="subst_fname", default=False, - help="substitutes all occurences \"FNAME\" in the \"process\" string by the actual \ -file basename. The option --arg_n will not have effect") parser.add_option("-n", "--none", action="store_true", dest="none", default=False, help="suppresses real execution") @@ -73,6 +69,8 @@ if len(args) != 1: else: process = args[0] +if not "FNAME" in process: + parser.error("process does not contain the required string 'FNAME'") # #----------- Function definitions @@ -125,25 +123,25 @@ def compose_name_nr(nr): nr -- number of filename to be processed """ if options.pad0 > 0: - ndig=count_digits(nr) - null_str=pad0(options.pad0 - ndig) - nr_str=null_str+str(nr) + ndig = count_digits(nr) + null_str = pad0(options.pad0 - ndig) + nr_str = null_str+str(nr) else: - nr_str=str(nr) + nr_str = str(nr) if options.prefix: if options.arg_n: - name=str(options.basename) + name = str(options.basename) else: - name=nr_str+str(options.basename) + name = nr_str+str(options.basename) else: if options.arg_n: - name=str(options.basename) + name = str(options.basename) else: - name=str(options.basename)+nr_str + name = str(options.basename)+nr_str if str(options.ext) != "None": - name=str(name)+str(".")+str(options.ext) + name = str(name) + str(".") + str(options.ext) return(name) @@ -157,17 +155,12 @@ def compose_cmd(name, nr): command=str(process) # Eventually, substitutes "-f" with: "nr -f" if options.arg_n: - command_tmp=re.sub("-f", str(nr)+" -f", command) - if command_tmp != command: - command = str(command_tmp)+" "+str(name) + if "-f" in command: + command=re.sub("-f", str(nr)+" -f", command) else: - command = str(command_tmp)+" "+str(nr)+" "+str(name) - else: - # Eventually, substitutes "FNAME" with the file base name - if options.subst_fname: - command=re.sub("FNAME", str(name), str(process)) - else: - command=str(command)+" "+str(name) + command=re.sub("FNAME", str(nr)+" FNAME", command) + # Substitutes "FNAME" with the file base name + command=re.sub("FNAME", str(name), str(command)) return command diff --git a/src/misc/series_ser.py b/src/misc/series_ser.py index 6aa690c..0fe0b95 100755 --- a/src/misc/series_ser.py +++ b/src/misc/series_ser.py @@ -54,10 +54,6 @@ parser.add_option("-p", "--print", help="prints process parameters/variables to stdout") parser.add_option("--pad", type='int', dest="pad0", default=0, help="padding number with zero's (default: 0)", metavar="N") -parser.add_option("-s", "--subst_fname", - action="store_true", dest="subst_fname", default=False, - help="substitutes all occurences \"FNAME\" in the \"process\" string by the actual \ -file basename. The option --arg_n will not have effect") parser.add_option("-n", "--none", action="store_true", dest="none", default=False, help="suppresses real execution") @@ -70,6 +66,8 @@ if len(args) != 1: else: process = args[0] +if not "FNAME" in process: + parser.error("process does not contain the required string 'FNAME'") # #----------- Function definitions @@ -154,17 +152,12 @@ def compose_cmd(name, nr): command=str(process) # Eventually, substitutes "-f" with: "nr -f" if options.arg_n: - command_tmp=re.sub("-f", str(nr)+" -f", command) - if command_tmp != command: - command = str(command_tmp)+" "+str(name) + if "-f" in command: + command=re.sub("-f", str(nr)+" -f", command) else: - command = str(command_tmp)+" "+str(nr)+" "+str(name) - else: - # Eventually, substitutes "FNAME" with the file base name - if options.subst_fname: - command=re.sub("FNAME", str(name), str(process)) - else: - command=str(command)+" "+str(name) + command=re.sub("FNAME", str(nr)+" FNAME", command) + # Substitutes "FNAME" with the file base name + command=re.sub("FNAME", str(name), str(command)) return command -- 2.11.4.GIT