WCSLIB 4.20
wcsutil.h
Go to the documentation of this file.
1 /*============================================================================
2 
3  WCSLIB 4.20 - an implementation of the FITS WCS standard.
4  Copyright (C) 1995-2013, Mark Calabretta
5 
6  This file is part of WCSLIB.
7 
8  WCSLIB is free software: you can redistribute it and/or modify it under the
9  terms of the GNU Lesser General Public License as published by the Free
10  Software Foundation, either version 3 of the License, or (at your option)
11  any later version.
12 
13  WCSLIB is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
16  more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with WCSLIB. If not, see http://www.gnu.org/licenses.
20 
21  Direct correspondence concerning WCSLIB to mark@calabretta.id.au
22 
23  Author: Mark Calabretta, Australia Telescope National Facility, CSIRO.
24  http://www.atnf.csiro.au/people/Mark.Calabretta
25  $Id: wcsutil_8h_source.html,v 1.1 2014/02/12 21:11:37 irby Exp $
26 *=============================================================================
27 *
28 * Summary of the wcsutil routines
29 * -------------------------------
30 * Simple utility functions for internal use only by WCSLIB. They are
31 * documented here solely as an aid to understanding the code. They are not
32 * intended for external use - the API may change without notice!
33 *
34 *
35 * wcsutil_blank_fill() - Fill a character string with blanks
36 * ----------------------------------------------------------
37 * INTERNAL USE ONLY.
38 *
39 * wcsutil_blank_fill() pads a character string with blanks starting with the
40 * terminating NULL character.
41 *
42 * Used by the Fortran wrapper functions in translating C character strings
43 * into Fortran CHARACTER variables.
44 *
45 * Given:
46 * n int Length of the character array, c[].
47 *
48 * Given and returned:
49 * c char[] The character string. It will not be null-terminated
50 * on return.
51 *
52 * Function return value:
53 * void
54 *
55 *
56 * wcsutil_null_fill() - Fill a character string with NULLs
57 * --------------------------------------------------------
58 * INTERNAL USE ONLY.
59 *
60 * wcsutil_null_fill() strips off trailing blanks and pads the character array
61 * holding the string with NULL characters.
62 *
63 * Used mainly to make character strings intelligible in the GNU debugger which
64 * prints the rubbish following the terminating NULL, obscuring the valid part
65 * of the string.
66 *
67 * Given:
68 * n int Number of characters.
69 *
70 * Given and returned:
71 * c char[] The character string.
72 *
73 * Function return value:
74 * void
75 *
76 *
77 * wcsutil_allEq() - Test for equality of a particular vector element
78 * ------------------------------------------------------------------
79 * INTERNAL USE ONLY.
80 *
81 * wcsutil_allEq() tests for equality of a particular element in a set of
82 * vectors.
83 *
84 * Given:
85 * nvec int The number of vectors.
86 *
87 * nelem int The length of each vector.
88 *
89 * first const double*
90 * Pointer to the first element to test in the array.
91 * The elements tested for equality are
92 *
93 = *first == *(first + nelem)
94 = == *(first + nelem*2)
95 = :
96 = == *(first + nelem*(nvec-1));
97 *
98 * The array might be dimensioned as
99 *
100 = double v[nvec][nelem];
101 *
102 * Function return value:
103 * int Status return value:
104 * 0: Not all equal.
105 * 1: All equal.
106 *
107 *
108 * wcsutil_setAll() - Set a particular vector element
109 * --------------------------------------------------
110 * INTERNAL USE ONLY.
111 *
112 * wcsutil_setAll() sets the value of a particular element in a set of vectors.
113 *
114 * Given:
115 * nvec int The number of vectors.
116 *
117 * nelem int The length of each vector.
118 *
119 * Given and returned:
120 * first double* Pointer to the first element in the array, the value
121 * of which is used to set the others
122 *
123 = *(first + nelem) = *first;
124 = *(first + nelem*2) = *first;
125 = :
126 = *(first + nelem*(nvec-1)) = *first;
127 *
128 * The array might be dimensioned as
129 *
130 = double v[nvec][nelem];
131 *
132 * Function return value:
133 * void
134 *
135 *
136 * wcsutil_setAli() - Set a particular vector element
137 * --------------------------------------------------
138 * INTERNAL USE ONLY.
139 *
140 * wcsutil_setAli() sets the value of a particular element in a set of vectors.
141 *
142 * Given:
143 * nvec int The number of vectors.
144 *
145 * nelem int The length of each vector.
146 *
147 * Given and returned:
148 * first int* Pointer to the first element in the array, the value
149 * of which is used to set the others
150 *
151 = *(first + nelem) = *first;
152 = *(first + nelem*2) = *first;
153 = :
154 = *(first + nelem*(nvec-1)) = *first;
155 *
156 * The array might be dimensioned as
157 *
158 = int v[nvec][nelem];
159 *
160 * Function return value:
161 * void
162 *
163 *
164 * wcsutil_setBit() - Set bits in selected elements of an array
165 * ------------------------------------------------------------
166 * INTERNAL USE ONLY.
167 *
168 * wcsutil_setBit() sets bits in selected elements of an array.
169 *
170 * Given:
171 * nelem int Number of elements in the array.
172 *
173 * sel const int*
174 * Address of a selection array of length nelem. May
175 * be specified as the null pointer in which case all
176 * elements are selected.
177 *
178 * bits int Bit mask.
179 *
180 * Given and returned:
181 * array int* Address of the array of length nelem.
182 *
183 * Function return value:
184 * void
185 *
186 *
187 * wcsutil_fptr2str() - Translate pointer-to-function to string
188 * ------------------------------------------------------------
189 * INTERNAL USE ONLY.
190 *
191 * wcsutil_fptr2str() translates a pointer-to-function to hexadecimal string
192 * representation for output. It is used by the various routines that print
193 * the contents of WCSLIB structs, noting that it is not strictly legal to
194 * type-pun a function pointer to void*. See
195 * http://stackoverflow.com/questions/2741683/how-to-format-a-function-pointer
196 *
197 * Given:
198 * fptr int(*)() Pointer to function.
199 *
200 * Returned:
201 * hext char[19] Null-terminated string. Should be at least 19 bytes
202 * in size to accomodate a 64-bit address (16 bytes in
203 * hex), plus the leading "0x" and trailing '\0'.
204 *
205 * Function return value:
206 * char * The address of hext.
207 *
208 *
209 * wcsutil_double2str() - Translate double to string ignoring the locale
210 * ---------------------------------------------------------------------
211 * INTERNAL USE ONLY.
212 *
213 * wcsutil_double2str() converts a double to a string, but unlike sprintf() it
214 * ignores the locale and always uses a '.' as the decimal separator.
215 *
216 * Returned:
217 * buf char * The buffer to write the string into.
218 *
219 * Given:
220 * format char * The formatting directive, such as "%f". This
221 * may be any of the forms accepted by sprintf(), but
222 * should only include a formatting directive and
223 * nothing else.
224 *
225 * value double The value to convert to a string.
226 *
227 *
228 * wcsutil_str2double() - Translate string to a double, ignoring the locale
229 * ------------------------------------------------------------------------
230 * INTERNAL USE ONLY.
231 *
232 * wcsutil_str2double() converts a string to a double, but unlike sscanf() it
233 * ignores the locale and always expects a '.' as the decimal separator.
234 *
235 * Given:
236 * buf char * The string containing the value
237 *
238 * format char * The formatting directive, such as "%lf". This
239 * may be any of the forms accepted by sscanf(), but
240 * should only include a single formatting directive.
241 *
242 * Returned:
243 * value double * The double value parsed from the string.
244 *
245 *===========================================================================*/
246 
247 #ifndef WCSLIB_WCSUTIL
248 #define WCSLIB_WCSUTIL
249 
250 #ifdef __cplusplus
251 extern "C" {
252 #endif
253 
254 void wcsutil_blank_fill(int n, char c[]);
255 void wcsutil_null_fill (int n, char c[]);
256 
257 int wcsutil_allEq (int nvec, int nelem, const double *first);
258 void wcsutil_setAll(int nvec, int nelem, double *first);
259 void wcsutil_setAli(int nvec, int nelem, int *first);
260 void wcsutil_setBit(int nelem, const int *sel, int bits, int *array);
261 char *wcsutil_fptr2str(int (*func)(void), char hext[19]);
262 int wcsutil_str2double(const char *buf, const char *format, double *value);
263 void wcsutil_double2str(char *buf, const char *format, double value);
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 
269 #endif /* WCSLIB_WCSUTIL */