OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
init_packet_read.c
Go to the documentation of this file.
1 // Ported from IDL subroutine to initialize the reading of a packet file by finding
2 // the first packet of a scan.
3 
4 // Arguments
5 //
6 // Name Type I/O Description
7 // ---- ---- --- -----------
8 // infile FILE I Input file pointer
9 // epacket byte(9318) O Byte array containing first packet of scan
10 // len_packet int O packet size
11 // endfile long int O File Length (bytes); value set to 0 at the end of file
12 
13 // Liang Hong, July 22, 2015
14 
15 #include <stdio.h>
16 #include <string.h>
17 #include <stdint.h>
18 #include "l0qc_viirs.h"
19 
20 int init_packet_read(FILE *infile, uint8_t epacket[], int *len_packet, long int *endfile) {
21  int apid = 0;
22  uint8_t packet[30000];
23 
24  // Read to the first packet of a scan (APID = 826)
25  while (apid != 826 || *len_packet != 9318) {
26  read_packet(infile, packet, len_packet, endfile);
27  if (*endfile == 0) {
28  printf("End of file reached before start of scan\n");
29  return 1;
30  } else {
31  apid = (packet[0] % 8)*256 + packet[1];
32  }
33  }
34 
35  memcpy(epacket, packet, *len_packet);
36 
37  return 0;
38 }
39 
40 
41 
int read_packet(FILE *infile, uint8_t packet[], int *len, long int *endfile)
Definition: read_packet.c:18
int init_packet_read(FILE *infile, uint8_t epacket[], int *len_packet, long int *endfile)