MISR Toolkit  1.5.1
MtkSetRegionByPathBlockRange.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkSetRegionByPathBlockRange =
4 = =
5 =============================================================================
6 
7  Jet Propulsion Laboratory
8  MISR
9  MISR Toolkit
10 
11  Copyright 2005, California Institute of Technology.
12  ALL RIGHTS RESERVED.
13  U.S. Government Sponsorship acknowledged.
14 
15 ============================================================================*/
16 
17 #include "MisrSetRegion.h"
18 #include "MisrCoordQuery.h"
19 #include "MisrError.h"
20 #include "MisrUtil.h"
21 #include "MisrOrbitPath.h"
22 #include "MisrProjParam.h"
23 
38  int path_number,
39  int start_block,
40  int end_block,
41  MTKt_Region *region )
42 {
43  MTKt_status status_code; /* Return status of this function */
44  MTKt_status status; /* Return status */
45  MTKt_Region rgn; /* Region structure */
46  int block; /* Block loop index */
47  double min_som_x; /* Minimum SOM X */
48  double max_som_x; /* Maximum SOM X */
49  double min_som_y; /* Minimum SOM Y */
50  double max_som_y; /* Maximum SOM Y */
51  double ulc_som_x; /* Upper left SOM X */
52  double ulc_som_y; /* Upper left SOM Y */
53  double lrc_som_x; /* Lower right SOM X */
54  double lrc_som_y; /* Lower right SOM Y */
55 
56  if (region == NULL)
58 
59  /* Check path bounds */
60  if (path_number < 1 || path_number > 233)
62 
63  /* Check block bounds */
64  if (start_block > end_block)
66 
67  if (start_block < 1 || end_block > 180)
69 
70  /* Set starting som bounds to the coordinates of the first block */
71  status = MtkBlsToSomXY(path_number, MAXRESOLUTION, start_block,
72  0.0, 0.0, &min_som_x, &min_som_y);
73  MTK_ERR_COND_JUMP(status);
74 
75  status = MtkBlsToSomXY(path_number, MAXRESOLUTION, start_block,
76  MAXNLINE-1, MAXNSAMPLE-1, &max_som_x, &max_som_y);
77  MTK_ERR_COND_JUMP(status);
78 
79  /* Expand the coordinates appropriately for each block */
80  for (block = start_block+1; block <= end_block; block++) {
81 
82  status = MtkBlsToSomXY(path_number, MAXRESOLUTION, block,
83  0.0, 0.0, &ulc_som_x, &ulc_som_y);
84  MTK_ERR_COND_JUMP(status);
85  status = MtkBlsToSomXY(path_number, MAXRESOLUTION, block,
86  MAXNLINE-1, MAXNSAMPLE-1, &lrc_som_x, &lrc_som_y);
87  MTK_ERR_COND_JUMP(status);
88 
89 #ifdef DEBUG
90  printf(" %f %f\n", ulc_som_x, min_som_x);
91  printf("%f %f %f %f\n", ulc_som_y, lrc_som_y, min_som_y, max_som_y);
92  printf(" %f %f\n", lrc_som_x, max_som_x);
93 #endif
94 
95  if (ulc_som_x < min_som_x) min_som_x = ulc_som_x;
96  if (lrc_som_x > max_som_x) max_som_x = lrc_som_x;
97  if (ulc_som_y < min_som_y) min_som_y = ulc_som_y;
98  if (lrc_som_y > max_som_y) max_som_y = lrc_som_y;
99  }
100 
101 #ifdef DEBUG
102  {
103  double ulclon, ulclat, lrclon, lrclat;
104 
105  MtkSomXYToLatLon(path_number,min_som_x,min_som_y, &ulclat,&ulclon);
106  MtkSomXYToLatLon(path_number,max_som_x,max_som_y, &lrclat,&lrclon);
107 
108  printf(" %f %f\n", ulclat, min_som_x);
109  printf("%f %f %f %f\n", ulclon, lrclon, min_som_y, max_som_y);
110  printf(" %f %f\n", lrclat, max_som_x);
111  }
112 #endif
113 
114  /* Determine half of the extent in som x/y for entire block range */
115  /* hextent is measured from edge pixel center to edge pixel center */
116  rgn.hextent.xlat = (max_som_x - min_som_x) / 2.0;
117  rgn.hextent.ylon = (max_som_y - min_som_y) / 2.0;
118 
119  if (rgn.hextent.xlat <= 0.0)
121 
122  if (rgn.hextent.ylon <= 0.0)
124 
125  /* Determine center in geographic coordinates */
126  status = MtkSomXYToLatLon(path_number, min_som_x + rgn.hextent.xlat,
127  min_som_y + rgn.hextent.ylon,
128  &(rgn.geo.ctr.lat), &(rgn.geo.ctr.lon));
129  MTK_ERR_COND_JUMP(status);
130 
131  *region = rgn;
132 
133  return MTK_SUCCESS;
134 
135 ERROR_HANDLE:
136  return status_code;
137 }
MTKt_GeoCenter geo
Definition: MisrSetRegion.h:42
#define MAXNSAMPLE
Definition: MisrProjParam.h:25
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
MTKt_status MtkSomXYToLatLon(int path, double som_x, double som_y, double *lat_dd, double *lon_dd)
Convert SOM X, SOM Y to decimal degrees latitude and longitude.
MTKt_GeoCoord ctr
Definition: MisrSetRegion.h:27
MTKt_status MtkSetRegionByPathBlockRange(int path_number, int start_block, int end_block, MTKt_Region *region)
Select region by path and block range.
MTKt_Extent hextent
Definition: MisrSetRegion.h:43
#define MAXRESOLUTION
Definition: MisrProjParam.h:22
MTKt_status MtkBlsToSomXY(int path, int resolution_meters, int block, float line, float sample, double *som_x, double *som_y)
Convert from Block, Line, Sample, to SOM Coordinates.
Definition: MtkBlsToSomXY.c:33
#define MTK_ERR_COND_JUMP(code)
Definition: MisrError.h:188
MTKt_status
Definition: MisrError.h:11
Region of interest.
Definition: MisrSetRegion.h:41
#define MAXNLINE
Definition: MisrProjParam.h:24

MISR Toolkit - Copyright © 2005 - 2020 Jet Propulsion Laboratory
Generated on Fri Jun 19 2020 22:49:51