updated copyright statement
[gpivtools.git] / src / misc / process-chain.pl
blobc331776ec458ffc6d6bada297014c6ea4da1b97a
1 #!/usr/bin/perl -w
3 # process-chain - A complete process chain on a single image in tif/bmp
4 # format using gpiv tools resulting into estimated PIV velocities
5 # or its derivatives.
8 # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
9 # Gerber van der Graaf <gerber_graaf@users.sourceforge.net
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2, or (at your option)
14 # any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software Foundation,
23 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #--------------------------------------------------------------------
27 $VERSION = q$Id: process-chain.pl,v 1.7 2007-01-29 14:26:54 gerber Exp $;
28 $HELP = "Processes a pipe of Gpiv-tool commands";
29 $USAGE = "gpiv_process-chain [-h|-help] [-n|-none] [-af] [-c|-clean] [-fik]
30 [-p|-print] [proc_*] [-v|-version] filename
32 keys:
33 -af string: append string to file_basename
34 -c: removes raw image data and header
35 -fik: use fi-keyline for filtering gpiv parms from README
36 -h: this on-line help
37 -n: suppresses real execution
38 -p: prints process commands to stdout
39 -pf string prepend string to file-base name
40 -proc_* defines processes to be included in the chain (recimg,
41 valid, scale, manipiv, flipx, flipy, revert, rot90, rot180
42 and vorty or nstrain or sstrain). Proc_vorty, proc_nstrain
43 and proc_sstrain not in combination with .gpi input file.
44 -v: prints version
45 filename input image filename. Format may be: .r, .gpi (hdf), .IMG
46 (davis), png, gif, tif or bmp
49 #----------------- Command line arguments handling ----------
50 ##$opt_a = 0;
51 ## $opt_c = 0;
52 $opt_fik = 0;
53 $opt_h = 0;
54 $opt_n = 0;
55 $opt_p = 0;
56 $opt_v = 0;
58 $opt_proc_recimg = 0;
59 $opt_proc_valid = 0;
60 $opt_proc_scale = 0;
61 $opt_proc_manipiv = 0;
62 $opt_proc_flipx = 0;
63 $opt_proc_flipy = 0;
64 $opt_proc_revert = 0;
65 $opt_proc_rot90 = 0;
66 $opt_proc_rot180 = 0;
67 $opt_proc_vorty = 0;
68 $opt_proc_nstrain = 0;
69 $opt_proc_sstrain = 0;
71 #$post_spatial_scale = 0.0; # [mm/px]
72 #$post_time_scale = .0; # [s]
73 #$post_zero_offx = 0.0; # [mm]
74 #$post_zero_offy = 0.0; # [mm]
76 use Getopt::Long;
77 ##$result =
78 GetOptions('h|help', 'n|none', 'p|print', 'v|version',
79 'c|clean',
80 'af=s' => \$append_fname,
81 't=s' => \$img_format,
82 'pf=s' => \$prepend_fname,
83 'fik',
84 'proc_recimg',
85 'proc_valid',
86 'proc_scale',
87 'proc_manipiv',
88 'proc_flipx',
89 'proc_flipy',
90 'proc_revert',
91 'proc_rot90',
92 'proc_rot180',
93 'proc_vorty',
94 'proc_nstrain',
95 'proc_sstrain'
99 if ($opt_h) {
100 print ("$HELP\n");
101 print ("$USAGE\n");
102 exit;
104 if ($opt_v) {
105 print ("$VERSION\n");
106 exit;
109 #printf ("argc = $#ARGV\n");
110 if ($#ARGV == 0) {
111 # ------------- splitting $filename up
112 $use_stdin_stdout = 0;
113 $filename = shift (@ARGV);
114 } elsif ($#ARGV == -1) {
115 #BUGFIX: TODO: $use_stdin_stdout = 1;
116 # if ($opt_p || $opt_n) {print ("using STDIN/STDOUT\n");}
117 printf ("\nUsage: $USAGE\n");
118 exit;
120 } else {
121 printf ("\nUsage: $USAGE\n");
122 exit;
124 # exit;
127 sub FileExt {
128 #--------------- extracts file extension from a full filename
129 my ($file_base_name, $file_extension);
130 @file_fields = split(/\./,$_[0]);
131 $file_extension = pop @file_fields;
132 $file_base_name = join(".", @file_fields);
133 return $file_extension;
137 sub FileBase {
138 #--------------- extracts file basename from a full filename
139 my ($file_base_name, $file_extension);
140 @file_fields = split(/\./,$_[0]);
141 pop @file_fields;
142 $file_base_name = join(".", @file_fields);
143 return $file_base_name;
148 #---------------------------------------------------- Intializing variables
149 $file_basename = FileBase($filename);
150 $img_format = FileExt($filename);
151 if ($opt_p || $opt_n) {
152 print("file_basename = $file_basename img_format = $img_format\n");
155 if ($opt_proc_vorty && $opt_proc_nstrain
156 || $opt_proc_vorty && $opt_proc_sstrain
157 || $opt_proc_sstrain && $opt_proc_nstrain) {
158 print ("Only one of the processes proc_vorty, proc_sstrain or proc_nstrain may be enabled\n");
159 exit;
162 if (($img_format && $img_format =~ "gpi") && $opt_proc_vorty
163 || ($img_format && $img_format =~ "gpi") && $opt_proc_sstrain
164 || ($img_format && $img_format =~ "gpi") && $opt_proc_nstrain) {
165 print ("proc_vorty, proc_sstrain or proc_nstrain may no be enabled in combination with -t hdf\n");
166 exit;
169 # ----------------- Default pars and Initial variables
170 if ($use_stdin_stdout == 0) {
171 if ($append_fname) {
172 $out_basefile = $file_basename.$append_fname;
175 if ($prepend_fname) {
176 @words = split(/\//, $file_basename); #splitting line $_ up in words
177 #printf("nwords = $#words\n");
178 for ($i=0; $i <= $#words; $i = $i+1) {
179 #printf("words[$i] = $words[$i]\n");
181 $words[$#words] = $prepend_fname.$words[$#words];
182 #printf("words[$#words] = $words[$#words]\n");
183 $out_basefile = join("/", @words);
184 #$prepend_fname.$file_basename;
185 #printf("out_basefile = $out_basefile\n");
188 if ($append_fname || $prepend_fname) {
189 $parfile = $out_basefile.".par";
190 if ($opt_proc_vorty) {
191 $out_file = $out_basefile.".vor";
192 } elsif ($opt_proc_nstrain) {
193 $out_file = $out_basefile.".nstr";
194 } elsif ($opt_proc_sstrain) {
195 $out_file = $out_basefile.".sstr";
196 } else {
197 $out_file = $out_basefile.".piv";
199 } else {
200 $parfile = $file_basename.".par";
201 if ($opt_proc_vorty) {
202 $out_file = $file_basename.".vor";
203 } elsif ($opt_proc_nstrain) {
204 $out_file = $file_basename.".nstr";
205 } elsif ($opt_proc_sstrain) {
206 $out_file = $file_basename.".sstr";
207 } else {
208 $out_file = $file_basename.".piv";
216 # ----------------- gpivtools image conversion program names
217 $fi_keyline = "gpiv_fi-keyline";
219 # ----------------- Filter parameters from README
220 if ($opt_fik) {
221 @words = split(/\//, $file_basename); #splitting line $_ up in words
222 $keyword = $words[$#words - 1];
223 $keyword = $keyword.">>";
224 @args=("$fi_keyline -if README -of gpivrc \"$keyword\"");
225 if ($opt_p || $opt_n) {printf ("@args \n");}
226 if (!$opt_n) {system (@args) == 0 || die "system @args failed: $?";}
229 # ----------------- Creating chain and execute
230 # $out_file
231 $CMD = "";
232 if ($opt_proc_recimg) {
233 $CMD = "gpiv_recimg ";
234 $CMD = $CMD."| gpiv_rr ";
235 } else {
236 if ($use_stdin_stdout == 1) {
237 $CMD = "gpiv_rr < <STDIN> "; #STDIN
238 } else {
239 $CMD = "gpiv_rr < $filename ";
243 if ($opt_proc_valid) {$CMD = $CMD."| gpiv_errvec ";}
244 if ($opt_proc_scale) {$CMD = $CMD."| gpiv_scale ";}
245 if ($opt_proc_manipiv) {$CMD = $CMD."| gpiv_manipiv ";}
246 if ($opt_proc_flipx) {$CMD = $CMD."| gpivflipx ";}
247 if ($opt_proc_flipy) {$CMD = $CMD."| gpiv_flipy ";}
248 if ($opt_proc_revert) {$CMD = $CMD."| gpiv_revert ";}
249 if ($opt_proc_rot90) {$CMD = $CMD."| gpiv_rot90 ";}
250 if ($opt_proc_rot180) {$CMD = $CMD."| gpiv_rot180 ";}
251 if ($opt_proc_vorty) {$CMD = $CMD."| gpiv_vorty ";}
252 if ($opt_proc_nstrain) {$CMD = $CMD."| gpiv_nstrain ";}
253 if ($opt_proc_sstrain) {$CMD = $CMD."| gpiv_sstrain ";}
255 if ($use_stdin_stdout == 1) {
256 $CMD = $CMD." > <STDOUT>"; #STDOUT
257 } else {
258 $CMD = $CMD." > $out_file";
260 #@args=("$eval < $file_basename.png | $valid | $post1 | $post2 > $out_file");
261 @args=($CMD);
263 if ($opt_p || $opt_n) {printf ("@args \n");}
264 if (!$opt_n) {system (@args) == 0 || die "system @args failed: $?";}
267 # ----------------- Save the pararameters
268 # @args=("cp gpivrc $parfile");
269 # if ($opt_p || $opt_n) {printf ("@args \n");}
270 # if (!$opt_n) {system (@args) == 0 || die "system @args failed: $?";}
272 if ($img_format && $img_format =~ "gpi") {
273 @args=("piv2hdf -i $file_basename.piv");
274 if ($opt_p || $opt_n) {printf ("@args \n");}
275 if (!$opt_n) {system (@args) == 0 || die "system @args failed: $?";}
279 #------------------------------------------------------------------------------
281 # that's all folks!