updated copyright statement
[gpivtools.git] / src / misc / piv2gnuplt.c
blob0661e01112488147258f4625f0cbdaa061ed0423
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)
13 any later version.
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 ------------------------------------------------------------------------*/
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <gpiv.h>
30 /* #define PARFILE "scale.par" */ /* Parameter file name */
31 #define PARFILE "gpivrc" /* Parameter file name */
32 #define USAGE "\
33 Usage: piv2gnuplt [-al L] [-au UNIT] [-h | --help] [-p | --print] [-s SCALE] \n\
34 [-v] filename \n\
35 \n\
36 keys: \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\
47 #define HELP "\
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";
60 TODO:
61 Annotation; length, unit
62 Full Zoom
65 void
66 command_args(int argc,
67 char *argv[],
68 char fname[GPIV_MAX_CHARS]
70 /*-----------------------------------------------------------------------------
71 * Command line argument handling
74 char c = '\0';
75 int argc_next = 0;
78 while (--argc > 0 && (*++argv)[0] == '-') {
79 argc_next = 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]))
87 switch (c) {
88 case 'a':
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; */
94 argc_next = 1;
95 --argc;
96 } else {
97 gpiv_error("%s: %s", argv[0], USAGE);
99 annot__set = TRUE;
100 break;
101 case 'v':
102 printf("%s\n", RCSID);
103 exit(0);
104 break;
105 case 'h':
106 printf("%s\n", argv[0]);
107 printf("%s\n",HELP);
108 printf("%s\n",USAGE);
109 exit(0);
110 break;
111 case 'p':
112 print_par = TRUE;
113 break;
114 case 's':
115 scale = atof(*++argv);
116 scale__set = TRUE;
117 --argc;
118 argc_next = 1;
119 break;
120 case 'z':
121 zoom = TRUE;
122 break;
125 * long option keys
127 case '-':
128 if (strcmp("-help", *argv) == 0) {
129 printf("\n%s", argv[0]);
130 printf("\n%s", HELP);
131 printf("\n%s", USAGE);
132 exit(0);
133 } else if (strcmp("-print", *argv) == 0) {
134 print_par = TRUE;
135 } else if (strcmp("-version", *argv) == 0) {
136 printf("%s\n", RCSID);
137 exit(0);
138 } else {
139 gpiv_error("%s: unknown option: %s", argv[0], *argv);
141 argc_next = 1;
142 break;
144 default:
145 fprintf (stderr,USAGE);
146 exit(1);
147 break;
151 if(argc != 1) {
152 gpiv_error("%s: %s", argv[0], USAGE);
154 strcpy(fname, argv[0]);
160 static gchar *
161 make_fname (char *fname_in,
162 char *fname_header
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\"";
173 return (err_msg);
177 * Stripping filename
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);
188 g_free (fname_base);
189 return (err_msg);
194 int
195 main(int argc,
196 char *argv[]
198 /*-----------------------------------------------------------------------------
199 * main program to convert PIV data gnuplot data
202 FILE *fp;
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
216 * General
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);
231 if ((err_msg =
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);
240 if ((err_msg =
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); */
247 if ((err_msg =
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
252 * first be read
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]);
261 fclose (fp);
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);
273 exit (0);