1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 c-style: "K&R" -*- */
3 /*---------------------------------------------------------------------------
5 piv2gnuplt - converts PIV data gnuplot 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 ------------------------------------------------------------------------*/
30 /* #define PARFILE "scale.par" */ /* Parameter file name */
31 #define PARFILE "gpivrc" /* Parameter file name */
33 Usage: piv2gnuplt [-al L] [-au UNIT] [-h | --help] [-p | --print] [-s SCALE] \n\
37 -al L: draws an annotation vector with lenght L \n\
38 -au UNIT: define unit of annotation vector (defaul m/s) \n\
39 -h | --help: this on-line help \n\
40 -p | --print: print parameters to stdout \n\
41 -s SCALE: scale factor for graphic output with gnuplot \n\
42 -v | --version: version number \n\
43 -z full zoom (for scaled data) \n\
44 filename: inpit PIV data file. \n\
48 piv2gnuplt - converts PIV data gnuplot data"
50 #define RCSID "$Id: piv2gnuplt.c,v 1.12 2008-09-25 13:08:34 gerber Exp $"
51 #define GNUPLOT_DISPLAY_SIZE 500
52 #define GNUPLOT_DISPLAY_COLOR "LightBlue"
54 gboolean print_par
= FALSE
, zoom
= FALSE
;
55 gboolean scale__set
= FALSE
, annot__set
= FALSE
;
56 float scale
= 1.0, annot_length
= 1.0;
57 char annot_unit
[GPIV_MAX_CHARS
] = "m/s";
61 Annotation; length, unit
66 command_args(int argc
,
68 char fname
[GPIV_MAX_CHARS
]
70 /*-----------------------------------------------------------------------------
71 * Command line argument handling
78 while (--argc
> 0 && (*++argv
)[0] == '-') {
81 * argc_next is set to 1 if the next cmd line argument has to be searched for;
82 * in case that the command line argument concerns more than one char or cmd
83 * line argument needs a parameter
86 while (argc_next
== 0 && (c
= *++argv
[0]))
89 if (strcmp(*argv
, "al") != 0) {
90 annot_length
= atof(*++argv
);
91 } else if (strcmp(*argv
, "au") != 0) {
92 strcpy(annot_unit
, *++argv
);
93 /* annot__set = TRUE; */
97 gpiv_error("%s: %s", argv
[0], USAGE
);
102 printf("%s\n", RCSID
);
106 printf("%s\n", argv
[0]);
108 printf("%s\n",USAGE
);
115 scale
= atof(*++argv
);
128 if (strcmp("-help", *argv
) == 0) {
129 printf("\n%s", argv
[0]);
130 printf("\n%s", HELP
);
131 printf("\n%s", USAGE
);
133 } else if (strcmp("-print", *argv
) == 0) {
135 } else if (strcmp("-version", *argv
) == 0) {
136 printf("%s\n", RCSID
);
139 gpiv_error("%s: unknown option: %s", argv
[0], *argv
);
145 fprintf (stderr
,USAGE
);
152 gpiv_error("%s: %s", argv
[0], USAGE
);
154 strcpy(fname
, argv
[0]);
161 make_fname (char *fname_in
,
164 /*-----------------------------------------------------------------------------
165 * function to generate filenames
168 gchar
*err_msg
= NULL
;
169 gchar
*fname_base
= NULL
;
171 if (fname_in
== NULL
) {
172 err_msg
= "make_fname: \"fname_in == NULL\"";
179 fname_base
= g_strdup(fname_in
);
180 strtok(fname_base
, ".");
183 * filenames for output
185 gpiv_io_make_fname(fname_base
, GPIV_EXT_HEADER
, fname_header
);
186 if (print_par
) printf("# Header data file: %s\n", fname_header
);
198 /*-----------------------------------------------------------------------------
199 * main program to convert PIV data gnuplot data
203 gchar
*err_msg
= NULL
;
204 gchar fname_in
[GPIV_MAX_CHARS
],
205 fname_header
[GPIV_MAX_CHARS
];
207 /* gchar c_line[GPIV_MAX_LINES_C][GPIV_MAX_CHARS]; */
208 /* gint nc_lines = 0, var_scale = 0; */
209 GpivPivData
*piv_data
= NULL
;
210 GpivImagePar
*image_par
= g_new0 (GpivImagePar
, 1);;
211 GpivPivPar
*piv_par
= g_new0 (GpivPivPar
, 1);
215 *Initializing parameters
218 gpiv_img_parameters_set (image_par
, FALSE
);
219 gpiv_piv_parameters_set (piv_par
, FALSE
);
222 command_args (argc
, argv
, fname_in
);
223 make_fname (fname_in
, fname_header
);
226 * Reads image header data from file.h and/or resource files
227 * if not overridden by the commandline options
229 gpiv_scan_parameter ("", fname_header
, image_par
, print_par
);
230 gpiv_scan_parameter ("", PARFILE
, image_par
, print_par
);
232 gpiv_scan_resourcefiles(GPIV_IMGPAR_KEY
, image_par
, print_par
))
233 != NULL
) gpiv_error ("%s: %s", argv
[0], err_msg
);
236 * Reads piv parameters from PARFILE and/or resource files
237 * if not overridden by the commandline options
239 gpiv_scan_parameter (GPIV_PIVPAR_KEY
, PARFILE
, piv_par
, print_par
);
241 gpiv_scan_resourcefiles (GPIV_PIVPAR_KEY
, piv_par
, print_par
))
242 != NULL
) gpiv_error ("%s: %s", argv
[0], err_msg
);
244 * Check if all parameters have been read
246 /* gpiv_img_check_header_read(GPIV_IMAGE_PAR_KEY); */
248 gpiv_piv_check_parameters_read (piv_par
, NULL
))
249 != NULL
) gpiv_error ("%s: %s", argv
[0], err_msg
);
251 * As piv_data.nx and piv_data.ny are not known, the input data file will
254 if ((fp
= fopen (fname_in
, "r")) == NULL
) {
255 gpiv_error ("%s: failing opening %s", argv
[0], fname_in
);
258 if ((piv_data
= gpiv_read_pivdata (fp
)) == NULL
) {
259 gpiv_error ("%s: failing gpiv_fread_pivdata", argv
[0]);
263 * plotting with gnuplot
265 gpiv_piv_gnuplot (strtok (g_strdup (fname_in
), "."), scale
,
266 GNUPLOT_DISPLAY_COLOR
, GNUPLOT_DISPLAY_SIZE
,
267 image_par
, piv_par
, piv_data
);
270 * Freeing allocated memory of matrices
272 gpiv_free_pivdata (piv_data
);