//************************************************************************ // Class for loadind and saving from FITS-formatted file to DPC objects // (G. Le Meur ; Francois Touze) OCT. 99 // // methods 'load(X& x, char f[])' get from FITS file "f" a DPC object x // from DPC class X. // methods 'save(X& x, char f[])' save a DPC object x from DPC // class X // onto a FITS file "f" . //************************************************************************ #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; long naxis; int n1, n2, n3; DVList dvl; planck_read_img(flnm, naxis, n1, n2, n3, dvl); nbrows=n1; nbcols=n2; if (naxis == 1) nbcols=1; if (naxis > 2) { cout<<" FitsIOServer : le fichier fits n'est pas une matrice, naxis= " < 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 == TFLOAT) 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]); for( int ii = 0; ii < tfields; ii++) { delete [] ttype[ii]; delete [] tform[ii]; } delete [] ttype; delete [] tform; // 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); for(int ii = 0; ii < column.size(); ii++) delete [] clname[ii]; delete [] clname; 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]= (int_4)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; } void FitsIoServer::load(SphericalMap& sph, char flnm[]) { int npixels=0; int nside=0; long naxis; int n1, n2, n3; FITS_tab_typ_ = TDOUBLE; DVList dvl; planck_read_img(flnm, naxis, n1, n2, n3, dvl); if (naxis != 1) { cout << " le fichier fits n'est pas une sphere, naxis= " << naxis << endl; } npixels=n1; nside= dvl.GetI("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 "<& sph, char flnm[], int hdunum) { int npixels=0; int nside=0; FITS_tab_typ_ = TFLOAT; DVList dvl; planck_read_bntbl(flnm, hdunum, npixels, dvl); //dvl.Print(); nside= dvl.GetI("NSIDE"); const char* ordering= dvl.GetS("ORDERING").c_str(); char* ring = "'RING"; if ( strncmp(ordering, ring,3) != 0) // if (ordering!="RING ") { cout << " numerotation non RING" << endl; } // 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 "<& sph, char flnm[]) { int npixels=0; int nside=0; long naxis; int n1, n2, n3; DVList dvl; FITS_tab_typ_ = TFLOAT; planck_read_img(flnm, naxis, n1, n2, n3, dvl); if (naxis != 1) { cout << " le fichier fits n'est pas une sphere, naxis= " << naxis << endl; } npixels=n1; nside= dvl.GetI("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 nbrows=0; int nbcols=0; FITS_tab_typ_ = TDOUBLE; long naxis; int n1, n2, n3; DVList dvl; planck_read_img(flnm, naxis, n1, n2, n3, dvl); nbrows=n1; nbcols=n2; if (naxis != 2) { cout<<" FitsIOServer : le fichier fits n'est pas une localmap, naxis= "<& mat, char filename[]) { int nbrows = mat.NRows(); int nbcols = mat.NCols(); long naxis = nbcols > 1 ? 2 : 1; cout << " nombre de lignes : " << nbrows << " colonnes " << nbcols << endl; FITS_tab_typ_ = TDOUBLE; if (r_8tab_ != NULL ) delete[] r_8tab_; r_8tab_=new r_8[nbrows*nbcols]; int ij=0; for (int j=0; j< nbcols; j++) for (int i = 0; i < nbrows; i++) r_8tab_[ij++]= (r_8)mat(i,j); DVList dvl; planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl); delete[] r_8tab_; } void FitsIoServer::save(NTuple& ntpl,char flnm[]) //****************************************************/ //* read the elements of the NTuple ntpl, and create */ //* a FITS file with a binary table extension */ //****************************************************/ { // delete old file if it already exists remove(flnm); // pointer to the FITS file, defined in fitsio.h fitsfile *fptr; int status = 0; if( fits_create_file(&fptr, flnm, &status) ) printerror( status ); // table will have tfields columns int tfields= ntpl.NVar(); // table will have nrows rows int nrows= ntpl.NEntry(); // extension name char extname[] = "NTuple_Binary_tbl"; // define the name, and the datatype for the tfields columns char **ttype, **tform; ttype= new char*[tfields]; tform= new char*[tfields]; for(int i = 0; i < tfields; i++) { ttype[i]= new char[FLEN_VALUE]; strcpy(ttype[i], ntpl.NomIndex(i)); tform[i]= new char[FLEN_VALUE]; strcpy(tform[i], "1E"); } // create a new empty binary table onto the FITS file // physical units if they exist, are defined in the DVList object // so the null pointer is given for the tunit parameters. if ( fits_create_tbl(fptr,BINARY_TBL,nrows,tfields,ttype,tform, NULL,extname,&status) ) printerror( status ); for( int ii = 0; ii < tfields; ii++) { delete [] ttype[ii]; delete [] tform[ii]; } delete [] ttype; delete [] tform; // first row in table to write int firstrow = 1; // first element in row (ignored in ASCII tables) int firstelem = 1; for(int i = 0; i < tfields; i++) { float *dens= new float[nrows]; for(int j = 0; j < nrows; j++) { dens[j]= ntpl.GetVal(j,i); } fits_write_col(fptr,TFLOAT,i+1,firstrow,firstelem,nrows,dens,&status); delete []dens; } // number of blocks per event int blk= ntpl.BLock(); fits_write_key(fptr,TINT,"BLK",&blk,"number of blocks per evt",&status); // get names and values from the join DVList object DVList dvl= ntpl.Info(); dvl.Print(); DVList::ValList::const_iterator it; for(it = dvl.Begin(); it != dvl.End(); it++) { char keytype= (*it).second.typ; char keyname[9]=""; strncpy(keyname,(*it).first.substr(0,64).c_str(),8); char comment[FLEN_COMMENT]=""; switch (keytype) { case 'I' : { int ival=(*it).second.mtv.iv; strcpy(comment,"I entier"); fits_write_key(fptr,TINT,keyname,&ival,comment,&status); break; } case 'D' : { double dval=(*it).second.mtv.dv; strcpy(comment,"D double"); fits_write_key(fptr,TDOUBLE,keyname,&dval,comment,&status); break; } case 'S' : { char strval[]=""; strcpy(strval,(*it).second.mtv.strv); strcpy(comment,"S character string"); fits_write_key(fptr,TSTRING,keyname,&strval,comment,&status); break; } } } //close the FITS file if ( fits_close_file(fptr, &status) ) printerror( status ); return; } //void FitsIoServer::save(SphericalMap& sph, char filename[]) void FitsIoServer::save(SphericalMap& sph, char filename[]) { int npixels = sph.NbPixels(); FITS_tab_typ_ = TDOUBLE; if (r_8tab_ != NULL ) delete[] r_8tab_; r_8tab_=new r_8[npixels]; for (int j = 0; j < npixels; j++) r_8tab_[j]= (r_8)sph(j); DVList dvl; dvl["NSIDE"] = (int_4) sph.SizeIndex(); dvl["ORDERING"]=sph.TypeOfMap(); planck_write_img(filename, 1, npixels, 0, 0, dvl); // decider ulterieurement ce qu'on fait de ce qui suit, specifique // pour l'instant, aux spheres gorski. /* // 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 ); */ delete[] r_8tab_; } void FitsIoServer::save(SphericalMap& sph, char filename[]) { int npixels = sph.NbPixels(); FITS_tab_typ_ = TFLOAT; if (r_4tab_ != NULL ) delete[] r_4tab_; r_4tab_=new r_4[npixels]; for (int j = 0; j < npixels; j++) r_4tab_[j]= (r_4)sph(j); DVList dvl; dvl["NSIDE"] = (int_4)sph.SizeIndex(); dvl["ORDERING"]=sph.TypeOfMap(); planck_write_img(filename, 1, npixels, 0, 0, dvl); delete[] r_4tab_; } 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 (r_8tab_ != NULL ) delete[] r_8tab_; r_8tab_=new r_8[nbrows*nbcols]; int ij=0; for (int j=0; j< nbcols; j++) for (int i = 0; i < nbrows; i++) r_8tab_[ij++]= (r_8)locm(i,j); DVList dvl; dvl["NSIDE"] = (int_4) 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"] = (int_4)x0; dvl["Y0"] = (int_4)y0; dvl["ANGLE"] = angle; dvl["ANGLEX"] = anglex; dvl["ANGLEY"] = angley; planck_write_img(filename, naxis, nbrows, nbcols, 0, dvl); delete[] r_8tab_;} void FitsIoServer::save(const 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; // write FITS image DVList dvl; dvl["DATATYPE"] = (int_4)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(); // j utilise la methode SetS parce que ses parametres sont const et // que l'argument DpcImg est const dans la presente method. // (dans dvlist, l'operateur surcharge [] renvoie MuTyV&, ce qui // est non const et provoque un warning sur mac (CodeWarrior) dvl.SetS("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; // get the values of the DpcImage if (r_4tab_ != NULL) delete [] r_4tab_; r_4tab_=new r_4[siz_x*siz_y]; PBaseDataTypes dataT=DataType((r_4)0); memcpy( r_4tab_, DpcImg.ImagePtr(), siz_x*siz_y*DataSize(dataT)); planck_write_img(flnm, naxis, siz_x, siz_y, 0, dvl); delete [] r_4tab_; } void FitsIoServer::save(const 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 ); // write FITS image DVList dvl; dvl["DATATYPE"] = (int_4)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(); // j utilise la methode SetS parce que ses parametres sont const et // que l'argument DpcImg est const dans la presente method. // (dans dvlist, l'operateur surcharge [] renvoie MuTyV&, ce qui // est non const et provoque un warning sur mac (CodeWarrior) dvl.SetS("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; // get the values of the DpcImage if (i_4tab_ != NULL) delete [] i_4tab_; i_4tab_=new int_4[siz_x*siz_y]; PBaseDataTypes dataT=DataType((int_4)0); memcpy( i_4tab_, DpcImg.ImagePtr(), siz_x*siz_y*DataSize(dataT)); planck_write_img(flnm, naxis, siz_x, siz_y, 0, dvl); // close the file //fits_close_file(fptr, &status); //if( status ) printerror( status ); delete [] i_4tab_; } void FitsIoServer::planck_write_img(char flnm[], int naxis,int n1, int n2, int n3, DVList& dvl) { // 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 ); 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, r_8tab_, &status); if( status ) printerror( status ); break; case TFLOAT : fits_write_img(fptr, TFLOAT, 1, nelements, r_4tab_, &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 ); } // close the file fits_close_file(fptr, &status); if( status ) printerror( status ); } void FitsIoServer::planck_read_img(char flnm[], long& naxis,int& n1, int& n2, int& n3, DVList& dvl) { int status=0; long bitpix; long naxes[3]={0,0,0}; char* comment=NULL; // pointer to the FITS file, defined in fitsio.h fitsfile *fptr; // initialize status before calling fitsio routines fits_open_file(&fptr, flnm, READONLY, &status); if( status ) printerror( status ); 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; r_8 dnullval=0.; r_4 fnullval=0.; int_4 inullval=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 " << flnm << " is not double, " << " conversion to double will be achieved by cfitsio lib " << endl; } if (r_8tab_ != NULL) delete [] r_8tab_; r_8tab_=new r_8[nelements]; fits_read_img(fptr, TDOUBLE, 1, nelements, &dnullval, r_8tab_, &anynull, &status); if( status ) printerror( status ); break; case TFLOAT : if (bitpix != FLOAT_IMG) { cout << " FitsIOServer : the data type on fits file " << flnm << " is not float, " << " conversion to float will be achieved by cfitsio lib " << endl; } if (r_4tab_ != NULL) delete [] r_4tab_; r_4tab_=new r_4[nelements]; fits_read_img(fptr, TFLOAT, 1, nelements, &fnullval, r_4tab_, &anynull, &status); if( status ) printerror( status ); break; case TINT : if (bitpix != LONG_IMG) { cout << " FitsIOServer : the data type on fits file " << flnm << " 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, &inullval, 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] = (int_4)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; } } } // close the file status=0; fits_close_file(fptr, &status); if( status ) printerror( status ); } void FitsIoServer::planck_read_bntbl(char flnm[], int hdunum, int& npixels, DVList& dvl) { int status=0; int nkeys,keypos; int hdutype; int tfields; int datype; long lastpix; long repeat, width; long nrows; long extend; char* comment=NULL; // pointer to the FITS file, defined in fitsio.h fitsfile *fptr; // initialize status before calling fitsio routines fits_open_file(&fptr, flnm, READONLY, &status); if( status ) printerror( status ); fits_read_key_lng(fptr, "EXTEND", &extend, comment, &status); if( status ) printerror( status ); if (extend!=1) { cout << "FitsIoServer:: le fichier fits ne contient pas d'extension binary table" << endl; return; } fits_movabs_hdu(fptr, hdunum,&hdutype,&status); if( status ) printerror( status ); if (hdutype!=BINARY_TBL) { cout << "FitsIoServer:: this HDU is not a binary table " << endl; exit(status); } char xtension[FLEN_VALUE]; fits_read_key_str(fptr,"XTENSION",xtension,NULL,&status); if( status ) printerror( status ); char binta[] = "BINTABLE"; if ( strncmp(xtension, binta,8) != 0) // if (xtension !="BINTABLE") { cout << "FitsIoServer:: not a binary table " << endl; exit(status); } fits_get_hdrpos(fptr,&nkeys,&keypos,&status); if( status ) printerror( status ); //cout << " nombre de mots-cles : " << nkeys << endl; fits_get_num_cols(fptr, &tfields, &status); if (tfields != 1) { cout << "FitsIoServer:: il y a plus d'une colonne" << endl; return; } fits_get_num_rows(fptr, &nrows, &status); //cout << "nblignes= " << nrows << endl; fits_get_coltype(fptr, 1, &datype, &repeat, &width, &status); if( status ) printerror( status ); //cout << " type de donnees : " << datype << endl; //cout << " repeat : " << repeat << endl; //cout << " width : " << width << endl; fits_read_key_lng(fptr, "LASTPIX", &lastpix, comment, &status); if( status ) printerror( status ); long nelements= nrows*repeat; if (nelements!=lastpix+1) { cout << " erreur sur longueur du vecteur " << endl; cout << " nelements= " << nelements << " lastpix+1=" << lastpix+1 << endl; } npixels=nelements; int anynull; r_8 dnullval=0.; r_4 fnullval=0.; int_4 inullval=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 (datype != TDOUBLE) { cout << " FitsIOServer : the data type on fits file " << flnm << " is not double, " << " conversion to double will be achieved by cfitsio lib " << endl; } if (r_8tab_ != NULL) delete [] r_8tab_; r_8tab_=new r_8[ npixels]; fits_read_col(fptr, TDOUBLE, 1, 1, 1, nelements, &dnullval, r_8tab_, &anynull, &status); if( status ) printerror( status ); break; case TFLOAT : if (datype != TFLOAT) { cout << " FitsIOServer : the data type on fits file " << flnm << " is not float, " << " conversion to float will be achieved by cfitsio lib " << endl; } if (r_4tab_ != NULL) delete [] r_4tab_; r_4tab_=new r_4[nelements]; fits_read_col(fptr, TFLOAT, 1, 1, 1, nelements, &fnullval, r_4tab_, &anynull, &status); if( status ) printerror( status ); break; case TINT : if (datype != TLONG) { cout << " FitsIOServer : the data type on fits file " << flnm << " 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_col(fptr, TLONG, 1, 1, 1, nelements, &inullval, i_4tab_, &anynull, &status); //fits_read_img(fptr, TINT, 1, nelements, &inullval, i_4tab_, // &anynull, &status); //if( status ) printerror( status ); break; default : cout << " FitsIOServer::read_bntbl : type non traite: " << FITS_tab_typ_ << endl; break; } char card[FLEN_CARD]; char keyname[LEN_KEYWORD]= ""; char strval[FLEN_VALUE]; char comment1[FLEN_COMMENT]; char dtype; //char bidon[LEN_KEYWORD]; char comkey[] = "COMMENT"; for(int j = 1; j <= nkeys; j++) { // fits_read_record(fptr, j, card, &status); // strncpy(keyname,card,LEN_KEYWORD-1); // cout << " bidon= " << keyname << endl; // if ( strncmp(keyname,comkey ,LEN_KEYWORD-1) != 0) fits_read_keyn(fptr,j,card,strval,comment1,&status); printf("%s\n", card); strncpy(keyname,card,LEN_KEYWORD-1); if ( strncmp(keyname,comkey ,LEN_KEYWORD-1) != 0) { fits_get_keytype(strval,&dtype,&status); // cout<<" keyname= "<< keyname <<" dtype= "<, according sinus-method, and saves onto // a FITS-file void FitsIoServer::sinus_picture_projection(SphericalMap& sph, char filename[]) { long naxes[2]={600, 300}; float* map =new float[ 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); delete [] map; } // projects a SphericalMap, according sinus-method, and saves onto // a FITS-file 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 = new float[ 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); delete [] map; } // projects a SphericalMap, according Mollweide-method, and saves onto // a FITS-file void FitsIoServer::Mollweide_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 = new float[ 600*300 ]; int npixels= naxes[0]*naxes[1]; cout << " image FITS en projection MOLLWEIDE" << 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); delete [] map; } // saves a (LocalMap on a FITS-file in order to be visualized // (for tests) 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