void GuiderOneStar::SaveStarFITS() { double StarX = m_star.X; double StarY = m_star.Y; usImage *pImage = CurrentImage(); usImage tmpimg; tmpimg.Init(60,60); int start_x = ROUND(StarX)-30; int start_y = ROUND(StarY)-30; if ((start_x + 60) > pImage->Size.GetWidth()) start_x = pImage->Size.GetWidth() - 60; if ((start_y + 60) > pImage->Size.GetHeight()) start_y = pImage->Size.GetHeight() - 60; int x,y, width; width = pImage->Size.GetWidth(); unsigned short *usptr = tmpimg.ImageData; for (y=0; y<60; y++) for (x=0; x<60; x++, usptr++) *usptr = *(pImage->ImageData + (y+start_y)*width + (x+start_x)); wxString fname = Debug.GetLogDir() + PATHSEPSTR + "PHD_GuideStar" + wxDateTime::Now().Format(_T("_%j_%H%M%S")) + ".fit"; fitsfile *fptr; // FITS file pointer int status = 0; // CFITSIO status value MUST be initialized to zero! long fpixel[3] = {1,1,1}; long fsize[3]; char keyname[9]; // was 9 char keycomment[100]; char keystring[100]; int output_format=USHORT_IMG; fsize[0] = 60; fsize[1] = 60; fsize[2] = 0; PHD_fits_create_file(&fptr, fname, false, &status); if (!status) { fits_create_img(fptr,output_format, 2, fsize, &status); time_t now; struct tm *timestruct; time(&now); timestruct=gmtime(&now); sprintf(keyname,"DATE"); sprintf(keycomment,"UTC date that FITS file was created"); sprintf(keystring,"%.4d-%.2d-%.2d %.2d:%.2d:%.2d",timestruct->tm_year+1900,timestruct->tm_mon+1,timestruct->tm_mday,timestruct->tm_hour,timestruct->tm_min,timestruct->tm_sec); if (!status) fits_write_key(fptr, TSTRING, keyname, keystring, keycomment, &status); sprintf(keyname,"DATE-OBS"); sprintf(keycomment,"YYYY-MM-DDThh:mm:ss observation start, UT"); sprintf(keystring,"%s", (const char *) pImage->GetImgStartTime().c_str()); if (!status) fits_write_key(fptr, TSTRING, keyname, keystring, keycomment, &status); sprintf(keyname,"EXPOSURE"); sprintf(keycomment,"Exposure time [s]"); float dur = (float) pImage->ImgExpDur / 1000.0; if (!status) fits_write_key(fptr, TFLOAT, keyname, &dur, keycomment, &status); unsigned int tmp = 1; sprintf(keyname,"XBINNING"); sprintf(keycomment,"Camera binning mode"); fits_write_key(fptr, TUINT, keyname, &tmp, keycomment, &status); sprintf(keyname,"YBINNING"); sprintf(keycomment,"Camera binning mode"); fits_write_key(fptr, TUINT, keyname, &tmp, keycomment, &status); sprintf(keyname,"XORGSUB"); sprintf(keycomment,"Subframe x position in binned pixels"); tmp = start_x; fits_write_key(fptr, TINT, keyname, &tmp, keycomment, &status); sprintf(keyname,"YORGSUB"); sprintf(keycomment,"Subframe y position in binned pixels"); tmp = start_y; fits_write_key(fptr, TINT, keyname, &tmp, keycomment, &status); if (!status) fits_write_pix(fptr,TUSHORT,fpixel,tmpimg.NPixels,tmpimg.ImageData,&status); } PHD_fits_close_file(fptr); }
bool usImage::Save(const wxString& fname, const wxString& hdrNote) const { bool bError = false; try { long fsize[3] = { (long)Size.GetWidth(), (long)Size.GetHeight(), 0L, }; long fpixel[3] = { 1, 1, 1 }; fitsfile *fptr; // FITS file pointer int status = 0; // CFITSIO status value MUST be initialized to zero! PHD_fits_create_file(&fptr, fname, true, &status); fits_create_img(fptr, USHORT_IMG, 2, fsize, &status); FITSHdrWriter hdr(fptr, &status); float exposure = (float) ImgExpDur / 1000.0; hdr.write("EXPOSURE", exposure, "Exposure time in seconds"); if (ImgStackCnt > 1) hdr.write("STACKCNT", (unsigned int) ImgStackCnt, "Stacked frame count"); if (!hdrNote.IsEmpty()) hdr.write("USERNOTE", static_cast<const char *>(hdrNote), 0); time_t now = wxDateTime::GetTimeNow(); struct tm *timestruct = gmtime(&now); char buf[100]; sprintf(buf, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d", timestruct->tm_year + 1900, timestruct->tm_mon + 1, timestruct->tm_mday, timestruct->tm_hour, timestruct->tm_min, timestruct->tm_sec); hdr.write("DATE", buf, "Time FITS file was created"); hdr.write("DATE-OBS", GetImgStartTime().c_str(), "Time image was captured"); hdr.write("CREATOR", wxString(APPNAME _T(" ") FULLVER).c_str(), "Capture software"); if (pCamera) { hdr.write("INSTRUME", pCamera->Name.c_str(), "Instrument name"); unsigned int b = pCamera->Binning; hdr.write("XBINNING", b, "Camera X Bin"); hdr.write("YBINNING", b, "Camera Y Bin"); hdr.write("CCDXBIN", b, "Camera X Bin"); hdr.write("CCDYBIN", b, "Camera Y Bin"); float sz = b * pCamera->PixelSize; hdr.write("XPIXSZ", sz, "pixel size in microns (with binning)"); hdr.write("YPIXSZ", sz, "pixel size in microns (with binning)"); } if (pPointingSource) { double ra, dec, st; pPointingSource->GetCoordinates(&ra, &dec, &st); hdr.write("RA", (float) (ra * 360.0 / 24.0), "Object Right Ascension in degrees"); hdr.write("DEC", (float) dec, "Object Declination in degrees"); { int h = (int) ra; ra -= h; ra *= 60.0; int m = (int) ra; ra -= m; ra *= 60.0; hdr.write("OBJCTRA", wxString::Format("%02d %02d %06.3f", h, m, ra).c_str(), "Object Right Ascension in hms"); } { int sign = dec < 0.0 ? -1 : +1; dec *= sign; int d = (int) dec; dec -= d; dec *= 60.0; int m = (int) dec; dec -= m; dec *= 60.0; hdr.write("OBJCTDEC", wxString::Format("%c%d %02d %06.3f", sign < 0 ? '-' : '+', d, m, dec).c_str(), "Object Declination in dms"); } } float sc = (float) pFrame->GetCameraPixelScale(); hdr.write("SCALE", sc, "Image scale (arcsec / pixel)"); hdr.write("PIXSCALE", sc, "Image scale (arcsec / pixel)"); fits_write_pix(fptr, TUSHORT, fpixel, NPixels, ImageData, &status); PHD_fits_close_file(fptr); bError = status ? true : false; } catch (wxString Msg) { POSSIBLY_UNUSED(Msg); bError = true; } return bError; }