OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
initialize_global_metadata.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include "L1A_prototype.h"
3 #include "hdf.h"
4 #include "PGS_MODIS_35005.h"
5 #include "PGS_TYPES.h"
6 #include "PGS_SMF.h"
7 #include "MD_metadata.h"
8 #include "PC_pcf_info.h"
9 #include "version.h"
10 #include "PGS_PC.h"
11 #include "smfio.h"
12 
14  PGSt_double gran_start_time,
15  PGSt_double gran_end_time,
16  int nscans,
17  PCF_CONFIG_t *pcf_config,
18  MD_ECS_GRA_INV_MET_t *ecs_gra_inv_met,
19  MD_L1A_SPECIFIC_MET_t *l1a_specific_met)
20 
21 /******************************************************************************
22 !C
23 
24 !Description: Function initialize_global_metadata initializes the ECS Granule
25  Inventory Metadata (MD_ECS_GRA_INV_MET_t) and the MODIS Level1A
26  Specific Granule Metadata (MD_L1A_SPECIFIFC_MET_t).
27 
28 !Input Parameters:
29  PGSt_double gran_start_time Start time of the L1A granule
30  PGSt_double gran_end_time Stop time of the L1A granule.
31  int nscans Number of scans
32  PCF_CONFIG_t pcf_config PCF configuration parameters
33 
34 !Output Parameters:
35  MD_ECS_GRA_INV_MET_t ecs_gra_inv_met ECS granule inventory metadata.
36  MD_L1A_SPECIFIC_MET_t l1a_specific_met Level 1A specific granule metadata
37 
38 Return Values:
39  MODIS_E_NULL_POINTER If any pointer argument is NULL
40  MODIS_S_SUCCESS If successful
41  PGS_E_TOOLKIT From subroutines
42  PGS_S_SUCCESS From subroutines
43  PGSTD_E_NO_LEAP_SECS From subroutines
44 
45 Externally Defined:
46  MD_ECS_GRA_INV_MET_t (MD_metadata.h)
47  MD_GRANULENUMBER (MD_metadata.h)
48  MD_L1A_SPECIFIC_MET_t (MD_metadata.h)
49  MD_MAX_MISSING_PKTS_IN_SCAN (MD_metadata.h)
50  MD_MIDNIGHT (MD_metadata.h)
51  MD_NA (MD_metadata.h)
52  MD_OTHER_STRING (MD_metadata.h)
53  MD_PROCESSVERSION (MD_metadata.h)
54  MODIS_E_NULL_POINTER (PGS_MODIS_35005.h)
55  MODIS_E_TAI_TO_UTC_FAILED (PGS_MODIS_35005.h)
56  MODIS_E_UTC_TO_TAI_FAILED (PGS_MODIS_35005.h)
57  MODIS_S_SUCCESS (PGS_MODIS_35005.h)
58  PCF_CONFIG_t (PC_pcf_info.h)
59  PGS_S_SUCCESS (PGS_SMF.h)
60  PGS_SMF_MASK_LEV_E (PGS_SMF.h)
61  PGS_E_TOOLKIT (PGS_SMF.h)
62  PGSt_SMF_status (PGS_SMF.h)
63  PGSt_double (PGS_types.h)
64  PGSTD_E_NO_LEAP_SECS (PGS_TD_3.h)
65  PROCESSVERSION (version.h)
66  TIMECODEASIZE (smfio.h)
67 
68 Called By:
69  process_a_granule
70 
71 Routines Called:
72  PGS_TD_TAItoUTC
73  PGS_TD_UTCtoTAI
74  PGS_SMF_TestStatusLevel
75  log_fmt_msg
76 
77 !Revision History:
78  $Log: initialize_global_metadata.c,v $
79  Revision 6.1 2010/08/24 16:08:49 kuyper
80  Corrected "%lf" sprintf() format specifiers to "%f".
81 
82  Revision 5.1 2006/01/02 19:38:32 kuyper
83  Changed calculation of granule number to work properly even for granules
84  covering leap seconds.
85 
86  Revision 4.2 2003/01/08 19:52:43 vlin
87  Initialization of field name "operation_mode" removed.
88 
89  Revision 4.1 2002/12/04 20:11:54 vlin
90  Use TIMECODEASIZE for buffer size
91 
92  Revision 4.0 2002/10/30 14:58:38 vlin
93  Updated to match initialize_global_metadata.pdl v4.2
94  vlin@saicmodis.com
95 
96  revision 1.0 1997/08/20 17:30:00
97  Qi Huang/RDC (qhuang@ltpmail.gsfc.nasa.gov)
98  Original development
99 
100 !Team-unique Header:
101 
102  This software is developed by the MODIS Science Data Support Team
103  for the National Aeronautics and Space Administration, Goddard
104  Space Flight Center, under contract NAS5-32373.
105 
106 References and Credits:
107  None
108 
109 Design Notes:
110  None
111 
112 !END
113 ****************************************************************************/
114 
115 {
116  char *routine = "initialize_global_metadata";
117  PGSt_SMF_status returnStatus = MODIS_S_SUCCESS;
118  PGSt_SMF_status tempStatus, level;
119  char temp_string[TIMECODEASIZE], midnight_UTC[TIMECODEASIZE];
120  char msg[128];
121  PGSt_double midnight_TAI;
122  int i, temp_granule_number;
123 
124  if (pcf_config==NULL || ecs_gra_inv_met==NULL || l1a_specific_met==NULL) {
125  log_fmt_msg(MODIS_E_NULL_POINTER, routine, "");
126  return MODIS_E_NULL_POINTER;
127  }
128 
129  tempStatus = PGS_TD_TAItoUTC(gran_start_time,temp_string);
130 
131  level = PGS_SMF_TestStatusLevel(tempStatus);
132 
133  if (level >= PGS_SMF_MASK_LEV_E) {
134  sprintf(msg,"The granule start time %f could not be converted from TAI "
135  "to UTC", gran_start_time);
136  returnStatus = tempStatus;
138  }
139  else {
140  strcpy(ecs_gra_inv_met->rangebeginningdate,strtok(temp_string,"T"));
141  strcpy(ecs_gra_inv_met->rangebeginningtime,strtok(NULL,"Z"));
142  }
143 
144  ecs_gra_inv_met->additionalattributename_1 = MD_GRANULENUMBER;
145  ecs_gra_inv_met->additionalattributename_2 = MD_PROCESSVERSION;
146  ecs_gra_inv_met->parametervalue_2 = PROCESSVERSION;
147  tempStatus = PGS_TD_TAItoUTC(gran_end_time,temp_string);
148  level = PGS_SMF_TestStatusLevel(tempStatus);
149 
150  if (level >= PGS_SMF_MASK_LEV_E) {
151  sprintf(msg, "The granule end time %f could not be converted from "
152  "TAI to UTC", gran_end_time);
153  returnStatus = tempStatus;
155  strcpy(ecs_gra_inv_met->parametervalue_1, "0");
156  }
157  else {
158  strcpy(ecs_gra_inv_met->rangeendingdate,strtok(temp_string,"T"));
159  strcpy(ecs_gra_inv_met->rangeendingtime,strtok(NULL,"Z"));
160 
161  sprintf(midnight_UTC,ecs_gra_inv_met->rangeendingdate, MD_MIDNIGHT);
162  tempStatus = PGS_TD_UTCtoTAI(midnight_UTC,&midnight_TAI);
163  level = PGS_SMF_TestStatusLevel(tempStatus);
164  if (level >= PGS_SMF_MASK_LEV_E) {
165  sprintf(msg, "Midnight %s could not be converted from UTC to TAI "
166  "therefore no granule number can be computed", midnight_UTC);
167  returnStatus = tempStatus;
169  strcpy(ecs_gra_inv_met->parametervalue_1, "0");
170  }
171  else {
172  temp_granule_number = (int)((gran_end_time-midnight_TAI)/300) + 1;
173  sprintf(ecs_gra_inv_met->parametervalue_1, "%d", temp_granule_number);
174  }
175  }
176 
177  strcpy(ecs_gra_inv_met->day_night_flag, MD_NA);
178  ecs_gra_inv_met->orbit_num_1 = -1;
179  ecs_gra_inv_met->equatorcrossinglongitude_1 = (double)-1.0;
180  ecs_gra_inv_met->equatorcrossingdate_1 = ecs_gra_inv_met->rangebeginningdate;
181  ecs_gra_inv_met->equatorcrossingtime_1 = ecs_gra_inv_met->rangebeginningtime;
182  strcpy(ecs_gra_inv_met->exclusiongringflag_1, "");
183 
184  for (i=0; i<4; i++) {
185  ecs_gra_inv_met->gringpointlatitude_1[i] = (double)-1.0;
186  ecs_gra_inv_met->gringpointlongitude_1[i] = (double)-1.0;
187  ecs_gra_inv_met->gringpointsequenceno_1[i] = -1;
188  }
189 
190  ecs_gra_inv_met->processingenvironment = pcf_config->processingenvironment;
191  ecs_gra_inv_met->localversionid = pcf_config->localversionid;
192  strcpy(ecs_gra_inv_met->productionhistory, "PGE01:");
193  strcat(ecs_gra_inv_met->productionhistory, pcf_config->pgeversion);
194  ecs_gra_inv_met->pgeversion = pcf_config->pgeversion;
195  ecs_gra_inv_met->reprocessingactual = pcf_config->reprocessingactual;
196  ecs_gra_inv_met->reprocessingplanned = pcf_config->reprocessingplanned;
197 
198 /* Set Level 1 A specific granule metadata */
199  l1a_specific_met->num_scans = 0;
200  l1a_specific_met->num_day_scans = 0;
201  l1a_specific_met->num_night_scans = 0;
202  l1a_specific_met->max_total_frames = 0;
203  l1a_specific_met->max_earth_frames = 0;
204  l1a_specific_met->max_sd_frames = 0;
205  l1a_specific_met->max_srca_frames = 0;
206  l1a_specific_met->max_bb_frames = 0;
207  l1a_specific_met->max_sv_frames = 0;
208  memset(l1a_specific_met->scan_types_product, '\0',
209  sizeof(l1a_specific_met->scan_types_product));
210  strcpy(l1a_specific_met->scan_types_product,MD_OTHER_STRING);
211  l1a_specific_met->incomplete_scans = 0;
212  l1a_specific_met->missing_packets = nscans * MD_MAX_MISSING_PKTS_IN_SCAN;
213  l1a_specific_met->packets_bad_crc = 0;
214  l1a_specific_met->discarded_packets = 0;
215 
216  return returnStatus;
217 }
#define MD_NA
Definition: MD_metadata.h:100
#define MD_MIDNIGHT
Definition: MD_metadata.h:105
char scan_types_product[10]
Definition: MD_metadata.h:203
PGSt_SMF_status initialize_global_metadata(PGSt_double gran_start_time, PGSt_double gran_end_time, int nscans, PCF_CONFIG_t *pcf_config, MD_ECS_GRA_INV_MET_t *ecs_gra_inv_met, MD_L1A_SPECIFIC_MET_t *l1a_specific_met)
char rangebeginningdate[MD_TIMECODEADATELEN]
Definition: MD_metadata.h:162
char pgeversion[PGSd_PC_VALUE_LENGTH_MAX]
Definition: PC_pcf_info.h:87
double gringpointlongitude_1[4]
Definition: MD_metadata.h:173
char processingenvironment[PGSd_PC_VALUE_LENGTH_MAX]
Definition: PC_pcf_info.h:88
#define NULL
Definition: decode_rs.h:63
char localversionid[PGSd_PC_VALUE_LENGTH_MAX]
Definition: PC_pcf_info.h:85
char productionhistory[16]
Definition: MD_metadata.h:183
#define TIMECODEASIZE
Definition: Metadata.c:59
char rangeendingtime[MD_TIMECODEATIMELEN]
Definition: MD_metadata.h:165
#define MODIS_E_TAI_TO_UTC_FAILED
char rangebeginningtime[MD_TIMECODEATIMELEN]
Definition: MD_metadata.h:163
double gringpointlatitude_1[4]
Definition: MD_metadata.h:172
double equatorcrossinglongitude_1
Definition: MD_metadata.h:168
#define MD_OTHER_STRING
Definition: MD_metadata.h:95
#define MD_PROCESSVERSION
Definition: MD_metadata.h:94
#define MD_MAX_MISSING_PKTS_IN_SCAN
Definition: MD_metadata.h:126
void log_fmt_msg(PGSt_SMF_status code, const char *routine, const char *msg_fmt,...)
Definition: log_fmt_msg.c:6
#define MD_GRANULENUMBER
Definition: MD_metadata.h:104
char reprocessingplanned[PGSd_PC_VALUE_LENGTH_MAX]
Definition: PC_pcf_info.h:91
char rangeendingdate[MD_TIMECODEADATELEN]
Definition: MD_metadata.h:164
#define PROCESSVERSION
Definition: version.h:112
char * additionalattributename_1
Definition: MD_metadata.h:175
integer, parameter double
#define MODIS_E_UTC_TO_TAI_FAILED
char * equatorcrossingtime_1
Definition: MD_metadata.h:170
level
Definition: mapgen.py:186
#define MODIS_S_SUCCESS
string msg
Definition: mapgen.py:227
int gringpointsequenceno_1[4]
Definition: MD_metadata.h:174
char * equatorcrossingdate_1
Definition: MD_metadata.h:169
char reprocessingactual[PGSd_PC_VALUE_LENGTH_MAX]
Definition: PC_pcf_info.h:90
int i
Definition: decode_rs.h:71
#define MODIS_E_NULL_POINTER
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
char * processingenvironment
Definition: MD_metadata.h:181
char * additionalattributename_2
Definition: MD_metadata.h:176
char exclusiongringflag_1[2]
Definition: MD_metadata.h:171