Running GEMPACK from the command prompt

Most new GEMPACK users start with the WinGEM, RunGTAP or RunDynam programs. These three Windows programs interface with or control the command-line (text-interface) programs that form the heart of GEMPACK. However, you can instead run GEMPACK directly from the command-prompt -- and sometimes this is more convenient.

After you know how to run GEMPACK from the command-prompt, you can easily use batch files to automate running sequences of programs. More about that here.

The command-prompt is often also called the "command line interface" or "DOS box".

If you are familiar with command-prompt concepts, you could skip the next section and go to straight on to command-prompt GEMPACK.

Basic Command-prompt

To launch a command-prompt: from the Start button, choose Run, and type in "cmd". The command-prompt (usually a black window) should appear.
DOS box

To the left of the blinking cursor is shown the current directory -- a very important concept. The terms "directory" and "folder" mean the same.

If you like, make a desktop shortcut to the command prompt (often located at C:\WINDOWS\system32\cmd.exe).

Basic DOS commands

Type commands into the command-prompt and press Enter. You should be (or become) familiar with the basic DOS commands:

dir/w          list files in current folder 
dir/?          show help on the dir command  
dir/od *.log   list LOG files in date order, most recent last
dir/os *.zip   list ZIP files in size order, biggest last
type notes.txt display short text file
cd test        go to sub-folder test
cd "My test"   go to sub-folder My test; NB: use double-quotes to enclose folder name containing spaces
cd ..          go to the folder above the current folder
cd \           go to the "root" or top-level folder
del data.har   delete file data.har
del "F 1.har"  delete file F 1.har; again note double-quotes around file name containing spaces 
del/?          show help on the dir command
del *.bak      delete all the files in current directory with suffix BAK
md test3       create new subdirectory test3
md \tt         create top level directory tt
path           show current PATH (list of folders that DOS or Windows searches to find programs)
rd/s test      remove subdirectory test
copy data.har data0.har         make a copy of file data.har
copy data.har c:\project3\data  copy data.har to folder c:\project3\data
move  *.let  c:\letters         move (as opposed to copy) all LET files to c:\letters
ren data.har data2.har          rename file data.har to data2.har
findstr/i/n  "error" *.inf      show lines containing 'error' in INF files

Above, the black text is what you type; do not type in the explanatory red text. The command-prompt is not case-sensitive.

Wild-card characters '*' and '?' in file names

Several commands allow 'Wildcards' to be used to specify files. The wild card character '*' represents any group of characters, while the '?' character matches any one character. For example:

*.log      matches all files with suffix LOG
sim*.log   matches all files beginning with 'sim' and with suffix LOG
sim?.log   matches files beginning with 'sim' followed by 1 character, then suffix LOG
model3.*   matches all files beginning with 'model3', with any suffix

Learning more about the command-prompt

Microsoft has provided online help ... if you can find it ! Click on the Desktop, and press F1 -- "Help and Support Centre" should appear. Then search for command-line reference. As shown above, you can also get help on a particular command by typing it from the command-prompt with the "/?" option.

Customizing your command-prompt

Press Alt+spacebar+p (or click the upper-left corner of the command-prompt window, then click Properties). You can make various changes, but make sure (on the Layout tab) to set the Screen Buffer Height to at least 3000. This will help you to use the vertical scroll bar to see text that scrolled above the currently-visible part of the command-prompt.

Right-click on desktop, choose Properties..Appearance..Advanced...Inactive Title Bar, and set its color 2 to yellow. This helps to prevent you trying to type into a non-active command-prompt.

Copy/paste to and from the command-prompt

To copy text from command-prompt to clipboard:

  1. Right-click in main part of command-print window; choose "Mark".
  2. Select text by dragging with left mouse button.
  3. Press Enter to copy to clipboard.

To paste text into command-prompt from clipboard, right-click in main part of command-print window, and choose "Paste".

Copy/paste works a bit differently if you selected "QuickEdit mode" on the Options tab of the command-prompt Properties dialogue (see previous section). In that case you can omit step 1 above, and you paste by merely right-clicking the main part of the command-prompt window.

Opening a command-prompt in the right folder

It's easier if the command-prompt opens in the folder where you want to work. The TABmate File menu offers a 'DOS box in current folder' command, which puts you in the same folder as the most-recently-opened file. Another method is available if you downloaded the "bundle" programs from here. Using Explorer, double-click (and run) the file DosDrop.Reg in your GEMPACK folder. You only need to do this once. Afterwards, from Explorer, you can right-click on any folder and choose the option 'Drop To Dos' to open a command-prompt in that folder.

If you made a desktop shortcut to the command-prompt (see above), right-click on the shortcut and choose Properties..Shortcut. Set the "Start in" folder to C:\MyModels (or whatever you wish for the default command-prompt folder).

