atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
w_data.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2026 by CNRS and University of Strasbourg */
15
21
22/*
23* This file: 'w_data.c'
24*
25* Contains:
26*
27
28 - The functions to export curve data
29
30*
31* List of functions:
32
33 void write_curve (gpointer idata);
34
35 G_MODULE_EXPORT void run_write_curve (GtkNativeDialog * info, gint response_id, gpointer data);
36 G_MODULE_EXPORT void run_write_curve (GtkDialog * info, gint response_id, gpointer data);
37
38*/
39
40#include <gtk/gtk.h>
41#include <string.h>
42#include <stdlib.h>
43
44#include "global.h"
45#include "interface.h"
46#include "project.h"
47#include "curve.h"
48
49void save_to_file_ (int *, char *, int *, double *, double *, int *, int *, int *, double *, int *, int *, int *, int *, int *, char *);
50void prep_file_ (int *, char *, int *, int *, int *, int *, double *, int *, int *);
51void append_to_file_ (int *, double *, double *, double *, int *, int *, int *, int *, int *, int *, int *, int *, char *);
52
53GtkFileFilter * filter1, * filter2;
54
55#ifdef GTK4
65G_MODULE_EXPORT void run_write_curve (GtkNativeDialog * info, gint response_id, gpointer data)
66{
67 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
68#else
78G_MODULE_EXPORT void run_write_curve (GtkDialog * info, gint response_id, gpointer data)
79{
80 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
81#endif
82 int a, b, c, i, j, k, l, m, n, o, p, q;
83 tint * cd = (tint *)data;
84 Curve * this_curve = get_curve_from_pointer (data);
85 a = cd -> a;
86 b = cd -> b;
87 c = cd -> c;
88 if (response_id == GTK_RESPONSE_ACCEPT)
89 {
90 project * this_proj = get_project_by_id(a);
91 double delta = this_proj -> analysis[b] -> delta;
92 this_curve -> cfile = file_chooser_get_file_name (chooser);
93 GtkFileFilter * tmp = gtk_file_chooser_get_filter (chooser);
94 if (tmp == filter1)
95 {
96 l = 0;
97 }
98 else if (tmp == filter2)
99 {
100 l = 1;
101 }
102 k = strlen (this_curve -> cfile);
103 j = strlen (this_curve -> title);
104 // Get n
105 if (this_curve -> extrac -> extras == 0)
106 {
107 m = activep;
109 save_to_file_ (& k, this_curve -> cfile,
110 & this_curve -> ndata,
111 this_curve -> data[0],
112 this_curve -> data[1],
113 & this_curve -> scale[0],
114 & this_curve -> scale[1],
115 & this_curve -> layout -> aspect,
116 & delta, & b, & c, & this_proj -> nspec, & l,
117 & j, this_curve -> title);
119 }
120 else
121 {
122 p = this_curve -> extrac -> extras + 1;
123 m = 0;
124 prep_file_ (& k, this_curve -> cfile, & this_proj -> nspec, & l,
125 & this_curve -> scale[0],
126 & this_curve -> scale[1],
127 & delta, & b, & c);
128 append_to_file_ (& this_curve -> ndata,
129 this_curve -> data[0],
130 this_curve -> data[1],
131 & delta,
132 & this_curve -> layout -> aspect,
133 & b, & c, & this_proj -> nspec, & l, & m, & p,
134 & j, this_curve -> title);
135 j = this_curve -> extrac -> extras;
136 CurveExtra * ctmp = this_curve -> extrac -> first;
137 for (i=0 ; i < j ; i++ )
138 {
139 m = m + 1;
140 q = ctmp -> id.a;
141 o = ctmp -> id.b;
142 n = ctmp -> id.c;
143 this_proj = get_project_by_id(q);
144 j = strlen (this_proj -> analysis[o] -> curves[n] -> title);
145 append_to_file_ (& this_proj -> analysis[o] -> curves[n] -> ndata,
146 this_proj -> analysis[o] -> curves[n] -> data[0],
147 this_proj -> analysis[o] -> curves[n] -> data[1],
148 & this_proj -> analysis[o] -> delta,
149 & ctmp -> layout -> aspect,
150 & o, & n, & this_proj -> nspec, & l, & m, & p,
151 & j, this_proj -> analysis[o] -> curves[n] -> title);
152 if (ctmp -> next) ctmp = ctmp -> next;
153 }
154 }
155 }
156#ifdef GTK4
158#else
159 destroy_this_dialog (info);
160#endif
161}
162
170void write_curve (gpointer idata)
171{
172#ifdef GTK4
173 GtkFileChooserNative * info;
174#else
175 GtkWidget * info;
176#endif
177 Curve * this_curve = get_curve_from_pointer (idata);
178 info = create_file_chooser (_("Save Data"),
179 GTK_WINDOW(this_curve -> window),
180 GTK_FILE_CHOOSER_ACTION_SAVE,
181 _("Save"));
182 GtkFileChooser * chooser = GTK_FILE_CHOOSER(info);
183#ifdef GTK3
184 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
185#endif
186 filter1 = gtk_file_filter_new();
187 gtk_file_filter_set_name (GTK_FILE_FILTER(filter1), _("Xmgrace file (*.agr)"));
188 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter1), "*.agr");
189 gtk_file_chooser_add_filter (chooser, filter1);
190 filter2 = gtk_file_filter_new();
191 gtk_file_filter_set_name (GTK_FILE_FILTER(filter2), _("x/y ASCII file (*.dat)"));
192 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter2), "*.dat");
193 gtk_file_chooser_add_filter (chooser, filter2);
194 if (this_curve -> cfile != NULL)
195 {
196 if (! file_chooser_set_file_name (chooser, this_curve -> cfile)) goto end;
197 }
198 else
199 {
201 gtk_file_chooser_set_current_name (chooser, this_curve -> name);
202 }
203#ifdef GTK4
204 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_write_curve), idata);
205#else
206 run_this_gtk_dialog (info, G_CALLBACK(run_write_curve), idata);
207#endif
208 end:;
209}
double scale(double axe)
find appropriate major tick spacing based on axis length
Definition curve.c:205
Curve * get_curve_from_pointer(gpointer data)
get Curve pointer from pointer
Definition curve.c:313
PangoLayout * layout
Definition curve.c:80
Variable declarations for the curve widget Functions for interactions with the curve widget.
int activep
Definition global.c:162
Global variable declarations Global convenience function declarations Global data structure defin...
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
Definition gtk-misc.c:533
void file_chooser_set_current_folder(GtkFileChooser *chooser)
set current folder in a GtkFilechooser
Definition gtk-misc.c:2358
gchar * file_chooser_get_file_name(GtkFileChooser *chooser)
get a file name from a GtkFileChooser (single file selected)
Definition gtk-misc.c:2306
gboolean file_chooser_set_file_name(GtkFileChooser *chooser, gchar *filename)
set file name in a GtkFilechooser
Definition gtk-misc.c:2339
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2235
GtkWidget * create_file_chooser(const gchar *title, GtkWindow *parent, GtkFileChooserAction act, const gchar *act_name)
create a GtkFileChooser, utility to select file(s)
Definition gtk-misc.c:2393
void destroy_this_native_dialog(GtkNativeDialog *dialog)
destroy a GtkNativeDialog
Definition gtk-misc.c:2254
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
Messaging function declarations.
Function declarations for reading atomes project file Function declarations for saving atomes proje...
void active_project_changed(int id)
change the active project
Definition update_p.c:220
Definition global.h:118
GtkFileFilter * filter1
Definition w_data.c:53
void save_to_file_(int *, char *, int *, double *, double *, int *, int *, int *, double *, int *, int *, int *, int *, int *, char *)
GtkFileFilter * filter2
Definition w_data.c:53
void prep_file_(int *, char *, int *, int *, int *, int *, double *, int *, int *)
G_MODULE_EXPORT void run_write_curve(GtkDialog *info, gint response_id, gpointer data)
save curve data - running the dialog GTK3
Definition w_data.c:78
void write_curve(gpointer idata)
save curve data - creating the dialog
Definition w_data.c:170
void append_to_file_(int *, double *, double *, double *, int *, int *, int *, int *, int *, int *, int *, int *, char *)