File: cmpack_phtfile.h

package info (click to toggle)
c-munipack 2.1.38-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,888 kB
  • sloc: ansic: 200,762; cpp: 106,123; lex: 9,035; yacc: 4,916; sh: 4,074; fortran: 2,613; xml: 2,105; python: 1,182; makefile: 546; perl: 104
file content (493 lines) | stat: -rw-r--r-- 19,904 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
/**
	\file
	\brief Functions for reading and writing photometry files.

	Photometry files contain photometry result for a single CCD frame.
	The file is valid standalone XML document. This format was introduced
	in the version 1.2
	
	\author David Motl <dmotl@volny.cz>
	
	\par Copying
	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation, version 2.
	
	$Id: cmpack_phtfile.h,v 1.3 2016/05/19 20:47:18 dmotl Exp $
*/

#ifndef _CMPACK_PHFILE_H_INCLUDED
#define _CMPACK_PHFILE_H_INCLUDED

#include "cmpack_common.h"
#include "cmpack_wcs.h"
#include "cmpack_table.h"

/*****************    Private data structures    ***************************/

/** 
	\brief Photometry file context
	\details This private structure holds the content of the read-all file.
*/
typedef struct _CmpackPhtFile CmpackPhtFile;

/** \brief Photometry file parameters */
typedef struct _CmpackPhtInfo
{
	int width;							/**< Width of frame in pixels */
	int height;							/**< Height of frame in pixels */
	double jd;							/**< Julian date of observation */
	char *filter;						/**< Color filter name */
	double exptime;						/**< Exposure duration in seconds */
	double ccdtemp;						/**< CCD temperature in deg. C */
	char *origin;						/**< Origin of the file (photometry software) */
	struct tm crtime;					/**< Creation time */
	double range[2];					/**< Low and high cutoff of pixel values */
	double gain;						/**< ADC gain */
	double rnoise;						/**< Readout noise */
	double fwhm_exp;					/**< Expected FWHM of objects */
	double fwhm_mean;					/**< Measured mean FWHM of objects */
	double fwhm_err;					/**< Standard deviation of FHWM of objects */
	double threshold;					/**< Detection threshold */
	double sharpness[2];				/**< Allowed range of roundness of objects */
	double roundness[2];				/**< Allowed range of sharpness of objects */
	int	matched;						/**< Non-zero if the frame has been matched */
	int match_rstars;					/**< Maximum number of stars used in Solve procedure */
	int match_istars;					/**< Number of vertices of polygons */
	int match_mstars;					/**< Number of stars that were successfully matched */
	double match_clip;					/**< Clipping threshold for matching */
	double offset[2];					/**< Frame offset in pixels */
	CmpackObjCoords object;				/**< Object's designation and coordinates */
	CmpackLocation location;			/**< Observer's location and coordinates */
	CmpackMatrix trafo;					/**< Trasformation matrix between the frame and the reference frame */
} CmpackPhtInfo;

/**	\brief Frame property flags */
typedef enum _CmpackPhtInfoMask
{
	CMPACK_PI_FRAME_PARAMS	= (1<<0),	/**< Fields: width, height, jd, filter, exptime, ccdtemp */
	CMPACK_PI_ORIGIN_CRDATE	= (1<<1),	/**< Fields: origin, crtime */
	CMPACK_PI_PHOT_PARAMS	= (1<<2),	/**< Fields: range, gain, rnoise, fwhm_*, threshold, sharpness, roundness */
	CMPACK_PI_MATCH_PARAMS	= (1<<3),	/**< Fields: matched, match_*, offset */
	CMPACK_PI_OBJECT		= (1<<4),	/**< Fields: object.* */
	CMPACK_PI_LOCATION		= (1<<5),	/**< Fields: location.* */
	CMPACK_PI_TRAFO			= (1<<6),	/**< Fields: trafo */
	CMPACK_PI_JD			= (1<<7)	/**< Fields: jd */
} CmpackPhtInfoMask;

/**	\brief Object properties */
typedef struct _CmpackPhtObject
{
	int id;								/**< Object identifier */
	int ref_id;							/**< Reference identifier */
	double x;							/**< Center - X coordinate */
	double y;							/**< Center - Y coordinate */
	double skymed;						/**< Background mean level in ADU */
	double skysig;						/**< Background noise level in ADU */
	double fwhm;						/**< Full width at half maximum in pixels */
} CmpackPhtObject;

