gpp4  1.3.1
Classes | Typedefs | Functions
library_file.h File Reference

Functions for file i/o. More...

#include "ccp4_sysdep.h"
#include "ccp4_types.h"

Go to the source code of this file.

Classes

struct  _CFileStruct
 

Typedefs

typedef struct _CFileStruct CCP4File
 

Functions

CCP4Fileccp4_file_open (const char *, const int)
 
CCP4Fileccp4_file_open_file (const FILE *, const int)
 
CCP4Fileccp4_file_open_fd (const int, const int)
 
int ccp4_file_rarch (CCP4File *)
 
int ccp4_file_warch (CCP4File *)
 
int ccp4_file_close (CCP4File *)
 
int ccp4_file_mode (const CCP4File *)
 
int ccp4_file_setmode (CCP4File *, const int)
 
int ccp4_file_setstamp (CCP4File *, const size_t)
 
int ccp4_file_itemsize (const CCP4File *)
 
int ccp4_file_setbyte (CCP4File *, const int)
 
int ccp4_file_byteorder (CCP4File *)
 
int ccp4_file_is_write (const CCP4File *)
 
int ccp4_file_is_read (const CCP4File *)
 
int ccp4_file_is_append (const CCP4File *)
 
int ccp4_file_is_scratch (const CCP4File *)
 
int ccp4_file_is_buffered (const CCP4File *)
 
int ccp4_file_status (const CCP4File *)
 
const char * ccp4_file_name (CCP4File *)
 
int ccp4_file_read (CCP4File *, uint8 *, size_t)
 
int ccp4_file_readcomp (CCP4File *, uint8 *, size_t)
 
int ccp4_file_readshortcomp (CCP4File *, uint8 *, size_t)
 
int ccp4_file_readfloat (CCP4File *, uint8 *, size_t)
 
int ccp4_file_readint (CCP4File *, uint8 *, size_t)
 
int ccp4_file_readshort (CCP4File *, uint8 *, size_t)
 
int ccp4_file_readchar (CCP4File *, uint8 *, size_t)
 
int ccp4_file_write (CCP4File *, const uint8 *, size_t)
 
int ccp4_file_writecomp (CCP4File *, const uint8 *, size_t)
 
int ccp4_file_writeshortcomp (CCP4File *, const uint8 *, size_t)
 
int ccp4_file_writefloat (CCP4File *, const uint8 *, size_t)
 
int ccp4_file_writeint (CCP4File *, const uint8 *, size_t)
 
int ccp4_file_writeshort (CCP4File *, const uint8 *, size_t)
 
int ccp4_file_writechar (CCP4File *, const uint8 *, size_t)
 
int ccp4_file_seek (CCP4File *, long, int)
 
void ccp4_file_rewind (CCP4File *)
 
void ccp4_file_flush (CCP4File *)
 
long ccp4_file_length (CCP4File *)
 
long ccp4_file_tell (CCP4File *)
 
int ccp4_file_feof (CCP4File *)
 
void ccp4_file_clearerr (CCP4File *)
 
void ccp4_file_fatal (CCP4File *, char *)
 
char * ccp4_file_print (CCP4File *, char *, char *)
 
int ccp4_file_raw_seek (CCP4File *, long, int)
 
int ccp4_file_raw_read (CCP4File *, char *, size_t)
 
int ccp4_file_raw_write (CCP4File *, const char *, size_t)
 
int ccp4_file_raw_setstamp (CCP4File *, const size_t)
 

Detailed Description

Functions for file i/o.

Author
Charles Ballard

Typedef Documentation

◆ CCP4File

typedef struct _CFileStruct CCP4File

Generic CCP4 file.

Function Documentation

◆ ccp4_file_clearerr()

void ccp4_file_clearerr ( CCP4File cfile)

ccp4_file_clearerr:

Parameters
cfile(CCP4File *)

Clears error status of cfile.

◆ ccp4_file_close()

int ccp4_file_close ( CCP4File cfile)

ccp4_file_close:

Parameters
cfile(CCP4File *)

close cfile if owned, close (non-buffered) or fclose (buffered), or fflush if stream not owned. Free resources.

Returns
0 on success, EOF on failure

References ccp4_signal().

Referenced by ccp4_cmap_close(), FORTRAN_SUBR(), and MtzFree().

◆ ccp4_file_fatal()

void ccp4_file_fatal ( CCP4File cfile,
char *  message 
)

