4 Softlink

 4.1 Logical names and soft links
 4.2 Overview of softlink
 4.3 Details
 4.4 Defining Standard Soft Links

Softlink is a tool to provide easy, portable use of standard Starlink include files on Unix systems. It is complementary to FORCONV and will be of general use when developing Fortran programs on Unix as well as in porting code to Unix.

4.1 Logical names and soft links

Starlink Fortran programs frequently make use of INCLUDE files to define symbolic constants or common blocks. When the INCLUDE file is one supplied by Starlink, a logical name is defined on VMS to point to the file. For example, the logical name SAE_PAR points to the file LIB_COMMON_DIR:SAE_PAR.FOR. This means that the file can be included in a Fortran program with the statement:

  INCLUDE ’SAE_PAR’

There is no need to refer to the location of the file, just to its name. This makes the program more portable than referring to the explicit file.

Unix does not provide logical names, but you can achieve a similar effect by the use of soft links. A soft link looks like a file in a directory, but is actually just a pointer to another file. To use a soft link to refer to the INCLUDE file in the above example, you would type:

  % ln -s /star/include/sae_par SAE_PAR

This command should be executed in the same directory as the source of the Fortran program. If you are working on Fortran programs in different directories, you will need the appropriate soft links in each directory. This is unlike VMS, where logical names exist independently of the file system. Note that the name of the file is in lower case, but the name in the include statement is in upper case. This distinction is important as Unix is case sensitive, unlike VMS.

4.2 Overview of softlink

Softlink is a Unix shell script that can be used to create and remove soft links to files. The purpose of writing it was to automate the setting up of soft links that point to standard Starlink Fortran include files. Rather than having programs contain lines like:

  INCLUDE ’/star/include/sae_par’

they will contain lines like:

  INCLUDE ’SAE_PAR’

and a soft link to the file /star/include/sae_par will be created in the directory containing the source code. This makes the source code more portable; it may well run on Unix and VMS systems with no changes.

Before compiling a program on a Unix system, the soft links to the include files should be created. This need only be done once as the soft links are permanent. For the above example, you would type:

  % softlink /star/include/sae_par upper

Note that the name of the file being pointed to must match the name of the file in the Fortran INCLUDE statement for softlink to be effective. If the names are different, then you should either set up the soft link by hand, or use FORCONV.

4.3 Details

Softlink accepts three arguments. Only the first one is mandatory. This specifies the full path name of the file that the soft link will point to. An example is /star/include/sae_par.

The second (optional) argument specifies whether the name of the soft link is in upper or lower case. If it is omitted (or given as the null string), then the name of the soft link matches exactly the name of the file that it points to. The value of the argument can be one of ‘lower’, ‘upper’, ‘both’, ‘all’ or ‘remove’. A value of ‘lower’ specifies that the name of the soft link will be in lower case and a value of ‘upper’ specifies that the name of the soft link will be in upper case. A value of ‘both’ specifies that two soft links are to be created, one in lower case and one in upper case. A value of ‘all’ specifies that links will be created in lower case, upper case and with the same name as the file that it is pointing to if that is not purely lower case or upper case. If the argument is ‘remove’, then all the soft links are removed. The script checks to see that it is only removing soft links and not files of the same name.

The third argument is normally absent. If it is present, then the script does not execute any commands to create soft links, but writes those command to the file named by the third argument. For example, the command

  % softlink /star/include/par_par all fred

will create a file called fred containing the lines:

  ln -s /star/include/par_par par_par
  ln -s /star/include/par_par PAR_PAR

If the output file already exists, then the commands are appended to the file so that a set of link commands can be built up. If the name of the output file is mfile, then the commands are output in a form suitable for inclusion in a make file. In particular, the first character of each line is a tab character.

4.4 Defining Standard Soft Links

When writing programs that call Starlink libraries, you will find yourself setting up the same soft links over and over again. To ease this process, shell scripts are provided to define the soft links for all of the Starlink subroutine libraries. The scripts are called lib_dev, e.g. to set up the soft links needed when writing a program that calls FIO, just type:

  % fio_dev

The soft links can be removed by typing:

  % fio_dev remove

The scripts provide fewer functions than the softlink script. All links are created in upper case and the only option is remove, which does not check to see that the names referred to are soft link rather than files. To offset these restrictions, the lib_dev scripts run faster than they would if they provided all the features of softlink. The list of scripts is as follows:

Package Script
AGI agi_dev
ARY ary_dev
CHR chr_dev
EMS ems_dev
ERR err_dev
FIO fio_dev
GKS gks_dev
GNS gns_dev
GRP grp_dev
GWM gwm_dev
HDS hds_dev
IDI idi_dev
NDF ndf_dev
PAR par_dev
PRIMDAT prm_dev
PSX psx_dev
REF ref_dev
SGS sgs_dev
TRANSFORM trn_dev

There are also scripts star_dev, which creates the soft links to SAE_PAR, and adam_dev, which creates the soft links needed when writing programs that call the internals of ADAM.