Avoiding re-typing

There are several tricks to save typing:

Redirecting output to a file

The Dir command shows files on the screen. But if you type:

dir    >Log.txt
notepad Log.txt

you should see that a file Log.txt has been created which contains just the same list that "dir" would send to the screen. This trick works with other commands too (not just dir), and has many uses.

The PATH

Although common commands such as DIR, CD or DEL are part of Windows (ie, there is no file DIR.EXE) most other commands correspond to EXE files. If you type TABLO, Windows searches through a list of folders to find and execute TABLO.EXE. That list is called the "path"; you can see its contents by typing PATH from the command-prompt.

It is vital that your GEMPACK folder (normally C:\GP) is on the PATH -- otherwise the GEMPACK programs cannot be located. Instructions for changing or extending the PATH are here.

Command-prompt GEMPACK

Checking the PATH

Open a command-prompt and type:

tablo

TABLO should start running (press Ctrl-C to stop it). However, if instead you see the message:

'tablo' is not recognized as an internal or external command,
operable program or batch file.

your GEMPACK folder is not on the PATH -- please read the previous section.

Compiling and running TAB files

We'll assume you have a TAB file Model3.TAB, and that you have a command-prompt open in the folder where Model3.TAB is. Commands differ slightly according to whether you have the Exe-Image (GEMSIM) or Source-Code (FORTRAN) version of GEMPACK.

... with Executable-Image GEMPACK

To make TABLO process Model3.TAB type:

tablo -pgs model3

TABLO should run and finish with the message:

  (The program has completed without error.)
  Total elapsed time is:  2 seconds.

If you type:

dir/od *.gs?

you should see that GSS and GST files have just been created.

If (as is common) your model uses a condensation file (called, say, Model3.STI) containing substitution or backsolve instructions, you need to follow a slightly different procedure. Make the GSS and GST files by typing:

tablo -sti model3.sti

To run Model3, with closure and shocks contained in the file Model3.cmf, type:

gemsim -cmf model3.cmf

GEMSIM should run, finishing with a "completed without error" message. Check that a solution (SL4) file has just been created by typing:

dir/od *.sl4

Compiling and running TAB files with Source-Code GEMPACK

To make TABLO process Model3.TAB type:

tablo -wfp model3

TABLO should run and finish with the message:

  (The program has completed without error.)
  Total elapsed time is:  2 seconds.

If you type:

dir/od *.ax?

you should see that AXS and AXT files have just been created.

If (as is common) your model uses a condensation file (called, say, Model3.STI) containing substitution or backsolve instructions, you need to follow a slightly different procedure. Make the AXS, AXT and FOR files by typing:

tablo -sti model3.sti

A line near the end of the STI controls whether Fortran (wfp) or GEMSIM (pgs) code is produced. To compile the Fortran code, type:

LTG model3

and use DIR to check that LTG produced model3.exe. Then, to run Model3, with closure and shocks contained in the file Model3.cmf, type:

model3 -cmf model3.cmf

Model3.exe should run, finishing with a "completed without error" message. Check that a solution (SL4) file has just been created by typing:

dir/od *.sl4

If there was a problem, the cause should be shown near the end of the screen output. Most programs produce a LOG file which you can open with TABmate; the error should be described near the file end. The relevant LOG file will be the most recently produced one: type

dir/od *.log

to see which that is.

Running GEMPACK Windows programs from the command-prompt

Most of these programs allow command line arguments. So you could type:

ViewHAR data3.har   open data3.har in ViewHAR 
ViewSOL sim7.sl4    open sim7.sl4 in ViewSOL 
TABmate Model3.tab  open Model3.tab in TABmate 

TABmate and ViewSOL let you open multiple files, using the * wildcard:

TABmate *.tab       open all the TAB files 
ViewSOL p*.sl4      open all SL4 files that begin with "p" 

Type the black text above (not the explanatory red text).

Automating the running of a sequence of commands

You can create a text file with BAT suffix that contains a sequence of the commands listed above. Say you created a file DOSIM.BAT, containing the lines:

tablo -sti model3.sti
gemsim -cmf model3.cmf
dir/od *.sl4

Then if you typed at the command-prompt:

dosim.bat

all 3 commands would be executed. BAT files offer many possibities to mechanize and speed your work.
Read more about them here.

Combining Windows and command-line programs

A typical work sequence is: editing a TAB file; running the TAB program; and examining data or results. Usually a mistake or sub-optimality is noticed; so the TAB file is edited and the whole cycle is repeated -- usually many times. During this iterative process, the screen might appear as below, with TABmate, command-prompt and ViewHAR windows visible.

desktop

The followings steps would be repeated:

The three arrows in the TABmate icon TABmate icon are intended to evoke the repetition of these three steps.



See also
Automating GEMPACK with batch files
GEMPACK FAQ Page