ccp4_file_fatal:

Parameters
cfile(CCP4File *)
messagemessage to output. Die with error message based on cfile error status.

References ccp4_signal().

◆ ccp4_file_feof()

int ccp4_file_feof ( CCP4File cfile)

ccp4_file_feof:

Parameters
cfile(CCP4File *)
Returns
true if cfile is at EoF.

References ccp4_signal().

Referenced by FORTRAN_SUBR().

◆ ccp4_file_flush()

void ccp4_file_flush ( CCP4File cfile)

ccp4_file_flush:

Parameters
cfile(CCP4File *)

flush buffer contents of cfile

◆ ccp4_file_is_append()

int ccp4_file_is_append ( const CCP4File cfile)

ccp4_file_is_append:

Parameters
cfile(CCP4File *)

is the cfile in append mode

Returns
1 if true.

◆ ccp4_file_is_buffered()

int ccp4_file_is_buffered ( const CCP4File cfile)

ccp4_file_is_buffered:

Parameters
cfile(CCP4File *)

is the file buffered

Returns
1 if true

◆ ccp4_file_is_read()

int ccp4_file_is_read ( const CCP4File cfile)

ccp4_file_is_read:

Parameters
cfile(CCP4File *)

is the cfile readable

Returns
1 if true.

Referenced by ccp4_cmap_seek_symop().

◆ ccp4_file_is_scratch()

int ccp4_file_is_scratch ( const CCP4File cfile)

ccp4_file_is_scratch:

Parameters
cfile(CCP4File *)

is scratch file

Returns
1 if true.

◆ ccp4_file_is_write()

int ccp4_file_is_write ( const CCP4File cfile)

◆ ccp4_file_itemsize()

int ccp4_file_itemsize ( const CCP4File cfile)

ccp4_file_itemsize:

Parameters
cfile(CCP4File *)
Returns
itemsize of cfile.

References ccp4_signal().

Referenced by ccp4_cmap_set_datamode(), ccp4_cmap_set_dim(), and FORTRAN_SUBR().

◆ ccp4_file_length()

long ccp4_file_length ( CCP4File cfile)

ccp4_file_length:

Parameters
cfile(CCP4File *)

Length of file on disk.

Returns
length of cfile on success, EOF on failure

References ccp4_signal().

Referenced by number_sections().

◆ ccp4_file_mode()

int ccp4_file_mode ( const CCP4File cfile)

ccp4_file_mode:

Parameters
cfile(CCP4File *)

get data mode of cfile (BYTE =0, INT16 =1, INT32=6, FLOAT32 =2, COMP32 =3, COMP64 =4)

Returns
mode

References ccp4_signal().

◆ ccp4_file_name()

const char* ccp4_file_name ( CCP4File cfile)

ccp4_file_name:

Parameters
cfile(CCP4File *)

strdup cfile->name

Returns
name of file as const char *

◆ ccp4_file_open()

CCP4File* ccp4_file_open ( const char *  filename,
const int  flag 
)

ccp4_file_open:

Parameters
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.

Returns
(CCP4File *) on success, NULL on failure

Referenced by ccp4_cmap_open().

◆ ccp4_file_open_fd()

CCP4File* ccp4_file_open_fd ( const int  fd,
const int  flag 
)

ccp4_file_open_fd:

Parameters
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.

Returns
(CCP4File *) on success, NULL on failure

◆ ccp4_file_open_file()

CCP4File* ccp4_file_open_file ( const FILE *  file,
const int  flag 
)

ccp4_file_open_file:

Parameters
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.

Returns
(CCP4File *) on success, NULL on failure

References ccp4_signal().

◆ ccp4_file_print()

char* ccp4_file_print ( CCP4File cfile,
char *  msg_start,
char *  msg_end 
)

ccp4_file_print:

Parameters
cfile(CCP4File *)
msg_startpointer to start position in string
msg_endpointer to end position in string
Returns
cfile information in char array for printing.

◆ ccp4_file_rarch()

int ccp4_file_rarch ( CCP4File cfile)

ccp4_file_rarch:

Parameters
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.

Returns
fileFT | (fileIT<<8)

References ccp4_signal().

◆ ccp4_file_raw_read()

int ccp4_file_raw_read ( CCP4File cfile,
char *  buffer,
size_t  n_items 
)

ccp4_file_raw_read:

Parameters
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.

Returns
number of bytes read.

References ccp4_signal().

