lsst.astshim  14.0-10-ga7aaa25+2
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 
200 class FitsChan : public Channel {
201 public:
212  explicit FitsChan(Stream &stream, std::string const &options = "");
213 
214  virtual ~FitsChan();
215 
216  FitsChan(FitsChan const &) = delete;
217  FitsChan(FitsChan &&) = default;
218  FitsChan &operator=(FitsChan const &) = delete;
219  FitsChan &operator=(FitsChan &&) = default;
220 
228  void delFits() {
229  astDelFits(getRawPtr());
230  assertOK();
231  }
232 
242  void emptyFits() {
243  astEmptyFits(getRawPtr());
244  assertOK();
245  }
246 
344  FoundValue<std::string> findFits(std::string const &name, bool inc);
345 
363  FoundValue<std::complex<double>> getFitsCF(std::string const &name = "",
364  std::complex<double> defval = {0, 0}) const;
365 
385  FoundValue<std::string> getFitsCN(std::string const &name = "", std::string defval = "") const;
386 
404  FoundValue<double> getFitsF(std::string const &name = "", double defval = 0) const;
405 
423  FoundValue<int> getFitsI(std::string const &name = "", int defval = 0) const;
424 
442  FoundValue<bool> getFitsL(std::string const &name = "", bool defval = false) const;
443 
465  FoundValue<std::string> getFitsS(std::string const &name = "", std::string defval = "") const;
466 
473  std::vector<std::string> getAllCardNames();
474 
479  std::string getAllWarnings() const { return getC("AllWarnings"); }
480 
484  int getCard() const { return getI("Card"); }
485 
489  std::string getCardComm() const { return getC("CardComm"); }
490 
494  std::string getCardName() const { return getC("CardName"); }
495 
499  CardType getCardType() const { return static_cast<CardType>(getI("CardType")); }
500 
504  bool getCarLin() const { return getB("CarLin"); }
505 
510  bool getCDMatrix() const { return getB("CDMatrix"); }
511 
515  bool getClean() const { return getB("Clean"); }
516 
520  bool getDefB1950() const { return getB("DefB1950"); }
521 
526  std::string getEncoding() const { return getC("Encoding"); }
527 
532  std::string getFitsAxisOrder() const { return getC("FitsAxisOrder"); }
533 
538  int getFitsDigits() const { return getI("FitsDigits"); }
539 
543  double getFitsTol() const { return getD("FitsTol"); }
544 
548  bool getIwc() const { return getB("Iwc"); }
549 
553  int getNCard() const { return getI("NCard"); }
554 
558  int getNKey() const { return getI("NKey"); }
559 
564  bool getSipReplace() const { return getB("SipReplace"); }
565 
569  int getTabOK() const { return getI("TabOK"); }
570 
575  int getPolyTan() const { return getI("PolyTan"); }
576 
581  std::string getWarnings() const { return getC("Warnings"); }
582 
588  void purgeWcs() {
589  astPurgeWCS(getRawPtr());
590  assertOK();
591  }
592 
609  void putCards(std::string const &cards) {
610  astPutCards(getRawPtr(), cards.c_str());
611  assertOK();
612  }
613 
637  void putFits(std::string const &card, bool overwrite) {
638  astPutFits(getRawPtr(), card.c_str(), overwrite);
639  assertOK();
640  }
641 
654  void readFits() {
655  astReadFits(getRawPtr());
656  assertOK();
657  }
658 
667  void retainFits() {
668  astRetainFits(getRawPtr());
669  assertOK();
670  }
671 
689  void setFitsCF(std::string const &name, std::complex<double> value, std::string const &comment = "",
690  bool overwrite = false) {
691  // this use of reinterpret_cast is explicitly permitted, for C compatibility
692  astSetFitsCF(getRawPtr(), name.c_str(), reinterpret_cast<double(&)[2]>(value), comment.c_str(),
693  overwrite);
694  assertOK();
695  }
696 
718  void setFitsCM(std::string const &comment, bool overwrite = false) {
719  astSetFitsCM(getRawPtr(), comment.c_str(), overwrite);
720  assertOK();
721  }
722 
749  void setFitsCN(std::string const &name, std::string value, std::string const &comment = "",
750  bool overwrite = false) {
751  astSetFitsCN(getRawPtr(), name.c_str(), value.c_str(), comment.c_str(), overwrite);
752  assertOK();
753  }
754 
779  void setFitsF(std::string const &name, double value, std::string const &comment = "",
780  bool overwrite = false) {
781  astSetFitsF(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
782  assertOK();
783  }
784 
809  void setFitsI(std::string const &name, int value, std::string const &comment = "",
810  bool overwrite = false) {
811  astSetFitsI(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
812  assertOK();
813  }
814 
839  void setFitsL(std::string const &name, bool value, std::string const &comment = "",
840  bool overwrite = false) {
841  astSetFitsL(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
842  assertOK();
843  }
844 
877  void setFitsS(std::string const &name, std::string value, std::string const &comment = "",
878  bool overwrite = false) {
879  astSetFitsS(getRawPtr(), name.c_str(), value.c_str(), comment.c_str(), overwrite);
880  assertOK();
881  }
882 
908  void setFitsU(std::string const &name, std::string const &comment = "", bool overwrite = false) {
909  astSetFitsU(getRawPtr(), name.c_str(), comment.c_str(), overwrite);
910  assertOK();
911  }
912 
916  void setCarLin(bool cdMatrix) { setB("CarLin", cdMatrix); }
917 
922  void setCDMatrix(bool cdMatrix) { setB("CDMatrix", cdMatrix); }
923 
927  void setClean(bool clean) { setB("Clean", clean); }
928 
932  void setDefB1950(bool defB1950) { setB("DefB1950", defB1950); }
933 
938  void setEncoding(std::string const &encoding) { setC("Encoding", encoding); }
939 
944  void setFitsAxisOrder(std::string const &order) { setC("FitsAxisOrder", order); }
945 
950  void setFitsDigits(int digits) { setI("FitsDigits", digits); }
951 
955  void setFitsTol(double tol) { return setD("FitsTol", tol); }
956 
960  void setIwc(bool iwcs) { setB("Iwc", iwcs); }
961 
966  void setSipReplace(bool replace) { setB("SipReplace", replace); }
967 
971  void setTabOK(int tabOK) { setI("TabOK", tabOK); }
972 
977  void setPolyTan(int polytan) { setI("PolyTan", polytan); }
978 
983  void setWarnings(std::string const &warnings) { setC("Warnings", warnings); }
984 
988  void showFits() const {
989  astShowFits(getRawPtr());
990  assertOK();
991  }
992 
1008  FitsKeyState testFits(std::string const &name = "") const;
1009 
1013  void writeFits() {
1014  astWriteFits(getRawPtr());
1015  assertOK();
1016  }
1017 
1019  void clearCard() { clear("Card"); }
1020 
1024  void setCard(int ind) { setI("Card", ind); }
1025 };
1026 
1027 } // namespace ast
1028 
1029 #endif
void setFitsTol(double tol)
Definition: FitsChan.h:955
void setIwc(bool iwcs)
Definition: FitsChan.h:960
bool found
Was the value found?
Definition: FitsChan.h:80
std::string getFitsAxisOrder() const
Definition: FitsChan.h:532
complex integer
void emptyFits()
Definition: FitsChan.h:242
FoundValue(bool found, T const &value)
Definition: FitsChan.h:76
void setCarLin(bool cdMatrix)
Definition: FitsChan.h:916
void setDefB1950(bool defB1950)
Definition: FitsChan.h:932
void purgeWcs()
Definition: FitsChan.h:588
complex floating point
double getFitsTol() const
Definition: FitsChan.h:543
AST wrapper classes and functions.
Definition: attributes_channel.dox:1
CardType getCardType() const
Definition: FitsChan.h:499
void setSipReplace(bool replace)
Definition: FitsChan.h:966
void setFitsCF(std::string const &name, std::complex< double > value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:689
void setPolyTan(int polytan)
Definition: FitsChan.h:977
Definition: Channel.h:60
std::string getCardComm() const
Definition: FitsChan.h:489
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:908
std::string getCardName() const
Definition: FitsChan.h:494
int getNCard() const
Definition: FitsChan.h:553
bool getCDMatrix() const
Definition: FitsChan.h:510
Definition: FitsChan.h:200
void retainFits()
Definition: FitsChan.h:667
void setFitsI(std::string const &name, int value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:809
void writeFits()
Definition: FitsChan.h:1013
void setCard(int ind)
Definition: FitsChan.h:1024
void setFitsDigits(int digits)
Definition: FitsChan.h:950
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:971
bool getCarLin() const
Definition: FitsChan.h:504
int getNKey() const
Definition: FitsChan.h:558
keyword is present, but has no value
keyword is not present
bool getClean() const
Definition: FitsChan.h:515
bool getDefB1950() const
Definition: FitsChan.h:520
void putFits(std::string const &card, bool overwrite)
Definition: FitsChan.h:637
void setFitsF(std::string const &name, double value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:779
void setFitsAxisOrder(std::string const &order)
Definition: FitsChan.h:944
void delFits()
Definition: FitsChan.h:228
T value
The found value; ignore if found is false.
Definition: FitsChan.h:81
bool getSipReplace() const
Definition: FitsChan.h:564
void setWarnings(std::string const &warnings)
Definition: FitsChan.h:983
void setClean(bool clean)
Definition: FitsChan.h:927
void setFitsS(std::string const &name, std::string value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:877
void putCards(std::string const &cards)
Definition: FitsChan.h:609
void setFitsCM(std::string const &comment, bool overwrite=false)
Definition: FitsChan.h:718
card has no value
std::string getAllWarnings() const
Definition: FitsChan.h:479
std::string getEncoding() const
Definition: FitsChan.h:526
int getCard() const
Definition: FitsChan.h:484
std::string getWarnings() const
Definition: FitsChan.h:581
FitsKeyState
Definition: FitsChan.h:39
void readFits()
Definition: FitsChan.h:654
int getTabOK() const
Definition: FitsChan.h:569
void setEncoding(std::string const &encoding)
Definition: FitsChan.h:938
void showFits() const
Definition: FitsChan.h:988
void setCDMatrix(bool cdMatrix)
Definition: FitsChan.h:922
void setFitsL(std::string const &name, bool value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:839
void setFitsCN(std::string const &name, std::string value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:749
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:1019
card does not exist (card number invalid)
Definition: Stream.h:41
bool getIwc() const
Definition: FitsChan.h:548
int getPolyTan() const
Definition: FitsChan.h:575
int getFitsDigits() const
Definition: FitsChan.h:538