Changeset 6a6cb97 in git


Ignore:
Timestamp:
17/06/10 16:40:42 (9 years ago)
Author:
Olly Betts <olly@…>
Branches:
svn/1.0, svn/tags/1.0.40
Children:
866a9a5
Parents:
722886f
Message:

src/img.c,src/img.h: Update to the version from 1.1.13 so that we
can read version 6 .3d files written by newer 1.1.x releases.
src/dump3d.c,src/extend.c,src/netskel.c: Set img_output_version to 3
before writing out a .3d file for compatibility with older 1.0.x
releases. We don't use any of the newer features, so there's no
benefit to using a newer format version.

git-svn-id: file:///home/survex-svn/survex/branches/1.0@3444 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r722886f r6a6cb97  
     1Thu Jun 17 15:36:50 GMT 2010  Olly Betts <olly@survex.com>
     2
     3        * src/img.c,src/img.h: Update to the version from 1.1.13 so that we
     4          can read version 6 .3d files written by newer 1.1.x releases.
     5        * src/dump3d.c,src/extend.c,src/netskel.c: Set img_output_version to 3
     6          before writing out a .3d file for compatibility with older 1.0.x
     7          releases.  We don't use any of the newer features, so there's no
     8          benefit to using a newer format version.
     9
    110Wed Jun 16 15:04:03 GMT 2010  Olly Betts <olly@survex.com>
    211
  • src/dump3d.c

    r722886f r6a6cb97  
    11/* dump3d.c */
    22/* Show raw contents of .3d file in text form */
    3 /* Copyright (C) 2001,2002 Olly Betts
     3/* Copyright (C) 2001,2002,2010 Olly Betts
    44 *
    55 * This program is free software; you can redistribute it and/or modify
     
    1515 * You should have received a copy of the GNU General Public License
    1616 * along with this program; if not, write to the Free Software
    17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1818 */
    1919
     
    7272
    7373#if 0
     74   img_output_version = 3;
    7475   pimg = img_open_write("dump3d.3d", "dump3d", fTrue);
    7576   if (!pimg) fatalerror(img_error(), "dump3d.3d");
  • src/extend.c

    r722886f r6a6cb97  
    11/* extend.c
    22 * Produce an extended elevation
    3  * Copyright (C) 1995-2002,2005 Olly Betts
     3 * Copyright (C) 1995-2002,2005,2010 Olly Betts
    44 * Copyright (C) 2004,2005 John Pybus
    55 *
     
    1616 * You should have received a copy of the GNU General Public License
    1717 * along with this program; if not, write to the Free Software
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1919 */
    2020
     
    593593   printf(msg(/*Writing %s...*/522), fnm_out);
    594594   putnl();
     595   img_output_version = 3;
    595596   pimg_out = img_open_write(fnm_out, desc, fTrue);
    596597
  • src/img.c

    r722886f r6a6cb97  
    11/* img.c
    22 * Routines for reading and writing Survex ".3d" image files
    3  * Copyright (C) 1993-2004,2005 Olly Betts
     3 * Copyright (C) 1993-2004,2005,2006,2010 Olly Betts
    44 *
    55 * This program is free software; you can redistribute it and/or modify
     
    1515 * You should have received a copy of the GNU General Public License
    1616 * along with this program; if not, write to the Free Software
    17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
    1818 */
    1919
     
    3030
    3131#include "img.h"
     32
     33#define LATEST_IMG_VERSION 6
    3234
    3335#ifdef IMG_HOSTED
     
    4042# define TIMEFMT msg(/*%a,%Y.%m.%d %H:%M:%S %Z*/107)
    4143#else
    42 # define INT32_T long
     44# define INT32_T int
    4345# define TIMENA "Time not available."
    4446# define TIMEFMT "%a,%Y.%m.%d %H:%M:%S %Z"
     
    6668# define SVX_ASSERT(X)
    6769
    68 static long
     70static INT32_T
    6971get32(FILE *fh)
    7072{
    71    long w = getc(fh);
    72    w |= (long)getc(fh) << 8l;
    73    w |= (long)getc(fh) << 16l;
    74    w |= (long)getc(fh) << 24l;
     73   INT32_T w = getc(fh);
     74   w |= (INT32_T)getc(fh) << 8l;
     75   w |= (INT32_T)getc(fh) << 16l;
     76   w |= (INT32_T)getc(fh) << 24l;
    7577   return w;
    7678}
     
    152154#endif
    153155
    154 unsigned int img_output_version = 3;
     156unsigned int img_output_version = LATEST_IMG_VERSION;
    155157
    156158#ifdef IMG_HOSTED
     
    179181#define LITLEN(S) (sizeof(S"") - 1)
    180182
     183/* Fake "version numbers" for non-3d formats we can read. */
     184#define VERSION_CMAP_SHOT       -4
     185#define VERSION_CMAP_STATION    -3
     186#define VERSION_COMPASS_PLT     -2
     187#define VERSION_SURVEX_POS      -1
     188
    181189static char *
    182190my_strdup(const char *str)
     
    295303
    296304   /* for version >= 3 we use label_buf to store the prefix for reuse */
    297    /* for version -2, 0 value indicates we haven't entered a survey yet */
    298    /* for version -4, we store the last station here to detect whether
    299     * we MOVE or LINE */
     305   /* for VERSION_COMPASS_PLT, 0 value indicates we haven't
     306    * entered a survey yet */
     307   /* for VERSION_CMAP_SHOT, we store the last station here
     308    * to detect whether we MOVE or LINE */
    300309   pimg->label_len = 0;
    301310   pimg->label_buf[0] = '\0';
     
    306315   pimg->date1 = 0;
    307316   pimg->date2 = 0;
     317   pimg->is_extended_elevation = 0;
    308318
    309319   pimg->l = pimg->r = pimg->u = pimg->d = -1.0;
     
    338348   }
    339349
    340    /* [version -2, -3, -4] pending IMG_LINE or IMG_MOVE - both have 4 added
    341     * [version -1] already skipped heading line, or there wasn't one
     350   /* [VERSION_COMPASS_PLT, VERSION_CMAP_STATION, VERSION_CMAP_SHOT] pending
     351    * IMG_LINE or IMG_MOVE - both have 4 added.
     352    * [VERSION_SURVEX_POS] already skipped heading line, or there wasn't one
    342353    * [version 0] not in the middle of a 'LINE' command
    343354    * [version >= 3] not in the middle of turning a LINE into a MOVE
     
    348359   if (has_ext(fnm, len, EXT_SVX_POS)) {
    349360pos_file:
    350       pimg->version = -1;
     361      pimg->version = VERSION_SURVEX_POS;
    351362      if (!pimg->survey) pimg->title = baseleaf_from_fnm(fnm);
    352363      pimg->datestamp = my_strdup(TIMENA);
     
    362373      long fpos;
    363374plt_file:
    364       pimg->version = -2;
     375      pimg->version = VERSION_COMPASS_PLT;
    365376      /* Spaces aren't legal in Compass station names, but dots are, so
    366377       * use space as the level separator */
     
    480491      }
    481492      if (line[1] == 'S') {
    482          pimg->version = -3; /* Station format */
     493         pimg->version = VERSION_CMAP_STATION;
    483494      } else {
    484          pimg->version = -4; /* Shot format */
     495         pimg->version = VERSION_CMAP_SHOT;
    485496      }
    486497      osfree(line);
     
    546557      /* nothing special to do */
    547558   } else if (pimg->version == 0) {
    548       if (ch < '2' || ch > '5' || getc(pimg->fh) != '\n') {
     559      if (ch < '2' || ch > '0' + LATEST_IMG_VERSION || getc(pimg->fh) != '\n') {
    549560         img_errno = IMG_TOONEW;
    550561         goto error;
     
    567578      osfree(pimg->title);
    568579      osfree(pimg->datestamp);
     580      osfree(pimg->filename_opened);
    569581      fclose(pimg->fh);
    570582      osfree(pimg);
     
    574586   pimg->start = ftell(pimg->fh);
    575587
     588   len = strlen(pimg->title);
     589   if (len > 11 && strcmp(pimg->title + len - 11, " (extended)") == 0) {
     590       pimg->title[len - 11] = '\0';
     591       pimg->is_extended_elevation = 1;
     592   }
     593
    576594   return pimg;
    577595}
     
    589607   }
    590608   clearerr(pimg->fh);
    591    /* [version -1] already skipped heading line, or there wasn't one
     609   /* [VERSION_SURVEX_POS] already skipped heading line, or there wasn't one
    592610    * [version 0] not in the middle of a 'LINE' command
    593611    * [version >= 3] not in the middle of turning a LINE into a MOVE */
     
    597615
    598616   /* for version >= 3 we use label_buf to store the prefix for reuse */
    599    /* for version -2, 0 value indicates we haven't entered a survey yet */
    600    /* for version -4, we store the last station here to detect whether
     617   /* for VERSION_COMPASS_PLT, 0 value indicates we haven't entered a survey
     618    * yet */
     619   /* for VERSION_CMAP_SHOT, we store the last station here to detect whether
    601620    * we MOVE or LINE */
    602621   pimg->label_len = 0;
     
    639658   }
    640659
     660   pimg->filename_opened = NULL;
     661
    641662   /* Output image file header */
    642663   fputs("Survex 3D Image File\n", pimg->fh); /* file identifier string */
     
    645666      fputs("Bv0.01\n", pimg->fh); /* binary file format version number */
    646667   } else {
    647       pimg->version = (img_output_version > 5) ? 5 : img_output_version;
     668      pimg->version = (img_output_version > LATEST_IMG_VERSION) ? LATEST_IMG_VERSION : img_output_version;
    648669      fprintf(pimg->fh, "v%d\n", pimg->version); /* file format version no. */
    649670   }
     
    658679      fputsnl(date, pimg->fh);
    659680   }
     681#if 0
     682   if (img_output_version >= 5) {
     683       static const unsigned char codelengths[32] = {
     684           4,  8,  8,  16, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
     685           0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0
     686       };
     687       fwrite(codelengths, 32, 1, pimg->fh);
     688   }
     689#endif
    660690   pimg->fRead = fFalse; /* writing to this file */
    661691   img_errno = IMG_NONE;
     
    672702
    673703   pimg->l = pimg->r = pimg->u = pimg->d = -1.0;
     704
     705   pimg->n_legs = 0;
     706   pimg->length = 0.0;
     707   pimg->E = pimg->H = pimg->V = 0.0;
    674708
    675709   /* Don't check for write errors now - let img_close() report them... */
     
    796830      int opt;
    797831      pimg->l = pimg->r = pimg->u = pimg->d = -1.0;
     832      if (pimg->pending == 256) {
     833         pimg->pending = 0;
     834         return img_XSECT_END;
     835      }
    798836      if (pimg->pending >= 0x80) {
    799837         *p = pimg->mv;
     
    851889                     pimg->date2 = get32(pimg->fh);
    852890                     break;
     891                 case 0x22: /* Error info */
     892                     pimg->n_legs = get32(pimg->fh);
     893                     pimg->length = get32(pimg->fh) / 100.0;
     894                     pimg->E = get32(pimg->fh) / 100.0;
     895                     pimg->H = get32(pimg->fh) / 100.0;
     896                     pimg->V = get32(pimg->fh) / 100.0;
     897                     return img_ERROR_INFO;
    853898                 case 0x30: case 0x31: /* LRUD */
    854                      if (read_v3label(pimg) == img_BAD) return img_BAD;
    855                      pimg->flags = (int)opt & 0x01;
    856                      pimg->l = get16(pimg->fh) / 100.0;
    857                      pimg->r = get16(pimg->fh) / 100.0;
    858                      pimg->u = get16(pimg->fh) / 100.0;
    859                      pimg->d = get16(pimg->fh) / 100.0;
    860                      return img_XSECT;
    861899                 case 0x32: case 0x33: /* Big LRUD! */
    862900                     if (read_v3label(pimg) == img_BAD) return img_BAD;
    863901                     pimg->flags = (int)opt & 0x01;
    864                      pimg->l = get32(pimg->fh) / 100.0;
    865                      pimg->r = get32(pimg->fh) / 100.0;
    866                      pimg->u = get32(pimg->fh) / 100.0;
    867                      pimg->d = get32(pimg->fh) / 100.0;
     902                     if (opt < 0x32) {
     903                         pimg->l = get16(pimg->fh) / 100.0;
     904                         pimg->r = get16(pimg->fh) / 100.0;
     905                         pimg->u = get16(pimg->fh) / 100.0;
     906                         pimg->d = get16(pimg->fh) / 100.0;
     907                     } else {
     908                         pimg->l = get32(pimg->fh) / 100.0;
     909                         pimg->r = get32(pimg->fh) / 100.0;
     910                         pimg->u = get32(pimg->fh) / 100.0;
     911                         pimg->d = get32(pimg->fh) / 100.0;
     912                     }
     913                     if (pimg->survey_len) {
     914                         size_t l = pimg->survey_len;
     915                         const char *s = pimg->label_buf;
     916                         if (strncmp(pimg->survey, s, l + 1) != 0) {
     917                             return img_XSECT_END;
     918                         }
     919                         pimg->label += l;
     920                         /* skip the dot if there */
     921                         if (*pimg->label) pimg->label++;
     922                     }
     923                     /* If this is the last cross-section in this passage, set
     924                      * pending so we return img_XSECT_END next time. */
     925                     if (pimg->flags & 0x01) {
     926                         pimg->pending = 256;
     927                         pimg->flags &= ~0x01;
     928                     }
    868929                     return img_XSECT;
    869                  default: /* 0x24 - 0x2f and 0x34 - 0x3f are currently unallocated. */
     930                 default: /* 0x23 - 0x2f and 0x34 - 0x3f are currently unallocated. */
    870931                     img_errno = IMG_BADFORMAT;
    871932                     return img_BAD;
     
    11731234            if (pimg->label[0] == '\\') pimg->label++;
    11741235
     1236            pimg->flags = img_SFLAG_UNDERGROUND; /* default flags */
     1237
    11751238            result = img_LABEL;
    11761239         } else {
     
    11921255
    11931256      return result;
    1194    } else if (pimg->version == -1) {
    1195       /* version -1: .pos file */
     1257   } else if (pimg->version == VERSION_SURVEX_POS) {
     1258      /* Survex .pos file */
    11961259      size_t off;
    11971260      pimg->flags = img_SFLAG_UNDERGROUND; /* default flags */
     
    12451308
    12461309      return img_LABEL;
    1247    } else if (pimg->version == -2) {
    1248       /* version -2: Compass .plt file */
     1310   } else if (pimg->version == VERSION_COMPASS_PLT) {
     1311      /* Compass .plt file */
    12491312      if (pimg->pending > 0) {
    12501313         /* -1 signals we've entered the first survey we want to
     
    13281391                  return img_BAD;
    13291392               }
    1330                /* Compass store coordinates as North, East, Up = (y,x,z)! */
     1393               /* Compass stores coordinates as North, East, Up = (y,x,z)! */
    13311394               if (sscanf(line, "%lf%lf%lf", &p->y, &p->x, &p->z) != 3) {
    13321395                  osfree(line);
     
    14031466      }
    14041467   } else {
    1405       /* version -3 or -4: CMAP .xyz file */
     1468      /* CMAP .xyz file */
    14061469      char *line = NULL;
    14071470      char *q;
     
    14471510
    14481511      len = strlen(line);
    1449       if (pimg->version == -3) {
     1512      if (pimg->version == VERSION_CMAP_STATION) {
    14501513         /* station variant */
    14511514         if (len < 37) {
     
    15691632}
    15701633
     1634static void
     1635img_write_item_date(img *pimg)
     1636{
     1637    if (pimg->date1 != pimg->olddate1 ||
     1638            pimg->date2 != pimg->olddate2) {
     1639        /* Only write dates when they've changed. */
     1640        if (pimg->date1 == pimg->date2) {
     1641            putc(0x20, pimg->fh);
     1642            put32(pimg->date1, pimg->fh);
     1643        } else {
     1644            putc(0x21, pimg->fh);
     1645            put32(pimg->date1, pimg->fh);
     1646            put32(pimg->date2, pimg->fh);
     1647        }
     1648        pimg->olddate1 = pimg->date1;
     1649        pimg->olddate2 = pimg->date2;
     1650    }
     1651}
     1652
    15711653void
    15721654img_write_item(img *pimg, int code, int flags, const char *s,
     
    15821664         break;
    15831665       case img_XSECT: {
    1584          INT32_T l = (INT32_T)my_round(pimg->l * 100.0);
    1585          INT32_T r = (INT32_T)my_round(pimg->r * 100.0);
    1586          INT32_T u = (INT32_T)my_round(pimg->u * 100.0);
    1587          INT32_T d = (INT32_T)my_round(pimg->d * 100.0);
    1588          INT32_T max_dim = max(max(l, r), max(u, d));
     1666         INT32_T l, r, u, d, max_dim;
     1667         /* Need at least version 5 for img_XSECT. */
     1668         if (pimg->version < 5) break;
     1669         img_write_item_date(pimg);
     1670         l = (INT32_T)my_round(pimg->l * 100.0);
     1671         r = (INT32_T)my_round(pimg->r * 100.0);
     1672         u = (INT32_T)my_round(pimg->u * 100.0);
     1673         d = (INT32_T)my_round(pimg->d * 100.0);
    15891674         if (l < 0) l = -1;
    15901675         if (r < 0) r = -1;
    15911676         if (u < 0) u = -1;
    15921677         if (d < 0) d = -1;
     1678         max_dim = max(max(l, r), max(u, d));
    15931679         flags &= 1;
    15941680         if (max_dim >= 32768) flags |= 2;
     
    16131699       case img_LINE:
    16141700         if (pimg->version >= 4) {
    1615              if (pimg->date1 != pimg->olddate1 ||
    1616                  pimg->date2 != pimg->olddate2) {
    1617                  /* Only write dates when they've changed. */
    1618                  if (pimg->date1 == pimg->date2) {
    1619                      putc(0x20, pimg->fh);
    1620                      put32(pimg->date1, pimg->fh);
    1621                  } else {
    1622                      putc(0x21, pimg->fh);
    1623                      put32(pimg->date1, pimg->fh);
    1624                      put32(pimg->date2, pimg->fh);
    1625                  }
    1626                  pimg->olddate1 = pimg->date1;
    1627                  pimg->olddate2 = pimg->date2;
    1628              }
     1701             img_write_item_date(pimg);
    16291702         }
    16301703         write_v3label(pimg, 0x80 | flags, s ? s : "");
     
    16901763      put32((INT32_T)my_round(z * 100.0), pimg->fh);
    16911764   }
     1765}
     1766
     1767/* Write error information for the current traverse
     1768 * n_legs is the number of legs in the traverse
     1769 * length is the traverse length (in m)
     1770 * E is the ratio of the observed misclosure to the theoretical one
     1771 * H is the ratio of the observed horizontal misclosure to the theoretical one
     1772 * V is the ratio of the observed vertical misclosure to the theoretical one
     1773 */
     1774void
     1775img_write_errors(img *pimg, int n_legs, double length,
     1776                 double E, double H, double V)
     1777{
     1778    putc(0x22, pimg->fh);
     1779    put32(n_legs, pimg->fh);
     1780    put32((INT32_T)my_round(length * 100.0), pimg->fh);
     1781    put32((INT32_T)my_round(E * 100.0), pimg->fh);
     1782    put32((INT32_T)my_round(H * 100.0), pimg->fh);
     1783    put32((INT32_T)my_round(V * 100.0), pimg->fh);
    16921784}
    16931785
     
    17221814      }
    17231815      osfree(pimg->label_buf);
     1816      osfree(pimg->filename_opened);
    17241817      osfree(pimg);
    17251818   }
  • src/img.h

    r722886f r6a6cb97  
    11/* img.h
    22 * Header file for routines to read and write Survex ".3d" image files
    3  * Copyright (C) Olly Betts 1993,1994,1997,2001,2002,2003,2004,2005
     3 * Copyright (C) Olly Betts 1993,1994,1997,2001,2002,2003,2004,2005,2006,2010
    44 *
    55 * This program is free software; you can redistribute it and/or modify
     
    1515 * You should have received a copy of the GNU General Public License
    1616 * along with this program; if not, write to the Free Software
    17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
     17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
    1818 */
    1919
     
    4141# define img_LABEL  3
    4242# define img_XSECT  4
     43# define img_XSECT_END 5
     44# define img_ERROR_INFO 6
    4345
    4446# define img_FLAG_SURFACE   0x01
     
    5254# define img_SFLAG_FIXED       0x10
    5355
     56/* No longer used: */
    5457# define img_XFLAG_END      0x01
    5558
     
    6871   time_t date1, date2;
    6972   double l, r, u, d;
    70    char * filename_opened; /* The filename actually opened (e.g. may have ".3d" added). */
     73   /* Error information - valid when IMG_ERROR is returned: */
     74   int n_legs;
     75   double length;
     76   double E, H, V;
     77   /* The filename actually opened (e.g. may have ".3d" added). */
     78   char * filename_opened;
     79   int is_extended_elevation;
    7180   /* all other members are for internal use only */
    7281   FILE *fh;          /* file handle of image file */
     
    91100    *   4 => survey date
    92101    *   5 => LRUD info
     102    *   6 => error info
    93103    */
    94104   int version;
     
    150160                    double x, double y, double z);
    151161
     162/* Write error information for the current traverse
     163 * n_legs is the number of legs in the traverse
     164 * length is the traverse length (in m)
     165 * E is the ratio of the observed misclosure to the theoretical one
     166 * H is the ratio of the observed horizontal misclosure to the theoretical one
     167 * V is the ratio of the observed vertical misclosure to the theoretical one
     168 */
     169void img_write_errors(img *pimg, int n_legs, double length,
     170                      double E, double H, double V);
     171
    152172/* rewind a .3d file opened for reading so the data can be read in
    153173 * several passes
  • src/netskel.c

    r722886f r6a6cb97  
    22 * Survex network reduction - remove trailing traverses and concatenate
    33 * traverses between junctions
    4  * Copyright (C) 1991-2002,2005 Olly Betts
     4 * Copyright (C) 1991-2002,2005,2010 Olly Betts
    55 *
    66 * This program is free software; you can redistribute it and/or modify
     
    1616 * You should have received a copy of the GNU General Public License
    1717 * along with this program; if not, write to the Free Software
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1919 */
    2020
     
    427427      } else {
    428428#endif
     429         img_output_version = 3;
    429430         pimg = img_open_write(fnm, survey_title, fTrue);
    430431         if (!pimg) fatalerror(img_error(), fnm);
Note: See TracChangeset for help on using the changeset viewer.