lsst.astshim  14.0-6-g52c7625+1
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,
41  NOVALUE,
42  PRESENT
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 
704  void setFitsCM(std::string const &comment, bool overwrite = false) {
705  astSetFitsCM(getRawPtr(), comment.c_str(), overwrite);
706  assertOK();
707  }
708 
735  void setFitsCN(std::string const &name, std::string value, std::string const &comment = "",
736  bool overwrite = false) {
737  astSetFitsCN(getRawPtr(), name.c_str(), value.c_str(), comment.c_str(), overwrite);
738  assertOK();
739  }
740 
765  void setFitsF(std::string const &name, double value, std::string const &comment = "",
766  bool overwrite = false) {
767  astSetFitsF(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
768  assertOK();
769  }
770 
795  void setFitsI(std::string const &name, int value, std::string const &comment = "",
796  bool overwrite = false) {
797  astSetFitsI(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
798  assertOK();
799  }
800 
825  void setFitsL(std::string const &name, bool value, std::string const &comment = "",
826  bool overwrite = false) {
827  astSetFitsL(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
828  assertOK();
829  }
830 
863  void setFitsS(std::string const &name, std::string value, std::string const &comment = "",
864  bool overwrite = false) {
865  astSetFitsS(getRawPtr(), name.c_str(), value.c_str(), comment.c_str(), overwrite);
866  assertOK();
867  }
868 
894  void setFitsU(std::string const &name, std::string const &comment = "", bool overwrite = false) {
895  astSetFitsU(getRawPtr(), name.c_str(), comment.c_str(), overwrite);
896  assertOK();
897  }
898 
903  void setCDMatrix(bool cdMatrix) { setB("CDMatrix", cdMatrix); }
904 
910  void setClean(bool clean) { setB("Clean", clean); }
911 
917  void setDefB1950(bool defB1950) { setB("DefB1950", defB1950); }
918 
923  void setEncoding(std::string const &encoding) { setC("Encoding", encoding); }
924 
931  void setFitsAxisOrder(std::string const &order) { setC("FitsAxisOrder", order); }
932 
939  void setFitsDigits(int digits) { setI("FitsDigits", digits); }
940 
946  void setIwc(bool iwcs) { setB("Iwc", iwcs); }
947 
953  void setTabOK(int tabOK) { setI("TabOK", tabOK); }
954 
961  void setPolyTan(int polytan) { setI("PolyTan", polytan); }
962 
969  void setWarnings(std::string const &warnings) { setC("Warnings", warnings); }
970 
974  void showFits() const {
975  astShowFits(getRawPtr());
976  assertOK();
977  }
978 
994  FitsKeyState testFits(std::string const &name = "") const;
995 
999  void writeFits() {
1000  astWriteFits(getRawPtr());
1001  assertOK();
1002  }
1003 
1005  void clearCard() { clear("Card"); }
1006 
1010  void setCard(int ind) { setI("Card", ind); }
1011 };
1012 
1013 } // namespace ast
1014 
1015 #endif
void setIwc(bool iwcs)
Definition: FitsChan.h:946
bool found
Was the value found?
Definition: FitsChan.h:80
std::string getFitsAxisOrder() const
Definition: FitsChan.h:529
complex integer
void emptyFits()
Definition: FitsChan.h:239
FoundValue(bool found, T const &value)
Definition: FitsChan.h:76
void setDefB1950(bool defB1950)
Definition: FitsChan.h:917
void purgeWcs()
Definition: FitsChan.h:574
complex floating point
AST wrapper classes and functions.
Definition: attributes_channel.dox:1
CardType getCardType() const
Definition: FitsChan.h:496
void setFitsCF(std::string const &name, std::complex< double > value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:675
void setPolyTan(int polytan)
Definition: FitsChan.h:961
Definition: Channel.h:60
std::string getCardComm() const
Definition: FitsChan.h:486
void assertOK(AstObject *rawPtr1=nullptr, AstObject *rawPtr2=nullptr)
Definition: base.cc:49
void setFitsU(std::string const &name, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:894
std::string getCardName() const
Definition: FitsChan.h:491
int getNCard() const
Definition: FitsChan.h:545
bool getCDMatrix() const
Definition: FitsChan.h:507
Definition: FitsChan.h:197
void retainFits()
Definition: FitsChan.h:653
void setFitsI(std::string const &name, int value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:795
void writeFits()
Definition: FitsChan.h:999
void setCard(int ind)
Definition: FitsChan.h:1010
void setFitsDigits(int digits)
Definition: FitsChan.h:939
keyword is present and has a value
card is a comment-style card with no "=" (COMMENT, HISTORY, ...)
CardType
Definition: FitsChan.h:48
void setTabOK(int tabOK)
Definition: FitsChan.h:953
bool getCarLin() const
Definition: FitsChan.h:501
int getNKey() const
Definition: FitsChan.h:550
keyword is present, but has no value
keyword is not present
bool getClean() const
Definition: FitsChan.h:512
bool getDefB1950() const
Definition: FitsChan.h:517
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:765
void setFitsAxisOrder(std::string const &order)
Definition: FitsChan.h:931
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:969
void setClean(bool clean)
Definition: FitsChan.h:910
void setFitsS(std::string const &name, std::string value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:863
void putCards(std::string const &cards)
Definition: FitsChan.h:595
void setFitsCM(std::string const &comment, bool overwrite=false)
Definition: FitsChan.h:704
card has no value
std::string getAllWarnings() const
Definition: FitsChan.h:476
std::string getEncoding() const
Definition: FitsChan.h:523
int getCard() const
Definition: FitsChan.h:481
std::string getWarnings() const
Definition: FitsChan.h:567
FitsKeyState
Definition: FitsChan.h:39
void readFits()
Definition: FitsChan.h:640
int getTabOK() const
Definition: FitsChan.h:555
void setEncoding(std::string const &encoding)
Definition: FitsChan.h:923
void showFits() const
Definition: FitsChan.h:974
void setCDMatrix(bool cdMatrix)
Definition: FitsChan.h:903
void setFitsL(std::string const &name, bool value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:825
void setFitsCN(std::string const &name, std::string value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:735
FoundValue()
Default constructor: found false, value is default-constructed.
Definition: FitsChan.h:79
Definition: FitsChan.h:68
void clearCard()
Rewind the card index to the beginning.
Definition: FitsChan.h:1005
card does not exist (card number invalid)
Definition: Stream.h:41
bool getIwc() const
Definition: FitsChan.h:540
int getPolyTan() const
Definition: FitsChan.h:561
int getFitsDigits() const
Definition: FitsChan.h:535