File indexing completed on 2024-09-08 03:28:59
0001 /* 0002 SPDX-FileCopyrightText: 2008 Akarsh Simha <akarshsimha@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #define HTM_LEVEL 6 // Does not matter 0008 #include "binfile.h" 0009 0010 #include <stdio.h> 0011 #include <stdlib.h> 0012 #include <math.h> 0013 #include <sys/types.h> 0014 #include <string.h> 0015 #include "byteorder.h" 0016 0017 /* 0018 * struct to store star data, to be written in this format, into the binary file. 0019 */ 0020 0021 typedef struct deepStarData 0022 { 0023 int32_t RA; 0024 int32_t Dec; 0025 int16_t dRA; 0026 int16_t dDec; 0027 int16_t B; 0028 int16_t V; 0029 } deepStarData; 0030 0031 /* 0032 * Does byteswapping for deepStarData structures 0033 */ 0034 void bswap_stardata(deepStarData *stardata) 0035 { 0036 stardata->RA = bswap_32(stardata->RA); 0037 stardata->Dec = bswap_32(stardata->Dec); 0038 stardata->dRA = bswap_16(stardata->dRA); 0039 stardata->dDec = bswap_16(stardata->dDec); 0040 stardata->B = bswap_16(stardata->B); 0041 stardata->V = bswap_16(stardata->V); 0042 } 0043 0044 int main(int argc, char *argv[]) 0045 { 0046 FILE *f; 0047 deepStarData data; 0048 0049 if (argc > 1) 0050 { 0051 f = fopen(argv[1], "rb"); 0052 if (f == NULL) 0053 { 0054 fprintf(stderr, "ERROR: Could not open file %s for binary read.\n", argv[1]); 0055 return 1; 0056 } 0057 } 0058 else 0059 f = stdin; 0060 0061 int id = 0; 0062 while (!feof(f)) 0063 { 0064 if (!fread(&data, sizeof(deepStarData), 1, f) && !feof(f)) 0065 { 0066 fprintf(stderr, "WARNING: Looks like we encountered a premature end\n"); 0067 break; 0068 } 0069 // if( byteswap ) bswap_stardata( &data ); 0070 fprintf(stdout, "*** Entry #%d ***\n", id); 0071 fprintf(stdout, "\tRA = %f\n", data.RA / 1000000.0); 0072 fprintf(stdout, "\tDec = %f\n", data.Dec / 100000.0); 0073 fprintf(stdout, "\tdRA/dt = %f\n", data.dRA / 1000.0); 0074 fprintf(stdout, "\tdDec/dt = %f\n", data.dDec / 1000.0); 0075 fprintf(stdout, "\tB = %f\n", data.B / 1000.0); 0076 fprintf(stdout, "\tV = %f\n", data.V / 1000.0); 0077 ++id; 0078 } 0079 0080 fclose(f); 0081 0082 return 0; 0083 }