MAOS
Multithreaded Adaptive Optics Simulator
Loading...
Searching...
No Matches
cell.h File Reference

Macros

#define cellfree(A)
#define writebin_async(A, ncol)

Functions

cell * cellnew (long nx, long ny)
cell * cellref (const_anyarray in)
uint32_t cellhash (const_anyarray A, uint32_t key)
cell * cellconvert (cell *A, cell *(*fun_convert)(cell *))
int cellinit (panyarray A, long nx, long ny)
void cellinit2 (panyarray A, const_anyarray B)
void celldim (const_anyarray A_, long *nx, long *ny, long **nxs, long **nys)
void cellresize (anyarray in, long nx, long ny)
int cell_is_diag (const_anyarray A)
void cellfree_do (anyarray dc)
void writedata (file_t *fd, const_anyarray A, long ncol)
void writebin (const_anyarray dc, const char *format,...)
cell * readdata (file_t *fp, M_ID id, header_t *header)
cell * readbin_fp (file_t *fp, M_ID id, int level)
cell * readbin_id (M_ID id, int level, const char *format,...)
cell * readbin (const char *format,...)
void writecell_async (const_anyarray A, long ncol)
void writebin_header (anyarray dc, const char *keywords, const char *format,...)
cell * readsock (int sock)
void writesock (const_anyarray dc, int sock)

Detailed Description

Function for a generic cell. Cast a typed cell (dcell, ccell, ...) to cell* to use them.

Macro Definition Documentation

◆ cellfree

#define cellfree ( A)
Value:
if(A){cellfree_do(A); A=NULL;}

free a cell array and zero the pointer.

◆ writebin_async

#define writebin_async ( A,
ncol )
Value:
writecell_async(A, ncol)

Function Documentation

◆ cellnew()

cell * cellnew ( long nx,
long ny )

Create a generic cell array.

Parameters
[in]nxNumber of rows. Negative is treated as 0.
[in]nyNumber of columns. Negative is treated as 0.
Returns
Newly allocated cell array with NULL elements; the caller frees it with cellfree().

◆ cellref()

cell * cellref ( const_anyarray in)

Construct a reference base on type. Cell arrays are recreated with each element referenced.

Parameters
[in]inArray or cell array to reference.
Returns
Newly allocated reference sharing the data with in; the caller frees it. NULL if in is NULL.

◆ cellhash()

uint32_t cellhash ( const_anyarray in,
uint32_t key )

Compute a hash of the numerical content of array or cell array in (recursively) using key as the seed. Returns the updated key. Sparse arrays are skipped.

Parameters
[in]inArray or cell array.
[in]keySeed of the hash.
Returns
The updated hash key.

◆ cellconvert()

cell * cellconvert ( cell * A,
cell *(* fun_convert )(cell *) )

Convert elements of cell array in place.

Parameters
[in,out]AArray or cell array whose (non-cell) elements are replaced by the result of fun_convert.
[in]fun_convertConversion function. It takes ownership of its input and returns the converted array.
Returns
The converted array (A itself if A is a cell array). NULL if A is NULL.

◆ cellinit()

int cellinit ( panyarray A_,
long nx,
long ny )

check the size of cell array if exist. Otherwise create it

Parameters
[in,out]A_Pointer to the cell array. Created if NULL, otherwise its type and size are checked.
[in]nxNumber of rows.
[in]nyNumber of columns.
Returns
0 on success, -1 if the existing cell array does not match.

◆ cellinit2()

void cellinit2 ( panyarray A_,
const_anyarray B_ )

check the size of cell array if exist. Otherwise create it with the same layout as B. m is created for dcell

Parameters
[in,out]A_Pointer to the cell array. Created if NULL, otherwise its type and size are checked.
[in]B_The reference cell array. Must be a cell.

◆ celldim()

void celldim ( const_anyarray A_,
long * nx,
long * ny,
long ** nxs,
long ** nys )

Obtain the dimensions of the dense matrix assembled from cell array A. nx, ny are the total rows and columns. *nxs and *nys are allocated (caller frees) to contain the number of rows of each cell row and columns of each cell column. Cells along a row (column) must have the same number of rows (columns).

Parameters
[in]A_The cell array.
[out]nxTotal number of rows.
[out]nyTotal number of columns.
[out]nxsNewly allocated number of rows of each cell row; the caller frees it. NULL if A is empty.
[out]nysNewly allocated number of columns of each cell column; the caller frees it. NULL if A is empty.

