Bsoft  2.1.0
Bernard's software package
rwstar.h
Go to the documentation of this file.
1 
9 #include "Bstring.h"
10 
11 // Constants
12 #define LINELENGTH 80 // Length of line for output
13 
14 #ifndef _STAR_
15 /************************************************************************
16 @Object: enum StarType
17 @Description:
18  Types of elements in a STAR database.
19 @Features:
20  Comments are ignored but passed to output files.
21  Numbers are either integer or floating point.
22 *************************************************************************/
23 enum StarType {
26  NumberItem = 2
27 } ;
28 
29 /************************************************************************
30 @Object: struct Bstar_item
31 @Description:
32  Structure for a single entry or a single column in a STAR database.
33 @Features:
34  Each item consists of a string or a zero-delimited sequence of strings.
35 *************************************************************************/
36 struct Bstar_item {
37  Bstar_item* next; // Pointer to next item
38  Bstring tag; // Item identifier
39  StarType type; // Item type
40  int loop; // Loop identifier
41  int maxlen; // Maximum length of a string
42  Bstring comment; // Comment following tag-value pair
43  Bstring* data; // Pointer to numbers or strings
44 } ;
45 
46 /************************************************************************
47 @Object: struct Bstar_block
48 @Description:
49  Structure for a data block with multiple items in a STAR database.
50 @Features:
51  Each data block contains a set set of unique items defined by tags
52  and with the associate data as single or multiple values.
53  The order of the items in the data block are important and preserved.
54 *************************************************************************/
55 struct Bstar_block {
56  Bstar_block* next; // Pointer to next block
57  int number; // Block number (classic)
58  Bstring tag; // Block identifier
59  Bstring comment; // Comment following tag-value pair
60  Bstring filename; // File containing this block
61  Bstar_item* item; // Pointer to items
62 } ;
63 
64 /************************************************************************
65 @Object: struct Bstar
66 @Description:
67  Overall STAR structure to hold all data blocks and options for I/O..
68 @Features:
69  The split flag allows the user to output data blocks in separte files
70  in stead of one big file.
71  The line length field allows the user to output long lines without
72  wrapping it around.
73  The comments are ignored but output to the a new file - this can be used
74  to document the history of the file.
75  The STAR database is a hierarchy consisting of blocks, each with a set
76  of items.
77 *************************************************************************/
78 struct Bstar {
79  int split; // Flag to indicate writing each data block in its own file
80  int line_length; // Length of lines in output file
81  Bstring comment; // List of comments before 1st data block
82  Bstar_block* block; // Pointer to first block
83 } ;
84 #define _STAR_
85 #endif
86 
87 // Function prototypes
88 Bstar* init_star();
89 int kill_star(Bstar* star);
90 int kill_block(Bstar_block* block);
91 int kill_item(Bstar_item* item);
92 int read_star(const char* filename, Bstar* star);
93 int read_star(Bstring& filename, Bstar* star);
94 int read_star(Bstring* file_list, Bstar* star);
95 Bstar_block* read_block(ifstream* fstar, char* aptr, Bstring& filename);
96 Bstar_item* read_single_item(ifstream* fstar, char* aline);
97 Bstar_item* read_loop_items(ifstream* fstar);
98 int write_star(const char* filename, Bstar* star);
99 int write_star(Bstring& filename, Bstar* star);
100 int write_block(ofstream* fstar, Bstar_block* block, int linelength);
101 int star_update_comment(Bstar* star, int n, char** strings);
102 long star_list_comments(Bstar* star, long len);
103 int star_set_string_lengths(Bstar* star);
104 int item_change_tag(Bstar* star, const char* tag, const char* newtag);
105 int show_tags(Bstar* star);
106 int item_index(Bstar_block* block, const char* tag);
107 Bstar_block* block_find_with_tag(Bstar* star, const char* tag);
108 Bstar_item* item_find(Bstar_block* block, const char* tag);
109 Bstar_item* item_find_or_make(Bstar_block* block, const char* tag);
110 long item_get_number(Bstar* star, const char* tag);
111 long item_get_number_for_block(Bstar_block* block, const char* tag);
112 char* item_get_string(Bstar_block* block, const char* tag);
113 int item_copy_string(char* string, Bstar_block* block, const char* tag);
114 int item_get_integer(Bstar_block* block, const char* tag);
115 float item_get_float(Bstar_block* block, const char* tag);
116 int item_put_string(Bstar_block* block, const char* tag, char* string);
117 int item_put_string(Bstar_block* block, const char* tag, Bstring& string);
118 int item_put_string_list(Bstar_block* block, const char* tag, Bstring* list);
119 int item_put_integer(Bstar_block* block, const char* tag, int value, const char* format);
120 int item_put_float(Bstar_block* block, const char* tag, float value, const char* format);
121 int item_put_list(Bstar_block* block, const char* tag, char* list,
122  size_t offset, const char* format);
123 int item_put_float_array(Bstar_block* block, const char* tag, int number,
124  float* value, const char* format);
125 int item_put_angle_list(Bstar_block* block, const char* tag, char* list,
126  size_t offset, const char* format);
127 int item_list(Bstar* star, Bstring& tag);
128 int item_delete_all(Bstar* star, const char* tag);
129 int item_delete_from_block(Bstar_block* block, const char* tag);
130 int block_delete(Bstar* star, Bstring& tag);
131 int item_integer_scale_shift(Bstar* star, Bstring& tag, int iscale, int ishift);
132 int item_float_scale_shift(Bstar* star, Bstring& tag, float scale, float shift);
133 int loop_set_identifier(Bstar_block* block, int loop, int n, ...);
134 int item_get_format(Bstar_item* item, char* format);
135 
136 
Bstar_item::data
Bstring * data
Definition: rwstar.h:43
Bstar_item
Definition: rwstar.h:36
Bstar_block::number
int number
Definition: rwstar.h:57
item_put_list
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 ...
Definition: rwstar.cpp:1436
item_change_tag
int item_change_tag(Bstar *star, const char *tag, const char *newtag)
Replaces one tag with another in the STAR data base.
Definition: rwstar.cpp:966
read_single_item
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.
Definition: rwstar.cpp:427
CommentItem
@ CommentItem
Definition: rwstar.h:24
Bstar_item::comment
Bstring comment
Definition: rwstar.h:42
star_update_comment
int star_update_comment(Bstar *star, int n, char **strings)
Puts a set of strings and time in the main comment of the STAR data base.
Definition: rwstar.cpp:880
item_index
int item_index(Bstar_block *block, const char *tag)
Gets the STAR item associated with a tag in a STAR data block.
Definition: rwstar.cpp:1029
item_get_integer
int item_get_integer(Bstar_block *block, const char *tag)
Gets an integer value associated with a tag in a STAR data block.
Definition: rwstar.cpp:1245
item_get_float
float item_get_float(Bstar_block *block, const char *tag)
Gets a floating point value associated with a tag in a STAR data block.
Definition: rwstar.cpp:1273
Bstring
Definition: Bstring.h:29
Bstar::comment
Bstring comment
Definition: rwstar.h:81
loop_set_identifier
int loop_set_identifier(Bstar_block *block, int loop, int n,...)
Assigns a loop identification number to items.
Definition: rwstar.cpp:1803
star_set_string_lengths
int star_set_string_lengths(Bstar *star)
Sets the maximum string lengths for each item in each block.
Definition: rwstar.cpp:938
item_find_or_make
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.
Definition: rwstar.cpp:1105
read_block
Bstar_block * read_block(ifstream *fstar, char *aptr, Bstring &filename)
Reads paramaters and data into a STAR data block from an open file.
Definition: rwstar.cpp:356
Bstar_item::maxlen
int maxlen
Definition: rwstar.h:41
item_put_string_list
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 dat...
Definition: rwstar.cpp:1337
item_put_float_array
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 ta...
Definition: rwstar.cpp:1486
Bstar_item::loop
int loop
Definition: rwstar.h:40
item_put_float
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 STA...
Definition: rwstar.cpp:1401
item_float_scale_shift
int item_float_scale_shift(Bstar *star, Bstring &tag, float scale, float shift)
Scales and shifts all items associated with a given tag from the STAR data base.
Definition: rwstar.cpp:1751
Bstar_block::tag
Bstring tag
Definition: rwstar.h:58
Bstar_block::item
Bstar_item * item
Definition: rwstar.h:61
item_put_integer
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.
Definition: rwstar.cpp:1368
read_loop_items
Bstar_item * read_loop_items(ifstream *fstar)
Reads a loop structure with multiple items into a STAR data block from an open file.
Definition: rwstar.cpp:528
StringItem
@ StringItem
Definition: rwstar.h:25
write_star
int write_star(const char *filename, Bstar *star)
Writes a STAR data base to one or more STAR format files.
Definition: rwstar.cpp:666
star_list_comments
long star_list_comments(Bstar *star, long len)
Lists the command lines in the STAR header.
Definition: rwstar.cpp:907
Bstar_item::tag
Bstring tag
Definition: rwstar.h:38
item_delete_all
int item_delete_all(Bstar *star, const char *tag)
Deletes all items associated with a given tag from the STAR data base.
Definition: rwstar.cpp:1603
Bstar_item::next
Bstar_item * next
Definition: rwstar.h:37
item_get_number_for_block
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.
Definition: rwstar.cpp:1163
write_block
int write_block(ofstream *fstar, Bstar_block *block, int linelength)
Writes paramaters and data from a STAR data block into an open file.
Definition: rwstar.cpp:750
Bstring.h
Header file for the string class.
NumberItem
@ NumberItem
Definition: rwstar.h:26
Bstar_block::comment
Bstring comment
Definition: rwstar.h:59
show_tags
int show_tags(Bstar *star)
Prints the list of tags in the STAR data base.
Definition: rwstar.cpp:991
read_star
int read_star(const char *filename, Bstar *star)
Reads paramaters and data into a STAR data base from a list of files.
Definition: rwstar.cpp:224
kill_star
int kill_star(Bstar *star)
Destroys a STAR data base.
Definition: rwstar.cpp:132
item_copy_string
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.
Definition: rwstar.cpp:1220
Bstar::line_length
int line_length
Definition: rwstar.h:80
kill_block
int kill_block(Bstar_block *block)
Destroys a STAR data block.
Definition: rwstar.cpp:163
kill_item
int kill_item(Bstar_item *item)
Destroys an item in a data block in a STAR data base.
Definition: rwstar.cpp:197
item_get_number
long item_get_number(Bstar *star, const char *tag)
Gets the number of values associated with a tag in a STAR data base.
Definition: rwstar.cpp:1134
item_list
int item_list(Bstar *star, Bstring &tag)
Lists all items associated with a given tag from the STAR data base.
Definition: rwstar.cpp:1571
item_find
Bstar_item * item_find(Bstar_block *block, const char *tag)
Gets the STAR item associated with a tag in a STAR data block.
Definition: rwstar.cpp:1083
item_put_angle_list
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...
Definition: rwstar.cpp:1528
item_integer_scale_shift
int item_integer_scale_shift(Bstar *star, Bstring &tag, int iscale, int ishift)
Scales and shifts all items associated with a given tag from the STAR data base.
Definition: rwstar.cpp:1709
item_get_string
char * item_get_string(Bstar_block *block, const char *tag)
Gets a string value associated with a tag in a STAR data block.
Definition: rwstar.cpp:1189
item_put_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.
Definition: rwstar.cpp:1300
block_delete
int block_delete(Bstar *star, Bstring &tag)
Deletes all blocks with a given tag from the STAR data base.
Definition: rwstar.cpp:1662
Bstar::block
Bstar_block * block
Definition: rwstar.h:82
item_get_format
int item_get_format(Bstar_item *item, char *format)
Gets the format from the item.
Definition: rwstar.cpp:1837
Bstar_block::filename
Bstring filename
Definition: rwstar.h:60
StarType
StarType
Definition: rwstar.h:23
Bstar_block
Definition: rwstar.h:55
Bstar_block::next
Bstar_block * next
Definition: rwstar.h:56
Bstar::split
int split
Definition: rwstar.h:79
init_star
Bstar * init_star()
Creates a STAR data base.
Definition: rwstar.cpp:111
Bstar_item::type
StarType type
Definition: rwstar.h:39
Bstar
Definition: rwstar.h:78
block_find_with_tag
Bstar_block * block_find_with_tag(Bstar *star, const char *tag)
Gets the first block associated with a tag in a STAR data base.
Definition: rwstar.cpp:1050
item_delete_from_block
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.
Definition: rwstar.cpp:1626