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

Functions

int readstr_strarr (char ***res, int len, int relax, const char *key, const char *sdata)
double readstr_num (const char *key, const char *data, char **endptr0)
int readstr_numarr (void **ret, int *nrow0, int *ncol0, int len, int relax, int type, const char *key, const char *data)
const char * trim_string (const char *header, const char **pend)
const char * search_keyword (const char *keywords, const char *key)
double search_keyword_num (const char *keywords, const char *key)
double search_keyword_num_valid (const char *keywords, const char *key)
double search_keyword_num_default (const char *keywords, const char *key, double value0)

Detailed Description

Group all routines that are used to parse values from string that contain key=value pairs.

Function Documentation

◆ readstr_strarr()

int readstr_strarr ( char *** res,
int len,
int relax,
const char * key,
const char * sdata )

Group all routines that are used to parse values from string that contain key=value pairs. Obtain a string array value from the key. String entries must be separated by coma [,]. Enclosing with quote is optional, but necessary to protect spaces. Examples: []: one empty string [,]: two empty strings [a,b]: two strings: "a" and "b"; [a,b,]: three strings, "a", "b", and "" ['a b']: one string "a b".

Parameters
[out]resResult
[in]lenmax number f values to read
[in]relaxWhether fewer entries are permitted. If true, will copy from last.
[in]keythe key that needs the value.
[in]sdataInput string

◆ readstr_num()

double readstr_num ( const char * key,
const char * data,
char ** endptr0 )

Read in a number from the value string. Will interpret +,0,*,/ operators if there is nospace in between. *endptr0 will be updated to point to the next valid entry, or at separator like coma (spaced are skipped).

Parameters
[in]keythe key that needs the value.
[in]dataInput string
[out]endptr0Location in Input string after readed number.

◆ readstr_numarr()

int readstr_numarr ( void ** ret,
int * nrow0,
int * ncol0,
int len,
int relax,
int type,
const char * key,
const char * data )

Read numerical array from a string. if len is nonzero, ret should be already allocated. NOTICe that continuous numbers are readin as column vector, not row vector(as in matlab) Can read in the following formats: [1 2 3] as 3 rows, 1 col [1 2 3] in memory [1 2 3]+2 as [3 4 5] in memory 2[1 2 3] or [1 2 3]*2 as [2 4 6] in memory [1 2 3]/2 as [0.5 1 1.5] in memory 2/[1 2 3] as [2/1 2/2 2/3] in memory 2/[1 2 3]*2+1 as [5 3 7/3] in memory

2-d arrays are groups as column vecotrs (in contrast to matlab that uses rows); semi-colon is used to separate columns. [1 2 3; 4 5 6] is 2 d array, 3 rows, 2 columns. In memory is stored as [1 2 3 4 5 6] transpose is supported: [1 2 3; 4 5 6]' is 2 d array, 2 rows, 3 columns. In memory is stored as [1 4 2 5 3 6]

when there is no [], only read until there is ';', '
', or end of str.

Returns
Number of values actually read not including duplicated when relax is set.
Parameters
[out]retResult
[out]nrow0Number of rows (nx)
[out]ncol0Number of columns (ny)
[in]lenMax number of values to read.
[in]relaxWhether fewer entries are permitted. If true, will copy from last.
[in]typeData type
[in]keythe key that needs the value.
[in]dataInput string

◆ trim_string()

const char * trim_string ( const char * start,
const char ** pend )

Return start of valid region and update pend (if set) to end of valid region. Does not modify the string

◆ search_keyword()

const char * search_keyword ( const char * keywords,
const char * key )

Search and return the value correspond to key. Case is ignored; NULL if not found. Do not free the returned pointer. The key must be preceeded by space, semicolon, coma or new line (isspace), and succeeded by = sign.

◆ search_keyword_num()

double search_keyword_num ( const char * keywords,
const char * key )

Read a number from the header with key

◆ search_keyword_num_valid()

double search_keyword_num_valid ( const char * keywords,
const char * key )

Read a number from the header and verify.

◆ search_keyword_num_default()

double search_keyword_num_default ( const char * keywords,
const char * key,
double value0 )

Read a number from the header and use value0 if not found.