1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 c-style: "K&R" -*- */
3 /*-----------------------------------------------------------------------------
5 suta - subtracts time-avaraged velocities (local mean velocities) from
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)
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 -----------------------------------------------------------------------------*/
35 /* #define PARFILE "scale.par" */ /* Parameter file name */
36 #define PARFILE "gpivrc" /* Parameter file name */
37 #define MAX_PIVSETS 1000 /* Maximum number of PIV data sets */
38 #define MIN_SAMPLES 20 /* Minimum number of samples used for estimation */
40 Usage: suta [-h | --help] [-p | --print] [-v | --version] \n\
41 filename_ta filename \n\
44 -h | --help: this on-line help \n\
45 -p | --print: print parameters to stdout \n\
46 -v | --version: version number \n\
47 filename File name of PIV data set (without .piv) \n\
48 filename_ta File name of time-averaged (local means) PIV data set \n\
53 suta - subtracts time-avaraged velocities (local mean) from the PIV estimators"
55 gboolean print_par
= FALSE
;
58 command_args(int argc
,
60 char fname_in
[GPIV_MAX_CHARS
],
61 char fname_mean
[GPIV_MAX_CHARS
]
63 /* ----------------------------------------------------------------------------
64 * Command line argument handling
70 while (--argc
> 0 && (*++argv
)[0] == '-') {
73 * argc_next is set to 1 if the next cmd line argument has to be searched for;
74 * in case that the command line argument concerns more than one char or cmd
75 * line argument needs a parameter
79 while (argc_next
== 0 && (c
= *++argv
[0]))
84 printf ("git hash: %s\n", GIT_REV
);
86 printf ("version: %s\n", GPIVTOOLS_VERSION
);
91 printf("%s\n", argv
[0]);
104 if (strcmp("-help", *argv
) == 0) {
105 printf("\n%s", argv
[0]);
106 printf("\n%s", HELP
);
107 printf("\n%s", USAGE
);
109 } else if (strcmp("-print", *argv
) == 0) {
111 } else if (strcmp("-version", *argv
) == 0) {
113 printf ("git hash: %s\n", GIT_REV
);
115 printf ("version: %s\n", GPIVTOOLS_VERSION
);
119 gpiv_error("%s: unknown option: %s", argv
[0], *argv
);
131 gpiv_error("%s: %s", argv
[0], USAGE
);
134 strcpy(fname_mean
, argv
[0]);
135 strcpy(fname_in
, argv
[1]);
142 make_fname(char *fname
,
146 /* ----------------------------------------------------------------------------
147 * define input and output filenames
150 gpiv_io_make_fname(fname
, GPIV_EXT_PIV
, fname_in
);
151 if (print_par
) printf("# Input data file: %s\n",fname_in
);
154 * Extension of filename with time-averaged reduced piv data
156 #define EXT_SUB_TAVG_PIV ".suta.piv"
157 gpiv_io_make_fname(fname
, EXT_SUB_TAVG_PIV
, fname_out
);
158 if (print_par
) printf("# Output data file: %s\n",fname_out
);
168 /* ----------------------------------------------------------------------------
172 gchar
*err_msg
= NULL
;
173 gchar fname
[GPIV_MAX_CHARS
],
174 fname_in
[GPIV_MAX_CHARS
],
175 fname_out
[GPIV_MAX_CHARS
],
176 fname_mean
[GPIV_MAX_CHARS
];
179 GpivPivData
*in_data
= NULL
, *mean_data
= NULL
, *out_data
= NULL
;
183 command_args(argc
, argv
, fname
, fname_mean
);
184 make_fname(fname
, fname_in
, fname_out
);
186 g_message("fname_mean = %s", fname_mean
);
191 if ((fp
= fopen (fname_in
, "r")) == NULL
) {
192 gpiv_error ("%s: failing opening %s", argv
[0], fname_in
);
195 if ((in_data
= gpiv_read_pivdata (fp
)) == NULL
) {
196 gpiv_error ("%s: failing gpiv_read_pivdata", argv
[0], err_msg
);
202 if ((fp
= fopen (fname_mean
, "r")) == NULL
) {
203 gpiv_error ("%s: failing opening %s", argv
[0], fname_mean
);
206 if ((mean_data
= gpiv_read_pivdata (fp
)) == NULL
) {
207 gpiv_error ("%s: gpiv_read_pivdata", argv
[0], err_msg
);
212 out_data
= gpiv_alloc_pivdata (in_data
->nx
, in_data
->ny
);
214 for (i
= 0; i
< in_data
->ny
; i
++) {
215 for (j
= 0; j
< in_data
->nx
; j
++) {
216 out_data
->point_x
[i
][j
] = in_data
->point_x
[i
][j
];
217 out_data
->point_y
[i
][j
] = in_data
->point_y
[i
][j
];
218 out_data
->peak_no
[i
][j
] = in_data
->peak_no
[i
][j
];
219 if (mean_data
->peak_no
[i
][j
] > 0) {
220 out_data
->snr
[i
][j
] = in_data
->snr
[i
][j
];
221 out_data
->dx
[i
][j
] = in_data
->dx
[i
][j
] - mean_data
->dx
[i
][j
];
222 out_data
->dy
[i
][j
] = in_data
->dy
[i
][j
] - mean_data
->dy
[i
][j
];
224 out_data
->snr
[i
][j
] = GPIV_SNR_DISABLE
;
225 out_data
->dx
[i
][j
] = 0.0;
226 out_data
->dy
[i
][j
] = 0.0;
232 if ((fp
= fopen (fname_out
, "w")) == NULL
) {
233 gpiv_error ("%s: failing opening %s", argv
[0], fname_out
);
236 if ((err_msg
= gpiv_write_pivdata(fp
, out_data
, TRUE
)) != NULL
) {
237 gpiv_error ("%s: %s", argv
[0], err_msg
);
243 gpiv_free_pivdata (in_data
);
244 gpiv_free_pivdata (mean_data
);