bes  Updated for version 3.20.6
misr_init.cc
1 // The code in this file is adopted from A.7.2 of MISR data products specifications
2 // Revision S
3 // https://eosweb.larc.nasa.gov/sites/default/files/project/misr/DPS_v50_RevS.pdf)
4 //
5 #ifdef USE_HDFEOS2_LIB
6 #include "misrproj.h" /* Prototype for this function */
7 #include "errormacros.h" /* Error macros */
8 int nb;
9 int nl;
10 int ns;
11 float absOffset[NBLOCK];
12 float relOffset[NBLOCK-1];
13 double ulc[2];
14 double lrc[2];
15 double sx;
16 double sy;
17 double xc;
18 double yc;
19 #define FUNC_NAMEm "misr_init"
20 int misr_init(
21  const int nblock, /* Number of blocks */
22  const int nline, /* Number of lines in a block */
23  const int nsample, /* Number of samples in a block */
24  const float relOff[NOFFSET],/* Block offsets */
25 
26  const double ulc_coord[], /* Upper left corner coord. in meters */
27  const double lrc_coord[] /* Lower right corner coord. in meters */
28 )
29 {
30  int i; /* Offset index */
31  char msg[STRLEN]; /* Warning message */
32  /* Argument checks */
33  if (nblock < 1 || nblock > NBLOCK) {
34  snprintf(msg,STRLEN,"nblock is out of range (1 < %d < %d)", nblock, NBLOCK);
35  WRN_LOG_JUMP(msg);
36  }
37  /* Convert relative offsets to absolute offsets */
38  absOffset[0] = 0.0;
39  for (i = 1; i < NBLOCK; i++) {
40  absOffset[i] = absOffset[i-1] + relOff[i-1];
41  relOffset[i-1] = relOff[i-1];
42  }
43  /* Set ulc and lrc SOM coordinates */
44  /* Note; ulc y and lrc y are reversed in the structural metadata. */
45  ulc[0] = ulc_coord[0];
46  ulc[1] = lrc_coord[1];
47  lrc[0] = lrc_coord[0];
48  lrc[1] = ulc_coord[1];
49  /* Set number of blocks, lines and samples */
50  nb = nblock;
51  nl = nline;
52  ns = nsample;
53  /* Compute pixel size in ulc/lrc units (meters) */
54  sx = (lrc[0] - ulc[0]) / nl;
55  sy = (lrc[1] - ulc[1]) / ns;
56  /* Adjust ulc to be in the center of the pixel */
57  xc = ulc[0] + sx / 2.0;
58  yc = ulc[1] + sy / 2.0;
59  return(0);
60 ERROR_HANDLE:
61  return(1);
62 }
63 #endif