size_t write_memory(void** mem, size_t width, size_t height, size_t noutput, cl_float* output[], const char* names[]) { int status = 0; // memory block *mem = NULL; size_t siz = 0; // the FITS file fitsfile* fptr; // create in-memory FITS fits_create_memfile(&fptr, mem, &siz, 0, realloc, &status); // write in-memory FITS write_fits(fptr, TFLOAT, width, height, noutput, (void**)output, names, &status); // close in-memory FITS fits_close_file(fptr, &status); // report FITS errors if(status) fits_error(NULL, status); // return the in-memory FITS return siz; }
bool INDI::CCD::ExposureComplete(CCDChip *targetChip) { void *memptr; size_t memsize; int img_type=0; int byte_type=0; int status=0; long naxes[2]; long naxis=2; int nelements=0; fitsfile *fptr=NULL; naxes[0]=targetChip->getSubW()/targetChip->getBinX(); naxes[1]=targetChip->getSubH()/targetChip->getBinY(); switch (targetChip->getBPP()) { case 8: byte_type = TBYTE; img_type = BYTE_IMG; break; case 16: byte_type = TUSHORT; img_type = USHORT_IMG; break; case 32: byte_type = TULONG; img_type = ULONG_IMG; break; default: IDLog("Unsupported bits per pixel value %d\n", targetChip->getBPP() ); return false; break; } nelements = naxes[0] * naxes[1]; // Now we have to send fits format data to the client memsize=5760; memptr=malloc(memsize); if(!memptr) { IDLog("Error: failed to allocate memory: %lu\n",(unsigned long)memsize); } fits_create_memfile(&fptr,&memptr,&memsize,2880,realloc,&status); if(status) { IDLog("Error: Failed to create FITS image\n"); fits_report_error(stderr, status); /* print out any error messages */ return false; } fits_create_img(fptr, img_type , naxis, naxes, &status); if (status) { IDLog("Error: Failed to create FITS image\n"); fits_report_error(stderr, status); /* print out any error messages */ return false; } addFITSKeywords(fptr, targetChip); fits_write_img(fptr,byte_type,1,nelements,targetChip->getFrameBuffer(),&status); if (status) { IDLog("Error: Failed to write FITS image\n"); fits_report_error(stderr, status); /* print out any error messages */ return false; } fits_close_file(fptr,&status); targetChip->ImageExposureNP->s=IPS_OK; IDSetNumber(targetChip->ImageExposureNP,NULL); targetChip->FitsB.blob=memptr; targetChip->FitsB.bloblen=memsize; targetChip->FitsB.size=memsize; strcpy(targetChip->FitsB.format,".fits"); targetChip->FitsBP->s=IPS_OK; //IDLog("Enter Uploadfile with %d total sending via %s, and format %s\n",total,targetChip->FitsB.name, targetChip->FitsB.format); IDSetBLOB(targetChip->FitsBP,NULL); free(memptr); return true; }