OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
EnvsatDSR.cpp
Go to the documentation of this file.
1 /*
2  * File: EnvsatDSR.cpp
3  * Author: dshea
4  *
5  * Created on November 28, 2012, 1:11 PM
6  */
7 
8 #include "EnvsatDSR.h"
9 
10 #include "EnvsatUtil.h"
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <genutils.h>
16 
17 using namespace std;
18 
20  init(orig.size);
21 }
22 
24  init(size);
25 }
26 
28  if (buffer)
29  free(buffer);
30 }
31 
32 void EnvsatDSR::init(int size) {
33  this->size = size;
34  buffer = (char*) malloc(size);
35  arrayOffset = 13;
36  pixelSize = 2;
37  numPixels = (size - arrayOffset) / pixelSize;
38 }
39 
41  printf("EnvsatDSR-----\n");
42  printf("size = %d\n", size);
43  printf("numPixels = %d\n", numPixels);
44 }
45 
47  print();
48 }
49 
50 int EnvsatDSR::readData(int fin) {
51  ssize_t result;
52  int num = 0;
53 
54  while (num < size) {
55  result = read(fin, buffer + num, size - num);
56  if (result <= 0)
57  return -1;
58  else
59  num += result;
60  }
61  return 0;
62 }
63 
64 int EnvsatDSR::writeData(int fout) {
65  ssize_t result;
66  int num = 0;
67 
68  while (num < size) {
69  result = write(fout, buffer + num, size - num);
70  if (result <= 0)
71  return -1;
72  else
73  num += result;
74  }
75  return 0;
76 }
77 
78 void EnvsatDSR::setRange(int offset, int count, int val) {
79  if (offset < 0)
80  return;
81  if (offset + count > numPixels)
82  count = numPixels - offset;
83 
84  // the gcc optimizer crashes if accessing 16 bit int on an odd boundary in
85  // some cases, so we need to accessing the array by byte.
86  char* ptr = buffer + arrayOffset + offset * pixelSize;
87  int16_t val16 = val;
88  char* valPtr = (char*) &val16;
89 
90 
91  if (!endianess())
92  swapc_bytes(valPtr, 2, 1);
93 
94  int i;
95  for (i = 0; i < count; i++) {
96  *ptr = valPtr[0];
97  ptr++;
98  *ptr = valPtr[1];
99  ptr++;
100  }
101 
102 }
103 
virtual int readData(int fin)
Definition: EnvsatDSR.cpp:50
EnvsatDSR(const EnvsatDSR &orig)
Definition: EnvsatDSR.cpp:19
int endianess(void)
determine endianess
Definition: endianess.c:10
int swapc_bytes(char *in, int nbyte, int ntime)
Definition: swapc_bytes.c:4
int init(int32_t ipr, int32_t jpr, char *efile, char *pfile)
Definition: proj_report.c:51
virtual ~EnvsatDSR()
Definition: EnvsatDSR.cpp:27
virtual void printRecursive()
Definition: EnvsatDSR.cpp:46
virtual int writeData(int fout)
Definition: EnvsatDSR.cpp:64
l2prod offset
int i
Definition: decode_rs.h:71
msiBandIdx val
Definition: l1c_msi.cpp:34
virtual void setRange(int offset, int count, int val)
Definition: EnvsatDSR.cpp:78
virtual void print()
Definition: EnvsatDSR.cpp:40
int count
Definition: decode_rs.h:79