atomes 1.1.14
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-2024 by CNRS and University of Strasbourg */
15
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 save_project_curve (FILE * fp, int wid, project * this_proj, int rid, int cid);
34
35 gboolean write_data_layout (FILE * fp, DataLayout * layout);
36
37*/
38
39#include "global.h"
40#include "project.h"
41
51{
52 if (fwrite (& layout -> datacolor, sizeof(ColRGBA), 1, fp) != 1) return FALSE;
53 if (fwrite (& layout -> thickness, sizeof(double), 1, fp) != 1) return FALSE;
54 if (fwrite (& layout -> dash, sizeof(int), 1, fp) != 1) return FALSE;
55 if (fwrite (& layout -> glyph, sizeof(int), 1, fp) != 1) return FALSE;
56 if (fwrite (& layout -> gsize, sizeof(double), 1, fp) != 1) return FALSE;
57 if (fwrite (& layout -> gfreq, sizeof(int), 1, fp) != 1) return FALSE;
58 if (fwrite (& layout -> hwidth, sizeof(double), 1, fp) != 1) return FALSE;
59 if (fwrite (& layout -> hopac, sizeof(double), 1, fp) != 1) return FALSE;
60 if (fwrite (& layout -> hpos, sizeof(int), 1, fp) != 1) return FALSE;
61 if (fwrite (& layout -> aspect, sizeof(int), 1, fp) != 1) return FALSE;
62 return TRUE;
63}
64
76int save_project_curve (FILE * fp, int wid, project * this_proj, int rid, int cid)
77{
78 int i, j;
79 if (wid > 0)
80 {
81 if (fwrite (& this_proj -> id, sizeof(int), 1, fp) != 1) return ERROR_RW;
82 }
83 if (fwrite (& rid, sizeof(int), 1, fp) != 1) return ERROR_RW;
84 if (fwrite (& cid, sizeof(int), 1, fp) != 1) return ERROR_RW;
85 if (fwrite (& this_proj -> curves[rid][cid] -> displayed, sizeof(gboolean), 1, fp) != 1) return ERROR_RW;
86 if (fwrite (& this_proj -> curves[rid][cid] -> ndata, sizeof(int), 1, fp) != 1) return ERROR_RW;
87 if (fwrite (this_proj -> curves[rid][cid] -> data[0],
88 sizeof(double), this_proj -> curves[rid][cid] -> ndata, fp) != this_proj -> curves[rid][cid] -> ndata) return ERROR_RW;
89 if (fwrite (this_proj -> curves[rid][cid] -> data[1],
90 sizeof(double), this_proj -> curves[rid][cid] -> ndata, fp) != this_proj -> curves[rid][cid] -> ndata) return ERROR_RW;
91 i = 0;
92 if (this_proj -> curves[rid][cid] -> err != NULL) i = 1;
93 if (fwrite (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
94 if (this_proj -> curves[rid][cid] -> err != NULL)
95 {
96 if (fwrite (this_proj -> curves[rid][cid] -> err,
97 sizeof(double), this_proj -> curves[rid][cid] -> ndata, fp) != this_proj -> curves[rid][cid] -> ndata) return ERROR_RW;
98 }
99
100 if (this_proj -> curves[rid][cid] -> displayed)
101 {
102 if (fwrite (this_proj -> curves[rid][cid] -> wsize, sizeof(int), 2, fp) != 2) return ERROR_RW;
103 if (fwrite (this_proj -> curves[rid][cid] -> cmin, sizeof(double), 2, fp) != 2) return ERROR_RW;
104 if (fwrite (this_proj -> curves[rid][cid] -> cmax, sizeof(double), 2, fp) != 2) return ERROR_RW;
105 // Title
106 if (fwrite (& this_proj -> curves[rid][cid] -> show_title, sizeof(gboolean), 1, fp) != 1) return ERROR_RW;
107 if (fwrite (& this_proj -> curves[rid][cid] -> default_title, sizeof(gboolean), 1, fp) != 1) return ERROR_RW;
108 if (! this_proj -> curves[rid][cid] -> default_title)
109 {
110 if (save_this_string (fp, this_proj -> curves[rid][cid] -> title) != OK) return ERROR_RW;
111 }
112 if (fwrite (this_proj -> curves[rid][cid] -> title_pos, sizeof(double), 2, fp) != 2) return ERROR_RW;
113 if (save_this_string (fp, this_proj -> curves[rid][cid] -> title_font) != OK) return ERROR_RW;
114 if (fwrite (& this_proj -> curves[rid][cid] -> title_color, sizeof(ColRGBA), 1, fp) != 1) return ERROR_RW;
115 // Axis
116 if (fwrite (this_proj -> curves[rid][cid] -> axmin, sizeof(double), 2, fp) != 2) return ERROR_RW;
117 if (fwrite (this_proj -> curves[rid][cid] -> axmax, sizeof(double), 2, fp) != 2) return ERROR_RW;
118 for (j=0; j<2; j++)
119 {
120 if (save_this_string (fp, this_proj -> curves[rid][cid] -> axis_title[j]) != OK) return ERROR_RW;
121 if (save_this_string (fp, this_proj -> curves[rid][cid] -> axis_title_font[j]) != OK) return ERROR_RW;
122 }
123 if (fwrite (this_proj -> curves[rid][cid] -> axis_title_x, sizeof(int), 2, fp) != 2) return ERROR_RW;
124 if (fwrite (this_proj -> curves[rid][cid] -> axis_title_y, sizeof(int), 2, fp) != 2) return ERROR_RW;
125 if (fwrite (this_proj -> curves[rid][cid] -> scale, sizeof(int), 2, fp) != 2) return ERROR_RW;
126 if (fwrite (this_proj -> curves[rid][cid] -> axis_defaut_title, sizeof(gboolean), 2, fp) != 2) return ERROR_RW;
127 if (fwrite (this_proj -> curves[rid][cid] -> autoscale, sizeof(gboolean), 2, fp) != 2) return ERROR_RW;
128 if (fwrite (this_proj -> curves[rid][cid] -> majt, sizeof(double), 2, fp) != 2) return ERROR_RW;
129 if (fwrite (this_proj -> curves[rid][cid] -> mint, sizeof(int), 2, fp) != 2) return ERROR_RW;
130 if (fwrite (this_proj -> curves[rid][cid] -> ticks_io, sizeof(int), 2, fp) != 2) return ERROR_RW;
131 if (fwrite (this_proj -> curves[rid][cid] -> ticks_pos, sizeof(int), 2, fp) != 2) return ERROR_RW;
132 if (fwrite (this_proj -> curves[rid][cid] -> majt_size, sizeof(int), 2, fp) != 2) return ERROR_RW;
133 if (fwrite (this_proj -> curves[rid][cid] -> mint_size, sizeof(int), 2, fp) != 2) return ERROR_RW;
134 if (fwrite (this_proj -> curves[rid][cid] -> labels_pos, sizeof(int), 2, fp) != 2) return ERROR_RW;
135 if (fwrite (this_proj -> curves[rid][cid] -> labels_digit, sizeof(int), 2, fp) != 2) return ERROR_RW;
136 for (j=0; j<2; j++)
137 {
138 if (save_this_string (fp, this_proj -> curves[rid][cid] -> labels_font[j]) != OK) return ERROR_RW;
139 }
140 if (fwrite (this_proj -> curves[rid][cid] -> labels_angle, sizeof(double), 2, fp) != 2) return ERROR_RW;
141 if (fwrite (this_proj -> curves[rid][cid] -> labels_shift_x, sizeof(int), 2, fp) != 2) return ERROR_RW;
142 if (fwrite (this_proj -> curves[rid][cid] -> labels_shift_y, sizeof(int), 2, fp) != 2) return ERROR_RW;
143 if (fwrite (this_proj -> curves[rid][cid] -> show_grid, sizeof(gboolean), 2, fp) != 2) return ERROR_RW;
144 if (fwrite (this_proj -> curves[rid][cid] -> show_axis, sizeof(gboolean), 2, fp) != 2) return ERROR_RW;
145 // Legend
146 if (fwrite (& this_proj -> curves[rid][cid] -> show_legend, sizeof(gboolean), 1, fp) != 1) return ERROR_RW;
147 if (save_this_string (fp, this_proj -> curves[rid][cid] -> legend_font) != OK) return ERROR_RW;
148 if (fwrite (this_proj -> curves[rid][cid] -> legend_pos, sizeof(double), 2, fp) != 2) return ERROR_RW;
149 if (fwrite (& this_proj -> curves[rid][cid] -> legend_color, sizeof(ColRGBA), 1, fp) != 1) return ERROR_RW;
150 if (fwrite (& this_proj -> curves[rid][cid] -> show_legend_box, sizeof(gboolean), 1, fp) != 1) return ERROR_RW;
151 if (fwrite (& this_proj -> curves[rid][cid] -> legend_box_dash, sizeof(int), 1, fp) != 1) return ERROR_RW;
152 if (fwrite (& this_proj -> curves[rid][cid] -> legend_box_thickness, sizeof(double), 1, fp) != 1) return ERROR_RW;
153 if (fwrite (& this_proj -> curves[rid][cid] -> legend_box_color, sizeof(ColRGBA), 1, fp) != 1) return ERROR_RW;
154 // Frame
155 if (fwrite (& this_proj -> curves[rid][cid] -> show_frame, sizeof(gboolean), 1, fp) != 1) return ERROR_RW;
156 if (fwrite (& this_proj -> curves[rid][cid] -> frame_type, sizeof(int), 1, fp) != 1) return ERROR_RW;
157 if (fwrite (& this_proj -> curves[rid][cid] -> frame_dash, sizeof(int), 1, fp) != 1) return ERROR_RW;
158 if (fwrite (& this_proj -> curves[rid][cid] -> frame_thickness, sizeof(double), 1, fp) != 1) return ERROR_RW;
159 if (fwrite (& this_proj -> curves[rid][cid] -> frame_color, sizeof(ColRGBA), 1, fp) != 1) return ERROR_RW;
160 if (fwrite (this_proj -> curves[rid][cid] -> frame_pos, sizeof(this_proj -> curves[rid][cid] -> frame_pos), 1, fp) != 1) return ERROR_RW;
161 // Data
162 if (fwrite (& this_proj -> curves[rid][cid] -> backcolor, sizeof(ColRGBA), 1, fp) != 1) return ERROR_RW;
163 if (! write_data_layout (fp, this_proj -> curves[rid][cid] -> layout)) return ERROR_RW;
164 if (fwrite (& this_proj -> curves[rid][cid] -> draw_id, sizeof(int), 1, fp) != 1) return ERROR_RW;
165 if (fwrite (& this_proj -> curves[rid][cid] -> bshift, sizeof(int), 1, fp) != 1) return ERROR_RW;
166 if (fwrite (& this_proj -> curves[rid][cid] -> extrac -> extras, sizeof(int), 1, fp) != 1) return ERROR_RW;
167 if (this_proj -> curves[rid][cid] -> extrac -> extras > 0)
168 {
169 CurveExtra * ctmp = this_proj -> curves[rid][cid] -> extrac -> first;
170 for (i=0; i<this_proj -> curves[rid][cid] -> extrac -> extras; i++)
171 {
172 if (fwrite (& ctmp -> id.a, sizeof(int), 1, fp) != 1) return ERROR_RW;
173 if (fwrite (& ctmp -> id.b, sizeof(int), 1, fp) != 1) return ERROR_RW;
174 if (fwrite (& ctmp -> id.c, sizeof(int), 1, fp) != 1) return ERROR_RW;
175 if (! write_data_layout (fp, ctmp -> layout)) return ERROR_RW;
176 if (ctmp -> next != NULL) ctmp = ctmp -> next;
177 }
178 }
179 if (save_this_string (fp, this_proj -> curves[rid][cid] -> cfile) != OK) return ERROR_RW;
180 }
181#ifdef DEBUG
182// debugiocurve (this_proj, win, rid, cid, "WRITE");
183#endif
184 return OK;
185}
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
Global variable declarations Global convenience function declarations Global data structure defin...
#define ERROR_RW
Definition global.h:252
#define OK
Definition global.h:251
void autoscale(gpointer data)
autoscale callback
Definition m_curve.c:82
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:49
int save_project_curve(FILE *fp, int wid, project *this_proj, int rid, int cid)
save project curve to file
Definition save_curve.c:76
gboolean write_data_layout(FILE *fp, DataLayout *layout)
save curve data layout to file
Definition save_curve.c:50
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