1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 c-style: "K&R" -*- */
/*-----------------------------------------------------------------------------
suta - subtracts time-avaraged velocities (local mean velocities) from
the PIV estimators
Copyright (C) 2002, 2003, 2004 Gerber van der Graaf
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, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-----------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <gpiv.h>
/* #define PARFILE "scale.par" */ /* Parameter file name */
#define PARFILE "gpivrc" /* Parameter file name */
#define MAX_PIVSETS 1000 /* Maximum number of PIV data sets */
#define MIN_SAMPLES 20 /* Minimum number of samples used for estimation */
#define USAGE "\
Usage: suta [-h | --help] [-p | --print] [-v | --version] \n\
filename_ta filename \n\
\n\
keys: \n\
-h | --help: this on-line help \n\
-p | --print: print parameters to stdout \n\
-v | --version: version number \n\
filename File name of PIV data set (without .piv) \n\
filename_ta File name of time-averaged (local means) PIV data set \n\
(full name) \n\
"
#define HELP "\
suta - subtracts time-avaraged velocities (local mean) from the PIV estimators"
#define RCSID "$Id: suta.c,v 1.4 2006/01/31 14:18:04 gerber Exp $"
gboolean print_par = FALSE;
void
command_args(int argc,
char *argv[],
char fname_in[GPIV_MAX_CHARS],
char fname_mean[GPIV_MAX_CHARS]
)
/* ----------------------------------------------------------------------------
* Command line argument handling
*/
{
char c = '\0';
int argc_next;
while (--argc > 0 && (*++argv)[0] == '-') {
/*
* argc_next is set to 1 if the next cmd line argument has to be searched for;
* in case that the command line argument concerns more than one char or cmd
* line argument needs a parameter
*/
argc_next = 0;
while (argc_next == 0 && (c = *++argv[0]))
switch (c) {
case 'v':
printf("%s\n", RCSID);
exit(0);
break;
case 'h':
printf("%s\n", RCSID);
printf("%s\n",HELP);
printf("%s\n",USAGE);
exit(0);
break;
case 'p':
print_par = TRUE;
break;
/*
* long option keys
*/
case '-':
if (strcmp("-help", *argv) == 0) {
printf("\n%s", RCSID);
printf("\n%s", HELP);
printf("\n%s", USAGE);
exit(0);
} else if (strcmp("-print", *argv) == 0) {
print_par = TRUE;
} else if (strcmp("-version", *argv) == 0) {
printf("%s\n", RCSID);
exit(0);
} else {
gpiv_error("%s: unknown option: %s", RCSID, *argv);
}
argc_next = 1;
break;
default:
gpiv_error(USAGE);
break;
}
}
if(argc != 2) {
gpiv_error("%s: %s", RCSID, USAGE);
}
strcpy(fname_mean, argv[0]);
strcpy(fname_in, argv[1]);
}
void
make_fname(char *fname,
char *fname_in,
char *fname_out
)
/* ----------------------------------------------------------------------------
* define input and output filenames
*/
{
gpiv_io_make_fname(fname, GPIV_EXT_PIV, fname_in);
if (print_par) printf("# Input data file: %s\n",fname_in);
/*
* Extension of filename with time-averaged reduced piv data
*/
#define EXT_SUB_TAVG_PIV ".suta.piv"
gpiv_io_make_fname(fname, EXT_SUB_TAVG_PIV, fname_out);
if (print_par) printf("# Output data file: %s\n",fname_out);
}
int
main(int argc,
char *argv[]
)
/* ----------------------------------------------------------------------------
*/
{
/* FILE *fp_out = NULL; */
gchar *err_msg = NULL;
gchar fname[GPIV_MAX_CHARS],
fname_in[GPIV_MAX_CHARS],
fname_out[GPIV_MAX_CHARS],
fname_mean[GPIV_MAX_CHARS];
gint i, j, scale = 0;
gchar c_line[GPIV_MAX_LINES_C][GPIV_MAX_CHARS];
gint nc_lines = 0;
GpivPivData in_data, mean_data, out_data;
in_data.point_x = NULL;
in_data.point_y = NULL;
in_data.dx = NULL;
in_data.dy = NULL;
in_data.snr = NULL;
in_data.peak_no = NULL;
mean_data.point_x = NULL;
mean_data.point_y = NULL;
mean_data.dx = NULL;
mean_data.dy = NULL;
mean_data.snr = NULL;
mean_data.peak_no = NULL;
out_data.point_x = NULL;
out_data.point_y = NULL;
out_data.dx = NULL;
out_data.dy = NULL;
out_data.snr = NULL;
out_data.peak_no = NULL;
command_args(argc, argv, fname, fname_mean);
make_fname(fname, fname_in, fname_out);
if (print_par) {
g_message("fname_mean = %s", fname_mean);
}
if ((scale = gpiv_fcount_pivdata(fname_in, &in_data)) == -1) {
gpiv_error("%s: Failure calling gpiv_count_pivdata", RCSID);
return 1;
}
mean_data.nx = in_data.nx;
mean_data.ny = in_data.ny;
out_data.nx = in_data.nx;
out_data.ny = in_data.ny;
gpiv_alloc_pivdata(&in_data);
gpiv_alloc_pivdata(&mean_data);
gpiv_alloc_pivdata(&out_data);
if ((err_msg =
gpiv_fread_pivdata(fname_in, &in_data, c_line, &nc_lines))
!= NULL) gpiv_error ("%s: %s", RCSID, err_msg);
if ((err_msg =
gpiv_fread_pivdata(fname_mean, &mean_data, c_line, &nc_lines))
!= NULL) gpiv_error ("%s: %s", RCSID, err_msg);
for (i = 0; i < in_data.ny; i++) {
for (j = 0; j < in_data.nx; j++) {
out_data.point_x[i][j] = in_data.point_x[i][j];
out_data.point_y[i][j] = in_data.point_y[i][j];
out_data.peak_no[i][j] = in_data.peak_no[i][j];
if (mean_data.peak_no[i][j] > 0) {
out_data.snr[i][j] = in_data.snr[i][j];
out_data.dx[i][j] = in_data.dx[i][j] - mean_data.dx[i][j];
out_data.dy[i][j] = in_data.dy[i][j] - mean_data.dy[i][j];
} else {
out_data.snr[i][j] = GPIV_SNR_DISABLE;
out_data.dx[i][j] = 0.0;
out_data.dy[i][j] = 0.0;
}
}
}
if ((err_msg =
gpiv_fwrite_pivdata(fname_out, &out_data, c_line,
nc_lines, scale, RCSID))
!= NULL) gpiv_error ("%s: %s", RCSID, err_msg);
gpiv_free_pivdata(&in_data);
gpiv_free_pivdata(&mean_data);
gpiv_free_pivdata(&out_data);
exit(0);
}
|