Matlab Option Tree Tutorial

From ICE Enterprises
Jump to navigation Jump to search

The Matlab Option Tree allows you to run NeXtMidas commands and talk directly to ICE-PIC cards from Matlab (or Octave). This tutorial will walk you through installing a Java Development Kit, NeXtMidas, the ICE Option Tree, and the Matlab Option Tree. There are also pages on how to configure Matlab and Octave. If you have questions, it might be worth checking out the Frequently Asked Questions.

Key

Listed below are some symbols and notations that are used throughout this document for the purpose of clarity:

$    commands typed at a Linux terminal
nM>  commands typed at a NeXtMidas prompt
!    comments
#    comments

Assumptions & Notes

This tutorial has been tested on:

  • CentOS 6.3 (32 & 64 bit)
  • CentOS 6.4 (32 & 64 bit)
  • Red Hat 6.3 (32 & 64 bit)
  • Red Hat 6.4 (32 & 64 bit)

You might run into complexities with other distributions

Our NeXtMidas user is named 'iceman'

  • We recommend using the same user for clarity purposes

System Staging

This section will walk you through:

  • Installing 3rd party software from your package manager
  • Creating an ICE User
  • Setting up your file system
  • Downloading software

Download dependent packages from your package installer

The NeXtMidas/ICE/Matlab Toolchain requires additional software on top of a base Linux installation. This software is most easily installed from a package manager. Here are the terminal commands that need to be run to install the necessary packages:

$ sudo yum install tcsh libstdc++-devel gcc nano

User Setup

We need to add a user, alter some privileges and create some directories. You can name your user anything you desire; however, we recommend using 'iceman'. This will make following this tutorial easier. Here is how to add a NeXtMidas user:

$ su -l
(enter password)
$ useradd iceman
$ passwd iceman
(type password)
$ mkdir -p /home/iceman/Downloads
$ mkdir -p {/opt/ice/aux/data01/iceman,/opt/ice/aux/icedisk,/opt/ice/pkg}
$ chown -R iceman:iceman {/home/iceman,/opt/ice}
$ chsh iceman
/bin/tcsh
$ exit

Superuser Privileges (optional)

If you want your user to have superuser privileges (execute sudo commands), then you'll need to create a sudoers file(s).

$ su -l
$ echo "iceman  ALL=(ALL:ALL) ALL" > /etc/sudoers.d/00iceman
$ chmod 0440 /etc/sudoers.d/00iceman
$ exit

NOTE: The sudoers.d directory is new in the CentOS/Red Hat 6 Series. If you're using CentOS/Red Hat 5.x, then you'll have to add 'iceman ALL=(ALL:ALL) ALL' to the file '/etc/sudeors'.

Switch Users

It is now time to logout of your current user and login as your new Midas user (iceman).

Downloading and Unpacking Software

Now we'll download and unpack our Software. This should be done as your new user (in our case 'iceman'). To confirm that you are the 'normal' Midas user type:

$ whoami
iceman

Matlab Option Tree

We'll download that Matlab Option Tree first (even though we won't compile it first). The Matlab Option Tree contains additional software inside of the tarball. It is available as stable software from ICE at the Downloads page.

NOTE: At the time of this tutorial, the latest version was nextmat-01_01_06.

After download, move the tarball to the appropriate directory and unpack:

$ mv ~/Downloads/nextmat-01_01_06.tar.gz /opt/ice/pkg
$ cd /opt/ice/pkg
$ tar xvzf nextmat-01_01_06.tar.gz
$ ln -sf nextmat-01_01_06 nextmat

JDK

Matlab did not start supporting JDK 1.7 until R2013. Therefore, if you're using an older version of Matlab, please use Java 1.6.

NOTE: The latest version at the time of this tutorial was JDK 7u45

64-Bit

Here are the commands to setup your JDK on a 64-Bit Architecture:

$ cp /opt/ice/pkg/nextmat/pkg/jdk-7u45-linux-x64.tar.gz /opt/ice/pkg/
$ cd /opt/ice/pkg
$ tar xvzf jdk-7u45-linux-x64.tar.gz
$ ln -sf jdk1.7.0_45 jdk

32-Bit

Here are the commands to setup your JDK on a 32-Bit Architecture:

$ cp /opt/ice/pkg/nextmat/pkg/jdk-7u45-linux-i586.tar.gz /opt/ice/pkg/
$ cd /opt/ice/pkg
$ tar xvzf jdk-7u45-linux-i586.tar.gz
$ ln -sf jdk1.7.0_45 jdk

