* CATALOG NO. 704988  SIGMA 5/7 SORT             OVERLAY 3              P3  0000
*  VERSION C00                                                          P3  0001
         SYSTEM   SIG7FDP                                               P3  0002
         SYSTEM   BPM                                                   P3  0003
*                                                                       P3  0004
PGMSEG3  CSECT    0                                                     P3  0005
*                                                                       P3  0006
         PAGE                                                           P3  0007
*                                                                       P3  0008
         REF      BCT0,CCT0,FCT0,FCT1,FCT2,FCT3,FCT4,ILT0               P3  0009
         REF       BFVB1,BVDR1,CNVRT,CSO,SC5,ILT1                       P3  0010
         REF      BINEBC,EBCBN,KRASC,KRDSC,OS1                          P3  0011
         REF      CRSF,NUMPGS,SIN1R
         REF      OUTLENSW,MEMPROSW
         REF      ENDSORT
         SREF     MCR1X,MFPSX,MFP4X,MRSX,MEB9X,MWRTX,MSWR1X
         SREF     MREADX,OPCLSX,S:OUTPUT
         DEF      MCR,MCRR,MEB1,MFPWT,MFPWTR,MFP25,MFP3
         DEF      MOWR1,MREAD,MREAD0,MRGSEL,MRS1,MSWR1
         DEF      MWRITER,OPCLSR
*        LINE 17 REMOVED FOR UTS                                        P3  0013
*                                                                       P3  0014
         PAGE                                                           P3  0015
*                                                                       P3  0016
X1       EQU      1                                                     P3  0017
X2       EQU      2                                                     P3  0018
X3       EQU      3                                                     P3  0019
X4       EQU      4                                                     P3  0020
X5       EQU      5                                                     P3  0021
X6       EQU      6                                                     P3  0022
X7       EQU      7                                                     P3  0023
R0       EQU      8                                                     P3  0024
R1       EQU      9                                                     P3  0025
R2       EQU      10                                                    P3  0026
RA       EQU      10                                                    P3  0027
RB       EQU      11                                                    P3  0028
RC       EQU      12                                                    P3  0029
RD       EQU      13                                                    P3  0030
RE       EQU      14                                                    P3  0031
RF       EQU      15                                                    P3  0032
S:SORTP3 EQU      MCR                                                   P3  0033
SORTP3   EQU      S:SORTP3                                              P3  0034
*                                                                       P3  0035
         PAGE                                                           P3  0036
*                                                                       P3  0037
         BOUND    8                                                     P3  0038
