Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Mar 7, 2013 #1
    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!
     
  2. jcsd
  3. Mar 7, 2013 #2

    rcgldr

    User Avatar
    Homework Helper

    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.
     
  4. Mar 7, 2013 #3
    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?
     
  5. Mar 7, 2013 #4

    Borek

    User Avatar

    Staff: Mentor

    Sounds like your problem is not with C but with programming in general.
     
  6. Mar 7, 2013 #5

    rcgldr

    User Avatar
    Homework Helper

    What operating sytem 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).

    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 text book used for a local college class. Hopefully someone here at PF can recommend a book.
     
  7. Mar 7, 2013 #6
    Assuming you use Linux, copy the following lines into a file and make it executable (chmod u+x <filename>):
    Code (Text):

    #!/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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Writing a script to repeat a C program (Umbrella Sampling Script)
  1. Writing a program in C (Replies: 8)

  2. Python Script (Replies: 2)

Loading...