MISR Toolkit  1.5.1
MisrToolkitTest.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = biz =
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 "MisrToolkit.h"
18 #include "MisrError.h"
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <math.h>
22 
23 
24 
25 int main( ) {
26 
27  MTKt_status status; /* For routine calls */
28  MTKt_status status_code; /* For error handler */
29  char *err_msg[] = MTK_ERR_DESC; /* Error message descriptions */
30 
31  double lat_dd = 32.2, lon_dd = -114.5;
32  double lat, lon;
33  double lat_extent = 200, lon_extent = 100;
34  double somx, somy;
35  int path, res;
36  float line, sample;
37  int block;
38  float blk_line, blk_sample;
39  int l, s;
40  int latdeg, londeg, latmin, lonmin;
41  double latsec, lonsec;
44  char datetime[MTKd_DATETIME_LEN];
45  char filename[200];
46  char gridname[200];
47  char fieldname[200];
49  MTKt_MapInfo brf_mapinfo = MTKT_MAPINFO_INIT;
51  MTKt_MapInfo hdrf_mapinfo = MTKT_MAPINFO_INIT;
52 
53 
54  /* ---------------------------------------------------------- */
55  /* Set a region given center latitude/longitude and an extent */
56  /* ---------------------------------------------------------- */
57 
58  status = MtkSetRegionByLatLonExtent(lat_dd, lon_dd,
59  lat_extent, lon_extent, "km", &region);
60  MTK_ERR_COND_JUMP(status);
61 
62  printf("region center lat/lon (dd) = (%f, %f)\n",
63  region.geo.ctr.lat, region.geo.ctr.lon);
64  printf(" region extent (m) = (%f, %f)\n",
65  region.hextent.xlat * 2.0, region.hextent.ylon * 2.0);
66 
67  /* --------------------------------------------------------- */
68  /* Read data in the region from filename/gridname/fieldname, */
69  /* do some coordinate conversions, query data buffer and */
70  /* get pixel time */
71  /* --------------------------------------------------------- */
72 
73  //strcpy(filename, getenv("MTKHOME"));
74  strcpy(filename, "");
75  strcat(filename, "C:\\Mtk_testdata\\in\\");
76  strcat(filename, "MISR_AM1_GRP_ELLIPSOID_GM_P037_O029058_AA_F03_0024.hdf");
77  strcpy(gridname, "RedBand");
78  strcpy(fieldname, "Red Brf");
79 
80  printf("Filename is: %s\n", filename);
81  status = MtkReadData(filename, gridname, fieldname, region,
82  &brf_databuf, &brf_mapinfo);
83  MTK_ERR_COND_JUMP(status);
84 
85  status = MtkLatLonToLS(brf_mapinfo, lat_dd, lon_dd, &line, &sample);
86  MTK_ERR_COND_JUMP(status);
87 
88  l = (int)round(line);
89  s = (int)round(sample);
90 
91  status = MtkFileToPath(filename, &path);
92  MTK_ERR_COND_JUMP(status);
93 
94  status = MtkFileGridToResolution(filename, gridname, &res);
95  MTK_ERR_COND_JUMP(status);
96 
97  status = MtkLatLonToBls(path, res, lat_dd, lon_dd,
98  &block, &blk_line, &blk_sample);
99  MTK_ERR_COND_JUMP(status);
100 
101  status = MtkLSToLatLon(brf_mapinfo, line, sample, &lat, &lon);
102  MTK_ERR_COND_JUMP(status);
103 
104  status = MtkDdToDegMinSec(lat, &latdeg, &latmin, &latsec);
105  MTK_ERR_COND_JUMP(status);
106 
107  status = MtkDdToDegMinSec(lon, &londeg, &lonmin, &lonsec);
108  MTK_ERR_COND_JUMP(status);
109 
110  status = MtkLSToSomXY(brf_mapinfo, line, sample, &somx, &somy);
111  MTK_ERR_COND_JUMP(status);
112 
113  status = MtkTimeMetaRead(filename, &timemeta);
114  MTK_ERR_COND_JUMP(status);
115 
116  status = MtkPixelTime(timemeta, somx, somy, datetime);
117  MTK_ERR_COND_JUMP(status);
118 
119  printf("\n Reading file = %s\n",filename);
120  printf(" Reading grid = %s\n",gridname);
121  printf(" Reading field = %s\n",fieldname);
122  printf(" number of lines/samples = (%d, %d)\n",
123  brf_mapinfo.nline, brf_mapinfo.nsample);
124  printf(" input lat/lon (dd) = (%f, %f)\n", lat_dd, lon_dd);
125  printf(" line/sample = (%f, %f)\n", line, sample);
126  printf(" Brf[%d][%d] = %f\n", l, s, brf_databuf.data.f[l][s]),
127  printf(" block/line/sample = (%d, %f, %f)\n",
128  block, blk_line, blk_sample);
129  printf(" lat/lon (dd) = (%f, %f)\n", lat, lon);
130  printf(" lat/lon (dms) = (%d:%d:%f, %d:%d:%f)\n",
131  latdeg, latmin, latsec, londeg, lonmin, lonsec);
132  printf(" SOM x/y = (%f, %f)\n", somx, somy);
133  printf(" pixel time[%d][%d] = %s\n", l, s, datetime);
134 
135  MtkDataBufferFree(&brf_databuf);
136 
137  /* --------------------------------------------------------- */
138  /* Read data in the region from filename/gridname/fieldname */
139  /* with extra dimensions, do some coordinate conversions and */
140  /* query data buffer */
141  /* --------------------------------------------------------- */
142 
143  //strcpy(filename, getenv("MTKHOME"));
144  strcpy(filename,"");
145  strcat(filename, "C:\\Mtk_testdata\\in\\");
146  strcat(filename, "MISR_AM1_AS_LAND_P037_O029058_F06_0017.hdf");
147  strcpy(gridname, "SubregParamsLnd");
148  strcpy(fieldname, "LandHDRF[3][4]");
149 
150  status = MtkReadData(filename, gridname, fieldname, region,
151  &hdrf_databuf, &hdrf_mapinfo);
152  MTK_ERR_COND_JUMP(status);
153 
154  status = MtkLatLonToLS(hdrf_mapinfo, lat_dd, lon_dd, &line, &sample);
155  MTK_ERR_COND_JUMP(status);
156 
157  l = (int)round(line);
158  s = (int)round(sample);
159 
160  status = MtkFileToPath(filename, &path);
161  MTK_ERR_COND_JUMP(status);
162 
163  status = MtkFileGridToResolution(filename, gridname, &res);
164  MTK_ERR_COND_JUMP(status);
165 
166  status = MtkLatLonToBls(path, res, lat_dd, lon_dd,
167  &block, &blk_line, &blk_sample);
168  MTK_ERR_COND_JUMP(status);
169 
170  status = MtkLSToLatLon(hdrf_mapinfo, line, sample, &lat, &lon);
171  MTK_ERR_COND_JUMP(status);
172 
173  status = MtkDdToDegMinSec(lat, &latdeg, &latmin, &latsec);
174  MTK_ERR_COND_JUMP(status);
175 
176  status = MtkDdToDegMinSec(lon, &londeg, &lonmin, &lonsec);
177  MTK_ERR_COND_JUMP(status);
178 
179  status = MtkLatLonToSomXY(path, lat_dd, lon_dd, &somx, &somy);
180  MTK_ERR_COND_JUMP(status);
181 
182  printf("\n Reading file = %s\n",filename);
183  printf(" Reading grid = %s\n",gridname);
184  printf(" Reading field = %s\n",fieldname);
185  printf(" number of lines/samples = (%d, %d)\n",
186  hdrf_mapinfo.nline, hdrf_mapinfo.nsample);
187  printf(" input lat/lon (dd) = (%f, %f)\n", lat_dd, lon_dd);
188  printf(" line/sample = (%f, %f)\n", line, sample);
189  printf(" HDRF[%d][%d] = %f\n", l, s, hdrf_databuf.data.f[l][s]),
190  printf(" block/line/sample = (%d, %f, %f)\n",
191  block, blk_line, blk_sample);
192  printf(" lat/lon (dd) = (%f, %f)\n", lat, lon);
193  printf(" lat/lon (dms) = (%d:%d:%f, %d:%d:%f)\n",
194  latdeg, latmin, latsec, londeg, lonmin, lonsec);
195  printf(" SOM x/y = (%f, %f)\n", somx, somy);
196 
197  MtkDataBufferFree(&hdrf_databuf);
198 
199  return MTK_SUCCESS;
200  ERROR_HANDLE:
201  printf("Error: %s\n",err_msg[status_code]);
202  MtkDataBufferFree(&hdrf_databuf);
203  return status_code;
204 }
MTKt_status MtkLatLonToBls(int path, int resolution_meters, double lat_dd, double lon_dd, int *block, float *line, float *sample)
Convert decimal degrees latitude and longitude to block, line, sample.
#define MTKT_TIME_METADATA_INIT
Definition: MisrFileQuery.h:91
char * filename
Definition: cdjpeg.h:133
MTKt_DataBufferType data
Definition: MisrUtil.h:104
#define MTKT_MAPINFO_INIT
Definition: MisrMapQuery.h:79
MTKt_status MtkLSToLatLon(MTKt_MapInfo mapinfo, float line, float sample, double *lat_dd, double *lon_dd)
Convert line, sample to decimal degrees latitude and longitude.
Definition: MtkLSToLatLon.c:33
MTKt_GeoCenter geo
Definition: MisrSetRegion.h:42
#define MTKT_REGION_INIT
Definition: MisrSetRegion.h:46
MTKt_status MtkLSToSomXY(MTKt_MapInfo mapinfo, float line, float sample, double *som_x, double *som_y)
Convert line, sample to SOM X, SOM Y.
Definition: MtkLSToSomXY.c:33
MTKt_status MtkLatLonToLS(MTKt_MapInfo mapinfo, double lat_dd, double lon_dd, float *line, float *sample)
Convert decimal degrees latitude and longitude to line, sample.
Definition: MtkLatLonToLS.c:33
Map Information.
Definition: MisrMapQuery.h:65
2-dimensional Data Buffer
Definition: MisrUtil.h:98
MTKt_float ** f
Definition: MisrUtil.h:93
MTKt_GeoCoord ctr
Definition: MisrSetRegion.h:27
#define MTKT_DATABUFFER_INIT
Definition: MisrUtil.h:109
MTKt_status MtkDataBufferFree(MTKt_DataBuffer *databuf)
Free data buffer.
#define MTK_ERR_DESC
Definition: MisrError.h:91
int main()
MTKt_Extent hextent
Definition: MisrSetRegion.h:43
MTKt_status MtkReadData(const char *filename, const char *gridname, const char *fieldname, MTKt_Region region, MTKt_DataBuffer *databuf, MTKt_MapInfo *mapinfo)
Reads any grid/field from any MISR product file and performs unpacking or unscaling. It also reads any MISR conventional product file.
Definition: MtkReadData.c:62
MTKt_status MtkSetRegionByLatLonExtent(double ctr_lat_dd, double ctr_lon_dd, double lat_extent, double lon_extent, const char *extent_units, MTKt_Region *region)
Select region by latitude, longitude in decimal degrees, and extent in specified units of degrees...
MTKt_status MtkTimeMetaRead(const char *filename, MTKt_TimeMetaData *time_metadata)
Read time metadata from L1B2 Ellipsoid product file.
Time Metadata.
Definition: MisrFileQuery.h:77
MTKt_status MtkPixelTime(MTKt_TimeMetaData time_metadata, double som_x, double som_y, char pixel_time[MTKd_DATETIME_LEN])
Given SOM Coordinates compute pixel time.
Definition: MtkPixelTime.c:41
MTKt_status MtkDdToDegMinSec(double dd, int *deg, int *min, double *sec)
Convert decimal degrees to unpacked degrees, minutes, seconds.
#define MTK_ERR_COND_JUMP(code)
Definition: MisrError.h:188
MTKt_status
Definition: MisrError.h:11
Region of interest.
Definition: MisrSetRegion.h:41
MTKt_status MtkFileToPath(const char *filename, int *path)
Read path number from file.
Definition: MtkFileToPath.c:35
#define MTKd_DATETIME_LEN
Definition: MisrUtil.h:149
MTKt_status MtkLatLonToSomXY(int path, double lat_dd, double lon_dd, double *som_x, double *som_y)
Convert decimal degrees latitude and longitude to SOM X, SOM Y.
MTKt_status MtkFileGridToResolution(const char *filename, const char *gridname, int *resolution)
Get resolution of a particular grid.

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