#include <stdio.h>
#include "ccp4_utils.h"
#include "ccp4_spg.h"
Go to the source code of this file.
Classes | |
struct | CCP4PARSERTOKEN |
CCP4 Parser token Construct to hold the information about a single token. More... | |
struct | CCP4PARSERARRAY |
CCP4 Parser array Construct to hold the information about a parsed line. More... | |
Defines | |
#define | CCP4_PARSER_MAXLINELENGTH 200 |
#define | CCP4_PARSER_MAXFILENAMELENGTH 200 |
Functions | |
CCP4PARSERARRAY * | ccp4_parse_start (const int maxtokens) |
int | ccp4_parse_end (CCP4PARSERARRAY *parsePtr) |
int | ccp4_parse_init_token (const CCP4PARSERARRAY *parsePtr, const int itok) |
int | ccp4_parse_delimiters (CCP4PARSERARRAY *parsePtr, const char *delim, const char *nulldelim) |
int | ccp4_parse_comments (CCP4PARSERARRAY *parsePtr, const char *comment_chars) |
int | ccp4_parse_maxmin (CCP4PARSERARRAY *parsePtr, const double max_exponent, const double min_exponent) |
int | ccp4_parse_reset (CCP4PARSERARRAY *parsePtr) |
int | ccp4_parse (const char *line, CCP4PARSERARRAY *parser) |
int | ccp4_parser (char *line, const int n, CCP4PARSERARRAY *parser, const int print) |
int | ccp4_keymatch (const char *keyin1, const char *keyin2) |
char * | strtoupper (char *str1, const char *str2) |
char * | strtolower (char *str1, const char *str2) |
int | strmatch (const char *str1, const char *str2) |
int | charmatch (const char character, const char *charlist) |
int | doublefromstr (const char *str, const double max_exp, const double min_exp, double *valuePtr, double *intvaluePtr, int *intdigitsPtr, double *frcvaluePtr, int *frcdigitsPtr, double *expvaluePtr, int *expdigitsPtr) |
ccp4_symop | symop_to_rotandtrn (const char *symchs_begin, const char *symchs_end) |
const char * | symop_to_mat4 (const char *symchs_begin, const char *symchs_end, float *rot) |
ccp4_symop | mat4_to_rotandtrn (const float rsm[4][4]) |
char * | rotandtrn_to_symop (char *symchs_begin, char *symchs_end, const ccp4_symop symop) |
void | rotandtrn_to_mat4 (float rsm[4][4], const ccp4_symop symop) |
char * | mat4_to_symop (char *symchs_begin, char *symchs_end, const float rsm[4][4]) |
char * | mat4_to_recip_symop (char *symchs_begin, char *symchs_end, const float rsm[4][4]) |
#define CCP4_PARSER_MAXFILENAMELENGTH 200 |
Maximum length of file name to be parsed
#define CCP4_PARSER_MAXLINELENGTH 200 |
Maximum length of line to be parsed
int ccp4_keymatch | ( | const char * | keyin1, | |
const char * | keyin2 | |||
) |
Test whether two keywords are identical.
This function compares input strings to see if they match as CCP4-style keywords. Keywords are identical if they are the same up to the first four characters, independent of case.
keyin1 | keyword 1. | |
keyin2 | keyword 2. |
References strmatch(), and strtoupper().
Referenced by ccp4spg_load_spacegroup(), MtzGet(), and MtzParseLabin().
int ccp4_parse | ( | const char * | line, | |
CCP4PARSERARRAY * | parser | |||
) |
Parsing scanner
This is a scanner based on the old CCP4 Fortranic PARSE routine. Given a string "line", break up into tokens and store in CCP4PARSERARRAY "parser"
The function takes an input string ("line") and returns the number of tokens ("ntokens") which are delimited by certain characters (defaulted to space, tab, comma, equals - these can be changed by the application using a call to ccp4_parse_delimiters). Information about the tokens themselves is returned as members of elements in an array ("tokens") of type CCP4PARSERTOKEN (see header file for definition and members).
Substrings can be delimited by single- or double-quotes but must be surrounded by delimiters to be recognised.
An unquoted comment character (defaulted to ! or #) in the input line introduces a trailing comment which is ignored. The comment characters can be changed using a call to ccp4_parse_comments.
Null fields are denoted by two adjacent null delimiters (defaulted to comma and equals - these can be changed by the application using a call to ccp4_parse_delimiters).
line | = pointer to a null-terminated string of characters, forming the input to be processed. Unaltered on output. | |
parser | = pointer to a CCP4PARSERARRAY structure which will be used to hold the results of processing the input line. |
References ccp4_signal(), ccp4_utils_malloc(), charmatch(), CCP4PARSERARRAY::comment, CCP4PARSERARRAY::delim, doublefromstr(), CCP4PARSERTOKEN::frcdigits, CCP4PARSERTOKEN::fullstring, CCP4PARSERTOKEN::ibeg, CCP4PARSERTOKEN::iend, CCP4PARSERTOKEN::intdigits, CCP4PARSERTOKEN::isnull, CCP4PARSERTOKEN::isnumber, CCP4PARSERTOKEN::isquoted, CCP4PARSERTOKEN::isstring, CCP4PARSERARRAY::max_exponent, CCP4PARSERARRAY::maxtokens, CCP4PARSERARRAY::min_exponent, CCP4PARSERARRAY::ntokens, CCP4PARSERARRAY::nulldelim, CCP4PARSERTOKEN::strlength, CCP4PARSERARRAY::token, CCP4PARSERTOKEN::value, and CCP4PARSERTOKEN::word.
Referenced by ccp4_parser(), and ccp4fyp().
int ccp4_parse_comments | ( | CCP4PARSERARRAY * | parsePtr, | |
const char * | comment_chars | |||
) |
Set up or restore non-default comment characters.
This allows the application to set its own comment characters to be used in the ccp4_parser routines.
If a NULL pointer is supplied for the list of comment characters then the default comment characters are (re)set.
References ccp4_utils_malloc(), and CCP4PARSERARRAY::comment.
Referenced by ccp4_parse_start().
int ccp4_parse_delimiters | ( | CCP4PARSERARRAY * | parsePtr, | |
const char * | delim, | |||
const char * | nulldelim | |||
) |
Set up or restore non-default delimiter characters.
This function allows the application to set its own delimiter characters to be used in the ccp4_parser routines.
If a NULL pointer is supplied for either of the two lists then then the default delimiters are (re)set.
References ccp4_utils_malloc(), CCP4PARSERARRAY::delim, and CCP4PARSERARRAY::nulldelim.
Referenced by ccp4_parse_start(), ccp4fyp(), and ccp4spg_load_spacegroup().
int ccp4_parse_end | ( | CCP4PARSERARRAY * | parsePtr | ) |
Cleans up a CCP4PARSEARRAY
This function cleans up a CCP4PARSERARRAY after being used by ccp4_parse/ ccp4_parser functions.
parsePtr | pointer to a CCP4PARSERARRAY structure |
References CCP4PARSERARRAY::comment, CCP4PARSERARRAY::delim, CCP4PARSERTOKEN::fullstring, CCP4PARSERARRAY::maxtokens, CCP4PARSERARRAY::nulldelim, and CCP4PARSERARRAY::token.
Referenced by ccp4_parse_start(), ccp4fyp(), ccp4spg_load_spacegroup(), MtzGet(), and MtzParseLabin().
int ccp4_parse_init_token | ( | const CCP4PARSERARRAY * | parsePtr, | |
const int | itok | |||
) |
Initialise a token in a parser array
This function initialise a single token in CCP4PARSERARRAY before use. It sets all string members of the specified token to NULL and all numerical values (including flags) to zero
References CCP4PARSERTOKEN::fullstring, CCP4PARSERTOKEN::ibeg, CCP4PARSERTOKEN::iend, CCP4PARSERTOKEN::isnull, CCP4PARSERTOKEN::isnumber, CCP4PARSERTOKEN::isquoted, CCP4PARSERTOKEN::isstring, CCP4PARSERARRAY::token, CCP4PARSERTOKEN::value, and CCP4PARSERTOKEN::word.
Referenced by ccp4_parse_reset().
int ccp4_parse_maxmin | ( | CCP4PARSERARRAY * | parsePtr, | |
const double | max_exponent, | |||
const double | min_exponent | |||
) |
Set non-default maximum and minimum values for numerical tokens.
This allows the application to set its own maximum and minimum exponent values, which are used as limits when evaluating the values of numerical tokens in order to avoid over/underflow.
References CCP4PARSERARRAY::max_exponent, and CCP4PARSERARRAY::min_exponent.
Referenced by ccp4_parse_start().
int ccp4_parse_reset | ( | CCP4PARSERARRAY * | parsePtr | ) |
Reinitialise a parser array before calling ccp4_parse
Call this function to initialise CCP4PARSERARRAY before use (includes calls to ccp4_parse_init_token to initialise all tokens).
An application using ccp4_parse (rather than ccp4_parser, which also calls this function) can call this function to reset the parser array, rather than reinitialising the structure members explicitly
References ccp4_parse_init_token(), CCP4PARSERARRAY::maxtokens, and CCP4PARSERARRAY::ntokens.
Referenced by ccp4_parse_start(), ccp4_parser(), and ccp4fyp().
CCP4PARSERARRAY* ccp4_parse_start | ( | const int | maxtokens | ) |
Initialise a CCP4PARSERARRAY
This function initialises a CCP4PARSERARRAY to be used in subsequent calls to ccp4_parser routines. The calling function must supply the maximum number of tokens on a line (including continuation lines).
maxtokens | maximum number of tokens on a line |
References ccp4_parse_comments(), ccp4_parse_delimiters(), ccp4_parse_end(), ccp4_parse_maxmin(), ccp4_parse_reset(), ccp4_utils_malloc(), CCP4PARSERARRAY::comment, CCP4PARSERARRAY::delim, CCP4PARSERARRAY::fp, CCP4PARSERTOKEN::fullstring, CCP4PARSERARRAY::maxtokens, CCP4PARSERARRAY::nulldelim, and CCP4PARSERARRAY::token.
Referenced by ccp4fyp(), ccp4spg_load_spacegroup(), MtzGet(), and MtzParseLabin().
int ccp4_parser | ( | char * | line, | |
const int | nchars, | |||
CCP4PARSERARRAY * | parser, | |||
const int | ||||
) |
The main function for parsing lines
ccp4_parser is the main function for reading lines, either supplied or read from stdin. It is based on the old CCP4 Fortranic PARSER routine. The function reads input from stdin or external file, breaks it up into tokens that are stored in CCP4PARSERARRAY "parser".
The normal behaviour is to read "keyworded" data from the input stream, and interpret it. Stdin is the default, but a line starting with <name> starts reading from file <name> until eof.
Each input line may be continued on the next line by the continuation characters `&', `-' or `\' at the end of the input line. This character is dropped from the list returned to the calling application.
Pass in a zero length line to force reading from the command line. nchars is the maximum number of characters which will be read into the line. (If line is not blank then it will be processed and more input read in if it ends in a continuation character, or forces reading from an external file.)
The "print" argument should be supplied as 0 to suppress echoing of the input lines to standard output.
ccp4_parser returns the number of tokens parsed in the input line. The results of the parsing are stored as members of the CCP4PARSEARRAY structure "parser" and can be accessed by the application program.
line | pointer to a null-terminated string of characters, forming the input to be processed. On input can either be an empty string ("") which forces reading from stdin, or contain characters to be processed. On output "line" will be overwritten with the actual input line, up to nchar characters. | |
nchars | maximum number of characters that can be read into "line" i.e. the size of "line" in memory. | |
parser | pointer to a CCP4PARSERARRAY structure which will be used to hold the results of processing the input line. | |
flag controlling echoing of input lines to stdout. print=0: suppress echoing of lines to stdout. Otherwise echoing is turned on. |
References ccp4_parse(), ccp4_parse_reset(), ccp4_signal(), ccp4_utils_malloc(), CCP4PARSERARRAY::fp, CCP4PARSERTOKEN::ibeg, CCP4PARSERARRAY::keyword, CCP4PARSERARRAY::ntokens, strmatch(), strtoupper(), CCP4PARSERARRAY::token, and CCP4PARSERTOKEN::word.
Referenced by ccp4spg_load_spacegroup(), MtzGet(), and MtzParseLabin().
int charmatch | ( | const char | character, | |
const char * | charlist | |||
) |
Match characters
[in] | character | character to find |
[in] | charlist | string to search in |
Referenced by ccp4_parse().
int doublefromstr | ( | const char * | str, | |
const double | max_exp, | |||
const double | min_exp, | |||
double * | valuePtr, | |||
double * | intvaluePtr, | |||
int * | intdigitsPtr, | |||
double * | frcvaluePtr, | |||
int * | frcdigitsPtr, | |||
double * | expvaluePtr, | |||
int * | expdigitsPtr | |||
) |
Convert a string representation of a number into the number.
Determine whether string represents a valid number, and return the numerical value if it is. The function also checks for exponent over/underflow, returns numbers of digits and values of "components" (integer and fractional parts, and base-10 exponent) The function returns 1 for a valid number, 0 otherwise.
Valid numbers are represented by: ^[+-]?[0-9]*\.?[0-9]*[Ee]?[+-]?[0-9]*$ (I think this is the correct regular expression...? -pjx)
The component parts are: an integer part representing the value of the number upto the decimal point; a decimal fraction representing the value of the number upto the base-10 exponent; a base-10 exponent. The full value of the string is then int_part + frac_part * 10^(exp_part)
The value of each component is returned separately via the argument list. The number of "digits" (= number of characters in the string) of each component are also returned - note that these include non- significant digits such as leading zeroes in the integer part, but non-numeric characters (+-eE) are not counted.
The function can also trap for large or small exponents, to avoid overflow or underflow. The maximum and minimum allowed exponents are supplied by the calling application as the arguments max_exp and min_exp. (Values can be be taken from float.h). In the event of the limits being exceeded, only the values of the components are evaluated; the total value of the number is returned as zero.
References ccp4_signal().
Referenced by ccp4_parse().
char* mat4_to_recip_symop | ( | char * | symchs_begin, | |
char * | symchs_end, | |||
const float | rsm[4][4] | |||
) |
Convert symmetry operator as matrix to string in reciprocal space notation.
This is Charles' version of symtr. Note that translations are held in elements [*][3] and [3][3] is set to 1.0
symchs_begin | pointer to beginning of string | |
symchs_end | pointer to end of string (i.e. last character is *(symchs_end-1) ) | |
rsm | 4 x 4 matrix operator |
References ccp4_utils_malloc(), and mat4_to_symop().
Referenced by ccp4spg_print_recip_ops().
ccp4_symop mat4_to_rotandtrn | ( | const float | rsm[4][4] | ) |
Convert symmetry operator as matrix to string.
This is Charles' version of symtr. Note that translations are held in elements [*][3] and [3][3] is set to 1.0.
rsm | 4 x 4 matrix operator |
References ccp4_symop_::rot, and ccp4_symop_::trn.
Referenced by ccp4_symop_invert(), ccp4spg_load_spacegroup(), and symop_to_rotandtrn().
char* mat4_to_symop | ( | char * | symchs_begin, | |
char * | symchs_end, | |||
const float | rsm[4][4] | |||
) |
Convert symmetry operator as matrix to string.
Note that translations are held in elements [*][3] and [3][3] is set to 1.0
symchs_begin | pointer to beginning of string | |
symchs_end | pointer to end of string (i.e. last character is *(symchs_end-1) ) | |
rsm | 4 x 4 matrix operator |
References ccp4_signal().
Referenced by ccp4_lhprt(), mat4_to_recip_symop(), MtzPut(), and rotandtrn_to_symop().
void rotandtrn_to_mat4 | ( | float | rsm[4][4], | |
const ccp4_symop | symop | |||
) |
Convert rotation/translation string to 4x4 matrix data structure.
rsm | 4x4 matrix | |
symop |
References ccp4_symop_::rot, and ccp4_symop_::trn.
Referenced by ccp4_symop_invert(), and rotandtrn_to_symop().
char* rotandtrn_to_symop | ( | char * | symchs_begin, | |
char * | symchs_end, | |||
const ccp4_symop | symop | |||
) |
Convert rotation/translation string to symmetry operator.
symchs_begin | pointer to beginning of string | |
symchs_end | pointer to end of string (i.e. last character is *(symchs_end-1) ) | |
symop |
References mat4_to_symop(), and rotandtrn_to_mat4().
int strmatch | ( | const char * | str1, | |
const char * | str2 | |||
) |
Compare two strings.
This function checks if character appears in a list of possibilities.
Referenced by ccp4_keymatch(), ccp4_parser(), and ccp4setenv().
char* strtolower | ( | char * | str1, | |
const char * | str2 | |||
) |
Convert string to lowercase.
str1 | On exit str1 will contain lowercased copy of str2 | |
str2 | Input string |
char* strtoupper | ( | char * | str1, | |
const char * | str2 | |||
) |
Convert string to uppercase.
str1 | On exit str1 will contain uppercased copy of str2 | |
str2 | Input string |
Referenced by ccp4_keymatch(), ccp4_parser(), ccp4fyp(), ccp4spg_name_equal(), ccp4spg_name_equal_to_lib(), and ccp4spg_pgname_equal().
const char* symop_to_mat4 | ( | const char * | symchs_begin, | |
const char * | symchs_end, | |||
float * | rot | |||
) |
Convert symmetry operator as string to matrix.
Translates a single symmetry operator string into a 4x4 quine matrix representation. NB! Uses a utility function (symop_to_mat4_err) when reporting failures.
Syntax of possible symop strings:
real space symmetry operations, e.g. X+1/2,Y-X,Z reciprocal space operations, e.g. h,l-h,-k reciprocal axis vectors, e.g. a*+c*,c*,-b* real space axis vectors, e.g. a,c-a,-b
The strings can contain spaces, and the coordinate and translation parts may be in either order.
The function returns 1 on success, 0 if there was a failure to generate a matrix representation.
symchs_begin | pointer to beginning of string | |
symchs_end | pointer to end of string (i.e. last character is *(symchs_end-1) ) | |
rot | 4 x 4 matrix operator |
References ccp4_signal().
Referenced by ccp4spg_load_spacegroup(), MtzGet(), and symop_to_rotandtrn().
ccp4_symop symop_to_rotandtrn | ( | const char * | symchs_begin, | |
const char * | symchs_end | |||
) |
Convert symmetry operator as string to ccp4_symop struct.
symchs_begin | pointer to beginning of string | |
symchs_end | pointer to end of string (i.e. last character is *(symchs_end-1) ) |
References mat4_to_rotandtrn(), and symop_to_mat4().