◆ cellresize()

void cellresize ( anyarray A_,
long nx,
long ny )

Resize a generic cell array. Elements outside of the new size are freed and new elements are NULL.

Parameters
[in,out]A_The cell array. Must be valid and with m unset.
[in]nxNew number of rows.
[in]nyNew number of columns.

◆ cell_is_diag()

int cell_is_diag ( const_anyarray A_)

Check whether the cell has only diagonal entries.

Parameters
[in]A_The cell array.
Returns
1 if all off diagonal elements are empty, 0 otherwise or if A_ is not a cell array.

◆ cellfree_do()

void cellfree_do ( anyarray A_)

free a mat or cell object.

Parameters
[in,out]A_The object to free (recursively for cell arrays). May be NULL.

◆ writedata()

void writedata ( file_t * fp,
const_anyarray A_,
long ncol )

Write array or cell array to file.

Parameters
[in]fpFile to write to. Must be NULL when ncol>0.
[in]A_Array or cell array to write.
[in]ncol0: normal writing. -1: initialize async data. >0: async writing of the first ncol columns.

◆ writebin()

void writebin ( const_anyarray A,
const char * format,
... )

Write array or cell array A to file with name given by the printf-style format. Does nothing if the file name is empty or cannot be opened.

Parameters
[in]AArray or cell array to write.
[in]formatprintf-style format of the file name.

◆ readdata()

cell * readdata ( file_t * fp,
M_ID id,
header_t * header )

Read a block which may be cell array or basic arrys. do not scan. id is intended only for the fundamental data. header is read first if header==0 or header->id==0.

Parameters
[in]fpFile to read from.
[in]idRequested type of the fundamental data. 0 to use the type in the file.
[in,out]headerHeader of the block. May be NULL. Its str is taken by the returned cell array.
Returns
Newly allocated data; the caller frees it. NULL if empty or if reading fails.

◆ readbin_fp()

cell * readbin_fp ( file_t * fp,
M_ID id,
int level )

Read array or cell array from an opened file, socket, or pipe, like readbin_id().

Parameters
[in]fpFile to read from, e.g., from zfdopen_as().
[in]idRequested fundamental data type. 0 for native.
[in]levelCell nesting level, see readdata_auto(). -1 to detect automatically.
Returns
Newly allocated data; the caller frees it. NULL if empty or if reading fails.

◆ readbin_id()

cell * readbin_id ( M_ID id,
int level,
const char * format,
... )

Read array or cell array from file with name given by the printf-style format. id is the requested fundamental data type (converted if necessary, 0 for native), level is the cell nesting level, see readdata_auto(). Returns NULL if the file cannot be opened. The caller owns the result.

Parameters
[in]idRequested fundamental data type. 0 for native.
[in]levelCell nesting level, see readdata_auto().
[in]formatprintf-style format of the file name.
Returns
Newly allocated data; the caller frees it. NULL if the file cannot be opened.

◆ readbin()

cell * readbin ( const char * format,
... )

Read any data from file with automatic type and nesting detection. The caller needs to cast the result and free it.

Parameters
[in]formatprintf-style format of the file name.
Returns
Newly allocated data; the caller frees it. NULL if the file cannot be opened.

◆ writecell_async()

void writecell_async ( const_anyarray A,
long ncol )

Asynchronously write data to the file previously initialized with writedata() with ncol=-1.

Parameters
[in]AArray or cell array to write.
[in]ncolNumber of columns that are ready to write. Must not be 0.

◆ writebin_header()

void writebin_header ( anyarray Ac_,
const char * keywords,
const char * format,
... )

A generic routine for write data to file with separate keywords

Parameters
[in,out]Ac_Array or cell array to write; its keywords are replaced by keywords if not NULL.
[in]keywordsKeywords to write.
[in]formatprintf-style format of the file name.

◆ readsock()

cell * readsock ( int sock)

A generic routine for reading data from socket. User need to cast the result. We dup the fd to avoid close it after read.

Parameters
[in]sockThe socket.
Returns
Newly allocated data; the caller frees it. NULL on failure.

◆ writesock()

void writesock ( const_anyarray A,
int sock )

A generic routine for write data to socket. We dup the fd to avoid close it after read.

Parameters
[in]AArray or cell array to write.
[in]sockThe socket.