Allen CDNE

Computational Design in Nuclear Engineering · Allen

Download the PDF

Computational Design in Nuclear Engineering, second edition, by Kenneth S. Allen, Ph.D., P.E.

Download the PDF

Chapter 2 · Introduction to Computation

DOS Commands and Batch Files

On this page

Chapter 2 · 3 / 57 min readPDF page 58

Worked examples

Good pre- and post-processing greatly increases the engineer’s efficiency when working with computational programs. This includes programs written by the engineer or other large-scale programs used to calculate results. Most undergraduate nuclear engineering students have little to no experience using computer programs that have a command prompt interface such as the DOS prompt or Linux command prompt. Many nuclear engineering computer programs, like MCNP, are still operated through a DOS or Linux prompt. This text will work exclusively with the DOS command prompt. For Linux operations, refer to an appropriate reference.

Being familiar with basic DOS commands will greatly increase the productivity of the engineer and allow him or her to navigate the operation of a program with ease. In addition to running a program that uses the command prompt, DOS commands can be written into a batch file. Batch files can greatly increase productivity by executing multiple input files in sequence or performing repeated functions. Batch files allow the engineer to perform many iterations of a calculation without having to wait for the program to complete the operation and then start the next file and repeating until all of the files are complete. Advanced users can write scripts into an executable using Julia, Python, C++ or FORTRAN to do even more. For example, a script can read in an input file, change a parameter, execute the program, read through the results, tabulate items of interest and repeat. The NJOYHelper program, used assist in generating the cross section plots presented in Chapter 1, was written to read in temperatures and isotopes to generate NJOY input files and a batch file that executes NJOY as many times as necessary to generate the required cross sections. Table 2.4 contains many common DOS commands and their meanings for reference. (Hope; 2023)

Table 2.4. Several Useful DOS Commands and their Meanings

CommandDescription
assocView the file associations
callCalls a batch file from another batch file
cdChange directories
compCompares files
copyCopy one or more files to an alternate location
delDeletes one or more files
dirList the contents of one or more directory
echoDisplay messages and enables and disables echo
fcCompare files
findSearch for text within a file
forBoolean used in batch files
ifAllows for batch files to perform conditional processing
mkdirCommand to create a new directory
moreDisplay one page at a time
moveMove one or more files from one directory to another directory
printPrints data to a printer port
promptView and change the MS-DOS prompt
renameRenames a file or directory
rmdirRemoves an empty directory

There are many more DOS commands that have been used throughout the years. Some commands are no longer available depending on the version of Windows being used. CAUTION, some DOS commands can delete, format, or lock a hard drive and these operations may not be repairable and DOS may not prompt the user that there is potential damage prior to executing them.

In addition to the typed commands, there are a number of shortcut keys that are available to the user to navigate the DOS command prompt faster. Because DOS does not use a graphical user interface (i.e. a mouse and pointer), knowing the shortcut keys can greatly help the user efficiently move through the screen prompts and commands. Table 2.5 lists many of the command prompt shortcut keys and their actions. (GeeksforGeeks; 2023)

Table 2.5. Useful Command Prompt Shortcuts

ShortcutMeaning
Shift+HomeExtend current selection to the beginning of a command. Press Shift+Home again to include the path (e.g., C:\ Windows\ system32) in the selection.
Shift+EndExtend current selection to the end of the current line.
Ctrl+Shift+Home/EndExtent current selection to the beginning or end of the screen buffer (respectively).
Shift+Page Up/Page DownExtend current selection by one page up or down.
Ctrl+C (or Ctrl+Insert)Copy currently selected text.
F2 and then a letterCopy text to the right of the insertion point up to the letter you typed.
Ctrl+V (or Shift+Insert)Paste text from the clipboard.
BackspaceDelete the character to the left of the insertion point.
Ctrl+BackspaceDelete the word to the left of the insertion point.
TabAutocomplete a folder name.
EscapeDelete the current line of text.
InsertToggle insertion mode. When insertion mode is on, anything you type is inserted at your current location. When it’s off, anything you type overwrites what’s already there.
Ctrl+Home/EndDelete text from the insertion point to the beginning or end of the current line.
Ctrl+ZMarks the end of a line. Text you type after that point on that line will be ignored.
F3Repeat the previous command.
Up/Down ArrowScroll backwards and forwards through previous commands you’ve typed in the current session. You can also press F5 instead of the Up Arrow to scroll backwards through the command history.
Right Arrow (or F1)Recreate the previous command character by character.
F7Show a history of previous commands. You can use the Up/Down arrow keys to select any command and then hit Enter to execute the command.
Alt+F7Clear the command history.
F8Move backward in the command history to commands matching the current command. This is useful if you want to type part of a command you’ve used several times and then scroll back in your history to find the exact command you want to repeat.
Ctrl+CWhen working with the command history, abort the current line you’re typing or a command that is currently executing.

