CRUISE_SETUP.expect
changeset 4 fda11de1826e
child 5 f41d45fe7ae9
equal deleted inserted replaced
3:99a41e0476b1 4:fda11de1826e
       
     1 #======================================================================
       
     2 #                    C R U I S E _ S E T U P . E X P E C T 
       
     3 #                    doc: Wed Mar 10 21:14:18 2004
       
     4 #                    dlm: Thu Aug 26 19:49:03 2010
       
     5 #                    (c) 2004 A.M. Thurnherr
       
     6 #                    uE-Info: 118 24 NIL 0 0 72 2 2 8 NIL ofnI
       
     7 #======================================================================
       
     8 
       
     9 #--------
       
    10 # HISTORY
       
    11 #--------
       
    12 
       
    13 # Mar 10, 2004: - created during NBP0402
       
    14 # Apr  4, 2004: - final version NBP0402
       
    15 # Jun 15, 2004: - adapted to BB150/Workhorse setup
       
    16 # Jun 16, 2004: - ditto
       
    17 # Jun 19, 2004: - BUG: could not handle multiple BB150 data files
       
    18 # Jan 19, 2006: - updated documentation
       
    19 #		- allowed for empty-string time_server
       
    20 # Nov  4, 2006: - changed backup dir structure
       
    21 # Aug 25, 2010: - rename* funs modified to allow them to be used to 
       
    22 #		  that downladed file names have correct case
       
    23 #		- renamed from DEFAULTS.expect to CRUISE_SETUP.expect
       
    24 # Aug 26, 2010: - added ymodem_receive_cmd
       
    25 #		- changed default string quotes to {} to prevent Tcl variable
       
    26 #		  and command substitutions
       
    27 
       
    28 #-----------
       
    29 # TWEAKABLES
       
    30 #-----------
       
    31 
       
    32 # At the beginning of each cast, the clock of the acquisition computer should
       
    33 # synchronized with the master clock used for timestamping the GPS information.
       
    34 # The easiest way to accomplish this is by probing an NTP server on the ship
       
    35 # (if there is one), which can be defined by setting the following variable.
       
    36 # If there is no such server available, the variable should be set to the
       
    37 # empty string (set time_server {}), in which case clock synchronization must
       
    38 # be done differently (e.g. manually).
       
    39 
       
    40 set time_server	{199.92.161.2};
       
    41 
       
    42 # bbabble needs to know the tty device name(s) of the serial connection(s)
       
    43 # to the ADCP head(s). If only one head is connected, tty1 is ignored.
       
    44 # If two heads are connected, the device names are exchangeable, i.e.
       
    45 # either instrument can be connected to either port.
       
    46 
       
    47 set tty0 {/dev/ttyS0};
       
    48 set tty1 {/dev/ttyS1};
       
    49 
       
    50 # In case of 2 ADCP heads, babble needs to know which is the master and
       
    51 # which is the slave. This is accomplished by setting the following variables
       
    52 # to the corresponding instrument serial numbers (PS0 output). By convention,
       
    53 # the downlooker is the master. If only a single head is connected, both
       
    54 # variables are ignored.
       
    55 
       
    56 set master_sn 7877;
       
    57 set slave_sn  1412;
       
    58 
       
    59 # Before deployment, every ADCP head has to be programmed by sending it
       
    60 # a corresponding command file, defined by the following variables. If only
       
    61 # a single head is connected, the slave_* variable is ignored.
       
    62 
       
    63 set master_cmd_file {MASTER.cmd};
       
    64 set slave_cmd_file  {SLAVE.cmd};
       
    65 
       
    66 # For convenience, it is best to use the station number to name the ADCP data
       
    67 # files, and to indicate whether the data file comes from the master or
       
    68 # slave. The following variables variables define the printf(3) format
       
    69 # that is used to create the files names from the station number. If only
       
    70 # a single head is connected, the slave_* variable is ignored.
       
    71 # NOTE: Some implementations of the ymodem protocol (notably lrb running
       
    72 #	under Mandrake 8) use lowercase for the downloaded file. It is
       
    73 #	therefore better to use only lowercase characters in the deployment
       
    74 #	names.
       
    75 
       
    76 set master_deployment_name_fmt	{%03ddn};
       
    77 set slave_deployment_name_fmt	{%03dup};
       
    78 
       
    79 # Older RDI instruments (e.g. the BB150) do not allow the data-file name
       
    80 # to be defined in the instrument, in which case the files have to be
       
    81 # renamed after downloading. The following variables define the shell
       
    82 # globbing patterns for the master and slave. For example, the UH BB150
       
    83 # used during CLIVAR P02 generated files with extension .612; the coresponding
       
    84 # globbing pattern is {*.612}. If only a single head is connected, the
       
    85 # slave_* variable is ignored.
       
    86 # NB: For dual-headed LADCP systems it is important that the globs do not
       
    87 #     match both master and slave data files. {*.000} therefore will not
       
    88 #     work for dual-head Workhorse systems.
       
    89 
       
    90 set master_download_glob 	{};
       
    91 set slave_download_glob		{};
       
    92 
       
    93 # For consistency it is nicest if low station numbers contain leading
       
    94 # zeroes. The following variable defines the corresponding printf(3) format.
       
    95 
       
    96 set stn_format {%03d};
       
    97 
       
    98 # The following directory is used to store command files, instrument
       
    99 # configurations and ADCP data. Separate subdirectories (named according to
       
   100 # stn_format) are used for each cast.
       
   101 
       
   102 set raw_dir {../data/raw};
       
   103 
       
   104 # After downloading, the data directory is backed up to the following
       
   105 # directory. Make sure that it resides on a different disk than raw_dir.
       
   106 # Empty string disables backup for testing purposes.
       
   107 # NOTE: RELATIVE PATHNAMES MUST START FROM CAST DIR (NOT ACQUISITION DIR)
       
   108 
       
   109 set backup_dir {../../backup/raw};
       
   110 
       
   111 # By default, bbabble will look for standard UN*X ymodem receive
       
   112 # programs (rb and lrb). If neither of these exist, if neither is in the
       
   113 # current $PATH, or if options have to be passed (as is the case on some
       
   114 # Linux distributions to ensure that the downloaded files have consistent
       
   115 # (upper-)case filenames, the following variable can be set to a non-empty
       
   116 # string, such as {rb -u}
       
   117 
       
   118 set ymodem_receive_cmd {}
       
   119 
       
   120 # bbabble can be made to abort downloading after a preset amount of time,
       
   121 # defined by the following variable. 
       
   122 
       
   123 set download_timeout 999999;
       
   124 
       
   125 #----------------------------------------------------------------------
       
   126 # Semi-Standard Functions
       
   127 #----------------------------------------------------------------------
       
   128 
       
   129 proc set_computer_time {} {				# set computer clock
       
   130 	global time_server;
       
   131 	if {[string length $time_server] == 0} {return}
       
   132 	exec sudo rdate -s $time_server;
       
   133 }
       
   134 
       
   135 proc check_data {file} {				# check data file
       
   136 	exec sh -c "scanbb $file";
       
   137 	exec sh -c "sed -n '/^zmax/,/^zend/s/ at.*/m/p' `basename $file .000`.scn > /dev/tty";
       
   138 }
       
   139 
       
   140 proc backup_master_data {stn} {				# copy data to network
       
   141 	global master_deployment_name_fmt master_cmd_file backup_dir;
       
   142 	if {[string length $backup_dir] == 0} {return}
       
   143 
       
   144 	if {![file isdirectory $backup_dir]} {
       
   145 		error "$backup_dir does not exist relative to [pwd]";
       
   146 	}
       
   147 
       
   148 	set master_dir [format $backup_dir/$master_deployment_name_fmt $stn];
       
   149 	if {![file isdirectory $master_dir]} {exec mkdir $master_dir};
       
   150 	exec sh -c "cp [format $master_deployment_name_fmt $stn]* $master_dir";
       
   151 	exec sh -c "cp $master_cmd_file* $master_dir";
       
   152 	exec sh -c "cp *log $master_dir";
       
   153 }
       
   154 	
       
   155 proc backup_slave_data {stn} {				# copy data to network
       
   156 	global slave_deployment_name_fmt slave_cmd_file backup_dir;
       
   157 	if {[string length $backup_dir] == 0} {return}
       
   158 
       
   159 	if {![file isdirectory $backup_dir]} {
       
   160 		error "$backup_dir does not exist relative to [pwd]";
       
   161 	}
       
   162 
       
   163 	set slave_dir [format $backup_dir/$slave_deployment_name_fmt $stn];
       
   164 	if {![file isdirectory $slave_dir]} {exec mkdir $slave_dir};
       
   165 	exec sh -c "cp [format $slave_deployment_name_fmt $stn]* $slave_dir";
       
   166 	exec sh -c "cp $slave_cmd_file* $slave_dir";
       
   167 	exec sh -c "cp *log $slave_dir";
       
   168 }
       
   169 
       
   170 proc rename_master_download_file {target} {		# rename after download 
       
   171 	global master_download_glob;
       
   172 	
       
   173 	if {[string length $master_download_glob] == 0} {return}
       
   174 	set files [glob -nocomplain $master_download_glob];
       
   175 	set nfiles [llength $files];
       
   176 	if {$nfiles == 0} {
       
   177 		if {![file exists $target]} {
       
   178 			error {can't find downloaded master file};
       
   179 		}
       
   180 		return;
       
   181         }
       
   182         if {$nfiles > 1} {
       
   183 	        send_user {WARNING: Multiple files downloaded from master --- rename, backup, check manually!};
       
   184 	}
       
   185 	if {![string equal [lindex $files end] $target]} {
       
   186 		exec mv [lindex $files end] $target;
       
   187 	}
       
   188 }
       
   189 
       
   190 proc rename_slave_download_file {target} {		# rename after download
       
   191 	global slave_download_glob;
       
   192 	
       
   193 	if {[string length $slave_download_glob] == 0} {return}
       
   194 	set files [glob -nocomplain $slave_download_glob];
       
   195 	set nfiles [llength $files];
       
   196 	if {$nfiles == 0} {
       
   197 		if {![file exists $target]} {
       
   198 			error {can't find downloaded slave file};
       
   199 		}
       
   200 		return;
       
   201         }
       
   202         if {$nfiles > 1} {
       
   203 	        send_user {WARNING: Multiple files downloaded from slave --- rename, backup, check manually!};
       
   204 	}
       
   205 	if {![string equal [lindex $files end] $target]} {
       
   206 		exec mv [lindex $files end] $target;
       
   207 	}
       
   208 }