#! /bin/sh # plotum.pl --- plot UMARC output file fort.9 # Copyright (C) 2001 Jinwei Shen # Author: Jinwei Shen # created on :Tue Jan 2 13:36:46 2001 # last modified on:Tue Jan 9 13:20:02 2001 # status :still in developing stage # $Id: plotum.pl,v 1.2 2001/01/09 18:20:52 shenjw Exp $ # 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 2, 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, you can either send email to this # program's maintainer or write to: The Free Software Foundation, # Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA. # Commentary: # This perl script can retrieve information from UMARC output file # (fort.9), and plot those information by piping into GNUPLOT. It # currently support two output devices, X11 terminals (Default) and # postscript file. It takes any number of fort.9 files, and plots the # relevant information correspondingly on one plot. (This is good for # comparison.) It currently only support UMARC 2.02 version ouput file # format. It plots: tip response, elastic twist distribution, pitch # link loads and displacements, blade modal response, blade root force # and moments in rotating frame, hub loads in nonrotating frame, and # various trailing-edge flap related plots. It can plot any # combination of those plots or all of them. (see -s options) # Installation: # 1. Put this file in any directory which was set in your $PATH # environment variable. # 2. chmod u+x plotum.pl # see sub print_usage for usage information. # Requirement: # UNIX/Linux system. # Perl 5 or later version is required. # gnuplot (http://www.gnuplot.org) # Todo: # 1. support UMARC 1x version output file format by generalizing the data # file format. (put column number in a hash table) # 2. adding more plots. # Code: exec ${PERL-perl} -Sx $0 ${1+"$@"} #!perl [perl will skip all lines in this file before this line] use strict; # use warnings; # require 5.004; use Getopt::Std; use vars qw($opt_h $opt_s $opt_v $opt_t $opt_o $opt_k); my $fort9file="fort.9"; # Defined look-up keywords in fort.9 my %keywords= ('tefhgmt' => "TEF hinge motion response", 'tiprsps' => "non-linear steady-state solution .blade tip response.", 'eltw' => "elastic twist distribution", 'pl' => "Pitch link loads normalized to", 'mdrsps' => "Blade modal response", 'tefhmnt' => "Flap hinge moments .nondimensional, total flaps.", 'tefpwr' => "Flap actuation power .nondim., single blade.", 'rtfm' => "blade root forces & moments .rotating frame.", 'hbfm' => "hub loads in nonrotating frame", ); # define dispatch table for plot subroutines my %dispatch_plot = ( tiprsps => \&plot_tiprsps, eltw => \&plot_eltw, pl => \&plot_pl, mdrsps => \&plot_mdrsps, tefhmnt => \&plot_tefhmnt, tefpwr => \&plot_tefpwr, rtfm => \&plot_rtfm, hbfm => \&plot_hbfm, tefhgmt => \&plot_tefhgmt, ); print_usage() if (!@ARGV); # bomb if not give input files getopts('htvks:o:') || print_usage(); # bomb if not valid options print_usage() if $opt_h; # bomb if you want help my $nonverbose = ""; $nonverbose = "2>/dev/null" if (! $opt_v); my ($plotwhat, @plotthese); # @plotthese = split(/ */, $opt_s) if ($opt_s); if (! $opt_s) { $opt_s = 'tiprsps'; # default plot tiprsps } elsif ( $opt_s eq "all" ) { # plot all available figure $opt_s = 'tiprsps pl mdrsps rtfm hbfm tefhmnt tefpwr tefhgmt'; } $_ = $opt_s; @plotthese = split; my @ffiles = @ARGV; # Startup the gnuplot thread open GNUPLOT, "| gnuplot -persist - $nonverbose" or die "ERROR: can't open gnuplot pipe: $!"; # Force a buffer flush on every write use FileHandle; GNUPLOT->autoflush(1); use Fcntl; # for get temp file name use POSIX qw(tmpnam); my $xtermcntr=1; my $term = "x11"; my $psfile = "plotum.ps"; if ($opt_t) { $term = "ps"; $psfile = $opt_o if ($opt_o); print GNUPLOT "set term post enha color solid 22\n"; print GNUPLOT "set output '$psfile'\n"; # overwrite it } else { my $xtermcntr=1; # x11 term } my $fort9tot = @ARGV; my ($lpct, @tmpfile, @alltmpfiles); foreach $plotwhat (@plotthese) { ($dispatch_plot{$plotwhat}) || die "unkown plot option: '$plotwhat'?\n"; undef @tmpfile; $lpct = 0; # tmpfile counter foreach $fort9file (@ffiles) { $tmpfile[$lpct] = gettmpfl(); retrieve($keywords{$plotwhat}, $fort9file, $tmpfile[$lpct]); ++$lpct; } # call plotting subroutines. ($dispatch_plot{$plotwhat} || sub { die "unkown plot option: '$plotwhat'?\n" })->(@tmpfile); push @alltmpfiles, @tmpfile; } close(GNUPLOT); END { $opt_k or (unlink @alltmpfiles or die "Couldn't unlink @alltmpfiles : $!") } sub gettmpfl{ my ($tmpfl, $FH); do { $tmpfl = tmpnam() } until sysopen(FH, $tmpfl, O_RDWR|O_CREAT|O_EXCL); return $tmpfl } sub plot_fancy{ # give the UMARC label. and fort.9's time, rotor name. stuff at # window 0 # how to get the nondimensional m0/omega, stuff to print in dim. ? } sub plot_sin{ plot_set_xterm () if ( $term eq "x11" ); print GNUPLOT "reset\n"; print GNUPLOT "plot sin(x)\n"; } sub plot_tiprsps { plot_set_xterm () if ( $term eq "x11" ); print GNUPLOT "reset\n"; print GNUPLOT "a = 3; b = 5; c = 7;\n"; print GNUPLOT "set xrange [0:360]\n"; print GNUPLOT "set ytics nomirror\n"; print GNUPLOT "set y2tics nomirror\n"; print GNUPLOT "set ylabel 'v and w'\n"; print GNUPLOT "set xzeroaxis\n"; print GNUPLOT "set x2zeroaxis\n"; print GNUPLOT "set y2label 'phi'\n"; print GNUPLOT "set title 'Blade Tip Response'\n"; print GNUPLOT "set xtics 0, 90, 360\n"; print GNUPLOT "plot "; my ($lt, $filecnt, $filecntlb, $filetot); $lt = 1; $filecnt = 1; $filecntlb = ""; $filetot = @_; foreach my $file (@_) { if ($filetot > 1) {$filecntlb = "$filecnt:"}; print GNUPLOT "'$file' u 1:a t '$filecntlb v' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:b t '$filecntlb w' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:c axis x1y2 t '$filecntlb phi' w l lt $lt,"; ++$lt; ++$filecnt; } print GNUPLOT "(0==0 ? 0: 1/0) notitle w l lt 0 \n"; } sub plot_eltw{ plot_set_xterm () if ( $term eq "x11" ); print GNUPLOT "reset\n"; print GNUPLOT "set pointsize 2.0\n"; print GNUPLOT "set xrange [0:1]\n"; print GNUPLOT "set ytics nomirror\n"; print GNUPLOT "set ylabel 'phi'\n"; print GNUPLOT "set xzeroaxis\n"; print GNUPLOT "set title 'Elastic twist distribution'\n"; print GNUPLOT "set xtics 0, .2, 1\n"; print GNUPLOT "plot "; my ($lt, $filecnt, $filecntlb, $filetot); $lt = 1; $filecnt = 1; $filecntlb = ""; $filetot = @_; foreach my $file (@_) { if ($filetot > 1) {$filecntlb = "$filecnt:"}; print GNUPLOT "'$file' u 1:2 t '$filecntlb phi' w p pt $lt,"; ++$lt; ++$filecnt; } print GNUPLOT "(0==0 ? 0: 1/0) notitle w p pt 0 \n"; } sub plot_pl{ plot_set_xterm () if ( $term eq "x11" ); print GNUPLOT "reset\n"; print GNUPLOT "a = 2; b = 3;\n"; print GNUPLOT "set xrange [0:360]\n"; print GNUPLOT "set ytics nomirror\n"; print GNUPLOT "set y2tics nomirror\n"; print GNUPLOT "set ylabel 'pl load'\n"; print GNUPLOT "set xzeroaxis\n"; print GNUPLOT "set x2zeroaxis\n"; print GNUPLOT "set y2label 'pl disp.'\n"; print GNUPLOT "set title 'Pitch link (load & disp.)'\n"; print GNUPLOT "set xtics 0, 90, 360\n"; print GNUPLOT "plot "; my ($lt, $filecnt, $filecntlb, $filetot); $lt = 1; $filecnt = 1; $filecntlb = ""; $filetot = @_; foreach my $file (@_) { if ($filetot > 1) {$filecntlb = "$filecnt:"}; print GNUPLOT "'$file' u 1:a t '$filecntlb load' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:b axis x1y2 t '$filecntlb disp.' w l lt $lt,"; ++$lt; ++$filecnt; } print GNUPLOT "(0==0 ? 0: 1/0) notitle w l lt 0 \n"; plot_plrttip(@tmpfile); } sub plot_plrttip{ plot_set_xterm () if ( $term eq "x11" ); print GNUPLOT "reset\n"; print GNUPLOT "a = 5; b = 6; c = 7; d = 8; e = 4;\n"; print GNUPLOT "set xrange [0:360]\n"; print GNUPLOT "set ytics nomirror\n"; print GNUPLOT "set y2tics nomirror\n"; print GNUPLOT "set ylabel 'flap & elastic pitch'\n"; print GNUPLOT "set xzeroaxis\n"; print GNUPLOT "set x2zeroaxis\n"; print GNUPLOT "set y2label 'total pitch'\n"; print GNUPLOT "set title 'Pitch link (root/tip pitch)'\n"; print GNUPLOT "set xtics 0, 90, 360\n"; print GNUPLOT "plot "; my ($lt, $filecnt, $filecntlb, $filetot); $lt = 1; $filecnt = 1; $filecntlb = ""; $filetot = @_; foreach my $file (@_) { if ($filetot > 1) {$filecntlb = "$filecnt:"}; print GNUPLOT "'$file' u 1:e t '$filecntlb root flap' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:a t '$filecntlb root pitch elastic' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:b axis x1y2 t '$filecntlb root pitch total' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:c t '$filecntlb tip pitch elastic' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:d axis x1y2 t '$filecntlb tip pitch total' w l lt $lt,"; ++$lt; ++$filecnt; } print GNUPLOT "(0==0 ? 0: 1/0) notitle w l lt 0 \n"; } sub plot_mdrsps{ plot_set_xterm () if ( $term eq "x11" ); print GNUPLOT "reset\n"; print GNUPLOT "set pointsize 2.0\n"; print GNUPLOT "set xrange [0:360]\n"; print GNUPLOT "set ytics nomirror\n"; print GNUPLOT "set ylabel 'phi'\n"; print GNUPLOT "set xzeroaxis\n"; print GNUPLOT "set title 'Blade modal response'\n"; print GNUPLOT "set xtics 0, 90, 360\n"; print GNUPLOT "plot "; my ($lt, $filecnt, $filecntlb, $filetot); $lt = 1; $filecnt = 1; $filecntlb = ""; $filetot = @_; foreach my $file (@_) { my $coltot = getcol($file); if ($filetot > 1) {$filecntlb = "$filecnt:"}; for (my $i = 1; $i <= $coltot; $i++) { my $col = $i + 1; print GNUPLOT "'$file' u 1:$col t '$filecntlb mode $i' w l lt $lt,"; ++$lt; } ++$filecnt; } print GNUPLOT "(0==0 ? 0: 1/0) notitle w p pt 0 \n"; } sub plot_tefhmnt{ plot_set_xterm () if ( $term eq "x11" ); print GNUPLOT "reset\n"; print GNUPLOT "set xrange [0:360]\n"; print GNUPLOT "set ytics nomirror\n"; print GNUPLOT "set ylabel 'nondim.'\n"; print GNUPLOT "set xzeroaxis\n"; print GNUPLOT "set title 'TEF hinge moment'\n"; print GNUPLOT "set xtics 0, 90, 360\n"; print GNUPLOT "plot "; my ($lt, $filecnt, $filecntlb, $filetot); $lt = 1; $filecnt = 1; $filecntlb = ""; $filetot = @_; foreach my $file (@_) { if ($filetot > 1) {$filecntlb = "$filecnt:"}; print GNUPLOT "'$file' u 1:2 t '$filecntlb inertial' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:3 t '$filecntlb aero' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:4 t '$filecntlb total' w l lt $lt,"; ++$lt; ++$filecnt; } print GNUPLOT "(0==0 ? 0: 1/0) notitle w p pt 0 \n"; } sub plot_tefpwr{ plot_set_xterm () if ( $term eq "x11" ); print GNUPLOT "reset\n"; print GNUPLOT "set xrange [0:360]\n"; print GNUPLOT "set ytics nomirror\n"; print GNUPLOT "set ylabel 'tefpwr'\n"; print GNUPLOT "set xzeroaxis\n"; print GNUPLOT "set title 'Flap actuation power (single blade)'\n"; print GNUPLOT "set xtics 0, 90, 360\n"; print GNUPLOT "plot "; my ($lt, $filecnt, $filecntlb, $filetot); $lt = 1; $filecnt = 1; $filecntlb = ""; $filetot = @_; foreach my $file (@_) { if ($filetot > 1) {$filecntlb = "$filecnt:"}; print GNUPLOT "'$file' u 1:2 t '$filecntlb tefpwr' w l lt $lt,"; ++$lt; ++$filecnt; } print GNUPLOT "(0==0 ? 0: 1/0) notitle w p pt 0 \n"; } sub plot_rtforce{ plot_set_xterm () if ( $term eq "x11" ); print GNUPLOT "reset\n"; print GNUPLOT "set xrange [0:360]\n"; print GNUPLOT "set ytics nomirror\n"; print GNUPLOT "set ylabel 'fx'\n"; print GNUPLOT "set y2tics nomirror\n"; print GNUPLOT "set y2label 'fy & fz'\n"; print GNUPLOT "set xzeroaxis\n"; print GNUPLOT "set x2zeroaxis\n"; print GNUPLOT "set title 'Blade root forces (rotating frame)'\n"; print GNUPLOT "set xtics 0, 90, 360\n"; print GNUPLOT "plot "; my ($lt, $filecnt, $filecntlb, $filetot); $lt = 1; $filecnt = 1; $filecntlb = ""; $filetot = @_; foreach my $file (@_) { if ($filetot > 1) {$filecntlb = "$filecnt:"}; print GNUPLOT "'$file' u 1:2 t '$filecntlb fx' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:3 axis x1y2 t '$filecntlb fy' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:4 axis x1y2 t '$filecntlb fz' w l lt $lt,"; ++$lt; ++$filecnt; } print GNUPLOT "(0==0 ? 0: 1/0) axis x1y2 notitle w l lt 0 \n"; } sub plot_rtmoment{ plot_set_xterm () if ( $term eq "x11" ); print GNUPLOT "reset\n"; print GNUPLOT "set xrange [0:360]\n"; print GNUPLOT "set ytics nomirror\n"; print GNUPLOT "set y2tics nomirror\n"; print GNUPLOT "set ylabel 'mx'\n"; print GNUPLOT "set y2label 'my & mz'\n"; print GNUPLOT "set xzeroaxis\n"; print GNUPLOT "set x2zeroaxis\n"; print GNUPLOT "set title 'Blade root moments (rotating frame)'\n"; print GNUPLOT "set xtics 0, 90, 360\n"; print GNUPLOT "plot "; my ($lt, $filecnt, $filecntlb, $filetot); $lt = 1; $filecnt = 1; $filecntlb = ""; $filetot = @_; foreach my $file (@_) { if ($filetot > 1) {$filecntlb = "$filecnt:"}; print GNUPLOT "'$file' u 1:5 t '$filecntlb mx' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:6 axis x1y2 t '$filecntlb my' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:7 axis x1y2 t '$filecntlb mz' w l lt $lt,"; ++$lt; ++$filecnt; } print GNUPLOT "(0==0 ? 0: 1/0) notitle w l lt 0 \n"; } sub plot_rtfm{ plot_rtforce(@_); plot_rtmoment(@_); } sub plot_rtfmm{ plot_set_xterm () if ( $term eq "x11" ); print GNUPLOT "reset\n"; print GNUPLOT "set xrange [0:360]\n"; print GNUPLOT "set ytics nomirror\n"; print GNUPLOT "set y2tics nomirror\n"; print GNUPLOT "set ylabel 'force'\n"; print GNUPLOT "set xzeroaxis\n"; print GNUPLOT "set x2zeroaxis\n"; print GNUPLOT "set y2label 'moment'\n"; print GNUPLOT "set title 'Blade root forces & moments (rotating frame)'\n"; print GNUPLOT "set xtics 0, 90, 360\n"; print GNUPLOT "plot "; my ($lt, $filecnt, $filecntlb, $filetot); $lt = 1; $filecnt = 1; $filecntlb = ""; $filetot = @_; foreach my $file (@_) { if ($filetot > 1) {$filecntlb = "$filecnt:"}; print GNUPLOT "'$file' u 1:2 t '$filecntlb fx' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:3 t '$filecntlb fy' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:4 t '$filecntlb fz' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:5 axis x1y2 t '$filecntlb mx' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:6 axis x1y2 t '$filecntlb my' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:7 axis x1y2 t '$filecntlb mz' w l lt $lt,"; ++$lt; ++$filecnt; } print GNUPLOT "(0==0 ? 0: 1/0) notitle w l lt 0 \n"; } sub plot_hbforce{ plot_set_xterm () if ( $term eq "x11" ); print GNUPLOT "reset\n"; print GNUPLOT "set xrange [0:360]\n"; print GNUPLOT "set ytics nomirror\n"; print GNUPLOT "set y2tics nomirror\n"; print GNUPLOT "set ylabel 'fx & fy'\n"; print GNUPLOT "set xzeroaxis\n"; print GNUPLOT "set x2zeroaxis\n"; print GNUPLOT "set y2label 'fz'\n"; print GNUPLOT "set title 'Hub forces in nonrotating frame'\n"; print GNUPLOT "set xtics 0, 90, 360\n"; print GNUPLOT "plot "; my ($lt, $filecnt, $filecntlb, $filetot); $lt = 1; $filecnt = 1; $filecntlb = ""; $filetot = @_; foreach my $file (@_) { if ($filetot > 1) {$filecntlb = "$filecnt:"}; print GNUPLOT "'$file' u 1:2 t '$filecntlb fx' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:3 t '$filecntlb fy' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:4 axis x1y2 t '$filecntlb fz' w l lt $lt,"; ++$lt; ++$filecnt; } print GNUPLOT "(0==0 ? 0: 1/0) notitle w l lt 0 \n"; } sub plot_hbmoment{ plot_set_xterm () if ( $term eq "x11" ); print GNUPLOT "reset\n"; print GNUPLOT "set xrange [0:360]\n"; print GNUPLOT "set ytics nomirror\n"; print GNUPLOT "set y2tics nomirror\n"; print GNUPLOT "set ylabel 'mx & my'\n"; print GNUPLOT "set xzeroaxis\n"; print GNUPLOT "set x2zeroaxis\n"; print GNUPLOT "set y2label 'mz'\n"; print GNUPLOT "set title 'Hub moments in nonrotating frame'\n"; print GNUPLOT "set xtics 0, 90, 360\n"; print GNUPLOT "plot "; my ($lt, $filecnt, $filecntlb, $filetot); $lt = 1; $filecnt = 1; $filecntlb = ""; $filetot = @_; foreach my $file (@_) { if ($filetot > 1) {$filecntlb = "$filecnt:"}; print GNUPLOT "'$file' u 1:5 t '$filecntlb mx' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:6 t '$filecntlb my' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:7 axis x1y2 t '$filecntlb mz' w l lt $lt,"; ++$lt; ++$filecnt; } print GNUPLOT "(0==0 ? 0: 1/0) notitle w l lt 0 \n"; } sub plot_hbfm{ plot_hbforce(@_); plot_hbmoment(@_); } sub getcol{ # return how many column this data file has my ($colold, $col, $row, $line, @fields); open(INFILE, $_[0]) || die "cannot open $_[0] for reading: $!"; $colold = -1; $row = 0; while (($line = )) { chomp($line); $line =~ s/(,|\t|\s)+/:/g; # use : as seperator $line =~ s/^://; # remove the leading : $line =~ s/:$//; # remove the trailing : next if $line =~ /^\s*$/; # skip empty line next if $line =~ /^( |\t|\s)*(#|%)/; # non numerical value # print "$line $col\n"; @fields = split(/:/, $line); $col = @fields; ++$row; if ($colold != -1 && $colold != $col) { print "$_[0] is not a matrix data file!\n"; last; } $colold = $col; last; # we only want to know col now } close(INFILE); return $col; } sub print_usage () { print <<"EOF"; Usage: plotum.pl [-htkv] [-o outputfile.ps] [-s options] [files...] plot result from UMARC output file [fort.9]. -h, print this help and exit -v, verbose -t, plot to postscript file (Default plotum.ps) -k, keep the temporary data files ploted by gnuplot -o, postscript file name -s plot what, value from below tiprsps: blade tip response eltw: elastic twist distribution pl: Pitch link loads normalized to mdrsps: Blade modal response rtfm: blade root forces & moments (rotating frame) hbfm: hub loads in nonrotating frame tefhmnt: Flap hinge moments (nondimensional, total flaps) tefpwr: Flap actuation power (nondim., single blade) tefhgmt: TEF hinge motion response all: all of them Report bugs to shenjw\@wam.umd.edu EOF exit 1; } sub plot_set_xterm () { print GNUPLOT "set term x11 $xtermcntr\n"; ++$xtermcntr; } sub plot_tef_disp_rate{ plot_set_xterm () if ( $term eq "x11" ); print GNUPLOT "reset\n"; print GNUPLOT "set xrange [0:360]\n"; print GNUPLOT "set ytics nomirror\n"; print GNUPLOT "set ylabel 'tef disp'\n"; print GNUPLOT "set y2tics nomirror\n"; print GNUPLOT "set y2label 'tef rate'\n"; print GNUPLOT "set xzeroaxis\n"; print GNUPLOT "set x2zeroaxis\n"; print GNUPLOT "set title 'TEF deflection (disp. & rate)'\n"; print GNUPLOT "set xtics 0, 90, 360\n"; print GNUPLOT "plot "; my ($lt, $filecnt, $filecntlb, $filetot); $lt = 1; $filecnt = 1; $filecntlb = ""; $filetot = @_; foreach my $file (@_) { if ($filetot > 1) {$filecntlb = "$filecnt:"}; print GNUPLOT "'$file' u 1:2 t '$filecntlb disp' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:3 axis x1y2 t '$filecntlb rate' w l lt $lt,"; ++$lt; ++$filecnt; } print GNUPLOT "(0==0 ? 0: 1/0) axis x1y2 notitle w l lt 0 \n"; } sub plot_tef_acce{ plot_set_xterm () if ( $term eq "x11" ); print GNUPLOT "reset\n"; print GNUPLOT "set xrange [0:360]\n"; print GNUPLOT "set ytics nomirror\n"; print GNUPLOT "set y2tics nomirror\n"; print GNUPLOT "set ylabel 'acce. (from eq)'\n"; print GNUPLOT "set y2label 'acce. (dif.)'\n"; print GNUPLOT "set xzeroaxis\n"; print GNUPLOT "set x2zeroaxis\n"; print GNUPLOT "set title 'TEF deflection (accelation)'\n"; print GNUPLOT "set xtics 0, 90, 360\n"; print GNUPLOT "plot "; my ($lt, $filecnt, $filecntlb, $filetot); $lt = 1; $filecnt = 1; $filecntlb = ""; $filetot = @_; foreach my $file (@_) { if ($filetot > 1) {$filecntlb = "$filecnt:"}; print GNUPLOT "'$file' u 1:4 t '$filecntlb acce (eq)' w l lt $lt,"; ++$lt; print GNUPLOT "'$file' u 1:5 axis x1y2 t '$filecntlb acce (dif)' w l lt $lt,"; ++$lt; ++$filecnt; } print GNUPLOT "(0==0 ? 0: 1/0) notitle w l lt 0 \n"; } sub plot_tefhgmt{ plot_tef_disp_rate(@_); plot_tef_acce(@_); } sub retrieve{ my $argtot = @_; die "sub retrieve need 3 argument: $!" if ($argtot != 3); my $keyword = $_[0]; my $infile = $_[1]; my $outfile = $_[2]; my ($IN, $OUT, $foundit, $skipln, $count); $foundit = 0; # initialize use Fcntl ':flock'; # import LOCK_* constants open(IN, "<$infile") or die "Can't open $infile: $!"; open(OUT, ">$outfile") or die "Can't open $outfile: $!"; flock(IN,LOCK_EX); flock(OUT,LOCK_EX); # lock both files while () { chomp; if ($_ =~ /$keyword/) { $foundit = 1; $skipln = 4; # how many lines after keyword there are data } if ($foundit == 1) { $count++; if (($count > $skipln) && ($_ =~ /^ *[A-z=]/)) { $foundit = 0; # non digital line, data block end } else { if ($_ =~ /^[ (]*[A-z]/) { print OUT '# ' . $_ . "\n"; # add comment char in front of nondigital line } else { print OUT $_ . "\n"; # data line } } } } flock(IN,LOCK_UN); flock(OUT,LOCK_UN); # unlock both files close(IN); close(OUT); }