#!/bin/bash

if [ ! $# == 3 ]; then {
  echo "This code will open independent screen windows and run the same Matlab code in each"
  echo "Note: Should be run within a screen environment, i.e., type <screen -S youruser> command first"
  echo "type <man screen> to learn how to manipulate and switch between screens"
  echo "Usage: $0 <number of shells> <path> <code name>"
  echo "Example: $0 8 ~/Data10/cxs_software/ptycho/ ptycho_round_roi_wrap"
  echo "Useful keys:"
  echo "Ctrl-a \"    will let you toggle between windows"
  echo "Ctrl-a n    will go to next window"
  echo "Ctrl-a p    will go to previous window"
  echo "Ctrl-a [    will let you scroll"
  echo "Ctrl-a ?    will give you available key combinations"
  exit
} fi

#if [ $1 >= 10 ]; then {
#  echo "Maximum number of additional windows per screen session is 9 $1"
#  exit
#} fi

cd $2

for (( i = 1 ; i <= $1 ; i++  ))
do
  #echo "Here I create the $i shell"
  screen -t matlab$i matlab -nodesktop -nosplash -r "$3"
  sleep 5
done

#  Ctrl-a ?   will tell you more available options for screens 
#  Ctrl-a c   will create a new empty screen so that more options become available
#  Ctrl-a d   will detach current screen
#  screen -x <screenname>  will attach specified screen
#  Guizar  2011-11-09
