1 /*********************************************************************
2 table -- functions for table input and output.
3 This is part of GNU Astronomy Utilities (Gnuastro) package.
4 
5 Original author:
6      Mohammad Akhlaghi <mohammad@akhlaghi.org>
7 Contributing author(s):
8 Copyright (C) 2015-2021, Free Software Foundation, Inc.
9 
10 Gnuastro is free software: you can redistribute it and/or modify it
11 under the terms of the GNU General Public License as published by the
12 Free Software Foundation, either version 3 of the License, or (at your
13 option) any later version.
14 
15 Gnuastro is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with Gnuastro. If not, see <http://www.gnu.org/licenses/>.
22 **********************************************************************/
23 #ifndef __GAL_TABLE_H__
24 #define __GAL_TABLE_H__
25 
26 /* Include other headers if necessary here. Note that other header files
27    must be included before the C++ preparations below */
28 
29 #include <gnuastro/list.h>
30 #include <gnuastro/fits.h>
31 
32 
33 
34 /* C++ Preparations */
35 #undef __BEGIN_C_DECLS
36 #undef __END_C_DECLS
37 #ifdef __cplusplus
38 # define __BEGIN_C_DECLS extern "C" {
39 # define __END_C_DECLS }
40 #else
41 # define __BEGIN_C_DECLS                /* empty */
42 # define __END_C_DECLS                  /* empty */
43 #endif
44 /* End of C++ preparations */
45 
46 
47 
48 
49 
50 /* Actual header contants (the above were for the Pre-processor). */
51 __BEGIN_C_DECLS  /* From C++ preparations */
52 
53 
54 
55 
56 
57 /* 'printf' default formattings. Note that the string type shouldn't have
58    any precision and for the width,  */
59 #define GAL_TABLE_DEF_WIDTH_STR       6
60 #define GAL_TABLE_DEF_WIDTH_INT       6
61 #define GAL_TABLE_DEF_WIDTH_LINT      10
62 #define GAL_TABLE_DEF_WIDTH_FLT       13
63 #define GAL_TABLE_DEF_WIDTH_DBL       18
64 
65 #define GAL_TABLE_DEF_PRECISION_INT   0
66 #define GAL_TABLE_DEF_PRECISION_FLT   6
67 #define GAL_TABLE_DEF_PRECISION_DBL   14
68 
69 
70 
71 
72 
73 /* Particular display formats for different types: Integers or floating
74    point numbers can be printed in various display formats. The values here
75    are stored in 'gal_data_t' when necessary to help in printing of the
76    data.*/
77 enum gal_table_diplay_formats
78 {
79   GAL_TABLE_DISPLAY_FMT_INVALID,        /* Invalid (=0 by C standard). */
80 
81   GAL_TABLE_DISPLAY_FMT_STRING,         /* String/Character.           */
82   GAL_TABLE_DISPLAY_FMT_DECIMAL,        /* Integers: signed decimal.   */
83   GAL_TABLE_DISPLAY_FMT_UDECIMAL,       /* Integers: unsigned decimal. */
84   GAL_TABLE_DISPLAY_FMT_OCTAL,          /* Integers: octal.            */
85   GAL_TABLE_DISPLAY_FMT_HEX,            /* Integers: hexadecimal.      */
86   GAL_TABLE_DISPLAY_FMT_FLOAT,          /* Floats: with decimal point. */
87   GAL_TABLE_DISPLAY_FMT_EXP,            /* Floats: as exponential.     */
88   GAL_TABLE_DISPLAY_FMT_GENERAL,        /* Floats: general (%g in C).  */
89 };
90 
91 
92 
93 
94 
95 /* Formats of table storage for input or output, as strings and
96    integers. */
97 enum gal_table_types
98 {
99   GAL_TABLE_FORMAT_INVALID,       /* Invalid (=0 by C standard).       */
100 
101   GAL_TABLE_FORMAT_TXT,           /* Plain text table.                 */
102   GAL_TABLE_FORMAT_AFITS,         /* FITS ASCII table.                 */
103   GAL_TABLE_FORMAT_BFITS,         /* FITS binary table.                */
104 };
105 
106 
107 
108 
109 
110 /* When the desired column is not a number, should the string match or
111    regular expression search be in the name, units or comments of the
112    columns? */
113 enum gal_table_where_to_search
114 {
115   GAL_TABLE_SEARCH_INVALID,       /* Invalid (=0 by C standard).     */
116 
117   GAL_TABLE_SEARCH_NAME,          /* Match/search in names.          */
118   GAL_TABLE_SEARCH_UNIT,          /* Match/search in units.          */
119   GAL_TABLE_SEARCH_COMMENT,       /* Match/search in comments.       */
120 };
121 
122 
123 
124 /************************************************************************/
125 /***************         Information about a table        ***************/
126 /************************************************************************/
127 gal_data_t *
128 gal_table_info(char *filename, char *hdu, gal_list_str_t *lines,
129                size_t *numcols, size_t *numrows, int *tableformat);
130 
131 void
132 gal_table_print_info(gal_data_t *allcols, size_t numcols, size_t numrows);
133 
134 
135 
136 /************************************************************************/
137 /***************               Read a table               ***************/
138 /************************************************************************/
139 gal_data_t *
140 gal_table_read(char *filename, char *hdu, gal_list_str_t *lines,
141                gal_list_str_t *cols, int searchin, int ignorecase,
142                size_t minmapsize, int quietmmap, size_t *colmatch);
143 
144 gal_list_sizet_t *
145 gal_table_list_of_indexs(gal_list_str_t *cols, gal_data_t *allcols,
146                          size_t numcols, int searchin, int ignorecase,
147                          char *filename, char *hdu, size_t *colmatch);
148 
149 
150 
151 /************************************************************************/
152 /***************              Write a table               ***************/
153 /************************************************************************/
154 void
155 gal_table_comments_add_intro(gal_list_str_t **comments,
156                              char *program_string, time_t *rawtime);
157 
158 void
159 gal_table_write(gal_data_t *cols, struct gal_fits_list_key_t **keylist,
160                 gal_list_str_t *comments, int tableformat, char *filename,
161                 char *extname, uint8_t colinfoinstdout);
162 
163 void
164 gal_table_write_log(gal_data_t *logll, char *program_string,
165                     time_t *rawtime, gal_list_str_t *comments,
166                     char *filename, int quiet);
167 
168 
169 
170 
171 
172 __END_C_DECLS    /* From C++ preparations */
173 
174 #endif           /* __GAL_TABLE_H__ */
175