OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
GEO_get_ephatt_inputs.c
Go to the documentation of this file.
1 #include <errno.h>
2 #include <stdio.h>
3 #include "PGS_IO.h"
4 #include "smfio.h"
5 #include "GEO_earth.h"
6 #include "GEO_product.h"
7 #include "PGS_MODIS_35251.h"
8 
9 /* Used internally by the EPH portion of the SDP Toolkit library. */
10 extern int byteswap(char *, int);
11 
12 PGSt_SMF_status GEO_get_ephatt_inputs(
13  PGSt_PC_Logical file_logical,
14  PGSt_integer file_version,
15  char universal_references[][PGSd_UR_FIELD_SIZE]
16 ){
83  PGSt_IO_Gen_FileHandle *handle;
84  PGSt_ephemHeader fileHeader;
85  PGSt_SMF_status retval = PGS_S_SUCCESS;
86  char filefunc[] = __FILE__ ", GEO_get_ephatt_inputs";
87  char msgbuf[256];
88 
89  if(universal_references == NULL)
90  {
91  modsmf(MODIS_E_BAD_INPUT_ARG, "universal_references is null",
92  filefunc);
93 
94  return MODIS_E_BAD_INPUT_ARG;
95  }
96 
97  if(PGS_IO_Gen_Open(file_logical, PGSd_IO_Gen_Read, &handle, file_version)
98  != PGS_S_SUCCESS)
99  {
100  sprintf(msgbuf, "PGS_IO_Gen_Open(%ld, %ld)",
101  (long)file_logical, (long)file_version);
102  modsmf(MODIS_E_GEO, msgbuf, filefunc);
103 
104  return MODIS_E_GEO;
105  }
106 
107  errno = 0;
108  if(fread(&fileHeader, sizeof fileHeader, 1, handle) != 1)
109  {
110  if(errno)
111  PGS_SMF_SetUNIXMsg(errno, "during fread(fileHeader)", filefunc);
112  else
113  modsmf(MODIS_E_GEO, "fread(fileHeader)", filefunc);
114 
115  retval = PGS_E_UNIX;
116  }
117  else
118  {
119  /* Simplistic byte-order check, borrowed from PGS_EPH_GetEphMet() */
120  if(fileHeader.nURs > 100)
121  byteswap((char*)&fileHeader.nURs, sizeof fileHeader.nURs);
122 
123  if(fileHeader.nURs > MAX_EA_INPUTS)
124  fileHeader.nURs = MAX_EA_INPUTS;
125 
126  if(fread(universal_references, PGSd_UR_FIELD_SIZE, fileHeader.nURs,
127  handle) != fileHeader.nURs)
128  {
129  if(errno)
130  PGS_SMF_SetUNIXMsg(errno, "during fread(universal_references",
131  filefunc);
132  else
133  modsmf(MODIS_E_GEO, "fread(universal_references)", filefunc);
134 
135  retval = PGS_E_UNIX;
136  }
137  else if(fileHeader.nURs < MAX_EA_INPUTS)
138  /*Terminate the array with an empty string. */
139  universal_references[fileHeader.nURs][0] = '\0';
140  }
141 
142  if(PGS_IO_Gen_Close(handle) != PGS_S_SUCCESS)
143  modsmf(MODIS_E_GEO, "PGE_IO_Gen_Close()", filefunc);
144 
145  return retval;
146 }
147 
#define NULL
Definition: decode_rs.h:63
#define MODIS_E_BAD_INPUT_ARG
PGSt_SMF_status GEO_get_ephatt_inputs(PGSt_PC_Logical file_logical, PGSt_integer file_version, char universal_references[][PGSd_UR_FIELD_SIZE])
#define MODIS_E_GEO
int byteswap(char *, int)
int errno
#define MAX_EA_INPUTS
Definition: GEO_product.h:254