newbie question: using Python to coordinate C++ program and use gnuplot

Mark Robinson m.1.robinson at herts.ac.uk
Thu Aug 16 11:03:10 EDT 2001


Hey

Eduardo Zea wrote:

> Hello all,
> 
> Can someone suggest a good place to look for info on achieving the
> following kind of tasks:
> 
> 1) I have a C++ program that reads a file with parameters (say
> parameters.txt) and runs a simulation, then produces an output file (say
> output.txt). I want to write a Python program that loops over the
> parameter values and on each loop does this:
> 
> 1. Updates parameters.txt
> 2. Runs the C++ program with the updated file
> 3. Renames the output of the C++ program according to the simulation
> number, e.g. output1.txt


You could try something along the lines of the following. I don't know 
how you pass parameters to your c++ program I have assumed it is a 
command line option.

import os

def = 'output'
def_ext = '.txt'
paramfile = open('parameters.txt', 'r')
count = 1
for param in paramfile.readlines():
	os.system('c++ program name', param)
	os.rename(de, '%s%s%s' % (def, count, def_ext)

I hope that helps (always a pleasure to help a fellow biologist ;)), I 
don't know about gnuplot so I'll leave that to someone more knowledgable 
than I.

blobby




More information about the Python-list mailing list