Commit 2f5efd3b authored by Réza Ansari's avatar Réza Ansari
Browse files

1/ Ajout methode VisiP4ReaderBase::SelectTimeFrame()

2/ methode statique VisiP4ReaderBase::getReader() qui cree automatiquement un
  VisiP4ReaderDB ou VisiP4ReaderNoDB
3/ Adaptation de rdvisip4.cc
                        Reza 14/09/2017
parent 25acef68
......@@ -92,7 +92,10 @@ int main(int narg, const char* arg[])
int nvmtx=(Imax-Imin+1)/Istep;
int nmod=nvmtx/20;
if (nmod<1) nmod=1;
VisiP4Reader vreader(paths, Imin,Imax,Istep,fgreorderfreq);
VisiP4ReaderBase * reader = VisiP4ReaderBase::getReader(paths);
VisiP4ReaderBase & vreader = (*reader);
vreader.setFreqReordering(fgreorderfreq);
vreader.SelectSerialNum(Imin,Imax,Istep);
vreader.setPrintLevel(prtlev);
bool fgok=true;
//vismtx: visib matrice, meanmtx: mean FFT coef, vismtx_center: visib matrix corrigee de l'offset (normalisee avec NPAQSUM)
......
......@@ -3,13 +3,52 @@
// Classe(s) de lecture des fichiers de visibilites PAON4
//----------------------------------------------------------------
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <fstream>
#include "visip4reader.h"
#include "pexceptions.h"
/* --Methode-- */
VisiP4ReaderBase::VisiP4ReaderBase(vector<string> const& vpath, bool reorderfreq)
: paths_(vpath), fgreorderfreq_(reorderfreq),
VisiP4ReaderBase * VisiP4ReaderBase::getReader(vector<string> const& vpath)
{
if (vpath.size() < 1) throw ParmError("VisiP4ReaderBase::getReader(vector<string> const& vpath) vpath.size()=0 !");
cout << "VisiP4ReaderBase::getReader() Creating VisiP4Reader for data in "<<endl;
for(size_t k=0; k<vpath.size(); k++) cout << " ...path["<<k<<"]= "<<vpath[k]<<endl;
char filenamebuff[2048];
bool fgdb = false;
sprintf(filenamebuff,"%s/vmtxdbdesc.txt",vpath[0].c_str());
int fid;
if ((fid=open(filenamebuff,O_RDONLY))>=0) {
close(fid);
fgdb = true;
cout << "... file vmtxdbdesc.txt exist -> VisiP4ReaderDB object"<<endl;
}
bool fgok = true;
int nbvisgrp=0;
while (fgok) {
sprintf(filenamebuff,"%s/chanum_%d.ppf",vpath[0].c_str(),nbvisgrp);
if ((fid=open(filenamebuff,O_RDONLY))>=0) {
close(fid);
nbvisgrp++;
}
else fgok = false;
}
cout << "... NbVisGrp determined from chanum_JJ.ppf file -> NbVisGrp="<<nbvisgrp<<endl;
VisiP4ReaderBase * reader=NULL;
if (fgdb) reader = new VisiP4ReaderDB(vpath);
else reader = new VisiP4ReaderNoDB(vpath,0,0,1,false);
reader->setNbVisGrp(nbvisgrp);
return reader;
}
/* --Methode-- */
VisiP4ReaderBase::VisiP4ReaderBase(vector<string> const& vpath)
: paths_(vpath), fgreorderfreq_(false),
cur_serialnum_(0)
{
SelectSerialNum(0,0);
......@@ -51,7 +90,13 @@ void VisiP4ReaderBase::SelectSerialNum(int first, int last, int step)
cur_serialnum_=ser_first_;
return;
}
/* --Methode-- */
void VisiP4ReaderBase::SelectTimeFrame(TimeStamp const & tustart, TimeStamp const & tuend, int step)
{
throw ForbiddenError("VisiP4ReaderBase::SelectTimeFrame() - this operation is not implemented");
}
/* --Methode-- */
bool VisiP4ReaderBase::ReadNext_P(TMatrix< complex<r_4> >* vismtx, TMatrix< complex<r_4> >* meanmtx,
TimeStamp& dateobs, double& mttag)
......@@ -199,8 +244,9 @@ TMatrix< complex<r_4> > VisiP4ReaderBase::SubtractOffset(TMatrix< complex<r_4>
/* --Methode-- */
VisiP4ReaderNoDB::VisiP4ReaderNoDB(vector<string> const& vpath, int first, int last, int step, bool reorderfreq)
: VisiP4ReaderBase(vpath, reorderfreq)
: VisiP4ReaderBase(vpath)
{
setFreqReordering(reorderfreq);
SelectSerialNum(first, last, step);
}
......@@ -221,8 +267,8 @@ void VisiP4ReaderNoDB::ReadVisMtx(int band, int visgrp, long sernum, TMatrix< co
}
/* --Methode-- */
VisiP4ReaderDB::VisiP4ReaderDB(vector<string> const& vpath, bool reorderfreq)
: VisiP4ReaderBase(vpath, reorderfreq)
VisiP4ReaderDB::VisiP4ReaderDB(vector<string> const& vpath)
: VisiP4ReaderBase(vpath)
{
Init();
SelectSerialNum(0,0,1);
......@@ -230,9 +276,10 @@ VisiP4ReaderDB::VisiP4ReaderDB(vector<string> const& vpath, bool reorderfreq)
/* --Methode-- */
VisiP4ReaderDB::VisiP4ReaderDB(vector<string> const& vpath, int first, int last, int step, bool reorderfreq)
: VisiP4ReaderBase(vpath, reorderfreq)
: VisiP4ReaderBase(vpath)
{
Init();
setFreqReordering(reorderfreq);
SelectSerialNum(first, last, step);
}
......@@ -247,6 +294,7 @@ VisiP4ReaderDB::~VisiP4ReaderDB()
/* --Methode-- */
void VisiP4ReaderDB::SelectSerialNum(int first, int last, int step)
{
if (last < first) throw ParmError("VisiP4ReaderDB::SelectSerialNum() last < first !");
VisiP4ReaderBase::SelectSerialNum(first, last, step);
for(size_t k=0; k<vdb_.size(); k++) {
if ((ser_first_>=vdb_[k].ser_start)&&(ser_first_<vdb_[k].ser_end)) {
......@@ -257,6 +305,20 @@ void VisiP4ReaderDB::SelectSerialNum(int first, int last, int step)
last_filenum_ = vdb_[k].filenum;
}
OpenFiles(cur_vdb_index_);
return;
}
/* --Methode-- */
void VisiP4ReaderDB::SelectTimeFrame(TimeStamp const & tustart, TimeStamp const & tuend, int step)
{
int sfirst = 0;
int slast = 0;
for(size_t k=0; k<vdb_.size(); k++) {
if ((tustart >= vdb_[k].tu_start)&&(tustart < vdb_[k].tu_end)) sfirst = vdb_[k].ser_start;
if ((tuend >= vdb_[k].tu_start)&&(tuend < vdb_[k].tu_end)) slast = vdb_[k].ser_end;
}
SelectSerialNum(sfirst,slast,step);
return;
}
/* --Methode-- */
......@@ -303,13 +365,18 @@ void VisiP4ReaderDB::Init()
void VisiP4ReaderDB::ReadVisMtx(int band, int visgrp, long sernum, TMatrix< complex<r_4> > & vmtx, TMatrix< complex<r_4> > * mmtxp)
{
if ((sernum < vdb_[cur_vdb_index_].ser_start)||(sernum >= vdb_[cur_vdb_index_].ser_end)) {
for(size_t k=0; k<vdb_.size(); k++) {
if ((sernum>=vdb_[k].ser_start)&&(sernum<vdb_[k].ser_end)) {
cur_filenum_ = vdb_[k].filenum;
cur_vdb_index_ = k ; // k should be same value as vdb_[k].filenum
break;
}
}
if ((sernum < vdb_[cur_vdb_index_+1].ser_start)||(sernum >= vdb_[cur_vdb_index_+1].ser_end)) {
cur_vdb_index_ ++ ; cur_filenum_ = vdb_[cur_vdb_index_].filenum;
}
else {
for(size_t k=0; k<vdb_.size(); k++) {
if ((sernum>=vdb_[k].ser_start)&&(sernum<vdb_[k].ser_end)) {
cur_filenum_ = vdb_[k].filenum;
cur_vdb_index_ = k ; // k should be same value as vdb_[k].filenum
break;
}
}
}
OpenFiles(cur_vdb_index_);
}
char tagbuff[128];
......
......@@ -10,9 +10,9 @@
#include <vector>
#include <iostream>
// Include utiles SOPHYA TArray , FitsIOServer
#include "array.h"
#include "fitsioserver.h"
// Include utiles SOPHYA TArray
#include "array.h"
#include "timestamp.h"
using namespace std;
using namespace SOPHYA;
......@@ -21,14 +21,24 @@ using namespace SOPHYA;
//----- class VisiP4ReaderBase : classe de base pour le lecture des matrices de visibilite PAON4
//------------------------------------------------------------------------------------------------
/*! \brief Base class for reading PAON-4 visibility data
This class has pure virtual method ReadVisMtx() that should be implemented in derived classes */
class VisiP4ReaderBase {
public:
VisiP4ReaderBase(vector<string> const& vpath, bool reorderfreq=true);
//! Create and returns a VisiP4ReaderNoDB or VisiP4ReaderDB reader according to the existence of vmtxdbdesc.txt in the path
static VisiP4ReaderBase * getReader(vector<string> const& vpath);
VisiP4ReaderBase(vector<string> const& vpath);
virtual ~VisiP4ReaderBase();
/*! \brief Select range of Serial Number for Visibility Matrices to be processed
Process VisMtx with serial numbers sn such as ser_first_<= sn <= ser_last_ , one matrix out of ser_step_ */
virtual void SelectSerialNum(int first, int last, int step=1);
/*! \brief Select the time interval for Visibility Matrices to be processed
Default implementation throws an exception */
virtual void SelectTimeFrame(TimeStamp const & tustart, TimeStamp const & tuend, int step=1);
//! Activate or deactivate frequency reordering when reading visibility matrices
inline void setFreqReordering(bool fg)
{ fgreorderfreq_ = fg; }
......@@ -100,24 +110,32 @@ protected:
//------------------------------------------------------------------------------------------------
//----- class VisiP4ReaderNoDB : lecture des donnees ecrites sous forme d un fichier / matrice de visibilite
//------------------------------------------------------------------------------------------------
/*! \brief Implementation of VisiP4ReaderBase to handle reading the first version of PAON4 visibility data,
with a single visibility matrix per file */
class VisiP4ReaderNoDB : public VisiP4ReaderBase {
public:
VisiP4ReaderNoDB(vector<string> const& vpath, int first, int last, int step=1, bool reorderfreq=true);
VisiP4ReaderNoDB(vector<string> const& vpath, int first, int last, int step=1, bool reorderfreq=false);
protected:
virtual void ReadVisMtx(int band, int visgrp, long sernum, TMatrix< complex<r_4> > & vmtx, TMatrix< complex<r_4> > * mmtx);
};
//------------------------------------------------------------------------------------------------
//----- class VisiP4ReaderNoDB : lecture des donnees ecrites VisMtxDBWriter (plusieurs matrices / fichier)
//----- class VisiP4ReaderDB : lecture des donnees ecrites VisMtxDBWriter (plusieurs matrices / fichier)
//------------------------------------------------------------------------------------------------
/*! \brief Implementation of VisiP4ReaderBase to handle reading the second version of PAON4 visibility data,
saved through the TAcq/VisMtxDBWriter class */
class VisiP4ReaderDB : public VisiP4ReaderBase {
public:
VisiP4ReaderDB(vector<string> const& vpath, bool reorderfreq=false);
VisiP4ReaderDB(vector<string> const& vpath);
VisiP4ReaderDB(vector<string> const& vpath, int first, int last, int step=1, bool reorderfreq=false);
virtual ~VisiP4ReaderDB();
virtual void SelectSerialNum(int first, int last, int step=1);
virtual void SelectTimeFrame(TimeStamp const & tustart, TimeStamp const & tuend, int step=1);
protected:
void Init();
......@@ -132,8 +150,8 @@ protected:
std::vector<PInPersist *> cur_filep_;
};
// typedef VisiP4ReaderNoDB VisiP4Reader;
typedef VisiP4ReaderDB VisiP4Reader;
// For compatibility for old code
typedef VisiP4ReaderNoDB VisiP4Reader;
#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