OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
validate_L0_header.c
Go to the documentation of this file.
1 #include "L1A_prototype.h"
2 #include "PGS_MODIS_35005.h"
3 #include "PGS_IO_L0.h"
4 #include "PGS_SMF.h"
5 #include "MS_misc.h"
6 #include "PC_pcf_info.h"
7 
8 
9 unsigned int bytetoint (void *bitstream, unsigned int length);
10 
11 PGSt_SMF_status validate_L0_header (PGSt_IO_L0_VirtualDataSet L0_file)
12 
13 /*
14 !C******************************************************************************
15 
16 !Description: Function validate_L0_header gets the L0 header and validate
17  the contents of the header.
18 
19 !Input Parameters:
20  PGSt_IO_L0_VirtualDataSet L0_file ** L0 file descriptor **
21 
22 !Output Parameters:
23  None
24 
25 Return Values:
26  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
27  MODIS_F_L0_HEADER_VAL_FAILED (PGS_MODIS_35005.h)
28 
29 Externally Defined:
30  PGSt_IO_L0_VirtualDataSet (PGS_IO_L0.h)
31  MS_HEADER_BUFF_SIZE (MS_misc.h)
32  MS_FOOTER_BUFF_SIZE (MS_misc.h)
33  PC_INSTRUMENT (PC_pcf_info.h)
34  AQUA_SCID (PC_pcf_info.h)
35  TERRA_SCID (PC_pcf_info.h)
36  INSTRUMENT_AQUA (PC_pcf_info.h)
37  NSTRUMENT_TERRA (PC_pcf_info.h)
38 
39 Called By:
40  get_valid_L0_file
41  read_a_packet
42  set_start_position
43 
44 Routines Called:
45  PGS_IO_L0_GetHeader
46  PGS_SMF_TestSuccessLevel
47  log_fmt_msg
48  PGS_PC_GetConfigData
49 
50 !Revision History:
51 $Log: validate_L0_header.c,v $
52 Revision 5.2 2004/09/29 19:32:53 seaton
53 Fixed bug found while unit testing.
54 
55 Revision 5.1 2004/09/23 19:06:00 seaton
56 Added code to check the L0 construction record SCID to make sure we are processing the
57 correct spacecraft L0 data. This is a collection 5 modification.
58 seaton@saicmodis.com
59 
60  revision 3.0
61  John Seaton
62  Added logic to not fail if the CR header buffer overflows.
63 
64  revision 1.0 1997/09/19 17:30:00
65  Qi Huang/RDC (qhuang@ltpmail.gsfc.nasa.gov)
66  Original development
67 
68 !Team-unique Header:
69  This software is developed by the MODIS Science
70  Data Support Team (SDST) for the National Aeronautics
71  and Space Administration (NASA), Goddard Space Flight
72  Center (GSFC), under contract NAS5-32373.
73 
74 !References and Credits:
75  None
76 
77 !Design Notes:
78  None
79 
80 !END***************************************************************************
81 */
82 
83 {
84  /***************************************************************************/
85  /* */
86  /* Declare and Initialize Local Variables */
87  /* */
88  /***************************************************************************/
89 
90  char *routine = "validate_L0_header";
91  PGSt_SMF_status returnStatus=MODIS_S_SUCCESS;
92  PGSt_IO_L0_Header head_buff[MS_HEADER_BUFF_SIZE];
93  PGSt_IO_L0_Footer foot_buff[MS_FOOTER_BUFF_SIZE];
94  PGSt_SMF_status PGS_status;
95  char buffer[PGSd_PC_VALUE_LENGTH_MAX];
96  int scid_val;
97  char msg[300];
98  int offset=0;
99  int value,i;
100 
101  /***************************************************************************/
102  /* */
103  /* CALL PGS_IO_L0_GetHeader to get the L0 header */
104  /* INPUT: L0_file, header_buff_size, foot_buff_size */
105  /* OUTPUT: head_buff, foot_buff */
106  /* RETURN: PGS_status */
107  /* */
108  /***************************************************************************/
109 
110  PGS_status = PGS_IO_L0_GetHeader(L0_file,MS_HEADER_BUFF_SIZE,head_buff,
111  MS_FOOTER_BUFF_SIZE,foot_buff);
112 
113 
114  /***************************************************************************/
115  /* */
116  /* CALL PGS_SMF_TestSuccessLevel to determine if getting L0 header was */
117  /* successful */
118  /* INPUT: PGS_status */
119  /* ONTPUT: None */
120  /* RETURN: TestStatus */
121  /* */
122  /* IF TestStatus is not equal to PGS_TRUE */
123  /* THEN */
124  /* IF PGS_status not warning that header buffer was truncated */
125  /* THEN */
126  /* Set returnStatus to MODIS_F_L0_HEADER_VAL_FAILED */
127  /* CALL log_fmt_msg to report that getting L0 header was not successful*/
128  /* INPUT: PGS_status, routine, msg */
129  /* OUTPUT: None */
130  /* RETURN: None */
131  /* ENDIF */
132  /* ENDIF */
133  /* */
134  /***************************************************************************/
135 
136  if (PGS_SMF_TestSuccessLevel(PGS_status) != PGS_TRUE) {
137  if (PGS_status != PGSIO_W_L0_HDR_BUF_TRUNCATE) {
138  returnStatus = MODIS_F_L0_HEADER_VAL_FAILED;
140  "L0 header was not successfully retrieved");
141  }
142  } else {
143  PGS_status = PGS_PC_GetConfigData(PC_INSTRUMENT, buffer);
144 
145  if (!PGS_SMF_TestSuccessLevel(PGS_status)) {
146  returnStatus = MODIS_E_GETCONFIG_FAILED;
148  "The satellite instrument string could not be retrieved from the pcf file");
149  }
150  else {
151  /* parse cr to get scid here */
152  /* See CDRL B301 for Layout of the L0 Construction Record file */
153 
154  offset += 50;
155 
156  value = bytetoint(&head_buff[offset], 2);
157  offset+=2;
158 
159  for(i=0; i<value; i++)
160  offset += 16;
161 
162  offset += 81;
163  scid_val = bytetoint(&head_buff[offset], 1);
164 
165  if ((!((scid_val == TERRA_SCID) && (strcmp(buffer,INSTRUMENT_TERRA) == 0))) &&
166  (!((scid_val == AQUA_SCID) && (strcmp(buffer,INSTRUMENT_AQUA) == 0)))) {
167  returnStatus = MODIS_F_L0_HEADER_VAL_FAILED;
168  sprintf(msg, "SCID from Construction Record %d does not match PC_INSTRUMENT tag %s in the pcf file", scid_val, buffer);
170  }
171  }
172  }
173 
174 
175  /***************************************************************************/
176  /* */
177  /* RETURN returnStatus */
178  /* */
179  /***************************************************************************/
180 
181  return (returnStatus);
182 
183 } /* End of routine validate_L0_header */
184 
185 unsigned int bytetoint (void *bitstream, unsigned int length) {
186 
187  unsigned char *bitPtr;
188  unsigned int number=0;
189 
190  bitPtr = ((unsigned char*) bitstream);
191 
192  while (length--)
193  number = number*256 + *(bitPtr++);
194 
195  return number;
196 
197 }
198 
int32 value
Definition: Granule.c:1235
#define TERRA_SCID
Definition: PC_pcf_info.h:73
#define INSTRUMENT_AQUA
Definition: PC_pcf_info.h:72
#define MODIS_F_L0_HEADER_VAL_FAILED
#define MS_FOOTER_BUFF_SIZE
Definition: MS_misc.h:53
#define MODIS_E_GETCONFIG_FAILED
#define MS_HEADER_BUFF_SIZE
Definition: MS_misc.h:52
#define INSTRUMENT_TERRA
Definition: PC_pcf_info.h:71
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
#define PC_INSTRUMENT
Definition: PC_pcf_info.h:69
#define MODIS_S_SUCCESS
unsigned int bytetoint(void *bitstream, unsigned int length)
PGSt_SMF_status validate_L0_header(PGSt_IO_L0_VirtualDataSet L0_file)
l2prod offset
string msg
Definition: mapgen.py:227
int i
Definition: decode_rs.h:71
#define AQUA_SCID
Definition: PC_pcf_info.h:74