1 03/29/76  sort, merge
  2 
  3 Syntax:
  4      sort  input_specs  output_spec  {-control_args}
  5      merge input_specs  output_spec  {-control_args}
  6 
  7 
  8 Function: Sort (Merge) one or more files
  9 according to the values of one or more key fields.
 10 
 11 This info file applies to both the sort and the merge;
 12 see the section "Differences Between Sort and Merge".
 13 
 14 
 15 Arguments:
 16 input_specs
 17    Specify each input file (up to 10) as -
 18      -if pathname             Pathname in Storage System, or
 19      -ids "attach_desc"       Attach description.
 20 
 21 output_spec
 22    Specify just one output file as -
 23      -of pathname             Pathname in Storage System, or
 24      -of -replace             Replace input file by output file, or
 25      -ods "attach_desc"       Attach description.
 26 
 27 
 28 
 29 Control arguments:
 30      -ci            Sort (Merge) Description input via terminal, or
 31      -sd pathname   Pathname of Sort Description (sort command only), or
 32      -md pathname   Pathname of Merge Description (merge command only).
 33      -td pathname   Pathname of directory to contain work files;
 34                     default is user's process directory (sort command only).
 35      -file_size f   Estimated total amount of data to be sorted,
 36                     in millions of bytes (sort command only).
 37 
 38 
 39 
 40 Examples:
 41 1)  sort -ci -if in -of -rp   Sort Description from user's terminal;
 42                               input file is named in;
 43                               output file will replace input file.
 44 Input.                        The Sort requests the Sort Description.
 45 keys: char(10) 0;             The single key is a character string
 46                               whose length is 10 bytes,
 47                               and which starts at the first byte
 48                               of the record (word 0, bit 0).
 49 .                             A line consisting of "." terminates
 50                               the Sort Description from a terminal.
 51 
 52 2)  sort -sd sort_desc -td >udd>pool
 53                               Sort Description entered from a segment;
 54                               work files will be contained in the
 55                               directory >udd>pool;
 56                               no input or output file is named.
 57      Assume the segment sort_desc contains -
 58 key: bin(17) 1;               The key is fixed binary aligned, and
 59                               occupies the second word of the record.
 60 exits: input_file  user$input Input_file exit procedure is user$input.
 61     output_file user$output;  Output_file exit procedure is user$output.
 62 
 63 3)  sort -ids "tape_ansi_ V" -ods "record_stream_ -target vfile_ b" -ci
 64                               Input file specified by attach description
 65                               for a magnetic tape in ANSI format;
 66                               output file specified to be unstructured
 67                               (the Sort's record output will be
 68                               transformed into stream output).
 69 
 70 4)  merge -md merge_desc -if a.in -if b.in -of =.out
 71                                 Merge Description entered from a segment;
 72                                 input files are named a.in and b.in;
 73                                 output file will be named b.out.
 74 
 75 
 76 Syntax of the Sort (Merge) Description:
 77      keys:  <key_description> ... ;
 78      exits:  <exit_description>  ... ;
 79 If -ci is used, the additional line "." terminates input.
 80 There may be up to 32 keys described.
 81 
 82 
 83 Syntax of a Key Description:
 84      <datatype> (<size>) <word_offset> [(<bit_offset>)] [descending]
 85 where -
 86      <datatype>     Data type of a key field; can be -
 87                     char, bit, fixed bin, float bin, dec, float dec.
 88      <size>         Length of the key field (in decimal),
 89                     in units appropriate to the data type.
 90      <word_offset>  Offset in words from the beginning of the record.
 91                     Words are numbered (in decimal) starting at 0.
 92      <bit_offset>   Offset in bits from the beginning of the word.
 93                     Bits are numbered (in decimal) starting at 0.
 94      descending     Rank in descending order for this key field.
 95 
 96 
 97 Syntax of an Exit Description:
 98      <exit_name>  <user_name>
 99 where -
100      <exit_name>    Name of the exit point -
101           input_file          (sort command only)
102           output_file         (sort command only)
103           compare
104           input_record        (sort command only
105           output_record
106 
107       <user_name>   Name of the entry point of the user procedure,
108                     in the same form as a command name.
109 
110 
111 Writing an Exit Procedure:
112 See the MPM descriptions of the subroutines sort_ and merge_
113 for a complete description of how to write a user exit procedure;
114 or type "help sort_" or "help merge_" for a summary.
115 
116 
117 Functions:
118 Sort or merge one or more files of records which are not ordered,
119 to create a new file of ordered (or "ranked") records.
120 
121 
122 Files Supported:
123 An input or output file can be specified
124 either by a pathname or by an attach description.
125 Its organization must be structured (record I/O is used).
126 Records can be either fixed length or variable length.
127 If the user names an input file or an output file,
128 it must be in the Multics Storage System.
129 (It can be either a segment or a multisegment file.)
130 If the user supplies an attach description,
131 any I/O module available at the installation can be used,
132 provided it supports sequential record I/O.
133 
134 
135 Input:  The user can specify up to 10 input files.
136 The organization can be either sequential or indexed.
137 Alternatively, the user must name an input_file exit procedure,
138 which is then responsible for releasing records to the Sort.
139 
140 
141 Output:  The user can specify one output file.
142 The organization must be sequential.
143 Alternatively, the user must name an output_file exit procedure,
144 which is then responsible for retrieving records
145 (ranked by the Sort) from the Sort.
146 
147 
148 Sort Description:
149 In addition to the arguments to the sort or merge command,
150 a Sort (Merge) Description is necessary
151 to specialize the Sort (Merge) for a particular execution.
152 It can be supplied either via the user's terminal, or via a segment.
153 A Sort Description can include the following statements -
154      keys           Specifies key fields, used for ranking records.
155      exits          Names user-written exit procedures.
156 
157 
158 Keys Statement:  Up to 32 key fields can be specified.
159 Use any PL/I data type - except varying string, complex, or pictured.
160 Ordering can be ascending, descending, or mixed.
161 The original order of records with equal keys is preserved.
162 
163 If key fields are not described via the keys statement,
164 then the user must name a compare exit procedure.
165 
166 
167 Exits Statement:  User-written "exit procedures" can be supplied
168 at specific points in the sorting process.
169 The following exits are supported:
170      input_file     Reads input file, releases records to the sort.
171      output_file    Receives records in ranked order, writes output file.
172      compare        Compares two records, decides which ranks first.
173      input_record   Process each input record (delete, insert, or alter).
174      output_record  Process each output record (delete, insert, alter,
175                     or summarize data).
176 
177 
178 Differences Between Sort and Merge:
179 The merge command has the following restrictions -
180 1)  -replace cannot be used for the output file.
181 2)  -td and -file_size cannot be specified.
182 3)  The following exit points are not provided -
183           input_file
184           output_file
185           input_record