Changeset 564 in Sophya for trunk/SophyaExt
- Timestamp:
- Nov 10, 1999, 12:14:20 PM (26 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/fitsioserver.cc
r531 r564 291 291 for (int j = 0; j < sph.NbPixels(); j++) sph(j)= (double)r_8tab_[j]; 292 292 } 293 294 295 void FitsIoServer::load(SphereGorski<float>& sph, char flnm[], int hdunum) 296 { 297 int npixels=0; 298 int nside=0; 299 300 FITS_tab_typ_ = TFLOAT; 301 302 DVList dvl; 303 planck_read_bntbl(flnm, hdunum, npixels, dvl); 304 //dvl.Print(); 305 nside= dvl.GetI("NSIDE"); 306 const char* ordering= dvl.GetS("ORDERING").c_str(); 307 char* ring = "'RING"; 308 if ( strncmp(ordering, ring,3) != 0) 309 310 // if (ordering!="RING ") 311 { 312 cout << " numerotation non RING" << endl; 313 } 314 // number of pixels in the sphere 315 if (sph.NbPixels() != npixels) 316 { 317 cout << " found " << npixels << " pixels" << endl; 318 cout << " expected " << sph.NbPixels() << endl; 319 if (nside <= 0 ) 320 { 321 cout<<" FITSIOSERVER: no resolution parameter on fits file "<<endl; 322 exit(0); 323 } 324 if (nside != sph.SizeIndex()) 325 { 326 sph.Resize(nside); 327 cout << " resizing the sphere to nside= " << nside << endl; 328 } 329 else 330 { 331 cout << " FITSIOSERVER : same resolution, surprising ! " << endl; 332 exit(0); 333 } 334 } 335 for (int j = 0; j < sph.NbPixels(); j++) sph(j)= (float)r_4tab_[j]; 336 } 337 293 338 void FitsIoServer::load(SphericalMap<float>& sph, char flnm[]) 294 339 { … … 1106 1151 1107 1152 1153 void FitsIoServer::planck_read_bntbl(char flnm[], int hdunum, int& npixels, DVList& dvl) 1154 { 1155 int status=0; 1156 int nkeys,keypos; 1157 int hdutype; 1158 int tfields; 1159 int datype; 1160 long lastpix; 1161 long repeat, width; 1162 long nrows; 1163 long extend; 1164 char* comment=NULL; 1165 1166 // pointer to the FITS file, defined in fitsio.h 1167 fitsfile *fptr; 1168 // initialize status before calling fitsio routines 1169 fits_open_file(&fptr, flnm, READONLY, &status); 1170 if( status ) printerror( status ); 1171 fits_read_key_lng(fptr, "EXTEND", &extend, comment, &status); 1172 if( status ) printerror( status ); 1173 if (extend!=1) 1174 { 1175 cout << "FitsIoServer:: le fichier fits ne contient pas d'extension binary table" << endl; 1176 return; 1177 } 1178 fits_movabs_hdu(fptr, hdunum,&hdutype,&status); 1179 if( status ) printerror( status ); 1180 if (hdutype!=BINARY_TBL) 1181 { 1182 cout << "FitsIoServer:: this HDU is not a binary table " << endl; 1183 exit(status); 1184 } 1185 char xtension[FLEN_VALUE]; 1186 fits_read_key_str(fptr,"XTENSION",xtension,NULL,&status); 1187 if( status ) printerror( status ); 1188 cout << "xtension= " << xtension << endl; 1189 1190 char binta[] = "BINTABLE"; 1191 if ( strncmp(xtension, binta,8) != 0) 1192 // if (xtension !="BINTABLE") 1193 { 1194 cout << "FitsIoServer:: not a binary table " << endl; 1195 exit(status); 1196 } 1197 fits_get_hdrpos(fptr,&nkeys,&keypos,&status); 1198 if( status ) printerror( status ); 1199 //cout << " nombre de mots-cles : " << nkeys << endl; 1200 fits_get_num_cols(fptr, &tfields, &status); 1201 cout << "tfields= " << tfields << endl; 1202 if (tfields != 1) 1203 { 1204 cout << "FitsIoServer:: il y a plus d'une colonne" << endl; 1205 return; 1206 } 1207 fits_get_num_rows(fptr, &nrows, &status); 1208 //cout << "nblignes= " << nrows << endl; 1209 fits_get_coltype(fptr, 1, &datype, &repeat, &width, &status); 1210 if( status ) printerror( status ); 1211 //cout << " type de donnees : " << datype << endl; 1212 //cout << " repeat : " << repeat << endl; 1213 //cout << " width : " << width << endl; 1214 fits_read_key_lng(fptr, "LASTPIX", &lastpix, comment, &status); 1215 if( status ) printerror( status ); 1216 1217 long nelements= nrows*repeat; 1218 if (nelements!=lastpix+1) 1219 { 1220 cout << " erreur sur longueur du vecteur " << endl; 1221 cout << " nelements= " << nelements << " lastpix+1=" << lastpix+1 << endl; 1222 } 1223 npixels=nelements; 1224 int anynull; 1225 r_8 dnullval=0.; 1226 r_4 fnullval=0.; 1227 int_4 inullval=0; 1228 // on laisse a fits le soin de convertir le type du tableau lu vers 1229 // le type suppose par l'utilisateur de fitsioserver 1230 // 1231 switch ( FITS_tab_typ_) 1232 { 1233 case TDOUBLE : 1234 if (datype != TDOUBLE) 1235 { 1236 cout << " FitsIOServer : the data type on fits file " << flnm << " is not double, " 1237 << " conversion to double will be achieved by cfitsio lib " << endl; 1238 } 1239 if (r_8tab_ != NULL) delete [] r_8tab_; 1240 r_8tab_=new r_8[ npixels]; 1241 fits_read_col(fptr, TDOUBLE, 1, 1, 1, nelements, &dnullval, 1242 r_8tab_, 1243 &anynull, &status); 1244 if( status ) printerror( status ); 1245 break; 1246 case TFLOAT : 1247 if (datype != TFLOAT) 1248 { 1249 1250 cout << " FitsIOServer : the data type on fits file " << flnm << " is not float, " 1251 << " conversion to float will be achieved by cfitsio lib " << endl; 1252 } 1253 if (r_4tab_ != NULL) delete [] r_4tab_; 1254 r_4tab_=new r_4[nelements]; 1255 fits_read_col(fptr, TFLOAT, 1, 1, 1, nelements, &fnullval, 1256 r_4tab_, &anynull, &status); 1257 if( status ) printerror( status ); 1258 break; 1259 1260 1261 case TINT : 1262 if (datype != TLONG) 1263 { 1264 cout << " FitsIOServer : the data type on fits file " << flnm << " is not long, " 1265 << " conversion to long will be achieved by cfitsio lib " << endl; 1266 } 1267 if (i_4tab_ != NULL) delete [] i_4tab_; 1268 i_4tab_=new int_4[nelements]; 1269 fits_read_col(fptr, TLONG, 1, 1, 1, nelements, &inullval, 1270 i_4tab_, &anynull, &status); 1271 //fits_read_img(fptr, TINT, 1, nelements, &inullval, i_4tab_, 1272 // &anynull, &status); 1273 //if( status ) printerror( status ); 1274 break; 1275 1276 1277 default : 1278 cout << " FitsIOServer::read_img : type non traite: " << FITS_tab_typ_ << endl; 1279 break; 1280 } 1281 char card[FLEN_CARD]; 1282 char keyname[LEN_KEYWORD]= ""; 1283 char strval[FLEN_VALUE]; 1284 char comment1[FLEN_COMMENT]; 1285 char dtype; 1286 //char bidon[LEN_KEYWORD]; 1287 char comkey[] = "COMMENT"; 1288 1289 for(int j = 1; j <= nkeys; j++) 1290 { 1291 // fits_read_record(fptr, j, card, &status); 1292 // strncpy(keyname,card,LEN_KEYWORD-1); 1293 // cout << " bidon= " << keyname << endl; 1294 // if ( strncmp(keyname,comkey ,LEN_KEYWORD-1) != 0) 1295 fits_read_keyn(fptr,j,card,strval,comment1,&status); 1296 strncpy(keyname,card,LEN_KEYWORD-1); 1297 1298 if ( strncmp(keyname,comkey ,LEN_KEYWORD-1) != 0) 1299 { 1300 fits_get_keytype(strval,&dtype,&status); 1301 strip (keyname, 'B',' '); 1302 strip(strval, 'B',' '); 1303 switch( dtype ) 1304 { 1305 case 'C': 1306 dvl[keyname]= strval; 1307 break; 1308 case 'I': 1309 int ival; 1310 ctoi(strval,&ival); 1311 dvl[keyname]= (int_4)ival; 1312 break; 1313 case 'F': 1314 double dval; 1315 ctof(strval,&dval); 1316 dvl[keyname]= dval; 1317 break; 1318 default : 1319 cout << " FitsIOServer : mot-cle bizerre " << endl; 1320 break; 1321 } 1322 } 1323 } 1324 1325 // close the file 1326 status=0; 1327 fits_close_file(fptr, &status); 1328 if( status ) printerror( status ); 1329 } 1330 1108 1331 1109 1332 // projects a SphericalMap<double>, according sinus-method, and saves onto … … 1180 1403 } 1181 1404 1405 // projects a SphericalMap<double>, according Mollweide-method, and saves onto 1406 // a FITS-file 1407 void FitsIoServer::Mollweide_picture_projection(SphericalMap<float>& sph, char filename[]) 1408 { 1409 // le code de cete methode duplique celui de la precedente, la seule 1410 //difference etant le type de sphere en entree. Ces methodes de projection 1411 // sont provisoires, et ne servent que pour les tests. C est pourquoi je 1412 // ne me suis pas casse la tete, pour l instant 1413 1414 long naxes[2]={600, 300}; 1415 float* map = new float[ 600*300 ]; 1416 int npixels= naxes[0]*naxes[1]; 1417 1418 cout << " image FITS en projection MOLLWEIDE" << endl; 1419 // table will have npixels rows 1420 for(int j=0; j < npixels; j++) map[j]=0.; 1421 for(int j=0; j<naxes[1]; j++) 1422 { 1423 double yd = (j+0.5)/naxes[1]-0.5; 1424 double facteur=2.*Pi/sin(acos(yd*2)); 1425 double theta = (0.5-yd)*Pi; 1426 for(int i=0; i<naxes[0]; i++) 1427 { 1428 double xa = (i+0.5)/naxes[0]-0.5; 1429 double phi = xa*facteur+Pi; 1430 float th=float(theta); 1431 float ff=float(phi); 1432 if (phi<2*Pi && phi>= 0) 1433 { 1434 map[j*naxes[0]+i] = sph.PixValSph(th, ff); 1435 } 1436 } 1437 } 1438 1439 write_picture(naxes, map, filename); 1440 delete [] map; 1441 1442 } 1443 1444 1445 1182 1446 // saves a (LocalMap<double> on a FITS-file in order to be visualized 1183 1447 // (for tests) -
trunk/SophyaExt/FitsIOServer/fitsioserver.h
r488 r564 5 5 #include "tvector.h" 6 6 #include "sphericalmap.h" 7 #include "spheregorski.h" 7 8 #include "localmap.h" 8 9 #include "ntuple.h" … … 33 34 void load(ImageR4& DpcImg,char flnm[]); 34 35 void load(ImageI4& DpcImg,char flnm[]); 36 void load(SphereGorski<float>& sph, char flnm[], int hdunum); 35 37 void save(TMatrix<double>& mat, char flnm[]); 36 38 void save(NTuple& ntpl,char flnm[]); … … 42 44 void sinus_picture_projection(SphericalMap<double>& sph, char flnm[]); 43 45 void sinus_picture_projection(SphericalMap<float>& sph, char flnm[]); 46 void Mollweide_picture_projection(SphericalMap<float>& sph, char flnm[]); 44 47 void picture(LocalMap<double>& lcm, char flnm[]); 45 48 … … 56 59 57 60 void planck_read_img(char flnm[],long& naxis,int& n1,int& n2,int& n3,DVList& dvl); 61 void planck_read_bntbl(char flnm[], int hdunum, int& npixels, DVList& dvl); 58 62 void write_picture(long* naxes,float* map,char* filename) const; 59 63
Note:
See TracChangeset
for help on using the changeset viewer.