#include #include #include "fitsioserver.h" #include "strutil.h" void FitsIoServer::load(TMatrix& mat,char flnm[]) { int nbrows=0; int nbcols=0; FITS_tab_typ_ = TDOUBLE; int status=0; long naxis; int n1, n2, n3; DVList dvl; // pointer to the FITS file, defined in fitsio.h fitsfile *fptr; fits_open_file(&fptr, flnm, READONLY, &status); if( status ) printerror( status ); planck_read_img(fptr, naxis, n1, n2, n3, dvl); // close the file fits_close_file(fptr, &status); if( status ) printerror( status ); nbrows=n1; nbcols=n2; if (naxis == 1) nbcols=1; //dvl.Print(); DVList::ValList::const_iterator it; for(it = dvl.Begin(); it != dvl.End(); it++) { char datatype= (*it).second.typ; char keyname[]=""; strcpy(keyname, (*it).first.substr(0,64).c_str()); int ival=0; double dval=0.; char strval[]=""; switch (datatype) { case 'I' : ival=(*it).second.mtv.iv; break; case 'D' : dval=(*it).second.mtv.dv; break; case 'S' : strcpy(strval, (*it).second.mtv.strv); break; default : cout << " FitsIOServer : probleme dans type mot cle optionnel" << endl; break; } } if (naxis > 2) { cout<<" FitsIOServer : le fichier fits n'est pas une matrice, naxis= " <& sph, char flnm[]) { int npixels=0; int nside=0; FITS_tab_typ_ = TFLOAT; read_sphere(flnm, npixels, nside); // number of pixels in the sphere if (sph.NbPixels() != npixels) { cout << " found " << npixels << " pixels" << endl; cout << " expected " << sph.NbPixels() << endl; if (nside <= 0 ) { cout<<" FITSIOSERVER: no resolution parameter on fits file "<& lcm, char flnm[]) { int nside; int nbrows=0; int nbcols=0; FITS_tab_typ_ = TDOUBLE; int status=0; long naxis; int n1, n2, n3; DVList dvl; // pointer to the FITS file, defined in fitsio.h fitsfile *fptr; fits_open_file(&fptr, flnm, READONLY, &status); if( status ) printerror( status ); planck_read_img(fptr, naxis, n1, n2, n3, dvl); // close the file fits_close_file(fptr, &status); if( status ) printerror( status ); nbrows=n1; nbcols=n2; if (naxis != 2) { cout<<" FitsIOServer : le fichier fits n'est pas une localmap, naxis= "<& sph, char filename[]) void FitsIoServer::save(SphericalMap& sph, char filename[]) { int npixels = sph.NbPixels(); FITS_tab_typ_ = TDOUBLE; if (dtab_ != NULL ) delete[] dtab_; dtab_=new double[npixels]; //pointer to the FITS file, defined in fitsio.h fitsfile *fptr; // initialize status before calling fitsio routines int status = 0; // delete old file if it already exists remove(filename); // create new FITS file fits_create_file(&fptr, filename, &status); if( status ) printerror( status ); for (int j = 0; j < npixels; j++) dtab_[j]= sph(j); DVList dvl; dvl["NSIDE"] = sph.SizeIndex(); dvl["ORDERING"]=sph.TypeOfMap(); planck_write_img(fptr, 1, npixels, 0, 0, dvl); // decider ulterieurement ce qu'on fait de ce qui suit, specifique // pour l'instant, aux spheres gorski. Actuellement, on ne sauve pas // les informations d'analyse harmonique /* // write supplementary keywords fits_write_comment(fptr, " ", &status); if( status ) printerror( status ); strcpy(comment,"HEALPIX Pixelisation"); strcpy(svalue, "HEALPIX"); fits_write_key(fptr, TSTRING, "PIXTYPE", svalue, comment, &status); if( status ) printerror( status ); strcpy(comment,"pixel ordering scheme, either RING or NESTED"); strcpy(svalue, "RING"); fits_write_key(fptr, TSTRING, "ORDERING", svalue, comment, &status); if( status ) printerror( status ); strcpy(comment,"Random generator seed"); int iseed= sph.iseed(); fits_write_key(fptr, TINT, "RANDSEED", &iseed, comment, &status); if( status ) printerror( status ); strcpy(comment,"--------------------------------------------"); fits_write_comment(fptr, comment, &status); if( status ) printerror( status ); strcpy(comment," Above keywords are still likely to change !"); fits_write_comment(fptr, comment, &status); if( status ) printerror( status ); strcpy(comment,"--------------------------------------------"); fits_write_comment(fptr, comment, &status); if( status ) printerror( status ); */ // close the file fits_close_file(fptr, &status); if( status ) printerror( status ); } void FitsIoServer::save(SphericalMap& sph, char filename[]) { int npixels = sph.NbPixels(); FITS_tab_typ_ = TFLOAT; if (ftab_ != NULL ) delete[] ftab_; ftab_=new float[npixels]; //pointer to the FITS file, defined in fitsio.h fitsfile *fptr; // initialize status before calling fitsio routines int status = 0; // delete old file if it already exists remove(filename); // create new FITS file fits_create_file(&fptr, filename, &status); if( status ) printerror( status ); for (int j = 0; j < npixels; j++) ftab_[j]= sph(j); DVList dvl; dvl["NSIDE"] = sph.SizeIndex(); dvl["ORDERING"]=sph.TypeOfMap(); planck_write_img(fptr, 1, npixels, 0, 0, dvl); // close the file fits_close_file(fptr, &status); if( status ) printerror( status ); } void FitsIoServer::save(LocalMap& locm, char filename[]) { int nbrows = locm.Size_x(); int nbcols = locm.Size_y(); long naxis = 2; cout << " nombre de pts en x : " << nbrows << " en y " << nbcols << endl; FITS_tab_typ_ = TDOUBLE; if (dtab_ != NULL ) delete[] dtab_; dtab_=new double[nbrows*nbcols]; //pointer to the FITS file, defined in fitsio.h fitsfile *fptr; // initialize status before calling fitsio routines int status = 0; // delete old file if it already exists remove(filename); // create new FITS file fits_create_file(&fptr, filename, &status); if( status ) printerror( status ); int ij=0; for (int j=0; j< nbcols; j++) for (int i = 0; i < nbrows; i++) dtab_[ij++]= locm(i,j); DVList dvl; dvl["NSIDE"] = locm.SizeIndex(); dvl["ORDERING"]=locm.TypeOfMap(); double theta0; double phi0; int x0; int y0; double angle; locm.Origin(theta0,phi0,x0,y0,angle); double anglex; double angley; locm.Aperture(anglex,angley); dvl["THETA0"] = theta0; dvl["PHI0"] = phi0; dvl["X0"] = x0; dvl["Y0"] = y0; dvl["ANGLE"] = angle; dvl["ANGLEX"] = anglex; dvl["ANGLEY"] = angley; planck_write_img(fptr, naxis, nbrows, nbcols, 0, dvl); // close the file fits_close_file(fptr, &status); if( status ) printerror( status ); } void FitsIoServer::planck_write_img( fitsfile *fptr, int naxis,int n1, int n2, int n3, DVList& dvl) { int status=0; int bitpix=0; if ( FITS_tab_typ_ == TDOUBLE) bitpix = DOUBLE_IMG; if ( FITS_tab_typ_ == TFLOAT) bitpix = FLOAT_IMG; if ( FITS_tab_typ_ == TINT) bitpix = LONG_IMG; long naxes[3]; naxes[0] = n1; naxes[1] = n2; naxes[2] = n3; if (n2 > 0 && naxis < 2) cout << " FitsIoServer:: n2 = " << n2 << " seems to be incompatible with naxis = " << naxis << endl; if (n3 > 0 && naxis < 3) cout << " FitsIoServer:: n3 = " << n3 << " seems to be incompatible with naxis = " << naxis << endl; fits_create_img(fptr, bitpix, naxis, naxes, &status); if( status ) printerror( status ); long nelements= naxes[0]; if (naxis >=2) nelements*=naxes[1]; if (naxis == 3) nelements*=naxes[2]; switch (FITS_tab_typ_) { case TDOUBLE : fits_write_img(fptr, TDOUBLE, 1, nelements, dtab_, &status); if( status ) printerror( status ); break; case TFLOAT : fits_write_img(fptr, TFLOAT, 1, nelements, ftab_, &status); if( status ) printerror( status ); break; case TINT : fits_write_img(fptr, TINT, 1, nelements, i_4tab_, &status); if( status ) printerror( status ); break; default : cout << " FitsIOServer : type de tableau non traite en ecriture " << endl; break; } // write the current date fits_write_date(fptr, &status); if( status ) printerror( status ); // on convient d ecrire apres la date, les mots cles utilisateur. // la date servira de repere pour relire ces mots cles. //dvl.Print(); DVList::ValList::const_iterator it; for(it = dvl.Begin(); it != dvl.End(); it++) { int datatype= key_type_PL2FITS( (*it).second.typ); char keyname[]=""; int flen_keyword = 9; // FLEN_KEYWORD est la longueur max d'un mot-cle. Il doit y avoir une // erreur dans la librairie fits qui donne FLEN_KEYWORD=72 // contrairement a la notice qui donne FLEN_KEYWORD=9 (ch. 5, p.39) strncpy(keyname, (*it).first.substr(0,64).c_str(),flen_keyword-1); char comment[FLEN_COMMENT]=""; int ival=0; double dval=0.; char strval[]=""; switch (datatype) { case TINT : ival=(*it).second.mtv.iv; strcpy(comment,"I entier"); fits_write_key(fptr, datatype, keyname, &ival, comment, &status); break; case TDOUBLE : dval=(*it).second.mtv.dv; strcpy(comment,"D double"); fits_write_key(fptr, datatype, keyname, &dval, comment, &status); break; case TSTRING : strcpy(strval, (*it).second.mtv.strv); strcpy(comment,"S character string"); fits_write_key(fptr, datatype, keyname, &strval, comment, &status); break; default : cout << " FitsIOServer : probleme dans type mot cle optionnel" << endl; break; } if( status ) printerror( status ); } } void FitsIoServer::planck_read_img( fitsfile *fptr, long& naxis,int& n1, int& n2, int& n3, DVList& dvl) { int status=0; long bitpix; long naxes[3]={0,0,0}; char* comment=NULL; fits_read_key_lng(fptr, "BITPIX", &bitpix, comment, &status); if( status ) printerror( status ); fits_read_key_lng(fptr, "NAXIS", &naxis, comment, &status); if( status ) printerror( status ); int nfound; int nkeys=(int)naxis; fits_read_keys_lng(fptr, "NAXIS", 1, nkeys, naxes, &nfound, &status); if( status ) printerror( status ); n1 = naxes[0] ; n2 = naxes[1] ; n3 = naxes[2] ; long nelements= naxes[0]; if (naxis >=2) nelements*=naxes[1]; if (naxis == 3) nelements*=naxes[2]; int anynull; double dnullval=0.; float fnullval=0.; // on laisse a fits le soin de convertir le type du tableau lu vers // le type suppose par l'utilisateur de fitsioserver // switch ( FITS_tab_typ_) { case TDOUBLE : if (bitpix != DOUBLE_IMG) { cout << " FitsIOServer : the data type on fits file is not double, " << " conversion to double will be achieved by cfitsio lib " << endl; } if (dtab_ != NULL) delete [] dtab_; dtab_=new double[nelements]; fits_read_img(fptr, TDOUBLE, 1, nelements, &dnullval, dtab_, &anynull, &status); if( status ) printerror( status ); break; case TFLOAT : if (bitpix != FLOAT_IMG) { cout << " FitsIOServer : the data type on fits file is not float, " << " conversion to float will be achieved by cfitsio lib " << endl; } if (ftab_ != NULL) delete [] ftab_; ftab_=new float[nelements]; fits_read_img(fptr, TFLOAT, 1, nelements, &fnullval, ftab_, &anynull, &status); if( status ) printerror( status ); break; case TINT : if (bitpix != LONG_IMG) { cout << " FitsIOServer : the data type on fits file is not long, " << " conversion to long will be achieved by cfitsio lib " << endl; } if (i_4tab_ != NULL) delete [] i_4tab_; i_4tab_=new int_4[nelements]; fits_read_img(fptr, TINT, 1, nelements, &fnullval, i_4tab_, &anynull, &status); if( status ) printerror( status ); break; default : cout << " FitsIOServer::read_img : type non traite: " << FITS_tab_typ_ << endl; break; } status = 0; char card[FLEN_CARD]; int num = 0; char comment2[FLEN_COMMENT] = "x"; char keyname[]= ""; char datekey[]= "DATE"; char endkey[] = "END"; char typ='x'; int ival; double dval; char strval[]=""; // on a convenu que les mots cles utilisateur sont apres le mot cle DATE // on va jusqu'au mot cle DATE int flen_keyword = 9; // FLEN_KEYWORD est la longueur max d'un mot-cle. Il doit y avoir une // erreur dans la librairie fits qui donne FLEN_KEYWORD=72 // contrairement a la notice qui donne FLEN_KEYWORD=9 (ch. 5, p.39) while (status == 0 && strncmp(keyname, datekey,4) != 0 ) { num++; fits_read_record(fptr, num, card, &status); strncpy(keyname,card,flen_keyword-1); } if (status != 0 ) { cout << " fitsio::planck_read_img : erreur, mot cle DATE absent " << endl; } // on recupere la liste des mots-cles utilisateurs while (status == 0) { num++; // on lit un record pour recuperer le nom du mot-cle fits_read_record(fptr, num, card, &status); strncpy(keyname,card,flen_keyword-1); char value[FLEN_VALUE]; // on recupere le premier caractere du commentaire, qui contient // le code du type de la valeur // (tant que ce n est pas le mot cle END) fits_read_keyword(fptr, keyname, value, comment2, &status); if ( strncmp(keyname, endkey,flen_keyword-1) != 0) { typ = comment2[0]; // quand le type est connu, on lit la valeur switch (typ) { case 'I' : fits_read_key(fptr, TINT, keyname, &ival, comment2, &status); if( status ) printerror( status ); strip (keyname, 'B',' '); dvl[keyname] = ival; break; case 'D' : fits_read_key(fptr, TDOUBLE, keyname, &dval, comment2, &status); if( status ) printerror( status ); strip (keyname, 'B',' '); dvl[keyname] = dval; break; case 'S' : fits_read_key(fptr, TSTRING, keyname, strval, comment2, &status); if( status ) printerror( status ); strip (keyname, 'B',' '); strip(strval, 'B',' '); dvl[keyname]=strval; break; default : cout << " FITSIOSERVER::planck_read_img : type de donnee non prevu " << endl; break; } } } } void FitsIoServer::sinus_picture_projection(SphericalMap& sph, char filename[]) { long naxes[2]={600, 300}; float map [ 600*300 ]; int npixels= naxes[0]*naxes[1]; cout << " image FITS en projection SINUS" << endl; // table will have npixels rows for(int j=0; j < npixels; j++) map[j]=0.; for(int j=0; j= 0) { map[j*naxes[0]+i] = sph.PixValSph(th, ff); } } } write_picture(naxes, map, filename); } void FitsIoServer::sinus_picture_projection(SphericalMap& sph, char filename[]) { // le code de cete methode duplique celui de la precedente, la seule //difference etant le type de sphere en entree. Ces methodes de projection // sont provisoires, et ne servent que pour les tests. C est pourquoi je // ne me suis pas casse la tete, pour l instant long naxes[2]={600, 300}; float map [ 600*300 ]; int npixels= naxes[0]*naxes[1]; cout << " image FITS en projection SINUS" << endl; // table will have npixels rows for(int j=0; j < npixels; j++) map[j]=0.; for(int j=0; j= 0) { map[j*naxes[0]+i] = sph.PixValSph(th, ff); } } } write_picture(naxes, map, filename); } void FitsIoServer::picture(LocalMap& lcm, char filename[]) { long naxes[2]; naxes[0] = lcm.Size_x(); naxes[1] = lcm.Size_y(); int npixels= naxes[0]*naxes[1]; float* map = new float[npixels]; // table will have npixels rows for(int j=0; j < npixels; j++) map[j]=0.; for(int j=0; j column; for( int ii = 0; ii < tfields; ii++) { fits_binary_tform(tform[ii],&typecode, &repeat, &width, &status); //printf("\n%4s %3d %2ld %2ld", tform[ii], typecode, repeat, width); if(typecode == 42) column.push_back(ii+1); } // get input elements to create the NTuple char **clname; clname= new char*[column.size()]; for(int ii = 0; ii < column.size(); ii++) clname[ii]= new char[FLEN_VALUE]; list::iterator itr; int index= 0; for(itr= column.begin(); itr != column.end(); itr++) strcpy(clname[index++],ttype[*itr-1]); // check if the specified keyword BLK exists int blk= 512; if(check_keyword(fptr,nkeys,"BLK")) { if( fits_read_key(fptr,TINT,"BLK",&blk,NULL,&status) ) printerror( status ); } // create a NTuple NTuple nt0(column.size(),clname,blk); float value[1]; long felem = 1; char strnull[10]; strcpy(strnull, " "); int anynull= 0; long longnull = 0; // value to represent undefined array elements float floatnull = FLOATNULLVALUE; // read elements from columns and fill NTuple for (int k = 0; k < nrows; k++) { int j= 0; float *xnt= new float[column.size()]; list::iterator itr; for(itr= column.begin(); itr != column.end(); itr++) { fits_read_col(fptr,TFLOAT,*itr,k+1,felem,1,&floatnull,value, &anynull, &status); xnt[j++]= value[0]; } nt0.Fill(xnt); delete[] xnt; } // the TUNITn keywords are optional, if they exist they are put // in the DVLIst object char keyname[LEN_KEYWORD]= ""; char strval[FLEN_VALUE]; for(int ii = 0; ii < tfields; ii++) { fits_make_keyn("TUNIT",ii+1,keyname,&status); if(check_keyword(fptr,nkeys,keyname)) { num++; if( fits_read_key_str(fptr,keyname,strval,NULL,&status) ) printerror(status); strip (keyname, 'B',' '); strip(strval, 'B',' '); nt0.Info()[keyname]= strval; } } // add the number of mandatory keywords of a binary table num += 8; // put names and values of other reserved keywords in a DVList object char comment[FLEN_COMMENT]; char dtype; for(int j = num+1; j <= nkeys; j++) { fits_read_keyn(fptr,j,keyname,strval,comment,&status); fits_get_keytype(strval,&dtype,&status); strip (keyname, 'B',' '); strip(strval, 'B',' '); switch( dtype ) { case 'C': nt0.Info()[keyname]= strval; break; case 'I': int ival; ctoi(strval,&ival); nt0.Info()[keyname]= ival; break; case 'F': double dval; ctof(strval,&dval); nt0.Info()[keyname]= dval; break; } } // copy in the input NTuple ntpl= nt0; if( fits_close_file(fptr, &status) ) printerror(status); printf("\n"); return; } bool FitsIoServer::check_keyword(fitsfile *fptr,int nkeys,char keyword[]) //*****************************************************/ //* check if the specified keyword exits in the CHU */ //*****************************************************/ { bool KEY_EXIST = false; int status = 0; char strbide[FLEN_VALUE]; char keybide[LEN_KEYWORD]= ""; for(int jj = 1; jj <= nkeys; jj++) { if( fits_read_keyn(fptr,jj,keybide,strbide,NULL,&status) ) printerror( status ); if( !strcmp(keybide,keyword) ) { KEY_EXIST= true; break; } } return(KEY_EXIST); } void FitsIoServer::readheader ( char filename[] ) //**********************************************************************/ //* Print out all the header keywords in all extensions of a FITS file */ //**********************************************************************/ { // standard string lengths defined in fitsioc.h char card[FLEN_CARD]; // pointer to the FITS file, defined in fitsio.h fitsfile *fptr; int status = 0; if ( fits_open_file(&fptr, filename, READONLY, &status) ) printerror( status ); // attempt to move to next HDU, until we get an EOF error int hdutype; for (int ii = 1; !(fits_movabs_hdu(fptr,ii,&hdutype,&status));ii++) { if (hdutype == ASCII_TBL) printf("\nReading ASCII table in HDU %d:\n", ii); else if (hdutype == BINARY_TBL) printf("\nReading binary table in HDU %d:\n", ii); else if (hdutype == IMAGE_HDU) printf("\nReading FITS image in HDU %d:\n", ii); else { printf("Error: unknown type of this HDU \n"); printerror( status ); } // get the number of keywords int nkeys, keypos; if ( fits_get_hdrpos(fptr, &nkeys, &keypos, &status) ) printerror( status ); printf("Header listing for HDU #%d:\n", ii); for (int jj = 1; jj <= nkeys; jj++) { if ( fits_read_record(fptr, jj, card, &status) ) printerror( status ); // print the keyword card printf("%s\n", card); } printf("END\n\n"); } // got the expected EOF error; reset = 0 if (status == END_OF_FILE) status = 0; else printerror( status ); if ( fits_close_file(fptr, &status) ) printerror( status ); return; } void FitsIoServer::printerror(int status) const //*****************************************************/ //* Print out cfitsio error messages and exit program */ //*****************************************************/ { // print out cfitsio error messages and exit program if( status ) { // print error report fits_report_error(stderr, status); // terminate the program, returning error status exit( status ); } return; } void FitsIoServer::save(ImageR4& DpcImg,char flnm[]) { long naxis=2; int siz_x = DpcImg.XSize(); int siz_y = DpcImg.YSize(); int nbpixels = siz_x*siz_y; FITS_tab_typ_ = TFLOAT; // pointer to the FITS file, defined in fitsio.h fitsfile *fptr; // initialize status before calling fitsio routines int status = 0; // delete old file if it already exists remove(flnm); // create new FITS file fits_create_file(&fptr, flnm, &status); if( status ) printerror( status ); // get the values of the DpcImage if (ftab_ != NULL) delete [] ftab_; ftab_=DpcImg.ImagePtr(); // write FITS image DVList dvl; dvl["DATATYPE"] = int(DpcImg.PixelType()); dvl["ORG_X"] = DpcImg.XOrg(); dvl["ORG_Y"] = DpcImg.YOrg(); dvl["PIXSZ_X"] = DpcImg.XPxSize(); dvl["PIXSZ_Y"] = DpcImg.YPxSize(); dvl["IDENT"] = DpcImg.Ident(); dvl["NAME"] = DpcImg.Nom(); dvl["NBSAT"] = DpcImg.nbSat; dvl["NBNUL"] = DpcImg.nbNul; dvl["MINPIX"] = DpcImg.minPix; dvl["MAXPIX"] = DpcImg.maxPix; dvl["MOYPIX"] = DpcImg.moyPix; dvl["SIGPIX"] = DpcImg.sigPix; dvl["FOND"] = DpcImg.fond; dvl["SIGFON"] = DpcImg.sigmaFond; planck_write_img(fptr, naxis, siz_x, siz_y, 0, dvl); // close the file fits_close_file(fptr, &status); if( status ) printerror( status ); ftab_=NULL; } void FitsIoServer::load(ImageR4& DpcImg,char flnm[]) { FITS_tab_typ_ = TFLOAT; long naxis; int siz_x; int siz_y; int n3; DVList dvl; // pointer to the FITS file, defined in fitsio.h fitsfile *fptr; // initialize status before calling fitsio routines int status = 0; fits_open_file(&fptr, flnm, READONLY, &status); if( status ) printerror( status ); planck_read_img(fptr, naxis, siz_x, siz_y, n3, dvl); // close the file fits_close_file(fptr, &status); if( status ) printerror( status ); if (naxis != 2) { cout << " FitsIOServer : naxis= " << naxis << " not equal to 2 ?" << endl; } DpcImg.Allocate(siz_x, siz_y, 0., 0); float* pixelPtr=DpcImg.ImagePtr(); //for (int i=0; i < siz_x*siz_y; i++) pixelPtr[i]=ftab_[i]; // verifications de type PBaseDataTypes dataT=DataType((r_4)0); int TypeDonnees=dvl.GetI("DATATYPE"); if (int(dataT) != TypeDonnees) { cout << " FitsIOServer : parameter DATATYPE on file is not float " << endl; cout << " eventual conversion to float is achieved by cfitsio lib " << endl; } memcpy(pixelPtr, ftab_, siz_x*siz_y*DataSize(dataT)); const char* nom=dvl.GetS("NAME").c_str(); DpcImg.SetNameId(dvl.GetI("IDENT"), nom); DpcImg.SetOrg(dvl.GetI("ORG_X"), dvl.GetI("ORG_Y")); DpcImg.SetPxSize(dvl.GetD("PIXSZ_X"), dvl.GetD("PIXSZ_Y")); DpcImg.SetAtt(dvl.GetI("NBNUL"), dvl.GetI("NBSAT"), dvl.GetD("MINPIX"), dvl.GetD("MAXPIX"), dvl.GetD("MOYPIX"), dvl.GetD("SIGPIX"),dvl.GetD("FOND"), dvl.GetD("SIGFON")); } void FitsIoServer::save(ImageI4& DpcImg,char flnm[]) { long naxis=2; int siz_x = DpcImg.XSize(); int siz_y = DpcImg.YSize(); int nbpixels = siz_x*siz_y; FITS_tab_typ_ = TINT; // pointer to the FITS file, defined in fitsio.h fitsfile *fptr; // initialize status before calling fitsio routines int status = 0; // delete old file if it already exists remove(flnm); // create new FITS file fits_create_file(&fptr, flnm, &status); if( status ) printerror( status ); // get the values of the DpcImage if (i_4tab_ != NULL) delete [] i_4tab_; i_4tab_=DpcImg.ImagePtr(); // write FITS image DVList dvl; dvl["DATATYPE"] = int(DpcImg.PixelType()); dvl["ORG_X"] = DpcImg.XOrg(); dvl["ORG_Y"] = DpcImg.YOrg(); dvl["PIXSZ_X"] = DpcImg.XPxSize(); dvl["PIXSZ_Y"] = DpcImg.YPxSize(); dvl["IDENT"] = DpcImg.Ident(); dvl["NAME"] = DpcImg.Nom(); dvl["NBSAT"] = DpcImg.nbSat; dvl["NBNUL"] = DpcImg.nbNul; dvl["MINPIX"] = DpcImg.minPix; dvl["MAXPIX"] = DpcImg.maxPix; dvl["MOYPIX"] = DpcImg.moyPix; dvl["SIGPIX"] = DpcImg.sigPix; dvl["FOND"] = DpcImg.fond; dvl["SIGFON"] = DpcImg.sigmaFond; planck_write_img(fptr, naxis, siz_x, siz_y, 0, dvl); // close the file fits_close_file(fptr, &status); if( status ) printerror( status ); i_4tab_=NULL; } void FitsIoServer::load(ImageI4& DpcImg,char flnm[]) { FITS_tab_typ_ = TINT; long naxis; int siz_x; int siz_y; int n3; DVList dvl; // pointer to the FITS file, defined in fitsio.h fitsfile *fptr; // initialize status before calling fitsio routines int status = 0; fits_open_file(&fptr, flnm, READONLY, &status); if( status ) printerror( status ); planck_read_img(fptr, naxis, siz_x, siz_y, n3, dvl); // close the file fits_close_file(fptr, &status); if( status ) printerror( status ); if (naxis != 2) { cout << " FitsIOServer : naxis= " << naxis << " not equal to 2 ?" << endl; } DpcImg.Allocate(siz_x, siz_y, 0., 0); int_4* pixelPtr=DpcImg.ImagePtr(); // verifications de type PBaseDataTypes dataT=DataType((int_4)0); int TypeDonnees=dvl.GetI("DATATYPE"); if (int(dataT) != TypeDonnees) { cout << " FitsIOServer : parameter DATATYPE on file is not int_4 " << endl; cout << " eventual conversion to float is achieved by cfitsio lib " << endl; } memcpy(pixelPtr, i_4tab_, siz_x*siz_y*DataSize(dataT)); const char* nom=dvl.GetS("NAME").c_str(); DpcImg.SetNameId(dvl.GetI("IDENT"), nom); DpcImg.SetOrg(dvl.GetI("ORG_X"), dvl.GetI("ORG_Y")); DpcImg.SetPxSize(dvl.GetD("PIXSZ_X"), dvl.GetD("PIXSZ_Y")); DpcImg.SetAtt(dvl.GetI("NBNUL"), dvl.GetI("NBSAT"), dvl.GetD("MINPIX"), dvl.GetD("MAXPIX"), dvl.GetD("MOYPIX"), dvl.GetD("SIGPIX"),dvl.GetD("FOND"), dvl.GetD("SIGFON")); }