Is python a good choice for this task?

William Park opengeometry at yahoo.ca
Mon Nov 11 18:43:39 EST 2002


In comp.lang.python Ron Lau <ral at spongebob.corporate.com> wrote:
> Hi,
> 
> This IS NOT a request for someone to write a program for me. (But I won't
> turn it down :)  ).  The only programming I ever did was FORTRAN >:P , and short shell
> scripts. I'm just looking for advice.
> 
> 
> I have a CFD program that takes a text file as input (Q1.1). I run it on the
> command line as:
> 
> phoe Q1.1
> 
> which outputs the binary file PH.1
> 
> 
> I also have a program that gives me a number as the last line of its
> output to the terminal with the command
> 
> pointquerey  PH.1 TempK 1 1 1 | tail -1
> 
> 
> What I do now is compare the output of the line above to the value I want
> it to be, then change a parameter in the Q1.1 file, say T1=500.0
> 
> I would like to write something that would Goal Seek this for me.
> (something simple like a newtonian method)
> 
> So I would need a program to..
> --------------------------
> 
> run the command "phoe Q1.1"
> 
> then run the command "pointquery PH.1 TempK 1 1 1 | tail -1"
> 
> read the output of the above and compare to the desired value.
> 
> calculate a better value of T1.
> 
> replace T1=oldvalue in the file Q1.1 with the calculated value from
> above.
> 
> loop back to the beginning...
> 
> -------------------------
> 
> 
> My question is, What language is best suited for this? Perl, Python, or
> shell scripts?
> 
> 
> TIA!
> 
> ral

Well, shell is more natural approach, though you can do it in any scripting
language.  For example,
    while [ $out ... $some_value ]; do
	phoe Q1.1
	out=`pointquery PH.1 TempK 1 1 1 | tail -1`
	if [ ...<terminal_condition>... ]; then 
	    break
	fi
	T1=...
	sed "g/T1=.*/s//T1=$T1/" Q1.1 > new && mv new Q1.1
    done

-- 
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
Linux solution for data management and processing. 
1986 VW Jetta, 350000km :-))



More information about the Python-list mailing list