atomes 1.1.16
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-2024 by CNRS and University of Strasbourg */
15
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_project_curve (FILE * fp, int wid, int pid);
34
35 gboolean read_data_layout (FILE * fp, DataLayout * layout);
36
37*/
38
39#include "global.h"
40#include "project.h"
41
51{
52 if (fread (& layout -> datacolor, sizeof(ColRGBA), 1, fp) != 1) return FALSE;
53 if (fread (& layout -> thickness, sizeof(double), 1, fp) != 1) return FALSE;
54 if (fread (& layout -> dash, sizeof(int), 1, fp) != 1) return FALSE;
55 if (fread (& layout -> glyph, sizeof(int), 1, fp) != 1) return FALSE;
56 if (fread (& layout -> gsize, sizeof(double), 1, fp) != 1) return FALSE;
57 if (fread (& layout -> gfreq, sizeof(int), 1, fp) != 1) return FALSE;
58 if (fread (& layout -> hwidth, sizeof(double), 1, fp) != 1) return FALSE;
59 if (fread (& layout -> hopac, sizeof(double), 1, fp) != 1) return FALSE;
60 if (fread (& layout -> hpos, sizeof(int), 1, fp) != 1) return FALSE;
61 if (fread (& layout -> aspect, sizeof(int), 1, fp) != 1) return FALSE;
62 return TRUE;
63}
64
74int read_project_curve (FILE * fp, int wid, int pid)
75{
76 int i, j;
77 int pic, rid, cid;
78 if (wid > 0)
79 {
80 if (fread (& pic, sizeof(int), 1, fp) != 1) return ERROR_RW;
81 }
82 else
83 {
84 pic = pid;
85 }
86 project * this_proj = get_project_by_id (pic);
87 if (fread (& rid, sizeof(int), 1, fp) != 1) return ERROR_RW;
88 if (fread (& cid, sizeof(int), 1, fp) != 1) return ERROR_RW;
89 if (fread (& this_proj -> curves[rid][cid] -> displayed, sizeof(gboolean), 1, fp) != 1) return ERROR_RW;
90 if (fread (& this_proj -> curves[rid][cid] -> ndata, sizeof(int), 1, fp) != 1) return ERROR_RW;
91 this_proj -> curves[rid][cid] -> data[0] = allocdouble (this_proj -> curves[rid][cid] -> ndata);
92 if (fread (this_proj -> curves[rid][cid] -> data[0], sizeof(double), this_proj -> curves[rid][cid] -> ndata, fp) != this_proj -> curves[rid][cid] -> ndata) return ERROR_RW;
93 this_proj -> curves[rid][cid] -> data[1] = allocdouble (this_proj -> curves[rid][cid] -> ndata);
94 if (fread (this_proj -> curves[rid][cid] -> data[1], sizeof(double), this_proj -> curves[rid][cid] -> ndata, fp) != this_proj -> curves[rid][cid] -> ndata) return ERROR_RW;
95 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
96 if (i)
97 {
98 this_proj -> curves[rid][cid] -> err = allocdouble (this_proj -> curves[rid][cid] -> ndata);
99 if (fread (this_proj -> curves[rid][cid] -> err, sizeof(double), this_proj -> curves[rid][cid] -> ndata, fp) != this_proj -> curves[rid][cid] -> ndata) return ERROR_RW;
100 }
101
102 if (this_proj -> curves[rid][cid] -> displayed)
103 {
104 if (fread (this_proj -> curves[rid][cid] -> wsize, sizeof(int), 2, fp) != 2) return ERROR_RW;
105 if (fread (this_proj -> curves[rid][cid] -> cmin, sizeof(double), 2, fp) != 2) return ERROR_RW;
106 if (fread (this_proj -> curves[rid][cid] -> cmax, sizeof(double), 2, fp) != 2) return ERROR_RW;
107 // Title
108 if (fread (& this_proj -> curves[rid][cid] -> show_title, sizeof(gboolean), 1, fp) != 1) return ERROR_RW;
109 if (fread (& this_proj -> curves[rid][cid] -> default_title, sizeof(gboolean), 1, fp) != 1) return ERROR_RW;
110 if (! this_proj -> curves[rid][cid] -> default_title)
111 {
112 this_proj -> curves[rid][cid] -> title = read_this_string (fp);
113 if (this_proj -> curves[rid][cid] -> title == NULL) return ERROR_RW;
114 }
115 if (fread (this_proj -> curves[rid][cid] -> title_pos, sizeof(double), 2, fp) != 2) return ERROR_RW;
116 this_proj -> curves[rid][cid] -> title_font = read_this_string (fp);
117 if (this_proj -> curves[rid][cid] -> title_font == NULL) return ERROR_RW;
118 if (fread (& this_proj -> curves[rid][cid] -> title_color, sizeof(ColRGBA), 1, fp) != 1) return ERROR_RW;
119 // Axis
120 if (fread (this_proj -> curves[rid][cid] -> axmin, sizeof(double), 2, fp) != 2) return ERROR_RW;
121 if (fread (this_proj -> curves[rid][cid] -> axmax, sizeof(double), 2, fp) != 2) return ERROR_RW;
122 for (j=0; j<2; j++)
123 {
124 this_proj -> curves[rid][cid] -> axis_title[j] = read_this_string (fp);
125 if (this_proj -> curves[rid][cid] -> axis_title[j] == NULL) return ERROR_RW;
126 this_proj -> curves[rid][cid] -> axis_title_font[j] = read_this_string (fp);
127 if (this_proj -> curves[rid][cid] -> axis_title_font[j] == NULL) return ERROR_RW;
128 }
129 if (fread (this_proj -> curves[rid][cid] -> axis_title_x, sizeof(int), 2, fp) != 2) return ERROR_RW;
130 if (fread (this_proj -> curves[rid][cid] -> axis_title_y, sizeof(int), 2, fp) != 2) return ERROR_RW;
131 if (fread (this_proj -> curves[rid][cid] -> scale, sizeof(int), 2, fp) != 2) return ERROR_RW;
132 if (fread (this_proj -> curves[rid][cid] -> axis_defaut_title, sizeof(gboolean), 2, fp) != 2) return ERROR_RW;
133 if (fread (this_proj -> curves[rid][cid] -> autoscale, sizeof(gboolean), 2, fp) != 2) return ERROR_RW;
134 if (fread (this_proj -> curves[rid][cid] -> majt, sizeof(double), 2, fp) != 2) return ERROR_RW;
135 if (fread (this_proj -> curves[rid][cid] -> mint, sizeof(int), 2, fp) != 2) return ERROR_RW;
136 if (fread (this_proj -> curves[rid][cid] -> ticks_io, sizeof(int), 2, fp) != 2) return ERROR_RW;
137 if (fread (this_proj -> curves[rid][cid] -> ticks_pos, sizeof(int), 2, fp) != 2) return ERROR_RW;
138 if (fread (this_proj -> curves[rid][cid] -> majt_size, sizeof(int), 2, fp) != 2) return ERROR_RW;
139 if (fread (this_proj -> curves[rid][cid] -> mint_size, sizeof(int), 2, fp) != 2) return ERROR_RW;
140 if (fread (this_proj -> curves[rid][cid] -> labels_pos, sizeof(int), 2, fp) != 2) return ERROR_RW;
141 if (fread (this_proj -> curves[rid][cid] -> labels_digit, sizeof(int), 2, fp) != 2) return ERROR_RW;
142 for (j=0; j<2; j++)
143 {
144 this_proj -> curves[rid][cid] -> labels_font[j] = read_this_string (fp);
145 if (this_proj -> curves[rid][cid] -> labels_font[j] == NULL) return ERROR_RW;
146 }
147 if (fread (this_proj -> curves[rid][cid] -> labels_angle, sizeof(double), 2, fp) != 2) return ERROR_RW;
148 if (fread (this_proj -> curves[rid][cid] -> labels_shift_x, sizeof(int), 2, fp) != 2) return ERROR_RW;
149 if (fread (this_proj -> curves[rid][cid] -> labels_shift_y, sizeof(int), 2, fp) != 2) return ERROR_RW;
150 if (fread (this_proj -> curves[rid][cid] -> show_grid, sizeof(gboolean), 2, fp) != 2) return ERROR_RW;
151 if (fread (this_proj -> curves[rid][cid] -> show_axis, sizeof(gboolean), 2, fp) != 2) return ERROR_RW;
152
153 // Legend
154 if (fread (& this_proj -> curves[rid][cid] -> show_legend, sizeof(gboolean), 1, fp) != 1) return ERROR_RW;
155 this_proj -> curves[rid][cid] -> legend_font = read_this_string (fp);
156 if (this_proj -> curves[rid][cid] -> legend_font == NULL) return ERROR_RW;
157 if (fread (this_proj -> curves[rid][cid] -> legend_pos, sizeof(double), 2, fp) != 2) return ERROR_RW;
158 if (fread (& this_proj -> curves[rid][cid] -> legend_color, sizeof(ColRGBA), 1, fp) != 1) return ERROR_RW;
159 if (fread (& this_proj -> curves[rid][cid] -> show_legend_box, sizeof(gboolean), 1, fp) != 1) return ERROR_RW;
160 if (fread (& this_proj -> curves[rid][cid] -> legend_box_dash, sizeof(int), 1, fp) != 1) return ERROR_RW;
161 if (fread (& this_proj -> curves[rid][cid] -> legend_box_thickness, sizeof(double), 1, fp) != 1) return ERROR_RW;
162 if (fread (& this_proj -> curves[rid][cid] -> legend_box_color, sizeof(ColRGBA), 1, fp) != 1) return ERROR_RW;
163 // Frame
164 if (fread (& this_proj -> curves[rid][cid] -> show_frame, sizeof(gboolean), 1, fp) != 1) return ERROR_RW;
165 if (fread (& this_proj -> curves[rid][cid] -> frame_type, sizeof(int), 1, fp) != 1) return ERROR_RW;
166 if (fread (& this_proj -> curves[rid][cid] -> frame_dash, sizeof(int), 1, fp) != 1) return ERROR_RW;
167 if (fread (& this_proj -> curves[rid][cid] -> frame_thickness, sizeof(double), 1, fp) != 1) return ERROR_RW;
168 if (fread (& this_proj -> curves[rid][cid] -> frame_color, sizeof(ColRGBA), 1, fp) != 1) return ERROR_RW;
169 if (fread (this_proj -> curves[rid][cid] -> frame_pos, sizeof(this_proj -> curves[rid][cid] -> frame_pos), 1, fp) != 1) return ERROR_RW;
170 if (fread (& this_proj -> curves[rid][cid] -> backcolor, sizeof(ColRGBA), 1, fp) != 1) return ERROR_RW;
171 // Data
172 this_proj -> curves[rid][cid] -> layout = g_malloc0 (sizeof*this_proj -> curves[rid][cid] -> layout);
173 if (! read_data_layout (fp, this_proj -> curves[rid][cid] -> layout)) return ERROR_RW;
174 if (fread (& this_proj -> curves[rid][cid] -> draw_id, sizeof(int), 1, fp) != 1) return ERROR_RW;
175 if (fread (& this_proj -> curves[rid][cid] -> bshift, sizeof(int), 1, fp) != 1) return ERROR_RW;
176
177 this_proj -> curves[rid][cid] -> extrac = g_malloc0 (sizeof*this_proj -> curves[rid][cid] -> extrac);
178 if (fread (& this_proj -> curves[rid][cid] -> extrac -> extras, sizeof(int), 1, fp) != 1) return ERROR_RW;
179 if (this_proj -> curves[rid][cid] -> extrac -> extras > 0)
180 {
181 this_proj -> curves[rid][cid] -> extrac -> first = g_malloc0 (sizeof*this_proj -> curves[rid][cid] -> extrac -> first);
182 this_proj -> curves[rid][cid] -> extrac -> last = g_malloc0 (sizeof*this_proj -> curves[rid][cid] -> extrac -> last);
183 CurveExtra * ctmp = this_proj -> curves[rid][cid] -> extrac -> first;
184 for (i=0; i<this_proj -> curves[rid][cid] -> extrac -> extras; i++)
185 {
186 if (fread (& ctmp -> id.a, sizeof(int), 1, fp) != 1) return ERROR_RW;
187 if (fread (& ctmp -> id.b, sizeof(int), 1, fp) != 1) return ERROR_RW;
188 if (fread (& ctmp -> id.c, sizeof(int), 1, fp) != 1) return ERROR_RW;
189 ctmp -> layout = g_malloc0 (sizeof*ctmp -> layout);
190 if (! read_data_layout (fp, ctmp -> layout)) return ERROR_RW;
191 if (i < this_proj -> curves[rid][cid] -> extrac -> extras - 1)
192 {
193 ctmp -> next = g_malloc0 (sizeof*ctmp -> next);
194 ctmp -> next -> prev = ctmp;
195 ctmp = ctmp -> next;
196 }
197 else if (i == this_proj -> curves[rid][cid] -> extrac -> extras - 1)
198 {
199 this_proj -> curves[rid][cid] -> extrac -> last = ctmp;
200 }
201 }
202 }
203 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
204 if (i == 1)
205 {
206 this_proj -> curves[rid][cid] -> cfile = read_this_string (fp);
207 if (this_proj -> curves[rid][cid] -> cfile == NULL) return ERROR_RW;
208 }
209 }
210#ifdef DEBUG
211 // debugiocurve (this_proj, win, rid, cid, "READ");
212#endif
213 return OK;
214}
double scale(double axe)
find appropriate major tick spacing based on axis length
Definition curve.c:204
PangoLayout * layout
Definition curve.c:79
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
Definition tab-4.c:103
const gchar * default_title(int ax, int c)
default title string
Definition title.c:54
void show_legend(cairo_t *cr, project *this_proj, int rid, int cid)
draw legend
Definition legend.c:56
void show_title(cairo_t *cr, project *this_proj, int rid, int cid)
draw title
Definition title.c:107
FILE * fp
double * allocdouble(int val)
allocate a double * pointer
Definition global.c:459
Global variable declarations Global convenience function declarations Global data structure defin...
#define ERROR_RW
Definition global.h:280
#define OK
Definition global.h:279
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:100
gchar * read_this_string(FILE *fp)
is there a string to read in this file ? yes do it
Definition open_p.c:95
Function declarations for reading atomes project file Function declarations for saving atomes proje...
gboolean read_data_layout(FILE *fp, DataLayout *layout)
read data layout from file
Definition read_curve.c:50
int read_project_curve(FILE *fp, int wid, int pid)
read a project curve from file
Definition read_curve.c:74
int b
Definition tab-1.c:95
int c
Definition tab-1.c:95
int a
Definition tab-1.c:95
GtkWidget * axis_title_font
Definition tab-4.c:102
GtkWidget * show_grid
Definition tab-4.c:98
GtkWidget * axis_title
Definition tab-4.c:101
GtkWidget * show_axis
Definition tab-4.c:97