Kstars

nomadbinfile2sqlite.h
1 /*
2  SPDX-FileCopyrightText: 2011 Akarsh Simha <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #ifndef NOMADBINFILE2SQLITE_H
8 #define NOMADBINFILE2SQLITE_H
9 
10 #define pow2(x) (1 << (x))
11 #define HTM_LEVEL 6
12 #define INDEX_ENTRY_SIZE 12
13 #define NTRIXELS pow2(2 * HTM_LEVEL) * 8
14 #define PM_MILLENIA 10 // This is not good. Needs to be stored in the data file
15 
16 #include "HTMesh.h"
17 
18 #include <sqlite3.h>
19 #include <sys/types.h>
20 #include <stdio.h>
21 
22 /*
23  * struct to store star data, to be written in this format, into the binary file.
24  */
25 
26 typedef struct DeepStarData
27 {
28  int32_t RA;
29  int32_t Dec;
30  int16_t dRA;
31  int16_t dDec;
32  int16_t B;
33  int16_t V;
34 } DeepStarData;
35 
36 /**
37  *@class NOMADStarDataWriter
38  *@short Writes NOMAD star data
39  *@note This is ugly code, not part of the main KStars program
40  *@author Akarsh Simha <[email protected]>
41  */
43 {
44  public:
45  /**
46  *@short Constructor. Sets up the HTMesh, initializes various things.
47  */
48  NOMADStarDataWriter(FILE *f, int HTMLevel, sqlite3 *_db, char *_db_tbl);
49 
50  /**
51  *@short Destructor. Deletes the HTMesh we created.
52  */
54 
55  /**
56  *@short Byteswaps the DeepStarData structure
57  */
58  static void bswap_stardata(DeepStarData *stardata);
59 
60  /**
61  *@short Computes the (unprecessed) coordinates of a star after
62  * accounting for proper motion
63  */
64  static void calculatePMCoords(double startRA, double startDec, double dRA, double dDec, double *endRA,
65  double *endDec, float years);
66 
67  /**
68  *@short Writes the star data into the DB by calling multiple functions
69  *@return Whether the write was successful
70  */
71  bool write();
72 
73  private:
74  /**
75  *@short Creates the table to write data into
76  */
77  bool createTable();
78 
79  /**
80  *@short Truncates the table
81  */
82  bool truncateTable();
83 
84  /**
85  *@short Insert the star data into the database
86  *@param trixel The trixel in which the star exists according to the data file
87  *@param data The DeepStarData structure containing the star's information
88  *@return true if inserted or star was a duplicate, false if an error occurred
89  *@note This method takes care of duplicating the star and finding the number of copies
90  */
91  bool insertStarData(unsigned int trixel, const DeepStarData *const data);
92 
93  /**
94  *@short Write star data into the DB
95  *@note See README.binfileformat for more details
96  */
97  bool writeStarDataToDB();
98 
99  /**
100  *@short Read the KStars binary file header and gets various
101  * parameters required for further processing.
102  *@returns true on success.
103  */
104  bool readFileHeader();
105 
106  HTMesh *m_Mesh;
107  sqlite3 *db;
108  char db_tbl[20];
109  bool byteswap;
110  bool m_HeaderRead;
111  long m_IndexOffset;
112  u_int16_t ntrixels;
113  FILE *DataFile;
114 };
115 
116 #endif
bool write()
Writes the star data into the DB by calling multiple functions.
static void bswap_stardata(DeepStarData *stardata)
Byteswaps the DeepStarData structure.
Definition: HTMesh.h:56
Writes NOMAD star data.
NOMADStarDataWriter(FILE *f, int HTMLevel, MYSQL *link, char *_db_tbl)
Constructor.
A 16-byte structure that holds star data for really faint stars.
static void calculatePMCoords(double startRA, double startDec, double dRA, double dDec, double *endRA, double *endDec, float years)
Computes the (unprecessed) coordinates of a star after accounting for proper motion.
~NOMADStarDataWriter()
Destructor.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Aug 11 2022 04:00:02 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.