3 # sca2grid - Converts scalar data from gpiv to grid data for contour
4 # plotting purposes with gnuplot, plotmtv, ..
6 # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
7 # Gerber van der Graaf <gerber_graaf@users.sourceforge.net
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software Foundation,
21 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #------------------------------------------------------------------
25 $VERSION = q
$Id: sca2gri
.pl
,v
1.5 2006-03-04 12:37:08 gerber Exp
$;
27 $HELP = "Converts scalar data from gpiv to grid data for contour plotting
28 purposes with gnuplot and plotmtv";
29 $USAGE = "Usage: gpiv_sca2gri [-f|filename fn] [-h] [-p] [-v] < input > output
32 -f fn: complete filename
34 -p: prints process parameters/variables to stdout
35 -v: prints version and exits sucessfully
39 #----------------- Command arguments handling ----------
43 #use lib "/home/gerber/lib";
48 GetOptions
('h|help', 'p|print', 'v|version',
49 'f|filename=s' => \
$full_filename
54 #$full_filename = $opt_f;
56 # $filename_logic = 1;
72 print ("Usage: $USAGE\n");
75 #--------------- initializing variables and functions
80 #--------------- extracts file extension from a full filename
81 my ($file_base_name, $file_extension);
82 @file_fields = split(/\./,$_[0]);
83 $file_extension = pop @file_fields;
84 $file_base_name = join(".", @file_fields);
85 return $file_extension;
90 #--------------- extracts file basename from a full filename
91 my ($file_base_name, $file_extension);
92 @file_fields = split(/\./,$_[0]);
94 $file_base_name = join(".", @file_fields);
95 return $file_base_name;
100 #---------------------------------------------------- Intializing variables
101 $file_base_name = FileBase
($full_filename);
102 $file_extension = FileExt
($full_filename);
104 printf("$PRG: file_base_name=%s\n", $file_base_name);
105 printf("$PRG: file_extension=%s\n", $file_extension);
108 $file_name_sca = $full_filename;
109 $file_name_gri = $file_base_name.".gri.".$file_extension;
110 $infile = $file_name_sca;
111 $outfile = $file_name_gri;
113 printf ("Scalar data file: %s\n", $file_name_sca);
114 printf ("Grid data file: %s\n", $file_name_gri);
118 open (STDIN
,"$infile") || die 'can\'t open $infile';
119 open (STDOUT
,">$outfile") || die 'can\'t open $outfile';
122 #----------------------------------------- Starts reading the lines with data
125 if ($_ ne "" && (!/^(\#|;)/)) { #skip blank lines or ; sign at first col
126 s/,/./g; #substitutes eventually komma's by dot
128 s/^ *//; #removes eventually leading spaces
129 @words = split(/\s+/,$_); #splitting line $_ up in words
130 #same as @words = split
134 # $y_pos[$k] = $words[1];
135 # $dx[$k] = $words[2];
136 # $dy[$k] = $words[3];
137 # $snr[$k] = $words[4];
138 # $peak_nr[$k] = $words[5];
139 if ($x_pos != $x_old) {
143 printf(STDOUT
"\n%s",$_);
147 close (STDIN
) || die 'can\'t close $infile';
148 close (STDOUT
) || die 'can\'t close $outfile';