1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 c-style: "K&R" -*- */
3 /*---------------------------------------------------------------------------
5 piv2h5 - converts PIV data to hdf5 format data
7 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
8 Gerber van der Graaf <gerber_graaf@users.sourceforge.net
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software Foundation,
22 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 ------------------------------------------------------------------------*/
31 /* #define PARFILE "scale.par" */ /* Parameter file name */
32 #define PARFILE "gpivrc" /* Parameter file name */
34 Usage: piv2grid [-h | --help] [-p | --print] [-v | --version] [-t type] \n\
38 -h | --help: this on-line help \n\
39 -p | --print: print parameters to stdout \n\
40 -v | --version: version number \n\
41 -t: select which data to be stored on grid; dx, dy or snr \n\
46 piv2grid - converts PIV data to grid data for generating contour plots \n\
50 #define RCSID "$Id: piv2grid.c,v 1.9 2008-09-25 13:08:34 gerber Exp $"
58 gboolean print_par
= FALSE
;
63 command_args(int argc
,
65 char fname
[GPIV_MAX_CHARS
],
66 enum DataType
*datatype
68 /*-----------------------------------------------------------------------------
69 * Command line argument handling
75 while (--argc
> 0 && (*++argv
)[0] == '-') {
78 * argc_next is set to 1 if the next cmd line argument has to be searched for;
79 * in case that the command line argument concerns more than one char or cmd
80 * line argument needs a parameter
83 while (argc_next
== 0 && (c
= *++argv
[0])) {
87 printf("%s\n", RCSID
);
91 printf("%s\n", argv
[0]);
100 if (strcmp("dx", *argv
) == 0) {
104 if (strcmp("dy", *argv
) == 0) {
108 if (strcmp("snr", *argv
) == 0) {
111 gpiv_error("piv2grid: wrong specification of data type");
119 if (strcmp("-help", *argv
) == 0) {
120 printf("\n%s", argv
[0]);
121 printf("\n%s", HELP
);
122 printf("\n%s", USAGE
);
124 } else if (strcmp("-print", *argv
) == 0) {
126 } else if (strcmp("-version", *argv
) == 0) {
127 printf("%s\n", RCSID
);
130 gpiv_error("%s: unknown option: %s", argv
[0], *argv
);
136 fprintf (stderr
,USAGE
);
144 gpiv_error("%s: %s", argv
[0], USAGE
);
146 strcpy(fname
, argv
[0]);
153 make_fname(char *fname
,
157 /*-----------------------------------------------------------------------------
161 gpiv_io_make_fname(fname
, GPIV_EXT_PIV
, fname_piv
);
162 if (print_par
) printf("# Input data file: %s\n",fname_piv
);
164 gpiv_io_make_fname(fname
, ".grid", fname_out
);
165 if (print_par
) printf("# Output file: %s\n",fname_out
);
179 /* ----------------------------------------------------------------------------
180 * main routine to convert PIV data to grid data for generating contour plots
184 gchar
*err_msg
= NULL
;
185 gchar fname
[GPIV_MAX_CHARS
],
186 fname_out
[GPIV_MAX_CHARS
],
187 fname_piv
[GPIV_MAX_CHARS
],
188 fname_parameter
[GPIV_MAX_CHARS
];
191 GpivPivData
*piv_data
= NULL
;
192 GpivScalarData
*sc_data
= NULL
;
193 enum DataType datatype
= DT_SNR
;
196 command_args (argc
, argv
, fname
, &datatype
);
197 make_fname (fname
, fname_piv
, fname_out
);
198 gpiv_io_make_fname (fname
, GPIV_EXT_PAR
, fname_parameter
);
199 if (print_par
) printf ("datatype = %d\n", datatype
);
203 if ((fp
= fopen (fname_piv
, "r")) == NULL
) {
204 gpiv_error ("%s: failing opening %s", argv
[0], fname_piv
);
207 if ((piv_data
= gpiv_read_pivdata(fp
)) != NULL
) {
208 gpiv_error ("%s: %s", argv
[0], err_msg
);
212 * copying PIV data to SCALAR data
214 if ((sc_data
= gpiv_alloc_scdata (piv_data
->nx
, piv_data
->ny
)) == NULL
) {
215 gpiv_error ("%s: failing gpiv_alloc_scdata", argv
[0]);
218 for (i
= 0; i
< sc_data
->ny
; i
++) {
219 for (j
= 0; j
< sc_data
->nx
; j
++) {
220 sc_data
->point_x
[i
][j
] = piv_data
->point_x
[i
][j
];
221 sc_data
->point_y
[i
][j
] = piv_data
->point_y
[i
][j
];
222 if (piv_data
->peak_no
[i
][j
] != -1) {
223 if (datatype
== DT_DX
) sc_data
->scalar
[i
][j
] = piv_data
->dx
[i
][j
];
224 if (datatype
== DT_DY
) sc_data
->scalar
[i
][j
] = piv_data
->dy
[i
][j
];
225 if (datatype
== DT_SNR
) sc_data
->scalar
[i
][j
] = piv_data
->snr
[i
][j
];
227 sc_data
->scalar
[i
][j
] = -1.0;
229 sc_data
->flag
[i
][j
] = piv_data
->peak_no
[i
][j
];
238 if ((fp
= fopen (fname_out
, "w")) == NULL
) {
239 gpiv_error ("%s: failing opening %s", argv
[0], fname_out
);
242 if ((err_msg
= gpiv_write_sc_mtvgriddata (fp
, sc_data
, TRUE
))
243 != NULL
) gpiv_error ("%s: %s", argv
[0], err_msg
);
247 gpiv_free_pivdata (piv_data
);