PALM installation#

Use these instructions to install PALM and enable its use with either MATLAB or Octave. These instructions were written for PALM version alpha-1.1.2.

1. Download PALM#

To install PALM for use with QuNex, we recommend to generate a folder PALM within $TOOLS directory, and either download or clone the current version of PALM from https://github.com/andersonwinkler/PALM in this directory. If you are planning to support the use of PALM with both MATLAB and Octave, we recommend creating two copies of the PALM distribution with different names, e.g.:

$TOOLS/PALM/palm-alpha112m      # to use with MATLAB
$TOOLS/PALM/palm-alpha112o      # to use with Octave

2. Set up PALM#

Open $TOOLS/PALM/palm-alpha112m/palm and/or $TOOLS/PALM/palm-alpha112o in a text editor and set up the following variables:

# To use with MATLAB
WHICH_TO_RUN=2
MATLABPATH=<path to your MATLAB installation>

# To use with Octave
WHICH_TO_RUN=1
OCTAVEPATH=<path to your Octave installation>

3. Compile mex files#

We have found that for use with MATLAB, no compilation of mex files was required; however, to work with Octave additional steps had to be taken. In all the following steps, $PALMPATH refers to the location of the PALM distribution, e.g. $TOOLS/PALM/palm-alpha112o.

Compile @file_array mex files:

cd $PALMPATH/fileio/@file_array/private
./compile.sh

mv file2mat.m x_file2mat.m
mv init.m x_init.m
mv mat2file.m x_mat2file.m

In our experience the last three lines were necessary, as Octave was loading the .m files instead of the compiled .mex files even when the latter were present. The same strategy of masking the .m files is employed in the following steps.

Compile @gifti mex files:

cd $PALMPATH/fileio/@gifti/private
./compile.sh

mv zstream.m x_zstream.m

Compile @nifti mex files:

cd $PALMPATH/fileio/@nifti/private
octave
mkoctfile --mex nifti_stats.c nifti_stats_mex.c -O
exit

mv nifti_stats.m x_nifti_stats.m

Compile @xmltree mex files:

cd $PALMPATH/fileio/@xmltree/private
cp $PALMPATH/fileio/@file_array/private/Makefile.var .
cp $PALMPATH/fileio/@file_array/private/compile.sh .
sed -i -e 's|include ../../src/Makefile.var|include Makefile.var|g' Makefile
./compile.sh

mv xml_findstr.m x_xml_findstr.m

4. Edit qunex_environment.sh#

To make sure that QuNex 'sees' the correct PALM installation, edit the following segment of the $TOOLS/qunex/env/qunex_environment.sh file so that PALMDIR variable in qunex_environment.sh references the PALM installation that matches with the PALM WHICH_TO_RUN variable set in step 2.:

# ------------------------------------------------------------------------------
# -- Running matlab vs. octave
# ------------------------------------------------------------------------------

if [ "$USEOCTAVE" == "TRUE" ]; then
    if [[ ${OctaveTest} == "fail" ]]; then 
        reho " ===> ERROR: Cannot setup Octave because module test failed."
    else
         ln -s `which octave` ${OCTAVEDIR}/octave > /dev/null 2>&1
         export OCTAVEPKGDIR
         export OCTAVEDIR
         export OCTAVEBINDIR
         cyaneho " ---> Setting up Octave "; echo ""
         QUNEXMCOMMAND='octave -q --no-init-file --eval'
         if [ ! -e ~/.octaverc ]; then
             cp ${QUNEXPATH}/qx_library/.octaverc ~/.octaverc
         fi
         export LD_LIBRARY_PATH=/usr/lib64/hdf5/:${LD_LIBRARY_PATH} > /dev/null 2>&1
         if [[ -z ${PALMDIR} ]]; then PALMDIR="${TOOLS}/palm/palm-latest-o"; fi
    fi
else
    # if [[ ${MatlabTest} == "fail" ]]; then
    #     reho " ===> ERROR: Cannot setup Matlab because module test failed."
    # else

         cyaneho " ---> Setting up Matlab "; echo ""
         QUNEXMCOMMAND='matlab -nodisplay -nosplash -r'
         if [[ -z ${PALMDIR} ]]; then PALMDIR="${TOOLS}/palm/palm-latest-m"; fi
    # fi
fi
# -- Use the following command to run .m code in MATLAB
export QUNEXMCOMMAND