HASSLE STAT PACK FORTRAN IV-KSORT Lars Palmer AB HASSLE Fack 431 20 Molndal 1 Sweden HASSLE STAT PACK F IV - Ksort A major revision of KSORT was done in October 74. Functions of KSORT. KSORT will do the following: 1)Rearrange the material in an OUTLAY file to allow for the comparisons in Stat of e.g. column 1 group 1 against column 1 group 2. 2)Convert material in a given column to e.g. roots. 3)Sort the file according to any given column. 4)When interfaced with a user written subroutine splitting or combining groups or excluding certain data according to (more or less) any criteria. A)INDATA AND FILE UNIT NUMBERS UNIT CONTAINS 6 INDATA FILE OUTLAY FORMAT 5 PARAMETER FILE SEE B) 3 SUMMARY OF THE NEW FILE 7 THE OUTPUT FILE AS REQUESTED 0 ERROR MESSAGES B)THE PARAMETER FILE The parameter file (unit 5) has the following format: CARD NO CONTAINS: 1 NG,NK,FILL,SORT,EXTERN,LIST,MISS. Written in integer format separated by commas. NG No of groups in new file can be in the forms: >0 Used as stated. NG subheadings must follow. =0 Use the number of groups and headings in unit 6. <0 Use absolute (NG) groups, generate headings in the program. NK Number of columns in new file. If NG is set to 0 or < 0, NK can be set to 0 in which case columns are taken from unit 6. FILL If set to non-zero, any group-col not specifically requested by parameter cards is to be copied over from input. If set to zero, such columns will be set to "Missing". FIV-KSORT-PAGE 1 HASSLE STAT PACK F IV - Ksort CRD NO CONTAINS SORT If >0, the material is sorted according to col "Sort". N.B. under Extern. EXTERN If set to non-zero, EXTERN is to be called. See this. LIST If set to non-zero, the effects of the operations of KSORT are summarized on the printer (unit 3). See also under Extern. MISS If non-zero, any row with a missing observation is deleted. 2 Main heading new file. 3 TO NK+3 One heading for each group in new file. Headings are conditional on the value of NG. Heading cards must not be included if NG is set to 0 or <0. NK+4 TO L-1 Request for make-up of new file. See below. L Last card must be blank. FIV-KSORT-PAGE 2 HASSLE STAT PACK F IV - Ksort Request cards are made up as follows: POSITION NR CONTAINS 1 NEW GROUP NR ** 2 NEW COL NR ** 3 OLD GROUP NR 4 OLD COL NR 5 CODE & 6 OLD COL 2 & 7 CONSTANT & i.e. 1,3,2,4,6,3,1.2 is: use old group 2 cols 4 & 3 combining by operation code 6 and constant 1.2 & See XFUNC below. ** Either or both of the new group number and new col number can be replaced by -1. This leads to the corresponding information being matched by all in the input file. The corresponding "New" is ignored and can be set to 0. C)XFUNC The subroutine XFUNC is called for every data with code <>0. It implements the conversions detailed in the source code for the subroutine. See appendix 1. D)EXTERN The subroutine EXTERN must be added by the user if EXTERN is non-zero. It is called just before writing the row to the output file. It can be used to implement any kind of logic not possible by XFUNC. SUBROUTINE EXTERN (NG,X,NKO,SW,TWICE,COUNT,SKIP) LOGICAL SW,TWICE,SKIP INTEGER COUNT DIMENSION X(1) FIV-KSORT-PAGE 3 HASSLE STAT PACK F IV - Ksort The parameters are: NG Current group number. X The vector of X-values to be output. NKO Number of values in X **Must not be changed** SW Set to false if the data is not to be written. TWICE Set to true if the subroutine wants to be re-called for this data e.g. if it is to be duplicated. COUNT Is a counter of the number of times the routine has been called for this data. SKIP If set to true inhibits further calls to Extern in this data group. N.B. If the routine changes the size of NG, it is impossible to do a sort. In this case also the summary produced by the list request is in error. For these reasons sort and list are negated if NG is changed. If NKO is changed the program stops. See appendix 2 for an example of the usage of the routine. E)RUNNING THE PROGRAM KSORT is available as loader image and run by: EX KSORT.LD *PARAMETERFILE/5 *LPT:/3 Optional if lineprinter is available (only used if list is true). *OLDDATA/6 *NEWDATA100 STOP SPECIFICATION ERROR COL>10 STOP SPECIFICATION ERROR GROUP OR COL REQUESTED OUT OF RANGE IGNORED NO TOTAL DATA IN GROUP>1000 GROUP IGNORED YES SORT<0 OR SORT>NK STOP SPECIFICATION ERROR NK CHANGED BY EXTERN STOP NO NG CHANGED BY EXTERN: LIST DISABLED IF REQUESTED YES SORT DISABLED IF REQUESTED YES FIV-KSORT-PAGE 5 HASSLE STAT PACK F IV - Ksort Appendix 1 Examples A)Use old groups and generate 2 columns (4 & 5): Col 4 = The difference between col 1 and 2. Col 5 = The difference between col 1 and 3. This is to be done for all groups: 0,5,1,0,0,1 -1,4,0,1,1,2,-1 /col 4=col 1+col 2*-1 -1,5,0,1,1,3,-1 00 B)Sort each group in a file according to col 3. 0,0,1,3 000 FIV-KSORT-PAGE 6 HASSLE STAT PACK F IV - Ksort Appendix 2 Having a data file with 8 groups and 3 col we want to: A)Make a group 9 = groups 1+2+3. B)Make a group 10 = all with COL 1=col 2. C)Unconditionally exclude all rows with any data >160. D)For the so generated data: COL 4=LOG COL 2 COL 5=SQRT(COL 3) and the data finally sorted according to COL 1. This is done in 2 passes: A)Load KSORT,XFUNC and the following subroutine: FUNCTION EXTERN(NG,X,NKO,SW,TWICE,N,SKIP) LOGICAL SW,TWICE DIMENSION X(1) GOTO(10,20,30),N 10 SW=.FALSE. IF(AMAX1(X(1),X(2),X(3)).GT.160)RETURN SW=.TRUE. TWICE=.TRUE. RETURN 20 IF(NG.GT.3)GOTO 30 NG=9 TWICE=.TRUE. RETURN 30 NG=10 IF(X(1).NE.X(2))SW=.FALSE. RETURN END B) This is then run with the unit 5 file: -10,0,1,0,1 /10 COL AUTO HEADINGS FILL OUT. NO SORT. /CALL EXTERN TEST /MAIN HEADING 0000 /END TEST A C)The so produced file is then run with the following unit 5 file: 0,5,1,1,0,1 /HEADINGS & NG FROM UNIT 6. 5 COL. /FILL OUT. SORT ACC COL 1. NO EXTERN .LIST. TEST B /MAIN HEADING -1,4,0,2,7 /ALL GROUPS COL 4 FROM COL 2 CODE 7=LN -1,5,0,3,9,,0.5 /ALL GROUPS COL 5 FROM COL 3 CODE 9 /CONST:0.5 CODE:9 X=X**CONST 000 This gives the desired result. FIV-KSORT-PAGE 7 HASSLE STAT PACK F IV - Ksort Appendix 3 Listing of XFUNC follows: OS/8 FORTRAN IV 3.02 OCT 18 1974 C XFUNC C 73-10-24 0002 SUBROUTINE XFUNC (X,XIN,IARG,K) C TO IMPLEMENT THE CONVERSION CODES LISTED C CODE RESULTS IN C 0 NO CHANGE C 1 X=Y+K*Z C 2 =0 C 3 X=Y*Z**K C 4 =0 C 5 X=Y/Z*100 C 6 X=((Y-Z)/Z)*100 C 7 X=LN(Y) C 8 X=LOG(Y) C 9 X=Y**K C 10 X=Y*K C 11 X=Y+K C 12 =0 C 13 =0 C 14 =0 C 15 =0 C C ANY CODE OUTSIDE 1-15 IS TAKEN AS 0 0003 DIMENSION XIN(1),IARG(1) 0004 REAL K 0005 COMMON NKO 0006 DIMENSION ITYPE(15) 0007 DATA ITYPE/4,0,4,0,2*2,1,1,3*3,4*0/ C ITYPE CONTAINS: C A 0 IF CODE IS UNDEFINED DEFAULTS TO 0 C A 1 IF CODE IS A FUNCTION OF X C A 2 IF CODE IS A FUNCTION OF Y Z C A 3 IF CODE IS A FUNCTION OF Y K C A 4 IF CODE IS A FUNCTION OF Y,Z,K 0010 IY=IARG(2) 0011 IP=IARG(3) 0012 IF(IP.LE.0.OR.IP.GT.15)GOTO 300 0013 IT=ITYPE(IP) 0014 Y=XIN(IY) 0015 IF(IT.EQ.0.OR.Y.EQ.0)GOTO 300 0016 IF(IT.EQ.1.OR.IT.EQ.3)GOTO 100 0017 IZ=IARG(4) 0020 IF(IZ.GT.NKO.OR.IZ.LE.0)GOTO 300 0021 Z=XIN(IZ) 0022 IF(Z.EQ.0)GOTO 310 0023 100 CONTINUE 0024 GOTO(1,300,3,300,5,6,7,8,9,10,11, 300,300,300,300),IP 0025 1 X=Y+K*Z 0026 GOTO 200 FIV-KSORT-PAGE 8 HASSLE STAT PACK F IV - Ksort 0027 3 X=Y*Z**K 0030 GOTO 200 0031 5 X=Y/Z*100. 0032 GOTO 200 0033 6 X=((Y-Z)/Z)*100. 0034 GOTO 200 0035 7 IF(Y.LT.0)GOTO 300 0036 X=ALOG(Y) 0037 GOTO 300 0040 8 IF(X.LT.0)GOTO 300 0041 X=ALOG10(Y) 0042 GOTO 300 0043 9 X=Y**K 0044 GOTO 300 0045 10 X=Y*K 0046 GOTO 300 0047 11 X=Y+K 0050 GOTO 200 0051 200 IF(X.EQ.0)X=1.E-25 0052 300 RETURN 0053 310 X=0 0054 END FIV-KSORT-PAGE 9