home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / doc / mir / 17fixed < prev    next >
Encoding:
Text File  |  1992-06-29  |  13.2 KB  |  288 lines

  1.               ═══════════════════════════════════
  2.  
  3.                   7.   WORKED EXAMPLES...
  4.                        FIXED LENGTH RECORDS
  5.  
  6.               ═══════════════════════════════════
  7.  
  8.  
  9.             In the 1950s, virtually all computer records were fixed
  10. length.  They are still in wide use today.  Again, we look to you
  11. for data samples that can be used to explain the various forms in
  12. which data is held in real files.
  13.  
  14.  
  15.         ═══════════════════════════════════════════════
  16. 7.1           Recognizing fixed length ASCII text
  17.         ═══════════════════════════════════════════════
  18.  
  19.             Recall that the first step in analysis of a file is a
  20. byte survey.  We have concentrated so far on ASCII text data in
  21. which all characters are printable.  A_BYTES (analyze bytes) tells
  22. us immediately if we are within the printable subset, which is much
  23. more manageable than the full set of 256 characters.  Many of the
  24. standard software utilities have unpredictable (read "nasty")
  25. effects when used on non-printing characters.  The MORE command
  26. produces garbage on a personal computer screen, and often locks up
  27. a terminal so badly that it has to be turned off to reset.
  28.  
  29.             Assuming a file contains printable characters only, how
  30. do we recognize if it contains fixed length data?  First, check
  31. whether the byte survey shows any line feeds or carriage returns.
  32. Fixed length ASCII text normally contains none.  If there are none,
  33. then use the MORE command to pass part of the file over the screen. 
  34. MORE normally shows 1920 characters at a time (1840 on a terminal).
  35.  
  36.  
  37. ≡≡≡≡->> QUESTION:
  38.             Why these numbers?  And why are the numbers incorrect
  39.             if there are line feeds or carriage returns present?
  40.                                                             <<-≡≡≡≡
  41.  
  42.             In cases where the fixed length is less than a single
  43. screen display, you should be able to spot recurring patterns.  If
  44. the data is unfielded, watch for blank padding at the end of each
  45. record.  If there are fields, watch for distinctive features such
  46. as dates, or numeric groups, or fields that are blank repeatedly. 
  47. If the fixed length is a multiple of 80, the patterns will recur
  48. directly under one another.  If it is just over a multiple of 80,
  49. the patterns will shift progressively to the right.
  50.  
  51.  
  52. ≡≡≡≡->> QUESTION:
  53.             Each fixed length ASCII record in a file is 343 bytes
  54.             long.  How many lines will there be between pattern
  55.             repetitions?  Will the pattern appear to shift to the
  56.             right or left?  By how many columns each time?
  57.                                                             <<-≡≡≡≡
  58.  
  59.             For historic reasons (length of punch cards, early
  60. printer widths, etc.), certain fixed lengths are especially
  61. common... 80, 120, 128 and 132 bytes.
  62.  
  63.             The record length turns out to be a multiple of 80 plus
  64. the number of bytes extra on the next line (or less the number of
  65. bytes in which a new record intrudes on the last line).  To test
  66. the number that you have calculated, use the NEWLINES program on a
  67. sample.
  68.  
  69. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  70. Usage - newlines  file_in  file_out  bytes_per_line
  71.  
  72.         Inserts carriage return and line feed every "file_in"
  73.         bytes.  Used to deblock data received in line blocks.
  74.  
  75. input:  A file in which data is broken into units in which every
  76.         unit is precisely the same length, and there are no line
  77.         feeds or carriage returns.  In the past this was a common
  78.         way of storing text and fixed length records.
  79.  
  80. output: The same data, expanded by the addition of carriage returns
  81.         and line feeds.  In this form, the data can be further
  82.         analyzed and processed using line-oriented programs.
  83.  
  84. writeup: MIR TUTORIAL ONE, topic 7
  85. ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  86.  
  87.             For example,
  88.  
  89.                 NEWLINES SAMPLE SAMPLE.FIX 120
  90.  
  91. Using MORE on SAMPLE.FIX looks quite different... every second line
  92. is only half full, and the patterns recur directly under each
  93. other.  If they don't... back to the drawing board!  Test alternate
  94. values until the patterns are aligned vertically.
  95.  
  96.  
  97.  
  98.  
  99.  
  100.         ═════════════════════════
  101. 7.2           Field layouts
  102.         ═════════════════════════
  103.  
  104.             Here is a fixed length version of the inventory record
  105. example in the previous topic.  This version omits tags and end of
  106. data markers.  Location within the record determines the field. 
  107. The record is displayed 50 bytes per line.  A byte counter is added
  108. below the record.
  109.  
  110.  
  111. CL4-097-BVALVE SPRING ASSEMBLY         00005700000
  112. 0016212008004004211003654031032023996             
  113.   00   000100000001297500           000000   CL4-9
  114. 97-XDY6-000-P
  115. 0         1         2         3         4
  116. 01234567890123456789012345678901234567890123456789
  117.  
  118.             Successive records each have the same fields.  The same
  119. number of bytes is reserved for any given field in every record,
  120. whether or not the field is empty.  A fixed length data record may
  121. prove cryptic unless we have a precise definition of the allocation
  122. of bytes.  Recall the list of headings in the first version: it
  123. does not account for all the data.  Watch what happens when we try
  124. attempt to assign start and end bytes:
  125.  
  126.                                                 Start    End
  127.                                                 byte     byte
  128.  
  129. Part Number:         CL4-097-B                     0        8
  130. Description:         VALVE SPRING ASSEMBLY         9        ???
  131. Quantity on hand, location 1:           57        39 ?     44
  132. Quantity on hand, location 2:            0        45 ?     50 ?
  133. Quantity on hand, location 3:       16,212        51 ?     56
  134. Quantity on hand, location 4:        8,004        57 ?     62
  135. Usage, this month:                   4,211        63 ?     68
  136. Usage, same month last year:         3,654        69 ?     74
  137. Usage, current year to date:        31,032        75 ?     80
  138. Usage, last year to date:           23,996        81 ?     86
  139. Economic order quantity:             1,000         ???      ???
  140. Cost per unit:                    $ 12.975         ???      ???
  141. Permitted substitute part #:     CL4-997-X       145      153
  142. Permitted substitute part #:     DY6-000-P       154      162
  143.  
  144.             Where there is a single question mark, there is a bit
  145. of uncertainty.  Where there are triple question marks, we are
  146. really floundering.  Is the economic order quantity in single units
  147. or to one, two or three places after the decimal?  What is the
  148. maximum economic order quantity value?  Is the description field 30
  149. bytes wide, or is there an intervening field which in this record
  150. is blank?
  151.  
  152.             In the ideal world, whoever provides the data also
  153. gives us the fixed record definition with full headings and byte
  154. ranges.  Where the definition is not available, we can infer some
  155. (and perhaps all) of the byte assignments and field titles if we
  156. have access to the software normally used to display the data.  A
  157. third best is to have hard copy of samples of the same data that is
  158. in the file.  The more samples we have, the more likely we are to
  159. find the extreme values that fill fields to their full width.  For
  160. example, if "usage, last year to date" displays as 248,377 and we
  161. find in bytes 81 through 86 the digits 248377 then that field is
  162. defined with full certainty.
  163.  
  164.  
  165.         ═════════════════════════════════════
  166. 7.3           Extracting a single field
  167.         ═════════════════════════════════════
  168.  
  169.             In MIR TUTORIAL TWO, we will look at software that
  170. converts fixed length ASCII fielded text into tagged text.
  171.  
  172. ≡≡≡≡->> QUESTION:
  173.             Under what conditions would the tagged version conserve
  174.             resources?  When is it wasteful?  Which has to be more
  175.             carefully planned... tagged or fixed length?  Why? 
  176.             What are the advantages and disadvantages of tags
  177.             versus fixed length record definitions?
  178.                                                             <<-≡≡≡≡
  179.  
  180.             For now, here is a quick and dirty way to break out the
  181. content of a single field.  This works for record lengths up to 510
  182. bytes.  (With a carriage return and line feed added, we reach the
  183. limit for the COLRM program.)  The steps:
  184.  
  185.         »   Use A_BYTES to check that there are no unprintable
  186.             characters, no line feeds, and no carriage returns.
  187.  
  188.         »   Verify that patterns recur at regular intervals.
  189.  
  190.         »   Determine as accurately as possible the fixed record
  191.             length.
  192.  
  193.         »   Use NEWLINES to break the data into lines.
  194.  
  195.         »   Use COLRM to delete all characters after the desired
  196.             field, and all characters before.  Watch differences in
  197.             counting conventions; COLRM is based on the UNIX
  198.             utility which numbers the first column "1".
  199.  
  200.         »   If the field data appears repetitious, sort the result
  201.             and run it through the A_OCCUR program to get a full
  202.             listing of field content.
  203.  
  204.             This depth of analysis would normally be overkill.  But
  205. there are times when you want to be sure of what you have before
  206. you go further.
  207.  
  208.             As an alternative to the last step in the case where
  209. the full field is too long or variable, you can still make a
  210. listing of all the words or terms.  Avoid this if there is heavy
  211. numeric content, because numbers vary far more widely than words;
  212. the sorting gets slow and the final list is not altogether useful. 
  213. In order to make a list of terms, you convert all blanks in the
  214. field data to line feeds.  In UNIX, the TR utility is ideal:
  215.  
  216.                 TR '\040' '012' < field_data | SORT | A_OCCUR
  217.                                 > output_list
  218.  
  219. In Tutorial TWO, we will introduce a DOS  program REPLACE1.  It
  220. could be used with a replacement table consisting of one line: 
  221. "\20 \0A".  Again sort the result and run it through A_OCCUR to get
  222. an ordered list with frequencies.
  223.  
  224. ≡≡≡≡->> QUESTION:
  225.             The UNIX TR utility is exceptionally quick, yet it is
  226.             flexible.  I use it heavily in UNIX indexing.  A DOS
  227.             equivalent, especially one which is copyleft, would be
  228.             widely welcomed by serious indexers.   Would anyone
  229.             care to take this on as a project?  (You might consider
  230.             using hexadecimal rather than octal notation for non-
  231.             printing characters.)
  232.                                                             <<-≡≡≡≡
  233.  
  234.  
  235.         ══════════════════════════════════════════════════
  236. 7.4           Packed numbers in fixed length records
  237.         ══════════════════════════════════════════════════
  238.  
  239.             Suppose we have either display software or hard copy to
  240. match data in a file that we are examining.  Suppose further that
  241. where numbers are shown, often the matching field bytes contain
  242. non-printing characters.  The byte analysis shows a low to moderate
  243. frequency set of non-text characters.  What's happening?
  244.  
  245.             Chances are, you are dealing with packed numbers. 
  246. COBOL and BASIC each have packing schemes; doubtless there are
  247. others.  COBOL packing works on the basis that four bits can
  248. express 16 different values.  0 through 9 take up 10 of the 16
  249. values.  Others are used to indicate negative, positive, unsigned
  250. values, decimal sign, end of packed data.  Compression is slightly
  251. under two to one compared with unpacked decimal data (one byte per
  252. character).
  253.  
  254.  
  255. ≡≡≡≡->> QUESTION:
  256.             Can anyone find evidence that COBOL packed numbers have
  257.             been rigorously standardized?  I'm still looking!
  258.                                                             <<-≡≡≡≡
  259.  
  260.             The presence of packed values makes recognition of
  261. fixed length data more difficult.  A byte within a packed value may
  262. happen to correspond to a line feed or carriage return or to some
  263. other value that will upset software intended for ASCII text.  The
  264. next topic takes up the problem of analysis under such conditions.
  265.  
  266.             For analysis purposes, we simply need to know that
  267. specific ranges of bytes within a fixed length record have been
  268. assigned to packed numeric values.  Do not push the analysis any
  269. further at this point.  There is an extra headache that may confuse
  270. the analysis; typically the data started as EBCDIC and has been
  271. converted to ASCII.  The packed characters have to be switched back
  272. to EBCDIC for unpacking, while the other fields must be left in
  273. ASCII.  More on this in TUTORIAL TWO.
  274.  
  275.                           *  *  *  *  *
  276.  
  277.             We have studied methods of recognizing fixed length
  278. ASCII text and of determining the fixed length.  Building a list of
  279. field layouts from data is possible, particularly if we have
  280. display software or hard copy of records.  It is possible to
  281. isolate the content of any field and create a summary listing of
  282. terms or field entries, complete with frequencies.  The presence of
  283. packed information within fixed length data creates hazards for
  284. software intended for ASCII text only.
  285.  
  286.             In the next topic, we relax all assumptions about the
  287. character set, and assume that we are dealing with all 256 possible
  288. combinations of bits within a byte.