MISR Toolkit  1.5.1
MtkCreateLatLon.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkCreateLatLon =
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 "MisrReadData.h"
18 #include "MisrProjParam.h"
19 #include "MisrMapQuery.h"
20 #include "MisrCoordQuery.h"
21 #include "MisrUtil.h"
22 #include "MisrError.h"
23 
49  MTKt_MapInfo mapinfo,
50  MTKt_DataBuffer *latbuf,
51  MTKt_DataBuffer *lonbuf )
52 {
53  MTKt_status status; /* Return status */
54  MTKt_status status_code; /* Return status code for error macros */
56  /* Latitude data buffer structure */
58  /* Longitude data buffer structure */
59  float line; /* Data plane line index */
60  float sample; /* Data plane sample index */
61  double somx; /* SOM X */
62  double somy; /* SOM Y */
63  int b; /* Block index */
64  int l; /* Block line index */
65  int s; /* Block sample index */
66  int lp; /* Data plane integer line index */
67  int sp; /* Data plane integer sample index */
68 
69  /* --------------------------------------------------- */
70  /* Allocate buffers of the latitude and longitude data */
71  /* --------------------------------------------------- */
72 
73  status = MtkDataBufferAllocate(mapinfo.nline, mapinfo.nsample,
74  MTKe_double, &lat);
75  MTK_ERR_COND_JUMP(status);
76  status = MtkDataBufferAllocate(mapinfo.nline, mapinfo.nsample,
77  MTKe_double, &lon);
78  MTK_ERR_COND_JUMP(status);
79 
80  /* ------------------------------ */
81  /* Fill with a default fill value */
82  /* ------------------------------ */
83 
84  for (l = 0; l < mapinfo.nline; l++) {
85  for (s = 0; s < mapinfo.nsample; s++) {
86  lat.data.d[l][s] = -200.0;
87  lon.data.d[l][s] = -200.0;
88  }
89  }
90 
91  /* --------------------------------------------------------------- */
92  /* Compute the lat/lon for each block/line/sample in the swath */
93  /* that intersect with the data plane defined my mapinfo */
94  /* --------------------------------------------------------------- */
95 
96  for (b = mapinfo.start_block; b <= mapinfo.end_block; b++) {
97  for (l = 0; l < mapinfo.pp.nline; l++) {
98  for (s = 0; s < mapinfo.pp.nsample; s++) {
99  MtkBlsToSomXY(mapinfo.path, mapinfo.resolution, b, (float)l, (float)s,
100  &somx, &somy);
101  MtkSomXYToLS(mapinfo, somx, somy, &line, &sample);
102  lp = (int)line;
103  sp = (int)sample;
104  if (lp >= 0 && lp < mapinfo.nline &&
105  sp >= 0 && sp < mapinfo.nsample) {
106  MtkSomXYToLatLon(mapinfo.path, somx, somy,
107  &(lat.data.d[lp][sp]), &(lon.data.d[lp][sp]));
108  }
109  }
110  }
111  }
112 
113  *latbuf = lat;
114  *lonbuf = lon;
115 
116  return MTK_SUCCESS;
117  ERROR_HANDLE:
118  MtkDataBufferFree(&lat);
119  MtkDataBufferFree(&lon);
120  return status_code;
121 }
MTKt_double ** d
Definition: MisrUtil.h:94
MTKt_status MtkDataBufferAllocate(int nline, int nsample, MTKt_DataType datatype, MTKt_DataBuffer *databuf)
Allocate Data Buffer.
MTKt_DataBufferType data
Definition: MisrUtil.h:104
Map Information.
Definition: MisrMapQuery.h:65
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.
2-dimensional Data Buffer
Definition: MisrUtil.h:98
long b
Definition: jpegint.h:371
MTKt_MisrProjParam pp
Definition: MisrMapQuery.h:76
#define MTKT_DATABUFFER_INIT
Definition: MisrUtil.h:109
MTKt_status MtkDataBufferFree(MTKt_DataBuffer *databuf)
Free data buffer.
MTKt_status MtkSomXYToLS(MTKt_MapInfo mapinfo, double som_x, double som_y, float *line, float *sample)
Convert SOM X, SOM Y to line, sample.
Definition: MtkSomXYToLS.c:32
MTKt_status MtkCreateLatLon(MTKt_MapInfo mapinfo, MTKt_DataBuffer *latbuf, MTKt_DataBuffer *lonbuf)
Creates a 2-D latitude buffer and a 2-D longitude buffer in decimal degrees corresponding to the data...
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

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