1 /*
2      cmaplib.h: C/C++ level API for accessing CCP4 map files
3      Copyright (C) 2001  CCLRC, Charles Ballard
4 
5      This library is free software: you can redistribute it and/or
6      modify it under the terms of the GNU Lesser General Public License
7      version 3, modified in accordance with the provisions of the
8      license to address the requirements of UK law.
9 
10      You should have received a copy of the modified GNU Lesser General
11      Public License along with this library.  If not, copies may be
12      downloaded from http://www.ccp4.ac.uk/ccp4license.php
13 
14      This program is distributed in the hope that it will be useful,
15      but WITHOUT ANY WARRANTY; without even the implied warranty of
16      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17      GNU Lesser General Public License for more details.
18 */
19 
20 /** @page cmap_page CMAP library
21  *
22  * @verbatim
23 
24 <!-- ::INDEX_INFO::CMAP library::Library::::C/C++ Software Library for CCP4 map files:::::::: -->
25 
26    @endverbatim
27  *
28  *  @section cmap_file_list File list
29 
30 <ul>
31 <li>cmaplib.h - contains details of the C/C++ API
32 <li>cmap_data.h
33 <li>cmap_header.h
34 <li>cmap_skew.h
35 <li>cmap_errno.h
36 <li>cmap_labels.h
37 <li>cmap_stats.h
38 </ul>
39 
40  *  @section cmap_overview Overview
41 
42   Functions defining the C-level API for accessing CCP4 map files.
43 
44  */
45 
46 /** @file cmaplib.h
47  *
48  *  @brief ccp4 map i/o user-level library header file
49  *
50  *  Functions defining the C-level API for accessing CCP4 map files.
51  *
52  *  @author Charles Ballard
53  */
54 
55 #ifndef __GUARD_MAPLIB
56 #define __GUARD_MAPLIB
57 
58 #include "ccp4_utils.h"
59 
60 #ifdef __cplusplus
61 namespace CMap_io {
62 typedef CCP4::CCP4File CCP4File;
63 extern "C" {
64 #endif
65 
66 typedef struct _CMMFile_Skew CMMFile_Skew;
67 typedef struct _CMMFile_Labels CMMFile_Labels;
68 typedef struct _CMMFile_Symop CMMFile_Symop;
69 typedef struct _CMMFile_Data CMMFile_Data;
70 typedef struct _CMMFile_Stats CMMFile_Stats;
71 typedef struct _CMMFile CMMFile;
72 
73 struct _CMMFile_Labels {
74   unsigned int number;
75   char *labels[10];
76 };
77 
78 struct _CMMFile_Skew {
79   float rotation[3][3];
80   float translation[3];
81 };
82 
83 struct _CMMFile_Symop {
84 unsigned int offset;
85 unsigned int size;
86 unsigned int number;
87 };
88 
89 struct _CMMFile_Data {
90   size_t offset;
91   size_t section_size;
92   size_t header_size;
93   size_t block_size;
94   unsigned int number;
95 };
96 
97 struct _CMMFile_Stats {
98   float offset;                /* pseudo zero value */
99   float min;                   /* minimum density value */
100   float max;                   /* maximum density value */
101   double mean;               /* sum of densities (less offset) */
102   double rms;              /* sum of square of densities (less offset) */
103   int total;                    /* number of summed densities */
104 };
105 
106 struct _CMMFile {
107 CCP4File *stream;
108 char *file_name;
109 unsigned int data_mode;
110 unsigned int close_mode;
111 float cell[6];
112 int spacegroup;
113 int EM_spacegroup;
114 char EM_exthead_type[5];
115 char EM_contents[5];
116 int map_dim[3];
117 int origin[3];
118 int cell_grid[3];
119 int axes_order[3];
120 CMMFile_Symop symop;
121 CMMFile_Data data;
122 CMMFile_Stats stats;
123 CMMFile_Labels labels;
124 CMMFile_Skew skew;
125 int reserved[8];
126 char user_access[28];
127 };
128 
129 /* open a file for read/write */
130 void *ccp4_cmap_open(const char *filename, int mode);
131 
132 /* close a file for read/write (dumping the header if write) */
133 void ccp4_cmap_close(CMMFile *mfile);
134 
135 /* set the close mode (calculation of map statistics) */
136 void ccp4_cmap_closemode(CMMFile *mfile, unsigned int closemode);
137 
138 /* seek to a section in the map (read mode only)*/
139 int ccp4_cmap_seek_section(CMMFile *mfile, int offset, unsigned int seek_mode);
140 
141 /* seek to a row in a section (read mode only)*/
142 int ccp4_cmap_seek_row(CMMFile *, int offset, unsigned int seek_mode);
143 
144 /* raw seek (read mode only)*/
145 int ccp4_cmap_seek_data(CMMFile *, int offset, unsigned int seek_mode);
146 
147 /* read a map section from file to memory */
148 int ccp4_cmap_read_section(CMMFile *mfile, void *section);
149 
150 /* read a row from file to memory */
151 int ccp4_cmap_read_row(CMMFile *mfile, void *row);
152 
153 /* read n_items from file to memory (item determined by data mode) */
154 int ccp4_cmap_read_data(const CMMFile *mfile, void *items, int n_items);
155 
156 /* write a map section from memory to file */
157 int ccp4_cmap_write_section(CMMFile *mfile, const void *section);
158 
159 /* write a map row from memory to file */
160 int ccp4_cmap_write_row(CMMFile *mfile, const void *row);
161 
162 /* write n_items from memory to file (item determined by data mode) */
163 int ccp4_cmap_write_data(CMMFile *mfile, const void *items, int n_items);
164 
165 /* read the section header corresponding to the current section */
166 int ccp4_cmap_read_section_header(const CMMFile *mfile, char *header);
167 
168 /* write the section header corresponding to the current section */
169 int ccp4_cmap_write_section_header(CMMFile *mfile, const char *header);
170 
171 /* get the header parameters */
172 void ccp4_cmap_get_cell(const CMMFile *mfile, float *cell);
173 void ccp4_cmap_get_grid(const CMMFile *mfile, int *grid);
174 void ccp4_cmap_get_origin(const CMMFile *mfile, int *origin);
175 void ccp4_cmap_get_order(const CMMFile *mfile, int *axes_order);
176 void ccp4_cmap_get_dim(const CMMFile *mfile, int *map_dim);
177 int ccp4_cmap_get_spacegroup(const CMMFile *mfile);
178 void ccp4_cmap_get_mapstats(const CMMFile *mfile, float *min, float* max,
179                            double *mean, double *rms);
180 
181 /* set the header parameters */
182 void ccp4_cmap_set_cell(CMMFile *mfile, const float *cell);
183 void ccp4_cmap_set_grid(CMMFile *mfile, const int *grid);
184 void ccp4_cmap_set_origin(CMMFile *mfile, const int *origin);
185 void ccp4_cmap_set_order(CMMFile *mfile, const int *axes_order);
186 void ccp4_cmap_set_dim(CMMFile *mfile, const int *map_dim);
187 void ccp4_cmap_set_spacegroup(CMMFile *mfile, int spacegroup);
188 void ccp4_cmap_set_mapstats(CMMFile *mfile, const float min, const float max,
189                            const double mean, const double rms);
190 
191 /* get map file datamode */
192 unsigned int ccp4_cmap_get_datamode(const CMMFile *mfile);
193 
194 /* set map file datamode */
195 void ccp4_cmap_set_datamode(CMMFile *mfile, unsigned int datamode);
196 
197 /* get the local header size */
198 size_t ccp4_cmap_get_local_header(CMMFile *mfile);
199 
200 /* set the local header size (before data writing begins) */
201 void ccp4_cmap_set_local_header(CMMFile *mfile, size_t size);
202 
203 /* get the number of symops in the file */
204 int ccp4_cmap_num_symop(const CMMFile *mfile);
205 
206 /* seek among the symops strings */
207 int ccp4_cmap_seek_symop(CMMFile *mfile, int isymop, unsigned int whence);
208 
209 /* read a symop string of 80 characters */
210 int ccp4_cmap_get_symop(CMMFile *mfile, char *buffer);
211 
212 /* write a symop string of 80 characters */
213 int ccp4_cmap_set_symop(CMMFile *mfile, const char *buffer);
214 
215 /* get the mask */
216 int ccp4_cmap_get_mask(const CMMFile *mfile, float *skew_mat, float *skew_trans);
217 
218 /* set the mask */
219 int ccp4_cmap_set_mask(CMMFile *mfile, const float *skew_mat, const float *skew_trans);
220 
221 /* the number of labels used */
222 int ccp4_cmap_number_label(const CMMFile *mfile);
223 
224 /* set label at posn from C-string */
225 int ccp4_cmap_set_label(CMMFile *mfile, const char *label, int posn);
226 
227 /* return label at posn as C-string */
228 char *ccp4_cmap_get_label(const CMMFile *mfile, int posn);
229 
230 /* set title (label=0) */
231 int ccp4_cmap_set_title(CMMFile *mfile, const char *label);
232 
233 /* get title (label=0) */
234 char *ccp4_cmap_get_title(const CMMFile *mfile);
235 
236 #ifdef __cplusplus
237 }
238 }
239 #endif
240 
241 #endif  /* __GUARD_MAPLIB */
242