OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
epr_param.c
Go to the documentation of this file.
1 /*
2  * $Id: epr_param.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_core.h"
26 #include "epr_string.h"
27 #include "epr_ptrarray.h"
28 #include "epr_swap.h"
29 #include "epr_field.h"
30 #include "epr_record.h"
31 #include "epr_param.h"
32 #include "epr_dsd.h"
33 #include "epr_msph.h"
34 #include "epr_band.h"
35 #include "epr_bitmask.h"
36 
37 
46 EPR_SParamElem* epr_create_param_elem(const char* param_name, int param_value)
47 {
48  EPR_SParamElem* param_elem = NULL;
49 /*
50  LINE_LENGTH=+02241<samples>
51  -1
52  /
53  LINES_PER_TIE_PT=+064
54  +1
55  =
56  */
57  param_elem = (EPR_SParamElem*) calloc(1, sizeof (EPR_SParamElem));
58  if (param_elem == NULL) {
60  "epr_create_field_info: out of memory");
61  return NULL;
62  }
63 
64  param_elem->param_name = epr_clone_string(param_name);
65  param_elem->param_value = param_value;
66 
67  return param_elem;
68 }
69 
70 EPR_SPtrArray* epr_create_param_table()
71 {
72  EPR_SPtrArray* param_table = NULL;
74  return param_table;
75 }
76 
86 void epr_free_param_table(EPR_SPtrArray* param_table)
87 {
88  EPR_SParamElem* param_elem = NULL;
89  int param_index = 0;
90 
91  if (param_table == NULL)
92  return;
93 
94  for (param_index = 0; param_index < (int)param_table->length; param_index++) {
95  param_elem = (EPR_SParamElem*)epr_get_ptr_array_elem_at(param_table, param_index);
96  epr_free_param_elem(param_elem);
97  }
98 
100 }
101 
102 
112 void epr_free_param_elem(EPR_SParamElem* param_elem)
113 {
114 
115  if (param_elem == NULL)
116  return;
117  epr_free_string(param_elem->param_name);
118  param_elem->param_name = NULL;
119  param_elem->param_value = 0;
120 
121  free(param_elem);
122  return;
123 }
124 
125 
127 {
128  const EPR_SField* field;
129  const EPR_SField* product_field;
130  char* tmp;
131  EPR_SParamElem* param_elem = NULL;
132 
133  epr_uint line_length = 0;
134  epr_uint num_tie_points_across = 0;
135  epr_uint ntpa = 0;
136 
137  product_field = epr_get_field(product_id->mph_record, "PRODUCT");
138  tmp = epr_sub_string((char*)product_field->elems, 0, 3);
139  /* MERIS */
140  if (strcmp(EPR_ENVISAT_PRODUCT_MERIS, tmp) == 0) {
141  if (product_id->sph_record == NULL) {
142  product_id->sph_record = epr_read_sph(product_id);
143  if (product_id->sph_record == NULL) {
144  epr_set_err(e_err_file_read_error, "epr_set_param: wrong SPH");
146  return 0;
147  }
148  }
149 
150  field = epr_get_field(product_id->sph_record, "LINE_LENGTH");
151  if (field == NULL) {
153  "epr_set_param: wrong SPH: unable to read LINE_LENGTH");
155  return 0;
156  }
157 
158  line_length = ((epr_uint*) field->elems)[0];
159  if (line_length == 0) {
161  "epr_set_param: wrong SPH: LINE_LENGTH must be > 0");
163  return 0;
164  }
165 
166  field = epr_get_field(product_id->sph_record, "LINES_PER_TIE_PT");
167  if (field == NULL) {
169  "epr_set_param: wrong SPH: unable to read LINES_PER_TIE_PT");
171  return 0;
172  }
173 
174  num_tie_points_across = ((epr_uint*) field->elems)[0];
175  if (num_tie_points_across == 0) {
177  "epr_set_param: wrong SPH: LINES_PER_TIE_PT must be > 0");
179  return 0;
180  }
181 
182  param_elem = epr_create_param_elem("sceneRasterWidth", line_length);
183  epr_add_ptr_array_elem(product_id->param_table, param_elem);
184 
185  ntpa = ((line_length - 1) / num_tie_points_across) + 1;
186 
187  param_elem = epr_create_param_elem("tiePointGridWidth", ntpa);
188  epr_add_ptr_array_elem(product_id->param_table, param_elem);
189 
190  }
191 
192  /* AATSR does NOT have any dynamic parameters in DDDB */
193 
194  /* ASAR */
195  else if ((strcmp(EPR_ENVISAT_PRODUCT_ASAR, epr_sub_string((char*)product_field->elems, 0, 3)) == 0) ||
196  (strcmp(EPR_ENVISAT_PRODUCT_SAR, epr_sub_string((char*)product_field->elems, 0, 3)) == 0)) {
197 
198  field = epr_get_field(product_id->sph_record, "LINE_LENGTH");
199  if (field == NULL) {
201  "epr_set_param: wrong SPH: unable to read LINE_LENGTH");
203  return 0;
204  }
205 
206  line_length = ((epr_uint*) field->elems)[0];
207  if (line_length == 0) {
209  "epr_set_param: wrong SPH: LINE_LENGTH must be > 0");
211  return 0;
212  }
213 
214  param_elem = epr_create_param_elem("sceneRasterWidth", line_length);
215  epr_add_ptr_array_elem(product_id->param_table, param_elem);
216 
217  param_elem = epr_create_param_elem("tiePointGridWidth", EPR_ASAR_NUM_PER_POINT_ACROSS_LOCAT);
218  epr_add_ptr_array_elem(product_id->param_table, param_elem);
219  }
220 
222  return 1;
223 }
@ e_err_out_of_memory
Definition: epr_api.h:83
#define EPR_ASAR_NUM_PER_POINT_ACROSS_LOCAT
Definition: epr_core.h:78
unsigned int epr_uint
Definition: epr_api.h:188
void epr_free_ptr_array(EPR_SPtrArray *ptr_array)
Definition: epr_ptrarray.c:51
char * param_name[]
Definition: l2lists.h:16
#define NULL
Definition: decode_rs.h:63
int epr_set_dyn_dddb_params(EPR_SProductId *product_id)
Definition: epr_param.c:126
char * epr_sub_string(const char *str, int start, int length)
Definition: epr_string.c:62
const EPR_SField * epr_get_field(const EPR_SRecord *record, const char *field_name)
Definition: epr_field.c:247
#define EPR_ENVISAT_PRODUCT_SAR
Definition: epr_core.h:39
data_t tmp
Definition: decode_rs.h:74
char * epr_clone_string(const char *str)
Definition: epr_string.c:43
@ e_err_file_read_error
Definition: epr_api.h:91
@ e_err_invalid_value
Definition: epr_api.h:108
void epr_free_param_table(EPR_SPtrArray *param_table)
Definition: epr_param.c:86
What value is used by your function when the data value is bad Default is BAD_FLT l2prod product_id[0]
EPR_SPtrArray * epr_create_param_table()
Definition: epr_param.c:70
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
void epr_set_err(EPR_EErrCode err_code, const char *err_message)
Definition: epr_core.c:221
#define EPR_ENVISAT_PRODUCT_MERIS
Definition: epr_core.h:37
#define EPR_ENVISAT_PRODUCT_ASAR
Definition: epr_core.h:38
EPR_SParamElem * epr_create_param_elem(const char *param_name, int param_value)
Definition: epr_param.c:46
void epr_free_string(char *str)
Definition: epr_string.c:100
void epr_free_param_elem(EPR_SParamElem *param_elem)
Definition: epr_param.c:112
EPR_SRecord * epr_read_sph(EPR_SProductId *product_id)
Definition: epr_msph.c:92
EPR_SPtrArray * epr_create_ptr_array(unsigned int capacity)
Definition: epr_ptrarray.c:29