gpp4  1.3.1
Functions
cmap_data.c File Reference

Functions to manipulate CCP4 map files. More...

#include <math.h>
#include <string.h>
#include <stdlib.h>
#include "cmaplib.h"
#include "cmap_data.h"
#include "cmap_stats.h"
#include "cmap_errno.h"

Functions

int number_sections (CMMFile *mfile)
 
int ccp4_cmap_seek_section (CMMFile *mfile, int sec, unsigned int whence)
 
int ccp4_cmap_write_section (CMMFile *mfile, const void *section)
 
int ccp4_cmap_read_section (CMMFile *mfile, void *section)
 
int ccp4_cmap_read_section_header (const CMMFile *mfile, char *header)
 
int ccp4_cmap_write_section_header (CMMFile *mfile, const char *header)
 
int ccp4_cmap_seek_row (CMMFile *mfile, int row, unsigned int whence)
 
int ccp4_cmap_write_row (CMMFile *mfile, const void *row)
 
int ccp4_cmap_read_row (CMMFile *mfile, void *row)
 
int ccp4_cmap_seek_data (CMMFile *mfile, int offset, unsigned int whence)
 
int ccp4_cmap_write_data (CMMFile *mfile, const void *items, int n_items)
 
int ccp4_cmap_read_data (const CMMFile *mfile, void *items, int n_items)
 

Detailed Description

Functions to manipulate CCP4 map files.

Function Documentation

int ccp4_cmap_read_data ( const CMMFile mfile,
void *  items,
int  n_items 
)

raw read of nelements items from file according to the datamode at current location

Parameters
mfile(const CMMFile *)
items(void *) values read to here, so should have enough space for nelements items
n_items(int) number of items to be read
Returns
number of items read or EOF

References ccp4_file_is_read(), ccp4_file_read(), ccp4_signal(), and _CMMFile::stream.

int ccp4_cmap_read_row ( CMMFile mfile,
void *  row 
)

read current map section from file to section. Some checking is performed to ensure we are at the start of a legitimate map row.

Parameters
mfile(CMMFile *)
row(void *) array large enough to hold the map row
Returns
1 on success, 0 on failure

References ccp4_file_is_read(), ccp4_file_itemsize(), ccp4_file_raw_seek(), ccp4_file_read(), ccp4_file_tell(), ccp4_signal(), _CMMFile::map_dim, and _CMMFile::stream.

Referenced by FORTRAN_SUBR().

int ccp4_cmap_read_section ( CMMFile mfile,
void *  section 
)

read current map section from file to section. Some checking is performed to ensure we are at the start of a legitimate map section.

Parameters
mfile(CMMFile *)
section(void *) array large enough to hold the map section
Returns
1 on success, 0 on failure

References ccp4_file_is_read(), ccp4_file_raw_seek(), ccp4_file_read(), ccp4_file_tell(), ccp4_signal(), _CMMFile::map_dim, and _CMMFile::stream.

Referenced by FORTRAN_SUBR().

int ccp4_cmap_read_section_header ( const CMMFile mfile,
char *  header 
)

read current section header (character array) After reading we are at the end of the local header

Parameters
mfile(CMMFile *)
header(char *) character array large enough to hold the local header (raw read so not string)
Returns
1 on success, 0 on failure

References ccp4_errno, ccp4_file_is_read(), ccp4_file_raw_seek(), ccp4_file_readchar(), ccp4_file_tell(), ccp4_signal(), and _CMMFile::stream.

Referenced by FORTRAN_SUBR().

int ccp4_cmap_seek_data ( CMMFile mfile,
int  offset,
unsigned int  whence 
)

raw seek in items

Parameters
mfile(CMMFile *)
offset(int) number of items
whence(unsigned int) SEEK_SET, SEEK_CUR, SEEK_END;
Returns
0 on success, EOF on failure

References ccp4_errno, ccp4_file_seek(), ccp4_signal(), and _CMMFile::stream.

int ccp4_cmap_seek_row ( CMMFile mfile,
int  row,
unsigned int  whence 
)

seek a row within a map section

Parameters
mfile(CMMFile *)
row(int)
whence(unsigned int) SEEK_SET, SEEK_END, SEEK_CUR
Returns
offset in file or EOF

References ccp4_file_itemsize(), ccp4_file_raw_seek(), ccp4_file_tell(), ccp4_signal(), _CMMFile::map_dim, and _CMMFile::stream.

int ccp4_cmap_seek_section ( CMMFile mfile,
int  sec,
unsigned int  whence 
)

seek among the map sections. The units are of size block_size.

Parameters
mfile(CMMFile *)
sec(int) section number
whence(unsigned int) SEEK_SET, SEEK_CUR or SEEK_END
Returns
offset in file, or EOF

References ccp4_file_is_read(), ccp4_file_raw_seek(), ccp4_file_tell(), ccp4_signal(), and _CMMFile::stream.

Referenced by FORTRAN_SUBR().

int ccp4_cmap_write_data ( CMMFile mfile,
const void *  items,
int  n_items 
)

raw write of nelements items to file, according to the datamode, at current location

Parameters
mfile(const CMMFile *)
section(void *) values written, should contain at least nelements items
n_items(int) number of items to be written
Returns
number of items written or EOF

References ccp4_file_is_write(), ccp4_file_write(), ccp4_signal(), and _CMMFile::stream.

Referenced by FORTRAN_SUBR().

int ccp4_cmap_write_row ( CMMFile mfile,
const void *  row 
)

write map row to file. Note: this wraps a raw write, with no location checking. It is therefore the responsibility of the calling program to ensure that everything is correct. Effectively assume appending to file.

Parameters
mfile(CMMFile *)
row(const void *) data to be written
Returns
1 on success, 0 on failure

References ccp4_file_is_write(), ccp4_file_write(), ccp4_signal(), _CMMFile::map_dim, and _CMMFile::stream.

int ccp4_cmap_write_section ( CMMFile mfile,
const void *  section 
)

write map section to file. Note: this wraps a raw write, with no location checking. It is therefore the responsibility of the calling program to ensure that everything is correct. Effectively assume appending to file.

Parameters
mfile(CMMFile *)
section(const void *)
Returns
1 on success, 0 on failure

References ccp4_file_is_write(), ccp4_file_write(), ccp4_signal(), _CMMFile::map_dim, and _CMMFile::stream.

Referenced by FORTRAN_SUBR().

int ccp4_cmap_write_section_header ( CMMFile mfile,
const char *  header 
)

write the local section header to the file. This must be of size mfile->data.header.size. Note: no checking is done so it is up to the calling program to ensure that the file is in the correct location. As seeking is turned off, this assumes we are appending to the file.

Parameters
mfile(CMMFile *)
header(const char *) the local header character array (not necessarily a string)
Returns
number of bytes written or EOF

References ccp4_errno, ccp4_file_is_write(), ccp4_file_writechar(), ccp4_signal(), and _CMMFile::stream.

Referenced by FORTRAN_SUBR().

int number_sections ( CMMFile mfile)

Internal: return the an estimate of the number of sections in the map file based upon the length. Update mfile->data.number as a side effect.

Parameters
mfile(CMMFile *)
Returns
number of sections according to length-data/section_size

References ccp4_file_length(), and _CMMFile::stream.