-
Notifications
You must be signed in to change notification settings - Fork 4
/
datawrit.cpp
124 lines (110 loc) · 3.86 KB
/
datawrit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//***********************************************************
// D A T A W R I T
// Save the scattered data points in XYZ - Comment format.
// Copyright (c) 1999 by John Coulthard
//
// This file is part of QuikGrid.
//
// QuikGrid is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// QuikGrid is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with QuikGrid (File gpl.txt); if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// or visit their website at http://www.fsf.org/licensing/licenses/gpl.txt .
//
// Jan. 28/99: Initial implementation. (Adapted from GridWrit).
// Feb. 1/99: Handle both metric and lat/lon data.
// Jun 1/99: Change to use format conversion routines for lat/lon.
// Jan 9/02: Use double precision for metric output.
//***********************************************************
#include <windows.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <strstream>
#include <math.h>
#include <string.h>
#include <commdlg.h>
#include <time.h>
#pragma hdrstop
#include "surfgrid.h"
#include "scatdata.h"
#include "xygrid.h"
#include "utilitys.h"
#include "rc.h"
#include "quikgrid.h"
#include "paintcon.h"
#include "erwrite.h"
#include "assert.h"
#include "loaddata.h"
using namespace std;
extern char SeparatorCharacter;
//******************************************************************
// A b o r t W r i t e F i l e
//******************************************************************
static void AbortWriteFile( char FileName[] )
{
ostrstream Buf;
Buf << "Error writing data points to the file "
<< FileName
<< ". Output terminated. " << ends;
char *szBuf = Buf.str();
NotifyUser( szBuf );
delete szBuf;
RestoreCursor();
}
//******************************************************************
// S a v e D a t a P o i n t s
//******************************************************************
int OutputDataPointFile( HWND &hwnd )
{
char FileName[256];
if( !GetSaveFile( FileName, hwnd, "Save data points to file" ) ) return 0;
ofstream outFile( FileName, ios::out );
if( !outFile )
{ NotifyUser( IDS_NOOUTPUTFILE );
return 0;
}
static int i, NumberOfDataPoints;
static double xadjust, yadjust, zadjust;
NumberOfDataPoints = ScatterData.Size();
LoadNormalization( xadjust, yadjust);
zadjust = ScatterData.zAdjust();
SetWaitCursor();
outFile << setprecision(12);
for( i = 0; i < NumberOfDataPoints; i++ )
{
if( !(ScatterData.flags(i)&1) ) // Don't write out ignored points.
{
if( LatLonData )
{
outFile << FormatLat( ScatterData.y(i)+yadjust, FALSE )
<< SeparatorCharacter
<< FormatLon( ScatterData.x(i)+xadjust, FALSE )
<< SeparatorCharacter ;
}
else
{
outFile << (ScatterData.x(i)+xadjust) << SeparatorCharacter
<< (ScatterData.y(i)+yadjust) << SeparatorCharacter;
}
outFile << ( ScatterData.z(i)-zadjust ) << SeparatorCharacter ;
outFile << ScatterData.comment(i);
outFile << endl;
if( outFile.fail() ){ AbortWriteFile( FileName );
outFile.close();
return 0; }
}
}
outFile.close();
RestoreCursor();
return 1;
}