GNU Astronomy Utilities


Previous: , Up: Program source   [Contents][Index]


11.4.2 The TEMPLATE program

The extra creativity offered by libraries comes at a cost: you have to actually write your main function and get your hands dirty in managing user inputs: are all the necessary parameters given a value? is the input in the correct format? do the options and the inputs correspond? and many other similar checks. So when an operation has well-defined inputs and outputs and is commonly needed, it is much more worthwhile to simply do use all the great features that Gnuastro has already defined for such operations.

To make it easier to learn/apply the internal program infra-structure discussed in Mandatory source code files, Gnuastro ships with a template program when using the Version controlled source. It is not available in the Gnuastro tarball so it doesn’t confuse people using the tarball. The bin/TEMPLATE directory in Gnuastro’s clone contains the bare-minimum files necessary to define a new program and all the necessary files/functions are pre-defined there. You can take the following steps if you want to add a new program to Gnuastro:

  1. Select a name for your new program (for example myprog).
  2. Copy the TEMPLATE directory to a directory with your program’s name:
    $ cp -R bin/TEMPLATE bin/myprog
    
  3. Open configure.ac in the top Gnuastro source. This file manages the operations that are done when a user runs ./configure. Going down the file, you will notice repetitive parts for each program. Copy one of those and correct the names of the copied program to your new program name. We follow alphabetic ordering here, so please place it correctly. There are multiple places where this has to be done, so be patient and go down to the bottom of the file. Ultimately add bin/myprog/Makefile to AC_CONFIG_FILES, only here the ordering depends on the length of the name.
  4. Open Makefile.am in the top Gnuastro source. Similar to the previous step, add your new program similar to all the other programs.
  5. Change TEMPLATE to myprog in the file names and contents of the files in the bin/myprog/ directory.
  6. Run the following command to re-build the configuration and build system.
    $ autoreconf -f
    

    Your new program will be built the next time you run ./configure and make. You can now start adding your special checks/processing.


Previous: , Up: Program source   [Contents][Index]