Batch files can be written using a text editor, such as TexPad®, and saved as *.bat file. To execute, type the filename at the command prompt. Example 2.3 demonstrates how to write a batch file that will clean up the MCNP Working folder by deleting the files written to the directory where the input file is located after MCNP is used without deleting the input and output files.

During an MCNP run, the program creates runtapes, sourcetapes and other files that store some of the computational information which can be used later if needed. The naming convention in MCNP names the first runtape, "runtpe". The next run of MCNP from that same working directory will write the runtape to a file named "runtpf" and subsequent runs will alphabetically iterate the last letter of the file name through z and back to "runtpd". If the user runs files in the same working directory without deleting the runtape files, the program will exhaust names for the runtape (26 runs). This will cause a Bad Trouble error in MCNP that is troublesome because no MCNP files will run as there is no place to store the runtape. The error message on the console will not tell the user the cause and inexperienced users may believe their MCNP program has just stopped working.

The Cleanup.bat batch file deletes unwanted files and keeps the files the user needs by identifying any files with the file format for the runtape and sourcetape files along with files created by Visual Editor during plotting that are no longer needed. The batch file then deletes the files. CAUTION – all the files identified in the batch file within the working directory will be lost when this batch file is executed. An alternate approach would be to write a batch file that deleted specific files within the folder. This can be accomplished by naming the files explicitly or by using the * before the extension to delete all files of that type. For example, @ del *.txt will delete all text files in that directory.

Example 2.3

The MCNP and Visual Editor program write numerous files to the working directory that routinely need to be deleted. These include files in the format out*, runtp*, srct*, and comou* where the * indicates the last letter of the filename that is iterated each time the program runs. After 26 runs (i.e. when the alphabet is exhausted) the program will stop working. Write a batch file named cleanup.bat that will delete out all of the files of the type specified and leave other files unchanged within a directory.

Solution: Use a text editor, like Textpad® to write the following commands:

Batch file — Example 2.3, listing 1
@ rem ----- MCNP bin cleanup batch file
@ del out*
@ del runtp*
@ del srct*
@ del comou*
pause

Then save the file as Cleanup.bat. You can do that by selecting “Save as” and then using the All Files (*.*) option.

Example 2.3, listing 2

Once the batch file is created. You can execute it either by going to the file manager and double-clicking the cleanup.bat filename or going to the command prompt (click start button and type “CMD” enter) and type the following:

Program output — Example 2.3, listing 3
Microsoft Windows [Version 10.0.19045.2364]
(c) Microsoft Corporation. All rights reserved.

C:\Users\kenneth.allen\OneDrive - West Point\Documents\MCNP IO>cleanup
Could Not Find C:\Users\kenneth.allen\OneDrive - West Point\Documents\MCNP IO\srct*
Could Not Find C:\Users\kenneth.allen\OneDrive - West Point\Documents\MCNP IO\comou*

C:\Users\kenneth.allen\OneDrive - West Point\Documents\MCNP IO>pause
Press any key to continue . . .

Note that the command prompt will indicate if files of that type are not present and ask for any key to close.

Computational Design in Nuclear Engineering, second edition, by Kenneth S. Allen, Ph.D., P.E. — the complete book as a 394-page PDF.

Download the PDF