~ubuntu-branches/ubuntu/raring/geotranz/raring

« back to all changes in this revision

Viewing changes to geotrans2/src/source.c

  • Committer: Bazaar Package Importer
  • Author(s): Roberto Lumbreras
  • Date: 2008-10-17 14:43:09 UTC
  • Revision ID: james.westby@ubuntu.com-20081017144309-jb7uzfi1y1lvez8j
Tags: upstream-2.4.2
ImportĀ upstreamĀ versionĀ 2.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************/
 
2
/* RSC IDENTIFIER: Source
 
3
 *
 
4
 * ABSTRACT
 
5
 *
 
6
 *
 
7
 * ERROR HANDLING
 
8
 *
 
9
 *    This component checks for input file errors and input parameter errors.
 
10
 *    If an invalid value is found, the error code is combined with the current
 
11
 *    error code using the bitwise or.  This combining allows multiple error
 
12
 *    codes to be returned. The possible error codes are:
 
13
 *
 
14
 *  SOURCE_NO_ERROR                  : No errors occurred in function
 
15
 *  SOURCE_INVALID_INDEX_ERROR       : Index out of valid range (less than one
 
16
 *                                      or more than Source_Count)
 
17
 *  SOURCE_INVALID_NAME_ERROR        : Source name not found
 
18
 *
 
19
 *
 
20
 * REUSE NOTES
 
21
 *
 
22
 *    Source is intended for reuse by any application that needs access to 
 
23
 *    accuracy sources.
 
24
 *
 
25
 *    
 
26
 * REFERENCES
 
27
 *
 
28
 *    Further information on Source can be found in the Reuse Manual.
 
29
 *
 
30
 *    Source originated from :  U.S. Army Topographic Engineering Center (USATEC)
 
31
 *                              Geospatial Information Division (GID)
 
32
 *                              7701 Telegraph Road
 
33
 *                              Alexandria, VA  22310-3864
 
34
 *
 
35
 * LICENSES
 
36
 *
 
37
 *    None apply to this component.
 
38
 *
 
39
 * RESTRICTIONS
 
40
 *
 
41
 *    Source has no restrictions.
 
42
 *
 
43
 * ENVIRONMENT
 
44
 *
 
45
 *    Source was tested and certified in the following environments:
 
46
 *
 
47
 *    1. Solaris 2.5 with GCC 2.8.1
 
48
 *    2. MS Windows 95 with MS Visual C++ 6
 
49
 *
 
50
 * MODIFICATIONS
 
51
 *
 
52
 *    Date              Description
 
53
 *    ----              -----------
 
54
 *    01/07/2008        Changed SE90 values,
 
55
 *                      Ned A. Ferris
 
56
 *                      (see extended explanation below)
 
57
 *
 
58
 * The modifications discussed below were made by Ned A. Ferris
 
59
 * on 7 January 2008.
 
60
 *
 
61
 * During Final Acceptance Testing (FAT) of the Coordinate
 
62
 * Conversion Service and Application (CCS and CCA),
 
63
 * 15 to 17 July 2007, Dr. Duane Brown (Navy) filed a 
 
64
 * discrepancy reported against the 90% Spherical Error values
 
65
 * for DTED Levels 1 and 2. This DR was GEOTRANS-0013 which cross 
 
66
 * references with the BAE discrepancy report BAEts21981.
 
67
 * 
 
68
 * Discussions with Dr. Brown and Dan Mullaney (NGA) regarding SE90 
 
69
 * values culminated at the MSP FAT DR TEM on 20 December 2007. 
 
70
 * At this technical exchange meeting, it was decided to replace 
 
71
 * the existing SE90 values with those calculated by an equation 
 
72
 * developed by Dr. Brown (see below). The formulas given below
 
73
 * were extracted from a PowerPoint Presentation sent to NGMS by
 
74
 * Dr. Brown; the actual derivations of the formulas were not documented.
 
75
 * 
 
76
 * Given CE90 and LE90 and the following definitions:
 
77
 * 
 
78
 * sqrt(x):  the square root of x.
 
79
 * 
 
80
 * sigma_xy: the standard deviation of the circular/ground components.
 
81
 * 
 
82
 * ratio:    the ratio of sigma_Z over sigma_xy
 
83
 * 
 
84
 * Let sigma_xy = sqrt(CE90^2/chi-square_distribution(0.1,2))
 
85
 *              = sqrt(CE90^2/4.60517612509304)
 
86
 * 
 
87
 * Let ratio    = (sqrt(LE90^2/chi-square_distribution(0.1,1)))/sigma_xy
 
88
 *              = (sqrt(LE90^2/2.70554058545338))/sigma_xy
 
89
 * 
 
90
 * If ratio < 5, then:
 
91
 * 
 
92
 * SE90 = 
 
93
 * (2.129292146             - 
 
94
 * (0.115864822 * ratio)    +
 
95
 * (0.6391671   * ratio^2)  -
 
96
 * (0.277130883 * ratio^3)  +
 
97
 * (0.148193487 * ratio^4)  -  
 
98
 * (0.037837525 * ratio^5)  +
 
99
 * (0.003262523 * ratio^6)) * sigma_xy
 
100
 * 
 
101
 * If ratio >= 5, then:
 
102
 * 
 
103
 * SE90 = 
 
104
 * (0.010469959           + 
 
105
 * (1.636566894*ratio)    +
 
106
 * (3.58376E-10*ratio^2)  -
 
107
 * (1.3613E-14*ratio^3)   +
 
108
 * (2.4342E-19*ratio^4)   -  
 
109
 * (2.04984E-24*ratio^5)  +
 
110
 * (6.55643E-30*ratio^6)) * sigma_xy
 
111
 * 
 
112
 * The 90% Spherical Error values in the Accuracy_Sources Source_Table
 
113
 * were recalculated using the above formula (except for CIB and DFAD,
 
114
 * see below). They were all rounded up to the nearest integer value.
 
115
 * The ratio values were all less than 5, so only the first of the above 
 
116
 * two formulas was used.
 
117
 * 
 
118
 * In addition, based on communications with Dan Mullaney on 
 
119
 * 27 December 2007, it was determined that:
 
120
 * 
 
121
 * 1. CIB has no vertical accuracy standard.
 
122
 * 
 
123
 * 2. DFAD is planimetric and doesn't have a vertical component.
 
124
 *    
 
125
 * SE90 is therefore not applicable for either CIB or DFAS. The SE90
 
126
 * values for all CIB and DFAD products were set to -1.
 
127
 *
 
128
 */
 
