bugrepair: drag and drop
[gpiv.git] / src / utils_par.c
blob072e7faf2ba9cc0f590b5e7a8368bc6da54f3644
1 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 c-style: "K&R" -*- */
3 /*----------------------------------------------------------------------
5 gpiv - Graphic program for Particle Image Velocimetry, based on gtk/gnome
6 libraries.
8 Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008
9 Gerber van der Graaf
11 This file is part of gpiv.
13 Gpiv is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2, or (at your option)
16 any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ----------------------------------------------------------------------*/
30 * utility functions for gpiv
31 * $Log: utils_par.c,v $
32 * Revision 1.2 2008-10-09 14:43:37 gerber
33 * paralellized with OMP and MPI
35 * Revision 1.1 2008-09-16 11:24:37 gerber
36 * added utils_par
41 #include "gpiv_gui.h"
42 #include "utils_par.h"
46 * Prottyping
48 static void
49 set_par_bool_ifdiff (gboolean *val_src,
50 gboolean *val_dest,
51 gboolean *set_dest);
53 static void
54 set_par_int_ifdiff (gint *val_src,
55 gint *val_dest,
56 gboolean *set_dest);
58 static void
59 print_par_bool (gchar *parname,
60 gboolean val,
61 gboolean set);
63 static void
64 print_par_int (gchar *parname,
65 gint val,
66 gboolean set);
68 static void
69 par_ovwrt_parameters (Par *par_src,
70 Par *par_dest,
71 gboolean force);
75 * Program-wide public functions
77 void
78 parameters_set (Par *par,
79 gboolean bool
81 /*-----------------------------------------------------------------------------
82 * Defines each parameter member of par_dest->*__set to bool
86 par->img_fmt__set = bool;
87 par->hdf__set = bool;
88 par->print_par__set = bool;
89 par->verbose__set = bool;
90 par->x_corr__set = bool;
91 par->console__show_tooltips__set = bool;
92 par->console__view_tabulator__set = bool;
93 par->console__view_gpivbuttons__set = bool;
94 par->console__nbins__set = bool;
96 #ifdef ENABLE_CAM
97 par->process__cam = bool;
98 #endif /* ENABLE_CAM */
100 #ifdef ENABLE_TRIG
101 par->process__trig = bool;
102 #endif /* ENABLE_DAC */
104 #ifdef ENABLE_IMGPROC
105 par->process__imgproc = bool;
106 #endif /* ENABLE_IMGPROC */
108 par->process__piv = bool;
109 par->process__gradient = bool;
110 par->process__resstats = bool;
111 par->process__errvec = bool;
112 par->process__peaklock = bool;
113 par->process__scale = bool;
114 par->process__average = bool;
115 par->process__subtract = bool;
116 par->process__vorstra = bool;
117 par->display__view_menubar = bool;
118 par->display__view_rulers = bool;
119 par->display__stretch_auto = bool;
120 par->display__vector_scale = bool;
121 par->display__vector_color = bool;
122 par->display__zoom_index = bool;
123 par->display__backgrnd__set = bool;
124 par->display__intregs = bool;
125 par->display__piv = bool;
126 par->display__scalar__set = bool;
128 #ifdef ENABLE_MPI
129 par->mpi_nodes__set = bool;
130 #endif /* ENABLE_MPI */
136 void
137 set_parameters_ifdiff (Par *par_src,
138 Par *par_dest
140 /*-----------------------------------------------------------------------------
141 * Defines each parameter member of par_dest->*__set to TRUE if par_src differs
145 set_par_int_ifdiff ((int *) &par_src->img_fmt,
146 (int *) &par_dest->img_fmt,
147 &par_dest->img_fmt__set);
149 set_par_bool_ifdiff (&par_src->hdf,
150 &par_dest->hdf,
151 &par_dest->hdf__set);
153 set_par_bool_ifdiff (&par_src->print_par,
154 &par_dest->print_par,
155 &par_dest->print_par__set);
157 set_par_bool_ifdiff (&par_src->verbose,
158 &par_dest->verbose,
159 &par_dest->verbose__set);
161 set_par_bool_ifdiff (&par_src->x_corr,
162 &par_dest->x_corr,
163 &par_dest->x_corr__set);
165 set_par_bool_ifdiff (&par_src->console__show_tooltips,
166 &par_dest->console__show_tooltips,
167 &par_dest->console__show_tooltips__set);
169 set_par_bool_ifdiff (&par_src->console__view_tabulator,
170 &par_dest->console__view_tabulator,
171 &par_dest->console__view_tabulator__set);
173 set_par_bool_ifdiff (&par_src->console__view_gpivbuttons,
174 &par_dest->console__view_gpivbuttons,
175 &par_dest->console__view_gpivbuttons__set);
177 set_par_int_ifdiff (&par_src->console__nbins,
178 &par_dest->console__nbins,
179 &par_dest->console__nbins__set);
181 #ifdef ENABLE_CAM
182 set_par_bool_ifdiff (&par_src->process__cam,
183 &par_dest->process__cam,
184 &par_dest->process__cam__set);
185 #endif /* ENABLE_CAM */
187 #ifdef ENABLE_TRIG
188 set_par_bool_ifdiff (&par_src->process__trig,
189 &par_dest->process__trig,
190 &par_dest->process__trig__set);
191 #endif /* ENABLE_DAC */
193 #ifdef ENABLE_IMGPROC
194 set_par_bool_ifdiff (&par_src->process__imgproc,
195 &par_dest->process__imgproc,
196 &par_dest->process__imgproc__set);
197 #endif /* ENABLE_IMGPROC */
199 set_par_bool_ifdiff (&par_src->process__piv,
200 &par_dest->process__piv,
201 &par_dest->process__piv__set);
203 set_par_bool_ifdiff (&par_src->process__gradient,
204 &par_dest->process__gradient,
205 &par_dest->process__gradient__set);
207 set_par_bool_ifdiff (&par_src->process__resstats,
208 &par_dest->process__resstats,
209 &par_dest->process__resstats__set);
211 set_par_bool_ifdiff (&par_src->process__errvec,
212 &par_dest->process__errvec,
213 &par_dest->process__errvec__set);
215 set_par_bool_ifdiff (&par_src->process__peaklock,
216 &par_dest->process__peaklock,
217 &par_dest->process__peaklock__set);
220 set_par_bool_ifdiff (&par_src->process__scale,
221 &par_dest->process__scale,
222 &par_dest->process__scale__set);
225 set_par_bool_ifdiff (&par_src->process__average,
226 &par_dest->process__average,
227 &par_dest->process__average__set);
230 set_par_bool_ifdiff (&par_src->process__subtract,
231 &par_dest->process__subtract,
232 &par_dest->process__subtract__set);
235 set_par_bool_ifdiff (&par_src->process__vorstra,
236 &par_dest->process__vorstra,
237 &par_dest->process__vorstra__set);
240 set_par_bool_ifdiff (&par_src->display__view_menubar,
241 &par_dest->display__view_menubar,
242 &par_dest->display__view_menubar__set);
245 set_par_bool_ifdiff (&par_src->display__view_rulers,
246 &par_dest->display__view_rulers,
247 &par_dest->display__view_rulers__set);
250 set_par_bool_ifdiff (&par_src->display__stretch_auto,
251 &par_dest->display__stretch_auto,
252 &par_dest->display__stretch_auto__set);
255 set_par_int_ifdiff ((int *) &par_src->display__vector_scale,
256 (int *) &par_dest->display__vector_scale,
257 &par_dest->display__vector_scale__set);
260 set_par_int_ifdiff ((int *) &par_src->display__vector_color,
261 (int *) &par_dest->display__vector_color,
262 &par_dest->display__vector_color__set);
265 set_par_int_ifdiff ((int *) &par_src->display__zoom_index,
266 (int *) &par_dest->display__zoom_index,
267 &par_dest->display__zoom_index__set);
270 set_par_int_ifdiff ((int *) &par_src->display__backgrnd,
271 (int *) &par_dest->display__backgrnd,
272 &par_dest->display__backgrnd__set);
275 set_par_bool_ifdiff (&par_src->display__intregs,
276 &par_dest->display__intregs,
277 &par_dest->display__intregs__set);
280 set_par_bool_ifdiff (&par_src->display__piv,
281 &par_dest->display__piv,
282 &par_dest->display__piv__set);
285 set_par_int_ifdiff ((int *) &par_src->display__scalar,
286 (int *) &par_dest->display__scalar,
287 &par_dest->display__scalar__set);
289 #ifdef ENABLE_MPI
290 set_par_int_ifdiff (&par_src->mpi_nodes,
291 &par_dest->mpi_nodes,
292 &par_dest->mpi_nodes__set);
293 #endif /* ENABLE_MPI */
299 void
300 print_parameters (Par *par
302 /*-----------------------------------------------------------------------------
306 print_par_int ("img_fmt", par->img_fmt,
307 par->img_fmt__set);
309 print_par_bool ("hdf", par->hdf,
310 par->hdf__set);
312 print_par_bool ("print_par", par->print_par,
313 par->print_par__set);
315 print_par_bool ("verbose", par->verbose,
316 par->verbose__set);
318 print_par_bool ("x_corr", par->x_corr,
319 par->x_corr__set);
321 print_par_bool ("console__show_tooltips", par->console__show_tooltips,
322 par->console__show_tooltips__set);
324 print_par_bool ("console__view_tabulator", par->console__view_tabulator,
325 par->console__view_tabulator__set);
327 print_par_bool ("console__view_gpivbuttons", par->console__view_gpivbuttons,
328 par->console__view_gpivbuttons__set);
330 print_par_int ("console__nbins", par->console__nbins,
331 par->console__nbins__set);
333 #ifdef ENABLE_CAM
334 print_par_bool ("process__cam", par->process__cam,
335 par->process__cam__set);
336 #endif /* ENABLE_CAM */
338 #ifdef ENABLE_TRIG
339 print_par_bool ("process__trig", par->process__trig,
340 par->process__trig__set);
341 #endif /* ENABLE_DAC */
343 #ifdef ENABLE_IMGPROC
344 print_par_bool ("process__imgproc", par->process__imgproc,
345 par->process__imgproc__set);
346 #endif /* ENABLE_IMGPROC */
348 print_par_bool ("process__piv", par->process__piv,
349 par->process__piv__set);
351 print_par_bool ("process__gradient", par->process__gradient,
352 par->process__gradient__set);
354 print_par_bool ("process__resstats", par->process__resstats,
355 par->process__resstats__set);
357 print_par_bool ("process__errvec", par->process__errvec,
358 par->process__errvec__set);
360 print_par_bool ("process__peaklock", par->process__peaklock,
361 par->process__peaklock__set);
364 print_par_bool ("process__scale", par->process__scale,
365 par->process__scale__set);
368 print_par_bool ("process__average", par->process__average,
369 par->process__average__set);
372 print_par_bool ("process__subtract", par->process__subtract,
373 par->process__subtract__set);
376 print_par_bool ("process__vorstra", par->process__vorstra,
377 par->process__vorstra__set);
380 print_par_bool ("display__view_menubar", par->display__view_menubar,
381 par->display__view_menubar__set);
384 print_par_bool ("display__view_rulers", par->display__view_rulers,
385 par->display__view_rulers__set);
388 print_par_bool ("display__stretch_auto", par->display__stretch_auto,
389 par->display__stretch_auto__set);
392 print_par_bool ("display__vector_scale", par->display__vector_scale,
393 par->display__vector_scale__set);
396 print_par_bool ("display__vector_color", par->display__vector_color,
397 par->display__vector_color__set);
400 print_par_bool ("display__zoom_index", par->display__zoom_index,
401 par->display__zoom_index__set);
404 print_par_bool ("display__background", par->display__backgrnd,
405 par->display__backgrnd__set);
408 print_par_bool ("display__intregs", par->display__intregs,
409 par->display__intregs__set);
412 print_par_bool ("display__piv", par->display__piv,
413 par->display__piv__set);
416 print_par_bool ("display__scalar", par->display__scalar,
417 par->display__scalar__set);
419 #ifdef ENABLE_MPI
420 print_par_int ("mpi_nodes", par->mpi_nodes,
421 par->mpi_nodes__set);
423 #endif /* ENABLE_MPI */
428 gchar *
429 cp_undef_parameters (Par *par_src,
430 Par *par_dest
432 /*-----------------------------------------------------------------------------
433 * DESCRIPTION:
434 * Copies only those gpiv parameters from src to dest if dest has not
435 * been defined
437 * INPUTS:
438 * par_src: source gpiv parameters
439 * force: flag to force the copying, even if destination
440 * already exists
441 * print_par: verbose output. Not implemented, yet.
443 * OUTPUTS:
444 * par_dest: destination piv parameters
446 * RETURNS:
448 *---------------------------------------------------------------------------*/
450 gchar *err_msg = NULL;
451 gboolean force = FALSE;
454 par_ovwrt_parameters (par_src, par_dest, force);
457 return err_msg;
462 Par *
463 cp_parameters (Par *par_src
465 /*-----------------------------------------------------------------------------
466 * DESCRIPTION:
467 * Copies all gpiv parameters
469 * INPUTS:
470 * par_src: source gpiv parameters
471 * force: flag to force the copying, even if destination
472 * already exists
473 * print_par: verbose output. Not implemented, yet.
475 * OUTPUTS:
476 * par_dest: destination piv parameters
478 * RETURNS:
480 *---------------------------------------------------------------------------*/
482 Par *par_dest = g_new0 (Par, 1);
483 gboolean force = TRUE;
486 par_ovwrt_parameters (par_src, par_dest, force);
489 return par_dest;
494 * Local functions
497 static void
498 set_par_bool_ifdiff (gboolean *val_src,
499 gboolean *val_dest,
500 gboolean *set_dest)
501 /*-----------------------------------------------------------------------------
504 if (*val_src != *val_dest) {
505 *val_dest = *val_src;
506 *set_dest = TRUE;
507 } else {
508 *set_dest = FALSE;
514 static void
515 set_par_int_ifdiff (gint *val_src,
516 gint *val_dest,
517 gboolean *set_dest)
518 /*-----------------------------------------------------------------------------
521 if (*val_src != *val_dest) {
522 *val_dest = *val_src;
523 *set_dest = TRUE;
524 } else {
525 *set_dest = FALSE;
531 static void
532 print_par_bool (gchar *parname,
533 gboolean val,
534 gboolean set)
535 /*-----------------------------------------------------------------------------
538 if (set) {
539 g_message ("%s__set is TRUE", parname);
540 } else {
541 g_message ("%s__set is FALSE", parname);
544 if (val) {
545 g_message ("%s is set to: TRUE", parname);
546 } else {
547 g_message ("%s is set to: FALSE", parname);
552 static void
553 print_par_int (gchar *parname,
554 gint val,
555 gboolean set)
556 /*-----------------------------------------------------------------------------
559 if (set) {
560 g_message ("%s__set is TRUE", parname);
561 } else {
562 g_message ("%s__set is FALSE", parname);
565 g_message ("%s is set to: %d", parname, val);
569 static void
570 par_ovwrt_parameters (Par *par_src,
571 Par *par_dest,
572 gboolean force
574 /*-----------------------------------------------------------------------------
575 * DESCRIPTION:
576 * Copies gpiv parameters
578 * INPUTS:
579 * par_src: source gpiv parameters
580 * par_dest: destination gpiv parameters
581 * force: flag to force the copying, even if destination
582 * already exists
584 * OUTPUTS:
585 * par_dest: destination piv parameters
587 * RETURNS:
589 *---------------------------------------------------------------------------*/
592 if (force
593 || ( par_src->img_fmt__set
594 && !par_dest->img_fmt__set)) {
595 par_dest->img_fmt = par_src->img_fmt;
596 par_dest->img_fmt__set = TRUE;
599 if (force
600 || ( par_src->hdf__set
601 && !par_dest->hdf__set)) {
602 par_dest->hdf = par_src->hdf;
603 par_dest->hdf__set = TRUE;
606 if (force
607 || ( par_src->print_par__set
608 && !par_dest->print_par__set)) {
609 par_dest->print_par = par_src->print_par;
610 par_dest->print_par__set = TRUE;
613 if (force
614 || ( par_src->verbose__set
615 && !par_dest->verbose__set)) {
616 par_dest->verbose = par_src->verbose;
617 par_dest->verbose__set = TRUE;
620 if (force
621 || ( par_src->x_corr__set
622 && !par_dest->x_corr__set)) {
623 par_dest->x_corr = par_src->x_corr;
624 par_dest->x_corr__set = TRUE;
627 if (force
628 || ( par_src->console__show_tooltips__set
629 && !par_dest->console__show_tooltips__set)) {
630 par_dest->console__show_tooltips = par_src->console__show_tooltips;
631 par_dest->console__show_tooltips__set = TRUE;
634 if (force
635 || ( par_src->console__view_tabulator__set
636 && !par_dest->console__view_tabulator__set)) {
637 par_dest->console__view_tabulator = par_src->console__view_tabulator;
638 par_dest->console__view_tabulator__set = TRUE;
641 if (force
642 || ( par_src->console__view_gpivbuttons__set
643 && !par_dest->console__view_gpivbuttons__set)) {
644 par_dest->console__view_gpivbuttons = par_src->console__view_gpivbuttons;
645 par_dest->console__view_gpivbuttons__set = TRUE;
648 if (force
649 || ( par_src->console__nbins__set
650 && !par_dest->console__nbins__set)) {
651 par_dest->console__nbins = par_src->console__nbins;
652 par_dest->console__nbins__set = TRUE;
655 #ifdef ENABLE_CAM
656 if (force
657 || ( par_src->process__cam__set
658 && !par_dest->process__cam__set)) {
659 par_dest->process__cam = par_src->process__cam;
660 par_dest->process__cam__set = TRUE;
662 #endif /* ENABLE_CAM */
664 #ifdef ENABLE_TRIG
665 if (force
666 || ( par_src->process__trig__set
667 && !par_dest->process__trig__set)) {
668 par_dest->process__trig = par_src->process__trig;
669 par_dest->process__trig__set = TRUE;
671 #endif /* ENABLE_DAC */
673 #ifdef ENABLE_IMGPROC
674 if (force
675 || ( par_src->process__imgproc__set
676 && !par_dest->process__imgproc__set)) {
677 par_dest->process__piv = par_src->process__piv;
678 par_dest->process__imgproc__set = TRUE;
680 #endif /* ENABLE_IMGPROC */
682 if (force
683 || ( par_src->process__piv__set
684 && !par_dest->process__piv__set)) {
685 par_dest->process__piv = par_src->process__piv;
686 par_dest->process__piv__set = TRUE;
689 if (force
690 || ( par_src->process__gradient__set
691 && !par_dest->process__gradient__set)) {
692 par_dest->process__gradient = par_src->process__gradient;
693 par_dest->process__gradient__set = TRUE;
696 if (force
697 || ( par_src->process__resstats__set
698 && !par_dest->process__resstats__set)) {
699 par_src->process__resstats = par_dest->process__resstats;
700 par_dest->process__resstats__set = TRUE;
703 if (force
704 || ( par_src->process__errvec__set
705 && !par_dest->process__errvec__set)) {
706 par_dest->process__errvec = par_src->process__errvec;
707 par_dest->process__errvec__set = TRUE;
710 if (force
711 || ( par_src->process__peaklock__set
712 && !par_dest->process__peaklock__set)) {
713 par_dest->process__peaklock = par_src->process__peaklock;
714 par_dest->process__peaklock__set = TRUE;
717 if (force
718 || ( par_src->process__scale__set
719 && !par_dest->process__scale__set)) {
720 par_dest->process__scale = par_src->process__scale;
721 par_dest->process__scale__set = TRUE;
724 if (force
725 || ( par_src->process__average__set
726 && !par_dest->process__average__set)) {
727 par_dest->process__average = par_src->process__average;
728 par_dest->process__average__set = TRUE;
731 if (force
732 || ( par_src->process__subtract__set
733 && !par_dest->process__subtract__set)) {
734 par_dest->process__subtract = par_src->process__subtract;
735 par_dest->process__subtract__set = TRUE;
738 if (force
739 || ( par_src->process__vorstra__set
740 && !par_dest->process__vorstra__set)) {
741 par_dest->process__vorstra = par_src->process__vorstra;
742 par_dest->process__vorstra__set = TRUE;
745 if (force
746 || ( par_src->display__view_menubar__set
747 && !par_dest->display__view_menubar__set)) {
748 par_dest->display__view_menubar = par_src->display__view_menubar;
749 par_dest->display__view_menubar__set = TRUE;
752 if (force
753 || ( par_src->display__view_rulers__set
754 && !par_dest->display__view_rulers__set)) {
755 par_dest->display__view_rulers = par_src->display__view_rulers;
756 par_dest->display__view_rulers__set = TRUE;
759 if (force
760 || ( par_src->display__stretch_auto__set
761 && !par_dest->display__stretch_auto__set)) {
762 par_dest->display__view_rulers = par_src->display__view_rulers;
763 par_dest->display__stretch_auto__set = TRUE;
766 if (force
767 || ( par_src->display__vector_scale__set
768 && !par_dest->display__vector_scale__set)) {
769 par_dest->display__vector_scale = par_src->display__vector_scale;
770 par_dest->display__vector_scale__set = TRUE;
773 if (force
774 || ( par_src->display__vector_color__set
775 && !par_dest->display__vector_color__set)) {
776 par_dest->display__vector_color = par_src->display__vector_color;
777 par_dest->display__vector_color__set = TRUE;
780 if (force
781 || ( par_src->display__zoom_index__set
782 && !par_dest->display__zoom_index__set)) {
783 par_dest->display__zoom_index = par_src->display__zoom_index;
784 par_dest->display__zoom_index__set = TRUE;
787 if (force
788 || ( par_src->display__backgrnd__set
789 && !par_dest->display__backgrnd__set)) {
790 par_dest->display__backgrnd = par_src->display__backgrnd;
791 par_dest->display__backgrnd__set = TRUE;
794 if (force
795 || ( par_src->display__intregs__set
796 && !par_dest->display__intregs__set)) {
797 par_dest->display__intregs = par_src->display__intregs;
798 par_dest->display__intregs__set = TRUE;
801 if (force
802 || ( par_src->display__piv__set
803 && !par_dest->display__piv__set)) {
804 par_dest->display__piv = par_src->display__piv;
805 par_dest->display__piv__set = TRUE;
808 if (force
809 || ( par_src->display__scalar__set
810 && !par_dest->display__scalar__set)) {
811 par_dest->display__scalar = par_src->display__scalar;
812 par_dest->display__scalar__set = TRUE;
815 #ifdef ENABLE_MPI
816 if (force
817 || ( par_src->mpi_nodes__set
818 && !par_dest->mpi_nodes__set)) {
819 par_dest->mpi_nodes = par_src->mpi_nodes;
820 par_dest->mpi_nodes__set = TRUE;
822 #endif /* ENABLE_MPI */