1 /*
2 *  fitsiowrap.h
3 *  PHD Guiding
4 *
5 *  Created by Andy Galasso
6 *  Copyright (c) 2014 Andy Galasso
7 *  All rights reserved.
8 *
9 *  This source code is distributed under the following "BSD" license
10 *  Redistribution and use in source and binary forms, with or without
11 *  modification, are permitted provided that the following conditions are met:
12 *    Redistributions of source code must retain the above copyright notice,
13 *     this list of conditions and the following disclaimer.
14 *    Redistributions in binary form must reproduce the above copyright notice,
15 *     this list of conditions and the following disclaimer in the
16 *     documentation and/or other materials provided with the distribution.
17 *    Neither the name of Craig Stark, Stark Labs,
18 *     Bret McKee, Dad Dog Development, Ltd, nor the names of its
19 *     contributors may be used to endorse or promote products derived from
20 *     this software without specific prior written permission.
21 *
22 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 *  POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
35 
36 #ifndef FITSIOWRAP_INCLUDED
37 #define FITSIOWRAP_INCLUDED
38 
39 #include "fitsio.h"
40 
41 extern int PHD_fits_open_diskfile(fitsfile **fptr, const wxString& filename, int iomode, int *status);
42 extern int PHD_fits_create_file(fitsfile **fptr, const wxString& filename, bool clobber, int *status);
43 extern void PHD_fits_close_file(fitsfile *fptr);
44 
45 class FITSHdrWriter
46 {
47     fitsfile *fptr;
48     int *status;
49 
50 public:
51 
FITSHdrWriter(fitsfile * fptr_,int * status_)52     FITSHdrWriter(fitsfile *fptr_, int *status_) : fptr(fptr_), status(status_) { }
53 
write(const char * key,float val,const char * comment)54     void write(const char *key, float val, const char *comment) {
55         fits_write_key(fptr, TFLOAT, const_cast<char *>(key), &val, const_cast<char *>(comment), status);
56     }
57 
write(const char * key,unsigned int val,const char * comment)58     void write(const char *key, unsigned int val, const char *comment) {
59         fits_write_key(fptr, TUINT, const_cast<char *>(key), &val, const_cast<char *>(comment), status);
60     }
61 
write(const char * key,int val,const char * comment)62     void write(const char *key, int val, const char *comment) {
63         fits_write_key(fptr, TINT, const_cast<char *>(key), &val, const_cast<char *>(comment), status);
64     }
65 
write(const char * key,const char * val,const char * comment)66     void write(const char *key, const char *val, const char *comment) {
67         fits_write_key(fptr, TSTRING, const_cast<char *>(key), const_cast<char *>(val), const_cast<char *>(comment), status);
68     }
69 
write(const char * key,const wxDateTime & t,const wxDateTime::TimeZone & z,const char * comment)70     void write(const char *key, const wxDateTime& t, const wxDateTime::TimeZone& z, const char *comment) {
71         wxString s = t.Format("%Y-%m-%dT%H:%M:%S", z) + wxString::Format(".%03d", t.GetMillisecond(z));
72         write(key, (const char *) s.c_str(), comment);
73     }
74 };
75 
76 #endif
77