/**	\brief Frame property flags */
typedef enum _CmpackPhtObjectMask
{
	CMPACK_PO_ID		= (1<<0),		/**< Fields: id (read only) */
	CMPACK_PO_REF_ID	= (1<<1),		/**< Fields: ref_id */
	CMPACK_PO_CENTER	= (1<<2),		/**< Fields: x, y */
	CMPACK_PO_SKY		= (1<<3),		/**< Fields: skymed, skysig */
	CMPACK_PO_FWHM		= (1<<4)		/**< Fields: fwhm */
} CmpackPhtObjectMask;

/**	\brief Aperture properties */
typedef struct _CmpackPhtAperture
{
	int id;								/**< Aperture identifier */
	double radius;						/**< Radius in pixels */
} CmpackPhtAperture;

/** \brief Aperture property flags */
typedef enum _CmpackPhtApertureFlags
{
	CMPACK_PA_ID		= (1<<0),		/**< Fields: id (read only) */
	CMPACK_PA_RADIUS	= (1<<1)		/**< Fields: radius */
} CmpackPhtApertureFlags;

/** \brief Measurement of an object for an aperture */
typedef struct _CmpackPhtData
{
	int		mag_valid;					/**< Is the magnitude valid? */
	double	magnitude;					/**< Instrumental magnitude */
	double	mag_error;					/**< Error estimation of brightness (0 = not available) */
} CmpackPhtData;

/********************   Public functions   **************************/

