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 ------------------------------------------------------------------------*/
33 /* #define PARFILE "scale.par" */ /* Parameter file name */
34 #define PARFILE "gpivrc" /* Parameter file name */
36 Usage: piv2hdf [-e] [-h | --help] [-i] [-p | --print] [-v | --version] \n\
37 [-V | --verbose] filename \n\
41 -h | --help: this on-line help \n\
42 -i: includes image data \n\
43 -p | --print: print parameters to stdout \n\
44 -v | --version: version number \n\
45 -V | --verbose: program behaves more verbose \n\
46 filename: input PIV datafile, including .piv extension \n\
50 piv2hdf - converts ASCII PIV-data and derived scalars to hdf5 formatted data"
52 gboolean print_par
= FALSE
, verbose
= FALSE
, exclude_data
= FALSE
,
53 include_image
= FALSE
;
56 command_args(gint argc
,
58 gchar fname
[GPIV_MAX_CHARS
]
60 /*-----------------------------------------------------------------------------
61 * Command line argument handling
68 while (--argc
> 0 && (*++argv
)[0] == '-') {
71 * argc_next is set to 1 if the next cmd line argument has to be searched for;
72 * in case that the command line argument concerns more than one char or cmd
73 * line argument needs a parameter
76 while (argc_next
== 0 && (c
= *++argv
[0]))
81 printf ("git hash: %s\n", GIT_REV
);
83 printf ("version: %s\n", GPIVTOOLS_VERSION
);
94 printf("%s\n", argv
[0]);
100 include_image
= TRUE
;
110 if (strcmp("-help", *argv
) == 0) {
111 printf("\n%s", argv
[0]);
112 printf("\n%s", HELP
);
113 printf("\n%s", USAGE
);
115 } else if (strcmp("-print", *argv
) == 0) {
117 } else if (strcmp("-version", *argv
) == 0) {
119 printf ("git hash: %s\n", GIT_REV
);
121 printf ("version: %s\n", GPIVTOOLS_VERSION
);
124 } else if (strcmp("-verbose", *argv
) == 0) {
127 gpiv_error("%s: unknown option: %s", argv
[0], *argv
);
139 gpiv_error("%s: %s", argv
[0], USAGE
);
141 strcpy(fname
, argv
[0]);
148 make_fname(gchar
*fname_in
,
151 gchar
*fname_nstrain
,
152 gchar
*fname_sstrain
,
154 gchar
*fname_parameter
156 /*-----------------------------------------------------------------------------
157 * generates filenames
160 gchar
*err_msg
= NULL
;
161 gchar
*fname_base
= NULL
;
163 if (fname_in
== NULL
) {
164 err_msg
= "make_fname: \"fname_in == NULL\"";
171 fname_base
= g_strdup(fname_in
);
172 strtok(fname_base
, ".");
175 * filenames for output PIV data
178 gpiv_io_make_fname(fname_base
, GPIV_EXT_PNG_IMAGE
, fname_img
);
179 if (verbose
) printf("# Image data file: %s\n", fname_img
);
182 if (exclude_data
== FALSE
) {
184 gpiv_io_make_fname(fname_base
, GPIV_EXT_VOR
, fname_vor
);
185 if (verbose
) printf("# Input data file: %s\n", fname_vor
);
187 gpiv_io_make_fname(fname_base
, GPIV_EXT_NSTR
, fname_nstrain
);
188 if (verbose
) printf("# Input data file: %s\n", fname_nstrain
);
190 gpiv_io_make_fname(fname_base
, GPIV_EXT_SSTR
, fname_sstrain
);
191 if (verbose
) printf("# Input data file: %s\n", fname_sstrain
);
195 gpiv_io_make_fname(fname_base
, GPIV_EXT_GPIV
, fname_out
);
196 if (verbose
) printf("# Output file: %s\n",fname_out
);
198 gpiv_io_make_fname(fname_base
, GPIV_EXT_PAR
, fname_parameter
);
214 /*-----------------------------------------------------------------------------
215 * main routine to converts ASCII PIV-data to hdf5 formatted data
218 gchar
*err_msg
= NULL
;
220 gchar fname_piv
[GPIV_MAX_CHARS
],
221 fname_out
[GPIV_MAX_CHARS
],
222 fname_vor
[GPIV_MAX_CHARS
],
223 fname_nstrain
[GPIV_MAX_CHARS
],
224 fname_sstrain
[GPIV_MAX_CHARS
],
225 fname_img
[GPIV_MAX_CHARS
],
226 fname_parameter
[GPIV_MAX_CHARS
];
229 /* gchar c_line[GPIV_MAX_LINES_C][GPIV_MAX_CHARS]; */
230 /* gint nc_lines=0, var_scale=0; */
232 GpivPivPar
*piv_par
= g_new0 (GpivPivPar
, 1);
233 GpivValidPar
*valid_par
= g_new0 (GpivValidPar
, 1);
234 GpivPostPar
*post_par
= g_new0 (GpivPostPar
, 1);
236 GpivImage
*image
= NULL
;
237 GpivPivData
*piv_data
= NULL
;
238 GpivScalarData
*sc_data
= NULL
;
240 gboolean stored__post_par
= FALSE
;
243 * Initializing parameters
245 gpiv_piv_parameters_set(piv_par
, FALSE
);
246 gpiv_valid_parameters_set(valid_par
, FALSE
);
247 gpiv_post_parameters_set(post_par
, FALSE
);
250 command_args(argc
, argv
, fname_piv
);
252 make_fname(fname_piv
, fname_img
, fname_vor
, fname_nstrain
,
253 fname_sstrain
, fname_out
, fname_parameter
))
255 gpiv_error ("%s: %s\n", argv
[0], err_msg
);
259 * Reads piv program parameters from fname_parameter
261 gpiv_scan_parameter (GPIV_PIVPAR_KEY
, fname_parameter
, piv_par
,
263 gpiv_scan_parameter (GPIV_VALIDPAR_KEY
, fname_parameter
, valid_par
,
265 gpiv_scan_parameter (GPIV_POSTPAR_KEY
, fname_parameter
, post_par
,
271 gpiv_scan_resourcefiles (GPIV_PIVPAR_KEY
, piv_par
, print_par
))
272 != NULL
) gpiv_error ("%s: %s", argv
[0], err_msg
);
274 gpiv_scan_resourcefiles (GPIV_VALIDPAR_KEY
, valid_par
, print_par
))
275 != NULL
) gpiv_error ("%s: %s", argv
[0], err_msg
);
277 gpiv_scan_resourcefiles (GPIV_POSTPAR_KEY
, post_par
, print_par
))
278 != NULL
) gpiv_error ("%s: %s", argv
[0], err_msg
);
279 #endif /* USE_RESOURCES */
282 * writing to output int hdf5
284 if ((err_msg
= gpiv_fcreate_hdf5 (fname_out
)) != NULL
) {
285 gpiv_error ("%s: %s", argv
[0], err_msg
);
293 if ((fp
= fopen(fname_img
, "r")) != NULL
) {
294 if ((image
= gpiv_read_png_image (fp
)) == NULL
) {
296 gpiv_error ("%s: faling gpiv_read_png_image", argv
[0]);
301 if ((err_msg
= gpiv_fwrite_hdf5_image (fname_out
, image
, TRUE
))
303 gpiv_error ("%s: %s", argv
[0], err_msg
);
309 if (exclude_data
== FALSE
) {
311 * Piv data, PIV and validation parameters
313 if ((fp
= fopen (fname_piv
, "r")) != NULL
) {
314 if ((piv_data
= gpiv_read_pivdata (fp
)) == NULL
) {
316 gpiv_error ("%s: faling gpiv_read_pivdata", argv
[0]);
321 if ((err_msg
= gpiv_fwrite_hdf5_pivdata (fname_out
, piv_data
, "PIV",
323 != NULL
) gpiv_error ("%s: %s", argv
[0], err_msg
);
327 if (piv_par
!= NULL
) {
329 gpiv_piv_fwrite_hdf5_parameters (fname_out
, piv_par
))
330 != NULL
) gpiv_error ("%s: %s", argv
[0], err_msg
);
333 if (valid_par
!= NULL
) {
335 gpiv_valid_fwrite_hdf5_parameters (fname_out
, valid_par
))
336 != NULL
) gpiv_error ("%s: %s", argv
[0], err_msg
);
342 * Scalar data: vorticity
344 if ((fp
= fopen (fname_vor
, "r")) != NULL
) {
345 if ((sc_data
= gpiv_read_scdata (fp
)) == NULL
) {
347 gpiv_error ("%s: faling gpiv_read_scdata", argv
[0]);
352 if ((err_msg
= gpiv_fwrite_hdf5_scdata (fname_out
, sc_data
,
354 != NULL
) gpiv_error ("%s: %s", argv
[0], err_msg
);
357 if (post_par
!= NULL
&& stored__post_par
== FALSE
) {
358 stored__post_par
= TRUE
;
360 gpiv_post_fwrite_hdf5_parameters (fname_out
, post_par
))
361 != NULL
) gpiv_error ("%s: %s", argv
[0], err_msg
);
366 * Scalar data: sstrain
368 if ((fp
= fopen (fname_sstrain
, "r")) != NULL
) {
370 if ((sc_data
= gpiv_read_scdata (fp
)) == NULL
) {
372 gpiv_error ("%s: faling gpiv_read_scdata", argv
[0]);
378 gpiv_fwrite_hdf5_scdata(fname_out
, sc_data
,
379 "SHEAR_STRAIN", TRUE
))
380 != NULL
) gpiv_error ("%s: %s", argv
[0], err_msg
);
382 if (post_par
!= NULL
&& stored__post_par
== FALSE
) {
383 stored__post_par
= TRUE
;
385 gpiv_post_fwrite_hdf5_parameters (fname_out
, post_par
))
386 != NULL
) gpiv_error ("%s: %s", argv
[0], err_msg
);
391 * Scalar data: normal strain
393 if((fp
=fopen(fname_nstrain
, "r")) != NULL
) {
394 if ((sc_data
= gpiv_read_scdata (fp
)) == NULL
) {
396 gpiv_error ("%s: faling gpiv_read_scdata", argv
[0]);
403 gpiv_fwrite_hdf5_scdata(fname_out
, sc_data
,
404 "NORMAL_STRAIN", TRUE
))
405 != NULL
) gpiv_error ("%s: %s", argv
[0], err_msg
);
407 if (post_par
!= NULL
&& stored__post_par
== FALSE
) {
408 stored__post_par
= TRUE
;
410 gpiv_post_fwrite_hdf5_parameters (fname_out
, post_par
))
411 != NULL
) gpiv_error ("%s: %s", argv
[0], err_msg
);