OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
handle_missing_scans.c
Go to the documentation of this file.
1 #include "PGS_SMF.h"
2 #include "mapi.h"
3 #include "EN_eng_data.h"
4 #include "L1A_prototype.h"
5 #include "MD_metadata.h"
6 #include "PGS_MODIS_35005.h"
7 #include "SC_scan.h"
8 
9 PGSt_SMF_status handle_missing_scans (MODFILE *L1A_file_ptr,
10  PGSt_double SD_start_time,
11  PGSt_double *pre_SD_time,
12  PGSt_double scan_rate,
13  int *scan_number,
14  MD_ECS_GRA_INV_MET_t *ecs_gran_meta,
15  MD_L1A_SPECIFIC_MET_t *L1A_specific_meta,
16  PGSt_SMF_boolean *gran_start_time_used,
17  PGSt_double gran_start_time,
18  EN_VDATA_TYPE_t *eng_data )
19 /*
20 !C******************************************************************************
21 
22 !Description: Function handle_missing_scans determines if there are any missing
23  scans in this granule and if so, creates those scans.
24 
25 !Input Parameters:
26  PGSt_double SD_start_time ** SD start time for the
27  current packet **
28  PGSt_double scan_rate ** Scan rate **
29  EN_VDATA_TYPE_t *eng_data ** Engineering data **
30 
31 !Output Parameters:
32  None
33 
34 !Input/Output Parameters:
35  PGSt_double *pre_SD_time ** SD start time for the
36  last packet *
37  int16 *scan_number ** Previous scan number **
38  MD_ECS_GRA_INV_MET_t, *ecs_gran_meta ** ECS granule metadata **
39  MD_L1A_SPECIFIC_MET_t *L1A_specific_meta ** L1A specific metadata **
40  PGSt_SMF_boolean *gran_start_time_used ** Flag indicating if
41  the SD start time for
42  the last packet is an
43  estimate **
44  MODFILE *L1A_file_ptr ** L1A file pointer **
45 
46 Return Values:
47  MODIS_S_SUCCESS
48  MODIS_E_ARRAY_OUTPUT_ERR
49  MODIS_E_HANDLE_MISSING_SCANS
50  MODIS_F_WRITE_ENG_DATA_FAIL
51 
52 Externally Defined:
53  EN_VDATA_TYPE_t (EN_eng_data.h)
54  MD_ECS_GRA_INV_MET_t (MD_metadata.h)
55  MD_L1A_SPECIFIC_MET_t (MD_metadata.h)
56  MD_SCAN_MET_t (MD_metadata.h)
57  PGS_TRUE (PGS_SMF.h)
58  PGS_FALSE (PGS_SMF.h)
59  PGSt_double (PGS_TYPES.h)
60  PGSt_SMF_boolean (PGS_SMF.h)
61  SC_SCAN_RATE_TOLERANCE (SC_scan.h)
62 
63 Called By:
64  process_a_granule
65 
66 Routines Called:
67  create_missing_scans
68  write_scan_metadata
69  write_eng_data
70  update_global_metadata
71  log_fmt_msg
72 
73 !Revision History:
74  $Log: handle_missing_scans.c,v $
75  Revision 5.1 2007/01/26 20:56:31 kuyper
76  Fixed to resolve Bug 199 by preventing the insertion of too many missing
77  scans.
78 
79  Revision 1.3 2001/04/13 18:09:20 seaton
80  Changed raw_mir_enc to type uint16 and fixed numerous prologs.
81 
82  Revision 1.2 2000/02/08 17:19:49 seaton
83  Bug fixes and error message corrections version 2.1.4
84 
85  Revision 1.1 1999/08/10 14:05:25 seaton
86  Initial revision
87 
88  revision 1.0 1997/08/28 17:30:00
89  Qi Huang/RDC (qhuang@ltpmail.gsfc.nasa.gov)
90  Original development
91 
92 !Team-unique Header:
93  This software is developed by the MODIS Science Data Support
94  Team (SDST) for the National Aeronautics and Space Administration
95  (NASA), Goddard Space Flight Center (GSFC), under contract
96  NAS5-32373.
97 
98 !References and Credits:
99  None
100 
101 !Design Notes:
102  None
103 
104 !END****************************************************************************
105 */
106 {
107  char *routine = "handle_missing_scans";
108  char msg[300];
109  PGSt_SMF_status returnStatus;
110  PGSt_SMF_status L1A_status;
111 
112  int num_missing_scans;
113  int i;
114  MD_SCAN_MET_t scan_meta;
115  SC_PIXEL_QUALITY_DATA_t pix_qual_data;
116 
117  returnStatus = MODIS_S_SUCCESS;
118 
119  if ((SD_start_time - *pre_SD_time) / (scan_rate + SC_SCAN_RATE_TOLERANCE) > 0)
120  {
121  num_missing_scans = ((SD_start_time - gran_start_time) /
122  (scan_rate+SC_SCAN_RATE_TOLERANCE)) - 0.5
123  - L1A_specific_meta->num_scans;
124  if(num_missing_scans < 0)
125  num_missing_scans = 0;
126  if (*gran_start_time_used == PGS_TRUE)
127  *pre_SD_time = SD_start_time - (scan_rate * (num_missing_scans + 1));
128 
129  i = 0;
130  while ((i < num_missing_scans) &&
131  (returnStatus != MODIS_F_WRITE_ENG_DATA_FAIL))
132  {
133  create_missing_scans(*scan_number,
134  scan_rate,
135  pre_SD_time,
136  &scan_meta,
137  &pix_qual_data);
138 
139  *scan_number = scan_meta.scan_num;
140 
141  L1A_status = write_scan_metadata(L1A_file_ptr,&scan_meta);
142  if (L1A_status != MODIS_S_SUCCESS)
143  {
144  returnStatus = MODIS_E_HANDLE_MISSING_SCANS;
145  sprintf(msg,"The scan metadata could not be written succesfully for missing scan number %d",
146  scan_meta.scan_num);
148  }
149 
150  L1A_status = write_pix_qual(L1A_file_ptr, &pix_qual_data, scan_meta.scan_num);
151 
152  if (L1A_status != MODIS_S_SUCCESS)
153  {
154  returnStatus = MODIS_E_HANDLE_MISSING_SCANS;
155  sprintf(msg,"The pixel quality data could not be written succesfully for missing scan number %d",
156  scan_meta.scan_num);
158  }
159 
160  L1A_status = write_eng_data(eng_data);
161 
162  if (L1A_status != MODIS_S_SUCCESS)
163  {
164  returnStatus = L1A_status;
165  sprintf(msg,"The engineering data could not be written succesfully for missing scan number %d",
166  scan_meta.scan_num);
168  }
169 
170  update_global_metadata(&scan_meta,ecs_gran_meta,L1A_specific_meta);
171  i++;
172  }
173  }
174 
175 
176  *pre_SD_time = SD_start_time;
177  *gran_start_time_used = PGS_FALSE;
178 
179  return (returnStatus);
180 
181 }
void create_missing_scans(int16 prev_scan_num, PGSt_double scan_rate, PGSt_double *SD_start_time, MD_SCAN_MET_t *scan_metadata, SC_PIXEL_QUALITY_DATA_t *pixel_qual_data)
#define MODIS_E_HANDLE_MISSING_SCANS
PGSt_SMF_status write_eng_data(EN_VDATA_TYPE_t *eng_data)
void update_global_metadata(MD_SCAN_MET_t *scan_meta, MD_ECS_GRA_INV_MET_t *ecs_gra_inv_met, MD_L1A_SPECIFIC_MET_t *l1a_specific_met)
PGSt_SMF_status write_scan_metadata(MODFILE *L1A_file_ptr, MD_SCAN_MET_t *scan_meta)
#define SC_SCAN_RATE_TOLERANCE
Definition: SC_scan.h:123
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
#define MODIS_E_ARRAY_OUTPUT_ERR
PGSt_SMF_status handle_missing_scans(MODFILE *L1A_file_ptr, PGSt_double SD_start_time, PGSt_double *pre_SD_time, PGSt_double scan_rate, int *scan_number, MD_ECS_GRA_INV_MET_t *ecs_gran_meta, MD_L1A_SPECIFIC_MET_t *L1A_specific_meta, PGSt_SMF_boolean *gran_start_time_used, PGSt_double gran_start_time, EN_VDATA_TYPE_t *eng_data)
#define MODIS_F_WRITE_ENG_DATA_FAIL
#define MODIS_S_SUCCESS
string msg
Definition: mapgen.py:227
PGSt_SMF_status write_pix_qual(MODFILE *L1A_file_ptr, SC_PIXEL_QUALITY_DATA_t *pix_qual, int16 scan_num)
int i
Definition: decode_rs.h:71