atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
save_curve.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: 'save_curve.c'
24*
25* Contains:
26*
27
28 - The functions to save curves information in the atomes project file format
29
30*
31* List of functions:
32
33 int write_data_layout (FILE * fp, DataLayout * layout);
34 int save_project_curve (FILE * fp, project * this_proj, int wid, int rid, int cid);
35
36*/
37
38#include "global.h"
39#include "project.h"
40
50{
51 if (fwrite (& layout -> datacolor, sizeof(ColRGBA), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
52 if (fwrite (& layout -> thickness, sizeof(double), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
53 if (fwrite (& layout -> dash, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
54 if (fwrite (& layout -> glyph, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
55 if (fwrite (& layout -> gsize, sizeof(double), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
56 if (fwrite (& layout -> gfreq, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
57 if (fwrite (& layout -> hwidth, sizeof(double), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
58 if (fwrite (& layout -> hopac, sizeof(double), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
59 if (fwrite (& layout -> hpos, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
60 if (fwrite (& layout -> aspect, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
61 return OK;
62}
63
75int save_project_curve (FILE * fp, project * this_proj, int wid, int rid, int cid)
76{
77 int i, j, k;
78
79 if (fwrite (& rid, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
80 if (fwrite (& cid, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
81 Curve * this_curve = this_proj -> analysis[rid] -> curves[cid];
82 if (save_this_string (fp, this_curve -> name) != OK) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
83 if (fwrite (& this_curve -> displayed, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
84 if (fwrite (& this_curve -> ndata, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
85 if (fwrite (this_curve -> data[0], sizeof(double), this_curve -> ndata, fp) != this_curve -> ndata) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
86 if (fwrite (this_curve -> data[1], sizeof(double), this_curve -> ndata, fp) != this_curve -> ndata) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
87 i = 0;
88 if (this_curve -> err != NULL) i = 1;
89 if (fwrite (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
90 if (this_curve -> err != NULL)
91 {
92 if (fwrite (this_curve -> err, sizeof(double), this_curve -> ndata, fp) != this_curve -> ndata) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
93 }
94
95 if (this_curve -> displayed)
96 {
97 if (fwrite (this_curve -> wsize, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
98 if (fwrite (this_curve -> cmin, sizeof(double), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
99 if (fwrite (this_curve -> cmax, sizeof(double), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
100 // Title
101 if (fwrite (& this_curve -> show_title, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
102 if (fwrite (& this_curve -> default_title, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
103 if (! this_curve -> default_title)
104 {
105 if (save_this_string (fp, this_curve -> title) != OK) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
106 }
107 if (fwrite (this_curve -> title_pos, sizeof(double), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
108 if (save_this_string (fp, this_curve -> title_font) != OK) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
109 if (fwrite (& this_curve -> title_color, sizeof(ColRGBA), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
110 // Axis
111 if (fwrite (this_curve -> axmin, sizeof(double), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
112 if (fwrite (this_curve -> axmax, sizeof(double), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
113 for (j=0; j<2; j++)
114 {
115 if (save_this_string (fp, this_curve -> axis_title[j]) != OK) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
116 if (save_this_string (fp, this_curve -> axis_title_font[j]) != OK) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
117 }
118 if (fwrite (this_curve -> axis_title_x, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
119 if (fwrite (this_curve -> axis_title_y, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
120 if (fwrite (this_curve -> scale, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
121 if (fwrite (this_curve -> axis_defaut_title, sizeof(gboolean), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
122 if (fwrite (this_curve -> autoscale, sizeof(gboolean), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
123 if (fwrite (this_curve -> majt, sizeof(double), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
124 if (fwrite (this_curve -> mint, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
125 if (fwrite (this_curve -> ticks_io, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
126 if (fwrite (this_curve -> ticks_pos, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
127 if (fwrite (this_curve -> majt_size, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
128 if (fwrite (this_curve -> mint_size, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
129 if (fwrite (this_curve -> labels_pos, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
130 if (fwrite (this_curve -> labels_digit, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
131 for (j=0; j<2; j++)
132 {
133 if (save_this_string (fp, this_curve -> labels_font[j]) != OK) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
134 }
135 if (fwrite (this_curve -> labels_angle, sizeof(double), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
136 if (fwrite (this_curve -> labels_shift_x, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
137 if (fwrite (this_curve -> labels_shift_y, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
138 if (fwrite (this_curve -> show_grid, sizeof(gboolean), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
139 if (fwrite (this_curve -> show_axis, sizeof(gboolean), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
140 // Legend
141 if (fwrite (& this_curve -> show_legend, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
142 if (save_this_string (fp, this_curve -> legend_font) != OK) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
143 if (fwrite (this_curve -> legend_pos, sizeof(double), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
144 if (fwrite (& this_curve -> legend_color, sizeof(ColRGBA), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
145 if (fwrite (& this_curve -> show_legend_box, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
146 if (fwrite (& this_curve -> legend_box_dash, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
147 if (fwrite (& this_curve -> legend_box_thickness, sizeof(double), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
148 if (fwrite (& this_curve -> legend_box_color, sizeof(ColRGBA), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
149 // Frame
150 if (fwrite (& this_curve -> show_frame, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
151 if (fwrite (& this_curve -> frame_type, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
152 if (fwrite (& this_curve -> frame_dash, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
153 if (fwrite (& this_curve -> frame_thickness, sizeof(double), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
154 if (fwrite (& this_curve -> frame_color, sizeof(ColRGBA), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
155 if (fwrite (this_curve -> frame_pos, sizeof(this_curve -> frame_pos), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
156 // Data
157 if (fwrite (& this_curve -> backcolor, sizeof(ColRGBA), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
158 if (write_data_layout (fp, this_curve -> layout) != OK )
159 {
160 update_error_trace (__FILE__, __func__, __LINE__-2);
161 return ERROR_CURVE;
162 }
163 if (fwrite (& this_curve -> draw_id, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
164 if (fwrite (& this_curve -> bshift, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
165 i = 0;
166 CurveExtra * ctmp;
167 if (this_curve -> extrac -> extras > 0)
168 {
169 ctmp = this_curve -> extrac -> first;
170 for (j=0; j<this_curve -> extrac -> extras; j++)
171 {
172 if (ctmp -> id.a == this_proj -> id || wid)
173 {
174 i ++;
175 }
176 if (ctmp -> next != NULL) ctmp = ctmp -> next;
177 }
178 }
179 if (fwrite (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
180 if (i > 0)
181 {
182 ctmp = this_curve -> extrac -> first;
183 for (j=0; j<this_curve -> extrac -> extras; j++)
184 {
185 if (ctmp -> id.a == this_proj -> id || wid)
186 {
187 k = (wid) ? ctmp -> id.a : 0;
188 if (fwrite (& k, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
189 if (fwrite (& ctmp -> id.b, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
190 if (fwrite (& ctmp -> id.c, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
191 if (write_data_layout (fp, ctmp -> layout) != OK) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
192 }
193 if (ctmp -> next != NULL) ctmp = ctmp -> next;
194 }
195 }
196 if (save_this_string (fp, this_curve -> cfile) != OK) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
197 }
198#ifdef DEBUG
199// debugiocurve (this_proj, win, rid, cid, "WRITE");
200#endif
201 return OK;
202}
double scale(double axe)
find appropriate major tick spacing based on axis length
Definition curve.c:205
PangoLayout * layout
Definition curve.c:80
void show_frame(cairo_t *cd, int tf, int da, int res[2], double ti, double x[2], double y[2], ColRGBA dcol)
draw frame
Definition frame.c:81
GtkWidget * majt
void show_title(cairo_t *cr, Curve *this_curve)
draw title
Definition title.c:104
void show_legend(cairo_t *cr, project *this_proj, int rid, int cid)
draw legend
Definition legend.c:56
const gchar * default_title(int ax, gpointer data)
default title string
Definition title.c:54
FILE * fp
Global variable declarations Global convenience function declarations Global data structure defin...
int signal_error(const char *file, const char *func, int error_line, int error_id)
Definition callbacks.c:182
#define ERROR_CURVE
Definition global.h:298
#define OK
Definition global.h:295
void update_error_trace(const char *file, const char *func, int trace_line)
Definition callbacks.c:200
void autoscale(gpointer data)
autoscale callback
Definition m_curve.c:99
Function declarations for reading atomes project file Function declarations for saving atomes proje...
int save_this_string(FILE *fp, gchar *string)
save string to file
Definition save_p.c:50
int save_project_curve(FILE *fp, project *this_proj, int wid, int rid, int cid)
save project curve to file
Definition save_curve.c:75
int write_data_layout(FILE *fp, DataLayout *layout)
save curve data layout to file
Definition save_curve.c:49