source: trunk/FACT++/src/fitsHacker.cc@ 13414

Last change on this file since 13414 was 12731, checked in by lyard, 13 years ago
changed from FitsHacker to FitsRepair
File size: 2.7 KB
Line 
1/*
2 * fitsHacker.cc
3 *
4 * Created on: Sep 8, 2011
5 * Author: lyard
6 */
7
8#include <fstream>
9#include <cstdlib>
10#include <iostream>
11#include <cstring>
12
13using namespace std;
14/*
15 * Usage: fitsHacker <nameOfFileToHack> <numberOfBytesToSkip> <WhichCharactersToPutAfterShift>(optionnal)
16 *
17 *
18 *
19 */
20
21enum ModeT {seekingHDU,
22 foundHDU,
23 fixedEND,
24 reachedHeaderEnd};
25
26int main(int argc, char** argv)
27{
28 if (argc < 2)
29 return 0;
30
31/* ENDfixer */
32 fstream file(argv[1]);
33
34 char c[81];
35 c[80] = 0;
36 int seeking=0;
37
38 ModeT mode = seekingHDU;
39
40 bool reallyFixedEnd = false;
41 int endAddress = 0;
42
43 while (mode != fixedEND)
44 {
45 file.read(c, 80);
46 if (!file.good()) {
47 cout << 0;
48 return 0;
49 }
50 string str(c);
51// cout << c << endl;
52 if (str.substr(0, 9) == "XTENSION=")
53 mode = foundHDU;
54
55 if (mode == foundHDU && str=="END ")
56 {
57 mode = fixedEND;
58 endAddress = seeking;
59// cout << "found END at " << endAddress << endl;
60 }
61 if (mode == foundHDU && str ==" ")
62 {
63 file.seekp(seeking);
64 file.put('E');
65 file.put('N');
66 file.put('D');
67 mode = fixedEND;
68 reallyFixedEnd = true;
69 endAddress = seeking;
70// cout << "added END at " << endAddress << endl;
71 }
72
73 seeking+=80;
74 }
75
76 file.seekp(seeking-1);
77 while (mode != reachedHeaderEnd)
78 {
79 file.read(c, 80);
80 if (!file.good()) {
81 cout << 0;
82 return 0;
83 }
84 string str(c);
85
86 if (str ==" ")
87 seeking+=80;
88 else
89 mode = reachedHeaderEnd;
90 }
91
92 file.close();
93
94 if (seeking % 2880 != 0)
95 {
96 cout << "Error: header length not acceptable" << endl;
97 return 0;
98 }
99
100 if (((seeking - endAddress)/80) > 35)
101 {
102 cout << "Error: too much header space after END keyword" << endl;
103 return 0;
104 }
105
106 cout << seeking;
107
108 return seeking;
109
110/* FITS HACKER
111 file.get(data, shift);
112
113 for (int i=0;i<shift;i++)
114 {
115 if (i%80 == 0)
116 cout << "||| " << endl;
117 cout << data[i];
118 }
119 cout << endl;
120 if (argc < 4)
121 return 0;
122
123 int length = strlen(argv[3]);
124
125
126 file.seekp(shift-1);
127 for (int i=0;i<length;i++)
128 file.put(argv[3][i]);
129
130 file.close();
131
132 delete[] data;*/
133}
Note: See TracBrowser for help on using the repository browser.