Added option -U
[gpivtools.git] / src / misc / sca2gri.pl
blob8c2bf742a890489e2fbd174b048adc4e4aabb480
1 #!/usr/bin/perl -w
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)
12 # any later version.
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 $;
26 $PRG = "sca2gri";
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
31 keys:
32 -f fn: complete filename
33 -h: on-line help
34 -p: prints process parameters/variables to stdout
35 -v: prints version and exits sucessfully
39 #----------------- Command arguments handling ----------
40 $opt_h = 0;
41 $opt_v = 0;
43 #use lib "/home/gerber/lib";
44 #use FileBaseExt;
45 #use Getopt::Std;
46 #getopts('f:hpv');
47 use Getopt::Long;
48 GetOptions('h|help', 'p|print', 'v|version',
49 'f|filename=s' => \$full_filename
54 #$full_filename = $opt_f;
55 #if ($opt_f) {
56 # $filename_logic = 1;
59 if ($opt_h) {
60 print ("$HELP\n");
61 print ("$USAGE\n");
62 exit;
65 if ($opt_v) {
66 print ("$VERSION\n");
67 exit;
71 if ($#ARGV != -1) {
72 print ("Usage: $USAGE\n");
73 exit;
75 #--------------- initializing variables and functions
76 $x_old = 0;
79 sub FileExt {
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;
89 sub FileBase {
90 #--------------- extracts file basename from a full filename
91 my ($file_base_name, $file_extension);
92 @file_fields = split(/\./,$_[0]);
93 pop @file_fields;
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);
103 if ($opt_p) {
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;
112 if ($opt_p == 1) {
113 printf ("Scalar data file: %s\n", $file_name_sca);
114 printf ("Grid data file: %s\n", $file_name_gri);
116 #exit;
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
123 while (<STDIN>) {
124 chomp;
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
133 $x_pos = $words[0];
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) {
140 $x_old = $x_pos;
141 printf(STDOUT "\n");
143 printf(STDOUT "\n%s",$_);
147 close (STDIN) || die 'can\'t close $infile';
148 close (STDOUT) || die 'can\'t close $outfile';