| Return to Computer Support Return to PAV Home Page |
PFE-GAMS : GAMS under WindowsPhilip A. Viton
Department of City and Regional Planning The Ohio State University 190 W. 17th Avenue Columbus OH 43210 November 8, 1999
Contents1 Introduction2 Using the PFE-GAMS system 2.1 An example 2.2 Large files — the gamsrd utility 3 Upgrading PFE-GAMS 4 Getting and Setting Up PFE 4.1 Obtaining PFE 4.2 Setting up PFE 4.3 Customizing PFE 5 Setting up PFE-GAMS 5.1 Creating the GAMS configuration 5.2 PFE version 00.07.002 or later 5.3 Setting up the GAMS configuration 5.4 Last steps 6 Extensions 6.1 Command-Line Parameters 6.2 Keyboard shortcuts 6.3 Read-Only Files 6.4 Autoloading results 7 Debugging 1 IntroductionGAMS under MS-Windows is normally run from the command line in a DOS session; you would then use an DOS text editor and/or viewer to work with your output. This note describes an integrated environment, which I call PFE-GAMS, for running GAMS programs directly under Windows. With this environment you will be able to edit your GAMS source file in one window, view the results of GAMS runs in another, and switch between them just as you would with any multi-window editor. Changed files will be automatically updated. This system is based on Alan Phillips' PFE text editor, which is available as free-ware — that is, it is absolutely free, and no licensing fee is required — from many Internet sites: see section 4.1. The next section describes how you would use PFE-GAMS once it is set up; after that we explain how to obtain PFE and set up PFE-GAMS. The setup explanation is geared to Windows95/NT, and assumes that you are using the 32-bit version of PFE. There is also a 16-bit version of PFE which runs under Windows 3.1/3.11 and for which there is one important difference: those systems do not use the Registry to store configuration information, but rather rely on configuration-specific .ini files. So instead of creating a new Registry key, you will create a new .ini file. See the PFE documentation on how to do this.1 2 Using the PFE-GAMS systemWe assume that you have followed the instructions in the next sections, and now have an icon for PFE-GAMS which calls the PFE editor with the required GAMS settings. The way you use this system varies as between the first GAMS run and all others.
2.1 An exampleWe can test the system using the GAMS file swe9 located in c:\gams\users.
This is the end of the first run. GAMS creates the files swe9.lst (if you chose GAMS, or GAMS Compile) or swe9.lst and swe9.sum (if you chose GAMS+Gamsrd).
That's all there is to it. You can start a second run from the .lst or .sum windows, because the Execute menu commands pass through everything about the file except its extension, which is supplied by a batch file. If something goes wrong, then first, make sure that all the items on the Execute menu refer to the right files; see section 5.3.1. For some additional debugging hints, see section 7 below. 2.2 Large files — the gamsrd utilityGAMS can produce extremely large (multi-megabyte, under some circumstances) .lst files. While there are ways of reducing this, and while PFE can handle large files up to the memory limits of your system, it can be time-consuming to load a large file, or to page through it in search of the information you want. This section describes one solution to the problem, a way of producing a small file containing only the optimization results you need to check.2 While you can do the same thing using GAMS' put report-writing facility, the approach here is simpler — if less well formatted — requiring only the display statement. To implement this solution, you simply include a series of display statements at the end of the GAMS source file. This writes the desired results to the end of the .lst file. After running GAMS and producing the .lst file, you run the program gamsrd, which extracts the information to a separate file. For gamsrd to work, it needs to know where your summary information starts in the .lst file. To show this, you must include in your GAMS source file, a special display statement containing a keyword. This keyword must be unique to your program: it cannot be the name of any other variable or value, either supplied by you or produced by GAMS.3 Place this statement immediately before the display statements summarizing your results, like this:
where “ZQQ” is the keyword. The keyword statement can contain other information as well, but the keyword should normally be first. This statement should then be followed by the series of display statements which actually produce your summary output; and these should be the last part of your source code. Important: the keyword is case-sensitive: it must match the way the line is displayed in the GAMS .lst file. Given this, gamsrd looks for the keyword, and then writes everything that comes after it to a file you name. So for example, to write the summary information contained in myfile.lst (which is produced by GAMS) to myfile.sum you would say
or in other words
The batch file pfegamsr provides support in PFE-GAMS for this utility; the file c\gams\users\swe9.gms illustrates the source-file setup. One problem with this is that your summary file gives no indication of when GAMS was run, and this information could be important. You cannot use the display statement to write this information directly, so you need to be indirect. One solution is to have GAMS create a file with the date (and time) of the run, which you will then append to the summary file created by GAMSRD. Here's some GAMS code to do this: it creates a file datime.txt in the same directory as your .lst file.
Then add the following lines to pfegamsr.bat, to insert the contents of datime.txt at the end of the .sum file, and then delete it:
(The >nul just prevents any messages associated with the copy from appearing on the screen). It's important to delete the file, in case some other GAMS source file does not create one: if it had not been deleted, the (wrong) information would be appended to the other results. 3 Upgrading PFE-GAMSIt is occasionally necessary to upgrade the 32-bit version of PFE-GAMS, to fix bugs. Here's how (assuming that you've installed it into c:\gams\users):
4 Getting and Setting Up PFEThis section describes how to obtain and set up PFE in “non-GAMS” mode. In the next section, we set up the GAMS-specific features. 4.1 Obtaining PFEThe first thing is to obtain the correct version of PFE. There are separate builds for Windows 3.1/3.11 and for Windows 95/NT, and it is important to obtain the one matched to your operating system, because though the editor will run under an operating system mis-match, the DOS Command facility — which is at the heart of the PFE-GAMS system — will not. If you set up PFE and then find that the first menu item under Execute is grayed out, then you are probably using the wrong version. The site
is the primary source for the files, though they are widely mirrored. I strongly recommend that if you already use PFE, you upgrade to the latest version. If you are using Windows 3.1/3.11 then you must use PFE version 00.07.002 or later: although the configuration-specific .ini file option was present on earlier versions, it didn't work correctly. Version 00.07.002 fixed it. Important note, November 1999. Alan Phillips has announced that development of PFE has ceased. I very much regret this — PFE is a wonderful editor — and I'm leaving the link to Lancaster in place in the hopes that he'll reconsider. Meanwhile, the final versions of PFE are available at
— look there for pfe101i.zip (Win 95/95/NT/2000) or pfe101.zip (Win3.1x). 4.2 Setting up PFECreate a directory on your hard disk for PFE, calling it (say) c:\pfe. Change to that directory, and unzip PFE's .zip file into that area. If you're updating your PFE system, just over-write the older files (updating preserves Registry information in the 32-bit version). Now create a shortcut for the basic PFE program. Choose a folder or your Desktop, then right-click. Select New then Shortcut. Reply to the dialog as follows:
Click Finish and the PFE icon will appear. 4.3 Customizing PFEStart PFE by double-clicking on its icon. Then click Options then Preferences. You see a number of items displayed in a list on the left of the window. You can now make any changes that you might want to have available in all configurations of PFE. You can look through the list and see what you want to change: one thing is to create backup files with the extension .bak: the default is to use the extension .$$$, which I for one do not like. To change this:
when you have made any changes you want, click OK. This updates PFE's default configuration set. 5 Setting up PFE-GAMSIn this section we describe how to set up the features which make GAMS usable from within PFE. Begin by creating an area (folder) for some files associated with the PFE-GAMS system. In what follows I assume that this directory is c:\gams\users.Copy the file pfegams.zip to this folder, unzip them; you may now delete the .zip file. You will have the following files:
The two batch files are the crucial ones. As distributed, they assume that your GAMS executables reside in c:\gams\nt and subdirectories. If you have installed GAMS to a different location, you must edit both batch files and fill in the correct locations. 5.1 Creating the GAMS configurationWe now create a special PFE setup for running GAMS programs. Start PFE, and click Options then Preferences and click on the item Configuration Sets. This opens a dialog box which allows you to create special configurations in the system Registry. To the right you see three boxes, for Default Startup Configuration Set, Current Active Configuration Set, and Configuration Sets. All currently say the same thing, namely, DefaultConfiguration.
Quit PFE. We now create a separate shortcut for the PFE-GAMS system.
At this point you can customize the shortcut. We supply a PFE-GAMS icon (c:\gams\users\pfegams.ico), which you can substitute for the default PFE icon. In addition, you may want to have PFE-GAMS start in a more convenient folder, one closer to your GAMS source files. Either of these changes can be made by right-clicking on the PFE-GAMS icon, selecting Properties and making the necessary changes. If you are using PFE version 00.07.002 or later go to section 5.2. Otherwise go to section 5.3 5.2 PFE version 00.07.002 or laterVersion 00.07.002 of the PFE editor was released in January 1998. The 32-bit version contains a quick way of setting up the PFE-GAMS system, the ability to write and read a configuration file. The distribution of the PFE-GAMS system includes a file pfegams.rcf which incorporates all the facilities discussed below, so you don't have to set each item by hand. Here's how to import the configuration:
If you have placed the PFE-GAMS batch files in a directory other than c:\gams\users you will need to change their locations on the Execute menu. To do this:
That's all there is to it (except that you may want to read the material in section 6); you can now test the PFE-GAMS system, as described in section 2.1. 5.3 Setting up the GAMS configurationThis section contains detailed steps for creating the GAMS-specific configuration for PFE. Remember, if you are using PFE version 00.07.002 or later, you can avoid all this work by using the configuration-import technique described in section 5.2 Otherwise, double-click on the PFE-GAMS shortcut you created in section 5.1. PFE will start. Click Options then Preferences, then click on the item Configuration Sets. You should see that the Current Active Configuration Set is GAMS. You're now ready to modify this for GAMS-specific settings. 5.3.1 Add the Execute Menu itemsWe first add support for running GAMS from within PFE. Click Execute Menu.
We now create a second GAMS command, which allows you to compile without executing your file.
The last step is optional, and should be added only if you want to work with the GAMSRD utility for creating short summary files from GAMS' .lst file, as described in section 2.2. In that case:
5.3.2 Configure the File Filters for GAMS filesNext, click on File Filters. We'll add a file filter so that, when you click on the Open dialog, you see only files with extensions relevant to GAMS.
5.3.3 Other configuration itemsUnder General Options, make sure that the box “Check disk files for changes by other applications” is checked. Make any other changes you'd like in the list. Under MRU List you may want to change the number of files shown in the list from 5 to 9; it will make your work easier if you check the box “Change directory on opening file”. Under Screen Font, you may want to change the default font used for your editing: I prefer Courier New, Bold, 9 point; but it's up to you. Click OK. This saves the configuration in the Registry. Lastly, set up PFE's print facility.
Note that there is an interaction between the printer font point size and the PW entry in the pfegams batch file. PW controls the width of the lines written by GAMS: you should adjust the PW value so that at your chosen printer font point-size the entire line fits on a page. 5.4 Last stepsIf you created the GAMS+Gamsrd command, the batch file pfegamsr will first run GAMS on your source file, and then run the gamsrd program to extract a summary file. The batch file is set up to produce a summary file with extension .sum, and to expect that the required “marker”(see section 2.2) is ZQQ. If you wish to change either of these, edit pfegamsr.bat: note that if you change the extension you should also change the file filters as described in section 5.3.2. If you would like the DOS window created by the batch files to remain visible for a few extra seconds after GAMS has finished, you can edit the batch files pfegams.bat or pfegamsr.bat in your \gams\users directory, and add the command c:\gams\users\wait n as the last line, where n is the number of seconds to wait. You can now test the system, as described in section 2.1. However, the next section describes some additional features you may want to consider adding to your setup. 6 Extensions6.1 Command-Line ParametersIf you need to include additional command-line parameters (as described in Appendix B of the GAMS manual) in all your GAMS work you can do so in two ways:
PFE has a sophisticated set of ways to pass directory and file information to external programs: look under sub[stituting current filename] in PFE's Help Search for Help On feature for more information. 6.2 Keyboard shortcutsWith the setup described thus far, you run or compile a GAMS program by making its window active and then using the mouse to click on Execute and then the menu item you want. I find that it's a lot easier to avoid the mouse, and start GAMS using a keyboard shortcut. Here's how to set this up. First, we'll have Alt+R (“R” for “run”) do a GAMS run — ie act as a shortcut for item 1 on the Execute menu:
Next, we'll set up ALT+C (“C” for “compile”) do do a GAMS compliation, assuming that this is item “3” on the Execute menu:
Now save the file:
Finally, tell PFE-GAMS to load this file at startup:
6.3 Read-Only FilesPFE “knows” if files have been altered, and will ask you whether you want to save any altered files before it will Compile or Run a GAMS program. You can save yourself some effort by declaring certain files as Read-Only from the start. Here's how to make GAMS's .lst files Read-Only. In PFE-GAMS:
6.4 Autoloading resultsYou can set up PFE-GAMS to automatically load files produced by the run: if you have an old version of the file already loaded into PFE, doing this avoids the dialog which tells you that the file has been changed, and asks your permission to update it. To force PFE-GAMS to always load the .lst file produced by your run, add the line
to the end of your batch file pfegams.bat. You can go even further and conditionally load a file. For example, to load the .lst file after a compilation only if something went wrong, add the following to pfegams.bat immediately after the call to GAMS (in particular, this must precede the call to the wait program if you use it):
Note that this relies on the batch file containing the string a=c with the “a” being the fourth batch parameter, and the “c” being lowercase. If you alter the batch file you will have to check that this is still correct. 7 DebuggingIf something goes wrong, you will need to see what information PFE is passing to the batch files, and to do this, you will need the DOS window created by the batch files to stay on the screen after the batch file finishes, long enough for you to diagnose what's going on. To have the window persist, edit the batch files in c:\gams\users and add a line saying
to the end of the files (or a larger value if you're a slow reader): the effect of this is that the window remains longer on screen before being closed by PFE, and you can see what the batch files are doing. If you are doing complicated parameter passing, you may want to see directly what each batch file parameter is. One way to do this is to add a series of lines of the form
to the batch file you're testing, and then use the wait feature described above to make the information remain on screen. Last Revised: November 8, 1999 at 19:24 PM |