Commit ef67a71b authored by jclamber's avatar jclamber
Browse files

fits coverter to uns using CCfits lib

git-svn-id: http://svn.oamp.fr/repos/uns_projects/trunk@115 f264a43e-d52d-4b82-913b-c2bd5215a18a
parent 32c7143a
// ============================================================================
// Copyright Jean-Charles LAMBERT - 2010-2015
// Centre de donneeS Astrophysiques de Marseille (CeSAM)
// e-mail: Jean-Charles.Lambert@lam.fr
// address: Aix Marseille Universite, CNRS, LAM
// Laboratoire d'Astrophysique de Marseille
// Pole de l'Etoile, site de Chateau-Gombert
// 38, rue Frederic Joliot-Curie
// 13388 Marseille cedex 13 France
// CNRS UMR 7326
// ============================================================================
#define _FILE_OFFSET_BITS 64
#include <cstdio>
#include <assert.h>
#define _vectmath_h // put this statement to avoid conflict with C++ vector class
namespace nos { // use namespace to avoid conflict between
// typedef char * string from stdinc.h
// and using std::string from ccfits.h
typedef char * string;
#include "getparam.h"
}
#include <CCfits>
#include <uns.h>
#include <cmath>
// The library is enclosed in a namespace.
using namespace CCfits;
// ------------------------------------------------------------
// Nemo variable
const char * defv[] = { // use `::'string because of 'using namespace std'
"in=???\n tipsy input file ",
"out=???\n output file)",
"type=nemo\n nemo|gadget2",
"verbose=f\n verbose mode ",
"VERSION=1.0\n compiled on <"__DATE__"> JCL ",
NULL
};
const char * usage="Simple converter fits to uns compatible output format";
int readImage(std::string in, std::string out, std::string type);
int main(int argc, char ** argv )
{
if (argc) {;} // remove compiler warning :)
// start NEMO
nos::initparam(const_cast<char**>(argv),const_cast<char**>(defv));
// Get input parameters
std::string simname (nos::getparam ((char *) "in" ));
std::string outname (nos::getparam ((char *) "out" ));
std::string typeout = (nos::getparam ((char *) "type" ));
bool verbose = (nos::getbparam((char *) "verbose" ));
FITS::setVerboseMode(true);
try {
if (!readImage(simname,outname,typeout)) std::cerr << " readImage() \n";
}
catch (FitsException&)
// will catch all exceptions thrown by CCfits, including errors
// found by cfitsio (status != 0)
{
std::cerr << " Fits Exception Thrown by test function \n";
}
return 0;
nos::finiparam();
}
int readImage(std::string in, std::string out, std::string type)
{
// std::auto_ptr<FITS> pInfile(new FITS("/windows7/JDL/ngc6503.fits",Read,true));
std::auto_ptr<FITS> pInfile(new FITS(in,Read,true));
PHDU& image = pInfile->pHDU();
std::valarray<unsigned long> contents;
// read all user-specifed, coordinate, and checksum keys in the image
image.readAllKeys();
image.read(contents);
std::cout << "#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::cout << "value = " << contents.size() << "\n";
for (int i=0; i<contents.size(); i++) {
if (isnan(contents[i])) {
std::cerr << "Nan ["<<i<<"]\n";
}
}
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;
}
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