source: git/src/netskel.c

walls-data-hanging-as-warning
Last change on this file was 094d93d, checked in by Olly Betts <olly@…>, 7 days ago

Skip replacing traverse if hanging

  • Property mode set to 100644
File size: 31.5 KB
RevLine 
[ff6cfe1]1/* netskel.c
[045c055]2 * Survex network reduction - remove trailing traverses and concatenate
3 * traverses between junctions
[fdf79f4]4 * Copyright (C) 1991-2004,2005,2006,2010,2011,2012,2013,2014,2015 Olly Betts
[846746e]5 *
[89231c4]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.
[846746e]10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
[89231c4]13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
[846746e]15 *
[89231c4]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
[d333899]18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
[045c055]19 */
20
[7fda0c8]21/* #define BLUNDER_DETECTION */
[045c055]22
23#if 0
24#define DEBUG_INVALID 1
25#define VALIDATE 1
[c30a8f3]26#define DUMP_NETWORK 1
[045c055]27#endif
28
[4c83f84]29#include <config.h>
[045c055]30
31#include "validate.h"
32#include "debug.h"
33#include "cavern.h"
[5d59477]34#include "commands.h"
[045c055]35#include "filename.h"
36#include "message.h"
37#include "filelist.h"
[a405bc1]38#include "img_hosted.h"
[e329f0f]39#include "netartic.h"
[045c055]40#include "netbits.h"
41#include "netskel.h"
42#include "network.h"
43#include "out.h"
44
45#define sqrdd(X) (sqrd((X)[0]) + sqrd((X)[1]) + sqrd((X)[2]))
46
47typedef struct Stack {
48   struct Link *join1, *join2;
49   struct Stack *next;
50} stack;
51
52typedef struct StackTr {
53   struct Link *join1;
54   struct StackTr *next;
55} stackTrail;
56
57/* string used between things in traverse printouts eg \1 - \2 - \3 -...*/
58static const char *szLink = " - ";
59static const char *szLinkEq = " = "; /* use this one for equates */
60
61#if 0
62#define fprint_prefix(FH, NAME) BLK((fprint_prefix)((FH), (NAME));\
[421b7d2]63                                    fprintf((FH), " [%p]", (void*)(NAME)); )
[045c055]64#endif
65
66static stack *ptr; /* Ptr to TRaverse linked list for in-between travs */
67static stackTrail *ptrTrail; /* Ptr to TRaverse linked list for trail travs*/
68
69static void remove_trailing_travs(void);
70static void remove_travs(void);
71static void replace_travs(void);
72static void replace_trailing_travs(void);
[ee05463]73static void write_passage_models(void);
[045c055]74
75static void concatenate_trav(node *stn, int i);
76
77static void err_stat(int cLegsTrav, double lenTrav,
78                     double eTot, double eTotTheo,
79                     double hTot, double hTotTheo,
80                     double vTot, double vTotTheo);
81
82extern void
83solve_network(void /*node *stnlist*/)
84{
85   static int first_solve = 1;
86   node *stn;
87
[fdf79f4]88   /* We can't average across solving to fix positions. */
89   clear_last_leg();
90
[dfe4a520]91   if (stnlist == NULL) {
92      if (first_solve) fatalerror(/*No survey data*/43);
93      /* We've had a *solve followed by another *solve (or the implicit
94       * *solve at the end of the data.  Don't moan about that. */
95      return;
96   }
[045c055]97   ptr = NULL;
98   ptrTrail = NULL;
99   dump_network();
100
[b39e24a]101   if (first_solve && !pcs->proj_str && !proj_str_out) {
[3b066f6]102      /* If we haven't already solved to find some station positions, and
103       * there's no specified coordinate system, then check if there are any
104       * fixed points, and if there aren't, invent one at (0,0,0).
105       *
106       * We do this first so the solving part is just like the standard case -
107       * this avoid problems, such as sub-nodes of the invented fix having been
108       * removed.  It also means we can fix the "first" station, which makes
109       * more sense to the user. */
110      FOR_EACH_STN(stn, stnlist)
111         if (fixed(stn)) break;
112
113      if (!stn) {
114        /* If we've had a *solve and all the new survey since then is hanging,
115         * we don't want to invent a fixed point.  We want to complain but
116         * the easiest way to is just to continue processing and let
117         * articulate() catch this condition as it will any hanging survey
118         * data. */
119         node *stnFirst = NULL;
120
121         /* New stations are pushed onto the head of the list, so the
122          * first station added is the last in the list. */
123         FOR_EACH_STN(stn, stnlist) {
124             /* Prefer a station with legs attached when choosing one to fix
125              * so that if there's a hanging station on a nosurvey leg we pick
126              * the main clump of survey data. */
127             if (stnFirst && !stnFirst->leg[0]) continue;
128             stnFirst = stn;
129         }
130
131         /* If we've got nosurvey legs, then the station we find to fix could
132          * have no real legs attached. */
133         SVX_ASSERT2(nosurveyhead || stnFirst->leg[0],
134                     "no fixed stns, but we've got a zero node!");
135         SVX_ASSERT2(stnFirst, "no stations left in net!");
136         stn = stnFirst;
137         printf(msg(/*Survey has no fixed points. Therefore I’ve fixed %s at (0,0,0)*/72),
138                sprint_prefix(stn->name));
139         putnl();
140         POS(stn,0) = (real)0.0;
141         POS(stn,1) = (real)0.0;
142         POS(stn,2) = (real)0.0;
143         fix(stn);
[1fa9b83]144      }
[045c055]145   }
146
[c30a8f3]147   first_solve = 0;
148
[045c055]149   remove_trailing_travs();
150   validate(); dump_network();
151   remove_travs();
152   validate(); dump_network();
153   remove_subnets();
154   validate(); dump_network();
[7222b04]155   articulate();
[045c055]156   validate(); dump_network();
157   replace_subnets();
158   validate(); dump_network();
159   replace_travs();
160   validate(); dump_network();
161   replace_trailing_travs();
162   validate(); dump_network();
[ee05463]163
164   /* Now write out any passage models. */
165   write_passage_models();
[045c055]166}
167
168static void
169remove_trailing_travs(void)
170{
171   node *stn;
[736f7df]172   /* TRANSLATORS: In French, Eric chose to use the terminology used by
173    * toporobot: "sequence" for the English "traverse", which makes sense
174    * (although toporobot actually uses this term to mean something more
175    * specific).  Feel free to follow this lead if you can't think of a better
176    * term - these messages mostly indicate how processing is progressing.
[b49ac56]177    *
[736f7df]178    * A trailing traverse is a dead end back to a junction. */
[045c055]179   out_current_action(msg(/*Removing trailing traverses*/125));
180   FOR_EACH_STN(stn, stnlist) {
181      if (!fixed(stn) && one_node(stn)) {
182         int i = 0;
183         int j;
184         node *stn2 = stn;
185         stackTrail *trav;
186
187#if PRINT_NETBITS
188         printf("Removed trailing trav ");
189#endif
190         do {
191            struct Link *leg;
192#if PRINT_NETBITS
[e27a0c3]193            print_prefix(stn2->name); printf("<%p>",stn2); fputs(szLink, stdout);
[045c055]194#endif
195            remove_stn_from_list(&stnlist, stn2);
196            leg = stn2->leg[i];
197            j = reverse_leg_dirn(leg);
198            stn2 = leg->l.to;
199            i = j ^ 1; /* flip direction for other leg of 2 node */
200            /* stop if fixed or 3 or 1 node */
201         } while (two_node(stn2) && !fixed(stn2));
[cb3d1e2]202
[045c055]203         /* put traverse on stack */
204         trav = osnew(stackTrail);
205         trav->join1 = stn2->leg[j];
206         trav->next = ptrTrail;
207         ptrTrail = trav;
208
209         /* We want to keep all 2-nodes using legs 0 and 1 and all one nodes
210          * using leg 0 so we may need to swap leg j with leg 2 (for a 3 node)
211          * or leg 1 (for a fixed 2 node) */
[421b7d2]212         if ((j == 0 && !one_node(stn2)) || (j == 1 && three_node(stn2))) {
[045c055]213            /* i is the direction to swap with */
[eb18f4d]214            i = (three_node(stn2)) ? 2 : 1;
[045c055]215            /* change the other direction of leg i to use leg j */
216            reverse_leg(stn2->leg[i])->l.reverse += j - i;
217            stn2->leg[j] = stn2->leg[i];
218            j = i;
219         }
220         stn2->leg[j] = NULL;
221
222#if PRINT_NETBITS
223         print_prefix(stn2->name); printf("<%p>",stn2); putnl();
224#endif
225      }
226   }
227}
228
229static void
230remove_travs(void)
231{
232   node *stn;
[736f7df]233   /* TRANSLATORS: In French, Eric chose to use the terminology used by
234    * toporobot: "sequence" for the English "traverse", which makes sense
235    * (although toporobot actually uses this term to mean something more
236    * specific).  Feel free to follow this lead if you can't think of a better
237    * term - these messages mostly indicate how processing is progressing. */
[c20d521]238   out_current_action(msg(/*Concatenating traverses*/126));
[045c055]239   FOR_EACH_STN(stn, stnlist) {
[4a0d231]240      if (fixed(stn) || three_node(stn)) {
[ec8a439]241         int d;
242         for (d = 0; d <= 2; d++) {
243            linkfor *leg = stn->leg[d];
244            if (leg && !(leg->l.reverse & FLAG_REPLACEMENTLEG))
245               concatenate_trav(stn, d);
246         }
[045c055]247      }
248   }
249}
250
251static void
252concatenate_trav(node *stn, int i)
253{
254   int j;
255   stack *trav;
256   node *stn2;
257   linkfor *newleg, *newleg2;
258
259   stn2 = stn->leg[i]->l.to;
260   /* Reject single legs as they may be already concatenated traverses */
261   if (fixed(stn2) || !two_node(stn2)) return;
262
263   trav = osnew(stack);
264   newleg2 = (linkfor*)osnew(linkrev);
265
266#if PRINT_NETBITS
267   printf("Concatenating trav "); print_prefix(stn->name); printf("<%p>",stn);
268#endif
269
270   newleg2->l.to = stn;
271   newleg2->l.reverse = i | FLAG_REPLACEMENTLEG;
272   trav->join1 = stn->leg[i];
273
274   j = reverse_leg_dirn(stn->leg[i]);
[4c07c51]275   SVX_ASSERT(j == 0 || j == 1);
[045c055]276
277   newleg = copy_link(stn->leg[i]);
278
[cb3d1e2]279   while (1) {
[045c055]280      stn = stn2;
281
282#if PRINT_NETBITS
[e27a0c3]283      fputs(szLink, stdout); print_prefix(stn->name); printf("<%p>",stn);
[045c055]284#endif
[cb3d1e2]285
[045c055]286      /* stop if fixed or 3 or 1 node */
287      if (fixed(stn) || !two_node(stn)) break;
[cb3d1e2]288
[045c055]289      remove_stn_from_list(&stnlist, stn);
290
291      i = j ^ 1; /* flip direction for other leg of 2 node */
292
293      stn2 = stn->leg[i]->l.to;
294      j = reverse_leg_dirn(stn->leg[i]);
295
296      addto_link(newleg, stn->leg[i]);
297   }
[cb3d1e2]298
[045c055]299   trav->join2 = stn->leg[j];
300   trav->next = ptr;
301   ptr = trav;
302
303   newleg->l.to = stn;
[4a0d231]304   newleg->l.reverse = j | FLAG_DATAHERE | FLAG_REPLACEMENTLEG;
[045c055]305
[ec8a439]306   newleg2->l.to->leg[reverse_leg_dirn(newleg2)] = newleg;
307   /* i.e. stn->leg[i] = newleg; with original stn and i */
308
[045c055]309   stn->leg[j] = newleg2;
310
311#if PRINT_NETBITS
312   putchar(' ');
[be97baf]313   print_var(&(newleg->v));
[045c055]314   printf("\nStacked ");
315   print_prefix(newleg2->l.to->name);
316   printf(",%d-", reverse_leg_dirn(newleg2));
317   print_prefix(stn->name);
318   printf(",%d\n", j);
319#endif
320}
321
322#ifdef BLUNDER_DETECTION
323/* expected_error is actually squared... */
[25ab06b]324/* only called if fhErrStat != NULL */
[045c055]325static void
[eb18f4d]326do_gross(delta e, delta v, node *stn1, node *stn2, double expected_error)
[cb3d1e2]327{
[045c055]328   double hsqrd, rsqrd, s, cx, cy, cz;
329   double tot;
330   int i;
331   int output = 0;
[647407d]332   prefix *name1 = stn1->name, *name2 = stn2->name;
[045c055]333
334#if 0
335printf( "e = ( %.2f, %.2f, %.2f )", e[0], e[1], e[2] );
336printf( " v = ( %.2f, %.2f, %.2f )\n", v[0], v[1], v[2] );
337#endif
338   hsqrd = sqrd(v[0]) + sqrd(v[1]);
339   rsqrd = hsqrd + sqrd(v[2]);
340   if (rsqrd == 0.0) return;
341
342   cx = v[0] + e[0];
343   cy = v[1] + e[1];
344   cz = v[2] + e[2];
345
346   s = (e[0] * v[0] + e[1] * v[1] + e[2] * v[2]) / rsqrd;
347   tot = 0;
348   for (i = 2; i >= 0; i--) tot += sqrd(e[i] - v[i] * s);
349
[25ab06b]350   if (tot <= expected_error) {
[045c055]351      if (!output) {
352         fprint_prefix(fhErrStat, name1);
353         fputs("->", fhErrStat);
354         fprint_prefix(fhErrStat, name2);
355      }
[647407d]356      fprintf(fhErrStat, " L: %.2f", sqrt(tot));
357      /* checked - works */
358      fprintf(fhErrStat, " (%.2fm -> %.2fm)", sqrt(sqrdd(v)), sqrt(sqrdd(v)) * (1 - s));
[045c055]359      output = 1;
360   }
361
362   s = sqrd(cx) + sqrd(cy);
363   if (s > 0.0) {
364      s = hsqrd / s;
[4c07c51]365      SVX_ASSERT(s >= 0.0);
[647407d]366      s = sqrt(s);
[045c055]367      s = 1 - s;
368      tot = sqrd(cx * s) + sqrd(cy * s) + sqrd(e[2]);
[25ab06b]369      if (tot <= expected_error) {
[647407d]370         double newval, oldval;
[045c055]371         if (!output) {
372            fprint_prefix(fhErrStat, name1);
373            fputs("->", fhErrStat);
374            fprint_prefix(fhErrStat, name2);
375         }
[647407d]376         fprintf(fhErrStat, " B: %.2f", sqrt(tot));
377         /* checked - works */
378         newval = deg(atan2(cx, cy));
379         if (newval < 0) newval += 360;
380         oldval = deg(atan2(v[0], v[1]));
381         if (oldval < 0) oldval += 360;
382         fprintf(fhErrStat, " (%.2fdeg -> %.2fdeg)", oldval, newval);
[045c055]383         output = 1;
384      }
385   }
386
387   if (hsqrd > 0.0) {
388      double nx, ny;
389      s = (e[0] * v[1] - e[1] * v[0]) / hsqrd;
390      nx = cx - s * v[1];
391      ny = cy + s * v[0];
392      s = sqrd(nx) + sqrd(ny) + sqrd(cz);
393      if (s > 0.0) {
[421b7d2]394         s = rsqrd / s;
[4c07c51]395         SVX_ASSERT(s >= 0);
[421b7d2]396         s = sqrt(s);
397         tot = sqrd(cx - s * nx) + sqrd(cy - s * ny) + sqrd(cz - s * cz);
[25ab06b]398         if (tot <= expected_error) {
[045c055]399            if (!output) {
400               fprint_prefix(fhErrStat, name1);
401               fputs("->", fhErrStat);
402               fprint_prefix(fhErrStat, name2);
403            }
[647407d]404            fprintf(fhErrStat, " G: %.2f", sqrt(tot));
405            /* checked - works */
406            fprintf(fhErrStat, " (%.2fdeg -> %.2fdeg)",
407                    deg(atan2(v[2], sqrt(v[0] * v[0] + v[1] * v[1]))),
408                    deg(atan2(cz, sqrt(nx * nx + ny * ny))));
[045c055]409            output = 1;
410         }
411      }
412   }
[25ab06b]413   if (output) fputnl(fhErrStat);
[045c055]414}
415#endif
416
417static void
418replace_travs(void)
419{
420   stack *ptrOld;
421   node *stn1, *stn2, *stn3;
422   int i, j, k;
[407084d]423   double eTot = 0, lenTrav = 0, lenTot;
424   double eTotTheo = 0;
425   double vTot = 0, vTotTheo = 0, hTot = 0, hTotTheo = 0;
[eb18f4d]426   delta e, sc;
[045c055]427   bool fEquate; /* used to indicate equates in output */
[407084d]428   int cLegsTrav = 0;
[402c753]429   bool fArtic;
[045c055]430
[736f7df]431    /* TRANSLATORS: In French, Eric chose to use the terminology used by
432     * toporobot: "sequence" for the English "traverse", which makes sense
433     * (although toporobot actually uses this term to mean something more
434     * specific).  Feel free to follow this lead if you can't think of a better
435     * term - these messages mostly indicate how processing is progressing. */
[c20d521]436   out_current_action(msg(/*Calculating traverses*/127));
[045c055]437
[647407d]438   if (!fhErrStat && !fSuppress)
[045c055]439      fhErrStat = safe_fopen_with_ext(fnm_output_base, EXT_SVX_ERRS, "w");
440
[693388e]441   if (!pimg) {
[a4ae909]442      char *fnm = add_ext(fnm_output_base, EXT_SVX_3D);
[06a871f]443      filename_register_output(fnm);
[0532954]444      pimg = img_open_write_cs(fnm, s_str(&survey_title), proj_str_out,
[5d59477]445                               img_FFLAG_SEPARATOR(output_separator));
[a4ae909]446      if (!pimg) fatalerror(img_error(), fnm);
[06a871f]447      osfree(fnm);
[045c055]448   }
449
450   /* First do all the one leg traverses */
451   FOR_EACH_STN(stn1, stnlist) {
[be97baf]452#if PRINT_NETBITS
453      printf("One leg traverses from ");
454      print_prefix(stn1->name);
455      printf(" [%p]\n", stn1);
456#endif
[045c055]457      for (i = 0; i <= 2; i++) {
458         linkfor *leg = stn1->leg[i];
459         if (leg && data_here(leg) &&
[693388e]460             !(leg->l.reverse & (FLAG_REPLACEMENTLEG | FLAG_FAKE))) {
[4c07c51]461            SVX_ASSERT(fixed(stn1));
462            SVX_ASSERT(!fZeros(&leg->v));
[693388e]463
[e6cfe52]464            stn2 = leg->l.to;
465            if (TSTBIT(leg->l.flags, FLAGS_SURFACE)) {
466               stn1->name->sflags |= BIT(SFLAGS_SURFACE);
467               stn2->name->sflags |= BIT(SFLAGS_SURFACE);
468            } else {
469               stn1->name->sflags |= BIT(SFLAGS_UNDERGROUND);
470               stn2->name->sflags |= BIT(SFLAGS_UNDERGROUND);
471            }
[a4ae909]472            img_write_item(pimg, img_MOVE, 0, NULL,
473                           POS(stn1, 0), POS(stn1, 1), POS(stn1, 2));
474            if (leg->meta) {
[1ee204e]475                pimg->days1 = leg->meta->days1;
476                pimg->days2 = leg->meta->days2;
[a4ae909]477            } else {
[1ee204e]478                pimg->days1 = pimg->days2 = -1;
[e6cfe52]479            }
[eb5aea0]480            pimg->style = (leg->l.flags >> FLAGS_STYLE_BIT0) & 0x07;
481            img_write_item(pimg, img_LINE, leg->l.flags & FLAGS_MASK,
[a4ae909]482                           sprint_prefix(stn1->name->up),
483                           POS(stn2, 0), POS(stn2, 1), POS(stn2, 2));
[e6cfe52]484            if (!(leg->l.reverse & FLAG_ARTICULATION)) {
[25ab06b]485#ifdef BLUNDER_DETECTION
[e6cfe52]486               delta err;
487               int do_blunder;
[25ab06b]488#else
[e6cfe52]489               if (fhErrStat) {
490                  fprint_prefix(fhErrStat, stn1->name);
491                  fputs(szLink, fhErrStat);
492                  fprint_prefix(fhErrStat, stn2->name);
493               }
[402c753]494#endif
[e6cfe52]495               subdd(&e, &POSD(stn2), &POSD(stn1));
496               subdd(&e, &e, &leg->d);
497               if (fhErrStat) {
498                  eTot = sqrdd(e);
499                  hTot = sqrd(e[0]) + sqrd(e[1]);
500                  vTot = sqrd(e[2]);
[045c055]501#ifndef NO_COVARIANCES
[f795df0]502                  /* FIXME: what about covariances? */
[e6cfe52]503                  hTotTheo = leg->v[0] + leg->v[1];
504                  vTotTheo = leg->v[2];
[0a208f9]505                  eTotTheo = hTotTheo + vTotTheo;
[045c055]506#else
[e6cfe52]507                  hTotTheo = leg->v[0] + leg->v[1];
508                  vTotTheo = leg->v[2];
[f7c455c]509                  eTotTheo = hTotTheo + vTotTheo;
[0a208f9]510#endif
[647407d]511#ifdef BLUNDER_DETECTION
[a8c4cfa]512                  memcpy(&err, &e, sizeof(delta));
[e6cfe52]513                  do_blunder = (eTot > eTotTheo);
514                  fputs("\ntraverse ", fhErrStat);
515                  fprint_prefix(fhErrStat, stn1->name);
516                  fputs("->", fhErrStat);
517                  fprint_prefix(fhErrStat, stn2->name);
518                  fprintf(fhErrStat, " e=(%.2f, %.2f, %.2f) mag=%.2f %s\n",
519                          e[0], e[1], e[2], sqrt(eTot),
520                          (do_blunder ? "suspect:" : "OK"));
521                  if (do_blunder)
522                     do_gross(err, leg->d, stn1, stn2, eTotTheo);
523#endif
524                  err_stat(1, sqrt(sqrdd(leg->d)), eTot, eTotTheo,
525                           hTot, hTotTheo, vTot, vTotTheo);
[cb3d1e2]526               }
[045c055]527            }
528         }
529      }
530   }
531
532   while (ptr != NULL) {
533      /* work out where traverse should be reconnected */
[eb18f4d]534      linkfor *leg = ptr->join1;
[045c055]535      leg = reverse_leg(leg);
536      stn1 = leg->l.to;
537      i = reverse_leg_dirn(leg);
538
539      leg = ptr->join2;
540      leg = reverse_leg(leg);
541      stn2 = leg->l.to;
542      j = reverse_leg_dirn(leg);
543
544#if PRINT_NETBITS
545      printf(" Trav ");
546      print_prefix(stn1->name);
[be97baf]547      printf("<%p>[%d]%s...%s", stn1, i, szLink, szLink);
[045c055]548      print_prefix(stn2->name);
[be97baf]549      printf("<%p>[%d]\n", stn2, j);
[045c055]550#endif
[e6cfe52]551
[094d93d]552      if (!fixed(stn1)) {
553          SVX_ASSERT(!fixed(stn2));
554          goto skip_hanging_traverse;
555      }
[4c07c51]556      SVX_ASSERT(fixed(stn2));
[e6cfe52]557
[045c055]558      /* calculate scaling factors for error distribution */
[e6cfe52]559      eTot = 0.0;
560      hTot = vTot = 0.0;
[4c07c51]561      SVX_ASSERT(data_here(stn1->leg[i]));
[e6cfe52]562      if (fZeros(&stn1->leg[i]->v)) {
563         sc[0] = sc[1] = sc[2] = 0.0;
564      } else {
565         subdd(&e, &POSD(stn2), &POSD(stn1));
566         subdd(&e, &e, &stn1->leg[i]->d);
567         eTot = sqrdd(e);
568         hTot = sqrd(e[0]) + sqrd(e[1]);
569         vTot = sqrd(e[2]);
570         divds(&sc, &e, &stn1->leg[i]->v);
571      }
[045c055]572#ifndef NO_COVARIANCES
[f795df0]573      /* FIXME: what about covariances? */
[e6cfe52]574      hTotTheo = stn1->leg[i]->v[0] + stn1->leg[i]->v[1];
575      vTotTheo = stn1->leg[i]->v[2];
[045c055]576#else
[e6cfe52]577      hTotTheo = stn1->leg[i]->v[0] + stn1->leg[i]->v[1];
578      vTotTheo = stn1->leg[i]->v[2];
[045c055]579#endif
[f7c455c]580      eTotTheo = hTotTheo + vTotTheo;
[e6cfe52]581      cLegsTrav = 0;
582      lenTrav = 0.0;
[a4ae909]583      img_write_item(pimg, img_MOVE, 0, NULL,
584                     POS(stn1, 0), POS(stn1, 1), POS(stn1, 2));
[e6cfe52]585
[402c753]586      fArtic = stn1->leg[i]->l.reverse & FLAG_ARTICULATION;
[045c055]587      osfree(stn1->leg[i]);
588      stn1->leg[i] = ptr->join1; /* put old link back in */
589
590      osfree(stn2->leg[j]);
591      stn2->leg[j] = ptr->join2; /* and the other end */
592
593#ifdef BLUNDER_DETECTION
[e6cfe52]594      delta err;
595      int do_blunder;
[a8c4cfa]596      memcpy(&err, &e, sizeof(delta));
[e6cfe52]597      do_blunder = (eTot > eTotTheo);
598      if (fhErrStat && !fArtic) {
599         fputs("\ntraverse ", fhErrStat);
600         fprint_prefix(fhErrStat, stn1->name);
601         fputs("->", fhErrStat);
602         fprint_prefix(fhErrStat, stn2->name);
603         fprintf(fhErrStat, " e=(%.2f, %.2f, %.2f) mag=%.2f %s\n",
604                 e[0], e[1], e[2], sqrt(eTot),
605                 (do_blunder ? "suspect:" : "OK"));
606      }
[045c055]607#endif
[63d4f07]608      while (true) {
[e6cfe52]609         int reached_end;
[693388e]610         prefix *leg_pfx;
[421b7d2]611
[63d4f07]612         fEquate = true;
[e6cfe52]613         /* get next node in traverse
614          * should have stn3->leg[k]->l.to == stn1 */
615         stn3 = stn1->leg[i]->l.to;
616         k = reverse_leg_dirn(stn1->leg[i]);
[4c07c51]617         SVX_ASSERT2(stn3->leg[k]->l.to == stn1,
[e6cfe52]618                 "reverse leg doesn't reciprocate");
[421b7d2]619
[e6cfe52]620         reached_end = (stn3 == stn2 && k == j);
[421b7d2]621
[e6cfe52]622         if (data_here(stn1->leg[i])) {
[693388e]623            leg_pfx = stn1->name->up;
[e6cfe52]624            leg = stn1->leg[i];
[045c055]625#ifdef BLUNDER_DETECTION
[e6cfe52]626            if (do_blunder && fhErrStat)
627               do_gross(err, leg->d, stn1, stn3, eTotTheo);
[045c055]628#endif
[e6cfe52]629            if (!reached_end)
630               adddd(&POSD(stn3), &POSD(stn1), &leg->d);
631         } else {
[693388e]632            leg_pfx = stn3->name->up;
[e6cfe52]633            leg = stn3->leg[k];
[045c055]634#ifdef BLUNDER_DETECTION
[e6cfe52]635            if (do_blunder && fhErrStat)
636               do_gross(err, leg->d, stn1, stn3, eTotTheo);
[045c055]637#endif
[e6cfe52]638            if (!reached_end)
639               subdd(&POSD(stn3), &POSD(stn1), &leg->d);
640         }
[421b7d2]641
[e6cfe52]642         lenTot = sqrdd(leg->d);
[421b7d2]643
[63d4f07]644         if (!fZeros(&leg->v)) fEquate = false;
[e6cfe52]645         if (!reached_end) {
646            add_stn_to_list(&stnlist, stn3);
[be97baf]647            if (!fEquate) {
[e6cfe52]648               mulsd(&e, &leg->v, &sc);
649               adddd(&POSD(stn3), &POSD(stn3), &e);
[95c3272]650            }
[e6cfe52]651            fix(stn3);
652         }
[421b7d2]653
[64d37a3]654         if (!(leg->l.reverse & (FLAG_REPLACEMENTLEG | FLAG_FAKE))) {
655             if (TSTBIT(leg->l.flags, FLAGS_SURFACE)) {
656                stn1->name->sflags |= BIT(SFLAGS_SURFACE);
657                stn3->name->sflags |= BIT(SFLAGS_SURFACE);
658             } else {
659                stn1->name->sflags |= BIT(SFLAGS_UNDERGROUND);
660                stn3->name->sflags |= BIT(SFLAGS_UNDERGROUND);
661             }
662
[a4ae909]663            SVX_ASSERT(!fEquate);
664            SVX_ASSERT(!fZeros(&leg->v));
665            if (leg->meta) {
[1ee204e]666                pimg->days1 = leg->meta->days1;
667                pimg->days2 = leg->meta->days2;
[a4ae909]668            } else {
[1ee204e]669                pimg->days1 = pimg->days2 = -1;
[64d37a3]670            }
[eb5aea0]671            pimg->style = (leg->l.flags >> FLAGS_STYLE_BIT0) & 0x07;
672            img_write_item(pimg, img_LINE, leg->l.flags & FLAGS_MASK,
[a4ae909]673                           sprint_prefix(leg_pfx),
674                           POS(stn3, 0), POS(stn3, 1), POS(stn3, 2));
[64d37a3]675         }
[045c055]676
[e6cfe52]677         /* FIXME: equate at the start of a traverse treated specially
[421b7d2]678          * - what about equates at end? */
[be97baf]679         if (stn1->name != stn3->name && !(fEquate && cLegsTrav == 0)) {
[a4ae909]680            /* (node not part of same stn) &&
[e6cfe52]681             * (not equate at start of traverse) */
[647407d]682#ifndef BLUNDER_DETECTION
[e6cfe52]683            if (fhErrStat && !fArtic) {
[be97baf]684               if (!stn1->name->ident) {
[e6cfe52]685                  /* FIXME: not ideal */
686                  fputs("<fixed point>", fhErrStat);
687               } else {
[be97baf]688                  fprint_prefix(fhErrStat, stn1->name);
[e6cfe52]689               }
690               fputs(fEquate ? szLinkEq : szLink, fhErrStat);
691               if (reached_end) {
[ff6cfe1]692                  if (!stn3->name->ident) {
[5b256a2]693                     /* FIXME: not ideal */
694                     fputs("<fixed point>", fhErrStat);
695                  } else {
[e6cfe52]696                     fprint_prefix(fhErrStat, stn3->name);
[5b256a2]697                  }
[647407d]698               }
[e6cfe52]699            }
[045c055]700#endif
[e6cfe52]701            if (!fEquate) {
702               cLegsTrav++;
703               lenTrav += sqrt(lenTot);
704            }
705         } else {
[045c055]706#if SHOW_INTERNAL_LEGS
[e6cfe52]707            if (fhErrStat && !fArtic) fprintf(fhErrStat, "+");
[045c055]708#endif
[e6cfe52]709            if (lenTot > 0.0) {
[045c055]710#if DEBUG_INVALID
[e6cfe52]711               fprintf(stderr, "lenTot = %8.4f ", lenTot);
[be97baf]712               fprint_prefix(stderr, stn1->name);
[e6cfe52]713               fprintf(stderr, " -> ");
714               fprint_prefix(stderr, stn3->name);
[045c055]715#endif
[e6cfe52]716               BUG("during calculation of closure errors");
[045c055]717            }
[e6cfe52]718         }
719         if (reached_end) break;
[421b7d2]720
[e6cfe52]721         i = k ^ 1; /* flip direction for other leg of 2 node */
[421b7d2]722
[e6cfe52]723         stn1 = stn3;
724      } /* endwhile */
[421b7d2]725
[e6cfe52]726      if (cLegsTrav && !fArtic && fhErrStat)
727         err_stat(cLegsTrav, lenTrav, eTot, eTotTheo,
728                  hTot, hTotTheo, vTot, vTotTheo);
[421b7d2]729
[094d93d]730skip_hanging_traverse:
[045c055]731      ptrOld = ptr;
732      ptr = ptr->next;
733      osfree(ptrOld);
734   }
735
[f1067a2]736   /* Leave fhErrStat open in case we're asked to close loops again... */
[045c055]737}
738
739static void
740err_stat(int cLegsTrav, double lenTrav,
741         double eTot, double eTotTheo,
742         double hTot, double hTotTheo,
743         double vTot, double vTotTheo)
744{
[c61aa79]745   double E = sqrt(eTot / eTotTheo);
746   double H = sqrt(hTot / hTotTheo);
747   double V = sqrt(vTot / vTotTheo);
[647407d]748   if (!fSuppress) {
[c61aa79]749      double sqrt_eTot = sqrt(eTot);
[cb3d1e2]750      fputnl(fhErrStat);
[034141d]751      fprintf(fhErrStat, msg(/*Original length %6.2fm (%3d legs), moved %6.2fm (%5.2fm/leg). */145),
[cb3d1e2]752              lenTrav, cLegsTrav, sqrt_eTot, sqrt_eTot / cLegsTrav);
[736f7df]753      if (lenTrav > 0.0) {
[034141d]754         fprintf(fhErrStat, msg(/*Error %6.2f%%*/146), 100 * sqrt_eTot / lenTrav);
[736f7df]755      } else {
756         /* TRANSLATORS: Here N/A means "Not Applicable" -- it means the
757          * traverse has zero length, so error per metre is meaningless.
758          *
759          * There should be 4 spaces between "Error" and "N/A" so that it lines
760          * up with the numbers in the message above. */
[421b7d2]761         fputs(msg(/*Error    N/A*/147), fhErrStat);
[736f7df]762      }
[cb3d1e2]763      fputnl(fhErrStat);
[c61aa79]764      fprintf(fhErrStat, "%f\n", E);
765      fprintf(fhErrStat, "H: %f V: %f\n", H, V);
[cb3d1e2]766      fputnl(fhErrStat);
767   }
[c61aa79]768   img_write_errors(pimg, cLegsTrav, lenTrav, E, H, V);
[045c055]769}
770
771static void
772replace_trailing_travs(void)
773{
774   stackTrail *ptrOld;
775   node *stn1, *stn2;
776   linkfor *leg;
777   int i;
778
[736f7df]779   /* TRANSLATORS: In French, Eric chose to use the terminology used by
780    * toporobot: "sequence" for the English "traverse", which makes sense
781    * (although toporobot actually uses this term to mean something more
782    * specific).  Feel free to follow this lead if you can't think of a better
783    * term - these messages mostly indicate how processing is progressing.
[b49ac56]784    *
[736f7df]785    * A trailing traverse is a dead end back to a junction. */
[045c055]786   out_current_action(msg(/*Calculating trailing traverses*/128));
787
788   while (ptrTrail != NULL) {
789      leg = ptrTrail->join1;
790      leg = reverse_leg(leg);
791      stn1 = leg->l.to;
[9a92e86]792      if (!fixed(stn1)) {
793          // This happens in a component which wasn't attached to fixed points.
794          goto skip;
795      }
[045c055]796      i = reverse_leg_dirn(leg);
797#if PRINT_NETBITS
798      printf(" Trailing trav ");
799      print_prefix(stn1->name);
800      printf("<%p>", stn1);
801      printf("%s...\n", szLink);
802      printf("    attachment stn is at (%f, %f, %f)\n",
803             POS(stn1, 0), POS(stn1, 1), POS(stn1, 2));
804#endif
[09bfd4c]805      /* We may have swapped the links round when we removed the leg.  If
806       * we did then stn1->leg[i] will be in use.  The link we swapped
807       * with is the first free leg */
[045c055]808      if (stn1->leg[i]) {
809         /* j is the direction to swap with */
810         int j = (stn1->leg[1]) ? 2 : 1;
811         /* change the other direction of leg i to use leg j */
812         reverse_leg(stn1->leg[i])->l.reverse += j - i;
813         stn1->leg[j] = stn1->leg[i];
814      }
815      stn1->leg[i] = ptrTrail->join1;
[4c07c51]816      SVX_ASSERT(fixed(stn1));
[a4ae909]817      img_write_item(pimg, img_MOVE, 0, NULL,
818                     POS(stn1, 0), POS(stn1, 1), POS(stn1, 2));
[045c055]819
[e6cfe52]820      while (1) {
[693388e]821         prefix *leg_pfx;
[e6cfe52]822         int j;
[693388e]823
[e6cfe52]824         leg = stn1->leg[i];
825         stn2 = leg->l.to;
826         j = reverse_leg_dirn(leg);
827         if (data_here(leg)) {
[693388e]828            leg_pfx = stn1->name->up;
[e6cfe52]829            adddd(&POSD(stn2), &POSD(stn1), &leg->d);
[045c055]830#if 0
[e6cfe52]831            printf("Adding leg (%f, %f, %f)\n", leg->d[0], leg->d[1], leg->d[2]);
[045c055]832#endif
[e6cfe52]833         } else {
[693388e]834            leg_pfx = stn2->name->up;
[e6cfe52]835            leg = stn2->leg[j];
836            subdd(&POSD(stn2), &POSD(stn1), &leg->d);
[045c055]837#if 0
[e6cfe52]838            printf("Subtracting reverse leg (%f, %f, %f)\n", leg->d[0], leg->d[1], leg->d[2]);
[045c055]839#endif
[e6cfe52]840         }
[045c055]841
[e6cfe52]842         fix(stn2);
843         add_stn_to_list(&stnlist, stn2);
[64d37a3]844         if (!(leg->l.reverse & (FLAG_REPLACEMENTLEG | FLAG_FAKE))) {
845             if (TSTBIT(leg->l.flags, FLAGS_SURFACE)) {
846                stn1->name->sflags |= BIT(SFLAGS_SURFACE);
847                stn2->name->sflags |= BIT(SFLAGS_SURFACE);
848             } else {
849                stn1->name->sflags |= BIT(SFLAGS_UNDERGROUND);
850                stn2->name->sflags |= BIT(SFLAGS_UNDERGROUND);
851             }
[e6cfe52]852         }
[a4ae909]853         if (!(leg->l.reverse & (FLAG_REPLACEMENTLEG | FLAG_FAKE))) {
854            SVX_ASSERT(!fZeros(&leg->v));
855            if (leg->meta) {
[1ee204e]856                pimg->days1 = leg->meta->days1;
857                pimg->days2 = leg->meta->days2;
[a4ae909]858            } else {
[1ee204e]859                pimg->days1 = pimg->days2 = -1;
[693388e]860            }
[eb5aea0]861            pimg->style = (leg->l.flags >> FLAGS_STYLE_BIT0) & 0x07;
862            img_write_item(pimg, img_LINE, leg->l.flags & FLAGS_MASK,
[a4ae909]863                           sprint_prefix(leg_pfx),
864                           POS(stn2, 0), POS(stn2, 1), POS(stn2, 2));
[e6cfe52]865         }
[045c055]866
[e6cfe52]867         /* stop if not 2 node */
868         if (!two_node(stn2)) break;
[045c055]869
[e6cfe52]870         stn1 = stn2;
871         i = j ^ 1; /* flip direction for other leg of 2 node */
[045c055]872      }
873
[9a92e86]874skip:
[045c055]875      ptrOld = ptrTrail;
876      ptrTrail = ptrTrail->next;
877      osfree(ptrOld);
878   }
879
[647407d]880   /* write out connections with no survey data */
[a4ae909]881   while (nosurveyhead) {
882      nosurveylink *p = nosurveyhead;
883      SVX_ASSERT(fixed(p->fr));
884      SVX_ASSERT(fixed(p->to));
885      if (TSTBIT(p->flags, FLAGS_SURFACE)) {
886         p->fr->name->sflags |= BIT(SFLAGS_SURFACE);
887         p->to->name->sflags |= BIT(SFLAGS_SURFACE);
888      } else {
889         p->fr->name->sflags |= BIT(SFLAGS_UNDERGROUND);
890         p->to->name->sflags |= BIT(SFLAGS_UNDERGROUND);
[647407d]891      }
[a4ae909]892      img_write_item(pimg, img_MOVE, 0, NULL,
893                     POS(p->fr, 0), POS(p->fr, 1), POS(p->fr, 2));
[ee05463]894      if (p->meta) {
[1ee204e]895          pimg->days1 = p->meta->days1;
896          pimg->days2 = p->meta->days2;
[a4ae909]897      } else {
[1ee204e]898          pimg->days1 = pimg->days2 = -1;
[a4ae909]899      }
[eb5aea0]900      pimg->style = img_STYLE_NOSURVEY;
901      img_write_item(pimg, img_LINE, (p->flags & FLAGS_MASK),
[a4ae909]902                     sprint_prefix(p->fr->name->up),
903                     POS(p->to, 0), POS(p->to, 1), POS(p->to, 2));
904      nosurveyhead = p->next;
905      osfree(p);
[647407d]906   }
907
[045c055]908   /* write stations to .3d file and free legs and stations */
909   FOR_EACH_STN(stn1, stnlist) {
[e6cfe52]910      int d;
[4c07c51]911      SVX_ASSERT(fixed(stn1));
[a2c33ae]912      if (stn1->name->stn == stn1) {
[a4ae909]913         int sf = stn1->name->sflags;
[a2c33ae]914         /* take care of unused fixed points */
[a4ae909]915         if (!TSTBIT(sf, SFLAGS_SOLVED)) {
[a2c33ae]916            const char * label = NULL;
917            if (TSTBIT(sf, SFLAGS_ANON)) {
918               label = "";
919            } else if (stn1->name->ident) {
920               label = sprint_prefix(stn1->name);
921            }
922            if (label) {
923               /* Set flag to stop station being rewritten after *solve. */
924               stn1->name->sflags = sf | BIT(SFLAGS_SOLVED);
925               sf &= SFLAGS_MASK;
926               if (stn1->name->max_export) sf |= BIT(SFLAGS_EXPORTED);
927               img_write_item(pimg, img_LABEL, sf, label,
928                              POS(stn1, 0), POS(stn1, 1), POS(stn1, 2));
929            }
[95c3272]930         }
[e6cfe52]931      }
932      /* update coords of bounding box, ignoring the base positions
[c9eb197]933       * of points fixed with error estimates and only counting stations
[a2c33ae]934       * in underground surveys.
935       *
936       * NB We don't set SFLAGS_UNDERGROUND for the anchor station for
937       * a point fixed with error estimates, so this test will exclude
938       * those too, which is what we want.
939       */
940      if (TSTBIT(stn1->name->sflags, SFLAGS_UNDERGROUND)) {
[e6cfe52]941         for (d = 0; d < 3; d++) {
942            if (POS(stn1, d) < min[d]) {
943               min[d] = POS(stn1, d);
944               pfxLo[d] = stn1->name;
[045c055]945            }
[e6cfe52]946            if (POS(stn1, d) > max[d]) {
947               max[d] = POS(stn1, d);
948               pfxHi[d] = stn1->name;
[045c055]949            }
950         }
[dfac588]951
[378112a]952         /* Range without anonymous stations at offset 3. */
[dfac588]953         if (!TSTBIT(stn1->name->sflags, SFLAGS_ANON)) {
954            for (d = 0; d < 3; d++) {
955               if (POS(stn1, d) < min[d + 3]) {
956                  min[d + 3] = POS(stn1, d);
957                  pfxLo[d + 3] = stn1->name;
958               }
959               if (POS(stn1, d) > max[d + 3]) {
960                  max[d + 3] = POS(stn1, d);
961                  pfxHi[d + 3] = stn1->name;
962               }
963            }
964         }
[e6cfe52]965      }
[421b7d2]966
[e6cfe52]967      d = stn1->name->shape;
[f15cde77]968      if (d <= 1 && !TSTBIT(stn1->name->sflags, SFLAGS_USED)) {
[63d4f07]969         bool unused_fixed_point = false;
[f15cde77]970         if (d == 0) {
971            /* Unused fixed point without error estimates */
[63d4f07]972            unused_fixed_point = true;
[f15cde77]973         } else if (stn1->leg[0]) {
974            prefix *pfx = stn1->leg[0]->l.to->name;
[a2c33ae]975            if (!pfx->ident && !TSTBIT(pfx->sflags, SFLAGS_ANON)) {
[f15cde77]976               /* Unused fixed point with error estimates */
[63d4f07]977               unused_fixed_point = true;
[f15cde77]978            }
979         }
980         if (unused_fixed_point) {
[736f7df]981            /* TRANSLATORS: fixed survey station that is not part of any survey
982             */
[1edaf8d]983            warning_in_file(stn1->name->filename, stn1->name->line,
[0804fbe]984                    /*Unused fixed point “%s”*/73, sprint_prefix(stn1->name));
[045c055]985         }
986      }
[eb04711]987
988      /* For stations fixed with error estimates, we need to ignore the leg to
989       * the "real" fixed point in the node stats.
990       */
[a2c33ae]991      if (stn1->leg[0] && !stn1->leg[0]->l.to->name->ident &&
992          !TSTBIT(stn1->leg[0]->l.to->name->sflags, SFLAGS_ANON))
[eb04711]993         stn1->name->shape--;
994
[045c055]995      for (i = 0; i <= 2; i++) {
996         leg = stn1->leg[i];
997         /* only want to think about forwards legs */
998         if (leg && data_here(leg)) {
[eb18f4d]999            linkfor *legRev;
[045c055]1000            node *stnB;
1001            int iB;
1002            stnB = leg->l.to;
1003            iB = reverse_leg_dirn(leg);
1004            legRev = stnB->leg[iB];
[4c07c51]1005            SVX_ASSERT2(legRev->l.to == stn1, "leg doesn't reciprocate");
1006            SVX_ASSERT(fixed(stn1));
[e6cfe52]1007            if (!(leg->l.flags &
[95c3272]1008                  (BIT(FLAGS_DUPLICATE)|BIT(FLAGS_SPLAY)|
1009                   BIT(FLAGS_SURFACE)))) {
[693388e]1010               /* check not an equating leg, or one inside an sdfix point */
1011               if (!(leg->l.reverse & (FLAG_REPLACEMENTLEG | FLAG_FAKE))) {
[045c055]1012                  totadj += sqrt(sqrd(POS(stnB, 0) - POS(stn1, 0)) +
1013                                 sqrd(POS(stnB, 1) - POS(stn1, 1)) +
1014                                 sqrd(POS(stnB, 2) - POS(stn1, 2)));
1015                  total += sqrt(sqrdd(leg->d));
[27b8b59]1016                  totplan += hypot(leg->d[0], leg->d[1]);
[045c055]1017                  totvert += fabs(leg->d[2]);
1018               }
1019            }
1020            osfree(leg);
1021            osfree(legRev);
1022            stn1->leg[i] = stnB->leg[iB] = NULL;
1023         }
1024      }
1025   }
1026
1027   /* The station position is attached to the name, so we leave the names and
1028    * positions in place - they can then be picked up if we have a *solve
1029    * followed by more data */
1030   for (stn1 = stnlist; stn1; stn1 = stn2) {
1031      stn2 = stn1->next;
1032      stn1->name->stn = NULL;
1033      osfree(stn1);
1034   }
1035   stnlist = NULL;
1036}
[ee05463]1037
1038static void
1039write_passage_models(void)
1040{
1041   lrudlist * psg = model;
1042   while (psg) {
1043      lrudlist * oldp;
1044      lrud * xsect = psg->tube;
1045      int xflags = 0;
1046      while (xsect) {
1047         lrud *oldx;
[d333899]1048         prefix *pfx;
[ee05463]1049         const char *name;
1050         pimg->l = xsect->l;
1051         pimg->r = xsect->r;
1052         pimg->u = xsect->u;
1053         pimg->d = xsect->d;
[b08ad81]1054         if (xsect->meta) {
[1ee204e]1055             pimg->days1 = xsect->meta->days1;
1056             pimg->days2 = xsect->meta->days2;
[b08ad81]1057         } else {
[1ee204e]1058             pimg->days1 = pimg->days2 = -1;
[b08ad81]1059         }
[d333899]1060
1061         pfx = xsect->stn;
1062         name = sprint_prefix(pfx);
[ee05463]1063         oldx = xsect;
1064         xsect = xsect->next;
1065         osfree(oldx);
[d333899]1066
1067         if (!pfx->pos) {
[736f7df]1068             /* TRANSLATORS: e.g. the user specifies a passage cross-section at
1069              * station "entrance.27", but there is no station "entrance.27" in
1070              * the centre-line. */
[d333899]1071             error_in_file(pfx->filename, pfx->line,
[0804fbe]1072                           /*Cross section specified at non-existent station “%s”*/83,
[d333899]1073                           name);
1074         } else {
1075             if (xsect == NULL) xflags = img_XFLAG_END;
1076             img_write_item(pimg, img_XSECT, xflags, name, 0, 0, 0);
1077         }
[ee05463]1078      }
1079      oldp = psg;
1080      psg = psg->next;
1081      osfree(oldp);
1082   }
1083   model = NULL;
1084}
Note: See TracBrowser for help on using the repository browser.