#======================================================================
# C R U I S E _ S E T U P . E X P E C T
# doc: Wed Mar 10 21:14:18 2004
# dlm: Fri Dec 10 15:42:51 2010
# (c) 2004 A.M. Thurnherr
# uE-Info: 184 25 NIL 0 0 72 2 2 8 NIL ofnI
#======================================================================
#--------
# HISTORY
#--------
# Mar 10, 2004: - created during NBP0402
# Apr 4, 2004: - final version NBP0402
# Jun 15, 2004: - adapted to BB150/Workhorse setup
# Jun 16, 2004: - ditto
# Jun 19, 2004: - BUG: could not handle multiple BB150 data files
# Jan 19, 2006: - updated documentation
# - allowed for empty-string time_server
# Nov 4, 2006: - changed backup dir structure
# Aug 25, 2010: - rename* funs modified to allow them to be used to ensure
# that downladed file names have correct case
# - renamed from DEFAULTS.expect to CRUISE_SETUP.expect
# Aug 26, 2010: - added ymodem_receive_cmd
# - changed default string quotes to {} to prevent Tcl variable
# and command substitutions
# Oct 18, 2010: - changed comment for ymodem_receive_cmd to account for the
# fact that bbabble now uses the -u option by default
# Dec 10, 2010: - updated comments
# - made mkProfile default file-checking program
# - made backup dir structure consistent with raw dir structure
#-----------
# TWEAKABLES
#-----------
# At the beginning of each cast, the clock of the acquisition computer should
# synchronized with the master clock used for timestamping the GPS information.
# The best way to accomplish this is to run a NTP daemon (e.g. ntpd) polling
# an NTP server on the ship.
# If running ntpd is inconvenient or not possible, the follwing variable can
# be set to the name of the NTP server, in which case the time is sync'ed
# at the beginning of each cast with the function set_computer_time (defined
# below).
# If there is no NTP server available, the variable should be set to the
# empty string and the clock must be sync'ed manually.
set time_server {};
# bbabble needs to know the tty device name(s) of the serial connection(s)
# to the ADCP head(s). If only one head is connected, tty1 is ignored.
# If two heads are connected, the device names are exchangeable, i.e.
# either instrument can be connected to either port.
set tty0 {/dev/ttyS0};
set tty1 {/dev/ttyS1};
# In case of 2 ADCP heads, babble needs to know which is the master and
# which is the slave. This is accomplished by setting the following variables
# to the corresponding instrument serial numbers (PS0 output). By convention,
# the downlooker is the master. If only a single head is connected, both
# variables are ignored.
set master_sn 7877;
set slave_sn 1412;
# Before deployment, every ADCP head has to be programmed by sending it
# a corresponding command file, defined by the following variables. If only
# a single head is connected, the slave_* variable is ignored.
set master_cmd_file {MASTER.cmd};
set slave_cmd_file {SLAVE.cmd};
# For convenience, it is best to use the station number to name the ADCP data
# files, and to indicate whether the data file comes from the master or
# slave. The following variables variables define the printf(3) format
# that is used to create the files names from the station number. If only
# a single head is connected, the slave_* variable is ignored.
set master_deployment_name_fmt {%03dDL};
set slave_deployment_name_fmt {%03dUL};
# Older RDI instruments (e.g. the BB150) do not allow the data-file name
# to be defined in the instrument, in which case the files have to be
# renamed after downloading. The following variables define the shell
# globbing patterns for the master and slave. For example, the UH BB150
# used during CLIVAR P02 generated files with extension .612; the coresponding
# globbing pattern is {*.612}. If only a single head is connected, the
# slave_* variable is ignored.
# NB: For dual-headed LADCP systems it is important that the globs do not
# match both master and slave data files. {*.000} therefore will not
# work for dual-head Workhorse systems.
set master_download_glob {};
set slave_download_glob {};
# For consistency it is nicest if low station numbers contain leading
# zeroes. The following variable defines the corresponding printf(3) format.
set stn_format {%03d};
# The following directory is used to store command files, instrument
# configurations and ADCP data. Separate subdirectories (named according to
# stn_format) are used for each cast.
set raw_dir {../data/raw};
# After downloading, the data directory is backed up to the following
# directory. Make sure that it resides on a different disk than raw_dir.
# Empty string disables backup for testing purposes.
# NOTE: RELATIVE PATHNAMES MUST START FROM CAST DIR (NOT ACQUISITION DIR)
set backup_dir {../../backup/raw};
# By default, bbabble will look for standard UN*X ymodem receive
# programs (rb and lrb) and call the first one it finds with the
# -u option. If neither of the standard programs exist, if neither is in the
# current $PATH, or if non-standard options have to be passed the following
# variable can be set to a non-empty string, such as {/sw/bin/rb -u}
set ymodem_receive_cmd {}
# bbabble can be made to abort downloading after a preset amount of time,
# defined by the following variable.
set download_timeout 999999;
#----------------------------------------------------------------------
# Semi-Standard Functions
#----------------------------------------------------------------------
# The program for polling an NTP server is different on different
# UN*X systems. Either rdate or ntpdate should be available. Note
# that sudo will propt for the login password of the user running
# the LADCP acquisition, unless it is explicitly set to allow execution
# of the command without a password.
proc set_computer_time {} { # set computer clock
global time_server;
if {[string length $time_server] == 0} {return}
exec sudo rdate -s $time_server;
# exec sudo ntpdate -s $time_server;
}
#----------------------------------------------------------------------
# After the LADCP data files have been downloaded they should be
# checked. A simple yet effective check consists in estimating the
# bottom depth (zmax) and end depth (zend) by time-integrating the
# vertical-velocity measurements. There are two different publicly
# available programs to accomplish this: scanbb from the UH LADCP
# software suite, and mkProfile from the perl-utilities available
# from the LDEO LADCP repository.
proc check_data {file} { # check data file
exec sh -c "mkProfile -Q $file 2> `basename $file .000`.profinfo";
exec sh -c "cat `basename $file .000`.profinfo > /dev/tty";
# exec sh -c "scanbb $file";
# exec sh -c "sed -n '/^zmax/,/^zend/s/ at.*/m/p' `basename $file .000`.scn > /dev/tty";
}
#----------------------------------------------------------------------
# The following two routines backup the master and slave files from the
# raw directory.
proc backup_master_data {stn} {
global stn_format master_deployment_name_fmt master_cmd_file backup_dir;
if {[string length $backup_dir] == 0} {return}
if {![file isdirectory $backup_dir]} {
error "$backup_dir does not exist relative to [pwd]";
}
set stnstr [format $stn_format $stn];
set cast_dir [format %s/%s $backup_dir $stnstr];
if {![file isdirectory $cast_dir]} {exec mkdir $cast_dir};
exec sh -c "cp [format $master_deployment_name_fmt $stn]* $cast_dir";
exec sh -c "cp $master_cmd_file* $cast_dir";
exec sh -c "cp *log $cast_dir";
}
proc backup_slave_data {stn} { # copy data to network
global stn_format slave_deployment_name_fmt slave_cmd_file backup_dir;
if {[string length $backup_dir] == 0} {return}
if {![file isdirectory $backup_dir]} {
error "$backup_dir does not exist relative to [pwd]";
}
set stnstr [format $stn_format $stn];
set cast_dir [format %s/%s $backup_dir $stnstr];
if {![file isdirectory $cast_dir]} {exec mkdir $cast_dir};
exec sh -c "cp [format $slave_deployment_name_fmt $stn]* $cast_dir";
exec sh -c "cp $slave_cmd_file* $cast_dir";
exec sh -c "cp *log $cast_dir";
}
#----------------------------------------------------------------------
# See comments on master_download_glob and slave_download_glob above.
proc rename_master_download_file {target} { # rename after download
global master_download_glob;
if {[string length $master_download_glob] == 0} {return}
set files [glob -nocomplain $master_download_glob];
set nfiles [llength $files];
if {$nfiles == 0} {
if {![file exists $target]} {
error {can't find downloaded master file};
}
return;
}
if {$nfiles > 1} {
send_user {WARNING: Multiple files downloaded from master --- rename, backup, check manually!};
}
if {![string equal [lindex $files end] $target]} {
exec mv [lindex $files end] $target;
}
}
proc rename_slave_download_file {target} { # rename after download
global slave_download_glob;
if {[string length $slave_download_glob] == 0} {return}
set files [glob -nocomplain $slave_download_glob];
set nfiles [llength $files];
if {$nfiles == 0} {
if {![file exists $target]} {
error {can't find downloaded slave file};
}
return;
}
if {$nfiles > 1} {
send_user {WARNING: Multiple files downloaded from slave --- rename, backup, check manually!};
}
if {![string equal [lindex $files end] $target]} {
exec mv [lindex $files end] $target;
}
}