OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
emeta.c
Go to the documentation of this file.
1 /*
2  * Name: emeta.c
3  *
4  * Purpose:
5  * Source file containing the functions used to allocate and release memory in the
6  * enhanced metadata structure.
7  */
8 #include <stdlib.h>
9 #include "ias_logging.h"
10 #include "emeta.h"
11 
13  EMETA *emeta, /* Enhanced metadata structure */
14  int nephem ) /* Number of ephemeris points required */
15 {
16  EMETA_EPHEM *local_ephem = NULL; /* Local pointer to allocated buffer */
17 
18  /* Check the number of points requested */
19  if ( nephem < 1 )
20  {
21  IAS_LOG_ERROR("Invalid number of ephemeris samples requested.");
22  return(ERROR);
23  }
24 
25  /* Allocate the ephemeris array */
26  local_ephem = (EMETA_EPHEM *)malloc( nephem * sizeof( EMETA_EPHEM ) );
27  if ( local_ephem == NULL )
28  {
29  IAS_LOG_ERROR("Unable to allocate enhanced metadata ephemeris structure.");
30  return(ERROR);
31  }
32 
33  /* Set the ephemeris pointer in the EMETA structure */
34  emeta->ephemeris = local_ephem;
35 
36  /* Allocate the sunvector array */
37  local_ephem = (EMETA_EPHEM *)malloc( nephem * sizeof( EMETA_EPHEM ) );
38  if ( local_ephem == NULL )
39  {
40  IAS_LOG_ERROR("Unable to allocate enhanced metadata solar ECEF vector structure.");
41  free( emeta->ephemeris );
42  return(ERROR);
43  }
44 
45  /* Set the sunvector pointer in the EMETA structure */
46  emeta->sunvector = local_ephem;
47 
48  return(SUCCESS);
49 }
50 
52  EMETA *emeta ) /* Enhanced metadata structure */
53 {
54  free( emeta->ephemeris );
55  free( emeta->sunvector );
56  return;
57 }
58 
#define SUCCESS
Definition: ObpgReadGrid.h:15
#define IAS_LOG_ERROR(format,...)
Definition: ias_logging.h:96
void emeta_free_ephemeris(EMETA *emeta)
Definition: emeta.c:51
int emeta_allocate_ephemeris(EMETA *emeta, int nephem)
Definition: emeta.c:12
#define NULL
Definition: decode_rs.h:63
Definition: emeta.h:102
EMETA_EPHEM * sunvector
Definition: emeta.h:115
EMETA_EPHEM * ephemeris
Definition: emeta.h:114
#define ERROR
Definition: ancil.h:24