Altitude diving depth and NITROX calculations

For several reasons I’ve found myself diving (with SCUBA) in inland lakes on altitude. Due to the lower atmospheric pressure, altitude diving requires different depth calculations. There are diving tables and computer software that help divers to plan a safe dive. Although, I’ve though of making my “quick and dirty” script for calculating the theoretical ocean depth of an altitude dive, the depth of the safety stop at altitude as well as the best NITROX mix at the given altitude for PO2 of 1.2, 1.4 and 1.6.

The scripts accepts only two parameters: the altitude and the depth. For instance, for a dive at 1350m altitude and 30m depth:

 ./calcDepth.sh 1350 30
=======================================================
Every individual diver is responsible for planning 
and conducting dives using SCUBA equipment up to the 
trained and certified qualification he or she holds.

The creator of this program does not have any 
responsibility for symptoms of Decompressions Sickness 
when the suggested values of this program are used 
for conducting a dive.
========================================================


Altitude: 	1350 m
Depth: 		30 mfw
Pressure: 	.86 atm
TOD: 		33.65900 msw
Safety Stop: 	4.45 mfw

Best NITROX mix with 1.2 PO2: 27.00
Best NITROX mix with 1.4 PO2: 32.00
Best NITROX mix with 1.6 PO2: 36.00

###########################################################################
# Copyright (C) 2011  Panagiotis Kritikakos <panoskrt@gmail.com>           #
#                                                                          #
#    This program is free software: you can redistribute it and/or modify  #
#    it under the terms of the GNU General Public License as published by  #
#    the Free Software Foundation, either version 3 of the License, or     #
#    (at your option) any later version.                                   #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
#                                                                          #
#    You should have received a copy of the GNU General Public License     #
#    along with this program.  If not, see <http://www.gnu.org/licenses/>. #
############################################################################
#!/bin/bash
MSW=10.0584
MFW=10.3632
SSDSW=5
ALT=$1
Da=$2

disclaimer()
{
echo "
=======================================================
Every individual diver is responsible for planning
and conducting dives using SCUBA equipment up to the
trained and certified qualification he or she holds.

The creator of this program does not have any
responsibility for symptoms of Decompressions Sickness
when the suggested values of this program are used
for conducting a dive.
========================================================
"
}

if [ -z $ALT ] || [ -z $Da ]; then
  echo " Specify altitude and depth: ./calcDepth.sh 1350 24"
  exit 1
else
  clear
  Pa=`echo "100-(0.01*$ALT)" | bc`

  TOD=`echo "scale=5; ($Da*(1/$Pa)*($MSW/$MFW))*100" | bc`
  SSDA=`echo "scale=2; ($SSDSW*($Pa/1)*($MFW/$MSW))/100" | bc`

  PAatm=`echo "scale=2; $Pa/100" | bc`

  N1=`echo "scale=2; 100*(1.2/(($TOD/10)+1))" | bc`
  N2=`echo "scale=2; 100*(1.4/(($TOD/10)+1))" | bc`
  N3=`echo "scale=2; 100*(1.6/(($TOD/10)+1))" | bc`

  echo
  disclaimer
  echo

  printf "Altitude: \t$ALT m\n"
  printf "Depth: \t\t$Da mfw\n"
  printf "Pressure: \t$PAatm atm\n"
  printf "TOD: \t\t$TOD msw\n"
  printf "Safety Stop: \t$SSDA mfw\n\n"
  printf "Best NITROX mix with 1.2 PO2: $N1\n"
  printf "Best NITROX mix with 1.4 PO2: $N2\n"
  printf "Best NITROX mix with 1.6 PO2: $N3\n\n"
  exit 0
fi
Advertisements

Speedup and efficiency shell calculator

The following script can be used to calculate the speedup and efficiency of a parallel code when compared to its serial version. Pretty much straight forward process. This script can be used either individually or as part of another script to automate the process of generating the required results. It accepts three arguments: 1) serial execution time 2) parallel execution time 3) number of processors.

./SEcalc.sh <serial> <parallel> <procs>

Script:

############################################################################
# Copyright (C) 2011  Panagiotis Kritikakos <panoskrt@gmail.com>           #
#                                                                          #
#    This program is free software: you can redistribute it and/or modify  #
#    it under the terms of the GNU General Public License as published by  #
#    the Free Software Foundation, either version 3 of the License, or     #
#    (at your option) any later version.                                   #
#                                                                          #
#    This program is distributed in the hope that it will be useful,       #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of        #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
#    GNU General Public License for more details.                          #
#                                                                          #
#    You should have received a copy of the GNU General Public License     #
#    along with this program.  If not, see <http://www.gnu.org/licenses/>. #
############################################################################

