File: suta.c

package info (click to toggle)
gpivtools 0.6.0-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,472 kB
  • ctags: 528
  • sloc: ansic: 6,804; sh: 5,105; perl: 1,035; makefile: 299; python: 207
file content (240 lines) | stat: -rw-r--r-- 6,858 bytes parent folder | download | duplicates (3)
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
/* -*- 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.6 2008-09-25 13:08:34 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", argv[0]); 
                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", argv[0]);
                    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", argv[0], *argv);
		}
		argc_next = 1;
		break;
                
            default:
                gpiv_error(USAGE);
                break;
            }
    }

    if(argc != 2) { 
        gpiv_error("%s: %s", argv[0], 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 = 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];
    guint i, j;
    
    GpivPivData *in_data = NULL, *mean_data = NULL, *out_data = 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 ((fp = fopen (fname_in, "r")) == NULL) {
        gpiv_error ("%s: failing opening %s", argv[0], fname_in);
    }

    if ((in_data = gpiv_read_pivdata (fp)) == NULL) {
        gpiv_error ("%s: failing gpiv_read_pivdata", argv[0], err_msg);
    }
    fclose (fp);



    if ((fp = fopen (fname_mean, "r")) == NULL) {
        gpiv_error ("%s: failing opening %s", argv[0], fname_mean);
    }

    if ((mean_data = gpiv_read_pivdata (fp)) == NULL) {
        gpiv_error ("%s: gpiv_read_pivdata", argv[0], err_msg);
    }
    fclose (fp);


    out_data = gpiv_alloc_pivdata (in_data->nx, in_data->ny);

    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 ((fp = fopen (fname_out, "w")) == NULL) {
        gpiv_error ("%s: failing opening %s", argv[0], fname_out);
    }

    if ((err_msg = gpiv_write_pivdata(fp, out_data, TRUE)) != NULL) {
        gpiv_error ("%s: %s", argv[0], err_msg);
    }
    fclose (fp);
    


    gpiv_free_pivdata (in_data);
    gpiv_free_pivdata (mean_data);
    exit (0);
}