MISR Toolkit  1.5.1
MtkGCTPProjInfoRead.c
Go to the documentation of this file.
1 /*===========================================================================
2 = =
3 = MtkGCTPProjInfoRead =
4 = =
5 =============================================================================
6 
7  Jet Propulsion Laboratory
8  MISR
9  MISR Toolkit
10 
11  Copyright 2008, California Institute of Technology.
12  ALL RIGHTS RESERVED.
13  U.S. Government Sponsorship acknowledged.
14 
15 ============================================================================*/
16 
17 #include "MisrMapQuery.h"
18 #include "MisrUtil.h"
19 #include <stdlib.h>
20 #include <math.h>
21 
22 #define MAX_LENGTH 1000
23 
65  const char *Filename,
66  MTKt_GCTPProjInfo *Proj_info
67 )
68 {
69  MTKt_status status; /* Return status */
70  MTKt_status status_code; /* Return status of this function */
72  /* Proj information */
73  int proj_code;
74  int utm_zone = -1;
75  int sphere_code;
76  double proj_param[15] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
77  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
78 
79  int proj_code_found = 0;
80  int utm_zone_found = 0;
81  int sphere_code_found = 0;
82 
83  int i;
84  double value;
85 
86  FILE *fp = NULL;
87  char line[MAX_LENGTH]; /* Line buffer for input file. */
88 
89  /* ------------------------------------------------------------------ */
90  /* Argument check: Filename == NULL */
91  /* ------------------------------------------------------------------ */
92 
93  if (Filename == NULL) {
94  MTK_ERR_CODE_MSG_JUMP(MTK_NULLPTR,"Filename == NULL");
95  }
96 
97  /* ------------------------------------------------------------------ */
98  /* Argument check: Proj_info == NULL */
99  /* ------------------------------------------------------------------ */
100 
101  if (Proj_info == NULL) {
102  MTK_ERR_CODE_MSG_JUMP(MTK_NULLPTR,"Proj_info == NULL");
103  }
104 
105  /* ------------------------------------------------------------------ */
106  /* Open file. */
107  /* ------------------------------------------------------------------ */
108 
109  fp = fopen(Filename,"r");
110  if (fp == NULL) {
112  }
113 
114  /* ------------------------------------------------------------------ */
115  /* Scan input file for proj parameters. */
116  /* ------------------------------------------------------------------ */
117 
118  while (NULL != fgets(line,MAX_LENGTH,fp)) {
119  if (line[0] == '#') continue;
120 
121  if (1 == sscanf(line, "proj_code = %d",&proj_code)) {
122  proj_code_found = 1;
123  } else if (1 == sscanf(line, "utm_zone = %d",&utm_zone)) {
124  utm_zone_found = 1;
125  } else if (1 == sscanf(line, "sphere_code = %d",&sphere_code)) {
126  sphere_code_found = 1;
127  } else if (2 == sscanf(line, "proj_param(%d) = %lf",&i,&value)) {
128  if (i > 0 && i < 16) {
129  proj_param[i-1] = value;
130  }
131  } else {
132  /* Skip unrecognized input */
133  }
134  }
135 
136  /* ------------------------------------------------------------------ */
137  /* Close file. */
138  /* ------------------------------------------------------------------ */
139 
140  fclose(fp);
141  fp = NULL;
142 
143  /* ------------------------------------------------------------------ */
144  /* Check that all required paramters were found. */
145  /* Argument check: proj_code not found */
146  /* proj_code == UTM && utm_zone not found */
147  /* sphere_code not found */
148  /* ------------------------------------------------------------------ */
149 
150  if (!proj_code_found) {
151  MTK_ERR_CODE_MSG_JUMP(MTK_NOT_FOUND,"proj_code not found");
152  }
153  if (proj_code == 1 && !utm_zone_found) {
154  MTK_ERR_CODE_MSG_JUMP(MTK_NOT_FOUND,"utm_zone not found");
155  }
156  if (!sphere_code_found) {
157  MTK_ERR_CODE_MSG_JUMP(MTK_NOT_FOUND,"sphere_code not found");
158  }
159 
160  /* ------------------------------------------------------------------ */
161  /* Initialize proj information. */
162  /* ------------------------------------------------------------------ */
163 
164  status = MtkGCTPProjInfo(proj_code, sphere_code, utm_zone, proj_param,
165  &proj_info_tmp);
166  MTK_ERR_COND_JUMP(status);
167 
168  /* ------------------------------------------------------------------ */
169  /* Return. */
170  /* ------------------------------------------------------------------ */
171 
172  *Proj_info = proj_info_tmp;
173  return MTK_SUCCESS;
174 
175 ERROR_HANDLE:
176  if (fp != NULL) {
177  fclose(fp);
178  }
179  return status_code;
180 }
181 
182 
GCTP projection information.
Definition: MisrMapQuery.h:123
#define MTK_ERR_CODE_JUMP(code)
Definition: MisrError.h:175
MTKt_status MtkGCTPProjInfo(int Proj_code, int Sphere_code, int Zone_code, double Proj_param[15], MTKt_GCTPProjInfo *Proj_info)
Initialize a MTKt_GCTPProjInfo structure.
#define MTK_ERR_CODE_MSG_JUMP(code, msg)
Definition: MisrError.h:181
MTKt_status MtkGCTPProjInfoRead(const char *Filename, MTKt_GCTPProjInfo *Proj_info)
Initialize a MTKt_GCTPProjInfo structure using data from an external file.
#define MAX_LENGTH
#define MTK_ERR_COND_JUMP(code)
Definition: MisrError.h:188
MTKt_status
Definition: MisrError.h:11
#define MTKT_GCTPPROJINFO_INIT
Definition: MisrMapQuery.h:130

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