#!/bin/bash

if [ "$#" -eq "3" ]; then
   runtime1proc=$1
   runtimeNproc=$2
   totalprocs=$3
   speedup=`echo "${runtime1proc}/${runtimeNproc}" | bc -l`;
   efficiency=`echo "${speedup}/${totalprocs}" | bc -l`;

   printf "\n Total processors: ${totalprocs}\n\n";
   printf " Runtime for serial code: ${runtime1proc}\n Runtime for parallel code: \
   ${runtimeNproc}\n\n";
   printf " Speedup: ${speedup}\n Efficiency: ${efficiency}\n\n";
else
   printf "\n Usage: SEcalc.sh   \n\n";
   printf " SEcalc.sh 0.350 0.494 2\n\n";
fi

Running Fortran on ARM

Generally and very briefly, there is no official Fortran compiler available for the ARM architecture. The easiest way to get Fortran code (specifically Fortran 77) to run on the ARM architecture, or any other architecture that doesn’t have a Fortran compiler, is to convert the Fortran code to C. In order to do that efficiently, we can use Netlib’s f2c command line tool, available for Linux, Unix and Windows.

The steps that need to be followed are:

1) Compile the library – source at http://www.netlib.org/f2c/libf2c.zip
Rename makefile.u to makefile and do make. Copy the generated libf2c.a to /usr/lib and the f2c.h header under /usr/include.
2) Compile the binary – source at http://www.netlib.org/f2c/src/
Rename makefile.u to makefile and do make. Copy the binary f2c under /usr/local/bin.

Supposing we have the foo.f file we can generate the C version by running f2c foo.f, giving us foo.c. It can now be compiled using ‘gcc foo.c -o foo -lf2c‘.

In order to automate this process a while, the following script can be used. It accepts only one argument, the Fortran source file.

#!/bin/bash
fortranFile=$1
fileName=`echo $1 | sed 's/\(.*\)\..*/\1/'`
echo $fileName
f2c $fortranFile
gcc ${fileName}.c -o $fileName -lf2c

UPDATE: There is GCC Fortran compiler for ARM Fedora and Debian and I presume for other distros as well. The issue now is that these distributions are compiled for ARMv5, while the latest ARM processors (Cortex-A8, A9, A15) are of the ARMv7 architecture. The compilers, and the OS in general is therefore unable to make use of the additional instructions sets and FPU. Other distros, such as Slackware, are compiled on even older architecture, ARMv4.

Nagios remote resources monitoring using SSH (check_by_ssh)

Recently I have been setting up Nagios as the increasing number of machines and services per machines can make it difficult to monitor and tell what’s wrong and what’s not or when you should pay more attention at a system or a service.

Following Nagios documentation is pretty much straight forward to set up the monitoring server. Start monitoring exposed services such as SSH, HTTP, FTP, MySQL, PostgreSQL is also straight forward. Plugins such as check_tcp and check_udp provide also an easy way to see if a service is actually running. For instance, for a CVS pserver, you can use the check_tcp script to check if port 2401 is open or not. Not the best way you should actually test a service but works OK when you want to do a check.

The systems I had to get monitored regarding their local resources were of three types: LCFG Linux, self-managed Linux and self-managed Solaris. This differentiation brings a bit of complexity on its own as they need different ways of sorting monitoring with SSH but still of course using the same principles and techniques. The easiest one is the LCFG ones as a configuration header was created and “included” in every system that needed to be monitored. That looks something like the following:

/** Configuration for monitored remote hosts.
*   This header will allow Nagios server to monitor
*   services on remote system that use this header by
*   running check_by_ssh.
**/

/** Nagios will fail to run remote command if an SSH banner is displayed **/
!openssh.sshdopts       mREMOVE(Banner)

!tcpwrappers.allow_sshd mCONCATQ(" <Nagios_server_hostname_goes_here")

!auth.extrapasswd       mADD(nagios)
auth.pwent_nagios       nagios:*:007:007:Nagios:/home/nagios:/bin/bash
!auth.extragroup        mADD(nagios)
auth.grpent_nagios      nagios:*:007:apache

/** You may add "nagios" user to the user access list of the machine depending the
authentication method **/

/** Public key authentication for 'nagios' user **/
!file.files             mADD(nagiosKey)
file.file_nagiosKey     /localdisk/home/nagios/.ssh/authorized_keys
file.type_nagiosKey     literal
file.mode_nagiosKey     0644
!file.tmpl_nagiosKey    mCONCATQ("<hey_goes_here>")

