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
8 Copyright (C) 2007, 2008 Gerber van der Graaf
10 This file is part of gpiv.
12 Gpiv is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 -----------------------------------------------------------------------------*/
28 * Program wide input / output functions (no callbacks)
30 * Revision 1.1 2008-09-16 11:21:27 gerber
42 #include "display_image.h"
44 #define BYTES_TO_PROCESS 8192
47 select_action_from_uri (GpivConsole
*gpiv
,
51 select_action_from_fname (GpivConsole
*gpiv
,
55 open_img (char *fname_in
59 open_piv (char *fname_in
,
64 load_buffer (GpivConsole
*gpiv
,
69 enum ClistPut clist_put
73 write_from_tmp_to_uri (const gchar
*uri_string_tmp
,
74 const gchar
*uri_string_out
);
77 move_to_uri (GnomeVFSURI
*uri_out
,
78 const gchar
*fname_out
);
81 write_ascii_scalardata (GnomeVFSURI
*uri_out
,
82 GpivScalarData
*scalar_data
,
83 const char *fname_out_nosuf
,
88 * Program-wide public functions
92 * Retrieving functions
95 select_action_from_name (GpivConsole
*gpiv
,
97 /* ----------------------------------------------------------------------------
98 * Checks on validity of uri and whether local file or not.
99 * Calls apropiate functions.
104 GnomeVFSURI
* uri
= NULL
;
107 text_uri
= gnome_vfs_make_uri_from_shell_arg (name
);
108 g_message("select_action_from_name:: text_uri = %s", text_uri
);
109 uri
= gnome_vfs_uri_new (text_uri
);
111 if (gnome_vfs_uri_exists (uri
)) {
112 if (gnome_vfs_uri_is_local (uri
)) {
113 const gchar
*path
= gnome_vfs_uri_get_path (uri
);
114 select_action_from_fname (gpiv
, (gchar
*) path
);
116 if ((result
= select_action_from_uri (gpiv
, uri
)) != 0) {
117 g_error("select_action_from_name: select_action_from_uri");
122 warning_gpiv ("Uri or filename of input image does not exist");
132 write_hdf_img_data (const gchar
*fname_out_nosuf
,
133 GnomeVFSURI
*uri_out
)
134 /*------------------------------------------------------------------------------
137 char *err_msg
= NULL
;
138 gchar
*fname_out
= g_strdup_printf ("%s%s" , fname_out_nosuf
,
142 if (gpiv_par
->verbose
) g_message ("writing to %s", fname_out
);
145 gpiv_fcreate_hdf5 (fname_out
))
146 != NULL
) error_gpiv ("%s", err_msg
);
148 if (gpiv_par
->img_fmt
== IMG_FMT_HDF
149 && display_act
->img
->saved_img
== FALSE
) {
151 gpiv_img_fwrite_hdf5_parameters (fname_out
,
152 display_act
->img
->image
->header
))
153 != NULL
) error_gpiv ("%s", err_msg
);
156 gpiv_fwrite_hdf5_image (fname_out
, display_act
->img
->image
, FALSE
))
157 != NULL
) error_gpiv ("%s", err_msg
);
158 display_act
->img
->saved_img
= TRUE
;
162 if (display_act
->pida
->exist_piv
) {
163 if (display_act
->pida
->scaled_piv
) {
165 gpiv_fwrite_hdf5_pivdata (fname_out
,
166 display_act
->pida
->piv_data_scaled
,
169 != NULL
) error_gpiv ("%s", err_msg
);
173 gpiv_fwrite_hdf5_pivdata (fname_out
,
174 display_act
->pida
->piv_data
,
177 != NULL
) error_gpiv ("%s", err_msg
);
181 display_act
->pida
->saved_piv
= TRUE
;
184 gpiv_piv_fwrite_hdf5_parameters (fname_out
,
185 display_act
->pida
->piv_par
))
186 != NULL
) error_gpiv ("%s", err_msg
);
190 if (display_act
->pida
->exist_valid
) {
192 gpiv_valid_fwrite_hdf5_parameters (fname_out
,
193 display_act
->pida
->valid_par
))
194 != NULL
) error_gpiv ("%s", err_msg
);
198 if (display_act
->pida
->exist_vor
) {
199 if (display_act
->pida
->scaled_piv
) {
201 gpiv_fwrite_hdf5_scdata (fname_out
,
202 display_act
->pida
->vor_data_scaled
,
205 != NULL
) error_gpiv ("%s", err_msg
);
208 gpiv_fwrite_hdf5_scdata (fname_out
,
209 display_act
->pida
->vor_data
,
212 != NULL
) error_gpiv ("%s", err_msg
);
214 display_act
->pida
->saved_vor
= TRUE
;
218 if (display_act
->pida
->exist_sstrain
) {
219 if (display_act
->pida
->scaled_piv
) {
221 gpiv_fwrite_hdf5_scdata (fname_out
,
222 display_act
->pida
->sstrain_data_scaled
,
225 != NULL
) error_gpiv ("%s", err_msg
);
228 gpiv_fwrite_hdf5_scdata (fname_out
,
229 display_act
->pida
->sstrain_data
,
232 != NULL
) error_gpiv ("%s", err_msg
);
234 display_act
->pida
->saved_sstrain
= TRUE
;
238 if (display_act
->pida
->exist_nstrain
) {
239 if (display_act
->pida
->scaled_piv
) {
241 gpiv_fwrite_hdf5_scdata (fname_out
,
242 display_act
->pida
->nstrain_data_scaled
,
245 != NULL
) error_gpiv ("%s", err_msg
);
248 gpiv_fwrite_hdf5_scdata (fname_out
,
249 display_act
->pida
->nstrain_data
,
252 != NULL
) error_gpiv ("%s", err_msg
);
254 display_act
->pida
->saved_nstrain
= TRUE
;
259 gpiv_post_fwrite_hdf5_parameters (fname_out
,
260 display_act
->pida
->post_par
))
261 != NULL
) error_gpiv ("%s", err_msg
);
264 move_to_uri (uri_out
, fname_out
);
271 write_img (const gchar
*fname_out_nosuf
,
272 GnomeVFSURI
*uri_out
)
273 /*------------------------------------------------------------------------------
274 * Store image to RAW, HDF or PNG format
277 char *err_msg
= NULL
;
282 if (display_act
->img
->saved_img
== FALSE
) {
283 if (gpiv_par
->img_fmt
== IMG_FMT_PNG
) {
284 fname_out
= g_strdup_printf ("%s%s" ,
285 replace_tilde_with_home_dir (fname_out_nosuf
),
288 if ((fp_out
= fopen (fname_out
, "wb")) == NULL
) {
290 error_gpiv ("gpiv: write_img: fopen (%s, \"wb\")) == NULL",
293 if ((err_msg
= gpiv_write_png_image (fp_out
,
294 display_act
->img
->image
,
297 gpiv_error ("gpiv: write_img: %s\n", err_msg
);
300 move_to_uri (uri_out
, fname_out
);
303 } else if (gpiv_par
->img_fmt
== IMG_FMT_HDF
) {
304 fname_out
= g_strdup_printf ("%s%s" ,
305 replace_tilde_with_home_dir (fname_out_nosuf
),
307 if (gpiv_par
->verbose
) g_message ("writing image to %s", fname_out
);
309 gpiv_fcreate_hdf5 (fname_out
))
310 != NULL
) error_gpiv ("%s", err_msg
);
312 gpiv_img_fwrite_hdf5_parameters (fname_out
,
313 display_act
->img
->image
->header
))
314 != NULL
) error_gpiv ("%s", err_msg
);
316 gpiv_fwrite_hdf5_image (fname_out
,
317 display_act
->img
->image
,
319 != NULL
) error_gpiv ("%s", err_msg
);
320 move_to_uri (uri_out
, fname_out
);
323 } else if (gpiv_par
->img_fmt
== IMG_FMT_RAW
) {
325 * Saving ASCII header
328 gchar
*fname_header
= g_strdup_printf ("%s%s" ,
329 replace_tilde_with_home_dir (fname_out_nosuf
),
331 if (gpiv_par
->verbose
) g_message ("writing header to %s", fname_header
);
332 if ((fp_header
= fopen (fname_header
, "w")) == NULL
) {
333 error_gpiv (_("Failure opening image header for output"));
335 /* fprintf(fp_par, "#%s\n", gl_image_par->software);
337 gpiv_img_print_header (fp_header
, display_act
->img
->image
->header
);
339 move_to_uri (uri_out
, fname_header
);
340 g_free (fname_header
);
342 * BUGFIX: Saving RAW image
345 display_act
->img
->saved_img
= TRUE
;
352 write_ascii_parameters (const char *fname_out_nosuf
,
353 GnomeVFSURI
*uri_out
,
355 /*-----------------------------------------------------------------------------
356 * Saves parameters in ascii format
361 gchar
*fname
= g_strdup_printf ("%s%s" ,
362 replace_tilde_with_home_dir (fname_out_nosuf
),
366 if ((fp
= fopen (fname
, "w")) == NULL
) {
367 error_gpiv (_("Failure opening parameter file for output"));
371 * Saving image header
373 if (gl_image_par
->software__set
) {
374 fprintf (fp
, "# Software: %s\n", gl_image_par
->software
);
376 gpiv_img_print_header (fp
, display_act
->img
->image
->header
);
379 * Saving PIV parameters
381 if (display_act
->pida
->exist_piv
) {
382 gpiv_piv_print_parameters (fp
, display_act
->pida
->piv_par
);
383 if (display_act
->pida
->exist_valid
) {
384 gpiv_valid_print_parameters (fp
, display_act
->pida
->valid_par
);
390 * Saving scalar parameters for vorticity
392 if (display_act
->pida
->exist_vor
) {
394 gpiv_post_print_parameters (stdout
, display_act
->pida
->post_par
);
395 gpiv_post_print_parameters (fp
, display_act
->pida
->post_par
);
401 * Saving scalar parameters for shear strain
403 if (display_act
->pida
->exist_sstrain
) {
405 gpiv_post_print_parameters (fp
, display_act
->pida
->post_par
);
411 * Saving scalar parameters for normal strain
413 if (display_act
->pida
->exist_nstrain
) {
415 gpiv_post_print_parameters (fp
, display_act
->pida
->post_par
);
421 move_to_uri (uri_out
, fname
);
428 write_ascii_data (const gchar
*fname_out_nosuf
,
429 GnomeVFSURI
*uri_out
)
430 /*------------------------------------------------------------------------------
431 * Store resulting (PIV and derived) data in ASCII format at
435 char *err_msg
= NULL
;
443 if (display_act
->pida
->exist_piv
) {
444 fname
= g_strdup_printf ("%s%s",
445 replace_tilde_with_home_dir (fname_out_nosuf
),
448 if ((fp
= fopen (fname
, "wb")) == NULL
) {
449 warning_gpiv ("write_ascii_data: failing fopen %s", fname
);
453 if (display_act
->pida
->scaled_piv
) {
455 gpiv_write_pivdata (fp
,
456 display_act
->pida
->piv_data_scaled
,
458 != NULL
) error_gpiv ("%s", err_msg
);
461 gpiv_write_pivdata (fp
,
462 display_act
->pida
->piv_data
,
464 != NULL
) error_gpiv ("%s", err_msg
);
468 display_act
->pida
->saved_piv
= TRUE
;
469 move_to_uri (uri_out
, fname
);
476 if (display_act
->pida
->exist_histo
) {
477 fname
= g_strdup_printf ("%s%s" ,
478 replace_tilde_with_home_dir (fname_out_nosuf
),
480 if (gpiv_par
->verbose
) g_message ("writing HISTO data to %s", fname
);
482 if ((fp
= fopen (fname
, "wb")) == NULL
) {
483 warning_gpiv ("write_ascii_data: failing fopen %s", fname
);
487 gpiv_print_histo (fp
,
488 display_act
->pida
->klass
,
492 display_act
->pida
->saved_histo
= TRUE
;
493 move_to_uri (uri_out
, fname
);
498 * Saving scalar vorticity data
500 if (display_act
->pida
->exist_vor_scaled
) {
501 write_ascii_scalardata (uri_out
, display_act
->pida
->vor_data_scaled
,
502 fname_out_nosuf
, GPIV_EXT_VOR
);
503 display_act
->pida
->saved_vor
= TRUE
;
504 } else if (display_act
->pida
->exist_vor
) {
505 write_ascii_scalardata (uri_out
, display_act
->pida
->vor_data
,
506 fname_out_nosuf
, GPIV_EXT_VOR
);
507 display_act
->pida
->saved_vor
= TRUE
;
512 * Saving scalar shear strain data
514 if (display_act
->pida
->exist_sstrain_scaled
) {
515 write_ascii_scalardata (uri_out
, display_act
->pida
->sstrain_data_scaled
,
516 fname_out_nosuf
, GPIV_EXT_SSTR
);
517 display_act
->pida
->saved_sstrain
= TRUE
;
518 } else if (display_act
->pida
->exist_sstrain
) {
519 write_ascii_scalardata (uri_out
, display_act
->pida
->sstrain_data
,
520 fname_out_nosuf
, GPIV_EXT_SSTR
);
521 display_act
->pida
->saved_sstrain
= TRUE
;
525 * Saving scalar normal strain data
527 if (display_act
->pida
->exist_nstrain_scaled
) {
528 write_ascii_scalardata (uri_out
, display_act
->pida
->nstrain_data_scaled
,
529 fname_out_nosuf
, GPIV_EXT_NSTR
);
530 display_act
->pida
->saved_nstrain
= TRUE
;
531 } else if (display_act
->pida
->exist_nstrain
) {
532 write_ascii_scalardata (uri_out
, display_act
->pida
->nstrain_data
,
533 fname_out_nosuf
, GPIV_EXT_NSTR
);
534 display_act
->pida
->saved_nstrain
= TRUE
;
542 * Local functions on retrieving data
546 select_action_from_uri (GpivConsole
*gpiv
,
548 /* ----------------------------------------------------------------------------
549 * checks filename extension on valid image/data name, on existence of buffer,
551 * As i/o from libgpiv (which does not have libgnomevfs) will have to be
552 * be used (applying libpng funcionality), the image (data) are copied to a
553 * tmp directory and subsequtially be loaded with libgpiv i/o
557 GnomeVFSHandle
*read_handle
, *write_handle
;
558 GnomeVFSResult result
, result_while
;
559 GnomeVFSFileSize bytes_read
, bytes_written
;
560 guint buffer
[BYTES_TO_PROCESS
];
561 gchar
*output_uri_string
;
563 const gchar
*tmp_dir
= g_get_tmp_dir ();
564 const gchar
*user_name
= g_get_user_name ();
565 const gchar
*local_tmp_dirname
= g_strdup_printf ("%s/%s",
569 gchar
*dirname
= gnome_vfs_uri_extract_dirname (uri
);
570 gchar
*basename
= gnome_vfs_uri_extract_short_name (uri
);
574 g_mkdir(local_tmp_dirname
, 0777);
575 if (gpiv_par
->verbose
) {
576 g_message ("select_action_from_uri:: tmp_dir = %s", tmp_dir
);
577 g_message ("select_action_from_uri:: user_name = %s", user_name
);
578 g_message ("select_action_from_uri:: local_tmp_dirname = %s",
580 g_message ("select_action_from_uri:: dirname = %s basename = %s",
584 output_uri_string
= g_strdup_printf ("%s/%s/%s" ,tmp_dir
,
585 user_name
, basename
);
586 if (gpiv_par
->verbose
) {
587 g_message ("select_action_from_uri:: output_uri_string = %s",
591 if ((result
= gnome_vfs_open_uri (&read_handle
, uri
, GNOME_VFS_OPEN_READ
))
593 gpiv_error ("select_action_from_uri: gnome_vfs_open_uri");
595 if ((result
= gnome_vfs_create (&write_handle
, output_uri_string
,
596 GNOME_VFS_OPEN_WRITE
, FALSE
, 0777))
597 != GNOME_VFS_OK
) gpiv_error ("select_action_from_uri: gnome_vfs_create");
599 /* read data from the input uri */
600 while (result
== GNOME_VFS_OK
) {
601 result
= gnome_vfs_read (read_handle
, buffer
, BYTES_TO_PROCESS
,
604 if ((result_while
= gnome_vfs_seek (write_handle
, GNOME_VFS_SEEK_END
, 0))
606 gpiv_error ("select_action_from_uri: gnome_vfs_seek");
608 if ((result_while
= gnome_vfs_write (write_handle
, buffer
, bytes_read
,
611 gpiv_error ("select_action_from_uri: gnome_vfs_write");
615 * add to uri to fname_last;
616 * Reading image from temporarly storage
617 * put correct name in Image tab
620 gpiv_var
->fname_last
= gnome_vfs_uri_to_string (uri
, TRUE
);
621 gnome_config_push_prefix ("/gpiv/RuntimeVariables/");
622 gnome_config_set_string ("fname_last", gpiv_var
->fname_last
);
623 gnome_config_pop_prefix ();
624 gnome_config_sync ();
625 push_list_lastfnames (gpiv_var
->fname_last
);
627 gpiv_var
->fname_last__set
= TRUE
;
628 select_action_from_fname (gpiv
, output_uri_string
);
629 gpiv_var
->fname_last__set
= FALSE
;
631 display_act
->file_uri_name
=
632 g_strdup_printf ("%s",
633 strtok (gnome_vfs_uri_to_string (uri
, TRUE
), "."));
635 update_imgh_entries (gpiv
, display_act
->img
->image
->header
);
637 command
= g_strdup_printf ("rm %s", output_uri_string
);
638 if (gpiv_par
->verbose
) {
639 g_message ("command = %s", command
);
641 if (system (command
) != 0) {
642 g_warning ("select_action_from_uri: could not exec shell command: %s",
647 g_free (output_uri_string
);
648 g_free (local_tmp_dirname
);
657 select_action_from_fname (GpivConsole
*gpiv
,
659 /* ----------------------------------------------------------------------------
660 * checks filename suffux on valid image/data name, on existence of buffer,
664 gchar
*err_msg
= NULL
;
665 gint ibuf
, return_val
;
666 gchar
*suf
, /* filename suffix */
667 *dirname
, /* directory name */
668 *fname_base
, /* Image name without suffix and dirname */
669 *fname_nosuf
, /* Image name without suffix */
671 gboolean exist_buf
= FALSE
;
672 gchar command
[2 * GPIV_MAX_CHARS
];
673 /* gchar *command; */
676 suf
= g_strdup (strrchr (fname_in
, '.'));
677 /* add to push_list_lastfnames (fname_base); */
678 if (!gpiv_var
->fname_last__set
) {
679 gpiv_var
->fname_last
= g_strdup (fname_in
);
680 gnome_config_push_prefix ("/gpiv/RuntimeVariables/");
681 gnome_config_set_string ("fname_last", gpiv_var
->fname_last
);
682 gnome_config_pop_prefix ();
683 gnome_config_sync ();
686 * Stripping file name
687 * We need them for displaying in the image header tab and on the buffer list
689 fname_home
= replace_home_dir_with_tilde (fname_in
);
690 dirname
= g_strdup (g_path_get_dirname (fname_home
));
691 /* (replace_home_dir_with_tilde (fname_in))); */
693 fname_base
= g_strdup (g_path_get_basename (fname_in
));
694 strtok (fname_base
, ".");
695 if (!gpiv_var
->fname_last__set
) {
696 push_list_lastfnames (fname_base
);
698 fname_nosuf
= g_strdup (g_strconcat (dirname
, G_DIR_SEPARATOR_S
,
702 * reading image data from raw, PNG, hdf or Davis(tm) format
703 * Ensure that the tabulator widgets are enabled
705 if (g_str_has_suffix (fname_in
, GPIV_EXT_RAW_IMAGE
)
706 || g_str_has_suffix (fname_in
, GPIV_EXT_PNG_IMAGE
)
707 || g_str_has_suffix (fname_in
, GPIV_EXT_PNG_IMAGE_UPCASE
)
708 || g_str_has_suffix (fname_in
, GPIV_EXT_GPIV
)
709 || g_str_has_suffix (fname_in
, GPIV_EXT_DAVIS
)
710 || g_str_has_suffix (fname_in
, GPIV_EXT_PGM_IMAGE
)
711 || g_str_has_suffix (fname_in
, GPIV_EXT_PGM_IMAGE_UPCASE
)
712 || g_str_has_suffix (fname_in
, ".gif")
713 || g_str_has_suffix (fname_in
, ".GIF")
714 || g_str_has_suffix (fname_in
, ".tif")
715 || g_str_has_suffix (fname_in
, ".TIF")
716 || g_str_has_suffix (fname_in
, ".bmp")
717 || g_str_has_suffix (fname_in
, ".BMP")
723 sensitive (gpiv
, IMG
, TRUE
);
724 sensitive (gpiv
, EVAL
, TRUE
);
728 * Check if file basename (and buffer/display) already exists
729 * or if there is a gap in the numbering of the buffers
731 for (ibuf
= 0; ibuf
< nbufs
; ibuf
++) {
732 display_act
= gtk_clist_get_row_data (GTK_CLIST (gpiv
->clist_buf
),
734 if (ibuf
== display_act
->id
735 && strcmp (fname_nosuf
, display_act
->file_uri_name
) == 0 ) {
736 if ((display_act
->img
->image
= open_img (fname_in
)) == NULL
) {
743 } else if (ibuf
< display_act
->id
) {
745 load_buffer (gpiv
, fname_in
, fname_base
, fname_nosuf
,
746 ibuf
, INSERT
)) != NULL
) {
747 g_warning ("select_action_from_fname: failing load_buffer");
754 /* g_warning ("select_action_from_fname: should not arrive here"); */
760 * All buffers with id between 0 and nbufs already exist.
761 * Create a new buffer and launches a display if file basename doesn't exist
762 * and append to the list
767 load_buffer (gpiv
, fname_in
, fname_base
, fname_nosuf
,
772 warning_gpiv (_("select_action_from_fname: non-valid file name"));
775 gtk_clist_set_selection_mode (GTK_CLIST (gpiv
->clist_buf
),
776 GTK_SELECTION_EXTENDED
);
778 #ifdef ENABLE_IMGPROC
779 set_imgproc_filtervar (gpiv
, GPIV_IMGFI_SUBACK
, nbufs
- 1);
785 g_free (fname_nosuf
);
791 open_img (char *fname_in
793 /*-----------------------------------------------------------------------------
794 * Opens an image from png, hdf or raw-data file (<=> open_dac_img)
797 GpivImage
*image
= NULL
;
798 gchar
*err_msg
= NULL
;
801 if ((image
= gpiv_fread_image (fname_in
)) == NULL
) {
802 warning_gpiv ("OPEN_IMG: failing gpiv_fread_image %s", fname_in
);
806 display_act
->img
->exist_img
= TRUE
;
809 * The loaded image has not yet been modified, so there is no need to save
810 * image or header information
812 display_act
->img
->saved_img
= TRUE
;
821 open_piv (char *fname_in
,
824 /*-----------------------------------------------------------------------------
825 * Opens piv data file and displays
828 char *err_msg
= NULL
, RCSID_DATA
[GPIV_MAX_CHARS
];
829 char *ext
= g_strdup (strrchr (fname_in
, '.'));
830 gint var_scale
= 0, scale
= 0;
834 * parameter initializing of piv data
836 /* pida->piv_par->autokey = 1; */
837 gpiv_piv_parameters_set (pida
->piv_par
, FALSE
);
842 if (strcmp (ext
, GPIV_EXT_GPIV
) == 0) {
843 if ((pida
->piv_data
=
844 gpiv_fread_hdf5_pivdata (fname_in
, "PIV"))
846 warning_gpiv ("OPEN_PIV: failing piv_fread_hdf5_pivdata %s",
850 pida
->exist_piv
= TRUE
;
851 pida
->averaged_piv
= FALSE
;
855 * Reads raw data format
857 } else if (strcmp (ext
, GPIV_EXT_RAW_IMAGE
) == 0
858 || strcmp (ext
, GPIV_EXT_DAVIS
) == 0
861 gchar
*dirname
= g_strdup (g_dirname (fname_in
)),
862 *fname_base
= g_strdup (g_basename (fname_in
)),
867 * check on existance of piv data file
869 strtok (fname_base
, ".");
870 fname_ext
= g_strdup (g_strconcat (dirname
, G_DIR_SEPARATOR_S
,
872 fname_piv
= g_strdup (g_strconcat (fname_ext
, GPIV_EXT_PIV
, NULL
));
874 if ((fp
= fopen (fname_piv
, "r")) == NULL
) {
875 warning_gpiv ("OPEN_PIV: failing fopen %s", fname_piv
);
878 if ((pida
->piv_data
= gpiv_read_pivdata (fp
)) == NULL
) {
879 warning_gpiv ("OPEN_PIV: failing gpiv_read_pivdata");
884 pida
->exist_piv
= TRUE
;
885 pida
->averaged_piv
= FALSE
;
894 if (gpiv_par
->verbose
) g_message ("open_piv: no PIV data");
906 load_buffer (GpivConsole
*gpiv
,
911 enum ClistPut clist_put
913 /*-----------------------------------------------------------------------------
914 * create display and its (popup) menu, load image, piv data and puts
915 * buffername into clist
919 gchar
*err_msg
= NULL
;
920 gchar
*clist_buf_txt
[MAX_BUFS
][2], cl_int
[3];
921 gboolean local_stretch_window
= gpiv_par
->display__stretch_window
;
922 GpivImage
*image
= NULL
;
926 * We need to know the image dimensions before creating the buffer display
927 * So, first load the image
929 if ((image
= gpiv_fread_image (fname_in
)) == NULL
) {
930 warning_gpiv ("load_buffer: failing gpiv_fread_image %s", fname_in
);
931 err_msg
= "failing gpiv_fread_image";
936 * Creating buffer and display
938 display
[ibuf
] = create_display (fname_ext
, image
, ibuf
, gpiv
);
939 display_act
= display
[ibuf
];
940 display_act
->img
->exist_img
= TRUE
;
941 display_act
->img
->saved_img
= TRUE
;
944 * Load eventually existing PIV data
946 open_piv (fname_in
, display
[ibuf
]->pida
);
949 * Suppress creating intregs during load_buffer by toggle menu;
950 * after displaying it will result into the correct effect
952 view_toggle_intregs_flag
= FALSE
;
953 gpiv_par
->display__stretch_window
= TRUE
;
955 display_act
->display_popupmenu
= create_display_popupmenu (display_act
);
956 gtk_signal_connect_object (GTK_OBJECT (display_act
->mwin
),
957 "button_press_event",
958 GTK_SIGNAL_FUNC (on_my_popup_handler
),
959 GTK_OBJECT (display_act
->display_popupmenu
));
960 gpiv_par
->display__stretch_window
= local_stretch_window
;
961 stretch_window (display_act
);
964 * Creating pixbuf image for displaying of image data
966 if ( display_act
->gci_bg
!= NULL
) {
967 destroy_background(display_act
->gci_bg
);
969 display_act
->gci_bg
= create_background (display_act
);
971 create_img (display_act
);
972 if (display_act
->img
->image
->header
->x_corr
973 && display_act
->img
->image
->frame2
974 && display_act
->display_backgrnd
== SHOW_BG_IMG1
) {
975 /* hide_img2 (display_act); */
976 show_img1 (display_act
);
977 } else if (display_act
->display_backgrnd
== SHOW_BG_IMG2
) {
978 /* hide_img1 (display_act); */
979 show_img2 (display_act
);
980 } else if (display_act
->display_backgrnd
== SHOW_BG_DARKBLUE
) {
981 gchar
*color
= "darkblue";
982 /* hide_img1 (display_act); */
983 /* hide_img2 (display_act); */
984 if (display_act
->gci_bg
!= NULL
) {
985 gnome_canvas_item_set (GNOME_CANVAS_ITEM (display_act
->gci_bg
),
990 gchar
*color
= "black";
991 if (display_act
->gci_bg
!= NULL
) {
992 gnome_canvas_item_set (GNOME_CANVAS_ITEM (display_act
->gci_bg
),
1000 * Creating PIV vectors
1002 if (display_act
->display_piv
) {
1003 create_all_vectors (display_act
->pida
);
1006 display_act
->img
->img_mean
=
1007 image_mean (display_act
->img
->image
->frame1
,
1008 display_act
->img
->image
->header
->ncolumns
,
1009 display_act
->img
->image
->header
->nrows
);
1012 if (gpiv_par
->display__intregs
== 1) {
1013 show_all_intregs (display_act
);
1015 view_toggle_intregs_flag
= TRUE
;
1018 * Add buffer to clist; the column int the console which shows the names of
1021 g_snprintf (cl_int
, 3, "%d", ibuf
);
1022 clist_buf_txt
[ibuf
][0] = (gchar
*) cl_int
;
1023 clist_buf_txt
[ibuf
][1] = fname_base
;
1024 if (clist_put
== PREPEND
) {
1025 gtk_clist_prepend (GTK_CLIST (gpiv
->clist_buf
),
1026 clist_buf_txt
[ibuf
]);
1027 } else if (clist_put
== INSERT
) {
1028 gtk_clist_insert (GTK_CLIST (gpiv
->clist_buf
), ibuf
,
1029 clist_buf_txt
[ibuf
]);
1030 } else if (clist_put
== APPEND
) {
1031 gtk_clist_append (GTK_CLIST (gpiv
->clist_buf
),
1032 clist_buf_txt
[ibuf
]);
1034 error_gpiv ("non-existent CLIST enumerate");
1037 gtk_clist_set_row_data (GTK_CLIST (gpiv
->clist_buf
), ibuf
,
1041 gtk_widget_set_size_request (display_act
->canvas
,
1042 (gint
) (display_act
->zoom_factor
*
1043 display_act
->img
->image
->header
->ncolumns
),
1044 (gint
) (display_act
->zoom_factor
*
1045 display_act
->img
->image
->header
->nrows
));
1047 #ifdef ENABLE_IMGPROC
1048 set_imgproc_filtervar (gpiv
, GPIV_IMGFI_SUBACK
, nbufs
- 1);
1056 * Local functions on writing
1060 write_from_tmp_to_uri (const gchar
*uri_string_tmp
,
1061 const gchar
*uri_string_out
)
1062 /*-----------------------------------------------------------------------------
1065 GnomeVFSHandle
*read_handle
, *write_handle
;
1066 GnomeVFSResult result
, result_while
;
1067 GnomeVFSFileSize bytes_read
, bytes_written
;
1068 guint buffer
[BYTES_TO_PROCESS
];
1072 if ((result
= gnome_vfs_open (&read_handle
, uri_string_tmp
,
1073 GNOME_VFS_OPEN_READ
))
1074 != GNOME_VFS_OK
) gpiv_error ("write_from_tmp_to_uri: gnome_vfs_open_uri");
1076 if ((result
= gnome_vfs_create (&write_handle
, uri_string_out
,
1077 GNOME_VFS_OPEN_WRITE
, FALSE
, 0777))
1078 != GNOME_VFS_OK
) gpiv_error ("write_from_tmp_to_uri: gnome_vfs_create");
1080 while (result
== GNOME_VFS_OK
) {
1081 result
= gnome_vfs_read (read_handle
, buffer
, BYTES_TO_PROCESS
,
1084 if ((result_while
= gnome_vfs_write (write_handle
, buffer
, bytes_read
,
1086 != GNOME_VFS_OK
) gpiv_error ("write_from_tmp_to_uri: gnome_vfs_write");
1090 command
= g_strdup_printf ("rm %s", gnome_vfs_uri_get_path
1091 (gnome_vfs_uri_new (uri_string_tmp
)));
1092 if (system (command
) != 0) {
1093 warning_gpiv ("write_from_tmp_to_uri: could not exec shell command: %s",
1104 move_to_uri (GnomeVFSURI
*uri_out
,
1105 const gchar
*fname_out
)
1106 /*-----------------------------------------------------------------------------
1107 * Move file to uri if not local
1110 gchar
*suffix
= g_strdup (strrchr (fname_out
, '.'));
1113 if (!gnome_vfs_uri_is_local (uri_out
)) {
1114 gchar
*uri_string_tmp
= gnome_vfs_make_uri_from_input(fname_out
);
1115 gchar
*uri_string_out
= gnome_vfs_make_uri_from_input
1118 (g_strdup_printf ("%s%s" ,
1119 display_act
->file_uri_name
,
1121 write_from_tmp_to_uri (uri_string_tmp
, uri_string_out
);
1122 g_free (uri_string_tmp
);
1123 g_free (uri_string_out
);
1131 write_ascii_scalardata (GnomeVFSURI
*uri_out
,
1132 GpivScalarData
*scalar_data
,
1133 const char *fname_out_nosuf
,
1134 const gchar
*suffix
)
1135 /*-----------------------------------------------------------------------------
1136 * Saves scalar data in ascii format
1139 gchar
*err_msg
= NULL
;
1140 gchar
*fname_out
= g_strdup_printf ("%s%s" ,
1141 replace_tilde_with_home_dir
1147 if (gpiv_par
->verbose
) g_message ("writing ascii data to %s", fname_out
);
1149 if ((fp
= fopen (fname_out
, "w")) == NULL
) {
1150 warning_gpiv ("write_ascii_data: failing fopen %s", fname_out
);
1156 gpiv_write_scdata (fp
, scalar_data
, FALSE
))
1157 != NULL
) error_gpiv ("%s", err_msg
);
1161 move_to_uri (uri_out
, fname_out
);