135{
136
137
138 const unsigned short DEFAULT_HEADER[256] {
139
140 0x4543, 0x4c44, 0x5350, 0x2046, 0x494c, 0x4500, 0x0000, 0x0000,
141 0xABCD, 0xffff, 0x0000, 0x0000, 0x0000, 0xABCD, 0xABCD, 0xABCD,
142 0xABCD, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
143 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
144 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
145 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
146 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
147 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
148 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD,
149 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD,
150 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
151 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
152 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
153 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
154 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
155 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
156 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD,
157 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD,
158 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
159 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
160 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
161 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
162 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
163 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
164 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD,
165 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD,
166 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD,
167 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD, 0xABCD,
168 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
169 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
170 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
171 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
172 };
173
174 FILE* fl;
175 fl = fopen(filename, "wb");
176
177 const int nsiz = 2;
178
179 int nsiz1 = 256;
180
181 unsigned short header[256];
182
183 int format_version = data->getExtraData()[0];
184 if (format_version > ECLDSP_FORMAT_VERSION) {
185 B2WARNING("Format version " << format_version << " is not fully supported, some data might be discarded.");
186 }
187
188 for (int i = 0; i < 256; i++) {
189 if (i == 8) {
190 header[i] = (data->getverMin() << 8) | data->getverMaj();
191 } else if (i == 13) {
192 header[i] = (data->getkb() << 8) | data->getka();
193 } else if (i == 14) {
194 header[i] = (data->gety0Startr() << 8) | data->getkc();
195 } else if (i == 15) {
196 header[i] = data->getchiThresh();
197 } else if (i == 16) {
198 header[i] = (data->getk2() << 8) | data->getk1();
199 } else if (i >= 64 && i < 80) {
200 header[i] = data->gethT();
201 } else if (i >= 128 && i < 144) {
202 header[i] = data->getlAT();
203 } else if (i >= 192 && i < 208) {
204 header[i] = data->getsT();
205 } else if (i >= 208 && i < 224) {
206 header[i] = data->getaAT();
207 } else {
208
209 int high = (DEFAULT_HEADER[i] & 0xFF00) >> 8;
210 int low = (DEFAULT_HEADER[i] & 0x00FF);
211 header[i] = (low << 8) + high;
212 }
213 }
214
215 int size = fwrite(header, nsiz, nsiz1, fl);
216 if (size != nsiz1) {
217 B2FATAL("Error writing header of DSP file " << filename);
218 }
219
220 std::vector<short int> f(49152), f1(49152), f31(49152),
221 f32(49152), f33(49152), f41(6144), f43(6144);
222 data->getF41(f41);
223 data->getF31(f31);
224 data->getF32(f32);
225 data->getF33(f33);
226 data->getF43(f43);
227 data->getF(f);
228 data->getF1(f1);
229
230 for (int i = 0; i < 16; ++i) {
231 nsiz1 = 384;
232 fwrite(&(*(f41.begin() + i * nsiz1)), nsiz, nsiz1, fl);
233 nsiz1 = 3072;
234 fwrite(&(*(f31.begin() + i * nsiz1)), nsiz, nsiz1, fl);
235 fwrite(&(*(f32.begin() + i * nsiz1)), nsiz, nsiz1, fl);
236 fwrite(&(*(f33.begin() + i * nsiz1)), nsiz, nsiz1, fl);
237 nsiz1 = 384;
238 fwrite(&(*(f43.begin() + i * nsiz1)), nsiz, nsiz1, fl);
239 nsiz1 = 3072;
240 fwrite(&(*(f.begin() + i * nsiz1)), nsiz, nsiz1, fl);
241 fwrite(&(*(f1.begin() + i * nsiz1)), nsiz, nsiz1, fl);
242 }
243 fclose(fl);
244}