Commit 5b272f2c authored by jclamber's avatar jclamber
Browse files

improve fits2uns

git-svn-id: http://svn.oamp.fr/repos/uns_projects/trunk@119 f264a43e-d52d-4b82-913b-c2bd5215a18a
parent e3aac64e
......@@ -59,7 +59,10 @@ int main(int argc, char ** argv )
std::string typeout = (nos::getparam ((char *) "type" ));
bool verbose = (nos::getbparam((char *) "verbose" ));
FITS::setVerboseMode(true);
if (verbose)
FITS::setVerboseMode(true);
else
FITS::setVerboseMode(false);
try {
......@@ -89,18 +92,19 @@ int readImage(std::string in, std::string out, std::string type, int zmin, int z
std::cerr << " Begin \n";
std::valarray<float> contents;
#if 1
try {
image = &pInfile->extension(1);
image = &pInfile->extension(0);
std::cerr << "There is an extension\n";
std::cout << "#axis ="<<image->axes() << std::endl;
std::cerr << "#axis ="<<image->axes() << std::endl;
//(pInfile->extension(1)).read(contents);
((ExtHDU *) image)->read(contents);
} catch (FitsException&) {
#endif
image = &pInfile->pHDU();
std::cerr << "There is a pHDU\n";
std::cout << "#axis ="<<image->axes() << std::endl;
std::cerr << "#axis ="<<image->axes() << std::endl;
//(pInfile->pHDU()).read(contents);
((PHDU *) image)->read(contents);
}
......@@ -112,17 +116,17 @@ int readImage(std::string in, std::string out, std::string type, int zmin, int z
// read all user-specifed, coordinate, and checksum keys in the image
image->readAllKeys();
std::cout << "#axis ="<<image->axes() << std::endl;
std::cerr << "#axis ="<<image->axes() << std::endl;
//image->read(contents);
std::cout << "#axis ="<<image->axes() << std::endl;
std::cerr << "#axis ="<<image->axes() << std::endl;
for (int i=0;i<image->axes();i++) {
std::cerr << "axis["<<i<<"]="<<image->axis(i)<<"\n";
}
// this doesn't print the data, just header info.
//std::cout << *image << std::endl;
//std::cerr << *image << std::endl;
long ax(image->axis(0));
long ay(image->axis(1));
......@@ -137,19 +141,19 @@ int readImage(std::string in, std::string out, std::string type, int zmin, int z
std::vector <float> pos,hsml,rho;
long nan=0;
std::cout << "value = " << contents.size() << "\n";
std::cerr << "value = " << contents.size() << "\n";
for (unsigned long i=0; i<contents.size(); i++) {
if (std::isfinite(contents[i])) {
if (std::isfinite(contents[i]) && contents[i]>1e-5 && contents[i] < 10.) {
long z_i=int(i/(ax*ay));
long z_i=int(i/(ax*ay)); // current Z plane
assert(z_i<=az);
if (z_i>=zmin && z_i<=zmax) {
long nxy=i-z_i*(ax*ay);
long y_i=int(nxy/ax);
if (z_i>=zmin && z_i<=zmax) { // inside Z selection
long nxy=i-z_i*(ax*ay);// #pixels (x/y) of the latest Z plane
long y_i=int(nxy/ax); // current Y coordinate
assert(y_i<ay);
long x_i=nxy-(y_i*ax);
assert(z_i<az);
long x_i=nxy-(y_i*ax); // current X coordinate
assert(z_i<=az);
pos.push_back(x_i*1.0);
pos.push_back(y_i*1.0);
pos.push_back(z_i*1.0);
......@@ -163,26 +167,16 @@ int readImage(std::string in, std::string out, std::string type, int zmin, int z
}
std::cerr << " #NAN values = "<< nan << "\n";
uns::CunsOut * unsout = new uns::CunsOut(out,type,false);
std::string comp="gas";
if (type=="nemo") comp="all";
unsout->snapshot->setData("time",0.0);
unsout->snapshot->setData("gas","pos",pos.size()/3,&pos[0],false);
unsout->snapshot->setData("gas","rho",rho.size(),&rho[0],false);
unsout->snapshot->setData("gas","hsml",hsml.size(),&hsml[0],false);
unsout->snapshot->setData(comp,"pos",pos.size()/3,&pos[0],false);
unsout->snapshot->setData(comp,"rho",rho.size(),&rho[0],false);
unsout->snapshot->setData(comp,"hsml",hsml.size(),&hsml[0],false);
// save snapshot
unsout->snapshot->save();
return 0;
long ax1(image->axis(0));
long ax2(image->axis(1));
for (long j = 0; j < ax2; j+=10)
{
std::ostream_iterator<short> c(std::cout,"\t");
std::copy(&contents[j*ax1],&contents[(j+1)*ax1-1],c);
std::cout << '\n';
}
std::cout << std::endl;
return 0;
#endif
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment