====== Writing shell scripts ====== (improve this text by edits in appropriate places; blog remarks into [[gtspring2009:howto:shell_scripts#hiccups|Hiccups section at the bottom]]) This page is probably woefully incomplete, but it worked for me without causing a catastrophic meltdown, yet. I hope group members more knowledgeable will edit this page where needed so this is safer to do. -- Dustin 2009-02-26 {{gtspring2009:gibson.png?24}} See comments in [[#hiccups]]. //John Gibson 2009-03-09// This might also be helpful when students start [[gtspring2009:howto:pace|using the PACE cluster]], as I'm pretty sure you send the cluster script files. ===== Simple Shell Script ===== * To create a simple shell script, first create a directory in your channelflow directory called, say test_script, so that you don't orphan any files. * Within the test_script directory, use your favorite text editor to create an extension-less file called my_script. * Enter the following into my_script #!/bin/bash # First script echo "That's easy" The first line is very important, don't leave it out. The second line is just a comment on what your script does, documentation good. The line without the '#' is what the computer actually executes. * (I'm not 100% sure about this step, but I blindly followed the seedy Linux site, and it worked.) Next, you need to change permissions on the file you just created so that it can be executed. Do this by entering the following command into your shell: [dustin@localhost test_script]$ chmod 755 my_script * Now you are ready to execute your shell script. You can do this using: [dustin@localhost test_script]$ ./my_script * Hopefully, your shell printed out "That's easy" right after you execute command, and you are done. ===== Unstable Manifold Example ===== It is important when you create a shell script to enter the commands into the script file exactly as you want them executed, with no typos or logic errors, or else the script file will bail on you and your preparation will be for not. We are going to create a script file to compute the 1-D unstable manifold of the Nagata Upper Branch Solution, similar to the tutorial example, just a different solution. You might want to save this for the end of the day, so all of your data will be available fresh in the morning the next day. * Name a directory where you want all of your data to be stored within channelflow, I used UB-eqb2. * Create a script file, I called mine UB_manif_script. * Enter the following into the script file: #!/bin/bash #Some documentation here about what your script file does - documentation is extremely important. wget http://channelflow.org/database/a1.14_g2.5_Re400/UB.ff fieldplots -o plot UB arnoldi --flow UB.ff addfields 1 UB 0.01 ef1 UBp01ef1 addfields 1 UB -0.01 ef1 UBm01ef1 couette -T0 0 -T1 400 -o data-UBp01ef1 UBp01ef1 couette -T0 0 -T1 400 -o data-UBm01ef1 UBm01ef1 seriesprops -T0 0 -T1 400 data-UBp01ef1 -o props-UBp01ef1 seriesprops -T0 0 -T1 400 data-UBm01ef1 -o props-UBm01ef1 movieframes -T0 0 -T1 400 data-UBp01ef1 -o frames-UBp01ef1 movieframes -T0 0 -T1 400 data-UBm01ef1 -0 frames-UBm01ef1 * Change the permissions on the file using: [dustin@localhost UB-eqb2]$ chmod 755 UB_manif_script * Execute the script: [dustin@localhost UB-eqb2]$ ./UB_manif_script * Get back to doing something else and leave your computer for a few hours. This program took somewhere between 1 and 10 hours to run to completion, I don't know because I wasn't there when it finished. ===== Hiccups ===== (blog here: prepend the latest post at the top) {{gtspring2009:gibson.png?24}} My verdict: thumbs up and no obvious possibilities for melted computers. I've found shell scripts such as these to be very useful for running a series of predefined calculations such as computing statistics and making movies of orbits, and doing poor man's continuation of existing solutions. For these shell scripts are adequate. For the PACE cluster, jobs are submitted to a job queue with "qsub" and monitored with "qstat". It's somewhat like shell scripting but not entirely. I have written a few shell functions that simplify the job submission procedure and need to post and document them. I am also feeling the need (quite strongly, in fact) to enable more sophisticated scripting with channelflow utilities and functions. For example, shell scripts are not flexible and mathematical enough for doing adaptive continuation, where you adjust the size of the parameter steps based on the second derivative of the continuation curve, or for switching the continuation parameter in order to turn the corner around a bifurcation point. For this, we either need to write a new channelflow utility that combines the quadratic continuation and solution-finding algorithms, or we need to use a more sophisticated scripting language like Python. There are merits to either approach. I would dearly love to work on either but it would take a few days focused effort. This would be a very good project for anyone interested in continuation. //John F. Gibson 2009-03-09// :-) Because many of us sleep some hours of the day and can't keep watchful guard over our computers at all times during the day even though our computers would like to be doing calculations even though we aren't here, I thought it would be useful if I posted a HowTo of writing shell scripts. I know these will be particularly helpful for me because I am still a first year grad student and I have lots of homework and can't man a terminal at all hours of the day. --- //[[dustin.spieker@gatech.edu|Dustin Spieker]] 2009-02-26//