#include "SaoFile.h" #include #include #include "slamac.h" #include "File.h" #define FALSE 0 #define TRUE 1 static int lt(sort_t *t1, sort_t *t2) { // t1->ra < t2->ra if (t1->ra < t2->ra) return 1; // t1->ra > t2->ra if (t1->ra > t2->ra) return 0; // t1->ra == t2->ra if (t1->dec < t2->dec) return 1; else return 0; } static void rekMergesort(sort_t **a, int length, int l, int r) { // a recursive merge sort algorithm if ( r <= l ) return; sort_t **b = new sort_t*[length]; int m = (r+l)/2; rekMergesort(a, length, l, m); rekMergesort(a, length, m+1, r); int i; for (i=m+1; i>l; i--) b[i-1]=a[i-1]; int j; for (j=m; jSize()/(compressed?70-20:205); cout << "Opening" << (compressed?" compressed":"") << " catalog '" << name << "'" << " with " << fEntries << " entries" << endl; delFlag = ' '; } SaoFile::~SaoFile() { delete file; } int SaoFile::GetEntryNr() const { return file->Tell()/(compressed?70-20:205); } int SaoFile::GetEntry(const int i) { file->Seek(i*(compressed?70-20:205)); return GetNextEntry(); } void SaoFile::Reset() const { file->Seek(0); } int SaoFile::GetNextEntry() { if (file->Eof()) return FALSE; SAO = file->Geti(6); if (!compressed) { delFlag = file->Getc(); file->Skip(77-8); } Pmag = file->Getf(4); Vmag = file->Getf(4); if (!compressed) file->Skip(161/*151*/-85); /* RA2000h = file->geti(2); RA2000m = file->geti(2); RA2000s = file->getf(6); */ pmRA2000 = file->Getf(7); if (!compressed) file->Skip(178-168); /* DE2000sgn = file->getc(); DE2000d = file->geti(2); DE2000m = file->geti(2); DE2000s = file->getf(5); */ pmDE2000 = file->Getf(6); RA2000rad = file->Getf(10); DE2000rad = file->Getf(11); file->Newline(); sprintf(data, "%6i%4.1f%4.1f"/*"%2i%2i%6.3f"*/"%7.4f"/*"%c%2i%2i%5.2f"*/"%6.3f%10.8f%11.8f\n", Nr(), MagP(), MagV(), /*RaH(), RaM(), RaS(),*/ RaPm(), /*DecSgn(), DecD(), DecM(), DecS(),*/ DecPm(), Ra(), Dec()); return !file->Eof(); } void SaoFile::Print() const { cout << SAO << " " << delFlag << " " << Pmag << " " << Vmag << " " << /*RA2000h << "h" << RA2000m << "m" << RA2000s << "s " << */pmRA2000 << " " << /*DE2000sgn << DE2000d << "d" << DE2000m << "m" << DE2000s << "s " << */pmDE2000 << " Ra:" << RA2000rad << " Dec:" << DE2000rad << endl; } void SaoFile::Compress() { FILE *f = fopen("sao.cmp", "w"); cout << endl << " Compressing catalog..." << flush; const int entries = GetNrOfEntries(); const int step = entries/360; for (int i=0; ira = (int)(360.0*(Ra()/D2PI)); srt[counter]->dec = (int)(360.0*(Dec()/D2PI)); srt[counter]->nr = counter; if (counter%step==0) cout << "." << flush; counter++; } cout << "done." << endl << endl; /* sort entries */ cout << "Sorting coordinates..." << flush; rekMergesort(srt, entries, 0, entries-1); cout << "done." << endl << endl; cout << "Writing sorted catalogue..." << flush; FILE *f = fopen("sao-sort.cmp", "w"); FILE *idx = fopen("sao-sort.idx", "w"); int ra=0, ral=0; int dec=0, decl=0; for (int i=0; inr); ra = (int)(360.0*Ra()/D2PI); dec = (int)(360.0*Dec()/D2PI); if (ra!=ral || dec!=decl) { if (ra!=ral) cout << "." << flush; fprintf(idx, "%3d %3d %10d\n", ra, dec, i); } ral = ra; decl = dec; fprintf(f, String()); if (i%5000==0) cout << "." << flush; } fclose(idx); fclose(f); cout << "done." << endl; }