Magics provides a C programming interface. This interface is identical to the FORTRAN interface in terms of functionality, but with different action routine names in order to avoid conflicts with some C standard library names.

Converting From FORTRAN to C

If you wish to copy an existing FORTRAN Magics program and change it to C, then here are the things that you will need to change within the body of the program:

• In order to derive the C form of an action routine, take the FORTRAN routine name, change it to lower case and replace the initial P with mag_. For example, POPEN becomes mag_open.

• Strings in C use double quotes, not single quotes (" not ').

• Remember to place a semicolon at the end of each line.

• Remember that in C, function names are case-sensitive, but the Magics parameter names are not.

• In FORTRAN, if a 2-dimensional array is declared as DIMENSION FIELD (NLON,NLAT), the equivalent in C would be double Field[NumLat][NumLon], ie the array indices are 'the other way around'.

C Interface Example

The following example shows how to use Magics in a C program.

 

Example C program
#include <magics_api.h>

 

int main()

{

/* open magics and set the output device */

mag_open ();

mag_setc ("output_format","ps");

mag_setc ("output_name","cont_colours");

 

/* load the data */

mag_setc ("grib_input_type","file");

mag_setc ("grib_input_file_name", "data/z500.grb");

mag_grib ();

 

/* set up the coastline attributes */

mag_setc ("map_coastline_colour", "khaki");

mag_setc ("map_grid_colour","grey");

 

/* define the contouring parameters */

mag_setc ("contour","on");

mag_setc ("contour_line_colour","sky");

mag_setc ("CONTOUR_HIGHLIGHT_COLOUR", "GREEN");

mag_setc ("contour_label","on");

mag_cont ();

 

/* plot the title text and the coastlines */

mag_text ();

mag_coast ();

mag_new ("SUPER_PAGE");

 

/* Area specification (SOUTH, WEST, NORTH, EAST ) */

mag_setr ("SUBPAGE_LOWER_LEFT_LATITUDE",30.0);

mag_setr ("SUBPAGE_LOWER_LEFT_LONGITUDE", -30.0);

mag_setr ("SUBPAGE_UPPER_RIGHT_LATITUDE", 65.0);

mag_setr ("SUBPAGE_UPPER_RIGHT_LONGITUDE", 70.0);

 

/* Plot page 2 */

mag_text ();

mag_coast ();

mag_cont();

mag_close ();

return 0;

}

 

Figure 2-1. Resultant plot from example C program