Writing a script to repeat a C program (Umbrella Sampling Script)

Click For Summary

Discussion Overview

The discussion revolves around writing a script to automate the execution of a C program that generates histograms, specifically focusing on how to modify a variable based on user input and save the resulting data. The scope includes programming concepts, scripting, and basic C programming knowledge.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant expresses a need for a script to rerun a C program multiple times with varying user-defined input.
  • Another participant suggests two approaches: creating a separate script or modifying the existing C program to include a loop for generating multiple histograms.
  • A participant indicates confusion about scripting basics and requests references for learning C programming.
  • One reply comments that the issue may stem from general programming knowledge rather than C specifically.
  • Another participant inquires about the operating system being used, noting that the scripting approach would differ between Windows and Unix/Linux environments.
  • A later reply provides a sample Bash script for Linux users, illustrating how to loop through parameters and execute the program, while also mentioning that Windows scripts would be similar.

Areas of Agreement / Disagreement

Participants generally agree on the need for a script to automate the process, but there is no consensus on the best approach or the specifics of implementation. Confusion about basic programming concepts and syntax persists among some participants.

Contextual Notes

Limitations include varying levels of programming knowledge among participants, differing operating systems affecting scripting methods, and the need for foundational understanding of C programming and scripting syntax.

Who May Find This Useful

Individuals new to programming, particularly those learning C and interested in automating tasks through scripting, as well as those seeking to understand how to manipulate program parameters and save outputs effectively.

kd215
Messages
8
Reaction score
0
I have a C code that creates a small histogram, but I need it to rerun many many times by changing one variable that the user can input. I've NEVER used C until this week so if someone could given me an idea of how to write a script to repeat a code and save a bunch of data from it that would be great!

Thanks!
 
Technology news on Phys.org
It's not clear to me what you want to do. You could create a script / batch file to run the program repeatedly, or you could change the program so that it loops and creates many historgrams.
 
I don't even know the basics of writing a script. I'm really confused with the syntax. Are there any references for basic C programming that you know of?
 
Sounds like your problem is not with C but with programming in general.
 
kd215 said:
I don't even know the basics of writing a script.
What operating system are you using? If it's windows, then you'll be using MSDOS type batch files, which include a loop operator. If it's unix or linux, there are different command "shells", each with it's own scripting language (although they are similar).

kd215 said:
Are there any references for basic C programming that you know of?
I haven't kept up with the books or articles that are available. You could do a web search for "C primer", or perhaps get a textbook used for a local college class. Hopefully someone here at PF can recommend a book.
 
Assuming you use Linux, copy the following lines into a file and make it executable (chmod u+x <filename>):
Code:
#!/bin/bash
for parameter in 0.1 0.2 0.3 ; do
  echo "calling the program with the parameter "$parameter

  # call the program.
  ./my_program $parameter

  # backup the result to some other file.
  cp theresultfile resultfile_of_parameter_$parameter
done
Customization to your needs should be straightforward - Windows scripts should be somewhat similar.
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 25 ·
Replies
25
Views
3K
  • · Replies 22 ·
Replies
22
Views
2K
Replies
65
Views
5K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
6
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 14 ·
Replies
14
Views
35K