OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
GEO_get_utcpole_metadata.c
Go to the documentation of this file.
1 #include <errno.h>
2 #include "PGS_MODIS_35251.h"
3 #include "PGS_CSC.h"
4 #include "PGS_SMF.h"
5 #include "PGS_IO.h"
6 #include "smfio.h"
7 #include "GEO_output.h"
8 #define MAXMSGLEN 120
9 
10 PGSt_SMF_status GEO_get_utcpole_metadata(
11  const ECS_metadata_struct *ECS_metadata,
12  utcpole_metadata_struct *utcpole_metadata)
13 /*****************************************************************************
14 !C
15 
16 !Description:
17  Fills in utcpole_metadata with values read/interpolated from
18  the utpole.data file.
19 
20 !Input Parameters:
21  ECS_metadata Used to obtain RangeBeginningDateTime
22 
23 !Output Parameters:
24  utcpole_metadata Contains metadata identifying the utcpole file.
25 
26 Return Parameters:
27  MODIS_E_BAD_INPUT_ARG If either argument is NULL
28  PGS_E_UNIX If the call to fgets() fails.
29  MODIS_E_GEO If any other subroutine fails.
30  MODIS_E_PREMATURE_EOF if the utcpole.dat file is empty.
31  PGS_S_SUCCESS Otherwise
32 
33 
34 Externally Defined:
35  errno <errno.h>
36  MODIS_E_BAD_INPUT_ARG "PGS_MODIS_35251.h"
37  MODIS_E_GEO "PGS_MODIS_35251.h"
38  MODIS_E_PREMATURE_EOF "PGS_MODIS_35251.h"
39  PGSCSC_W_PREDICTED_UT1 "PGS_CSC.h"
40  PGSd_IO_Gen_Read "PGS_IO.h"
41  PGSd_UTCPOLE "PGS_CSC.h"
42  PGS_E_UNIX "PGS_SMF.h"
43  PGS_S_SUCCESS "PGS_SMF.h"
44  TIMECODEASIZE "smfio.h"
45 
46 Called by:
47  GEO_write_granule_metadata
48 
49 Routines Called:
50  modsmf To log status messages.
51  PGS_IO_Gen_Open To open a file, identified by a LUN
52  PGS_IO_Gen_Close To close afile opened with PGS_IO_GenOpen
53  PGS_SMF_SetUnixMessage To log Unix error messages as status messages.
54  PGS_TD_UTCtoUTCjd To calculate the Julian Day for a UTC time.
55  PGS_CSC_UTC_UT1Pole To calculate utcpole value for a given time.
56 
57 !Revision History:
58 $Log: GEO_get_utcpole_metadata.c,v $
59 Revision 4.2 2003/08/28 16:24:04 kuyper
60 Corrected prolog.
61 
62 Revision 4.1 2003/02/21 22:40:11 kuyper
63 Corrected to use void* pointers with %p format code.
64 
65 Revision 3.4 2001/06/12 11:12:34 kuyper
66 Corrected to treat PGSCSC_W_PREDICTED_UT1 as a normal return from
67  PGS_CSC_UTC_UT1Pole.
68 
69 Revision 3.3 2001/03/28 19:34:20 pliu
70 Corrected handling of error returns from fgets().
71 
72 Revision 3.2 2001/03/15 21:43:08 pliu
73 Corrected based on walkthrough. Change direct use of 79 to sizeof.
74 
75 Revision 3.1 2001/03/01 19:43:57 pliu
76 Initial revision.
77 
78 
79 Ping Liu (pliu@ltpmail.gsfc.nasa.gov)
80 
81 
82 Requirements:
83  PR03-F-4.1-1.6
84  PR03-I-1
85  PR03-I-2
86  PR03-S-1
87 
88 !Team-unique Header:
89  This software is developed by the MODIS Science Data Support
90  Team for the National Aeronautics and Space Administration,
91  Goddard Space Flight Center, under contract NAS5-32373.
92 
93  References and Credits
94 
95 !END**************************************************************************
96  */
97 {
98  /* define local variables */
99 
100  PGSt_SMF_status retval = PGS_S_SUCCESS;
101  PGSt_SMF_status status = PGS_S_SUCCESS;
102  char asciiUTC[TIMECODEASIZE] = "";
103  PGSt_double jdUTC[2];
104 
105  char msgbuf[MAXMSGLEN];
106  static char filefunc[] = __FILE__ ", GEO_get_utcpole_metadata";
107  PGSt_integer version = 1;
108  PGSt_IO_Gen_FileHandle *filehandle;
109  PGSt_double jdtable;
110 
111  /* Checking for NULL input */
112 
113  if (ECS_metadata == NULL || utcpole_metadata == NULL) {
114  sprintf(msgbuf, "ECS_metadata: %p utcpole_metadata: %p",
115  (void*)ECS_metadata, (void*)utcpole_metadata);
116  modsmf(MODIS_E_BAD_INPUT_ARG, msgbuf, filefunc);
117  return MODIS_E_BAD_INPUT_ARG;
118  }
119 
120 
121  /* Call PGS_IO_Gen_Open() to open the file utcpole.dat */
122 
123  if (PGS_IO_Gen_Open(PGSd_UTCPOLE, PGSd_IO_Gen_Read, &filehandle, version)
124  != PGS_S_SUCCESS) {
125  sprintf(msgbuf, "PGS_IO_Gen_Open(%d)", (int)PGSd_UTCPOLE);
126  modsmf(MODIS_E_GEO, msgbuf, filefunc);
127  return MODIS_E_GEO;
128  }
129 
130 
131  /* Call fgets to read in the first line of the utcpole file. */
132 
133  if ( fgets(utcpole_metadata->header, sizeof(utcpole_metadata->header), filehandle)
134  != utcpole_metadata->header) {
135  if (ferror(filehandle)) {
136  PGS_SMF_SetUNIXMsg(errno, "fgets(utcpole.dat)", filefunc);
137  retval = PGS_E_UNIX;
138  }
139  else {
140  modsmf(MODIS_E_PREMATURE_EOF, "utcpole.dat", filefunc);
141  retval = MODIS_E_PREMATURE_EOF;
142  }
143  }
144 
145  /* Call PGS_IO_Gen_Close() to close the utcpole file. */
146  status = PGS_IO_Gen_Close(filehandle);
147 
148  /* Fill in asciiUTC */
149  sprintf(asciiUTC, "%.10sT%.15s", ECS_metadata->rangebeginningdate,
150  ECS_metadata->rangebeginningtime);
151 
152  /* Convert asciiUTC into jdUTC. If success, load the elements of the
153  utcpole.polar_motion array with the x and y values for the polar wander,
154  and the UT1-UTC difference, in that order, corresponding to Julian date
155  jdUTC[0]+jdUTC[1]. */
156  status = PGS_TD_UTCtoUTCjd(asciiUTC, jdUTC);
157  if (status != PGS_S_SUCCESS) {
158  sprintf(msgbuf, "PGS_TD_UTCtoUTCjd(%s)", asciiUTC);
159  modsmf(MODIS_E_GEO, msgbuf, filefunc);
160  return MODIS_E_GEO;
161  }
162  else {
163  status = PGS_CSC_UTC_UT1Pole(jdUTC, &(utcpole_metadata->polar_motion[0]),
164  &(utcpole_metadata->polar_motion[1]),
165  &(utcpole_metadata->polar_motion[2]),
166  &jdtable);
167  if (status != PGSCSC_W_PREDICTED_UT1 && status != PGS_S_SUCCESS) {
168  sprintf(msgbuf, "PGS_CSC_UTC_UT1Pole(%s)", asciiUTC);
169  modsmf(MODIS_E_GEO, msgbuf, filefunc);
170  return MODIS_E_GEO;
171  }
172  }
173 
174  return retval;
175 }
176 
int status
Definition: l1_czcs_hdf.c:32
#define NULL
Definition: decode_rs.h:63
#define MODIS_E_BAD_INPUT_ARG
#define TIMECODEASIZE
Definition: Metadata.c:59
PGSt_SMF_status GEO_get_utcpole_metadata(const ECS_metadata_struct *ECS_metadata, utcpole_metadata_struct *utcpole_metadata)
#define MODIS_E_GEO
int errno
#define MODIS_E_PREMATURE_EOF
#define MAXMSGLEN
version
Definition: setup.py:15