#ifdef __cplusplus
extern "C" {
#endif

/**
	\brief Create a new photometry file context
	\details The function creates a new photometry file and returns a new 
	reference to it. This file is designed to store data temporarily
	in the memory. To open a file from the disk or create a permanent
	file, use cmpack_pht_open() function instead. The reference counter 
	is set to one. The caller is responsible to call cmpack_pht_close() 
	or cmpack_pht_destroy() when it is no longer needed.
	\return pointer to a new reference
*/
	CMPACK_EXPORT(CmpackPhtFile*, cmpack_pht_init, (void));

/**
	\brief Make a new reference to the catalog file
	\details The function makes a new reference to the file and returns a 
	pointer to it. The reference counter is incremented by one. The caller 
	is responsible to call cmpack_pht_destroy() when the reference is 
	no longer needed.
	\param[in]	file		file context
	\return pointer to a new reference
*/
	CMPACK_EXPORT(CmpackPhtFile*, cmpack_pht_reference, (CmpackPhtFile* file));

/**
	\brief Release a reference to the photometry file.
	\details The function releases a reference to the file. The reference 
	counter is decreased by one and when it was the last reference to the 
	file, the content of the disk file is updated and it is closed. The data
	are freed from the memory.
	\param[in]	file		file context
*/
	CMPACK_EXPORT(void, cmpack_pht_destroy, (CmpackPhtFile* file));

/**
	\brief Open or create a photometry file stored on the disk.
	\details The function opens an existing photometry file stored on the
	disk or creates a new file. 
	\param[out]	file			new file context
	\param[in] 	filename		path + file name
	\param[in]	mode			opening mode (see CMPACK_OPEN_xxx constants)
	\param[in] 	flags 			not used, should be 0
	\return zero on success, error code on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_open, (CmpackPhtFile** file, const char* filename,
		CmpackOpenMode mode, unsigned flags));

/**
	\brief Close photometry file and release the reference
	\details The function updates the content of the disk file and 
	closes the file. The context is then switched to the read-only
	mode, so it is possible in some cases to retrieve the information, 
	but the file cannot be modified. The function also decrements the 
	reference counter and when it was the last reference, the memory 
	is freed. In that case, the context is no longer valid and it is 
	not possible to retrieve the information from it.
	\param[in]	file			file context
	\return zero on success, error code on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_close, (CmpackPhtFile* file));

/**
	\brief Copy content of the photometry file 
	\details The function makes copy of the source photometry file
	and to the target photometry file. If the target file contains
	any information, it is overwritten.
	\param[in] dstfile			target file
	\param[in] srcfile			source file
	\return zero on success, error code on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_copy, (CmpackPhtFile* dstfile, CmpackPhtFile* srcfile));

/**
	\brief Clear the photometry file
	\details The function deletes all defined objects and sets all header
	fields to default values.
	\param[in]	file			catalog file 
*/
	CMPACK_EXPORT(void, cmpack_pht_clear, (CmpackPhtFile* file));

/** 
	\brief Test if given file seems to be a valid photometry file
	\details The function reads the beginning of the file and
	examines them to check if the file is a valid catalogue file or not.
	This function is used for file format autodetection.
	\param[in] 	filename		path + file name
	\return nonzero if the file is a valid photometry file, zero otherwise
*/
	CMPACK_EXPORT(int, cmpack_pht_test, (const char* filename));

/** 
	\brief Test memory buffer if it seems to be a valid photometry file
	\details The function examines the given memory buffer to check
	if the buffer contains a beginning of a valid photometry file or not.
	This function is used for file format autodetection.
	\param[in] 	buffer			data to be examined
	\param[in]	buflen			number of bytes in the buffer
	\param[in]	filesize		real size of the complete file in bytes
	\return nonzero if the file is a valid catalog file, zero otherwise
*/
	CMPACK_EXPORT(int, cmpack_pht_test_buffer, (const char* buffer, int buflen, int filesize));

/**
	\brief Dump content of the photometry file to a file
	\details The function makes a table of objects and their positions.
	If a valid aperture index is specified, the function dumps also
	magnitudes and their error. If aperture is not specified, the first aperture
	is used as a default.
	\param[in] file				file context
	\param[out] table			new table with the light curve
	\param[in] aperture			aperture index (-1 = use first aperture)
	\param[in] con				where debug messages are printed to
	\param[in] flags			reserved for future use, set to zero
	\return zero on success or error code on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_dump, (CmpackPhtFile* file, CmpackTable** table, int aperture, 
		CmpackConsole* con, unsigned flags));

/******************* File header ***************************/

/**
	\brief Set frame parameters to the photometry file
	\details The function sets the parameters that are stored in the
	header of the photometry file.
	\param[in] file 		file context
	\param[in] mask			which fields shall be changed
	\param[in] info			frame properties
	\return zero on success or error code on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_set_info, (CmpackPhtFile* file, unsigned mask, const CmpackPhtInfo* info));

/**
	\brief Get frame parameters from the photometry file
	\details 
	\param[in] file 		file context
	\param[in] mask			which fields shall be retrieved
	\param[out] info		frame properties
	\return zero on success or error code on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_get_info, (CmpackPhtFile* file, unsigned mask, CmpackPhtInfo* info));

/************************* Table of apertures ********************************/

/**
	\brief Get number of apertures stored in a photometry file
	\details The function returns the number of apertures that
	are defined in the photometry file.
	\param[in]	file 		file context
	\return number of apertures or zero on failure.
*/
	CMPACK_EXPORT(int, cmpack_pht_aperture_count, (CmpackPhtFile* file));

/**
	\brief Find aperture in the photometry file by identifier
	\details The function finds an aperture record with specified
	aperture identifier and returns its index. When such record does
	not exist, the function returns -1.
	\param[in] file			file context
	\param[in] aper_id		aperture identifier
	\return aperture index or negative value on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_find_aperture, (CmpackPhtFile* file, int aper_id));

/** 
	\brief Add new aperture to a file
	\details The function adds a new aperture to the photometry file. The
	aperture is appended to the end of the table.
	\param[in] file			file context
	\param[in] mask			which fields shall be initialized
	\param[in] data			initial parameters
	\returns aperture index or negative value on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_add_aperture, (CmpackPhtFile* file, unsigned mask,
		const CmpackPhtAperture* data));

/** 
	\brief Get aperture parameters
	\details The function reads aperture parameters. The caller specify
	by a bitmask which parameters shall be retrieved.
	\param[in] file			file context
	\param[in] index		aperture index
	\param[in] mask			which fields shall be retieved
	\param[out] data		aperture parameters
	\return returns zero on success or error code on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_get_aperture, (CmpackPhtFile* file, int index, unsigned mask,
		CmpackPhtAperture* data));

/** 
	\brief Get radius of an aperture
	\details The function returns radius of the aperture
	from the table of apertures. The item is specified by an index
	to the table.
	\param[in] file			file context
	\param[in] index		aperture index
	\param[in] mask			which fields shall be modified
	\param[in] data			aperture parameters
	\return returns zero on success or error code on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_set_aperture, (CmpackPhtFile* file, int index, unsigned mask,
		const CmpackPhtAperture* data));

/*************************** Table of stars **********************************/

/**
	\brief Get number of stars stored in a photometry file
	\details The function returns number of objects that are
	defined in the photometry file.
	\param[in]	file 		file context
	\return zero on success, error code on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_object_count, (CmpackPhtFile* file));

/**
	\brief Add new star to a file
	\details The function creates a new record in the table 
	of objects and assigns its properties. The new record is
	appended to the end of the table.
	\param[in] file			file context
	\param[in] mask			which fields shall be initialized
	\param[in] info			object properties
	\return star index or negative value on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_add_object, (CmpackPhtFile* file, unsigned mask,
		const CmpackPhtObject* info));

/**
	\brief Get star context by object identifier or reference identifier
	\details The function finds an object record with specified
	object/reference identifier and returns its index. When such record does
	not exist, the function returns -1.
	\param[in] file			file context
	\param[in] id			identifier
	\param[in] ref_id		0 = object id, 1 = reference id
	\return star index or negative value on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_find_object, (CmpackPhtFile* file, int id, int ref_id));

/**
	\brief Get object parameters
	\details The function retrieves object properties from 
	the record that is indicated by its index. When such record 
	does not exist, an error code is returned.
	\param[in] file			file context
	\param[in] index		object index
	\param[in] mask			which fields shall be retrieved?
	\param[out] info		object properties
	\return zero on success or error code on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_get_object, (CmpackPhtFile* file, int index, unsigned mask,
		CmpackPhtObject* info));

/**
	\brief Set object parameters
	\details The function changes object properties in the record
	that is indicated by its index. 
	\param[in] file			file context
	\param[in] index		record index
	\param[in] mask			which fields shall be modified?
	\param[in] info			object properties
	\return zero on success or error code on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_set_object, (CmpackPhtFile* file, int index, unsigned mask,
		const CmpackPhtObject* info));

/*************************** Measurements **********************************/

/**
	\brief Set measurement to the photometry file
	\details The function sets measurement data for specified
	object and aperture. 
	\param[in] file			photometry file
	\param[in] object		object index
	\param[in] aperture		aperture index
	\param[in] data			measurement data
	\return zero on success or error code on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_set_data, (CmpackPhtFile* file, int object, int aperture,
		const CmpackPhtData* data));

/**
	\brief Set measurement to the photometry file
	\details The function sets measurement data for specified
	object and aperture. 
	\param[in] file			photometry file
	\param[in] object		object index
	\param[in] aperture		aperture index
	\param[in] data			measurement data
	\param[in] code			code indicating a reason why the brightness was not measured
	\return zero on success or error code on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_set_data_with_code, (CmpackPhtFile* file, int object, int aperture,
		const CmpackPhtData* data, CmpackError code));

/**
	\brief Get measurement from the photometry file
	\details The function retrieves measurement data for specified
	object and aperture. 
	Please note: The function returns zero if it has found the record
	for the indicated star and aperture. It may happen, that the brightness
	was not measured. The function returns zero and clears the data.mag_valid flag.
	\param[in] file			photometry file
	\param[in] object		object index
	\param[in] aperture		aperture index
	\param[out] data		measurement data
	\return zero on success or error code on failure.
*/
	CMPACK_EXPORT(int, cmpack_pht_get_data, (CmpackPhtFile* file, int object, int aperture,
		CmpackPhtData* data));

/**
	\brief Get measurement from the photometry file
	\details The function retrieves measurement data for specified
	object and aperture. 
	Please note: The function returns zero if it has found the record
	for the indicated star and aperture. It may happen, that the brightness
	was not measured. The function returns zero and clears the data.mag_valid flag.
	\param[in] file			photometry file
	\param[in] object		object index
	\param[in] aperture		aperture index
	\param[out] data		measurement data
	\param[out] code		code indicating reason why the brightness was not measured
	\return zero on success or error code on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_get_data_with_code, (CmpackPhtFile* file, int object, int aperture,
		CmpackPhtData* data, CmpackError* code));

/**
	\brief Get code indicating reason why the brightness was not measured
	\details The function retrieves error code for specified object and aperture. 
	\param[in] file			photometry file
	\param[in] object		object index
	\param[in] aperture		aperture index
	\param[out] code		code indicating reason why the brightness was not measured
	\return zero on success or error code on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_get_code, (CmpackPhtFile* file, int object, int aperture,
		CmpackError* code));

/*************************** World Coordinate System **********************************/

/**
	\brief Update World Coordinate System (WCS) data in the file
	\details The function updates the WCS data stored in the file. 
	\param[in] file			photometry file
	\param[in] wcs			WCS data to be saved to the file
	\returns zero on success, error code on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_set_wcs, (CmpackPhtFile* file, const CmpackWcs* wcs));

/**
	\brief Read World Coordinate System (WCS) data from the file
	\details The function retrieves WCS data stored in the file. The data
	are returned as a new CmpackWcs object. If the file contains several 
	WCS data sets, all of them are retrieved. The returned object is a pointer
	to internal data, the caller should not modify or free it.
	\param[in] file			photometry file
	\param[out] wcs			WCS data retrieved from the file
	\returns zero on success, error code on failure
*/
	CMPACK_EXPORT(int, cmpack_pht_get_wcs, (CmpackPhtFile* file, CmpackWcs** wcs));

#ifdef __cplusplus
}
#endif

#endif