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 -----------------------------------------------------------------------------*/
33 /* #define PARFILE "scale.par" */ /* Parameter file name */
34 #define PARFILE "gpivrc" /* Parameter file name */
35 #define MAX_PIVSETS 1000 /* Maximum number of PIV data sets */
36 #define MIN_SAMPLES 20 /* Minimum number of samples used for estimation */
38 Usage: suta [-h | --help] [-p | --print] [-v | --version] \n\
39 filename_ta filename \n\
42 -h | --help: this on-line help \n\
43 -p | --print: print parameters to stdout \n\
44 -v | --version: version number \n\
45 filename File name of PIV data set (without .piv) \n\
46 filename_ta File name of time-averaged (local means) PIV data set \n\
51 suta - subtracts time-avaraged velocities (local mean) from the PIV estimators"
53 #define RCSID "$Id: suta.c,v 1.6 2008-09-25 13:08:34 gerber Exp $"
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]))
83 printf("%s\n", RCSID
);
87 printf("%s\n", argv
[0]);
100 if (strcmp("-help", *argv
) == 0) {
101 printf("\n%s", argv
[0]);
102 printf("\n%s", HELP
);
103 printf("\n%s", USAGE
);
105 } else if (strcmp("-print", *argv
) == 0) {
107 } else if (strcmp("-version", *argv
) == 0) {
108 printf("%s\n", RCSID
);
111 gpiv_error("%s: unknown option: %s", argv
[0], *argv
);
123 gpiv_error("%s: %s", argv
[0], USAGE
);
126 strcpy(fname_mean
, argv
[0]);
127 strcpy(fname_in
, argv
[1]);
134 make_fname(char *fname
,
138 /* ----------------------------------------------------------------------------
139 * define input and output filenames
142 gpiv_io_make_fname(fname
, GPIV_EXT_PIV
, fname_in
);
143 if (print_par
) printf("# Input data file: %s\n",fname_in
);
146 * Extension of filename with time-averaged reduced piv data
148 #define EXT_SUB_TAVG_PIV ".suta.piv"
149 gpiv_io_make_fname(fname
, EXT_SUB_TAVG_PIV
, fname_out
);
150 if (print_par
) printf("# Output data file: %s\n",fname_out
);
160 /* ----------------------------------------------------------------------------
164 gchar
*err_msg
= NULL
;
165 gchar fname
[GPIV_MAX_CHARS
],
166 fname_in
[GPIV_MAX_CHARS
],
167 fname_out
[GPIV_MAX_CHARS
],
168 fname_mean
[GPIV_MAX_CHARS
];
171 GpivPivData
*in_data
= NULL
, *mean_data
= NULL
, *out_data
= NULL
;
175 command_args(argc
, argv
, fname
, fname_mean
);
176 make_fname(fname
, fname_in
, fname_out
);
178 g_message("fname_mean = %s", fname_mean
);
183 if ((fp
= fopen (fname_in
, "r")) == NULL
) {
184 gpiv_error ("%s: failing opening %s", argv
[0], fname_in
);
187 if ((in_data
= gpiv_read_pivdata (fp
)) == NULL
) {
188 gpiv_error ("%s: failing gpiv_read_pivdata", argv
[0], err_msg
);
194 if ((fp
= fopen (fname_mean
, "r")) == NULL
) {
195 gpiv_error ("%s: failing opening %s", argv
[0], fname_mean
);
198 if ((mean_data
= gpiv_read_pivdata (fp
)) == NULL
) {
199 gpiv_error ("%s: gpiv_read_pivdata", argv
[0], err_msg
);
204 out_data
= gpiv_alloc_pivdata (in_data
->nx
, in_data
->ny
);
206 for (i
= 0; i
< in_data
->ny
; i
++) {
207 for (j
= 0; j
< in_data
->nx
; j
++) {
208 out_data
->point_x
[i
][j
] = in_data
->point_x
[i
][j
];
209 out_data
->point_y
[i
][j
] = in_data
->point_y
[i
][j
];
210 out_data
->peak_no
[i
][j
] = in_data
->peak_no
[i
][j
];
211 if (mean_data
->peak_no
[i
][j
] > 0) {
212 out_data
->snr
[i
][j
] = in_data
->snr
[i
][j
];
213 out_data
->dx
[i
][j
] = in_data
->dx
[i
][j
] - mean_data
->dx
[i
][j
];
214 out_data
->dy
[i
][j
] = in_data
->dy
[i
][j
] - mean_data
->dy
[i
][j
];
216 out_data
->snr
[i
][j
] = GPIV_SNR_DISABLE
;
217 out_data
->dx
[i
][j
] = 0.0;
218 out_data
->dy
[i
][j
] = 0.0;
224 if ((fp
= fopen (fname_out
, "w")) == NULL
) {
225 gpiv_error ("%s: failing opening %s", argv
[0], fname_out
);
228 if ((err_msg
= gpiv_write_pivdata(fp
, out_data
, TRUE
)) != NULL
) {
229 gpiv_error ("%s: %s", argv
[0], err_msg
);
235 gpiv_free_pivdata (in_data
);
236 gpiv_free_pivdata (mean_data
);