!profile.packages       mEXTRA(+nagios-plugins-1.4.13-4.el5)

/** List of plugins to be installed remotely **/
!profile.packages       mEXTRA(+nagios-plugins-disk-1.4.13-4.el5)
!profile.packages       mEXTRA(+nagios-plugins-load-1.4.13-4.el5)
!profile.packages       mEXTRA(+nagios-plugins-procs-1.4.13-4.el5)
!profile.packages       mEXTRA(+nagios-plugins-swap-1.4.13-4.el5)
!profile.packages       mEXTRA(+nagios-plugins-users-1.4.13-4.el5)

The self managed systems would make use of either a local or network “nagios” account using public key authentication and each remote system would need to have installed manually its own set of required plugins. A single compile of the plugins in the NFS home directory of the network “nagios” account might not work when you have multiple different *NIX operating systems.

I have configured the Nagios config files for remote services based on this *very* helpful and clear guide http://wiki.nagios.org/index.php/Howtos:checkbyssh_RedHat

The key point with the remote commands is to define the right commands for Nagios, pointing at the right location of the plugins remotely and passing the correct arguments. So, five remote services have been defined, as can be seen from the RPMs above: check_disk, check_load, check_procs, check_swap, check_users.

To call each remote plugin, new command definitions need to be added in /etc/nagios/commands.cfg

define command{
        command_name    check_remote_disk
        command_line    $USER1$/check_by_ssh -p $ARG1$ \
        -H $HOSTADDRESS$ -C '/usr/lib/nagios/plugins/check_disk \
        -w $ARG2$ -c $ARG3$ -p $ARG4$'
        }

define command{
        command_name    check_remote_users
        command_line    $USER1$/check_by_ssh -p $ARG1$ \
        -H $HOSTADDRESS$ -C '/usr/lib/nagios/plugins/check_users \
        -w $ARG2$ -c $ARG3$'
        }

define command{
        command_name    check_remote_load
        command_line    $USER1$/check_by_ssh -p $ARG1$ \
       -H $HOSTADDRESS$ -C '/usr/lib/nagios/plugins/check_load \
       -w $ARG2$ -c $ARG3$'
        }

define command{
        command_name    check_remote_procs
        command_line    $USER1$/check_by_ssh -p $ARG1$ 
       -H $HOSTADDRESS$ -C '/usr/lib/nagios/plugins/check_procs \
       -w $ARG2$ -c $ARG3$ -s $ARG4$'
        }

define command{
        command_name    check_remote_swap
        command_line    $USER1$/check_by_ssh -p $ARG1$ \
        -H $HOSTADDRESS$ -C '/usr/lib/nagios/plugins/check_swap \
        -w $ARG2$ -c $ARG3$'
        }

Depending on the setup you might need to change the location of the plugins or use more options such as desirable user to login, location of keys, IPv4 or IPv6 connection, use of SSH1 or SSH2 etc… Once having defined the commands, they can be used to define services within host configuration files.

The main reason I wanted to avoid using NRPE was the fact that one more services should be exposed, even internally, from system that you want to expose only what is necessary. NRPE would be useful if Windows servers should be monitored for their resources.

OS X terminal type σε Solaris

Συνδεόμενος μέσω SSH σε κάποιο μηχάνημα Solaris από OS X, πάω να ανοίξω τον Vi και βλέπω το παρακάτω μήνυμα:

$:vi
xterm-color: Unknown terminal type
Visual needs addressable cursor or upline capability
:

Στη συνέχεια δοκιμάζοντας με Emacs:

$:emacs
emacs: Terminal type xterm-color is not defined.
If that is not the actual type of terminal you have,
use the Bourne shell command `TERM=... export TERM' (C-shell:
`setenv TERM ...') to specify the correct type.  It may be necessary
to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.

Ο λόγος: το OS X έχει ως προεπιλογμένο τύπο terminal το xterm-color το οποίο το Solaris δεν αναγνωρίζει. Ο τύπος του terminal ορίζεται μέσω της μεταβλητής περιβάλλοντος $TERM. Εάν οριστεί αυτή ως vt100 τότε το Solaris θα είναι και πάλι χαρούμενο:

export TERM=vt100

Για συνεχή χρήση του συγκεκριμένου τύπου terminal μπορεί να προστεθεί ο παραπάνω ορισμό στο .bash_profile του απομακρυσμένου λογαριασμού ή ακόμη καλύτερα να γίνει αλλαγή των προεπιλεγμένων ρυθμίσεων του terminal του OS X: