European Organization for Nuclear Research

Accelerator and Beam Physics Group, AB Department

MAD-8 on Windows

MAD Home page         Windows versions of MAD

This page was moved to a new URL on 05-Apr-04.

Fix to MAD8.BAT file: 30-Aug-06: a path in the file was wrong and has now been fixed.  The file also now has DOS line-end characters.

Latest update to MAD8 program: 03-Mar-04: this is a bug fix with no new version number to keep in step with the latest Linux version. Changes are connected with sign convention of t1 tilt of multipoles and the FINTX parameter.   If you already have MAD8 on your PC, the only file changed in the distribution ZIP file is mad8.exe itself so you can simply replace that in your installation.

19-Feb-03: (a small bug fix to the version of 21-Jun-2002) , new version of MAD8 available, fixes some bugs, instructions below improved, including more set-up information on Windows 95, 98 (as well as NT, 2000, XP).  You are recommended to upgrade to the new version. 

January 2002: you can run MAD entirely within KEDIT and benefit from automatic syntax colouring for the MAD language.  

Installation Procedure

This is a procedure for installing your own copy of (the latest 8.51/15 or later ... ) MAD Version 8 for Windows.  This version of MAD8 should be identical to the Linux and Unix versions with the same version number currently available at CERN.  


It does not explain how to create input files for MAD nor the physics involved.  


MAD8 runs on 32-bit Windows systems (e.g. Windows NT, Windows 2000, Windows 98, ….).  

MAD8 should be installed on your hard disk for autonomy and performance reasons.  It uses very little disk space. The ZIP file is easily downloaded even over a slow connection or can easily fit on a diskette.


The manual installation described in the following may be superseded in due course as we hope to arrange for automatic centralised installation in CERN.  It is not very complicated but please follow the details carefully.  


Under Windows there are a number of possible ways to run a program like MAD.  The choice between them is partly a matter of taste and convenience.  However the "minimum" procedure described first is certainly not the most convenient: most users will prefer to set up file associations as described further down.

Minimum installation procedure (necessary in all cases)

(Recommended folder paths were changed on 17/3/2005!!)

  1. Download the zip file and open it  (with WinZip or a similar utility).  

  2. Create a sub-folder of your PC’s  "Program Files" folder called "mad".  Normally the following link will open it:

            C:\Program Files\mad\

  3. Extract the contents of the ZIP file to this folder.   If you already have a "mad8" folder there (from a previous version), you should delete it.

  4. This should create a folder file:///C:/Program Files/mad/mad8 looking like something this:


  5. Then, to run MAD, you can create a shortcut to the mad8.bat  file in any convenient place (Desktop, SendTo … ) and drag MAD input files onto it.  However it is much better to set up proper file associations (see below).

That’s the necessary minimum you need.  This recipe should work for all 32-bit Windows systems (i.e., Windows 95 and later).

Terminal Sessions

You may like to start the MAD8 program directly, by double-clicking, say, the mad8.exe file’s icon in order to get a text-based terminal session in Unix  style.  

  1. You must first set an environment variable giving the location of the MAD8 "dictionary file".  In Windows NT, 2000, XP you can do this from the System icon in the Windows Control Panel.    Create a USER environment variable called DICT and give it the value 

    C:\Program Files\mad\mad8\mad8.dic

    (The dialogue boxes shown above are for Windows 2000.  They are slightly different on NT.)
    For Windows 95, Windows 98, Windows ME (probably, we have not checked), you can set this variable by
    adding the line

    SET DICT=C:\Progra~1\mad\mad8\mad8.dic

    to your C:\autoexec.bat file. Reboot your PC for it to take effect (you can check by typing SET at a command prompt).

  2. Once you have decided on your shortcut to start terminal sessions you can right-click it to change the start-up directory to, say your "My Documents" folder:

    wpe1.jpg (52974 bytes)

  3. You can further customise the behaviour of terminal windows by clicking on the Window menu/Properties (top left hand corner of the terminal window).  You can then choose to have the settings applied to all future windows started from the same shortcut. This is highly desirable since the default window is rather small.   Here are my settings:

    wpe2.jpg (21532 bytes)
    wpe5.jpg (35588 bytes)

  4. This gives a nice big window with a scroll bar and the QuickEdit feature (right-click to copy or paste information in the terminal window; if something is selected it may beep when you try to type - hit "Esc").  

  5. Unix people should feel at home, except that they would nee a separated shortcut for starting up MAD8 in every folder where they might go to work.  To get real Unix behaviour, put the MAD8 program folder on your PATH environment variable and start it as a command in a generic command-prompt window ...

File associations, how to run MAD in the "usual" Windows style

The following procedure assumes that Microsoft Access has already been installed on your computer.  If that is not the case, the procedure is simpler (but is not detailed here). You will have to create a new filetype with the .mad extension. 

At least on Windows 2000, I have managed to break Microsoft Access’s hold on the .mad extension: in the Windows Explorer as follows. 

  1. First set up the DICT environment variable as described under "Terminal sessions" above.

  2. Go to Tools/Folder Options/FileTypes, find the MAD extension in the list, click Advanced, create a new action by browsing to the mad8dl.bat file to get:   

  3. I also changed the name of the “Open” or "Design" action for clarity, in case I ever use the original Access type of file (probably a rare occurrence) and created a KEDIT action that is my default for MAD files:

    You can replace KEDIT with any other editor for plain text files that you use. 

    If you exchange files with Unix systems, it is better to set your editor to use the Unix line-end (LF-only) convention (rather than the CR-LF that is used by programs like Windows Notepad.  In KEDIT this is accomplished with SET  EOLOUT LF (I use this as default for all files).  
    (Side remark: you can get into a mess if you use editors like Notepad or Wordpad.  Also avoid transferring files using the ancient FTP protocol, the Netscape browser or Netscape mail.  All of these try to turn you against Windows by adding CR-LFs to your files without telling you.  This list of bad ways to transfer files is not exhaustive.  Good ways include the AFS client for Windows or the HTTP protocol in Internet Explorer.)

  4. You can also change the description of the file type from "Microsoft Access Module Shortcut" to "MAD input" and check the "Always show extension" box.  

  5. For easy visual identification of MAD files, change the icon of .mad files to the MAD8 icon in the MAD8 program folder.  All of this seems to work fine in practice.  With this setup, double-clicking a MAD file opens it in KEDIT, or you can run MAD on a file by right-clicking and then selecting MAD8 from the menu.  It should look something like this:

Expert - and very confident - users can accomplish all the above steps more quickly by downloading this registry file. Only execute this file if  you understand exactly what it does - we take no responsibility!!

MAD within KEDIT

It is also convenient to run MAD8 from within the KEDIT editor and see the output immediately.  The ZIP file contains some additional files to facilitate this.  Do the following: 

  1. Move or copy the files 


    from the  C:\Program Files\mad\mad8 folder to your KEDIT User folder (usually C:\Program Files\KEDITW\User , a sub-folder of the folder where KEDIT is installed).  
  2. To switch on MAD syntax recognition for file extensions that usually indicate MAD files, add these lines (or similar) to your profile file for KEDIT (usually winprof.kex in the User folder):

    if initial() then do
    "set parser mad mad.kld"
    "set autocolor .mad mad"
    "set autocolor .mmad mad"
    "set autocolor .seq mad"
    "set autocolor .opt mad"
    "set autocolor .str mad"
    "set autocolor .mou mad"
    "set autocolor .tfs mad"

    For further information see KEDIT's help for KEDIT language definition (KLD) files. 
  3. Having done this you can simply type "mad" on KEDIT's command line to run the contents of the current file through MAD and immediately view the terminal output in another KEDIT window.  If the file starts with the MAD command 
    then all the print output will be in the same file.  

Note that, to avoid saving the current file (which need not even have a name yet), a copy of its contents is saved in a temporary input file.  Unless you take steps to save them under different names, this temporary input and the corresponding output file will be overwritten each time you run MAD.

With the language definition feature, the MAD syntax is recognised and coloured helpfully.  Here are some screen images: 

MAD from Mathematica

It is possible to use the Mathematica Front End to capture MAD’s terminal output and send the input; this is rather like an enhanced terminal window. 


However I often run this version of MAD inside Mathematica functions.   I will explain this in more detail elsewhere but meanwhile here is an example in PDF format.

Graphics from MAD

As usual, the MAD graphics are created in a postscript file with the hard-wired file name so unfortunately you cannot tell which input file it is associated with.  This file is overwritten each time MAD runs.

It is possible to view these with the Ghostview program ( that is also available for installation in the Windows 2000 Control Panel at CERN).  However it is much more convenient to install Acrobat.  Then the PS will automatically be converted to compact PDF files and you can work with them in Acrobat.

MAD input files

It seems that the Windows MAD will accept input files with either the Unix or DOS type format (line-end characters).  Personally, I edit MAD files with KEDIT, and have it set to save them in Unix format anyway.  Then I can use the same files on all systems with no changes. 

Uninstalling MAD8 

The following has not been tested:  Just delete the program installation directory mentioned above.  If you made file associations, you can follow the reverse of the procedure to create them above.  Or open the registry editor and search for "MAD8".  You should find something like

Delete the KEDIT, MAD8 etc keys and rename the MS Access key as just plain "Open" or "Design" to put it back how it was.  You should probably also put back the Access icon.

You can also delete the key corresponding to the  DICT environment variable.

That should do the trick but this is all at your own risk.

About the batch file

Compared with the original SLAC/Daresbury version I have adjusted contents of mad8.bat as follows.   There are some slightly tricky details, explained in the comments in the file itself.  Please check these in case of problems.


@echo off

rem Batch file for launching MAD8, John Jowett, CERN 22/8/2001.
rem Derived from earlier version written at SLAC by Mark Woodley.

rem This is a wrapper for the MAD8 executable which is necessary only because
rem MAD8 (being a very old program written for old systems like Unix)
rem does not accept input file names as command-line arguments.
rem This could be changed in the Windows version but I decided to change the
rem source code as little as possible to simplify maintenance.

rem If you start the executable (mad8.exe) directly, the DICT environment variable must already
rem be set to the path to the mad8.dic file (as below).
rem This is not necessary if the executable is started by this .bat file.

rem The main purpose of this .bat file is to allow you to keep MAD input files
rem in any convenient working folder (without this people end up keeping them in the
rem program folder which is undesirable).

rem One way to use this it to make a shortcut to the .bat file in a
rem convenient location (e.g. desktop, working folder, ...) and drag input files
rem onto the shortcut icon.

rem This file assumes that you have installed the mad8.dic and mad8.exe files in
rem the locations
rem "C:\Program Files\mad\mad8\mad8.exe"
rem "C:\Program Files\mad\mad8\mad8.dic"
rem (which are the recommended ones for a typical Windows PC).
rem In case of problems, or if you have installed the MAD files in another
rem location, please check that they are precisely correct and adapt if necessary.

rem Note that, in this file, you cannot use long forms like
rem      "C:\Program Files\mad\mad8\mad8.exe"
rem Instead, you must use the "8dot3" type file names like
rem      "C:\Progra~1\mad\mad8\mad8.exe"
rem Conceivably, "C:\Program Files" might not map to "C:\Progra~1".
rem You can check the mapping of long to short names with

rem        DIR /X 

rem at the Windows command prompt.
rem --------------------------------------------------------------------------------
rem --------------------------------------------------------------------------------

rem Go to folder containing the input file and execute from there.
rem from there

pushd %~dp1

@echo off
set fname=%1

rem set up a (local) environment variable with dict file location

set DICT=C:\Progra~1\mad\mad8\mad8.dic

rem Check that worked by uncommenting next two lines:
rem set
rem more < %dict%

rem run MAD8, syntax here seems to be critical

rem pause to look at terminal output

@echo on

Programming Notes

MAD8 has been compiled using Compaq Visual Fortran Version 6.1.  Both MAD8 and MAD8DL can be built as two different projects in the same workspace (although almost every routine in the source code is different between the two versions).  There are only two source files that have to modified by hand to compile under Windows.  

Additional information

Some transparencies shown at the CERN SL AP group meeting 23/8/2001.  They include a performance comparison of MAD8 on different computers and operating systems.


JMJ (Please do not contact me with general questions about MAD Version 8, instead consult the main MAD8 Web pages.)

Last modified: 30-Aug-06