MAOS
Multithreaded Adaptive Optics Simulator
|
Data Structures | |
struct | header_t |
union | header_t.__unnamed__ |
Macros | |
#define | M_INT M_INT32 |
#define | M_STR M_INT8 |
#define | M_SPINT M_INT |
#define | M_DSP M_DSP32 |
#define | M_CSP M_CSP32 |
#define | M_SSP M_SSP32 |
#define | M_ZSP M_ZSP32 |
#define | IS_SHM(name) (name && ((name[0]=='/' && !strchr(name+1, '/')) || !mystrcmp(name, "/shm"))) |
Typedefs | |
typedef int | spint |
Functions | |
int | zfexist (const char *format,...) |
saving to disk will be disabled when set to nonzero. More... | |
void | zftouch (const char *format,...) |
int | zfeof (file_t *fp) |
long | zfpos (file_t *fp) |
long | zfseek (file_t *fp, long offset, int whence) |
void | zfrewind (file_t *fp) |
long | zflen (file_t *fp) |
file_t * | zfopen (const char *fn, const char *mod) |
file_t * | zfdopen (int fd) |
const char * | zfname (file_t *fp) |
int | zfisfits (file_t *fp) |
void | zfclose (file_t *fp) |
int | zfwrite (const void *ptr, const size_t size, const size_t nmemb, file_t *fp) |
int | zfread (void *ptr, const size_t size, const size_t nmemb, file_t *fp) |
int | zferrno (file_t *fp) |
uint64_t | bytes_header (const char *keywords) |
void | write_timestamp (file_t *fp) |
void | write_header (const header_t *header, file_t *fp) |
int | read_header (header_t *header, file_t *fp) |
long | writearr (const void *fpn, const int isfile, const size_t size, const uint32_t magic, const char *keywords, const void *p, const uint64_t nx, const uint64_t ny) |
struct mem_t * | mem_new (void *p) __attribute__((warn_unused_result)) |
void | mem_unref (mem_t **in) |
mem_t * | mem_ref (mem_t *in) __attribute__((warn_unused_result)) |
void | mem_replace (mem_t *in, void *p) |
int | mem_nref (const mem_t *in) |
void * | mem_p (const mem_t *in) |
mem_t * | mmap_open (const char *fn, size_t msize, int rw) |
void | mmap_write_header (char **p0, uint32_t magic, long nx, long ny, const char *keywords) |
void | mmap_read_header (char **p0, uint32_t *magic, long *nx, long *ny, const char **pkeywords) |
async_t * | async_init (file_t *fp, const size_t size, const uint32_t magic, const char *str, const void *p, const uint64_t nx, const uint64_t ny) |
void | async_write (async_t *async, long offset, int wait) |
void | async_free (async_t *async) |
Defines our custom file format .bin that may be gzipped and the basic IO functions. All file read/write operators are through functions in this file. The routines can also operate on .fits files.
struct header_t |
Data Fields | ||
---|---|---|
union header_t | __unnamed__ | |
uint64_t | nx | |
uint64_t | ny | |
char * | str |
union header_t.__unnamed__ |
int zfexist | ( | const char * | format, |
... | |||
) |
saving to disk will be disabled when set to nonzero.
Test whether a bin file exist.
void zftouch | ( | const char * | format, |
... | |||
) |
Update the modification time of a bin file.
int zfeof | ( | file_t * | fp | ) |
Return 1 if end of file is reached.
long zfpos | ( | file_t * | fp | ) |
Tell position pointer in file.
void zfrewind | ( | file_t * | fp | ) |
Move the file position pointer to the beginning
long zflen | ( | file_t * | fp | ) |
Return file length
file_t* zfopen | ( | const char * | fni, |
const char * | mod | ||
) |
Open a bin file for read/write access.
Whether the file is gzipped or not is automatically determined when open for reading. When open for writing, if the file name ends with .bin or .fits, will not be gzipped. If the file has no suffix, the file will be gzipped and .bin is appened to file name.
const char* zfname | ( | file_t * | fp | ) |
Open a bin file or socket for read/write access.
Whether the file is gzipped or not is automatically determined when open for reading. When open for writing, if the file name ends with .bin or .fits, will not be gzipped. If the file has no suffix, the file will be gzipped and .bin is appened to file name. Return the underlining filename
int zfisfits | ( | file_t * | fp | ) |
Return 1 when it is a fits file.
void zfclose | ( | file_t * | fp | ) |
Close the file.
int zfwrite | ( | const void * | ptr, |
const size_t | size, | ||
const size_t | nmemb, | ||
file_t * | fp | ||
) |
Handles byteswapping in fits file format then call zfwrite_do to do the actual writing.
int zfread | ( | void * | ptr, |
const size_t | size, | ||
const size_t | nmemb, | ||
file_t * | fp | ||
) |
Handles byteswapping in fits file format then call zfread_do to do the actual writing. return 0 when succeed and -1 when error.
int zferrno | ( | file_t * | fp | ) |
Return the error number
uint64_t bytes_header | ( | const char * | keywords | ) |
Get the length of mem to storge the header and its dimension, rounded to multiple of 8.
void write_header | ( | const header_t * | header, |
file_t * | fp | ||
) |
A unified header writing routine for .bin and .fits files. It write the array information and string header if any.
int read_header | ( | header_t * | header, |
file_t * | fp | ||
) |
A unified header reading routine for .bin and .fits files. It read the array information and string header if any. Return non zero value if reading failed
long writearr | ( | const void * | fpn, |
const int | isfn, | ||
const size_t | size, | ||
const uint32_t | magic, | ||
const char * | str, | ||
const void * | p, | ||
const uint64_t | nx, | ||
const uint64_t | ny | ||
) |
Check whether the header refers to a cell. If yes, return NULL. nx, ny are assigned to the dimension.
Write the time stamp as header into current location in the file. Write an 1-d or 2-d array into the file. First write a magic number that represents the data type. Then write two numbers representing the dimension. Finally write the data itself.
returns the file offset of the array start
[in] | fpn | The file pointer |
[in] | isfn | Is this a filename or already opened file |
[in] | size | Size of each element |
[in] | magic | The magic number. see bin.h |
[in] | str | The header as string |
[in] | p | The data of the array |
[in] | nx | Number of rows. this index changes fastest |
[in] | ny | Number of columns. 1 for vector |
struct mem_t* mem_new | ( | void * | p | ) |
Create a mem_t object.
Notice that nref is set to 0. Default is set to reference heap memory.
void mem_unref | ( | mem_t ** | pin | ) |
Unreference the mmaped memory. When the reference drops to zero free or unmap it.
mem_t* mem_ref | ( | mem_t * | in | ) |
Add a reference to a mem_t.
void mem_replace | ( | mem_t * | in, |
void * | p | ||
) |
Replace internal vector. If p is null, checking only. Use with care.
int mem_nref | ( | const mem_t * | in | ) |
Check whether it is a referenced data.
void* mem_p | ( | const mem_t * | in | ) |
Return internal pointer
mem_t* mmap_open | ( | const char * | fn, |
size_t | msize, | ||
int | rw | ||
) |
Open a file for write with mmmap. We don't provide an access control here for generic usage of the function. Lock on a special dummy file for access control.
Initialize the header in the mmaped file. If header is not null, header0 points to its location in mmaped file. Upon exit, p0 points to the location of data p.
void mmap_read_header | ( | char ** | p0, |
uint32_t * | magic, | ||
long * | nx, | ||
long * | ny, | ||
const char ** | pkeywords | ||
) |
Initialize the dimension from the header in the mmaped file.
async_t* async_init | ( | file_t * | fp, |
const size_t | size, | ||
const uint32_t | magic, | ||
const char * | str, | ||
const void * | p, | ||
const uint64_t | nx, | ||
const uint64_t | ny | ||
) |
Allocates space in fp for our block of data by writing header first and skip to the end of data offset. It has the same interface as writearr except only fp is allowed Use aio_* api if USE_ASYNC is set, otherwise use pwrite() aio_* api launches threads for async writing. pwrite is much simpler for our usecase. There is no impact on simulation step timing. we don't use mmap to write to file as it causes excessive traffic to NFS file system.
void async_write | ( | async_t * | async, |
long | offset, | ||
int | wait | ||
) |
Wait until previous async write are finished. Write to file asynchronously. offset is the end of block that is ready to write.