lsst.astshim  14.0-8-g6380fcc
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 
198 class FitsChan : public Channel {
199 public:
210  explicit FitsChan(Stream &stream, std::string const &options = "");
211 
212  virtual ~FitsChan();
213 
214  FitsChan(FitsChan const &) = delete;
215  FitsChan(FitsChan &&) = default;
216  FitsChan &operator=(FitsChan const &) = delete;
217  FitsChan &operator=(FitsChan &&) = default;
218 
226  void delFits() {
227  astDelFits(getRawPtr());
228  assertOK();
229  }
230 
240  void emptyFits() {
241  astEmptyFits(getRawPtr());
242  assertOK();
243  }
244 
342  FoundValue<std::string> findFits(std::string const &name, bool inc);
343 
361  FoundValue<std::complex<double>> getFitsCF(std::string const &name = "",
362  std::complex<double> defval = {0, 0}) const;
363 
383  FoundValue<std::string> getFitsCN(std::string const &name = "", std::string defval = "") const;
384 
402  FoundValue<double> getFitsF(std::string const &name = "", double defval = 0) const;
403 
421  FoundValue<int> getFitsI(std::string const &name = "", int defval = 0) const;
422 
440  FoundValue<bool> getFitsL(std::string const &name = "", bool defval = false) const;
441 
463  FoundValue<std::string> getFitsS(std::string const &name = "", std::string defval = "") const;
464 
471  std::vector<std::string> getAllCardNames();
472 
477  std::string getAllWarnings() const { return getC("AllWarnings"); }
478 
482  int getCard() const { return getI("Card"); }
483 
487  std::string getCardComm() const { return getC("CardComm"); }
488 
492  std::string getCardName() const { return getC("CardName"); }
493 
497  CardType getCardType() const { return static_cast<CardType>(getI("CardType")); }
498 
502  bool getCarLin() const { return getB("CarLin"); }
503 
508  bool getCDMatrix() const { return getB("CDMatrix"); }
509 
513  bool getClean() const { return getB("Clean"); }
514 
518  bool getDefB1950() const { return getB("DefB1950"); }
519 
524  std::string getEncoding() const { return getC("Encoding"); }
525 
530  std::string getFitsAxisOrder() const { return getC("FitsAxisOrder"); }
531 
536  int getFitsDigits() const { return getI("FitsDigits"); }
537 
541  double getFitsTol() const { return getD("FitsTol"); }
542 
546  bool getIwc() const { return getB("Iwc"); }
547 
551  int getNCard() const { return getI("NCard"); }
552 
556  int getNKey() const { return getI("NKey"); }
557 
561  int getTabOK() const { return getI("TabOK"); }
562 
567  int getPolyTan() const { return getI("PolyTan"); }
568 
573  std::string getWarnings() const { return getC("Warnings"); }
574 
580  void purgeWcs() {
581  astPurgeWCS(getRawPtr());
582  assertOK();
583  }
584 
601  void putCards(std::string const &cards) {
602  astPutCards(getRawPtr(), cards.c_str());
603  assertOK();
604  }
605 
629  void putFits(std::string const &card, bool overwrite) {
630  astPutFits(getRawPtr(), card.c_str(), overwrite);
631  assertOK();
632  }
633 
646  void readFits() {
647  astReadFits(getRawPtr());
648  assertOK();
649  }
650 
659  void retainFits() {
660  astRetainFits(getRawPtr());
661  assertOK();
662  }
663 
681  void setFitsCF(std::string const &name, std::complex<double> value, std::string const &comment = "",
682  bool overwrite = false) {
683  // this use of reinterpret_cast is explicitly permitted, for C compatibility
684  astSetFitsCF(getRawPtr(), name.c_str(), reinterpret_cast<double(&)[2]>(value), comment.c_str(),
685  overwrite);
686  assertOK();
687  }
688 
710  void setFitsCM(std::string const &comment, bool overwrite = false) {
711  astSetFitsCM(getRawPtr(), comment.c_str(), overwrite);
712  assertOK();
713  }
714 
741  void setFitsCN(std::string const &name, std::string value, std::string const &comment = "",
742  bool overwrite = false) {
743  astSetFitsCN(getRawPtr(), name.c_str(), value.c_str(), comment.c_str(), overwrite);
744  assertOK();
745  }
746 
771  void setFitsF(std::string const &name, double value, std::string const &comment = "",
772  bool overwrite = false) {
773  astSetFitsF(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
774  assertOK();
775  }
776 
801  void setFitsI(std::string const &name, int value, std::string const &comment = "",
802  bool overwrite = false) {
803  astSetFitsI(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
804  assertOK();
805  }
806 
831  void setFitsL(std::string const &name, bool value, std::string const &comment = "",
832  bool overwrite = false) {
833  astSetFitsL(getRawPtr(), name.c_str(), value, comment.c_str(), overwrite);
834  assertOK();
835  }
836 
869  void setFitsS(std::string const &name, std::string value, std::string const &comment = "",
870  bool overwrite = false) {
871  astSetFitsS(getRawPtr(), name.c_str(), value.c_str(), comment.c_str(), overwrite);
872  assertOK();
873  }
874 
900  void setFitsU(std::string const &name, std::string const &comment = "", bool overwrite = false) {
901  astSetFitsU(getRawPtr(), name.c_str(), comment.c_str(), overwrite);
902  assertOK();
903  }
904 
909  void setCDMatrix(bool cdMatrix) { setB("CDMatrix", cdMatrix); }
910 
916  void setClean(bool clean) { setB("Clean", clean); }
917 
923  void setDefB1950(bool defB1950) { setB("DefB1950", defB1950); }
924 
929  void setEncoding(std::string const &encoding) { setC("Encoding", encoding); }
930 
937  void setFitsAxisOrder(std::string const &order) { setC("FitsAxisOrder", order); }
938 
945  void setFitsDigits(int digits) { setI("FitsDigits", digits); }
946 
950  void setFitsTol(double tol) { return setD("FitsTol", tol); }
951 
957  void setIwc(bool iwcs) { setB("Iwc", iwcs); }
958 
964  void setTabOK(int tabOK) { setI("TabOK", tabOK); }
965 
972  void setPolyTan(int polytan) { setI("PolyTan", polytan); }
973 
980  void setWarnings(std::string const &warnings) { setC("Warnings", warnings); }
981 
985  void showFits() const {
986  astShowFits(getRawPtr());
987  assertOK();
988  }
989 
1005  FitsKeyState testFits(std::string const &name = "") const;
1006 
1010  void writeFits() {
1011  astWriteFits(getRawPtr());
1012  assertOK();
1013  }
1014 
1016  void clearCard() { clear("Card"); }
1017 
1021  void setCard(int ind) { setI("Card", ind); }
1022 };
1023 
1024 } // namespace ast
1025 
1026 #endif
void setFitsTol(double tol)
Definition: FitsChan.h:950
void setIwc(bool iwcs)
Definition: FitsChan.h:957
bool found
Was the value found?
Definition: FitsChan.h:80
std::string getFitsAxisOrder() const
Definition: FitsChan.h:530
complex integer
void emptyFits()
Definition: FitsChan.h:240
FoundValue(bool found, T const &value)
Definition: FitsChan.h:76
void setDefB1950(bool defB1950)
Definition: FitsChan.h:923
void purgeWcs()
Definition: FitsChan.h:580
complex floating point
double getFitsTol() const
Definition: FitsChan.h:541
AST wrapper classes and functions.
Definition: attributes_channel.dox:1
CardType getCardType() const
Definition: FitsChan.h:497
void setFitsCF(std::string const &name, std::complex< double > value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:681
void setPolyTan(int polytan)
Definition: FitsChan.h:972
Definition: Channel.h:60
std::string getCardComm() const
Definition: FitsChan.h:487
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:900
std::string getCardName() const
Definition: FitsChan.h:492
int getNCard() const
Definition: FitsChan.h:551
bool getCDMatrix() const
Definition: FitsChan.h:508
Definition: FitsChan.h:198
void retainFits()
Definition: FitsChan.h:659
void setFitsI(std::string const &name, int value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:801
void writeFits()
Definition: FitsChan.h:1010
void setCard(int ind)
Definition: FitsChan.h:1021
void setFitsDigits(int digits)
Definition: FitsChan.h:945
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:964
bool getCarLin() const
Definition: FitsChan.h:502
int getNKey() const
Definition: FitsChan.h:556
keyword is present, but has no value
keyword is not present
bool getClean() const
Definition: FitsChan.h:513
bool getDefB1950() const
Definition: FitsChan.h:518
void putFits(std::string const &card, bool overwrite)
Definition: FitsChan.h:629
void setFitsF(std::string const &name, double value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:771
void setFitsAxisOrder(std::string const &order)
Definition: FitsChan.h:937
void delFits()
Definition: FitsChan.h:226
T value
The found value; ignore if found is false.
Definition: FitsChan.h:81
void setWarnings(std::string const &warnings)
Definition: FitsChan.h:980
void setClean(bool clean)
Definition: FitsChan.h:916
void setFitsS(std::string const &name, std::string value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:869
void putCards(std::string const &cards)
Definition: FitsChan.h:601
void setFitsCM(std::string const &comment, bool overwrite=false)
Definition: FitsChan.h:710
card has no value
std::string getAllWarnings() const
Definition: FitsChan.h:477
std::string getEncoding() const
Definition: FitsChan.h:524
int getCard() const
Definition: FitsChan.h:482
std::string getWarnings() const
Definition: FitsChan.h:573
FitsKeyState
Definition: FitsChan.h:39
void readFits()
Definition: FitsChan.h:646
int getTabOK() const
Definition: FitsChan.h:561
void setEncoding(std::string const &encoding)
Definition: FitsChan.h:929
void showFits() const
Definition: FitsChan.h:985
void setCDMatrix(bool cdMatrix)
Definition: FitsChan.h:909
void setFitsL(std::string const &name, bool value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:831
void setFitsCN(std::string const &name, std::string value, std::string const &comment="", bool overwrite=false)
Definition: FitsChan.h:741
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:1016
card does not exist (card number invalid)
Definition: Stream.h:41
bool getIwc() const
Definition: FitsChan.h:546
int getPolyTan() const
Definition: FitsChan.h:567
int getFitsDigits() const
Definition: FitsChan.h:536