2 * Export from Aven as Survex .pos or .csv.
4 /* Copyright (C) 2001,2002,2011,2013,2014,2015,2018 Olly Betts
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include "export.h" // For LABELS, etc
34 #include "namecompare.h"
41 csv_quote(const char* s
, FILE* fh
)
60 // Double up any " in the string to escape them.
71 vector
<pos_label
*>::const_iterator i
;
72 for (i
= todo
.begin(); i
!= todo
.end(); ++i
) {
81 static const int default_passes
[] = { LABELS
|ENTS
|FIXES
|EXPORTS
, 0 };
82 return default_passes
;
85 void POS::header(const char *, const char *, time_t,
86 double, double, double, double, double, double)
90 for (int msgno
: { /*Easting*/378,
93 /*Station Name*/100 }) {
94 if (comma
) PUTC(',', fh
);
95 csv_quote(msg(msgno
), fh
);
100 /* TRANSLATORS: Heading line for .pos file. Please try to ensure the
101 * “,”s (or at least the columns) are in the same place */
102 fputsnl(msg(/*( Easting, Northing, Altitude )*/195), fh
);
107 POS::label(const img_point
*p
, const char *s
, bool /*fSurface*/, int /*type*/)
109 size_t len
= strlen(s
);
110 pos_label
* l
= (pos_label
*)malloc(offsetof(pos_label
, name
) + len
+ 1);
112 throw std::bad_alloc();
116 memcpy(l
->name
, s
, len
+ 1);
120 class pos_label_ptr_cmp
{
124 explicit pos_label_ptr_cmp(char separator_
) : separator(separator_
) { }
126 bool operator()(const POS::pos_label
* a
, const POS::pos_label
* b
) {
127 return name_cmp(a
->name
, b
->name
, separator
) < 0;
134 sort(todo
.begin(), todo
.end(), pos_label_ptr_cmp(separator
));
135 vector
<pos_label
*>::const_iterator i
;
136 for (i
= todo
.begin(); i
!= todo
.end(); ++i
) {
138 fprintf(fh
, "%.2f,%.2f,%.2f,", (*i
)->x
, (*i
)->y
, (*i
)->z
);
139 csv_quote((*i
)->name
, fh
);
142 fprintf(fh
, "(%8.2f, %8.2f, %8.2f ) %s\n",
143 (*i
)->x
, (*i
)->y
, (*i
)->z
, (*i
)->name
);