◆ ccp4_file_raw_seek()

int ccp4_file_raw_seek ( CCP4File cfile,
long  offset,
int  whence 
)

ccp4_file_raw_seek:

Parameters
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.

Returns
offset in bytes on success, -1 on failure.

References ccp4_signal().

Referenced by is_cmap(), and parse_maplabels().

◆ ccp4_file_raw_setstamp()

int ccp4_file_raw_setstamp ( CCP4File cfile,
const size_t  offset 
)

Set file offset

Parameters
cfile(CCP4File *)
offsetstamp location

◆ ccp4_file_raw_write()

int ccp4_file_raw_write ( CCP4File cfile,
const char *  buffer,
size_t  n_items 
)

ccp4_file_raw_write:

Parameters
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.

Returns
number of bytes written.

References ccp4_signal().

◆ ccp4_file_read()

int ccp4_file_read ( CCP4File cfile,
uint8 *  buffer,
size_t  nitems 
)

ccp4_file_read:

Parameters
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.

Returns
number of items read on success, EOF on failure

References ccp4_signal().

Referenced by FORTRAN_SUBR(), and MtzRrefl().

◆ ccp4_file_readchar()

int ccp4_file_readchar ( CCP4File cfile,
uint8 *  buffer,
size_t  nitems 
)

ccp4_file_readchar:

Parameters
cfile(CCP4File *)
buffer(uint8 *) buffer
nitems(size_t) number of items

character read function. Reads nitems characters from stream cfile->stream to buffer.

Returns
number of characters read on success, EOF on failure

References ccp4_signal().

Referenced by is_cmap(), parse_mapheader(), and parse_maplabels().

◆ ccp4_file_readcomp()

int ccp4_file_readcomp ( CCP4File cfile,
uint8 *  buffer,
size_t  nitems 
)

ccp4_file_readcomp:

Parameters
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).

Returns
number of complex read on success, EOF on failure

References ccp4_signal().

Referenced by FORTRAN_SUBR().

◆ ccp4_file_readfloat()

int ccp4_file_readfloat ( CCP4File cfile,
uint8 *  buffer,
size_t  nitems 
)

ccp4_file_readfloat:

Parameters
cfile(CCP4File *)
buffer(uint8 *) buffer
nitems(size_t) number of items

float read function. Reads nitems floats from stream cfile->stream to buffer.

Returns
number of floats read on success, EOF on failure

References ccp4_signal().

Referenced by FORTRAN_SUBR(), and parse_mapheader().

◆ ccp4_file_readint()

int ccp4_file_readint ( CCP4File cfile,
uint8 *  buffer,
size_t  nitems 
)

ccp4_file_readint:

Parameters
cfile(CCP4File *)
buffer(uint8 *) buffer
nitems(size_t) number of items

integer read function. Reads nitems int from stream cfile->stream to buffer.

Returns
number of int read on success, EOF on failure

References ccp4_signal().

Referenced by FORTRAN_SUBR(), and parse_mapheader().

◆ ccp4_file_readshort()

int ccp4_file_readshort ( CCP4File cfile,
uint8 *  buffer,
size_t  nitems 
)

ccp4_file_readshort:

Parameters
cfile(CCP4File *)
buffer(uint8 *) buffer
nitems(size_t) number of items

short read function. Reads nitems shorts from stream cfile->stream to buffer.

Returns
number of shorts read on success, EOF on failure

References ccp4_signal().

Referenced by FORTRAN_SUBR().

◆ ccp4_file_readshortcomp()

int ccp4_file_readshortcomp ( CCP4File cfile,
uint8 *  buffer,
size_t  nitems 
)

ccp4_file_readshortcomp:

Parameters
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).

Returns
number of complex read on success, EOF on failure

References ccp4_signal().

◆ ccp4_file_rewind()

void ccp4_file_rewind ( CCP4File cfile)

ccp4_file_rewind:

Parameters
cfile(CCP4File *)

Seek to start of file. Clear error status.

Returns
0 on success, EOF on failure

References ccp4_signal().

Referenced by is_cmap(), and parse_mapheader().

◆ ccp4_file_seek()

int ccp4_file_seek ( CCP4File cfile,
long  offset,
int  whence 
)

ccp4_file_seek:

Parameters
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.

Returns
0 on success, -1 on failure

References ccp4_signal().

Referenced by FORTRAN_SUBR(), and MtzRewdInput().

◆ ccp4_file_setbyte()

