1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 c-style: "K&R" -*- */
3 /*-----------------------------------------------------------------------------
5 hdf2piv - converts hdf5 PIV data ASCII 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: hdf2piv [-e] [-h | --help] [-p | --print] [-v | --version] \n\
37 [-V | --verbose] filename \n\
41 -h | --help: this on-line help \n\
42 -p | --print: print parameters to stdout \n\
43 -v | --version: version number \n\
44 -V | --verbose: version number \n\
45 filename: input file, hdf formatted (including .hdf extension) \n\
49 hdf2piv - converts hdf5 PIV-data to ASCII data"
51 gboolean print_par
= FALSE
, verbose
= FALSE
, exclude_data
= FALSE
;
55 command_args(gint argc
,
57 gchar fname
[GPIV_MAX_CHARS
]
59 /* ----------------------------------------------------------------------------
60 * Command line argument handling
66 while (--argc
> 0 && (*++argv
)[0] == '-') {
69 * argc_next is set to 1 if the next cmd line argument has to be searched for;
70 * in case that the command line argument concerns more than one char or cmd
71 * line argument needs a parameter
75 while (argc_next
== 0 && (c
= *++argv
[0]))
80 printf ("git hash: %s\n", GIT_REV
);
82 printf ("version: %s\n", GPIVTOOLS_VERSION
);
93 printf("%s\n", argv
[0]);
106 if (strcmp("-help", *argv
) == 0) {
107 printf("\n%s", argv
[0]);
108 printf("\n%s", HELP
);
109 printf("\n%s", USAGE
);
111 } else if (strcmp("-print", *argv
) == 0) {
113 } else if (strcmp("-version", *argv
) == 0) {
115 printf ("git hash: %s\n", GIT_REV
);
117 printf ("version: %s\n", GPIVTOOLS_VERSION
);
120 } else if (strcmp("-verbose", *argv
) == 0) {
123 gpiv_error("%s: unknown option: %s", argv
[0], *argv
);
135 strcpy (fname
, argv
[argc
- 1]);
137 gpiv_error ("%s: %s", argv
[0], USAGE
);
145 make_fname(gchar
*fname_in
,
146 gchar
*fname_out_img
,
147 gchar
*fname_out_piv
,
148 gchar
*fname_out_vor
,
149 gchar
*fname_out_nstrain
,
150 gchar
*fname_out_sstrain
,
153 /* ----------------------------------------------------------------------------
157 gchar
*err_msg
= NULL
;
158 gchar
*fname_base
= NULL
;
160 if (fname_in
== NULL
) {
161 err_msg
= "make_fname: \"fname_in == NULL\"";
168 fname_base
= g_strdup (fname_in
);
169 strtok (fname_base
, ".");
172 * filenames for output PIV data
174 gpiv_io_make_fname (fname_base
, GPIV_EXT_RAW_IMAGE
, fname_out_img
);
175 if (verbose
) printf("# Output data file: %s\n", fname_out_img
);
177 if (exclude_data
== FALSE
) {
178 gpiv_io_make_fname(fname_base
, GPIV_EXT_PIV
, fname_out_piv
);
179 if (verbose
) printf("# Output data file: %s\n",fname_out_piv
);
181 gpiv_io_make_fname(fname_base
, GPIV_EXT_VOR
, fname_out_vor
);
182 if (verbose
) printf("# Input data file: %s\n",fname_out_vor
);
184 gpiv_io_make_fname(fname_base
, GPIV_EXT_NSTR
, fname_out_nstrain
);
185 if (verbose
) printf("# Input data file: %s\n",
188 gpiv_io_make_fname(fname_base
, GPIV_EXT_SSTR
, fname_out_sstrain
);
189 if (verbose
) printf("# Input data file: %s\n",
192 gpiv_io_make_fname(fname_base
, GPIV_EXT_PAR
, fname_out_par
);
193 if (verbose
) printf("# Input parameter file: %s\n",
206 /* ----------------------------------------------------------------------------
210 gchar
*err_msg
= NULL
;
211 gchar fname_in
[GPIV_MAX_CHARS
],
212 fname_out_img
[GPIV_MAX_CHARS
],
213 fname_out_piv
[GPIV_MAX_CHARS
],
214 fname_out_vor
[GPIV_MAX_CHARS
],
215 fname_out_nstrain
[GPIV_MAX_CHARS
],
216 fname_out_sstrain
[GPIV_MAX_CHARS
],
217 fname_out_par
[GPIV_MAX_CHARS
];
219 GpivImage
*image
= NULL
;
220 GpivPivData
*piv_data
= NULL
;
221 GpivScalarData
*sc_data
;
223 GpivPivPar
*piv_par
= NULL
;
224 GpivValidPar
*valid_par
= NULL
;
225 GpivPostPar
*post_par
= NULL
;
228 * Initializing parameters
230 command_args (argc
, argv
, fname_in
);
232 make_fname (fname_in
, fname_out_img
, fname_out_piv
, fname_out_vor
,
233 fname_out_nstrain
, fname_out_sstrain
,
236 gpiv_error ("%s: %s\n", argv
[0], err_msg
);
240 * reading input from hdf5
244 if ((image
= gpiv_fread_hdf5_image (fname_in
)) == NULL
) {
245 gpiv_error ("%s: %s", argv
[0], err_msg
);
248 if ((fp_out
= fopen (fname_out_img
, "wb")) == NULL
) {
249 gpiv_error("%s error: failure opening %s for output",
250 argv
[0], fname_out_img
);
252 gpiv_write_png_image (fp_out
, image
, TRUE
);
258 if (exclude_data
== FALSE
) {
259 if ((piv_data
= gpiv_fread_hdf5_pivdata (fname_in
, "PIV" )) == NULL
) {
260 gpiv_error ("%s: failing gpiv_fread_hdf5_pivdata", argv
[0]);
263 if ((fp_out
= fopen (fname_out_piv
, "w")) == NULL
) {
264 gpiv_error("%s error: failure opening %s for output",
265 argv
[0], fname_out_piv
);
268 if ((err_msg
= gpiv_write_pivdata (fp_out
, piv_data
, TRUE
))
270 gpiv_error ("%s: %s", argv
[0], err_msg
);
275 * scalar data: vorticity
277 if ((sc_data
= gpiv_fread_hdf5_scdata (fname_in
, "VORTICITY" ))
279 gpiv_error ("%s: failing gpiv_fread_hdf5_scdata", argv
[0]);
282 if ((fp_out
= fopen (fname_out_vor
, "w")) == NULL
) {
283 gpiv_error("%s error: failure opening %s for output",
284 argv
[0], fname_out_vor
);
287 if ((err_msg
= gpiv_write_scdata (fp_out
, sc_data
, TRUE
))
289 gpiv_error ("%s: %s", argv
[0], err_msg
);
294 * scalar data: normal strain
296 if ((sc_data
= gpiv_fread_hdf5_scdata (fname_in
, "NORMAL STRAIN" ))
298 gpiv_error ("%s: failing gpiv_fread_hdf5_scdata", argv
[0]);
301 if ((fp_out
= fopen (fname_out_nstrain
, "w")) == NULL
) {
302 gpiv_error("%s error: failure opening %s for output",
303 argv
[0], fname_out_vor
);
306 if ((err_msg
= gpiv_write_scdata (fp_out
, sc_data
, TRUE
))
308 gpiv_error ("%s: %s", argv
[0], err_msg
);
313 * scalar data: shear strain
315 if ((sc_data
= gpiv_fread_hdf5_scdata (fname_in
, "SHEAR STRAIN" ))
317 gpiv_error ("%s: failing gpiv_fread_hdf5_scdata", argv
[0]);
320 if ((fp_out
= fopen (fname_out_sstrain
, "w")) == NULL
) {
321 gpiv_error("%s error: failure opening %s for output",
322 argv
[0], fname_out_vor
);
325 if ((err_msg
= gpiv_write_scdata (fp_out
, sc_data
, TRUE
))
327 gpiv_error ("%s: %s", argv
[0], err_msg
);
335 gpiv_piv_fread_hdf5_parameters (fname_in
))
337 gpiv_error ("%s: failing gpiv_piv_fread_hdf5_parameters", argv
[0]);
341 gpiv_valid_fread_hdf5_parameters (fname_in
))
343 gpiv_error ("%s: failing gpiv_valid_fread_hdf5_parameters", argv
[0]);
347 gpiv_post_fread_hdf5_parameters(fname_in
))
349 gpiv_error ("%s: failing gpiv_post_fread_hdf5_parameters", argv
[0]);
353 if ((fp_out
= fopen (fname_out_par
, "w")) == NULL
) {
354 gpiv_error("%s error: failure opening %s for output",
355 argv
[0], fname_out_par
);
357 gpiv_img_print_parameters (fp_out
, image
->header
);
358 gpiv_piv_print_parameters (fp_out
, piv_par
);
359 gpiv_valid_print_parameters (fp_out
, valid_par
);
360 gpiv_post_print_parameters (fp_out
, post_par
);
364 gpiv_img_print_parameters (NULL
, image
->header
);
365 gpiv_piv_print_parameters (NULL
, piv_par
);
366 gpiv_valid_print_parameters (NULL
, valid_par
);
367 gpiv_post_print_parameters (NULL
, post_par
);