source: trunk/src/FillerWrapper.h@ 3017

Last change on this file since 3017 was 2998, checked in by Kana Sugimoto, 10 years ago

r2993 | KanaSugimoto | 2014-10-15 20:32:13 +0900 (Wed, 15 Oct 2014) | 14 lines

New Development: No

JIRA Issue: No

Ready for Test: Yes/No

Interface Changes: Yes/No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: creating a test branch to merge from NRAO repository



r2994 | KanaSugimoto | 2014-10-15 20:51:59 +0900 (Wed, 15 Oct 2014) | 3 lines

Initialized merge tracking via "svnmerge" with revisions "1-31330" from
https://svn.cv.nrao.edu/svn/casa/branches/personal/kana/test-merge-43-01/asap


r2995 | KanaSugimoto | 2014-10-15 21:15:27 +0900 (Wed, 15 Oct 2014) | 3 lines

Initialized merge tracking via "svnmerge" with revisions "1-31330" from
https://svn.cv.nrao.edu/svn/casa/branches/personal/kana/test-merge-43-01/asap


r2996 | KanaSugimoto | 2014-10-15 21:24:23 +0900 (Wed, 15 Oct 2014) | 20 lines

Merged revisions 31331 via svnmerge from
https://svn.cv.nrao.edu/svn/casa/branches/personal/kana/test-merge-43-01/asap

........

r31331 | kana.sugimoto | 2014-10-15 21:06:50 +0900 (Wed, 15 Oct 2014) | 14 lines



New Development: Yes/No

JIRA Issue: No/Yes List JIRA ticket.

Ready for Test: Yes/No

Interface Changes: Yes/No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: dummy commit



........


r2997 | KanaSugimoto | 2014-10-15 21:48:06 +0900 (Wed, 15 Oct 2014) | 17 lines

Merged revisions 31332-31334 via svnmerge from
https://svn.cv.nrao.edu/svn/casa/branches/personal/kana/test-merge-43-01/asap

........

r31332 | kana.sugimoto | 2014-10-15 21:30:59 +0900 (Wed, 15 Oct 2014) | 1 line


A minor modification to a comment

........

r31333 | kana.sugimoto | 2014-10-15 21:36:19 +0900 (Wed, 15 Oct 2014) | 1 line


Removed a white line

........

r31334 | kana.sugimoto | 2014-10-15 21:39:32 +0900 (Wed, 15 Oct 2014) | 1 line


Put back year change

........


File size: 2.7 KB
Line 
1//
2// C++ Interface: Filler
3//
4// Description:
5//
6//
7// Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2010
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#ifndef ASAPFILLER_H
13#define ASAPFILLER_H
14
15#include <casa/aips.h>
16#include <casa/Exceptions.h>
17#include <casa/Utilities/CountedPtr.h>
18#include <casa/Containers/Record.h>
19#include <casa/OS/File.h>
20
21#include <string>
22
23#include "ScantableWrapper.h"
24#include "FillerBase.h"
25#include "PKSFiller.h"
26#include "NROFiller.h"
27
28
29namespace asap
30{
31class FillerWrapper
32{
33public:
34
35 explicit FillerWrapper(ScantableWrapper tbl) : filler_(0), attached_(false)
36 { stable_ = tbl.getCP(); }
37
38 virtual ~FillerWrapper() { close(); }
39
40
41 void open(const std::string& filename, const casa::Record& rec) {
42 // void open(const std::string& filename) {
43 casa::File file(filename);
44 if ( !file.exists() ) {
45 throw(AipsError("File does not exist"));
46 }
47 int fileType = dataType( filename ) ;
48 if ( fileType == 0 ) {
49 filler_ = new PKSFiller(stable_);
50 if (filler_->open(filename, rec)) {
51 attached_ = true;
52 return;
53 }
54 }
55 else if ( fileType == 1 ) {
56 filler_ = new NROFiller(stable_);
57 if (filler_->open(filename, rec)) {
58 attached_ = true;
59 return;
60 }
61 }
62 filler_ = 0;
63 attached_ = false;
64 throw casa::AipsError("Unknown Data Format");
65 }
66 void close() {
67 if (attached_) {
68 filler_->close();
69 }
70 }
71
72 void fill() {
73 if (attached_) {
74 filler_->fill();
75 }
76 }
77
78 void setReferenceRegex(const std::string& rx) {
79 if (attached_) {
80 filler_->setReferenceRegex(rx);
81 }
82 }
83
84private:
85
86 int dataType( const std::string &filename ) {
87 int ret = -1 ;
88 int pks = 0 ;
89 int nro = 1 ;
90 casa::File file( filename ) ;
91 if ( file.isDirectory() )
92 ret = pks ;
93 else if ( file.isReadable() ) {
94 // if we want to compare to 6 characters we should only read in 6
95 FILE *f = fopen( filename.c_str(), "r") ;
96 char buf[7] ;
97 fread( buf, 6, 1, f ) ;
98 fclose( f ) ;
99 buf[6]='\0' ;
100 // NRO data has two types:
101 // 1) specific binary data for OTF observation
102 // 2) (pseudo-)FITS data that doesn't have primary HDU
103 // So, one can distinguish NRO and non-NRO data by examining
104 // first keyword name.
105 if ( casa::String( buf ) == "SIMPLE" ) {
106 ret = pks ;
107 }
108 else {
109 ret = nro ;
110 }
111 }
112 return ret ;
113 }
114
115 FillerWrapper();
116 FillerWrapper(const FillerWrapper&);
117 FillerWrapper& operator=(const FillerWrapper&);
118
119 casa::CountedPtr<FillerBase> filler_;
120 bool attached_;
121 casa::CountedPtr<Scantable> stable_;
122};
123
124};
125#endif
Note: See TracBrowser for help on using the repository browser.