|
ocssw
1.0
|
00001 #include "L1A_prototype.h" 00002 #include "PGS_MODIS_35005.h" 00003 #include "PGS_IO_L0.h" 00004 #include "PGS_SMF.h" 00005 #include "MS_misc.h" 00006 #include "PC_pcf_info.h" 00007 00008 00009 unsigned int bytetoint (void *bitstream, unsigned int length); 00010 00011 PGSt_SMF_status validate_L0_header (PGSt_IO_L0_VirtualDataSet L0_file) 00012 00013 /* 00014 !C****************************************************************************** 00015 00016 !Description: Function validate_L0_header gets the L0 header and validate 00017 the contents of the header. 00018 00019 !Input Parameters: 00020 PGSt_IO_L0_VirtualDataSet L0_file ** L0 file descriptor ** 00021 00022 !Output Parameters: 00023 None 00024 00025 Return Values: 00026 MODIS_S_SUCCESS (PGS_MODIS_35005.h) 00027 MODIS_F_L0_HEADER_VAL_FAILED (PGS_MODIS_35005.h) 00028 00029 Externally Defined: 00030 PGSt_IO_L0_VirtualDataSet (PGS_IO_L0.h) 00031 MS_HEADER_BUFF_SIZE (MS_misc.h) 00032 MS_FOOTER_BUFF_SIZE (MS_misc.h) 00033 PC_INSTRUMENT (PC_pcf_info.h) 00034 AQUA_SCID (PC_pcf_info.h) 00035 TERRA_SCID (PC_pcf_info.h) 00036 INSTRUMENT_AQUA (PC_pcf_info.h) 00037 NSTRUMENT_TERRA (PC_pcf_info.h) 00038 00039 Called By: 00040 get_valid_L0_file 00041 read_a_packet 00042 set_start_position 00043 00044 Routines Called: 00045 PGS_IO_L0_GetHeader 00046 PGS_SMF_TestSuccessLevel 00047 log_fmt_msg 00048 PGS_PC_GetConfigData 00049 00050 !Revision History: 00051 $Log: validate_L0_header.c,v $ 00052 Revision 5.2 2004/09/29 19:32:53 seaton 00053 Fixed bug found while unit testing. 00054 00055 Revision 5.1 2004/09/23 19:06:00 seaton 00056 Added code to check the L0 construction record SCID to make sure we are processing the 00057 correct spacecraft L0 data. This is a collection 5 modification. 00058 seaton@saicmodis.com 00059 00060 revision 3.0 00061 John Seaton 00062 Added logic to not fail if the CR header buffer overflows. 00063 00064 revision 1.0 1997/09/19 17:30:00 00065 Qi Huang/RDC (qhuang@ltpmail.gsfc.nasa.gov) 00066 Original development 00067 00068 !Team-unique Header: 00069 This software is developed by the MODIS Science 00070 Data Support Team (SDST) for the National Aeronautics 00071 and Space Administration (NASA), Goddard Space Flight 00072 Center (GSFC), under contract NAS5-32373. 00073 00074 !References and Credits: 00075 None 00076 00077 !Design Notes: 00078 None 00079 00080 !END*************************************************************************** 00081 */ 00082 00083 { 00084 /***************************************************************************/ 00085 /* */ 00086 /* Declare and Initialize Local Variables */ 00087 /* */ 00088 /***************************************************************************/ 00089 00090 char *routine = "validate_L0_header"; 00091 PGSt_SMF_status returnStatus=MODIS_S_SUCCESS; 00092 PGSt_IO_L0_Header head_buff[MS_HEADER_BUFF_SIZE]; 00093 PGSt_IO_L0_Footer foot_buff[MS_FOOTER_BUFF_SIZE]; 00094 PGSt_SMF_status PGS_status; 00095 char buffer[PGSd_PC_VALUE_LENGTH_MAX]; 00096 int scid_val; 00097 char msg[300]; 00098 int offset=0; 00099 int value,i; 00100 00101 /***************************************************************************/ 00102 /* */ 00103 /* CALL PGS_IO_L0_GetHeader to get the L0 header */ 00104 /* INPUT: L0_file, header_buff_size, foot_buff_size */ 00105 /* OUTPUT: head_buff, foot_buff */ 00106 /* RETURN: PGS_status */ 00107 /* */ 00108 /***************************************************************************/ 00109 00110 PGS_status = PGS_IO_L0_GetHeader(L0_file,MS_HEADER_BUFF_SIZE,head_buff, 00111 MS_FOOTER_BUFF_SIZE,foot_buff); 00112 00113 00114 /***************************************************************************/ 00115 /* */ 00116 /* CALL PGS_SMF_TestSuccessLevel to determine if getting L0 header was */ 00117 /* successful */ 00118 /* INPUT: PGS_status */ 00119 /* ONTPUT: None */ 00120 /* RETURN: TestStatus */ 00121 /* */ 00122 /* IF TestStatus is not equal to PGS_TRUE */ 00123 /* THEN */ 00124 /* IF PGS_status not warning that header buffer was truncated */ 00125 /* THEN */ 00126 /* Set returnStatus to MODIS_F_L0_HEADER_VAL_FAILED */ 00127 /* CALL log_fmt_msg to report that getting L0 header was not successful*/ 00128 /* INPUT: PGS_status, routine, msg */ 00129 /* OUTPUT: None */ 00130 /* RETURN: None */ 00131 /* ENDIF */ 00132 /* ENDIF */ 00133 /* */ 00134 /***************************************************************************/ 00135 00136 if (PGS_SMF_TestSuccessLevel(PGS_status) != PGS_TRUE) { 00137 if (PGS_status != PGSIO_W_L0_HDR_BUF_TRUNCATE) { 00138 returnStatus = MODIS_F_L0_HEADER_VAL_FAILED; 00139 log_fmt_msg(MODIS_F_L0_HEADER_VAL_FAILED, routine, 00140 "L0 header was not successfully retrieved"); 00141 } 00142 } else { 00143 PGS_status = PGS_PC_GetConfigData(PC_INSTRUMENT, buffer); 00144 00145 if (!PGS_SMF_TestSuccessLevel(PGS_status)) { 00146 returnStatus = MODIS_E_GETCONFIG_FAILED; 00147 log_fmt_msg(MODIS_E_GETCONFIG_FAILED, routine, 00148 "The satellite instrument string could not be retrieved from the pcf file"); 00149 } 00150 else { 00151 /* parse cr to get scid here */ 00152 /* See CDRL B301 for Layout of the L0 Construction Record file */ 00153 00154 offset += 50; 00155 00156 value = bytetoint(&head_buff[offset], 2); 00157 offset+=2; 00158 00159 for(i=0; i<value; i++) 00160 offset += 16; 00161 00162 offset += 81; 00163 scid_val = bytetoint(&head_buff[offset], 1); 00164 00165 if ((!((scid_val == TERRA_SCID) && (strcmp(buffer,INSTRUMENT_TERRA) == 0))) && 00166 (!((scid_val == AQUA_SCID) && (strcmp(buffer,INSTRUMENT_AQUA) == 0)))) { 00167 returnStatus = MODIS_F_L0_HEADER_VAL_FAILED; 00168 sprintf(msg, "SCID from Construction Record %d does not match PC_INSTRUMENT tag %s in the pcf file", scid_val, buffer); 00169 log_fmt_msg(MODIS_F_L0_HEADER_VAL_FAILED, routine, msg); 00170 } 00171 } 00172 } 00173 00174 00175 /***************************************************************************/ 00176 /* */ 00177 /* RETURN returnStatus */ 00178 /* */ 00179 /***************************************************************************/ 00180 00181 return (returnStatus); 00182 00183 } /* End of routine validate_L0_header */ 00184 00185 unsigned int bytetoint (void *bitstream, unsigned int length) { 00186 00187 unsigned char *bitPtr; 00188 unsigned int number=0; 00189 00190 bitPtr = ((unsigned char*) bitstream); 00191 00192 while (length--) 00193 number = number*256 + *(bitPtr++); 00194 00195 return number; 00196 00197 } 00198
1.7.6.1