OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
epr_band.c
Go to the documentation of this file.
1 /*
2  * $Id: epr_band.c,v 1.2 2009-03-27 10:25:54 sabine 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 #include <math.h>
24 
25 #include "epr_api.h"
26 #include "epr_core.h"
27 #include "epr_string.h"
28 #include "epr_ptrarray.h"
29 #include "epr_swap.h"
30 #include "epr_field.h"
31 #include "epr_record.h"
32 #include "epr_param.h"
33 #include "epr_dsd.h"
34 #include "epr_msph.h"
35 #include "epr_band.h"
36 #include "epr_bitmask.h"
37 
38 #include "epr_dddb.h"
39 
43 EPR_SPtrArray* epr_create_band_ids(EPR_SProductId* product_id) {
44  EPR_SBandId* band_id = NULL;
45  EPR_SPtrArray* band_ids = NULL;
46  char test_block[1024];
47  int bt_index;
48  int i;
49  const struct BandDescriptorTable* b_tables;
50  int num_descr;
51 
52  if (product_id == NULL) {
54  "epr_create_band_ids: product_id must not be NULL");
55  return NULL;
56  }
57 
58 
59  /* @DDDB */
60 
61  b_tables = dddb_band_tables;
62  bt_index = -1;
63  for (i = 0; i < EPR_NUM_BAND_TABLES; i++) {
64  const char* id = b_tables[i].name;
65  if (strncmp(product_id->id_string, id, 10) == 0) {
66  if (product_id->meris_iodd_version == 5) {
67  if (strcmp(id, "MER_RR__1P_IODD5") == 0 ||
68  strcmp(id, "MER_FR__1P_IODD5") == 0) {
69  bt_index = i;
70  }
71  } else if (product_id->meris_iodd_version == 6) {
72  if (strcmp(id, "MER_RR__2P_IODD6") == 0 ||
73  strcmp(id, "MER_FR__2P_IODD6") == 0) {
74  bt_index = i;
75  }
76  } else {
77  bt_index = i;
78  }
79  }
80  if (bt_index != -1) {
81  break;
82  }
83  }
84  if (bt_index == -1) {
86  "epr_create_band_ids: unknown product type");
87  return NULL;
88  }
89 
90  band_ids = epr_create_ptr_array(16);
91  num_descr = b_tables[bt_index].num_descriptors;
92  for (i = 0; i < num_descr; i++) {
93 
94  band_id = (EPR_SBandId*) calloc(1, sizeof (EPR_SBandId));
95  if (band_id == NULL) {
97  "epr_create_band_ids: out of memory");
98  return NULL;
99  }
100  band_id->magic = EPR_MAGIC_BAND_ID;
101  band_id->product_id = product_id;
102 
103  /* 1: band_name */
104  epr_assign_string(&band_id->band_name, b_tables[bt_index].descriptors[i].id);
105  /* 2: dataset_name */
106  band_id->dataset_ref = epr_get_ref_struct(product_id, b_tables[bt_index].descriptors[i].rec_name);
107  if (band_id->dataset_ref.dataset_id == NULL) {
109  "epr_create_band_ids: invalid dataset name in DDDB");
110  epr_free_band_id(band_id);
111  return NULL;
112  }
113  /* 3: sample_offset */
114  band_id->sample_model = b_tables[bt_index].descriptors[i].sample_offset;
115  /* 4: band_datatype */
116  band_id->data_type = b_tables[bt_index].descriptors[i].type;
117  /* 5: spectr_band_index*/
118  band_id->spectr_band_index = b_tables[bt_index].descriptors[i].spectral_index;
119  /* 6: scaling_method*/
120  if (b_tables[bt_index].descriptors[i].scale_method == e_smid_non) {
121  band_id->scaling_method = 0;
122  band_id->scaling_offset = 0.0;
123  band_id->scaling_factor = 1.0;
124  } else {
125  band_id->scaling_method = b_tables[bt_index].descriptors[i].scale_method;
126  /* 7: scaling_offset*/
127  strcpy (test_block, b_tables[bt_index].descriptors[i].scale_offset);
128  float scaling_offset = (float)atof(test_block);
129  if (epr_numeral_suspicion(test_block) == 1) {
130  band_id->scaling_offset = scaling_offset;
131  } else {
132  scaling_offset = epr_get_scaling_params(product_id, test_block);
133  if (scaling_offset == -909.909) { /* @todo what an ugly return value. Eeeek!*/
135  "epr_create_band_ids: invalid dataset name in dddb");
136  epr_free_band_id(band_id);
137  return NULL;
138  }
139  band_id->scaling_offset = scaling_offset;
140  }
141  /* 8: scaling_factor*/
142  strcpy (test_block, b_tables[bt_index].descriptors[i].scale_factor);
143  float scaling_factor = (float)atof(test_block);
144  if (epr_numeral_suspicion(test_block) == 1) {
145  band_id->scaling_factor = scaling_factor;
146  } else {
147  scaling_factor = epr_get_scaling_params(product_id, test_block);
148  if (scaling_factor == -909.909) { /* @todo what an ugly return value. Eeeek!*/
150  "epr_create_band_ids: invalid dataset name in dddb");
151  epr_free_band_id(band_id);
152  return NULL;
153  }
154  band_id->scaling_factor = scaling_factor;
155  }
156  }
157  /* 9: bit_expr*/
158  epr_assign_string(&band_id->bm_expr, b_tables[bt_index].descriptors[i].bitmask_expr);
159  /* 10: flags_definition_file*/
160  if (b_tables[bt_index].descriptors[i].flag_coding_name != NULL) {
161  band_id->flag_coding = epr_create_flag_coding(product_id, b_tables[bt_index].descriptors[i].flag_coding_name);
162  if (band_id->flag_coding == NULL) {
164  "epr_create_band_ids: out of memory");
165  epr_free_band_id(band_id);
166  return NULL;
167  }
168  } else {
169  band_id->flag_coding = NULL;
170  }
171  /* 11: unit*/
172  epr_assign_string(&band_id->unit, b_tables[bt_index].descriptors[i].unit);
173  /* 12: description*/
174  epr_assign_string(&band_id->description, b_tables[bt_index].descriptors[i].description);
175 
176  /* lines_flipped*/
177  if (strncmp(product_id->id_string, EPR_ENVISAT_PRODUCT_MERIS, 3) == 0
178  || strncmp(product_id->id_string, EPR_ENVISAT_PRODUCT_AATSR, 3) == 0) {
179  band_id->lines_mirrored = EPR_TRUE;
180  } else {
181  if (strncmp(product_id->id_string, EPR_ENVISAT_PRODUCT_ASAR, 3) == 0
182  && strncmp(product_id->id_string, "ASA_IMG", 7) != 0
183  && strncmp(product_id->id_string, "ASA_APG", 7) != 0) {
184  band_id->lines_mirrored = EPR_TRUE;
185  } else {
186  if (strncmp(product_id->id_string, EPR_ENVISAT_PRODUCT_SAR, 3) == 0
187  && strncmp(product_id->id_string, "SAR_IMG", 7) != 0
188  && strncmp(product_id->id_string, "SAR_APG", 7) != 0) {
189  band_id->lines_mirrored = EPR_TRUE;
190  } else {
191  band_id->lines_mirrored = EPR_FALSE;
192  }
193  }
194  }
195 
196  epr_add_ptr_array_elem(band_ids, band_id);
197  }
198 
199  return band_ids;
200 }
201 
202 
204  epr_clear_err();
205  if (!epr_check_api_init_flag()) {
206  return 0;
207  }
208 
209  if (product_id == NULL) {
211  "epr_get_num_bands: product_id must not be NULL");
212  return (epr_uint) -1;
213  }
214  return product_id->band_ids->length;
215 }
216 
217 EPR_SBandId* epr_get_band_id_at(EPR_SProductId* product_id, epr_uint index) {
218  EPR_SBandId* band_id = NULL;
219 
220  epr_clear_err();
221 
222  if (product_id == NULL) {
224  "epr_get_band_id_at: product_id must not be NULL");
225  return NULL;
226  }
227  if (index >= product_id->band_ids->length) {
229  "epr_get_band_id_at: band index out of range");
230  return NULL;
231  }
232 
233  band_id = (EPR_SBandId*)epr_get_ptr_array_elem_at(product_id->band_ids, index);
234  return band_id;
235 }
236 
237 EPR_SBandId* epr_get_band_id(EPR_SProductId* product_id, const char* band_name) {
238  EPR_SBandId* band_id = NULL;
239  int num_bands, i;
240 
241  epr_clear_err();
242 
243  if (product_id == NULL) {
245  "epr_get_band_id: product_id must not be NULL");
246  return NULL;
247  }
248  if (band_name == NULL) {
250  "epr_get_band_id: dataset_name must not be NULL");
251  return NULL;
252  }
253 
254  num_bands = epr_get_num_bands(product_id);
255  for (i = 0; i < num_bands; i++) {
256  band_id = epr_get_band_id_at(product_id, i);
257  if (epr_equal_names(band_name, epr_get_band_name(band_id))) {
258  return band_id;
259  }
260  }
262  "epr_get_band_id: band not found");
263  return NULL;
264 }
265 
266 const char* epr_get_band_name(EPR_SBandId* band_id) {
267  epr_clear_err();
268 
269  if (band_id == NULL) {
271  "epr_get_band_name: band_id must not be NULL");
272  return NULL;
273  }
274  return band_id->band_name;
275 }
276 
284 void epr_free_band_id(EPR_SBandId* band_id) {
285  if (band_id == NULL)
286  return;
287 
288  band_id->dataset_ref.elem_index = -1;
289  band_id->dataset_ref.field_index = -1;
290  band_id->dataset_ref.dataset_id = NULL;
291 
292  epr_free_and_null_string(&band_id->band_name);
293  epr_free_and_null_string(&band_id->bm_expr);
294 
295  epr_free_flag_coding(band_id->flag_coding);
296  band_id->flag_coding = NULL;
297 
298  band_id->spectr_band_index = 0;
299  band_id->scaling_offset = 0;
300  band_id->scaling_factor = 0;
301  band_id->data_type = e_tid_unknown;
302 
303  epr_free_and_null_string(&band_id->unit);
304  epr_free_and_null_string(&band_id->description);
305 
306  band_id->lines_mirrored = EPR_FALSE;
307 
308  free(band_id);
309 }
310 
311 
320 float epr_get_scaling_params(EPR_SProductId* product_id, const char* str) {
321  EPR_SDatasetRef scal_fact;
322  const EPR_SField* field = NULL;
323  EPR_SRecord* record = NULL;
324  float ziff;
325 
326  scal_fact = epr_get_ref_struct(product_id, str);
327  if (scal_fact.dataset_id == NULL) {
328  return (float)(-909.909);
329  }
330 
331  /*'Scaling_Factor_GADS'*/
332  record = epr_create_record(scal_fact.dataset_id);
333  record = epr_read_record(scal_fact.dataset_id, 0, record);
334 
335  field = epr_get_field_at(record, scal_fact.field_index - 1);
336  ziff = epr_get_field_elem_as_float(field, (epr_uint)(scal_fact.elem_index - 1));
337 
338  epr_free_record(record);
339 
340  return ziff;
341 }
342 
343 
352 float epr_get_scaling_factor(EPR_SProductId* product_id, const char* str) {
353  EPR_SDatasetRef scal_fact;
354  const EPR_SField* field = NULL;
355  EPR_SRecord* record = NULL;
356  float ziff;
357 
358  scal_fact = epr_get_ref_struct(product_id, str);
359  if (scal_fact.dataset_id == NULL) {
360  return (float)(-909.909);
361  }
362 
363  /*'Scaling_Factor_GADS'*/
364  record = epr_create_record(scal_fact.dataset_id);
365  record = epr_read_record(scal_fact.dataset_id, 0, record);
366 
367  field = epr_get_field_at(record, scal_fact.field_index - 1);
368  ziff = epr_get_field_elem_as_float(field, (epr_uint)(scal_fact.elem_index - 1));
369 
370  epr_free_record(record);
371 
372  return ziff;
373 }
374 
383 EPR_SDatasetRef epr_get_ref_struct(EPR_SProductId* product_id, const char* str) {
384  EPR_SDatasetRef ref_struct;
385  int pos = 0;
386  char* stopstring;
387  char* token;
388 
389  ref_struct.dataset_id = NULL;
390  ref_struct.field_index = -1;
391  ref_struct.elem_index = -1;
392 
393  token = epr_str_tok(str, ".", &pos);
394 
395  ref_struct.dataset_id = epr_get_dataset_id(product_id, token);
396  if (ref_struct.dataset_id == NULL) {
397  epr_free_and_null_string(&token);
398  return ref_struct;
399  }
400  epr_free_and_null_string(&token);
401 
402  token = epr_str_tok(str, ".", &pos);
403  if (token == NULL) {
404  ref_struct.field_index = -1;
405  } else {
406  ref_struct.field_index = strtol(token, &stopstring, 10);
407  }
408  epr_free_and_null_string(&token);
409 
410  token = epr_str_tok(str, ".", &pos);
411  if (token == NULL) {
412  ref_struct.elem_index = -1;
413  } else {
414  ref_struct.elem_index = strtol(token, &stopstring, 10);
415  }
416  epr_free_and_null_string(&token);
417 
418  return ref_struct;
419 }
420 
430  assert(str != NULL);
431  if (epr_equal_names(str, "Linear_Scale"))
432  return e_smid_lin;
433  else if (epr_equal_names(str, "Log_Scale"))
434  return e_smid_log;
435  else
436  return e_smid_non;
437 }
438 
439 
449  assert(str != NULL);
450  if (epr_equal_names(str, "1OF2"))
451  return e_smod_1OF2;
452  else if (epr_equal_names(str, "2OF2"))
453  return e_smod_2OF2;
454  else if (epr_equal_names(str, "3TOI"))
455  return e_smod_3TOI;
456  else if (epr_equal_names(str, "2TOF"))
457  return e_smod_2TOF;
458  else
459  return e_smod_1OF1;
460 }
461 
472 EPR_SRaster* epr_create_bitmask_raster(epr_uint source_width,
473  epr_uint source_height,
474  epr_uint source_step_x,
475  epr_uint source_step_y) {
477  source_width,
478  source_height,
479  source_step_x,
480  source_step_y);
481 }
482 
483 
495 EPR_SRaster* epr_create_raster(EPR_EDataTypeId data_type,
496  epr_uint source_width,
497  epr_uint source_height,
498  epr_uint source_step_x,
499  epr_uint source_step_y) {
500  EPR_SRaster* raster = NULL;
501  epr_uint num_elems;
502 
503  epr_clear_err();
504 
505  if (data_type == e_tid_string ||
506  data_type == e_tid_spare ||
507  data_type == e_tid_time) {
508  epr_set_err(e_err_illegal_data_type, "epr_create_raster: illegal data type");
509  return NULL;
510  }
511 
512  raster = (EPR_SRaster*) calloc(1, sizeof (EPR_SRaster));
513  if (raster == NULL) {
514  epr_set_err(e_err_out_of_memory, "epr_create_raster: out of memory");
515  return NULL;
516  }
517 
518 
519  raster->magic = EPR_MAGIC_RASTER;
520  raster->data_type = data_type;
521  raster->elem_size = epr_get_data_type_size(data_type);
522  raster->source_height = source_height;
523  raster->source_width = source_width;
524  raster->source_step_x = source_step_x;
525  raster->source_step_y = source_step_y;
526  raster->raster_width = (source_width - 1) / source_step_x + 1;
527  raster->raster_height = (source_height - 1) / source_step_y + 1;
528 
529  num_elems = raster->raster_width * raster->raster_height;
530 
531  raster->buffer = calloc(raster->elem_size, num_elems);
532  if (raster->buffer == NULL) {
533  epr_free_raster(raster);
534  epr_set_err(e_err_out_of_memory, "epr_create_raster: out of memory");
535  return NULL;
536  }
537 
538  return raster;
539 }
540 
541 
549 EPR_SRaster* epr_create_compatible_raster(EPR_SBandId* band_id,
550  epr_uint source_width,
551  epr_uint source_height,
552  epr_uint source_step_x,
553  epr_uint source_step_y) {
554  epr_clear_err();
555 
556  if (band_id == NULL) {
557  epr_set_err(e_err_invalid_band, "epr_create_raster: band_id must not be NULL");
558  return NULL;
559  }
560  return epr_create_raster(band_id->data_type,
561  source_width,
562  source_height,
563  source_step_x,
564  source_step_y);
565 }
566 
567 
568 void epr_free_raster(EPR_SRaster* raster) {
569  epr_clear_err();
570 
571  if (raster == NULL)
572  return;
573 
574  raster->data_type = e_tid_unknown;
575  raster->elem_size = 0;
576  raster->raster_height = 0;
577  raster->raster_width = 0;
578  raster->source_height = 0;
579  raster->source_width = 0;
580  raster->source_step_x = 0;
581  raster->source_step_y = 0;
582 
583  if (raster->buffer != NULL) {
584  free(raster->buffer);
585  raster->buffer = NULL;
586  }
587 
588  free(raster);
589 }
590 
591 
592 
593 int epr_read_band_raster(EPR_SBandId* band_id,
594  int offset_x,
595  int offset_y,
596  EPR_SRaster* raster/*, EPR_SRaster** bitmask_raster*/) {
597 
598  EPR_SProductId* product_id = NULL;
599  EPR_SDatasetId* dataset_id = NULL;
600  char* rec_type;
601 
602  epr_clear_err();
603 
604  if (band_id == NULL) {
606  "epr_read_band_raster: band_id must not be NULL");
607  return epr_get_last_err_code();
608  }
609  if (band_id->data_type != raster->data_type) {
611  "epr_read_band_raster: illegal raster data type");
612  return epr_get_last_err_code();
613  }
614  if (raster->buffer == NULL) {
616  "epr_read_band_raster: raster->buffer must not be NULL");
617  return epr_get_last_err_code();
618  }
619  if ((offset_x<0) || (offset_y<0) || (raster->raster_width<0) || (raster->raster_height<0) || (raster->source_step_x<0) || (raster->source_step_y<0)) {
621  "epr_read_band_raster: all digit parameter must be positive");
622  return epr_get_last_err_code();
623  }
624  /* removed because the source_step_x can truly be greater than raster_width.
625  if ((raster->source_step_x>raster->raster_width) || (raster->source_step_y>raster->raster_height)) {
626  epr_set_err(e_err_invalid_value,
627  "epr_read_band_raster: too small raster sizes or large steps");
628  return epr_get_last_err_code();
629  }
630  */
631  product_id = band_id->product_id;
632  dataset_id = band_id->dataset_ref.dataset_id;
633  rec_type = dataset_id->dsd->ds_type;
634  if (strcmp(rec_type, "M") == 0) {
635  if (epr_read_band_measurement_data(band_id,
636  offset_x,
637  offset_y,
638  raster) != 0) {
640  "epr_read_band_raster: unsuccessfully reading band measurement data");
641  return epr_get_last_err_code();
642  }
643  if (band_id->bm_expr != NULL) {
644  EPR_SRaster* bm_raster;
645 
646  bm_raster = epr_create_raster(e_tid_uchar, /*was char*/
647  raster->source_width,
648  raster->source_height,
649  raster->source_step_x,
650  raster->source_step_y);
651 
652 
654  band_id->bm_expr,
655  offset_x,
656  offset_y,
657  bm_raster);
658 
659  epr_zero_invalid_pixels(raster, bm_raster);
660 
661  epr_free_raster(bm_raster);
662 
663  }
664  } else if (strcmp(rec_type, "A") == 0) {
666  (band_id, offset_x, offset_y, raster) == 1) {
668  "epr_read_band_raster: unsuccessfully reading band annotation data");
669  return epr_get_last_err_code();
670  }
671  } else {
673  "epr_read_band_raster: illegat DS-TYPE; 'A' or'M' will be accepted");
674  return epr_get_last_err_code();
675  }
676  return e_err_none;
677 }
678 
689 int epr_read_band_measurement_data(EPR_SBandId* band_id,
690  int offset_x,
691  int offset_y,
692  EPR_SRaster* raster) {
693  EPR_SProductId* product_id = NULL;
694  const EPR_SField* field = NULL;
695  EPR_SFieldInfo* field_info = NULL;
696  EPR_SDatasetId* dataset_id = NULL;
697  EPR_SRecord* record = NULL;
698  EPR_SRecord* sph_record = NULL;
699  EPR_EDataTypeId band_datatype, datatype_id;
700  EPR_ESampleModel band_smod;
701  //epr_uint rec_size;
702  epr_uint rec_numb;
703  int iY, raster_pos, delta_raster_pos;
704  int offset_x_mirrored = 0;
705  epr_uint scan_line_length;
706  EPR_FLineDecoder decode_func;
707  epr_uint scene_width;
708 
709  product_id = band_id->product_id;
710 
711  if (strncmp(EPR_ENVISAT_PRODUCT_MERIS, product_id->id_string, 3) == 0) {
712  sph_record = product_id->sph_record;
713  field = epr_get_field(sph_record, "LINE_LENGTH");
714  scan_line_length = epr_get_field_elem_as_uint(field, 0);
715  } else if (strncmp(EPR_ENVISAT_PRODUCT_AATSR, product_id->id_string, 3) == 0) {
716  scan_line_length = EPR_ATS_LINE_LENGTH;
717  } else if (strncmp(EPR_ENVISAT_PRODUCT_ASAR, product_id->id_string, 3) == 0) {
718  scan_line_length = epr_get_scene_width(product_id);
719  } else if (strncmp(EPR_ENVISAT_PRODUCT_SAR, product_id->id_string, 3) == 0) {
720  scan_line_length = epr_get_scene_width(product_id);
721  } else {
723  "epr_read_band_measurement_data: scan line length unknown");
724  return epr_get_last_err_code();
725  }
726 
727  dataset_id = band_id->dataset_ref.dataset_id;
728  /*the length of measurement record size*/
729  //rec_size = dataset_id->dsd->dsr_size;
730  /*the number of measurement records*/
731  rec_numb = dataset_id->dsd->num_dsr;
732  /*data type in the band*/
733  band_datatype = band_id->data_type;
734  /*data model in the band*/
735  band_smod = band_id->sample_model;
736  record = epr_create_record(dataset_id);
737  field_info = (EPR_SFieldInfo*)epr_get_ptr_array_elem_at(record->info->field_infos, band_id->dataset_ref.field_index - 1);
738  datatype_id = field_info->data_type_id;
739 
740  /* if the user raster (or part of) is outside bbox in source coordinates*/
741  if (offset_x + raster->raster_width > (int)scan_line_length) {
743  "epr_read_band_measurement_data: raster x co-ordinates out of bounds");
744  epr_free_record(record);
745  return epr_get_last_err_code();
746  }
747  if (offset_y + raster->raster_height > (int)(rec_numb)) {
749  "epr_read_band_measurement_data: raster y co-ordinates out of bounds");
750  epr_free_record(record);
751  return epr_get_last_err_code();
752  }
753  raster_pos = 0;
754  delta_raster_pos = (int)floor((raster->source_width - 1) / raster->source_step_x) + 1;
755 
756  /*select the correspondent function to scaling and transform data type*/
757  decode_func = select_line_decode_function(band_datatype, band_smod, datatype_id);
758  if (decode_func == NULL) {
760  "epr_read_band_measurement_data: internal error: unknown data type");
761  epr_free_record(record);
762  return epr_get_last_err_code();
763  }
764 
765  scene_width = band_id->product_id->scene_width;
766  if (band_id->lines_mirrored) {
767  offset_x_mirrored = (scene_width - 1) - (offset_x + raster->source_width - 1);
768  } else {
769  offset_x_mirrored = offset_x;
770  }
771 
772  for (iY = offset_y; (epr_uint)iY < offset_y + raster->source_height; iY += raster->source_step_y ) {
773 
774  /*get the next record by the given name*/
775  record = epr_read_record(dataset_id, iY, record);
776  if (record == NULL) {
777  return epr_get_last_err_code();
778  }
779  /*get the field at its number*/
780  field = epr_get_field_at(record, band_id->dataset_ref.field_index - 1);
781  /*get the scaled "line" of physical values*/
782  decode_func(field->elems, band_id, offset_x_mirrored, raster->source_width, raster->source_step_x, raster->buffer, raster_pos);
783  /*locate "data point" for the next "line"*/
784  raster_pos += delta_raster_pos;
785  }
786 
787  if (band_id->lines_mirrored) {
788  if (band_datatype == e_tid_float) {
789  mirror_float_array((float*)raster->buffer, raster->raster_width, raster->raster_height);
790  } else if (band_datatype == e_tid_uchar || band_datatype == e_tid_char) {
791  mirror_uchar_array((epr_uchar*)raster->buffer, raster->raster_width, raster->raster_height);
792  } else if (band_datatype == e_tid_ushort || band_datatype == e_tid_short) {
793  mirror_ushort_array((epr_ushort*)raster->buffer, raster->raster_width, raster->raster_height);
794  } else if (band_datatype == e_tid_uint || band_datatype == e_tid_int) {
795  mirror_uint_array((epr_uint*)raster->buffer, raster->raster_width, raster->raster_height);
796  } else {
798  "epr_read_band_measurement_data: internal error: unknown data type");
799  epr_free_record(record);
800  return epr_get_last_err_code();
801  }
802  }
803 
804  epr_free_record(record);
805 
806  return 0;
807 }
808 
809 
820 int epr_read_band_annotation_data(EPR_SBandId* band_id,
821  int offset_x,
822  int offset_y,
823  EPR_SRaster* raster) {
824  EPR_SProductId* product_id = NULL;
825  const EPR_SField* field = NULL;
826  const EPR_SField* field_beg = NULL;
827  const EPR_SField* field_end = NULL;
828  EPR_SFieldInfo* field_info = NULL;
829  EPR_SDatasetId* dataset_id = NULL;
830  EPR_SRecord* record = NULL;
831  EPR_SRecord* record_beg = NULL;
832  EPR_SRecord* record_end = NULL;
833  EPR_SRecord* sph_record = NULL;
834  EPR_EDataTypeId band_datatype = 0, datatype_id = 0;
835  //EPR_ESampleModel band_smod = 0;
836  epr_uint rec_numb = 0;
837  epr_uint lines_per_tie_pt, samples_per_tie_pt, scan_line_length;
838  int iY, raster_pos, delta_raster_pos;
839  EPR_FArrayTransformer transform_array_func = NULL;
840  int y_beg, y_end, y_beg_old, y_end_old;
841  //int offset_x_mirrored = 0;
842  epr_uint num_elems = 0;
843  float y_mod = 0;
844  float scan_offset_x = 0;
845  float scan_offset_y = 0;
846  void* line_beg_buffer = NULL;
847  void* line_end_buffer = NULL;
848 
849  product_id = band_id->product_id;
850 
851  dataset_id = band_id->dataset_ref.dataset_id;
852  /*the length of annotation record size*/
853  //rec_size = dataset_id->dsd->dsr_size;
854  /*the number of annotation records*/
855  rec_numb = dataset_id->dsd->num_dsr;
856  /*data type in the band*/
857  band_datatype = band_id->data_type;
858  /*data model in the band*/
859  //band_smod = band_id->sample_model;
860  record = epr_create_record(dataset_id);
861  field_info = (EPR_SFieldInfo*)epr_get_ptr_array_elem_at(record->info->field_infos, band_id->dataset_ref.field_index - 1);
862  datatype_id = field_info->data_type_id;
863 
864 
865  /*find LINES_PER_TIE_PT & SAMPLES_PER_TIE_PT for different products*/
866  if (strncmp(EPR_ENVISAT_PRODUCT_MERIS, product_id->id_string, 3) == 0) {
867  /*elements number in the band (e.g.71)*/
868  scan_offset_x = 0.0F;
869  scan_offset_y = 0.0F;
870  num_elems = field_info->num_elems;
871  sph_record = product_id->sph_record;
872  field = epr_get_field(sph_record, "LINES_PER_TIE_PT");
873  lines_per_tie_pt = epr_get_field_elem_as_uint(field, 0);
874  field = epr_get_field(sph_record, "SAMPLES_PER_TIE_PT");
875  samples_per_tie_pt = epr_get_field_elem_as_uint(field, 0);
876  field = epr_get_field(sph_record, "LINE_LENGTH");
877  scan_line_length = epr_get_field_elem_as_uint(field, 0);
878  } else if (strncmp(EPR_ENVISAT_PRODUCT_AATSR, product_id->id_string, 3) == 0) {
879  scan_offset_y = 0.0F;
880  scan_line_length = EPR_ATS_LINE_LENGTH;
881  lines_per_tie_pt = EPR_AATSR_LINES_PER_TIE_PT;
882  num_elems = field_info->num_elems;
883  if (num_elems == EPR_ATS_NUM_PER_POINT_ACROSS_LOCAT) {
884  scan_offset_x = -19.0F;
885  samples_per_tie_pt = 25;
886  } else if (num_elems == EPR_ATS_NUM_PER_POINT_ACROSS_SOLAR) {
887  scan_offset_x = 6.0F;
888  samples_per_tie_pt = 50;
889  } else {
890  epr_set_err(e_err_invalid_value, "epr_read_band_annotation_data: internal error: illegal value for samples_per_tie_pt");
891  epr_free_record(record);
892  return epr_get_last_err_code();
893  }
894  } else if ((strncmp(EPR_ENVISAT_PRODUCT_ASAR, product_id->id_string, 3) == 0) ||
895  (strncmp(EPR_ENVISAT_PRODUCT_SAR, product_id->id_string, 3) == 0)) {
896  EPR_SDatasetId* dataset_id = NULL;
897  epr_uint num_rec;
898  scan_offset_x = 0.5F; /* @todo CHECK THIS FOR ASAR! */
899  scan_offset_y = 0.5F;
900  scan_line_length = epr_get_scene_width(product_id);
901  samples_per_tie_pt = scan_line_length / (EPR_ASAR_NUM_PER_POINT_ACROSS_LOCAT - 1);
902  dataset_id = epr_get_dataset_id(product_id, "GEOLOCATION_GRID_ADS");
903  num_rec = epr_get_num_records(dataset_id);
904  lines_per_tie_pt = epr_get_scene_height(product_id) / (num_rec - 1);
905  num_elems = field_info->num_elems;
906  } else {
908  "epr_read_band_annotation_data: unhandled ENVISAT product type");
909  epr_free_record(record);
910  return epr_get_last_err_code();
911  }
912 
913  /*memory allocate for the increasingly begin tie point line*/
914  line_beg_buffer = calloc(sizeof(float), num_elems);
915  if (line_beg_buffer == NULL) {
916  epr_set_err(e_err_out_of_memory, "epr_read_band_annotation_data: out of memory");
917  epr_free_record(record);
918  return epr_get_last_err_code();
919  }
920  /*memory allocate for the increasingly end tie point line*/
921  line_end_buffer = calloc(sizeof(float), num_elems);
922  if (line_end_buffer == NULL) {
923  epr_set_err(e_err_out_of_memory, "epr_read_band_annotation_data: out of memory");
924  epr_free_record(record);
925  free(line_beg_buffer);
926  return epr_get_last_err_code();
927  }
928  /* if the user raster (or its part) is outside of orbit in source coordinates*/
929  if (offset_x + raster->raster_width > (int)scan_line_length) {
931  "epr_read_band_data: raster x co-ordinates out of bounds");
932  epr_free_record(record);
933  free(line_beg_buffer);
934  free(line_end_buffer);
935  return epr_get_last_err_code();
936  }
937  if (offset_y + raster->raster_height > (int)(rec_numb * lines_per_tie_pt)) {
939  "epr_read_band_data: raster y co-ordinates out of bounds");
940  epr_free_record(record);
941  free(line_beg_buffer);
942  free(line_end_buffer);
943  return epr_get_last_err_code();
944  }
945  raster_pos = 0;
946 
947  delta_raster_pos = (int)floor((raster->source_width - 1) / raster->source_step_x) + 1;
948 
949  /*select the correspondent function to scaling and transform data type*/
950  transform_array_func = select_transform_array_function(band_datatype, datatype_id);
951  if (transform_array_func == NULL) {
953  "epr_read_band_annotation_data: internal error: illegal data type");
954  epr_free_record(record);
955  free(line_beg_buffer);
956  free(line_end_buffer);
957  return epr_get_last_err_code();
958  }
959  y_beg_old = 9999;
960  y_end_old = 9999;
961 
962  //if (band_id->lines_mirrored) {
963  // offset_x_mirrored = num_elems - (offset_x + raster->source_width - 1) - 1;
964  //} else {
965  // offset_x_mirrored = offset_x;
966  //}
967 
968  for (iY = offset_y; (epr_uint)iY < offset_y + raster->source_height; iY += raster->source_step_y ) {
969 
970  /*find the increasing neighbour begin and end tie point lines*/
971  y_mod = ((float)iY - scan_offset_y) / lines_per_tie_pt;
972  y_beg = (epr_uint)floor(y_mod);
973 
974  if (y_beg < 0) {
975  y_beg = 0;
976  }
977  if ((epr_uint)y_beg > dataset_id->dsd->num_dsr - 2) {
978  y_beg = dataset_id->dsd->num_dsr - 2;
979  }
980 
981  y_mod -= y_beg;
982  y_end = y_beg + 1;
983 
984  /*as long as between increasing neighbour tie point lines, not to change them*/
985  if (y_beg_old != y_beg) {
986  record_beg = epr_read_record(dataset_id, y_beg, record_beg);
987  y_beg_old = y_beg;
988  }
989  if (y_end_old != y_end) {
990  record_end = epr_read_record(dataset_id, y_end, record_end);
991  y_end_old = y_end;
992  }
993 
994  /*get the values for the increasing neighbour tie point lines*/
995  field_beg = epr_get_field_at(record_beg, band_id->dataset_ref.field_index - 1);
996  field_end = epr_get_field_at(record_end, band_id->dataset_ref.field_index - 1);
997 
998  /*transform and scale the values for the increasing neighbour tie point lines*/
999  transform_array_func(field_beg->elems, band_id, line_beg_buffer, num_elems);
1000  transform_array_func(field_end->elems, band_id, line_end_buffer, num_elems);
1001 
1002  /*get the "line" of interpolated physical values from tie point data*/
1003  decode_tiepoint_band(line_beg_buffer, line_end_buffer,
1004  samples_per_tie_pt, num_elems, band_id, offset_x, scan_offset_x, y_mod,
1005  raster->source_width, raster->source_step_x, raster->buffer, raster_pos);
1006  /*locate "data point" for the next "line"*/
1007  raster_pos += delta_raster_pos;
1008  }
1009 
1010  if (strncmp(EPR_ENVISAT_PRODUCT_MERIS, product_id->id_string, 3) == 0) {
1011  mirror_float_array((float*)raster->buffer, raster->raster_width, raster->raster_height);
1012  } else {
1013  if (strncmp(EPR_ENVISAT_PRODUCT_AATSR, product_id->id_string, 3) == 0) {
1014  mirror_float_array((float*)raster->buffer, raster->raster_width, raster->raster_height);
1015  } else {
1016  if (strncmp(EPR_ENVISAT_PRODUCT_ASAR, product_id->id_string, 3) == 0
1017  && strncmp(product_id->id_string, "ASA_IMG", 7) != 0
1018  && strncmp(product_id->id_string, "ASA_APG", 7) != 0) {
1019  mirror_float_array((float*)raster->buffer, raster->raster_width, raster->raster_height);
1020  } else {
1021  if (strncmp(EPR_ENVISAT_PRODUCT_SAR, product_id->id_string, 3) == 0
1022  && strncmp(product_id->id_string, "SAR_IMG", 7) != 0
1023  && strncmp(product_id->id_string, "SAR_APG", 7) != 0) {
1024  mirror_float_array((float*)raster->buffer, raster->raster_width, raster->raster_height);
1025  }
1026  }
1027  }
1028  }
1029 
1030  epr_free_record(record_beg);
1031  epr_free_record(record_end);
1032  epr_free_record(record);
1033  free(line_beg_buffer);
1034  free(line_end_buffer);
1035  return 0;
1036 }
1037 
1038 
1039 epr_uint epr_get_raster_elem_size(const EPR_SRaster* raster) {
1040  if (raster == NULL) {
1041  epr_set_err(e_err_invalid_raster, "epr_get_raster_elem_size: raster must not be NULL");
1042  return 0;
1043  }
1044  return raster->elem_size;
1045 }
1046 
1047 void* epr_get_raster_elem_addr(const EPR_SRaster* raster, epr_uint offset) {
1048  if (raster == NULL) {
1049  epr_set_err(e_err_invalid_raster, "epr_get_raster_elem_addr: raster must not be NULL");
1050  return 0;
1051  }
1052  return ((epr_uchar*) raster->buffer) + epr_get_raster_elem_size(raster) * offset;
1053 }
1054 
1055 void* epr_get_raster_pixel_addr(const EPR_SRaster* raster, epr_uint x, epr_uint y) {
1056  if (raster == NULL) {
1057  epr_set_err(e_err_invalid_raster, "epr_get_raster_pixel_addr: raster must not be NULL");
1058  return 0;
1059  }
1060  return epr_get_raster_elem_addr(raster, y * raster->raster_width + x);
1061 }
1062 
1063 void* epr_get_raster_line_addr(const EPR_SRaster* raster, epr_uint y) {
1064  if (raster == NULL) {
1065  epr_set_err(e_err_invalid_raster, "epr_get_raster_line_addr: raster must not be NULL");
1066  return 0;
1067  }
1068  return epr_get_raster_elem_addr(raster, y * raster->raster_width);
1069 }
1070 
1071 epr_uint epr_get_raster_width(EPR_SRaster* raster) {
1072  if (raster == NULL) {
1073  epr_set_err(e_err_invalid_raster, "epr_get_raster_width: raster must not be NULL");
1074  return 0;
1075  }
1076  return raster->raster_width;
1077 }
1078 
1079 epr_uint epr_get_raster_height(EPR_SRaster* raster) {
1080  if (raster == NULL) {
1081  epr_set_err(e_err_invalid_raster, "epr_get_raster_height: raster must not be NULL");
1082  return 0;
1083  }
1084  return raster->raster_height;
1085 }
1086 
1087 /******************************************************************/
1089  EPR_ESampleModel band_smod,
1090  EPR_EDataTypeId raw_tid) {
1091  EPR_FLineDecoder decode_func;
1092  if ((band_tid == e_tid_char || band_tid == e_tid_uchar)
1093  && band_smod == e_smod_1OF1
1094  && (raw_tid == e_tid_char || raw_tid == e_tid_uchar))
1095  decode_func = decode_line_uchar_1_of_1_to_uchar;
1096  else if ((band_tid == e_tid_char || band_tid == e_tid_uchar)
1097  && band_smod == e_smod_1OF2
1098  && (raw_tid == e_tid_char || raw_tid == e_tid_uchar))
1099  decode_func = decode_line_uchar_1_of_2_to_uchar;
1100  else if ((band_tid == e_tid_char || band_tid == e_tid_uchar)
1101  && band_smod == e_smod_2OF2
1102  && (raw_tid == e_tid_char || raw_tid == e_tid_uchar))
1103  decode_func = decode_line_uchar_2_of_2_to_uchar;
1104  else if ((band_tid == e_tid_short || band_tid == e_tid_ushort)
1105  && band_smod == e_smod_1OF1
1106  && (raw_tid == e_tid_short || raw_tid == e_tid_ushort))
1108  else if (band_tid == e_tid_float
1109  && band_smod == e_smod_1OF1
1110  && raw_tid == e_tid_uchar)
1111  decode_func = decode_line_uchar_1_of_1_to_float;
1112  else if (band_tid == e_tid_float
1113  && band_smod == e_smod_1OF1
1114  && raw_tid == e_tid_char)
1115  decode_func = decode_line_char_1_of_1_to_float;
1116  else if (band_tid == e_tid_float
1117  && band_smod == e_smod_1OF1
1118  && raw_tid == e_tid_ushort)
1119  decode_func = decode_line_ushort_1_of_1_to_float;
1120  else if (band_tid == e_tid_float
1121  && band_smod == e_smod_1OF1
1122  && raw_tid == e_tid_short)
1123  decode_func = decode_line_short_1_of_1_to_float;
1124  else if (band_tid == e_tid_float
1125  && band_smod == e_smod_1OF2
1126  && raw_tid == e_tid_short)
1127  decode_func = decode_line_short_1_of_2_to_float;
1128  else if (band_tid == e_tid_float
1129  && band_smod == e_smod_2OF2
1130  && raw_tid == e_tid_short)
1131  decode_func = decode_line_short_2_of_2_to_float;
1132  else if (band_tid == e_tid_float
1133  && band_smod == e_smod_1OF2
1134  && raw_tid == e_tid_uchar)
1135  decode_func = decode_line_uchar_1_of_2_to_float;
1136  else if (band_tid == e_tid_float
1137  && band_smod == e_smod_2OF2
1138  && raw_tid == e_tid_uchar)
1139  decode_func = decode_line_uchar_2_of_2_to_float;
1140  else if (band_tid == e_tid_float
1141  && band_smod == e_smod_2TOF
1142  && raw_tid == e_tid_uchar)
1143  decode_func = decode_line_uchar_2_to_f_to_float;
1144  else if (band_tid == e_tid_uint
1145  && band_smod == e_smod_3TOI
1146  && raw_tid == e_tid_uchar)
1147  decode_func = decode_line_uchar_3_to_i_to_uint;
1148  else {
1149  return NULL;
1150  }
1151  return decode_func;
1152 }
1153 
1154 
1156  EPR_EDataTypeId raw_tid) {
1157  EPR_FArrayTransformer transform_array_func;
1158  if (band_tid == e_tid_float && raw_tid == e_tid_short)
1159  transform_array_func = transform_array_short_to_float;
1160  else if (band_tid == e_tid_float && raw_tid == e_tid_ushort)
1161  transform_array_func = transform_array_ushort_to_float;
1162  else if (band_tid == e_tid_float && raw_tid == e_tid_int)
1163  transform_array_func = transform_array_int_to_float;
1164  else if (band_tid == e_tid_float && raw_tid == e_tid_uint)
1165  transform_array_func = transform_array_uint_to_float;
1166  else {
1167  return NULL;
1168  }
1169  return transform_array_func;
1170 }
1171 
1172 
1173 void decode_line_uchar_1_of_1_to_float(void* source_array,
1174  EPR_SBandId* band_id,
1175  int offset_x,
1176  int raster_width,
1177  int step_x,
1178  void* raster_buffer,
1179  int raster_pos) {
1180  int x, x1, x2;
1181  epr_uchar* sa = (epr_uchar*) source_array;
1182  float* buf = (float*) raster_buffer;
1183 
1184  x1 = offset_x;
1185  x2 = x1 + raster_width - 1;
1186 
1187  if (band_id->scaling_method == e_smid_log) {
1188  for (x = x1; x <= x2; x += step_x) {
1189  buf[raster_pos++] = (float)pow(10, band_id->scaling_offset + band_id->scaling_factor * sa[x]);
1190  }
1191  } else if (band_id->scaling_method == e_smid_lin) {
1192  for (x = x1; x <= x2; x += step_x) {
1193  buf[raster_pos++] = band_id->scaling_offset + band_id->scaling_factor * sa[x];
1194  }
1195  } else {
1196  for (x = x1; x <= x2; x += step_x) {
1197  buf[raster_pos++] = sa[x];
1198  }
1199  }
1200 }
1201 
1202 
1203 void decode_line_char_1_of_1_to_float(void* source_array,
1204  EPR_SBandId* band_id,
1205  int offset_x,
1206  int raster_width,
1207  int step_x,
1208  void* raster_buffer,
1209  int raster_pos) {
1210  int x, x1, x2;
1211  char* sa = (char*) source_array;
1212  float* buf = (float*) raster_buffer;
1213 
1214  x1 = offset_x;
1215  x2 = x1 + raster_width - 1;
1216 
1217  if (band_id->scaling_method == e_smid_log) {
1218  for (x = x1; x <= x2; x += step_x) {
1219  buf[raster_pos++] = (float)pow(10, band_id->scaling_offset + band_id->scaling_factor * sa[x]);
1220  }
1221  } else if (band_id->scaling_method == e_smid_lin) {
1222  for (x = x1; x <= x2; x += step_x) {
1223  buf[raster_pos++] = band_id->scaling_offset + band_id->scaling_factor * sa[x];
1224  }
1225  } else {
1226  for (x = x1; x <= x2; x += step_x) {
1227  buf[raster_pos++] = sa[x];
1228  }
1229  }
1230 }
1231 
1232 
1233 void decode_line_ushort_1_of_1_to_float(void* source_array,
1234  EPR_SBandId* band_id,
1235  int offset_x,
1236  int raster_width,
1237  int step_x,
1238  void* raster_buffer,
1239  int raster_pos) {
1240  int x, x1, x2;
1241  epr_ushort* sa = (epr_ushort*) source_array;
1242  float* buf = (float*) raster_buffer;
1243 
1244  x1 = offset_x;
1245  x2 = x1 + raster_width - 1;
1246 
1247  if (band_id->scaling_method == e_smid_log) {
1248  for (x = x1; x <= x2; x += step_x) {
1249  buf[raster_pos++] = (float)pow(10, band_id->scaling_offset + band_id->scaling_factor * sa[x]);
1250  }
1251  } else if (band_id->scaling_method == e_smid_lin) {
1252  for (x = x1; x <= x2; x += step_x) {
1253  buf[raster_pos++] = band_id->scaling_offset + band_id->scaling_factor * sa[x];
1254  }
1255  } else {
1256  for (x = x1; x <= x2; x += step_x) {
1257  buf[raster_pos++] = sa[x];
1258  }
1259  }
1260 }
1261 
1262 
1263 void decode_line_short_1_of_1_to_float(void* source_array,
1264  EPR_SBandId* band_id,
1265  int offset_x,
1266  int raster_width,
1267  int step_x,
1268  void* raster_buffer,
1269  int raster_pos) {
1270  int x, x1, x2;
1271  short* sa = (short*) source_array;
1272  float* buf = (float*) raster_buffer;
1273 
1274  x1 = offset_x;
1275  x2 = x1 + raster_width - 1;
1276 
1277  if (band_id->scaling_method == e_smid_log) {
1278  for (x = x1; x <= x2; x += step_x) {
1279  buf[raster_pos++] = (float)pow(10, band_id->scaling_offset + band_id->scaling_factor * sa[x]);
1280  }
1281  } else if (band_id->scaling_method == e_smid_lin) {
1282  for (x = x1; x <= x2; x += step_x) {
1283  buf[raster_pos++] = band_id->scaling_offset + band_id->scaling_factor * sa[x];
1284  }
1285  } else {
1286  for (x = x1; x <= x2; x += step_x) {
1287  buf[raster_pos++] = sa[x];
1288  }
1289  }
1290 }
1291 
1292 void decode_line_short_1_of_2_to_float(void* source_array,
1293  EPR_SBandId* band_id,
1294  int offset_x,
1295  int raster_width,
1296  int step_x,
1297  void* raster_buffer,
1298  int raster_pos) {
1299  int x, x1, x2;
1300  short* sa = (short*) source_array;
1301  float* buf = (float*) raster_buffer;
1302 
1303  x1 = offset_x;
1304  x2 = x1 + raster_width - 1;
1305 
1306  if (band_id->scaling_method == e_smid_log) {
1307  for (x = x1; x <= x2; x += step_x) {
1308  buf[raster_pos++] = (float)pow(10, band_id->scaling_offset + band_id->scaling_factor * sa[2 * x]);
1309  }
1310  } else if (band_id->scaling_method == e_smid_lin) {
1311  for (x = x1; x <= x2; x += step_x) {
1312  buf[raster_pos++] = band_id->scaling_offset + band_id->scaling_factor * sa[2 * x];
1313  }
1314  } else {
1315  for (x = x1; x <= x2; x += step_x) {
1316  buf[raster_pos++] = (float)(sa[2 * x]);
1317  }
1318  }
1319 }
1320 
1321 
1322 void decode_line_short_2_of_2_to_float(void* source_array,
1323  EPR_SBandId* band_id,
1324  int offset_x,
1325  int raster_width,
1326  int step_x,
1327  void* raster_buffer,
1328  int raster_pos) {
1329  int x, x1, x2;
1330  short* sa = (short*) source_array;
1331  float* buf = (float*) raster_buffer;
1332 
1333  x1 = offset_x;
1334  x2 = x1 + raster_width - 1;
1335 
1336  if (band_id->scaling_method == e_smid_log) {
1337  for (x = x1; x <= x2; x += step_x) {
1338  buf[raster_pos++] = (float)pow(10, band_id->scaling_offset + band_id->scaling_factor * sa[2 * x + 1]);
1339  }
1340  } else if (band_id->scaling_method == e_smid_lin) {
1341  for (x = x1; x <= x2; x += step_x) {
1342  buf[raster_pos++] = band_id->scaling_offset + band_id->scaling_factor * sa[2 * x + 1];
1343  }
1344  } else {
1345  for (x = x1; x <= x2; x += step_x) {
1346  buf[raster_pos++] = (float)(sa[2 * x + 1]);
1347  }
1348  }
1349 }
1350 
1351 
1352 void decode_line_uchar_1_of_1_to_uchar(void* source_array,
1353  EPR_SBandId* band_id,
1354  int offset_x,
1355  int raster_width,
1356  int step_x,
1357  void* raster_buffer,
1358  int raster_pos) {
1359  int x, x1, x2;
1360  epr_uchar* sa = (epr_uchar*) source_array;
1361  epr_uchar* buf = (epr_uchar*) raster_buffer;
1362 
1363  x1 = offset_x;
1364  x2 = x1 + raster_width - 1;
1365 
1366  for (x = x1; x <= x2; x += step_x) {
1367  buf[raster_pos++] = sa[x];
1368  }
1369 }
1370 
1371 void decode_line_uchar_1_of_2_to_uchar(void* source_array,
1372  EPR_SBandId* band_id,
1373  int offset_x,
1374  int raster_width,
1375  int step_x,
1376  void* raster_buffer,
1377  int raster_pos) {
1378  int x, x1, x2;
1379  epr_uchar* sa = (epr_uchar*) source_array;
1380  epr_uchar* buf = (epr_uchar*) raster_buffer;
1381 
1382  x1 = offset_x;
1383  x2 = x1 + raster_width - 1;
1384 
1385  for (x = x1; x <= x2; x += step_x) {
1386  buf[raster_pos++] = sa[2 * x];
1387  }
1388 }
1389 
1390 
1391 void decode_line_uchar_2_of_2_to_uchar(void* source_array,
1392  EPR_SBandId* band_id,
1393  int offset_x,
1394  int raster_width,
1395  int step_x,
1396  void* raster_buffer,
1397  int raster_pos) {
1398  int x, x1, x2;
1399  epr_uchar* sa = (epr_uchar*) source_array;
1400  epr_uchar* buf = (epr_uchar*) raster_buffer;
1401 
1402  x1 = offset_x;
1403  x2 = x1 + raster_width - 1;
1404 
1405  for (x = x1; x <= x2; x += step_x) {
1406  buf[raster_pos++] = sa[2 * x + 1];
1407  }
1408 }
1409 
1410 void decode_line_ushort_1_of_1_to_ushort(void* source_array,
1411  EPR_SBandId* band_id,
1412  int offset_x,
1413  int raster_width,
1414  int step_x,
1415  void* raster_buffer,
1416  int raster_pos) {
1417  int x, x1, x2;
1418  epr_ushort* sa = (epr_ushort*) source_array;
1419  epr_ushort* buf = (epr_ushort*) raster_buffer;
1420 
1421  x1 = offset_x;
1422  x2 = x1 + raster_width - 1;
1423 
1424  for (x = x1; x <= x2; x += step_x) {
1425  buf[raster_pos++] = sa[x];
1426  }
1427 }
1428 
1429 void decode_line_uchar_2_to_f_to_float(void* source_array,
1430  EPR_SBandId* band_id,
1431  int offset_x,
1432  int raster_width,
1433  int step_x,
1434  void* raster_buffer,
1435  int raster_pos) {
1436  int x, x1, x2, shi;
1437  epr_uchar* sa = (epr_uchar*) source_array;
1438  float* buf = (float*) raster_buffer;
1439 
1440  x1 = offset_x;
1441  x2 = x1 + raster_width - 1;
1442 
1443  if (band_id->scaling_method == e_smid_log) {
1444  for (x = x1; x <= x2; x += step_x) {
1445  shi = (((sa[2 * x] & 0xff)) | ((sa[2 * x + 1] & 0xff) << 8)) & 0xffff;
1446  buf[raster_pos++] = (float)pow(10, band_id->scaling_offset + band_id->scaling_factor * shi);
1447  }
1448  } else if (band_id->scaling_method == e_smid_lin) {
1449  for (x = x1; x <= x2; x += step_x) {
1450  shi = (((sa[2 * x] & 0xff)) | ((sa[2 * x + 1] & 0xff) << 8)) & 0xffff;
1451  buf[raster_pos++] = band_id->scaling_offset + band_id->scaling_factor * shi;
1452  }
1453  } else {
1454  for (x = x1; x <= x2; x += step_x) {
1455  shi = (((sa[2 * x] & 0xff)) | ((sa[2 * x + 1] & 0xff) << 8)) & 0xffff;
1456  buf[raster_pos++] = (float)shi;
1457  }
1458  }
1459 }
1460 
1461 void decode_line_uchar_1_of_2_to_float(void* source_array,
1462  EPR_SBandId* band_id,
1463  int offset_x,
1464  int raster_width,
1465  int step_x,
1466  void* raster_buffer,
1467  int raster_pos) {
1468  int x, x1, x2;
1469  epr_uchar* sa = (epr_uchar*) source_array;
1470  float* buf = (float*) raster_buffer;
1471 
1472  x1 = offset_x;
1473  x2 = x1 + raster_width - 1;
1474 
1475  if (band_id->scaling_method == e_smid_log) {
1476  for (x = x1; x <= x2; x += step_x) {
1477  buf[raster_pos++] = (float)pow(10, band_id->scaling_offset + band_id->scaling_factor * (sa[2 * x] & 0xff));
1478  }
1479  } else if (band_id->scaling_method == e_smid_lin) {
1480  for (x = x1; x <= x2; x += step_x) {
1481  buf[raster_pos++] = band_id->scaling_offset + band_id->scaling_factor * (sa[2 * x] & 0xff);
1482  }
1483  } else {
1484  for (x = x1; x <= x2; x += step_x) {
1485  buf[raster_pos++] = (float)(sa[2 * x] & 0xff);
1486  }
1487  }
1488 }
1489 
1490 
1491 
1492 void decode_line_uchar_2_of_2_to_float(void* source_array,
1493  EPR_SBandId* band_id,
1494  int offset_x,
1495  int raster_width,
1496  int step_x,
1497  void* raster_buffer,
1498  int raster_pos) {
1499  int x, x1, x2;
1500  epr_uchar* sa = (epr_uchar*) source_array;
1501  float* buf = (float*) raster_buffer;
1502 
1503  x1 = offset_x;
1504  x2 = x1 + raster_width - 1;
1505 
1506  if (band_id->scaling_method == e_smid_log) {
1507  for (x = x1; x <= x2; x += step_x) {
1508  buf[raster_pos++] = (float)pow(10, band_id->scaling_offset + band_id->scaling_factor * (sa[2 * x + 1] & 0xff));
1509  }
1510  } else if (band_id->scaling_method == e_smid_lin) {
1511  for (x = x1; x <= x2; x += step_x) {
1512  buf[raster_pos++] = band_id->scaling_offset + band_id->scaling_factor * (sa[2 * x + 1] & 0xff);
1513  }
1514  } else {
1515  for (x = x1; x <= x2; x += step_x) {
1516  buf[raster_pos++] = (float)(sa[2 * x + 1] & 0xff);
1517  }
1518  }
1519 }
1520 
1521 void decode_line_uchar_3_to_i_to_uint(void* source_array,
1522  EPR_SBandId* band_id,
1523  int offset_x,
1524  int raster_width,
1525  int step_x,
1526  void* raster_buffer,
1527  int raster_pos) {
1528  int x, x1, x2, n;
1529  epr_uchar* sa = (epr_uchar*) source_array;
1530  epr_uint* buf = (epr_uint*) raster_buffer;
1531 
1532  x1 = offset_x;
1533  x2 = x1 + raster_width - 1;
1534 
1535  for (x = x1; x <= x2; x += step_x) {
1536  n = 3 * x;
1537  buf[raster_pos++] = (sa[n] & 0xff) << 16 | ((sa[n+1] & 0xff) << 8) | ((sa[n+2] & 0xff) );
1538  }
1539 }
1540 
1557 void decode_tiepoint_band(float* sa_beg,
1558  float* sa_end,
1559  epr_uint samples_per_tie_pt,
1560  epr_uint num_elems,
1561  EPR_SBandId* band_id,
1562  int offset_x,
1563  float scan_offset_x,
1564  float y_mod,
1565  int raster_width,
1566  int s_x,
1567  float* raster_buffer,
1568  int raster_pos) {
1569 
1570  int ix;
1571  float x_mod;
1572  epr_uint x_knot;
1573  int inti_flag = 0;
1574  int intersection = 0;
1575  float circle;
1576  float half_circle;
1577  float null_point;
1578 
1580  half_circle = 0.5F * circle;
1581  null_point = 0.5F * (EPR_LONGI_ABS_MAX + EPR_LONGI_ABS_MIN);
1582 
1583  if (strncmp(band_id->band_name, EPR_LONGI_BAND_NAME, strlen(EPR_LONGI_BAND_NAME)) == 0) {
1584  inti_flag = 1;
1585  } else {
1586  inti_flag = 0;
1587  }
1588 
1589  for (ix = offset_x; ix < offset_x + raster_width; ix += s_x) {
1590  x_mod = (ix - scan_offset_x) / samples_per_tie_pt;
1591  if (x_mod >= 0.0F) {
1592  x_knot = (epr_uint)floor(x_mod);
1593  if (x_knot >= num_elems - 1) {
1594  x_knot = num_elems - 2;
1595  }
1596  } else {
1597  x_knot = (epr_uint)0;
1598  }
1599  x_mod -= x_knot;
1600 
1601  if (inti_flag == 1) {
1602  if (fabs((float)(sa_beg[x_knot + 1] - sa_beg[x_knot])) > half_circle ||
1603  fabs((float)(sa_beg[x_knot] - sa_end[x_knot])) > half_circle ||
1604  fabs((float)(sa_end[x_knot] - sa_end[x_knot + 1])) > half_circle ||
1605  fabs((float)(sa_end[x_knot + 1] - sa_beg[x_knot + 1])) > half_circle) {
1606  intersection = 1;
1607  if (sa_beg[x_knot] < (float)null_point) {
1608  sa_beg[x_knot] += circle;
1609  }
1610  if (sa_beg[x_knot + 1] < (float)null_point) {
1611  sa_beg[x_knot + 1] += circle;
1612  }
1613  if (sa_end[x_knot] < (float)null_point) {
1614  sa_end[x_knot] += circle;
1615  }
1616  if (sa_end[x_knot + 1] < (float)null_point) {
1617  sa_end[x_knot + 1] += circle;
1618  }
1619  }
1620  } else {
1621  intersection = 0;
1622  }
1623 
1624  raster_buffer[raster_pos] = epr_interpolate2D(x_mod, y_mod,
1625  sa_beg[x_knot], sa_beg[x_knot + 1],
1626  sa_end[x_knot], sa_end[x_knot + 1]);
1627 
1628  if (inti_flag == 1 &&
1629  intersection == 1 &&
1630  raster_buffer[raster_pos] > EPR_LONGI_ABS_MAX) {
1631  raster_buffer[raster_pos] -= circle;
1632  }
1633 
1634  raster_pos++;
1635  }
1636 }
1637 
1638 
1639 float epr_interpolate2D(float wi, float wj, float x00, float x10, float x01, float x11) {
1640  return x00 + wi * (x10 - x00) + wj * (x01 - x00) + wi * wj * (x11 + x00 - x01 - x10);
1641 }
1642 
1643 
1644 void transform_array_short_to_float (void* sourceArray,
1645  EPR_SBandId* band_id,
1646  float* raster_buffer,
1647  epr_uint nel) {
1648  epr_uint ix;
1649  short* sa = (short*) sourceArray;
1650 
1651  for (ix = 0; ix < nel; ix ++) {
1652  raster_buffer[ix] = band_id->scaling_offset + band_id->scaling_factor * sa[ix];
1653  }
1654 }
1655 
1656 void transform_array_ushort_to_float (void* sourceArray,
1657  EPR_SBandId* band_id,
1658  float* raster_buffer,
1659  epr_uint nel) {
1660  epr_uint ix;
1661  epr_ushort* sa = (epr_ushort*) sourceArray;
1662 
1663  for (ix = 0; ix < nel; ix ++) {
1664  raster_buffer[ix] = band_id->scaling_offset + band_id->scaling_factor * sa[ix];
1665  }
1666 }
1667 
1668 void transform_array_int_to_float (void* sourceArray,
1669  EPR_SBandId* band_id,
1670  float* raster_buffer,
1671  epr_uint nel) {
1672  epr_uint ix;
1673  int* sa = (int*) sourceArray;
1674 
1675  for (ix = 0; ix < nel; ix ++) {
1676  raster_buffer[ix] = band_id->scaling_offset + band_id->scaling_factor * sa[ix];
1677  }
1678 }
1679 
1680 void transform_array_uint_to_float (void* sourceArray,
1681  EPR_SBandId* band_id,
1682  float* raster_buffer,
1683  epr_uint nel) {
1684  epr_uint ix;
1685  epr_uint* sa = (epr_uint*) sourceArray;
1686 
1687  for (ix = 0; ix < nel; ix ++) {
1688  raster_buffer[ix] = band_id->scaling_offset + band_id->scaling_factor * sa[ix];
1689  }
1690 }
1691 
1692 void mirror_float_array(float* raster_buffer, epr_uint raster_width, epr_uint raster_height) {
1693  epr_uint w, h, pol_w, offset;
1694  float tmp;
1695  pol_w = raster_width / 2;
1696 
1697  for (h = 0; h < raster_height; h ++) {
1698  for (w = 0; w < pol_w; w ++) {
1699  offset = h * raster_width;
1700  tmp = raster_buffer[w + offset];
1701  raster_buffer[w + offset] = raster_buffer[raster_width - 1 - w + offset];
1702  raster_buffer[raster_width - 1 - w + offset] = tmp;
1703  }
1704  }
1705 }
1706 
1707 void mirror_uchar_array(epr_uchar* raster_buffer, epr_uint raster_width, epr_uint raster_height) {
1708  epr_uint w, h, pol_w, offset;
1709  epr_uchar tmp;
1710  pol_w = raster_width / 2;
1711 
1712  for (h = 0; h < raster_height; h ++) {
1713  for (w = 0; w < pol_w; w ++) {
1714  offset = h * raster_width;
1715  tmp = raster_buffer[w + offset];
1716  raster_buffer[w + offset] = raster_buffer[raster_width - 1 - w + offset];
1717  raster_buffer[raster_width - 1 - w + offset] = tmp;
1718  }
1719  }
1720 }
1721 
1722 void mirror_ushort_array(epr_ushort* raster_buffer, epr_uint raster_width, epr_uint raster_height) {
1723  epr_uint w, h, pol_w, offset;
1724  epr_ushort tmp;
1725  pol_w = raster_width / 2;
1726 
1727  for (h = 0; h < raster_height; h ++) {
1728  for (w = 0; w < pol_w; w ++) {
1729  offset = h * raster_width;
1730  tmp = raster_buffer[w + offset];
1731  raster_buffer[w + offset] = raster_buffer[raster_width - 1 - w + offset];
1732  raster_buffer[raster_width - 1 - w + offset] = tmp;
1733  }
1734  }
1735 }
1736 
1737 void mirror_uint_array(epr_uint* raster_buffer, epr_uint raster_width, epr_uint raster_height) {
1738  epr_uint w, h, pol_w, offset;
1739  epr_uint tmp;
1740  pol_w = raster_width / 2;
1741 
1742  for (h = 0; h < raster_height; h ++) {
1743  for (w = 0; w < pol_w; w ++) {
1744  offset = h * raster_width;
1745  tmp = raster_buffer[w + offset];
1746  raster_buffer[w + offset] = raster_buffer[raster_width - 1 - w + offset];
1747  raster_buffer[raster_width - 1 - w + offset] = tmp;
1748  }
1749  }
1750 }
1751 
1752 void epr_zero_invalid_pixels(EPR_SRaster* raster, EPR_SRaster* bm_raster) {
1753 
1754  epr_uchar* bm_pixels;
1755  epr_uint bm_pos = 0;
1756  epr_uint bm_len = raster->raster_width * raster->raster_height;
1757 
1758  assert(bm_raster->data_type == e_tid_char
1759  || bm_raster->data_type == e_tid_uchar);
1760 
1761 
1762  bm_pixels = (epr_uchar*) bm_raster->buffer;
1763  switch (raster->data_type) {
1764  case e_tid_char:
1765  case e_tid_uchar: {
1766  char* pixels = (char*) raster->buffer;
1767  for (bm_pos = 0; bm_pos < bm_len; bm_pos++) {
1768  if (bm_pixels[bm_pos] == 0) {
1769  pixels[bm_pos] = 0;
1770  }
1771  }
1772  }
1773  break;
1774  case e_tid_short:
1775  case e_tid_ushort: {
1776  short* pixels = (short*) raster->buffer;
1777  for (bm_pos = 0; bm_pos < bm_len; bm_pos++) {
1778  if (bm_pixels[bm_pos] == 0) {
1779  pixels[bm_pos] = 0;
1780  }
1781  }
1782  }
1783  break;
1784  case e_tid_int:
1785  case e_tid_uint: {
1786  int* pixels = (int*) raster->buffer;
1787  for (bm_pos = 0; bm_pos < bm_len; bm_pos++) {
1788  if (bm_pixels[bm_pos] == 0) {
1789  pixels[bm_pos] = 0;
1790  }
1791  }
1792  }
1793  break;
1794  case e_tid_float: {
1795  float* pixels = (float*) raster->buffer;
1796  for (bm_pos = 0; bm_pos < bm_len; bm_pos++) {
1797  if (bm_pixels[bm_pos] == 0) {
1798  pixels[bm_pos] = 0.0F;
1799  }
1800  }
1801  }
1802  break;
1803  case e_tid_double: {
1804  double* pixels = (double*) raster->buffer;
1805  for (bm_pos = 0; bm_pos < bm_len; bm_pos++) {
1806  if (bm_pixels[bm_pos] == 0) {
1807  pixels[bm_pos] = 0.0;
1808  }
1809  }
1810  }
1811  break;
1812  default: {}
1813  break;
1814  }
1815 }
const EPR_EScalingMethod scale_method
Definition: epr_dddb.h:32
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
@ e_smod_1OF2
Definition: epr_api.h:133
#define EPR_ENVISAT_PRODUCT_AATSR
Definition: epr_core.h:40
@ e_err_out_of_memory
Definition: epr_api.h:83
@ e_err_invalid_band_name
Definition: epr_api.h:106
@ e_err_illegal_arg
Definition: epr_api.h:81
void decode_line_uchar_2_of_2_to_float(void *source_array, EPR_SBandId *band_id, int offset_x, int raster_width, int step_x, void *raster_buffer, int raster_pos)
Definition: epr_band.c:1492
#define EPR_ATS_NUM_PER_POINT_ACROSS_SOLAR
Definition: epr_core.h:75
#define EPR_MAGIC_RASTER
Definition: epr_api.h:199
EPR_SRaster * epr_create_compatible_raster(EPR_SBandId *band_id, epr_uint source_width, epr_uint source_height, epr_uint source_step_x, epr_uint source_step_y)
Definition: epr_band.c:549
#define EPR_ASAR_NUM_PER_POINT_ACROSS_LOCAT
Definition: epr_core.h:78
void decode_line_ushort_1_of_1_to_float(void *source_array, EPR_SBandId *band_id, int offset_x, int raster_width, int step_x, void *raster_buffer, int raster_pos)
Definition: epr_band.c:1233
epr_uint epr_get_data_type_size(EPR_EDataTypeId data_type_id)
Definition: epr_core.c:148
unsigned int epr_uint
Definition: epr_api.h:188
void decode_line_uchar_2_of_2_to_uchar(void *source_array, EPR_SBandId *band_id, int offset_x, int raster_width, int step_x, void *raster_buffer, int raster_pos)
Definition: epr_band.c:1391
void epr_free_raster(EPR_SRaster *raster)
Definition: epr_band.c:568
void epr_free_record(EPR_SRecord *record)
Definition: epr_record.c:405
unsigned short epr_ushort
Definition: epr_api.h:187
#define NULL
Definition: decode_rs.h:63
#define EPR_MAGIC_BAND_ID
Definition: epr_api.h:196
void epr_free_flag_coding(EPR_SPtrArray *flag_coding)
Definition: epr_bitmask.c:395
void mirror_uchar_array(epr_uchar *raster_buffer, epr_uint raster_width, epr_uint raster_height)
Definition: epr_band.c:1707
@ e_err_none
Definition: epr_api.h:77
void mirror_float_array(float *raster_buffer, epr_uint raster_width, epr_uint raster_height)
Definition: epr_band.c:1692
@ e_err_invalid_band
Definition: epr_api.h:100
void decode_line_short_1_of_1_to_float(void *source_array, EPR_SBandId *band_id, int offset_x, int raster_width, int step_x, void *raster_buffer, int raster_pos)
Definition: epr_band.c:1263
const char * bitmask_expr
Definition: epr_dddb.h:35
float h[MODELMAX]
Definition: atrem_corl1.h:131
float32 * pos
Definition: l1_czcs_hdf.c:35
#define EPR_LONGI_ABS_MAX
Definition: epr_core.h:62
char * epr_assign_string(char **str_clone, const char *str)
Definition: epr_string.c:29
@ e_tid_float
Definition: epr_api.h:60
EPR_SPtrArray * epr_create_band_ids(EPR_SProductId *product_id)
Definition: epr_band.c:43
@ e_smid_lin
Definition: epr_api.h:141
const char * epr_get_band_name(EPR_SBandId *band_id)
Definition: epr_band.c:266
#define EPR_LONGI_ABS_MIN
Definition: epr_core.h:63
void * epr_get_raster_pixel_addr(const EPR_SRaster *raster, epr_uint x, epr_uint y)
Definition: epr_band.c:1055
void decode_line_short_2_of_2_to_float(void *source_array, EPR_SBandId *band_id, int offset_x, int raster_width, int step_x, void *raster_buffer, int raster_pos)
Definition: epr_band.c:1322
void epr_free_band_id(EPR_SBandId *band_id)
Definition: epr_band.c:284
EPR_SBandId * epr_get_band_id_at(EPR_SProductId *product_id, epr_uint index)
Definition: epr_band.c:217
const double F
const EPR_SField * epr_get_field(const EPR_SRecord *record, const char *field_name)
Definition: epr_field.c:247
float epr_get_scaling_params(EPR_SProductId *product_id, const char *str)
Definition: epr_band.c:320
EPR_SRaster * epr_create_raster(EPR_EDataTypeId data_type, epr_uint source_width, epr_uint source_height, epr_uint source_step_x, epr_uint source_step_y)
Definition: epr_band.c:495
#define EPR_LONGI_BAND_NAME
Definition: epr_core.h:42
epr_boolean epr_equal_names(const char *name1, const char *name2)
Definition: epr_string.c:91
@ e_tid_int
Definition: epr_api.h:58
int epr_numeral_suspicion(const char *str)
Definition: epr_string.c:347
@ e_tid_ushort
Definition: epr_api.h:52
@ e_smod_2TOF
Definition: epr_api.h:136
@ e_err_illegal_data_type
Definition: epr_api.h:86
EPR_SDatasetId * epr_get_dataset_id(EPR_SProductId *product_id, const char *dataset_name)
Definition: epr_dsd.c:96
@ e_smod_2OF2
Definition: epr_api.h:134
@ e_err_null_pointer
Definition: epr_api.h:80
void transform_array_short_to_float(void *sourceArray, EPR_SBandId *band_id, float *raster_buffer, epr_uint nel)
Definition: epr_band.c:1644
void transform_array_int_to_float(void *sourceArray, EPR_SBandId *band_id, float *raster_buffer, epr_uint nel)
Definition: epr_band.c:1668
#define EPR_ENVISAT_PRODUCT_SAR
Definition: epr_core.h:39
EPR_SPtrArray * epr_create_flag_coding(EPR_SProductId *product_id, const char *flag_coding_name)
Definition: epr_bitmask.c:333
epr_uint epr_get_raster_height(EPR_SRaster *raster)
Definition: epr_band.c:1079
epr_uint epr_get_scene_width(const EPR_SProductId *product_id)
Definition: epr_product.c:357
data_t tmp
Definition: decode_rs.h:74
@ e_err_file_read_error
Definition: epr_api.h:91
@ e_err_index_out_of_range
Definition: epr_api.h:84
epr_uint epr_get_raster_elem_size(const EPR_SRaster *raster)
Definition: epr_band.c:1039
const char * description
Definition: epr_dddb.h:38
@ e_err_invalid_value
Definition: epr_api.h:108
enum EPR_ScalingMethod EPR_EScalingMethod
Definition: epr_api.h:165
@ e_tid_uint
Definition: epr_api.h:56
EPR_FLineDecoder select_line_decode_function(EPR_EDataTypeId band_tid, EPR_ESampleModel band_smod, EPR_EDataTypeId raw_tid)
Definition: epr_band.c:1088
What value is used by your function when the data value is bad Default is BAD_FLT l2prod product_id[0]
epr_uint epr_get_field_elem_as_uint(const EPR_SField *field, epr_uint elem_index)
Definition: epr_typconv.c:363
EPR_SRecord * epr_read_record(EPR_SDatasetId *dataset_id, epr_uint record_index, EPR_SRecord *record)
Definition: epr_dataset.c:269
@ e_err_invalid_raster
Definition: epr_api.h:101
EPR_SRaster * epr_create_bitmask_raster(epr_uint source_width, epr_uint source_height, epr_uint source_step_x, epr_uint source_step_y)
Definition: epr_band.c:472
@ e_tid_spare
Definition: epr_api.h:66
void decode_line_uchar_3_to_i_to_uint(void *source_array, EPR_SBandId *band_id, int offset_x, int raster_width, int step_x, void *raster_buffer, int raster_pos)
Definition: epr_band.c:1521
int epr_read_band_annotation_data(EPR_SBandId *band_id, int offset_x, int offset_y, EPR_SRaster *raster)
Definition: epr_band.c:820
#define EPR_ATS_NUM_PER_POINT_ACROSS_LOCAT
Definition: epr_core.h:74
float epr_get_scaling_factor(EPR_SProductId *product_id, const char *str)
Definition: epr_band.c:352
void * epr_get_ptr_array_elem_at(const EPR_SPtrArray *ptr_array, unsigned int index)
Definition: epr_ptrarray.c:122
#define EPR_ATS_LINE_LENGTH
Definition: epr_core.h:76
void decode_line_short_1_of_2_to_float(void *source_array, EPR_SBandId *band_id, int offset_x, int raster_width, int step_x, void *raster_buffer, int raster_pos)
Definition: epr_band.c:1292
@ e_err_invalid_dataset_name
Definition: epr_api.h:102
void(* EPR_FLineDecoder)(void *sourceArray, EPR_SBandId *band_id, int xo, int raster_width, int s_x, void *raster_buffer, int raster_pos)
Definition: epr_band.h:208
@ e_tid_char
Definition: epr_api.h:50
enum EPR_SampleModel EPR_ESampleModel
Definition: epr_api.h:164
int epr_add_ptr_array_elem(EPR_SPtrArray *ptr_array, void *elem)
Definition: epr_ptrarray.c:75
EPR_EScalingMethod epr_str_to_scaling_method(const char *str)
Definition: epr_band.c:429
void epr_clear_err()
Definition: epr_core.c:247
#define EPR_AATSR_LINES_PER_TIE_PT
Definition: epr_core.h:44
void decode_line_uchar_1_of_1_to_uchar(void *source_array, EPR_SBandId *band_id, int offset_x, int raster_width, int step_x, void *raster_buffer, int raster_pos)
Definition: epr_band.c:1352
const char * unit
Definition: epr_dddb.h:37
void decode_line_uchar_1_of_2_to_uchar(void *source_array, EPR_SBandId *band_id, int offset_x, int raster_width, int step_x, void *raster_buffer, int raster_pos)
Definition: epr_band.c:1371
void epr_zero_invalid_pixels(EPR_SRaster *raster, EPR_SRaster *bm_raster)
Definition: epr_band.c:1752
float epr_get_field_elem_as_float(const EPR_SField *field, epr_uint elem_index)
Definition: epr_typconv.c:435
void epr_set_err(EPR_EErrCode err_code, const char *err_message)
Definition: epr_core.c:221
void mirror_ushort_array(epr_ushort *raster_buffer, epr_uint raster_width, epr_uint raster_height)
Definition: epr_band.c:1722
epr_uint epr_get_num_bands(EPR_SProductId *product_id)
Definition: epr_band.c:203
@ e_tid_double
Definition: epr_api.h:62
void decode_line_uchar_1_of_1_to_float(void *source_array, EPR_SBandId *band_id, int offset_x, int raster_width, int step_x, void *raster_buffer, int raster_pos)
Definition: epr_band.c:1173
void transform_array_ushort_to_float(void *sourceArray, EPR_SBandId *band_id, float *raster_buffer, epr_uint nel)
Definition: epr_band.c:1656
void decode_line_uchar_1_of_2_to_float(void *source_array, EPR_SBandId *band_id, int offset_x, int raster_width, int step_x, void *raster_buffer, int raster_pos)
Definition: epr_band.c:1461
EPR_SRecord * epr_create_record(EPR_SDatasetId *dataset_id)
Definition: epr_dataset.c:241
const EPR_ESampleModel sample_offset
Definition: epr_dddb.h:29
float epr_interpolate2D(float wi, float wj, float x00, float x10, float x01, float x11)
Definition: epr_band.c:1639
void decode_tiepoint_band(float *sa_beg, float *sa_end, epr_uint samples_per_tie_pt, epr_uint num_elems, EPR_SBandId *band_id, int offset_x, float scan_offset_x, float y_mod, int raster_width, int s_x, float *raster_buffer, int raster_pos)
Definition: epr_band.c:1557
epr_uint epr_get_scene_height(const EPR_SProductId *product_id)
Definition: epr_product.c:374
EPR_SDatasetRef epr_get_ref_struct(EPR_SProductId *product_id, const char *str)
Definition: epr_band.c:383
const char * str
Definition: l1c_msi.cpp:35
@ e_smod_1OF1
Definition: epr_api.h:132
void decode_line_uchar_2_to_f_to_float(void *source_array, EPR_SBandId *band_id, int offset_x, int raster_width, int step_x, void *raster_buffer, int raster_pos)
Definition: epr_band.c:1429
@ e_smod_3TOI
Definition: epr_api.h:135
EPR_ESampleModel epr_str_to_sample_offset(const char *str)
Definition: epr_band.c:448
epr_uint epr_get_num_records(const EPR_SDatasetId *dataset_id)
Definition: epr_dataset.c:184
@ e_tid_string
Definition: epr_api.h:64
#define fabs(a)
Definition: misc.h:93
@ e_tid_short
Definition: epr_api.h:54
#define EPR_ENVISAT_PRODUCT_MERIS
Definition: epr_core.h:37
char * epr_str_tok(const char *str, const char *seps, int *pos)
Definition: epr_string.c:122
const char * id
Definition: epr_dddb.h:27
@ e_smid_non
Definition: epr_api.h:140
EPR_SBandId * epr_get_band_id(EPR_SProductId *product_id, const char *band_name)
Definition: epr_band.c:237
#define EPR_ENVISAT_PRODUCT_ASAR
Definition: epr_core.h:38
EPR_FArrayTransformer select_transform_array_function(EPR_EDataTypeId band_tid, EPR_EDataTypeId raw_tid)
Definition: epr_band.c:1155
@ e_tid_time
Definition: epr_api.h:68
enum EPR_DataTypeId EPR_EDataTypeId
Definition: epr_api.h:161
#define EPR_NUM_BAND_TABLES
Definition: epr_dddb.h:84
void(* EPR_FArrayTransformer)(void *sourceArray, EPR_SBandId *band_id, float *raster_buffer, epr_uint nel)
Definition: epr_band.h:221
EPR_EErrCode epr_get_last_err_code()
Definition: epr_core.c:265
void * epr_get_raster_line_addr(const EPR_SRaster *raster, epr_uint y)
Definition: epr_band.c:1063
@ e_smid_log
Definition: epr_api.h:142
@ e_tid_unknown
Definition: epr_api.h:46
epr_uint epr_get_raster_width(EPR_SRaster *raster)
Definition: epr_band.c:1071
for(i=0;i< NROOTS;i++) s[i]
Definition: decode_rs.h:85
const int spectral_index
Definition: epr_dddb.h:31
l2prod offset
unsigned char epr_uchar
Definition: epr_api.h:186
void epr_free_and_null_string(char **str)
Definition: epr_string.c:370
const struct BandDescriptor * descriptors
Definition: epr_dddb.h:59
@ e_tid_uchar
Definition: epr_api.h:48
int epr_read_band_raster(EPR_SBandId *band_id, int offset_x, int offset_y, EPR_SRaster *raster)
Definition: epr_band.c:593
#define EPR_FALSE
Definition: epr_api.h:203
int i
Definition: decode_rs.h:71
void * epr_get_raster_elem_addr(const EPR_SRaster *raster, epr_uint offset)
Definition: epr_band.c:1047
How many dimensions is the output array Default is Not sure if anything above will work correctly strcpy(l2prod->title, "no title yet")
const struct BandDescriptorTable dddb_band_tables[37]
Definition: epr_dddb.c:4238
void decode_line_ushort_1_of_1_to_ushort(void *source_array, EPR_SBandId *band_id, int offset_x, int raster_width, int step_x, void *raster_buffer, int raster_pos)
Definition: epr_band.c:1410
epr_boolean epr_check_api_init_flag()
Definition: epr_core.c:475
void mirror_uint_array(epr_uint *raster_buffer, epr_uint raster_width, epr_uint raster_height)
Definition: epr_band.c:1737
void decode_line_char_1_of_1_to_float(void *source_array, EPR_SBandId *band_id, int offset_x, int raster_width, int step_x, void *raster_buffer, int raster_pos)
Definition: epr_band.c:1203
#define EPR_TRUE
Definition: epr_api.h:202
int epr_read_bitmask_raster(EPR_SProductId *product_id, const char *bm_expr, int offset_x, int offset_y, EPR_SRaster *raster)
Definition: epr_bitmask.c:99
int epr_read_band_measurement_data(EPR_SBandId *band_id, int offset_x, int offset_y, EPR_SRaster *raster)
Definition: epr_band.c:689
const char * name
Definition: epr_dddb.h:56
const EPR_EDataTypeId type
Definition: epr_dddb.h:30
const EPR_SField * epr_get_field_at(const EPR_SRecord *record, epr_uint field_index)
Definition: epr_record.c:360
EPR_SPtrArray * epr_create_ptr_array(unsigned int capacity)
Definition: epr_ptrarray.c:29
void transform_array_uint_to_float(void *sourceArray, EPR_SBandId *band_id, float *raster_buffer, epr_uint nel)
Definition: epr_band.c:1680