// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL // Eric Aubourg // Christophe Magneville // Reza Ansari // $Id: fitstoiwtr.cc,v 1.20 2001-11-27 22:05:41 aubourg Exp $ #include "fitstoiwtr.h" #include "toimanager.h" #include extern void fits_lock(); extern void fits_unlock(); FITSTOIWriter::FITSTOIWriter(string fn) { fname = fn; fstatus = 0; implicitSN = false; nCols = 1; // Open file remove(fname.c_str()); fits_lock(); fits_create_file(&fptr,fname.c_str(),&fstatus); fits_unlock(); name = "wtr"; totnscount = 0; } FITSTOIWriter::~FITSTOIWriter() { } void FITSTOIWriter::setImplicitSN() { implicitSN = true; nCols = 0; } void FITSTOIWriter::addInput(string name, TOI* toi, bool withFlag) { declareInput(name); int iTOI = fwinputs.size(); fwinputs.push_back(toi); colsinput[iTOI] = pair(nCols, withFlag); nCols++; if (withFlag) nCols++; toi->addConsumer(this); } void FITSTOIWriter::afterinit() { if (inTOIs) delete[] inTOIs; inTOIs = new (TOI*[fwinputs.size()]); for (int i=0; i::iterator ii = inIx.begin(); ii != inIx.end(); ii++) { int jTOI = (*ii).second; pair p = colsinput[jTOI]; int ck = p.first; coln[ck] = (*ii).first; colnames[ck] = const_cast(coln[ck].c_str()); cout << " Column[" << ck << "] Name=" << coln[ck] << endl; coltypes[ck] = "1D"; colunits[ck] = "double"; if (p.second) { ck++; coln[ck] = "fg_" + coln[ck-1]; colnames[ck] = const_cast(coln[ck].c_str()); cout << " Column[" << ck << "] -Flag- Name=" << coln[ck] << endl; coltypes[ck] = "1J"; colunits[ck] = "UInt_8Flag"; } } fits_lock(); fits_create_tbl(fptr, BINARY_TBL, 0, nCols, colnames, coltypes, colunits, NULL, &fstatus); fits_write_date(fptr, &fstatus); fits_unlock(); delete[] colunits; delete[] coltypes; delete[] colnames; delete[] coln; // Add headers ? // loop int fitsLine = 1; int snb = getMinIn(); int sne = getMaxIn(); double* tabdata = new double[ndata]; uint_8* tabflag = new uint_8[ndata]; long* tabflagl = (long*) tabflag; // il faut uint_8 == long, // c'est long long dans sophya bool* tabck = new bool[ndata]; int i; for(i=0; i p = colsinput[i]; fits_write_col_dbl(fptr, p.first+1, fitsLine, 1, 1, tabdata+i, &fstatus); if (p.second) { long f = tabflag[i]; fits_write_col_lng(fptr, p.first+2, fitsLine, 1, 1, &f, &fstatus); // fits_write_col_lng(fptr, p.first+2, fitsLine, 1, 1, tabflagl+i, &fstatus); } if (fstatus != 0) { cerr << "fitstoiwtr error sn = " << sn << " i = "<< i << endl; fits_report_error(stderr, fstatus); abort(); } } fits_unlock(); if (fitsLine%50==0) { sched_yield(); } // if ((sn%2000 == 0) || (sn