forked from gmcgarragh/seviri_util
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_write_nat.c
729 lines (565 loc) · 24.3 KB
/
read_write_nat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
/*******************************************************************************
*
* Copyright (C) 2014-2018 Greg McGarragh <[email protected]>
*
* This source code is licensed under the GNU General Public License (GPL),
* Version 3. See the file COPYING for more details.
*
******************************************************************************/
#include "external.h"
#include "hrit_anc_funcs.h"
#include "internal.h"
#include "read_write.h"
#include "read_write_nat.h"
/*******************************************************************************
* Read a VIS/IR line record structure - the actual image data.
*
* fp : Pointer to the image data file set to the beginning of the
* : line record structure.
* image : The output seviri_image_data struct with the image data
* marf_header : The seviri_marf_header_data struct for the current image data
* file.
* n_bands : Described in the seviri_read_nat() header
* band_ids : ''
* bounds : ''
* line0 : ''
* line1 : ''
* column0 : ''
* column1 : ''
* lat0 : ''
* lat1 : ''
* lon0 : ''
* lon1 : ''
* aux : Seviri_auxillary_io_data struct containing information related
* to the read operation
*
* returns : Non-zero on error
******************************************************************************/
static int seviri_image_read(FILE *fp, struct seviri_image_data *image,
const struct seviri_marf_header_data *marf_header,
uint n_bands, const uint *band_ids,
enum seviri_bounds bounds,
uint line0, uint line1, uint column0, uint column1,
double lat0, double lat1, double lon0, double lon1,
struct seviri_auxillary_io_data *aux)
{
uchar *data10 = '\0';
const uchar shifts[] = {6, 4, 2, 0};
ushort temp=0;
const ushort masks[] = {0xFFC0, 0x3FF0, 0x0FFC, 0x03FF};
uint i;
uint ii;
uint iii;
uint j;
uint jj;
uint jjj;
uint k;
uint length;
uint i_band;
uint i_image;
uint n_bands_VIR;
uint n_bands_HRV;
uint n_bytes_VIR_line;
uint n_bytes_HRV_line;
uint n_bytes_line_group;
uint j_offset;
uint i_column0;
uint i_column1;
uint i_alignment0;
uint i_alignment1;
uint n_loop0;
uint n_loop1;
long file_start;
long file_offset;
long file_offset2;
struct seviri_dimension_data *dimens;
int i_bands_infile[12];
/*-------------------------------------------------------------------------
* Check if the requested band IDs are valid.
*-----------------------------------------------------------------------*/
image->n_bands = n_bands;
for (i = 0; i < n_bands; ++i) {
if (band_ids[i] < 1 || band_ids[i] > SEVIRI_N_BANDS) {
fprintf(stderr, "ERROR: Invalid SEVIRI band Id at band list "
"element %d: %d\n", i, band_ids[i]);
return -1;
}
image->band_ids[i] = band_ids[i];
}
/* Check that the caller is not expecting HRV data. */
for (i = 0; i < n_bands; ++i) {
if (band_ids[i] == 12) {
fprintf(stderr, "ERROR: Reading of the HRV channel is not yet "
"fully supported\n");
return -1;
}
}
/*-------------------------------------------------------------------------
* Count the number VIR and HRV bands in the file.
*-----------------------------------------------------------------------*/
n_bands_VIR = 0;
for (i = 0; i < 11; ++i) {
if (marf_header->secondary.SelectedBandIDs.Value[i] == 'X') {
n_bands_VIR++;
}
}
n_bands_HRV = 0;
if (marf_header->secondary.SelectedBandIDs.Value[11] == 'X')
n_bands_HRV = 1;
/*-------------------------------------------------------------------------
*
*-----------------------------------------------------------------------*/
ii = 0;
for (i = 0; i < n_bands; ++i) {
if (marf_header->secondary.SelectedBandIDs.Value[band_ids[i] - 1] == 'X') {
iii = -1;
for (ii = 0; ii < band_ids[i]; ++ii) {
if (marf_header->secondary.SelectedBandIDs.Value[ii] == 'X')
iii++;
}
i_bands_infile[i] = iii;
}
else
i_bands_infile[i] = -1;
}
/*-------------------------------------------------------------------------
* Allocate and fill in the seviri_dimension_data struct.
*-----------------------------------------------------------------------*/
dimens = (struct seviri_dimension_data *) &image->dimens;
if (seviri_get_dimension_data(dimens, marf_header, bounds, line0, line1,
column0, column1, lat0, lat1, lon0, lon1, 0)) {
fprintf(stderr, "ERROR: seviri_get_dimension_data()\n");
return -1;
}
/*-------------------------------------------------------------------------
* Quantities useful for moving around in the file.
*-----------------------------------------------------------------------*/
n_bytes_VIR_line = PACKET_HEADER_SIZE + LINE_SIDE_INFO_SIZE +
dimens->n_columns_selected_VIR / 4 * 5;
n_bytes_HRV_line = PACKET_HEADER_SIZE + LINE_SIDE_INFO_SIZE +
dimens->n_columns_selected_HRV / 4 * 5 / 2;
n_bytes_line_group = n_bands_VIR * n_bytes_VIR_line +
n_bands_HRV * 3 * n_bytes_HRV_line;
/*-------------------------------------------------------------------------
* Image offsets and dimensions and the fill_value for the caller.
*-----------------------------------------------------------------------*/
image->i_line = dimens->i_line_requested_VIR;
image->i_column = dimens->i_column_requested_VIR;
image->n_lines = dimens->n_lines_requested_VIR;
image->n_columns = dimens->n_columns_requested_VIR;
image->fill_value = FILL_VALUE_US;
/*-------------------------------------------------------------------------
* Allocate memory to hold structure fields.
*-----------------------------------------------------------------------*/
image->packet_header = malloc(image->n_bands *
sizeof(struct seviri_packet_header_data *));
for (i = 0; i < image->n_bands; ++i)
image->packet_header[i] = malloc(dimens->n_lines_requested_VIR *
sizeof(struct seviri_packet_header_data));
image->LineSideInfo = malloc(image->n_bands *
sizeof(struct seviri_LineSideInfo_data *));
for (i = 0; i < image->n_bands; ++i)
image->LineSideInfo[i] = malloc(dimens->n_lines_requested_VIR *
sizeof(struct seviri_LineSideInfo_data ));
length = dimens->n_lines_requested_VIR * dimens->n_columns_requested_VIR;
image->data_vir = malloc(image->n_bands * sizeof(ushort *));
for (i = 0; i < image->n_bands; ++i) {
image->data_vir[i] = malloc(length * sizeof(float));
su_init_array_us(image->data_vir[i], length, image->fill_value);
}
/*-------------------------------------------------------------------------
* Read the image data.
*-----------------------------------------------------------------------*/
data10 = malloc(dimens->n_columns_selected_VIR / 4 * 5 * sizeof(uchar));
file_start = ftell(fp);
file_offset = file_start + dimens->i_line_to_read_VIR * n_bytes_line_group;
/* Considerable effort is gone into dealing with starting columns and
ending columns that are not aligned on 4 pixel/5 byte boundaries. Below
are quantities used for this effort. */
/* Quantities for approach 1 which simply checks every pixel to see if they
are in the requested image area. Simple but has an if statement within
the inner loop. */
j_offset = dimens->i0_column_selected_VIR + dimens->i_column_to_read_VIR;
i_column0 = dimens->i_column_requested_VIR;
i_column1 = dimens->i_column_requested_VIR + dimens->n_columns_requested_VIR - 1;
/* Quantities for approach 2 which only loops over the pixels required.
more complicated but more efficient. */
if (dimens->i_column_requested_VIR > dimens->i0_column_selected_VIR)
i_alignment0 = (dimens->i_column_requested_VIR -
dimens->i0_column_selected_VIR) % 4;
else
i_alignment0 = 0;
if (dimens->i_column_requested_VIR + dimens->n_columns_requested_VIR - 1 <
dimens->i1_column_selected_VIR)
i_alignment1 = (dimens->i_column_requested_VIR +
dimens->n_columns_requested_VIR - 1 -
dimens->i0_column_selected_VIR) % 4;
else
i_alignment1 = (dimens->n_columns_selected_VIR - 1) % 4;
n_loop0 = dimens->n_columns_to_read_VIR -
k - (i_alignment1 == 3 ? 0 : 4);
n_loop1 = i_alignment1 < 3 ? i_alignment1 + 1 : 0;
for (i = 0; i < dimens->n_lines_to_read_VIR; ++i) {
ii = dimens->i_line_in_output_VIR + i;
for (i_band = 0; i_band < image->n_bands; ++i_band) {
if (i_bands_infile[i_band] < 0)
continue;
file_offset2 = file_offset + i_bands_infile[i_band] *
n_bytes_VIR_line + dimens->i_column_to_read_VIR / 4 * 5;
fseek(fp, file_offset2, SEEK_SET);
if (seviri_packet_header_read(fp, &image->packet_header[i_band][i], aux)) {
fprintf(stderr, "ERROR: seviri_packet_header_read()\n");
return -1;
}
if (seviri_LineSideInfo_read(fp, &image->LineSideInfo [i_band][i], aux)) {
fprintf(stderr, "ERROR: seviri_LineSideInfo_read()\n");
return -1;
}
if (fread(data10, sizeof(char), dimens->n_columns_to_read_VIR / 4 * 5, fp) <
dimens->n_columns_to_read_VIR / 4 * 5) E_L_R();
i_image = ii * dimens->n_columns_requested_VIR + dimens->i_column_in_output_VIR;
if (0) {
for (j = 0, jj = 0, jjj = 0; j < dimens->n_columns_to_read_VIR; ) {
for (k = 0; k < 4; ++k) {
if (j_offset + j >= i_column0 && j_offset + j <= i_column1) {
temp = *((ushort *) (data10 + jj));
SWAP_2(temp, temp);
image->data_vir[i_band][i_image + jjj] = (temp & masks[k]) >> shifts[k];
jjj++;
}
j++, jj++;
}
jj++;
}
}
else {
jj = k = i_alignment0;
for (j = 0, jjj = 0; j < n_loop0; ) {
for ( ; k < 4; ++k) {
temp = *((ushort *) (data10 + jj));
SWAP_2(temp, temp);
image->data_vir[i_band][i_image + jjj] = (temp & masks[k]) >> shifts[k];
j++, jj++; jjj++;
}
jj++; k = 0;
}
for (k = 0; k < n_loop1; ++k) {
temp = *((ushort *) (data10 + jj));
SWAP_2(temp, temp);
image->data_vir[i_band][i_image + jjj] = (temp & masks[k]) >> shifts[k];
jj++; jjj++;
}
}
}
file_offset += n_bytes_line_group;
}
file_offset = file_start + dimens->n_lines_selected_VIR * n_bytes_line_group;
fseek(fp, file_offset, SEEK_SET);
free(data10);
return 0;
}
/*******************************************************************************
* Write a VIS/IR line record structure - the actual image data.
*
* fp : File pointer to where the line record structure is to be
* written.
* image : The input seviri_image_data struct
* aux : Seviri_auxillary_io_data struct containing information related
* to the read operation
*
* returns : Non-zero on error
*
******************************************************************************/
static int seviri_image_write(FILE *fp, const struct seviri_image_data *image,
struct seviri_auxillary_io_data *aux)
{
uchar *data10;
const uchar shifts[] = {6, 4, 2, 0};
ushort temp;
uint i;
uint ii;
uint j;
uint jj;
uint k;
uint i_band;
uint i_image;
const struct seviri_dimension_data *dimens;
/*-------------------------------------------------------------------------
* For convenience.
*-----------------------------------------------------------------------*/
dimens = (struct seviri_dimension_data *) &image->dimens;
/*-------------------------------------------------------------------------
* Write the image data.
*-----------------------------------------------------------------------*/
data10 = malloc(dimens->n_columns_selected_VIR / 4 * 5 * sizeof(uchar));
for (i = 0; i < dimens->n_lines_to_read_VIR; ++i) {
ii = dimens->i_line_in_output_VIR + i;
for (i_band = 0; i_band < image->n_bands; ++i_band) {
if (seviri_packet_header_read(fp, &image->packet_header[i_band][i], aux)) {
fprintf(stderr, "ERROR: seviri_packet_header_read()\n");
return -1;
}
if (seviri_LineSideInfo_read(fp, &image->LineSideInfo [i_band][i], aux)) {
fprintf(stderr, "ERROR: seviri_LineSideInfo_read()\n");
return -1;
}
su_init_array_uc(data10, dimens->n_columns_to_read_VIR / 4 * 5, 0);
i_image = ii * dimens->n_columns_requested_VIR + dimens->i_column_in_output_VIR;
for (j = 0, jj = 0; j < dimens->n_columns_to_read_VIR; ) {
for (k = 0; k < 4; ++k) {
temp = image->data_vir[i_band][i_image + j] << shifts[k];
SWAP_2(temp, temp);
*((ushort *) (data10 + jj)) = *((ushort *) (data10 + jj)) | temp;
j++, jj++;
}
jj++;
}
if (fwrite(data10, sizeof(char), dimens->n_columns_to_read_VIR / 4 * 5, fp) <
dimens->n_columns_to_read_VIR / 4 * 5) E_L_R();
}
}
free(data10);
return 0;
}
/*******************************************************************************
* Free memory allocated by seviri_image_read() to hold seviri_image_data struct
* fields.
*
* image : The input seviri_image_data struct
*
* returns : Non-zero on error
******************************************************************************/
static int seviri_image_free(struct seviri_image_data *d)
{
uint i;
for (i = 0; i < d->n_bands; ++i)
free(d->packet_header[i]);
free(d->packet_header);
for (i = 0; i < d->n_bands; ++i)
free(d->LineSideInfo[i]);
free(d->LineSideInfo);
for (i = 0; i < d->n_bands; ++i)
free(d->data_vir[i]);
free(d->data_vir);
/*
for (i = 0; i < d->n_bands; ++i)
free(d->data_hrv[i]);
free(d->data_hrv);
*/
return 0;
}
/*******************************************************************************
* Convenience function that returns the number of lines and columns in the
* image to be read with the given choice of offset and dimension parameters.
*
* filename : Native SEVIRI level 1.5 filename
* i_line : Output line offset to the beginning of the actual image
* within the full disk
* i_column : Output column offset to the beginning of the actual image
* within the full disk
* n_lines : Output number of lines of the actual image
* n_columns : Output number of columns of the actual image
* bounds : Described in the seviri_read_nat() header.
* line0 : ''
* line1 : ''
* column0 : ''
* column1 : ''
* lat0 : ''
* lat1 : ''
* lon0 : ''
* lon1 : ''
* aux : Seviri_auxillary_io_data struct containing information related
* to the read operation
*
* returns : Non-zero on error
******************************************************************************/
int seviri_get_dimens_nat(const char *filename, uint *i_line, uint *i_column,
uint *n_lines, uint *n_columns, enum seviri_bounds bounds,
uint line0, uint line1, uint column0, uint column1,
double lat0, double lat1, double lon0, double lon1)
{
FILE *fp;
struct seviri_auxillary_io_data aux;
struct seviri_dimension_data dimens;
struct seviri_marf_header_data marf_header;
aux.operation = 0;
aux.swap_bytes = su_is_little_endian();
seviri_auxillary_alloc(&aux);
if ((fp = fopen(filename, "r")) == NULL) {
fprintf(stderr, "ERROR: Problem opening file for reading: %s ... %s\n",
filename, strerror(errno));
return -1;
}
if (seviri_marf_header_read(fp, &marf_header, &aux)) {
fprintf(stderr, "ERROR: seviri_marf_header_read(), filename = %s\n",
filename);
fclose(fp);
return -1;
}
if (seviri_get_dimension_data(&dimens, &marf_header, bounds, line0, line1,
column0, column1, lat0, lat1, lon0, lon1, 0)) {
fprintf(stderr, "ERROR: seviri_get_dimension_data()\n");
fclose(fp);
return -1;
}
fclose(fp);
seviri_auxillary_free(&aux);
*i_line = dimens.i_line_requested_VIR;
*i_column = dimens.i_column_requested_VIR;
*n_lines = dimens.n_lines_requested_VIR;
*n_columns = dimens.n_columns_requested_VIR;
return 0;
}
/*******************************************************************************
* The main read function.
*
* filename : Native SEVIRI level 1.5 filename
* d : The output seviri_data struct with the U-MARF header, level
* 1.5 header and trailer, and the image data.
* n_bands : The desired number of bands to read
* band_ids : Array of band Ids to read of length n_bands
* bounds : Type of image sub-setting desired. Valid choices are:
* SEVIRI_BOUNDS_FULL_DISK : Produce a full disk image even though
* the actual image may be smaller.
* fill_value is used for the rest of the
* image.
* SEVIRI_BOUNDS_ACTUAL_IMAGE : Read the actual sub-image
* SEVIRI_BOUNDS_LINE_COLUMN : Produce a sub-image based on pixel
* coordinates. fill_value is used for
* when the desired image is bigger than
* the actual image.
* SEVIRI_BOUNDS_LAT_LON : Produce a sub-image based on lat/lon
* coordinates. fill_value is used when
* the desired image is bigger than the
* actual image.
*
* The following are used with bounds = SEVIRI_BOUNDS_LINE_COLUMN
* line0 : Starting line within the full disk of the desired sub-image
* line1 : Ending line within the full disk of the desired sub-image
* column0 : Starting column within the full disk of the desired sub-image
* column1 : Ending column within the full disk of the desired sub-image
*
* The following are used with bounds = SEVIRI_BOUNDS_LAT_LON
* lat0 : Starting latitude of the desired sub-image
* lat1 : Ending latitude of the desired sub-image
* lon0 : Starting longitude of the desired sub-image
* lon1 : Ending longitude of the desired sub-image
*
* returns : Non-zero on error
******************************************************************************/
int seviri_read_nat(const char *filename, struct seviri_data *d,
uint n_bands, const uint *band_ids,
enum seviri_bounds bounds,
uint line0, uint line1, uint column0, uint column1,
double lat0, double lat1, double lon0, double lon1)
{
FILE *fp;
struct seviri_auxillary_io_data aux;
aux.operation = 0;
aux.swap_bytes = su_is_little_endian();
seviri_auxillary_alloc(&aux);
if ((fp = fopen(filename, "r")) == NULL) {
fprintf(stderr, "ERROR: Problem opening file for reading: %s ... %s\n",
filename, strerror(errno));
return -1;
}
if (seviri_marf_header_read(fp, &d->marf_header, &aux)) {
fprintf(stderr, "ERROR: seviri_marf_header_read(), filename = %s\n",
filename);
fclose(fp);
return -1;
}
if (seviri_packet_header_read(fp, &d->packet_header1, &aux)) {
fprintf(stderr, "ERROR: seviri_packet_header_read()\n");
return -1;
}
if (seviri_15HEADER_read(fp, &d->header, &aux)) {
fprintf(stderr, "ERROR: seviri_15HEADER_read(), filename = %s\n",
filename);
fclose(fp);
return -1;
}
if (seviri_image_read(fp, &d->image, &d->marf_header, n_bands, band_ids,
bounds, line0, line1, column0, column1, lat0, lat1,
lon0, lon1, &aux)) {
fprintf(stderr, "ERROR: seviri_image_read(), filename = %s\n",
filename);
fclose(fp);
return -1;
}
if (seviri_packet_header_read(fp, &d->packet_header2, &aux)) {
fprintf(stderr, "ERROR: seviri_packet_header_read()\n");
return -1;
}
if (seviri_15TRAILER_read(fp, &d->trailer, &aux)) {
fprintf(stderr, "ERROR: seviri_15TRAILER_read(), filename = %s\n",
filename);
fclose(fp);
return -1;
}
fclose(fp);
seviri_auxillary_free(&aux);
return 0;
}
/*******************************************************************************
* The main write function.
*
* filename : Native SEVIRI level 1.5 filename
* d : The input seviri_data struct with the U-MARF header, level 1.5
* header and trailer, and the image data.
*
* returns : Non-zero on error
******************************************************************************/
int seviri_write_nat(const char *filename, const struct seviri_data *d)
{
FILE *fp;
struct seviri_auxillary_io_data aux;
aux.operation = 1;
aux.swap_bytes = su_is_little_endian();
seviri_auxillary_alloc(&aux);
if ((fp = fopen(filename, "w")) == NULL) {
fprintf(stderr, "ERROR: Problem opening file for reading: %s ... %s\n",
filename, strerror(errno));
return -1;
}
if (seviri_marf_header_read(fp, (struct seviri_marf_header_data *)
&d->marf_header, &aux)) {
fprintf(stderr, "ERROR: seviri_marf_header_read(), filename = %s\n",
filename);
fclose(fp);
return -1;
}
if (seviri_packet_header_read(fp, (struct seviri_packet_header_data *)
&d->packet_header1, &aux)) {
fprintf(stderr, "ERROR: seviri_packet_header_read()\n");
return -1;
}
if (seviri_15HEADER_read(fp, (struct seviri_15HEADER_data *)
&d->header, &aux)) {
fprintf(stderr, "ERROR: seviri_15HEADER_read(), filename = %s\n",
filename);
fclose(fp);
return -1;
}
if (seviri_image_write(fp, &d->image, &aux)) {
fprintf(stderr, "ERROR: seviri_image_write(), filename = %s\n",
filename);
fclose(fp);
return -1;
}
if (seviri_packet_header_read(fp, (struct seviri_packet_header_data *)
&d->packet_header2, &aux)) {
fprintf(stderr, "ERROR: seviri_packet_header_read()\n");
return -1;
}
if (seviri_15TRAILER_read(fp, (struct seviri_15TRAILER_data *)
&d->trailer, &aux)) {
fprintf(stderr, "ERROR: seviri_15TRAILER_read(), filename = %s\n",
filename);
fclose(fp);
return -1;
}
fclose(fp);
seviri_auxillary_free(&aux);
return 0;
}