MISR Toolkit  1.5.1
MtkCreateGeoGrid.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkCreateGeoGrid =
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 "MisrReProject.h"
18 #include "MisrError.h"
19 #include "MisrUtil.h"
20 
37  double ulc_lat_dd,
38  double ulc_lon_dd,
39  double lrc_lat_dd,
40  double lrc_lon_dd,
41  double lat_cellsize_dd,
42  double lon_cellsize_dd,
43  MTKt_DataBuffer *latbuf,
44  MTKt_DataBuffer *lonbuf )
45 {
46  MTKt_status status; /* Return status */
47  MTKt_status status_code; /* Return code of this function */
49  /* Latitude data buffer structure */
51  /* Longitude data buffer structure */
52  double lat_extent_dd; /* Latitude extent */
53  double lon_extent_dd; /* Longitude extent */
54  double lontmp; /* Temporary longitude */
55  int nline; /* Number of lines */
56  int nsample; /* Number of samples */
57  int l; /* Line index */
58  int s; /* Sample index */
59 
60  /* Check latitude bounds */
61  if (ulc_lat_dd > 90.0 || ulc_lat_dd < -90.0)
63  if (lrc_lat_dd > 90.0 || lrc_lat_dd < -90.0)
65  if (ulc_lat_dd < lrc_lat_dd)
67 
68  /* Check longitude bounds */
69  if (ulc_lon_dd > 180.0 || ulc_lon_dd < -180.0)
71  if (lrc_lon_dd > 180.0 || lrc_lon_dd < -180.0)
73 
74  /* Check latitude cell size bounds */
75  if (lat_cellsize_dd <= 0.0)
77 
78  /* Check longitude cell size bounds */
79  if (lon_cellsize_dd <= 0.0)
81 
82  /* Check for date line crossing */
83  lat_extent_dd = ulc_lat_dd - lrc_lat_dd;
84  if (ulc_lon_dd > lrc_lon_dd) {
85  lon_extent_dd = 360 + lrc_lon_dd - ulc_lon_dd; /* Date line crossed */
86  } else {
87  lon_extent_dd = lrc_lon_dd - ulc_lon_dd;
88  }
89 
90  nline = (int) (lat_extent_dd / lat_cellsize_dd) + 1;
91  nsample = (int) (lon_extent_dd / lon_cellsize_dd) + 1;
92 
93  /* --------------------------------------------------- */
94  /* Allocate buffers of the latitude and longitude data */
95  /* --------------------------------------------------- */
96 
97  status = MtkDataBufferAllocate(nline, nsample, MTKe_double, &lat);
98  MTK_ERR_COND_JUMP(status);
99  status = MtkDataBufferAllocate(nline, nsample, MTKe_double, &lon);
100  MTK_ERR_COND_JUMP(status);
101 
102  /* ------------------------ */
103  /* Compute Geographic Grid */
104  /* ------------------------ */
105 
106  if (ulc_lon_dd > lrc_lon_dd) {
107  for (l=0; l < nline; l++) { /* Date line crossed */
108  for (s=0; s < nsample; s++) {
109  lat.data.d[l][s] = ulc_lat_dd - lat_cellsize_dd * l;
110  lontmp = ulc_lon_dd + lon_cellsize_dd * s;
111  lon.data.d[l][s] = lontmp > 180 ? lontmp - 360.0 : lontmp;
112  }
113  }
114  } else {
115  for (l=0; l < nline; l++) {
116  for (s=0; s < nsample; s++) {
117  lat.data.d[l][s] = ulc_lat_dd - lat_cellsize_dd * l;
118  lon.data.d[l][s] = ulc_lon_dd + lon_cellsize_dd * s;
119  }
120  }
121  }
122 
123  *latbuf = lat;
124  *lonbuf = lon;
125 
126  return MTK_SUCCESS;
127 ERROR_HANDLE:
128  MtkDataBufferFree(&lat);
129  MtkDataBufferFree(&lon);
130  return status_code;
131 }
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
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
2-dimensional Data Buffer
Definition: MisrUtil.h:98
#define MTKT_DATABUFFER_INIT
Definition: MisrUtil.h:109
MTKt_status MtkDataBufferFree(MTKt_DataBuffer *databuf)
Free data buffer.
MTKt_status MtkCreateGeoGrid(double ulc_lat_dd, double ulc_lon_dd, double lrc_lat_dd, double lrc_lon_dd, double lat_cellsize_dd, double lon_cellsize_dd, MTKt_DataBuffer *latbuf, MTKt_DataBuffer *lonbuf)
Creates a regularly spaced geographic 2-D grid consisting of a latitude buffer and a longitude buffer...
#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