#!/bin/tcsh # ATMS 502/CSE 566 Spring, 2025 # Shell script for Program #3 - adaptive grid nesting # The first line says which Linux command interpreter ('shell') to use. # A shell script is just a series of commands, as if you typed them. # More on scripting: rfd.atmos.uiuc.edu/502/Shells_and_scripting.html # The 'vim' text editor is probably coloring this text for you. Info # on vim highlighting: https://linuxhandbook.com/syntax-highlight-vim/ # 'nano' can highlight shell / programming languages too: # askubuntu.com/questions/90013/how-do-i-enable-syntax-highlighting-in-nano # IMPORTANT: set the email address below if sending plots to yourself!! # 1. SETTINGS set myEmail = YOUR_EMAIL@illinois.edu # any email address should work set program = pgm3 # name of the running program set output = ${program}_output.txt # name of output text file # # 2. DELETE old files: program, gmeta, .zip, output files from earlier. # Note: the '-f' argument suppresses a warning if a file doesn't exist # (in general I would use "rm" instead of "rm -f" but it is OK here) # rm -f $program gmeta gmeta.zip $output # no warning if it doesn't exist # # 3. BUILD the code using the make program # .. it reads your 'Makefile' to compile/link your program. # .. change this if e.g. you have to type "make pgm3" # make # # If make found problems: the code had errors, and program doesn't exist (so we stop) # Csh Syntax: "-e" means a file exists, "! -e" means it does Not exist. # We use '$program' here, so you need to have set "program=" earlier in this script. # if (! -e $program) then echo Compile of program failed, stopping. exit endif # # 4. RUN the program. It reads everything from "<< END" to "END" # There is nothing special about the word END; << STORMS would work too. # # The program output goes to the screen but ALSO to a text file, split with # Linux 'tee' command. The "|&" is csh scripting for "send as input to". # Documentation: Type "man tee", or: linuxize.com/post/linux-tee-command/ # If you choose to Mail plots to yourself, this output is also mailed. # # Change this to match what data your program reads in !!! # $program << END |& tee $output 400 100 L 3 END endif # # 5. PLOTS # If program created plots (if "gmeta" exists), we can view the plots now. # There are two ways to view the plots: # # (1) If you are using Xquarts/Xming for X-windows graphics, "idt" will display "gmeta" # idt = interactive display tool, www.ncl.ucar.edu/Document/Tools/idt.shtml # If you don't want this, comment out idt below by inserting "#" before "idt gmeta" # # (2) Mail the output plots to yourself. This has two steps - # (a) Convert the gmeta plot metacode file to a bunch of .gif files, and # create an archive (typically gmeta.zip) of the .gif files # (b) Mail the archive file gmeta.zip to yourself. # If you don't want this, comment out the steps below by inserting "#" before each line # # Note: the indentation used in this script is just to make it easily readable. # Shell scripts (usually) don't care about 'white space' (blank lines, tabs, spaces). # The bash shell is a little more picky on white space than the csh/tcsh shell. if (-e gmeta) then # Graphics file 'gmeta' was created, let's view plots # OPTION #1: Display plots over X-windows with "idt". Insert '#' to turn off. idt gmeta # OPTION #2: Make .gif files, combine in gmeta.zip, Mail gmeta.zip to yourself # If you don't want this, insert #'s' before each command line below. echo Making .gif files and putting into archive '"gmeta.zip"' ... ~bjewett/bin/metagif gmeta -all -zip if (-e gmeta.zip) then echo Mailing $output and gmeta.zip to: $myEmail cat $output | Mail -a gmeta.zip -s "$program plots" $myEmail echo "Mail sent; it may take a few minutes to arrive." echo ... the subject line is: $program plots else echo gmeta.zip not found ... so no email was sent. endif # Details about Option #2 above -- # a) metagif converts gmeta to a series of .gif images # -all -zip processes all plots and creates gmeta.zip # metagif is a shell script; you can view with nano or vim # b) Mail command really runs "mailx", a Linux mail program. # -a filename ... makes "filename" an email attachment # -s text.. ... also adds a Subject line to the email. # Documentation: type "man Mail" for Linux manual pages on Mail. # c) "cat $output | Mail ..." sends the output from your program # to you as the body of the mail message. The pipe key "|" # takes output from the concatenate command "cat" and turns # that into input for the Mail program, instead of Mail # reading from the keyboard. This also prevents Mail # from sitting forever waiting for you to type control-D. # Documentation: Pipe: https://www.redhat.com/sysadmin/pipes-command-line-linux # Documentation: Cat: https://phoenixnap.com/kb/linux-cat-command (or: man cat) # 6. THIS is a great place to add commands to make web pages!! # (this is still inside if..endif for 'gmeta') # You can run scripts to convert "gmeta" to images and make web pages, # then email the .zip file to yourself (or combine this with email above) endif # end of "does gmeta exist" if-statement above. echo Done. # >>>>>>>>>>> ============ More on Linux shells ============== <<<<<<<<<<<<<<<< # https://unix.stackexchange.com/questions/3320/what-are-the-fundamental-differences-between-the-mainstream-nix-shells # http://www.faqs.org/faqs/unix-faq/shell/shell-differences/