## Packages

A main program using SIC is reduced to practically nothing: For example, the main program of Mapping is

    program mapping
      !----------------------------------------------------------------------
      ! Main astro program
      !----------------------------------------------------------------------
      external :: mapping_pack_set
      !
      call gmaster_run(mapping_pack_set)
      !
    end program mapping

All the job is done by gmaster_run which declares Mapping as the master program, and calls its package setup routine mapping_pack_set.

This package setup routine named name_pack_set, where name is the package name, contains e.g. for MAPPING

    subroutine mapping_pack_set(pack)
      use gpack_def
      !
      type(gpack_info_t), intent(out) :: pack
      !
      external :: greg_pack_set
      external :: mapping_pack_init
      external :: mapping_pack_on_exit
      !
      pack%name='mapping'
      pack%ext = '.map'
      pack%depend(1:1) = (/ locwrd(greg_pack_set) /)
      pack%init=locwrd(mapping_pack_init)
      pack%on_exit=locwrd(mapping_pack_on_exit)
      pack%authors="J.Pety, N.Rodriguez-Fernandez, S.Guilloteau, F.Gueth"
      !
    end subroutine mapping_pack_set

pack is here a Fortran derived-type variable, with the following elements

- pack%name The package name (Character(len=12))
- pack%ext The default extension for procedures (Character(len=12))
- pack%depend The addresses of the package setting routines required by this package (an integer array of type Address_Length, 32 or 64 bits depending on the machine). Note that a package may depend on several other ones. The dependent packages are automatically loaded.
- pack%init The address of the initialization routine (an integer of type Address_Length)
- pack%init The address of the cleaning on exit routine (an integer of type Address_Length)
- pack%authors A character string handling the authors name

The initialisation routine referred to by pack%init must setup all the package languages, and execute any code require to provide the initial setup of the package. In addition, it is recommended to setup the messaging facility: in the example below this is done using name_message_set_id.

    subroutine mapping_pack_init(gpack_id,error)
      use sic_def
      !----------------------------------------------------------------------
      !
      !----------------------------------------------------------------------
      integer :: gpack_id
      logical :: error
      !
      ! Local language
      call init_clean
      !
      ! One time initialization
      call map_message_set_id(gpack_id)  ! Set library id
      !
      ! Language priorities
      call exec_program('SIC'//backslash//'SIC PRIORITY 1 CLEAN')
      !
      ! Specific initializations
      !
    end subroutine mapping_pack_init