McIDAS Programmer's Manual
Version 2003
[Search Manual] [Table of Contents] [Go to Previous] [Go to Next]
In this section, you will learn how to compile your McIDAS-X source files, link object files, and store the object files in a library. You'll use the mccomp script to compile and link your code, and the mcar script to create and update libraries.
The script mccomp provides a platform-independent compilation and linking environment for McIDAS-X source files. By recognizing source file extensions, mccomp can understand some of the compile options needed by some source files. For example, if the source file extension is .for, .fp, or .pgm, mccomp calls the Fortran compiler.
The mccomp script has four options that you will frequently use when compiling source files.
Option
|
Description
|
---|---|
For example, to compile the source file program.pgm, use the mccomp script shown below. This script creates the object file program.o. The next section, Linking object files describes how to create the McIDAS-X command program.k.
mccomp -c -I. -I/home/mcidas/inc program.pgm |
Once the object file has been created, you must link the file with the necessary libraries to create the executable code. The mccomp script recognizes the platform's linking options, so you do not need to change link options when moving between platforms.
The table below lists three mccomp script options that you will frequently use for linking source files.
Option
|
Description
|
---|---|
links the command with the a directory containing the libraries |
|
To link the object file program.o created in the previous example to create program.k, run the script below.
mccomp /home/mcidas/lib/main.o program.o -L/home/mcidas/lib -lmcidas -o program.k |
Note that the script contains the object file main.o. McIDAS-X commands written in Fortran do not contain their own MAIN program. You must link the appropriate MAIN program from main.o.
See the section Writing McIDAS-X applications in Chapter 2, Learning the Basics for more information about the MAIN program. |
You may want to keep all your local functions in a local library. This makes software management much easier. Use the script mcar to put object files in a local library. The example below shows you how to compile the file foo.for and store the resulting object file in the library libdev.a.
Use mccomp to compile your function and create the object file, foo.o.
mccomp -c -I. -I/home/mcidas/inc foo.f |
Move the object file to the library libdev.a.
mcar libdev.a foo.o |
If you want to create the file bar.k to link with the function foo, use the mccomp script below. Assume the bar command is written in C so that it contains its own main.o.
mccomp bar.o -L. -L/home/mcidas/lib -ldev -lmcidas -o bar.k |
If your projects contain several source files, you may want to use a project management utility such as make to compile your code. The Unix make utility uses a description file or makefile to construct a sequence of Unix commands that the Unix shell runs. This utility helps you generate your mccomp and mcar commands. If you are not familiar with the make utility, SSEC recommends the book Managing Projects with Make (O'Reilly, 1991).
Dynamic Link Library modules (DLLs) allow functions to be linked into an application at runtime as needed, rather than when the application is initially compiled and linked. McIDAS-X does not support dynamic link modules. Instead, it emulates dynamic linking at compile time by preprocessing the module to contain unique type-based names for the API functions and imbedded common blocks. The preprocessor program, convdlm (in convdlm.fp) automatically modifies the entry point names in a unique way to avoid duplication. This mechanism is normally used in McIDAS-X for the navigation and calibration subsystems. For this process to work,
When adding a new dynamic link library to McIDAS-X, you must generate a new subsystem initialization function. For navigation, this function is named nvprep.for and for calibration it is named kbprep.for. This is most easily done using the nav_init script and cal_init scripts.
To generate nvprep.for, run the command below at the Unix prompt in the directory containing your new navigation modules.
~mcidas/mcidasversion/src/nav_init ~mcidas/mcidasversion/src/nvx*.dlm -o nvprep.for |
To generate kbprep.for, run the command below at the Unix prompt in the directory containing your new calibration modules.
~mcidas/mcidasversion/src/cal_init ~mcidas/mcidasversion/scr/kbx*.dlm kbx*.dlm -o kbprep.for |
To allow applications to access your new navigation types, recompile nvprep.for and all applications that use navigation. For new calibration types, recompile kbprep.for and all applications that use calibration. For ADDE applications, the calibration is usually done on the server, requiring relinking of the ADDE servers.
Consider the guidelines below when writing a calibration or navigation module. Most restrictions are related to preprocessing the routine with convdlm.
Write the module in Fortran, since convdlm only runs against Fortran. Using a C module will require a manual modification of the entry point names.
Write the code in uppercase. When convdlm was written, all the modules were in uppercase. The only recognized comment line begins with a C.
Don't use the words SUBROUTINE, FUNCTION, or COMMON in comment lines or messages such as DDEST. Also, in these lines, don't enter the name of any subroutine, function, or common block in uppercase.
Don't use the Fortran ENTRY statement; convdlm doesn't recognize it or handle it correctly.
Don't embed a function call within another function call if both functions are in the module. convdlm can't handle the expansion and will print an error message and then exit. For example, if SUBROUTINE ASUB(K) and FUNCTION BFUNC(J) are both in the .DLM, the following is illegal:
CALL ASUB (BFUNC(10)) |
Don't allow routines that expect character variables to be passed in (KBXINI, KBXOPT, for example), to declare the variables as CHARACTER*(*). The length of the variable is not passed along. So, in KBXINI and KBXOPT, the lengths are known and are so declared as CHARACTER*4.
Don't output text with SDEST or Fortran WRITE, for example. This causes problems with ADDE servers that send data through standard output. You can embed DDEST calls for debugging, but they will only be output with non-ADDE commands.
To look at .f files, run the process convdlm manually, since these files are automatically deleted during compiling. When compiling .DLMs on Unix, convdlm reads the .DLM file and outputs three .f files: kbxtest.dlm becomes kbxtest1.f, kbxtest2.f, and kbxtest3.f. These files are compiled, so any compiler warnings and/or errors refer to these files, which have different line numbers for the statements than the .DLMs.
To run convdlm,
use: convdlm filename
For example: convdlm kbxtext.dlm
[Search Manual] [Table of Contents] [Go to Previous] [Go to Next]