- Home
- User Articles
- How To Write ZEMAX Extensions in FORTRAN
- Home
- Programming ZEMAX
- Extensions
- How To Write ZEMAX Extensions in FORTRAN
How To Write ZEMAX Extensions in FORTRAN
- By Anthony Richards
- Published 22 June 2006
- User Articles , Extensions
-
Rating:




Building the Executable Code
I found that the following works (access to an integrated development environment such as Microsoft Developer Studio is assumed here):
- Start a C++ compile-only project, inserting a single file, ZCLIENT.CPP into it.
- Compile the ZCLIENT.CPP file using the Microsoft Visual C++ compiler, creating a Release version of the ZCLIENT.OBJ file. This needs only be done once and you will then be able to add it to any FORTRAN extension project that you wish to write.
- Start a FORTRAN project to generate a full 32-bit windows application that will be your ZEMAX extension. Select an ‘empty’ project, then add to it the files DDEFUNCS.F90, DDETYPE.F90, GLOBALS_ENV.F90, MCDGLOBALS.F90 and ZCLIENT.OBJ.
- Write your USERFUNCTION code and add it to the FORTRAN project.
- Compile and link the FORTRAN code to produce your executable, YOUR_EXTENSION.EXE (say).
- When you have debugged it and have generated a release version, copy YOUR_EXTENSION.EXE over to the ZEMAXEXTEND folder where ZEMAX will automatically find it and list it under the ‘Extensions’ drop-down menu (it is a good idea to select ‘Refresh Extensions list’ if the copying was done while ZEMAX is running).
- Start ZEMAX and load a file. As an example try SAMPLESSEQUENTIALOBJECTIVES Double Gauss 5 degree field.ZMX.
Here is a screen shot of the way the ZCLIENT.CPP file is included in a project called ‘userfunc’ and then compiled. In this case, the Microsoft Visual C++ 6.0 compiler and the Compaq Visual Fortran are integrated into the Microsoft Developer Studio environment, so, depending on the file extension (.C, .CPP, .F90 .FOR etc), the appropriate compiler is invoked.
Here is a screen shot showing how the FORTRAN project called ‘Hellofunc’ is organised. In this case the executable file has been given the name HELLOFUNC.EXE: