lsst.astshim  14.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
FitsChan.h
1 /*
2  * LSST Data Management System
3  * Copyright 2017 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 #ifndef ASTSHIM_FITSCHAN_H
23 #define ASTSHIM_FITSCHAN_H
24 
25 #include <complex>
26 #include <string>
27 #include <vector>
28 
29 #include "astshim/base.h"
30 #include "astshim/Object.h"
31 #include "astshim/Stream.h"
32 #include "astshim/Channel.h"
33 
34 namespace ast {
35 
39 enum class FitsKeyState {
40  ABSENT = 0, // keyword is not present
41  NOVALUE, // keyword is present, but has no value
42  PRESENT // keyword is present and has a value
43 };
44 
48 enum class CardType {
49  NOTYPE = AST__NOTYPE,
50  COMMENT = AST__COMMENT,
51  INT = AST__INT,
52  FLOAT = AST__FLOAT,
53  STRING = AST__STRING,
54  COMPLEXF = AST__COMPLEXF,
55  COMPLEXI = AST__COMPLEXI,
56  LOGICAL = AST__LOGICAL,
57  CONTINUE = AST__CONTINUE,
58  UNDEF = AST__UNDEF,
59 };
60 
67 template <typename T>
68 class FoundValue {
69 public:
76  FoundValue(bool found, T const &value) : found(found), value(value) {}
77 
79  FoundValue() : found(false), value() {}
80  bool found;
81  T value;
82 };
83 
197 class FitsChan : public Channel {
198 public:
209  explicit FitsChan(Stream &stream, std::string const &options = "");
210 
211  virtual ~FitsChan();
212 
213  FitsChan(FitsChan const &) = delete;
214  FitsChan(FitsChan &&) = default;
215  FitsChan &operator=(FitsChan const &) = delete;
216  FitsChan &operator=(FitsChan &&) = default;
217 
225  void delFits() {
226  astDelFits(getRawPtr());
227  assertOK();
228  }
229 
239  void emptyFits() {
240  astEmptyFits(getRawPtr());
241  assertOK();
242  }
243 
341  FoundValue<std::string> findFits(std::string const &name, bool inc);
342 
360  FoundValue<std::complex<double>> getFitsCF(std::string const &name,
361  std::complex<double> defval = {0, 0}) const;
362 
382  FoundValue<std::string> getFitsCN(std::string const &name, std::string defval = "") const;
383 
401  FoundValue<double> getFitsF(std::string const &name, double defval = 0) const;
402 
420  FoundValue<int> getFitsI(std::string const &name, int defval = 0) const;
421 
439  FoundValue<bool> getFitsL(std::string const &name, bool defval = false) const;
440 
462  FoundValue<std::string> getFitsS(std::string const &name, std::string defval = "") const;
463 
470  std::vector<std::string> getAllCardNames();
471 
476  std::string getAllWarnings() const { return getC("AllWarnings"); }
477 
481  int getCard() const { return getI("Card"); }
482 
486  std::string getCardComm() const { return getC("CardComm"); }
487 
491  std::string getCardName() const { return getC("CardName"); }
492 
496  CardType getCardType() const { return static_cast<CardType>(getI("CardType")); }
497 
501  bool getCarLin() const { return getB("CarLin"); }
502 
507  bool getCDMatrix() const { return getB("CDMatrix"); }
508 
512  bool getClean() const { return getB("Clean"); }
513 
517  bool getDefB1950() const { return getB("DefB1950"); }
518 
523  std::string getEncoding() const { return getC("Encoding"); }
524 
529  std::string getFitsAxisOrder() const { return getC("FitsAxisOrder"); }
530 
535  int getFitsDigits() const { return getI("FitsDigits"); }
536 
540  bool getIwc() const { return getB("Iwc"); }
541 
545  int getNCard() const { return getI("NCard"); }
546 
550  int getNKey() const { return getI("NKey"); }
551 
555  int getTabOK() const { return getI("TabOK"); }
556 
561  int getPolyTan() const { return getI("PolyTan"); }
562 
567  std::string getWarnings() const { return getC("Warnings"); }
568 
574  void purgeWcs() {
575  astPurgeWCS(getRawPtr());
576  assertOK();
577  }
578 
595  void putCards(std::string const &cards) {
596  astPutCards(getRawPtr(), cards.c_str());
597  assertOK();
598  }
599 
623  void putFits(std::string const &card, bool overwrite) {
624  astPutFits(getRawPtr(), card.c_str(), overwrite);
625  assertOK();
626  }
627 
640  void readFits() {
641  astReadFits(getRawPtr());
642  assertOK();
643  }
644 
653  void retainFits() {
654  astRetainFits(getRawPtr());
655  assertOK();
656  }
657 
675  void setFitsCF(std::string const &name, std::complex<double> value, std::string const &comment = "",
676  bool overwrite = false) {
677  // this use of reinterpret_cast is explicitly permitted, for C compatibility
678  astSetFitsCF(getRawPtr(), name.c_str(), reinterpret_cast<double(&)[2]>(value), comment.c_str(),
679  overwrite);
680  assertOK();
681  }
682 
705  void setFitsCM(std::string const &comment, bool overwrite = false) {
706  astSetFitsCM(getRawPtr(), comment.c_str(), overwrite);
707  assertOK();
708  }
709 
736  void setFitsCN(std::string const &name, std::string value, std::string const &comment = "",
737  bool overwrite = false) {
738  astSetFitsCN(getRawPtr(), name.c_str(), value.c_str(), comment.c_str(), overwrite);
739  assertOK();
740  }
741 
766  void setFitsF(std::string const &name, double value, std::string const &comment = "",
767  bool overwrite = false) {
768  astSetFitsF(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
769  assertOK();
770  }
771 
796  void setFitsI(std::string const &name, int value, std::string const &comment = "",
797  bool overwrite = false) {
798  astSetFitsI(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
799  assertOK();
800  }
801 
826  void setFitsL(std::string const &name, bool value, std::string const &comment = "",
827  bool overwrite = false) {
828  astSetFitsL(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
829  assertOK();
830  }
831 
864  void setFitsS(std::string const &name, std::string value, std::string const &comment = "",
865  bool overwrite = false) {
866  astSetFitsS(getRawPtr(), name.c_str(), value.c_str(), comment.c_str(), overwrite);
867  assertOK();
868  }
869 
895  void setFitsU(std::string const &name, std::string const &comment = "", bool overwrite = false) {
896  astSetFitsU(getRawPtr(), name.c_str(), comment.c_str(), overwrite);
897  assertOK();
898  }
899 
904  void setCDMatrix(bool cdMatrix) { setB("CDMatrix", cdMatrix); }
905 
911  void setClean(bool clean) { setB("Clean", clean); }
912 
918  void setDefB1950(bool defB1950) { setB("DefB1950", defB1950); }
919 
924  void setEncoding(std::string const &encoding) { setC("Encoding", encoding); }
925 
932  void setFitsAxisOrder(std::string const &order) { setC("FitsAxisOrder", order); }
933 
940  void setFitsDigits(int digits) { setI("FitsDigits", digits); }
941 
947  void setIwc(bool iwcs) { setB("Iwc", iwcs); }
948 
954  void setTabOK(int tabOK) { setI("TabOK", tabOK); }
955 
962  void setPolyTan(int polytan) { setI("PolyTan", polytan); }
963 
970  void setWarnings(std::string const &warnings) { setC("Warnings", warnings); }
971 
975  void showFits() const {
976  astShowFits(getRawPtr());
977  assertOK();
978  }
979 
992  FitsKeyState testFits(std::string const &name) const;
993 
997  void writeFits() {
998  astWriteFits(getRawPtr());
999  assertOK();
1000  }
1001 
1003  void clearCard() { clear("Card"); }
1004 
1008  void setCard(int ind) { setI("Card", ind); }
1009 };
1010 
1011 } // namespace ast
1012 
1013 #endif
void setIwc(bool iwcs)
Definition: FitsChan.h:947
bool found
Was the value found?
Definition: FitsChan.h:80
void emptyFits()
Definition: FitsChan.h:239
FoundValue(bool found, T const &value)
Definition: FitsChan.h:76
bool getCDMatrix() const
Definition: FitsChan.h:507
void setDefB1950(bool defB1950)
Definition: FitsChan.h:918
void setB(std::string const &attrib, bool value)
Definition: Object.h:448
FoundValue< std::string > findFits(std::string const &name, bool inc)
Definition: FitsChan.cc:112
void purgeWcs()
Definition: FitsChan.h:574
bool getB(std::string const &attrib) const
Definition: Object.h:347
FoundValue< bool > getFitsL(std::string const &name, bool defval=false) const
Definition: FitsChan.cc:79
void setFitsCF(std::string const &name, std::complex< double > value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:675
int getTabOK() const
Definition: FitsChan.h:555
AstObject const * getRawPtr() const
Definition: Object.h:286
void setPolyTan(int polytan)
Definition: FitsChan.h:962
Definition: Channel.h:60
void assertOK(AstObject *rawPtr1=nullptr, AstObject *rawPtr2=nullptr)
Definition: base.cc:49
FoundValue< std::string > getFitsS(std::string const &name, std::string defval="") const
Definition: FitsChan.cc:86
std::vector< std::string > getAllCardNames()
Definition: FitsChan.cc:94
void setFitsU(std::string const &name, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:895
std::string getFitsAxisOrder() const
Definition: FitsChan.h:529
int getNCard() const
Definition: FitsChan.h:545
Definition: FitsChan.h:197
bool getDefB1950() const
Definition: FitsChan.h:517
void retainFits()
Definition: FitsChan.h:653
void setFitsI(std::string const &name, int value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:796
void writeFits()
Definition: FitsChan.h:997
FitsChan(Stream &stream, std::string const &options="")
Definition: FitsChan.cc:35
FoundValue< double > getFitsF(std::string const &name, double defval=0) const
Definition: FitsChan.cc:65
void setCard(int ind)
Definition: FitsChan.h:1008
void setFitsDigits(int digits)
Definition: FitsChan.h:940
CardType
Definition: FitsChan.h:48
FoundValue< std::string > getFitsCN(std::string const &name, std::string defval="") const
Definition: FitsChan.cc:57
KeyMap warnings() const
Definition: Channel.cc:64
FoundValue< std::complex< double > > getFitsCF(std::string const &name, std::complex< double > defval={0, 0}) const
Definition: FitsChan.cc:47
std::string getAllWarnings() const
Definition: FitsChan.h:476
void setTabOK(int tabOK)
Definition: FitsChan.h:954
void setC(std::string const &attrib, std::string const &value)
Definition: Object.h:460
void putFits(std::string const &card, bool overwrite)
Definition: FitsChan.h:623
void setFitsF(std::string const &name, double value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:766
void setFitsAxisOrder(std::string const &order)
Definition: FitsChan.h:932
void delFits()
Definition: FitsChan.h:225
T value
The found value; ignore if found is false.
Definition: FitsChan.h:81
void setWarnings(std::string const &warnings)
Definition: FitsChan.h:970
int getCard() const
Definition: FitsChan.h:481
void setClean(bool clean)
Definition: FitsChan.h:911
void setFitsS(std::string const &name, std::string value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:864
FoundValue< int > getFitsI(std::string const &name, int defval=0) const
Definition: FitsChan.cc:72
bool getCarLin() const
Definition: FitsChan.h:501
void putCards(std::string const &cards)
Definition: FitsChan.h:595
std::string getCardName() const
Definition: FitsChan.h:491
void setFitsCM(std::string const &comment, bool overwrite=false)
Definition: FitsChan.h:705
int getFitsDigits() const
Definition: FitsChan.h:535
CardType getCardType() const
Definition: FitsChan.h:496
FitsKeyState testFits(std::string const &name) const
Definition: FitsChan.cc:120
std::string getEncoding() const
Definition: FitsChan.h:523
std::string const getC(std::string const &attrib) const
Definition: Object.h:360
FitsKeyState
Definition: FitsChan.h:39
void readFits()
Definition: FitsChan.h:640
int getI(std::string const &attrib) const
Definition: Object.h:399
void setEncoding(std::string const &encoding)
Definition: FitsChan.h:924
void setI(std::string const &attrib, int value)
Definition: Object.h:496
void setCDMatrix(bool cdMatrix)
Definition: FitsChan.h:904
void showFits() const
Definition: FitsChan.h:975
int getNKey() const
Definition: FitsChan.h:550
void setFitsL(std::string const &name, bool value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:826
void setFitsCN(std::string const &name, std::string value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:736
FoundValue()
Default constructor: found false, value is default-constructed.
Definition: FitsChan.h:79
Definition: FitsChan.h:68
std::string getWarnings() const
Definition: FitsChan.h:567
void clearCard()
Rewind the card index to the beginning.
Definition: FitsChan.h:1003
Definition: Stream.h:41
int getPolyTan() const
Definition: FitsChan.h:561
void clear(std::string const &attrib)
Definition: Object.h:113
std::string getCardComm() const
Definition: FitsChan.h:486
bool getClean() const
Definition: FitsChan.h:512
bool getIwc() const
Definition: FitsChan.h:540