OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
epr_ptrarray.c
Go to the documentation of this file.
1 /*
2  * $Id: epr_ptrarray.c,v 1.1.1.1 2004-10-28 19:22:23 norman Exp $
3  *
4  * Copyright (C) 2002 by Brockmann Consult (info@brockmann-consult.de)
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the
8  * Free Software Foundation. This program is distributed in the hope it will
9  * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
10  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16  */
17 
18 #include <assert.h>
19 #include <errno.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 
24 #include "epr_api.h"
25 #include "epr_ptrarray.h"
26 #include "epr_string.h"
27 
28 
29 EPR_SPtrArray* epr_create_ptr_array(unsigned int capacity)
30 {
31  EPR_SPtrArray* ptr_array = NULL;
32  void** elems = NULL;
33 
34  elems = (void**) calloc(capacity, sizeof (void*));
35  if (elems == NULL) {
36  return NULL;
37  }
38 
39  ptr_array = (EPR_SPtrArray*) calloc(1, sizeof (EPR_SPtrArray));
40  if (ptr_array == NULL) {
41  free(elems);
42  return NULL;
43  }
44 
45  ptr_array->capacity = capacity;
46  ptr_array->length = 0;
47  ptr_array->elems = elems;
48  return ptr_array;
49 }
50 
51 void epr_free_ptr_array(EPR_SPtrArray* ptr_array)
52 {
53  if (ptr_array == NULL)
54  return;
55  if (ptr_array->elems != NULL)
56  free(ptr_array->elems);
57  ptr_array->capacity = 0;
58  ptr_array->length = 0;
59  ptr_array->elems = NULL;
60  free(ptr_array);
61 }
62 
63 
64 
65 void epr_free_char_ptr_array(EPR_SPtrArray* char_ptr_array)
66 {
67  epr_uint i;
68  for (i = 0; i < char_ptr_array->length; i++) {
69  epr_free_string((char*) char_ptr_array->elems[i]);
70  }
71  epr_free_ptr_array(char_ptr_array);
72 }
73 
74 
75 int epr_add_ptr_array_elem(EPR_SPtrArray* ptr_array, void* elem)
76 {
77  assert(ptr_array != NULL);
78  assert(ptr_array->elems != NULL);
79 
80  if (ptr_array->length + 1 > ptr_array->capacity) {
81  int status = epr_grow_ptr_array(ptr_array, 2 * ptr_array->capacity);
82  if (status != 0)
83  return status;
84  }
85 
86  ptr_array->elems[ptr_array->length++] = elem;
87  return e_err_none;
88 }
89 
90 
91 int epr_grow_ptr_array(EPR_SPtrArray* ptr_array, unsigned int capacity)
92 {
93  void* elems = NULL;
94 
95  assert(ptr_array != NULL);
96  assert(capacity >= ptr_array->capacity);
97 
98  if (capacity == ptr_array->capacity)
99  return e_err_none;
100 
101  elems = (void**) realloc(ptr_array->elems, capacity * sizeof (void*));
102  if (elems == NULL)
103  return e_err_out_of_memory;
104 
105  memset(((char*)elems) + ptr_array->length * sizeof (void*),
106  0,
107  (capacity - ptr_array->length) * sizeof (void*));
108 
109  ptr_array->capacity = capacity;
110  ptr_array->elems = elems;
111  return e_err_none;
112 }
113 
114 
115 unsigned int epr_get_ptr_array_length(const EPR_SPtrArray* ptr_array)
116 {
117  assert(ptr_array != NULL);
118  return ptr_array->length;
119 }
120 
121 
122 void* epr_get_ptr_array_elem_at(const EPR_SPtrArray* ptr_array, unsigned int index)
123 {
124  assert(ptr_array != NULL);
125  assert(ptr_array->elems != NULL);
126  assert(index < ptr_array->length);
127  return ptr_array->elems[index];
128 }
129 
130 
an array had not been initialized Several spelling and grammar corrections were which is read from the appropriate MCF the above metadata values were hard coded A problem calculating the average background DN for SWIR bands when the moon is in the space view port was corrected The new algorithm used to calculate the average background DN for all reflective bands when the moon is in the space view port is now the same as the algorithm employed by the thermal bands For non SWIR changes in the averages are typically less than Also for non SWIR the black body DNs remain a backup in case the SV DNs are not available For SWIR the changes in computed averages were larger because the old which used the black body suffered from contamination by the micron leak As a consequence of the if SV DNs are not available for the SWIR the EV pixels will not be the granule time is used to identify the appropriate tables within the set given for one LUT the first two or last two tables respectively will be used for the interpolation If there is only one LUT in the set of it will be treated as a constant LUT The manner in which Earth View data is checked for saturation was changed Previously the raw Earth View DNs and Space View DNs were checked against the lookup table values contained in the table dn_sat The change made is to check the raw Earth and Space View DNs to be sure they are less than the maximum saturation value and to check the Space View subtracted Earth View dns against a set of values contained in the new lookup table dn_sat_ev The metadata configuration and ASSOCIATEDINSTRUMENTSHORTNAME from the MOD02HKM product The same metatdata with extensions and were removed from the MOD021KM and MOD02OBC products ASSOCIATEDSENSORSHORTNAME was set to MODIS in all products These changes are reflected in new File Specification which users may consult for exact the pow functions were eliminated in Emissive_Cal and Emissive bands replaced by more efficient code Other calculations throughout the code were also made more efficient Aside from a few round off there was no difference to the product The CPU time decreased by about for a day case and for a night case A minor bug in calculating the uncertainty index for emissive bands was corrected The frame index(0-based) was previously being used the frame number(1-based) should have been used. There were only a few minor changes to the uncertainty index(maximum of 1 digit). 3. Some inefficient arrays(Sigma_RVS_norm_sq) were eliminated and some code lines in Preprocess_L1A_Data were moved into Process_OBCEng_Emiss. There were no changes to the product. Required RAM was reduced by 20 MB. Now
void epr_free_char_ptr_array(EPR_SPtrArray *char_ptr_array)
Definition: epr_ptrarray.c:65
@ e_err_out_of_memory
Definition: epr_api.h:83
unsigned int epr_get_ptr_array_length(const EPR_SPtrArray *ptr_array)
Definition: epr_ptrarray.c:115
int status
Definition: l1_czcs_hdf.c:32
unsigned int epr_uint
Definition: epr_api.h:188
void epr_free_ptr_array(EPR_SPtrArray *ptr_array)
Definition: epr_ptrarray.c:51
#define NULL
Definition: decode_rs.h:63
@ e_err_none
Definition: epr_api.h:77
int epr_grow_ptr_array(EPR_SPtrArray *ptr_array, unsigned int capacity)
Definition: epr_ptrarray.c:91
void * epr_get_ptr_array_elem_at(const EPR_SPtrArray *ptr_array, unsigned int index)
Definition: epr_ptrarray.c:122
int epr_add_ptr_array_elem(EPR_SPtrArray *ptr_array, void *elem)
Definition: epr_ptrarray.c:75
int i
Definition: decode_rs.h:71
void epr_free_string(char *str)
Definition: epr_string.c:100
EPR_SPtrArray * epr_create_ptr_array(unsigned int capacity)
Definition: epr_ptrarray.c:29