ERIS Pipeline Reference Manual 1.8.15
sc_basic.h
Go to the documentation of this file.
1/*
2 * This file is part of the SKYCORR software package.
3 * Copyright (C) 2009-2013 European Southern Observatory
4 *
5 * This programme is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This programme is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this programme. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/*****************************************************************************
43 * INCLUDES *
44 ****************************************************************************/
45
46/* Config header */
47
48#ifdef HAVE_CONFIG_H
49#include <config.h>
50#endif
51
52/* C standard libraries */
53
54#include <stdio.h>
55#include <stdlib.h>
56#include <string.h>
57#include <ctype.h>
58#include <math.h>
59#include <float.h>
60#include <errno.h>
61#include <unistd.h>
62#include <assert.h>
63#include <sys/dir.h>
64#include <sys/stat.h>
65#include <sys/wait.h>
66
67/* CPL library */
68
69#include <cpl.h>
70
71/* MPFIT */
72
73#include <mpfit.h>
74
75/*****************************************************************************
76 * DEFINES *
77 ****************************************************************************/
78
79#ifndef SC_BASIC_H
80#define SC_BASIC_H
81
82/* Basic definitions */
83
85#define SC_MIN(a, b) ((a) > (b) ? (b) : (a))
87#define SC_MAX(a, b) ((a) < (b) ? (b) : (a))
88
89/* Definition of constants */
90
92#define SC_LENLINE 160
94#define SC_MAXLEN 1024
96#define SC_TOL 1e-7
99#define SC_MAXPAR 21
102#define SC_THERMIRLIM 2.31
103
104/* Default column names */
105
107#define SC_DEFLAMCOL "LAMBDA"
109#define SC_DEFFLUXCOL "FLUX"
111#define SC_DEFDFLUXCOL "DFLUX"
113#define SC_DEFMASKCOL "MASK"
114
115/* Parameters for damped sinc kernel */
116
118#define SC_SINCRAD_PRECOMP 6.0
120#define SC_SINCNBIN 10000
122#define SC_SINCDAMP 3.25
123
124/* Definition of error codes and corresponding standard error messages */
125
128typedef enum _sc_error_code_ {
129 SC_ERROR_FOPEN = CPL_ERROR_EOL + 11, // "File opening failed"
130 SC_ERROR_UFS = CPL_ERROR_EOL + 12, // "Unexpected file structure"
131 SC_ERROR_IFE = CPL_ERROR_EOL + 13, // "Invalid file name extension"
132 SC_ERROR_NDA = CPL_ERROR_EOL + 20, // "No data"
133 SC_ERROR_INSUFF_DATA = CPL_ERROR_EOL + 21, // "Insufficient data points"
134 SC_ERROR_IDG = CPL_ERROR_EOL + 22, // "Inconsistent data grids"
135 SC_ERROR_IDR = CPL_ERROR_EOL + 23, // "Invalid data range"
136 SC_ERROR_IOD = CPL_ERROR_EOL + 24, // "Invalid order of data points"
137 SC_ERROR_IIP = CPL_ERROR_EOL + 30, // "Invalid input parameter(s)"
138 SC_ERROR_IOV = CPL_ERROR_EOL + 31, // "Invalid object value(s)"
139 SC_ERROR_IOS = CPL_ERROR_EOL + 32, // "Invalid object structure"
140 SC_ERROR_SUBROUTINE = CPL_ERROR_EOL + 40, // "Error in subroutine"
141 // ERRORS RELATED TO access(), mkdir(), chdir()
142 SC_ERROR_ACCES = CPL_ERROR_EOL + 50, // access(), mkdir(), chdir()
143 SC_ERROR_LOOP = CPL_ERROR_EOL + 51, // access(), mkdir(), chdir()
144 SC_ERROR_NAMETOOLONG = CPL_ERROR_EOL + 52, // access(), mkdir(), chdir()
145 SC_ERROR_NOENT = CPL_ERROR_EOL + 53, // access(), mkdir(), chdir()
146 SC_ERROR_NOTDIR = CPL_ERROR_EOL + 54, // access(), mkdir(), chdir()
147 SC_ERROR_ROFS = CPL_ERROR_EOL + 55, // access(), mkdir()
148 SC_ERROR_FAULT = CPL_ERROR_EOL + 56, // access(), mkdir(), chdir()
149 SC_ERROR_INVAL = CPL_ERROR_EOL + 57, // access()
150 SC_ERROR_IO = CPL_ERROR_EOL + 58, // access(), chdir()
151 SC_ERROR_NOMEM = CPL_ERROR_EOL + 59, // access(), mkdir(), chdir()
152 SC_ERROR_TXTBSY = CPL_ERROR_EOL + 60, // access()
153 SC_ERROR_EXIST = CPL_ERROR_EOL + 61, // mkdir()
154 SC_ERROR_NOSPC = CPL_ERROR_EOL + 62, // mkdir()
155 SC_ERROR_PERM = CPL_ERROR_EOL + 63, // mkdir()
156 // General errors
157 SC_ERROR_BADUSERINPUT = CPL_ERROR_EOL + 70,
158 SC_ERROR_LINK = CPL_ERROR_EOL + 71,
159 SC_ERROR_CD = CPL_ERROR_EOL + 72, // could not change directory
160 SC_ERROR_GETCWD = CPL_ERROR_EOL + 73, // could not get current
161 // working directory
162 SC_ERROR_RFM = CPL_ERROR_EOL + 81, // general RFM error
163 SC_ERROR_UNDEF = CPL_ERROR_EOL + 80
165
166/* Aliases for sky model related error codes */
167
168#define SC_ERROR_FOF SC_ERROR_FOPEN
169#define SC_ERROR_ISM SC_ERROR_NOMEM
170#define SC_ERROR_EIS SC_ERROR_SUBROUTINE
171#define SC_ERROR_ISD SC_ERROR_INSUFF_DATA
172
173/* Standard messages for sky model related errors */
174
175#define SC_ERROR_FOPEN_TXT "File opening failed"
176#define SC_ERROR_UFS_TXT "Unexpected file structure"
177#define SC_ERROR_IFE_TXT "Invalid file name extension"
178#define SC_ERROR_BDR_TXT "Bad directory"
179#define SC_ERROR_NDA_TXT "No data"
180#define SC_ERROR_ISD_TXT "Insufficient data points"
181#define SC_ERROR_IDG_TXT "Inconsistent data grids"
182#define SC_ERROR_IDR_TXT "Invalid data range"
183#define SC_ERROR_IOD_TXT "Invalid order of data points"
184#define SC_ERROR_IIP_TXT "Invalid input parameter(s)"
185#define SC_ERROR_IOV_TXT "Invalid object value(s)"
186#define SC_ERROR_IOS_TXT "Invalid object structure"
187#define SC_ERROR_SUBROUTINE_TXT "Error in subroutine"
188// ERRORS RELATED TO access(), mkdir(), chdir()
189#define SC_ERROR_ACCES_TXT "Permission denied"
190#define SC_ERROR_LOOP_TXT "Too many symbolic links"
191#define SC_ERROR_NAMETOOLONG_TXT "Pathname too long"
192#define SC_ERROR_NOENT_TXT "File/dir does not exist"
193#define SC_ERROR_NOTDIR_TXT "Component used as directory in pathname " \
194 "is not a directory"
195#define SC_ERROR_ROFS_TXT "Write permission requested for file/dir " \
196 "on read-only file system"
197#define SC_ERROR_FAULT_TXT "Pathname points outside accessible " \
198 "address space"
199#define SC_ERROR_INVAL_TXT "Mode was incorrectly specified"
200#define SC_ERROR_IO_TXT "I/O error occurred"
201#define SC_ERROR_NOMEM_TXT "Insufficient memory"
202#define SC_ERROR_TXTBSY_TXT "Write access requested to executable " \
203 "which is being executed"
204#define SC_ERROR_EXIST_TXT "File/dir already exists"
205#define SC_ERROR_NOSPC_TXT "No space left on device"
206#define SC_ERROR_PERM_TXT "File system does not support creation of " \
207 "directories"
208#define SC_ERROR_LINK_TXT "Could not create symbolic link"
209#define SC_ERROR_UNDEF_TXT "Undefined error"
210#define SC_ERROR_CD_TXT "Could not change directory"
211#define SC_ERROR_GETCWD_TXT "Could not get current working directory"
212
213#define SC_ERROR_FOF_TXT SC_ERROR_FOPEN_TXT
214#define SC_ERROR_ISM_TXT SC_ERROR_NOMEM_TXT
215#define SC_ERROR_EIS_TXT SC_ERROR_SUBROUTINE_TXT
216
217/*****************************************************************************
218 * TYPEDEF *
219 ****************************************************************************/
220
221/* Definition of structures */
222
231typedef struct _scpar_ {
232 char c[SC_LENLINE+2];
233 int i;
234 double d;
236
237/*****************************************************************************
238 * PROTOTYPES *
239 ****************************************************************************/
240
241/* Declaration of functions */
242
243cpl_error_code sc_basic_readline(FILE *stream, scpar par[], int *npar);
244double sc_basic_mjd2fracyear(double mjd);
245double sc_basic_fracyear2date(int *year, int *month, int *day,
246 int *hh, int *mm, double *ss,
247 const double *fracyear);
248cpl_error_code sc_basic_rebin(cpl_table *outspec, const char *outlam,
249 const char *outflux, const cpl_table *inspec,
250 const char *inlam, const char *influx);
251cpl_error_code sc_basic_convolve(cpl_table *spec, const char *colname,
252 const cpl_array *kernel);
253cpl_error_code sc_basic_convolvewindow(cpl_array *convflux,
254 const cpl_array *flux,
255 const int range[2],
256 const cpl_array *kernel);
257cpl_error_code sc_basic_filtermedian(cpl_table *spec, const char *colname,
258 const int npix);
259cpl_error_code sc_basic_linecount(long *n_lines, FILE *fp);
260cpl_error_code sc_basic_rhum2ppmv_old(const cpl_array *temp,
261 const cpl_array *pres,
262 const cpl_array *rhum,
263 cpl_array *ppmv);
264void sc_basic_rhum2ppmv(double *ppmv, const double *tem, const double *p,
265 const double *hum);
266cpl_error_code sc_basic_planck(cpl_array *bb, const cpl_array *wavelength,
267 const double temp);
268void sc_basic_dirslash(char *dir);
269void sc_basic_abspath(char *out, const char *dir, const char *cwd);
270cpl_error_code sc_basic_access(const char *pathname, const int mode);
271cpl_error_code sc_basic_greg2jd(long *jd, const int year, const int month,
272 const int day);
273cpl_error_code sc_basic_jd2greg(int *year, int *month, int *day,
274 const long jd);
275cpl_error_code sc_basic_absfile(char *absfilename, const char *filename);
276cpl_boolean sc_basic_parameterlists_same(cpl_parameterlist *list1,
277 cpl_parameterlist *list2);
278cpl_error_code sc_basic_status2txt(char *msg, const int status);
279cpl_error_code sc_basic_clipmean(double *mean, double *rms,
280 cpl_array *arr, const cpl_boolean clip);
281
282cpl_error_code sc_basic_col2arr(cpl_array *arr, const cpl_table *tab,
283 const char *colname);
284cpl_error_code sc_basic_arr2col(cpl_table *tab, const char *colname,
285 const cpl_array *arr);
286int sc_basic_sortarr_double(const void *p1, const void *p2);
287cpl_error_code sc_basic_sortarr(cpl_array *arr, cpl_type type);
288cpl_error_code sc_basic_copytable_content(cpl_table *outtab,
289 const cpl_table *intab);
290cpl_error_code sc_basic_copytable_full(cpl_table *outtab,
291 const cpl_table *intab);
292void sc_basic_initstring(char *str, const long n);
293void sc_basic_terminatestring(char *str);
294char *sc_basic_strtrim(char *str);
295void sc_basic_strtrim_inplace(char *str);
296cpl_boolean sc_basic_isnumber(char *str);
297cpl_boolean sc_basic_isinteger(char *str);
298cpl_error_code sc_basic_interpollin(const double *x_out, double *y_out,
299 const long n_out, const double *x_ref,
300 const double *y_ref, const long n_ref,
301 const int extrapolate);
302extern int sc_basic_gaussfunc(double *fgauss, const double *xgauss,
303 const int n_data, const double *par);
304cpl_error_code sc_basic_getfilename(char *dir, char *filename, char *suffix,
305 const char *path);
306cpl_error_code sc_basic_getmaskval_vector(double maskval[2],
307 const cpl_vector *vector);
308cpl_error_code sc_basic_getmaskval_image(double maskval[2],
309 const cpl_image *image);
310cpl_error_code sc_basic_calcsinc(cpl_vector *sinc);
311
312#endif /* SC_BASIC_H */
313
314#ifdef __cplusplus
315}
316#endif
317
cpl_error_code sc_basic_rebin(cpl_table *outspec, const char *outlam, const char *outflux, const cpl_table *inspec, const char *inlam, const char *influx)
Definition: sc_basic.c:296
double sc_basic_mjd2fracyear(double mjd)
Definition: sc_basic.c:179
cpl_error_code sc_basic_linecount(long *n_lines, FILE *fp)
Definition: sc_basic.c:831
int sc_basic_gaussfunc(double *fgauss, const double *xgauss, const int n_data, const double *par)
Definition: sc_basic.c:2473
cpl_error_code sc_basic_access(const char *pathname, const int mode)
Definition: sc_basic.c:1199
cpl_error_code sc_basic_col2arr(cpl_array *arr, const cpl_table *tab, const char *colname)
Definition: sc_basic.c:1652
cpl_boolean sc_basic_isnumber(char *str)
Definition: sc_basic.c:2237
cpl_error_code sc_basic_clipmean(double *mean, double *rms, cpl_array *arr, const cpl_boolean clip)
Definition: sc_basic.c:1539
cpl_error_code sc_basic_copytable_content(cpl_table *outtab, const cpl_table *intab)
Definition: sc_basic.c:1923
cpl_error_code sc_basic_greg2jd(long *jd, const int year, const int month, const int day)
Definition: sc_basic.c:1297
cpl_error_code sc_basic_filtermedian(cpl_table *spec, const char *colname, const int npix)
Definition: sc_basic.c:745
cpl_error_code sc_basic_copytable_full(cpl_table *outtab, const cpl_table *intab)
Definition: sc_basic.c:1991
cpl_error_code sc_basic_interpollin(const double *x_out, double *y_out, const long n_out, const double *x_ref, const double *y_ref, const long n_ref, const int extrapolate)
Definition: sc_basic.c:2369
cpl_error_code sc_basic_convolve(cpl_table *spec, const char *colname, const cpl_array *kernel)
Definition: sc_basic.c:441
char * sc_basic_strtrim(char *str)
Definition: sc_basic.c:2115
cpl_error_code sc_basic_getmaskval_image(double maskval[2], const cpl_image *image)
Definition: sc_basic.c:2657
cpl_error_code sc_basic_arr2col(cpl_table *tab, const char *colname, const cpl_array *arr)
Definition: sc_basic.c:1757
double sc_basic_fracyear2date(int *year, int *month, int *day, int *hh, int *mm, double *ss, const double *fracyear)
Definition: sc_basic.c:206
void sc_basic_abspath(char *out, const char *dir, const char *cwd)
Definition: sc_basic.c:1133
void sc_basic_dirslash(char *dir)
Definition: sc_basic.c:1109
#define SC_LENLINE
Definition: sc_basic.h:92
void sc_basic_rhum2ppmv(double *ppmv, const double *tem, const double *p, const double *hum)
Definition: sc_basic.c:870
void sc_basic_initstring(char *str, const long n)
Definition: sc_basic.c:2060
cpl_error_code sc_basic_getfilename(char *dir, char *filename, char *suffix, const char *path)
Definition: sc_basic.c:2507
cpl_error_code sc_basic_convolvewindow(cpl_array *convflux, const cpl_array *flux, const int range[2], const cpl_array *kernel)
Definition: sc_basic.c:564
_sc_error_code_
Definition: sc_basic.h:128
struct _scpar_ scpar
cpl_error_code sc_basic_rhum2ppmv_old(const cpl_array *temp, const cpl_array *pres, const cpl_array *rhum, cpl_array *ppmv)
Definition: sc_basic.c:935
void sc_basic_strtrim_inplace(char *str)
Definition: sc_basic.c:2175
cpl_error_code sc_basic_readline(FILE *stream, scpar par[], int *npar)
Definition: sc_basic.c:52
cpl_error_code sc_basic_getmaskval_vector(double maskval[2], const cpl_vector *vector)
Definition: sc_basic.c:2601
cpl_error_code sc_basic_calcsinc(cpl_vector *sinc)
Definition: sc_basic.c:2714
cpl_error_code sc_basic_planck(cpl_array *bb, const cpl_array *wavelength, const double temp)
Definition: sc_basic.c:1058
cpl_error_code sc_basic_jd2greg(int *year, int *month, int *day, const long jd)
Definition: sc_basic.c:1334
cpl_error_code sc_basic_sortarr(cpl_array *arr, cpl_type type)
Definition: sc_basic.c:1871
void sc_basic_terminatestring(char *str)
Definition: sc_basic.c:2086
cpl_boolean sc_basic_isinteger(char *str)
Definition: sc_basic.c:2322
enum _sc_error_code_ sc_error_code