// ----------------------------------------------------------------------------
// tmain
// ----------------------------------------------------------------------------
int tmain(int argc, TCHAR *argv[])
{
  int ii, ac, opt;
  TCHAR *s, *av[MAXC], *errtxt;
  TCHAR geoid[MAXS+1];
  int value, tr, rev, warn;
  TCHAR inpname[MAXS+1], outname[MAXS+1], prjname[MAXS+1];
  static GEOGRA ifl, ofl; static GEOUTM ixy, oxy;
  struct timespec start, stop;
  double tdif;
  SHPHandle iSHP, oSHP;
  DBFHandle iDBF, oDBF;
  int nShapeType, nEntities; //, nVertices, nParts;
  int nEntity, nVertex, nPart;
  double adfMinBound[4], adfMaxBound[4];
  SHPObject *psShape;
  TCHAR *pszPartType, *pszPlus;
  TCHAR *iTuple, *oTuple;
  FILE *out; TCHAR *proj;
  int nPercentBefore, nPercent;

  // Get program name
  if ((prog = strrchr(argv[0], DIRSEP)) == NULL) prog = argv[0];
  else prog++;
  if ((s = strstr(prog, T(".exe"))) != NULL) *s = T('\0');
  if ((s = strstr(prog, T(".EXE"))) != NULL) *s = T('\0');

  // Default global flags
  debug = 0;   // no debug
  tr = 1;      // default transformation: xy (d96tm) --> fila (etrs89)
  rev = 0;     // don't reverse xy/fila
  geoid[0] = T('\0');
  gid_wgs = 1; // slo2000
  hsel = -1;   // no default height processing (use internal recommendations)

  // Parse command line
  ac = 0; opt = 1;
  for (ii = 1; ii < argc && ac < MAXC; ii++) {
    if (opt && *argv[ii] == T('-')) {
      if (strcasecmp(argv[ii], T("-g")) == 0) { // geoid
        ii++; if (ii >= argc) goto usage;
        xstrncpy(geoid, argv[ii], MAXS);
        if (strlen(geoid) == 0) goto usage;
        if (strncasecmp(geoid, T("slo"), 1) == 0) gid_wgs = 1;      // slo2000
        else if (strncasecmp(geoid, T("egm"), 1) == 0) gid_wgs = 2; // egm2008
        else goto usage;
        continue;
      }
      else if (strcasecmp(argv[ii], T("-t")) == 0) { // transformation
        ii++; if (ii >= argc) goto usage;
        if (strlen(argv[ii]) == 0) goto usage;
        errno = 0; value = strtol(argv[ii], &s, 10);
        if (errno || *s) goto usage;
        if (value < 1 || value > 10) goto usage;
        tr = value;
        continue;
      }
      else if (strcasecmp(argv[ii], T("-ht")) == 0) { // transformed height
        hsel = 0;
        continue;
      }
      else if (strcasecmp(argv[ii], T("-hc")) == 0) { // copy height
        hsel = 1;
        continue;
      }
      else if (strcasecmp(argv[ii], T("-hg")) == 0) { // geoid height
        hsel = 2;
        continue;
      }
      else if (strcasecmp(argv[ii], T("--")) == 0) { // end of options
        opt = 0;
        continue;
      }
      s = argv[ii];
      while (*++s) {
        switch (*s) {
          case T('d'): // debug
            debug++;
            break;
          case T('r'): // reverse xy/fila
            rev = 1;
            break;
          case T('v'): // version
            usage(prog, 1); // show version only
            exit(0);
            break;
          default: // usage
usage:      usage(prog, 0);
            exit(1);
        }
      }
      continue;
    } // if opt
    av[ac] = (TCHAR *)malloc(MAXS+1);
    if (av[ac] == NULL) {
      errtxt = xstrerror();
      if (errtxt != NULL) {
        fprintf(stderr, T("malloc(av): %s\n"), errtxt); free(errtxt);
      } else
        fprintf(stderr, T("malloc(av): Unknown error\n"));
      exit(3);
    }
    xstrncpy(av[ac++], argv[ii], MAXS);
  } // for each argc
  av[ac] = NULL;

  ellipsoid_init();
  params_init();

  if (ac < 2) goto usage;

  if ((s = strrchr(av[0], T('.'))) != NULL) *s = T('\0'); // clear current extension
  xstrncat(av[0], T(".shp"), MAXS); // look for <name>.shp

  convert_shp_file(av[0], av[1], NULL);

  return 0;
} /* main */
Exemple #2
0
int main ()
{
    object ellipsoid;
    int depth;
    int run;

    long min_syscall = -1;
    long min_init = -1;
    long min_seq = -1;
    long min_par = -1;
    long min_libsphere_draw = -1;
    long min_libsphere = -1;

    /*
    // Find the fastest execution time among 100 runs
    // of gettimeofday system call.
    */
    for (run = 1; run <= max_run; run++) {
        //gettimeofday (&t0);
        //gettimeofday (&t1);

 //       microsec = (t1.tv_sec-t0.tv_sec)*1000000 + (t1.tv_usec-t0.tv_usec);
        if (min_syscall > microsec || min_syscall < 0)
            min_syscall = microsec;
    }

    /*
    // Find the fastest execution time among 100 runs
    // of ellipsoid initialization for each depth.
    */
    for (depth = 1; depth <= max_depth; depth++) {
        for (run = 1; run <= max_run; run++) {
            //gettimeofday (&t0);
            ellipsoid_init (depth);
            //gettimeofday (&t1);
            ellipsoid_done ();

  //          microsec = (t1.tv_sec-t0.tv_sec)*1000000 + (t1.tv_usec-t0.tv_usec);
            if (min_init > microsec || min_init < 0)
                min_init = microsec;
        }
        min_init -= min_syscall;
        timing[depth-1].init = min_init;
        min_init = -1;
    }

    /*
    // Find the fastest execution time among 100 runs
    // of ellipsoid generation by ellipsoid_seq() for each depth.
    */
    ellipsoid_init (max_depth);
    for (depth = 1; depth <= max_depth; depth++) {
        for (run = 1; run <= max_run; run++) {
            //gettimeofday (&t0);
            ellipsoid_seq (&ellipsoid, depth, 1.0, 2.0, 3.0);
            //gettimeofday (&t1);
            ellipsoid_free (&ellipsoid);

//            microsec = (t1.tv_sec-t0.tv_sec)*1000000 + (t1.tv_usec-t0.tv_usec);
            if (min_seq > microsec || min_seq < 0)
                min_seq = microsec;
        }
        min_seq -= min_syscall;
        timing[depth-1].seq = min_seq;
        min_seq = -1;
    }

    /*
    // Find the fastest execution time among 100 runs
    // of ellipsoid generation by ellipsoid_par() for each depth.
    */
    ellipsoid_init (max_depth);
    for (depth = 1; depth <= max_depth; depth++) {
        for (run = 1; run <= max_run; run++) {
            //getrimeofday (&t0);
            ellipsoid_par (&ellipsoid, depth, 1.0, 2.0, 3.0);
            //getrimeofday (&t1);
            ellipsoid_free (&ellipsoid);

            //microsec = (t1.tv_sec-t0.tv_sec)*1000000 + (t1.tv_usec-t0.tv_usec);
            if (min_par > microsec || min_par < 0)
                min_par = microsec;
        }
        min_par -= min_syscall;
        timing[depth-1].par = min_par;
        min_par = -1;
    }

    /*
    // Find the fastest execution time among 100 runs
    // of sphere generation by IRIS GL sphere library for each depth.
    */
    foreground ();
    noport ();
    winopen ("");
    sphmode (SPH_TESS, SPH_OCT); /* octahedral subdivision */
    sphmode (SPH_PRIM, SPH_POLY);
    for (depth = 1; depth <= SPH_MAXDEPTH; depth++) {
        static float sphparams[] = { 0.0, 0.0, 0.0, 1.0 };

        /*
        // Find the fastest execution time among 100 runs
        // of sphere drawing by IRIS GL sphere library.
        */
        sphmode (SPH_DEPTH, depth);
        sphdraw (sphparams); /* generation and drawing of the sphere */
        for (run = 1; run <= max_run; run++) {
            finish (); /* block until the geometry pipeline is empty */
            //getrimeofday (&t0);
            sphdraw (sphparams); /* drawing only without generation */
            //getrimeofday (&t1);

            //microsec = (t1.tv_sec-t0.tv_sec)*1000000 + (t1.tv_usec-t0.tv_usec);
            if (min_libsphere_draw > microsec || min_libsphere_draw < 0)
                min_libsphere_draw = microsec;
        }
        sphfree ();
        min_libsphere_draw -= min_syscall;

        /*
        // Find the fastest execution time among 100 runs
        // of sphere generation by IRIS GL sphere library.
        */
        for (run = 1; run <= max_run; run++) {
            sphmode (SPH_DEPTH, depth);
            finish ();
            //getrimeofday (&t0);
            sphdraw (sphparams); /* generation and drawing of the sphere */
            //getrimeofday (&t1);
            sphfree ();

            //microsec = (t1.tv_sec-t0.tv_sec)*1000000 + (t1.tv_usec-t0.tv_usec);
            if (min_libsphere > microsec || min_libsphere < 0)
                min_libsphere = microsec;
        }
        min_libsphere -= min_libsphere_draw + min_syscall;
        timing[depth-1].libsphere = min_libsphere;
        min_libsphere = -1;
    }

    for (depth = 1; depth <= max_depth; depth++) {
        printf ("depth = %3d: nv = %8d, nf = %8d, init = %8ld, seq = %8ld, par = %8ld",
            depth, 4*depth*depth + 2, 8*depth*depth,
            timing[depth-1].init, timing[depth-1].seq, timing[depth-1].par);
        if (depth <= SPH_MAXDEPTH)
            printf (", libsphere = %8ld", timing[depth-1].libsphere);
        printf ("\n");
    }

    return 0;
}