Main Page   Compound List   File List   Compound Members   File Members   Related Pages  

cmaplib.h

Go to the documentation of this file.
00001 /*
00002      cmaplib.h: C/C++ level API for accessing CCP4 map files
00003      Copyright (C) 2001  CCLRC, Charles Ballard
00004 
00005      This library is free software and is distributed under the terms and
00006      conditions of the CCP4 licence agreement as `Part 0' (Annex 2)
00007      software, which is version 2.1 of the GNU Lesser General Public
00008      Licence (LGPL) with the following additional clause:
00009 
00010         `You may also combine or link a "work that uses the Library" to
00011         produce a work containing portions of the Library, and distribute
00012         that work under terms of your choice, provided that you give
00013         prominent notice with each copy of the work that the specified
00014         version of the Library is used in it, and that you include or
00015         provide public access to the complete corresponding
00016         machine-readable source code for the Library including whatever
00017         changes were used in the work. (i.e. If you make changes to the
00018         Library you must distribute those, but you do not need to
00019         distribute source or object code to those portions of the work
00020         not covered by this licence.)'
00021 
00022      Note that this clause grants an additional right and does not impose
00023      any additional restriction, and so does not affect compatibility
00024      with the GNU General Public Licence (GPL). If you wish to negotiate
00025      other terms, please contact the maintainer.
00026 
00027      You can redistribute it and/or modify the library under the terms of
00028      the GNU Lesser General Public License as published by the Free Software
00029      Foundation; either version 2.1 of the License, or (at your option) any
00030      later version.
00031 
00032      This library is distributed in the hope that it will be useful, but
00033      WITHOUT ANY WARRANTY; without even the implied warranty of
00034      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00035      Lesser General Public License for more details.
00036 
00037      You should have received a copy of the CCP4 licence and/or GNU
00038      Lesser General Public License along with this library; if not, write
00039      to the CCP4 Secretary, Daresbury Laboratory, Warrington WA4 4AD, UK.
00040      The GNU Lesser General Public can also be obtained by writing to the
00041      Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00042      MA 02111-1307 USA
00043 */
00044 
00080 #ifndef __GUARD_MAPLIB
00081 #define __GUARD_MAPLIB
00082 
00083 #include "ccp4_utils.h"
00084 
00085 #ifdef __cplusplus
00086 namespace CMap_io {
00087 typedef CCP4::CCP4File CCP4File;
00088 extern "C" {
00089 #endif
00090 
00091 typedef struct _CMMFile_Skew CMMFile_Skew;
00092 typedef struct _CMMFile_Labels CMMFile_Labels;
00093 typedef struct _CMMFile_Symop CMMFile_Symop;
00094 typedef struct _CMMFile_Data CMMFile_Data;
00095 typedef struct _CMMFile_Stats CMMFile_Stats;
00096 typedef struct _CMMFile CMMFile;
00097 
00098 struct _CMMFile_Labels {
00099   unsigned int number;
00100   char *labels[10];
00101 };
00102 
00103 struct _CMMFile_Skew {
00104   float rotation[3][3];
00105   float translation[3];
00106 };
00107 
00108 struct _CMMFile_Symop {
00109 unsigned int offset;
00110 unsigned int size;
00111 unsigned int number;
00112 };
00113 
00114 struct _CMMFile_Data {
00115   size_t offset;
00116   size_t section_size;
00117   size_t header_size;
00118   size_t block_size;
00119   unsigned int number;
00120 };
00121 
00122 struct _CMMFile_Stats {
00123   float offset;                /* pseudo zero value */
00124   float min;                   /* minimum density value */
00125   float max;                   /* maximum density value */
00126   double mean;               /* sum of densities (less offset) */
00127   double rms;              /* sum of square of densities (less offset) */
00128   int total;                    /* number of summed densities */
00129 };
00130 
00131 struct _CMMFile {
00132 CCP4File *stream;
00133 char *file_name;
00134 unsigned int data_mode;
00135 unsigned int close_mode;
00136 float cell[6];
00137 int spacegroup;
00138 int map_dim[3];
00139 int origin[3];
00140 int cell_grid[3];
00141 int axes_order[3];
00142 CMMFile_Symop symop;
00143 CMMFile_Data data;
00144 CMMFile_Stats stats;
00145 CMMFile_Labels labels;
00146 CMMFile_Skew skew;
00147 int reserved[8];
00148 char user_access[24];
00149 };
00150 
00151 /* open a file for read/write */
00152 void *ccp4_cmap_open(const char *filename, int mode);
00153 
00154 /* close a file for read/write (dumping the header if write) */
00155 void ccp4_cmap_close(CMMFile *mfile);
00156 
00157 /* set the close mode (calculation of map statistics) */
00158 void ccp4_cmap_closemode(CMMFile *mfile, unsigned int closemode);
00159 
00160 /* seek to a section in the map (read mode only)*/
00161 int ccp4_cmap_seek_section(CMMFile *mfile, int offset, unsigned int seek_mode);
00162 
00163 /* seek to a row in a section (read mode only)*/
00164 int ccp4_cmap_seek_row(CMMFile *, int offset, unsigned int seek_mode);
00165 
00166 /* raw seek (read mode only)*/
00167 int ccp4_cmap_seek_data(CMMFile *, int offset, unsigned int seek_mode);
00168 
00169 /* read a map section from file to memory */
00170 int ccp4_cmap_read_section(CMMFile *mfile, void *section);
00171 
00172 /* read a row from file to memory */
00173 int ccp4_cmap_read_row(CMMFile *mfile, void *row);
00174 
00175 /* read n_items from file to memory (item determined by data mode) */
00176 int ccp4_cmap_read_data(const CMMFile *mfile, void *items, int n_items);
00177 
00178 /* write a map section from memory to file */
00179 int ccp4_cmap_write_section(CMMFile *mfile, const void *section);
00180 
00181 /* write a map row from memory to file */
00182 int ccp4_cmap_write_row(CMMFile *mfile, const void *row);
00183 
00184 /* write n_items from memory to file (item determined by data mode) */
00185 int ccp4_cmap_write_data(CMMFile *mfile, const void *items, int n_items);
00186 
00187 /* read the section header corresponding to the current section */
00188 int ccp4_cmap_read_section_header(const CMMFile *mfile, char *header);
00189 
00190 /* write the section header corresponding to the current section */
00191 int ccp4_cmap_write_section_header(CMMFile *mfile, const char *header);
00192 
00193 /* get the header parameters */
00194 void ccp4_cmap_get_cell(const CMMFile *mfile, float *cell);
00195 void ccp4_cmap_get_grid(const CMMFile *mfile, int *grid);
00196 void ccp4_cmap_get_origin(const CMMFile *mfile, int *origin);
00197 void ccp4_cmap_get_order(const CMMFile *mfile, int *axes_order);
00198 void ccp4_cmap_get_dim(const CMMFile *mfile, int *map_dim);
00199 int ccp4_cmap_get_spacegroup(const CMMFile *mfile);
00200 void ccp4_cmap_get_mapstats(const CMMFile *mfile, float *min, float* max, 
00201                            double *mean, double *rms);
00202 
00203 /* set the header parameters */
00204 void ccp4_cmap_set_cell(CMMFile *mfile, const float *cell);
00205 void ccp4_cmap_set_grid(CMMFile *mfile, const int *grid);
00206 void ccp4_cmap_set_origin(CMMFile *mfile, const int *origin);
00207 void ccp4_cmap_set_order(CMMFile *mfile, const int *axes_order);
00208 void ccp4_cmap_set_dim(CMMFile *mfile, const int *map_dim);
00209 void ccp4_cmap_set_spacegroup(CMMFile *mfile, int spacegroup);
00210 void ccp4_cmap_set_mapstats(CMMFile *mfile, const float min, const float max,
00211                            const double mean, const double rms);
00212 
00213 /* get map file datamode */
00214 unsigned int ccp4_cmap_get_datamode(const CMMFile *mfile);
00215 
00216 /* set map file datamode */
00217 void ccp4_cmap_set_datamode(CMMFile *mfile, unsigned int datamode);
00218 
00219 /* get the local header size */
00220 size_t ccp4_cmap_get_local_header(CMMFile *mfile);
00221 
00222 /* set the local header size (before data writing begins) */
00223 void ccp4_cmap_set_local_header(CMMFile *mfile, size_t size);
00224 
00225 /* get the number of symops in the file */
00226 int ccp4_cmap_num_symop(const CMMFile *mfile);
00227 
00228 /* seek among the symops strings */
00229 int ccp4_cmap_seek_symop(CMMFile *mfile, int isymop, unsigned int whence);
00230 
00231 /* read a symop string of 80 characters */
00232 int ccp4_cmap_get_symop(CMMFile *mfile, char *buffer);
00233 
00234 /* write a symop string of 80 characters */
00235 int ccp4_cmap_set_symop(CMMFile *mfile, const char *buffer);
00236 
00237 /* get the mask */
00238 int ccp4_cmap_get_mask(const CMMFile *mfile, float *skew_mat, float *skew_trans);
00239 
00240 /* set the mask */
00241 int ccp4_cmap_set_mask(CMMFile *mfile, const float *skew_mat, const float *skew_trans);
00242 
00243 /* the number of labels used */
00244 int ccp4_cmap_number_label(const CMMFile *mfile);
00245 
00246 /* set label at posn from C-string */
00247 int ccp4_cmap_set_label(CMMFile *mfile, const char *label, int posn);
00248 
00249 /* return label at posn as C-string */
00250 char *ccp4_cmap_get_label(const CMMFile *mfile, int posn);
00251 
00252 /* set title (label=0) */
00253 int ccp4_cmap_set_title(CMMFile *mfile, const char *label);
00254 
00255 /* get title (label=0) */
00256 char *ccp4_cmap_get_title(const CMMFile *mfile);
00257 
00258 #ifdef __cplusplus
00259 }
00260 }
00261 #endif
00262 
00263 #endif  /* __GUARD_MAPLIB */