int ccp4_file_setbyte ( CCP4File cfile,
const int  byte_order 
)

ccp4_file_setbyte:

Parameters
cfile(CCP4File *)
byte_order(int)

set byte ordering for file Return:

References ccp4_signal().

◆ ccp4_file_setmode()

int ccp4_file_setmode ( CCP4File cfile,
const int  mode 
)

ccp4_file_setmode:

Parameters
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).

Returns
0 on success, EOF on failure.

References ccp4_signal().

Referenced by ccp4_cmap_set_datamode(), FORTRAN_SUBR(), and MtzRrefl().

◆ ccp4_file_setstamp()

int ccp4_file_setstamp ( CCP4File cfile,
const size_t  offset 
)

ccp4_file_setstamp:

Parameters
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().

Returns
0 on success, EOF on failure

References ccp4_signal().

Referenced by FORTRAN_SUBR().

◆ ccp4_file_status()

int ccp4_file_status ( const CCP4File cfile)

ccp4_file_status:

Parameters
cfile(CCP4File *)
Returns
cfile error status

◆ ccp4_file_tell()

long ccp4_file_tell ( CCP4File cfile)

ccp4_file_tell:

Parameters
cfile(CCP4File *)

Current location in file, uses either ftell or lseek.

Returns
current offset of cfile in bytes.

References ccp4_signal().

Referenced by FORTRAN_SUBR().

◆ ccp4_file_warch()

int ccp4_file_warch ( CCP4File cfile)

ccp4_file_warch:

Parameters
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).

Returns
0 on success, EOF on failure

References ccp4_signal().

Referenced by ccp4_cmap_close().

◆ ccp4_file_write()

int ccp4_file_write ( CCP4File cfile,
const uint8 *  buffer,
size_t  nitems 
)

ccp4_file_write:

Parameters
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.

Returns
number of items written on success, EOF on failure

References ccp4_signal().

Referenced by FORTRAN_SUBR().

◆ ccp4_file_writechar()

int ccp4_file_writechar ( CCP4File cfile,
const uint8 *  buffer,
size_t  nitems 
)

ccp4_file_writechar:

Parameters
cfile(CCP4File *)
buffer(uint8 *) buffer
nitems(size_t) number of items

char write function. Write nitems items from buffer to cfile->stream.

Returns
number of bytes written on success, EOF on failure

References ccp4_signal().

Referenced by ccp4_cmap_set_symop(), and write_maplabels().

◆ ccp4_file_writecomp()

int ccp4_file_writecomp ( CCP4File cfile,
const uint8 *  buffer,
size_t  nitems 
)

ccp4_file_writecomp:

Parameters
cfile(CCP4File *)
buffer(uint8 *) buffer
nitems(size_t) number of items

complex {float,float} write function. Write nitems items from buffer to cfile->stream.

Returns
number of complex items written on success, EOF on failure

References ccp4_signal().

Referenced by FORTRAN_SUBR().

◆ ccp4_file_writefloat()

int ccp4_file_writefloat ( CCP4File cfile,
const uint8 *  buffer,
size_t  nitems 
)

ccp4_file_writefloat:

Parameters
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_signal().

Referenced by FORTRAN_SUBR().

◆ ccp4_file_writeint()

int ccp4_file_writeint ( CCP4File cfile,
const uint8 *  buffer,
size_t  nitems 
)

ccp4_file_writeint:

Parameters
cfile(CCP4File *)
buffer(uint8 *) buffer
nitems(size_t) number of items

int write function. Write nitems items from buffer to cfile->stream.

Returns
number of int written on success, EOF on failure

References ccp4_signal().

Referenced by FORTRAN_SUBR().

◆ ccp4_file_writeshort()

int ccp4_file_writeshort ( CCP4File cfile,
const uint8 *  buffer,
size_t  nitems 
)

ccp4_file_writeshort:

Parameters
cfile(CCP4File *)
buffer(uint8 *) buffer
nitems(size_t) number of items

short write function. Write nitems items from buffer to cfile->stream.

Returns
number of short written on success, EOF on failure

References ccp4_signal().

◆ ccp4_file_writeshortcomp()

int ccp4_file_writeshortcomp ( CCP4File cfile,
const uint8 *  buffer,
size_t  nitems 
)

ccp4_file_writeshortcomp:

Parameters
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.

Returns
number of complex items written on success, EOF on failure

References ccp4_signal().