Modifying the source code

To compile SWAN on your computer system properly, some subroutines should be adapted first depending on the operating system, use of compilers and the wish to use MPI for parallel runs. This can be done by removing the switches started with '!' followed by an indentifiable prefix in the first 3 or 4 columns of the subroutine. A Perl script called switch.pl is provided in the material that enables the user to quickly select the switches to be removed. This script can be used as follows:

perl switch.pl [-dos] [-unix] [-f95] [-jac] [-mpi] [-metis] [-cray] [-sgi]
               [-cvis] [-timg] [-matl4] [-impi] [-adcirc] [-netcdf] *.ftn
where the options are all optionally. The meaning of these options are as follows.
-dos, -unix Depending on the operating system, both the TAB and directory separator character must have a proper value (see also Chapter 4). This can be done by removing the switch !DOS or !UNIX, for Windows and Linux/UNIX platforms, respectively, in the subroutines OCPINI (in ocpids.ftn) and TXPBLA (in swanser.ftn). For other operating system (e.g., Macintosh), you should change the values of the following variables manually: DIRCH1, DIRCH2 (in OCPINI), TABC (in OCPINI) and ITABVL (in TXPBLA).
-f95 If you have a Fortran 95 compiler or a Fortran 90 compiler that supports Fortran 95 features, it might be useful to activate the CPU_TIME statement in the subroutines SWTSTA and SWTSTO (in swanser.ftn) by removing the switch !F95 meant for the detailed timings of several parts of the SWAN calculation. Note that this can be obtained with the command TEST by setting itest=1 in your command file.
-jac In case of parallel runs on distributed memory systems an efficient algorithm is required to parallelize the implicit propagation operator. The simplest strategy consists in treating the data on subdomain interfaces explicitly, which in mathematical terms amounts to using a block Jacobi approximation of the implicit operator. To minimize the communication volume, a recursive application of alternately horizontal and vertical stripwise partitioning is carried out. This strategy possess a high degree of parallelism, but may lead to a certain degradation of convergence properties. Another strategy is the block wavefront approach. This approach does not alter the order of computing operations of the sequential algorithm and thus preserving the convergence properties, but reduces parallel efficiency to a lesser extent because of the serial start-up and shut-down phases. The user is advised to choose the block Jacobi approach in case of non- or quasi-stationary SWAN simulations, otherwise the block wavefront method is preferable.


By default, the block wavefront approach will be applied and so the switch !WFR will be removed automatically. However, if the user want to apply the block Jacobi method then the switch !JAC must be removed while the switch !WFR should not be removed. This can be realized with the option -jac. Note that this option must be followed by the next option -mpi.
-mpi For the proper use of MPI, you must remove the switch !MPI at several places in the file swanparll.ftn, swancom1.ftn and swmod1.ftn.
-metis To enable to partition the unstructured mesh, the switch !METIS must be removed at several places in different files.
-cray, -sgi If you use a Cray or SGI Fortran 90 compiler, the subroutines OCPINI (in ocpids.ftn) and FOR (in ocpmix.ftn) should be adapted by removing the switch !/Cray or !/SGI since, these compilers cannot read/write lines longer than 256 characters by default. By means of the option RECL in the OPEN statement sufficiently long lines can be read/write by these compilers.
-cvis The same subroutines OCPINI and FOR need also to be adapted when the Compaq Visual Fortran compiler is used in case of a parallel MPI run. Windows systems have a well-known problem of the inability of opening a file by multiple SWAN executables. This can be remedied by using the option SHARED in the OPEN statement for shared access. For this, just remove the switch !CVIS.
-timg If the user want to print the timings (both wall-clock and CPU times in seconds) of different processes within SWAN then remove the switch !TIMG. Otherwise, no timings will be keeped up and subsequently printed in the PRINT file.
-matl4 By default, the created binary Matlab files are of Level 5 MAT-File format and are thus compatible with MATLAB version 5 and up. In this case the switch !MatL5 must be removed. However, some machines do not support a 1-byte unit for the record length (e.g. IBM Power6). At those computers, the binary Matlab files must be formatted of Level 4. In this case the switch !MatL4 must be removed while the switch !MatL5 should not be removed. Level 4 MAT-files are compatible with MATLAB versions 4 and earlier. However, they can be read with the later versions of MATLAB.
-impi Some Fortran compilers do not support USE MPI statement and therefore, the module MPI in swmod1.ftn must be included by removing the switch !/impi.
-adcirc To enable to do coupled ADCIRC+SWAN simulation, the switch !ADC must be removed at several places in different files. However, for a standalone SWAN simulation, the switch !NADC must be removed while the switch !ADC should not be removed.
-netcdf For the proper use of netCDF, you must remove the switch !NCF at several places in different files.

For example, you work on a Linux cluster where MPI has been installed and use the Intel\textregistered Fortran compiler (that can handle Fortran 95 statements), then type the following:

perl switch.pl -unix -f95 -mpi *.ftn *.ftn90
Note that due to the option -unix the extension ftn is automatically changed into f and ftn90 into f90. Also note that the block wavefront algorithm is chosen for parallel runs.

The SWAN team 2024-03-19