home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / ddfdump.icn < prev    next >
Text File  |  2001-08-02  |  2KB  |  95 lines

  1. ############################################################################
  2. #
  3. #    File:     ddfdump.icn
  4. #
  5. #    Subject:  Program to print the contents of an ISO 8211 DDF file
  6. #
  7. #    Author:   Gregg M. Townsend
  8. #
  9. #    Date:     August 2, 2001
  10. #
  11. ############################################################################
  12. #
  13. #    This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #    Usage:  ddfdump [file...]
  18. #
  19. #    Ddfdump prints the contents of Data Descriptive Files (DDF).
  20. #    DDF is an incredibly complex file format enshrined by the
  21. #    ISO 8211 standard and used by the United States Geological
  22. #    Survey (USGS) for digital data.
  23. #
  24. ############################################################################
  25. #
  26. #  Links:  ddfread
  27. #
  28. ############################################################################
  29.  
  30. link ddfread
  31.  
  32.  
  33. $define RecSep "\x1E"        # ASCII Record Separator
  34. $define UnitSep "\x1F"        # ASCII Unit Separator
  35. $define ShowRecSep "\xB6"    # show record separator as paragraph mark
  36. $define ShowUnitSep "\xA7"    # show unit separator as section mark
  37.  
  38.  
  39.  
  40. procedure main(args)
  41.    local f, nbytes
  42.  
  43.    if *args > 0 then
  44.       every dofile(!args)
  45.    else
  46.       dofile()
  47.  
  48. end
  49.  
  50. procedure dofile(fname)
  51.    local f, dda, d, e, s
  52.  
  53.    write("\n", \fname, ":")
  54.    if /fname then
  55.       f := ddfopen(&input) | stop("standard input is not a DDF file")
  56.    else
  57.       f := ddfopen(fname) | stop("can't open ", fname, " as DDF file")
  58.    write()
  59.  
  60.    dda := ddfdda(f)
  61.    every e := !dda do {
  62.       write(e.tag, ": ", img(e.control), " ", img(e.name), " ", img(e.format))
  63.       every write("   ", img(!e.labels))
  64.       }
  65.  
  66.    while d := ddfread(f) do {
  67.       write()
  68.       every e := !d do {
  69.          writes(get(e), ":")
  70.          while s := get(e) do
  71.             if type(s) == "string" then
  72.                writes(" ", img(s))
  73.             else
  74.                writes(" ", image(s))
  75.          write()
  76.          }
  77.       }
  78.  
  79.    ddfclose(f)
  80. end
  81.  
  82. procedure img(s, n)
  83.    static s1, s2
  84.    initial {
  85.       s1 := s2 := string(&cset)
  86.       every !s2[1+:32] := "."        # show unprintables as "."
  87.       every !s2[128+:33] := "."
  88.       s2[1+ord(RecSep)] := ShowRecSep    # show record sep (1E) as section mark
  89.       s2[1+ord(UnitSep)] := ShowUnitSep    # show unit sep (1F) as paragraph mark
  90.    }
  91.    if *s > \n then
  92.       s := s[1+:n]
  93.    return "<" || map(s, s1, s2) || ">"
  94. end
  95.