NeXtMidas & ICE Option Tree

Download latest version of NeXtMidas & ICE from the stable branch at the Downloads page.

NOTE: At the time of this tutorial, the latest versions were nxm332i & ice380-04.

After download, move the tarball to the appropriate directory and unpack.

$ mv ~/Downloads/nxm332i.zip /opt/ice/pkg/
$ mv ~/Downloads/ice380-04.zip /opt/ice/pkg/
$ cd /opt/ice/pkg
$ unzip nxm332i.zip
$ unzip ice380-04.zip
$ ln -sf nxm332i nmxxx
$ ln -sf ice380-04 icexxx

NeXtMidas Setup

NeXtMidas Environment

Our software looks for specific environment variables. We have provided an example C-Shell resource file (.cshrc) in the Matlab Option Tree that will set these variables. Here is what it looks like:

$ cat /opt/ice/pkg/nextmat/cfg/example.cshrc

#!/bin/csh

# JDK Location
setenv JAVAHOME /opt/ice/pkg/jdk
setenv MATLAB_JAVA $JAVAHOME/jre

# NeXtMidas location & alias
setenv NMROOT /opt/ice/pkg/nmxxx
alias nmstart 'source $NMROOT/os/unix/nmstart'
alias nms 'nmstart'

# ICE Tree location & alias
setenv ICEROOT /opt/ice/pkg/icexxx
alias ice ${ICEROOT}/jre/ice 

# Matlab Option Tree location
setenv NEXTMATROOT /opt/ice/pkg/nextmat

This file will set up a minimal development environment. To install this file, simply copy it to your home directory with the correct name. Please note that you might wish to add more information to your .cshrc file. Also note that if you already have a .cshrc file, you might wish to preserve it by backing it up before overwriting it.

Copy the example .cshrc file and 'source' it.

$ cp /opt/ice/pkg/nextmat/cfg/example.cshrc ~/.cshrc
$ source ~/.cshrc

NeXtMidas Compilation

Once your environment is setup, NeXtMidas can be compiled. It will take several minutes to compile. Here are the commands:

$ nms
$ nm make all

After this is complete, NeXtMidas is compiled. You will now be able to enter the NeXtMidas shell by typing:

$ nms
$ nm

If you wish to exit the NeXtMidas shell, type:

nM> nmend

To test NeXtMidas, try to 'plot apenny':

$ nms
$ nm
nM> plot apenny
nM> nmend

ICE Option Tree Compilation

Unpack and compile the ICE Option Tree:

$ ice unpack 
(Don't worry if the terminal displays errors)
$ nms
$ nm
nM> option ice /opt/ice/pkg/icexxx
nM> make all ice
nM> nmend

Matlab Option Tree

Compile the Matlab Option Tree:

$ nms
$ nm
nM> option nextmat /opt/ice/pkg/nextmat
nM> make all nextmat
nM> nmend

Configuring NeXtMidas

NeXtMidas can be configured with a local macro. The file must reside in your home directory, and must it be named 'nmstartup.mm'. We have provided a practical example in the Matlab Option Tree. Here is what it looks like:

$ cat /opt/ice/pkg/nextmat/cfg/nmstartup.mm

startmacro
  ! Define AUX'es
  file name u:aux.1  (opt,ice,aux,data01,+)
  file name u:aux.9  (ramd:,opt,ice,aux,icedisk)
  sedit AUX.9 AUX.9 append ",RAM,AUTO" 

  ! Add option trees
  option ice /opt/ice/pkg/icexxx
  option nextmat /opt/ice/pkg/nextmat

  ! Set the path
  path set ice,nextmat,sys,dsp,hwc

  ! Set the hardware file
  hw file nxm.ice.dat.hwconfig

  ! Set the PIC AUX
  pic aux 9

  ! Set AUX'es
  aux 1 1|9|DAT|CWD|HOME

endmacro

You may alter this file to suit your needs, but for now, let's copy it into our home directory.

NOTE: Make sure to back up your ~/nmstartup.mm (if it exists) before copying the example:

$ cp /opt/ice/pkg/nextmat/cfg/nmstartup.mm ~/

Interfacing with NeXtMidas

The NeXtMidas interface should be set up now. The next step is to configure Matlab or Octave for communication with NeXtMidas. We have supplied demonstrations for both. You can follow this guide for Matlab or this guide for Octave.