File: ccdfile_test.cpp

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 (163 lines) | stat: -rw-r--r-- 4,841 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
/**************************************************************

ccdfile_test.c (C-Munipack project)
Copyright (C) 2003 David Motl, dmotl@volny.cz

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; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

**************************************************************/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <fitsio.h>
#include <cmunipack.h>

extern CmpackConsole *g_console;

/* Testing FITS file */
#define FITS_FILE	"test_fits.fts"
/* Testing SBIG file */
#define SBIG_FILE	"test_sbig.st7"
/* Testing OES file */
#define OES_FILE	"test_oes.ast"
	
/* Input file name */
#define OUT_FILE	"test_out.fts"
/* Width of a sample file */
#define OUT_WIDTH	32
/* Height of a sample file */
#define OUT_HEIGHT	32

/* String buffer size */
#define MAXLINE		1024

/* Create sample FITS file */
static int test_out(const char *filename)
{
	fitsfile *fits;
	long naxes[2];
	int i, stat=0, nx = OUT_WIDTH, ny = OUT_HEIGHT;
	char buf[MAXLINE];
	time_t tsec;
	struct tm *actim;
	double *image;

	/* Create simple FITS file */
	remove(filename);
	ffdkinit(&fits, filename, &stat);
	if (stat!=0) {
		ffclos(fits, &stat);
		return stat;
	}

	/* Set file header */
	naxes[0]=nx; naxes[1]=ny;
	ffphps(fits, 16, 2, naxes, &stat);
	sprintf(buf, "%04d-%02d-%02d", 2005, 12, 31);
	ffukys(fits, "DATE-OBS", buf, "UT DATE OF START", &stat);
	sprintf(buf, "%02d:%02d:%02d.%03d", 12, 34, 56, 0);
	ffukys(fits, "TIME-OBS", buf, "UT TIME OF START", &stat);
	tsec = time(&tsec);
	actim = localtime(&tsec);
	sprintf(buf, "%04d-%02d-%02d", actim->tm_year+1900, actim->tm_mon+1, actim->tm_mday);
	ffpkys(fits, "DATE", buf, "DATE OF CREATION", &stat);
	ffpkys(fits, "ORIGIN", "C-Munipack test suite", "FILE ORIGIN", &stat);
	ffpkys(fits, "OBJECT", "Sample", "SAMPLE FITS FILE", &stat);
	ffpkyg(fits, "EXPTIME", 20.0, 2, "EXPOSURE IN SECONDS", &stat);
	ffpkyg(fits, "TEMPERAT", -10.0, 2, "TEMPERATURE IN DEGREES C", &stat);
	ffpkys(fits, "FILTER", "None", "OPTICAL FILTER NAME", &stat);
	/* Set image data */
	image = (double *)malloc(nx*ny*sizeof(double));
	if (image) {
		for (i=0; i<nx*ny; i++)
			image[i] = i;
		ffp2dd(fits, 1, nx, nx, ny, image, &stat);
		free(image);
	}
	/* Close file */
	ffclos(fits, &stat);
	return stat;
}

static void print_par(CmpackCcdFile *file)
{
	CmpackCcdParams params;
   	
	cmpack_ccd_get_params(file, CMPACK_CM_IMAGE | CMPACK_CM_FORMAT |
		CMPACK_CM_OBJECT | CMPACK_CM_DATETIME | CMPACK_CM_EXPOSURE |
		CMPACK_CM_CCDTEMP | CMPACK_CM_FILTER, &params);
	if (params.format_name)
		printf("File format: %s\n", params.format_name);
	printf("Image size : %d x %d pixels\n", params.image_width, params.image_height);
	if (params.object.designation)
		printf("Object     : %s\n", params.object.designation);
  	printf("Date & time: %2d.%2d.%04d %2d:%02d:%02d.%03d UT\n", 
		params.date_time.date.year, params.date_time.date.month, params.date_time.date.day, 
		params.date_time.time.hour, params.date_time.time.minute, params.date_time.time.second, 
		params.date_time.time.milisecond);
	if (params.exposure > 0)
		printf("Exposure   : %.2f s\n", params.exposure);
	if (params.ccdtemp > -999 && params.ccdtemp < 999)
		printf("Temperature: %.1f deg.C\n", params.ccdtemp);
	if (params.filter) 
		printf("Filter     : %s\n", params.filter);
}
 
/* Test reading FITS file */
static int test_read(const char *filename)
{
	int res;
	CmpackCcdFile *f = NULL;
	
	printf("Input file : %s\n", filename);
	res = cmpack_ccd_open(&f, filename, CMPACK_OPEN_READONLY, 0);
	if (f) {
		/* Print short info */
		print_par(f);
		/* Close files */
		cmpack_ccd_destroy(f);
	}
	printf("-------------------------------\n");
	return res;
}

int ccdfile_test(void)
{
	int res;

	/* Create sample FITS file */
	res = test_out(OUT_FILE);
	if (res!=0)
		return res;

	/* Read testing FITS file */
	res = test_read(FITS_FILE);
	if (res!=0)
		return res;

	/* Read testing SBIG file */
	res = test_read(SBIG_FILE);
	if (res!=0)
		return res;

	/* Read testing OES file */
	res = test_read(OES_FILE);
	if (res!=0)
		return res;

	return 0;
}