Next: , Previous: Customized Coding, Up: Customized Coding


5.1 Customized Program Templates

Whenever a new project is begun with the spaopen (with flags as appropriate) command, a FORTRAN90 main program template is loaded into the newly-created directory. The template will have the same name as the project, but with a .f90 extension. (Note that there is also a configuation file generated in the directory, named settings.cfg .) Although the template main program will compile and execute without modifications, any useful project will require the modification of the template to fit the specific requirements of the work.

Remember that the purpose of the main program is to interface with the subprograms of the library and of the project; this is not the place to implement calculations and new functionality since any such modifications will not be able to be transferred to the archive. As the archive changes, so too do the template programs, so a template that you created some time ago may no longer work with newer versions of the archive (although we try to maintain backwards compatiblity as much as possible). This is no problem if you've added a couple of read/write satements and a subprogram call to the template file, but will be particularly irritating if you have spent hours creating a monolithic main program out of the template. Obey good coding practices by using subroutines to abstract the functionality of your code and you will be much better off in the long run.

Each standard template file consists of nine parts:

  1. Module loading (use association of SPA modules);
  2. Program information and header;
  3. Variable declarations;
  4. Fetching of configuration information (from settings.cfg: call to getParams;
  5. Initialization and opening of input/output files: call to openGridFiles;
  6. Setup of the time-looping for the main program loop: call to timeLoop;
  7. Determine grid information and allocate data arrays: calls to getGridSize and getGridInfo;
  8. Creation of data descriptor, dim: call to makeDim;
  9. Loop over times for read/manipulate/write: calls to readGrid and writeGrid.

As you can probably see from this list, much of the hard work involved in setting up for your calculations has already been done for you. Throughout the code (it would be a good idea to start a test project now so that you can follow along, if you haven't already) you will see MODIFY comments (only 5 in the current implemenation). These alert you to areas in which you may have to make changes, specifically, items 1, 3, 6, 7 and 9 above. Most of these changes will be very minor (ie declaration and allocation of data arrays for your work).

For alternate templates, such as the composite and observational templates (accessed using the -composite and -obs flags to the spaopen call, respectively) the nature and number of modifications may vary. This is particularly true for the observational template where the calls, while conceptually similar, vary in syntax and type.