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

library_file.c File Reference

#include <string.h>
#include <limits.h>
#include <fcntl.h>
#include "library_file.h"
#include "ccp4_errno.h"
#include "ccp4_file_err.h"

Functions

int ccp4_file_raw_read (CCP4File *cfile, char *buffer, size_t n_items)
int ccp4_file_raw_write (CCP4File *cfile, const char *buffer, size_t n_items)
int ccp4_file_raw_seek (CCP4File *cfile, long offset, int whence)
int ccp4_file_is_write (const CCP4File *cfile)
int ccp4_file_is_read (const CCP4File *cfile)
int ccp4_file_is_append (const CCP4File *cfile)
int ccp4_file_is_scratch (const CCP4File *cfile)
int ccp4_file_is_buffered (const CCP4File *cfile)
int ccp4_file_status (const CCP4File *cfile)
int ccp4_file_raw_setstamp (CCP4File *cfile, const size_t offset)
int ccp4_file_setstamp (CCP4File *cfile, const size_t offset)
int ccp4_file_setmode (CCP4File *cfile, const int mode)
int ccp4_file_mode (const CCP4File *cfile)
int ccp4_file_itemsize (const CCP4File *cfile)
const char * ccp4_file_name (CCP4File *cfile)
int ccp4_file_setbyte (CCP4File *cfile, const int byte_order)
int ccp4_file_byte (CCP4File *cfile)
CCP4Fileccp4_file_open_file (const FILE *file, const int flag)
CCP4Fileccp4_file_open_fd (const int fd, const int flag)
CCP4Fileccp4_file_open (const char *filename, const int flag)
int ccp4_file_close (CCP4File *cfile)
int ccp4_file_rarch (CCP4File *cfile)
int ccp4_file_warch (CCP4File *cfile)
int ccp4_file_read (CCP4File *cfile, uint8 *buffer, size_t nitems)
int ccp4_file_readcomp (CCP4File *cfile, uint8 *buffer, size_t nitems)
int ccp4_file_readshortcomp (CCP4File *cfile, uint8 *buffer, size_t nitems)
int ccp4_file_readfloat (CCP4File *cfile, uint8 *buffer, size_t nitems)
int ccp4_file_readint (CCP4File *cfile, uint8 *buffer, size_t nitems)
int ccp4_file_readshort (CCP4File *cfile, uint8 *buffer, size_t nitems)
int ccp4_file_readchar (CCP4File *cfile, uint8 *buffer, size_t nitems)
int ccp4_file_write (CCP4File *cfile, const uint8 *buffer, size_t nitems)
int ccp4_file_writecomp (CCP4File *cfile, const uint8 *buffer, size_t nitems)
int ccp4_file_writeshortcomp (CCP4File *cfile, const uint8 *buffer, size_t nitems)
int ccp4_file_writefloat (CCP4File *cfile, const uint8 *buffer, size_t nitems)
int ccp4_file_writeint (CCP4File *cfile, const uint8 *buffer, size_t nitems)
int ccp4_file_writeshort (CCP4File *cfile, const uint8 *buffer, size_t nitems)
int ccp4_file_writechar (CCP4File *cfile, const uint8 *buffer, size_t nitems)
int ccp4_file_seek (CCP4File *cfile, long offset, int whence)
void ccp4_file_rewind (CCP4File *cfile)
long ccp4_file_length (CCP4File *cfile)
long ccp4_file_tell (CCP4File *cfile)
int ccp4_file_feof (CCP4File *cfile)
void ccp4_file_clearerr (CCP4File *cfile)
void ccp4_file_fatal (CCP4File *cfile, char *message)
int ccp4_file_error (CCP4File *cfile)
void ccp4_file_flush (CCP4File *cfile)
char * ccp4_file_print (CCP4File *cfile, char *msg_start, char *msg_end)

Detailed Description

Functions for file i/o. Charles Ballard


Function Documentation

int ccp4_file_byte CCP4File   cfile
 

ccp4_file_byte:

Parameters:
cfile  (CCP4File *)
get byte ordering for file
Returns:
byte ordering information

void ccp4_file_clearerr CCP4File   cfile
 

ccp4_file_clearerr:

Parameters:
cfile  (CCP4File *)
Clears error status of @cfile.

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

int ccp4_file_error CCP4File   cfile
 

ccp4_file_error:

Parameters:
cfile  (CCP4File *)
print error mesage.
Returns:
associated error code

void ccp4_file_fatal CCP4File   cfile,
char *    message
 

ccp4_file_fatal:

Parameters:
cfile  (CCP4File *)
Die with error message based on @cfile error status.

int ccp4_file_feof CCP4File   cfile
 

ccp4_file_feof:

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

void ccp4_file_flush CCP4File   cfile
 

ccp4_file_flush:

Parameters:
cfile  (CCP4File *)
flush buffer contents of @cfile

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.

int ccp4_file_is_buffered const CCP4File   cfile
 

ccp4_file_is_buffered:

Parameters:
cfile  (CCP4File *)
is the file buffered
Returns:
1 if true

int ccp4_file_is_read const CCP4File   cfile
 

ccp4_file_is_read:

Parameters:
cfile  (CCP4File *)
is the @cfile readable
Returns:
1 if true.

int ccp4_file_is_scratch const CCP4File   cfile
 

ccp4_file_is_scratch:

Parameters:
cfile  (CCP4File *)
is scratch file
Returns:
1 if true.

int ccp4_file_is_write const CCP4File   cfile
 

ccp4_file_is_write:

Parameters:
cfile  (CCP4File *)
is the @cfile writeable
Returns:
1 if true

int ccp4_file_itemsize const CCP4File   cfile
 

ccp4_file_itemsize:

Parameters:
cfile  (CCP4File *)
Returns:
itemsize of @cfile.

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

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

const char* ccp4_file_name CCP4File   cfile
 

ccp4_file_name:

Parameters:
cfile  (CCP4File *)
strdup @cfile->name
Returns:
name of file as const char *

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

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

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

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

ccp4_file_print:

Parameters:
cfile  (CCP4File *)
Returns:
@cfile information in char array for printing.

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)

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.

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.

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.

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

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

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

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

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

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

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

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

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

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:

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.

int ccp4_file_setstamp CCP4File   cfile,
const size_t    offset
 

ccp4_file_setstamp:

Parameters:
cfile  (CCP4File *)
stamp_loc  (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

int ccp4_file_status const CCP4File   cfile
 

ccp4_file_status:

Parameters:
cfile  (CCP4File *)
Returns:
@cfile error status

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.

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

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

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

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

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

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

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

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