surface topology data converter
Wookey
wookey@aleph1.co.uk
Tue, 11 Feb 2003 12:47:55 +0000 (GMT)
This message is in MIME format. If you are reading this text, then your mail
package doesn't fully support MIME - there may be a newer release available
from your supplier.
Created using the !Marcel mail package from ANT Ltd <sales@ant.co.uk>
--1447163-1732761957-1044967675=:349093473
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
On Thu 30 Jan, Erin Lynch wrote:
> Sorry to bother everyone, but does anyone have a copy
> of the C program mentioned by Wookey in:
>
> http://www.chaos.org.uk/survex/cp/CP11/CPoint11.htm#Art_5
>
> I have surface topology in HPGL, and I'd like to
> convert it to a format survex can use. Thanks.
Hmm, I've almost certainly got a copy somewhere, but it may take a while to
find.
This would probably be better done a perl or python script these days, but
that's still work for someone.
<fx: wanders round computer for a bit>
got it:
One naff bit of 1994 vintage c code attached.
Wookey
--
Aleph One Ltd, Bottisham, CAMBRIDGE, CB5 9BA, UK Tel +44 (0) 1223 811679
work: http://www.aleph1.co.uk/ play: http://www.chaos.org.uk/~wookey/
--1447163-1732761957-1044967675=:349093473
Content-Type: TEXT/Plain; NAME=HPGL2SVX
Content-Transfer-Encoding: QUOTED-PRINTABLE
/* 1994.09.09 HPtoSVX.C */
/* HPGL to SVX contour converter */
/* Wookey */
/* This code is released under the GNU GPL */
/* takes lines in from HPGL file. If there is a PR line indicating relative
co-ords it stops */
/* For each PU (pen up=3Dmove) command it assumes a new traverse is startin=
g
and writes a new *begin command*/
/* for each PD (pen down=3Ddraw) command it just adds the corresponding leg
to the SVX file */
/* you should get a file in sections with each connected traverse having a
different name, fixed point, and section */
/* There are no heights, as they are not in the original data - you have to
work them out yourself and use search & replace to put them in */
#define INFILE "CONTOUR"
#define OUTFILE "CONTSVX"
#define BUFLEN 20
#define DEBUG 0
#define PI 3.14
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
extern int main (void)
{
FILE *HPGL,*SVX;
char command[3];
int x=3D0,oldx=3D0,y=3D0,oldy=3D0,deltax,deltay;
char buf[BUFLEN];
int cpoint=3D0;
char label[11]=3D"cont";
int clabel=3D0;
int numfields;
double value, comp, tape;
HPGL =3D fopen (INFILE, "rt");
if (HPGL=3D=3DNULL)
{
printf ("couldn't open input HPGL file\n");
exit(0);
}
SVX =3D fopen (OUTFILE, "w");
if (SVX=3D=3DNULL)
{
printf ("couldn't open output .SVX file\n");
exit(0);
}
while (fgets(buf, BUFLEN, HPGL)!=3DNULL)
{
#if DEBUG
printf ("%s\n", buf);
#endif
numfields =3D sscanf (buf, "%2s %d,%d", command,&x,&y);
#if DEBUG
printf ("%s %d %d\n", command, x, y);
#endif
switch (numfields)
{
case (0):
{
printf ("empty line\n");
break;
}
case (1):
{
if (strcmp(command, "PA")=3D=3D0)
printf ("Absolute Coordinates\n");
else
if (strcmp(command, "PR")=3D=3D0)
{
printf ("Relative co-ordinates not implemented - aborting\n");
exit(0);
}
printf ("command ignored\n");
break;
}
case (2):
{
printf ("invalid line\n");
break;
}
case (3):
{
if (strcmp(command,"PU")=3D=3D0) /* start new traverse */
{
if (clabel!=3D0)
/* fprintf(SVX,"*END %s%d\n\n",label,clabel);*/ /* don't do it 1st ti=
me */
printf ("converting traverse %s%d\n",label,clabel);
clabel=3Dclabel+100;
cpoint=3D0;
fprintf(SVX,"*PREFIX \\%s%d\n",label,clabel);
/*fprintf(SVX,"*BEGIN %s%d\n",label,clabel);
*/
fprintf(SVX,"*FIX %d %d %d %d\n",cpoint, x, y, clabel);
oldx=3Dx;oldy=3Dy; /* reset 'from' co-ords */
}
if (strcmp(command,"PD")=3D=3D0)
{
deltax=3Doldx-x;
deltay=3Doldy-y;
/* if (deltay=3D=3D0) /* straight north or south - avoid fp exception =
*/
/*{
if (deltax>=3D0) comp=3D0.0;
if (deltax<0) comp=3D180;
}
else */
{
value=3Datan2((double)deltax,(double)deltay);
comp=3D(360.0*value)/(2.0*PI)+180;
}
tape=3Dsqrt(((double)deltax*(double)deltax) + ((double)deltay*(double=
)deltay));
fprintf(SVX,"%d %d %d %d 0\n",cpoint, cpoint+1, (int)tape, (int)comp)=
;
cpoint++;
oldx=3Dx;oldy=3Dy; /* reset 'from' co-ords */
}
}
}
}; /*do*/
/*fprintf (SVX,"*END %s%d\n",label,clabel);*/ /* complete last survey blo=
ck */
/* tidy up */
fclose (HPGL);
fclose (SVX);
}
--1447163-1732761957-1044967675=:349093473--