#!/usr/bin/perl -w # read_ctladv.pl # Perl script to read a Sontek ADV .ctl file and # generate a matlab .m file to assign values. # Usage: perl -w pathnameofthisperlscript\read_ctladv.pl filename.ctl # eg: perl -w e:\sherwood\matlab\advlib\read_ctladv.pl jan10001.ctl # # Chris Sherwood, USGS # Last revised January 14, 2001 # # Jessie Lacy, USGS # Last revised Feb 6, 2001 # array w/ text to search for in .ctl file: @ctl_text = ( "DefaultTemp", "DefaultSal", "DefaultSoundSpeed", "VelRange Index" ); @ctl2_text = ( "Number of Bursts -", "SampRate", "BurstInterval", "SamplesPerBurst", ); # corresponding array of matlab names @mat_name = ( "def_temp", "def_sal", "def_csound", "vel_range" ); @mat2_name = ( "num_bursts", "samp_rate", "b_int", "samp_per_burst", ); $fn = "d:\\crs\\matlab\\advlib\\read_ctladv.m"; open(MFILE,">$fn")||die "cant open $fn for output"; print MFILE "% READ_CTLADV - Creates variables found in .ctl file for Sontek ADV\n"; print MFILE "% Can be created automatically by running read_ctl.pl\n"; # read lines from file specified on command line while(<>){ $i=0; foreach $a (@ctl_text) { # does the line from the .ctl file match the array text? if( /^$a/i ) { # remove newline char chomp; # split line into @words = split /\s/; #evaluate last word print MFILE "adv.$mat_name[$i] = $words[$#words]\;\n"; } $i++; } $i=0; foreach $a (@ctl2_text) { # does the line from the .ctl file match the array text? if( /^$a/i ) { # remove newline char chomp; # split line into @words = split /\s+/; # \s+ means one or more spaces # print ($words[3], "\n", $words[4], "\n", $words[5],"\n"); #evaluate third to last word print MFILE "adv.$mat2_name[$i] = $words[-3]\;\n"; } $i++; } # look for CoordSystem if( /^CoordSystem/i ) { # remove newline char chomp; # split line into @words = split /\s+/; print ("Coord System is $words[-1] \n"); #evaluate last word print MFILE "adv.coord_sys = '$words[-1]'\;\n"; } } close(MFILE);