129
 
 
130
 
 
131
/***************************************************************************/
 
132
/*
 
133
 *                               INCLUDES
 
134
 */
 
135
 
 
136
#include <string.h>
 
137
#include "source.h"
 
138
 
 
139
/***************************************************************************/
 
140
/*
 
141
 *                               DEFINES
 
142
 */
 
143
#define SOURCE_NAME_LENGTH          50
 
144
#define NUMBER_SOURCES              19
 
145
 
 
146
/***************************************************************************/
 
147
/*
 
148
 *                          GLOBAL DECLARATIONS
 
149
 */
 
150
 
 
151
typedef struct Accuracy_Source_Value
 
152
{
 
153
  char Name[SOURCE_NAME_LENGTH];
 
154
  double CE;        /* circular error */
 
155
  double LE;        /* linear error */
 
156
  double SE;        /* spherical error */
 
157
} Accuracy_Sources; /* defines an accuracy source */
 
158
 
 
159
 
 
160
 
 
161
static const Accuracy_Sources Source_Table[NUMBER_SOURCES] = {{"Unknown", -1, -1, -1},
 
162
                                                              {"User defined (1 meter)", 1, 1, 2},
 
163
                                                              {"GPS PPS", 20, 20, 26},
 
164
                                                              {"GPS SPS", 20, 20, 26},
 
165
                                                              {"1:25,000 City Map", 50, 20, 52},
 
166
                                                              {"1:50,000 Topographic Line Map (TLM)", 50, 20, 52},
 
167
                                                              {"1:50,000 Combat Chart", 50, 20, 52},
 
168
                                                              {"1:100,000 Topographic Line Map (TLM)", 100, 20, 100},
 
169
                                                              {"1:250,000 Joint Operations Graphic (JOG)", 250, 100, 258},
 
170
                                                              {"1:500,000 Tactical Pilotage Chart (TPC)", 1000, 150, 993},
 
171
                                                              {"1:1,000,000 Operational Navigation Chart (ONC)", 2000, 650, 2031},
 
172
                                                              {"Digital Terrain Elevation Data (DTED) Level 1", 50, 30, 55},
 
173
                                                              {"Digital Terrain Elevation Data (DTED) Level 2", 23, 18, 27},
 
174
                                                              {"Digital Feature Analysis Data (DFAD) Level 1", 130, -1, -1},
 
175
                                                              {"Digital Feature Analysis Data (DFAD) Level 2", 130, -1, -1},
 
176
                                                              {"Controlled Image Base (CIB) [>10m GSD]", 25, -1, -1},
 
177
                                                              {"Vector Smart Map (VMAP) Level 1", 250, 100, 258},
 
178
                                                              {"Vector Smart Map (VMAP) Level 2 (1:100,000)", 100, 20, 100},
 
179
                                                              {"Vector Smart Map (VMAP) Level 2 (1:50,000)", 50, 20, 52}};
 
180
 
 
181
 
 
182
 
 
183
/***************************************************************************/
 
