lsst.astshim  18.0.0+3
FitsChan.h
Go to the documentation of this file.
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 
201 class FitsChan : public Channel {
202 public:
213  explicit FitsChan(Stream &stream, std::string const &options = "");
214 
215  virtual ~FitsChan();
216 
217  FitsChan(FitsChan const &) = delete;
218  FitsChan(FitsChan &&) = default;
219  FitsChan &operator=(FitsChan const &) = delete;
220  FitsChan &operator=(FitsChan &&) = default;
221 
229  void delFits() {
230  astDelFits(getRawPtr());
231  assertOK();
232  }
233 
243  void emptyFits() {
244  astEmptyFits(getRawPtr());
245  assertOK();
246  }
247 
345  FoundValue<std::string> findFits(std::string const &name, bool inc);
346 
364  FoundValue<std::complex<double>> getFitsCF(std::string const &name = "",
365  std::complex<double> defval = {0, 0}) const;
366 
386  FoundValue<std::string> getFitsCN(std::string const &name = "", std::string defval = "") const;
387 
405  FoundValue<double> getFitsF(std::string const &name = "", double defval = 0) const;
406 
424  FoundValue<int> getFitsI(std::string const &name = "", int defval = 0) const;
425 
443  FoundValue<bool> getFitsL(std::string const &name = "", bool defval = false) const;
444 
466  FoundValue<std::string> getFitsS(std::string const &name = "", std::string defval = "") const;
467 
474  std::vector<std::string> getAllCardNames();
475 
480  std::string getAllWarnings() const { return getC("AllWarnings"); }
481 
485  int getCard() const { return getI("Card"); }
486 
490  std::string getCardComm() const { return getC("CardComm"); }
491 
495  std::string getCardName() const { return getC("CardName"); }
496 
500  CardType getCardType() const { return static_cast<CardType>(getI("CardType")); }
501 
505  bool getCarLin() const { return getB("CarLin"); }
506 
511  bool getCDMatrix() const { return getB("CDMatrix"); }
512 
516  bool getClean() const { return getB("Clean"); }
517 
521  bool getDefB1950() const { return getB("DefB1950"); }
522 
527  std::string getEncoding() const { return getC("Encoding"); }
528 
533  std::string getFitsAxisOrder() const { return getC("FitsAxisOrder"); }
534 
539  int getFitsDigits() const { return getI("FitsDigits"); }
540 
544  double getFitsTol() const { return getD("FitsTol"); }
545 
549  bool getIwc() const { return getB("Iwc"); }
550 
554  int getNCard() const { return getI("NCard"); }
555 
559  int getNKey() const { return getI("NKey"); }
560 
564  bool getSipOK() const { return getB("SipOK"); }
565 
570  bool getSipReplace() const { return getB("SipReplace"); }
571 
575  int getTabOK() const { return getI("TabOK"); }
576 
581  int getPolyTan() const { return getI("PolyTan"); }
582 
587  std::string getWarnings() const { return getC("Warnings"); }
588 
594  void purgeWcs() {
595  astPurgeWCS(getRawPtr());
596  assertOK();
597  }
598 
615  void putCards(std::string const &cards) {
616  astPutCards(getRawPtr(), cards.c_str());
617  assertOK();
618  }
619 
643  void putFits(std::string const &card, bool overwrite) {
644  astPutFits(getRawPtr(), card.c_str(), overwrite);
645  assertOK();
646  }
647 
660  void readFits() {
661  astReadFits(getRawPtr());
662  assertOK();
663  }
664 
673  void retainFits() {
674  astRetainFits(getRawPtr());
675  assertOK();
676  }
677 
695  void setFitsCF(std::string const &name, std::complex<double> value, std::string const &comment = "",
696  bool overwrite = false) {
697  // this use of reinterpret_cast is explicitly permitted, for C compatibility
698  astSetFitsCF(getRawPtr(), name.c_str(), reinterpret_cast<double(&)[2]>(value), comment.c_str(),
699  overwrite);
700  assertOK();
701  }
702 
724  void setFitsCM(std::string const &comment, bool overwrite = false) {
725  astSetFitsCM(getRawPtr(), comment.c_str(), overwrite);
726  assertOK();
727  }
728 
755  void setFitsCN(std::string const &name, std::string value, std::string const &comment = "",
756  bool overwrite = false) {
757  astSetFitsCN(getRawPtr(), name.c_str(), value.c_str(), comment.c_str(), overwrite);
758  assertOK();
759  }
760 
785  void setFitsF(std::string const &name, double value, std::string const &comment = "",
786  bool overwrite = false) {
787  astSetFitsF(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
788  assertOK();
789  }
790 
815  void setFitsI(std::string const &name, int value, std::string const &comment = "",
816  bool overwrite = false) {
817  astSetFitsI(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
818  assertOK();
819  }
820 
845  void setFitsL(std::string const &name, bool value, std::string const &comment = "",
846  bool overwrite = false) {
847  astSetFitsL(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
848  assertOK();
849  }
850 
883  void setFitsS(std::string const &name, std::string value, std::string const &comment = "",
884  bool overwrite = false) {
885  astSetFitsS(getRawPtr(), name.c_str(), value.c_str(), comment.c_str(), overwrite);
886  assertOK();
887  }
888 
914  void setFitsU(std::string const &name, std::string const &comment = "", bool overwrite = false) {
915  astSetFitsU(getRawPtr(), name.c_str(), comment.c_str(), overwrite);
916  assertOK();
917  }
918 
922  void setCarLin(bool cdMatrix) { setB("CarLin", cdMatrix); }
923 
928  void setCDMatrix(bool cdMatrix) { setB("CDMatrix", cdMatrix); }
929 
933  void setClean(bool clean) { setB("Clean", clean); }
934 
938  void setDefB1950(bool defB1950) { setB("DefB1950", defB1950); }
939 
944  void setEncoding(std::string const &encoding) { setC("Encoding", encoding); }
945 
950  void setFitsAxisOrder(std::string const &order) { setC("FitsAxisOrder", order); }
951 
956  void setFitsDigits(int digits) { setI("FitsDigits", digits); }
957 
961  void setFitsTol(double tol) { return setD("FitsTol", tol); }
962 
966  void setIwc(bool iwcs) { setB("Iwc", iwcs); }
967 
971  void setSipOK(bool sipOK) { setB("SipOK", sipOK); }
972 
977  void setSipReplace(bool replace) { setB("SipReplace", replace); }
978 
982  void setTabOK(int tabOK) { setI("TabOK", tabOK); }
983 
988  void setPolyTan(int polytan) { setI("PolyTan", polytan); }
989 
994  void setWarnings(std::string const &warnings) { setC("Warnings", warnings); }
995 
999  void showFits() const {
1000  astShowFits(getRawPtr());
1001  assertOK();
1002  }
1003 
1019  FitsKeyState testFits(std::string const &name = "") const;
1020 
1024  void writeFits() {
1025  astWriteFits(getRawPtr());
1026  assertOK();
1027  }
1028 
1030  void clearCard() { clear("Card"); }
1031 
1035  void setCard(int ind) { setI("Card", ind); }
1036 };
1037 
1038 } // namespace ast
1039 
1040 #endif
void setFitsTol(double tol)
Definition: FitsChan.h:961
void setIwc(bool iwcs)
Definition: FitsChan.h:966
bool found
Was the value found?
Definition: FitsChan.h:80
std::string getFitsAxisOrder() const
Definition: FitsChan.h:533
complex integer
void emptyFits()
Definition: FitsChan.h:243
FoundValue(bool found, T const &value)
Definition: FitsChan.h:76
void setCarLin(bool cdMatrix)
Definition: FitsChan.h:922
void setDefB1950(bool defB1950)
Definition: FitsChan.h:938
void purgeWcs()
Definition: FitsChan.h:594
complex floating point
double getFitsTol() const
Definition: FitsChan.h:544
AST wrapper classes and functions.
Definition: attributes_channel.dox:1
CardType getCardType() const
Definition: FitsChan.h:500
void setSipReplace(bool replace)
Definition: FitsChan.h:977
void setFitsCF(std::string const &name, std::complex< double > value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:695
void setPolyTan(int polytan)
Definition: FitsChan.h:988
Definition: Channel.h:60
std::string getCardComm() const
Definition: FitsChan.h:490
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:914
std::string getCardName() const
Definition: FitsChan.h:495
int getNCard() const
Definition: FitsChan.h:554
bool getCDMatrix() const
Definition: FitsChan.h:511
Definition: FitsChan.h:201
void retainFits()
Definition: FitsChan.h:673
void setFitsI(std::string const &name, int value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:815
void writeFits()
Definition: FitsChan.h:1024
void setCard(int ind)
Definition: FitsChan.h:1035
void setFitsDigits(int digits)
Definition: FitsChan.h:956
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:982
bool getCarLin() const
Definition: FitsChan.h:505
int getNKey() const
Definition: FitsChan.h:559
keyword is present, but has no value
keyword is not present
bool getClean() const
Definition: FitsChan.h:516
bool getDefB1950() const
Definition: FitsChan.h:521
void putFits(std::string const &card, bool overwrite)
Definition: FitsChan.h:643
void setFitsF(std::string const &name, double value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:785
void setFitsAxisOrder(std::string const &order)
Definition: FitsChan.h:950
void delFits()
Definition: FitsChan.h:229
T value
The found value; ignore if found is false.
Definition: FitsChan.h:81
bool getSipReplace() const
Definition: FitsChan.h:570
void setWarnings(std::string const &warnings)
Definition: FitsChan.h:994
void setClean(bool clean)
Definition: FitsChan.h:933
void setFitsS(std::string const &name, std::string value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:883
void putCards(std::string const &cards)
Definition: FitsChan.h:615
void setFitsCM(std::string const &comment, bool overwrite=false)
Definition: FitsChan.h:724
card has no value
std::string getAllWarnings() const
Definition: FitsChan.h:480
std::string getEncoding() const
Definition: FitsChan.h:527
int getCard() const
Definition: FitsChan.h:485
std::string getWarnings() const
Definition: FitsChan.h:587
FitsKeyState
Definition: FitsChan.h:39
void readFits()
Definition: FitsChan.h:660
int getTabOK() const
Definition: FitsChan.h:575
void setEncoding(std::string const &encoding)
Definition: FitsChan.h:944
void showFits() const
Definition: FitsChan.h:999
void setSipOK(bool sipOK)
Definition: FitsChan.h:971
void setCDMatrix(bool cdMatrix)
Definition: FitsChan.h:928
void setFitsL(std::string const &name, bool value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:845
void setFitsCN(std::string const &name, std::string value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:755
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:1030
card does not exist (card number invalid)
Definition: Stream.h:41
bool getIwc() const
Definition: FitsChan.h:549
bool getSipOK() const
Definition: FitsChan.h:564
int getPolyTan() const
Definition: FitsChan.h:581
int getFitsDigits() const
Definition: FitsChan.h:539