53 lines
1.4 KiB
Plaintext
53 lines
1.4 KiB
Plaintext
core.log("Script to modify FITS header in FITS and XISF files");
|
|
|
|
function checkFITS(key)
|
|
{
|
|
const noEditableKey = ["SIMPLE", "BITPIX", "NAXIS", "NAXIS1", "NAXIS2", "NAXIS3", "EXTEND", "BZERO", "BSCALE"];
|
|
return noEditableKey.indexOf(key) < 0;
|
|
}
|
|
|
|
if(files.length == 0)
|
|
{
|
|
core.log("No input files");
|
|
throw "";
|
|
}
|
|
|
|
let action = core.getItem(["UPDATE", "ADD", "REMOVE"], "Do you want update, add or remove record?");
|
|
|
|
let modify = new FITSRecordModify();
|
|
|
|
if(action == "UPDATE")
|
|
{
|
|
let keywords = files[0].fitsKeywords().filter(checkFITS);
|
|
let keyword = core.getItem(keywords, "Select keyword to update");
|
|
let value = files[0].fitsValue(keyword);
|
|
if(isNaN(value))
|
|
value = core.getString("Enter new value", value);
|
|
else
|
|
value = core.getFloat("Enter new value", value);
|
|
modify.updateKeyword(keyword, value);
|
|
}
|
|
else if(action == "ADD")
|
|
{
|
|
let keyword = core.getString("Enter keyword to add");
|
|
let value = core.getString("Enter new value");
|
|
keyword = keyword.toUpperCase();
|
|
modify.addKeyword(keyword, value);
|
|
}
|
|
else if(action == "REMOVE")
|
|
{
|
|
let keywords = files[0].fitsKeywords().filter(checkFITS);
|
|
let keyword = core.getItem(keywords, "Select keyword to remove");
|
|
modify.removeKeyword(keyword);
|
|
}
|
|
|
|
for(file of files)
|
|
{
|
|
if(file.suffix() == "fits" || file.suffix() == "fit" || file.suffix() == "xisf")
|
|
{
|
|
core.log("Modifing " + file.fileName());
|
|
file.modifyFITSRecords(modify);
|
|
}
|
|
}
|
|
|