184
/*
 
185
 *                              FUNCTIONS     
 
186
 */
 
187
void Source_Count (long *Count)
 
188
 
 
189
{ /* Begin Source_Count */
 
190
  /*
 
191
   *  The function Source_Count returns the number of source accuracies 
 
192
   *
 
193
   *  Count                : number of accuracy sources      (output)
 
194
   */
 
195
 
 
196
    *Count = NUMBER_SOURCES;
 
197
 
 
198
} /* End of Source_Count */
 
199
 
 
200
 
 
201
long Source_Index( const char *Name,
 
202
                   long *Index )
 
203
 
 
204
{ /* Begin Source_Index */
 
205
  /*
 
206
   *  The function Source_Index returns the index of the source accuracy with the 
 
207
   *  specified name.
 
208
   *
 
209
   *  Name    : The source name being searched for.                   (input)
 
210
   *  Index   : The index of the accuracy source with the             (output)
 
211
   *              specified code.
 
212
   */
 
213
  char temp_name[SOURCE_NAME_LENGTH];
 
214
  long error_code = SOURCE_NO_ERROR;
 
215
  long length;
 
216
  long i = 0;
 
217
 
 
218
  *Index = 0;
 
219
  length = strlen(Name);
 
220
  if (length > (SOURCE_NAME_LENGTH-1))
 
221
    error_code |= SOURCE_INVALID_NAME_ERROR;
 
222
  else
 
223
  {
 
224
    strcpy(temp_name,Name);
 
225
 
 
226
    /* Convert to upper case */
 
227
/*    for (i=0;i<length;i++)
 
228
      temp_name[i] = (char)toupper(temp_name[i]);*/
 
229
 
 
230
    /* Strip blank spaces */
 
231
/*      while (pos < length)
 
232
    {
 
233
      if (isspace(temp_name[pos]))
 
234
      {
 
235
        for (i=pos;i<=length;i++)
 
236
          temp_name[i] = temp_name[i+1];
 
237
        length -= 1;
 
238
      }
 
239
      else
 
240
        pos += 1;
 
241
    }*/
 
242
    /* Search for code */
 
243
   /// i = 0;
 
244
    while (i < NUMBER_SOURCES && strcmp(temp_name, Source_Table[i].Name))
 
245
    {
 
246
      i++;
 
247
    }
 
248
    if (i == NUMBER_SOURCES || strcmp(temp_name, Source_Table[i].Name))
 
249
      error_code |= SOURCE_INVALID_NAME_ERROR;
 
250
    else
 
251
      *Index = i+1;
 
252
  }
 
253
  return (error_code);
 
254
} /* End Source_Index */
 
255
 
 
256
 
 
257
long Source_Name (const long Index,
 
258
                  char *Name)
 
259
{ /* Begin Source_Name */
 
260
  /*
 
261
   *  The function Source_Name returns the name of the source accuracy referenced by
 
262
   *  index.
 
263
   *
 
264
   *  Index   : The index of a given datum in the datum table.        (input)
 
265
   *  Name    : The accuracy source Name referenced by Index.         (output)
 
266
   */
 
267
 
 
268
  long error_code = SOURCE_NO_ERROR;
 
269
 
 
270
  if ((Index > 0) && (Index <= NUMBER_SOURCES))
 
271
    strcpy(Name, Source_Table[Index-1].Name);
 
272
  else
 
273
    error_code |= SOURCE_INVALID_INDEX_ERROR;
 
274
  return (error_code);
 
275
} /* End Source_Name */
 
276
 
 
277
 
 
278
long Source_Accuracy (const long Index, 
 
279
                                                    double *CE,
 
280
                                                    double *LE,
 
281
                                                    double *SE)
 
282
{ /* Begin Source_Accuracy */
 
283
/*
 
284
 *   The function Source_Accuracy returns the accuracy values (CE, LE, SE)
 
285
 *   for the source referenced by index.
 
286
 *
 
287
 *    Index      : The index of a given datum in the datum table   (input)
 
288
 *    CE         : Circular error                                  (output)
 
289
 *    LE         : Linear error                                    (output)
 
290
 *    SE         : Spherical error                                 (output)
 
291
 */
 
292
 
 
293
  long error_code = SOURCE_NO_ERROR;
 
294
 
 
295
  if (Index > 0 && Index <= NUMBER_SOURCES)
 
296
  {
 
297
    *CE = Source_Table[Index-1].CE;
 
298
    *LE = Source_Table[Index-1].LE;
 
299
    *SE = Source_Table[Index-1].SE;
 
300
  }
 
301
  else
 
302
  {
 
303
    error_code |= SOURCE_INVALID_INDEX_ERROR;
 
304
  }
 
305
  return (error_code);
 
306
} /* End Source_Accuracy */
 
307
 
 
308
 
 
309