![]() |
Bsoft 2.1.4
Bernard's software package
|
Parse and interpret STAR format files. More...
#include "rwstar.h"
#include "linked_list.h"
#include "file_util.h"
#include "utilities.h"
#include <iostream>
#include <stdarg.h>
Functions | |
char * | clean_line (char *string) |
string | clean_line (string s) |
int | no_square_brackets (Bstar_old *star) |
bool | tag_compare (Bstring item_tag, Bstring tag) |
Bstar_old * | init_star () |
Creates a STAR data base. More... | |
int | kill_star (Bstar_old *star) |
Destroys a STAR data base. More... | |
int | kill_block (Bstar_block *block) |
Destroys a STAR data block. More... | |
int | kill_item (Bstar_item *item) |
Destroys an item in a data block in a STAR data base. More... | |
int | read_star (const char *filename, Bstar_old *star) |
Reads paramaters and data into a STAR data base from a list of files. More... | |
int | read_star (Bstring &filename, Bstar_old *star) |
int | read_star (Bstring *file_list, Bstar_old *star) |
Bstar_block * | read_block (ifstream *fstar, char *aptr, Bstring &filename) |
Reads paramaters and data into a STAR data block from an open file. More... | |
Bstar_item * | read_single_item (ifstream *fstar, char *aline) |
Reads a single-valued item or comment line into a STAR data block from an open file. More... | |
Bstar_item * | read_loop_items (ifstream *fstar) |
Reads a loop structure with multiple items into a STAR data block from an open file. More... | |
int | write_star (const char *filename, Bstar_old *star) |
Writes a STAR data base to one or more STAR format files. More... | |
int | write_star (Bstring &filename, Bstar_old *star) |
int | write_block (ofstream *fstar, Bstar_block *block, int linelength) |
Writes paramaters and data from a STAR data block into an open file. More... | |
int | star_update_comment (Bstar_old *star, int n, char **strings) |
Puts a set of strings and time in the main comment of the STAR data base. More... | |
long | star_list_comments (Bstar_old *star, long len) |
Lists the command lines in the STAR header. More... | |
int | star_set_string_lengths (Bstar_old *star) |
Sets the maximum string lengths for each item in each block. More... | |
int | item_change_tag (Bstar_old *star, const char *tag, const char *newtag) |
Replaces one tag with another in the STAR data base. More... | |
int | show_tags (Bstar_old *star) |
Prints the list of tags in the STAR data base. More... | |
int | item_index (Bstar_block *block, const char *tag) |
Gets the STAR item associated with a tag in a STAR data block. More... | |
Bstar_block * | block_find_with_tag (Bstar_old *star, const char *tag) |
Gets the first block associated with a tag in a STAR data base. More... | |
Bstar_item * | item_find (Bstar_block *block, Bstring tag) |
Gets the STAR item associated with a tag in a STAR data block. More... | |
Bstar_item * | item_find_or_make (Bstar_block *block, const char *tag) |
Gets the STAR item associated with a tag in a STAR data block. More... | |
long | item_get_number (Bstar_old *star, const char *tag) |
Gets the number of values associated with a tag in a STAR data base. More... | |
long | item_get_number_for_block (Bstar_block *block, const char *tag) |
Gets the number of values associated with a tag in a STAR data block. More... | |
char * | item_get_string (Bstar_block *block, const char *tag) |
Gets a string value associated with a tag in a STAR data block. More... | |
int | item_copy_string (char *string, Bstar_block *block, const char *tag) |
Copies a string value associated with a tag in a STAR data block. More... | |
int | item_get_integer (Bstar_block *block, const char *tag) |
Gets an integer value associated with a tag in a STAR data block. More... | |
float | item_get_float (Bstar_block *block, const char *tag) |
Gets a floating point value associated with a tag in a STAR data block. More... | |
int | item_put_string (Bstar_block *block, const char *tag, char *string) |
Writes a string into a data item associated with a specific data block and tag in a STAR data base. More... | |
int | item_put_string (Bstar_block *block, const char *tag, Bstring &string) |
int | item_put_string_list (Bstar_block *block, const char *tag, Bstring *list) |
Writes a list of strings into a data item associated with a specific data block and tag in a STAR data base. More... | |
int | item_put_integer (Bstar_block *block, const char *tag, int value, const char *format) |
Writes a integer into a data item associated with a specific data block and tag in a STAR data base. More... | |
int | item_put_float (Bstar_block *block, const char *tag, float value, const char *format) |
Writes a floating point value into a data item associated with a specific data block and tag in a STAR data base. More... | |
int | item_put_list (Bstar_block *block, const char *tag, char *list, size_t offset, const char *format) |
Writes a list of string or numeric values into a data item associated with a specific data block and tag in a STAR data base. More... | |
int | item_put_float_array (Bstar_block *block, const char *tag, int number, float *value, const char *format) |
Writes a list of floating point numbers into a data item associated with a specific data block and tag in a STAR data base. More... | |
int | item_put_angle_list (Bstar_block *block, const char *tag, char *list, size_t offset, const char *format) |
Writes a list of angular values in degrees into a data item associated with a specific data block and tag in a STAR data base. More... | |
int | item_list (Bstar_old *star, Bstring &tag) |
Lists all items associated with a given tag from the STAR data base. More... | |
int | item_delete_all (Bstar_old *star, const char *tag) |
Deletes all items associated with a given tag from the STAR data base. More... | |
int | item_delete_from_block (Bstar_block *block, const char *tag) |
Deletes an item associated with a given tag from a block in the STAR data base. More... | |
int | block_delete (Bstar_old *star, Bstring &tag) |
Deletes all blocks with a given tag from the STAR data base. More... | |
int | item_integer_scale_shift (Bstar_old *star, Bstring &tag, int iscale, int ishift) |
Scales and shifts all items associated with a given tag from the STAR data base. More... | |
int | item_float_scale_shift (Bstar_old *star, Bstring &tag, float scale, float shift) |
Scales and shifts all items associated with a given tag from the STAR data base. More... | |
int | loop_set_identifier (Bstar_block *block, int loop, int n,...) |
Assigns a loop identification number to items. More... | |
int | item_get_format (Bstar_item *item, char *format) |
Gets the format from the item. More... | |
Variables | |
int | verbose |
Parse and interpret STAR format files.
Deletes all blocks with a given tag from the STAR data base.
*star | the STAR database. |
&tag | tag for blocks to be deleted. |
The blocks containing a given tag are deleted and the block pointers are rearranged to fill in the gap.
Bstar_block * block_find_with_tag | ( | Bstar_old * | star, |
const char * | tag | ||
) |
Gets the first block associated with a tag in a STAR data base.
*star | the STAR data base. |
*tag | a STAR tag string. |
char * clean_line | ( | char * | string | ) |
string clean_line | ( | string | s | ) |
Bstar_old * init_star | ( | ) |
Creates a STAR data base.
A STAR structure is allocated. This function should be called before reading a STAR file, or before composing a STAR database for writing.
int item_change_tag | ( | Bstar_old * | star, |
const char * | tag, | ||
const char * | newtag | ||
) |
Replaces one tag with another in the STAR data base.
*star | the STAR database. |
*tag | old tag. |
*newtag | new tag. |
The item with a given tag has the tag replaced with a new one. If an item with the new tag exists, it is deleted first.
int item_copy_string | ( | char * | string, |
Bstar_block * | block, | ||
const char * | tag | ||
) |
Copies a string value associated with a tag in a STAR data block.
*string | destination string - must exist on stack or allocated. |
*block | block in the STAR database. |
*tag | a STAR tag string. |
The STAR data blocks is traversed to obtain the string value associated with a STAR tag defined in a header file.
int item_delete_all | ( | Bstar_old * | star, |
const char * | tag | ||
) |
Deletes all items associated with a given tag from the STAR data base.
*star | the STAR database. |
*tag | tag for items to be deleted. |
The item with a given tag is deleted in all blocks it is found and the item pointers are rearranged to fill in the gap.
int item_delete_from_block | ( | Bstar_block * | block, |
const char * | tag | ||
) |
Deletes an item associated with a given tag from a block in the STAR data base.
*block | block in the STAR database. |
*tag | tag for items to be deleted. |
The item with a given tag is deleted in the specified block it is found and the item pointers are rearranged to fill in the gap.
Bstar_item * item_find | ( | Bstar_block * | block, |
Bstring | tag | ||
) |
Gets the STAR item associated with a tag in a STAR data block.
*block | a STAR data block. |
*tag | a STAR tag string. |
The items in the STAR data block are traversed to find the item associated with a STAR tag defined in a header file.
Bstar_item * item_find_or_make | ( | Bstar_block * | block, |
const char * | tag | ||
) |
Gets the STAR item associated with a tag in a STAR data block.
*block | a STAR data block. |
*tag | a STAR tag string. |
The items in the STAR data block are traversed to find the item associated with a STAR tag defined in a header file.
Scales and shifts all items associated with a given tag from the STAR data base.
*star | the STAR database. |
&tag | tag for items to be modified. |
scale | multiplier. |
shift | value added. |
The item must be numeric and is modified as: new_value = old_value*scale + shift.
float item_get_float | ( | Bstar_block * | block, |
const char * | tag | ||
) |
Gets a floating point value associated with a tag in a STAR data block.
*block | block in the STAR database. |
*tag | a STAR tag string. |
The STAR data block is traversed to obtain the floating point value associated with a STAR tag defined in a header file.
int item_get_format | ( | Bstar_item * | item, |
char * | format | ||
) |
Gets the format from the item.
*item | STAR item. |
*format | pointer to pre-allocated format string (modified). |
Returns the format in the given format string.
int item_get_integer | ( | Bstar_block * | block, |
const char * | tag | ||
) |
Gets an integer value associated with a tag in a STAR data block.
*block | block in the STAR database. |
*tag | a STAR tag string. |
The STAR data block is traversed to obtain the first integer value associated with a STAR tag defined in a header file.
long item_get_number | ( | Bstar_old * | star, |
const char * | tag | ||
) |
Gets the number of values associated with a tag in a STAR data base.
*star | the STAR data base. |
*tag | a STAR tag string. |
All STAR data blocks are traversed to count the number of values associated with a STAR tag defined in a header file.
long item_get_number_for_block | ( | Bstar_block * | block, |
const char * | tag | ||
) |
Gets the number of values associated with a tag in a STAR data block.
*block | block in the STAR database. |
*tag | a STAR tag string. |
The STAR data block is traversed to count the number of values associated with a STAR tag defined in a header file.
char * item_get_string | ( | Bstar_block * | block, |
const char * | tag | ||
) |
Gets a string value associated with a tag in a STAR data block.
*block | block in the STAR database. |
*tag | a STAR tag string. |
The STAR data block is traversed to obtain the string value associated with a STAR tag defined in a header file.
int item_index | ( | Bstar_block * | block, |
const char * | tag | ||
) |
Gets the STAR item associated with a tag in a STAR data block.
*block | a STAR data block. |
*tag | a STAR tag string. |
The items in the STAR data block are traversed to find the item associated with a STAR tag defined in a header file.
Scales and shifts all items associated with a given tag from the STAR data base.
*star | the STAR database. |
&tag | tag for items to be modified. |
iscale | multiplier. |
ishift | value added. |
The item must be integer and is modified as: new_value = old_value*scale + shift.
Lists all items associated with a given tag from the STAR data base.
*star | the STAR database. |
&tag | tag for items to be listed. |
The item with a given tag is listed to standard output as an end-of-line delimited array.
int item_put_angle_list | ( | Bstar_block * | block, |
const char * | tag, | ||
char * | list, | ||
size_t | offset, | ||
const char * | format | ||
) |
Writes a list of angular values in degrees into a data item associated with a specific data block and tag in a STAR data base.
*block | block in the STAR database. |
*tag | a STAR tag string. |
*list | linked list. |
offset | offset of structure element. |
*format | string format. |
Each angle in radians is first converted to degrees before writing it into a string.
int item_put_float | ( | Bstar_block * | block, |
const char * | tag, | ||
float | value, | ||
const char * | format | ||
) |
Writes a floating point value into a data item associated with a specific data block and tag in a STAR data base.
*block | block in the STAR database. |
*tag | a STAR tag string. |
value | integer value. |
*format | string format. |
int item_put_float_array | ( | Bstar_block * | block, |
const char * | tag, | ||
int | number, | ||
float * | value, | ||
const char * | format | ||
) |
Writes a list of floating point numbers into a data item associated with a specific data block and tag in a STAR data base.
*block | block in the STAR database. |
*tag | a STAR tag string. |
number | the number of values. |
*value | a list of floating point values. |
*format | string format. |
NaN values are taken as missing numbers and indicated by a '.' in the STAR file.
int item_put_integer | ( | Bstar_block * | block, |
const char * | tag, | ||
int | value, | ||
const char * | format | ||
) |
Writes a integer into a data item associated with a specific data block and tag in a STAR data base.
*block | block in the STAR database. |
*tag | a STAR tag string. |
value | integer value. |
*format | string format. |
int item_put_list | ( | Bstar_block * | block, |
const char * | tag, | ||
char * | list, | ||
size_t | offset, | ||
const char * | format | ||
) |
Writes a list of string or numeric values into a data item associated with a specific data block and tag in a STAR data base.
*block | block in the STAR database. |
*tag | a STAR tag string. |
*list | linked list. |
offset | offset of structure element. |
*format | string format. |
int item_put_string | ( | Bstar_block * | block, |
const char * | tag, | ||
Bstring & | string | ||
) |
int item_put_string | ( | Bstar_block * | block, |
const char * | tag, | ||
char * | string | ||
) |
Writes a string into a data item associated with a specific data block and tag in a STAR data base.
*block | block in the STAR database. |
*tag | a STAR tag string. |
*string | string value. |
int item_put_string_list | ( | Bstar_block * | block, |
const char * | tag, | ||
Bstring * | list | ||
) |
Writes a list of strings into a data item associated with a specific data block and tag in a STAR data base.
*block | block in the STAR database. |
*tag | a STAR tag string. |
*list | list of strings. |
int kill_block | ( | Bstar_block * | block | ) |
Destroys a STAR data block.
*block | pointer to the STAR data block. |
A data block in a STAR data base structure and all of the items associated with that data block are freed.
int kill_item | ( | Bstar_item * | item | ) |
Destroys an item in a data block in a STAR data base.
*item | the item. |
An item and all of the items referenced are freed.
int kill_star | ( | Bstar_old * | star | ) |
Destroys a STAR data base.
*star | the STAR data base. |
A STAR data base structure and all of the data blocks and items are freed.
int loop_set_identifier | ( | Bstar_block * | block, |
int | loop, | ||
int | n, | ||
... | |||
) |
Assigns a loop identification number to items.
*block | block in the STAR database. |
loop | loop identifier to use. |
n | number of patterns to test for. |
... | (tag_pattern) tag pattern to match to set the loop identifier. |
The items in the data block are rearranged so that the item assigned to the loop follows the other loop items.
int no_square_brackets | ( | Bstar_old * | star | ) |
Bstar_block * read_block | ( | ifstream * | fstar, |
char * | aptr, | ||
Bstring & | filename | ||
) |
Reads paramaters and data into a STAR data block from an open file.
*fstar | an open STAR format file. |
*aptr | a pointer to the current line in the file. |
&filename | file containing this block. |
A block defines a unit of parameters or a unit of data. Every data block is read separately and comments are preserved as far as possible.
Bstar_item * read_loop_items | ( | ifstream * | fstar | ) |
Reads a loop structure with multiple items into a STAR data block from an open file.
*fstar | an open STAR format file. |
The loop is read line by line, checking to get every column value in a row. A row may extend over multiple lines, as long as it contains the number values specified by the number of tags at the beginning of the loop. A multiple line string value must be enclosed in ";" as the first character in the lines before and after the string. The loop ends with an empty line or when too few values occur in a row. An empty line at the end of a loop is required. Note: The loop flag field of the STAR item is equal to the item index of the first item in the loop.
Bstar_item * read_single_item | ( | ifstream * | fstar, |
char * | aline | ||
) |
Reads a single-valued item or comment line into a STAR data block from an open file.
*fstar | an open STAR format file. |
*aline | a pointer to the current line in the file. |
All tags with single values and outside loops are interpreted here. A single item is defined where the first non-space character on a line is an underscore. A comment is defined by a '#' or ';' as the first character on the line. Note: The loop flag field of the STAR item is equal to -1.
int read_star | ( | const char * | filename, |
Bstar_old * | star | ||
) |
Reads paramaters and data into a STAR data base from a list of files.
*filename | a list of file names separated by commas. |
*star | an existing STAR data base. |
Every data block is read separately and comments are preserved as far as possible.
int show_tags | ( | Bstar_old * | star | ) |
Prints the list of tags in the STAR data base.
*star | the STAR database |
long star_list_comments | ( | Bstar_old * | star, |
long | len | ||
) |
Lists the command lines in the STAR header.
*star | the STAR data base. |
len | maximum line length, infinite if zero. |
int star_set_string_lengths | ( | Bstar_old * | star | ) |
Sets the maximum string lengths for each item in each block.
*star | the STAR data base. |
This is designed to clean up after creating a STAR database.
int star_update_comment | ( | Bstar_old * | star, |
int | n, | ||
char ** | strings | ||
) |
Puts a set of strings and time in the main comment of the STAR data base.
*star | the STAR data base. |
n | the number of strings. |
**strings | an array of strings. |
This is designed to pack the command line into a string followed by a second string for the time.
int write_block | ( | ofstream * | fstar, |
Bstar_block * | block, | ||
int | linelength | ||
) |
Writes paramaters and data from a STAR data block into an open file.
*fstar | an open STAR format file. |
*block | a data block. |
linelength | output maximum line length. |
A block defines a unit of parameters or a unit of data.
int write_star | ( | const char * | filename, |
Bstar_old * | star | ||
) |
Writes a STAR data base to one or more STAR format files.
*filename | the base file name (can be NULL if star->split == 9). |
*star | the STAR data base. |
The STAR data base structure contains a flag (star->split) to indicate whether one or multiple files should be written. In the case of multiple files, the base name is taken from the input file name, with an underscore and a number appended. The length of the number is determined by the star->split variable.
|
extern |