Add support for FITSKeywords

This commit is contained in:
2023-01-26 23:28:09 +01:00
parent 429a54d4c3
commit 14d654a9e3
4 changed files with 39 additions and 11 deletions
+24 -9
View File
@@ -410,6 +410,8 @@ void XISFReader::readImageElement()
{
if(_xml->name() == "Property")
image.properties.push_back(readPropertyElement());
else if(_xml->name() == "FITSKeyword")
image.fitsKeywords.push_back(readFITSKeyword());
else if(_xml->name() == "ICCProfile")
{
DataBlock icc = readDataBlock();
@@ -442,6 +444,15 @@ Property XISFReader::readPropertyElement()
return property;
}
FITSKeyword XISFReader::readFITSKeyword()
{
QXmlStreamAttributes attributes = _xml->attributes();
if(attributes.hasAttribute("name") && attributes.hasAttribute("value") && attributes.hasAttribute("comment"))
return { attributes.value("name").toString(), attributes.value("value").toString(), attributes.value("comment").toString() };
else
throw Error("Invalid FITSKeyword element");
}
void XISFReader::readDataElement(DataBlock &dataBlock)
{
_xml->readNextStartElement();
@@ -552,15 +563,6 @@ void XISFWriter::save(QIODevice &io)
}
}
void XISFWriter::saveXML(const QString &name)
{
QFile fw(name);
fw.open(QIODevice::WriteOnly);
QByteArray header = _xisfHeader.mid(16);
header.truncate(header.indexOf('\0'));
fw.write(header);
}
void XISFWriter::writeImage(const Image &image)
{
_images.push_back(image);
@@ -633,6 +635,9 @@ void XISFWriter::writeImageElement(const Image &image)
for(auto &property : image.properties)
writePropertyElement(property);
for(auto &fitsKeyword : image.fitsKeywords)
writeFITSKeyword(fitsKeyword);
_xml->writeEndElement();
}
@@ -703,6 +708,16 @@ void XISFWriter::writePropertyElement(const Property &property)
throw Error("Failed to write property");
}
void XISFWriter::writeFITSKeyword(const FITSKeyword &keyword)
{
_xml->writeEmptyElement("FITSKeyword");
_xml->writeAttribute("name", keyword.name);
_xml->writeAttribute("value", keyword.value);
_xml->writeAttribute("comment", keyword.comment);
if(_xml->hasError())
throw Error("Failed to write FITS keyword");
}
void XISFWriter::writeMetadata()
{
_xml->writeStartElement("Metadata");