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

AI Thread Summary
To rerun a C program that generates a histogram with user-defined input, options include creating a script or modifying the program to loop through various inputs. For beginners unfamiliar with scripting, it's important to understand the basics of the operating system in use—Windows utilizes batch files with loop operators, while Unix/Linux systems use shell scripts. Resources for learning C programming include searching for "C primer" or obtaining textbooks from local colleges. A sample shell script illustrates how to loop through parameters, execute the program, and save the results, which can be adapted for Windows with similar syntax.
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.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top