atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
read_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: 'read_curve.c'
24*
25* Contains:
26*
27
28 - The functions to read curve data in the atomes project file format
29
30*
31* List of functions:
32
33 int read_data_layout (FILE * fp, DataLayout * layout);
34 int read_project_curve (FILE * fp, int wid, int pid);
35
36*/
37
38#include "global.h"
39#include "project.h"
40
41extern gboolean version_2_9_and_above;
42// Project reading flag, required for project files < v2.9
43gboolean reading_project = FALSE;
44
54{
55 if (fread (& layout -> datacolor, sizeof(ColRGBA), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
56 if (fread (& layout -> thickness, sizeof(double), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
57 if (fread (& layout -> dash, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
58 if (fread (& layout -> glyph, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
59 if (fread (& layout -> gsize, sizeof(double), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
60 if (fread (& layout -> gfreq, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
61 if (fread (& layout -> hwidth, sizeof(double), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
62 if (fread (& layout -> hopac, sizeof(double), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
63 if (fread (& layout -> hpos, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
64 if (fread (& layout -> aspect, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
65 return OK;
66}
67
77int read_project_curve (FILE * fp, int wid, int pid)
78{
79 int i, j;
80 int rid, cid;
82 {
83 if (fread (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
84 }
85 project * this_proj = get_project_by_id (pid);
86 if (fread (& rid, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
87 if (fread (& cid, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
88 Curve * this_curve = this_proj -> analysis[rid] -> curves[cid];
90 {
91 // curve name can be NULL, so do not test for emptyness
92 this_curve -> name = read_this_string (fp);
93 }
94 if (fread (& this_curve -> displayed, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
95 if (fread (& this_curve -> ndata, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
96 this_curve -> data[0] = allocdouble (this_curve -> ndata);
97 if (fread (this_curve -> data[0], sizeof(double), this_curve -> ndata, fp) != this_curve -> ndata) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
98 this_curve -> data[1] = allocdouble (this_curve -> ndata);
99 if (fread (this_curve -> data[1], sizeof(double), this_curve -> ndata, fp) != this_curve -> ndata) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
100 if (fread (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
101 if (i)
102 {
103 this_curve -> err = allocdouble (this_curve -> ndata);
104 if (fread (this_curve -> err, sizeof(double), this_curve -> ndata, fp) != this_curve -> ndata) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
105 }
106 if (this_curve -> displayed)
107 {
108 if (fread (this_curve -> wsize, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
109 if (fread (this_curve -> cmin, sizeof(double), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
110 if (fread (this_curve -> cmax, sizeof(double), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
111 // Title
112 if (fread (& this_curve -> show_title, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
113 if (fread (& this_curve -> default_title, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
114 if (! this_curve -> default_title)
115 {
116 this_curve -> title = read_this_string (fp);
117 if (this_curve -> title == NULL) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
118 }
119 if (fread (this_curve -> title_pos, sizeof(double), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
120 this_curve -> title_font = read_this_string (fp);
121 if (this_curve -> title_font == NULL) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
122 if (fread (& this_curve -> title_color, sizeof(ColRGBA), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
123 // Axis
124 if (fread (this_curve -> axmin, sizeof(double), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
125 if (fread (this_curve -> axmax, sizeof(double), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
126 for (j=0; j<2; j++)
127 {
128 this_curve -> axis_title[j] = read_this_string (fp);
129 if (this_curve -> axis_title[j] == NULL) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
130 this_curve -> axis_title_font[j] = read_this_string (fp);
131 if (this_curve -> axis_title_font[j] == NULL) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
132 }
133 if (fread (this_curve -> axis_title_x, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
134 if (fread (this_curve -> axis_title_y, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
135 if (fread (this_curve -> scale, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
136 if (fread (this_curve -> axis_defaut_title, sizeof(gboolean), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
137 if (fread (this_curve -> autoscale, sizeof(gboolean), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
138 if (fread (this_curve -> majt, sizeof(double), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
139 if (fread (this_curve -> mint, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
140 if (fread (this_curve -> ticks_io, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
141 if (fread (this_curve -> ticks_pos, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
142 if (fread (this_curve -> majt_size, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
143 if (fread (this_curve -> mint_size, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
144 if (fread (this_curve -> labels_pos, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
145 if (fread (this_curve -> labels_digit, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
146 for (j=0; j<2; j++)
147 {
148 this_curve -> labels_font[j] = read_this_string (fp);
149 if (this_curve -> labels_font[j] == NULL) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
150 }
151 if (fread (this_curve -> labels_angle, sizeof(double), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
152 if (fread (this_curve -> labels_shift_x, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
153 if (fread (this_curve -> labels_shift_y, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
154 if (fread (this_curve -> show_grid, sizeof(gboolean), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
155 if (fread (this_curve -> show_axis, sizeof(gboolean), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
156
157 // Legend
158 if (fread (& this_curve -> show_legend, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
159 this_curve -> legend_font = read_this_string (fp);
160 if (this_curve -> legend_font == NULL) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
161 if (fread (this_curve -> legend_pos, sizeof(double), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
162 if (fread (& this_curve -> legend_color, sizeof(ColRGBA), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
163 if (fread (& this_curve -> show_legend_box, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
164 if (fread (& this_curve -> legend_box_dash, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
165 if (fread (& this_curve -> legend_box_thickness, sizeof(double), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
166 if (fread (& this_curve -> legend_box_color, sizeof(ColRGBA), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
167 // Frame
168 if (fread (& this_curve -> show_frame, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
169 if (fread (& this_curve -> frame_type, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
170 if (fread (& this_curve -> frame_dash, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
171 if (fread (& this_curve -> frame_thickness, sizeof(double), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
172 if (fread (& this_curve -> frame_color, sizeof(ColRGBA), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
173 if (fread (this_curve -> frame_pos, sizeof(this_curve -> frame_pos), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
174 if (fread (& this_curve -> backcolor, sizeof(ColRGBA), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
175 // Data
176 this_curve -> layout = g_malloc0(sizeof*this_curve -> layout);
177 if (read_data_layout (fp, this_curve -> layout) != OK)
178 {
179 update_error_trace (__FILE__, __func__, __LINE__-2);
180 return ERROR_CURVE;
181 }
182 if (fread (& this_curve -> draw_id, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
183 if (fread (& this_curve -> bshift, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
184
185 this_curve -> extrac = g_malloc0(sizeof*this_curve -> extrac);
186 if (fread (& this_curve -> extrac -> extras, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
187 if (this_curve -> extrac -> extras > 0)
188 {
189 this_curve -> extrac -> first = g_malloc0(sizeof*this_curve -> extrac -> first);
190 this_curve -> extrac -> last = g_malloc0(sizeof*this_curve -> extrac -> last);
191 CurveExtra * ctmp = this_curve -> extrac -> first;
192 for (i=0; i<this_curve -> extrac -> extras; i++)
193 {
194 if (fread (& ctmp -> id.a, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
195 if (! wid) ctmp -> id.a += (nprojects - 1);
196 if (fread (& ctmp -> id.b, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
197 if (fread (& ctmp -> id.c, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_CURVE);
198 ctmp -> layout = g_malloc0(sizeof*ctmp -> layout);
199 if (read_data_layout (fp, ctmp -> layout) != OK)
200 {
201 update_error_trace (__FILE__, __func__, __LINE__-2);
202 return ERROR_CURVE;
203 }
204 if (i < this_curve -> extrac -> extras - 1)
205 {
206 ctmp -> next = g_malloc0(sizeof*ctmp -> next);
207 ctmp -> next -> prev = ctmp;
208 ctmp = ctmp -> next;
209 }
210 else if (i == this_curve -> extrac -> extras - 1)
211 {
212 this_curve -> extrac -> last = ctmp;
213 }
214 }
215 }
216 this_curve -> cfile = read_this_string (fp);
217 }
218
219#ifdef DEBUG
220 // debugiocurve (this_proj, FALSE, rid, cid, "READ");
221#endif
222 return OK;
223}
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
int nprojects
Definition global.c:161
double * allocdouble(int val)
allocate a double * pointer
Definition global.c:446
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
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
void autoscale(gpointer data)
autoscale callback
Definition m_curve.c:99
gchar * read_this_string(FILE *fp)
is there a string to read in this file ? yes do it
Definition open_p.c:109
gboolean version_2_9_and_above
Definition open_p.c:79
Function declarations for reading atomes project file Function declarations for saving atomes proje...
gboolean reading_project
Definition read_curve.c:43
int read_project_curve(FILE *fp, int wid, int pid)
read a project curve from file
Definition read_curve.c:77
int read_data_layout(FILE *fp, DataLayout *layout)
read data layout from file
Definition read_curve.c:53