*                                                                       P3  0039
SELI     DATA,4   0,0                                      /SIG7-4137/*EP3  0040
*                                                                       P3  0041
MTT0     DO1      68
         DATA     0                                                     P3  0043
MTT1     EQU      MTT0+1                                                P3  0044
MTT2     EQU      MTT0+34
MTT3     EQU      MTT2+1                                                P3  0046
*                                                                       P3  0047
INPUT    DATA     0,0                                                   P3  0048
MRGSEL   DATA     0,0                                                   P3  0049
*                                                                       P3  0050
         PAGE                                                           P3  0051
*                                                                       P3  0052
*                                                                       P3  0053
*                                                                       P3  0054
*                                                                       P3  0055
*  THIS PHASE MERGES THE ORDERED STRINGS PRODUCE BY THE INTERNAL        P3  0056
*       SORT INTO A FINAL SINGLE STRING.  THIS MERGING PROCESS IS       P3  0057
*       PERFORMED AS A SERIES OF SUBPHASES, EACH OF WHICH REDUCES       P3  0058
*       THE NUMBER OF STRINGS UNTIL THE FINAL SUBPHASE PRODUCES         P3  0059
*       AS ITS OUTPUT A SINGLE ORDERED STRING, THE OUTPUT FILE.         P3  0060
*                                                                       P3  0061
         PAGE                                                           P3  0062
*                                                                       P3  0063
*                                                                       P3  0064
*  THIS ROUTINE IS THE MERGE CONTROL ROUTINE.  IT CONTROLS THE          P3  0065
*       EXECUTION OF THE SUBROUTINES THAT MAKE UP SEGMENT THREE         P3  0066
*       OF THE SORT.  THIS ROUTINE CHECKS AND SETS UP THE FINAL         P3  0067
*       MERGE PHASE OPTIONS.                                            P3  0068
*                                                                       P3  0069
         PAGE                                                           P3  0070
*                                                                       P3  0071
*                                                                       P3  0072
MCRR     DATA     0                                                     P3  0073
*                                                                       P3  0074
MCR      STW,X5   MCRR              SAVE RETURN ADDRESS                 P3  0075
         LI,5     ENDP3
         STW,5    ENDSORT            IN CASE OF ERROR DUMP
         LW,5     KRDSC                                    /SIG7-4137/*EP3  0076
         STW,5    SELI                                     /SIG7-4137/*EP3  0077
         LW,5     KRASC                                    /SIG7-4137/*EP3  0078
         STW,5    SELI+1                                   /SIG7-4137/*EP3  0079
         LI,X5    3                                                     P3  0080
         LI,X1    1                                                     P3  0081
         STH,X5   CCT0,X1           SET TO PHASE 3                      P3  0082
*                                                                       P3  0083
         BAL,X5   MRGI              GO INITIALIZE FOR MERGE             P3  0084
*                                                                       P3  0085
         BAL,X5   PFPS              CHECK FOR PREMATURE FINAL PASS      P3  0086
*                                                                       P3  0087
MCR1     BAL,X5   MRPI              GO INITIALIZE FOR THIS STRING       P3  0088
*                           MRPI:   RETURN HERE WITH CCT0=4 IF FINAL PASP3  0089
         BAL,X5   MFPS              GO SET UP FINAL PHASE OPTIONS       P3  0090
*                           MRPI:   RETURN HERE IF NOT THE FINAL PASS   P3  0091
         BAL,X5   MVG               GO GENERATE MTT TABLES              P3  0092
*                                                                       P3  0093
         BAL,X5   MRS               GO MERGE THIS GROUP OF STRINGS      P3  0094
*                                                                       P3  0095
         BAL,X5   MEB               GO COUNT STRINGS AND TEST FOR 'END  P3  0096
*                                       OF PHASE--END BOOKKEEPING       P3  0097
         LI,X5    X'F'                                                  P3  0098
         AND,X5   CCT0                                                  P3  0099
         CI,X5    4                 IS THIS THE END OF THE SORT         P3  0100
         BNE      MCR1              NO:  GO PROCESS ANOTHER STRING      P3  0101
         LW,X5    CRSF              CHECK IF CO-RESIDENT
         BEZ      MCR1X             NO. GO TO P3A
MCR3     B        *MCRR                                                 P3  0102
*                                                                       P3  0103
         PAGE                                                           P3  0104
*                                                                       P3  0105
*                                                                       P3  0106
*  THIS ROUTINE INITIALIZES FOR THE MERGE.  IT SETS THE MERGE INPUT     P3  0107
*       AND OUTPUT PHYSICAL RECORD LENGTHS IN THE FCT TABLES AND        P3  0108
*       SETS THE BEGINNING BUFFER ADDRESSES FOR EACH TAPE DRIVE.        P3  0109
*       AFTER SETTING UP FOR INITIAL MERGE I/O, THIS ROUTINE SETS       P3  0110
*       MRGSEL TO RCR OR RCRD FOR THE FIRST STRING.                     P3  0111
*                                                                       P3  0112
MRGIR    DATA     0                                                     P3  0113
*                                                                       P3  0114
MRGI     STW,X5   MRGIR             SAVE RETURN ADDRESS                 P3  0115
         LI,X5    MWRITE            INITIALIZE TO WRITE SCRATCH         P3  0116
         STW,X5   MWRT                  FILES                           P3  0117
         LH,X2    ILT0,X1           OUTPUT TAPE ORDINAL--FCT/ILT        P3  0118
         LH,X5    BCT0+3,X1         MERGE BUFFER LENGTH                 P3  0119
         LH,6     BCT0+4,1           OUT LOG REC LEN
         STW,X5   FCT1              SET INPUT PHYSICAL RECORD LENGTH    P3  0121
         STW,X5   FCT2              SET OUTPUT PHYSICAL RECORD LENGTH   P3  0122
         AI,X6    2                                                     P3  0123
         STW,X6   FCT3              SET INPUT LOGICAL RECORD LENGTH     P3  0124
         STW,X6   FCT4              SET OUTPUT LOGICAL RE               P3  0125
*                                                                       P3  0126
         LH,X5    ILT1,X2                                               P3  0127
         LD,X6    SELI              OPPOSING                            P3  0128
         AND,X5   1                                                     P3  0129
         BE       MRG1                                                  P3  0130
         XW,X7    X6                REQUESTED SEQUENCE                  P3  0131
*                                                                       P3  0132
MRG1     STD,X6   MRGSEL                                                P3  0133
         LH,X6    ILT0,X1                                               P3  0134
         LW,X4    BCT0+12           UPPER LIMIT ADDRESS FOR SORT USE    P3  0135
MRG2     SH,X4    BCT0+3,X1         MINUS BUFFER LENGTH                 P3  0136
         STW,X4   FCT2,X6           INTO ALTERNATE BUFFER               P3  0137
         SH,X4    BCT0+3,X1         MINUS BUFFER LENGTH                 P3  0138
         STW,X4   FCT1,X6           INTO BUFFER                         P3  0139
         BDR,X6   MRG2                                                  P3  0140
         LI,6     76
MRG3     LW,X5    FCT1-1,X6             FROM WORD ADDRESSING            P3  0142
         SLS,X5   2                                                     P3  0143
         STW,X5   FCT1-1,X6                                             P3  0144
         BDR,X6   MRG3                                                  P3  0145
         B        *MRGIR                                                P3  0146
*                                                                       P3  0147
         PAGE                                                           P3  0148
*                                                                       P3  0149
PFPSR    DATA     0                                                     P3  0150
*                                                                       P3  0151
PFPS     STW,X5   PFPSR             SAVE RETURN ADDRESS                 P3  0152
         LI,X5    0                 IS PREMATURE FINAL PASS POSSIBLE    P3  0153
         CW,X5    ILT0+1                                                P3  0154
         BNE      *PFPSR            NO                                  P3  0155
         LI,X5    X'10001'                                              P3  0156
         CW,X5    ILT0+2                                                P3  0157
         BE       PFPS1             NO STRINGS AT ALL                   P3  0158
         CW,X1    ILT0+2            ONLY ONE STRING                     P3  0159
         BNE      *PFPSR            NOT POSSIBLE                        P3  0160
PFPS1    MTW,1    PFPSR                                                 P3  0161
         MTW,15   CCT0              SET CCT0 = 2 FOR MFPS TO TEST       P3  0162
         B        *PFPSR                                                P3  0163
*                                                                       P3  0164
         PAGE                                                           P3  0165
*                                                                       P3  0166
*                                                                       P3  0167
*  THIS ROUTINE CHECKS FOR AN EARLY FINAL PHASE AND FOR A ONE-WAY       P3  0168
*                                                                       P3  0169
MRPIR    DATA     0,0                                                   P3  0170
*                                                                       P3  0171
MRPI     STW,X5   MRPIR             SAVE RETURN ADDRESS                 P3  0172
         LH,X6    ILT0,X1           NUMBER OF ILT0 ENTRIES              P3  0173
         LI,X5    0                                                     P3  0174
         CW,X5    ILT0,X6           IS THIS THE BEGINNING OF A PHASE    P3  0175
         BNE      MRP3              NO;  SKIP FINAL PHASE TEST          P3  0176
         LI,X5    1                                                     P3  0177
MRP1     BDR,X6   MRP2                                                  P3  0178
         B        *MRPIR            NO TAPE HAS MORE THAN ONE STRING    P3  0179
MRP2     CW,X5    ILT0,X6           DOES THIS TAPE CONTAIN MORE THAN    P3  0180
         BGE      MRP1              NO:  TRY NEXT TAPE                  P3  0181
MRP3     MTW,1    MRPIR             NOT BEGINNING OF PHASE OR TOO MANY  P3  0182
         B        *MRPIR            SKIP FINAL PASS SET-UP    /STRINGS  P3  0183
*                                                                       P3  0184
         PAGE                                                           P3  0185
*                                                                       P3  0186
*  THIS ROUTINE INITIALIZES FOR THE FINAL PASS                          P3  0187
*                                                                       P3  0188
MFPSR    DATA     0                                                     P3  0189
*                                                                       P3  0190
MFPS     STW,X5   MFPSR             SAVE RETURN ADDRESS                 P3  0191
         LI,X5    MFPWT             SET WRITE ROUTINE TO FINAL PASS     P3  0192
         STW,X5   MWRT                  WRITE                           P3  0193
         MTW,1    CCT0                                                  P3  0194
         LW,RD    CRSF              CHECK IF CO-RESIDENT
         BEZ      MFPSX             NO. GO TO P3A
*                                                                       P3  0195
*  THIS REGION INITIALIZES THE FCT TABLES FOR THE FINAL OUTPUT FILE     P3  0196
*                                                                       P3  0197
         LI,X1    1                                                     P3  0198
         LH,X6    ILT0,X1                                               P3  0199
         LI,RE    X'FFFF'                                               P3  0200
         AND,RE   FCT0,X6                                               P3  0201
         SLS,RE   1                                                     P3  0202
         STW,RE   FCT2                                                  P3  0203
         M:CLOSE  *FCT2,(REL),(REM)
*                                                                       P3  0205
*  THIS REGION TESTS FOR A TAPE COPY IF THIS IS A PREMATURE FINAL PASS  P3  0206
*                                                                       P3  0207
MFP25    RES      0                 RETURN FROM P3A
         LH,X2    CCT0,X1                                               P3  0208
         CI,X2    3                                                     P3  0209
         BNE      *MFPSR            NOT PREMATURE FINAL PHASE           P3  0210
*                                                                       P3  0211
         LI,X5    X'10001'                                              P3  0212
         CW,X5    ILT0+2                                                P3  0213
         BNE      MFP4              ONE STRING                          P3  0214
         BAL,X5   OPCLS             GO EXECUTE OPEN AND CLOSE OWN CODE  P3  0215
MFP3     MTW,3    MFPSR                                                 P3  0216
         MTW,1    CCT0              SKIP MERGE                          P3  0217
         B        *MFPSR            EXIT                                P3  0218
*                                                                       P3  0219
*  THIS REGION COPIES THE SINGLE STRING ONTO THE OUTPUT FILE            P3  0220
*                                                                       P3  0221
MFP4     CW,X1    ILT0+3                                                P3  0222
         BE       MFP3+1            MORE THAN ON  STRING TO BE MERGED   P3  0223
         LI,X6    2                                                     P3  0224
         STW,X6   BCT0+9            FCT ORDINATE FOR INPUT FILE         P3  0225
         LI,7     0                 SET TO OPEN INPUT STRING            P3  0226
         BAL,5    OS1               GO OPEN STRING                      P3  0227
         LW,X6    CRSF              CHECK IF CO-RESIDENT
         BEZ      MFP4X             NO   GO TO P3A
MFP5     BAL,X5   MREAD                                                 P3  0228
         CI,X7    0                 IS THIS THE END OF STRING           P3  0229
         BE       MFP6                YES                               P3  0230
MFP55    BAL,X5   MFPWT                                    /SIG7-1883/*DP3  0231
MFP56    B        MFP5                                     /SIG7-1883/*DP3  0232
*                                                          /SIG7-1883/*DP3  0233
*                                                                       P3  0234
MFP6     LI,7     0                                                     P3  0235
         BAL,11   S:OUTPUT                                              P3  0236
         B        MFP3              EXIT                   /SIG7-1883/*DP3  0237
         PAGE                                                           P3  0238
*                                                                       P3  0239
*                                                                       P3  0240
*                                                                       P3  0241
*  THIS ROUTINE OPENS AN INPUT STRING ON EACH TAPE CONTAINING           P3  0242
*       STRING DATA AND WHICH ALSO HAS NO ZERO (DUMMY) STRINGS.         P3  0243
*  AFTER OPENING THESE STRINGS, THIS ROUTINE READS ONE RECORD FROM      P3  0244
*       EACH STRING, PERFORMS THE NECESSARY COMPARISONS, AND            P3  0245
*       CONSTRUCTS THE MERGE COMPARISON CONTROL TABLE (MTT).            P3  0246
*  WHEN THIS ROUTINE EXITS THE FIRST OUTPUT RECORD HAS BEEN SELECTED.   P3  0247
*                                                                       P3  0248
         PAGE                                                           P3  0249
*                                                                       P3  0250
MVGR     DATA     0,0                                                   P3  0251
*                                                                       P3  0252
*                                                                       P3  0253
MVG      STW,X5   MVGR              SAVE RETURN ADDRESS                 P3  0254
         LI,X1    1                                                     P3  0255
         BAL,X5   TPCPY                                                 P3  0256
         LI,X2    0                                                     P3  0257
         LH,X6    ILT0,X1           ILT0-FCT ORDINATE                   P3  0258
*                                                                       P3  0259
MVG1     BDR,X6   MVG2                                                  P3  0260
         B        MVG5              ALL STRINGS HAVE BEEN OPENED        P3  0261
*                                                                       P3  0262
MVG2     LW,RE    ILT0,X6           ZERO AND ACTUAL STRING COUNTS       P3  0263
         BE       MVG1              THERE ARE NO STRINGS ON THIS UNIT   P3  0264
*                                                                       P3  0265
         LH,X7    RE                ZERO STRING COUNT                   P3  0266
         BNE      MVG1                  IS NON-ZERO--CANNOT USE UNIT    P3  0267
*                                                                       P3  0268
         STH,X2   X6                                                    P3  0269
         STW,X6   MTT2,X2           PREDICTED WINNER ILT-FCT ORDINATE   P3  0270
         AND,X6   =X'FF'                                                P3  0271
         BAL,X5   OS1               GO:  OPEN INPUT STRING              P3  0272
*                                                                       P3  0273
MVG3     BDR,X6   MVG4                                                  P3  0274
         LI,X7    0                                                     P3  0275
         STW,X7   MTT0,X2                                               P3  0276
         STW,X7   MTT1,X2                                               P3  0277
         AI,X2    2                                                     P3  0278
         B        MVG5              ALL STRINGS HAVE BEEN OPENED        P3  0279
*                                                                       P3  0280
MVG4     LW,RE    ILT0,X6           ZERO AND ACTUAL STRING COUNTS       P3  0281
         BE       MVG3              THERE ARE NO STRINGS ON THIS UNIT   P3  0282
*                                                                       P3  0283
         LH,X7    RE                ZERO STRING COUNT                   P3  0284
         BNE      MVG3                  IS NON-ZERO--CANNOT USE UNIT    P3  0285
*                                                                       P3  0286
         STH,X2   X6                                                    P3  0287
         STW,X6   MTT0,X2           PREDICTED LOSER ILT-FCT ORDINATE    P3  0288
         AND,X6   =X'FF'                                                P3  0289
         BAL,X5   OS1                                                   P3  0290
         AI,X2    2                 INCREMENT FOR NEXT PAIR             P3  0291
         B        MVG1                                                  P3  0292
*                                                                       P3  0293
         PAGE                                                           P3  0294
*                                                                       P3  0295
*  THIS REGION READS ONE RECORD FROM EACH INPUT FILE IN MTT AND         P3  0296
*       PERFORMS THE X-LEVEL COMPARES                                   P3  0297
*                                                                       P3  0298
MVG5     LI,X3    0                                                     P3  0299
*                                                                       P3  0300
MVG6     LW,X6    MTT2,X3                                               P3  0301
         STW,X3   MVGR+1                                                P3  0302
         STW,X6   BCT0+9                                                P3  0303
         BAL,X5   MREAD             GO READ PREDICTED WINNER            P3  0304
         LW,X3    MVGR+1                                                P3  0305
         STW,X7   MTT3,X3           RECORD'S ADDRESS IN INPUT BUFFER    P3  0306
         LW,X6    MTT0,X3                                               P3  0307
         BE       MVG7              EMPTY LOSER--LAST ENTRY             P3  0308
         STW,X3   MVGR+1                                                P3  0309
         STW,X6   BCT0+9                                                P3  0310
         BAL,X5   MREAD             GO READ PREDICTED LOSER             P3  0311
         LW,X3    MVGR+1                                                P3  0312
         STW,X7   MTT1,X3           RECORD'S ADDRESS IN INPUT BUFFER    P3  0313
         LW,X4    MTT3,X3           PREDICTED X-LEVEL WINNER ADDRESS    P3  0314
         LW,X5    X7                                                    P3  0315
         BAL,R1   *MRGSEL           GO-COMPARE RECORDS ON SPECIFIED KEYSP3  0316
         BGE      MVG7              NO EXCHANGE NECESSARY               P3  0317
*                                                                       P3  0318
         LCI      2                                                     P3  0319
         LM,RA    MTT0,X3           EXCHANGE LOSER                      P3  0320
         LM,RC    MTT2,X3                                               P3  0321
         STM,RA   MTT2,X3               ENTRIES IN                      P3  0322
         STM,RC   MTT0,X3               MTT TABLE                       P3  0323
MVG7     AI,X3    2                                                     P3  0324
         CW,X3    X2                                                    P3  0325
         BL       MVG6              ALL READS AND COMPARES NOT DONE     P3  0326
         CI,X2    2                                                     P3  0327
         BNE      MVG8-1            MORE THAN TWO FILES TO BE MERGED    P3  0328
         LI,X2    0                 ONLY TWO FILES INTO MERGE           P3  0329
         B        MVG11                                                 P3  0330
*                                                                       P3  0331
         PAGE                                                           P3  0332
*                                                                       P3  0333
*  AT THIS POINT ALL READS AND X-LEVEL COMPARES HAVE BEEN PERFORMED     P3  0334
*                                                                       P3  0335
*  THE Y-LEVEL COMPARISONS ARE MADE IN THE FOLLOWING REGION             P3  0336
*                                                                       P3  0337
         LI,X3    0                                                     P3  0338
MVG8     LW,X4    MTT3,X3           PREDICTED Y-LEVEL WINNER ADDRESS    P3  0339
         LW,X5    MTT3+2,X3         PREDICTED Y-LEVEL LOSER ADDRESS     P3  0340
         BAL,R1   *MRGSEL           GO COMPARE RECORDS ON SPECIFIED KEYSP3  0341
         BGE      MVG9              NO EXCHANGE                         P3  0342
         LCI      2                                                     P3  0343
         LM,RA    MTT2,X3           EXCHANGE                            P3  0344
         LM,RC    MTT2+2,X3                                             P3  0345
         B        MVG10                                                 P3  0346
*                                                                       P3  0347
MVG9     LCI      2                                                     P3  0348
         LM,RA    MTT2+2,X3         LOSER                               P3  0349
         LM,RC    MTT2,X3           WINNER                              P3  0350
MVG10    STM,RA   MTT0,X2                                               P3  0351
         STM,RC   MTT2,X2                                               P3  0352
         STW,X2   MTT2,X3           NEXT ENTRY ORDINATE                 P3  0353
         STW,X2   MTT2+2,X3                                             P3  0354
         AI,X3    4                 INCREMENT X-LEVEL INDEX             P3  0355
         CW,X3    X2                IS IT EQUAL TO Y-LEVEL INDEX        P3  0356
         BGE      MVG11                                                 P3  0357
*                                                                       P3  0358
         AI,X2    2                 INCREMENT Y-LEVEL INDEX             P3  0359
         B        MVG8              GO PROCESS NEXT Y-LEVEL PAIR        P3  0360
*                                                                       P3  0361
         PAGE                                                           P3  0362
*                                                                       P3  0363
*  AT THIS POINT ALL COMPARES NECESSARY TO BUILD THE TOURNAMENT         P3  0364
*       HAVE BEEN COMPLETED.  THE WINNER OF THE LAST COMPARE IS         P3  0365
*       THE FIRST MERGE SELECTEE.                                       P3  0366
*                                                                       P3  0367
*  THE FOLLOWING REGION CONVERTS THE FINAL ENTRY TO A Y-LEVEL           P3  0368
*       ENTRY TYPE AND CREATES IN BCT0+9 AND BCT0+10, A DUMMY           P3  0369
*       Y-LEVEL ENTRY FOR THE FIRST SELECTEE.                           P3  0370
*                                                                       P3  0371
MVG11    LW,RA    MTT2,X2           WINNER FEO-ILT ORDINATE             P3  0372
         LW,RB    MTT3,X2               AND ADDRESS                     P3  0373
         LI,X7    0                                                     P3  0374
         STW,X7   MTT2,X2           NO NEO                              P3  0375
         STD,RA   BCT0+9                                                P3  0376
         B        *MVGR                                                 P3  0377
*                                                                       P3  0378
         PAGE                                                           P3  0379
*                                                                       P3  0380
*                                                                       P3  0381
*  MVG CREATES X-LEVEL MTT ENTRIES  WHICH HAVE THE FORM:                P3  0382
*                                                                       P3  0383
*  MTT0:                                                                P3  0384
*         BIT 0--15 = FIRST ENTRY ORDINATE FOR LOSER                    P3  0385
*         BIT 16-31 = ILT-FCT ORDINATE FOR LOSER                        P3  0386
*                                                                       P3  0387
*  MTT1:                                                                P3  0388
*         BIT 15-31 = LOSER RECORD'S CORE WORD ADDRESS                  P3  0389
*                                                                       P3  0390
*  MTT2 AND MTT3:                                                       P3  0391
*         SAME AS MTT0 AND MTT1 EXCEPT FOR WINNER                       P3  0392
*                                                                       P3  0393
*                                                                       P3  0394
*  WHEN ALL X-LEVEL COMPARES HAVE BEEN MADE, MVG CONVERTS THE X-LEVEL   P3  0395
*       MTT ENTRIES INTO Y-LEVEL ENTRIES WHICH ARE THE SAME AS THE      P3  0396
*       X-LEVEL ENTRIES EXCEPT THAT ONLY LOSER INFORMATION IS RETAINED. P3  0397
*       THUS MTT0 AND MTT1 ARE UNCHANGED, MTT2 = NEXT ENTRY ORDINATE    P3  0398
*       AND MTT3 IS NOT USED.  THE LAST ENTRY IS SIGNALLED BY A ZERO    P3  0399
*       VALUE IN THE NEXT ENTRY ORDINATE (NEO).                         P3  0400
*                                                                       P3  0401
         PAGE                                                           P3  0402
*                                                                       P3  0403
*                                                                       P3  0404
*  THIS ROUTINE CONTROLS THE COMPARISONS REQUIRED TO SELECT EACH        P3  0405
*       NEW OUTPUT RECORD.  THAT IS, IT PROCESSES THE MTT TABLES.       P3  0406
*                                                                       P3  0407
*  MSR WRITES THE PREVIOUSLY SELECTED RECORD, READS A REPLACEMENT,      P3  0408
*       AND SELECTS THE NEXT OUTPUT RECORD, AFTER WHICH IT REPEATS      P3  0409
*       THE PROCESS UNTIL ALL INPUT STRINGS ARE VACANT.  THE            P3  0410
*       VACANT CONDITION FOR A STRING IS SIGNALLED BY A ZERO RECORD     P3  0411
*       ADDRESS IN THE  MTT1 ENTRY FOR THE STRING.                      P3  0412
*                                                                       P3  0413
         PAGE                                                           P3  0414
*                                                                       P3  0415
MRSR     DATA     0                                                     P3  0416
*                                                                       P3  0417
MRS      STW,X5   MRSR              SAVE RETURN ADDRESS                 P3  0418
         LI,X1    1                                                     P3  0419
         LH,X6    ILT0,X1                                               P3  0420
         LH,X5    CCT0,X1                                               P3  0421
         CI,X5    3                                                     P3  0422
         BE       MRS0                                                  P3  0423
         LW,X5    CRSF              CHECK IF CO-RESIDENT
         BEZ      MRSX              NO. GO TO P3A
         B        MRS1                                                  P3  0424
MRS0     LI,X7    1                                                     P3  0425
         BAL,X5   OS1               OPEN SCRATCH FILE                   P3  0426
MRS1     BAL,X5   *MWRT             GO WRITE PREVIOUS SELECTEE          P3  0427
         BAL,X5   MREAD             GO READ REPLACEMENT                 P3  0428
         LH,X2    BCT0+9            FIRST ENTRY ORDINATE                P3  0429
MRS2     LW,X5    MTT1,X2           PREDICTED LOSER'S ADDRESS           P3  0430
         BE       MRS5              SEE IF MANDATORY SELECT OR END      P3  0431
         LW,X4    BCT0+10                                               P3  0432
         BE       MRS3              MANDATORY EXCHANGE                  P3  0433
         BAL,R1   *MRGSEL           GO COMPARE RECORDS ON SPECIFIED KEYSP3  0434
         BGE      MRS4              NO EXCHANGE                         P3  0435
MRS3     LCI      2                                                     P3  0436
         LM,RA    MTT0,X2           EXCHANGE THE MTT ENTRY              P3  0437
         LM,RC    BCT0+9                AND THE BCT0+9,BCT0+10 ENTRY    P3  0438
         STM,RC   MTT0,X2                                               P3  0439
         STD,RA   BCT0+9                                                P3  0440
MRS4     LW,X2    MTT2,X2                                               P3  0441
         BNE      MRS2              GO TRY NEW PARTNER                  P3  0442
*                                                                       P3  0443
*  AT THIS POINT A RECORD HAS BEEN SELECTED                             P3  0444
*                                                                       P3  0445
         B        MRS1                                                  P3  0446
*                                                                       P3  0447
*  TEST FOR MANDATORY ACCEPT OR END OF STRING FOR ALL STRINGS           P3  0448
*                                                                       P3  0449
MRS5     LW,X4    MTT2,X2           IS THERE ANOTHER COMPARE            P3  0450
         BE       MRS6              NO:  SEE IF MANDATORY WRITE OR END  P3  0451
         B        MRS4                                                  P3  0452
*                                                                       P3  0453
MRS6     LW,X4    BCT0+10           IS THIS THE END OF ALL STRINGS      P3  0454
         BE       *MRSR             YES:  EXIT                          P3  0455
         B        MRS1              NO:  MANDATORY WRITE                P3  0456
*                                                                       P3  0457
*  THIS ROUTINE PERFORMS THE END MERGE BOOKKEEPING TASKS.  IT COUNTS    P3  0458
*       THE STRING JUST WRITTEN AND REDUCES THE COUNTS FOR EACH INPUT   P3  0459
*       UNIT.  IF THE ZERO STRING COUNT IS ZERO AND THE ACTUAL COUNT    P3  0460
*       GOES TO ZERO THIS SIGNALS THE END OF A MERGE SUBPHASE.  AT      P3  0461
*       THE END OF A SUBPHASE, THE ILT0 AND FCT0 ENTRIES FOR THE OUT-   P3  0462
*       PUT TAPE ARE EXCHANGED WITH THOSE FOR THE EMPTY INPUT TAPE      P3  0463
*                                                                       P3  0464
*  EACH TIME THROUGH THIS ROUTINE, THOSE FILES WHICH ENTERED INTO THE   P3  0465
*       MERGE ARE CLOSED WITH A CLOSE STRING.                           P3  0466
         PAGE                                                           P3  0467
*                                                                       P3  0468
MEBR     DATA     0,0                                                   P3  0469
*                                                                       P3  0470
MEB      STW,X5   MEBR              SAVE RETURN ADDRESS                 P3  0471
         LI,X1    1                                                     P3  0472
*                                                                       P3  0476
         LH,X6    ILT0,X1                                               P3  0477
         LI,X7    0                                                     P3  0478
         LH,X5    CCT0,X1                                               P3  0479
         CI,X5    4                 IF FINAL OUTPUT PHASE               P3  0480
         BE       MEB9                  GO CLOSE FINAL OUTPUT FILE      P3  0481
         LD,10    MRGSEL
         XW,10    11
         STD,10   MRGSEL            REV ORDR NXT TIME THRU
         BAL,X5   CSO               GO CLOSE OUTPUT STRING              P3  0482
*                                                                       P3  0483
MEB1     MTW,1    ILT0,X6           COUNT STRING JUST WRITTEN           P3  0484
*                                                                       P3  0485
MEB2     BDR,X6   MEB3                                                  P3  0486
         B        MEB6                                                  P3  0487
*                                                                       P3  0488
MEB3     LW,X4    ILT0,X6                                               P3  0489
         MTH,15   X4                REDUCE ZERO STRING COUNT            P3  0490
         BGE      MEB4              NOT NEGATIVE                        P3  0491
         AI,X4    X'10000'          NEGATIVE:  ADD 1 BACK               P3  0492
*                                                                       P3  0493
MEB4     MTH,15   X4,X1             REDUCE TOTAL STRING COUNT           P3  0494
         BGE      MEB5              NOT NEGATIVE                        P3  0495
         MTH,1    X4,X1             NEGATIVE ADD 1 BACK                 P3  0496
*                                                                       P3  0497
MEB5     STW,X4   ILT0,X6           SET UPDATED COUNT BACK INTO ILT0    P3  0498
         B        MEB2              GO UPDATE NEXT ENTRY                P3  0499
*                                                                       P3  0500
*  ALL STRING COUNTS HAVE BEEN UPDATED.  CHECK FOR END OF PHASE.        P3  0501
*                                                                       P3  0502
MEB6     LH,X6    ILT0,X1                                               P3  0503
MEB7     BDR,X6   MEB8                                                  P3  0504
         B        *MEBR                                                 P3  0505
*                                                                       P3  0506
MEB8     LW,X5    ILT0,X6           ARE THERE STRINGS ON THIS UNIT      P3  0507
         BNE      MEB7              YES:  GO EXAMINE MORE               P3  0508
*                                                                       P3  0509
         LH,X5    ILT1,X6                                               P3  0510
         BE       MEB84                                                 P3  0511
         SLS,X5   16                                                    P3  0512
         STW,X5   ILT0,X6                                               P3  0513
         LI,X5    0                                                     P3  0514
         STH,X5   ILT1,X6                                               P3  0515
         B        MEB7                                                  P3  0516
*                                                                       P3  0517
MEB84    STH,X6   ILT0                                                  P3  0518
         LH,X6    ILT0,X1                                               P3  0519
         LH,X7    CCT0,X1                                               P3  0520
         CI,X7    4                                                     P3  0521
         BE       MEB9-1                                                P3  0522
         LI,X7    1                                                     P3  0523
         BAL,X5   CSO               GO CLOSE OUTPUT FILE AS A FILE      P3  0524
*                                                                       P3  0525
         LH,X5    ILT0              EXCHANGE ILT0-FCT0 ENTRIES          P3  0526
         LW,RA    ILT0,X6               TO ACHIEVE A NEW INPUT          P3  0527
         XW,RA    ILT0,X5               AND A NEW OUTPUT UNIT           P3  0528
         STW,RA   ILT0,X6                                               P3  0529
*        LINE 623,624,625          REMOVED FOR UTS                      P3  0530
         LW,RA    FCT0,X6                                               P3  0531
         XW,RA    FCT0,X5                                               P3  0532
         STW,RA   FCT0,X6                                               P3  0533
         LH,RA    ILT1,X6                                               P3  0534
         STH,RA   ILT1,X5                                               P3  0535
         LI,RA    0                                                     P3  0536
         STH,RA   ILT1,X6                                               P3  0537
*                                                                       P3  0538
         B        *MEBR                                                 P3  0539
*                                                                       P3  0540
MEB9     RES      0                                                     P3  0541
         LW,X5    CRSF              CHECK IF CO-RESIDENT
         BEZ      MEB9X             NO. GO TO P3A
MEB10    LI,7      0              INDICATE END OF OUTPUT                P3  0542
         STW,6    MEBR+1                                                P3  0543
         BAL,11    S:OUTPUT                                             P3  0544
         LW,6     MEBR+1                                                P3  0545
         LI,1     1                                                     P3  0546
         B         MEB1                                                 P3  0547
*                                                                       P3  0548
TPCPYR   DATA     0                                                     P3  0549
*                                                                       P3  0550
TPCPY    STW,X5   TPCPYR            SAVE RETURN ADDRESS                 P3  0551
TPCP0    LI,X3    X'F0000'          LEFT HALF WORD MASK                 P3  0552
         LH,X6    ILT0,X1                                               P3  0553
         BDR,X6   %+1                                                   P3  0554
         LI,X2    0                                                     P3  0555
TPCP1    CS,X2    ILT0,X6                                               P3  0556
         BE       TPCP2             ONE FILE WITH NO DUMMY STRINGS      P3  0557
         BDR,X6   TPCP1                                                 P3  0558
TPCP2    LI,X3    X'FFFF'                                               P3  0559
         CS,X2    ILT0,X6                                               P3  0560
         BNE      TPCP3             NO DUMMY STRINGS AND HAS REAL ONES  P3  0561
         LI,X3    X'F0000'                                              P3  0562
         BDR,X6   TPCP1-1           NO STRINGS AT ALL                   P3  0563
*                                                                       P3  0564
TPCP3    LI,X3    X'F0000'                                              P3  0565
         STW,X6   BCT0+9                                                P3  0566
         B        TPCP6                                                 P3  0567
*                                                                       P3  0568
TPCP5    CS,X2    ILT0,X6                                               P3  0569
         BE       *TPCPYR                                               P3  0570
TPCP6    BDR,X6   TPCP5                                                 P3  0571
*                             COPY THE STRING                           P3  0572
         LI,X7    0                                                     P3  0573
         LW,X6    BCT0+9                                                P3  0574
         BAL,X5   OS1               GO OPEN INPUT                       P3  0575
         LH,X6    ILT0,X1                                               P3  0576
         LI,X7    1                                                     P3  0577
         BAL,X5   OS1               GO OPEN OUTPUT                      P3  0578
TPCP7    BAL,X5   MREAD             GO READ A RECORD                    P3  0579
         CI,X7    0                                                     P3  0580
         BE       TPCP8             END OF STRING                       P3  0581
         BAL,X5   *MWRT             GO WRITE THE RECORD                 P3  0582
         B        TPCP7                                                 P3  0583
*                                                                       P3  0584
TPCP8    MTW,1    MVGR                                                  P3  0585
         B        *MVGR                                                 P3  0586
*                                                                       P3  0587
         PAGE                                                           P3  0588
*                                                                       P3  0589
MWRT     DATA     0                                                     P3  0590
MWRITER  DATA     0                                                     P3  0591
*                                                                       P3  0592
MWRITE   STW,X5   MWRITER           SAVE RETURN ADDRESS                 P3  0593
         LH,X6    ILT0,X1           FCT ORDINATE FOR OUTPUT FILE        P3  0594
         LW,X7    BCT0+10           RECORDS'S ADDRESS                   P3  0595
         LH,R0    *BCT0+10,X1       REOCRD'S LENGTH                     P3  0596
         SLS,X7   2                 CONVERT WORD TO BYTE ADDRESSING     P3  0597
         LW,X5    CRSF              CHECK IF CO-RESIDENT
         BEZ      MWRTX             NO. GO TO P3A
         BAL,5    BFVB1                                                 P3  0598
         B        *MWRITER                                              P3  0599
*                                                                       P3  0600
MFPWTR   DATA     0                                                     P3  0601
*                                                                       P3  0602
MFPWT    STW,X5   MFPWTR            SAVE RETURN ADDRESS                 P3  0603
MOWR1    B        %+1
MSWR1    B        %+1
         LH,X6    ILT0,X1           FCT ORDINATE                        P3  0604
         LW,X7    BCT0+10           RECORD ADDRESS                      P3  0605
         LH,R0    *BCT0+10,X1       RECORD LENGTH                       P3  0606
         SLS,R0   -2                                                    P3  0607
         AI,R0    -1                                                    P3  0608
         AW,R0    X7                                                    P3  0609
         LH,R0    *R0                                                   P3  0610
         SLS,X7   2                 CONVERT WORD TO BYTE ADDRESSING     P3  0611
         AI,7     8                 STRIR RCW AND LOW KEY  /SIG7-2254/*DP3  0612
         MTW,0    OUTLENSW          DOES USER WANT OUT LEN
         BEZ      MSWR2             NO USE INPUT
         STW,8    11                SAVE INPUT LENGTH
         LH,8     BCT0+4,1          OUT LEN IN WORDS
         SLS,8    2                 TO BYTES
         AH,8     BCT0+15,1         ADD BYTE INCR
         CW,8     11                IS OUT LARGER THAN IN
         BLE      %+2               NO
         MTW,1    MEMPROSW          POSSIBLE MEM PRO IF LAST REC IN MEM
MSWR2    RES      0
*                                      INPUT ORDER         /SIG7-2254/*DP3  0613
         LW,11    CRSF              CHECK IF CO-RESIDENT
         BEZ      MSWR1X            NO. GO TO P3A
         BAL,11   S:OUTPUT                                              P3  0614
         LI,1     1                                                     P3  0615
         MTW,1    BCT0+7                                                P3  0616
         CI,7     0                                                     P3  0617
         BE       MCR3                                                  P3  0618
MFPWT1   B        *MFPWTR                                               P3  0619
*                                                                       P3  0620
MREADR   DATA     0                                                     P3  0621
*                                                                       P3  0622
MREAD    STW,X5   MREADR            SAVE RETURN ADDRESS                 P3  0623
         LI,X6    X'FF'                                                 P3  0624
         AND,X6   BCT0+9                                                P3  0625
         LI,X7    0                                                     P3  0626
         LW,X5    CRSF              CHECK IF CO-RESIDENT
         BEZ      MREADX            NO. GO TO P3A
         BAL,5     BVDR1                                                P3  0627
MREAD0   RES      0                 RETURN FROM P3A
         SLS,X7   -2                                                    P3  0628
         STW,X7   BCT0+10                                               P3  0629
         LW,X5    FCT0,X6                                               P3  0630
         BGE      MREAD1                                                P3  0631
         B        *MREADR                                               P3  0632
MREAD1   LI,X7    0                                                     P3  0633
         STW,X7   BCT0+10                                               P3  0634
         B        *MREADR                                               P3  0635
*                                                                       P3  0636
         PAGE                                                           P3  0637
*                                                                       P3  0638
OPCLSR   DATA     0                                                     P3  0639
*                                                                       P3  0640
OPCLS    STW,X5   OPCLSR            SAVE RETURN ADDRESS                 P3  0641
         LI,X7    4                                                     P3  0642
         STH,X7   CCT0,X1           SET TO FINAL MERGE                  P3  0643
         LW,X7    CRSF              CHECK IF CO-RESIDENT
         BEZ      OPCLSX            NO. GO TO P3A
         LI,7     0                                                     P3  0644
         BAL,11   S:OUTPUT                                              P3  0645
ENDP3    RES      0
         B        *OPCLSR                                               P3  0646
*                                                                       P3  0647
         PAGE                                                           P3  0648
*                                                                       P3  0649
         END                                                            P3  0650

