File indexing completed on 2024-09-08 03:28:59
0001 /* 0002 SPDX-FileCopyrightText: 2011 Akarsh Simha <akarshsimha@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef NOMADBINFILE2MYSQL_H 0008 #define NOMADBINFILE2MYSQL_H 0009 0010 #define pow2(x) (1 << (x)) 0011 #define HTM_LEVEL 6 0012 #define INDEX_ENTRY_SIZE 12 0013 #define NTRIXELS 32768 // TODO: Change if HTM Level Changes 0014 #define PM_MILLENIA 10 // This is not good. Needs to be stored in the data file 0015 0016 #include "HTMesh.h" 0017 0018 #include <mysql/mysql.h> 0019 #include <sys/types.h> 0020 #include <stdio.h> 0021 0022 /* 0023 * struct to store star data, to be written in this format, into the binary file. 0024 */ 0025 0026 typedef struct DeepStarData 0027 { 0028 int32_t RA; 0029 int32_t Dec; 0030 int16_t dRA; 0031 int16_t dDec; 0032 int16_t B; 0033 int16_t V; 0034 } DeepStarData; 0035 0036 /** 0037 *@class NOMADStarDataWriter 0038 *@short Writes NOMAD star data 0039 *@note This is ugly code, not part of the main KStars program 0040 *@author Akarsh Simha <akarsh.simha@kdemail.net> 0041 */ 0042 class NOMADStarDataWriter 0043 { 0044 public: 0045 /** 0046 *@short Constructor. Sets up the HTMesh, initializes various things. 0047 */ 0048 NOMADStarDataWriter(FILE *f, int HTMLevel, MYSQL *link, char *_db_tbl); 0049 0050 /** 0051 *@short Destructor. Deletes the HTMesh we created. 0052 */ 0053 ~NOMADStarDataWriter(); 0054 0055 /** 0056 *@short Byteswaps the DeepStarData structure 0057 */ 0058 static void bswap_stardata(DeepStarData *stardata); 0059 0060 /** 0061 *@short Computes the (unprecessed) coordinates of a star after 0062 * accounting for proper motion 0063 */ 0064 static void calculatePMCoords(double startRA, double startDec, double dRA, double dDec, double *endRA, 0065 double *endDec, float years); 0066 0067 /** 0068 *@short Writes the star data into the DB by calling multiple functions 0069 *@return Whether the write was successful 0070 */ 0071 bool write(); 0072 0073 private: 0074 /** 0075 *@short Creates the table to write data into 0076 */ 0077 bool createTable(); 0078 0079 /** 0080 *@short Truncates the table 0081 */ 0082 bool truncateTable(); 0083 0084 /** 0085 *@short Insert the star data into the database 0086 *@param trixel The trixel in which the star exists according to the data file 0087 *@param data The DeepStarData structure containing the star's information 0088 *@return true if inserted or star was a duplicate, false if an error occurred 0089 *@note This method takes care of duplicating the star and finding the number of copies 0090 */ 0091 bool insertStarData(unsigned int trixel, const DeepStarData *const data); 0092 0093 /** 0094 *@short Write star data into the DB 0095 *@note See README.binfileformat for more details 0096 */ 0097 bool writeStarDataToDB(); 0098 0099 /** 0100 *@short Read the KStars binary file header and gets various 0101 * parameters required for further processing. 0102 *@returns true on success. 0103 */ 0104 bool readFileHeader(); 0105 0106 HTMesh *m_Mesh; 0107 MYSQL *m_MySQLLink; 0108 char db_tbl[20]; 0109 bool byteswap; 0110 bool m_HeaderRead; 0111 long m_IndexOffset; 0112 u_int16_t ntrixels; 0113 FILE *DataFile; 0114 }; 0115 0116 #endif