Functions for file i/o. More...
#include "ccp4_sysdep.h"
#include "ccp4_types.h"
Go to the source code of this file.
Functions for file i/o.
typedef struct _CFileStruct CCP4File |
Generic CCP4 file.
void ccp4_file_clearerr | ( | CCP4File * | cfile | ) |
ccp4_file_clearerr:
cfile | (CCP4File *) |
Clears error status of cfile.
Referenced by ccp4_file_rewind(), and ccp4_file_seek().
int ccp4_file_close | ( | CCP4File * | cfile | ) |
ccp4_file_close:
cfile | (CCP4File *) |
close cfile if owned, close (non-buffered) or fclose (buffered), or fflush if stream not owned. Free resources.
References ccp4_signal().
Referenced by ccp4_cmap_close(), ccp4_cmap_open(), FORTRAN_SUBR(), MtzFree(), MtzGetUserCellTolerance(), and MtzPut().
void ccp4_file_fatal | ( | CCP4File * | cfile, | |
char * | message | |||
) |
ccp4_file_fatal:
cfile | (CCP4File *) | |
message | message to output. Die with error message based on cfile error status. |
References ccp4_fatal(), and ccp4_signal().
int ccp4_file_feof | ( | CCP4File * | cfile | ) |
ccp4_file_feof:
cfile | (CCP4File *) |
References ccp4_signal().
Referenced by FORTRAN_SUBR().
void ccp4_file_flush | ( | CCP4File * | cfile | ) |
ccp4_file_flush:
cfile | (CCP4File *) |
flush buffer contents of cfile
int ccp4_file_is_append | ( | const CCP4File * | cfile | ) |
ccp4_file_is_append:
cfile | (CCP4File *) |
is the cfile in append mode
int ccp4_file_is_buffered | ( | const CCP4File * | cfile | ) |
ccp4_file_is_buffered:
cfile | (CCP4File *) |
is the file buffered
int ccp4_file_is_read | ( | const CCP4File * | cfile | ) |
ccp4_file_is_read:
cfile | (CCP4File *) |
is the cfile readable
Referenced by ccp4_cmap_read_data(), ccp4_cmap_read_row(), ccp4_cmap_read_section(), ccp4_cmap_read_section_header(), ccp4_cmap_seek_section(), and ccp4_cmap_seek_symop().
int ccp4_file_is_scratch | ( | const CCP4File * | cfile | ) |
ccp4_file_is_scratch:
cfile | (CCP4File *) |
is scratch file
int ccp4_file_is_write | ( | const CCP4File * | cfile | ) |
ccp4_file_is_write:
cfile | (CCP4File *) |
is the cfile writeable
Referenced by ccp4_cmap_close(), ccp4_cmap_get_mapstats(), ccp4_cmap_set_cell(), ccp4_cmap_set_datamode(), ccp4_cmap_set_dim(), ccp4_cmap_set_grid(), ccp4_cmap_set_label(), ccp4_cmap_set_local_header(), ccp4_cmap_set_mapstats(), ccp4_cmap_set_order(), ccp4_cmap_set_origin(), ccp4_cmap_set_spacegroup(), ccp4_cmap_set_symop(), ccp4_cmap_write_data(), ccp4_cmap_write_row(), ccp4_cmap_write_section(), and ccp4_cmap_write_section_header().
int ccp4_file_itemsize | ( | const CCP4File * | cfile | ) |
ccp4_file_itemsize:
cfile | (CCP4File *) |
References ccp4_signal().
Referenced by ccp4_cmap_read_row(), ccp4_cmap_seek_row(), ccp4_cmap_set_datamode(), ccp4_cmap_set_dim(), FORTRAN_SUBR(), and parse_mapheader().
long ccp4_file_length | ( | CCP4File * | cfile | ) |
ccp4_file_length:
cfile | (CCP4File *) |
Length of file on disk.
References ccp4_signal().
Referenced by FORTRAN_SUBR(), and number_sections().
int ccp4_file_mode | ( | const CCP4File * | cfile | ) |
ccp4_file_mode:
cfile | (CCP4File *) |
get data mode of cfile (BYTE =0, INT16 =1, INT32=6, FLOAT32 =2, COMP32 =3, COMP64 =4)
References ccp4_signal().
const char* ccp4_file_name | ( | CCP4File * | cfile | ) |
ccp4_file_name:
cfile | (CCP4File *) |
strdup cfile->name
CCP4File* ccp4_file_open | ( | const char * | filename, | |
const int | flag | |||
) |
ccp4_file_open:
filename | (const char *) filename | |
flag | (const int) i/o mode, possible values are O_RDONLY, O_WRONLY, O_RDWR, O_APPEND, O_TMP, O_CREAT, O_TRUNC - see ccp4_sysdep.h |
initialise CCP4File struct for file filename with mode flag
. If !buffered use open(), otherwise fopen() The struct stat is check to determine if file is a regular file, if it is, and is not stdin, it is assumed to be direct access.
References ccp4_signal().
Referenced by ccp4_cmap_open(), FORTRAN_SUBR(), MtzGetUserCellTolerance(), and MtzOpenForWrite().
CCP4File* ccp4_file_open_fd | ( | const int | fd, | |
const int | flag | |||
) |
ccp4_file_open_fd:
fd | (const int) file descriptor | |
flag | (const int) io mode (O_RDONLY =0, O_WRONLY =1, O_RDWR =2, O_TMP =, O_APPEND =) |
initialise CCP4File struct with file descriptor fd
and mode flag
The struct stat is check to determine if file is a regular file, if it is, and is not stdin, it is assumed to be direct access.
References ccp4_signal().
CCP4File* ccp4_file_open_file | ( | const FILE * | file, | |
const int | flag | |||
) |
ccp4_file_open_file:
file | (const FILE *) FILE struct | |
flag | (const int) io mode (O_RDONLY =0, O_WRONLY =1, O_RDWR =2, O_TMP =, O_APPEND =) |
open cfile with existing handle FILE struct file and mode flag
. The struct stat is check to determine if file is a regular file, if it is, and is not stdin, it is assumed to be direct access.
References ccp4_signal().
char* ccp4_file_print | ( | CCP4File * | cfile, | |
char * | msg_start, | |||
char * | msg_end | |||
) |
ccp4_file_print:
cfile | (CCP4File *) | |
msg_start | pointer to start position in string | |
msg_end | pointer to end position in string |
int ccp4_file_rarch | ( | CCP4File * | cfile | ) |
ccp4_file_rarch:
cfile | (CCP4File *) |
read machine stamp from file cfile->stream. The machine stamp is at cfile->stamp_loc items, set by ccp4_file_setstamp() (default 0). NB. these values may be overrriden with the environmental variable CONVERT_FROM.
References ccp4_file_raw_read(), ccp4_file_raw_seek(), and ccp4_signal().
Referenced by ccp4_cmap_open(), FORTRAN_SUBR(), and MtzGetUserCellTolerance().
int ccp4_file_raw_read | ( | CCP4File * | cfile, | |
char * | buffer, | |||
size_t | n_items | |||
) |
ccp4_file_raw_read:
cfile | * (CCP4File *) | |
buffer | * (char *) input array | |
n_items | (size_t) number of items |
reads block of n_items bytes from cfile to buffer via FILE struct cfile->stream(fread) or file desc cfile->fd read/_read). Increments location value cfile->loc. The cfile->iostat flag is set on failure.
References ccp4_signal().
Referenced by ccp4_file_rarch(), ccp4_file_readchar(), ccp4_file_readcomp(), ccp4_file_readfloat(), ccp4_file_readint(), ccp4_file_readshort(), and ccp4_file_readshortcomp().
int ccp4_file_raw_seek | ( | CCP4File * | cfile, | |
long | offset, | |||
int | whence | |||
) |
ccp4_file_raw_seek:
cfile | (CCP4File *) | |
offset | (long) offset in bytes | |
whence | (int) SEEK_SET, SEEK_CUR, or SEEK_END |
if the file is "seekable" (not stdin) the function seeks on cfile by offset bytes using fseek/ftell (cfile->stream) or lseek (cfile->fd). SEEK_SET is relative to start of file, SEEK_CUR to current, SEEK_END to end.
References ccp4_signal().
Referenced by ccp4_cmap_read_row(), ccp4_cmap_read_section(), ccp4_cmap_read_section_header(), ccp4_cmap_seek_row(), ccp4_cmap_seek_section(), ccp4_cmap_seek_symop(), ccp4_file_rarch(), ccp4_file_readchar(), ccp4_file_readcomp(), ccp4_file_readfloat(), ccp4_file_readint(), ccp4_file_readshort(), ccp4_file_readshortcomp(), ccp4_file_rewind(), ccp4_file_seek(), ccp4_file_warch(), ccp4_file_writechar(), ccp4_file_writecomp(), ccp4_file_writefloat(), ccp4_file_writeint(), ccp4_file_writeshort(), ccp4_file_writeshortcomp(), is_cmap(), and parse_maplabels().
int ccp4_file_raw_setstamp | ( | CCP4File * | cfile, | |
const size_t | offset | |||
) |
Set file offset
cfile | (CCP4File *) | |
offset | stamp location |
Referenced by ccp4_cmap_open(), and ccp4_file_setstamp().
int ccp4_file_raw_write | ( | CCP4File * | cfile, | |
const char * | buffer, | |||
size_t | n_items | |||
) |
ccp4_file_raw_write:
cfile | (CCP4File *) | |
buffer | (char *) output array | |
n_items | (size_t) number of items |
writes block of n_items
bytes from buffer to cfile via FILE struct cfile->stream(fwrite) or file desc cfile->fd(write/_write). Increments cfile->loc on success, or resets on failure, which is then used to determine the file length. On failure cfile->iostat is set.
References ccp4_file_tell(), ccp4_signal(), and MAX.
Referenced by ccp4_file_warch(), ccp4_file_writechar(), ccp4_file_writecomp(), ccp4_file_writefloat(), ccp4_file_writeint(), ccp4_file_writeshort(), and ccp4_file_writeshortcomp().
int ccp4_file_read | ( | CCP4File * | cfile, | |
uint8 * | buffer, | |||
size_t | nitems | |||
) |
ccp4_file_read:
cfile | (CCP4File *) | |
buffer | (uint8 *) buffer | |
nitems | (size_t) number of items |
mode dependent read function. Reads nitems items from stream cfile->stream to buffer as determined by cfile->mode.
References ccp4_signal().
Referenced by ccp4_cmap_read_data(), ccp4_cmap_read_row(), ccp4_cmap_read_section(), FORTRAN_SUBR(), MtzGetUserCellTolerance(), and MtzRrefl().
int ccp4_file_readchar | ( | CCP4File * | cfile, | |
uint8 * | buffer, | |||
size_t | nitems | |||
) |
ccp4_file_readchar:
cfile | (CCP4File *) | |
buffer | (uint8 *) buffer | |
nitems | (size_t) number of items |
character read function. Reads nitems characters from stream cfile->stream to buffer.
References ccp4_file_raw_read(), ccp4_file_raw_seek(), and ccp4_signal().
Referenced by ccp4_cmap_get_symop(), ccp4_cmap_read_section_header(), FORTRAN_SUBR(), is_cmap(), MtzGetUserCellTolerance(), parse_mapheader(), and parse_maplabels().
int ccp4_file_readcomp | ( | CCP4File * | cfile, | |
uint8 * | buffer, | |||
size_t | nitems | |||
) |
ccp4_file_readcomp:
cfile | (CCP4File *) | |
buffer | (uint8 *) buffer | |
nitems | (size_t) number of items |
float complex {float,float} read function. Reads nitems complex from stream cfile->stream to buffer. Allows short count when eof is detected ( buffered input only).
References ccp4_file_raw_read(), ccp4_file_raw_seek(), and ccp4_signal().
Referenced by FORTRAN_SUBR().
int ccp4_file_readfloat | ( | CCP4File * | cfile, | |
uint8 * | buffer, | |||
size_t | nitems | |||
) |
ccp4_file_readfloat:
cfile | (CCP4File *) | |
buffer | (uint8 *) buffer | |
nitems | (size_t) number of items |
float read function. Reads nitems floats from stream cfile->stream to buffer.
References ccp4_file_raw_read(), ccp4_file_raw_seek(), and ccp4_signal().
Referenced by FORTRAN_SUBR(), and parse_mapheader().
int ccp4_file_readint | ( | CCP4File * | cfile, | |
uint8 * | buffer, | |||
size_t | nitems | |||
) |
ccp4_file_readint:
cfile | (CCP4File *) | |
buffer | (uint8 *) buffer | |
nitems | (size_t) number of items |
integer read function. Reads nitems int from stream cfile->stream to buffer.
References ccp4_file_raw_read(), ccp4_file_raw_seek(), and ccp4_signal().
Referenced by FORTRAN_SUBR(), and parse_mapheader().
int ccp4_file_readshort | ( | CCP4File * | cfile, | |
uint8 * | buffer, | |||
size_t | nitems | |||
) |
ccp4_file_readshort:
cfile | (CCP4File *) | |
buffer | (uint8 *) buffer | |
nitems | (size_t) number of items |
short read function. Reads nitems shorts from stream cfile->stream to buffer.
References ccp4_file_raw_read(), ccp4_file_raw_seek(), and ccp4_signal().
Referenced by FORTRAN_SUBR().
int ccp4_file_readshortcomp | ( | CCP4File * | cfile, | |
uint8 * | buffer, | |||
size_t | nitems | |||
) |
ccp4_file_readshortcomp:
cfile | (CCP4File *) | |
buffer | (uint8 *) buffer | |
nitems | (size_t) number of items |
short complex {short,short} read function. Reads nitems complex from stream cfile->stream to buffer. Allows short count when eof is detected ( buffered input only).
References ccp4_file_raw_read(), ccp4_file_raw_seek(), and ccp4_signal().
void ccp4_file_rewind | ( | CCP4File * | cfile | ) |
ccp4_file_rewind:
cfile | (CCP4File *) |
Seek to start of file. Clear error status.
References ccp4_file_clearerr(), ccp4_file_raw_seek(), and ccp4_signal().
Referenced by is_cmap(), and parse_mapheader().
int ccp4_file_seek | ( | CCP4File * | cfile, | |
long | offset, | |||
int | whence | |||
) |
ccp4_file_seek:
cfile | (CCP4File *) | |
offset | (long) offset in items | |
whence | (int) SEEK_SET, SEEK_CUR, or SEEK_END |
seeks on file by offset items. SEEK_SET is relative to start of file, SEEK_CUR to current, SEEK_END to end.
References ccp4_file_clearerr(), ccp4_file_raw_seek(), and ccp4_signal().
Referenced by ccp4_cmap_seek_data(), FORTRAN_SUBR(), MtzGetUserCellTolerance(), MtzOpenForWrite(), MtzPut(), and write_mapheader().
int ccp4_file_setbyte | ( | CCP4File * | cfile, | |
const int | byte_order | |||
) |
ccp4_file_setbyte:
cfile | (CCP4File *) | |
byte_order | (int) |
set byte ordering for file Return:
References ccp4_signal().
int ccp4_file_setmode | ( | CCP4File * | cfile, | |
const int | mode | |||
) |
ccp4_file_setmode:
cfile | (CCP4File *) | |
mode | (int) io_mode |
set the data mode of cfile to mode (BYTE (8 bit) = 0, INT16 (16 bit) = 1, INT32 (32 bit) = 6, FLOAT32 (32 bit) = 2, COMP32 (2*16 bit) = 3, COMP64 (2*32 bit) = 4).
References ccp4_signal().
Referenced by ccp4_cmap_set_datamode(), FORTRAN_SUBR(), MtzGetUserCellTolerance(), MtzOpenForWrite(), MtzPut(), MtzRrefl(), and parse_mapheader().
int ccp4_file_setstamp | ( | CCP4File * | cfile, | |
const size_t | offset | |||
) |
ccp4_file_setstamp:
cfile | (CCP4File *) | |
offset | (size_t) offset in items |
set the machine stamp offset in CCP4 items determined by the mode of cfile. See ccp4_file_setmode().
References ccp4_file_raw_setstamp(), and ccp4_signal().
Referenced by FORTRAN_SUBR(), MtzGetUserCellTolerance(), and MtzOpenForWrite().
int ccp4_file_status | ( | const CCP4File * | cfile | ) |
ccp4_file_status:
cfile | (CCP4File *) |
long ccp4_file_tell | ( | CCP4File * | cfile | ) |
ccp4_file_tell:
cfile | (CCP4File *) |
Current location in file, uses either ftell or lseek.
References ccp4_signal().
Referenced by ccp4_cmap_get_symop(), ccp4_cmap_read_row(), ccp4_cmap_read_section(), ccp4_cmap_read_section_header(), ccp4_cmap_seek_row(), ccp4_cmap_seek_section(), ccp4_cmap_seek_symop(), ccp4_file_raw_write(), and FORTRAN_SUBR().
int ccp4_file_warch | ( | CCP4File * | cfile | ) |
ccp4_file_warch:
cfile | (CCP4File *) |
write machine stamp to file cfile->stream. The machine stamp is placed at cfile->stamp_loc items, set by ccp4_file_setstamp() (defaults to 0).
References ccp4_file_raw_seek(), ccp4_file_raw_write(), and ccp4_signal().
Referenced by ccp4_cmap_close(), FORTRAN_SUBR(), and MtzOpenForWrite().
int ccp4_file_write | ( | CCP4File * | cfile, | |
const uint8 * | buffer, | |||
size_t | nitems | |||
) |
ccp4_file_write:
cfile | (CCP4File *) | |
buffer | (uint8 *) buffer | |
nitems | (size_t) number of items |
mode dependent write function. Write nitems items from buffer to cfile->stream as determined by cfile->mode.
References ccp4_signal().
Referenced by ccp4_cmap_write_data(), ccp4_cmap_write_row(), ccp4_cmap_write_section(), FORTRAN_SUBR(), MtzOpenForWrite(), MtzPut(), and MtzWrefl().
int ccp4_file_writechar | ( | CCP4File * | cfile, | |
const uint8 * | buffer, | |||
size_t | nitems | |||
) |
ccp4_file_writechar:
cfile | (CCP4File *) | |
buffer | (uint8 *) buffer | |
nitems | (size_t) number of items |
char write function. Write nitems items from buffer to cfile->stream.
References ccp4_file_raw_seek(), ccp4_file_raw_write(), and ccp4_signal().
Referenced by ccp4_cmap_set_symop(), ccp4_cmap_write_section_header(), MtzOpenForWrite(), MtzWhdrLine(), write_mapheader(), and write_maplabels().
int ccp4_file_writecomp | ( | CCP4File * | cfile, | |
const uint8 * | buffer, | |||
size_t | nitems | |||
) |
ccp4_file_writecomp:
cfile | (CCP4File *) | |
buffer | (uint8 *) buffer | |
nitems | (size_t) number of items |
complex {float,float} write function. Write nitems items from buffer to cfile->stream.
References ccp4_file_raw_seek(), ccp4_file_raw_write(), and ccp4_signal().
Referenced by FORTRAN_SUBR().
int ccp4_file_writefloat | ( | CCP4File * | cfile, | |
const uint8 * | buffer, | |||
size_t | nitems | |||
) |
ccp4_file_writefloat:
cfile | (CCP4File *) | |
buffer | (uint8 *) buffer | |
nitems | (size_t) number of items |
float write function. Write nitems items from buffer to cfile->stream.
Returns number of floats written on success, EOF on failure
References ccp4_file_raw_seek(), ccp4_file_raw_write(), and ccp4_signal().
Referenced by FORTRAN_SUBR(), and write_mapheader().
int ccp4_file_writeint | ( | CCP4File * | cfile, | |
const uint8 * | buffer, | |||
size_t | nitems | |||
) |
ccp4_file_writeint:
cfile | (CCP4File *) | |
buffer | (uint8 *) buffer | |
nitems | (size_t) number of items |
int write function. Write nitems items from buffer to cfile->stream.
References ccp4_file_raw_seek(), ccp4_file_raw_write(), and ccp4_signal().
Referenced by FORTRAN_SUBR(), and write_mapheader().
int ccp4_file_writeshort | ( | CCP4File * | cfile, | |
const uint8 * | buffer, | |||
size_t | nitems | |||
) |
ccp4_file_writeshort:
cfile | (CCP4File *) | |
buffer | (uint8 *) buffer | |
nitems | (size_t) number of items |
short write function. Write nitems items from buffer to cfile->stream.
References ccp4_file_raw_seek(), ccp4_file_raw_write(), and ccp4_signal().
int ccp4_file_writeshortcomp | ( | CCP4File * | cfile, | |
const uint8 * | buffer, | |||
size_t | nitems | |||
) |
ccp4_file_writeshortcomp:
cfile | (CCP4File *) | |
buffer | (uint8 *) buffer | |
nitems | (size_t) number of items |
short complex {short,short} write function. Write nitems items from buffer to cfile->stream.
References ccp4_file_raw_seek(), ccp4_file_raw_write(), and ccp4_signal().