1C THIS FILE CONTAINS THE FOLLOWING: 2C 3C 1. DPFIT - DRIVER FOR FIT COMMAND 4C 5C DPFIT2 - NON-LINEAR FIT 6C DPFIT3 - LINEAR FIT (ROUTINES FROM OMNITAB) 7C LSQRT 8C LSQ 9C SCALDP 10C PDECOM 11C SLVE 12C DSUMAL 13C SDPRED 14C PINVRT 15C DPDIV 16C SPDIV 17C DPCON 18C DPSQRT 19C SPSQRT 20C SPLO10 21C IDIV 22C 23C 2. BACK - BEST SUBSETS FOR LINEAR FITS (ROUTINES FROM OMNITAB) 24C CODEXY 25C COEF 26C CPSTRE 27C CRSPRD 28C FDDIV 29C FDIV 30C FDPCON 31C FDSQRT 32C FLOG10 33C PIVOT 34C RFORMT 35C SCREEN 36C 37C 3. ACM591 - ANOVA ROUTINES FROM ACM 591. NOTE THAT THESE 38C DECOMP ARE NOT CURRENTLY IMPLEMENTED BY DATAPLOT'S 39C SCAN ANOVA COMMAND. INCLUDED FOR FUTURE IMPLEMENTATION. 40C STEP 41C PART1 42C PART2 43C POOL 44C IGET 45C LABEL 46C 47C 4. SNSQE - NON-LINEAR EQUATIONS, SINGLE PRECISION (FROM CMLIB) 48C SNSQ 49C FDJAC1 50C QRFAC 51C QFORM 52C DOGLEG 53C R1UPDT 54C R1MPYQ 55C 56C 5. DNSQE - NON-LINEAR EQUATIONS, DOUBLE PRECISION (FROM CMLIB) 57C DNSQ 58C DFDJC1 59C DQRFAC 60C DENORM 61C DQFORM 62C DDOGLG 63C D1UPDT 64C D1MPYQ 65C 66 SUBROUTINE DPFIT(ICAPSW,IFORSW, 67 1 IBUGA2,IBUGA3,IBUGCO,IBUGEV,IBUGQ,ISUBRO, 68 1 IFOUND,IERROR) 69C 70C PURPOSE--CARRY OUT A LEAST SQUARES FIT 71C FOR LINEAR AND NON-LINEAR MODELS. 72C WRITTEN BY--JAMES J. FILLIBEN 73C STATISTICAL ENGINEERING DIVISION 74C CENTER FOR APPLIED MATHEMATICS 75C NATIONAL BUREAU OF STANDARDS 76C WASHINGTON, D. C. 20234 77C PHONE--301-975-2855 78C NOTE--DATAPLOT IS A REGISTERED TRADEMARK 79C OF THE NATIONAL BUREAU OF STANDARDS. 80C LANGUAGE--ANSI FORTRAN (1977) 81C VERSION NUMBER--88/2 82C ORIGINAL VERSION--FEBRUARY 1988. 83C UPDATED --FEBRUARY 1988. (SIMPLIFY THE CALL TO DPFIT3) 84C UPDATED --MARCH 1988. (ALLOW B0 IN MULTILINEAR FIT) 85C UPDATED --MARCH 1988. ADD LOFCDF 86C UPDATED --MAY 1989. ALLOW OMNITAB FIT BEYOND 5 VAR. 87C UPDATED --MAY 1989. ADDED ISUBRO IN CALL TO DPFIT3 88C UPDATED --MAY 1989. AUTO COEF--A11, A12, A13, ... 89C UPDATED --AUGUST 1989. NUMPAR FIXED FOR POLY FIT 90C UPDATED --JUNE 1990. TEMPORARY ARRAYS TO GARBAGE COMMON 91C ALSO, MOVE SOME DIMENSIONS FROM DPFIT2 92C AND DPFIT3 TO DPFIT 93C UPDATED --JUNE 1991. REPLICATION BUG FOR POLY FIT 94C UPDATED --SEPT 1991. EXPAND IND. VAR. 5 TO 15 95C UPDATED --MARCH 1992. FIX INSTAB. MESSAGE (WEIGHTS) 96C UPDATED --MARCH 1992. ISUBRO ADDED TO DPFIT2 ARG LIST 97C UPDATED --MAY 1995. FIX SOME I/O 98C UPDATED --MAY 1995. ADDITIONAL EQUIVALENCE 99C UPDATED --APRIL 2002. OPTION TO OMIT CONSTANT TERM 100C FOR MULTILINEAR FIT 101C UPDATED --JULY 2003. MODIFY STORAGE FOR LINEAR FIT 102C SO THAT > MAXCMF DEPENDENT 103C VARIABLES CAN BE USED (I.E., 104C ADD VARIABLES AT EXPENSE OF 105C FEWER ROWS) 106C UPDATED --NOVEMBER 2003. CAPTURE HTML AND LATEX FORMATS 107C UPDATED --MAY 2009. WITH THE INCREASED DATA SET 108C SIZE ALLOWED, THE DPSWAP ROUTINE 109C WAS BECOMING A SERIOUS BOTTLE 110C NECK IN SOME CASES. USE 111C DPCOZD.INC IN PLACE OF DPSWAP 112C UPDATED --NOVEMBER 2016. SET FIT ADDITIVE CONSTANT FOR 113C POLYNOMIAL FITS 114C UPDATED --JULY 2019. TWEAK SCRATCH SPACE 115C UPDATED --JULY 2019. FOR DPFIT3, USE XMAT INSTEAD OF 116C X1 ... X15 TO REDUCE MEMORY 117C REQUIREMENTS 118C 119C-----CHARACTER STATEMENTS FOR NON-COMMON VARIABLES------------------- 120C 121 CHARACTER*4 ICAPSW 122 CHARACTER*4 IFORSW 123 CHARACTER*4 IBUGA2 124 CHARACTER*4 IBUGA3 125 CHARACTER*4 IBUGCO 126 CHARACTER*4 IBUGEV 127 CHARACTER*4 IBUGQ 128 CHARACTER*4 ISUBRO 129 CHARACTER*4 IFOUND 130 CHARACTER*4 IERROR 131C 132 CHARACTER*4 ICASFI 133 CHARACTER*4 IH 134 CHARACTER*4 IH2 135 CHARACTER*4 ICASEQ 136 CHARACTER*4 IKEY 137 CHARACTER*4 IWD 138 CHARACTER*4 IWD1 139 CHARACTER*4 IWD2 140 CHARACTER*4 IWD12 141 CHARACTER*4 IWD22 142 CHARACTER*4 IHPARN 143 CHARACTER*4 IHPAR2 144 CHARACTER*4 IPAROC 145 CHARACTER*4 IPARO3 146 CHARACTER*4 ICH 147 CHARACTER*4 IOP 148 CHARACTER*4 ITYPEH 149 CHARACTER*4 IW2HOL 150 CHARACTER*4 IW22HO 151 CHARACTER*4 IPARN 152 CHARACTER*4 IPARN2 153 CHARACTER*4 IPARN3 154 CHARACTER*4 IPARN4 155 CHARACTER*4 IVARN3 156 CHARACTER*4 IVARN4 157 CHARACTER*4 IREPU 158 CHARACTER*4 IRESU 159 CHARACTER*4 IHWUSE 160 CHARACTER*4 MESSAG 161 CHARACTER*4 IHLEFT 162 CHARACTER*4 IHLEF2 163 CHARACTER*4 IREP 164C 165CCCCC THE FOLLOWING 5 LINES WERE ADDED MAY 1989 166 CHARACTER*4 IHOUT 167 CHARACTER*4 IVALID 168 CHARACTER*4 IHOUT1 169 CHARACTER*4 IHOUT2 170 CHARACTER*4 IHOUT3 171C 172CCCCC THE FOLLOWING 2 LINES WERE ADDED MAY 1989 173 CHARACTER*4 IVARN1 174 CHARACTER*4 IVARN2 175C 176 CHARACTER*4 IHP 177 CHARACTER*4 IHP2 178 CHARACTER*4 ISUBN1 179 CHARACTER*4 ISUBN2 180 CHARACTER*4 ISTEPN 181 CHARACTER*4 ISUBN0 182C 183C--------------------------------------------------------------------- 184C 185CCCCC JULY 2003: MAKE MAXIMUM NUMBER OF PARAMETERS SETTABLE VIA 186CCCCC SINGLE PARAMETER STATEMENT. 187C 188 PARAMETER(MAXPAR=300) 189C 190 INCLUDE 'DPCOPA.INC' 191 INCLUDE 'DPCODA.INC' 192 INCLUDE 'DPCOZZ.INC' 193 INCLUDE 'DPCOZD.INC' 194 INCLUDE 'DPCOHO.INC' 195 INCLUDE 'DPCOMC.INC' 196 INCLUDE 'DPCOHK.INC' 197 INCLUDE 'DPCOSU.INC' 198 INCLUDE 'DPCOST.INC' 199C 200 DIMENSION IPAROC(MAXPAR) 201C 202 DIMENSION ITYPEH(1000) 203 DIMENSION IW2HOL(1000) 204 DIMENSION IW22HO(1000) 205 DIMENSION W2HOLD(1000) 206C 207 DIMENSION PARAM(MAXPAR) 208 DIMENSION IPARN(MAXPAR) 209 DIMENSION IPARN2(MAXPAR) 210 DIMENSION PARCOV(MAXPAR+1,MAXPAR+1) 211 DIMENSION PARAM3(MAXPAR) 212 DIMENSION IPARN3(MAXPAR) 213 DIMENSION IPARN4(MAXPAR) 214 DIMENSION ICON3(MAXPAR) 215 DIMENSION IPARO3(MAXPAR) 216 DIMENSION PARLI3(MAXPAR) 217 DIMENSION IVARN3(MAXPAR) 218 DIMENSION IVARN4(MAXPAR) 219 DIMENSION ICOLV3(MAXPAR) 220 DIMENSION NIV(MAXPAR) 221 DIMENSION IVARN1(MAXPAR) 222 DIMENSION IVARN2(MAXPAR) 223C 224 DIMENSION ICH(10) 225 DIMENSION IHOUT(10) 226C 227 DIMENSION W(MAXOBV) 228 DIMENSION VSDPRD(MAXOBV) 229 DIMENSION PRED2(MAXOBV) 230 DIMENSION RES2(MAXOBV) 231 DIMENSION DUMMY1(MAXOBV) 232 DIMENSION DUMMY2(MAXOBV) 233 DIMENSION DUMMY3(MAXOBV) 234 DIMENSION DUMMY4(MAXOBV) 235 DIMENSION DUMMY5(MAXOBV) 236 DIMENSION VSCRT(10*MAXOBV) 237 DIMENSION XMAT(MAXOBV*MAXCMF) 238C 239C-----COMMON---------------------------------------------------------- 240C 241C 242C-----COMMON VARIABLES (GENERAL)-------------------------------------- 243C 244 EQUIVALENCE (W(1),D(1)) 245 EQUIVALENCE (VSDPRD(1),D(MAXOBV+1)) 246 EQUIVALENCE (PRED2(1),DSIZE(1)) 247 EQUIVALENCE (RES2(1),DSIZE(MAXOBV+1)) 248 EQUIVALENCE (DUMMY1(1),DSYMB(1)) 249 EQUIVALENCE (DUMMY2(1),DSYMB(MAXOBV+1)) 250 EQUIVALENCE (DUMMY3(1),DCOLOR(1)) 251 EQUIVALENCE (DUMMY4(1),DCOLOR(MAXOBV+1)) 252 EQUIVALENCE (DUMMY5(1),DFILL(1)) 253 EQUIVALENCE (PARCOV(1,1),DFILL(MAXOBV+1)) 254 EQUIVALENCE (GARBAG(IGARB1),XMAT(1)) 255 EQUIVALENCE (DGARBG(IDGAR1),VSCRT(1)) 256C 257C--------------------------------------------------------------------- 258C 259 INCLUDE 'DPCOP2.INC' 260C 261C-----START POINT----------------------------------------------------- 262C 263 ISUBN1='DPFI' 264 ISUBN2='T ' 265 IERROR='NO' 266C 267 MAXCP1=MAXCOL+1 268 MAXCP2=MAXCOL+2 269 MAXCP3=MAXCOL+3 270 MAXCP4=MAXCOL+4 271 MAXCP5=MAXCOL+5 272 MAXCP6=MAXCOL+6 273C 274 IPAROC(1)='NONE' 275 MAXV2=15 276 MINN2=2 277 MAXITS=IFITIT 278 CPUEPS=R1MACH(3) 279 MAXN2=MAXCHF 280 MAXN3=MAXCHF 281 MAXN4=MAXCHF 282 NUMPV=(-999) 283 IP=(-999) 284 IV=(-999) 285 IWIDMO=(-999) 286 NUMIND=(-999) 287 ICUTMX=NUMBPW 288 IF(IHOST1.EQ.'CDC '.OR.IHOST1.EQ.'CYBE')ICUTMX=48 289 IF(IHOST1.EQ.'205 ')ICUTMX=48 290 CUTOFF=2**(ICUTMX-3) 291 IVAL=0 292 IDEGRE=0 293 K1=0 294C 295C ************************** 296C ** TREAT THE FIT CASE ** 297C ************************** 298C 299 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT')THEN 300 WRITE(ICOUT,999) 301 999 FORMAT(1X) 302 CALL DPWRST('XXX','BUG ') 303 WRITE(ICOUT,51) 304 51 FORMAT('***** AT THE BEGINNING OF DPFIT--') 305 CALL DPWRST('XXX','BUG ') 306 WRITE(ICOUT,53)IFITAC,IBUGA2,IBUGA3,NUMNAM 307 53 FORMAT('IFITAC,IBUGA2,IBUGA3,NUMNAM = ',3(A4,2X),I8) 308 CALL DPWRST('XXX','BUG ') 309 WRITE(ICOUT,54)IBUGCO,IBUGEV,IBUGQ 310 54 FORMAT('IBUGCO,IBUGEV,IBUGQ = ',2(A4,2X),A4) 311 CALL DPWRST('XXX','BUG ') 312 DO57I=1,NUMNAM 313 WRITE(ICOUT,58)I,IHNAME(I),IHNAM2(I),IUSE(I),IN(I),IVALUE(I), 314 1 VALUE(I) 315 58 FORMAT('I,IHNAME(I),IHNAM2(I),IUSE(I),IN(I),IVALUE(I)', 316 1 'VALUE(I) = ',I8,2X,2A4,2X,A4,2I8,G15.7) 317 CALL DPWRST('XXX','BUG ') 318 57 CONTINUE 319 ENDIF 320C 321C *************************** 322C ** STEP 1-- ** 323C ** EXTRACT THE COMMAND ** 324C *************************** 325C 326 ISTEPN='1' 327 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 328 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 329C 330 CALL CKFIT(ICASFI,ILOCFI,IBUGA3,IFOUND,IERROR) 331 IF(ICASFI.EQ.' '.OR.IFOUND.EQ.'NO')GOTO9000 332C 333C ******************************************************* 334C ** STEP 2-- ** 335C ** CHECK FOR THE PROPER NUMBER OF INPUT ARGUMENTS. ** 336C ******************************************************* 337C 338 ISTEPN='2' 339 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 340 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 341C 342 MINNA=0 343 MAXNA=100 344 CALL CHECKA(NUMARG,MINNA,MAXNA,IANS,IWIDTH,ISUBN1,ISUBN2, 345 1 IERROR) 346 IF(IERROR.EQ.'YES')GOTO9000 347C 348C ****************************************************** 349C ** STEP 3-- * 350C ** FOR THE CASES WHEN HAVE FIT Y = SOME EXPRESSION * 351C ** ROBUST FIT Y = SOME EXPRESSION, * 352C ** DETERMINE IF WE HAVE A VALID FUNCTIONAL * 353C ** EXPRESSION--IN PARTICULAR, CHECK THAT THE NUMBER * 354C ** OF ARGUMENTS IS AT LEAST 1, AND ALSO CHECK THAT * 355C ** THERE IS EXACTLY 1 EQUAL SIGN AND THAT THIS * 356C ** EQUAL SIGN OCCURS AS THE SECOND ARGUMENT. * 357C ****************************************************** 358C 359 ISTEPN='3' 360 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 361 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 362C 363 IF(NUMARG.LT.1)THEN 364 WRITE(ICOUT,2001) 365 2001 FORMAT('***** ERROR IN DPFIT--') 366 CALL DPWRST('XXX','BUG ') 367 WRITE(ICOUT,2002) 368 2002 FORMAT(' NUMBER OF ARGUMENTS DETECTED = 0. NUMARG = ',I6) 369 CALL DPWRST('XXX','BUG ') 370 WRITE(ICOUT,2007) 371 2007 FORMAT(' THE ENTERED COMMAND LINE WAS AS FOLLOWS--') 372 CALL DPWRST('XXX','BUG ') 373 IF(IWIDTH.GE.1)THEN 374 WRITE(ICOUT,2008)(IANS(J),J=1,MIN(100,IWIDTH)) 375 2008 FORMAT(' COMMAND LINE--',100A1) 376 CALL DPWRST('XXX','BUG ') 377 ENDIF 378 IERROR='YES' 379 GOTO9000 380 ENDIF 381C 382 DO2100J=1,NUMARG 383 J1=J 384 IF(IHARG(J).EQ.'SUBS'.AND.IHARG2(J).EQ.'ET ')GOTO2110 385 IF(IHARG(J).EQ.'EXCE'.AND.IHARG2(J).EQ.'PT ')GOTO2110 386 IF(IHARG(J).EQ.'FOR '.AND.IHARG2(J).EQ.' ')GOTO2110 387 2100 CONTINUE 388 ILOCQ=NUMARG+1 389 GOTO2120 390 2110 CONTINUE 391 ILOCQ=J1 392 GOTO2120 393 2120 CONTINUE 394C 395 IF(ICASFI.EQ.'FIT' .OR. ICASFI.EQ.'RFIT')THEN 396 NUMEQ=0 397 IMAX=ILOCQ-1 398 DO2130I=1,IMAX 399 IF(IHARG(I).EQ.'= '.AND.IHARG2(I).EQ.' ')NUMEQ=NUMEQ+1 400 2130 CONTINUE 401 IF(NUMEQ.NE.1)THEN 402 WRITE(ICOUT,2001) 403 CALL DPWRST('XXX','BUG ') 404 WRITE(ICOUT,2132) 405 2132 FORMAT(' THE NUMBER OF EQUAL SIGNS DETECTED, ',I6, 406 1 ', IN MODEL NOT EQUAL 1.') 407 CALL DPWRST('XXX','BUG ') 408 WRITE(ICOUT,2134)NUMARG,IMAX 409 2134 FORMAT(' NUMARG, IMAX = ',2I10) 410 CALL DPWRST('XXX','BUG ') 411 DO2135I=1,NUMARG 412 WRITE(ICOUT,2136)I,IHARG(I),IHARG2(I) 413 2136 FORMAT('I,IHARG(I),IHARG2(I) = ',I8,2A4) 414 CALL DPWRST('XXX','BUG ') 415 2135 CONTINUE 416 WRITE(ICOUT,2007) 417 CALL DPWRST('XXX','BUG ') 418 IF(IWIDTH.GE.1)THEN 419 WRITE(ICOUT,2008)(IANS(J),J=1,MIN(100,IWIDTH)) 420 CALL DPWRST('XXX','BUG ') 421 ENDIF 422 IERROR='YES' 423 GOTO9000 424 ENDIF 425 ENDIF 426C 427 IF(ICASFI.EQ.'FIT'.AND.IHARG(2).NE.'=')GOTO2200 428 IF(ICASFI.EQ.'RFIT'.AND.IHARG(3).NE.'=')GOTO2200 429 GOTO2290 430C 431 2200 CONTINUE 432 WRITE(ICOUT,999) 433 CALL DPWRST('XXX','BUG ') 434 WRITE(ICOUT,2001) 435 CALL DPWRST('XXX','BUG ') 436 WRITE(ICOUT,2202) 437 2202 FORMAT(' WHEN FITTING GENERAL EXPRESSIONS, THE') 438 CALL DPWRST('XXX','BUG ') 439 WRITE(ICOUT,2203) 440 2203 FORMAT(' SECOND ARGUMENT AFTER THE WORD FIT') 441 CALL DPWRST('XXX','BUG ') 442 WRITE(ICOUT,2204) 443 2204 FORMAT(' SHOULD BE (BUT WAS NOT) AN EQUAL SIGN.') 444 CALL DPWRST('XXX','BUG ') 445 IF(ICASFI.EQ.'FIT')THEN 446 WRITE(ICOUT,2205)IHARG(2),IHARG2(2) 447 2205 FORMAT(' THE ARGUMENT WAS ',2A4) 448 CALL DPWRST('XXX','BUG ') 449 ELSEIF(ICASFI.EQ.'RFIT')THEN 450 WRITE(ICOUT,2205)IHARG(3),IHARG2(3) 451 CALL DPWRST('XXX','BUG ') 452 ENDIF 453 WRITE(ICOUT,2007) 454 CALL DPWRST('XXX','BUG ') 455 IF(IWIDTH.GE.1)THEN 456 WRITE(ICOUT,2008)(IANS(J),J=1,MIN(100,IWIDTH)) 457 CALL DPWRST('XXX','BUG ') 458 ENDIF 459 IERROR='YES' 460 GOTO9000 461C 462 2290 CONTINUE 463C 464C ****************************************************** 465C ** STEP 4-- ** 466C ** FOR ALL VARIATIONS OF THE FIT COMMAND, ** 467C ** THE WORD AFTER FIT SHOULD BE THE RESPONSE* 468C ** VARIABLE (= THE DEPENDENT VARIABLE). ** 469C ** EXTRACT THE RESPONSE VARIABLE AND DETERMINE ** 470C ** IF IT IS ALREADY IN THE NAME LIST AND IS, IN FACT,* 471C ** A VARIABLE (AS OPPOSED TO A PARAMETER). ** 472C ****************************************************** 473C 474 ISTEPN='4' 475 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 476 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 477C 478 I2=0 479C 480 IF(ICASFI.EQ.'RFIT')THEN 481 IMAX=ILOCQ-1 482 DO2330I=1,IMAX 483 I2=I 484 IF(IHARG(I).EQ.'FIT')GOTO2349 485 2330 CONTINUE 486 WRITE(ICOUT,2001) 487 CALL DPWRST('XXX','BUG ') 488 WRITE(ICOUT,2332) 489 2332 FORMAT(' THE WORD FIT NOT FOUND IN THE ARGUMENT LIST') 490 CALL DPWRST('XXX','BUG ') 491 WRITE(ICOUT,3334) 492 3334 FORMAT(' EVEN THOUGH IT HAD BEEN PREVIOUSLY FOUND.') 493 CALL DPWRST('XXX','BUG ') 494 WRITE(ICOUT,2335)NUMARG,IMAX 495 2335 FORMAT(' NUMARG, IMAX = ',2I10) 496 CALL DPWRST('XXX','BUG ') 497 DO2336I=1,NUMARG 498 WRITE(ICOUT,2337)I,IHARG(I),IHARG2(I) 499 2337 FORMAT('I,IHARG(I),IHARG2(I) = ',I8,A4,A4) 500 CALL DPWRST('XXX','BUG ') 501 2336 CONTINUE 502 WRITE(ICOUT,2007) 503 CALL DPWRST('XXX','BUG ') 504 IF(IWIDTH.GE.1)THEN 505 WRITE(ICOUT,2008)(IANS(J),J=1,IWIDTH) 506 CALL DPWRST('XXX','BUG ') 507 ENDIF 508 IERROR='YES' 509 GOTO9000 510 ENDIF 511 2349 CONTINUE 512 ILOCFI=I2 513C 514 ILOCF1=ILOCFI+1 515 IHLEFT=IHARG(ILOCF1) 516 IHLEF2=IHARG2(ILOCF1) 517 DO2350I=1,NUMNAM 518 I2=I 519 IF(IHLEFT.EQ.IHNAME(I2).AND.IHLEF2.EQ.IHNAM2(I2).AND. 520 1 IUSE(I2).EQ.'V')THEN 521 ILOCV=I2 522 ICOLL=IVALUE(ILOCV) 523 NLEFT=IN(ILOCV) 524 GOTO2390 525 ENDIF 526 2350 CONTINUE 527C 528 WRITE(ICOUT,2001) 529 CALL DPWRST('XXX','BUG ') 530 WRITE(ICOUT,2362) 531 2362 FORMAT(' THE NAME FOLLOWING THE WORD FIT (WHICH ', 532 1 'SHOULD BE') 533 CALL DPWRST('XXX','BUG ') 534 WRITE(ICOUT,2363) 535 2363 FORMAT(' THE RESPONSE VARIABLE) DOES NOT EXIST IN THE') 536 CALL DPWRST('XXX','BUG ') 537 WRITE(ICOUT,2366) 538 2366 FORMAT(' CURRENT NAME TABLE AS A VARIABLE.') 539 CALL DPWRST('XXX','BUG ') 540 WRITE(ICOUT,999) 541 CALL DPWRST('XXX','BUG ') 542 WRITE(ICOUT,2369)IHLEFT,IHLEF2 543 2369 FORMAT(' NAME AFTER THE WORD FIT = ',2A4) 544 CALL DPWRST('XXX','BUG ') 545 WRITE(ICOUT,2007) 546 CALL DPWRST('XXX','BUG ') 547 IF(IWIDTH.GE.1)THEN 548 WRITE(ICOUT,2008)(IANS(J),J=1,MIN(100,IWIDTH)) 549 CALL DPWRST('XXX','BUG ') 550 ENDIF 551 IERROR='YES' 552 GOTO9000 553C 554 2390 CONTINUE 555C 556C ******************************************************* 557C ** STEP 5-- ** 558C ** FOR ALL VARIATIONS OF THE FIT COMMAND, ** 559C ** CHECK THAT THE INPUT NUMBER OF OBSERVATIONS (NLEFT) 560C ** FOR THE RESPONSE VARIABLE IS 2 OR LARGER. ** 561C ******************************************************* 562C 563 ISTEPN='5' 564 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 565 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 566C 567 IF(NLEFT.LT.MINN2)THEN 568 WRITE(ICOUT,999) 569 CALL DPWRST('XXX','BUG ') 570 WRITE(ICOUT,2001) 571 CALL DPWRST('XXX','BUG ') 572 WRITE(ICOUT,312)IHLEFT,IHLEF2 573 312 FORMAT(' THE NUMBER OF OBSERVATIONS IN VARIABLE ',2A4) 574 CALL DPWRST('XXX','BUG ') 575 WRITE(ICOUT,313) 576 313 FORMAT(' (FOR WHICH A LEAST-SQUARES FIT WAS TO HAVE BEEN') 577 CALL DPWRST('XXX','BUG ') 578 WRITE(ICOUT,315)MINN2 579 315 FORMAT(' PERFORMED) MUST BE ',I8,' OR LARGER;') 580 CALL DPWRST('XXX','BUG ') 581 WRITE(ICOUT,316) 582 316 FORMAT(' SUCH WAS NOT THE CASE HERE.') 583 CALL DPWRST('XXX','BUG ') 584 WRITE(ICOUT,317)NLEFT 585 317 FORMAT(' THE INPUT NUMBER OF OBSERVATIONS NLEFT = ',I8) 586 CALL DPWRST('XXX','BUG ') 587 WRITE(ICOUT,318) 588 318 FORMAT(' THE ENTERED COMMAND LINE WAS AS FOLLOWS--') 589 CALL DPWRST('XXX','BUG ') 590 WRITE(ICOUT,2007) 591 CALL DPWRST('XXX','BUG ') 592 IF(IWIDTH.GE.1)THEN 593 WRITE(ICOUT,2008)(IANS(I),I=1,MIN(100,IWIDTH)) 594 CALL DPWRST('XXX','BUG ') 595 ENDIF 596 IERROR='YES' 597 GOTO9000 598 ENDIF 599C 600C ************************************************ 601C ** STEP 5.1-- ** 602C ** CHECK TO SEE IF HAVE A WEIGHTS VARIABLE. ** 603C ** IF DO HAVE, CHECK TO SEE IF A VARIABLE ** 604C ** (AS OPPOSED TO A PARAMETER). ** 605C ************************************************ 606C 607 ISTEPN='5.1' 608 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 609 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 610C 611 ILOCW=-99 612 ICOLW=-99 613 NWEIGH=-99 614 IF(IWEIGH.EQ.'ON')THEN 615 DO2450I=1,NUMNAM 616 I2=I 617 IF(IWEIG1.EQ.IHNAME(I2).AND.IWEIG2.EQ.IHNAM2(I2).AND. 618 1 IUSE(I2).EQ.'V')THEN 619 ILOCW=I2 620 ICOLW=IVALUE(ILOCW) 621 NWEIGH=IN(ILOCW) 622 GOTO2490 623 ENDIF 624 2450 CONTINUE 625C 626 WRITE(ICOUT,999) 627 CALL DPWRST('XXX','BUG ') 628 WRITE(ICOUT,2001) 629 CALL DPWRST('XXX','BUG ') 630 WRITE(ICOUT,2463) 631 2463 FORMAT(' THE WEIGHTS VARIABLE (AS SPECIFIED VIA THE ', 632 1 'WEIGHTS COMMAND)') 633 CALL DPWRST('XXX','BUG ') 634 WRITE(ICOUT,2466) 635 2466 FORMAT(' DOES NOT EXIST AS A VARIABLE IN THE CURRENT ', 636 1 'NAME TABLE.') 637 CALL DPWRST('XXX','BUG ') 638 WRITE(ICOUT,2469)IWEIG1,IWEIG2 639 2469 FORMAT(' NAME OF SPECIFIED WEIGHTS VARIABLE = ',2A4) 640 CALL DPWRST('XXX','BUG ') 641 WRITE(ICOUT,2007) 642 CALL DPWRST('XXX','BUG ') 643 IF(IWIDTH.GE.1)THEN 644 WRITE(ICOUT,2008)(IANS(J),J=1,MIN(100,IWIDTH)) 645 CALL DPWRST('XXX','BUG ') 646 ENDIF 647 IERROR='YES' 648 GOTO9000 649 ENDIF 650C 651 2490 CONTINUE 652C 653C ******************************************************** 654C ** STEP 6.1-- ** 655C ** FOR THE CASES WHEN HAVE FIT Y = SOME EXPRESSION ** 656C ** ROBUST FIT Y = SOME EXPRESSION ** 657C ** EXTRACT THE ENTIRE (LEFT AND RIGHT SIDE) FUNCTIONAL* 658C ** EXPRESSION FROM THE INPUT COMMAND LINE. COPY ** 659C ** OUT TO IWIDTH, OR OUT TO 'SUBS' (EXCLUSIVE), ** 660C ** OR OUT THE 'EXCE' (EXCLUSIVE) ** 661C ** OR OUT THE 'FOR' (EXCLUSIVE). ** 662C ******************************************************** 663C 664 ISTEPN='6.1' 665 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 666 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 667C 668 IF(ICASFI.EQ.'FIT' .OR. ICASFI.EQ.'RFIT')THEN 669 IF(NUMARG.EQ.0)GOTO4160 670 IF(IHARG(1).EQ.'SUBS'.AND.IHARG2(1).EQ.'ET ')GOTO4160 671 IF(IHARG(1).EQ.'EXCE'.AND.IHARG2(1).EQ.'PT ')GOTO4160 672 IF(IHARG(1).EQ.'FOR '.AND.IHARG2(1).EQ.' ')GOTO4160 673 ISTART=-99 674 ISTOP=-99 675 DO4110I=1,IWIDTH 676 IP1=I+1 677 IP2=I+2 678 IP3=I+3 679 IP4=I+4 680 IP5=I+5 681 IP6=I+6 682 IP7=I+7 683C 684 IF(IP2.GT.IWIDTH)GOTO4120 685 IF(IANS(I).EQ.'F'.AND.IANS(IP1).EQ.'I'.AND. 686 1 IANS(IP2).EQ.'T')ISTART=IP3 687C 688 IF(IP4.GT.IWIDTH)GOTO4120 689 IF(IANS(I).EQ.' '.AND.IANS(IP1).EQ.'F'.AND. 690 1 IANS(IP2).EQ.'O'.AND.IANS(IP3).EQ.'R'.AND. 691 1 IANS(IP4).EQ.' ')ISTOP=I 692C 693 IF(IP7.GT.IWIDTH)GOTO4120 694 IF(IANS(I).EQ.' '.AND.IANS(IP1).EQ.'S'.AND. 695 1 IANS(IP2).EQ.'U'.AND.IANS(IP3).EQ.'B'.AND. 696 1 IANS(IP4).EQ.'S'.AND.IANS(IP5).EQ.'E'.AND. 697 1 IANS(IP6).EQ.'T'.AND.IANS(IP7).EQ.' ')ISTOP=I 698C 699 4110 CONTINUE 700 4120 CONTINUE 701 IF(ISTART.LT.1)THEN 702 IBRAN=4120 703 WRITE(ICOUT,2001) 704 CALL DPWRST('XXX','BUG ') 705 WRITE(ICOUT,4121)IBRAN 706 4121 FORMAT(' IMPOSSIBLE CONDITION AT BRANCH POINT = ',I8) 707 CALL DPWRST('XXX','BUG ') 708 WRITE(ICOUT,4122) 709 4122 FORMAT('THE STRING FIT NOT FOUND FOR MODEL EXTRACTION') 710 CALL DPWRST('XXX','BUG ') 711 WRITE(ICOUT,2007) 712 CALL DPWRST('XXX','BUG ') 713 IF(IWIDTH.GE.1)THEN 714 WRITE(ICOUT,4124)(IANS(I),I=1,MIN(100,IWIDTH)) 715 4124 FORMAT(' ',100A1) 716 CALL DPWRST('XXX','BUG ') 717 ENDIF 718 IERROR='YES' 719 GOTO9000 720 ENDIF 721C 722 IF(ISTOP.EQ.-99)ISTOP=IWIDTH 723 IF(ISTART.GT.ISTOP)THEN 724 IBRAN=4130 725 WRITE(ICOUT,2001) 726 CALL DPWRST('XXX','BUG ') 727 WRITE(ICOUT,4132)IBRAN 728 4132 FORMAT(' AT BRANCH POINT = ',I8) 729 CALL DPWRST('XXX','BUG ') 730 WRITE(ICOUT,4133) 731 4133 FORMAT(' ISTART GREATER THAN ISTOP FOR MODEL EXTRACTION') 732 CALL DPWRST('XXX','BUG ') 733 WRITE(ICOUT,4134)ISTART,ISTOP 734 4134 FORMAT(' ISTART, ISTOP = ',2I8) 735 CALL DPWRST('XXX','BUG ') 736 WRITE(ICOUT,2007) 737 CALL DPWRST('XXX','BUG ') 738 IF(IWIDTH.GE.1)THEN 739 WRITE(ICOUT,2008)(IANS(I),I=1,MIN(100,IWIDTH)) 740 CALL DPWRST('XXX','BUG ') 741 ENDIF 742 IERROR='YES' 743 GOTO9000 744 ENDIF 745C 746 J=0 747 DO4150I=ISTART,ISTOP 748 J=J+1 749 MODEL(J)=IANS(I) 750 4150 CONTINUE 751 NUMCHA=ISTOP-ISTART+1 752 4160 CONTINUE 753 ENDIF 754C 755C *************************************************** 756C ** STEP 6.2-- ** 757C ** FOR THE CASES WHEN HAVE ... FIT Y X , ** 758C ** EXTRACT THE INDEPENDENT VARIABLE, ** 759C ** AND FORM THE 1 CHARACTER PER WORD ** 760C ** REPRESENTATION OF THE MODEL. ** 761C *************************************************** 762C 763 ISTEPN='6.2' 764 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 765 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 766C 767 IF(ICASFI.EQ.'FIT')GOTO4290 768 IF(ICASFI.EQ.'RFIT')GOTO4290 769 IF(ICASFI.EQ.'MFIT')GOTO4290 770C 771 ILOCRV=ILOCFI+1 772 ILOCIV=ILOCFI+2 773C 774 IDEGRE=0 775 IF(ICASFI.EQ.'0FIT')IDEGRE=0 776 IF(ICASFI.EQ.'1FIT')IDEGRE=1 777 IF(ICASFI.EQ.'2FIT')IDEGRE=2 778 IF(ICASFI.EQ.'3FIT')IDEGRE=3 779 IF(ICASFI.EQ.'4FIT')IDEGRE=4 780 IF(ICASFI.EQ.'5FIT')IDEGRE=5 781 IF(ICASFI.EQ.'6FIT')IDEGRE=6 782 IF(ICASFI.EQ.'7FIT')IDEGRE=7 783 IF(ICASFI.EQ.'8FIT')IDEGRE=8 784 IF(ICASFI.EQ.'9FIT')IDEGRE=9 785 IF(ICASFI.EQ.'10FI')IDEGRE=10 786 K1=IDEGRE+1 787C 788 I=0 789C 790 IWD=IHARG(ILOCRV) 791 CALL DPXH1H(IWD,ICH,IEND,IBUGA3) 792 IF(IEND.LE.0)GOTO4219 793 DO4210J=1,IEND 794 I=I+1 795 MODEL(I)=ICH(J) 796 4210 CONTINUE 797 4219 CONTINUE 798C 799 IWD=IHARG2(ILOCRV) 800 CALL DPXH1H(IWD,ICH,IEND,IBUGA3) 801 IF(IEND.GT.0)THEN 802 DO4220J=1,IEND 803 I=I+1 804 MODEL(I)=ICH(J) 805 4220 CONTINUE 806 ENDIF 807C 808 KMAX=IDEGRE+1 809 I=I+1 810 MODEL(I)='=' 811C 812 KMAX=IDEGRE+1 813C 814C IF SET FIT ADDITIVE COMMAND ENTERED, THEN DO NOT INCLUDE 815C CONSTANT TERM. 816C 817 DO4250K=1,KMAX 818 KTEMP=0 819 IF(IFITAC.EQ.'OFF')THEN 820 IF(K.EQ.1)GOTO4250 821 KTEMP=1 822 ENDIF 823 KM1=K-1 824C 825 IF(KM1.GT.KTEMP)THEN 826 I=I+1 827 MODEL(I)='+' 828 ENDIF 829C 830 I=I+1 831 MODEL(I)='A' 832C 833 IF(0.LE.KM1.AND.KM1.LE.10)I=I+1 834 IF(KM1.EQ.0)MODEL(I)='0' 835 IF(KM1.EQ.1)MODEL(I)='1' 836 IF(KM1.EQ.2)MODEL(I)='2' 837 IF(KM1.EQ.3)MODEL(I)='3' 838 IF(KM1.EQ.4)MODEL(I)='4' 839 IF(KM1.EQ.5)MODEL(I)='5' 840 IF(KM1.EQ.6)MODEL(I)='6' 841 IF(KM1.EQ.7)MODEL(I)='7' 842 IF(KM1.EQ.8)MODEL(I)='8' 843 IF(KM1.EQ.9)MODEL(I)='9' 844 IF(KM1.EQ.10)MODEL(I)='1' 845 IF(KM1.EQ.10)I=I+1 846 IF(J.EQ.10)MODEL(I)='0' 847C 848 IF(KM1.LE.0)GOTO4250 849C 850 I=I+1 851 MODEL(I)='*' 852C 853 IWD=IHARG(ILOCIV) 854 CALL DPXH1H(IWD,ICH,IEND,IBUGA3) 855 IF(IEND.GT.0)THEN 856 DO4260J=1,IEND 857 I=I+1 858 MODEL(I)=ICH(J) 859 4260 CONTINUE 860 ENDIF 861C 862 IWD=IHARG2(ILOCIV) 863 CALL DPXH1H(IWD,ICH,IEND,IBUGA3) 864 IF(IEND.GT.0)THEN 865 DO4270J=1,IEND 866 I=I+1 867 MODEL(I)=ICH(J) 868 4270 CONTINUE 869 ENDIF 870C 871 IF(KM1.LE.1)GOTO4250 872C 873 I=I+1 874 MODEL(I)='*' 875 I=I+1 876 MODEL(I)='*' 877C 878 IF(0.LE.KM1.AND.KM1.LE.10)I=I+1 879 IF(KM1.EQ.0)MODEL(I)='0' 880 IF(KM1.EQ.1)MODEL(I)='1' 881 IF(KM1.EQ.2)MODEL(I)='2' 882 IF(KM1.EQ.3)MODEL(I)='3' 883 IF(KM1.EQ.4)MODEL(I)='4' 884 IF(KM1.EQ.5)MODEL(I)='5' 885 IF(KM1.EQ.6)MODEL(I)='6' 886 IF(KM1.EQ.7)MODEL(I)='7' 887 IF(KM1.EQ.8)MODEL(I)='8' 888 IF(KM1.EQ.9)MODEL(I)='9' 889 IF(KM1.EQ.10)MODEL(I)='1' 890 IF(KM1.EQ.10)I=I+1 891 IF(J.EQ.10)MODEL(I)='0' 892C 893 4250 CONTINUE 894 4290 CONTINUE 895 IWIDMO=I 896 NUMCHA=IWIDMO 897C 898C ********************************************** 899C ** STEP 6.3-- ** 900C ** FOR ALL VARIATIONS OF THE FIT COMMAND, ** 901C ** CHECK TO SEE THE TYPE CASE-- ** 902C ** 1) UNQUALIFIED (THAT IS, FULL); ** 903C ** 2) SUBSET/EXCEPT; OR ** 904C ** 3) FOR. ** 905C ********************************************** 906C 907 ISTEPN='6.3' 908 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 909 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 910C 911 ICASEQ='FULL' 912 ILOCQ=NUMARG+1 913 IF(NUMARG.GE.1)THEN 914 DO400J=1,NUMARG 915 J1=J 916 IF((IHARG(J).EQ.'SUBS'.AND.IHARG2(J).EQ.'ET ') .OR. 917 1 (IHARG(J).EQ.'EXCE'.AND.IHARG2(J).EQ.'PT '))THEN 918 ICASEQ='SUBS' 919 IKEY='SUBS' 920 IF(IHARG(J1).EQ.'EXCE')IKEY='EXCE' 921 ILOCQ=J1 922 ELSEIF(IHARG(J).EQ.'FOR '.AND.IHARG2(J).EQ.' ')THEN 923 ICASEQ='FOR' 924 ILOCQ=J1 925 ENDIF 926 400 CONTINUE 927 ENDIF 928C 929 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT')THEN 930 WRITE(ICOUT,491)NUMARG,ILOCQ 931 491 FORMAT('NUMARG,ILOCQ = ',2I8) 932 CALL DPWRST('XXX','BUG ') 933 ENDIF 934C 935C ********************************************** 936C ** STEP 6.4-- ** 937C ** FOR SOME VARIATIONS OF THE FIT COMMAND, ** 938C ** EXTRACT THE UNDERLYING FUNCTION ** 939C ** FROM FUNCTION DEFINITIONS. ** 940C ********************************************** 941C 942C 943 ISTEPN='6.4' 944 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 945 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 946C 947 IF(ICASFI.EQ.'FIT' .OR. ICASFI.EQ.'RFIT')THEN 948 DO5170I=1,NUMCHA 949 I2=I 950 IF(MODEL(I).EQ.'=')GOTO5175 951 5170 CONTINUE 952 IBRAN=5170 953 WRITE(ICOUT,2001) 954 CALL DPWRST('XXX','BUG ') 955 WRITE(ICOUT,5171)IBRAN 956 5171 FORMAT(' IMPOSSIBLE CONDITION AT BRANCH POINT = ',I8) 957 CALL DPWRST('XXX','BUG ') 958 WRITE(ICOUT,5172) 959 5172 FORMAT(' NO EQUAL SIGN FOUND FOR MODEL EXTRACTION') 960 CALL DPWRST('XXX','BUG ') 961 WRITE(ICOUT,2007) 962 CALL DPWRST('XXX','BUG ') 963 IF(IWIDTH.GE.1)THEN 964 WRITE(ICOUT,2008)(IANS(I),I=1,MIN(100,IWIDTH)) 965 CALL DPWRST('XXX','BUG ') 966 ENDIF 967 IERROR='YES' 968 GOTO9000 969 5175 CONTINUE 970 ILOCEQ=I2 971C 972 IWD1='= ' 973 IWD12=' ' 974 IF(ICASEQ.EQ.'FULL')THEN 975 IWD2=' ' 976 IWD22=' ' 977 ELSEIF(ICASEQ.EQ.'SUBS'.AND.IKEY.EQ.'SUBS')THEN 978 IWD2='SUBS' 979 IWD22='ET ' 980 ELSEIF(ICASEQ.EQ.'SUBS'.AND.IKEY.EQ.'EXCE')THEN 981 IWD2='EXCE' 982 IWD22='PT ' 983 ELSEIF(ICASEQ.EQ.'FOR')THEN 984 IWD2='FOR ' 985 IWD22=' ' 986 ENDIF 987C 988 IF(ICASFI.EQ.'FIT'.OR.ICASFI.EQ.'RFIT')THEN 989 CALL DPEXST(IANS,IWIDTH,IWD1,IWD12,IWD2,IWD22,MAXN2, 990 1 IFUNC2,N2,IBUGA3,IFOUND,IERROR) 991 ELSEIF(ICASFI.NE.'FIT'.AND.ICASFI.NE.'RFIT')THEN 992 CALL DPEXST(MODEL,IWIDMO,IWD1,IWD12,IWD2,IWD22,MAXN2, 993 1 IFUNC2,N2,IBUGA3,IFOUND,IERROR) 994 ENDIF 995 IF(IERROR.EQ.'YES')GOTO9000 996 IF(IFOUND.EQ.'NO')THEN 997 WRITE(ICOUT,999) 998 CALL DPWRST('XXX','BUG ') 999 WRITE(ICOUT,2001) 1000 CALL DPWRST('XXX','BUG ') 1001 WRITE(ICOUT,3372) 1002 3372 FORMAT(' INVALID COMMAND FORM FOR FITTING. GENERAL ', 1003 1 'FORM--') 1004 CALL DPWRST('XXX','BUG ') 1005 WRITE(ICOUT,3374) 1006 3374 FORMAT(' FIT ... = ... SUBSET ... ... ...') 1007 CALL DPWRST('XXX','BUG ') 1008 WRITE(ICOUT,2007) 1009 CALL DPWRST('XXX','BUG ') 1010 IF(IWIDTH.GE.1)THEN 1011 WRITE(ICOUT,2008)(IANS(I),I=1,MIN(100,IWIDTH)) 1012 CALL DPWRST('XXX','BUG ') 1013 ENDIF 1014 IERROR='YES' 1015 GOTO9000 1016 ENDIF 1017C 1018 CALL DPEXFU(IFUNC2,N2,IHNAME,IHNAM2,IUSE,IVSTAR,IVSTOP, 1019 1 NUMNAM,IANS,IWIDTH,IFUNC,NUMCHF,MAXCHF, 1020 1 IFUNC3,N3,MAXN3, 1021 1 IBUGA3,IERROR) 1022 IF(IERROR.EQ.'YES')GOTO9000 1023C 1024 J=ILOCEQ 1025 DO5180I=1,N3 1026 J=J+1 1027 MODEL(J)=IFUNC3(I) 1028 5180 CONTINUE 1029 NUMCHA=J 1030C 1031 ENDIF 1032C 1033C ****************************************************** 1034C ** STEP 7-- ** 1035C ** MAKE A NON-CALCULATING PASS AT THE MODEL ** 1036C ** SO AS TO EXTRACT ALL PARAMETER AND VARIABLE NAMES. 1037C ****************************************************** 1038C 1039 ISTEPN='7' 1040 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 1041 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 1042C 1043 IPASS=1 1044 IF(ICASFI.EQ.'FIT' .OR. ICASFI.EQ.'RFIT')THEN 1045 CALL COMPIM(MODEL,NUMCHA,IPASS,PARAM,IPARN,IPARN2,NUMPV, 1046 1 IANGLU,ITYPEH,IW2HOL,IW22HO,W2HOLD,NWHOLD,AJUNK, 1047 1 IBUGCO,IBUGEV,IERROR) 1048 IF(IERROR.EQ.'YES')GOTO9000 1049 ELSEIF(ICASFI.EQ.'MFIT')THEN 1050C 1051CCCCC APRIL 2002. IF SET FIT ADDITIVE CONSTANT OFF ENTERED, THEN DO 1052CCCCC NOT FIT A CONSTANT TERM. UPDATE CODE BELOW 1053CCCCC ACCORDINGLY. 1054C 1055 JMIN=2 1056 JMAX=ILOCQ-1 1057 MAXIND=MAXCMF-1 1058 CALL EXTVAR(IHARG,IHARG2,NUMARG,JMIN,JMAX,MAXIND, 1059 1 IHNAME,IHNAM2,IUSE,NUMNAM, 1060 1 IVARN1,IVARN2,NUMIND,IBUGA2,ISUBRO,IERROR) 1061 IF(IERROR.EQ.'YES')GOTO8000 1062C 1063 IF(IFITAC.EQ.'OFF')THEN 1064 NUMPAR=NUMIND 1065 ISTRT=2 1066 ISTOP=NUMPAR+1 1067 ELSE 1068 NUMPAR=NUMIND+1 1069 ISTRT=1 1070 ISTOP=NUMPAR 1071 ENDIF 1072C 1073 ICOUNT=0 1074 DO6411I5=ISTRT,ISTOP 1075 ICOUNT=ICOUNT+1 1076 I5M1=I5-1 1077 IH=' ' 1078 IH2=' ' 1079 CALL DPCOIH(I5M1,IHOUT,NOUT,IVALID,IBUGA3,ISUBRO,IERROR) 1080 IHOUT1=IHOUT(1) 1081 IHOUT2=IHOUT(2) 1082 IHOUT3=IHOUT(3) 1083 IH(1:1)='A' 1084 IF(NOUT.GE.1)IH(2:2)=IHOUT1(1:1) 1085 IF(NOUT.GE.2)IH(3:3)=IHOUT2(1:1) 1086 IF(NOUT.GE.3)IH(4:4)=IHOUT3(1:1) 1087 IPARN(ICOUNT)=IH 1088 IPARN2(ICOUNT)=IH2 1089 6411 CONTINUE 1090C 1091CCCCC THE FOLLOWING LINE WAS COMMENTED OUT MAY 1989 1092CCCCC NUMIND=ILOCQ-2 1093CCCCC THE FOLLOWING LINE WAS FIXED MARCH 1989 1094CCCCC NUMPV=NUMIND 1095 NUMPV=NUMPAR 1096 ILOCQM=ILOCQ-1 1097CCCCC THE FOLLOWING LINE WAS FIXED MAY 1989 1098CCCCC DO6412I5=2,ILOCQM 1099 DO6412I5=1,NUMIND 1100 NUMPV=NUMPV+1 1101CCCCC THE FOLLOWING LINE WAS FIXED MARCH 1989 1102CCCCC J5=NUMIND+(I5-1) 1103CCCCC J5=NUMIND+1+(I5-1) 1104 J5=NUMPAR+I5 1105 IPARN(J5)=IVARN1(I5) 1106 IPARN2(J5)=IVARN2(I5) 1107 6412 CONTINUE 1108 ELSE 1109CCCCC THE FOLLOWING LINE WAS ADDED AUGUST 1989 1110 NUMPAR=IDEGRE+1 1111 IF(IFITAC.EQ.'OFF')NUMPAR=IDEGRE 1112 DO6421I5=1,NUMPAR 1113 I5M1=I5-1 1114 IF(IFITAC.EQ.'OFF')I5M1=I5 1115 IH=' ' 1116 IH2=' ' 1117 CALL DPCOIH(I5M1,IHOUT,NOUT,IVALID,IBUGA3,ISUBRO,IERROR) 1118 IHOUT1=IHOUT(1) 1119 IHOUT2=IHOUT(2) 1120 IHOUT3=IHOUT(3) 1121 IH(1:1)='A' 1122 IF(NOUT.GE.1)IH(2:2)=IHOUT1(1:1) 1123 IF(NOUT.GE.2)IH(3:3)=IHOUT2(1:1) 1124 IF(NOUT.GE.3)IH(4:4)=IHOUT3(1:1) 1125 IPARN(I5)=IH 1126 IPARN2(I5)=IH2 1127 6421 CONTINUE 1128C 1129 IDEGRE=0 1130 IF(ICASFI.EQ.'0FIT')IDEGRE=0 1131 IF(ICASFI.EQ.'1FIT')IDEGRE=1 1132 IF(ICASFI.EQ.'2FIT')IDEGRE=2 1133 IF(ICASFI.EQ.'3FIT')IDEGRE=3 1134 IF(ICASFI.EQ.'4FIT')IDEGRE=4 1135 IF(ICASFI.EQ.'5FIT')IDEGRE=5 1136 IF(ICASFI.EQ.'6FIT')IDEGRE=6 1137 IF(ICASFI.EQ.'7FIT')IDEGRE=7 1138 IF(ICASFI.EQ.'8FIT')IDEGRE=8 1139 IF(ICASFI.EQ.'9FIT')IDEGRE=9 1140 IF(ICASFI.EQ.'10FI')IDEGRE=10 1141 NUMPV=IDEGRE+2 1142 IF(IFITAC.EQ.'OFF')NUMPV=IDEGRE+1 1143 IPARN(NUMPV)=IHARG(2) 1144 IPARN2(NUMPV)=IHARG2(2) 1145 ENDIF 1146C 1147C ******************************************** 1148C ** STEP 8-- ** 1149C ** CHECK TO MAKE SURE THAT THE COMBINED ** 1150C ** NUMBER OF PARAMETERS AND VARIABLES ** 1151C ** IN THE MODEL IS AT LEAST 1. ** 1152C ******************************************** 1153C 1154 ISTEPN='8' 1155 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 1156 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 1157C 1158 IF(NUMPV.LT.1)THEN 1159 WRITE(ICOUT,2001) 1160 CALL DPWRST('XXX','BUG ') 1161 WRITE(ICOUT,4402) 1162 4402 FORMAT(' COMBINED NUMBER OF PARAMETERS AND VARIABLES') 1163 CALL DPWRST('XXX','BUG ') 1164 WRITE(ICOUT,4403)NUMPV 1165 4403 FORMAT(' DETECTED IN THE MODEL IS 0. NUMPV = ',I8) 1166 CALL DPWRST('XXX','BUG ') 1167 WRITE(ICOUT,4407)NUMCHA 1168 4407 FORMAT(' NUMBER OF CHARACTERS IN MODEL = ',I8) 1169 CALL DPWRST('XXX','BUG ') 1170 IF(NUMCHA.GE.1)THEN 1171 WRITE(ICOUT,4408)(MODEL(J),J=1,MIN(100,NUMCHA)) 1172 4408 FORMAT(' MODEL--',100A1) 1173 CALL DPWRST('XXX','BUG ') 1174 ENDIF 1175 IERROR='YES' 1176 GOTO9000 1177 ENDIF 1178C 1179C ****************************************************** 1180C ** STEP 9-- ** 1181C ** CHECK THAT ALL VARIABLES ** 1182C ** IN THE MODEL ARE ALREADY PRESENT ** 1183C ** IN THE AVAILABLE NAME LIST IHNAME(.) AND IHNAM2(.). 1184C ** CHECK THAT ALL PARAMETERS ** 1185C ** IN THE MODEL ARE ALREADY PRESENT ** 1186C ** IN THE AVAILABLE NAME LIST IHNAME(.) AND IHNAM2(.). 1187C ** ALL NAMES IN THE MODEL THAT ARE NOT ** 1188C ** IN THE NAME LIST AT ALL WILL BE ADDED ** 1189C ** TO THE LIST, DEFINED AS PARAMETERS, ** 1190C ** AND GIVEN A VALUE OF 1.0. ** 1191C ** THIS ALLOWS US TO MAKE AN INITIAL FIT ** 1192C ** WITHOUT HAVING TO DEFINE STARTING VALUES AT ALL ** 1193C ** (THEY WILL BE AUTOMATICALLY SET TO 1.0). ALSO, ** 1194C ** FORM A NEW VECTOR WHICH HAS ONLY PARAMETER NAMES** 1195C ** AND ANOTHER VECTOR WHICH HAS ONLY VARIABLE NAMES.* 1196C ****************************************************** 1197C 1198 ISTEPN='9' 1199 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 1200 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 1201C 1202 IP=0 1203 IV=0 1204 DO4165J=1,NUMPV 1205 IHPARN=IPARN(J) 1206 IHPAR2=IPARN2(J) 1207 DO4166I=1,NUMNAM 1208 I2=I 1209 IF(IHPARN.EQ.IHNAME(I).AND.IHPAR2.EQ.IHNAM2(I).AND. 1210 1 IUSE(I).EQ.'V')THEN 1211 IV=IV+1 1212 IVARN3(IV)=IPARN(J) 1213 IVARN4(IV)=IPARN2(J) 1214 ICOLV3(IV)=IVALUE(I2) 1215 NIV(IV)=IN(I2) 1216 GOTO4165 1217 ELSEIF(IHPARN.EQ.IHNAME(I).AND.IHPAR2.EQ.IHNAM2(I).AND. 1218 1 IUSE(I).EQ.'P')THEN 1219 IP=IP+1 1220 IPARN3(IP)=IPARN(J) 1221 IPARN4(IP)=IPARN2(J) 1222 PARAM3(IP)=VALUE(I2) 1223 GOTO4165 1224 ENDIF 1225 4166 CONTINUE 1226 IP=IP+1 1227 IPARN3(IP)=IPARN(J) 1228 IPARN4(IP)=IPARN2(J) 1229 PARAM3(IP)=1.0 1230C 1231 IF(NUMNAM.GE.MAXNAM)THEN 1232 WRITE(ICOUT,2001) 1233 CALL DPWRST('XXX','BUG ') 1234 WRITE(ICOUT,7752) 1235 7752 FORMAT(' THE TOTAL NUMBER OF (VARIABLE + PARAMETER) ', 1236 1 'NAMES MUST') 1237 CALL DPWRST('XXX','BUG ') 1238 WRITE(ICOUT,7754)MAXNAM 1239 7754 FORMAT(' BE AT MOST ',I8,'. SUCH WAS NOT THE CASE ', 1240 1 'HERE--') 1241 CALL DPWRST('XXX','BUG ') 1242 WRITE(ICOUT,7755) 1243 7755 FORMAT(' THE MAXIMUM ALLOWABLE NUMBER OF NAMES WAS JUST') 1244 CALL DPWRST('XXX','BUG ') 1245 WRITE(ICOUT,7757) 1246 7757 FORMAT(' EXCEEDED. SUGGESTED ACTION--ENTER STAT') 1247 CALL DPWRST('XXX','BUG ') 1248 WRITE(ICOUT,7758) 1249 7758 FORMAT(' TO DETERMINE THE IMPORTANT (VERSUS ', 1250 1 'UNIMPORTANT)') 1251 CALL DPWRST('XXX','BUG ') 1252 WRITE(ICOUT,7760) 1253 7760 FORMAT(' VARIABLES AND PARAMETERS, AND THEN REUSE SOME') 1254 CALL DPWRST('XXX','BUG ') 1255 WRITE(ICOUT,7761) 1256 7761 FORMAT(' OF THE NAMES.') 1257 CALL DPWRST('XXX','BUG ') 1258 WRITE(ICOUT,2007) 1259 CALL DPWRST('XXX','BUG ') 1260 IF(IWIDTH.GE.1)THEN 1261 WRITE(ICOUT,2008)(IANS(I),I=1,MIN(100,IWIDTH)) 1262 CALL DPWRST('XXX','BUG ') 1263 ENDIF 1264 IERROR='YES' 1265 GOTO9000 1266 ENDIF 1267C 1268 I2=NUMNAM+1 1269 IHNAME(I2)=IPARN(J) 1270 IHNAM2(I2)=IPARN2(J) 1271 IUSE(I2)='P' 1272 IVALUE(I2)=1 1273 VALUE(I2)=1.0 1274 IN(I2)=1 1275 NUMNAM=I2 1276 IF(ICASFI.EQ.'MFIT')GOTO4259 1277 IF(ICASFI.EQ.'0FIT')GOTO4259 1278 IF(ICASFI.EQ.'1FIT')GOTO4259 1279 IF(ICASFI.EQ.'2FIT')GOTO4259 1280 IF(ICASFI.EQ.'3FIT')GOTO4259 1281 IF(ICASFI.EQ.'4FIT')GOTO4259 1282 IF(ICASFI.EQ.'5FIT')GOTO4259 1283 IF(ICASFI.EQ.'6FIT')GOTO4259 1284 IF(ICASFI.EQ.'7FIT')GOTO4259 1285 IF(ICASFI.EQ.'8FIT')GOTO4259 1286 IF(ICASFI.EQ.'9FIT')GOTO4259 1287 IF(ICASFI.EQ.'10FI')GOTO4259 1288 IF(IFEEDB.EQ.'ON')THEN 1289 WRITE(ICOUT,999) 1290 CALL DPWRST('XXX','BUG ') 1291 WRITE(ICOUT,4252) 1292 4252 FORMAT(' NOTE--A NAME USED IN AN EXPRESSION') 1293 CALL DPWRST('XXX','BUG ') 1294 WRITE(ICOUT,4253)IPARN(J),IPARN2(J) 1295 4253 FORMAT(' HAS NOT YET BEEN DEFINED. NAME = ',2A4) 1296 CALL DPWRST('XXX','BUG ') 1297 WRITE(ICOUT,4255) 1298 4255 FORMAT(' THIS NAME HAS BEEN ADDED TO THE LIST, ', 1299 1 'SPECIFIED') 1300 CALL DPWRST('XXX','BUG ') 1301 WRITE(ICOUT,4257) 1302 4257 FORMAT(' AS A PARAMETER, AND GIVEN THE VALUE 1.0 .') 1303 CALL DPWRST('XXX','BUG ') 1304 WRITE(ICOUT,4258)(MODEL(I),I=1,MIN(100,NUMCHA)) 1305 4258 FORMAT(' FUNCTION EXPRESSION--',100A1) 1306 CALL DPWRST('XXX','BUG ') 1307 ENDIF 1308 4259 CONTINUE 1309 GOTO4165 1310 4165 CONTINUE 1311 NUMPAR=IP 1312 NUMVAR=IV 1313C 1314C ******************************************* 1315C ** STEP 10-- ** 1316C ** CHECK FOR A VALID NUMBER ** 1317C ** OF INDEPENDENT VARIABLES (1 TO 5). ** 1318C ** CHECK THE VALIDITY OF EACH ** 1319C ** OF THE INDEPENDENT VARIABLES. ** 1320C ** DOES THE NAME EXIST IN THE TABLE? ** 1321C ** DOES THE NUMBER OF ELEMENTS ** 1322C ** AGREE WITH THE NUMBER OF ELEMENTS ** 1323C ** IN THE RESPONSE VARIABLE? ** 1324C ******************************************* 1325C 1326 ISTEPN='10' 1327 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 1328 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 1329C 1330CCCCC THE FOLLOWING LINE WAS INSERTED MAY 1989 1331 IF(ICASFI.NE.'FIT')GOTO520 1332C 1333 IF(NUMVAR.LT.1 .OR. NUMVAR.GT.MAXV2)THEN 1334 WRITE(ICOUT,999) 1335 CALL DPWRST('XXX','BUG ') 1336 WRITE(ICOUT,2001) 1337 CALL DPWRST('XXX','BUG ') 1338 WRITE(ICOUT,552) 1339 552 FORMAT(' FOR A LEAST SQUARES FIT, THE NUMBER OF') 1340 CALL DPWRST('XXX','BUG ') 1341 WRITE(ICOUT,553) 1342 553 FORMAT(' INDEPENDENT VARIABLES MUST BE AT LEAST 1 AND AT') 1343 CALL DPWRST('XXX','BUG ') 1344 WRITE(ICOUT,555)MAXV2 1345 555 FORMAT(' MOST ',I8,'. SUCH WAS NOT THE CASE HERE;') 1346 CALL DPWRST('XXX','BUG ') 1347 WRITE(ICOUT,557)NUMVAR 1348 557 FORMAT(' THE SPECIFIED NUMBER OF INDEPENDENT VARIABLES ', 1349 1 'WAS ',I8) 1350 CALL DPWRST('XXX','BUG ') 1351 WRITE(ICOUT,2007) 1352 CALL DPWRST('XXX','BUG ') 1353 IF(IWIDTH.GE.1)THEN 1354 WRITE(ICOUT,2008)(IANS(I),I=1,MIN(100,IWIDTH)) 1355 CALL DPWRST('XXX','BUG ') 1356 ENDIF 1357 WRITE(ICOUT,999) 1358 CALL DPWRST('XXX','BUG ') 1359 WRITE(ICOUT,4507)NUMCHA 1360 4507 FORMAT(' NUMBER OF CHARACTERS IN MODEL = ',I8) 1361 CALL DPWRST('XXX','BUG ') 1362 WRITE(ICOUT,4508)(MODEL(J),J=1,MIN(100,NUMCHA)) 1363 4508 FORMAT(' MODEL--',100A1) 1364 CALL DPWRST('XXX','BUG ') 1365 WRITE(ICOUT,4504) 1366 4504 FORMAT(' VARIABLES EXTRACTED FROM MODEL--') 1367 CALL DPWRST('XXX','BUG ') 1368 DO4505J=1,NUMVAR 1369 WRITE(ICOUT,4506)J,IVARN3(J),IVARN4(J),ICOLV3(J) 1370 4506 FORMAT('I,IVARN3(I),IVARN4(I),ICOLV3(I) = ',I8,2X,2A4,2X,I8) 1371 CALL DPWRST('XXX','BUG ') 1372 4505 CONTINUE 1373 IERROR='YES' 1374 GOTO9000 1375 ENDIF 1376C 1377 520 CONTINUE 1378 DO540J=1,NUMVAR 1379 IF(NIV(J).NE.NLEFT)THEN 1380 WRITE(ICOUT,999) 1381 CALL DPWRST('XXX','BUG ') 1382 WRITE(ICOUT,2001) 1383 CALL DPWRST('XXX','BUG ') 1384 WRITE(ICOUT,562) 1385 562 FORMAT(' FOR A LEAST SQUARES FIT, THE NUMBER OF ', 1386 1 'ELEMENTS') 1387 CALL DPWRST('XXX','BUG ') 1388 WRITE(ICOUT,564) 1389 564 FORMAT(' IN EACH INDEPENDENT VARIABLE SHOULD BE THE ', 1390 1 'SAME') 1391 CALL DPWRST('XXX','BUG ') 1392 WRITE(ICOUT,565) 1393 565 FORMAT(' AS THE NUMBER OF ELEMENTS IN THE DEPENDENT') 1394 CALL DPWRST('XXX','BUG ') 1395 WRITE(ICOUT,567) 1396 567 FORMAT(' VARIABLE (RESPONSE); SUCH WAS NOT THE CASE ', 1397 1 'HERE.') 1398 CALL DPWRST('XXX','BUG ') 1399 WRITE(ICOUT,999) 1400 CALL DPWRST('XXX','BUG ') 1401 WRITE(ICOUT,571) 1402 571 FORMAT(' DEPENDENT VARIABLE (RESPONSE)--') 1403 CALL DPWRST('XXX','BUG ') 1404 WRITE(ICOUT,572)IHLEFT,IHLEF2,NLEFT 1405 572 FORMAT(' ',2A4,' HAS ',I8,' ELEMENTS') 1406 CALL DPWRST('XXX','BUG ') 1407 WRITE(ICOUT,999) 1408 CALL DPWRST('XXX','BUG ') 1409 WRITE(ICOUT,576) 1410 576 FORMAT(' INDEPENDENT VARIABLES --') 1411 CALL DPWRST('XXX','BUG ') 1412 DO580JJ=1,NUMVAR 1413 WRITE(ICOUT,578)IVARN3(JJ),IVARN4(JJ),NIV(JJ) 1414 578 FORMAT(' ',2A4,' HAS ',I8,' ELEMENTS') 1415 CALL DPWRST('XXX','BUG ') 1416 580 CONTINUE 1417 WRITE(ICOUT,999) 1418 CALL DPWRST('XXX','BUG ') 1419 WRITE(ICOUT,2007) 1420 CALL DPWRST('XXX','BUG ') 1421 IF(IWIDTH.GE.1)THEN 1422 WRITE(ICOUT,588)(IANS(I),I=1,MIN(100,IWIDTH)) 1423 588 FORMAT(100A1) 1424 CALL DPWRST('XXX','BUG ') 1425 ENDIF 1426 IERROR='YES' 1427 GOTO9000 1428 ENDIF 1429 540 CONTINUE 1430C 1431C ****************************************************** 1432C ** STEP 11-- 1433C ** DUMP THE COMMON VECTOR V(.) OUT ONTO MASS STORAGE 1434C ** SO AS TO PRESERVE THEIR CONTENTS FOR LATER USE 1435C ** (AFTER DPFIT2). THE ABOVE DUMP TO MASS 1436C ** STORAGE IS UNNECESSARY AND IS NOT DONE FOR 1437C ** THE SPECIAL CASE WHEN THE NUMBER OF PARAMETERS IS 1438C ** 0 (A NO-FIT CASE WHEREBY WE ARE REALLY INTERESTED 1439C ** IN GENERATING PREDICTED VALUES AND RESIDUALS 1440C ** FOR A GIVEN FULLY-SPECIFIED MODEL). 1441C ****************************************************** 1442C 1443 ISTEPN='11' 1444 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 1445 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 1446C 1447CCCCC MAY 2009: NO LONGER NEED TO DO THIS 1448 IOP='WRIT' 1449CCCCC CALL DPSWAP(IOP,V,NUMNAM,IHNAME,IHNAM2,IUSE,IN, 1450CCCCC1IVALUE,MAXN,MAXCOL,MAXN2,MAXCO2,MAXIJ2,IBUGA3,ISUBRO,IERROR) 1451CCCCC CALL DPSWAP(IOP,NUMNAM,IHNAME,IHNAM2,IUSE,IN, 1452CCCCC1IVALUE,MAXN2,MAXCO2,MAXIJ2,IBUGA3,ISUBRO,IERROR) 1453C 1454C ******************************************************* 1455C ** STEP 12-- ** 1456C ** BRANCH TO THE APPROPRIATE SUBCASE; THEN COPY ** 1457C ** OVER THE RESPONSE VECTOR TO BE USED IN THE MODEL ** 1458C ** INTO THE VECTOR Y; AND ** 1459C ** COPY OVER THE WEIGHTS INTO THE VECTOR W; ** 1460C ** COPY OVER THE VECTORS THAT WERE USED IN THE MODEL** 1461C ** INTO THE VECTORS X1, X2, X3,X4, AND X5. ** 1462C ** (MAX NUMBER OF ALLOWABLE VECTORS = 5.) ** 1463C ******************************************************* 1464C 1465 ISTEPN='12' 1466 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT')THEN 1467 CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 1468 WRITE(ICOUT,601)N,NUMVAR 1469 601 FORMAT('N,NUMVAR = ',2I8) 1470 CALL DPWRST('XXX','BUG ') 1471 ENDIF 1472C 1473 IF(ICASEQ.EQ.'FULL')THEN 1474 DO615I=1,NLEFT 1475 ISUB(I)=1 1476 615 CONTINUE 1477 NQ=NLEFT 1478 ELSEIF(ICASEQ.EQ.'SUBS')THEN 1479 NIOLD=NLEFT 1480 CALL DPSUBS(NIOLD,ILOCS,NS,IBUGQ,IERROR) 1481 NQ=NIOLD 1482 ELSEIF(ICASEQ.EQ.'FOR')THEN 1483 NIOLD=NLEFT 1484 CALL DPFOR(NIOLD,NFOR,IROW1,IROWN,NLOCAL,ILOCS,NS,IBUGQ,IERROR) 1485 NQ=NFOR 1486 ELSE 1487 DO618I=1,NLEFT 1488 ISUB(I)=1 1489 618 CONTINUE 1490 NQ=NLEFT 1491 ENDIF 1492C 1493 IROW=0 1494 DO4501I=1,NLEFT 1495 IF(ISUB(I).EQ.0)GOTO4501 1496 IROW=IROW+1 1497 4501 CONTINUE 1498C 1499 K=ICOLL 1500 J=0 1501 DO4500I=1,NLEFT 1502 IF(ISUB(I).EQ.0)GOTO4500 1503 J=J+1 1504 IJ=MAXN*(K-1)+I 1505 IF(K.LE.MAXCOL)Y(J)=V(IJ) 1506 IF(K.EQ.MAXCP1)Y(J)=PRED(I) 1507 IF(K.EQ.MAXCP2)Y(J)=RES(I) 1508 IF(K.EQ.MAXCP3)Y(J)=YPLOT(I) 1509 IF(K.EQ.MAXCP4)Y(J)=XPLOT(I) 1510 IF(K.EQ.MAXCP5)Y(J)=X2PLOT(I) 1511 IF(K.EQ.MAXCP6)Y(J)=TAGPLO(I) 1512 4500 CONTINUE 1513C 1514 K=ICOLW 1515 J=0 1516 DO380I=1,NLEFT 1517 W(I)=1.0 1518CCCCC THE FOLLOWING LINE WAS MOVED MARCH 1992 1519CCCCC IF(IWEIGH.EQ.'OFF')GOTO380 1520 IF(ISUB(I).EQ.0)GOTO380 1521 J=J+1 1522CCCCC THE FOLLOWING LINE WAS ADDED MARCH 1992 1523 IF(IWEIGH.EQ.'OFF')GOTO380 1524 IJ=MAXN*(K-1)+I 1525 IF(K.LE.MAXCOL)W(J)=V(IJ) 1526 IF(K.EQ.MAXCP1)W(J)=PRED(I) 1527 IF(K.EQ.MAXCP2)W(J)=RES(I) 1528 IF(K.EQ.MAXCP3)W(J)=YPLOT(I) 1529 IF(K.EQ.MAXCP4)W(J)=XPLOT(I) 1530 IF(K.EQ.MAXCP5)W(J)=X2PLOT(I) 1531 IF(K.EQ.MAXCP6)W(J)=TAGPLO(I) 1532 380 CONTINUE 1533C 1534 IF(ICASFI.EQ.'FIT' .OR. ICASFI.EQ.'RFIT' .OR. 1535 1 ICASFI.EQ.'MFIT')THEN 1536 J=0 1537C 1538 IADJ=0 1539 IF(IFITAC.EQ.'ON' .AND. ICASFI.EQ.'MFIT')THEN 1540 DO383I=1,NLEFT 1541 IF(ISUB(I).EQ.0)GOTO383 1542 J=J+1 1543 XMAT(J)=1.0 1544 383 CONTINUE 1545 IADJ=1 1546 ENDIF 1547C 1548 DO385L=1,NUMVAR 1549 LP1=L+IADJ 1550 K=ICOLV3(L) 1551 J=0 1552 DO386I=1,NLEFT 1553 IF(ISUB(I).EQ.0)GOTO386 1554 J=J+1 1555 IJ=MAXN*(K-1)+I 1556 IF(K.LE.MAXCOL)XMAT((LP1-1)*IROW + J)=V(IJ) 1557 IF(K.EQ.MAXCP1)XMAT((LP1-1)*IROW + J)=PRED(I) 1558 IF(K.EQ.MAXCP2)XMAT((LP1-1)*IROW + J)=RES(I) 1559 IF(K.EQ.MAXCP3)XMAT((LP1-1)*IROW + J)=YPLOT(I) 1560 IF(K.EQ.MAXCP4)XMAT((LP1-1)*IROW + J)=XPLOT(I) 1561 IF(K.EQ.MAXCP5)XMAT((LP1-1)*IROW + J)=X2PLOT(I) 1562 IF(K.EQ.MAXCP6)XMAT((LP1-1)*IROW + J)=TAGPLO(I) 1563 386 CONTINUE 1564 385 CONTINUE 1565 ELSE 1566 K=ICOLV3(1) 1567 J=0 1568 DO381I=1,NLEFT 1569 IF(ISUB(I).EQ.0)GOTO381 1570 J=J+1 1571 IJ=MAXN*(K-1)+I 1572 IF(K.LE.MAXCOL)XMAT(J)=V(IJ) 1573 IF(K.EQ.MAXCP1)XMAT(J)=PRED(I) 1574 IF(K.EQ.MAXCP2)XMAT(J)=RES(I) 1575 IF(K.EQ.MAXCP3)XMAT(J)=YPLOT(I) 1576 IF(K.EQ.MAXCP4)XMAT(J)=XPLOT(I) 1577 IF(K.EQ.MAXCP5)XMAT(J)=X2PLOT(I) 1578 IF(K.EQ.MAXCP6)XMAT(J)=TAGPLO(I) 1579 381 CONTINUE 1580 ENDIF 1581C 1582 NS=J 1583C 1584C ****************************************************** 1585C ** STEP 13-- ** 1586C ** PREPARE FOR ENTRANCE INTO DPFIT2/DPFIT3-- ** 1587C ** SET THE ICON3 VECTOR (WHICH INDICATES WHICH ** 1588C ** PARAMETERS ARE TO BE HELD CONSTANT EQUAL TO 0 ** 1589C ** THROUGHOUT. DEFINE CONSTRAINTS AND LIMITS. ** 1590C ****************************************************** 1591C 1592 ISTEPN='13' 1593 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 1594 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 1595C 1596 DO4195I=1,NUMPAR 1597 ICON3(I)=0 1598 4195 CONTINUE 1599C 1600 IF(NUMCON.GT.0)THEN 1601 DO4700I=1,NUMPAR 1602 DO4800J=1,NUMCON 1603 J2=J 1604 IF(IPARN3(I).EQ.IPARNC(J).AND.IPARN4(I).EQ.IPANC2(J))THEN 1605 IPARO3(I)=IPAROC(J2) 1606 PARLI3(I)=PARLIM(J2) 1607 GOTO4700 1608 ENDIF 1609 4800 CONTINUE 1610 IPARO3(I)='NONE' 1611 4700 CONTINUE 1612 ENDIF 1613C 1614C ****************************************************** 1615C ** STEP 14-- ** 1616C ** CARRY OUT THE ACTUAL FIT ** 1617C ** VIA CALLING ** 1618C ** DPFIT2 (FOR GENERAL MODELS), OR ** 1619C ** DPFIT3 (FOR POLYNOMIAL AND MULTILINEAR MODELS) ** 1620C ****************************************************** 1621C 1622 ISTEPN='14' 1623 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT')THEN 1624 CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 1625 WRITE(ICOUT,999) 1626 CALL DPWRST('XXX','BUG ') 1627 WRITE(ICOUT,6081) 1628 6081 FORMAT('***** FROM DPFIT, AS ABOUT TO CALL DPFIT2/DPFIT3--') 1629 CALL DPWRST('XXX','BUG ') 1630 WRITE(ICOUT,6082)NUMCHA,NLEFT,MAXN,NS,NUMPV,NUMPAR,NUMVAR 1631 6082 FORMAT('NUMCHA,NLEFT,MAXN,NS,NUMPV,NUMPAR,NUMVAR = ',7I8) 1632 CALL DPWRST('XXX','BUG ') 1633 DO6083I=1,NS 1634 WRITE(ICOUT,6084)I,Y(I),XMAT(I),XMAT(I+IROW),W(I) 1635 6084 FORMAT('I,Y(I),XMAT(I,1),XMAT(I+IROW),W(I) = ', 1636 1 I6,2X,7F10.5) 1637 CALL DPWRST('XXX','BUG ') 1638 6083 CONTINUE 1639 WRITE(ICOUT,6085)(MODEL(I),I=1,MIN(120,NUMCHA)) 1640 6085 FORMAT('MODEL(.)--',120A1) 1641 CALL DPWRST('XXX','BUG ') 1642 DO6086J=1,NUMPAR 1643 WRITE(ICOUT,6087)J,IPARN3(J),IPARN4(J),PARAM3(J),ICON3(J) 1644 6087 FORMAT('I,IPARN3(I),IPARN4(I),PARAM3(I),ICON3(I) = ', 1645 1 I8,2X,2A4,E15.7,A4) 1646 CALL DPWRST('XXX','BUG ') 1647 6086 CONTINUE 1648 DO6088J=1,NUMVAR 1649 WRITE(ICOUT,6089)J,IVARN3(J),IVARN4(J),ICOLV3(J) 1650 6089 FORMAT('I,IVARN3(I),IVARN4(I),ICOLV3(I) = ',I8,2X,2A4,2X,I8) 1651 CALL DPWRST('XXX','BUG ') 1652 6088 CONTINUE 1653 WRITE(ICOUT,6091)IBUGA3,IBUGCO,IBUGEV,NUMIND 1654 6091 FORMAT('IBUGA3,IBUGCO,IBUGEV,NUMIND = ',2(A4,2X),A4,I8) 1655 CALL DPWRST('XXX','BUG ') 1656 ENDIF 1657C 1658 IF(ICASFI.EQ.'FIT')THEN 1659 CALL DPFIT2(Y,XMAT,IROW, 1660 1 NUMVAR,IVARN3,IVARN4,W,NS, 1661 1 MODEL,NUMCHA,PARAM3,IPARN3,IPARN4,NUMPAR,ICON3, 1662 1 IANGLU,IPARO3, 1663 1 PARLI3,VSCRT,MAXITS,FITSD,FITPOW,CPUEPS, 1664 1 ITYPEH,IW2HOL,IW22HO,W2HOLD,NWHOLD, 1665 1 IREP,REPSD,REPDF,RESSD,RESDF,PRED2,RES2,ALFCDF, 1666 1 DUMMY1,DUMMY2,DUMMY3,DUMMY4,DUMMY5, 1667 1 ICAPSW,ICAPTY,IFORSW,IFITAU,IAUXDP, 1668 1 IBUGA3,IBUGCO,IBUGEV,ISUBRO,IERROR) 1669 IF(IERROR.EQ.'YES')GOTO8000 1670 ELSE 1671CCCCC JUNE 2002: CHECK TO SEE IF ALPHA PARAMETER DEFINED. 1672C 1673 ALPHA=0.95 1674 IHP='ALPH' 1675 IHP2='A ' 1676 IHWUSE='P' 1677 MESSAG='NO' 1678 CALL CHECKN(IHP,IHP2,IHWUSE, 1679 1 IHNAME,IHNAM2,IUSE,IN,IVALUE,VALUE,NUMNAM,MAXNAM, 1680 1 ISUBN1,ISUBN2,MESSAG,IANS,IWIDTH,ILOCP,IERROR) 1681 IF(IERROR.EQ.'YES')THEN 1682 ALPHA=0.95 1683 ELSE 1684 ALPHA=VALUE(ILOCP) 1685 ENDIF 1686 IF(ALPHA.LE.0.0)THEN 1687 ALPHA=0.95 1688 ELSEIF(ALPHA.GE.1.0.AND.ALPHA.LT.100.0)THEN 1689 ALPHA=ALPHA/100.0 1690 ELSEIF(ALPHA.GE.100.0)THEN 1691 ALPHA=0.95 1692 ENDIF 1693 IF(ALPHA.LT.0.5)ALPHA=1.0-ALPHA 1694C 1695 CALL DPFIT3(Y,XMAT,IROW,PARCOV,MAXPAR, 1696 1 NUMVAR,IVARN3,IVARN4,W,NS, 1697 1 MODEL,NUMCHA,PARAM3,IPARN3,IPARN4,NUMPAR,ICON3, 1698 1 VSCRT,FITSD,FITPOW,ICASFI, 1699 1 IREP,REPSD,REPDF,RESSD,RESDF,PRED2,RES2,ALFCDF,BIC, 1700 1 DUMMY1,DUMMY2,DUMMY4,DUMMY5, 1701 1 IFITAC,ALPHA, 1702 1 RSQUAR,ADJRSQ,APRESS, 1703 1 ICAPSW,ICAPTY,IFORSW,IFITAU,IAUXDP, 1704 1 IBUGA3,IBUGCO,IBUGEV,ISUBRO,IERROR) 1705 IF(IERROR.EQ.'YES')GOTO8000 1706 ENDIF 1707C 1708C *************************************** 1709C ** STEP 15-- ** 1710C ** UPDATE INTERNAL DATAPLOT TABLES ** 1711C *************************************** 1712C 1713 ISTEPN='15' 1714 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 1715 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 1716C 1717 ICOLPR=MAXCP1 1718 ICOLRE=MAXCP2 1719 IREPU='ON' 1720 IRESU='ON' 1721 CALL UPDAPR(ICOLPR,ICOLRE,PRED2,RES2,PRED,RES,ISUB,NLEFT, 1722 1IREPU,REPSD,REPDF,IRESU,RESSD,RESDF,ALFCDF, 1723 1IHNAME,IHNAM2,IUSE,IN,IVALUE,VALUE,NUMNAM,MAXNAM, 1724 1IANS,IWIDTH,ILOCN,IBUGA3,IERROR) 1725C 1726CCCCC JUNE 2002. ADD FOLLOWING PARAMETERS FOR MULTI-LINEAR FIT 1727 IF(ICASFI.EQ.'MFIT')THEN 1728 IH='RSQU' 1729 IH2='ARE ' 1730 VALUE0=RSQUAR 1731 CALL DPADDP(IH,IH2,VALUE0,IHOST1,ISUBN0, 1732 1 IHNAME,IHNAM2,IUSE,VALUE,IVALUE,NUMNAM,MAXNAM, 1733 1 IANS,IWIDTH,IBUGA3,IERROR) 1734C 1735 IH='ADJR' 1736 IH2='SQUA' 1737 VALUE0=ADJRSQ 1738 CALL DPADDP(IH,IH2,VALUE0,IHOST1,ISUBN0, 1739 1 IHNAME,IHNAM2,IUSE,VALUE,IVALUE,NUMNAM,MAXNAM, 1740 1 IANS,IWIDTH,IBUGA3,IERROR) 1741C 1742 IH='PRES' 1743 IH2='SP ' 1744 VALUE0=APRESS 1745 CALL DPADDP(IH,IH2,VALUE0,IHOST1,ISUBN0, 1746 1 IHNAME,IHNAM2,IUSE,VALUE,IVALUE,NUMNAM,MAXNAM, 1747 1 IANS,IWIDTH,IBUGA3,IERROR) 1748C 1749 IH='BIC ' 1750 IH2=' ' 1751 VALUE0=BIC 1752 CALL DPADDP(IH,IH2,VALUE0,IHOST1,ISUBN0, 1753 1 IHNAME,IHNAM2,IUSE,VALUE,IVALUE,NUMNAM,MAXNAM, 1754 1 IANS,IWIDTH,IBUGA3,IERROR) 1755 ENDIF 1756C 1757 IF(ICASFI.EQ.'FIT')GOTO7900 1758 IF(ICASFI.EQ.'RFIT')GOTO7900 1759C 1760CCCCC THE FOLLOWING SECTION (DOWN TO 7640 CONTINUE) WAS REWRITTEN MAY 1989 1761 IF(ICASFI.EQ.'MFIT')K1=NUMPAR 1762 L=0 1763 DO7600J=1,K1 1764 JM1=J-1 1765 L=L+1 1766 IH=' ' 1767 IH2=' ' 1768 CALL DPCOIH(JM1,IHOUT,NOUT,IVALID,IBUGA3,ISUBRO,IERROR) 1769 IHOUT1=IHOUT(1) 1770 IHOUT2=IHOUT(2) 1771 IHOUT3=IHOUT(3) 1772 IH(1:1)='A' 1773 IF(NOUT.GE.1)IH(2:2)=IHOUT1(1:1) 1774 IF(NOUT.GE.2)IH(3:3)=IHOUT2(1:1) 1775 IF(NOUT.GE.3)IH(4:4)=IHOUT3(1:1) 1776C 1777 DO7650I=1,NUMNAM 1778 I2=I 1779 IF(IH.EQ.IHNAME(I).AND.IH2.EQ.IHNAM2(I).AND. 1780 1 IUSE(I).EQ.'P')THEN 1781 VALUE(I2)=PARAM3(L) 1782 VAL=VALUE(I2) 1783 IF((-CUTOFF).LE.VAL.AND.VAL.LE.CUTOFF)IVAL=INT(VAL+0.5) 1784 IF(VAL.GT.CUTOFF)IVAL=INT(CUTOFF) 1785 IF(VAL.LT.(-CUTOFF))IVAL=INT(-CUTOFF) 1786 IVALUE(I2)=IVAL 1787 GOTO7600 1788 ENDIF 1789 7650 CONTINUE 1790 IF(NUMNAM.GE.MAXNAM)THEN 1791 WRITE(ICOUT,2001) 1792 CALL DPWRST('XXX','BUG ') 1793 WRITE(ICOUT,7652) 1794 7652 FORMAT(' THE TOTAL NUMBER OF (VARIABLE + PARAMETER)') 1795 CALL DPWRST('XXX','BUG ') 1796 WRITE(ICOUT,7653)MAXNAM 1797 7653 FORMAT(' NAMES MUST BE AT MOST ',I8) 1798 CALL DPWRST('XXX','BUG ') 1799 WRITE(ICOUT,7654) 1800 7654 FORMAT(' SUCH WAS NOT THE CASE HERE--THE MAXIMUM ', 1801 1 'ALLOWABLE') 1802 CALL DPWRST('XXX','BUG ') 1803 WRITE(ICOUT,7656) 1804 7656 FORMAT(' NUMBER OF NAMES WAS JUST EXCEEDED.') 1805 CALL DPWRST('XXX','BUG ') 1806 WRITE(ICOUT,7657) 1807 7657 FORMAT(' SUGGESTED ACTION--ENTER STAT TO DETERMINE') 1808 CALL DPWRST('XXX','BUG ') 1809 WRITE(ICOUT,7659) 1810 7659 FORMAT(' THE IMPORTANT (VERSUS UNIMPORTANT) VARIABLES ', 1811 1 'AND') 1812 CALL DPWRST('XXX','BUG ') 1813 WRITE(ICOUT,7660) 1814 7660 FORMAT(' PARAMETERS, AND THEN REUSE SOME OF THE NAMES.') 1815 CALL DPWRST('XXX','BUG ') 1816 WRITE(ICOUT,2007) 1817 CALL DPWRST('XXX','BUG ') 1818 IF(IWIDTH.GE.1)THEN 1819 WRITE(ICOUT,2008)(IANS(I),I=1,MIN(100,IWIDTH)) 1820 CALL DPWRST('XXX','BUG ') 1821 ENDIF 1822 IERROR='YES' 1823 GOTO9000 1824 ENDIF 1825C 1826 NUMNAM=NUMNAM+1 1827 ILOC=NUMNAM 1828 IHNAME(ILOC)=IH 1829 IHNAM2(ILOC)=IH2 1830 IUSE(ILOC)='P' 1831 VALUE(ILOC)=PARAM3(L) 1832 VAL=VALUE(ILOC) 1833 IF((-CUTOFF).LE.VAL.AND.VAL.LE.CUTOFF)IVAL=INT(VAL+0.5) 1834 IF(VAL.GT.CUTOFF)IVAL=INT(CUTOFF) 1835 IF(VAL.LT.(-CUTOFF))IVAL=INT(-CUTOFF) 1836 IVALUE(ILOC)=IVAL 1837C 1838 7600 CONTINUE 1839 7900 CONTINUE 1840C 1841C ****************************************************** 1842C ** STEP 16-- 1843C ** READ BACK IN FROM MASS STORAGE 1844C ** THE CONTENTS OF THE V(.) VECTOR. THE ABOVE 1845C ** RETRIEVAL FROM MASS STORAGE IS UNNECESSARY AND IS 1846C ** FOR THE SPECIAL CASE WHEN THE NUMBER OF PARAMETERS 1847C ** IS 0 (A NO-FIT CASE WHEREBY WE ARE REALLY 1848C ** INTERESTED IN GENERATING PREDICTED VALUES 1849C ** AND RESIDUALS FOR A GIVEN FULLY-SPECIFIED MODEL). 1850C ****************************************************** 1851C 1852 8000 CONTINUE 1853C 1854 ISTEPN='16' 1855 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 1856 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 1857C 1858C ************************************************* 1859C ** STEP 17-- ** 1860C ** COPY THE FINAL ESTIMATES FROM THE FIT ** 1861C ** BACK INTO THE PARAMETERS. ** 1862C ** THESE FINAL ESTIMATES WILL THUS OVERWRITE ** 1863C ** THE STARTING VALUES THAT WERE ** 1864C ** ORIGINALLY ASSIGNED TO THE PARAMETERS. ** 1865C ************************************************* 1866C 1867 ISTEPN='17' 1868 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT') 1869 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 1870C 1871 IF(NUMPAR.GT.0)THEN 1872 DO6100J=1,NUMPAR 1873 IH=IPARN3(J) 1874 IH2=IPARN4(J) 1875 IHWUSE='P' 1876 MESSAG='YES' 1877 CALL CHECKN(IH,IH2,IHWUSE, 1878 1 IHNAME,IHNAM2,IUSE,IN,IVALUE,VALUE,NUMNAM,MAXNAM, 1879 1 ISUBN1,ISUBN2,MESSAG,IANS,IWIDTH,ILOCP,IERROR) 1880 IF(IERROR.EQ.'YES')GOTO9000 1881 VALUE(ILOCP)=PARAM3(J) 1882 VAL=VALUE(ILOCP) 1883 IF((-CUTOFF).LE.VAL.AND.VAL.LE.CUTOFF)IVAL=INT(VAL+0.5) 1884 IF(VAL.GT.CUTOFF)IVAL=INT(CUTOFF) 1885 IF(VAL.LT.(-CUTOFF))IVAL=INT(-CUTOFF) 1886 IVALUE(ILOCP)=IVAL 1887 6100 CONTINUE 1888 ENDIF 1889C 1890C ***************** 1891C ** STEP 90-- ** 1892C ** EXIT ** 1893C ***************** 1894C 1895 9000 CONTINUE 1896 IF(IBUGA2.EQ.'ON'.OR.ISUBRO.EQ.'PFIT')THEN 1897 WRITE(ICOUT,999) 1898 CALL DPWRST('XXX','BUG ') 1899 WRITE(ICOUT,9011) 1900 9011 FORMAT('***** AT THE END OF DPFIT--') 1901 CALL DPWRST('XXX','BUG ') 1902 WRITE(ICOUT,9015)NS,NUMNAM,ICASFI,ICASEQ 1903 9015 FORMAT('NS,NUMNAM,ICASFI,ICASEQ = ',2I8,2X,A4,2X,A4) 1904 CALL DPWRST('XXX','BUG ') 1905 DO9017I=1,NUMNAM 1906 WRITE(ICOUT,9018)I,IHNAME(I),IHNAM2(I),IUSE(I),IN(I), 1907 1 IVALUE(I),VALUE(I) 1908 9018 FORMAT('I,IHNAME(I),IHNAM2(I),IUSE(I),IN(I),IVALUE(I)', 1909 1 'VALUE(I) = ',I8,2X,2A4,2X,A4,2I8,G15.7) 1910 CALL DPWRST('XXX','BUG ') 1911 9017 CONTINUE 1912 WRITE(ICOUT,9021)NUMIND,NUMPV,NUMVAR,IP,IV 1913 9021 FORMAT('NUMIND,NUMPV,NUMVAR,IP,IV = ',5I8) 1914 CALL DPWRST('XXX','BUG ') 1915 IF(NUMPV.GT.0)THEN 1916 DO9022I=1,NUMPV 1917 WRITE(ICOUT,9023)I,IPARN(I),IPARN2(I) 1918 9023 FORMAT('I,IPARN(I),IPARN2(I) = ',I8,2X,2A4) 1919 CALL DPWRST('XXX','BUG ') 1920 9022 CONTINUE 1921 ENDIF 1922 IF(IP.GT.0)THEN 1923 DO9032I=1,IP 1924 WRITE(ICOUT,9033)I,IPARN3(I),IPARN4(I) 1925 9033 FORMAT('I,IPARN3(I),IPARN4(I) = ',I8,2X,2A4) 1926 CALL DPWRST('XXX','BUG ') 1927 9032 CONTINUE 1928 ENDIF 1929 IF(IV.GT.0)THEN 1930 DO9042I=1,IV 1931 WRITE(ICOUT,9043)I,IVARN3(I),IVARN4(I) 1932 9043 FORMAT('I,IVARN3(I),IVARN4(I) = ',I8,2X,2A4) 1933 CALL DPWRST('XXX','BUG ') 1934 9042 CONTINUE 1935 ENDIF 1936 WRITE(ICOUT,9051)MAXN2,NLEFT,NS,V(1),PRED(1),RES(1) 1937 9051 FORMAT('MAXN2,NLEFT,NS,V(1),PRED(1),RES(1) = ',3I8,3G15.7) 1938 CALL DPWRST('XXX','BUG ') 1939 WRITE(ICOUT,9053)IWIDTH,ICOLW,NWEIGH,IWIDMO,IWEIGH 1940 9053 FORMAT('IWIDTH,ICOLW,NWEIGH,IWIDMO,IWEIGH = ',4I8,2X,A4) 1941 CALL DPWRST('XXX','BUG ') 1942 IF(IWIDTH.GE.1)THEN 1943 WRITE(ICOUT,2008)(IANS(I),I=1,MIN(100,IWIDTH)) 1944 CALL DPWRST('XXX','BUG ') 1945 ENDIF 1946 IF(IWIDMO.GE.1)THEN 1947 WRITE(ICOUT,9064)(MODEL(I),I=1,MIN(IWIDMO,100)) 1948 9064 FORMAT('(MODEL(I),I=1,IWIDMO) = ',100A1) 1949 CALL DPWRST('XXX','BUG ') 1950 ENDIF 1951 WRITE(ICOUT,9069)IFOUND,IERROR 1952 9069 FORMAT('IFOUND,IERROR = ',A4,2X,A4) 1953 CALL DPWRST('XXX','BUG ') 1954 ENDIF 1955C 1956 RETURN 1957 END 1958 SUBROUTINE DPFIT2(Y,XMAT,IROW, 1959 1 NUMVAR,IVARN3,IVARN4,W,N, 1960 1 MODEL,NUMCHA,PARAM3,IPARN3,IPARN4,NUMPAR, 1961 1 ICON3,IANGLU,IPARO3, 1962 1 PARLI3,V,MAXITS,FITSD,FITPOW,CPUEPS, 1963 1 ITYPEH,IW2HOL,IW22HO,W2HOLD,NWHOLD, 1964 1 IREP,REPSD,REPDF,RESSD,RESDF,PRED2,RES2,ALFCDF, 1965 1 DUM1,DUM2,Y2,WSQRT,G, 1966 1 ICAPSW,ICAPTY,IFORSW,IFITAU,IAUXDP, 1967 1 IBUGA3,IBUGCO,IBUGEV,ISUBRO,IERROR) 1968C 1969CCCCC JUNE 1990. ADD DUM1 - G ARGUMENTS (DIMENSIONED IN DPFIT) 1970CCCCC SEPT. 1991. ARGS X6 TO X15 ABOVE ARE NEW. 1971CCCCC JULY 2019. REPLACE X1 ... X15 WITH XMAT 1972C 1973C LEVENBERG, MARQUARDT, MORRISON ALGORITHM IMPLEMENTED FOLLOWING 1974C SUGGESTION OF GOLUB (SEE OSBORNE 'SOME ASPECTS OF NONLINEAR LEAST 1975C SQUARES CALCULATION' EDITOR F.A. LOOTSMA ACADEMIC PRESS). MAIN 1976C FEATURE OF THIS ROUTINE IS AN IMPROVED TEST FOR ACCEPTING 1977C PREDICTED CORRECTION AND ADJUSTING LEVENBERG PARAMETER ALAMBA 1978C 1979C VARIABLES 1980C 1981C PARAM3(1) VECTOR OF INDEPENDENT VARIABLES 1982C INPUT. CONTAINS ESTIMATE OF SOLUTION 1983C OUTPUT. CONTAINS SOLUTION VECTOR OR LAST ATTEMPT 1984C 1985C V(1) STORAGE OF GRAD F BY COLUMNS 1986C I.E., THE DERIVATIVES EVALUATED AT EACH OF THE N DATA POINTS 1987C OF THE N RESIDUALS RES2(I) WITH RESPECT TO 1988C THE FIRST PARAMETER FOLLOWED BY ALL THE DERIVATIVES 1989C WITH RESPECT TO THE SECOND PARAMETER, ETC. 1990C 1991C RES2(1) STORAGE FOR F VECTOR OF TERMS IN SUM OF SQUARES 1992C OUTPUT. VECTOR OF TERMS (USALLY RESIDUALS) IN SUM 1993C OF SQUARES 1994C 1995C SUMSQ OUTPUT. CONTAINS SUM OF SQUARES 1996C 1997C N INPUT. NO. OF TERMS IN SUM OF SQUARES = NUMBER OF OBSERVATIONS. 1998C 1999C NP INPUT. NO. OF PARAMETERS INCLUDING ANY TO BE HELD CONSTANT 2000C 2001C TOL INPUT. TOLERANCE ON CALCULATION OF SUM OF SQUARES 2002C 2003C EXPND OUTPUT. FACTOR BY WHICH ALAMBA INCREASED IF TEST ON SUM OF 2004C SQUARES FAILS, SUGGESTED VALUE 1.5 2005C 2006C COMPR INPUT. FACTOR BY WHICH ALAMBA COMPREASED IF TEST ON SUM OF 2007C SQUARES SUCCEEDS ON FIRST ATTEMPT, SUGGESTED VALUE 0.5 2008C 2009C ITS INPUT. MAX NUMBER OF ITERATIONS 2010C OUTPUT. ACTUAL NUMBER OF ITERATIONS 2011C 2012C IER INPUT.=-1+(100*NCONST) NO PRINTING 2013C =0+(100*NCONST) PRINTING AFTER CONVERGENCE ONLY 2014C =1+(100*NCONST) PRINT DIAGNOSTIC INFORMATION 2015C =2+(100*NCONST) AS ABOVE PLUS GRADIENT CHECK 2016C WHERE NCONST = NO. OF PARAMETERS TO BE HELD CONSTANT 2017C OUTPUT.=1 SUCCESSUL TERMINATION 2018C =2 MAX ITS EXCEEDED 2019C =3 ALAMBA EXCEEDS 1.D6 2020C =4 ALL GRADIENTS ZERO FOR ONE OR MORE PARAMETERS 2021C =5 NO. OF PARAMETERS LESS THAN ONE 2022C 2023C C(1) OUTPUT. CONTAINS APPROXIMATE 2024C STANDARD ERRORS OF PARAMETER ESTIMATES 2025C 2026C G(1) OUTPUT. CONTAINS A VECTOR OF UNCORRELATED RESIDUALS 2027C 2028C WS(1) WORKING SPACE, MUST BE ALLOTTED AT LEAST 2029C NPR*(NPR+5) + NCONST IN CALLING PROGRAM, 2030C WHERE NCONST IS THE NUMBER OF PARAMETERS TO BE HELD 2031C CONSTANT AND NPR = NP - NCONST. 2032C 2033C ICON3(1) INPUT. ICON3(1)=1 IF THE I-TH PARAMETER IS TO BE HELD 2034C CONSTANT 2035C =0 OTHERWISE 2036C 2037C 2038C USER SUPPLIED SUBROUTINE F REQUIRED TO SET VALUES OF SUMSQ, 2039C F,A DECLARATION MUST BE 2040C SUBROUTINE F (X,N,PARAM3,NUMPAR,F,A,SUMSQ,IFL) 2041C IF IFL=1 SETS ALL VALUES 2042C IF IFL=2 SETS SUMSQ ONLY MUST NOT ALTER A,F 2043C 2044C N.B. THE VALUE OF ILF IS SUPPLIED BY DPFIT2 AND MUST NOT BE CHANGED 2045C 2046C EPS IS A MACHINE-DEPENDENT CONSTANT. 2047C 2048C NOTE--MAX NUMBER OF OBSERVATIONS N IS 1000 (NOT CHECKED FOR) 2049C NOTE--MAX NUMBER OF PARAMETERS K IS 30 (NOT CHECKED FOR) 2050C NOTE--DIMENSION OF G IS N (MAX IS 1000) 2051C NOTE--DIMENSION OF C IS K (MAX IS 30) 2052C NOTE--DIMENSION OF A IS N X K (BUT N X K MAX IS 10000) 2053C 2054C 2055C WRITTEN BY--JAMES J. FILLIBEN 2056C STATISTICAL ENGINEERING DIVISION 2057C CENTER FOR APPLIED MATHEMATICS 2058C NATIONAL BUREAU OF STANDARDS 2059C WASHINGTON, D. C. 20234 2060C PHONE--301-975-2855 2061C NOTE--DATAPLOT IS A REGISTERED TRADEMARK 2062C OF THE NATIONAL BUREAU OF STANDARDS. 2063C LANGUAGE--ANSI FORTRAN (1977) 2064C VERSION NUMBER--82/7 2065C ORIGINAL VERSION--DECEMBER 26, 1977. 2066C UPDATED --JULY 1978. 2067C UPDATED --NOVEMBER 1978. 2068C UPDATED --OCTOBER 1978. 2069C UPDATED --FEBRUARY 1979. 2070C UPDATED --JUNE 1979. 2071C UPDATED --JULY 1979. 2072C UPDATED --MARCH 1981. 2073C UPDATED --JULY 1981. 2074C UPDATED --OCTOBER 1981. 2075C UPDATED --NOVEMBER 1981. 2076C UPDATED --MARCH 1982. 2077C UPDATED --MAY 1982. 2078C UPDATED --AUGUST 1987. WEIGHTED FIT 2079C UPDATED --JANUARY 1988. FIX WEIGHTED FIT PRED & RES 2080C UPDATED --MARCH 1988. ADD LOFCDF 2081C UPDATED --JUNE 1990. MOVE SOME DIMENSIONS TO DPFIT 2082C UPDATED --JULY 1990. FIX OVERFLOW 2083C UPDATED --SEPT 1991. EXPAND IND. VAR. 5 TO 15 2084C UPDATED --MARCH 1992. FIX FORMAT MESSAGE 2085C UPDATED --MARCH 1992. WRITE COEF SDCOEF TCDF TO FILE 2086C UPDATED --MARCH 1992. ISUBRO ADDED TO INPUT ARG LIST 2087C UPDATED --FEBRUARY 1994. ACTIVATE FITSD TEST 2088C UPDATED --MAY 1994. FIX (= SPLIT) FORMAT 1122 2089C UPDATED --MAY 1994. CORRECT AN OVERFLOW DIVISION 2090C UPDATED --MAY 1995. FIX SOME I/O 2091C UPDATED --APRIL 1996. IPRINT SWITCH 2092C UPDATED --JULY 1997. PRINT SUMMARY INFORMATION IF 2093C MAXIMUM ITERATIONS REACHED 2094C UPDATED --FEBRUARY 1998. CALL DPFLSH (FOR GUI) 2095C UPDATED --APRIL 2001. PRINT OUT VAR-COV MATRIX 2096C UPDATED --NOVEMBER 2002. CAPTURE HTML, LATEX 2097C UPDATED --MAY 2011. USE DPAUFI TO OPEN/CLOSE 2098C DPST?F.DAT FILES 2099C UPDATED --MAY 2011. USE DPDTA1 AND DPDT5B TO 2100C PRINT OUTPUT 2101C UPDATED --JUNE 2014. USER OPTION TO SUPPRESS 2102C WRITING TO AUXILLARY FILES 2103C UPDATED --APRIL 2019. USER CAN SPECIFY NUMBER OF 2104C DECIMAL POINTS FOR AUXILLARY 2105C FILES 2106C UPDATED --JULY 2019. REPLACE X1 ... X15 WITH XMAT 2107C 2108C-----CHARACTER STATEMENTS FOR NON-COMMON VARIABLES------------------- 2109C 2110 CHARACTER*4 ICAPSW 2111 CHARACTER*4 ICAPTY 2112 CHARACTER*4 IFORSW 2113 CHARACTER*4 IFITAU 2114C 2115 CHARACTER*4 IVARN3 2116 CHARACTER*4 IVARN4 2117 CHARACTER*4 IPARN3 2118 CHARACTER*4 IPARN4 2119 CHARACTER*4 IANGLU 2120 CHARACTER*4 IPARO3 2121 CHARACTER*4 ITYPEH 2122 CHARACTER*4 IW2HOL 2123 CHARACTER*4 IW22HO 2124 CHARACTER*4 IREP 2125 CHARACTER*4 IBUGA3 2126 CHARACTER*4 IBUGCO 2127 CHARACTER*4 IBUGEV 2128 CHARACTER*4 ISUBRO 2129 CHARACTER*4 IERROR 2130 CHARACTER*4 IFOUND 2131C 2132 CHARACTER*4 IPARN5 2133 CHARACTER*4 IPARN6 2134 CHARACTER*4 ISUBN1 2135 CHARACTER*4 ISUBN2 2136 CHARACTER*4 ISTEPN 2137 CHARACTER*4 MODEL 2138 CHARACTER*4 IOP 2139 CHARACTER*20 IFORMT 2140C 2141 PARAMETER(NUMCLI=10) 2142 PARAMETER(MAXLIN=3) 2143 PARAMETER (MAXROW=60) 2144 CHARACTER*60 ITITLE 2145 CHARACTER*60 ITITLZ 2146 CHARACTER*60 ITITL9 2147 CHARACTER*50 ITEXT(MAXROW) 2148 CHARACTER*4 ALIGN(NUMCLI) 2149 CHARACTER*4 VALIGN(NUMCLI) 2150 REAL AVALUE(MAXROW) 2151 INTEGER NCTEXT(MAXROW) 2152 INTEGER IDIGIT(MAXROW) 2153 INTEGER IDIGI2(MAXROW,NUMCLI) 2154 INTEGER NTOT(MAXROW) 2155 INTEGER ROWSEP(MAXROW) 2156 CHARACTER*60 ITITL2(MAXLIN,NUMCLI) 2157 CHARACTER*20 IVALUE(MAXROW,NUMCLI) 2158 CHARACTER*4 ITYPCO(NUMCLI) 2159 INTEGER NCTIT2(MAXLIN,NUMCLI) 2160 INTEGER NCVALU(MAXROW,NUMCLI) 2161 INTEGER NCOLSP(MAXLIN,NUMCLI) 2162 INTEGER IWHTML(NUMCLI) 2163 INTEGER IWRTF(NUMCLI) 2164 REAL AMAT(MAXROW,NUMCLI) 2165 LOGICAL IFRST 2166 LOGICAL ILAST 2167 LOGICAL IFLAGS 2168 LOGICAL IFLAGE 2169C 2170C--------------------------------------------------------------------- 2171C 2172 DOUBLE PRECISION SUM,SSS,SSINIT,SSR,WW,SSN,SUMSQ 2173 DOUBLE PRECISION S 2174 DOUBLE PRECISION DS1,DS2,DTOL 2175 DOUBLE PRECISION DRAT1,DRAT2 2176 DOUBLE PRECISION DEPS,DTOL2,DRAT 2177C 2178C--------------------------------------------------------------------- 2179C 2180 INCLUDE 'DPCOPA.INC' 2181C 2182CCCCC THE FOLLOWING INCLUDE STATEMENT WAS ADDED MARCH 1992 2183 INCLUDE 'DPCOF2.INC' 2184C 2185 DIMENSION Y(*) 2186 DIMENSION XMAT(IROW,*) 2187 DIMENSION PRED2(*) 2188 DIMENSION RES2(*) 2189 DIMENSION W(*) 2190 DIMENSION V(*) 2191 DIMENSION DUM1(*) 2192 DIMENSION DUM2(*) 2193 DIMENSION Y2(*) 2194 DIMENSION WSQRT(*) 2195 DIMENSION G(*) 2196C 2197 DIMENSION MODEL(*) 2198 DIMENSION IVARN3(*) 2199 DIMENSION IVARN4(*) 2200 DIMENSION PARAM3(*) 2201 DIMENSION IPARN3(*) 2202 DIMENSION IPARN4(*) 2203 DIMENSION ICON3(*) 2204 DIMENSION IPARO3(*) 2205 DIMENSION PARLI3(*) 2206C 2207 DIMENSION ITYPEH(*) 2208 DIMENSION IW2HOL(*) 2209 DIMENSION IW22HO(*) 2210 DIMENSION W2HOLD(*) 2211C 2212 DIMENSION IPARN5(30) 2213 DIMENSION IPARN6(30) 2214 DIMENSION PARAM5(30) 2215C 2216 DIMENSION WS(1100) 2217 DIMENSION DUM(30) 2218 DIMENSION C(15) 2219 DIMENSION TVALU2(15) 2220 DIMENSION PARAM7(30) 2221 DIMENSION PARAM9(30) 2222 DIMENSION VARCOV(30,30) 2223 DIMENSION CORR(30,30) 2224C 2225C--------------------------------------------------------------------- 2226C 2227 INCLUDE 'DPCOP2.INC' 2228C 2229C-----START POINT----------------------------------------------------- 2230C 2231 ISUBN1='DPFI' 2232 ISUBN2='T2 ' 2233 IERROR='NO' 2234C 2235 KMIN=0 2236 KMAX=0 2237 IY=0 2238 IDX=0 2239 IDU=0 2240 IDA=0 2241 ID=0 2242 NTEMP=0 2243 NPST=0 2244 CDF2=0.0 2245 S=0.0 2246 DS3=0.0 2247C 2248 NUMDIG=7 2249 IF(IFORSW.EQ.'1')NUMDIG=1 2250 IF(IFORSW.EQ.'2')NUMDIG=2 2251 IF(IFORSW.EQ.'3')NUMDIG=3 2252 IF(IFORSW.EQ.'4')NUMDIG=4 2253 IF(IFORSW.EQ.'5')NUMDIG=5 2254 IF(IFORSW.EQ.'6')NUMDIG=6 2255 IF(IFORSW.EQ.'7')NUMDIG=7 2256 IF(IFORSW.EQ.'8')NUMDIG=8 2257 IF(IFORSW.EQ.'9')NUMDIG=9 2258 IF(IFORSW.EQ.'0')NUMDIG=0 2259 IF(IFORSW.EQ.'E')NUMDIG=-2 2260 IF(IFORSW.EQ.'-2')NUMDIG=-2 2261 IF(IFORSW.EQ.'-3')NUMDIG=-3 2262 IF(IFORSW.EQ.'-4')NUMDIG=-4 2263 IF(IFORSW.EQ.'-5')NUMDIG=-5 2264 IF(IFORSW.EQ.'-6')NUMDIG=-6 2265 IF(IFORSW.EQ.'-7')NUMDIG=-7 2266 IF(IFORSW.EQ.'-8')NUMDIG=-8 2267 IF(IFORSW.EQ.'-9')NUMDIG=-9 2268C 2269CCCCC THE FOLLOWING LINE WAS ADDED TO FIX OVERFLOW JULY 1990 2270 CPUMA2=CPUMAX/1000.0 2271C 2272 IF(IBUGA3.EQ.'ON' .OR. ISUBRO.EQ.'FIT2')THEN 2273 WRITE(ICOUT,999) 2274 999 FORMAT(1X) 2275 CALL DPWRST('XXX','BUG ') 2276 WRITE(ICOUT,51) 2277 51 FORMAT('***** AT THE BEGINNING OF DPFIT2--') 2278 CALL DPWRST('XXX','BUG ') 2279 WRITE(ICOUT,52)N,NUMVAR,NUMPAR,NUMCHA 2280 52 FORMAT('N,NUMVAR,NUMPAR,NUMCHA = ',4I8) 2281 CALL DPWRST('XXX','BUG ') 2282 WRITE(ICOUT,53)IBUGA3,IBUGCO,IBUGEV,ISUBRO,IFITAC 2283 53 FORMAT('IBUGA3,IBUGCO,IBUGEV,ISUBRO,IFITAC = ',4(A4,2X),A4) 2284 CALL DPWRST('XXX','BUG ') 2285 WRITE(ICOUT,59)CPUEPS,FITPOW,FITSD 2286 59 FORMAT('CPUEPS,FITPOW,FITSD = ',3G15.7) 2287 CALL DPWRST('XXX','BUG ') 2288 DO55I=1,N 2289 WRITE(ICOUT,56)I,Y(I),XMAT(I,1),W(I) 2290 56 FORMAT('I,Y(I),XMAT(I,1),W(I) = ',I5,3F20.10) 2291 CALL DPWRST('XXX','BUG ') 2292 55 CONTINUE 2293 DO61J=1,NUMVAR 2294 WRITE(ICOUT,62)J,IVARN3(J),IVARN4(J) 2295 62 FORMAT('I,IVARN3(I),IVARN4(I) = ',I8,2X,A4,A4) 2296 CALL DPWRST('XXX','BUG ') 2297 61 CONTINUE 2298 DO66J=1,NUMPAR 2299 WRITE(ICOUT,67)J,IPARN3(J),IPARN4(J),PARAM3(J),ICON3(J) 2300 67 FORMAT('I,IPARN3(I),IPARN4(I),PARAM3(I),ICON3(I) = ', 2301 1 I8,2X,2A4,G15.7,I8) 2302 CALL DPWRST('XXX','BUG ') 2303 66 CONTINUE 2304 NTEMP=MIN(NUMCHA,100) 2305 WRITE(ICOUT,71)(MODEL(J),J=1,NTEMP) 2306 71 FORMAT('FUNCTIONAL EXPRESSION--',100A1) 2307 CALL DPWRST('XXX','BUG ') 2308 ENDIF 2309C 2310CCCCCC THE FOLLOWING SECTION WAS ADDED MARCH 1992 2311C ************************************************** 2312C ** STEP 0.5-- ** 2313C ** OPEN THE STORAGE FILES ** 2314C ************************************************** 2315C 2316 ISTEPN='0.5' 2317 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2') 2318 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 2319C 2320 IF(IFITAU.EQ.'ON')THEN 2321 IOP='OPEN' 2322 IFLAG1=1 2323 IFLAG2=1 2324 IFLAG3=1 2325 IFLAG4=0 2326 IFLAG5=0 2327 CALL DPAUFI(IOP,IFLAG1,IFLAG2,IFLAG3,IFLAG4,IFLAG5, 2328 1 IOUNI1,IOUNI2,IOUNI3,IOUNI4,IOUNI5, 2329 1 IBUGA3,ISUBRO,IERROR) 2330 IF(IERROR.EQ.'YES')GOTO9000 2331 ENDIF 2332C 2333C ************************************************** 2334C ** STEP 1-- ** 2335C ** DETERMINE THE PARAMETER NAMES IN THE MODEL ** 2336C ** AND THE NUMBER NUMPAR OF PARAMETERS. ** 2337C ************************************************** 2338C 2339 ISTEPN='1' 2340 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2') 2341 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 2342C 2343 IPASS=2 2344C 2345 IF(NUMPAR.GT.0)THEN 2346 DO7100I=1,NUMPAR 2347 IPARN5(I)=IPARN3(I) 2348 IPARN6(I)=IPARN4(I) 2349 PARAM5(I)=PARAM3(I) 2350 7100 CONTINUE 2351 ENDIF 2352C 2353 IF(NUMVAR.GT.0)THEN 2354 DO7300I=1,NUMVAR 2355 IPARN5(NUMPAR+I)=IVARN3(I) 2356 IPARN6(NUMPAR+I)=IVARN4(I) 2357 7300 CONTINUE 2358 ENDIF 2359C 2360 NUMPV=NUMPAR+NUMVAR 2361C 2362C ****************************************************** 2363C ** STEP 2-- ** 2364C ** DEFINE VARIOUS CONSTANTS. ** 2365C ** DEFINE EPS = MACHINE EPSILON. ** 2366C ** DEFINE TOL = CUTOFF TOLERANCE FOR SUCCESSIVE ** 2367C ** ESTIMATES. ** 2368C ** DEFINE MAXITS = MAX NUMBER OF ITERATIONS. ** 2369C ** DEFINE EXPND = EXPANSION FACTOR ** 2370C ** DEFINE COMPR = COMPRESSION FACTOR ** 2371C ** DEFINE NCONST = NUMBER OF PARAMETERS HELD ** 2372C ** CONSTANT. ** 2373C ** DEFINE NP = NUMBER OF NON-CONSTNAT PARAMETERS. ** 2374C ** DEFINE DF = DEGREES OF FREEDOM. ** 2375C ** DEFINE SOME WORKING STORAGE START POINTS IN WS. ** 2376C ****************************************************** 2377C 2378 ISTEPN='2' 2379 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2') 2380 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 2381C 2382 IREP='NO' 2383 REPSD=0.0 2384 REPDF=0.0 2385 IREPDF=INT(REPDF+0.5) 2386 RESSD=0.0 2387 RESDF=0.0 2388 ALFCDF=(-999.99) 2389 IF(NUMPAR.GT.0)THEN 2390 EPS = 1.E-8 2391 DEPS=EPS 2392 TOL=0.00001 2393 DTOL=TOL 2394 ALAMBA=0.01 2395 EXPND=1.5 2396 COMPR=0.5 2397 NPST=NUMPAR 2398 NCONST=0 2399 DO501I=1,NUMPAR 2400 IF(ICON3(I).EQ.1)NCONST=NCONST+1 2401 501 CONTINUE 2402 NP=NUMPAR-NCONST 2403 IF(NP.LE.0) THEN 2404 WRITE(ICOUT,117) NP 2405117 FORMAT(10X,'NUMBER OF PARAMETERS TO BE VARIED = ',I8, 2406 * ' (LESS THAN ONE)') 2407 CALL DPWRST('XXX','BUG ') 2408 IER = 5 2409 IERROR='YES' 2410 GOTO9000 2411 ENDIF 2412 DF=N-NP 2413 RESDF=DF 2414 IRESDF=INT(DF+0.5) 2415 IC=0 2416 IER=2 2417 IDA=NP*NP 2418 IDU=IDA+NP 2419 ID =IDU+NP 2420 IDX=ID +NP 2421 IY =IDX+NP 2422 ENDIF 2423C 2424C ********************************************** 2425C ** STEP 2.2-- ** 2426C ** COMPUTE THE SQUARE ROOT OF THE WEIGHTS ** 2427C ********************************************** 2428C 2429 ISTEPN='2.2' 2430 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2') 2431 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 2432C 2433 DO550I=1,N 2434 IF(W(I).LT.0.0)THEN 2435 WRITE(ICOUT,999) 2436 CALL DPWRST('XXX','BUG ') 2437 WRITE(ICOUT,556) 2438 556 FORMAT('***** ERROR IN DPFIT2--') 2439 CALL DPWRST('XXX','BUG ') 2440 WRITE(ICOUT,557) 2441 557 FORMAT(' NEGATIVE WEIGHT ENCOUNTERED.') 2442 CALL DPWRST('XXX','BUG ') 2443 WRITE(ICOUT,558) 2444 558 FORMAT(' FITTING WITH NEGATIVE WEIGHTS NOT PERMITTED.') 2445 CALL DPWRST('XXX','BUG ') 2446 IERROR='YES' 2447 GOTO9000 2448 ELSEIF(W(I).EQ.0.0)THEN 2449 WSQRT(I)=W(I) 2450 ELSE 2451 WSQRT(I)=SQRT(W(I)) 2452 ENDIF 2453 550 CONTINUE 2454C 2455C *************************************************** 2456C * STEP 2.3-- ** 2457C * FORM A NEW RESPONSE VECTOR ( = ** 2458C * THE OLD RESPONSE * SQUARE ROOT OF WEIGHTS ( ** 2459C *************************************************** 2460C 2461 ISTEPN='2.3' 2462 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2') 2463 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 2464C 2465 DO560I=1,N 2466 Y2(I)=Y(I)*WSQRT(I) 2467 560 CONTINUE 2468C 2469C ****************************************************** 2470C ** STEP 2.5-- ** 2471C ** CHECK FOR REPLICATION AND IF EXISTENT ** 2472C ** COMPUTE A (MODEL-FREE) REPLICATION STANDARD ** 2473C ** DEVIATION. ** 2474C ****************************************************** 2475C 2476 ISTEPN='2.5' 2477 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2') 2478 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 2479C 2480 CALL DPREPS(Y,XMAT,IROW,N,NUMVAR,DUM1,DUM2, 2481 1 IREP,REPSS,REPMS,REPSD,REPDF,NUMSET, 2482 1 IBUGA3,IERROR) 2483 IREPDF=INT(REPDF+0.5) 2484C 2485C PRINT INTIAL INFORMATION (BEFORE ANY FIT ITERATIONS) 2486C 2487 IF(IPRINT.EQ.'ON')THEN 2488 IF(NUMPAR.GE.1)THEN 2489 ITITLE='Least Squares Non-Linear Fit' 2490 NCTITL=28 2491 ELSE 2492 ITITLE='Fully-Specified Model' 2493 NCTITL=21 2494 ENDIF 2495 ITITLZ=' ' 2496 NCTITZ=0 2497C 2498 ICNT=1 2499 ITEXT(ICNT)=' ' 2500 NCTEXT(ICNT)=0 2501 AVALUE(ICNT)=0.0 2502 IDIGIT(ICNT)=-1 2503 ICNT=ICNT+1 2504 ITEXT(ICNT)='Sample Size:' 2505 NCTEXT(ICNT)=12 2506 AVALUE(ICNT)=REAL(N) 2507 IDIGIT(ICNT)=0 2508C 2509 IMIN=1 2510 IF(MODEL(1).EQ.' ')IMIN=2 2511 IMAX=NUMCHA 2512 IDEL=IMAX-IMIN+1 2513 NUMLIN=((IDEL-1)/43)+1 2514 IF(NUMLIN.GE.1)THEN 2515 DO47240KLINE=1,NUMLIN 2516 IF(KLINE.EQ.1)THEN 2517 KMIN=IMIN 2518 KMAX=KMIN+43-1 2519 IF(KMAX.GT.IMAX)KMAX=IMAX 2520 ICNT=ICNT+1 2521 ITEXT(ICNT)(1:7)='Model: ' 2522 ELSEIF(KLINE.GE.2)THEN 2523 ICNT=ICNT+1 2524 KMIN=KMAX+1 2525 KMAX=KMIN+100-1 2526 IF(KMAX.GT.IMAX)KMAX=IMAX 2527 ITEXT(ICNT)(1:7)=' ' 2528 ENDIF 2529 ICNT2=7 2530 DO47245K=KMIN,KMAX 2531 ICNT2=ICNT2+1 2532 ITEXT(ICNT)(ICNT2:ICNT2)=MODEL(K)(1:1) 253347245 CONTINUE 2534 NCTEXT(ICNT)=ICNT2 2535 AVALUE(ICNT)=0.0 2536 IDIGIT(ICNT)=-1 253747240 CONTINUE 2538 ENDIF 2539C 2540 IF(IREP.EQ.'NO')THEN 2541 ICNT=ICNT+1 2542 ITEXT(ICNT)='No Replication Case:' 2543 NCTEXT(ICNT)=20 2544 AVALUE(ICNT)=0.0 2545 IDIGIT(ICNT)=-1 2546 ELSE 2547 ICNT=ICNT+1 2548 ITEXT(ICNT)='Replication Case:' 2549 NCTEXT(ICNT)=17 2550 AVALUE(ICNT)=0.0 2551 IDIGIT(ICNT)=-1 2552 ICNT=ICNT+1 2553 ITEXT(ICNT)='Replication Standard Deviation:' 2554 NCTEXT(ICNT)=31 2555 AVALUE(ICNT)=REPSD 2556 IDIGIT(ICNT)=NUMDIG 2557 ICNT=ICNT+1 2558 ITEXT(ICNT)='Replication Degrees of Freedom:' 2559 NCTEXT(ICNT)=31 2560 AVALUE(ICNT)=REAL(IREPDF) 2561 IDIGIT(ICNT)=0 2562 ICNT=ICNT+1 2563 ITEXT(ICNT)='Number of Distinct Subsets:' 2564 NCTEXT(ICNT)=31 2565 AVALUE(ICNT)=REAL(NUMSET) 2566 IDIGIT(ICNT)=0 2567 ENDIF 2568C 2569 NUMROW=ICNT 2570 DO2310I=1,NUMROW 2571 NTOT(I)=15 2572 2310 CONTINUE 2573C 2574 IFRST=.TRUE. 2575 ILAST=.TRUE. 2576 CALL DPDTA1(ITITLE,NCTITL,ITITLZ,NCTITZ,ITEXT, 2577 1 NCTEXT,AVALUE,IDIGIT, 2578 1 NTOT,NUMROW, 2579 1 ICAPSW,ICAPTY,ILAST,IFRST, 2580 1 ISUBRO,IBUGA3,IERROR) 2581C 2582C DEFINE HEADERS FOR THE INTERMEDIATE ITERATIONS 2583C 2584 ITITLE=' ' 2585 NCTITL=-99 2586 ITITL9=' ' 2587 NCTIT9=0 2588C 2589 IWHTML(1)=75 2590 IWHTML(2)=125 2591 IWHTML(3)=125 2592 IWHTML(4)=50 2593 IWHTML(5)=125 2594 IWHTML(6)=125 2595 IWHTML(7)=125 2596 IINC=1600 2597 IINC2=200 2598 IINC3=1200 2599 IWRTF(1)=IINC3 2600 IWRTF(2)=IWRTF(1)+IINC 2601 IWRTF(3)=IWRTF(2)+IINC 2602 IWRTF(4)=IWRTF(3)+IINC2 2603 IWRTF(5)=IWRTF(4)+IINC 2604 IWRTF(6)=IWRTF(5)+IINC 2605 IWRTF(7)=IWRTF(6)+IINC 2606 IFRST=.TRUE. 2607 ILAST=.TRUE. 2608 IFLAGS=.TRUE. 2609 IFLAGE=.TRUE. 2610C 2611C RESTRICT THE NUMBER OF PARAMETERS PER LINE DEPENDING 2612C ON OUTPUT FORMAT 2613C 2614 IF(ICAPTY.EQ.'HTML')THEN 2615 NTEMP=3 2616 ELSEIF(ICAPTY.EQ.'LATE')THEN 2617 NTEMP=4 2618 ELSEIF(ICAPTY.EQ.'RTF')THEN 2619 NTEMP=3 2620 ELSE 2621 NTEMP=6 2622 ENDIF 2623 IF(NUMPAR.LE.NTEMP)THEN 2624 NUMCOL=4+NUMPAR 2625 ELSE 2626 NUMCOL=4+NTEMP 2627 ENDIF 2628 NUMLIN=3 2629C 2630 DO3101J=1,NUMCLI 2631 DO3102I=1,MAXLIN 2632 ITITL2(I,J)=' ' 2633 NCTIT2(I,J)=0 2634 3102 CONTINUE 2635 DO3103I=1,MAXROW 2636 IVALUE(I,J)=' ' 2637 NCVALU(I,J)=0 2638 AMAT(I,J)=0.0 2639 IDIGI2(I,J)=-6 2640 3103 CONTINUE 2641 3101 CONTINUE 2642C 2643 ITITL2(1,1)=' ' 2644 NCTIT2(1,1)=0 2645 ITITL2(2,1)='Iteration' 2646 NCTIT2(2,1)=9 2647 ITITL2(3,1)='Number' 2648 NCTIT2(3,1)=6 2649C 2650 ITITL2(1,2)=' ' 2651 NCTIT2(1,2)=0 2652 ITITL2(2,2)='Convergence' 2653 NCTIT2(2,2)=11 2654 ITITL2(3,2)='Measure' 2655 NCTIT2(3,2)=7 2656C 2657 ITITL2(1,3)='Residual' 2658 NCTIT2(1,3)=8 2659 ITITL2(2,3)='Standard' 2660 NCTIT2(2,3)=8 2661 ITITL2(3,3)='Deviation' 2662 NCTIT2(3,3)=9 2663C 2664 ITITL2(1,4)=' * ' 2665 NCTIT2(1,4)=3 2666 ITITL2(2,4)=' * ' 2667 NCTIT2(2,4)=3 2668 ITITL2(3,4)=' * ' 2669 NCTIT2(3,4)=3 2670C 2671 ITITL2(1,5)=' ' 2672 NCTIT2(1,5)=0 2673 ITITL2(2,5)='Parameter' 2674 NCTIT2(2,5)=10 2675 ITITL2(3,5)='Estimates' 2676 NCTIT2(3,5)=10 2677C 2678 NMAX=0 2679 DO3110I=1,NUMCOL 2680 VALIGN(I)='b' 2681 ALIGN(I)='r' 2682 NTOT(I)=15 2683 IF(I.EQ.1)NTOT(I)=10 2684 IF(I.EQ.4)NTOT(I)=3 2685 NMAX=NMAX+NTOT(I) 2686 ITYPCO(I)='NUME' 2687 IF(I.EQ.4)ITYPCO(I)='ALPH' 2688 IDIGIT(I)=-7 2689 IF(I.EQ.1 .OR. I.EQ.4)THEN 2690 IDIGIT(I)=0 2691 ENDIF 2692 3110 CONTINUE 2693C 2694 ICNT=0 2695C 2696 ENDIF 2697C 2698C ******************************************************* 2699C ** STEP 2.6-- ** 2700C ** TREAT THE SPECIAL CASE WHERE NO PARAMETERS ** 2701C ** EXIST IN THE MODEL-- ** 2702C ** THAT IS, WE ARE REALLY INTERESTED ** 2703C ** IN GENERATING PREDICTED VALUES AND RESIDUALS ** 2704C ** FROM A FULLY-SPECIFIED MODEL. ** 2705C ** (THIS IS USEFUL FOR MANUALLY ARRIVING AT ** 2706C ** REASONABLE STARTING VALUES FOR A MORE ** 2707C ** COMPLICATED FIT; ** 2708C ** AND ALSO FOR TESTING THE GOODNESS OF AN ** 2709C ** ALREADY-DERIVED ** 2710C ** FIT FOR ONE DOMAIN OVER A SECOND DOMAIN.) ** 2711C ******************************************************* 2712C 2713 ISTEPN='2.6' 2714 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2') 2715 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 2716C 2717 IF(NUMPAR.LE.0)THEN 2718 DO3000I=1,N 2719 IF(NUMVAR.GT.0)THEN 2720 DO3005J=1,NUMVAR 2721 PARAM5(NUMPAR+J)=XMAT(I,J) 2722 3005 CONTINUE 2723 CALL COMPIM(MODEL,NUMCHA,IPASS,PARAM5,IPARN5,IPARN6,NUMPV, 2724 1 IANGLU,ITYPEH,IW2HOL,IW22HO,W2HOLD,NWHOLD, 2725 1 PRED2(I), 2726 1 IBUGCO,IBUGEV,IERROR) 2727 PRED2(I)=PRED2(I)*WSQRT(I) 2728 IF(IERROR.EQ.'YES')GOTO9000 2729 ENDIF 2730 3000 CONTINUE 2731C 2732 DO3100I=1,N 2733 RES2(I)=Y2(I)-PRED2(I) 2734 3100 CONTINUE 2735C 2736 SUM=0.0 2737 DO3200I=1,N 2738 SUM=SUM+RES2(I)**2 2739 3200 CONTINUE 2740 RESSS=SUM 2741C 2742 IRESDF=N 2743 RESDF=N 2744 RESMS=0.0 2745 IF(RESDF.GT.0.0)RESMS=RESSS/RESDF 2746 RESSD=0.0 2747 IF(RESMS.GT.0.0)RESSD=SQRT(RESMS) 2748 GOTO5000 2749 ENDIF 2750C 2751C ****************************************************** 2752C ** STEP 3-- ** 2753C ** USING THE GIVEN STARTING VALUES FOR THE ** 2754C ** PARAMETERS, ** 2755C ** COMPUTE PREDICTED VALUES AND EXACT DERIVATIVES; ** 2756C ** THEN CHECK THE CORRECTNESS OF THE DERIVATIVES ** 2757C ** FORMULAE ** 2758C ** BY APPROXIMATING THE DERIVATIVES WITH DIFFERENCES* 2759C ** AND COMPARING THE EXACT DERIVATIVES WITH THE ** 2760C ** DIFFERENCES. ** 2761C ****************************************************** 2762C 2763 ISTEPN='3' 2764 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2')THEN 2765 CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 2766 WRITE(ICOUT,999) 2767 CALL DPWRST('XXX','BUG ') 2768 WRITE(ICOUT,425) 2769 425 FORMAT(' GRADIENTS FROM DIFFERENCES') 2770 CALL DPWRST('XXX','BUG ') 2771 ENDIF 2772C 2773 DO1201J=1,NUMPAR 2774 PARAM5(J)=PARAM3(J) 2775 1201 CONTINUE 2776C 2777 DO1200I=1,N 2778 IF(NUMVAR.GE.1)THEN 2779 DO1205J=1,NUMVAR 2780 PARAM5(NUMPAR+J)=XMAT(I,J) 2781 1205 CONTINUE 2782 ENDIF 2783C 2784 CALL COMPIM(MODEL,NUMCHA,IPASS,PARAM5,IPARN5,IPARN6,NUMPV, 2785 1 IANGLU,ITYPEH,IW2HOL,IW22HO,W2HOLD,NWHOLD,DUM1(I), 2786 1 IBUGCO,IBUGEV,IERROR) 2787 DUM1(I)=DUM1(I)*WSQRT(I) 2788 IF(IERROR.EQ.'YES')GOTO9000 2789 1200 CONTINUE 2790C 2791 SUM=0.0 2792 DO1140I=1,N 2793 G(I)=Y2(I)-DUM1(I) 2794 SUM=SUM+G(I)**2 2795 1140 CONTINUE 2796 SSN=SUM 2797C 2798 DO1210J=1,NUMPAR 2799 PARAM7(J)=PARAM3(J) 2800 1210 CONTINUE 2801C 2802 DO1220J=1,NP 2803 IF(ICON3(J).EQ.1)GOTO1220 2804C 2805 IF(IBUGA3.EQ.'ON')THEN 2806 WRITE(ICOUT,119)J 2807 119 FORMAT('PARAMETER NUMBER ',I8) 2808 CALL DPWRST('XXX','BUG ') 2809 ENDIF 2810C 2811 PARAM7(J)=PARAM3(J) 2812 IF(PARAM7(J).EQ.0.0)H=0.001 2813 IF(PARAM7(J).NE.0.0)H=PARAM3(J)*0.01 2814 PARAM7(J)=PARAM3(J)+H 2815 DO1230I=1,N 2816 IF(NUMVAR.GE.1)THEN 2817 DO1235JJ=1,NUMVAR 2818 PARAM7(NUMPAR+JJ)=XMAT(I,JJ) 2819 1235 CONTINUE 2820 ENDIF 2821C 2822 CALL COMPIM(MODEL,NUMCHA,IPASS,PARAM7,IPARN5,IPARN6,NUMPV, 2823 1 IANGLU,ITYPEH,IW2HOL,IW22HO,W2HOLD,NWHOLD, 2824 1 PRED2(I), 2825 1 IBUGCO,IBUGEV,IERROR) 2826 PRED2(I)=PRED2(I)*WSQRT(I) 2827 IF(IERROR.EQ.'YES')GOTO9000 2828 K=I+(J-1)*N 2829 V(K)=(PRED2(I)-DUM1(I))/H 2830 V(K)=-V(K) 2831 1230 CONTINUE 2832C 2833 SUM=0.0 2834 DO1250I=1,N 2835 RES2(I)=Y2(I)-PRED2(I) 2836 SUM=SUM+RES2(I)**2 2837 1250 CONTINUE 2838 S=SUM 2839C 2840 DO 1260 I=1,N 2841 RES2(I)=(RES2(I)-G(I))/H 2842 1260 CONTINUE 2843C 2844 IF(IBUGA3.EQ.'ON' .OR. ISUBRO.EQ.'FIT2')THEN 2845 DO1261I=1,N 2846 WRITE(ICOUT,120)RES2(I) 2847 120 FORMAT(G15.7) 2848 CALL DPWRST('XXX','BUG ') 2849 1261 CONTINUE 2850 ENDIF 2851C 2852 PARAM7(J)=PARAM3(J) 2853 1220 CONTINUE 2854C 2855C 2856C 2857C ************************************************ 2858C ** STEP 4-- ** 2859C ** START THE ITERATIVE CYCLE. ** 2860C ** ITS = THE ITERATION NUMBER. ** 2861C ** NITS = THE NUMBER OF ITERATIONS. ** 2862C ************************************************ 2863C 2864 ISTEPN='4' 2865 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2') 2866 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 2867C 2868 ITS=0 2869 40 CONTINUE 2870 ITS=ITS+1 2871 NITS=0 2872C 2873C ***************************************************** 2874C ** STEP 5-- ** 2875C ** FILL THE VECTOR V(.) WITH EVALUATED DERIVATIVES** 2876C ** BASED ON THE STARTING VALUES FOR THE PARAMETERS.* 2877C ** ALL THE DERIVATIVES WITH RESPECT TO PARAMETER 1** 2878C ** GO IN THE FIRST N LOCATIONS. ** 2879C ** ALL THE DERIVATIVES WITH RESPECT TO PARAMETER 2** 2880C ** GO IN THE NEXT N LOCATIONS. ** 2881C ** ALL THE DERIVATIVES WITH RESPECT TO PARAMETER 3** 2882C ** GO IN THE FOLLOWING N LOCATIONS, ETC. ** 2883C ** ALSO COMPUTE A SUM OF SQUARED DEVIATIONS ** 2884C ** BASED ON THE CURRENT VALUES FOR THE PARAMETERS ** 2885C ** (THIS WILL BE USED FOR COMPARATIVE PURPOSES ** 2886C ** WITHIN THE ITERATION). ** 2887C ***************************************************** 2888C 2889 ISTEPN='5' 2890 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2') 2891 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 2892C 2893 DO1301J=1,NUMPAR 2894 PARAM5(J)=PARAM3(J) 2895 1301 CONTINUE 2896 DO1300I=1,N 2897 IF(NUMVAR.GE.1)THEN 2898 DO1305J=1,NUMVAR 2899 PARAM5(NUMPAR+J)=XMAT(I,J) 2900 1305 CONTINUE 2901 ENDIF 2902C 2903 CALL COMPIM(MODEL,NUMCHA,IPASS,PARAM5,IPARN5,IPARN6,NUMPV, 2904 1 IANGLU,ITYPEH,IW2HOL,IW22HO,W2HOLD,NWHOLD,PRED2(I), 2905 1 IBUGCO,IBUGEV,IERROR) 2906 PRED2(I)=PRED2(I)*WSQRT(I) 2907 IF(IERROR.EQ.'YES')GOTO9000 2908 1300 CONTINUE 2909C 2910 DO1310J=1,NUMPAR 2911 PARAM7(J)=PARAM3(J) 2912 1310 CONTINUE 2913 DO1320J=1,NUMPAR 2914 IF(PARAM3(J).EQ.0.0)H=0.001 2915 IF(PARAM3(J).NE.0.0)H=PARAM3(J)*0.01 2916 PARAM7(J)=PARAM3(J)+H 2917 DO1330I=1,N 2918 IF(NUMVAR.GE.1)THEN 2919 DO1335JJ=1,NUMVAR 2920 PARAM7(NUMPAR+JJ)=XMAT(I,JJ) 2921 1335 CONTINUE 2922 ENDIF 2923C 2924 CALL COMPIM(MODEL,NUMCHA,IPASS,PARAM7,IPARN5,IPARN6,NUMPV, 2925 1 IANGLU,ITYPEH,IW2HOL,IW22HO,W2HOLD,NWHOLD,Y1, 2926 1 IBUGCO,IBUGEV,IERROR) 2927 Y1=Y1*WSQRT(I) 2928 IF(IERROR.EQ.'YES')GOTO9000 2929 K=I+(J-1)*N 2930 V(K)=(Y1-PRED2(I))/H 2931 V(K)=-V(K) 2932C 2933 IF(IBUGA3.EQ.'ON' .OR. ISUBRO.EQ.'FIT2')THEN 2934 WRITE(ICOUT,1333)J,I,PARAM3(J),PARAM7(J),H, 2935 1 Y1,PRED2(I),V(K) 2936 1333 FORMAT(I2,I4,3F10.5,3D14.7) 2937 CALL DPWRST('XXX','BUG ') 2938 ENDIF 2939C 2940 1330 CONTINUE 2941 PARAM7(J)=PARAM3(J) 2942 1320 CONTINUE 2943C 2944 SUM=0.0 2945 DO1340I=1,N 2946 RES2(I)=Y2(I)-PRED2(I) 2947 SUM=SUM+RES2(I)**2 2948 1340 CONTINUE 2949 SSINIT=SUM 2950 SSINMS=0.0 2951 IF(DF.GT.0.0)SSINMS=SSINIT/DF 2952 SDINIT=0.0 2953 IF(SSINMS.GT.0.0)SDINIT=SQRT(SSINMS) 2954 IF(NCONST.EQ.0) GO TO 38 2955 J = 0 2956 DO 58 I=1,NPST 2957 K = ICON3(I) 2958 J = J + K 2959 IF(J.EQ.0.OR.K.EQ.1) GO TO 58 2960 II = (I-1)*N 2961 KK = (I-J-1)*N 2962 DO 54 K=1,N 2963 V(KK+K) = V(II+K) 2964 54 CONTINUE 2965 58 CONTINUE 2966 38 CONTINUE 2967C 2968 IF(IBUGA3.EQ.'ON' .OR. ISUBRO.EQ.'FIT2')THEN 2969 WRITE(ICOUT,999) 2970 CALL DPWRST('XXX','BUG ') 2971 WRITE(ICOUT,2401) 2972 CALL DPWRST('XXX','BUG ') 2973 WRITE(ICOUT,2402) 2974 CALL DPWRST('XXX','BUG ') 2975 WRITE(ICOUT,2403) 2976 CALL DPWRST('XXX','BUG ') 2977 WRITE(ICOUT,2404)ITS 2978 CALL DPWRST('XXX','BUG ') 2979 WRITE(ICOUT,2405)(PARAM3(J),J=1,NUMPAR) 2980 CALL DPWRST('XXX','BUG ') 2981 WRITE(ICOUT,2406)SDINIT 2982 CALL DPWRST('XXX','BUG ') 2983 WRITE(ICOUT,2411) 2984 CALL DPWRST('XXX','BUG ') 2985 IMAX=N 2986 JMAX=NUMPAR 2987 WRITE(ICOUT,2412)IMAX,JMAX 2988 CALL DPWRST('XXX','BUG ') 2989 2401 FORMAT('---------- AFTER STEP 5 OF DPFIT2 ----------') 2990 2402 FORMAT('(THAT IS, AFTER FILLING V(.) WITH DERIVATIVES') 2991 2403 FORMAT('BASED ON CURRENT VALUES OF PARAMETERS)') 2992 2404 FORMAT('ITERATION = ',I5) 2993 2405 FORMAT('CURRENT PARAMETERS = ',8F13.6) 2994 2406 FORMAT('CURRENT RESIDUAL STANDARD DEVIATION = ',F20.10) 2995 2411 FORMAT('THE "MATRIX" V(.) AND THE VECTOR RES--') 2996 2412 FORMAT(I5,' ROWS BY ',I5,' COLUMNS (PLUS AN EXTRA ', 2997 1 'COLUMN FOR RES)') 2998 DO2420I=1,IMAX 2999 L=0 3000 DO2430J=1,JMAX 3001 L=L+1 3002 K=(J-1)*IMAX+I 3003 DUM(L)=V(K) 3004 2430 CONTINUE 3005 LMAX=L 3006 WRITE(ICOUT,2431)(DUM(L),L=1,LMAX),RES2(I) 3007 2431 FORMAT(10F13.7) 3008 CALL DPWRST('XXX','BUG ') 3009 2420 CONTINUE 3010 WRITE(ICOUT,999) 3011 CALL DPWRST('XXX','BUG ') 3012 WRITE(ICOUT,2441) 3013 CALL DPWRST('XXX','BUG ') 3014 IMAX=NUMPAR 3015 JMAX=NUMPAR+4 3016 WRITE(ICOUT,2442)IMAX,JMAX 3017 2441 FORMAT('THE MATRIX WS--') 3018 CALL DPWRST('XXX','BUG ') 3019 2442 FORMAT(I5,' ROWS BY ',I5,' COLUMNS') 3020 DO2450I=1,IMAX 3021 L=0 3022 DO2460J=1,JMAX 3023 L=L+1 3024 K=(J-1)*IMAX+I 3025 DUM(L)=WS(K) 3026 2460 CONTINUE 3027 LMAX=L 3028 WRITE(ICOUT,2461)(DUM(L),L=1,LMAX) 3029 2461 FORMAT(10F13.7) 3030 CALL DPWRST('XXX','BUG ') 3031 2450 CONTINUE 3032 ENDIF 3033C 3034C PRINT RESULTS FOR CURRENT ITERATION 3035C 3036 IF(IPRINT.EQ.'ON')THEN 3037 IF(ICNT.GT.55)THEN 3038 CALL DPDTA5(ITITLE,NCTITL, 3039 1 ITITL9,NCTIT9,ITITL2,NCTIT2, 3040 1 MAXLIN,NUMLIN,NUMCLI,NUMCOL, 3041 1 IVALUE,NCVALU,AMAT,ITYPCO,MAXROW,ICNT, 3042 1 IDIGIT,NTOT,IWHTML,IWRTF,VALIGN,ALIGN,NMAX, 3043 1 ICAPSW,ICAPTY,IFRST,ILAST, 3044 1 IFLAGS,IFLAGE, 3045 1 ISUBRO,IBUGA3,IERROR) 3046 CALL DPFLSH(IPR,IBUGA3,ISUBRO,IFOUND,IERROR) 3047 ICNT=0 3048 ELSE 3049 NLINE=((NUMPAR-1)/NTEMP) + 1 3050 DO3910KK=1,NLINE 3051 ICNT=ICNT+1 3052 IVALUE(ICNT,4)=' * ' 3053 NCVALU(ICNT,4)=3 3054 AMAT(ICNT,1)=REAL(ITS) 3055 AMAT(ICNT,2)=ALAMBA 3056 AMAT(ICNT,3)=SDINIT 3057 INDX1=(KK-1)*NTEMP+1 3058 INDX2=KK*NTEMP 3059 IF(INDX2.GT.NUMPAR)INDX2=NUMPAR 3060 ICNT3=0 3061 DO3920JJ=INDX1,INDX2 3062 ICNT3=ICNT3+1 3063 AMAT(ICNT,4+ICNT3)=PARAM3(JJ) 3064 3920 CONTINUE 3065 3910 CONTINUE 3066 ENDIF 3067 ENDIF 3068C 3069C ****************************************************** 3070C ** STEP 6-- ** 3071C ** TO ENHANCE COMPUTATIONAL ACCURACY, ** 3072C ** SCALE THE "MATRIX" V(.) OF DERIVATIVES ** 3073C ** SO THAT COLUMNS HAVE LENGTH 1. ** 3074C ** STORE THE SCALE FACTOR FOR COLUMN (PARAMETER) 1 ** 3075C ** IN WS(ID+1). ** 3076C ** STORE THE SCALE FACTOR FOR COLUMN (PARAMETER) 2 ** 3077C ** IN WS(ID+2). ** 3078C ** STORE THE SCALE FACTOR FOR COLUMN (PARAMETER) 3 ** 3079C ** IN WS(ID+3), ** 3080C ****************************************************** 3081C 3082 ISTEPN='6' 3083 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2') 3084 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 3085C 3086 DO 1 I=1,NP 3087 II=(I-1)*N 3088 SUM=0.D0 3089 DO 2 J=1,N 3090 SUM=SUM+V(II+J)**2 3091 2 CONTINUE 3092 IF(SUM.EQ.0.0D0) THEN 3093 WRITE(ICOUT,999) 3094 CALL DPWRST('XXX','BUG ') 3095 WRITE(ICOUT,999) 3096 CALL DPWRST('XXX','BUG ') 3097 WRITE(ICOUT,121) 3098 CALL DPWRST('XXX','BUG ') 3099 WRITE(ICOUT,122) 3100 CALL DPWRST('XXX','BUG ') 3101 WRITE(ICOUT,123)IPARN3(I),IPARN4(I) 3102 CALL DPWRST('XXX','BUG ') 3103 WRITE(ICOUT,124) 3104 CALL DPWRST('XXX','BUG ') 3105 WRITE(ICOUT,125) 3106 CALL DPWRST('XXX','BUG ') 3107 WRITE(ICOUT,126) 3108 CALL DPWRST('XXX','BUG ') 3109 WRITE(ICOUT,999) 3110 CALL DPWRST('XXX','BUG ') 3111 WRITE(ICOUT,127) 3112 CALL DPWRST('XXX','BUG ') 3113 WRITE(ICOUT,128) 3114 CALL DPWRST('XXX','BUG ') 3115 WRITE(ICOUT,129) 3116 CALL DPWRST('XXX','BUG ') 3117 WRITE(ICOUT,130) 3118 CALL DPWRST('XXX','BUG ') 3119 WRITE(ICOUT,999) 3120 CALL DPWRST('XXX','BUG ') 3121 WRITE(ICOUT,131) 3122 CALL DPWRST('XXX','BUG ') 3123 WRITE(ICOUT,132) 3124 CALL DPWRST('XXX','BUG ') 3125 WRITE(ICOUT,133) 3126 CALL DPWRST('XXX','BUG ') 3127 WRITE(ICOUT,134) 3128 CALL DPWRST('XXX','BUG ') 3129 WRITE(ICOUT,135) 3130 CALL DPWRST('XXX','BUG ') 3131 WRITE(ICOUT,136) 3132 CALL DPWRST('XXX','BUG ') 3133 WRITE(ICOUT,999) 3134 CALL DPWRST('XXX','BUG ') 3135 WRITE(ICOUT,137) 3136 CALL DPWRST('XXX','BUG ') 3137 WRITE(ICOUT,138) 3138 CALL DPWRST('XXX','BUG ') 3139 WRITE(ICOUT,139) 3140 CALL DPWRST('XXX','BUG ') 3141 WRITE(ICOUT,140) 3142 CALL DPWRST('XXX','BUG ') 3143 WRITE(ICOUT,141) 3144 CALL DPWRST('XXX','BUG ') 3145 WRITE(ICOUT,142) 3146 CALL DPWRST('XXX','BUG ') 3147 WRITE(ICOUT,999) 3148 CALL DPWRST('XXX','BUG ') 3149 WRITE(ICOUT,143) 3150 CALL DPWRST('XXX','BUG ') 3151 WRITE(ICOUT,144) 3152 CALL DPWRST('XXX','BUG ') 3153 WRITE(ICOUT,145) 3154 CALL DPWRST('XXX','BUG ') 3155 WRITE(ICOUT,146) 3156 CALL DPWRST('XXX','BUG ') 3157 WRITE(ICOUT,999) 3158 CALL DPWRST('XXX','BUG ') 3159 WRITE(ICOUT,147) 3160 CALL DPWRST('XXX','BUG ') 3161 WRITE(ICOUT,148) 3162 CALL DPWRST('XXX','BUG ') 3163 121 FORMAT(' *** COMPUTATIONAL INSTABILITY ENCOUNTERED ***') 3164 122 FORMAT(' IN COMPUTING THE NUMERICAL DERIVIATIVE') 3165 123 FORMAT(' FOR PARAMETER ',A4,A4,', IT WAS FOUND THAT') 3166 124 FORMAT(' THE CALCULATED DERIVATIVE WAS IDENTICALLY ZERO') 3167 125 FORMAT(' FOR EVERY VALUE OF THE INDEPENDENT') 3168 126 FORMAT(' VARIABLE(S). ') 3169 127 FORMAT(' THIS IS USUALLY DUE TO INTERNAL DIFFERENCING') 3170 128 FORMAT(' ON A FINITE WORD LENGTH COMPUTER') 3171 129 FORMAT(' OF 2 VERY LARGE NUMBERS WHICH ARE') 3172 130 FORMAT(' NEARLY IDENTICAL.') 3173 131 FORMAT(' PROBABLE CAUSE 1--RAISING A LARGE') 3174 132 FORMAT(' VARIABLE VALUE TO A MODERATE OR LARGE POWER.') 3175 133 FORMAT(' THIS FREQUENTLY OCCURS FOR THE') 3176 134 FORMAT(' ADDITIVE CONSTANT PARAMETER IN A MODEL') 3177 135 FORMAT(' WHICH HAS LARGE INDEPENDENT VARIABLE VALUES') 3178 136 FORMAT(' BEING RAISED TO SOME POWER.') 3179 137 FORMAT(' SUGGESTED SOLUTION--SCALE DOWN') 3180 138 FORMAT(' THE INDEPENDENT VARIABLE VALUES ') 3181 139 FORMAT(' (IF POSSIBLE) TO A RANGE NEAR 1 TO 10,') 3182 140 FORMAT(' REFIT THE NEW MODEL, AND APPROPRIATELY') 3183 141 FORMAT(' CONVERT THE COEFFICENTS OF THE NEW MODEL') 3184 142 FORMAT(' BACK INTO COEFFICIENTS OF THE ORIGINAL MODEL') 3185 143 FORMAT(' PROBABLE CAUSE 2--RAISING A MODERATE ') 3186 144 FORMAT(' VARIABLE VALUE TO A LARGE POWER.') 3187 145 FORMAT(' THE DIFFERENT STARTING VALUES USUALLY') 3188 146 FORMAT(' RANGE OVER 10 OR MORE ORDERS OF MAGNITUDE.') 3189 147 FORMAT(' SUGGESTED SOLUTION--USE MORE MODERATE') 3190 148 FORMAT(' VALUES OF THE STARTING VALUES.') 3191 IER = 4 3192 IERROR='YES' 3193 GOTO9000 3194 ENDIF 3195C 3196 IF(SUM.GT.0.0)DS3=DSQRT(SUM) 3197 IF(SUM.LE.0.0)DS3=0.0 3198 IF(DS3.LE.0.0)THEN 3199 WRITE(ICOUT,76) 3200 76 FORMAT('ERROR IN DPFIT2--DENOMINATOR DS3 = 0.0 AT FORMAT 76') 3201 CALL DPWRST('XXX','BUG ') 3202 IERROR='YES' 3203 GOTO9000 3204 ENDIF 3205 SUM=1.0D0/DS3 3206 DO 3 J=1,N 3207 V(II+J)=V(II+J)*SUM 3208 3 CONTINUE 3209 WS(ID+I)=SUM 3210 1 CONTINUE 3211 WS(ID+I)=SUM 3212C 3213 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2')THEN 3214 CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 3215 WRITE(ICOUT,100)ITS,ALAMBA,SSINIT 3216 100 FORMAT (7H ITS=,I3,8H ALAMBA=,G14.6,7H SUMSQ=,D14.6) 3217 CALL DPWRST('XXX','BUG ') 3218 ENDIF 3219C 3220C ******************************************************* 3221C ** STEP 7-- ** 3222C ** OPERATE ON THE "MATRIX" V(.) AND THE VECTOR RES. ** 3223C ** PERFORM HOUSEHOLDER TRANSFORMATION ON ** 3224C ** SCALED DERIVATIVE MATRIX AND COLUMN OF RESIDUALS,** 3225C ** AND TEST FOR SINGULARITIES. ** 3226C ******************************************************* 3227C 3228 ISTEPN='7' 3229 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2') 3230 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 3231C 3232 DO 4 I=1,NP 3233 II=(I-1)*N 3234 SUM=0.D0 3235 DO 5 J=I,N 3236 SUM=SUM+V(II+J)**2 3237 5 CONTINUE 3238 IF(SUM.GT.0.0D0)SUM=DSQRT(SUM) 3239 IF(SUM.LE.0.0D0)SUM=0.0D0 3240 IF(SUM.GT.100.*EPS) GO TO 24 3241 IF(ITS.EQ.1) THEN 3242 SUM = SUM + EPS 3243 GO TO 24 3244 ENDIF 3245 II = I 3246 J = 1 324727 CONTINUE 3248 IF(ICON3(J).NE.0) II = II + 1 3249 J = J + 1 3250 IF (J.LE.II) GO TO 27 3251C 3252C (RANK DEFICIENCY DETECTED-- 3253C CONTINUE ITERATING WITH PARAMETER II FIXED. 3254C GO BACK TO BEGINNING OF CYCLE 3255C FOR A NEW ITERATION. 3256C NOTE THAT THE INPUT VECTOR ICON3(.) IS HERE 3257C BEING ALTERED DUE TO THIS RANK DEFICIENCY.) 3258C 3259 ICON3(II) = 1 3260 WRITE(ICOUT,1122)II 3261 1122 FORMAT(2X,'PARAMETER',I8,' IS LINEARLY DEPENDENT ON PREVIOUS') 3262 CALL DPWRST('XXX','BUG ') 3263 WRITE(ICOUT,1123) 3264 1123 FORMAT(2X,'PARAMETERS, AND WILL THEREFORE BE HELD CONSTANT') 3265 CALL DPWRST('XXX','BUG ') 3266 NP = NP - 1 3267 NCONST = NCONST + 1 3268 GO TO 40 3269C 3270 24 CONTINUE 3271 IF(V(II+I).GT.0.)SUM=-SUM 3272 WS(IDA+I)=SUM 3273 V(II+I)=V(II+I)-SUM 3274 IF(I.NE.NP) THEN 3275 IP1 = I+1 3276 KK=I*N 3277 DO 7 K=IP1,NP 3278 SUM=0.D0 3279 DO 8 J=I,N 3280 SUM=SUM+V(II+J)*V(KK+J) 3281 8 CONTINUE 3282 SUM=-SUM/(WS(IDA+I)*V(II+I)) 3283 DO 9 J=I,N 3284 V(KK+J)=V(KK+J)-SUM*V(II+J) 3285 9 CONTINUE 3286 KK=KK+N 3287 7 CONTINUE 3288 ENDIF 3289 SUM=0.D0 3290 DO 20 J=I,N 3291 SUM=SUM+V(II+J)*RES2(J) 3292 20 CONTINUE 3293 SUM=-SUM/(WS(IDA+I)*V(II+I)) 3294 DO 21 J=I,N 3295 RES2(J)=RES2(J)-SUM*V(II+J) 329621 CONTINUE 32974 CONTINUE 3298C 3299C ****************************************************** 3300C ** STEP 8-- ** 3301C ** COMPUTE SSR = PARTIAL SUM OF SQUARED RESIDUALS ** 3302C ** (NOTE THAT THE RESIDUALS HAVE JUST BEEN ALTERED).* 3303C ****************************************************** 3304C 3305 ISTEPN='8' 3306 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2') 3307 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 3308C 3309 NP1=NP+1 3310 SSR=0.D0 3311 DO 22 I=NP1,N 3312 SSR=SSR+RES2(I)**2 3313 22 CONTINUE 3314C 3315C ****************************************************** 3316C ** STEP 9-- ** 3317C ** ADD ON THE LAMBDA TO THE ** 3318C ** DIAGONAL ELEMENTS OF R'R ** 3319C ** FOR THE LEFT-HAND SIDE OF THE EQUATION. ** 3320C ** TRANSFORM THE RIGHT-HAND SIDE OF THE EQUATION. ** 3321C ** THE UPPER TRIANGLE OF THE TRANSFORMED MATRIX IS ** 3322C ** STORED IN WS ** 3323C ** ELEMENT (I,J) OF THE TRANSFORMED MATRIX STORED IN* 3324C ** ELEMENT (I-1)*NP + J OF WS. ** 3325C ****************************************************** 3326C 3327 ISTEPN='9' 3328 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2') 3329 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 3330C 333119 CONTINUE 3332 IP = 0 3333 DO 30 I=1,NP 3334 DO 31 J=1,I 3335 WS(IP+J)=0. 333631 CONTINUE 3337 WS(IP+I)=ALAMBA 3338 IP = IP + NP 333930 CONTINUE 3340 IP = 0 3341 DO 10 I=1,NP 3342 C(I)=0. 3343 S=WS(IDA+I)**2 3344 IP1=I+1 3345 IL1=I-1 3346 DO 12 J=1,I 3347 S=S+WS(IP+J)**2 334812 CONTINUE 3349 IF(S.GT.0.0D0)S=DSQRT(S) 3350 IF(S.LE.0.0D0)S=0.0D0 3351 IF(WS(IDA+I).GT.0.)S=-S 3352 WS(IDU+I)=S 3353 WW=WS(IDA+I)-S 3354 IF(I.NE.NP) THEN 3355 KP = IP + NP 3356 DO 13 K=IP1,NP 3357 KK=(K-1)*N+I 3358 S=V(KK)*WW 3359 IF(I.NE.1) THEN 3360 DO 14 J=1,IL1 3361 S=S+WS(IP+J)*WS(KP+J) 336214 CONTINUE 3363 ENDIF 3364 S=-S/(WS(IDU+I)*WW) 3365 WS(IP+K)=V(KK)-S*WW 3366 DO 15 J=1,I 3367 WS(KP+J)=WS(KP+J)-S*WS(IP+J) 336815 CONTINUE 3369 KP = KP + NP 337013 CONTINUE 3371 ENDIF 3372 S=RES2(I)*WW 3373 DO 16 J=1,I 3374 S=S+WS(IP+J)*C(J) 337516 CONTINUE 3376 S=-S/(WS(IDU+I)*WW) 3377 WS(IDX+I)=RES2(I)-S*WW 3378 DO 17 J=1,I 3379 C(J)=C(J)-S*WS(IP+J) 338017 CONTINUE 3381 IP = IP + NP 338210 CONTINUE 3383C 3384C ****************************************************** 3385C ** STEP 10-- ** 3386C ** BACK SUBSTITUTE. ** 3387C ** COEFFICIENTS OF THE DERIVATIVE FIT WILL END UP ** 3388C ** IN ELEMENTS IDX+1, IDX+2, ... OF WS. ** 3389C ** UPDATED VALUES OF THE PARAMETERS WILL END UP ** 3390C ** IN ELEMENTS IY+1, IY+2, ... OF WS. ** 3391C ****************************************************** 3392C 3393 ISTEPN='10' 3394 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2') 3395 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 3396C 3397CCCCC THE FOLLOWING LINE WAS FIXED TO AVOID OVERFLOWS MAY 1994 3398CCCCC WS(IY)=WS(IY)/WS(ID) 3399 IF(ABS(WS(IY)).LE.CPUMAX/10000)THEN 3400 WS(IY)=WS(IY)/WS(ID) 3401 ENDIF 3402C 3403 KP=(NP-1)*NP 3404 DO 25 I=2,NP 3405 K=NP-I+1 3406 KP1=K+1 3407 KP = KP - NP 3408 S=0.D0 3409 DO 26 J=KP1,NP 3410 S = S + WS(KP+J)*WS(IDX+J) 341126 CONTINUE 3412 WS(IDX+K)=(WS(IDX+K)-S)/WS(IDU+K) 341325 CONTINUE 3414 SSS=SSR 3415 J = 0 3416 DO 32 II=1,NPST 3417 IF(ICON3(II).NE.0) THEN 3418 J = J + 1 3419 WS(IY+II) = PARAM3(II) 3420 PARAM9(II)=WS(IY+II) 3421 GO TO 32 3422 ENDIF 3423 I = II - J 3424 SSS=SSS+C(I)**2 3425 WS(IDX+I) = WS(IDX+I)*WS(ID+I) 3426 WS(IY+II) = PARAM3(II) - WS(IDX+I) 3427C 3428C TEST FOR CONSTRAINTS 3429C 3430 IOP=IPARO3(II) 3431 IF(IOP.NE.'NONE')THEN 3432 PLIM=PARLI3(II) 3433 PUP=WS(IY+II) 3434 IF(IOP.EQ.'GT')THEN 3435 IF(PUP.LE.PLIM)PUP=PLIM 3436 ELSEIF(IOP.EQ.'GE')THEN 3437 IF(PUP.LT.PLIM)PUP=PLIM 3438 ELSEIF(IOP.EQ.'EQ')THEN 3439 IF(PUP.NE.PLIM)PUP=PLIM 3440 ELSEIF(IOP.EQ.'LE')THEN 3441 IF(PUP.GT.PLIM)PUP=PLIM 3442 ELSEIF(IOP.EQ.'LT')THEN 3443 IF(PUP.GE.PLIM)PUP=PLIM 3444 ENDIF 3445 WS(IY+II)=PUP 3446 ENDIF 3447C 344832 CONTINUE 3449 NITS=NITS+1 3450C 3451C ******************************************************* 3452C ** STEP 11-- ** 3453C ** BASED ON THE UPDATED PARAMETERS, ** 3454C ** COMPUTE THE LATEST RESIDUAL STANDARD DEVIATION. ** 3455C ** TEST FOR CONVERGENCE. ** 3456C ******************************************************* 3457C 3458 ISTEPN='11' 3459 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2') 3460 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 3461C 3462 DO1350II=1,NUMPAR 3463 PARAM9(II)=WS(IY+II) 3464 1350 CONTINUE 3465 DO1400IZ=1,N 3466 IF(NUMVAR.GE.1)THEN 3467 DO1405J=1,NUMVAR 3468 PARAM9(NUMPAR+J)=XMAT(IZ,J) 3469 1405 CONTINUE 3470 ENDIF 3471C 3472 CALL COMPIM(MODEL,NUMCHA,IPASS,PARAM9,IPARN5,IPARN6,NUMPV, 3473 1 IANGLU,ITYPEH,IW2HOL,IW22HO,W2HOLD,NWHOLD,PRED2(IZ), 3474 1 IBUGCO,IBUGEV,IERROR) 3475 PRED2(IZ)=PRED2(IZ)*WSQRT(IZ) 3476 IF(IERROR.EQ.'YES')GOTO9000 3477 1400 CONTINUE 3478C 3479 SUM=0.0 3480 DO1420IZ=1,N 3481 DEL=Y2(IZ)-PRED2(IZ) 3482 SUM=SUM+DEL**2 3483 IF(SUM.GT.CPUMA2)SUM=CPUMA2 3484 1420 CONTINUE 3485 SSN=SUM 3486 RESSS=SSN 3487 RESMS=0.0 3488 IF(DF.GT.0.0)RESMS=RESSS/DF 3489 RESSD=0.0 3490 IF(RESMS.GT.0.0)RESSD=SQRT(RESMS) 3491 IF(RESSD.LT.FITSD)GOTO1440 3492 GOTO1460 3493 1440 CONTINUE 3494 IC=1 3495 DO1450I=1,NPST 3496 PARAM3(I)=WS(IY+I) 3497 1450 CONTINUE 3498 GOTO220 3499C 3500 1460 CONTINUE 3501 DPSI=0.5D0*(SSINIT-SSN)/(SSINIT-SSS) 3502C 3503 IF(IBUGA3.EQ.'ON' .OR. ISUBRO.EQ.'FIT2')THEN 3504 WRITE(ICOUT,203)NITS,ALAMBA,SSN,SSS,DPSI,RESSD 3505 203 FORMAT(1H ,'NITS=',I8,' ALAMBA=',E15.7,' SUMSQ=',D15.7, 3506 1 ' RES SUMSQ=',D15.7,' PSI =',E15.7,' RESSD = ',D15.7) 3507 CALL DPWRST('XXX','BUG ') 3508 WRITE(ICOUT,221)SSINIT,SSS,SSN 3509 221 FORMAT('SSINIT,SSS,SSN = ',3D15.7) 3510 CALL DPWRST('XXX','BUG ') 3511 WRITE(ICOUT,227)N,NUMPAR,NCONST,NP,DF,RESDF,IRESDF 3512 227 FORMAT('N,NUMPAR,NCONST,NP,DF,RESDF,IRESDF = ',4I8,2E15.7,I8) 3513 CALL DPWRST('XXX','BUG ') 3514 ENDIF 3515C 3516 DRAT=0.0 3517 IF(SSINIT.GT.0.0)DRAT=SSS/SSINIT 3518 DTOL2=1.0D0-DEPS*50.0D0 3519C 3520 IF(IBUGA3.EQ.'ON' .OR. ISUBRO.EQ.'FIT2')THEN 3521 WRITE(ICOUT,224)SSINIT,SSS,DRAT,DTOL2 3522 224 FORMAT('SSINIT,SSS,DRAT,DTOL2= ',4D20.10) 3523 CALL DPWRST('XXX','BUG ') 3524 ENDIF 3525C 3526 IF(DTOL2.LE.DRAT.AND.DRAT.LE.1.0D0)GOTO28 3527 IF(DPSI.GE.1.0D-04) GO TO 28 3528 IF(DPSI.GE.0.0D0.AND.RESSD.LT.0.000001)GOTO28 3529 ALAMBA=ALAMBA*EXPND 3530 IC=0 3531 IER=3 3532 IF(ALAMBA.LT.1.0E6) GO TO 19 3533 WRITE(ICOUT,45) 3534 45 FORMAT('*****ERROR--ALAMBA HAS REACHED 1 MILLION') 3535 CALL DPWRST('XXX','BUG ') 3536 WRITE(ICOUT,3046)ALAMBA,EXPND 3537 3046 FORMAT('ALAMBA = ',F20.10,' EXPANSION FACTOR EXPND = ',F20.10) 3538 CALL DPWRST('XXX','BUG ') 3539 WRITE(ICOUT,3047) 3540 3047 FORMAT('POSSIBLE FIX--RESCALE Y (OR X) DOWN (OR UP)') 3541 CALL DPWRST('XXX','BUG ') 3542 WRITE(ICOUT,3049) 3543 3049 FORMAT(' E.G., DIVIDING OR MULTIPLYING BY, SAY, ', 3544 1 '1000') 3545 CALL DPWRST('XXX','BUG ') 3546 GO TO 910 3547C 3548 28 CONTINUE 3549 DO 29 I=1,NPST 3550 PARAM3(I)=WS(IY+I) 3551 29 CONTINUE 3552C 3553 IF(IBUGA3.EQ.'ON' .OR. ISUBRO.EQ.'FIT2')THEN 3554 WRITE(ICOUT,201)(I,PARAM3(I),I=1,NPST) 3555 201 FORMAT (4(8H PARAM3(,I2,1H),G14.6)) 3556 CALL DPWRST('XXX','BUG ') 3557 ENDIF 3558C 3559 IER=2 3560 IF(ITS.GE.MAXITS)GO TO 220 3561 IER=1 3562 IF(SSINIT.GT.0.0D0)DS1=DSQRT(SSINIT) 3563 IF(SSINIT.LE.0.0D0)DS1=0.0D0 3564 IF(SSS.GT.0.0D0)DS2=DSQRT(SSS) 3565 IF(SSS.LE.0.0D0)DS2=0.0D0 3566 DRAT1=DS2/DS1 3567 DRAT2=(DS1-DS2)/(1.0D0+DS1) 3568C 3569 IF(IBUGA3.EQ.'ON' .OR. ISUBRO.EQ.'FIT2')THEN 3570 WRITE(ICOUT,222)SSINIT,SSS,DS1,DS2 3571 CALL DPWRST('XXX','BUG ') 3572 WRITE(ICOUT,223)DRAT1,DRAT2,DTOL 3573 222 FORMAT('SSINIT,SSS,DS1,DS2= ',4D16.9) 3574 CALL DPWRST('XXX','BUG ') 3575 223 FORMAT('DRAT1,DRAT2,DTOL = ',3D16.9) 3576 ENDIF 3577C 3578 IF(DRAT2.LE.DTOL)GOTO220 3579 IF(NITS.EQ.1) ALAMBA=ALAMBA*COMPR 3580 IC=0 3581 GO TO 40 3582C 3583C THE ABOVE 'GO TO 40' MARKS THE USUAL END OF AN ITERATION. 3584C 3585C**** CONVERGENCE TEST SATISFIED OR MAXITS REACHED 3586C 3587220 CONTINUE 3588 SUMSQ=SSN 3589 IF(IC.EQ.1) GOTO78 3590 IF(SSINIT-SSN.LE.SSINIT*1000.*EPS) GOTO78 3591 IF(ITS.GE.MAXITS)THEN 3592 WRITE(ICOUT,204)ITS 3593 204 FORMAT(21X,'FAILED TO CONVERGE IN ',I6,' ITERATIONS') 3594 CALL DPWRST('XXX','BUG ') 3595 WRITE(ICOUT,9204) 3596 9204 FORMAT(21X,'NOTE THAT THE FOLLOWING SUMMARY STATISTICS ARE') 3597 CALL DPWRST('XXX','BUG ') 3598 WRITE(ICOUT,9205) 3599 9205 FORMAT (21X,'NOT THE BEST THAT CAN BE OBTAINED.') 3600 CALL DPWRST('XXX','BUG ') 3601CCCCC JULY 1997. PRINT SUMMARY INFORMATION EVEN IF MAX ITERATIONS 3602CCCCC REACHED. CHANGE FOLLOWING LINE. 3603CCCCC GO TO 910 3604 GO TO 2999 3605 ENDIF 3606C 3607 IF(IBUGA3.EQ.'ON' .OR. ISUBRO.EQ.'FIT2')THEN 3608 WRITE(ICOUT,205) 3609 205 FORMAT (1H ,20X,'EVIDENCE OF CONVERGENCE') 3610 CALL DPWRST('XXX','BUG ') 3611 WRITE(ICOUT,100)ITS,ALAMBA,SSN 3612 CALL DPWRST('XXX','BUG ') 3613 WRITE(ICOUT,201)(I,PARAM3(I),I=1,NPST) 3614 CALL DPWRST('XXX','BUG ') 3615 ENDIF 3616C 3617 IC=1 3618 ALAMBA=ALAMBA*COMPR 3619 GO TO 40 3620C 362178 CONTINUE 3622 DO 91 I=1,N 3623 G(I)=RES2(I) 362491 CONTINUE 3625 X0=0. 3626 ANMNP=N-NP 3627 IF(N.GT.NP)X0=SUMSQ/ANMNP 3628 II=0 3629 DO 33 I=1,NP 3630 V(II+I)=WS(IDA+I) 3631 IF(WS(IDA+I).NE.0.0) S=1.0/WS(ID+I) 3632 DO 34 J=1,I 3633 V(II+J)=V(II+J)*S 363434 CONTINUE 3635 II=II+N 363633 CONTINUE 3637C 3638C**** INVERT UPPER TRIANGULAR MATRIX 3639C 3640 II=0 3641 DO 70 I=1,NP 3642 IF(V(II+I).NE.0.0) V(II+I)=1.0/V(II+I) 3643 IF(I.NE.1) THEN 3644 IL1=I-1 3645 DO 65 J=1,IL1 3646 S=0.D0 3647 DO 60 K=J,IL1 3648 KJ=(K-1)*N+J 3649 S=S-V(II+K)*V(KJ) 365060 CONTINUE 3651 V(II+J)=S*V(II+I) 365265 CONTINUE 3653 ENDIF 3654 II=II+N 365570 CONTINUE 3656C 3657C**** MULTIPLY INVERSE BY ITS TRANSPOSE 3658C 3659 L=0 3660 II=0 3661 DO 80 I=1,NP 3662 DO 79 J=1,I 3663 L=L+1 3664 S=0.D0 3665 KK=II 3666 DO 75 K=I,NP 3667 S=S+V(KK+I)*V(KK+J) 3668 KK=KK+N 366975 CONTINUE 3670 WS(L)=S*X0 367179 CONTINUE 3672 II=II+N 367380 CONTINUE 3674C 3675C ******************************************************* 3676C ** STEP 12.2-- ** 3677C ** PRINT OUT FINAL PARAMETER ESTIMATES ** 3678C ** AND THEIR STANDARD DEVIATIONS. ** 3679C ** ALSO PRINT OUT THE RESIDUAL STANDARD DEVIATION. ** 3680C ******************************************************* 3681C 3682CCCCC JULY 1997. PRINT SUMMARY INFORMATION IF MAX ITERATIONS REACHED. 3683CCCCC ADD FOLLOWING LINE. 3684CCCCC NOVEMBER 2016. NEED TO DO SOME COMPUTATIONS IN THIS SECITON, 3685CCCCC SO JUST SKIP THE CALL TO PRINTING THE TABLE. 3686 2999 CONTINUE 3687CCCCC IF(IPRINT.EQ.'ON')THEN 3688C 3689C PRINT REST OF ITERATIONS TABLE 3690C 3691 IF(ICNT.GE.1)THEN 3692 CALL DPDTA5(ITITLE,NCTITL, 3693 1 ITITL9,NCTIT9,ITITL2,NCTIT2, 3694 1 MAXLIN,NUMLIN,NUMCLI,NUMCOL, 3695 1 IVALUE,NCVALU,AMAT,ITYPCO,MAXROW,ICNT, 3696 1 IDIGIT,NTOT,IWHTML,IWRTF,VALIGN,ALIGN,NMAX, 3697 1 ICAPSW,ICAPTY,IFRST,ILAST, 3698 1 IFLAGS,IFLAGE, 3699 1 ISUBRO,IBUGA3,IERROR) 3700 ENDIF 3701C 3702 ITITLE=' ' 3703 NCTITL=0 3704 ITITL9=' ' 3705 NCTIT9=0 3706C 3707 NUMCOL=6 3708 NUMLIN=2 3709C 3710 DO4101J=1,NUMCLI 3711 DO4102I=1,MAXLIN 3712 ITITL2(I,J)=' ' 3713 NCTIT2(I,J)=0 3714 NCOLSP(I,J)=0 3715 4102 CONTINUE 3716 DO4103I=1,MAXROW 3717 IVALUE(I,J)=' ' 3718 NCVALU(I,J)=0 3719 AMAT(I,J)=0.0 3720 ROWSEP(I)=0 3721 4103 CONTINUE 3722 4101 CONTINUE 3723C 3724 ITITL2(1,1)=' ' 3725 NCTIT2(1,1)=0 3726 NCOLSP(1,1)=1 3727 ITITL2(2,1)=' ' 3728 NCTIT2(2,1)=0 3729 NCOLSP(2,1)=1 3730C 3731 ITITL2(1,2)=' ' 3732 NCTIT2(1,2)=0 3733 NCOLSP(1,2)=3 3734 ITITL2(2,2)='Final Parameter Estimates' 3735 NCTIT2(2,2)=25 3736 NCOLSP(2,2)=3 3737C 3738 ITITL2(1,5)='Approximate' 3739 NCTIT2(1,5)=11 3740 NCOLSP(1,5)=1 3741 ITITL2(2,5)='Standard Deviation' 3742 NCTIT2(2,5)=18 3743 NCOLSP(2,5)=1 3744C 3745 ITITL2(1,6)=' ' 3746 NCTIT2(1,6)=0 3747 NCOLSP(1,6)=1 3748 ITITL2(2,6)='t-Value' 3749 NCTIT2(2,6)=7 3750 NCOLSP(2,6)=1 3751C 3752 NMAX=0 3753 DO4110I=1,NUMCOL 3754 VALIGN(I)='b' 3755 ALIGN(I)='r' 3756 NTOT(I)=15 3757 IF(I.EQ.1)NTOT(I)=3 3758 IF(I.EQ.2)NTOT(I)=10 3759 IF(I.EQ.3)NTOT(I)=10 3760 IF(I.EQ.5)NTOT(I)=20 3761 IF(I.EQ.6)NTOT(I)=10 3762 NMAX=NMAX+NTOT(I) 3763 ITYPCO(I)='NUME' 3764 IF(I.EQ.2 .OR. I.EQ.3)ITYPCO(I)='ALPH' 3765 DO4113J=1,MAXROW 3766 IDIGI2(J,I)=NUMDIG 3767 IF(I.EQ.1)THEN 3768 IDIGI2(J,I)=0 3769 ELSEIF(I.EQ.6)THEN 3770 IDIGI2(J,I)=4 3771 ENDIF 3772 4113 CONTINUE 3773 4110 CONTINUE 3774C 3775 KK=1 3776 J=0 3777 ICNT=0 3778 DO4120I=1,NP 3779C 3780 4188 CONTINUE 3781 II=I+J 3782 K=ICON3(II) 3783 J=J+K 3784C 3785 IF(K.EQ.1)THEN 3786 ICNT=ICNT+1 3787 AMAT(I,1)=REAL(I) 3788 IVALUE(I,2)(1:4)=IPARN3(I) 3789 IVALUE(I,2)(5:8)=IPARN4(I) 3790 NCVALU(I,2)=8 3791 IVALUE(I,3)(1:4)=' ' 3792 IVALUE(I,3)(5:8)=' ' 3793 NCVALU(I,3)=0 3794 AMAT(I,4)=PARAM3(II) 3795 AMAT(I,5)=0.0 3796 IDIGI2(I,5)=-1 3797 AMAT(I,6)=0.0 3798 IDIGI2(I,6)=-1 3799 GOTO4188 3800 ENDIF 3801 IF(WS(KK).GT.0.0)C(I)=SQRT(WS(KK)) 3802 IF(WS(KK).LE.0.0)C(I)=0.0 3803 KK=KK+I+1 3804C 3805 TVALUE=(-999.9) 3806 IF(C(I).NE.0.0)THEN 3807 TVALUE=PARAM3(II)/C(I) 3808 ENDIF 3809 TVALU2(I)=TVALUE 3810 ICNT=ICNT+1 3811 AMAT(I,1)=REAL(II) 3812 IVALUE(I,2)(1:4)=IPARN3(I) 3813 IVALUE(I,2)(5:8)=IPARN4(I) 3814 NCVALU(I,2)=8 3815 IVALUE(I,3)(1:4)=' ' 3816 IVALUE(I,3)(5:8)=' ' 3817 NCVALU(I,3)=0 3818 AMAT(I,4)=PARAM3(II) 3819 AMAT(I,5)=C(I) 3820 IDIGI2(I,5)=NUMDIG 3821 IF(C(I).GT.0.0)THEN 3822 AMAT(I,6)=TVALUE 3823 IDIGI2(I,6)=4 3824 ELSE 3825 AMAT(I,6)=0.0 3826 IDIGI2(I,6)=-1 3827 ENDIF 3828 4120 CONTINUE 3829C 3830 IWHTML(1)=50 3831 IWHTML(2)=100 3832 IWHTML(3)=100 3833 IWHTML(4)=150 3834 IWHTML(5)=200 3835 IWHTML(6)=150 3836 IINC=1800 3837 IINC2=200 3838 IINC3=1200 3839 IINC4=2500 3840 IWRTF(1)=IINC2 3841 IWRTF(2)=IWRTF(1)+IINC3 3842 IWRTF(3)=IWRTF(2)+IINC3 3843 IWRTF(4)=IWRTF(3)+IINC 3844 IWRTF(5)=IWRTF(4)+IINC4 3845 IWRTF(6)=IWRTF(5)+IINC 3846C 3847 IF(IPRINT.EQ.'ON')THEN 3848 IFRST=.TRUE. 3849 ILAST=.TRUE. 3850 IFLAGS=.TRUE. 3851 IFLAGE=.TRUE. 3852 CALL DPDT5B(ITITLE,NCTITL, 3853 1 ITITL9,NCTIT9,ITITL2,NCTIT2, 3854 1 MAXLIN,NUMLIN,NUMCLI,NUMCOL, 3855 1 IVALUE,NCVALU,AMAT,ITYPCO,MAXROW,ICNT, 3856 1 IDIGI2,NTOT,IWHTML,IWRTF,VALIGN,ALIGN,NMAX, 3857 1 NCOLSP,ROWSEP, 3858 1 ICAPSW,ICAPTY,IFRST,ILAST, 3859 1 IFLAGS,IFLAGE, 3860 1 ISUBRO,IBUGA3,IERROR) 3861 ENDIF 3862C 3863C ********************************************* 3864C ** STEP 13-- ** 3865C ** PRINT OUT GOODNESS OF FIT INFORMATION ** 3866C ********************************************* 3867C 3868 5000 CONTINUE 3869C 3870 IF(IREP.EQ.'YES')THEN 3871 IFITDF=IRESDF-IREPDF 3872 FITDF=IFITDF 3873 FITSS=RESSS-REPSS 3874 FITMS=100000.0 3875 IF(FITDF.GT.0.0)FITMS=FITSS/FITDF 3876 FSTAT=100000.0 3877 IF(REPMS.GT.0.0)FSTAT=FITMS/REPMS 3878 CALL FCDF(FSTAT,IFITDF,IREPDF,CDF) 3879 CDF2=100.0*CDF 3880 ALFCDF=CDF 3881 ENDIF 3882C 3883 IF(IPRINT.EQ.'ON')THEN 3884 ITITLE=' ' 3885 NCTITL=0 3886 ITITLZ=' ' 3887 NCTITZ=0 3888C 3889 ICNT=1 3890 ITEXT(ICNT)=' ' 3891 NCTEXT(ICNT)=0 3892 AVALUE(ICNT)=0.0 3893 IDIGIT(ICNT)=-1 3894 ICNT=ICNT+1 3895 ITEXT(ICNT)='Residual Standard Deviation:' 3896 NCTEXT(ICNT)=28 3897 AVALUE(ICNT)=RESSD 3898 IDIGIT(ICNT)=NUMDIG 3899 ICNT=ICNT+1 3900 ITEXT(ICNT)='Residual Degrees of Freedom:' 3901 NCTEXT(ICNT)=28 3902 AVALUE(ICNT)=REAL(IRESDF) 3903 IDIGIT(ICNT)=0 3904C 3905 IF(IREP.EQ.'YES')THEN 3906 ICNT=ICNT+1 3907 ITEXT(ICNT)='Replication Standard Deviation:' 3908 NCTEXT(ICNT)=31 3909 AVALUE(ICNT)=REPSD 3910 IDIGIT(ICNT)=NUMDIG 3911 ICNT=ICNT+1 3912 ITEXT(ICNT)='Replication Degrees of Freedom:' 3913 NCTEXT(ICNT)=31 3914 AVALUE(ICNT)=REAL(IREPDF) 3915 IDIGIT(ICNT)=0 3916 IF(IFITDF.LT.1)THEN 3917 ICNT=ICNT+1 3918 ITEXT(ICNT)='The Lack of Fit F Test cannot be done' 3919 NCTEXT(ICNT)=37 3920 AVALUE(ICNT)=0.0 3921 IDIGIT(ICNT)=-1 3922 ICNT=ICNT+1 3923 ITEXT(ICNT)='because the numerator of the F ratio' 3924 NCTEXT(ICNT)=36 3925 AVALUE(ICNT)=0.0 3926 IDIGIT(ICNT)=-1 3927 ICNT=ICNT+1 3928 ITEXT(ICNT)='has 0 degrees of freedom. This happens' 3929 NCTEXT(ICNT)=39 3930 AVALUE(ICNT)=0.0 3931 IDIGIT(ICNT)=-1 3932 ICNT=ICNT+1 3933 ITEXT(ICNT)='when the number of parameters fitted is' 3934 NCTEXT(ICNT)=39 3935 AVALUE(ICNT)=0.0 3936 IDIGIT(ICNT)=-1 3937 ICNT=ICNT+1 3938 ITEXT(ICNT)='equal to the number of distinct subsets.' 3939 NCTEXT(ICNT)=40 3940 AVALUE(ICNT)=0.0 3941 IDIGIT(ICNT)=-1 3942 ELSE 3943 ICNT=ICNT+1 3944 ITEXT(ICNT)='Lack of Fit F Ratio:' 3945 NCTEXT(ICNT)=20 3946 AVALUE(ICNT)=FSTAT 3947 IDIGIT(ICNT)=NUMDIG 3948 ICNT=ICNT+1 3949 ITEXT(ICNT)='Lack of Fit F CDF (%):' 3950 NCTEXT(ICNT)=22 3951 AVALUE(ICNT)=CDF2 3952 IDIGIT(ICNT)=NUMDIG 3953 ICNT=ICNT+1 3954 ITEXT(ICNT)='Lack of Fit Degrees of Freedom 1:' 3955 NCTEXT(ICNT)=33 3956 AVALUE(ICNT)=REAL(IFITDF) 3957 IDIGIT(ICNT)=0 3958 ICNT=ICNT+1 3959 ITEXT(ICNT)='Lack of Fit Degrees of Freedom 2:' 3960 NCTEXT(ICNT)=33 3961 AVALUE(ICNT)=REAL(IREPDF) 3962 IDIGIT(ICNT)=0 3963 ENDIF 3964 ENDIF 3965C 3966 NUMROW=ICNT 3967 DO2410I=1,NUMROW 3968 NTOT(I)=15 3969 2410 CONTINUE 3970C 3971 IFRST=.TRUE. 3972 ILAST=.TRUE. 3973 CALL DPDTA1(ITITLE,NCTITL,ITITLZ,NCTITZ,ITEXT, 3974 1 NCTEXT,AVALUE,IDIGIT, 3975 1 NTOT,NUMROW, 3976 1 ICAPSW,ICAPTY,ILAST,IFRST, 3977 1 ISUBRO,IBUGA3,IERROR) 3978 ENDIF 3979C 3980CCCCC JULY 1997. MAX ITERATIONS FIX 3981 IF(ITS.GE.MAXITS) GO TO 910 3982 IF(NUMPAR.LE.0)GOTO9000 3983C 3984C ******************************************** 3985C ** PRINT OUT CORRELATIONS OF REGRESSION ** 3986C ** COEFFICIENT ESTIMATES ** 3987C ** (IF CALLED FOR) ** 3988C ******************************************** 3989C 3990 IF(NP.GE.N) GO TO 910 3991C 3992 IF(IBUGA3.EQ.'ON' .OR. ISUBRO.EQ.'FIT2')THEN 3993 WRITE(ICOUT,108) 3994108 FORMAT(20X,'CORRELATIONS OF PARAMETER ESTIMATES') 3995 CALL DPWRST('XXX','BUG ') 3996 ENDIF 3997C 3998 L=0 3999 KJ = 0 4000 DO 95 I=1,NP 400189 CONTINUE 4002 II = I + KJ 4003 K = ICON3(II) 4004 KJ = KJ + K 4005 IF(K.EQ.1) GO TO 89 4006 IF(C(I).NE.0.0) GO TO 83 4007 C(I) = EPS 4008 GO TO 95 400983 CONTINUE 4010 DO 94 J=1,I 4011 L=L+1 4012 WS(IY+J)=WS(L)/(C(I)*C(J)) 4013 VARCOV(I,J)=WS(L) 4014 VARCOV(J,I)=WS(L) 4015 CORR(I,J)=WS(L)/(C(I)*C(J)) 4016 CORR(J,I)=WS(L)/(C(I)*C(J)) 4017 94 CONTINUE 4018C 4019 IF(IBUGA3.EQ.'ON' .OR. ISUBRO.EQ.'FIT2')THEN 4020 WRITE(ICOUT,209) II,(WS(IY+J),J=1,I) 4021 209 FORMAT(I6,(10F12.5)) 4022 CALL DPWRST('XXX','BUG ') 4023 ENDIF 4024C 402595 CONTINUE 4026 IF(X0.GT.0.0)X0=SQRT(X0) 4027 IF(X0.LE.0.0)X0=0.0 4028 DO1501J=1,NUMPAR 4029 PARAM5(J)=PARAM3(J) 4030 1501 CONTINUE 4031 DO1500I=1,N 4032 IF(NUMVAR.GE.1)THEN 4033 DO1505J=1,NUMVAR 4034 PARAM5(NUMPAR+J)=XMAT(I,J) 4035 1505 CONTINUE 4036 ENDIF 4037C 4038 CALL COMPIM(MODEL,NUMCHA,IPASS,PARAM5,IPARN5,IPARN6,NUMPV, 4039 1 IANGLU,ITYPEH,IW2HOL,IW22HO,W2HOLD,NWHOLD,PRED2(I), 4040 1 IBUGCO,IBUGEV,IERROR) 4041 PRED2(I)=PRED2(I)*WSQRT(I) 4042 IF(IERROR.EQ.'YES')GOTO9000 4043 1500 CONTINUE 4044 DO1510J=1,NUMPAR 4045 PARAM7(J)=PARAM3(J) 4046 1510 CONTINUE 4047 DO1520J=1,NUMPAR 4048 IF(PARAM3(J).EQ.0.0)H=0.001 4049 IF(PARAM3(J).NE.0.0)H=PARAM3(J)*0.01 4050 PARAM7(J)=PARAM3(J)+H 4051 DO1530I=1,N 4052 IF(NUMVAR.GE.1)THEN 4053 DO1535JJ=1,NUMVAR 4054 PARAM7(NUMPAR+JJ)=XMAT(I,JJ) 4055 1535 CONTINUE 4056 ENDIF 4057C 4058 CALL COMPIM(MODEL,NUMCHA,IPASS,PARAM7,IPARN5,IPARN6,NUMPV, 4059 1 IANGLU,ITYPEH,IW2HOL,IW22HO,W2HOLD,NWHOLD,Y1, 4060 1 IBUGCO,IBUGEV,IERROR) 4061 Y1=Y1*WSQRT(I) 4062 IF(IERROR.EQ.'YES')GOTO9000 4063 K=I+(J-1)*N 4064 V(K)=(Y1-PRED2(I))/H 4065 V(K)=-V(K) 4066 1530 CONTINUE 4067 PARAM7(J)=PARAM3(J) 4068 1520 CONTINUE 4069C 4070 SUM=0.0 4071 DO1540I=1,N 4072 RES2(I)=Y2(I)-PRED2(I) 4073 SUM=SUM+RES2(I)**2 4074 1540 CONTINUE 4075 SUMSQ=SUM 4076C 4077C**** FORM UNWEIGHTED (RAW) PREDICTED VALUES AND RESIDUALS 4078C 4079 DO1550I=1,N 4080 IF(WSQRT(I).LE.0.0)GOTO1550 4081 RES2(I)=Y2(I)-PRED2(I) 4082 RES2(I)=RES2(I)/WSQRT(I) 4083 PRED2(I)=Y(I)-RES2(I) 4084 1550 CONTINUE 4085C 4086C**** RELOCATE VAR-COV. MATRIX AND STANDARD ERRORS IF NCONST.NE.0. 4087C 4088CCCCC THE FOLLOWING LINE WAS CHANGED MARCH 1992 4089CC900 IF(NCONST.EQ.0) GOTO9000 4090 IF(NCONST.EQ.0) GOTO919 4091 L = NP*(NP+1)/2 4092 L2 = NP 4093 I = NPST 4094904 K = ICON3(I) 4095 IF(K.EQ.1) GO TO 903 4096 C(I) = C(L2) 4097 L2 = L2 - 1 4098 J = I 4099901 K = I*(I-1)/2 + J 4100 WS(K) = WS(L) 4101 L = L - 1 4102902 J = J - 1 4103 IF(J.LE.0) GO TO 903 4104 K = ICON3(J) 4105CCCCC IF(K) 902,901 4106 IF(K.LT.0)GOTO902 4107 IF(K.EQ.0)GOTO901 4108903 I = I - 1 4109 IF(I.GT.0) GO TO 904 4110910 NP = NPST 4111CCCCC THE FOLLOWING LINE WAS ADDED MARCH 1992 4112 919 CONTINUE 4113C 4114CCCCCC THE FOLLOWING SECTION WAS ADDED MARCH 1992 4115C ************************************************** 4116C ** STEP 81-- ** 4117C ** WRITE INFO OUT TO FILES-- ** 4118C ** 1) DPST1F.DAT--COEF SDCOEF TCDF ** 4119C ** 2) DPST2F.DAT--PRED AND SDPRED ** 4120C ** 3) DPST3F.DAT--PARAMETER VAR-COV MATRIX ** 4121C ************************************************** 4122C 4123 ISTEPN='86' 4124 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2') 4125 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 4126C 4127 IF(IFITAU.EQ.'OFF')GOTO9000 4128C 4129 IFORMT='(3E15.7,10X,2A4)' 4130 IF(IAUXDP.NE.7)THEN 4131 IFORMT=' ' 4132 IF(IAUXDP.LE.9)THEN 4133 IFORMT='(3Exx.x,10X,2A4)' 4134 ITOT=IAUXDP+8 4135 WRITE(IFORMT(4:5),'(I2)')ITOT 4136 WRITE(IFORMT(7:7),'(I1)')IAUXDP 4137 ELSE 4138 IFORMT='(3Exx.xx,10X,2A4)' 4139 ITOT=IAUXDP+8 4140 WRITE(IFORMT(4:5),'(I2)')ITOT 4141 WRITE(IFORMT(7:8),'(I2)')IAUXDP 4142 ENDIF 4143 ENDIF 4144C 4145 WRITE(IOUNI1,8613) 4146 8613 FORMAT(1X, 4147 1 'COEFFICIENT ', 4148 2 'COEF SD ', 4149 3 'T-VALUE ') 4150 DO8610I=1,NUMPAR 4151 WRITE(IOUNI1,IFORMT)PARAM3(I),C(I),TVALU2(I), 4152 1 IPARN3(I),IPARN4(I) 4153 8610 CONTINUE 4154C 4155 IFORMT='(30(E15.7,1X))' 4156 IF(IAUXDP.NE.7)THEN 4157 IFORMT=' ' 4158 IF(IAUXDP.LE.9)THEN 4159 IFORMT='(30(Exx.x,1X))' 4160 ITOT=IAUXDP+8 4161 WRITE(IFORMT(6:7),'(I2)')ITOT 4162 WRITE(IFORMT(9:9),'(I1)')IAUXDP 4163 ELSE 4164 IFORMT='(30(Exx.xx,1X))' 4165 ITOT=IAUXDP+8 4166 WRITE(IFORMT(6:7),'(I2)')ITOT 4167 WRITE(IFORMT(9:10),'(I2)')IAUXDP 4168 ENDIF 4169 ENDIF 4170C 4171 WRITE(IOUNI2,8624) 4172 8624 FORMAT(1X, 4173 1 'PARAMETER CORR ', 4174 2 'PARAMETER COV ') 4175 DO8623I=1,NP 4176 WRITE(IOUNI2,IFORMT) (CORR(I,J),J=1,NP) 4177 WRITE(IOUNI3,IFORMT) (VARCOV(I,J),J=1,NP) 4178 8623 CONTINUE 4179C8625 FORMAT(30(E15.7,1X)) 4180C 4181 IF(IFEEDB.EQ.'ON')THEN 4182 WRITE(ICOUT,8612) 4183 8612 FORMAT('DPST1F.DAT: COEF AND SD(COEF)') 4184 CALL DPWRST('XXX','BUG ') 4185 WRITE(ICOUT,8628) 4186 8628 FORMAT('DPST2F.DAT: PARAMETER CORRELATION MATRIX') 4187 CALL DPWRST('XXX','BUG ') 4188 WRITE(ICOUT,8627) 4189 8627 FORMAT('DPST3F.DAT: PARAMETER VARIANCE-COVARIANCE MATRIX') 4190 CALL DPWRST('XXX','BUG ') 4191 ENDIF 4192C 4193CCCCCC THE FOLLOWING SECTION WAS ADDED MARCH 1992 4194C ************************************** 4195C ** STEP 82-- ** 4196C ** CLOSE THE STORAGE FILES. ** 4197C ************************************** 4198C 4199 ISTEPN='82' 4200 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2') 4201 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 4202C 4203 IF(IFITAU.EQ.'ON')THEN 4204 IOP='CLOS' 4205 CALL DPAUFI(IOP,IFLAG1,IFLAG2,IFLAG3,IFLAG4,IFLAG5, 4206 1 IOUNI1,IOUNI2,IOUNI3,IOUNI4,IOUNI5, 4207 1 IBUGA3,ISUBRO,IERROR) 4208 IF(IERROR.EQ.'YES')GOTO9000 4209 ENDIF 4210C 4211C ***************** 4212C ** STEP 90-- ** 4213C ** EXIT ** 4214C ***************** 4215C 4216 9000 CONTINUE 4217 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT2')THEN 4218 WRITE(ICOUT,999) 4219 CALL DPWRST('XXX','BUG ') 4220 WRITE(ICOUT,9011) 4221 9011 FORMAT('***** AT THE END OF DPFIT2--') 4222 CALL DPWRST('XXX','BUG ') 4223 WRITE(ICOUT,9013)IERROR,N,NUMVAR,NUMPAR,NUMCHA 4224 9013 FORMAT('IERROR,N,NUMVAR,NUMPAR,NUMCHA = ',A4,2X,4I8) 4225 CALL DPWRST('XXX','BUG ') 4226 DO9015I=1,NUMPAR 4227 WRITE(ICOUT,9016)I,IPARN3(I),IPARN4(I),PARAM3(I) 4228 9016 FORMAT('I,IPARN3(I),IPARN4(I),PARAM3(I) = ',I8,2X,A4,A4,G15.7) 4229 CALL DPWRST('XXX','BUG ') 4230 9015 CONTINUE 4231 DO9020I=1,N 4232 WRITE(ICOUT,9021)I,Y(I),XMAT(I,1),XMAT(I,2),W(I), 4233 1 PRED2(I),RES2(I) 4234 9021 FORMAT('I,Y(I),XMAT(I,1),XMAT(I,2),W(I),PRED2(I),RES2(I) = ', 4235 1 I8,6G15.7) 4236 CALL DPWRST('XXX','BUG ') 4237 9020 CONTINUE 4238 DO9025I=1,N 4239 WRITE(ICOUT,9026)I,Y(I),Y2(I),W(I),WSQRT(I) 4240 9026 FORMAT('I,Y(I),Y2(I),W(I),WSQRT(I) = ',I8,4G15.7) 4241 CALL DPWRST('XXX','BUG ') 4242 9025 CONTINUE 4243 ENDIF 4244C 4245 RETURN 4246 END 4247 SUBROUTINE DPFIT3(Y,X,NLEFT,PARCOV,MAXPAR, 4248 1 NUMVAR,IVARN3,IVARN4,W,N, 4249 1 MODEL,NUMCHA,PARAM3,IPARN3,IPARN4,NUMPAR,ICON3, 4250 1 SCR,FITSD,FITPOW,ICASFI, 4251 1 IREP,REPSD,REPDF,RESSD,RESDF,PRED2,RES2,ALFCDF, 4252 1 BIC,DUM1,DUM2,Z,VSDPRE, 4253 1 IFITAC,ALPHA,RSQUAR,ADJRSQ,APRESS, 4254 1 ICAPSW,ICAPTY,IFORSW,IFITAU,IAUXDP, 4255 1 IBUGA3,IBUGCO,IBUGEV,ISUBRO,IERROR) 4256C 4257C NOTE--MAX NUMBER OF OBSERVATIONS N IS 1000 (NOT CHECKED FOR) 4258C NOTE--MAX NUMBER OF PARAMETERS K IS 30 (NOT CHECKED FOR) 4259C NOTE--DIMENSION OF G IS N (MAX IS 1000) 4260C NOTE--DIMENSION OF C IS K (MAX IS 30) 4261C NOTE--DIMENSION OF A IS N X K (BUT N X K MAX IS 10000) 4262C 4263C MORE DIMENSION INFO (FROM LSQRT)-- 4264C B VECTOR OF COEFFICIENTS (M+1 BY 1). 4265C Z VECTOR OF RESIDUALS (N BY 1). 4266C T VECTOR OF STANDARD DEVIATIONS OF COEFFICIENTS (M+1 BY 1). 4267C V VECTOR OF STANDARD DEVIATIONS OF PREDICTED VALUES 4268C (N BY 1). 4269C S VECTOR OF SQUARED FOURIER COEFFICIENTS (M+3 BY 1). THE 4270C FIRST M ELEMENTS OF THIS ARRAY ARE SUMS OF SQUARES 4271C WHICH CAN BE USED IN AN ANALYSIS OF VARIANCE. THE 4272C LAST TWO ELEMENTS OF S ARE NOT COMPUTED IN THIS SUB- 4273C ROUTINE BUT ARE RESERVED FOR QUANTITIES TO BE COMPUTED 4274C IN THE CALLING PROGRAM. 4275C E RESIDUAL SUM OF SQUARES. 4276C D AVERAGE NUMBER OF DIGITS IN AGREEMENT BETWEEN INITIAL 4277C SOLUTION AND THE FIRST ITERATION (IN SUBROUTINE SLVE). 4278C SD RESIDUAL STANDARD DEVIATION. 4279C NDF NO. OF DEGREES OF FREEDOM. 4280C SCR A SCRATCH VECTOR USED FOR INTERNAL CALCULATIONS 4281C ID ID = 0 EVERYTHING IS OK. 4282C ID = 1 AUGMENTED MATRIX IS SINGULAR. 4283C ID = 2 ITERATION PROCEDURE FAILED TO CONVERGE. 4284C 4285C WRITTEN BY--JAMES J. FILLIBEN 4286C STATISTICAL ENGINEERING DIVISION 4287C CENTER FOR APPLIED MATHEMATICS 4288C NATIONAL BUREAU OF STANDARDS 4289C WASHINGTON, D. C. 20234 4290C PHONE--301-921-3651 4291C NOTE--DATAPLOT IS A REGISTERED TRADEMARK 4292C OF THE NATIONAL BUREAU OF STANDARDS. 4293C LANGUAGE--ANSI FORTRAN (1977) 4294C VERSION NUMBER--87/7 4295C ORIGINAL VERSION--JUNE 1987. 4296C UPDATED --FEBRUARY 1988. (MAKE LINE NUMBERS ORDERLY) 4297C UPDATED --MARCH 1988. (INCLUDE B0 IN MULTILINEAR FIT) 4298C UPDATED --MARCH 1988. LOFCDF 4299C UPDATED --MARCH 1988. ERROR ARG. TO CALL TO LSQRT + BRANC 4300C UPDATED --SEPTEMBER 1988. ERROR BRANCH AFTER CALL TO DPREPS IF EM 4301C UPDATED --SEPTEMBER 1988. CONSTANT FIT 4302C UPDATED --NOVEMBER 1988. PROPER TITLE FOR MULTILINEAR 4303C UPDATED --MAY 1989. MATRIX X ADDED TO INPUT ARG LIST 4304C UPDATED --MAY 1989. ISUBRO ADDED TO INPUT ARG LIST 4305C UPDATED --NOVEMBER 1989. S(.) DOUB. PREC. TO SING. PREC. 4306C UPDATED --NOVEMBER 1989. OMITTED UNNEEDED DOUB. PREC. 4307C UPDATED --JUNE 1990. SOME DIMENSIONS MOVED TO DPFIT 4308C UPDATED --MARCH 1992. WRITE COEF SDCOEF TCDF TO FILE 4309C UPDATED --JULY 1993. WRITE DIAGONAL OF HAT MATRIX, 4310C PARAMETER COVARIANCE MATRIX TO 4311C FILE. 4312C UPDATED --SEPTEMBER 1993. ADD ISUBRO ARG TO LSQRT 4313C UPDATED --JANUARY 1994. WRITE SDPRED & LIMITS TO FILE 4314C UPDATED --FEBRUARY 1994. MERGE JIM AND ALAN UPDATES 4315C ADD DPST4F.DAT 4316C UPDATED --FEBRUARY 1994. DPWRST: 'BUG ' => 'WRIT' 4317C UPDATED --JUNE 1994. BUG IN DPST4F.DAT OUTPUT FOR 4318C POLYNOMIAL MODELS. 4319C UPDATED --MAY 1995. FIX SOME I/O 4320C UPDATED --SEPTEMBER 1995. ADD BLANK LINE FOR OUTPUT 4321C UPDATED --JANUARY 1996. FIX BOMB WITH CONSTANT FIT 4322C UPDATED --APRIL 1996. IPRINT SWITCH 4323C UPDATED --APRIL 2002. SUPPORT FOR NO CONSTANT TERM 4324C UPDATED --APRIL 2002. PRINT ERROR MESSAGE IF 4325C SINGULARITY DETECTED 4326C UPDATED --JUNE 2002. AUGMENT DPST2F.DAT OUTPUT 4327C UPDATED --JUNE 2002. AUGMENT DPST3F.DAT OUTPUT 4328C UPDATED --JUNE 2002. WRITE ANOVA TABLE TO 4329C DPST5F.DAT 4330C UPDATED --JULY 2003. MODIFY DIMENSIONING OF X TO 4331C ALLOW MORE FLEXIBILITY BETWEEN 4332C NUMBER OF ROWS AND COLUMNS. 4333C UPDATED --OCTOBER 2003. SUPPORT HTML, LATEX OUTPUT 4334C UPDATED --OCTOBER 2006. CALL LIST TO TPPF 4335C UPDATED --MAY 2011. USE DPAUFI TO OPEN/CLOSE 4336C DPST?F.DAT FILES 4337C UPDATED --MAY 2011. USE DPDTA1 AND DPDT5B TO PRINT 4338C OUTPUT 4339C UPDATED --OCTOBER 2013. COMPUTE BIC STATISTIC 4340C UPDATED --JUNE 2014. USER OPTION TO SUPPRESS 4341C WRITING TO AUXILLARY FILES 4342C UPDATED --APRIL 2019. USER CAN SPECIFY NUMBER OF 4343C DECIMAL POINTS FOR AUXILLARY 4344C FILES 4345C 4346C-----CHARACTER STATEMENTS FOR NON-COMMON VARIABLES------------------- 4347C 4348 CHARACTER*4 IVARN3 4349 CHARACTER*4 IVARN4 4350 CHARACTER*4 IPARN3 4351 CHARACTER*4 IPARN4 4352 CHARACTER*4 ICASFI 4353 CHARACTER*4 IREP 4354 CHARACTER*4 IWRITE 4355 CHARACTER*4 IBUGA3 4356 CHARACTER*4 IBUGCO 4357 CHARACTER*4 IBUGEV 4358CCCCC THE FOLLOWING LINE WAS INSERTED MAY 1989 4359 CHARACTER*4 ISUBRO 4360 CHARACTER*4 IERROR 4361C 4362 CHARACTER*4 IPARN5 4363 CHARACTER*4 IPARN6 4364C 4365 CHARACTER*4 IHOLD3 4366 CHARACTER*4 IHOLD4 4367 CHARACTER*4 ISUBN1 4368 CHARACTER*4 ISUBN2 4369 CHARACTER*4 ISTEPN 4370 CHARACTER*4 MODEL 4371 CHARACTER*4 IFITAC 4372 CHARACTER*4 IOP 4373C 4374 CHARACTER*4 ICAPSW 4375 CHARACTER*4 ICAPTY 4376 CHARACTER*4 IFORSW 4377 CHARACTER*4 IFITAU 4378 CHARACTER*20 IFORMT 4379C 4380 PARAMETER(NUMCLI=6) 4381 PARAMETER(MAXLIN=2) 4382 PARAMETER (MAXROW=40) 4383 CHARACTER*60 ITITLE 4384 CHARACTER*60 ITITLZ 4385 CHARACTER*60 ITITL9 4386 CHARACTER*60 ITEXT(MAXROW) 4387 CHARACTER*4 ALIGN(NUMCLI) 4388 CHARACTER*4 VALIGN(NUMCLI) 4389 REAL AVALUE(MAXROW) 4390 INTEGER NCTEXT(MAXROW) 4391 INTEGER IDIGIT(MAXROW) 4392 INTEGER IDIGI2(MAXROW,NUMCLI) 4393 INTEGER NTOT(MAXROW) 4394 INTEGER ROWSEP(MAXROW) 4395 CHARACTER*60 ITITL2(MAXLIN,NUMCLI) 4396 CHARACTER*20 IVALUE(MAXROW,NUMCLI) 4397 CHARACTER*4 ITYPCO(NUMCLI) 4398 INTEGER NCTIT2(MAXLIN,NUMCLI) 4399 INTEGER NCVALU(MAXROW,NUMCLI) 4400 INTEGER NCOLSP(MAXLIN,NUMCLI) 4401 INTEGER IWHTML(NUMCLI) 4402 INTEGER IWRTF(NUMCLI) 4403 REAL AMAT(MAXROW,NUMCLI) 4404 LOGICAL IFRST 4405 LOGICAL ILAST 4406 LOGICAL IFLAGS 4407 LOGICAL IFLAGE 4408C 4409C--------------------------------------------------------------------- 4410C 4411CCCCC THE FOLLOWING LINE WAS COMMENTED OUT NOVEMBER 1989 4412CCCCC BECAUSE THE VARIABLES WERE NEVER USED 4413CCCCC DOUBLE PRECISION SUM,SSS,SSINIT,SSR,WW,SSN,SUMSQ 4414C 4415CCCCC THE FOLLOWING LINE WAS COMMENTED OUT NOVEMBER 1989 4416CCCCC (BUG UNCOVERED BY NELSON HSU) 4417CCCCC DOUBLE PRECISION S 4418C 4419CCCCC THE FOLLOWING 3 LINES WERE COMMENTED OUT NOVEMBER 1989 4420CCCCC BECAUSE THE VARIABLES WERE NEVER USED 4421CCCCC DOUBLE PRECISION DS1,DS2 4422CCCCC DOUBLE PRECISION DRAT1,DRAT2 4423CCCCC DOUBLE PRECISION DRAT 4424C 4425 DOUBLE PRECISION DSUM1 4426C--------------------------------------------------------------------- 4427C 4428 INCLUDE 'DPCOPA.INC' 4429C 4430CCCCC THE FOLLOWING INCLUDE STATEMENT WAS ADDED MARCH 1992 4431 INCLUDE 'DPCOF2.INC' 4432 DIMENSION Y(*) 4433 DIMENSION X(NLEFT,*) 4434 DIMENSION PRED2(*) 4435 DIMENSION RES2(*) 4436 DIMENSION W(*) 4437 DIMENSION DUM1(*) 4438 DIMENSION DUM2(*) 4439 DIMENSION Z(*) 4440 DIMENSION VSDPRE(*) 4441 DIMENSION SCR(*) 4442C 4443 DIMENSION MODEL(*) 4444C 4445 DIMENSION IVARN3(*) 4446 DIMENSION IVARN4(*) 4447 DIMENSION PARAM3(*) 4448 DIMENSION IPARN3(*) 4449 DIMENSION IPARN4(*) 4450 DIMENSION ICON3(*) 4451C 4452 DIMENSION IPARN5(80) 4453 DIMENSION IPARN6(80) 4454 DIMENSION PARAM5(80) 4455C 4456 DIMENSION C(80) 4457 DIMENSION PARCOV(MAXPAR+1,MAXPAR+1) 4458C 4459 DIMENSION B(100) 4460 DIMENSION T(101) 4461 DIMENSION S(102) 4462C 4463C **** THE ABOVE DIMENSION IS PROBABLY WRONG FOR LARGE DATA SETS JULY 1987 4464C 4465C--------------------------------------------------------------------- 4466C 4467 INCLUDE 'DPCOP2.INC' 4468C 4469C-----START POINT----------------------------------------------------- 4470C 4471 ISUBN1='DPFI' 4472 ISUBN2='T3 ' 4473 IERROR='NO' 4474C 4475 CDF2=0.0 4476 S=0.0 4477C 4478 NUMDIG=7 4479 IF(IFORSW.EQ.'1')NUMDIG=1 4480 IF(IFORSW.EQ.'2')NUMDIG=2 4481 IF(IFORSW.EQ.'3')NUMDIG=3 4482 IF(IFORSW.EQ.'4')NUMDIG=4 4483 IF(IFORSW.EQ.'5')NUMDIG=5 4484 IF(IFORSW.EQ.'6')NUMDIG=6 4485 IF(IFORSW.EQ.'7')NUMDIG=7 4486 IF(IFORSW.EQ.'8')NUMDIG=8 4487 IF(IFORSW.EQ.'9')NUMDIG=9 4488 IF(IFORSW.EQ.'0')NUMDIG=0 4489 IF(IFORSW.EQ.'E')NUMDIG=-2 4490 IF(IFORSW.EQ.'-2')NUMDIG=-2 4491 IF(IFORSW.EQ.'-3')NUMDIG=-3 4492 IF(IFORSW.EQ.'-4')NUMDIG=-4 4493 IF(IFORSW.EQ.'-5')NUMDIG=-5 4494 IF(IFORSW.EQ.'-6')NUMDIG=-6 4495 IF(IFORSW.EQ.'-7')NUMDIG=-7 4496 IF(IFORSW.EQ.'-8')NUMDIG=-8 4497 IF(IFORSW.EQ.'-9')NUMDIG=-9 4498C 4499 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT3')THEN 4500 WRITE(ICOUT,999) 4501 999 FORMAT(1X) 4502 CALL DPWRST('XXX','WRIT') 4503 WRITE(ICOUT,51) 4504 51 FORMAT('***** AT THE BEGINNING OF DPFIT3--') 4505 CALL DPWRST('XXX','WRIT') 4506 WRITE(ICOUT,52)N,NLEFT,NUMVAR,NUMPAR,NUMCHA,ICASFI 4507 52 FORMAT('N,NLEFT,NUMVAR,NUMPAR,NUMCHA,ICASFI = ',5I8,2X,A4) 4508 CALL DPWRST('XXX','WRIT') 4509 WRITE(ICOUT,53)IBUGA3,IBUGCO,IBUGEV,ISUBRO 4510 53 FORMAT('IBUGA3,IBUGCO,IBUGEV,ISUBRO = ',3(A4,2X),A4) 4511 CALL DPWRST('XXX','WRIT') 4512 WRITE(ICOUT,54)FITPOW,FITSD 4513 54 FORMAT('FITPOW,FITSD = ',2G15.7) 4514 CALL DPWRST('XXX','WRIT') 4515 DO55I=1,N 4516 WRITE(ICOUT,56)I,Y(I),X(I,1),X(I,2),X(I,3),X(I,5),W(I) 4517 56 FORMAT('I,Y(I),X(I,1),X(I,2),X(I,3),X(I,4),W(I) = ',I5,6E13.6) 4518 CALL DPWRST('XXX','WRIT') 4519 55 CONTINUE 4520 DO61J=1,NUMVAR 4521 WRITE(ICOUT,62)J,IVARN3(J),IVARN4(J) 4522 62 FORMAT('I,IVARN3(I),IVARN4(I) = ',I8,2X,A4,A4) 4523 CALL DPWRST('XXX','WRIT') 4524 61 CONTINUE 4525 DO66J=1,NUMPAR 4526 WRITE(ICOUT,67)J,IPARN3(J),IPARN4(J),PARAM3(J),ICON3(J) 4527 67 FORMAT('I,IPARN3(I),IPARN4(I),PARAM3(I),ICON3(I) = ', 4528 1 I8,2X,A4,A4,G15.7,I8) 4529 CALL DPWRST('XXX','WRIT') 4530 66 CONTINUE 4531 WRITE(ICOUT,71)(MODEL(J),J=1,MAX(100,NUMCHA)) 4532 71 FORMAT('FUNCTIONAL EXPRESSION--',100A1) 4533 CALL DPWRST('XXX','WRIT') 4534 ENDIF 4535C 4536CCCCCC THE FOLLOWING SECTION WAS ADDED MARCH 1992 4537C ************************************************** 4538C ** STEP 0.5-- ** 4539C ** OPEN THE STORAGE FILES ** 4540C ************************************************** 4541C 4542 ISTEPN='0.5' 4543 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT3') 4544 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 4545C 4546 IF(IFITAU.EQ.'ON')THEN 4547 IOP='OPEN' 4548 IFLAG1=1 4549 IFLAG2=1 4550 IFLAG3=1 4551 IFLAG4=1 4552 IFLAG5=1 4553 CALL DPAUFI(IOP,IFLAG1,IFLAG2,IFLAG3,IFLAG4,IFLAG5, 4554 1 IOUNI1,IOUNI2,IOUNI3,IOUNI4,IOUNI5, 4555 1 IBUGA3,ISUBRO,IERROR) 4556 IF(IERROR.EQ.'YES')GOTO9000 4557 ENDIF 4558C 4559C ************************************************** 4560C ** STEP 11-- ** 4561C ** DETERMINE THE PARAMETER NAMES IN THE MODEL ** 4562C ** AND THE NUMBER NUMPAR OF PARAMETERS. ** 4563C ************************************************** 4564C 4565 ISTEPN='11' 4566CCCCC IF(IBUGA3.EQ.'ON')CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) MAY 1989 4567 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT3') 4568 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 4569C 4570 IF(NUMPAR.GE.1)THEN 4571 DO1110I=1,NUMPAR 4572 IPARN5(I)=IPARN3(I) 4573 IPARN6(I)=IPARN4(I) 4574 PARAM5(I)=PARAM3(I) 4575 1110 CONTINUE 4576 ENDIF 4577C 4578 IF(NUMVAR.GE.1)THEN 4579 DO1120I=1,NUMVAR 4580 IPARN5(NUMPAR+I)=IVARN3(I) 4581 IPARN6(NUMPAR+I)=IVARN4(I) 4582 1120 CONTINUE 4583 ENDIF 4584C 4585 NUMPV=NUMPAR+NUMVAR 4586C 4587C ******************************************************** 4588C ** STEP 12-- ** 4589C ** DEFINE VARIOUS CONSTANTS. ** 4590C ** DEFINE NCONST = NUMBER OF PARAMETERS HELD CONSTANT.* 4591C ** DEFINE NP = NUMBER OF NON-CONSTNAT PARAMETERS. ** 4592C ** DEFINE DF = DEGREES OF FREEDOM. ** 4593C ** DEFINE SOME WORKING STORAGE START POINTS IN WS. ** 4594C ******************************************************** 4595C 4596 ISTEPN='12' 4597 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT3') 4598 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 4599C 4600 IREP='NO' 4601 REPSD=0.0 4602 REPDF=0.0 4603 IREPDF=INT(REPDF+0.5) 4604 RESSD=0.0 4605 RESDF=0.0 4606 IRESDF=0 4607 ALFCDF=(-999.99) 4608C 4609 IF(NUMPAR.LE.0)GOTO1239 4610 NPST=NUMPAR 4611 NCONST=0 4612C 4613 DO1210I=1,NUMPAR 4614 IF(ICON3(I).EQ.1)NCONST=NCONST+1 4615 1210 CONTINUE 4616 NP=NUMPAR-NCONST 4617C 4618 IF(NP.LE.0)THEN 4619 WRITE(ICOUT,1220) 4620 1220 FORMAT('***** ERROR IN FIT--') 4621 CALL DPWRST('XXX','WRIT') 4622 WRITE(ICOUT,1221)NP 4623 1221 FORMAT(' THE NUMBER OF PARAMETERS TO BE VARIED = ',I8, 4624 1 ' (LESS THAN ONE)') 4625 CALL DPWRST('XXX','WRIT') 4626 IER = 5 4627 IERROR='YES' 4628 GOTO9000 4629 ENDIF 4630C 4631 DF=N-NP 4632 RESDF=DF 4633 IRESDF=INT(DF+0.5) 4634C 4635 IC=0 4636 IER=2 4637 IDA=NP*NP 4638 IDU=IDA+NP 4639 ID =IDU+NP 4640 IDX=ID +NP 4641 IY =IDX+NP 4642C 4643 1239 CONTINUE 4644C 4645 IDEGRE=NUMPAR-1 4646 IF(IFITAC.EQ.'OFF')IDEGRE=NUMPAR 4647C 4648C 4649C ********************************************** 4650C ** STEP 13-- ** 4651C ** CHANGE THE WEIGHTS VECTOR W(.) ** 4652C ** SO THAT THE SUM OF SQUARED WEIGHTS = 1 ** 4653C ********************************************** 4654C 4655 ISTEPN='13' 4656 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT3') 4657 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 4658C 4659C ******************************************************** 4660C ** STEP 21-- ** 4661C ** CHECK FOR REPLICATION AND IF EXISTENT COMPUTE ** 4662C ** A (MODEL-FREE) REPLICATION STANDARD DEVIATION. ** 4663C ******************************************************** 4664C 4665 ISTEPN='21' 4666 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT3') 4667 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 4668C 4669C COLUMN 1 CONTAINS THE CONSTANT TERM, SO START IN COLUMN 2 4670C FOR REPLICATION TEST. IF THE FIT CONSTANT HAS BEEN TURNED 4671C OFF, THEN START IN COLUMN 1. 4672C 4673 IF(IFITAC.EQ.'OFF')THEN 4674 CALL DPREPS(Y,X,NLEFT,N,NUMVAR,DUM1,DUM2, 4675 1 IREP,REPSS,REPMS,REPSD,REPDF,NUMSET,IBUGA3,IERROR) 4676 ELSE 4677 CALL DPREPS(Y,X(1,2),NLEFT,N,NUMVAR,DUM1,DUM2, 4678 1 IREP,REPSS,REPMS,REPSD,REPDF,NUMSET,IBUGA3,IERROR) 4679 ENDIF 4680 IREPDF=INT(REPDF+0.5) 4681 IF(IERROR.EQ.'YES')GOTO9000 4682C 4683C ******************************************************* 4684C ** STEP 31-- ** 4685C ** CARRY OUT THE LEAST SQUARES FIT ** 4686C ** NOTE--IT = 1 IMPLIES POLYNOMIAL ** 4687C ** IT = 2 IMPLIES MULTILINEAR ** 4688C ** NOTE--M = DEGREE (IF POLYNOMIAL) ** 4689C ** M = NUMBER OF PARAMETERS (IF MULTILINEAR) ** 4690C ******************************************************* 4691C 4692 ISTEPN='31' 4693 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT3') 4694 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 4695C 4696 IF(ICASFI.EQ.'MFIT')THEN 4697 IT=2 4698 M=NUMPAR 4699 NR=NLEFT 4700 ELSE 4701 IT=1 4702 M=NUMPAR-1 4703 IF(IFITAC.EQ.'OFF')M=NUMPAR 4704 NR=NLEFT 4705 ENDIF 4706C 4707C THE FOLLOWING CHUNK OF CODE WAS ADDED SEPTEMBER 1988 4708C TO HANDLE THE CONSTANT FIT (Y = CONSTANT + ERROR) CASE. 4709C 4710 IF(IT.EQ.1.AND.M.EQ.0)THEN 4711 SUMWY=0.0 4712 SUMW=0.0 4713 DO3172I=1,N 4714 SUMWY=SUMWY+W(I)*Y(I) 4715 SUMW=SUMW+W(I) 4716 3172 CONTINUE 4717 AMEAN=SUMWY/SUMW 4718 B(1)=AMEAN 4719 DO3173I=1,N 4720 Z(I)=Y(I)-AMEAN 4721 3173 CONTINUE 4722 NDF=N-1 4723 ANDF=NDF 4724 AN=N 4725 SUMWY=0.0 4726 DO3174I=1,N 4727 SUMWY=SUMWY+W(I)*Z(I)**2 4728 3174 CONTINUE 4729 SD=0.0 4730 IF(NDF.GT.0)SD=SUMWY/ANDF 4731 IF(SD.LE.0.0)SD=0.0 4732 IF(SD.GT.0.0)SD=SQRT(SD) 4733 T(1)=SD/SQRT(AN) 4734 GOTO3190 4735 ELSE 4736C 4737CCCCC APRIL 2002. CHECK FOR CERTAIN KINDS OF SINGULARITIES IN 4738CCCCC MULTI-LINEAR FITS: 4739CCCCC 1) ANY COLUMNS ARE CONSTANTS. 4740CCCCC 2) ANY COLUMNS ARE EQUAL. 4741 IF(ICASFI.EQ.'MFIT')THEN 4742 IF(IFITAC.EQ.'ON')THEN 4743 ISTRT=2 4744 ISTOP=NUMPAR 4745 ELSE 4746 ISTRT=1 4747 ISTOP=NUMPAR 4748 ENDIF 4749 DO3176J=ISTRT,ISTOP 4750 AHOLD=X(1,J) 4751 DO3178I=1,N 4752 IF(AHOLD.NE.X(I,J))GOTO3176 4753 3178 CONTINUE 4754 WRITE(ICOUT,3181) 4755 3181 FORMAT('***** FROM DPFIT3, MULTI-LINEAR FIT CASE--') 4756 CALL DPWRST('XXX','WRIT') 4757 INDX=J 4758 IF(IFITAC.EQ.'ON')INDX=J-1 4759 WRITE(ICOUT,3183)IVARN3(INDX),IVARN4(INDX),AHOLD 4760 3183 FORMAT(' VARIABLE ',A4,A4,' HAS ALL VALUES = ',E15.7) 4761 CALL DPWRST('XXX','WRIT') 4762 WRITE(ICOUT,3185) 4763 3185 FORMAT(' THIS RESULTS IN A SINGULAR MATRIX. NO FIT ', 4764 1 'PERFORMED.') 4765 CALL DPWRST('XXX','WRIT') 4766 IERROR='YES' 4767 GOTO9000 4768 3176 CONTINUE 4769C 4770 DO13176J=ISTRT,ISTOP 4771 DO13179K=ISTRT,ISTOP 4772 IF(J.EQ.K)GOTO13179 4773 DO13181I=1,N 4774 IF(X(I,J).NE.X(I,K))GOTO13179 477513181 CONTINUE 4776 WRITE(ICOUT,3181) 4777 CALL DPWRST('XXX','WRIT') 4778 INDX=J 4779 INDX2=K 4780 IF(IFITAC.EQ.'ON')THEN 4781 INDX=J-1 4782 INDX2=K-1 4783 ENDIF 4784 WRITE(ICOUT,13183)IVARN3(INDX),IVARN4(INDX),IVARN3(INDX2), 4785 1 IVARN4(INDX2) 478613183 FORMAT(' VARIABLE ',2A4,' HAS ALL VALUES = TO ', 4787 1 'VARIABLE ',2A4) 4788 CALL DPWRST('XXX','WRIT') 4789 WRITE(ICOUT,13185) 479013185 FORMAT(' THIS RESULTS IN A SINGULAR MATRIX. NO ', 4791 1 'FIT PERFORMED.') 4792 CALL DPWRST('XXX','WRIT') 4793 IERROR='YES' 4794 GOTO9000 479513179 CONTINUE 479613176 CONTINUE 4797 ENDIF 4798C 4799 ENDIF 4800C 4801 CALL LSQRTX(Y,W,N,X,NR,M,IT, 4802 1 B,Z,T,VSDPRE,S,E,D,SD,NDF,SCR,ID,IFITAC, 4803 1 IBUGA3,ISUBRO,IERROR) 4804 IF(IERROR.EQ.'YES')GOTO9000 4805C 4806 3190 CONTINUE 4807 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT3')THEN 4808 WRITE(ICOUT,3191)N,M,NUMPAR 4809 3191 FORMAT('N,M,NUMPAR = ',3I8) 4810 CALL DPWRST('XXX','WRIT') 4811 ENDIF 4812C 4813C ******************************************************* 4814C ** STEP 32-- ** 4815C ** IF NEEDED, COMPUTE PREDICTED VALUES ** 4816C ** AND RESIDUALS. ** 4817C ** COPY OVER PARAMETERS, ETC. ** 4818C ******************************************************* 4819C 4820 ISTEPN='32' 4821 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT3') 4822 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 4823C 4824CCCCC JUNE 2002. ADD SOME COMPUTATIONS USED FOR THE ANOVA TABLE 4825C 4826 IWRITE='OFF' 4827 CALL MEAN(Y,N,IWRITE,YMEAN,IBUGA3,IERROR) 4828C 4829 DSUM1=0.0D0 4830 DO3210I=1,N 4831 RES2(I)=Z(I) 4832 PRED2(I)=Y(I)-RES2(I) 4833 DSUM1=DSUM1 + DBLE(PRED2(I) - YMEAN)**2 4834C 4835 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT3')THEN 4836 WRITE(ICOUT,3211)I,Y(I),PRED2(I),RES2(I) 4837 3211 FORMAT('I,Y(I),PRED2(I),RES2(I) = ',I8,3E15.7) 4838 CALL DPWRST('XXX','WRIT') 4839 ENDIF 4840C 4841 3210 CONTINUE 4842C 4843 SSR=REAL(DSUM1) 4844C 4845 DO3220I=1,NUMPAR 4846 PARAM3(I)=B(I) 4847 C(I)=T(I) 4848C 4849 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT3')THEN 4850 WRITE(ICOUT,3221)I,PARAM3(I),C(I) 4851 3221 FORMAT('I,PARAM3(I),C(I) = ',I8,2E15.7) 4852 CALL DPWRST('XXX','WRIT') 4853 ENDIF 4854C 4855 3220 CONTINUE 4856C 4857 RESSD=SD 4858 RESDF=NDF 4859 RESMS=RESSD*RESSD 4860 RESSS=RESMS*RESDF 4861C 4862C COMPUTE BIC VALUE: 4863C 4864C BIC = N*LOG(RESVAR) + P*LOG(N) 4865C 4866C NOTE THAT RESVAR FOR BIC USES DENOMINATOR OF N RATHER THAN 4867C (N - P). SO ADJUST FOR BIC. 4868C 4869 RESVAR=RESSD**2 4870 SSQTMP=REAL(N-NP)*RESVAR 4871 RESVA2=SSQTMP/REAL(N) 4872 BIC=REAL(N)*LOG(RESVA2) + REAL(NP)*LOG(REAL(N)) 4873C 4874 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT3')THEN 4875 WRITE(ICOUT,3231)RESSD,RESDF,RESMS,RESSS 4876 3231 FORMAT('RESSD,RESDF,RESMS,RESSS = ',4E15.7) 4877 CALL DPWRST('XXX','WRIT') 4878 ENDIF 4879C 4880C ********************************************* 4881C ** STEP 42-- ** 4882C ** PRINT OUT FIT TABLES ** 4883C ********************************************* 4884C 4885 IF(IREP.EQ.'YES')THEN 4886 IFITDF=IRESDF-IREPDF 4887 FITDF=IFITDF 4888 FITSS=RESSS-REPSS 4889 FITMS=100000.0 4890 IF(FITDF.GT.0.0)FITMS=FITSS/FITDF 4891 FSTAT=100000.0 4892 IF(REPMS.GT.0.0)FSTAT=FITMS/REPMS 4893 CALL FCDF(FSTAT,IFITDF,IREPDF,CDF) 4894 CDF2=100.0*CDF 4895 ALFCDF=CDF 4896 ENDIF 4897C 4898 IF(IPRINT.EQ.'ON')THEN 4899 IF(NUMPAR.GE.1 .AND. ICASFI.NE.'MFIT')THEN 4900 ITITLE='Least Squares Polynomial Fit' 4901 NCTITL=28 4902 ELSEIF(NUMPAR.GE.1 .AND. ICASFI.EQ.'MFIT')THEN 4903 ITITLE='Least Squares Multilinear Fit' 4904 NCTITL=29 4905 ELSEIF(NUMPAR.LE.0)THEN 4906 ITITLE='Fully-Specified Model' 4907 NCTITL=21 4908 ENDIF 4909 ITITLZ=' ' 4910 NCTITZ=0 4911C 4912 DO2301I=1,MAXROW 4913 ITEXT(I)=' ' 4914 NCTEXT(I)=0 4915 AVALUE(I)=0.0 4916 IDIGIT(I)=NUMDIG 4917 2301 CONTINUE 4918 ICNT=1 4919 ITEXT(ICNT)=' ' 4920 NCTEXT(ICNT)=0 4921 AVALUE(ICNT)=0.0 4922 IDIGIT(ICNT)=-1 4923 ICNT=ICNT+1 4924 ITEXT(ICNT)='Sample Size:' 4925 NCTEXT(ICNT)=12 4926 AVALUE(ICNT)=REAL(N) 4927 IDIGIT(ICNT)=0 4928 IDEGRE=NUMPAR-1 4929 IF(ICASFI.NE.'MFIT')THEN 4930 IF(IFITAC.EQ.'OFF')IDEGRE=NUMPAR 4931 ICNT=ICNT+1 4932 ITEXT(ICNT)='Degree:' 4933 NCTEXT(ICNT)=7 4934 AVALUE(ICNT)=REAL(IDEGRE) 4935 IDIGIT(ICNT)=0 4936 ELSE 4937 ICNT=ICNT+1 4938 ITEXT(ICNT)='Number of Variables:' 4939 NCTEXT(ICNT)=20 4940 AVALUE(ICNT)=REAL(IDEGRE) 4941 IDIGIT(ICNT)=0 4942 ENDIF 4943C 4944 ICNT=ICNT+1 4945 ITEXT(ICNT)='Residual Standard Deviation:' 4946 NCTEXT(ICNT)=28 4947 AVALUE(ICNT)=RESSD 4948 IDIGIT(ICNT)=NUMDIG 4949 ICNT=ICNT+1 4950 ITEXT(ICNT)='Residual Degrees of Freedom:' 4951 NCTEXT(ICNT)=28 4952 AVALUE(ICNT)=REAL(IRESDF) 4953 IDIGIT(ICNT)=0 4954 ICNT=ICNT+1 4955 ITEXT(ICNT)='BIC:' 4956 NCTEXT(ICNT)=4 4957 AVALUE(ICNT)=BIC 4958 IDIGIT(ICNT)=NUMDIG 4959 ICNT=ICNT+1 4960 ITEXT(ICNT)=' ' 4961 NCTEXT(ICNT)=0 4962 AVALUE(ICNT)=0.0 4963 IDIGIT(ICNT)=-1 4964C 4965 IF(IREP.EQ.'NO')THEN 4966 ICNT=ICNT+1 4967 ITEXT(ICNT)='No Replication Case:' 4968 NCTEXT(ICNT)=20 4969 AVALUE(ICNT)=0.0 4970 IDIGIT(ICNT)=-1 4971 ELSE 4972 ICNT=ICNT+1 4973 ITEXT(ICNT)='Replication Case:' 4974 NCTEXT(ICNT)=17 4975 AVALUE(ICNT)=0.0 4976 IDIGIT(ICNT)=-1 4977 ICNT=ICNT+1 4978 ITEXT(ICNT)='Replication Standard Deviation:' 4979 NCTEXT(ICNT)=31 4980 AVALUE(ICNT)=REPSD 4981 IDIGIT(ICNT)=NUMDIG 4982 ICNT=ICNT+1 4983 ITEXT(ICNT)='Replication Degrees of Freedom:' 4984 NCTEXT(ICNT)=31 4985 AVALUE(ICNT)=REAL(IREPDF) 4986 IDIGIT(ICNT)=0 4987 ICNT=ICNT+1 4988 ITEXT(ICNT)='Number of Distinct Subsets:' 4989 NCTEXT(ICNT)=31 4990 AVALUE(ICNT)=REAL(NUMSET) 4991 IDIGIT(ICNT)=0 4992 IF(IFITDF.LT.1)THEN 4993 ICNT=ICNT+1 4994 ITEXT(ICNT)='The Lack of Fit F Test cannot be done' 4995 NCTEXT(ICNT)=37 4996 AVALUE(ICNT)=0.0 4997 IDIGIT(ICNT)=-1 4998 ICNT=ICNT+1 4999 ITEXT(ICNT)='because the numerator of the F ratio' 5000 NCTEXT(ICNT)=36 5001 AVALUE(ICNT)=0.0 5002 IDIGIT(ICNT)=-1 5003 ICNT=ICNT+1 5004 ITEXT(ICNT)='has 0 degrees of freedom. This happens' 5005 NCTEXT(ICNT)=39 5006 AVALUE(ICNT)=0.0 5007 IDIGIT(ICNT)=-1 5008 ICNT=ICNT+1 5009 ITEXT(ICNT)='when the number of parameters fitted is' 5010 NCTEXT(ICNT)=39 5011 AVALUE(ICNT)=0.0 5012 IDIGIT(ICNT)=-1 5013 ICNT=ICNT+1 5014 ITEXT(ICNT)='equal to the number of distinct subsets.' 5015 NCTEXT(ICNT)=40 5016 AVALUE(ICNT)=0.0 5017 IDIGIT(ICNT)=-1 5018 ELSE 5019 ICNT=ICNT+1 5020 ITEXT(ICNT)='Lack of Fit F Ratio:' 5021 NCTEXT(ICNT)=20 5022 AVALUE(ICNT)=FSTAT 5023 IDIGIT(ICNT)=NUMDIG 5024 ICNT=ICNT+1 5025 ITEXT(ICNT)='Lack of Fit F CDF (%):' 5026 NCTEXT(ICNT)=22 5027 AVALUE(ICNT)=CDF2 5028 IDIGIT(ICNT)=NUMDIG 5029 ICNT=ICNT+1 5030 ITEXT(ICNT)='Lack of Fit Degrees of Freedom 1:' 5031 NCTEXT(ICNT)=33 5032 AVALUE(ICNT)=REAL(IFITDF) 5033 IDIGIT(ICNT)=0 5034 ICNT=ICNT+1 5035 ITEXT(ICNT)='Lack of Fit Degrees of Freedom 2:' 5036 NCTEXT(ICNT)=33 5037 AVALUE(ICNT)=REAL(IREPDF) 5038 IDIGIT(ICNT)=0 5039 ENDIF 5040 ENDIF 5041C 5042 NUMROW=ICNT 5043 DO2310I=1,NUMROW 5044 NTOT(I)=15 5045 2310 CONTINUE 5046C 5047 IFRST=.TRUE. 5048 ILAST=.TRUE. 5049 CALL DPDTA1(ITITLE,NCTITL,ITITLZ,NCTITZ,ITEXT, 5050 1 NCTEXT,AVALUE,IDIGIT, 5051 1 NTOT,NUMROW, 5052 1 ICAPSW,ICAPTY,ILAST,IFRST, 5053 1 ISUBRO,IBUGA3,IERROR) 5054 ITITLE=' ' 5055 NCTITL=-99 5056 ITITL9=' ' 5057 NCTIT9=0 5058C 5059 NUMCOL=6 5060 NUMLIN=2 5061C 5062 DO4101J=1,NUMCLI 5063 DO4102I=1,MAXLIN 5064 ITITL2(I,J)=' ' 5065 NCTIT2(I,J)=0 5066 NCOLSP(I,J)=0 5067 4102 CONTINUE 5068 DO4103I=1,MAXROW 5069 IVALUE(I,J)=' ' 5070 NCVALU(I,J)=0 5071 AMAT(I,J)=0.0 5072 ROWSEP(I)=0 5073 4103 CONTINUE 5074 4101 CONTINUE 5075C 5076 ITITL2(1,1)=' ' 5077 NCTIT2(1,1)=0 5078 NCOLSP(1,1)=1 5079 ITITL2(2,1)=' ' 5080 NCTIT2(2,1)=0 5081 NCOLSP(2,1)=1 5082C 5083 ITITL2(1,2)=' ' 5084 NCTIT2(1,2)=0 5085 NCOLSP(1,2)=3 5086 ITITL2(2,2)='Parameter Estimates' 5087 NCTIT2(2,2)=19 5088 NCOLSP(2,2)=3 5089C 5090 ITITL2(1,5)='Approximate' 5091 NCTIT2(1,5)=11 5092 NCOLSP(1,5)=1 5093 ITITL2(2,5)='Standard Deviation' 5094 NCTIT2(2,5)=18 5095 NCOLSP(2,5)=1 5096C 5097 ITITL2(1,6)=' ' 5098 NCTIT2(1,6)=0 5099 NCOLSP(1,6)=1 5100 ITITL2(2,6)='t-Value' 5101 NCTIT2(2,6)=7 5102 NCOLSP(2,6)=1 5103C 5104 NMAX=0 5105 DO4110I=1,NUMCOL 5106 VALIGN(I)='b' 5107 ALIGN(I)='r' 5108 NTOT(I)=15 5109 IF(I.EQ.1)NTOT(I)=3 5110 IF(I.EQ.2)NTOT(I)=10 5111 IF(I.EQ.3)NTOT(I)=10 5112 IF(I.EQ.5)NTOT(I)=20 5113 IF(I.EQ.6)NTOT(I)=10 5114 NMAX=NMAX+NTOT(I) 5115 ITYPCO(I)='NUME' 5116 IF(I.EQ.2 .OR. I.EQ.3)ITYPCO(I)='ALPH' 5117 DO4113J=1,MAXROW 5118 IDIGI2(J,I)=NUMDIG 5119 IF(I.EQ.1)THEN 5120 IDIGI2(J,I)=0 5121 ELSEIF(I.EQ.6)THEN 5122 IDIGI2(J,I)=4 5123 ENDIF 5124 4113 CONTINUE 5125 4110 CONTINUE 5126C 5127 DO4120I=1,NUMPAR 5128C 5129 IF(IFITAC.EQ.'OFF')THEN 5130 IM1=I 5131 IHOLD3=IVARN3(IM1) 5132 IHOLD4=IVARN4(IM1) 5133 ELSE 5134 IF(I.LE.1)IHOLD3=' ' 5135 IF(I.LE.1)IHOLD4=' ' 5136 IM1=I-1 5137 IF(I.GE.2)IHOLD3=IVARN3(IM1) 5138 IF(I.GE.2)IHOLD4=IVARN4(IM1) 5139 ENDIF 5140 TVALUE=(-999.9) 5141 IF(C(I).GT.0.0)TVALUE=PARAM3(I)/C(I) 5142C 5143 AMAT(I,1)=REAL(I) 5144 IVALUE(I,2)(1:4)=IPARN3(I) 5145 IVALUE(I,2)(5:8)=IPARN4(I) 5146 NCVALU(I,2)=8 5147C 5148 IF(ICASFI.EQ.'MFIT'.AND.C(I).GT.0.0)THEN 5149 IVALUE(I,3)(1:4)=IHOLD3 5150 IVALUE(I,3)(5:8)=IHOLD4 5151 NCVALU(I,3)=8 5152 AMAT(I,4)=PARAM3(I) 5153 AMAT(I,5)=C(I) 5154 AMAT(I,6)=TVALUE 5155 ELSEIF(ICASFI.EQ.'MFIT'.AND.C(I).EQ.0.0)THEN 5156 IVALUE(I,3)(1:4)=IHOLD3 5157 IVALUE(I,3)(5:8)=IHOLD4 5158 NCVALU(I,3)=8 5159 AMAT(I,4)=PARAM3(I) 5160 AMAT(I,5)=C(I) 5161 AMAT(I,6)=0.0 5162 IDIGI2(I,6)=-1 5163 ELSEIF(ICASFI.NE.'MFIT'.AND.C(I).GT.0.0)THEN 5164 IVALUE(I,3)=' ' 5165 NCVALU(I,3)=0 5166 AMAT(I,4)=PARAM3(I) 5167 AMAT(I,5)=C(I) 5168 AMAT(I,6)=TVALUE 5169 ELSEIF(ICASFI.NE.'MFIT'.AND.C(I).EQ.0.0)THEN 5170 IVALUE(I,3)=' ' 5171 NCVALU(I,3)=0 5172 AMAT(I,4)=PARAM3(I) 5173 AMAT(I,5)=C(I) 5174 AMAT(I,6)=0.0 5175 IDIGI2(I,6)=-1 5176 ENDIF 5177 4120 CONTINUE 5178C 5179 IWHTML(1)=50 5180 IWHTML(2)=100 5181 IWHTML(3)=100 5182 IWHTML(4)=150 5183 IWHTML(5)=200 5184 IWHTML(6)=150 5185 IINC=1800 5186 IINC2=200 5187 IINC3=1200 5188 IINC4=2500 5189 IWRTF(1)=IINC2 5190 IWRTF(2)=IWRTF(1)+IINC3 5191 IWRTF(3)=IWRTF(2)+IINC3 5192 IWRTF(4)=IWRTF(3)+IINC 5193 IWRTF(5)=IWRTF(4)+IINC4 5194 IWRTF(6)=IWRTF(5)+IINC 5195C 5196 ICNT=NUMPAR 5197 IFRST=.TRUE. 5198 ILAST=.TRUE. 5199 IFLAGS=.TRUE. 5200 IFLAGE=.TRUE. 5201 CALL DPDT5B(ITITLE,NCTITL, 5202 1 ITITL9,NCTIT9,ITITL2,NCTIT2, 5203 1 MAXLIN,NUMLIN,NUMCLI,NUMCOL, 5204 1 IVALUE,NCVALU,AMAT,ITYPCO,MAXROW,ICNT, 5205 1 IDIGI2,NTOT,IWHTML,IWRTF,VALIGN,ALIGN,NMAX, 5206 1 NCOLSP,ROWSEP, 5207 1 ICAPSW,ICAPTY,IFRST,ILAST, 5208 1 IFLAGS,IFLAGE, 5209 1 ISUBRO,IBUGA3,IERROR) 5210 ENDIF 5211C 5212CCCCCC THE FOLLOWING SECTION WAS ADDED MARCH 1992 5213C ************************************************ 5214C ** STEP 81-- ** 5215C ** WRITE INFO OUT TO FILES-- ** 5216C ** 1) DPST1F.DAT--COEF SDCOEF TCDF ** 5217C ** JUNE 2002: ADD JOINT BONFERRNI ** 5218C ** CONFIDENCE INTERVAL FOR PARAMETERS ** 5219C ** 2) DPST2F.DAT--SDPRED, CONFIDENCE ** 5220C ** INTERVAL FOR PREDICTED VALUES ** 5221C ** 3) DPST3F.DAT--REGRESSION DIAGNOSTICS ** 5222C ** 4) DPST4F.DAT--CORR MATRIX ** 5223C ** 5) DPST5F.DAT--ADD ANOVA TABLE (AND ** 5224C ** R-SQUARE, ADJUSTED R-SQUARE, MALLOWS** 5225C ** CP, PRESS P STATISTICS ** 5226C ** ADDED JUNE 2002 ** 5227C ************************************************ 5228C 5229 ISTEPN='86' 5230 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT3') 5231 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 5232C 5233 IF(IFITAU.EQ.'OFF')GOTO8619 5234C 5235CCCCC JUNE 2002. ADD T-VALUE AND JOINT BONFERONI CONFIDENCE 5236CCCCC LIMITS TO OUTPUT 5237C 5238 AJUNK=1.0 - ALPHA 5239 AJUNK2=1.0 - (AJUNK/(2.0*REAL(NUMPAR))) 5240 NP=N-NUMPAR 5241 TBONF=0.0 5242 IF(NP.GE.1.AND.(AJUNK2.GE.0.0.AND.AJUNK2.LE.1.0)) 5243 1CALL TPPF(AJUNK2,REAL(NP),TBONF) 5244C 5245 IFORMT='(5(E15.7,2X),2A4)' 5246 IF(IAUXDP.NE.7)THEN 5247 IFORMT=' ' 5248 IF(IAUXDP.LE.9)THEN 5249 IFORMT='(5(Exx.x,2X),2A4)' 5250 ITOT=IAUXDP+8 5251 WRITE(IFORMT(5:6),'(I2)')ITOT 5252 WRITE(IFORMT(8:8),'(I1)')IAUXDP 5253 ELSE 5254 IFORMT='(5(Exx.xx,2X),2A4)' 5255 ITOT=IAUXDP+8 5256 WRITE(IFORMT(5:6),'(I2)')ITOT 5257 WRITE(IFORMT(8:9),'(I2)')IAUXDP 5258 ENDIF 5259 ENDIF 5260C 5261 IF(IFITAU.EQ.'ON')THEN 5262 WRITE(IOUNI1,8613) 5263 8613 FORMAT(1X, 5264 1 'COEFFICIENT ', 5265 2 'COEF SD ', 5266 3 'T-VALUE ', 5267 4 'BONF LOWER CONF ', 5268 5 'BONF UPPER CONF ') 5269 DO8610I=1,NUMPAR 5270 TVALUE=(-999.9) 5271 IF(C(I).GT.0.0)TVALUE=PARAM3(I)/C(I) 5272 TBONL=PARAM3(I) - TBONF*C(I) 5273 TBONU=PARAM3(I) + TBONF*C(I) 5274 WRITE(IOUNI1,IFORMT)PARAM3(I),C(I),TVALUE,TBONL,TBONU, 5275 1 IPARN3(I),IPARN4(I) 5276 8610 CONTINUE 5277C8611 FORMAT(5E15.7,2X,A4,A4) 5278C 5279CCCCC THE FOLLOWING 2 LINES WERE ADDED SEPTEMBER 1995 5280CCCCC APRIL 1996. SUPPRESS PRINTING IF IPRINT OFF 5281 IF(IFEEDB.EQ.'ON')THEN 5282 WRITE(ICOUT,999) 5283 CALL DPWRST('XXX','BUG ') 5284 WRITE(ICOUT,999) 5285 CALL DPWRST('XXX','BUG ') 5286 WRITE(ICOUT,8612) 5287 8612 FORMAT('DPST1F.DAT: COEF, SD(COEF), T-VALUE, LOWER ,', 5288 1 'BONFERRONI UPPER BONFERRONI') 5289 CALL DPWRST('XXX','BUG ') 5290 ENDIF 5291 ENDIF 5292C 5293 8619 CONTINUE 5294C 5295CCCCC THE FOLLOWING SECTION WAS ACTIVATED JANUARY 1994 5296CCCCC JUNE 2002: ADD SUPPORT FOR JOINT BONFERRONI AND JOINT 5297CCCCC HOTELLING CONFIDENCE INTERVALS. 5298 T975=0.0 5299 T995=0.0 5300 IF(IRESDF.GE.1)CALL TPPF(.975,REAL(IRESDF),T975) 5301 IF(IRESDF.GE.1)CALL TPPF(.995,REAL(IRESDF),T995) 5302C 5303 TBONF=0.0 5304 THOT=0.0 5305 IF(AJUNK.LE.0.0 .OR. AJUNK.GE.1.0)AJUNK=0.95 5306 IF(ALPHA.GE.0.5)THEN 5307 AJUNK=1.0 - ALPHA 5308 ELSE 5309 AJUNK=ALPHA 5310 ENDIF 5311 AJUNK2=1.0 - (AJUNK/(2.0*REAL(N))) 5312 NP=N-NUMPAR 5313 IF(NP.GE.1.AND.(AJUNK2.GE.0.0.AND.AJUNK2.LE.1.0)) 5314 1CALL TPPF(AJUNK2,REAL(NP),TBONF) 5315 IF(NP.GE.1.AND.NUMPAR.GE.1.AND.(ALPHA.GE.0.0.AND.ALPHA.LE.1.0)) 5316 1CALL FPPF(ALPHA,NUMPAR,NP,THOT) 5317 THOT=REAL(NUMPAR)*THOT 5318 IF(THOT.GT.0.0)THOT=SQRT(THOT) 5319C 5320 IF(IFITAU.EQ.'OFF')GOTO8629 5321C 5322 WRITE(IOUNI2,8623) 5323 8623 FORMAT(1X, 5324 1 'SD PRED VALUES ', 5325 2 '95% LOW PRED CL ', 5326 3 '95% UPP PRED CL ', 5327 4 '99% LOW PRED CL ', 5328 5 '99% UPP PRED CL ', 5329 6 'BONF LOW PRED CL', 5330 7 'BONF UPP PRED CL', 5331 8 'HOTE LOW PRED CL', 5332 9 'HOTE UPP PRED CL') 5333 DO8620I=1,N 5334 PR=PRED2(I) 5335 SDPR=VSDPRE(I) 5336 ALOW2=PR-T975*SDPR 5337 AUPP2=PR+T975*SDPR 5338 ALOW3=PR-T995*SDPR 5339 AUPP3=PR+T995*SDPR 5340 ALOW4=PR-TBONF*SDPR 5341 AUPP4=PR+TBONF*SDPR 5342 ALOW5=PR-THOT*SDPR 5343 AUPP5=PR+THOT*SDPR 5344C 5345 IFORMT='(9(E15.7))' 5346 IF(IAUXDP.NE.7)THEN 5347 IFORMT=' ' 5348 IF(IAUXDP.LE.9)THEN 5349 IFORMT='(9(Exx.x))' 5350 ITOT=IAUXDP+8 5351 WRITE(IFORMT(5:6),'(I2)')ITOT 5352 WRITE(IFORMT(8:8),'(I1)')IAUXDP 5353 ELSE 5354 IFORMT='(9(Exx.xx))' 5355 ITOT=IAUXDP+8 5356 WRITE(IFORMT(5:6),'(I2)')ITOT 5357 WRITE(IFORMT(8:9),'(I2)')IAUXDP 5358 ENDIF 5359 ENDIF 5360C 5361 WRITE(IOUNI2,IFORMT)SDPR,ALOW2,AUPP2,ALOW3,AUPP3,ALOW4,AUPP4, 5362 1 ALOW5,AUPP5 5363C8621 FORMAT(9E15.7) 5364 8620 CONTINUE 5365CCCCC APRIL 1996. SUPPRESS PRINTING IF IPRINT OFF 5366 IF(IFEEDB.EQ.'ON')THEN 5367 WRITE(ICOUT,8622) 5368 8622 FORMAT('DPST2F.DAT: SD(PRED),95LOWER,95UPPER,99LOWER,99UPPER') 5369 CALL DPWRST('XXX','BUG ') 5370 WRITE(ICOUT,8624) 5371 8624 FORMAT(' LOWER BONFERRONI,UPPER BONFERRONI,', 5372 1 'LOWER HOTELLING,UPPER HOTELLING') 5373 CALL DPWRST('XXX','BUG ') 5374 ENDIF 5375C 5376 8629 CONTINUE 5377C 5378CCCC JULY 1993. UNCOMMENT FOLLOWING BLOCK. COPUTE AND PRINT: 5379CCCCC 1) DIAGONALS OF HAT MATRIX (HII = VAR(PRED VALUE)/RESIDUAL VAR) 5380CCCCC 2) VARIANCE OF RESIDUALS (VAR(RES) = MSE*(1-HII)) 5381CCCCC 3) STANDARDIZED RESIDUALS (STRES = RES/SQRT(MSE)) 5382CCCCC 4) INTERNALLY STUDENTIZED RESIDUALS ( = RES/SD(RES)) 5383CCCCC 5) DELETED RESIDUALS ( = RES/(1-HII)) 5384CCCCC 6) EXTERNALLY STUDENTIZED RESIDUALS (=RES*SQRT((N-P-1)/(SSE* 5385CCCCC (1-HII)-RES**2)) 5386CCCCC 7) COOK'S DISTANCE (COOK=(RES**2/(P*MSE))*HII/(1-HII)**2 5387CCCCC 8) DFFITS (DFFITS=EXTSRES*SQRT(HII(1-HII)) 5388CCCCC WHERE EXTSRES=EXTERNAL STUDENT RES 5389CCCCC IF HAVE PERFECT FIT, RESSD IS ZERO. DON'T PRINT DIAGNOSTIC 5390CCCCC STATISTICS IN THIS CASE. 5391C 5392 IF(IFITAU.EQ.'OFF')GOTO8649 5393C 5394 IF(RESSD.EQ.0.0)THEN 5395 WRITE(IOUNI3,8631) 5396 8631 FORMAT(1X,'PERFECT FIT, NO DIAGNOSTICS GENERATED.') 5397 GOTO8659 5398 ENDIF 5399C 5400 AJUNK=RESSD**2 5401 DSUM1=0.0D0 5402 DO8635I=1,N 5403 AJUNK2=VSDPRE(I)**2 5404 CALL SPDIV(AJUNK2,AJUNK,IND,Z(I)) 5405 IF(W(I).EQ.0.0)Z(I)=0.0 5406 8635 CONTINUE 5407 WRITE(IOUNI3,8639) 5408 8639 FORMAT(1X, 5409 1'DIAGONAL OF HAT ', 5410 2'RESIDUAL VAR ', 5411 3'STANDARD RES ', 5412 4'INT. STUD. RES ', 5413 5'DELETED RES ', 5414 6'EXT. STUD. RES ', 5415 7'COOKS DISTANCE ', 5416 8'DFFITS ') 5417 DO8640I=1,N 5418 AJUNK3=RESMS*(1.0-Z(I)) 5419 IF(AJUNK3.LE.0.0)AJUNK3=0.0 5420 IF(SQRT(RESMS).GT.0.0)THEN 5421 AJUNK4=RES2(I)/SQRT(RESMS) 5422 ELSE 5423 AJUNK4=0.0 5424 ENDIF 5425 IF(AJUNK3.GT.0.0)THEN 5426 AJUNK5=RES2(I)/SQRT(AJUNK3) 5427 ELSE 5428 AJUNK5=0.0 5429 ENDIF 5430 IF(Z(I).NE.1.0)THEN 5431 AJUNK6=RES2(I)/(1.0-Z(I)) 5432 DSUM1=DSUM1 + DBLE(AJUNK6)**2 5433 ELSE 5434 AJUNK6=CPUMAX 5435 ENDIF 5436 ACONST=(RESDF-1.0) 5437CCCCC SEPTEMBER 1993. FIX TYPO IN FOLLOWING LINE 5438CCCCC IF(RESS*(1.0-Z(I))-RES2(I)**2.NE.0.0)THEN 5439 IF(RESSS*(1.0-Z(I))-RES2(I)**2.NE.0.0)THEN 5440 AJUNK2=ACONST/(RESSS*(1.0-Z(I))-RES2(I)**2) 5441 ELSE 5442 AJUNK2=0.0 5443 ENDIF 5444 AJUNK7=0.0 5445 IF(AJUNK2.GE.0.0)AJUNK7=RES2(I)*SQRT(AJUNK2) 5446CCCCC THE FOLLOWING LINE WAS FIXED JANUARY 1996 5447CCCCC TO FIX BOMB WITH CONSTANT FIT JANUARY 1996 5448CCCCC AJUNK=RES2(I)**2/(REAL(M)*RESMS) 5449CCCCC USE NUMPAR INSTEAD OF M. 5450 AJUNK=0.0 5451CCCCC IF(M.GT.0)AJUNK=RES2(I)**2/(REAL(M)*RESMS) 5452 IF(NUMPAR.GT.0)AJUNK=RES2(I)**2/(REAL(NUMPAR)*RESMS) 5453 AJUNK2=0.0 5454 IF(Z(I)-1.0.NE.0.0)AJUNK2=Z(I)/((1.0-Z(I))**2) 5455 AJUNK8=AJUNK*AJUNK2 5456 AJUNK2=0.0 5457 IF(Z(I)-1.0.NE.0.0)AJUNK2=SQRT(Z(I)/(1.0-Z(I))) 5458 AJUNK9=AJUNK7*AJUNK2 5459C 5460 IFORMT='(8(E15.7,1X))' 5461 IF(IAUXDP.NE.7)THEN 5462 IFORMT=' ' 5463 IF(IAUXDP.LE.9)THEN 5464 IFORMT='(8(Exx.x,1X))' 5465 ITOT=IAUXDP+8 5466 WRITE(IFORMT(5:6),'(I2)')ITOT 5467 WRITE(IFORMT(8:8),'(I1)')IAUXDP 5468 ELSE 5469 IFORMT='(8(Exx.xx,1X))' 5470 ITOT=IAUXDP+8 5471 WRITE(IFORMT(5:6),'(I2)')ITOT 5472 WRITE(IFORMT(8:9),'(I2)')IAUXDP 5473 ENDIF 5474 ENDIF 5475C 5476 WRITE(IOUNI3,IFORMT)Z(I),AJUNK3,AJUNK4,AJUNK5,AJUNK6, 5477 1AJUNK7,AJUNK8,AJUNK9 5478C8641 FORMAT(8(E15.7,1X)) 5479 8640 CONTINUE 5480C 5481 APRESS=REAL(DSUM1) 5482C 5483CCCCC APRIL 1996. SUPPRESS PRINTING IF IPRINT OFF 5484 IF(IFEEDB.EQ.'ON')THEN 5485 WRITE(ICOUT,8652) 5486 8652 FORMAT('DPST3F.DAT: REGRESSION DIAGNOSTICS') 5487 CALL DPWRST('XXX','BUG ') 5488 ENDIF 5489C 5490 8649 CONTINUE 5491C 5492CCCCC JULY 1993. WRITE OUT VARIANCE-COVARIANCE PARAMETER OF 5493CCCCC PARAMETERS. NOTE THAT IT IS STORED IN SCRATCH SCR, STARTING 5494CCCCC AT ELEMENT 1 AND (M+1)*(M+2)/2 ELEMENTS LONG 5495CCCCC ACTUALLY, THIS IS THE (X-TRANSPOSE X) INVERSE MATRIX, MULTIPLY 5496CCCCC BY MSE TO GET VARIANCE-COVARIANCE MATRIX. 5497CCCCC JUNE 1994. BUG: FOR POLYNOMIAL, M=NUMPAR-1, SO ADD 1 BACK IN 5498C 5499 IF(IFITAU.EQ.'OFF')GOTO8689 5500C 5501 8659 CONTINUE 5502 NTEMP=M 5503 IF(ICASFI.NE.'MFIT')NTEMP=M+1 5504 ICOUNT=0 5505 DO8660I=1,NTEMP 5506 DO8662J=I,NTEMP 5507 ICOUNT=ICOUNT+1 5508 PARCOV(I,J)=SCR(ICOUNT) 5509 PARCOV(J,I)=PARCOV(I,J) 5510 8662 CONTINUE 5511 8660 CONTINUE 5512C 5513 IFORMT='(8(E15.7,1X))' 5514 IF(IAUXDP.NE.7)THEN 5515 IFORMT=' ' 5516 IF(IAUXDP.LE.9)THEN 5517 IFORMT='(2(Exx.x,1X))' 5518 ITOT=IAUXDP+8 5519 WRITE(IFORMT(5:6),'(I2)')ITOT 5520 WRITE(IFORMT(8:8),'(I1)')IAUXDP 5521 ELSE 5522 IFORMT='(2(Exx.xx,1X))' 5523 ITOT=IAUXDP+8 5524 WRITE(IFORMT(5:6),'(I2)')ITOT 5525 WRITE(IFORMT(8:9),'(I2)')IAUXDP 5526 ENDIF 5527 ENDIF 5528C 5529 WRITE(IOUNI4,8673) 5530 8673 FORMAT(1X, 5531 1 'PARAMETER COV ', 5532 2 'INVERSE X-TRANSPOSE*X') 5533 DO8670J=1,NTEMP 5534 DO8672I=1,NTEMP 5535 AJUNK=RESMS*PARCOV(I,J) 5536 WRITE(IOUNI4,IFORMT)AJUNK,PARCOV(I,J) 5537C8679 FORMAT(E15.7,1X,E15.7) 5538 8672 CONTINUE 5539 WRITE(IOUNI4,8678) 5540 8678 FORMAT(1X) 5541 8670 CONTINUE 5542C 5543CCCCC APRIL 1996. SUPPRESS PRINTING IF IPRINT OFF 5544 IF(IFEEDB.EQ.'ON')THEN 5545 WRITE(ICOUT,8682) 5546 8682 FORMAT('DPST4F.DAT: PARAMETER VARIANCE-COVARIANCE MATRIX AND') 5547 CALL DPWRST('XXX','BUG ') 5548 WRITE(ICOUT,8683) 5549 8683 FORMAT(' INVERSE OF X-TRANSPOSE X MATRIX') 5550 CALL DPWRST('XXX','BUG ') 5551 ENDIF 5552C 5553 8689 CONTINUE 5554C 5555CCCCC WRITE REGRESSION ANOVA TABLE TO DPST5F.DAT 5556C 5557 RESSD=SD 5558 RESDF=NDF 5559 RESMS=RESSD*RESSD 5560 RESSS=RESMS*RESDF 5561C 5562 IREGDF=NUMPAR-1 5563 AMSR=SSR/REAL(IREGDF) 5564C 5565 ITOTDF=INT(RESDF) + IREGDF 5566 SSTO=SSR + RESSS 5567C 5568 RSQUAR=1.0 - RESSS/SSTO 5569 ADJRSQ=1.0 - (REAL(N-1)/REAL(N-NUMPAR))*RESSS/SSTO 5570C 5571 FSTAT=100000.0 5572 IF(RESMS.GT.0.0)FSTAT=AMSR/RESMS 5573 NP=N-NUMPAR 5574 CALL FCDF(FSTAT,IREGDF,NP,CDF) 5575C 5576 IF(IFITAU.EQ.'OFF')GOTO8729 5577C 5578 WRITE(IOUNI5,8710) 5579 8710 FORMAT('------------------------------------------------------', 5580 1 '-----------------------') 5581 WRITE(IOUNI5,8712) 5582 8712 FORMAT('SOURCE DF SUM OF SQUARES ', 5583 1 ' MEAN SQUARE F') 5584 WRITE(IOUNI5,8710) 5585C 5586 WRITE(IOUNI5,8714)IREGDF,SSR,AMSR,FSTAT 5587 8714 FORMAT('REGRESSION ',I8,3X,E15.7,3X,E15.7,3X,E15.7) 5588 WRITE(IOUNI5,8716)INT(RESDF),RESSS,RESMS 5589 8716 FORMAT('RESIDUAL ',I8,3X,E15.7,3X,E15.7) 5590 WRITE(IOUNI5,8718)ITOTDF,SSTO 5591 8718 FORMAT('TOTAL ',I8,3X,E15.7) 5592C 5593 WRITE(IOUNI5,8710) 5594 WRITE(IOUNI5,999) 5595 WRITE(IOUNI5,999) 5596 WRITE(IOUNI5,8722)RSQUAR 5597 8722 FORMAT('R-SQUARE = ',F10.7) 5598 WRITE(IOUNI5,8724)ADJRSQ 5599 8724 FORMAT('ADJUSTED R-SQUARE = ',F10.7) 5600 WRITE(IOUNI5,8726)APRESS 5601 8726 FORMAT('PRESS-P STATISTIC = ',G15.7) 5602 WRITE(IOUNI5,8727)BIC 5603 8727 FORMAT('BIC = ',G15.7) 5604C 5605 IF(IFEEDB.EQ.'ON')THEN 5606 WRITE(ICOUT,8782) 5607 8782 FORMAT('DPST5F.DAT: REGRESSION ANOVA TABLE') 5608 CALL DPWRST('XXX','BUG ') 5609 ENDIF 5610C 5611 8729 CONTINUE 5612C 5613CCCCCC THE FOLLOWING SECTION WAS ADDED MARCH 1992 5614C ************************************** 5615C ** STEP 88-- ** 5616C ** CLOSE THE STORAGE FILES. ** 5617C ************************************** 5618C 5619 ISTEPN='87' 5620 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT3') 5621 1CALL TRACE2(ISTEPN,ISUBN1,ISUBN2) 5622C 5623 IF(IFITAU.EQ.'ON')THEN 5624 IOP='CLOS' 5625 CALL DPAUFI(IOP,IFLAG1,IFLAG2,IFLAG3,IFLAG4,IFLAG5, 5626 1 IOUNI1,IOUNI2,IOUNI3,IOUNI4,IOUNI5, 5627 1 IBUGA3,ISUBRO,IERROR) 5628 IF(IERROR.EQ.'YES')GOTO9000 5629 ENDIF 5630C 5631C ***************** 5632C ** STEP 90-- ** 5633C ** EXIT ** 5634C ***************** 5635C 5636 9000 CONTINUE 5637CCCCC IF(IBUGA3.EQ.'OFF')GOTO9090 MAY 1989 5638 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'FIT3')THEN 5639 WRITE(ICOUT,999) 5640 CALL DPWRST('XXX','WRIT') 5641 WRITE(ICOUT,9011) 5642 9011 FORMAT('***** AT THE END OF DPFIT3--') 5643 CALL DPWRST('XXX','WRIT') 5644 WRITE(ICOUT,9012)IERROR,ICASFI,IT 5645 9012 FORMAT('IERROR,ICASFI,IT = ',2(A4,2X),I8) 5646 CALL DPWRST('XXX','WRIT') 5647 WRITE(ICOUT,9013)N,NUMVAR,NUMPAR,NUMCHA 5648 9013 FORMAT('N,NUMVAR,NUMPAR,NUMCHA = ',4I8) 5649 CALL DPWRST('XXX','WRIT') 5650 DO9015I=1,NUMPAR 5651 WRITE(ICOUT,9016)I,IPARN3(I),IPARN4(I),PARAM3(I) 5652 9016 FORMAT('I,IPARN3(I),IPARN4(I),PARAM3(I) = ',I8,2X,A4,A4,G15.7) 5653 CALL DPWRST('XXX','WRIT') 5654 9015 CONTINUE 5655 DO9020I=1,N 5656 WRITE(ICOUT,9021)I,Y(I),W(I),PRED2(I),RES2(I) 5657 9021 FORMAT('I,Y(I),W(I),PRED2(I),RES2(I) = ', 5658 1 I8,4G15.7) 5659 CALL DPWRST('XXX','WRIT') 5660 9020 CONTINUE 5661 ENDIF 5662C 5663 RETURN 5664 END 5665CCCCC-----LSQRT-------------------------------------- 5666 SUBROUTINE LSQRTX (Y,W,N,X,NR,M,IT, 5667 1 B,Z,T,V,S,E,D,SD,NDF,SCR,ID,IFITAC, 5668 1 IBUGA3,ISUBRO,IERROR) 5669CCCCC THE ABOVE LINE WAS AUGMENTED SEPTEMBER 1993 5670C 5671C PURPOSE--PERFORM LEAST SQUARES FIT 5672C OF MULTILINEAR MODEL OR POLYNOMIAL MODEL 5673C USING A MODIFIED GRAM-SCHMIDT ALGORITHM 5674C WITH ITERATIVE REFINEMENT OF THE SOLUTION. 5675C 5676C INPUT ARGUMENTS-- 5677C Y VECTOR OF OBSERVATIONS (N BY 1). 5678C W VECTOR OF WEIGHTS (N BY 1). 5679C N NUMBER OF OBSERVATIONS. 5680C X MATRIX OF INDEPENDENT VARIABLES WHICH ARE TO BE FITTED. 5681C NR MAXIMUM NUMBER OF ROWS IN X. 5682C M NUMBER OF UNKNOWN COEFFICIENTS OR DEGREE OF POLYNOMIAL 5683C (M LESS THAN OR EQUAL TO N). 5684C IT PARAMETER WHICH SPECIFIES WHETHER OR NOT A POLYNOMIAL TYPE 5685C FIT IS TO BE PERFORMED. 5686C IT = 1 INDICATES POLYNOMIAL FIT. 5687C IT = 2 INDICATES MULTILINEAR FIT. 5688C 5689C 5690C IF IT = 1, THE FUNCTION TO BE FITTED IS A POLYNOMIAL 5691C HAVING THE FORM 5692C 5693C Y(I) = B(1) + B(2)*Z(I) + B(3)*Z(I)**2 + ... 5694C + B(M)*Z(I)**(M-1) + ERROR, I=1,2,...,N. 5695C 5696C IF IT = 2, THE FUNCTION TO BE FITTED HAS THE FORM 5697C 5698C Y(I) = B(1)*X1(I) + B(2)*X2(I) + ... + B(M)*XM(I) + 5699C ERROR, I=1,2,...,N. 5700C OUTPUT ARGUMENTS-- 5701C B VECTOR OF COEFFICIENTS (M+1 BY 1). 5702C Z VECTOR OF RESIDUALS (N BY 1). 5703C T VECTOR OF STANDARD DEVIATIONS OF COEFFICIENTS (M+1 BY 1). 5704C V VECTOR OF STANDARD DEVIATIONS OF PREDICTED VALUES 5705C (N BY 1). 5706C S VECTOR OF SQUARED FOURIER COEFFICIENTS (M+3 BY 1). THE 5707C FIRST M ELEMENTS OF THIS ARRAY ARE SUMS OF SQUARES 5708C WHICH CAN BE USED IN AN ANALYSIS OF VARIANCE. THE 5709C LAST TWO ELEMENTS OF S ARE NOT COMPUTED IN THIS SUB- 5710C ROUTINE BUT ARE RESERVED FOR QUANTITIES TO BE COMPUTED 5711C IN THE CALLING PROGRAM. 5712C E RESIDUAL SUM OF SQUARES. 5713C D AVERAGE NUMBER OF DIGITS IN AGREEMENT BETWEEN INITIAL 5714C SOLUTION AND THE FIRST ITERATION (IN SUBROUTINE SLVE). 5715C SD RESIDUAL STANDARD DEVIATION. 5716C NDF NO. OF DEGREES OF FREEDOM. 5717C SCR A SCRATCH VECTOR USED FOR INTERNAL CALCULATIONS 5718C ID ID = 0 EVERYTHING IS OK. 5719C ID = 1 AUGMENTED MATRIX IS SINGULAR. 5720C ID = 2 ITERATION PROCEDURE FAILED TO CONVERGE. 5721C 5722C NOTE--THE INPUT ARRAYS X, Y AND W ARE LEFT UNCHANGED 5723C BY THIS SUBROUTINE. 5724C NOTE--THE SCR VECTOR MUST HAVE SIZE EQUAL TO OR GREATER THAN 5725C ((M + 1) (M + 2) / 2) + N*M + 2*N + 2*M +1 5726C PRIMARY CALLING SEQUENCE-- 5727C LSQRT 5728C LSQ 5729C SCALE 5730C PDECOM 5731C SLVE 5732C DSUMAL 5733C SDPRED 5734C PINVRT 5735C ADDITIONAL SUBROUTINES THAT HAVE BEEN CONVERTED FROM FUNCTIONS-- 5736C DPDIV 5737C SPDIV 5738C DPCON 5739C DPSQRT 5740C SPSQRT 5741C SPLO10 5742C IDIV 5743C 5744C SUBROUTINE LSQ COMPUTES SOLUTIONS TO LINEAR LEAST SQUARES 5745C PROBLEMS USING A MODIFIED GRAM-SCHMIDT ALGORITHM WITH 5746C ITERATIVE REFINEMENT OF THE SOLUTION. 5747C 5748C SUBROUTINES PDECOM, SLVE AND PINVRT ARE BASED ON ... 5749C (1) ITERATIVE REFINEMENT OF LINEAR LEAST SQUARES SOLUTIONS II, 5750C BY AKE BJORCK, BIT, VOL. 8 (1968), PP. 8-30. 5751C (2) SOLUTIONS TO WEIGHTED LEAST SQUARES PROBLEMS BY MODIFIED 5752C GRAM-SCHMIDT WITH ITERATIVE REFINEMENT, BY ROY H. WAMPLER, 5753C ACM TRANSACTIONS ON MATHEMATICAL SOFTWARE, VOL. 5 (1979), 5754C TO APPEAR. 5755C 5756C PRECISION-- 5757C SINGLE PRECISION ARITHMETIC IS USED FOR ALL CALCULATIONS EXCEPT 5758C THE DOUBLE PRECISION ACCUMULATION OF INNER PRODUCTS. (THE 5759C VARIABLE SUM (OR DSUM) IS DECLARED TO BE DOUBLE PRECISION IN 5760C SUBROUTINE LSQ, SCALE, PDECOM, SLVE, SDPRED AND PINVRT.) IT 5761C IS ESSENTIAL FOR THE SUCCESS OF THE ITERATIVE REFINEMENT 5762C PROCEDURE IN SUBROUTINE SLVE THAT INNER PRODUCTS BE ACCUMULATED 5763C IN DOUBLE PRECISION. 5764C 5765C * CONVERSION OF THE PROGRAM TO STRICTLY DOUBLE PRECISION, AND * 5766C * CONVERSION OF THE PROGRAM TO STRICTLY SINGLE PRECISION. * 5767C * ON COMPUTERS HAVING SHORT WORD LENGTH (AS THE IBM 360/370) * 5768C * IT MAY BE DESIRABLE TO PERFORM ALL CALCULATIONS IN DOUBLE * 5769C * PRECISION. ON COMPUTERS HAVING LONG WORD LENGTH (AS THE CDC * 5770C * 6600) IT MAY BE DESIRABLE TO PERFORM ALL CALCULATIONS IN * 5771C * SINGLE PRECISION. IN SUCH CASES, THE ITERATIVE REFINEMENT * 5772C * PRESENTLY INCLUDED IN SUBROUTINE SLVE SHOULD BE OMITTED. * 5773C * ADDITIONAL REMARKS ON HOW TO OMIT THE ITERATIVE REFINEMENT * 5774C * ARE GIVEN IN SUBROUTINE SLVE. * 5775C * IF ALL COMPUTING IS DONE IN DOUBLE PRECISION, THE VALUE OF * 5776C * ETA, A MACHINE DEPENDENT PARAMETER, SHOULD BE CHANGED SO THAT * 5777C * ETA IS THE SMALLEST DOUBLE PRECISION NUMBER SUCH THAT * 5778C * 1.0 + ETA IS GREATER THAN 1.0 IN DOUBLE PRECISION ARITHMETIC. * 5779C 5780C TEST PROBLEM-- 5781C SAMPLE INPUT FOR A MULTILINEAR FIT 5782C (4 INDEPENDENT VARIABLES EQUIVALENT TO A CUBIC FIT 5783C AND UNIT WEIGHTING)-- 5784C FIRST LINE GIVES SAMPLE SIZE, DEGREE, POLYNOMIAL TYPE 5785C 5786C 7 4 2 5787C 10. 1. 3.4 11.56 39.304 1. 5788C 20. 1. 11.7 136.89 1601.613 1. 5789C 30. 1. 37.2 1383.84 51478.848 1. 5790C 40. 1. 80.1 6416.01 513922.401 1. 5791C 50. 1. 151.4 22921.96 3470384.744 1. 5792C 60. 1. 253.2 64110.24 16232712.768 1. 5793C 70. 1. 392.6 154134.76 60513306.776 1. 5794C 5795C SAMPLE INPUT FOR A CUBIC POLYNOMIAL FIT 5796C (SAME EXAMPLE AS ABOVE)-- 5797C FIRST LINE GIVES SAMPLE SIZE, NUMBER OF VAR., MULTILINEAR TYPE 5798C 5799C 7 3 1 5800C 10. 3.4 1. 5801C 20. 11.7 1. 5802C 30. 37.2 1. 5803C 40. 80.1 1. 5804C 50. 151.4 1. 5805C 60. 253.2 1. 5806C 70. 392.6 1. 5807C 5808C OUTPUT (FROM EITHER OF THE ABOVE 2 TEST PROBLEMS)-- 5809C 5810C COEFFICIENTS 5811C .12212494E+02 .46908681E+00 -.16867931E-02 .22115341E-05 5812C RESIDUALS 5813C -.37879763E+01 .25265538E+01 .25578816E+01 -.10042261E+00 5814C -.22425069E+01 .12562386E+01 -.20976813E+00 5815C S D OF COEFFICIENTS 5816C .26445864E+01 .86317750E-01 .57921800E-03 .98128429E-06 5817C S D OF PREDICATED VALUES 5818C .24379267E+01 .20369802E+01 .17428904E+01 .23363574E+01 5819C .23017371E+01 .31747709E+01 .33588546E+01 5820C SQUARED FOURIER COEFFICIENTS 5821C .11200000E+05 .24784422E+04 .23016542E+03 .57456310E+02 5822C RESIDUAL SUM OF SQUARES = .33936057E+02 5823C AVERAGE NO. DIGITS IN AGREEMENT = .78267799E+01 5824C RESIDUAL STANDARD DEVIATION = .33633345E+01 5825C DEGREES OF FREEDOM = 3 5826C 5827C NOTE--IN THE ABOVE TEST PROBLEMS, N = 7 AND M = 4 5828C AND THUS THE DIMENSION OF SCR MUST BE AT LEAST 5829C ((M + 1) (M + 2) / 2) + N*M + 2*N + 2*M +1 = 5830C ((4 + 1) (4 + 2) / 2) + 7*4 + 2*7 + 2*4 +1 = 66 5831C 5832C NOTE--MAXOBV = MAXIMUM NUMBER OF OBSERVATIONS PER VARIABLE 5833C (= 2048 (JULY 1987)) 5834C MAXCMF = MAXIMUM NUMBER OF COEFFICIENTS THAT MAY 5835C BE ESTIMATED IN A MULTILINEAR FIT 5836C (= 30 (JULY 1987)) 5837C WRITTEN BY--ROY H. WAMPLER 5838C STATISTICAL ENGINEERING DIVISION 5839C CENTER FOR APPLIED MATHEMATICS 5840C A337 ADMINISTRATION BUILDING 5841C NATIONAL BUREAU OF STANDARDS 5842C GAITHERSBURG, MD. 20899 5843C 301-975-2844 5844C 5845C CONVERTED TO DATAPLOT BY--JAMES J. FILLIBEN (JUNE 1987) 5846C LANGUAGE--ANSI FORTRAN (1977) 5847C VERSION NUMBER--87/7 5848C ORIGINAL VERSION--JUNE 1987. 5849C UPDATED --MARCH 1988. CHECK THAT SCRATCH AREA NOT EXCEEDED 5850C UPDATED --NOVEMBER 1989. DIMENSION SCR(1) TO SCR(*) 5851C UPDATED --SEPTEMBER 1993. ADD ISUBRO TO INPUT ARGS 5852C UPDATED --JULY 1995. ADJUST DEBUG FORMATS 5853C 5854C-----CHARACTER STATEMENTS FOR NON-COMMON VARIABLES------------------- 5855C 5856 CHARACTER*4 IFITAC 5857 CHARACTER*4 IBUGA3 5858CCCCC THE FOLLOWING LINE WAS ADDED SEPTEMBER 1993 5859 CHARACTER*4 ISUBRO 5860 CHARACTER*4 IERROR 5861C 5862C-----DIMENSION------------------------------------------------------- 5863 5864 INCLUDE 'DPCOPA.INC' 5865C 5866CCCCC DIMENSION X(NR,M),Y(N),W(N),B(M),Z(N),T(M+1),V(N),S(M+2),SCR(1) 5867CCCCC DIMENSION X(NR,M) 5868CCCCC DIMENSION X(MAXOBV,MAXCMF) 5869 DIMENSION X(NR,*) 5870 DIMENSION Y(N) 5871 DIMENSION W(N) 5872 DIMENSION B(M) 5873 DIMENSION Z(N) 5874 DIMENSION T(M+1) 5875 DIMENSION V(N) 5876 DIMENSION S(M+2) 5877CCCCC THE FOLLOWING LINE WAS CORRECTED NOVEMBER 1989 5878CCCCC (BUG UNCOVERED BY NELSON HSU) 5879CCCCC DIMENSION SCR(1) 5880 DIMENSION SCR(*) 5881C 5882C-----COMMON---------------------------------------------------------- 5883C 5884C-----COMMON VARIABLES (GENERAL)-------------------------------------- 5885C 5886 INCLUDE 'DPCOP2.INC' 5887C 5888C-----START POINT----------------------------------------------------- 5889C 5890 IERROR='NO' 5891C 5892CCCCC THE FOLLOWING LINE WAS CHANGED SEPTEBMER 1993 5893 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'SQRT')THEN 5894 WRITE(ICOUT,999) 5895 999 FORMAT(1X) 5896 CALL DPWRST('XXX','BUG ') 5897 WRITE(ICOUT,51) 5898 51 FORMAT('***** AT THE BEGINNING OF LSQRT--') 5899 CALL DPWRST('XXX','BUG ') 5900 WRITE(ICOUT,55)N,M,IT,IBUGA3 5901 55 FORMAT('N,M,IT,IBUGA3 = ',3I8,2X,A4) 5902 CALL DPWRST('XXX','BUG ') 5903 DO56J=1,M 5904 DO57I=1,N 5905 WRITE(ICOUT,58)I,J,Y(I),X(I,J),W(I) 5906 58 FORMAT('I,J,Y(I),X(I,J),W(I) = ',2I8,3G15.7) 5907 CALL DPWRST('XXX','BUG ') 5908 57 CONTINUE 5909 56 CONTINUE 5910 ENDIF 5911C 5912CCCCC THE FOLLOWING SECTION OF CODE WAS INSERTED MARCH 1988. 5913C CHECK THAT THE SCRATCH AREA WILL NOT OVERFLOW 5914C 5915 INEED=(((M+1)*(M+2))/2)+2*M+1+N*(M+2)+2 5916 IAVAIL=MAXOBW 5917 IF(INEED.GT.IAVAIL)THEN 5918 IERROR='YES' 5919 WRITE(ICOUT,999) 5920 CALL DPWRST('XXX','BUG ') 5921 WRITE(ICOUT,111) 5922 111 FORMAT('***** ERROR IN LSQRT--') 5923 CALL DPWRST('XXX','BUG ') 5924 WRITE(ICOUT,112) 5925 112 FORMAT(' INTERNAL REGRESSION SCRATCH AREA EXCEEDED.') 5926 CALL DPWRST('XXX','BUG ') 5927 WRITE(ICOUT,113)INEED 5928 113 FORMAT(' NEEDED SCRATCH AREA SIZE = ',I8) 5929 CALL DPWRST('XXX','BUG ') 5930 WRITE(ICOUT,114)IAVAIL 5931 114 FORMAT(' AVAILABLE SCRATCH AREA SIZE = ',I8) 5932 CALL DPWRST('XXX','BUG ') 5933 WRITE(ICOUT,115) 5934 115 FORMAT(' RECOMMENDATION--') 5935 CALL DPWRST('XXX','BUG ') 5936 WRITE(ICOUT,116) 5937 116 FORMAT(' 1. FIT TO A SUBSET; OR') 5938 CALL DPWRST('XXX','BUG ') 5939 WRITE(ICOUT,117) 5940 117 FORMAT(' 2. SIMPLIFY THE MODEL.') 5941 CALL DPWRST('XXX','BUG ') 5942 GOTO9000 5943 ENDIF 5944C 5945C DEFINE STARTING POINT FOR THE R MATRIX 5946C 5947 ISUBR = 1 5948 MZ = M 5949 IF (IT.EQ.1 .AND. IFITAC.EQ.'ON') MZ = MZ+1 5950 MIN2 = (MZ+1) * (MZ+2) / 2 5951C 5952C DEFINE STARTING POINT FOR THE Q VECTOR 5953C 5954 ISUBQ = ISUBR + MIN2 5955 MM1 = N * (MZ+1) 5956C 5957C DEFINE STARTING POINT FOR THE F VECTOR 5958C 5959 ISUBF = ISUBQ + MM1 5960C 5961C DEFINE STARTING POINT FOR THE P VECTOR 5962C 5963 ISUBP = ISUBF + MZ + 1 5964C 5965C DEFINE STARTING POINT FOR THE A VECTOR 5966C 5967 ISUBA = ISUBP + N 5968 C = 0.0 5969 H = 0.0 5970C 5971CCCCC THE FOLLOWING ARGUMENT LIST WAS AUGMENTED SEPTEMBER 1995 5972 CALL LSQ (N,MZ,NR,X,Y,W,H,C,IT,B,Z,SCR(ISUBR),T,V,S,E,SCR(ISUBQ), 5973 1 SCR(ISUBF),SCR(ISUBP),SCR(ISUBA),ID,D,IFITAC, 5974 1 IBUGA3,ISUBRO,IERROR) 5975C 5976 NDF = 0 5977 DO 1100 I = 1,N 5978 IF (W(I) .GT. 0.0) NDF = NDF + 1 5979 1100 CONTINUE 5980 NDF = NDF-MZ 5981CCCCC SD = SPDIV(E,FLOAT(NDF),IND) 5982 CALL SPDIV(E,FLOAT(NDF),IND,RESULT) 5983 SD = RESULT 5984CCCCC SD = SPSQRT(SD) 5985 CALL SPSQRT(SD,RESULT) 5986 SD=RESULT 5987C 5988 9000 CONTINUE 5989CCCCC THE FOLLOWING SECTION WAS ADDED SEPTEBMER 1993 5990 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'SQRT')THEN 5991 WRITE(ICOUT,999) 5992 CALL DPWRST('XXX','BUG ') 5993 WRITE(ICOUT,9011) 5994 9011 FORMAT('***** AT THE END OF LSQRT--') 5995 CALL DPWRST('XXX','BUG ') 5996 WRITE(ICOUT,9015)SD,RESULT,M,NDF 5997 9015 FORMAT('SD,RESULT,M,NDF = ',2G15.7,2I8) 5998 CALL DPWRST('XXX','BUG ') 5999 DO9016I=1,M 6000 WRITE(ICOUT,9017)I,B(I),T(I) 6001 9017 FORMAT('I,B(I),T(I) = ',I8,2G15.7) 6002 CALL DPWRST('XXX','BUG ') 6003 9016 CONTINUE 6004 ENDIF 6005 RETURN 6006 END 6007CCCCC-----LSQ-------------------------------------- 6008 SUBROUTINE LSQ (N,M,NR,X,Y,W,H,C,IT,B,Z,R,T,V,S,E,Q,F,P,A,ID,D, 6009 1 IFITAC,IBUGA3,ISUBRO,IERROR) 6010CCCCC SUBROUTINE LSQ (N,M,NR,X,Y,W,H,C,IT,B,Z,R,T,V,S,E,Q,F,P,A,ID,D) 6011CCCCC THE ABOVE ARGUMENT LIST WAS AUGMENTED SEPTEMBER 1995 6012C 6013C ================================================================== 6014C 6015C *** GENERAL COMMENTS *** 6016C 6017C WRITTEN BY - 6018C ROY H. WAMPLER, 6019C STATISTICAL ENGINEERING DIVISION, 6020C CENTER FOR APPLIED MATHEMATICS, 6021C A337 ADMINISTRATION BUILDING, 6022C NATIONAL BUREAU OF STANDARDS, 6023C GAITHERSBURG,MD. 20899 6024C TELEPHONE 301-975-2844 6025C 6026C UPDATED--NOVEMBER 1989--DIMENSION (1) TO (*) (AND MOVED) 6027C UPDATED --JUNE 1990. TEMPORARY ARRAYS TO GARBAGE COMMON 6028C UPDATED --SEPTEMBER 1995. ADD BUGS TO ARGUMENT LIST 6029C 6030C ================================================================== 6031C 6032C 6033C *** SPECIFICATION STATEMENTS *** 6034C 6035CCCCC THE FOLLOWING 3 LINES WERE ADDED SEPTEMBER 1995 6036 CHARACTER*4 IFITAC 6037 CHARACTER*4 IBUGA3 6038 CHARACTER*4 ISUBRO 6039 CHARACTER*4 IERROR 6040C 6041CCCCC THE FOLLOWING 6 LINES WERE MOVED NOVEMBER 1989 6042CCCCC AND CHANGED DIMENSION (1) TO (*) 6043CCCCC (BUG UNCOVERED BY NELSON HSU) 6044CCCCC REAL A(1), B(1), F(1), P(1), Q(1), R(1), S(1) 6045CCCCC REALCCCCC T(1), V(1), W(1), X(NR,M), Y(1), Z(1) 6046CCCCC REAL T(1), V(1), W(1), X, Y(1), Z(1) 6047CCCCC REAL C, D, E, H 6048CCCCC REAL ETA, RESDF, RMS, RSS, SD, TOL, U, WC, WW, YINC 6049CCCCC REALCCCCC SPDIV, DPCON, SPSQRT 6050C 6051CCCCC THE FOLLOWING LINE WAS CORRECTED NOVEMBER 1989 6052CCCCC SPLIT INTO 2 LINES 6053CCCCC AND CHANGED DIMENSION (1) TO (MAXOBV) (SEE BELOW) 6054CCCCC (BUG UNCOVERED BY NELSON HSU) 6055 DOUBLE PRECISION DX(1) 6056C 6057 DOUBLE PRECISION SUM 6058CCCCC THE FOLLOWING 2 LINES WERE ADDED SEPTEMBER 1995 6059 DOUBLE PRECISION SNEG 6060 DOUBLE PRECISION SPOS 6061C 6062 REAL A(*), B(*), F(*), P(*), Q(*), R(*), S(*) 6063CCCCC REAL T(*), V(*), W(*), X(NR,M), Y(*), Z(*) 6064 REAL T(*), V(*), W(*), X, Y(*), Z(*) 6065 REAL C, D, E, H 6066 REAL ETA, RESDF, RMS, RSS, SD, TOL, U, WC, WW, YINC 6067CCCCC REAL SPDIV, DPCON, SPSQRT 6068C 6069 INCLUDE 'DPCOPA.INC' 6070CCCCC DIMENSION X(MAXOBV,MAXCMF) 6071 DIMENSION X(NR,*) 6072C 6073C-----COMMON VARIABLES (GENERAL)-------------------------------------- 6074C 6075 INCLUDE 'DPCOP2.INC' 6076C 6077C-----DATA STATEMENTS----------------------------------------------------- 6078C 6079 DATA RMXINT / 134217727. / 6080C 6081C-----START POINT----------------------------------------------------- 6082C 6083 IF(IBUGA3.EQ.'ON')THEN 6084 WRITE(ICOUT,2001) 6085 2001 FORMAT('AT START OF LSQ ROUTINE') 6086 CALL DPWRST('XXX','BUG ') 6087 WRITE(ICOUT,2003)IFITAC 6088 2003 FORMAT('IFITAC = ',A4) 6089 CALL DPWRST('XXX','BUG ') 6090 DO2000I=1,N 6091 WRITE(ICOUT,2011)I,J,(X(I,J),J=1,MAX(M,5)) 6092 2011 FORMAT('I,J,(X(I,J),J=1,MAX(M,5)) = ',2I5,5G15.7) 6093 CALL DPWRST('XXX','BUG ') 6094 2000 CONTINUE 6095 ENDIF 6096C 6097 IERROR='NO' 6098 ID = 0 6099 NN = N 6100 MM = M 6101 WC = H 6102 U = 0.0 6103 WW = 0.0 6104C 6105C SET VALUE OF ETA, A MACHINE-DEPENDENT PARAMETER. 6106C ETA IS THE SMALLEST POSITIVE REAL NUMBER FOR WHICH 1.0 + ETA IS 6107C GREATER THAN 1.0 IN FLOATING-POINT ARITHMETIC. 6108C THE VALUE ETA = 2.**(-26) IS APPROPRIATE FOR THE UNIVAC 1108. 6109C 6110CCCCC ETA = SPDIV (RMXINT,2.0,IRR) + 1.0 6111 CALL SPDIV (RMXINT,2.0,IRR,RESULT) 6112 ETA = RESULT + 1.0 6113CCCCC ETA = SPDIV (1.0,ETA,IND) 6114 CALL SPDIV (1.0,ETA,IND,ETA) 6115C 6116C SET VALUE OF TOL, A TOLERANCE USED IN DETERMINING THE RANK OF THE 6117C SYSTEM OF EQUATIONS. 6118C 6119C EMPIRICAL EVIDENCE SUGGESTS THAT TOL SHOULD BE CHOSEN NO SMALLER 6120C THAN N*ETA. 6121C 6122 TOL = FLOAT (NN) * ETA 6123C 6124C SET SCALE PARAMETER, ISCALE, EQUAL TO ZERO. 6125C ISCALE = 0 INDICATES THAT A SOLUTION IS SOUGHT WITHOUT SCALING 6126C THE INPUT DATA. 6127C 6128C IN THE EVENT THAT THE ALGORITHM FAILS TO OBTAIN A SOLUTION WITH 6129C UNSCALED DATA, ISCALE IS THEN SET EQUAL TO 1 AND ANOTHER 6130C ATTEMPT IS C ATTEMPT IS MADE TO OBTAIN A SOLUTION WITH THE DATA 6131C 6132 ISCALE = 0 6133 MP1 = MM + 1 6134C 6135C SET UP MATRIX Q, INPUT FOR SUBROUTINES SCALE AND PDECOM. 6136C 6137 10 IF (IT.EQ.2) GO TO 50 6138C 6139C CALL SUBROUTINE SCALE TO COMPUTE MEAN OF X-VECTOR (DENOTED BY U) 6140C FOR POLYNOMIAL TYPE PROBLEMS, IF DATA ARE TO BE SCALED. 6141C 6142 IF (ISCALE.EQ.1) THEN 6143 CALL SCALDP (ISCALE,2,NN,MM,IT,NR,W,WC,X,U,Q,S,B,A,Z,R,F,IFAULT) 6144 IF (IFAULT.EQ.1) ID = 1 6145C 6146 IF(IBUGA3.EQ.'ON')THEN 6147 WRITE(ICOUT,2101) 6148 2101 FORMAT('AFTER FIRST CALL TO SCALE') 6149 CALL DPWRST('XXX','BUG ') 6150 DO2100I=1,N 6151 WRITE(ICOUT,2111)(X(I,J),J=1,MAX(M,5)) 6152 2111 FORMAT('I,J,(X(I,J),J=1,MAX(M,5)) = ',2I5,5G15.7) 6153 CALL DPWRST('XXX','BUG ') 6154 2100 CONTINUE 6155 ENDIF 6156C 6157 ENDIF 6158C 6159 MM1 = MM - 1 6160 DO 40 I=1,NN 6161 K = MM * NN + I 6162 Q(K) = Y(I) 6163 Q(I) = 1.0 6164 IF (MM.EQ.1) GO TO 40 6165 DO 30 J=1,MM1 6166 K = (J) * NN + I 6167 Q(K) = (X(I,1) - U) ** (J) 6168 30 CONTINUE 6169 40 CONTINUE 6170C 6171 GO TO 80 6172C 6173 50 IF(ISCALE.EQ.1) GO TO 80 6174 DO 70 I=1,NN 6175 K = MM * NN + I 6176 Q(K) = Y(I) 6177 DO 60 J=1,MM 6178 K = (J-1) * NN + I 6179 Q(K) = X(I,J) 6180 60 CONTINUE 6181 70 CONTINUE 6182C 6183C CALL SUBROUTINE SCALE TO COMPUTE VECTOR NORMS AND TO SET VALUES OF 6184C SCALE FACTORS (F). 6185C 6186 80 CONTINUE 6187 CALL SCALDP (ISCALE,1,NN,MM,IT,NR,W,WC,X,U,Q,S,B,A,Z,R,F, 6188 1 IFAULT) 6189C 6190 IF(IBUGA3.EQ.'ON')THEN 6191 WRITE(ICOUT,2201) 6192 2201 FORMAT('AT START OF LSQ ROUTINE') 6193 CALL DPWRST('XXX','BUG ') 6194 DO2200I=1,N 6195 WRITE(ICOUT,2211)I,J,(X(I,J),J=1,MAX(M,5)) 6196 2211 FORMAT('I,J,(X(I,J),J=1,MAX(M,5)) = ',2I5,5G15.7) 6197 CALL DPWRST('XXX','BUG ') 6198 2200 CONTINUE 6199 ENDIF 6200C 6201C IFAULT IS SET EQUAL TO ONE IN SUBROUTINE SCALE WHEN A COLUMN OF 6202C MATRIX X IS FOUND TO EQUAL ZERO. 6203C 6204 IF (IFAULT.EQ.1) GO TO 240 6205C 6206C CALL SUBROUTINE PDECOM TO OBTAIN AN ORTHOGONAL QR-DECOMPOSITION OF 6207C THE MATRIX CONTAINED IN Q ON ENTRY TO PDECOM. ON RETURN FROM 6208C PDECOM, M1 IS THE COMPUTED RANK OF THE SYSTEM OF EQUATIONS. 6209C IF MATRIX Q IS FOUND TO BE SINGULAR, IS = 0 ON RETURN FROM 6210C PDECOM. OTHERWISE, IS = 1. 6211C 6212 CALL PDECOM (NN,MP1,TOL,W,WC,IS,M1,Q,T,R) 6213CCCCC APRIL 2002: PRINT WARNING MESSAGE FOR POTENTIAL SINGULARITY 6214C 6215 IF(IS.EQ.1)THEN 6216 WRITE(ICOUT,99) 6217 99 FORMAT(1X) 6218 CALL DPWRST('XXX','BUG ') 6219 WRITE(ICOUT,1001) 6220 1001 FORMAT('***** WARNING: POTENTIAL SINGULARITY FROM (LINEAR) ', 6221 1 'FIT DETECTED.') 6222 CALL DPWRST('XXX','BUG ') 6223 WRITE(ICOUT,1003) 6224 1003 FORMAT(' POTENTIAL CAUSES OF SINGULARITY INCLUDE:') 6225 CALL DPWRST('XXX','BUG ') 6226 WRITE(ICOUT,1005) 6227 1005 FORMAT(' 1. A COLUMN IN THE X MATRIX CONTAINS ALL THE ', 6228 1 'SAME VALUES.') 6229 CALL DPWRST('XXX','BUG ') 6230 WRITE(ICOUT,1007) 6231 1007 FORMAT(' 2. TWO COLUMNS IN THE X MATRIX ARE EQUAL.') 6232 CALL DPWRST('XXX','BUG ') 6233 WRITE(ICOUT,1009) 6234 1009 FORMAT(' 3. A MORE COMPLICATED LINEAR DEPENDENCY EXISTS ', 6235 1 'BETWEEN') 6236 CALL DPWRST('XXX','BUG ') 6237 WRITE(ICOUT,1010) 6238 1010 FORMAT(' BETWEEN THE COLUMNS IN THE X MATRIX.') 6239 CALL DPWRST('XXX','BUG ') 6240 WRITE(ICOUT,1011) 6241 1011 FORMAT(' FOR MULTI-LINEAR FITS, DATAPLOT CHECKS FOR THE ', 6242 1 'FIRST TWO CAUSES') 6243 CALL DPWRST('XXX','BUG ') 6244 WRITE(ICOUT,1012) 6245 1012 FORMAT(' FOR SINGULARITY.') 6246 CALL DPWRST('XXX','BUG ') 6247 WRITE(ICOUT,1013) 6248 1013 FORMAT(' RECOMMENDED FIX: PERFORM THE FIT AFTER REMOVING ', 6249 1 'ONE OR MORE OF') 6250 CALL DPWRST('XXX','BUG ') 6251 WRITE(ICOUT,1014) 6252 1014 FORMAT(' ONE OR MORE OF THE INDEPENDENT VARIABLES.') 6253 CALL DPWRST('XXX','BUG ') 6254 ENDIF 6255C 6256 IF (IS.EQ.0) GO TO 100 6257 IF (M1.GT.0) GO TO 90 6258 GO TO 240 6259C 6260C .................................................................. 6261C 6262 90 IF (M1.EQ.MM) GO TO 100 6263 IF (ISCALE.EQ.1) GO TO 240 6264 ISCALE = 1 6265 GO TO 10 6266 100 IR = ISCALE 6267C 6268C TRANSFER T(J) TO ARRAY R SO THAT T IS AVAILABLE FOR WORK AREA. 6269C 6270 DO 110 I=1,MP1 6271CCCCC LD = IDIV (2*(I-1)*MP1-I*(I-3),2,IRR) 6272 CALL IDIV (2*(I-1)*MP1-I*(I-3),2,IRR,LD) 6273 R(LD) = T(I) 6274 110 CONTINUE 6275C 6276C CALL SUBROUTINE SLVE TO OBTAIN THE SOLUTION (COEFFICIENTS AND 6277C RESIDUALS) OF THE LEAST SQUARES PROBLEM. ITERATIVE REFINEMENT 6278C IS USED TO IMPROVE (IF POSSIBLE) THE ACCURACY OF THE 6279C INITIAL SOLUTION. ON RETURN FROM SLVE, PARAMETER IR = 0 IF THE 6280C ITERATIVE REFINEMENT PROCEDURE CONVERGED TO A SOLUTION. 6281C OTHERWISE, IR = 1. 6282C 6283 CALL SLVE (NN,MM,NR,X,Y,W,WC,IT,ETA,F,U,Q,T,R,IR,B,P,Z,V,S,NI) 6284CCCCC THE FOLLOWING WRITE SECTION WAS ACTIVATED SEPTEMBER 1995 6285 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'LSQ')THEN 6286 WRITE(ICOUT,771) 6287 771 FORMAT(1H ,'*****FROM LSQ, AFTER 1ST CALL TO SLVE--') 6288 CALL DPWRST('XXX','BUG ') 6289 WRITE(ICOUT,772)E 6290 772 FORMAT('AFTER 120--E = ',E15.7) 6291 CALL DPWRST('XXX','BUG ') 6292 ENDIF 6293C 6294 D = V(1) 6295C 6296 IF (IR.EQ.0) GO TO 130 6297 IF (ISCALE.EQ.1) GO TO 120 6298 ISCALE = 1 6299 GO TO 10 6300 120 CONTINUE 6301CCCCC THE FOLLOWING LINE WAS ACTIVATED SEPTEMBER 1995 6302 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'LSQ')THEN 6303 WRITE(ICOUT,773)ISCALE 6304 773 FORMAT('FROM LSQ, AFTER 120--ISCALE = ',I8) 6305 CALL DPWRST('XXX','BUG ') 6306 ENDIF 6307C GO TO 240 6308 ID =2 6309 RETURN 6310C 6311C COMPUTATIONS NEEDED FOR COMPUTING ACCURATE DIGITS. 6312C SUBROUTINE SLVE IS NOW CALLED TO OBTAIN A VECTOR OF 6313C COEFFICIENTS (A) BY FITTING PREDICTED VALUES (Y - Z) INSTEAD OF 6314C THE ORIGINAL OBSERVATIONS (Y). A COMPARISON OF VECTOR B WITH 6315C VECTOR A IS USED TO ASSESS THE ACCURACY OF VECTOR B. 6316C THIS CALL TO SLVE IS OMITTED WHENEVER -- 6317C L1 = 24 (TWOWAY) 6318C L2 = 2 (SPOLYFIT) 6319C L2 = 4 (SFIT) 6320C 6321C130 IF (L1.EQ.24) GO TO 140 6322C IF (L2.EQ.2.OR. L2.EQ.4) GO TO 140 6323C 6324 130 IZ = ISCALE 6325 ITT = IT + 2 6326C 6327 CALL SLVE (NN,MM,NR,X,Y,W,WC,ITT,ETA,F,U,Q,T,R,IZ,A,Z,P,V,S,NJ) 6328CCCCC THE FOLLOWING WRITE SECTION WAS ACTIVATED SEPTEMBER 1995 6329 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'LSQ')THEN 6330 WRITE(ICOUT,775) 6331 775 FORMAT(1H ,'*****FROM LSQ, AFTER 2ND CALL TO SLVE--') 6332 CALL DPWRST('XXX','BUG ') 6333 WRITE(ICOUT,776)IZ,ID,E 6334 776 FORMAT('AFTER 120--IZ,ID,E = ',2I8,E15.7) 6335 CALL DPWRST('XXX','BUG ') 6336 ENDIF 6337 IF (IZ.EQ.0) GO TO 140 6338 ID = 2 6339 RETURN 6340C 6341C .................................................................. 6342C 6343C COMPUTE SQUARED FOURIER COEFFICIENTS (S) NEEDED FOR ANALYSIS OF 6344C VARIANCE. 6345C 6346 140 L = MP1 6347 DO 150 J=1,MM 6348CCCCC LD = IDIV (2*(J-1)*(MM+1)-J*J+3*J,2,IRR) 6349 CALL IDIV (2*(J-1)*(MM+1)-J*J+3*J,2,IRR,LD) 6350 S(J) = R(LD) * R(L)**2 6351 L = L + MP1 - J 6352 150 CONTINUE 6353C 6354C CALL SUBROUTINE SCALE TO ADJUST RESIDUALS (Z) AND SQUARED 6355C FOURIER COEFFICIENTS (S) FOR SCALING, IF DATA WERE SCALED. 6356C 6357 IF (ISCALE.EQ.1) THEN 6358 CALL SCALDP (ISCALE,3,NN,MM,IT,NR,W,WC,X,U,Q,S,B,A,Z,R,F,IFAULT) 6359 IF (IFAULT.EQ.1) GO TO 420 6360 ENDIF 6361C ADJUST THE FIRST SQUARED FOURIER COEFFICIENT IF Y MID-RANGE WAS 6362C SUBTRACTED FROM Y-VECTOR. IN THIS CASE C IS NONZERO. 6363C 6364 YINC = C 6365CCCCC IF (YINC.NE.0.0) S(1) = R(1) * ( SPDIV(R(MP1),F(MP1),IND) + 6366CCCCC1 SPDIV(YINC,F(1),IRR) )**2 6367 IF(YINC.NE.0.0)CALL SPDIV(R(MP1),F(MP1),IND,RESUL1) 6368 IF(YINC.NE.0.0)CALL SPDIV(YINC,F(1),IRR,RESUL2) 6369 IF(YINC.NE.0.0)S(1)=R(1)*(RESUL1+RESUL2)**2 6370C 6371C COMPUTE RESIDUAL SUM OF SQUARES (E) AND RESIDUAL STANDARD 6372C DEVIATION (SD). 6373C 6374 CALL DSUMAL (DX,0,SNEG,SPOS,SUM) 6375 WW = WC 6376 DO 160 I=1,NN 6377 IF (WC.LE.0.0) WW = W(I) 6378 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'LSQ')THEN 6379 WRITE(ICOUT,871)I,WC,WW 6380 871 FORMAT('FROM LSQ,160--I,WC,WW = ',I8,2E15.7) 6381 CALL DPWRST('XXX','BUG ') 6382 WRITE(ICOUT,872)I,Z(I),SUM 6383 872 FORMAT('FROM LSQ,160--I,Z(I),SUM = ',I8,E15.7,D15.7) 6384 CALL DPWRST('XXX','BUG ') 6385 ENDIF 6386 DX(1) = DBLE (Z(I)**2) * DBLE (WW) 6387 CALL DSUMAL (DX,-1,SNEG,SPOS,SUM) 6388 160 CONTINUE 6389 CALL DSUMAL (DX,1,SNEG,SPOS,SUM) 6390CCCCC RSS = DPCON (SUM) 6391 CALL DPCON (SUM,RSS) 6392C 6393 IF (NN.EQ.MM) GO TO 170 6394 GO TO 180 6395C 6396 170 RMS = 0.0 6397 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'LSQ')THEN 6398 WRITE(ICOUT,873)NN,MM,RSS,WC 6399 873 FORMAT('FROM LSQ,170--NN,MM,RSS,WC = ',2I8,2E15.7) 6400 CALL DPWRST('XXX','BUG ') 6401 ENDIF 6402 GO TO 210 6403C 6404 180 NOZWTS = 0 6405 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'LSQ')THEN 6406 WRITE(ICOUT,874)NN,MM,RSS,WC 6407 874 FORMAT('FROM LSQ,180--NN,MM,RSS,WC = ',2I8,2E15.7) 6408 CALL DPWRST('XXX','BUG ') 6409 ENDIF 6410 IF (WC.GT.0.0) GO TO 200 6411 DO 190 I=1,NN 6412 IF (W(I).NE.0.0) GO TO 190 6413 NOZWTS = NOZWTS + 1 6414 190 CONTINUE 6415 200 RESDF = NN - MM - NOZWTS 6416CCCCC RMS = SPDIV (RSS,RESDF,IRR) 6417 CALL SPDIV (RSS,RESDF,IRR,RMS) 6418C210 SD = SPSQRT (RMS) 6419 210 CONTINUE 6420 CALL SPSQRT (RMS,RESULT) 6421 SD=RESULT 6422 E = RSS 6423C 6424C CALL SUBROUTINE SDPRED TO COMPUTE STANDARD DEVIATION OF PREDICTED 6425C VALUES (V). 6426C 6427 CALL SDPRED (NN,MM,R,Q,T,SD,V) 6428C 6429C CALL SUBROUTINE PINVRT TO OBTAIN THE INVERSE OF (X-TRANSPOSE)*W*X 6430C USING RESULTS FROM PDECOM (MATRIX R) AS INPUT. 6431C 6432C MATRIX R IS OVERWRITTEN AND WILL EQUAL THE DESIRED INVERSE UPON 6433C RETURN TO SUBROUTINE LSQ. 6434C 6435C SINCE THE INVERSE MATRIX IS SYMMETRIC, ONLY THE PORTION ON OR 6436C ABOVE THE PRINCIPAL DIAGONAL IS STORED. COMMENTS AT THE 6437C BEGINNING OF SUBROUTINE PINVRT GIVE FURTHER DETAILS. 6438C 6439 CALL PINVRT (MM,R,T) 6440C 6441C CALL SUBROUTINE SCALE TO ADJUST COEFFICIENTS (B AND A) AND 6442C COVARIANCE MATRIX (R) FOR SCALING, IF DATA WERE SCALED. 6443C 6444 IF (ISCALE.EQ.1) THEN 6445 CALL SCALDP (ISCALE,4,NN,MM,IT,NR,W,WC,X,U,Q,S,B,A,Z,R,F,IFAULT) 6446 IF (IFAULT.EQ.1) GO TO 420 6447 ENDIF 6448C 6449C COMPUTE STANDARD DEVIATIONS OF COEFFICIENTS (T). 6450C 6451 DO 230 I=1,MM 6452 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'LSQ')THEN 6453 WRITE(ICOUT,777)I,R(I),RMS,RESDF,RSS 6454 777 FORMAT('FROM LSQ,230--I,R(I),RMS,RESDF,RSS = ',I8,4E15.7) 6455 CALL DPWRST('XXX','BUG ') 6456 ENDIF 6457CCCCC L = IDIV (2*(I-1)*MM-I*I+3*I,2,IRR) 6458 CALL IDIV (2*(I-1)*MM-I*I+3*I,2,IRR,L) 6459 IF (R(L).GE.0.0) GO TO 220 6460 R(L) = 0.0 6461C220 T(I) = SPSQRT (R(L)*RMS) 6462 220 CONTINUE 6463 CALL SPSQRT (R(L)*RMS,RESULT) 6464 T(I) = RESULT 6465 IF(IBUGA3.EQ.'ON'.OR.ISUBRO.EQ.'LSQ')THEN 6466 WRITE(ICOUT,778)I,T(I) 6467 778 FORMAT('FROM LSQ,230--I,T(I) = ',I8,E15.7) 6468 CALL DPWRST('XXX','BUG ') 6469 ENDIF 6470 230 CONTINUE 6471C 6472C SET VALUE OF ID. 6473 240 ID=NI 6474 RETURN 6475C 6476 420 ID = 1 6477C IF (ISCALE.EQ.0) ID = - ID 6478 RETURN 6479C 6480C ================================================================== 6481C 6482 END 6483CCCCC-----SCALE-------------------------------------- 6484 SUBROUTINE SCALDP (IS,NC,N,M,IT,NR,W,WC,X,U,Q,SS,B,A,Z,R,SF,IFT) 6485C 6486C ================================================================== 6487C 6488C *** GENERAL COMMENTS *** 6489C 6490C SUBROUTINE SCALE SCALES THE MATRIX Q IN ORDER TO MITIGATE THE 6491C ROUNDING ERROR PROBLEMS WHICH CAN OCCUR IN CONNECTION WITH 6492C SOLVING ILL-CONDITIONED SYSTEMS OF EQUATIONS. THIS IS DONE BY 6493C MULTIPLYING EACH COLUMN OF Q BY ITS APPROPRIATE SCALE FACTOR SO 6494C THAT THE COLUMNS OF THE SCALED MATRIX ALL HAVE UNIT LENGTH. IN 6495C THE CASE OF POLYNOMIAL TYPE PROBLEMS, THE MEAN OF THE X-VECTOR 6496C IS COMPUTED SO THAT IT CAN BE SUBTRACTED FROM EACH ELEMENT OF 6497C X WHENEVER POWERS OF X ARE GENERATED (IN SUBROUTINES LSQ AND 6498C SLVE). AFTER A SOLUTION IS OBTAINED FOR A SCALED PROBLEM, THE 6499C COEFFICIENTS, RESIDUALS, SQUARED FOURIER COEFFICIENTS AND 6500C COVARIANCE MATRIX MUST BE ADJUSTED TO ACCOUNT FOR SCALING. 6501C 6502C REFERENCE -- 6503C A. BJORCK, COMMENT ON THE ITERATIVE REFINEMENT OF LEAST-SQUARES 6504C SOLUTIONS, JOURNAL OF THE AMERICAN STATISTICAL ASSOCIATION, 6505C VOL. 73 (1978), PP. 161-166. 6506C 6507C WRITTEN BY - 6508C ROY H. WAMPLER, 6509C STATISTICAL ENGINEERING DIVISION, 6510C CENTER FOR APPLIED MATHEMATICS, 6511C A337 ADMINISTRATION BUILDING, 6512C NATIONAL BUREAU OF STANDARDS, 6513C GAITHERSBURG, MD. 20899 6514C TELEPHONE 301-975-2844 6515C 6516C UPDATED--NOVEMBER 1989--DIMENSION (1) TO (*) (AND MOVE) 6517C UPDATED --NOVEMBER 2009. RENAME "SCALE" TO "SCALDP". THIS 6518C IS SIMPLY TO AVOID COMPILATION 6519C ISSUES WITH VERSION 11 OF THE 6520C INTEL COMPILER ON WINDOWS 6521C (CONFLICTS WITH INTRINSIC 6522C SCALE FUNCTION EVEN IF AN 6523C EXTERNAL STATEMENT IS USED) 6524C 6525C ================================================================== 6526C 6527C *** SPECIFICATION STATEMENTS *** 6528C 6529C 6530C 6531CCCCC THE FOLLOWING 5 LINES WERE MOVED NOVEMBER 1989 6532CCCCC AND CHANGED DIMENSION (1) TO (*) 6533CCCCC (BUG UNCOVERED BY NELSON HSU) 6534CCCCC REAL A(1), B(1), Q(1), R(1), SF(1), SS(1) 6535CCCCC REALCCCCC W(1), X(NR,1), Z(1) 6536CCCCC REAL W(1), X, Z(1) 6537CCCCC REAL U, WC 6538CCCCC REAL VNORM2, WW 6539C 6540CCCCC REAL SPDIV, DPCON 6541C 6542 DOUBLE PRECISION DSUM 6543CCCCC DOUBLE PRECISION DPDIV, DPSQRT 6544 DOUBLE PRECISION DRESUL 6545C 6546 REAL A(*), B(*), Q(*), R(*), SF(*), SS(*) 6547CCCCC REAL W(1), X(NR,1), Z(1) 6548 REAL W(*), X, Z(*) 6549 REAL U, WC 6550 REAL VNORM2, WW 6551C 6552CCCCC INCLUDE 'DPCOPA.INC' 6553CCCCC DIMENSION X(MAXOBV,MAXCMF) 6554 DIMENSION X(NR,*) 6555C 6556C ================================================================== 6557C 6558 MP1 = M + 1 6559 IFT = 0 6560CCCCC TEMPORARY CHANGE OF NCC TO NC AS SUGGESTED BY RUTH VARNER MAY 1989 6561CCCCC GO TO (10,80,100,130), NCC 6562 GO TO (10,80,100,130), NC 6563 10 IF (IS.EQ.1) GO TO 30 6564C 6565C IS = 0. SET SF(I) = 1.0 FOR I=1,...,M+1. 6566C 6567 DO 20 I=1,MP1 6568 SF(I) = 1.0 6569 20 CONTINUE 6570 RETURN 6571C 6572C .................................................................. 6573C 6574C IS = 1. COMPUTE VECTOR NORMS. 6575C COMPUTE SCALE FACTORS (SF). 6576C SCALE MATRIX Q. 6577C 6578 30 WW = WC 6579 DO 70 J=1,MP1 6580 DSUM = 0.0D0 6581 K = (J-1) * N + 1 6582 DO 40 I=1,N 6583 IF (WC.LE.0.0) WW = W(I) 6584 DSUM = DSUM + DBLE (Q(K)) * DBLE (Q(K)) * DBLE (WW) 6585 K = K + 1 6586 40 CONTINUE 6587CCCCC DSUM = DPSQRT (DSUM) 6588 CALL DPSQRT (DSUM,DRESUL) 6589 DSUM = DRESUL 6590CCCCC VNORM2 = DPCON (DSUM) 6591 CALL DPCON (DSUM,VNORM2) 6592C 6593C VECTOR NORMS COULD BE SAVED HERE, IF DESIRED. 6594C 6595 IF (VNORM2.GT.0.0) GO TO 50 6596 IFT = 1 6597C 6598C IFT = 1 INDICATES ERROR RETURN. 6599C 6600 RETURN 6601C 6602C .................................................................. 6603C 6604CC50 SF(J) = SPDIV (1.0,VNORM2,IRR) 6605 50 CONTINUE 6606 CALL SPDIV (1.0,VNORM2,IRR,SF(J)) 6607C 6608C SCALE MATRIX Q. 6609C 6610 K = (J-1) * N + 1 6611 DO 60 I=1,N 6612 Q(K) = Q(K) * SF(J) 6613 K = K + 1 6614 60 CONTINUE 6615 70 CONTINUE 6616 RETURN 6617C 6618C .................................................................. 6619C 6620C COMPUTE MEAN OF X VECTOR (DENOTED BY U) FOR POLYNOMIAL TYPE 6621C PROBLEMS. 6622C 6623 80 DSUM = 0.0D0 6624 NW = 0 6625 DO 90 I=1,N 6626 L = L + 1 6627 IF (WC.LE.0.0 .AND. W(I).EQ.0.0) GO TO 90 6628 NW = NW + 1 6629 DSUM = DSUM + DBLE (X(I,1)) 6630 90 CONTINUE 6631CCCCC U = DPCON (DPDIV (DSUM,DBLE (FLOAT (NW)),IRR)) 6632 CALL DPDIV (DSUM,DBLE (FLOAT (NW)),IRR,DRESUL) 6633CCCCC U = DPCON (DRESUL) 6634 CALL DPCON (DRESUL,U) 6635 RETURN 6636C 6637C .................................................................. 6638C 6639C ADJUST SQUARED FOURIER COEFFICIENTS (SS) AND RESIDUALS (Z) FOR 6640C SCALING. 6641C 6642 100 DO 110 J=1,M 6643CCCCC SS(J) = SPDIV (SS(J),SF(MP1)*SF(MP1),IRR) 6644 CALL SPDIV (SS(J),SF(MP1)*SF(MP1),IRR,SS(J)) 6645 110 CONTINUE 6646C 6647 DO 120 I=1,N 6648CCCCC Z(I) = SPDIV (Z(I),SF(MP1),IRR) 6649 CALL SPDIV (Z(I),SF(MP1),IRR,Z(I)) 6650 120 CONTINUE 6651 RETURN 6652C 6653C .................................................................. 6654C 6655C ADJUST COEFFICIENTS (B AND A) AND COVARIANCE MATRIX (R) FOR 6656C SCALING. 6657C 6658 130 DO 140 J=1,M 6659CCCCC B(J) = SPDIV (B(J) * SF(J),SF(MP1),IRR) 6660 CALL SPDIV (B(J) * SF(J),SF(MP1),IRR,B(J)) 6661CCCCC A(J) = SPDIV (A(J) * SF(J),SF(MP1),IRR) 6662 CALL SPDIV (A(J) * SF(J),SF(MP1),IRR,A(J)) 6663 140 CONTINUE 6664 L = 0 6665 DO 160 I=1,M 6666 DO 150 J=I,M 6667 L = L + 1 6668 R(L) = R(L) * SF(I) * SF(J) 6669 150 CONTINUE 6670 160 CONTINUE 6671 IF (IT.EQ.2) RETURN 6672C 6673C .................................................................. 6674C 6675C COMPLETE ADJUSTMENTS OF B, A AND R FOR SCALING IN POLYNOMIAL TYPE 6676C PROBLEMS. 6677C REFERENCE -- 6678C G. A. F. SEBER, LINEAR REGRESSION ANALYSIS (1977), THEOREM 6679C 1.4 AND COROLLARIES, PAGES 10-11. 6680C 6681 K = 0 6682 DO 180 I=1,M 6683 DO 170 J=I,M 6684 K = K + 1 6685 L = (I - 1) * M + J 6686 Q(L) = R(K) 6687 IF (I.EQ.J) GO TO 170 6688 L = (J - 1) * M + I 6689 Q(L) = R(K) 6690 170 CONTINUE 6691 180 CONTINUE 6692 DO 250 I=1,M 6693 SF(I) = 1.0 6694 IP1 = I + 1 6695 IF (IP1.GT.M) GO TO 200 6696 DO 190 J=IP1,M 6697CCCCC SF(J) = DPCON (-DPDIV (DBLE(FLOAT(J-1)),DBLE(FLOAT(J-I)),IND) 6698CCCCC1 * DBLE (SF(J-1)) * DBLE (U) ) 6699 CALL DPDIV (DBLE(FLOAT(J-1)),DBLE(FLOAT(J-I)),IND,DRESUL) 6700CCCCC SF(J) = DPCON (-DRESUL) 6701CCCCC1 * DBLE (SF(J-1)) * DBLE (U) 6702 CALL DPCON (-DRESUL,RESULT) 6703 SF(J) = RESULT 6704 1 * DBLE (SF(J-1)) * DBLE (U) 6705 190 CONTINUE 6706 200 DSUM = 0.0D0 6707 DO 210 J=I,M 6708 DSUM = DSUM + DBLE (SF(J)) * DBLE (B(J)) 6709 210 CONTINUE 6710 B(I) = DSUM 6711 DSUM = 0.0D0 6712 DO 220 J=I,M 6713 DSUM = DSUM + DBLE (SF(J)) * DBLE (A(J)) 6714 220 CONTINUE 6715 A(I) = DSUM 6716 DO 240 J=I,M 6717 DSUM = 0.0D0 6718 DO 230 K=I,M 6719 L = (K-1)*M + J 6720 DSUM = DSUM + DBLE (SF(K)) * DBLE (Q(L)) 6721 230 CONTINUE 6722 L = (I - 1) * M + J 6723 Q(L) = DSUM 6724 240 CONTINUE 6725 250 CONTINUE 6726 DO 300 J=1,M 6727 SF(J) = 1.0 6728 IP1 = J + 1 6729 IF (IP1.GT.M) GO TO 270 6730 DO 260 I=IP1,M 6731CCCCC SF(I) = DPCON (-DPDIV (DBLE(FLOAT(I-1)),DBLE(FLOAT(I-J)),IND) 6732CCCCC1 * DBLE (SF(I-1)) * DBLE (U) ) 6733 CALL DPDIV (DBLE(FLOAT(I-1)),DBLE(FLOAT(I-J)),IND,DRESUL) 6734CCCCC SF(I) = DPCON (-DRESUL) 6735CCCCC1 * DBLE (SF(I-1)) * DBLE (U) 6736 CALL DPCON (-DRESUL,RESULT) 6737 SF(I) = RESULT 6738 1 * DBLE (SF(I-1)) * DBLE (U) 6739 260 CONTINUE 6740 270 DO 290 I=1,J 6741 DSUM = 0.0D0 6742 DO 280 K=J,M 6743 L = (I - 1) * M + K 6744 DSUM = DSUM + DBLE (Q(L)) * DBLE (SF(K)) 6745 280 CONTINUE 6746 L = (I - 1) * M + J 6747 Q(L) = DSUM 6748 290 CONTINUE 6749 300 CONTINUE 6750 K = 0 6751 DO 320 I=1,M 6752 DO 310 J=I,M 6753 K = K + 1 6754 L = (I - 1) * M + J 6755 R(K) = Q(L) 6756 310 CONTINUE 6757 320 CONTINUE 6758 RETURN 6759C 6760C ================================================================== 6761C 6762 END 6763CCCCC-----PDECOM-------------------------------------- 6764 SUBROUTINE PDECOM (KN,KM,TOL,W,WCC,ISING,M1,Q,D,R) 6765C 6766C ================================================================== 6767C 6768C *** GENERAL COMMENTS *** 6769C 6770C SUBROUTINE PDECOM USES A MODIFIED GRAM-SCHMIDT ALGORITHM TO OBTAIN 6771C AN ORTHOGONAL QR-DECOMPOSITION OF THE INPUT MATRIX GIVEN IN Q. 6772C 6773C WRITTEN BY - 6774C ROY H. WAMPLER, 6775C STATISTICAL ENGINEERING DIVISION, 6776C CENTER FOR APPLIED MATHEMATICS, 6777C A337 ADMINISTRATION BUILDING, 6778C NATIONAL BUREAU OF STANDARDS, 6779C GSITHERSBURG, MD. 20899 6780C TELEPHONE 301-975-2844 6781C 6782C UPDATED--NOVEMBER 1989--DIMENSION (1) TO (*) (AND MOVE) 6783C 6784C ================================================================== 6785C 6786C *** SPECIFICATION STATEMENTS *** 6787C 6788C 6789CCCCC THE FOLLOWING 3 LINES WERE MOVED NOVEMBER 1989 6790CCCCC AND DIMENSION (1) CHANGED TO DIMENSION (*) 6791CCCCC (BUG UNCOVERED BY NELSON HSU) 6792CCCCC REAL D(1), Q(1), R(1), W(1) 6793CCCCC REAL TOL, WCC 6794CCCCC REAL DMAX, DS, RSJ, TOL2, WW 6795C 6796CCCCC REAL SPDIV, DPCON 6797C 6798 DOUBLE PRECISION DSUM 6799C 6800 REAL D(*), Q(*), R(*), W(*) 6801 REAL TOL, WCC 6802 REAL DMAX, DS, RSJ, TOL2, WW 6803C 6804C ================================================================== 6805C 6806 WW = WCC 6807 ISING = 1 6808 M = KM 6809 N = KN 6810 M1 = 0 6811CCCCC M2 = IDIV (M*(M+1),2,IRR) 6812 CALL IDIV (M*(M+1),2,IRR,M2) 6813 DO 10 J=1,M 6814 D(J) = 0.0 6815 10 CONTINUE 6816C 6817 DO 20 L=1,M2 6818 R(L) = 0.0 6819 20 CONTINUE 6820C 6821 TOL2 = TOL * TOL 6822 DMAX = 0.0 6823 DO 110 I=1,M 6824C 6825C STEP NUMBER I IN THE DECOMPOSITION. 6826C 6827 DSUM = 0.0D0 6828 DO 30 L=1,N 6829 IF (WCC.LE.0.0) WW = W(L) 6830 J = (I-1) * N + L 6831 DSUM = DSUM + DBLE (Q(J)) * DBLE (Q(J)) * DBLE (WW) 6832 30 CONTINUE 6833C 6834CCCCC D(I) = DPCON (DSUM) 6835 CALL DPCON (DSUM,D(I)) 6836 DS = D(I) 6837 IF (I.GT.1) GO TO 40 6838 DMAX = D(1) 6839 GO TO 50 6840C 6841 40 IF (DS.GT.DMAX) DMAX = D(I) 6842 50 DO 60 J=1,I 6843 IF (D(J).LE.TOL2*DMAX) RETURN 6844 60 CONTINUE 6845C 6846 IF (DS.EQ.0.0) RETURN 6847 IPLUS1 = I + 1 6848 IF (IPLUS1.GT.M) GO TO 100 6849C 6850C BEGIN ORTHOGONALIZATION. 6851C 6852CCCCC LD = IDIV (2*(I-1)*M-I*I+3*I,2,IRR) 6853 CALL IDIV (2*(I-1)*M-I*I+3*I,2,IRR,LD) 6854 K = 1 6855 DO 90 J=IPLUS1,M 6856 DSUM = 0.0D0 6857 DO 70 L=1,N 6858 IF (WCC.LE.0.0) WW = W(L) 6859 LS = (I-1) * N + L 6860 LJ = (J-1) * N + L 6861 DSUM = DSUM + DBLE(Q(LS)) * DBLE(Q(LJ)) * DBLE (WW) 6862 70 CONTINUE 6863C 6864 L = LD + K 6865CCCCC R(L) = DPCON (DSUM) 6866 CALL DPCON (DSUM,R(L)) 6867CCCCC R(L) = SPDIV (R(L),DS,IRR) 6868 CALL SPDIV (R(L),DS,IRR,R(L)) 6869 RSJ = R(L) 6870 K = K + 1 6871 JJ = (J-1) * N + 1 6872 JS = (I-1) * N + 1 6873 DO 80 L=1,N 6874 Q(JJ) = Q(JJ) - RSJ * Q(JS) 6875 JJ = JJ + 1 6876 JS = JS + 1 6877 80 CONTINUE 6878C 6879 90 CONTINUE 6880C 6881C END ORTHOGONALIZATION. 6882C 6883 100 M1 = I 6884 IF (I.EQ.M-1) ISING = 0 6885 110 CONTINUE 6886C 6887C END STEP NUMBER I. 6888C 6889 RETURN 6890C 6891C ================================================================== 6892C 6893 END 6894CCCCC-----SLVE-------------------------------------- 6895 SUBROUTINE SLVE (N,M,NR,X,Y,W,WA,IT,E,S,U,Q,D,A,K,B,R,Z,F,G,NI) 6896C 6897C ================================================================== 6898C 6899C *** GENERAL COMMENTS *** 6900C 6901C SUBROUTINE SLVE COMPUTES THE SOLUTION (COEFFICIENTS AND RESIDUALS) 6902C OF THE LEAST SQUARES PROBLEM. ITERATIVE REFINEMENT IS USED TO 6903C IMPROVE (IF POSSIBLE) THE ACCURACY OF THE INITIAL SOLUTION. 6904C 6905C SUBROUTINE SLVE IS GENERALLY CALLED TWICE FROM SUBROUTINE LSQ. 6906C IN THE FIRST CALL, THE OBSERVATIONS (Y) ARE FITTED. LET R 6907C DENOTE THE RESIDUALS FROM THIS FIT. 6908C IN THE SECOND CALL, THE PREDICTED VALUES (Y - R) ARE FITTED. 6909C THE COEFFICIENTS OBTAINED FROM THIS FIT WILL BE USED IN 6910C ASSESSING THE ACCURACY OF THE COEFFICIENTS FROM THE FIRST FIT. 6911C 6912C * CONVERSION OF THE PROGRAM TO STRICTLY DOUBLE PRECISION, AND * 6913C * CONVERSION OF THE PROGRAM TO STRICTLY SINGLE PRECISION. * 6914C * ON COMPUTERS HAVING SHORT WORD LENGTH (AS THE IBM 360/370) * 6915C * IT MAY BE DESIRABLE TO PERFORM ALL CALCULATIONS IN DOUBLE * 6916C * PRECISION. ON COMPUTERS HAVING LONG WORD LENGTH (AS THE CDC * 6917C * 6600) IT MAY BE DESIRABLE TO PERFORM ALL CALCULATIONS IN * 6918C * SINGLE PRECISION. IN SUCH CASES, THE ITERATIVE REFINEMENT * 6919C * PRESENTLY INCLUDED IN SUBROUTINE SLVE SHOULD BE OMITTED. * 6920C * * 6921C * THE SIMPLEST WAY TO OBTAIN THE EFFECT OF OMITTING THE * 6922C * ITERATIVE REFINEMENT (WITHOUT ACTUALLY DOING SO) IS TO CHANGE * 6923C * THE ONE STATEMENT WHICH PRESENTLY READS * 6924C * 310 K = 1 (USE THIS FOR 64-BIT MACHINES) * 6925C * TO READ * 6926C * 310 K = 0 (USE THIS FOR 32-BIT MACHINES) * 6927C * * 6928C * TO ACTUALLY OMIT THE ITERATIVE REFINEMENT THE FOLLOWING * 6929C * APPROACH MAY BE USED. * 6930C * 1. OMIT USAGE OF E, ETA2, RNB, RNDB1, RNDB2, RNDR1, RNDR2, * 6931C * RNR, AND SPCA FROM SUBROUTINE, REAL, AND DATA STATEMENTS. * 6932C * 2. ATTACH LABEL 30 TO THE STATEMENT WHICH PRESENTLY READS * 6933C * DO 50 I=1,KN * 6934C * 3. INSERT A STATEMENT READING * 6935C * GO TO 320 * 6936C * IMMEDIATELY BEFORE THE STATEMENT WHICH PRESENTLY READS * 6937C * 160 DO 210 ISX=1,KM * 6938C * 4. OMIT THE FOUR BLOCKS OF STATEMENTS WHICH ARE SET OFF IN * 6939C * THE FOLLOWING MANNER -- * 6940C * * 6941C BLOCK I ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6942C 6943C (STATEMENTS TO BE OMITTED) 6944C 6945C BLOCK I (END) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6946C * * 6947C * BLOCK 1 CONTAINS 3 STATEMENTS (EXCLUDING COMMENTS). * 6948C * BLOCK 2 CONTAINS 10 STATEMENTS (EXCLUDING COMMENTS). * 6949C * BLOCK 3 CONTAINS 22 STATEMENTS (EXCLUDING COMMENTS). * 6950C * BLOCK 4 CONTAINS 4 STATEMENTS (EXCLUDING COMMENTS). * 6951C * * 6952C WRITTEN BY - 6953C ROY H. WAMPLER, 6954C STATISTICAL ENGINEERING DIVISION, 6955C CENTER FOR APPLIED MATHEMATICS, 6956C A337 ADMINISTRATION BUILDING, 6957C NATIONAL BUREAU OF STANDARDS, 6958C GAITHERSBURG, MD. 20899 6959C TELEPHONE 301-975-2844 6960C 6961C UPDATED--NOVEMBER 1989--DIMENSION (1) TO (*) (AND MOVED) 6962C 6963C ================================================================== 6964C 6965C *** SPECIFICATION STATEMENTS *** 6966C 6967CCCCC THE FOLLOWING 9 LINES WERE MOVED NOVEMBER 1989 6968CCCCC AND CHANGED DIMENSION (1) TO (*) 6969CCCCC (BUG UNCOVERED BY NELSON HSU) 6970CCCCC REAL A(1), B(1), D(1), F(1), G(1), Q(1) 6971CCCCC REALCCCCC R(1), S(1), W(1), X(NR,M), Y(1), Z(1) 6972CCCCC REAL R(1), S(1), W(1), X, Y(1), Z(1) 6973CCCCC REAL E, U, WA 6974CCCCC REAL C, ETA2, DIGITS, DXNORM 6975CCCCC REAL RNB, RNDB1, RNDB2, RNDR1, RNDR2 6976CCCCC REAL RNR, WC, WW, XNORM 6977CCCCC REALCCCCC SPDIV, DPCON, SPLO10, SPSQRT 6978CCCCC REAL SPCA 6979C 6980 DOUBLE PRECISION DX, DSUM, DY 6981C 6982 REAL A(*), B(*), D(*), F(*), G(*), Q(*) 6983CCCCC REAL R(*), S(*), W(*), X(NR,M), Y(*), Z(*) 6984 REAL R(*), S(*), W(*), X, Y(*), Z(*) 6985 REAL E, U, WA 6986 REAL C, ETA2, DIGITS, DXNORM 6987 REAL RNB, RNDB1, RNDB2, RNDR1, RNDR2 6988 REAL RNR, WC, WW, XNORM 6989CCCCC REAL SPDIV, DPCON, SPLO10, SPSQRT 6990 REAL SPCA 6991C 6992CCCCC INCLUDE 'DPCOPA.INC' 6993 DIMENSION X(NR,*) 6994C 6995C ================================================================== 6996C 6997C *** DATA INITIALIZATION STATEMENTS *** 6998C 6999 DATA SPCA / 64.0 / 7000C 7001C ================================================================== 7002C 7003C SET ISWAD = 0 IF COEFFICIENTS FOR ACCURATE DIGITS ARE NOT BEING 7004C COMPUTED. 7005C SET ISWAD = 1 IF COEFFICIENTS FOR ACCURATE DIGITS ARE BEING 7006C COMPUTED. 7007C 7008 ISWAD = 0 7009 IF (IT.GT.2) ISWAD = 1 7010 KN = N 7011 KM = M 7012 MN = KM * KN 7013 WC = WA 7014 WW = 0.0 7015 ITYP = IT 7016 IF (ITYP.GT.2) ITYP = ITYP - 2 7017 MPLUS1 = KM + 1 7018 DIGITS = 0.0 7019C 7020C BLOCK 1 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7021C 7022CCCCC ITMAX = INT (-SPLO10(E)) - 2 JUNE 1987 7023 CALL SPLO10(E,RESULT) 7024 ITMAX = INT (-RESULT) - 2 7025 IF (K.EQ.1) ITMAX = ITMAX + 3 7026 ETA2 = E * E 7027C 7028C BLOCK 1 (END) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7029C 7030C USE ELEMENTS M*N+1, M*N+2, ..., M*N+N OF ARRAY Q AS WORK AREA. 7031C 7032CCCCC IF (WC.GT.0.0) WW = SPSQRT(WC) 7033 IF (WC.GT.0.0) CALL SPSQRT(WC,RESULT) 7034 IF (WC.GT.0.0) WW = RESULT 7035 DO 10 I=1,KN 7036CCCCC IF (WC.LE.0.0) WW = SPSQRT(W(I)) 7037 IF (WC.LE.0.0) CALL SPSQRT(W(I),RESULT) 7038 IF (WC.LE.0.0) WW = RESULT 7039 IF (ISWAD.EQ.0) F(I) = Y(I) * WW * S(MPLUS1) 7040CCCCC IF (ISWAD.EQ.1 ) F(I) = (Y(I)-SPDIV(R(I),S(MPLUS1),IND)) * WW 7041CCCCC1 * S(MPLUS1) 7042 IF (ISWAD.EQ.1 ) CALL SPDIV(R(I),S(MPLUS1),IND,RESULT) 7043 IF (ISWAD.EQ.1 ) F(I) = (Y(I)-RESULT) * WW 7044 1 * S(MPLUS1) 7045 J = MN + I 7046 Q(J) = 0.0 7047 Z(I) = 0.0 7048 10 CONTINUE 7049C 7050 DO 20 J=1,KM 7051 B(J) = 0.0 7052 G(J) = 0.0 7053 20 CONTINUE 7054C 7055 KI = 0 7056 RNR = 0.0 7057 RNB = 0.0 7058 RNDB1 = 0.0 7059 RNDR1 = 0.0 7060C 7061C BLOCK 2 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7062C 7063 RNDB2 = 0.0 7064 RNDR2 = 0.0 7065C 7066C BEGIN KI-TH ITERATION STEP. 7067C 7068 30 IF (KI.LT.2) GO TO 40 7069 IF (SPCA*RNDB2.LT.RNDB1 .AND. RNDB2.GT.ETA2*RNB .OR. 7070 1 SPCA*RNDR2.LT.RNDR1 .AND. RNDR2.GT.ETA2*RNR) GO TO 40 7071 GO TO 300 7072C 7073 40 RNDB1 = RNDB2 7074 RNDR1 = RNDR2 7075 RNDB2 = 0.0 7076 RNDR2 = 0.0 7077C 7078C BLOCK 2 (END) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7079C 7080 IF (KI.EQ.0) GO TO 160 7081C 7082C NEW RESIDUALS. 7083C 7084 DO 50 I=1,KN 7085CCCCC IF (WC.LE.0.0) WW = SPSQRT(W(I)) 7086 IF (WC.LE.0.0) CALL SPSQRT(W(I),RESULT) 7087 IF (WC.LE.0.0) WW = RESULT 7088 J = MN + I 7089 Q(J) = Q(J) + F(I) * WW 7090CCCCC Z(I) = Z(I) + SPDIV (F(I),WW,IRR) 7091 CALL SPDIV (F(I),WW,IRR,RESULT) 7092 Z(I) = Z(I) + RESULT 7093 50 CONTINUE 7094C 7095 DO 100 ISX=1,KM 7096 B(ISX) = B(ISX) + G(ISX) 7097 DSUM = 0.0D0 7098 IF (ITYP.EQ.2) GO TO 70 7099 DO 60 L=1,KN 7100 J = MN + L 7101 DX = DBLE (Q(J)) * DBLE (S(ISX)) 7102 IF (ISX.GT.1) DX = DX * DBLE(X(L,1)-U) ** (ISX-1) 7103 DSUM = DSUM + DX 7104 60 CONTINUE 7105 GO TO 90 7106C 7107 70 DO 80 L=1,KN 7108 J = MN + L 7109 DSUM = DSUM + DBLE (Q(J)) * DBLE (X(L,ISX) * S(ISX)) 7110 80 CONTINUE 7111C 7112CC90 G(ISX) = -DPCON (DSUM) 7113 90 CONTINUE 7114 CALL DPCON (DSUM,RESULT) 7115 G(ISX) = -RESULT 7116 100 CONTINUE 7117C 7118 DO 150 I=1,KN 7119 DSUM = DBLE ( Z(I) ) 7120 IF (ITYP.EQ.2) GO TO 120 7121 DSUM = DSUM + DBLE (B(1)) * DBLE (S(1)) 7122 IF (KM.EQ.1) GO TO 140 7123 DO 110 L=2,KM 7124 DSUM = DSUM + DBLE(B(L))*DBLE(X(I,1)-U)**(L-1)*DBLE(S(L)) 7125 110 CONTINUE 7126 GO TO 140 7127C 7128 120 DO 130 L=1,KM 7129 DSUM = DSUM + DBLE(B(L)) * DBLE(X(I,L) * S(L)) 7130 130 CONTINUE 7131C 7132 140 DY = DBLE ( Y(I) ) 7133CCCCC IF (ISWAD.EQ.1) DY = DBLE (Y(I) - SPDIV (R(I),S(MPLUS1),IND) ) 7134 IF (ISWAD.EQ.1) CALL SPDIV (R(I),S(MPLUS1),IND,RESULT) 7135 IF (ISWAD.EQ.1) DY = DBLE (Y(I) - RESULT ) 7136 DSUM = DSUM - DY * DBLE (S(MPLUS1)) 7137CCCCC F(I) = -DPCON (DSUM) 7138 CALL DPCON (DSUM,RESULT) 7139 F(I) = -RESULT 7140CCCCC IF (WC.LE.0.0) WW = SPSQRT(W(I)) 7141 IF (WC.LE.0.0) CALL SPSQRT(W(I),RESULT) 7142 IF (WC.LE.0.0) WW = RESULT 7143 F(I) = F(I) * WW 7144CCCCC IF (WW.EQ.0.0) Z(I) = DPCON (DBLE (Z(I)) - DSUM) 7145 IF (WW.EQ.0.0) CALL DPCON (DBLE (Z(I)) - DSUM,Z(I)) 7146 150 CONTINUE 7147C 7148C END NEW RESIDUALS. 7149C 7150 160 DO 210 ISX=1,KM 7151 LESS1 = ISX - 1 7152 DSUM = - DBLE (G(ISX)) 7153 IF (1.GT.LESS1) GO TO 180 7154 J = ISX 7155 DO 170 L=1,LESS1 7156 DSUM = DSUM + DBLE (D(L)) * DBLE (A(J)) 7157 J = J + MPLUS1 - L 7158 170 CONTINUE 7159C 7160C180 D(ISX) = - DPCON (DSUM) 7161 180 CONTINUE 7162 CALL DPCON (DSUM,RESULT) 7163 D(ISX) = - RESULT 7164 DO 190 L=1,KN 7165CCCCC IF (WC.LE.0.0) WW = SPSQRT (W(L)) 7166 IF (WC.LE.0.0) CALL SPSQRT (W(L),RESULT) 7167 IF (WC.LE.0.0) WW = RESULT 7168 JJ = (ISX-1) * KN + L 7169 DSUM = DSUM + DBLE (F(L)) * DBLE (Q(JJ)) * DBLE (WW) 7170 190 CONTINUE 7171C 7172CCCCC C = DPCON (DSUM) 7173 CALL DPCON (DSUM,C) 7174CCCCC LD = IDIV (2*(ISX-1)*(MPLUS1)-ISX*ISX+3*ISX,2,IRR) 7175 CALL IDIV (2*(ISX-1)*(MPLUS1)-ISX*ISX+3*ISX,2,IRR,LD) 7176CCCCC C = SPDIV (C,A(LD),IRR) 7177 CALL SPDIV (C,A(LD),IRR,C) 7178 G(ISX) = C 7179 DO 200 I=1,KN 7180CCCCC IF (WC.LE.0.0) WW = SPSQRT (W(I)) 7181 IF (WC.LE.0.0) CALL SPSQRT (W(I),RESULT) 7182 IF (WC.LE.0.0) WW = RESULT 7183 JJ = (ISX-1) * KN + I 7184 F(I) = F(I) - C * Q(JJ) * WW 7185 200 CONTINUE 7186C 7187 210 CONTINUE 7188 DO 240 IS=1,KM 7189 ISX = MPLUS1 - IS 7190 IPLUS1 = ISX + 1 7191 DSUM = DBLE (-G(ISX)) 7192 IF (IPLUS1.GT.KM) GO TO 230 7193CCCCC LD = IDIV (2*(ISX-1)*(MPLUS1)-ISX*ISX+3*ISX,2,IRR) 7194 CALL IDIV (2*(ISX-1)*(MPLUS1)-ISX*ISX+3*ISX,2,IRR,LD) 7195 J = 0 7196 DO 220 L=IPLUS1,KM 7197 J = J + 1 7198 LJ = LD + J 7199 DSUM = DSUM + DBLE (G(L)) * DBLE (A(LJ)) 7200 220 CONTINUE 7201C230 G(ISX) = - DPCON (DSUM) 7202 230 CONTINUE 7203 CALL DPCON (DSUM,RESULT) 7204 G(ISX) = - RESULT 7205 240 CONTINUE 7206C 7207C BLOCK 3 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7208C 7209 DSUM = RNDB2 7210 DO 250 ISX=1,KM 7211 DSUM = DSUM + DBLE (G(ISX) * G(ISX) ) 7212 250 CONTINUE 7213C 7214CCCCC RNDB2 = DPCON (DSUM) 7215 CALL DPCON (DSUM,RNDB2) 7216 DSUM = RNDR2 7217 DO 260 I=1,KN 7218 DSUM = DSUM + DBLE (F(I) * F(I) ) 7219 260 CONTINUE 7220C 7221CCCCC RNDR2 = DPCON (DSUM) 7222 CALL DPCON (DSUM,RNDR2) 7223 IF (KI.NE.0) GO TO 270 7224 RNB = RNDB2 7225 RNR = RNDR2 7226C 7227C COMPUTE DIGITS = AVERAGE NUMBER OF DIGITS IN AGREEMENT BETWEEN 7228C INITIAL SOLUTION AND FIRST ITERATION. 7229C 7230 270 IF (KI.NE.1) GO TO 290 7231CCCCC XNORM = SPSQRT (RNB) 7232 CALL SPSQRT (RNB,RESULT) 7233 XNORM = RESULT 7234CCCCC DXNORM = SPSQRT (RNDB2) 7235 CALL SPSQRT (RNDB2,RESULT) 7236 DXNORM = RESULT 7237 IF (XNORM.NE.0.0) GO TO 280 7238CCCCC DIGITS = - SPLO10 (E) JUNE 1987 7239 CALL SPLO10(E,RESULT) 7240 DIGITS = - RESULT 7241 GO TO 290 7242C 7243C280 DIGITS = - SPLO10 (AMAX1(SPDIV(DXNORM,XNORM,IND),E)) 7244 280 CONTINUE 7245CCCCC CALL SPLO10 (AMAX1(SPDIV(DXNORM,XNORM,IND),E),RESULT) 7246 CALL SPDIV(DXNORM,XNORM,IND,RESUL2) 7247 CALL SPLO10 (AMAX1(RESUL2,E),RESULT) 7248 DIGITS = - RESULT 7249C 7250C END KI-TH ITERATION STEP. 7251C 7252 290 KI = KI + 1 7253 IF (KI.GT.ITMAX) GO TO 310 7254C 7255C BLOCK 3 (END) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7256C 7257 GO TO 30 7258C 7259C BLOCK 4 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7260C 7261 300 IF (RNDR2.GT.4.0*ETA2*RNR .AND. RNDB2.GT.4.0*ETA2*RNB) GO TO 310 7262 K = 0 7263 GO TO 320 7264C 7265C NOTE: IF SINGLE PRECISION = DOUBLE PRECISION, THEN YOU WANT TO 7266C EFFECTIVELY OMIT ITERATIVE REFINEMENT. 7267C310 K = 1 COMMENTED OUT (JUNE 1987) TO GIVE CORRECT ANSWERS ON THE VAX. 7268C310 K = 0 7269 310 CONTINUE 7270CCCCC print *,'k = ',k 7271 K = 0 7272C 7273C BLOCK 4 (END) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7274C 7275 320 NI = KI - 1 7276 F(1) = DIGITS 7277 RETURN 7278C 7279C ================================================================== 7280C 7281 END 7282CCCCC-----DSUMAL-------------------------------------- 7283 SUBROUTINE DSUMAL (DX,NN,SNEG,SPOS,SUM) 7284CCCCC SUBROUTINE DSUMAL (DX,NN,SUM) 7285CCCCC THE ARGUMENTS SNEG AND SPOS WERE ADDED SEPTEMBER 1995 7286CCCCC UPDATED--SEPTEMBER 1995 HAVE SNEG & SPOS AS INPUT/OUTPUT ARGUMENTS 7287CCCCC TO AVOID FAILURE-TO-SAVE ON SOME COMPUTERS 7288C 7289C ================================================================== 7290C 7291C *** GENERAL COMMENTS *** 7292C 7293C ALGORITHM DESCRIBED BY MALCOLM IN COM. OF ACM VOL. 14, NO. 11 7294C 7295C SPECIAL ALGORITHM FOR SUMMING DOUBLE PRECISION NUMBERS. 7296C (USE SUMMAL, IF NUMBERS ARE REAL.) 7297C 7298C NN EQUALS ZERO, CLEAR AREA TO PREPARE FOR NEW SUM. 7299C NN EQUALS ONE, OBTAIN FINAL SUM. 7300C NN GREATER THAN ZERO, CLEAR, DO SUM ON NN TERMS AND GET FINAL SUM. 7301C NN LESS THAN ZERO, CONTINUE SUM FOR NEXT ABS(NN) TERMS, 7302C DO NOT GET FINAL SUM. 7303C 7304C WRITTEN BY - 7305C SALLY T. PEAVY, 7306C STATISTICAL ENGINEERING DIVISION, 7307C CENTER FOR APPLIED MATHEMATICS, 7308C A337 ADMINISTRATION BUILDING, 7309C NATIONAL BUREAU OF STANDARDS, 7310C GAITHERSBURG, MD. 20899 7311C TELEPHONE 301-975-2844 7312C 7313C UPDATED--NOVEMBER 1989--DIMENSION (1) TO DIMENSION (*) 7314C 7315C ================================================================== 7316C 7317C *** SPECIFICATION STATEMENTS *** 7318C 7319CCCCC THE FOLLOWING LINE WAS MOVED AND NOVEMBER 1989 7320CCCCC CONVERTED (1) TO (*) 7321CCCCC (BUG UNCOVERED BY NELSON HSU) 7322CCCCC DIMENSION DX(1) 7323C 7324 DOUBLE PRECISION DX, SUM, SNEG, SPOS 7325C 7326 DIMENSION DX(*) 7327C 7328C ================================================================== 7329C 7330CCCCC IF(NN) 30,10,20 7331 IF(NN.LT.0)THEN 7332 GOTO30 7333 ELSEIF(NN.EQ.0)THEN 7334 GOTO10 7335 ELSEIF(NN.GT.0)THEN 7336 GOTO20 7337 ENDIF 7338 10 SPOS = 0.0 7339 SNEG = 0.0 7340 RETURN 7341C 7342C .................................................................. 7343C 7344 20 IF (NN.EQ.1) GO TO 50 7345 SPOS = 0.0 7346 SNEG = 0.0 7347C 7348 30 N = IABS (NN) 7349 DO 40 I=1,N 7350 IF (DX(I).LT.0.0) SNEG = SNEG + DX(I) 7351 IF (DX(I).GE.0.0) SPOS = SPOS + DX(I) 7352 40 CONTINUE 7353C 7354 IF (NN.LT.0) RETURN 7355C 7356 50 SUM = SPOS + SNEG 7357 RETURN 7358C 7359C ================================================================== 7360C 7361 END 7362 SUBROUTINE SDPRED (N,M,R,Q,SB,SD,SDYHAT) 7363C 7364C ================================================================== 7365C 7366C *** GENERAL COMMENTS *** 7367C 7368C SUBROUTINE SDPRED COMPUTES STANDARD DEVIATIONS OF PREDICTED 7369C VALUES. 7370C 7371C WRITTEN BY - 7372C ROY H. WAMPLER, 7373C STATISTICAL ENGINEERING DIVISION, 7374C CENTER FOR APPLIED MATHEMATICS, 7375C A337 ADMINISTRATION BUILDING, 7376C NATIONAL BUREAU OF STANDARDS, 7377C GAITHERSBURG, MD. 20899 7378C TELEPHONE 301-975-2844 7379C 7380C UPDATED--NOVEMBER 1989--DIMENSION (1) TO DIMENSION (*) 7381C 7382C ================================================================== 7383C 7384C *** SPECIFICATION STATEMENTS *** 7385C 7386CCCCC THE FOLLOWING LINE WAS TRANSLATED TO NOVEMBER 1989 7387CCCCC 4 DIMENSION STATEMENTS (SEE BELOW) 7388CCCCC (BUG UNCOVERED BY NELSON HSU) 7389CCCCC REAL Q(1), R(1), SB(1), SDYHAT(1) 7390 REAL SD 7391CCCCC REAL SPDIV, DPCON, SPSQRT 7392C 7393 DOUBLE PRECISION DSUM 7394C 7395 DIMENSION Q(*) 7396 DIMENSION R(*) 7397 DIMENSION SB(*) 7398 DIMENSION SDYHAT(*) 7399C 7400C ================================================================== 7401C 7402 DO 10 J=1,M 7403CCCCC L = IDIV (2*(J-1)*(M+1)-J*J+3*J,2,IND) 7404 CALL IDIV (2*(J-1)*(M+1)-J*J+3*J,2,IND,L) 7405CCCCC SB(J) = SPDIV (1.0,SPSQRT (R(L)),IND) 7406 CALL SPSQRT(R(L),RESULT) 7407CCCCC SB(J) = SPDIV (1.0,RESULT,IND) 7408 CALL SPDIV (1.0,RESULT,IND,SB(J)) 7409 10 CONTINUE 7410C 7411 DO 30 I=1,N 7412 DSUM = 0.0D0 7413 DO 20 J=1,M 7414 L = (J-1) * N + I 7415 DSUM = DSUM + (DBLE (Q(L)) * DBLE (SB(J))) ** 2 7416 20 CONTINUE 7417C 7418CCCCC SDYHAT(I) = DPCON (DSUM) 7419 CALL DPCON (DSUM,SDYHAT(I)) 7420 IF (SDYHAT(I).LT.0.0) SDYHAT(I) = 0.0 7421CCCCC SDYHAT(I) = SD * SPSQRT (SDYHAT(I)) 7422 CALL SPSQRT(SDYHAT(I),RESULT) 7423 SDYHAT(I) = SD * RESULT 7424 30 CONTINUE 7425 RETURN 7426C 7427C ================================================================== 7428C 7429 END 7430CCCCC-----PINVRT-------------------------------------- 7431 SUBROUTINE PINVRT (M,R,D) 7432C 7433C ================================================================== 7434C 7435C *** GENERAL COMMENTS *** 7436C 7437C SUBROUTINE PINVRT OBTAINS THE UNSCALED COVARIANCE MATRIX OF THE 7438C COEFFICIENTS, EQUAL TO THE INVERSE OF (X-TRANSPOSE)*W*X. 7439C MATRIX R OBTAINED FROM SUBROUTINE PDECOM IS USED AS INPUT. 7440C THIS MATRIX IS OVERWRITTEN AND ON EXIT WILL EQUAL THE DESIRED 7441C INVERSE. 7442C 7443C SINCE THE INVERSE MATRIX IS SYMMETRIC, ONLY THE PORTION ON OR 7444C ABOVE THE PRINCIPAL DIAGONAL IS STORED. 7445C 7446C WRITTEN BY - 7447C ROY H. WAMPLER, 7448C STATISTICAL ENGINEERING DIVISION, 7449C CENTER FOR APPLIED MATHEMATICS, 7450C A337 ADMINISTRATION BUILDING, 7451C NATIONAL BUREAU OF STANDARDS, 7452C GAITHERSBURG,MD. 20899 7453C TELEPHONE 301-975-2844 7454C 7455C UPDATED--NOVEMBER 1989--DIMENSION (1) TO DIMENSION (*) 7456C 7457C ================================================================== 7458C 7459C *** SPECIFICATION STATEMENTS *** 7460C 7461CCCCC THE FOLLOWING LINE WAS TRANSLATED INTO NOVEMBER 1989 7462CCCCC 2 DIMENSION STATEMENTS (SEE BELOW) 7463CCCCC (BUG UNCOVERED BY NELSON HSU) 7464CCCCC REAL D(1), R(1) 7465C 7466CCCCC REAL SPDIV, DPCON 7467C 7468 DOUBLE PRECISION DSUM 7469C 7470 DIMENSION D(*) 7471 DIMENSION R(*) 7472C 7473C ================================================================== 7474C 7475 DO 10 L=1,M 7476CCCCC LL = IDIV (2*(L-1)*(M+1)-L*L+3*L,2,IRR) 7477 CALL IDIV (2*(L-1)*(M+1)-L*L+3*L,2,IRR,LL) 7478CCCCC R(LL) = SPDIV (1.0,R(LL),IRR) 7479 CALL SPDIV (1.0,R(LL),IRR,R(LL)) 7480 10 CONTINUE 7481C 7482 IF (M.EQ.1) RETURN 7483 L = M 7484 20 J = L - 1 7485CCCCC LJ = IDIV (2*(J-1)*(M+1)-J*J+3*J,2,IRR) 7486 CALL IDIV (2*(J-1)*(M+1)-J*J+3*J,2,IRR,LJ) 7487 INC = 0 7488 DO 30 K=L,M 7489 INC = INC + 1 7490 JK = LJ + INC 7491 D(K) = R(JK) 7492 30 CONTINUE 7493C 7494 I = M 7495 DO 50 KA=J,M 7496 DSUM = 0.0D0 7497 IF (I.EQ.J) DSUM = DBLE (R(LJ)) 7498 DO 40 K=L,M 7499 JK = MIN0 (K,I) 7500CCCCC LL = IDIV (2*(JK-1)*(M+1)-JK*JK+3*JK,2,IRR) 7501 CALL IDIV (2*(JK-1)*(M+1)-JK*JK+3*JK,2,IRR,LL) 7502 INC = IABS (K-I) 7503 JK = LL + INC 7504 DSUM = DSUM -DBLE (D(K)) * DBLE (R(JK)) 7505 40 CONTINUE 7506 INC = I - J 7507 JK = LJ + INC 7508CCCCC R(JK) = DPCON (DSUM) 7509 CALL DPCON (DSUM,R(JK)) 7510 I = I - 1 7511 50 CONTINUE 7512 L = L - 1 7513 IF (L.GT.1) GO TO 20 7514C 7515C C 7516C PACK VECTOR R. 7517C 7518 DO 70 I=2,M 7519CCCCC L = IDIV (2*(I-1)*M-I*I+3*I,2,IRR) 7520 CALL IDIV (2*(I-1)*M-I*I+3*I,2,IRR,L) 7521 DO 60 J=I,M 7522 K = L + I - 1 7523 R(L) = R(K) 7524 L = L + 1 7525 60 CONTINUE 7526 70 CONTINUE 7527C 7528 RETURN 7529C 7530C ================================================================== 7531C 7532 END 7533CCCCC-----DPDIV-------------------------------------- 7534 SUBROUTINE DPDIV(FN,FD,IND,DRESUL) 7535C 7536C PURPOSE--PERFORM DOUBLE PRECISION DIVISION FN/FD, 7537C IF THE DENOMINATOR EQUALS ZERO, 7538C THE RESULT IS SET TO ZERO, 7539C AND THE INDICATOR, IND, IS SET EQUAL TO ONE. 7540C OTHERWISE, IND IS SET TO 0. 7541C INPUT ARGUMENTS--FN 7542C --FD 7543C OUTPUT ARGUMENTS--IND 7544C --DRESUL 7545C WRITTEN BY--ROY WAMPLER 7546C DAVE HOGBEN 7547C SALLY PEAVY 7548C CONVERTED TO DATAPLOT BY--JAMES J. FILLIBEN (JUNE 1987) 7549C LANGUAGE--ANSI FORTRAN (1977) 7550C VERSION NUMBER--87/7 7551C ORIGINAL VERSION--JUNE 1987. 7552C 7553C-----CHARACTER STATEMENTS FOR NON-COMMON VARIABLES------------------- 7554C 7555 DOUBLE PRECISION FN 7556 DOUBLE PRECISION FD 7557 DOUBLE PRECISION DRESUL 7558C 7559C-----DIMENSION------------------------------------------------------- 7560 7561C-----COMMON---------------------------------------------------------- 7562C 7563C-----COMMON VARIABLES (GENERAL)-------------------------------------- 7564C 7565 INCLUDE 'DPCOP2.INC' 7566C 7567C-----START POINT----------------------------------------------------- 7568C 7569 IND = 0 7570 IF(FD.EQ.0.0D0)GOTO1010 7571 DRESUL=FN/FD 7572 GOTO9000 7573C 7574 1010 CONTINUE 7575 DRESUL=0.0D0 7576 IND=1 7577 GOTO9000 7578C 7579 9000 CONTINUE 7580 RETURN 7581 END 7582CCCCC-----SPDIV-------------------------------------- 7583 SUBROUTINE SPDIV(FN,FD,IND,RESULT) 7584C 7585C PURPOSE--PERFORM SINGLE PRECISION DIVISION FN/FD, 7586C IF THE DENOMINATOR EQUALS ZERO, 7587C THE RESULT IS SET TO ZERO, 7588C AND THE INDICATOR, IND, IS SET EQUAL TO ONE. 7589C OTHERWISE, IND IS SET TO 0. 7590C INPUT ARGUMENTS--FN 7591C --FD 7592C OUTPUT ARGUMENTS--IND 7593C --RESULT 7594C WRITTEN BY--ROY WAMPLER 7595C DAVE HOGBEN 7596C SALLY PEAVY 7597C CONVERTED TO DATAPLOT BY--JAMES J. FILLIBEN (JUNE 1987) 7598C LANGUAGE--ANSI FORTRAN (1977) 7599C VERSION NUMBER--87/7 7600C ORIGINAL VERSION--JUNE 1987. 7601C 7602C-----CHARACTER STATEMENTS FOR NON-COMMON VARIABLES------------------- 7603C 7604C-----DIMENSION------------------------------------------------------- 7605 7606C-----COMMON---------------------------------------------------------- 7607C 7608C-----COMMON VARIABLES (GENERAL)-------------------------------------- 7609C 7610 INCLUDE 'DPCOP2.INC' 7611C 7612C-----START POINT----------------------------------------------------- 7613C 7614 IND = 0 7615 IF(FD.EQ.0.0D0)GOTO1010 7616 RESULT=FN/FD 7617 GOTO9000 7618C 7619 1010 CONTINUE 7620 RESULT=0.0D0 7621 IND=1 7622 GOTO9000 7623C 7624 9000 CONTINUE 7625 RETURN 7626 END 7627CCCCC-----DPCON-------------------------------------- 7628 SUBROUTINE DPCON(DX,RESULT) 7629C 7630C PURPOSE--CONVERT DOUBLE PRECISION NUMBER 7631C TO SINGLE PRECISION NUMBER BY OCTAL ROUNDING 7632C INSTEAD OF TRUNCATION. 7633C INPUT ARGUMENTS--DX (DOUBLE PRECISION) 7634C OUTPUT ARGUMENTS--RESULT (SINGLE PRECISION) 7635C WRITTEN BY - 7636C DAVID HOGBEN, 7637C STATISTICAL ENGINEERING DIVISION, 7638C CENTER FOR APPLIED MATHEMATICS, 7639C A337 ADMINISTRATION BUILDING, 7640C NATIONAL BUREAU OF STANDARDS, 7641C WASHINGTON, DC 20234 7642C TELEPHONE 301-975-2855 7643C ORIGINAL VERSION - AUGUST, 1969. 7644C CURRENT VERSION - NOVEMBER, 1978. 7645C CONVERTED TO DATAPLOT BY--JAMES J. FILLIBEN (JUNE 1987) 7646C LANGUAGE--ANSI FORTRAN (1977) 7647C VERSION NUMBER--87/7 7648C ORIGINAL VERSION--JUNE 1987. 7649C 7650C-----CHARACTER STATEMENTS FOR NON-COMMON VARIABLES------------------- 7651C 7652 REAL Y 7653C 7654 DOUBLE PRECISION DX 7655 DOUBLE PRECISION DXX 7656 DOUBLE PRECISION D 7657C 7658C-----DIMENSION------------------------------------------------------- 7659 7660C-----COMMON---------------------------------------------------------- 7661C 7662C-----COMMON VARIABLES (GENERAL)-------------------------------------- 7663C 7664 INCLUDE 'DPCOP2.INC' 7665C 7666C-----DATA STATEMETNS------------------------------------------------- 7667C 7668 DATA RMIFY / -1.0E37 / 7669 DATA RPIFY / 1.0E38 / 7670C 7671C-----START POINT----------------------------------------------------- 7672C 7673 DXX = DX 7674 IF (DXX.GT.DBLE(RPIFY)) DXX = RPIFY 7675 IF (DXX.LT.DBLE(RMIFY)) DXX = RMIFY 7676C 7677 Y = DXX 7678 D = Y 7679 RESULT = DXX + (DXX-D) 7680C 7681 RETURN 7682 END 7683CCCCC-----DPSQRT-------------------------------------- 7684 SUBROUTINE DPSQRT(DX,DRESUL) 7685C 7686C PURPOSE--PERFORM DOUBLE PRECISION SQUARE ROOT OF DX, 7687C IF THE DENOMINATOR IS LESS THAN 0, 7688C THE OUTPUT RESULT IS SET TO 0, 7689C AND AN ARITHMETIC FAULT MESSAGE IS PRINTED. 7690C INPUT ARGUMENTS--X 7691C OUTPUT ARGUMENTS--DRESUL 7692C WRITTEN BY--ROY WAMPLER 7693C DAVE HOGBEN 7694C SALLY PEAVY 7695C CONVERTED TO DATAPLOT BY--JAMES J. FILLIBEN (JUNE 1987) 7696C LANGUAGE--ANSI FORTRAN (1977) 7697C VERSION NUMBER--87/7 7698C ORIGINAL VERSION--JUNE 1987. 7699C 7700C-----CHARACTER STATEMENTS FOR NON-COMMON VARIABLES------------------- 7701C 7702 DOUBLE PRECISION DX 7703 DOUBLE PRECISION DRESUL 7704C 7705C-----DIMENSION------------------------------------------------------- 7706 7707C-----COMMON---------------------------------------------------------- 7708C 7709C-----COMMON VARIABLES (GENERAL)-------------------------------------- 7710C 7711 INCLUDE 'DPCOP2.INC' 7712C 7713C-----START POINT----------------------------------------------------- 7714C 7715 IF(DX.LE.0.0D0)GOTO1010 7716 DRESUL=DSQRT(DX) 7717 GOTO9000 7718C 7719 1010 CONTINUE 7720 DRESUL=0.0D0 7721 GOTO9000 7722C 7723 9000 CONTINUE 7724 RETURN 7725 END 7726CCCCC-----SPSQRT-------------------------------------- 7727 SUBROUTINE SPSQRT(X,RESULT) 7728C 7729C PURPOSE--PERFORM SINGLE PRECISION SQUARE ROOT OF X, 7730C IF THE DENOMINATOR IS LESS THAN 0, 7731C THE OUTPUT RESULT IS SET TO 0, 7732C CALLS ERROR(101) IS DONE. 7733C INPUT ARGUMENTS--X 7734C OUTPUT ARGUMENTS--RESULT 7735C WRITTEN BY--ROY WAMPLER 7736C DAVE HOGBEN 7737C SALLY PEAVY 7738C CONVERTED TO DATAPLOT BY--JAMES J. FILLIBEN (JUNE 1987) 7739C LANGUAGE--ANSI FORTRAN (1977) 7740C VERSION NUMBER--87/7 7741C ORIGINAL VERSION--NOVEMBER 1987. 7742C 7743C-----CHARACTER STATEMENTS FOR NON-COMMON VARIABLES------------------- 7744C 7745C 7746C-----DIMENSION------------------------------------------------------- 7747 7748C-----COMMON---------------------------------------------------------- 7749C 7750C-----COMMON VARIABLES (GENERAL)-------------------------------------- 7751C 7752 INCLUDE 'DPCOP2.INC' 7753C 7754C-----START POINT----------------------------------------------------- 7755C 7756 IF(X.LE.0.0)GOTO1010 7757 RESULT=SQRT(X) 7758 GOTO9000 7759C 7760 1010 CONTINUE 7761 RESULT=0.0 7762 GOTO9000 7763C 7764 9000 CONTINUE 7765 RETURN 7766 END 7767CCCCC-----SPLO10-------------------------------------- 7768 SUBROUTINE SPLO10(X,RESULT) 7769C 7770C PURPOSE--COMPUTER LOG TO BASE 10 OF X 7771C USING LIBRARY FUNCTION OF X IS POSITIVE, OR 7772C CALLS ERROR(101) AND SETS FUNCTION VALUE 7773C EQUAL TO 0 IF X IS NONPOSITIVE. 7774C 7775C INPUT ARGUMENTS--X 7776C OUTPUT ARGUMENTS--RESULT 7777C WRITTEN BY--ROY WAMPLER 7778C DAVE HOGBEN 7779C SALLY PEAVY 7780C CONVERTED TO DATAPLOT BY--JAMES J. FILLIBEN (JUNE 1987) 7781C LANGUAGE--ANSI FORTRAN (1977) 7782C VERSION NUMBER--87/7 7783C ORIGINAL VERSION--JUNE 1987. 7784C 7785C-----CHARACTER STATEMENTS FOR NON-COMMON VARIABLES------------------- 7786C 7787C-----DIMENSION------------------------------------------------------- 7788 7789C-----COMMON---------------------------------------------------------- 7790C 7791C-----COMMON VARIABLES (GENERAL)-------------------------------------- 7792C 7793 INCLUDE 'DPCOP2.INC' 7794C 7795C-----START POINT----------------------------------------------------- 7796C 7797 IF(X.GT.0.0)GOTO1020 7798 RESULT=0.0 7799 GOTO9000 7800C 7801 1020 CONTINUE 7802 RESULT=LOG10(X) 7803 GOTO9000 7804C 7805 9000 CONTINUE 7806 RETURN 7807 END 7808CCCCC-----IDIV-------------------------------------- 7809 SUBROUTINE IDIV(IN,ID,IND,IRESUL) 7810C 7811C PURPOSE--THIS INTEGER FUNCTION PERFORMS THE DIVISION IN/ID, WHEN 7812C THE NUMERATOR, IN, AND THE DENOMINATOR, ID, ARE INTEGERS. 7813C IF ID = 0, THE FUNCTION VALUE IS SET EQUAL TO ZERO. 7814C 7815C INPUT ARGUMENTS--IN 7816C --ID 7817C OUTPUT ARGUMENTS--IND 7818C --IRESUL 7819C WRITTEN BY--ROY WAMPLER 7820C DAVE HOGBEN 7821C SALLY PEAVY 7822C CONVERTED TO DATAPLOT BY--JAMES J. FILLIBEN (JUNE 1987) 7823C NOTE--DATAPLOT IS A REGISTERED TRADEMARK 7824C OF THE NATIONAL BUREAU OF STANDARDS. 7825C LANGUAGE--ANSI FORTRAN (1977) 7826C VERSION NUMBER--87/7 7827C ORIGINAL VERSION--JUNE 1987. 7828C 7829C-----CHARACTER STATEMENTS FOR NON-COMMON VARIABLES------------------- 7830C 7831C-----DIMENSION------------------------------------------------------- 7832 7833C-----COMMON---------------------------------------------------------- 7834C 7835C-----COMMON VARIABLES (GENERAL)-------------------------------------- 7836C 7837 INCLUDE 'DPCOP2.INC' 7838C 7839C-----START POINT----------------------------------------------------- 7840C 7841 IND = 0 7842 IF(ID.EQ.0)GOTO1010 7843 IRESUL=IN/ID 7844 GOTO9000 7845C 7846 1010 CONTINUE 7847 IRESUL=0 7848 IND=1 7849 GOTO9000 7850C 7851 9000 CONTINUE 7852 RETURN 7853 END 7854*BACK 7855 SUBROUTINE BACK (NC,LB,L,K,MV,RS,A,I,JC,ID,XI,MD,II,NI,ND,KZ,NL,N) 7856C 7857C ** NBS OMNITAB 1980 VERSION 6.01 1/ 1/81. BACK V 7.00 2/14/90. ** 7858C 7859C ================================================================== 7860C 7861C *** GENERAL COMMENTS *** 7862C 7863C LOOK BACK COMPUTATION OF RSS 7864C 7865C ONE OF FOUR SUBROUTINES CALLED BY MAIN SUBROUTINE SCREEN FOR 7866C REGRESSIONS BY LEAPS AND BOUNDS 7867C A PROGRAM FOR FINDING THE BEST SUBSET REGRESSIONS 7868C G.M.FURNIVAL AND R.W.WILSON 7869C YALE UNIVERSITY AND U.S. FOREST SERVICE 7870C VERSION 11/11/74 7871C 7872C ADAPTED TO OMNITAB BY - 7873C DAVID HOGBEN, 7874C STATISTICAL ENGINEERING DIVISION, 7875C CENTER FOR COMPUTING AND APPLIED MATHEMATICS, 7876C A337 ADMINISTRATION BUILDING, 7877C NATIONAL INSTITUTE OF STANDARDS AND TECHNOLOGY, 7878C GAITHERSBURG, MD 20899 7879C TELEPHONE 301-975-2845 7880C ORIGINAL VERSION - FEBRUARY, 1977. 7881C CURRENT VERSION - FEBRUARY, 1990. 7882C 7883C ================================================================== 7884C 7885C *** SPECIFICATION STATEMENTS *** 7886C 7887 DIMENSION I(ND,ND), ID(ND), K(ND), NC(ND,ND), NI(ND), MD(ND,ND) 7888C 7889 REAL XI(NL) 7890 REAL A, RS 7891 REAL B 7892 REAL FDIV 7893C 7894 DATA ITHRE /3/ 7895 DATA IONE /1/ 7896 DATA IZERO /0/ 7897C 7898C ================================================================== 7899C 7900C FIND SOURCE MATRIX. 7901C 7902 10 ISUB1 = K(JC) 7903 IF (LB.LE.NI(ISUB1)) GO TO 20 7904 JC = JC - IONE 7905 GO TO 10 7906C 7907C ADJUST FOR PREVIOUS PIVOTS. 7908C 7909 20 ISUB2 = IONE 7910 ISUB3 = IONE 7911 DO 50 J=JC,MV 7912 IN = K(J) 7913 L = I(IN,LB) 7914 MM = ID(IN) 7915 ISUB2 = MM + MD(L,KZ) 7916 ISUB3 = MM + MD(L,L) 7917 IF (J.EQ.MV) GO TO 60 7918 IS = K(J+1) 7919 ISUB4 = ID(IS) + MD(LB,KZ) 7920 IP = I(IN,IS-1) 7921 ISUB5 = MM + MD(IP,L) 7922 ISUB6 = MM + MD(IP,IP) 7923 ISUB7 = MM + MD(IP,KZ) 7924 B = FDIV (XI(ISUB5),XI(ISUB6),IND) 7925 KA = IS 7926 30 IF (KA.GT.LB) GO TO 40 7927 KN = I(IN,KA) 7928 ISUB8 = ID(IS) + MD(KA,LB) 7929 ISUB9 = MM + MD(KN,L) 7930 ISUB0 = MM + MD(KN,IP) 7931 XI(ISUB8) = XI(ISUB9) - B * XI(ISUB0) 7932 KA = KA + IONE 7933 GO TO 30 7934 40 XI(ISUB4) = XI(ISUB2) - B * XI(ISUB7) 7935 NI(IS) = LB 7936 I(IS,LB) = LB 7937 N = N + ITHRE + LB - IS 7938 IF (II.EQ.IZERO) NC(IS,LB) = NC(IN,L) 7939 50 CONTINUE 7940C 7941C CURRENT PIVOT. 7942C 7943 60 RS = A - FDIV (XI(ISUB2)*XI(ISUB2),XI(ISUB3),IND) 7944 RETURN 7945C 7946C ================================================================ 7947C 7948 END 7949*CODEXY 7950 SUBROUTINE CODEXY (X,N,SUMX,AVEX,XCODE,SQRTCT,U,L) 7951C 7952C ** NBS OMNITAB 1980 VERSION 6.01 1/ 1/81. CODEXY V 7.00 2/14/90. ** 7953C 7954C ================================================================== 7955C 7956C *** GENERAL COMMENTS *** 7957C 7958C PROCEDURE FOR CODING X FOR ACCURATELY COMPUTING 7959C SUM OF SQUARED DEVIATIONS FROM THE MEAN. 7960C 7961C INPUT PARAMETERS ARE - 7962C 7963C X = VECTOR OF MEASUREMENTS 7964C N = LENGTH OF X 7965C 7966C OUPUT PARAMETERS ARE - 7967C 7968C SUMX = DOUBLE PRECISION SUM OF X MEASUREMENTS 7969C AVEX = SINGLE PRECISION AVERAGE OF THE X MEASUREMENTS 7970C XCODE = CODED VALUE TO BE USED INSTEAD OF AVERAGE FOR 7971C CUMPUTING DEVIATIONS ABOUT THE MEAN. 7972C XCODE IS THE VALUE OF X(I) CLOSEST TO AVEX. 7973C SQRTCT = SQUARE ROOT OF CORRECTION TERM FOR COMPUTING 7974C SUM OF SQUARED DEVIATIONS ABOUT THE MEAN. 7975C 7976C SUM (X-AVEX)**2 = SUM(X-CODEX)**2 - SQRTCT**2, 7977C 7978C WHERE SQRTCT = (SUMX-N*XCODE)/SQRT(N) 7979C 7980C U(I) = X(I) -XCODE, = CODED VALUES OF X 7981C L = VALUE OF I FOR WHICH XCODE = X(I). 7982C 7983C WRITTEN BY - 7984C DAVID HOGBEN, 7985C STATISTICAL ENGINEERING DIVISION, 7986C CENTER FOR COMPUTING AND APPLIED MATHEMATICS, 7987C A337 ADMINISTRATION BUILDING, 7988C NATIONAL INSTITUTE OF STANDARDS AND TECHNOLOGY, 7989C GAITHERSBURG, MD 20899 7990C TELEPHONE 301-975-2845 7991C ORIGINAL VERSION - FEBRUARY, 1977. 7992C CURRENT VERSION - FEBRUARY, 1990. 7993C 7994C ================================================================== 7995C 7996C *** SPECIFICATION STATEMENTS *** 7997C 7998 REAL X(*), U(*) 7999 REAL AVEX, DELTA, XCODE 8000 REAL FDPCON 8001C 8002CCCCC DOUBLE PRECISION DZERO 8003 DOUBLE PRECISION DN, SQRTCT, SUMX 8004 DOUBLE PRECISION FDDIV, FDSQRT 8005 DOUBLE PRECISION DX(1) 8006 DOUBLE PRECISION SNEG 8007 DOUBLE PRECISION SPOS 8008C 8009CCCCC DATA DZERO /0.0D0/ 8010 DATA IONE /1/ 8011 DATA IZERO /0/ 8012C ================================================================== 8013C 8014 SNEG=0.0D0 8015 SPOS=0.0D0 8016C COMPUTE AVEX. 8017C 8018CCCCC CALL DSUMAL (DX,IZERO,SUMX) 8019 CALL DSUMAL (DX,IZERO,SNEG,SPOS,SUMX) 8020 DO 10 I=1,N 8021 DX(1) = DBLE ( X(I) ) 8022CCCCC CALL DSUMAL (DX,-IONE,SUMX) 8023 CALL DSUMAL (DX,-IONE,SNEG,SPOS,SUMX) 8024 10 CONTINUE 8025CCCCC CALL DSUMAL (DX,IONE,SUMX) 8026 CALL DSUMAL (DX,IONE,SNEG,SPOS,SUMX) 8027C 8028 DN = N 8029C 8030 AVEX = FDPCON ( FDDIV (SUMX,DN,IND) ) 8031C 8032C COMPUTE XCODE AND L. 8033C 8034 L = IONE 8035 DELTA = ABS (X(1)-AVEX) 8036 DO 30 I=2,N 8037CCCCC IF (ABS(X(I)-AVEX)-DELTA) 20,30,30 8038 IF (ABS(X(I)-AVEX)-DELTA.LT.0.0) THEN 8039 L = I 8040 DELTA = ABS (X(I)-AVEX) 8041 ENDIF 8042 30 CONTINUE 8043C 8044 XCODE = X(L) 8045C 8046C COMPUTE CODED X = (X-XCODE). 8047C 8048 DO 40 I=1,N 8049 U(I) = X(I) - XCODE 8050 40 CONTINUE 8051C 8052C COMPUTE CORRECTION TERM 8053C FOR COMPUTING SUMX OF DEVIATIONS ABOUT THE MEAN. 8054C 8055 SQRTCT = FDDIV (SUMX-DN*DBLE(XCODE),FDSQRT(DN),IND) 8056C 8057 RETURN 8058C 8059C ================================================================== 8060C 8061 END 8062*COEF 8063 SUBROUTINE COEF (R2,BIC,MP,KZ,XI,RR,MAXC,IND,NDEF,M, 8064 1 ND,MD,NL,IB,ZC, 8065 1 AMAT,IVALUE,NCVALU,MAXROW,NUMCLI,ITITL9,NCTIT9) 8066C 8067C ** NBS OMNITAB 1980 VERSION 6.01 1/ 1/81. COEF V 7.00 8/27/91. ** 8068C 8069C ================================================================== 8070C 8071C *** GENERAL COMMENTS *** 8072C 8073C COMPUTES REGRESSION STATISTICS 8074C 8075C ******************************************************************** * 8076C * 8077C ONE OF FOUR SUBROUTINES CALLED BY MAIN SUBROUTINE SCREEN FOR * 8078C REGRESSIONS BY LEAPS AND BOUNDS * 8079C A PROGRAM FOR FINDING THE BEST SUBSET REGRESSIONS * 8080C G.M.FURNIVAL AND R.W.WILSON * 8081C YALE UNIVERSITY AND U.S. FOREST SERVICE * 8082C VERSION 11/11/74 * 8083C * 8084C ******************************************************************** * 8085C 8086C MODIFIED TO PFORT BY - 8087C DAVID HOGBEN, 8088C STATISTICAL ENGINEERING DIVISION, 8089C CENTER FOR COMPUTING AND APPLIED MATHEMATICS, 8090C A337 ADMINISTRATION BUILDING, 8091C NATIONAL INSTITUTE OF STANDARDS AND TECHNOLOGY, 8092C GAITHERSBURG, MD 20899 8093C TELEPHONE 301-975-2845 8094C ORIGINAL VERSION - SEPTEMBER, 1976. 8095C CURRENT VERSION - AUGUST, 1991. 8096C 8097C ================================================================== 8098C 8099C *** SPECIFICATION STATEMENTS *** 8100C 8101CCCCC DIMENSION IND(ND), MD(ND,ND), NALPHA(15), NOUT(12) 8102CCCCC DIMENSION IND(ND), MD(ND,ND), NOUT(12) 8103 DIMENSION IND(ND), MD(ND,ND) 8104C 8105C ================================================================== 8106C 8107C *** TYPE STATEMENTS *** 8108C 8109CCCCC REAL RR(29,29), XI(NL), ZC(ND) 8110 REAL RR(MAXC,MAXC), XI(NL), ZC(ND) 8111 REAL DBET, F, R2, VAR 8112 REAL FDIV 8113C 8114 REAL AMAT(MAXROW,NUMCLI) 8115 INTEGER NCVALU(MAXROW,NUMCLI) 8116 CHARACTER*8 IVALUE(MAXROW,NUMCLI) 8117 CHARACTER*(*) ITITL9 8118C 8119C .................................................................. 8120C 8121CCCCC CHARACTER NALPHA*1, NOUT*1 8122CCCCC CHARACTER NOUT*1 8123C 8124 PARAMETER (MAXV=98) 8125 CHARACTER*1 ICOD(MAXV) 8126 CHARACTER*38 IOUT 8127 CHARACTER*8 IVLIST 8128 COMMON/BESTC1/IOUNI1,IOUNI2 8129 COMMON/BESTC2/IVLIST(MAXV) 8130C 8131 INCLUDE 'DPCOP2.INC' 8132C 8133C ================================================================== 8134C 8135C *** DATA INITIALIZATION STATEMENTS *** 8136C 8137CCCCC DATA NOUT( 1), NOUT( 2), NOUT( 3), NOUT( 4), NOUT( 5), NOUT( 6) / 8138CCCCC1 'R', '*', '*', '2', 'R', '*' / 8139CCCCC DATA NOUT( 7), NOUT( 8), NOUT( 9), NOUT(10), NOUT(11), NOUT(12) / 8140CCCCC1 '*', '2', 'C', '(', 'P', ')' / 8141 DATA ICOD(1) /'1'/ 8142 DATA ICOD(2) /'2'/ 8143 DATA ICOD(3) /'3'/ 8144 DATA ICOD(4) /'4'/ 8145 DATA ICOD(5) /'5'/ 8146 DATA ICOD(6) /'6'/ 8147 DATA ICOD(7) /'7'/ 8148 DATA ICOD(8) /'8'/ 8149 DATA ICOD(9) /'9'/ 8150 DATA ICOD(10) /'0'/ 8151 DATA ICOD(11) /'A'/ 8152 DATA ICOD(12) /'B'/ 8153 DATA ICOD(13) /'C'/ 8154 DATA ICOD(14) /'D'/ 8155 DATA ICOD(15) /'E'/ 8156 DATA ICOD(16) /'F'/ 8157 DATA ICOD(17) /'G'/ 8158 DATA ICOD(18) /'H'/ 8159 DATA ICOD(19) /'I'/ 8160 DATA ICOD(20) /'J'/ 8161 DATA ICOD(21) /'K'/ 8162 DATA ICOD(22) /'L'/ 8163 DATA ICOD(23) /'M'/ 8164 DATA ICOD(24) /'N'/ 8165 DATA ICOD(25) /'O'/ 8166 DATA ICOD(26) /'P'/ 8167 DATA ICOD(27) /'Q'/ 8168 DATA ICOD(28) /'R'/ 8169 DATA ICOD(29) /'S'/ 8170 DATA ICOD(30) /'T'/ 8171 DATA ICOD(31) /'U'/ 8172 DATA ICOD(32) /'V'/ 8173 DATA ICOD(33) /'W'/ 8174 DATA ICOD(34) /'X'/ 8175 DATA ICOD(35) /'Y'/ 8176 DATA ICOD(36) /'Z'/ 8177 DATA ICOD(37) /'a'/ 8178 DATA ICOD(38) /'b'/ 8179C 8180C IF THE FOLLOWING VALUE IS CHANGED, 8181C THE DIMENSION OF NALPHA MUST BE CHANGED AND 8182C 15A1 MUST BE CHANGED IN FORMAT 70. 8183C 8184CCCCC DATA NX / 15 / 8185C 8186 DATA IFOUR /4/ 8187 DATA ITHRE /3/ 8188C 8189CCCCC NOTE: ISIGD = 7 CAUSES PROBLEMS ON MICROSOFT COMPILER, SGI 8190CCCCC COMPILER. JUST SET TO 6 TO BE SAFE. 8191CCCCC DATA ISIGD /7/ 8192CCCCC DATA ISIGD /6/ 8193C 8194C ================================================================== 8195C 8196 IEND = IFOUR * IB 8197 IBEG = IEND - ITHRE 8198CCCCC WRITE(ICOUT,999) 8199CCCCC CALL DPWRST('XXX','BUG ') 8200CCCCC WRITE(ICOUT,60) (NOUT(I),I=IBEG,IEND), R2 8201CCCCC CALL DPWRST('XXX','BUG ') 8202CCCCC WRITE(ICOUT,61) 8203CCCCC CALL DPWRST('XXX','BUG ') 8204CC60 FORMAT(19X,4A1,' = ',F7.3) 8205CC61 FORMAT(4X,'VARIABLE',9X,'COEFFICIENT',7X,'F RATIO') 8206C 8207 ITITL9='C(p) = ' 8208 WRITE(ITITL9(8:19),'(F12.3)')R2 8209 ITITL9(20:27)=', BIC = ' 8210 WRITE(ITITL9(28:39),'(F12.3)')BIC 8211 NCTIT9=39 8212C 8213C FORM SUBMATRIX 8214C 8215 IND(MP) = KZ 8216 DO 20 I=1,MP 8217 DO 10 J=I,MP 8218 ISUB1 = MD(I,J) 8219 ISUB2 = IND(I) 8220 ISUB3 = IND(J) 8221 XI(ISUB1) = RR(ISUB2,ISUB3) 8222 10 CONTINUE 8223 20 CONTINUE 8224C 8225C INVERT SUBMATRIX 8226C 8227 DO 30 N=1,M 8228 NN = N 8229 CALL PIVOT (XI,MP,NN,MD,ND,NL) 8230 30 CONTINUE 8231C 8232 ISUB4 = MD(MP,MP) 8233 VAR = FDIV (XI(ISUB4),FLOAT(NDEF-M),IF) 8234C 8235 DO 40 I=1,M 8236 ISUB5 = MD(I,MP) 8237 ZC(I) = -XI(ISUB5) 8238 40 CONTINUE 8239C 8240CCCCC NOTE: HAD PROBLEMS WITH RFORMT ON SOME PLATFORMS (MICROSOFT 8241CCCCC FORTRAN, SGI), SO JUST USE E FORMAT FOR NOW. 8242CCCCC CALL RFORMT (0,ISIGD,ZC,XI(1), M,NX,LW,LD,NALPHA(1),IRF) 8243CCCCC LB = NX - LW 8244C 8245 DO 50 I=1,M 8246 DBET = ZC(I) 8247 ISUB6 = MD(I,I) 8248CCCCC CALL RFORMT (1,ISIGD,XI,ZC(I),LB, 1,LW,LD,NALPHA(1),IRF) 8249 F = -DBET*FDIV (DBET,XI(ISUB6)*VAR,IF) 8250CCCCC WRITE(ICOUT,70) IND(I), (NALPHA(J),J=1,NX), F 8251CCCCC WRITE(ICOUT,70) IVLIST(IND(I)), ZC(I), F 8252CCCCC CALL DPWRST('XXX','BUG ') 8253 IVALUE(I,1)=IVLIST(IND(I)) 8254 NCVALU(I,1)=8 8255 AMAT(I,2)=ZC(I) 8256 AMAT(I,3)=F 8257 50 CONTINUE 8258CC70 FORMAT (10X,I2,7X,15A1,5X,F7.3) 8259CC70 FORMAT (4X,A8,7X,E15.7,5X,F7.3) 8260C 8261 WRITE(IOUNI1,71)M,R2,BIC,(IVLIST(IND(J)),J=1,M) 8262 71 FORMAT(I3,1X,2F15.3,' :',38(1X,A8)) 8263C 8264 IOUT=' ' 8265 DO80I=1,M 8266 IOUT(I:I)=ICOD(IND(I)) 8267 80 CONTINUE 8268 WRITE(IOUNI2,'(38A1)')(IOUT(I:I),I=1,M) 8269C999 FORMAT(1X) 8270C 8271 RETURN 8272 END 8273*CPSTRE 8274 SUBROUTINE CPSTRE (RSS,CAB,KO,CL,RM,N,NS,ND) 8275C 8276C ** NBS OMNITAB 1980 VERSION 6.01 1/ 1/81. CPSTRE V 7.00 2/14/90. ** 8277C 8278C ================================================================== 8279C 8280C *** GENERAL COMMENTS *** 8281C 8282C SAVES RSS:S AND LABELS FOR BEST REGRESSIONS 8283C ******************************************************************** * 8284C * 8285C ONE OF FOUR SUBROUTINES CALLED BY MAIN SUBROUTINE SCREEN FOR * 8286C REGRESSIONS BY LEAPS AND BOUNDS * 8287C A PROGRAM FOR FINDING THE BEST SUBSET REGRESSIONS * 8288C G.M.FURNIVAL AND R.W.WILSON * 8289C YALE UNIVERSITY AND U.S. FOREST SERVICE * 8290C VERSION 11/11/74 * 8291C * 8292C ******************************************************************** * 8293C 8294C MODIFIED TO PFORT BY - 8295C DAVID HOGBEN, 8296C STATISTICAL ENGINEERING DIVISION, 8297C CENTER FOR COMPUTING AND APPLIED MATHEMATICS, 8298C A337 ADMINISTRATION BUILDING, 8299C NATIONAL INSTITUTE OF STANDARDS AND TECHNOLOGY, 8300C GAITHERSBURG, MD 20899 8301C TELEPHONE 301-975-2845 8302C ORIGINAL VERSION - FEBRUARY, 1977. 8303C CURRENT VERSION - FEBRUARY, 1990. 8304C 8305C ================================================================== 8306C 8307C *** SPECIFICATION STATEMENTS *** 8308C 8309 REAL CL(11,ND), RM(11,ND) 8310 REAL CAB, RSS 8311C 8312 DATA IONE /1/ 8313 DATA IZERO /0/ 8314C 8315C ================================================================== 8316C 8317 DO 10 L=1,KO 8318 IF (CAB.EQ.CL(L,N)) RETURN 8319 10 CONTINUE 8320C 8321 L = IZERO 8322 20 L = L + IONE 8323 IF (RSS.GT.RM(L+1,N)) GO TO 30 8324 RM(L,N) = RM(L+1,N) 8325 CL(L,N) = CL(L+1,N) 8326 IF (L.EQ.NS) GO TO 30 8327 GO TO 20 8328C 8329 30 RM(L,N) = RSS 8330 CL(L,N) = CAB 8331 RETURN 8332C 8333C ================================================================== 8334C 8335 END 8336*CRSPRD 8337 SUBROUTINE CRSPRD (X,N,M,INTCPT,CTERM,CP,MAXC) 8338C 8339C ** NBS OMNITAB 1980 VERSION 6.01 1/ 1/81. CRSPRD V 7.00 2/14/90. ** 8340C 8341C ================================================================== 8342C 8343C *** GENERAL COMMENTS *** 8344C 8345C PROGRAM UNIT FOR COMPUTING A CROSS PRODUCT OF DEVIATIONS ABOUT 8346C MEAN MATRIX, CP(). 8347C 8348C INPUT X(N,M) 8349C N = NUMBER OF MEASUREMENTS 8350C M = NUMBER OF VARIABLES. 8351C INTCPT = 0, CROSS PRODUCTS ABOUT ORIGIN ARE COMPUTED 8352C = 1, CROSS PRODUCTS ABOUT MEAN ARE COMPUTED. 8353C 8354C STORAGE CONST(M). 8355C 8356C OUTPUT CP(M,M) = CROSS PRODUCT MATRIX. 8357C 8358C WRITTEN BY - 8359C DAVID HOGBEN, 8360C STATISTICAL ENGINEERING DIVISION, 8361C CENTER FOR COMPUTING AND APPLIED MATHEMATICS, 8362C A337 ADMINISTRATION BUILDING, 8363C NATIONAL INSTITUTE OF STANDARDS AND TECHNOLOGY, 8364C GAITHERSBURG, MD 20899 8365C TELEPHONE 301-975-2845 8366C ORIGINAL VERSION - FEBRUARY, 1977. 8367C CURRENT VERSION - FEBRUARY, 1990. 8368C 8369C ================================================================== 8370C 8371C *** SPECIFICATION STATEMENTS *** 8372C 8373 REAL X(N,*) 8374CCCCC REAL CP(29,29) 8375 REAL CP(MAXC,MAXC) 8376 REAL AVEX, XCODE 8377 REAL FDPCON 8378C 8379 DOUBLE PRECISION DZERO 8380 DOUBLE PRECISION CTERM(*) 8381 DOUBLE PRECISION F, SUMNEG, SUMPOS, SUMX 8382C 8383C ================================================================== 8384C 8385 DATA IONE /1/ 8386 DATA DZERO /0.0D0/ 8387C 8388C BEGIN COMPUTING. 8389C 8390C COMPUTE CORRECTION TERM, CTERM(I), AND CODE X(I,J). 8391C 8392 IF (INTCPT.EQ.IONE) GO TO 20 8393 DO 10 I= 1,M 8394 CTERM(I) = DZERO 8395 10 CONTINUE 8396 GO TO 40 8397C 8398 20 DO 30 I=1,M 8399 CALL CODEXY (X(1,I),N,SUMX,AVEX,XCODE,CTERM(I),X(1,I),L) 8400 30 CONTINUE 8401C 8402C COMPUTE (N-1)*VARIANCES. 8403C 8404 40 DO 60 I=1,M 8405 SUMPOS = DZERO 8406 SUMNEG = DZERO 8407 DO 50 J=1,N 8408 F = X(J,I) 8409 F = F**2 8410 SUMPOS = SUMPOS + DMAX1 (DZERO, F) 8411 SUMNEG = SUMNEG + DMAX1 (DZERO,-F) 8412 50 CONTINUE 8413 CP(I,I) = FDPCON ( (SUMPOS - SUMNEG) - CTERM(I)**2 ) 8414 60 CONTINUE 8415C 8416C COMPUTE CROSS PRODUCT MATRIX. 8417C 8418 IEND = M-IONE 8419 DO 90 I=1,IEND 8420 JBEG = I + IONE 8421 DO 80 J=JBEG,M 8422 SUMPOS = DZERO 8423 SUMNEG = DZERO 8424 DO 70 K=1,N 8425 F = DBLE(X(K,I))*DBLE(X(K,J)) 8426 SUMPOS = SUMPOS + DMAX1 (DZERO, F) 8427 SUMNEG = SUMNEG + DMAX1 (DZERO,-F) 8428 70 CONTINUE 8429 CP(I,J) = FDPCON ( (SUMPOS - SUMNEG) - CTERM(I)*CTERM(J) ) 8430 CP(J,I) = CP(I,J) 8431 80 CONTINUE 8432 90 CONTINUE 8433C 8434 RETURN 8435C 8436C ================================================================== 8437C 8438 END 8439*FDDIV 8440 DOUBLE PRECISION FUNCTION FDDIV (FN,FD,IND) 8441C 8442C ** NBS OMNITAB 1980 VERSION 6.01 1/ 1/81. FDDIV V 7.00 2/21/90. ** 8443C 8444C ================================================================== 8445C 8446C *** GENERAL COMMENTS *** 8447C 8448C THIS FUNCTION PERFORMS DOUBLE PRECISION DIVISION. 8449C 8450C IF THE DENOMINATOR EQUALS ZERO, THE RESULT IS SET EQUAL TO ZERO 8451C AND THE INDICATOR, IND, IS SET EQUAL TO ONE. OTHERWISE 8452C IND EQUALS ZERO. 8453C 8454C ================================================================== 8455C 8456C *** SPECIFICATION STATEMENTS *** 8457C 8458 DOUBLE PRECISION DZERO 8459 DOUBLE PRECISION FN, FD 8460C 8461C ================================================================== 8462C 8463 DATA IZERO /0/ 8464 DATA IONE /1/ 8465 DATA DZERO /0.0D0/ 8466C 8467 IND = IZERO 8468 IF(FD-DZERO.EQ.0.0D0)THEN 8469 FDDIV = DZERO 8470 IND = IONE 8471 ELSE 8472 FDDIV = FN/FD 8473 ENDIF 8474 RETURN 8475C 8476C ================================================================== 8477C 8478 END 8479*FDIV 8480 REAL FUNCTION FDIV (FN,FD,IND) 8481C 8482C ** NBS OMNITAB 1980 VERSION 6.01 1/ 1/81. FDIV V 7.00 2/21/90. ** 8483C 8484C ================================================================== 8485C 8486C *** GENERAL COMMENTS *** 8487C 8488C PROGRAM UNIT ... 8489C DIVIDES FN BY FD USING FORTRAN OPERATOR /, 8490C IF X IS NOT EQUAL TO ZERO, OR 8491C SETS FAULT INDICATOR EQUAL TO ONE, 8492C IF X IS EQUAL TO ZERO. 8493C 8494C FAULT INDICATOR, IND = 0, IF FN IS NOT EQUAL TO ZERO, AND 8495C = 1, IF FN IS EQUAL TO ZERO. 8496C 8497C ================================================================== 8498C 8499C *** SPECIFICATION STATEMENTS *** 8500C 8501C 8502 REAL FN, FD 8503C 8504C ================================================================== 8505C 8506 DATA IONE /1/ 8507 DATA IZERO /0/ 8508 DATA RZERO /0.0/ 8509C 8510 IND = IZERO 8511 IF (FD.EQ.RZERO) GO TO 10 8512 FDIV = FN / FD 8513 RETURN 8514C 8515C .................................................................. 8516C 8517 10 FDIV = RZERO 8518 IND = IONE 8519 RETURN 8520C 8521C ================================================================== 8522C 8523 END 8524*FDPCON 8525 REAL FUNCTION FDPCON (X) 8526C 8527C ** NBS OMNITAB 1980 VERSION 6.01 1/ 1/81. FDPCON V 7.00 2/21/90. ** 8528C 8529C ================================================================== 8530C 8531C *** GENERAL COMMENTS *** 8532C 8533C FUNCTION TO CONVERT DOUBLE PRECISION NUMBER TO REAL NUMBER BY 8534C OCTAL ROUNDING INSTEAD OF TRUNCATION. 8535C 8536C WRITTEN BY - 8537C DAVID HOGBEN, 8538C STATISTICAL ENGINEERING DIVISION, 8539C CENTER FOR COMPUTING AND APPLIED MATHEMATICS, 8540C A337 ADMINISTRATION BUILDING, 8541C NATIONAL INSTITUTE OF STANDARDS AND TECHNOLOGY, 8542C GAITHERSBURG, MD 20899 8543C TELEPHONE 301-975-2845 8544C ORIGINAL VERSION - AUGUST, 1969. 8545C CURRENT VERSION - FEBRUARY, 1990. 8546C 8547C ================================================================== 8548C 8549C *** SPECIFICATION STATEMENTS *** 8550C 8551 REAL Y 8552C 8553 DOUBLE PRECISION X 8554 DOUBLE PRECISION XX, D 8555C 8556C ================================================================== 8557C 8558 DATA RPIFY /1.0E38/ 8559 DATA RMIFY /-1.0E37/ 8560C 8561 XX = X 8562 IF (XX.GT.DBLE(RPIFY)) XX = RPIFY 8563 IF (XX.LT.DBLE(RMIFY)) XX = RMIFY 8564C 8565 Y = XX 8566 D = Y 8567 FDPCON = XX + (XX-D) 8568C 8569 RETURN 8570C 8571C ================================================================== 8572C 8573 END 8574*FDSQRT 8575 DOUBLE PRECISION FUNCTION FDSQRT (X) 8576C 8577C ** NBS OMNITAB 1980 VERSION 6.01 1/ 1/81. FDSQRT V 7.00 2/21/90. ** 8578C 8579C ================================================================== 8580C 8581C *** GENERAL COMMENTS *** 8582C 8583C THIS FUNCTION COMPUTES THE DOUBLE PRECISION SQUARE ROOT OF X. 8584C 8585C IF THE ARGUMENT, X, IS LESS THAN ZERO, THE FUNCTION VALUE IS SET 8586C EQUAL TO ZERO AND AN ARITHMETIC FAULT MESSAGE IS PRINTED. 8587C 8588C ================================================================== 8589C 8590C *** SPECIFICATION STATEMENTS *** 8591C 8592 DOUBLE PRECISION DZERO 8593 DOUBLE PRECISION X, DSQRT 8594C 8595 INCLUDE 'DPCOP2.INC' 8596C 8597 DATA DZERO /0.0D0/ 8598C 8599C ================================================================== 8600C 8601CCCCC IF (X-DZERO) 20,30,10 8602 FDSQRT = DZERO 8603 IF (X-DZERO.LT.0.0D0)THEN 8604CCCCC CALL ERROR (101) 8605 WRITE(ICOUT,999) 8606 999 FORMAT(1X) 8607 CALL DPWRST('XXX','BUG ') 8608 WRITE(ICOUT,101) 8609 CALL DPWRST('XXX','BUG ') 8610 ELSEIF (X-DZERO.GT.0.0D0)THEN 8611 FDSQRT = DSQRT (X) 8612 ENDIF 8613 101 FORMAT('***** ERROR FROM FDSQRT: ATTEMPT TO TAKE SQUARE ROOT OF ', 8614 1 'NEGATIVE NUMBER.') 8615C 8616 RETURN 8617C 8618C ================================================================== 8619C 8620 END 8621*FLOG10 8622 REAL FUNCTION FLOG10 (X) 8623C 8624C ** NBS OMNITAB 1980 VERSION 6.01 1/ 1/81. FLOG10 V 7.00 2/21/90. ** 8625C 8626C ================================================================== 8627C 8628C *** GENERAL COMMENTS *** 8629C 8630C PROGRAM UNIT ... 8631C COMPUTES LOG TO BASE 10 OF X USING LIBRARY FUNCTION LOG10, 8632C IF X IS POSITIVE, OR 8633C CALLS ERROR (101) AND SETS FUNCTION VALUE EQUAL TO ZERO, 8634C IF X IS NONPOSITIVE. 8635C 8636C ================================================================== 8637C 8638C *** SPECIFICATION STATEMENTS *** 8639C 8640 REAL X 8641C 8642 INCLUDE 'DPCOP2.INC' 8643C 8644 DATA RZERO /0.0/ 8645C ================================================================== 8646C 8647 IF (X.GT.RZERO) THEN 8648 FLOG10 = LOG10 (X) 8649 ELSE 8650CCCCC CALL ERROR (101) 8651 WRITE(ICOUT,51) 8652 51 FORMAT('***** ERROR FROM FLOG10: ATTEMPT TO TAKE THE LOG OF ', 8653 1 'A NON-POSITIVE NUMBER') 8654 CALL DPWRST('XXX','BUG ') 8655 FLOG10 = RZERO 8656 ENDIF 8657C 8658C .................................................................. 8659C 8660 RETURN 8661C 8662C ================================================================== 8663C 8664 END 8665*PIVOT 8666 SUBROUTINE PIVOT (XI,KP,N,MD,ND,NL) 8667C 8668C ** NBS OMNITAB 1980 VERSION 6.01 1/ 1/81. PIVOT V 7.00 2/21/90. ** 8669C 8670C ================================================================== 8671C 8672C *** GENERAL COMMENTS *** 8673C 8674C SYMETRIC PIVOT-RETURNS NEGATIVE INVERSE 8675C ONE OF FOUR SUBROUTINES CALLED BY MAIN SUBROUTINE SCREEN FOR 8676C REGRESSIONS BY LEAPS AND BOUNDS 8677C A PROGRAM FOR FINDING THE BEST SUBSET REGRESSIONS 8678C G.M.FURNIVAL AND R.W.WILSON 8679C YALE UNIVERSITY AND U.S. FOREST SERVICE 8680C VERSION 11/11/74 8681C 8682C MODIFIED TO PFORT BY - 8683C DAVID HOGBEN, 8684C STATISTICAL ENGINEERING DIVISION, 8685C CENTER FOR COMPUTING AND APPLIED MATHEMATICS, 8686C A337 ADMINISTRATION BUILDING, 8687C NATIONAL INSTITUTE OF STANDARDS AND TECHNOLOGY, 8688C GAITHERSBURG, MD 20899 8689C TELEPHONE 301-975-2845 8690C ORIGINAL VERSION - SEPTEMBER, 1976. 8691C CURRENT VERSION - FEBRUARY, 1990. 8692C 8693C ================================================================== 8694C 8695C *** SPECIFICATION STATEMENTS *** 8696C 8697 DIMENSION MD(ND,ND) 8698C 8699 REAL XI(NL) 8700 REAL B 8701 REAL FDIV 8702C 8703 DATA RONE /1.0/ 8704C 8705C ================================================================== 8706C 8707 ISUB1 = MD(N,N) 8708 XI(ISUB1) = FDIV (-RONE,XI(ISUB1),IND) 8709 DO 20 I=1,KP 8710 IF (I.EQ.N) GO TO 20 8711 ISUB2 = MD(I,N) 8712 ISUB3 = MD(N,N) 8713 B = XI(ISUB2) * XI(ISUB3) 8714 DO 10 J=I,KP 8715 ISUB4 = MD(I,J) 8716 ISUB5 = MD(J,N) 8717 IF (J.NE.N) XI(ISUB4) = XI(ISUB4) + B*XI(ISUB5) 8718 10 CONTINUE 8719 XI(ISUB2) = B 8720 20 CONTINUE 8721 RETURN 8722C 8723C ================================================================== 8724C 8725 END 8726*RFORMT 8727 SUBROUTINE RFORMT (KTYPE,KDIGIT,X,XVALUE,K1,K2,KW,KD,NALPHA,KE) 8728C 8729C ** NBS OMNITAB 1980 VERSION 6.01 2/25/81. RFORMT V 7.00 2/19/91. ** 8730C 8731C ================================================================== 8732C 8733C *** GENERAL COMMENTS *** 8734C 8735C *** DESCRIPTION *** 8736C 8737C RFORMT IS A GENERAL-PURPOSE PORTABLE FORTRAN SUBROUTINE FOR USE IN 8738C PRINTING REAL NUMBERS. 8739C 8740C IT IS PRIMARILY INTENDED FOR PREPARING REAL NUMBERS TO BE PRINTED 8741C IN READABLE FORM, I.E., WITH A CONSTANT NUMBER OF SIGNIFICANT 8742C DIGITS AND THE DECIMAL POINT IN A CONSTANT POSITION. THIS IS 8743C IS CALLED R FORMAT. IT CAN ALSO BE USED TO PRINT REAL NUMBERS 8744C IN E, F, OR I FORMATS. 8745C 8746C TO USE THE R FORMAT, IT IS NORMALLY NECESSARY TO USE RFORMT IN TWO 8747C STAGES. IN THE FIRST STAGE, WITH ITYPE = 0, NWIDTH AND NDECS 8748C ARE CALCULATED. IN THE SECOND STAGE, NWIDTH AND NDECS ARE USED 8749C TO OBTAIN THE HOLLERITH CHARACTER STRING IN THE VECTOR NALPHA. 8750C 8751C IN STAGE 2, REAL NUMBERS ARE CONVERTED INTO A HOLLERITH STRING AND 8752C STORED IN THE VECTOR NALPHA FOR PRINTING WITH AN NA1 FORMAT. 8753C THE HOLLERITH STRING IS PACKED ONE CHARACTER PER WORD. 8754C 8755C .................................................................. 8756C 8757C *** STAGE 1 ARGUMENTS *** 8758C COMPUTE NWIDTH AND NDECS 8759C 8760C INPUT ARGUMENTS - 8761C 8762C (1) ITYPE = 0 8763C (2) NDIGIT = NUMBER OF SIGNIFICANT DIGITS TO BE USED 8764C (3) X = VECTOR OF REAL NUMBERS DIMENSIONED AT LEAST N1 8765C IN CALLING PROGRAM UNIT 8766C (4) XVALUE = DUMMY ARGUMENT 8767C (5) N1 = LENGTH OF VECTOR X 8768C (6) N2 = MAXIMUM VALUE OF NWIDTH ALLOWED 8769C 8770C OUTPUT ARGUMENTS - 8771C 8772C (7) NWIDTH = WIDTH OF FIELD NEEDED TO PRINT EVERY REAL NUMBER 8773C IN X IN R FORMAT 8774C (8) NDECS = NUMBER OF PLACES AFTER THE DECIMAL POINT NEEDED 8775C TO PRINT NUMBERS IN X IN R FORMAT 8776C (9) NALPHA = DUMMY ARRAY ARGUMENT, WHICH MUST BE 8777C DIMENSIONED IN CALLING PROGRAM UNIT 8778C (10) IFAULT = FAULT INDICATOR, 8779C = 0, IF EVERYTHING IS OK 8780C = 1, IF ITYPE IS NEGATIVE 8781C = 2, IF VALUE OF NDIGIT INVALID 8782C = 3, IF N1 IS NON-POSITIVE 8783C = 4, IF N2 IS LESS THAN NDIGIT+2 8784C = 5, IF CALCULATED VALUE OF NWIDTH EXCEEDS N2. 8785C NWIDTH IS RESET TO N2. 8786C = 6, IF CALCULATED NWIDTH EXCEEDS N2 AND NDIGIT+5 8787C EXCEEDS N2 8788C 8789C .................................................................. 8790C 8791C *** STAGE 2 ARGUMENTS *** 8792C PUT HOLLERITH STRING IN NALPHA 8793C 8794C INPUT ARGUMENTS - 8795C 8796C (1) ITYPE = TYPE OF FORMAT DESIRED, 8797C = 1, R FORMAT, NUMBER ZERO HAS BLANKS AFTER DEC. 8798C POINT, 1PEW.(D-1) FORMAT USED IF NECESSARY 8799C = 2, R FORMAT, ZERO CONVERTED NORMALLY 8800C 1PEW.(D-1) FORMAT USED IF NECESSARY 8801C = 3, R FORMAT, ZERO HAS BLANKS AFTER DEC. POINT, 8802C 0PEW.D FORMAT USED IF NECESSARY 8803C = 4, R FORMAT, ZEROS CONVERTED NORMALLY 8804C 0PEW.D JORMAT USED IF NECESSARY 8805C = 5, 1PEW.D FORMAT 8806C = 6, 0PEW.D FORMAT 8807C = 7, FW.D FORMAT, WITH ROUNDING 8808C = 8, FW.D FORMAT, WITH TRUNCATION 8809C = 9, IW FORMAT, WITH ROUNDING 8810C = 10, IW FORMAT, WITH TRUNCATION 8811C = 11, NWIDTH+N1 BLANKS STORED IN NALPHA 8812C (2) NDIGIT = NUMBER OF SIGNIFICANT DIGITS USED 8813C (3) X = DUMMY ARRAY ARGUMENT, WHICH MUST BE 8814C DIMENSIONED IN CALLING PROGRAM UNIT 8815C (4) XVALUE = REAL NUMBER TO BE CONVERTED 8816C (5) N1 = NUMBER OF BLANKS ADDED TO FIELD IN NALPHA 8817C (6) N2 = 0, NA BLANKS INSERTED ON LEFT (BEGINNING) 8818C = 1, N1 BLANKS ARE CENTERED 8819C (7) NWIDTH = LENGTH OF FIELD (HOLLERITH STRING) EXCLUDING N2 8820C BLANKS 8821C (8) NDECS = NUMBER OF PLACES AFTER THE DECIMAL POINT 8822C 8823C OUTPUT ARGUMENTS - 8824C 8825C (9) NALPHA = HOLLERITH STRING REPRESENTATION OF XVALUE, 8826C OF LENGTH NWIDTH+N1 8827C (10) IFAULT = FAULT INDICATOR, 8828C = 0, IF EVERYTHING IS OK 8829C = 1, IF VALUE OF ITYPE IS NOT VALID 8830C = 2, IF VALUE OF NDIGIT IS NOT VALID 8831C = 3, IF N1 IS NON-POSITIVE 8832C = 7, IF VALUE OF N2 IS NOT ZERO OR ONE 8833C = 8, IF VALUE OF NWIDTH IS NOT VALID 8834C = 9, IF VALUE OF NDECS IS NOT VALID 8835C = 10, IF OVERFLOW OCCURS WITH F OR I FORMATS 8836C = 11, IF R FORMAT FORCED INTO E FORMAT 8837C = 12, IF R FORMAT REQUIRES E FORMAT AND 8838C NWIDTH IS TOO SMALL 8839C = 13, IF R FORMAT REQUIRES E FORMAT AND 8840C NDECS IS TOO SMALL 8841C = 14, IF ITYPE EQUALS 9 OR 10 AND NDECS DOES NOT 8842C EQUAL ZERO. ZERO IS USED FOR IDECS. 8843C 8844C .................................................................. 8845C 8846C *** NOTES *** 8847C 8848C 1. CAUTION. IN STAGE 1 ITYPE MUST EQUAL ZERO OR RFORMT WILL 8849C EXECUTE STAGE 2. 8850C 2. IFAULT = 5, 10, 11 OR 14, INDICATES INFORMATIVE DIAGNOSTIC. 8851C OTHERWISE NON-ZERO VALUES OF IFAULT INDICATE FATAL ERRORS 8852C AND EXIT OCCURS WITHOUT ANY FURTHER CALCULATIONS OR ERROR 8853C CHECKING. 8854C 3. NDIGIT MUST BE GREATER THAN ZERO AND LESS THAN OR EQUAL TO 8855C NSIGD. SEE SECTION ON PORTABILITY BELOW FOR DEFINITION 8856C OF NSIGD. 8857C 4. X AND NALPHA MUST BE DIMENSIONED IN CALLING PROGRAM UNIT. 8858C 5. RFORMT HANDLES REAL NUMBERS BETWEEN 10**(-100) AND 10**100, 8859C EXCLUSIVELY. 8860C 6. WHEN N2 = 1 IN STAGE 2, LARGEST NUMBER OF BLANKS IS ON RIGHT 8861C IF N1 IS ODD. 8862C 7. IN STAGE 1, NWIDTH INCLUDES POSITION FOR SIGN, EVEN 8863C IF ALL NUMBERS ARE POSITIVE. HOWEVER THERE ARE TWO 8864C SPECIAL CASES ... 8865C (A) WHEN ALL X(I) = 0, IN WHICH CASE NWIDTH = 2 8866C AND NDECS = 0. 8867C (B) WHEN ALL X(I) ARE LESS THAN ONE IN ABSOLUTE VALUE 8868C AND AT LEAST ONE X(I) EQUALS ZERO. A POSITION 8869C FOR THE SIGN OF ZERO IS NOT INCLUDED IN NWIDTH. 8870C 8871C 8. WITH R FORMAT, A DECIMAL POINT IS NOT STORED IN NALPHA IF 8872C THE REAL NUMBER XVALUE EXCEEDS 10**NDIGIT. IF NDIGIT=3, 8873C 1.23+03 IS STORED AS 1230 RATHER THAN 1230., TO EMPHASIZE 8874C THAT THE ZERO IS NOT A SIGNIFICANT DIGIT. 8875C 9. RFORMT DOES NO PRINTING. PRINTING OF NALPHA WITH NA1 FORMAT 8876C MUST BE DONE BY THE CALLING PROGRAM UNIT. 8877C 10. WHEN ZERO IS PRINTED WITH R FORMAT, NDECS OVERRIDES NDIGIT. 8878C 11. CAUTION. IF IFAULT IS NOT EQUAL TO ZERO, NALPHA MAY NOT BE 8879C BLANKED OUT. 8880C 12. NALPHA IS UNCHANGED, IF ITYPE EQUALS ZERO. 8881C 8882C .................................................................. 8883C 8884C *** USE OF E, F, AND I FORMATS *** 8885C 8886C 1. 1PEW.D FORMAT IS OBTAINED BY SETTING - 8887C ITYPE = 5 8888C NWIDTH = W = WIDTH OF FIELD 8889C NDIGIT = (D+1) = NUMBER OF DIGITS 8890C 8891C WITH D=6, 12.345678 IS WRITTEN AS 1.234568+01 8892C 8893C 2. 0PEW.D FORMAT IS OBTAINED BY SETTING - 8894C ITYPE = 6 8895C NWIDTH = W = WIDTH OF FIELD 8896C NDIGIT = D = NUMBER OF DIGITS 8897C 8898C WITH D=7, 12.345678 IS WRITTEN AS .1234568+02 8899C 8900C 3. FW.D FORMAT IS OBTAINED BY SETTING - 8901C ITYPE = 7 OR 8 8902C NWIDTH = W = WIDTH OF FIELD 8903C NDECS = D = NUMBER OF PLACES AFTER DECIMAL POINT 8904C 8905C 4. IW FORMAT IS OBTAINED BY SETTING - 8906C ITYPE = 9 OR 10 8907C NWIDTH = W = WIDTH OF FIELD 8908C NDECS = 0 8909C 8910C NOTES - 8911C A. FOR E FORMAT, NDECS MUST BE GREATER THAN OR EQUAL TO ZERO. 8912C NSIGDS=NDECS IS SET EQUAL TO NDIGIT+2 BY RFORMT. 8913C B. WITH EW.D FORMAT, THE LETTER E IS NOT USED AFTER THE 8914C NUMBER AND BEFORE THE SIGNED CHARACTERISTIC. 8915C C. WITH 0PEW.D FORMAT, ZERO IS NOT PUT BEFORE THE DECIMAL 8916C POINT. 8917C D. WITH FW.D FORMAT AND THE ABSOLUTE VALUE OF NUMBER IS LESS 8918C THAN ONE, ZERO IS NOT PUT ON LEFT OF DECIMAL POINT, 8919C UNLESS D = 0. 8920C 8921C .................................................................. 8922C 8923C *** PORTABILITY *** 8924C 8925C RFORMT IS COMPLETELY PORTABLE EXCEPT FOR ONE MACHINE DEPENDENT 8926C CONSTANT, NSIGD, SET IN THE DATA STATEMENT ON LINE RF 320. 8927C 8928C NSIGD IS THE NUMBER OF SIGNIFICANT DECIMAL DIGITS IN THE COMPUTER. 8929C NSIGD = 7, FOR A 32 BIT WORD COMPUTER (IBM) 8930C = 8, FOR A 36 BIT WORD COMPUTER (UNIVAC), VALUE SET 8931C = 10, FOR A 48 BIT WORD COMPUTER (BURROUGHS) 8932C = 13, FOR A 60 BIT WORD COMPUTER (CDC). 8933C 8934C CAUTION. NSIGD MUST BE SMALL ENOUGH SO THAT 10**(NSIGD+1) IS A 8935C VALID MACHINE INTEGER. (THIS EXPLAINS WHY NSIGD EQUALS 13 AND 8936C NOT 14 FOR A 60 BIT WORD COMPUTER.) 8937C 8938C SOURCE LANGUAGE IS PFORT (A PORTABLE SUBSET OF ANS FORTRAN). 8939C 8940C FORTRAN LIBRARY FUNCTION USED IS LOG10, 8941C WHICH APPEARS ON LINES RF 389, RF 391, AND RF 612. 8942C 8943C STORAGE USED IS 1495 36 BIT WORDS WITH UNIVAC 1108 EXEC 8 COMPUTER 8944C 8945C .................................................................. 8946C 8947C *** STATIC PROFILE *** 8948C 8949C I/O STATEMENTS 0 8950C NONEXECUTABLE STATEMENTS 20 8951C EXECUTABLE STATEMENTS 244 8952C UNCONDITIONAL 160 8953C CONDITIONAL 84 8954C COMMENT STATEMENTS 532 8955C -------------------------------- 8956C TOTAL NUMBER OF STATEMENTS 796 8957C -------------------------------- 8958C CONTINUATION LINES 6 8959C -------------------------------- 8960C NUMBER OF LINES OF CODE 802 8961C 8962C .................................................................. 8963C 8964C *** REFERENCE *** 8965C 8966C HOGBEN, DAVID (1977). A FLEXIBLE PORTABLE FORTRAN PROGRAM UNIT 8967C FOR READABLE PRINTING OF REAL NUMBERS. IN PREPARATION. 8968C 8969C .................................................................. 8970C 8971C WRITTEN BY - 8972C DAVID HOGBEN, 8973C STATISTICAL ENGINEERING DIVISION, 8974C CENTER FOR COMPUTING AND APPLIED MATHEMATICS, 8975C A337 ADMINISTRATION BUILDING, 8976C NATIONAL INSTITUTE OF STANDARDS AND TECHNOLOGY, 8977C GAITHERSBURG, MD 20899 8978C TELEPHONE 301-975-2845 8979C ORIGINAL VERSION - APRIL, 1969. 8980C CURRENT VERSION - FEBRUARY, 1991. 8981C 8982C ================================================================== 8983C 8984C *** SPECIFICATION STATEMENTS *** 8985C 8986 DIMENSION NALPHA(*) 8987C 8988C ================================================================== 8989C 8990C *** TYPE STATEMENTS *** 8991C 8992 REAL X(*) 8993 REAL XVALUE 8994 REAL ABSMAX, ABSMIN, ABSX, ABSXVA, X1, X2 8995 REAL FLOG10 8996C 8997C...................................................................... 8998C 8999 DOUBLE PRECISION Z, ZLOWER, ZUPPER 9000 DOUBLE PRECISION DFIVE, DTEN 9001 DOUBLE PRECISION FDDIV 9002C 9003C .................................................................. 9004C 9005 CHARACTER*1 LA(74) 9006 CHARACTER NALPHA*1 9007C 9008CCCCC INCLUDE 'DPCOHO.INC' 9009C 9010C ================================================================== 9011C 9012C *** DATA INITIALIZATION STATEMENTS *** 9013C 9014 DATA DFIVE, DTEN / 5.0D0, 10.0D0 / 9015C 9016 DATA ITEN /10/ 9017 DATA IFIVE /5/ 9018 DATA IFOUR /4/ 9019 DATA ITHRE /3/ 9020 DATA ITWO /2/ 9021 DATA IONE /1/ 9022 DATA IZERO /0/ 9023C 9024 DATA RHALF /0.5/ 9025 DATA RONE /1.0/ 9026 DATA RZERO /0.0/ 9027C 9028CCCCC DATA ISIGD /7/ 9029C 9030C LA( 1) = 0 LA( 2) = 1 LA( 3) = 2 LA( 4) = 3 LA( 5) = 4 9031C LA( 6) = 5 LA( 7) = 6 LA( 8) = 7 LA( 9) = 8 LA(10) = 9 9032C LA(11) = A LA(12) = B LA(13) = C LA(14) = D LA(15) = E 9033C LA(16) = F LA(17) = G LA(18) = H LA(19) = I LA(20) = J 9034C LA(21) = K LA(22) = L LA(23) = M LA(24) = N LA(25) = O 9035C LA(26) = P LA(27) = Q LA(28) = R LA(29) = S LA(30) = T 9036C LA(31) = U LA(32) = V LA(33) = W LA(34) = X LA(35) = Y 9037C LA(36) = Z LA(37) = / LA(38) = . LA(39) = - LA(40) = + 9038C LA(41) = * LA(42) = ( LA(43) = ) LA(44) = , LA(45) = 9039C LA(46) = = LA(47) = $ LA(48) = ' LA(49) = a LA(50) = b 9040C LA(51) = c LA(52) = d LA(53) = e LA(54) = f LA(55) = g 9041C LA(56) = h LA(57) = i LA(58) = j LA(59) = k LA(60) = l 9042C LA(61) = m LA(62) = n LA(63) = o LA(64) = p LA(65) = q 9043C LA(66) = r LA(67) = s LA(68) = t LA(69) = u LA(70) = v 9044C LA(71) = w LA(72) = x LA(73) = y LA(74) = z 9045C 9046 DATA LA( 1), LA( 2), LA( 3), LA( 4), LA( 5), 9047 1 LA( 6), LA( 7), LA( 8), LA( 9), LA(10)/ 9048 2 '0', '1', '2', '3', '4', 9049 3 '5', '6', '7', '8', '9'/ 9050C 9051 DATA LA(11), LA(12), LA(13), LA(14), LA(15), 9052 1 LA(16), LA(17), LA(18), LA(19), LA(20)/ 9053 2 'A', 'B', 'C', 'D', 'E', 9054 3 'F', 'G', 'H', 'I', 'J'/ 9055C 9056 DATA LA(21), LA(22), LA(23), LA(24), LA(25), 9057 1 LA(26), LA(27), LA(28), LA(29), LA(30)/ 9058 2 'K', 'L', 'M', 'N', 'O', 9059 3 'P', 'Q', 'R', 'S', 'T'/ 9060C 9061 DATA LA(31), LA(32), LA(33), LA(34), LA(35), 9062 1 LA(36), LA(37), LA(38), LA(39), LA(40)/ 9063 2 'U', 'V', 'W', 'X', 'Y', 9064 3 'Z', '/', '.', '-', '+'/ 9065C 9066 DATA LA(41), LA(42), LA(43), LA(44), LA(45), 9067 1 LA(46), LA(47), LA(48), LA(49), LA(50)/ 9068 2 '*', '(', ')', ',', ' ', 9069 3 '=', '$', '''', 'a', 'b'/ 9070C 9071 DATA LA(51), LA(52), LA(53), LA(54), LA(55), 9072 1 LA(56), LA(57), LA(58), LA(59), LA(60)/ 9073 2 'c', 'd', 'e', 'f', 'g', 9074 3 'h', 'i', 'j', 'k', 'l'/ 9075C 9076 DATA LA(61), LA(62), LA(63), LA(64), LA(65), 9077 1 LA(66), LA(67), LA(68), LA(69), LA(70)/ 9078 2 'm', 'n', 'o', 'p', 'q', 9079 3 'r', 's', 't', 'u', 'v'/ 9080C 9081 DATA LA(71), LA(72), LA(73), LA(74)/ 9082 2 'w', 'x', 'y', 'z'/ 9083C 9084C ================================================================== 9085C 9086CCCCC ISIGD NEEDS TO BE 6 ON MICROSOFT/COMPAQ PC COMPILER. 9087CCCCC ALSO NEDS TO BE 6 ON SGI. 9088CCCCC TO BE SAFE, JUST SET TO 6, WHICH SHOULD WORK ON ALL 32-BIT 9089CCCCC HOSTS. 9090C 9091 LTEMP=0 9092 ISIGD = 6 9093CCCCC IF(ICOMPI.EQ.'MS-F')ISIGD = 6 9094CCCCC IF(ICOMPI.EQ.'LAHE')ISIGD = 6 9095C 9096C ADAPTIONS FOR OMNITAB. 9097C 9098C NW IS USED INSTEAD OF NWIDTH 9099C ND IS USED INSTEAD OF NDECS 9100C IE IS USED INSTEAD OF IFAULT 9101C 9102 ITYPE = KTYPE 9103 NDIGIT = KDIGIT 9104 N1 = K1 9105 N2 = K2 9106 NW = KW 9107 ND = KD 9108 IE = KE 9109C 9110C GENERAL ERROR CHECKING. 9111C 9112 ZLOWER = ITEN ** NDIGIT 9113 ZUPPER = DTEN * ZLOWER 9114 IE = IZERO 9115 IF (ITYPE.GE.IZERO) GO TO 10 9116 IE = IONE 9117 GO TO 390 9118C 9119C .................................................................. 9120C 9121 10 IF (NDIGIT.GT.IZERO .AND. NDIGIT.LE.ISIGD) GO TO 20 9122 IE = ITWO 9123 GO TO 390 9124C 9125C .................................................................. 9126C 9127 20 IF (ITYPE.GT.IZERO) GO TO 80 9128C 9129C ================================================================== 9130C 9131C *** STAGE 1 *** 9132C COMPUTE NWIDTH AND NDECS 9133C 9134C STAGE 1 ERROR CHECKING 9135C 9136 IF (N1.GT.IZERO) GO TO 30 9137 IE = ITHRE 9138 GO TO 390 9139C 9140C .................................................................. 9141C 9142C N2 MUST BE LARGE ENOUGH FOR NDIGIT, DECIMAL POINT, AND SIGN. 9143C 9144 30 IF (N2.GE.NDIGIT+ITWO) GO TO 40 9145 IE = IFOUR 9146 GO TO 390 9147C 9148C .................................................................. 9149C 9150C (1) COMPUTE MMIN, CHARACTERISTIC OF ABSMIN = MIN ABS VALUE X(I) 9151C AND COMPUTE MMAX, CHARACTERISTIC OF ABSMAX = MAX ABS X(I). 9152C 9153 40 ABSX = ABS (X(1)) 9154 IF (ABSX.LE.RZERO) ABSX = RONE 9155 ABSMIN = ABSX 9156 ABSMAX = ABSX 9157C 9158 K = IZERO 9159C 9160C K IS USED IN TWO SPECIAL CASES ... WHEN 9161C (A) ALL X(I) EQUAL ZERO, AND 9162C (B) ABS (X(I)) IS LESS THAN 1.0, FOR ALL I, AND SOME X(I)=0.0. 9163C 9164 DO 50 I=1,N1 9165 ABSX = ABS (X(I)) 9166 IF (ABSX.GE.RONE) K = IONE 9167 IF (ABSX.LE.RZERO) ABSX = RONE 9168 IF (ABSX.LT.ABSMIN) ABSMIN = ABSX 9169 IF (ABSX.GT.ABSMAX) ABSMAX = ABSX 9170 50 CONTINUE 9171C 9172 MMIN = INT(FLOG10 (ABSMIN)) 9173 IF (ABSMIN.LT.RONE) MMIN = MMIN - IONE 9174 MMAX = INT(FLOG10 (ABSMAX)) 9175 IF (ABSMAX.LT.RONE) MMAX = MMAX - IONE 9176C 9177C ADJUST FOR POSSIBLE INCORRECT VALUES OF MMIN AND MMAX DUE TO 9178C ERROR IN LOG10 CALCULATION. 9179C 9180 Z = ABSMIN 9181 Z = Z * DTEN ** (NDIGIT-MMIN) + DFIVE 9182C 9183 IF (Z.LT.ZLOWER) MMIN = MMIN - IONE 9184 IF (Z.GE.ZUPPER) MMIN = MMIN + IONE 9185C 9186 Z = ABSMAX 9187 Z = Z * DTEN ** (NDIGIT-MMAX) + DFIVE 9188C 9189 IF (Z.LT.ZLOWER) MMAX = MMAX - IONE 9190 IF (Z.GE.ZUPPER) MMAX = MMAX + IONE 9191C 9192C .................................................................. 9193C 9194C (2) USE MMIN AND MMAX TO COMPUTE NWIDTH AND NDECS. 9195C 9196 ND = NDIGIT - MMIN - IONE 9197 ND = MAX0 (IZERO,ND) 9198 NW = MMAX + ITHRE + ND 9199 IF (MMAX.LT.IZERO) NW = ND + ITWO 9200 IF (K.EQ.IONE) GO TO 60 9201C 9202C ADJUST FOR SPECIAL CASE (B) DESCRIBED ON LINE RF 368 9203C 9204 IF (ABSMIN.LT.RONE .AND. ABSMAX.GE.RONE) NW = NW - IONE 9205C 9206C ADJUST FOR SPECIAL CASE (A) DESCRIBED ON LINE RF 367 9207C 9208 IF (ABSMIN.LT.RONE .OR. ABSMAX.LT.RONE) GO TO 60 9209 NW = ITWO 9210 ND = IZERO 9211C 9212 60 IF (NW.LE.N2) GO TO 390 9213C 9214C NWIDTH IS TOO LARGE AND HAS TO BE ADJUSTED. 9215C 9216 IE = IFIVE 9217 IF (NDIGIT+IFIVE.LE.N2) GO TO 70 9218 IE = 6 9219 GO TO 390 9220C 9221C .................................................................. 9222C 9223C 9224C NDIGIT+2 = (NDIGIT-1) + (+XX), FOR EXPONENT OF FLOATING-POINT NO. 9225C 9226 70 ND = MAX0 (ND,NDIGIT+ITWO) 9227C 9228C N2-3 = N2 - (SIGN+DIGIT+DECIMAL POINT). 9229C 9230 ND = MIN0 (ND,N2-ITHRE) 9231 NW = N2 9232 GO TO 390 9233C 9234C ================================================================== 9235C 9236C ***** STAGE 2 ***** 9237C PUT HOLLERITH STRING IN NALPHA 9238C 9239 80 ABSXVA = ABS (XVALUE) 9240C 9241C STAGE 2 ERROR CHECKING 9242C 9243 IF (ITYPE.LT.12) GO TO 90 9244 IE = IONE 9245 GO TO 390 9246C 9247C .................................................................. 9248C 9249 90 IF (N1.GE.IZERO) GO TO 100 9250 IE = ITHRE 9251 GO TO 390 9252C 9253C .................................................................. 9254C 9255 100 IF (N2.EQ.IZERO .OR. N2.EQ.IONE) GO TO 110 9256 IE = 7 9257 GO TO 390 9258C 9259C .................................................................. 9260C 9261 110 IF (ITYPE.LT.9 .AND. NW.LT.ND+ITWO) GO TO 120 9262 IF (NW.LE.IZERO) GO TO 120 9263 IF (ITYPE.GT.6) GO TO 130 9264 IF (ABSXVA.LE.RZERO .AND. NW.GE.ITWO .AND. ITYPE.LE.IFOUR) 9265 1 GO TO 130 9266C 9267C CHECK WHETHER NWIDTH IS VALID. 9268C 9269 IF (NW.LT.NDIGIT+ITWO) GO TO 120 9270 IF (ITYPE.LT.IFIVE) GO TO 130 9271 IF (NW.GE.NDIGIT+IFIVE) GO TO 130 9272 120 IE = 8 9273 GO TO 390 9274C 9275C .................................................................. 9276C 9277 130 IF (ND.GE.IZERO) GO TO 140 9278 IE = 9 9279 GO TO 390 9280C 9281C .................................................................. 9282C 9283C VARIABLES USED TO DEFINE FIELD WIDTH FOR R FORMAT 9284C 9285C ----------------------------- 9286C I NWIDTH I 9287C ---------------------------------------------- 9288C I NBLANK I NDIFF I NDECS I I 9289C ---------------------------------------------- 9290C I NPONE I 9291C ---------------------------------------- 9292C I LTOTAL I 9293C ---------------------------------------------- 9294C I NTOTAL = NWIDTH + N1 I 9295C ---------------------------------------------- 9296C 9297C .................................................................. 9298C 9299C (1) INITIALIZATION. 9300C 9301C CLEAR OUT NALPHA WITH BLANKS. 9302C 9303 140 NTOTAL = NW + N1 9304 DO 150 I=1,NTOTAL 9305 NALPHA(I) = LA(45) 9306 150 CONTINUE 9307C 9308 IF (ITYPE.EQ.11) GO TO 390 9309C 9310C IF NECESSARY, CENTER BLANKS WITH LARGEST NUMBER ON RIGHT IF N1 ODD 9311C 9312 CALL IDIV (N1+IONE,ITWO,IND,NJUNK) 9313 NBLANK = N1 - NJUNK * N2 9314C 9315 MF = IZERO 9316 MREAL = IZERO 9317 IDECS = ND 9318 IF (ITYPE.LT.9 .OR. IDECS.EQ.IZERO) GO TO 160 9319 IDECS = IZERO 9320 IE = 14 9321 160 IF (ITYPE.EQ.IFIVE .OR. ITYPE.EQ.6) IDECS = NDIGIT + ITWO 9322C 9323C THE NEXT THREE STATEMENTS ARE USED TO SWITCH FROM F TO I FORMAT 9324C 9325 NSIGDS = NDIGIT 9326 IWIDTH = NW 9327 IF (ITYPE.EQ.9 .OR. ITYPE.EQ.ITEN) IWIDTH = IWIDTH + IONE 9328 NDIFF = IWIDTH - IDECS 9329 LTOTAL = IWIDTH + NBLANK 9330 NPONE = NDIFF + NBLANK 9331C 9332 IF (ABSXVA.GE.RONE) GO TO 200 9333 IF (ITYPE.LT.9 .AND. ABSXVA.GT.RZERO) GO TO 200 9334C 9335C .................................................................. 9336C 9337C (2) XVALUE = 0. IS SPECIAL CASE. 9338C 9339 IF (ITYPE.LT.9) GO TO 180 9340C 9341C INTEGER FORMAT 9342C 9343 IF (ABSXVA.LE.RHALF .OR. ITYPE.EQ.ITEN) GO TO 170 9344 NALPHA(LTOTAL-1) = LA(2) 9345 IF (XVALUE.LT.RZERO) NALPHA(LTOTAL-2) = LA(39) 9346 GO TO 390 9347C 9348C .................................................................. 9349C 9350 170 NALPHA(LTOTAL-1) = LA(1) 9351 GO TO 390 9352C 9353C .................................................................. 9354C 9355C R FORMAT WITH ZERO STORED AS 0. 9356C 9357 180 NALPHA(NPONE ) = LA(38) 9358 NALPHA(NPONE-1) = LA(1) 9359 IF (ITYPE.EQ.IONE .OR. ITYPE.EQ.ITHRE) GO TO 390 9360 IF (ITYPE.EQ.ITWO .AND. IDECS.EQ.IZERO) GO TO 390 9361 IF (ITYPE.EQ.IFOUR .AND. IDECS.EQ.IZERO) GO TO 390 9362C 9363C FIXED 0 9364C 9365 IF (ITYPE.EQ.7 .AND. ND.EQ.IZERO) GO TO 390 9366 IF (ITYPE.EQ.8 .AND. ND.EQ.IZERO) GO TO 390 9367C 9368 IF (ITYPE.EQ.7 .OR. ITYPE.EQ.8) NALPHA(NPONE-1) = LA(45) 9369C 9370C ALL OTHER CASES 9371C 9372 IBEG = NPONE + IONE 9373 IEND = NPONE + IDECS 9374 DO 190 I=IBEG,IEND 9375 NALPHA(I) = LA(1) 9376 190 CONTINUE 9377C 9378C .................................................................. 9379C 9380 IF (ITYPE.NE.IFIVE .AND. ITYPE.NE.6) GO TO 390 9381C 9382C FLOATING 9383C 9384 NALPHA(LTOTAL-2) = LA(40) 9385 IF (ITYPE.EQ.IFIVE) GO TO 390 9386 NALPHA(NPONE ) = LA(1) 9387 NALPHA(NPONE-1) = LA(38) 9388 GO TO 390 9389C 9390C .................................................................. 9391C 9392C (3) COMPUTE M = CHARACTERISTIC OF ABSXVA = ABS(XVALUE) AND 9393C LL = (NSIGDS+1) INTEGER REPRESENTATION OF ABSXVA. 9394C FOR XVALUE = -12.345678, M=1 AND LL=123456784, AN 9395C ADDITIONAL DIGIT IN LL IS USED TO AVOID ROUNDOFF ERROR. 9396C 9397 200 M = INT(FLOG10 (ABSXVA)) 9398 IF (ABSXVA.LT.RONE) M = M - IONE 9399 Z = ABSXVA 9400 Z = Z * DTEN**(NSIGDS-M) 9401C 9402C IF M IS COMPUTED ACCURATELY, ZLOWER .LE. Z .LT. ZUPPER 9403C 9404 IF (Z.GE.ZLOWER) GO TO 210 9405C 9406C Z IS LESS THAN ZLOWER BECAUSE M IS ONE TOO LARGE. 9407C ADJUST BY SUBTRACTING 1 FROM M AND MULTIPLYING Z BY 10. 9408C 9409 M = M - IONE 9410 Z = DTEN * Z 9411 GO TO 220 9412C 9413 210 IF (Z.LT.ZUPPER) GO TO 220 9414C 9415C Z IS GREATER THAN OR EQUAL TO ZUPPER BECAUSE M IS ONE TOO SMALL. 9416C ADJUST BY ADDING 1 TO M AND DIVIDING Z BY 10. 9417C 9418 M = M + IONE 9419 Z = FDDIV (Z,DTEN,IND) 9420C 9421 220 X1 = Z 9422 LL1 = INT(X1) 9423 X2 = Z - DBLE (X1) 9424 LL2 = INT(X2) 9425 LL = LL1 + LL2 + IFIVE 9426 IF (LL.LT.ITEN**(NSIGDS+IONE)) GO TO 230 9427C 9428C MAKE ADJUSTMENT WHEN LL IS TOO LARGE. 9429C 9430 M = M + IONE 9431 CALL IDIV (LL,ITEN,IND,LL) 9432 GO TO 240 9433 230 IF (LL.GE.ITEN**NSIGDS) GO TO 240 9434C 9435C MAKE ADJUSTMENT WHEN LL IS TOO SMALL. 9436C 9437 M = M - IONE 9438 LL = ITEN * LL 9439 240 IF (ITYPE.EQ.8 .OR. ITYPE.EQ.ITEN) LL = LL - IFIVE 9440 IF (ITYPE.LT.IFIVE) GO TO 290 9441 IF (ITYPE.EQ.IFIVE .OR. ITYPE.EQ.6) GO TO 300 9442C 9443C .................................................................. 9444C 9445C (4) FIXED AND INTEGER. 9446C 9447C CHECK FOR OVERFLOW. 9448C 9449 IF (M.GT.NDIFF-ITWO) GO TO 270 9450 IF (M.EQ.NDIFF-ITWO .AND. XVALUE.LT.RZERO) GO TO 270 9451C 9452C ADJUST NUMBER OF DIGITS (NSIGDS) AND LL. 9453C 9454 NSIGDS = MIN0 (NDIGIT,IDECS+M+IONE) 9455 NSIGDS = MAX0 (IZERO,NSIGDS) 9456 IF (ITYPE.EQ.7 .OR. ITYPE.EQ.9) LL = LL - IFIVE 9457 CALL IDIV (LL,ITEN**(NDIGIT-NSIGDS),IND,LLTEMP) 9458 LTEMP=LL 9459 IF (ITYPE.EQ.7 .OR. ITYPE.EQ.9) LL = LL + IFIVE 9460 IF (LL.LT.ITEN**(NSIGDS+IONE)) GO TO 250 9461C 9462C ADJUST FOR XVALUE ROUNDED TO ONE MORE DIGIT. 9463C 9464 M = M + IONE 9465 NSIGDS = MIN0 (NDIGIT,IDECS+M+IONE) 9466 NSIGDS = MAX0 (IZERO,NSIGDS) 9467C 9468C CHECK FOR OVERFLOW CAUSED BY ROUNDING TO ONE MORE DIGIT. 9469C 9470 IF (M.GT.NDIFF-ITWO) GO TO 270 9471 IF (M.EQ.NDIFF-ITWO .AND. XVALUE.LT.RZERO) GO TO 270 9472C 9473C CHECK FOR UNDERFLOW. 9474C 9475 250 IF (NSIGDS.GT.IZERO) GO TO 310 9476C 9477C ADJUST FOR UNDERFLOW. XVALUE ROUNDED TO IDECS EQUALS ZERO. 9478C 9479 IF (IDECS.EQ.IZERO) NALPHA(NPONE-1) = LA(1) 9480C 9481 DO 260 I=NPONE,LTOTAL 9482 NALPHA(I) = LA(1) 9483 260 CONTINUE 9484C 9485 NALPHA(NPONE) = LA(38) 9486 GO TO 390 9487C 9488C .................................................................. 9489C 9490C PUT IN ASTERISKS WHEN OVERFLOW OCCURS. 9491C 9492 270 IE = ITEN 9493 DO 280 I=1,NW 9494 ISUBSC = I + NBLANK 9495 NALPHA(ISUBSC) = LA(41) 9496 280 CONTINUE 9497 GO TO 390 9498C 9499C .................................................................. 9500C 9501C (5) CHECK WHETHER R FORMAT IS FORCED INTO E FORMAT. 9502C 9503 290 IF (M.GE.NSIGDS-IONE-IDECS .AND. M.LT.NDIFF-ITWO) GO TO 310 9504 IF (M.EQ.NDIFF-ITWO .AND. XVALUE.GT.RZERO) GO TO 310 9505 IE = 11 9506 IF (NW.GE.NDIGIT+IFIVE .AND. ND.GE.NDIGIT+ITWO) GO TO 300 9507 IE = 13 9508 IF (NW.GE.NDIGIT+IFIVE) GO TO 390 9509 IE = 12 9510 GO TO 390 9511C 9512C .................................................................. 9513C 9514C (6) FLOATING. 9515C 9516 300 MREAL = M 9517 M = IZERO 9518 MF = IONE 9519C 9520C .................................................................. 9521C 9522C (7) STORE REPRESENTATION IN NALPHA. 9523C 9524 310 IF (M.LT.NSIGDS .AND. ITYPE.LT.9) NALPHA(NPONE) = LA(38) 9525 NINT = NPONE - IONE - M 9526 IF (M.LT.IZERO) NINT = NINT + IONE 9527 NEND = NINT + NSIGDS - IONE 9528 IF (M.GE.IZERO .AND. M.LT.NSIGDS-IONE) NEND = NEND + IONE 9529 DO 320 J=NINT,NEND 9530 I = NEND + NINT - J 9531 IF (I.EQ.NPONE) GO TO 320 9532 CALL IDIV (LL,ITEN,IND,LLTEMP) 9533 LL = LTEMP 9534 NN = MOD (LL,ITEN) 9535 NALPHA(I) = LA(NN+1) 9536 320 CONTINUE 9537C 9538 IF (MF.EQ.IZERO) GO TO 340 9539C 9540C .................................................................. 9541C 9542C (8) PUT IN EXPONENT FOR FLOATING POINT NUMBER. 9543C 9544 IF (ITYPE.EQ.IONE .OR. ITYPE.EQ.ITWO .OR. ITYPE.EQ.IFIVE) GOTO 330 9545C 9546C CHANGE FROM 1PE TO 0PE 9547C 9548 NALPHA(NINT+1) = NALPHA(NINT) 9549 NALPHA(NINT ) = LA(38) 9550 MREAL = MREAL + IONE 9551C 9552 330 IF (MREAL.LT.IZERO) NALPHA(NEND+1) = LA(39) 9553 IF (MREAL.GE.IZERO) NALPHA(NEND+1) = LA(40) 9554 MREALA = IABS(MREAL) 9555 CALL IDIV (MREALA,ITEN,IND,M1) 9556 M2 = MOD (MREALA,ITEN) 9557 NALPHA(NEND+2) = LA(M1+1) 9558 NALPHA(NEND+3) = LA(M2+1) 9559C 9560C .................................................................. 9561C 9562C (9) PUT IN MINUS SIGN IF XVALUE LESS THAN ZERO. 9563C 9564 340 IF (XVALUE.GE.RZERO) GO TO 350 9565 IF (M.GE.IZERO) NALPHA(NINT-1) = LA(39) 9566 IF (M.LT.IZERO) NALPHA(NPONE-1) = LA(39) 9567 350 IF (M.GE.(-IONE)) GO TO 370 9568C 9569C PUT ZEROS AFTER DECIMAL POINT FOR ABSXVA LESS THAN 0.1 9570C 9571 IBEG = NPONE + IONE 9572 IEND = NINT - IONE 9573 DO 360 I=IBEG,IEND 9574 NALPHA(I) = LA(1) 9575 360 CONTINUE 9576 GO TO 390 9577C 9578C .................................................................. 9579C 9580C (10) PUT IN NON-SIGNIFICANT ZEROS FOR LARGE INTEGERS. 9581C 9582 370 IF (M.LT.NSIGDS .OR. MF.NE.IZERO) GO TO 390 9583 IBEG = NINT + NSIGDS 9584 IEND = NPONE - IONE 9585 DO 380 I=IBEG,IEND 9586 NALPHA(I) = LA(1) 9587 380 CONTINUE 9588C 9589C .................................................................. 9590C 9591 390 KW = NW 9592 KD = ND 9593 KE = IE 9594 IF (IE.EQ.IZERO .OR. IE.EQ.IFIVE .OR. IE.EQ.6 .OR. IE.EQ.ITEN 9595 1 .OR. IE.EQ.11 .OR. IE.GE.14) RETURN 9596CCCCC CALL ERROR (259) 9597 RETURN 9598C 9599C ================================================================== 9600C 9601 END 9602*SCREEN 9603 SUBROUTINE SCREEN(RR,KX,NR,NDEF,IBIT,MBST,INTCPT,A,NS, 9604 1 ICAPSW,ICAPTY,IFORSW, 9605 1 IBUGA3,ISUBRO,IERROR) 9606C 9607C ** NBS OMNITAB 1980 VERSION 6.01 1/ 1/81. SCREEN V 7.00 4/21/92. ** 9608C 9609C ================================================================== 9610C 9611C *** GENERAL COMMENTS *** 9612C 9613C **************************************************************** * 9614C * 9615C REGRESSIONS BY LEAPS AND BOUNDS * 9616C A PROGRAM FOR FINDING THE BEST SUBSET REGRESSIONS * 9617C G.M.FURNIVAL AND R.W.WILSON * 9618C YALE UNIVERSITY AND U.S. FOREST SERVICE * 9619C VERSION 11/11/74 * 9620C * 9621C CALL SCREEN(RR,KX,NR,NDEF,IBIT,MBST) * 9622C * 9623C RR = UPPER TRIANGULAR PORTION OF (KX+1)*(KX+1) CORRELATION OR * 9624C PRODUCT MATRIX. VARIABLE KX+1 IS THE DEPENDENT VARIABLE. * 9625C KX = NUMBER OF INDEPENDENT VARIABLES (3.LE.KX.LE.28) * 9626C NR = DIMENSION OF RR (NR.GT.KX) * 9627C NDEF = DEGREES OF FREEDOM FOR RR (NDEF.GT.KX) * 9628C IBIT = SELECTION CRITERION CODE (1=R**2,2=ADJUSTED R**2,3=CP) * 9629C MBST = NUMBER OF BEST REGRESSIONS DESIRED (1.LE.MBST.LE.10) * 9630C * 9631C MBST BEST REGRESSIONS FOR EACH SIZE SUBSET WHEN IBIT.EQ.1 * 9632C MBST BEST REGRESSIONS IN TOTAL WHEN IBIT.GT.1 * 9633C * 9634C **************************************************************** * 9635C 9636C ARRAY STORAGE REQUIRED FOR K=KX INDPENDENT VARIABLES AND M = K+1. 9637C 2*NL FOR XI AND XN, WHERE NL = M(M+1)(M+2)/6 9638C 4M**2 FOR ILI, ILM, MD AND NC 9639C 2*(11M) FOR CL AND RM 9640C 12M FOR CI, CN, CO, ID, IPI, IPN, NI, NN, TOLL, YI, YN AND ZC 9641C 9642C TOTAL STORAGE EQUALS 2M(M+1)(M+2)/6 + 4M**2 +22M + 12M 9643C = (M**3 + 15*M**2 + 104*M)/3 9644C 9645C *** ARRAY STORAGE EQUIVALENCE TO A(.) *** 9646C 9647C ARRAY SIZE START 9648C 9649C XI NL 1 9650C XN NL NL+1 9651C ............................................. 9652C ILI M**2 2*NL+ 1 9653C ILN M**2 2*NL+ M**2+1 9654C MD M**2 2*NL+2*M**2+1 9655C NC M**2 2*NL+3*M**2+1 9656C ............................................. 9657C CL 11*M 2*NL+4*M**2+ 1 9658C RM 11*M 2*NL+4*M**2+11*M+1 9659C ............................................. 9660C CI M 2*NL+4*M**2+22*M+1 9661C CN M 2*NL+4*M**2+23*M+1 9662C CO M 2*NL+4*M**2+24*M+1 9663C ID M 2*NL+4*M**2+25*M+1 9664C IPI M 2*NL+4*M**2+26*M+1 9665C IPN M 2*NL+4*M**2+27*M+1 9666C NI M 2*NL+4*M**2+28*M+1 9667C NN M 2*NL+4*M**2+29*M+1 9668C TOLL M 2*NL+4*M**2+30*M+1 9669C YI M 2*NL+4*M**2+31*M+1 9670C YN M 2*NL+4*M**2+32*M+1 9671C ZC M 2*NL+4*M**2+33*M+1 9672C ............................................. 9673C 9674C ADAPTED TO OMNITAB COMPUTING SYSTEM BY - 9675C DAVID HOGBEN, 9676C STATISTICAL ENGINEERING DIVISION, 9677C COMPUTING AND APPLIED MATHEMATICS LABORATORY, 9678C A337 ADMINISTRATION BUILDING, 9679C NATIONAL INSTITUTE OF STANDARDS AND TECHNOLOGY, 9680C GAITHERSBURG, MD 20899 9681C TELEPHONE 301-921-3651 9682C ORIGINAL VERSION - FEBRUARY, 1977. 9683C CURRENT VERSION - APRIL, 1992. 9684C 9685C ================================================================== 9686C 9687C *** SPECIFICATION STATEMENTS *** 9688C 9689 CHARACTER*4 ICAPSW 9690 CHARACTER*4 ICAPTY 9691 CHARACTER*4 IFORSW 9692C 9693 CHARACTER*4 IBUGA3 9694 CHARACTER*4 ISUBRO 9695 CHARACTER*4 IERROR 9696C 9697 PARAMETER (MAXC=100) 9698C 9699CCCCC DIMENSION ID(29), IPI(29), IPN(29), NI(29), NN(29) 9700 DIMENSION ID(MAXC), IPI(MAXC), IPN(MAXC), NI(MAXC), NN(MAXC) 9701 DIMENSION ILI(845), ILN(845), MD(845), NC(845) 9702C 9703CCCCC INCLUDE 'WRKSCR.H' 9704 REAL A(NS) 9705C 9706C ================================================================== 9707C 9708C *** TYPE STATEMENTS *** 9709C 9710CCCCC REAL RR(29,29) 9711 REAL RR(MAXC,MAXC) 9712 REAL BOUND, CAB, RS, R2 9713 REAL SIG, SS, TEMP, TOL, TWO 9714 REAL FDIV 9715 REAL SPCA, SPCB 9716C 9717C .................................................................. 9718C 9719 DOUBLE PRECISION DTWO 9720C 9721 PARAMETER (MAXV=98) 9722 CHARACTER*1 ICOD(MAXV) 9723 CHARACTER*8 IVLIST 9724 COMMON/BESTC1/IOUNI1,IOUNI2 9725 COMMON/BESTC2/IVLIST(MAXV) 9726C 9727 PARAMETER(NUMCLI=3) 9728CCCCC PARAMETER(NUMCLI=17) 9729 PARAMETER(MAXLIN=1) 9730 PARAMETER (MAXROW=38) 9731 CHARACTER*40 ITITLE 9732 CHARACTER*40 ITITLZ 9733 CHARACTER*40 ITITL9 9734 CHARACTER*4 ALIGN(NUMCLI) 9735 CHARACTER*4 VALIGN(NUMCLI) 9736 INTEGER IDIGI2(NUMCLI) 9737 INTEGER NTOT(MAXROW) 9738 CHARACTER*20 ITITL2(MAXLIN,NUMCLI) 9739 CHARACTER*8 IVALUE(MAXROW,NUMCLI) 9740 CHARACTER*4 ITYPCO(NUMCLI) 9741 INTEGER NCTIT2(MAXLIN,NUMCLI) 9742 INTEGER NCVALU(MAXROW,NUMCLI) 9743 INTEGER IWHTML(NUMCLI) 9744 INTEGER IWRTF(NUMCLI) 9745 REAL AMAT(MAXROW,NUMCLI) 9746 LOGICAL IFRSTZ 9747 LOGICAL ILASTZ 9748 LOGICAL IFLAGS 9749 LOGICAL IFLAGE 9750C 9751 INCLUDE 'DPCOP2.INC' 9752C 9753C ================================================================== 9754C 9755C *** DATA INITIALIZATION STATEMENTS *** 9756C 9757 DATA DTWO / 2.0D0 / 9758C 9759 DATA RTWO / 2.0 / 9760 DATA RONE / 1.0 / 9761 DATA RZERO / 0.0 / 9762 DATA RER / 1.0E-8 / 9763C 9764 DATA IFOUR /4/ 9765 DATA ITHRE /3/ 9766 DATA ITWO /2/ 9767 DATA IONE /1/ 9768 DATA IZERO /0/ 9769 DATA LWIDE /80/ 9770C 9771 DATA KO, NV / 10, 11 / 9772C 9773 DATA SPCA / 100.0 / 9774 DATA SPCB / 10000.0 / 9775C 9776 DATA ICOD(1) /'1'/ 9777 DATA ICOD(2) /'2'/ 9778 DATA ICOD(3) /'3'/ 9779 DATA ICOD(4) /'4'/ 9780 DATA ICOD(5) /'5'/ 9781 DATA ICOD(6) /'6'/ 9782 DATA ICOD(7) /'7'/ 9783 DATA ICOD(8) /'8'/ 9784 DATA ICOD(9) /'9'/ 9785 DATA ICOD(10) /'0'/ 9786 DATA ICOD(11) /'A'/ 9787 DATA ICOD(12) /'B'/ 9788 DATA ICOD(13) /'C'/ 9789 DATA ICOD(14) /'D'/ 9790 DATA ICOD(15) /'E'/ 9791 DATA ICOD(16) /'F'/ 9792 DATA ICOD(17) /'G'/ 9793 DATA ICOD(18) /'H'/ 9794 DATA ICOD(19) /'I'/ 9795 DATA ICOD(20) /'J'/ 9796 DATA ICOD(21) /'K'/ 9797 DATA ICOD(22) /'L'/ 9798 DATA ICOD(23) /'M'/ 9799 DATA ICOD(24) /'N'/ 9800 DATA ICOD(25) /'O'/ 9801 DATA ICOD(26) /'P'/ 9802 DATA ICOD(27) /'Q'/ 9803 DATA ICOD(28) /'R'/ 9804 DATA ICOD(29) /'S'/ 9805 DATA ICOD(30) /'T'/ 9806 DATA ICOD(31) /'U'/ 9807 DATA ICOD(32) /'V'/ 9808 DATA ICOD(33) /'W'/ 9809 DATA ICOD(34) /'X'/ 9810 DATA ICOD(35) /'Y'/ 9811 DATA ICOD(36) /'Z'/ 9812 DATA ICOD(37) /'a'/ 9813 DATA ICOD(38) /'b'/ 9814C 9815 IFRST=0 9816 ILAST=0 9817 ICNT9=0 9818 NUMDIG=7 9819 IF(IFORSW.EQ.'1')NUMDIG=1 9820 IF(IFORSW.EQ.'2')NUMDIG=2 9821 IF(IFORSW.EQ.'3')NUMDIG=3 9822 IF(IFORSW.EQ.'4')NUMDIG=4 9823 IF(IFORSW.EQ.'5')NUMDIG=5 9824 IF(IFORSW.EQ.'6')NUMDIG=6 9825 IF(IFORSW.EQ.'7')NUMDIG=7 9826 IF(IFORSW.EQ.'8')NUMDIG=8 9827 IF(IFORSW.EQ.'9')NUMDIG=9 9828 IF(IFORSW.EQ.'0')NUMDIG=0 9829 IF(IFORSW.EQ.'E')NUMDIG=-2 9830 IF(IFORSW.EQ.'-2')NUMDIG=-2 9831 IF(IFORSW.EQ.'-3')NUMDIG=-3 9832 IF(IFORSW.EQ.'-4')NUMDIG=-4 9833 IF(IFORSW.EQ.'-5')NUMDIG=-5 9834 IF(IFORSW.EQ.'-6')NUMDIG=-6 9835 IF(IFORSW.EQ.'-7')NUMDIG=-7 9836 IF(IFORSW.EQ.'-8')NUMDIG=-8 9837 IF(IFORSW.EQ.'-9')NUMDIG=-9 9838C 9839 IWHTML(1)=150 9840 IWHTML(2)=150 9841 IWHTML(3)=150 9842 IINC=1800 9843 IWRTF(1)=IINC 9844 IWRTF(2)=IWRTF(1) + IINC 9845 IWRTF(3)=IWRTF(2) + IINC 9846C 9847C ================================================================== 9848C 9849C 10=KO=NV-1 NL=(KX+1)*(KX+2)*(KX+3)/6 ND-1=NR-1 9850C NX=(KX+1)*(KX+2)/2 9851C 9852C SET UP SIZE OF KZ, ND, NL AND NX. 9853C 9854 KZ = KX + IONE 9855 ND = KZ 9856 CALL IDIV (ND * (ND + IONE) * (ND + ITWO),6,IND,NL) 9857 CALL IDIV (ND * (ND + IONE),ITWO,IND,NX) 9858C 9859C TEST INPUT. 9860C 9861 KZSIZE = ITWO * NL + IFOUR * ND ** 2 + 34 * ND 9862 IF (KZSIZE.GT.NS) THEN 9863 WRITE(ICOUT,23) 9864 CALL DPWRST('XXX','BUG ') 9865CCCCC CALL ERROR (23) 9866 RETURN 9867 ENDIF 9868 23 FORMAT(1X,'***** ERROR FROM SCREEN (BEST CP): INSUFFICIENT ', 9869 1 'SCRATCH SPACE.') 9870CCCCC IF (NERROR.NE.IZERO) RETURN 9871C 9872C .................................................................. 9873C 9874 IF (KX.GE.ITHRE .AND. KX.LT.ND .AND. NDEF.GT.KX .AND. 9875 1 MBST.GT.IZERO .AND. MBST.LE.KO .AND. KO.LE.NV .AND. NR.GT.KX 9876 2 .AND. IBIT.GE.IONE .AND. IBIT.LE.ITHRE) GO TO 10 9877CCCCC CALL ERROR (3) 9878 WRITE(ICOUT,3) 9879 CALL DPWRST('XXX','BUG ') 9880 3 FORMAT(1X,'***** ERROR FROM SCREEN (BEST CP): INVALID OPTIONS') 9881 RETURN 9882C 9883C .................................................................. 9884C 9885 10 SS = FDIV (RR(KZ,KZ),SPCA,IND) 9886 IF (IBIT.EQ.ITWO) SS = FDIV (SS,FLOAT(NDEF),IND) 9887 IF (SS.GT.RZERO) GO TO 30 9888 20 CONTINUE 9889CCCCC CALL ERROR (22) 9890 WRITE(ICOUT,22) 9891 CALL DPWRST('XXX','BUG ') 9892 22 FORMAT(1X,'***** ERROR FROM SCREEN (BEST CP): NON-POSITIVE SUM ', 9893 1 'OF SQUARES') 9894 RETURN 9895C 9896C .................................................................. 9897C 9898C INITIALIZE. 9899C 9900 30 LSUBXI = IONE 9901 LSUBXC = IONE 9902 LSUBXN = NL + IONE 9903 LSUBLI = ITWO * NL + IONE 9904 LSUBLN = LSUBLI + KZ ** 2 9905 LSUBMD = LSUBLN + KZ ** 2 9906 LSUBNC = LSUBMD + KZ ** 2 9907 LSUBCL = LSUBNC + KZ ** 2 9908 LSUBRM = LSUBCL + 11 * KZ 9909 LSUBCI = LSUBRM + 11 * KZ 9910 LSUBCN = LSUBCI + KZ 9911 LSUBCO = LSUBCN + KZ 9912 LSUBID = LSUBCO + KZ 9913 LSUBPI = LSUBID + KZ 9914 LSUBPN = LSUBPI + KZ 9915 LSUBNI = LSUBPN + KZ 9916 LSUBNN = LSUBNI + KZ 9917 LSUBTL = LSUBNN + KZ 9918 LSUBYI = LSUBTL + KZ 9919 LSUBYN = LSUBYI + KZ 9920 LSUBZC = LSUBYN + KZ 9921 A(LSUBCN) = RZERO 9922 A(LSUBCI) = RZERO 9923 TOL = FDIV (RER,SPCB,IND) 9924 TWO = RTWO * RR(KZ,KZ) * FLOAT(NDEF) 9925 LOW = KO - MBST + IONE 9926 LISUBL = IONE 9927 LNSUBL = IONE 9928 MDSUBL = IONE 9929 NCSUBL = IONE 9930 IDSUBL = IONE 9931 NPSUBL = IONE 9932 IPSUBL = IONE 9933 NISUBL = IONE 9934 NNSUBL = IONE 9935 ISUBLI = LISUBL 9936 ISUBNC = NCSUBL 9937 ISUBCL = LSUBCL 9938 ISUBRM = LSUBRM 9939 ISUBCO = LSUBCO 9940 KSUBRM = LSUBRM + KO 9941 ISUBID = IDSUBL 9942 ISUBPN = NPSUBL 9943 ISUBTL = LSUBTL 9944C 9945C FOR DATAPLOT, SET NTLINE HIGH. THAT IS, WE ARE NOT USING A PAGE 9946C BASED OUTPUT. 9947C 9948 NTLINE = 500 9949C 9950CCCCC IF (NCRT.NE.IZERO) NTLINE = LENGTH + ITHRE 9951 DO 50 L=1,KZ 9952 CALL IDIV ((KZ-IONE)*KZ*(KZ+IONE)-(KZ-L)*(KZ-L+IONE)* 9953 1 (KZ-L+ITWO),6,IND,ID(ISUBID)) 9954 IPN(ISUBPN) = IONE 9955 ILI(ISUBLI) = L 9956 A(KSUBRM) = -TWO 9957 KSUBRM = KSUBRM + 11 9958 A(ISUBCO) = DTWO**(KX-L) 9959 NC(ISUBNC) = L 9960 A(ISUBTL) = TOL * RR(L,L) 9961 IF (A(ISUBTL).LE.RZERO) GO TO 20 9962 JSUBCL = ISUBCL 9963 JSUBRM = ISUBRM 9964 DO 40 M=1,KO 9965 A(JSUBCL) = RZERO 9966 A(JSUBRM) = TWO 9967 JSUBCL = JSUBCL + IONE 9968 JSUBRM = JSUBRM + IONE 9969 40 CONTINUE 9970 ISUBCL = ISUBCL + 11 9971 ISUBRM = ISUBRM + 11 9972 ISUBCO = ISUBCO + IONE 9973 ISUBLI = ISUBLI + KZ 9974 ISUBNC = ISUBNC + KZ 9975 ISUBID = ISUBID + IONE 9976 ISUBPN = ISUBPN + IONE 9977 ISUBTL = ISUBTL + IONE 9978 50 CONTINUE 9979C 9980C STORE MATRICES AS VECTORS. 9981C 9982 LS = IZERO 9983 ISUBXC = LSUBXC - IONE 9984 ISUBXN = LSUBXN 9985 ISUBMD = MDSUBL 9986 MSUBMD = MDSUBL - IONE 9987 DO 70 L=1,KZ 9988 KSUBMD = ISUBMD 9989 JSUBMD = MSUBMD + KZ * (L - IONE) + L 9990 DO 60 M=L,KZ 9991 LS = LS + IONE 9992 ISUBXC = ISUBXC + IONE 9993 MD(KSUBMD) = LS 9994 MD(JSUBMD) = LS 9995 A(ISUBXC) = RR(L,M) 9996 A(ISUBXN) = A(ISUBXC) 9997 RR(M,L) = RR(L,M) 9998 ISUBXN = ISUBXN + IONE 9999 KSUBMD = KSUBMD + KZ 10000 JSUBMD = JSUBMD + IONE 10001 60 CONTINUE 10002 ISUBMD = ISUBMD + IONE + KZ 10003 70 CONTINUE 10004C 10005C INVERT MATRIX STEPWISE. 10006C 10007 ISUBMD = MDSUBL + KZ ** 2 - IONE 10008 ISUB2 = MD(ISUBMD) + LSUBXC - IONE 10009 NSUBLI = LISUBL 10010 NSUBLN = LNSUBL 10011 NSUBMD = MDSUBL + KZ * (KZ - IONE) - IONE 10012 ISUBRM = LSUBRM - IONE + KO 10013 MSUBRM = LSUBRM 10014 ISUBCO = LSUBCO - IONE 10015 DO 90 N=1,KX 10016 J = IZERO 10017 N1 = N 10018 ISUBLI = NSUBLI 10019 DO 80 LA=N,KX 10020 L = ILI(ISUBLI) 10021 ISUBLI = ISUBLI + KZ 10022 ISUBMD = MDSUBL + KZ * (L -IONE) - IONE 10023 MSUBMD = NSUBMD + L 10024 ISUBMD = ISUBMD + L 10025 ISUBTL = LSUBTL + L - IONE 10026 ISUB1 = MD(ISUBMD) + LSUBXC - IONE 10027 IF (A(ISUB1).LT.A(ISUBTL)) GO TO 80 10028 ISUB3 = MD(MSUBMD) + LSUBXC - IONE 10029 RS = A(ISUB2) - FDIV (A(ISUB3)*A(ISUB3),A(ISUB1),IND) 10030 IF (RS.LT.A(ISUBRM)) J = LA 10031 MSUBCO = ISUBCO + L 10032 IF (RS.LT.A(MSUBRM)) CALL CPSTRE (RS,A(LSUBCI)+A(MSUBCO), 10033 1 KO,A(LSUBCL),A(LSUBRM),N1,NV,ND) 10034 80 CONTINUE 10035 IF (J.EQ.IZERO) GO TO 100 10036 JSUBLI = LISUBL + KZ * (J -IONE) 10037 M = ILI(JSUBLI) 10038 ILI(JSUBLI) = ILI(NSUBLI) 10039 ILI(NSUBLI) = M 10040 ILN(NSUBLN) = M 10041 MSUBCO = ISUBCO + M 10042 A(LSUBCI) = A(LSUBCI) + A(MSUBCO) 10043 NSUBLI = NSUBLI + KZ 10044 NSUBLN = NSUBLN + KZ 10045 ISUBRM = ISUBRM + 11 10046 MSUBRM = MSUBRM + 11 10047 CALL PIVOT (A(LSUBXC),KZ,M,MD(MDSUBL),ND,NX) 10048 90 CONTINUE 10049C 10050 N = KZ 10051 100 K = N - IONE 10052 KP = KZ * K + LISUBL 10053 KXSUBL = KZ * (KX - IONE) + LISUBL 10054 IF (K.NE.KX) THEN 10055 ICNT=0 10056 DO102I=KP,KXSUBL,KZ 10057 ICNT=ICNT+1 10058 IF(ICNT.EQ.22)ILAST=I 10059 IF(ICNT.EQ.23)IFRST=I 10060 102 CONTINUE 10061CCCCC WRITE (ICOUT,330) (ILI(I),I=KP,KXSUBL,KZ) 10062 WRITE (ICOUT,330) 10063 330 FORMAT(2X, 10064 1 'SCREEN-MATRIX IS SINGULAR. VARIABLES DELETED ARE ...') 10065 CALL DPWRST('XXX','BUG ') 10066 IF(ICNT.LE.22)THEN 10067 WRITE (ICOUT,331) (ILI(I),I=KP,KXSUBL,KZ) 10068 331 FORMAT(5X,22I3) 10069 CALL DPWRST('XXX','BUG ') 10070 ELSE 10071 WRITE (ICOUT,331) (ILI(I),I=KP,KXSUBL,ILAST) 10072 CALL DPWRST('XXX','BUG ') 10073 WRITE (ICOUT,331) (ILI(I),I=IFRST,KXSUBL,KZ) 10074 CALL DPWRST('XXX','BUG ') 10075 ENDIF 10076 ENDIF 10077 IF (K.LT.ITHRE) RETURN 10078 KM = K - IONE 10079C 10080C INTCPT - IONE = ADJUSTMENT FOR USING WITH NO CONSTANT TERM. 10081C 10082 SIG = FDIV (RTWO*A(ISUBXC),FLOAT(NDEF-K+IONE-INTCPT),IND) 10083 A(LSUBYI) = A(ISUBXC) 10084 A(LSUBYN) = RR(KZ,KZ) 10085C 10086 NI(NISUBL) = K 10087 NN(NNSUBL) = K 10088 ISUBCL = LSUBCL - IONE 10089 ISUBRM = LSUBRM 10090 KSUBRM = LSUBRM + 11 * (KZ - IONE) 10091 IF (IBIT.EQ.IONE) GO TO 130 10092 DO 120 M=1,K 10093 MSUBCL = ISUBCL 10094 MSUBRM = ISUBRM 10095 DO 110 L=1,KO 10096 IF (IBIT.EQ.ITWO) RS = FDIV (A(MSUBRM),FLOAT(NDEF-M),IND) 10097 IF (IBIT.EQ.ITHRE) RS = A(MSUBRM) + SIG * FLOAT (M) 10098 MSUBCL = MSUBCL + IONE 10099 MSUBRM = MSUBRM + IONE 10100 IF (RS.GE.A(KSUBRM)) GO TO 110 10101 TEMP = A(MSUBCL) 10102 CALL CPSTRE (RS,TEMP,KO,A(LSUBCL),A(LSUBRM),KZ,NV,ND) 10103 110 CONTINUE 10104 ISUBCL = ISUBCL + 11 10105 ISUBRM = ISUBRM + 11 10106 120 CONTINUE 10107C 10108 130 NREG = IZERO 10109 NCAL = ITWO 10110 MN = ITWO 10111 MV = -IONE 10112C 10113C STAGE LOOP. 10114C 10115 140 CONTINUE 10116 JSUBRM = KSUBRM 10117 IF (MN.EQ.IONE) GO TO 240 10118 ISUBPN = NPSUBL + MN - IONE 10119 IP = IPN(ISUBPN) 10120 IPN(ISUBPN) = IP + IONE 10121 MV = MV - IPN(ISUBPN+1) + IP + ITWO 10122 ISUBPI = IPSUBL + MV - IONE 10123 IPI(ISUBPI) = IP 10124 MN = MN - IONE 10125 ISUBPN = ISUBPN - IONE 10126 IN = IPN(ISUBPN) 10127 JC = MV 10128 ISUBYI = LSUBYI + IP - IONE 10129 BOUND = A(ISUBYI) 10130 A(ISUBYI) = TWO 10131C 10132C FIND LEAP FROM BOUNDS. 10133C 10134 ISUBRM = LSUBRM + LOW - IONE 10135 KSUBRM = LSUBRM + 11 * (KZ - IONE) + LOW - IONE 10136 DO 150 LB=IP,KM 10137 MT = MN + KM - LB 10138 MSUBRM = ISUBRM + 11 * (MT - IONE) 10139 IF (IBIT.EQ.IONE .AND. A(MSUBRM).GT.BOUND) GO TO 160 10140 IF (IBIT.EQ.ITWO .AND. A(KSUBRM).GT.FDIV(BOUND,FLOAT(NDEF-MT), 10141 1 IND)) GO TO 160 10142 IF (IBIT.EQ.ITHRE .AND. A(KSUBRM).GT.BOUND+SIG*FLOAT(MT)) 10143 1 GO TO 160 10144 150 CONTINUE 10145 GO TO 140 10146C 10147 160 LC = KM + IP - LB 10148 NREG = NREG + ITWO * (LC-IP+IONE) 10149 IF (IP.EQ.IONE) LC = K 10150C 10151C REGRESSIONS FROM INVERSE MATRIX. 10152C 10153 ISUBNI = NISUBL + IP 10154 ISUBNN = NNSUBL + IP 10155 KSUBLI = LISUBL + IP - IONE 10156 KSUBLN = LNSUBL + IN - IONE 10157 KSUBNN = NNSUBL + IN - IONE 10158 DO 200 LB=IP,LC 10159 LBB = LB 10160 CALL BACK (NC(NCSUBL),LBB,LI,IPI(IPSUBL),MV,RS,BOUND,ILI(LISUBL) 10161 1 ,JC,ID(IDSUBL),A(LSUBXI),MD(MDSUBL), 10162 2 IONE,NI(NISUBL),ND,KZ,NL,NCAL) 10163C 10164C RE-ORDER VARIABLES. 10165C 10166 M = LB 10167 MSUBLN = KSUBLN + KZ * (M - IONE) 10168 MSUBLI = KSUBLI + KZ * (M - IONE) 10169 ISUBYI = LSUBYI + M - IONE 10170 IF (LB.GT.NN(KSUBNN)) GO TO 190 10171 LN = ILN(MSUBLN) 10172 170 IF (RS.LE.A(ISUBYI)) GO TO 180 10173 A(ISUBYI+1) = A(ISUBYI) 10174 NSUBLI = MSUBLI - KZ 10175 NSUBLN = MSUBLN - KZ 10176 ILI(MSUBLI) = ILI(NSUBLI) 10177 ILN(MSUBLN) = ILN(NSUBLN) 10178 M = M - IONE 10179 MSUBLI = MSUBLI - KZ 10180 MSUBLN = MSUBLN - KZ 10181 ISUBYI = ISUBYI - IONE 10182 GO TO 170 10183 180 ILI(MSUBLI) = LI 10184 ILN(MSUBLN) = LN 10185 190 A(ISUBYI+1) = RS 10186 NI(ISUBNI) = LB 10187 NN(ISUBNN) = LB 10188 ISUBNI = ISUBNI + IONE 10189 ISUBNN = ISUBNN + IONE 10190 200 CONTINUE 10191 IF (LC.EQ.K) LC = KM 10192 MI = K - MV 10193 JC = MN 10194C 10195C REGRESSIONS FROM PRODUCT MATRIX. 10196C 10197 ISUBRM = LSUBRM + 11 * (MI - IONE) 10198 KSUBRM = LSUBRM + 11 * (KZ - IONE) 10199 ISUBCI = LSUBCI + IP - IONE 10200 ISUBYI = LSUBYI + IP - IONE 10201 ISUBYN = LSUBYN + IP - IONE 10202 ISUBCO = LSUBCO - IONE 10203 DO 230 LB=IP,LC 10204 LBB = LB 10205 ISUBCN = LSUBCN + IN - IONE 10206 ISUBNC = NCSUBL + IN - IONE 10207 KSUBYN = LSUBYN + IN - IONE 10208 ISUBYI = ISUBYI + IONE 10209 ISUBYN = ISUBYN + IONE 10210 IS = LB + IONE 10211 MSUBCN = LSUBCN + LB 10212 A(MSUBCN) = A(KSUBYN) 10213 CALL BACK (NC(NCSUBL),LBB,L,IPN(NPSUBL),MN,A(ISUBYN),A(MSUBCN) 10214 1 ,ILN(LNSUBL),JC,ID(IDSUBL),A(LSUBXN),MD(MDSUBL), 10215 2 IZERO,NN(NNSUBL),ND,KZ,NL,NCAL) 10216 MSUBNC = ISUBNC + KZ * (L - IONE) 10217 ISUB4 = NC(MSUBNC) 10218 MSUBCI = LSUBCI + LB 10219 MSUBCO = ISUBCO + ISUB4 10220 A(MSUBCI) = A(ISUBCI) - A(MSUBCO) 10221 A(MSUBCN) = A(ISUBCN) + A(MSUBCO) 10222 IF (A(ISUBYI).GE.A(ISUBRM)) GO TO 210 10223 CALL CPSTRE (A(ISUBYI),A(MSUBCI),KO,A(LSUBCL),A(LSUBRM),MI, 10224 1 NV,ND) 10225 IF (IBIT.EQ.IONE) GO TO 210 10226 IF (IBIT.EQ.ITWO) RS = FDIV (A(ISUBYI),FLOAT(NDEF-MI),IND) 10227 IF (IBIT.EQ.ITHRE) RS = A(ISUBYI) + FLOAT(MI) * SIG 10228 IF (RS.LT.A(KSUBRM)) CALL CPSTRE (RS,A(MSUBCI),KO,A(LSUBCL), 10229 1 A(LSUBRM),KZ,NV,ND) 10230 210 MSUBRM = LSUBRM + 11 * (MN - IONE) 10231 IF (A(ISUBYN).GE.A(MSUBRM)) GO TO 220 10232 CALL CPSTRE (A(ISUBYN),A(MSUBCN),KO,A(LSUBCL),A(LSUBRM),MN, 10233 1 NV,ND) 10234 IF (IBIT.EQ.IONE) GO TO 220 10235 IF (IBIT.EQ.ITWO) RS = FDIV (A(ISUBYN),FLOAT(NDEF-MN),IND) 10236 IF (IBIT.EQ.ITHRE) RS = A(ISUBYN) + FLOAT(MN) * SIG 10237 IF (RS.LT.A(KSUBRM)) CALL CPSTRE (RS,A(MSUBCN),KO,A(LSUBCL), 10238 1 A(LSUBRM),KZ,NV,ND) 10239 220 MN = MN + IONE 10240 ISUBPN = NPSUBL + MN - IONE 10241 IPN(ISUBPN+1) = IPN(ISUBPN) + IONE 10242 IN = IS 10243 230 CONTINUE 10244 IF (LC.EQ.KM) MN = MN - IONE 10245 GO TO 140 10246C 10247C OUTPUT. 10248C 10249 240 CONTINUE 10250 CALL IDIV (KX-IONE,ITWO,IND,NJUNK) 10251 NLINES = 8 + NJUNK 10252 ISUBCL = LSUBCL - 12 10253 ISUBRM = LSUBRM - 12 10254C 10255 ITITLE=' ' 10256 NCTITL=0 10257 ITITLZ=' ' 10258 NCTITZ=0 10259C 10260 DO 320 M=1,K 10261 MM = M 10262 ISUBCL = ISUBCL + 11 10263 ISUBRM = ISUBRM + 11 10264CCCCC IF (NLINES+ITHRE.LE.NTLINE) GO TO 250 10265CCCCC CALL PAGE (IFOUR) 10266CCCCC NLINES = ITHRE 10267C250 CONTINUE 10268 IF (KO.GT.IONE .AND. M.EQ.IONE) THEN 10269CCCCC WRITE (ICOUT,390) 10270C390 FORMAT(4X,'REGRESSION WITH 1 VARIABLE') 10271CCCCC CALL DPWRST('XXX','BUG ') 10272 ITITLE='Regression with One Variable' 10273 NCTITL=28 10274 ELSEIF (KO.GT.IONE .AND. M.GT.IONE) THEN 10275CCCCC WRITE(ICOUT,999) 10276CCCCC CALL DPWRST('XXX','BUG ') 10277CCCCC WRITE (ICOUT,340) M 10278C340 FORMAT(4X,'REGRESSIONS WITH',I3,' VARIABLES') 10279CCCCC CALL DPWRST('XXX','BUG ') 10280 ITITLE='Regressions with Variables' 10281 WRITE(ITITLE(18:20),'(I3)')M 10282 NCTITL=30 10283 ENDIF 10284C 10285 NLINES = NLINES + ITWO 10286 IPRTSW = IZERO 10287 DO 310 LA=1,KO 10288 NCOF = IONE 10289 L = KO - LA + IONE 10290 MSUBRM = ISUBRM + L 10291CCCCC IF (A(MSUBRM).EQ.TWO) GO TO 320 10292 IF (A(MSUBRM).EQ.TWO) GO TO 329 10293 IF (IBIT.EQ.IONE) R2 = SPCA - FDIV (A(MSUBRM),SS,IND) 10294 IF (IBIT.EQ.ITWO) RS = FDIV (A(MSUBRM),FLOAT(NDEF-M),IND) 10295 IF (IBIT.EQ.ITHRE) RS = A(MSUBRM) + SIG * FLOAT(M) 10296 IF (IBIT.EQ.IONE .AND. LA.LE.MBST .OR. IBIT.GT.IONE 10297 1 .AND. RS.LE.A(JSUBRM)) NCOF = IZERO 10298 IF (IBIT.EQ.ITWO) R2 = SPCA - FDIV (RS,SS,IND) 10299 IF (IBIT.EQ.ITHRE) R2 = RTWO * FDIV (RS,SIG,IND) - FLOAT(NDEF) 10300C 10301C ADJUSTMENT TO ALLOW USE OF MODEL WHICH DOES NOT HAVE 10302C A CONSTANT TERM FOR THE FIRST TERM. 10303C CHANGE SUGGESTED BY JAMES W. FRANE. 10304C 10305 IF (IBIT.EQ.ITHRE .AND. INTCPT.EQ.IZERO) R2 = R2 - RONE 10306 IF (IBIT.EQ.ITHRE .AND. INTCPT.EQ.IONE ) R2 = R2 + RONE 10307 ANTEMP=REAL(NDEF+1) 10308 RSSTMP=A(MSUBRM) 10309 RSSTM2=RSSTMP/ANTEMP 10310 BIC=ANTEMP*LOG(RSSTM2) + REAL(M+1)*LOG(ANTEMP) 10311C 10312C DECODE LABELS. 10313C 10314 MSUBCL = ISUBCL + L 10315 CAB = A(MSUBCL) 10316 MP = IONE 10317 ISUBCO = LSUBCO - IONE 10318 ISUBPN = NPSUBL 10319 DO 260 I=1,KX 10320 ISUBCO = ISUBCO + IONE 10321 IF (CAB.LT.A(ISUBCO)) GO TO 260 10322 IPN(ISUBPN) = I 10323 MP = MP + IONE 10324 CAB = CAB - A(ISUBCO) 10325 ISUBPN = ISUBPN + IONE 10326 260 CONTINUE 10327C 10328 IF (NCOF.NE.IZERO) THEN 10329 ICNT9=ICNT9+1 10330 IF (IPRTSW.GT.IZERO) GO TO 300 10331 NLINES = NLINES + M + IONE 10332 IF (M.GT.15 .AND. LWIDE.LT.110) NLINES = NLINES + M 10333 IF (NLINES.LE.NTLINE) GO TO 290 10334CCCCC CALL PAGE (IFOUR) 10335 NLINES = M + IFOUR 10336 IF (M.GT.15 .AND. LWIDE.LT.110) NLINES = NLINES + M 10337 290 CONTINUE 10338C 10339CCCCC WRITE (ICOUT,350) 10340C350 FORMAT(10X,'C(P) STATISTIC',2X,'VARIABLES') 10341CCCCC CALL DPWRST('XXX','BUG ') 10342C 10343 NUMCOL=2 10344 NUMLIN=1 10345C 10346 DO1183I=1,MAXLIN 10347 DO1185J=1,NUMCLI 10348 ITITL2(I,J)=' ' 10349 NCTIT2(I,J)=0 10350 1185 CONTINUE 10351 1183 CONTINUE 10352C 10353 ITITL2(1,1)='C(p) Statistic' 10354 NCTIT2(1,1)=14 10355 ITITL2(1,2)='BIC' 10356 NCTIT2(1,2)=3 10357 ITITL2(1,3)='Variable' 10358 NCTIT2(1,3)=8 10359C 10360 NMAX=0 10361 NUMCOL=3 10362 DO1193I=1,NUMCOL 10363 VALIGN(I)='b' 10364 ALIGN(I)='r' 10365 NTOT(I)=15 10366 NMAX=NMAX+NTOT(I) 10367 ITYPCO(I)='NUME' 10368 IDIGI2(I)=NUMDIG 10369 IF(I.EQ.3)THEN 10370 ITYPCO(I)='ALPH' 10371 IDIGI2(I)=-1 10372 ENDIF 10373 DO1195J=1,MAXROW 10374 IVALUE(J,I)=' ' 10375 NCVALU(J,I)=0 10376 AMAT(J,I)=0.0 10377 1195 CONTINUE 10378 1193 CONTINUE 10379 ICNT=0 10380C 10381 IPRTSW = IONE 10382C 10383 300 CONTINUE 10384 ISTPPN = NPSUBL + M - IONE 10385 IJUNK=1 10386 IF(M.EQ.IONE)THEN 10387C 10388C FOLLOWING CODE ONLY IMPLEMENTED FOR THE REGRESSIONS 10389C WITH ONE VARIABLE, SO CAN SIMPLIFY CODE A BIT. 10390C 10391 WRITE(IOUNI1,71)IJUNK,R2,BIC,IVLIST(IPN(NPSUBL)) 10392 71 FORMAT(I3,1X,2F15.3,' : ',A8) 10393 WRITE(IOUNI2,'(A1)')ICOD(IPN(NPSUBL)) 10394 ENDIF 10395CCCCC IF (LWIDE.GE.110) THEN 10396CCCCC WRITE (ICOUT,360) R2, (IPN(I),I=NPSUBL,ISTPPN) 10397C360 FORMAT(13X,F8.3,5X,28I3) 10398CCCCC CALL DPWRST('XXX','BUG ') 10399CCCCC ELSEIF (LWIDE.LT.110) THEN 10400 INUMB=ISTPPN-NPSUBL+1 10401 IF(INUMB.LE.15)THEN 10402CCCCC WRITE (ICOUT,370) R2, (IPN(I),I=NPSUBL,ISTPPN) 10403C370 FORMAT(14X,F8.3,3X,15I3) 10404CCCCC CALL DPWRST('XXX','BUG ') 10405 ICNT=ICNT+1 10406 AMAT(ICNT,1)=R2 10407 AMAT(ICNT,2)=BIC 10408C 10409C FOLLOWING ASSUMES ONLY ONE VARIABLE 10410C 10411CCCCC WRITE(IVALUE(ICNT,3),'(15I3)')(IPN(I),I=NPSUBL,ISTPPN,15) 10412CCCCC NCVALU(ICNT,3)=3*INUMB 10413 IVALUE(ICNT,3)=IVLIST(IPN(NPSUBL)) 10414 NCVALU(ICNT,3)=8 10415 ELSE 10416C 10417C NOTE: SINCE THIS FORMATTING ONLY USED FOR THE 10418C ONE VARIABLE CASE, CAN COMMENT OUT THIS 10419C SECTION. 10420C 10421CONE ITEMP1=NPSUBL+14 10422CCCCC WRITE (ICOUT,370) R2, (IPN(I),I=NPSUBL,ITEMP1) 10423CCCCC CALL DPWRST('XXX','BUG ') 10424CCCCC WRITE (ICOUT,371) R2, (IPN(I),I=ITEMP1+1,ISTPPN) 10425C371 FORMAT(26X,15I3) 10426CCCCC CALL DPWRST('XXX','BUG ') 10427CONE ICNT=ICNT+1 10428CONE AMAT(ICNT,1)=R2 10429CONE AMAT(ICNT,2)=BIC 10430CONE WRITE(IVALUE(ICNT,3),'(15I3)') 10431CONE 1 (IPN(I),I=NPSUBL,ITEMP1) 10432CONE NCVALU(ICNT,3)=45 10433CONE ICNT=ICNT+1 10434CONE AMAT(ICNT,1)=R2 10435CONE AMAT(ICNT,2)=BIC 10436CONE WRITE(IVALUE(ICNT,3),'(15I3)') 10437CONE 1 (IPN(I),I=ITEMP1+1,ISTPPN) 10438CONE ITEMP2=ISTPPN-ITEMP1 10439CONE NCVALU(ICNT,3)=3*ITEMP2 10440 ENDIF 10441 ELSE 10442 NUMCOL=3 10443 NUMLIN=1 10444C 10445 DO183I=1,MAXLIN 10446 DO185J=1,NUMCLI 10447 ITITL2(I,J)=' ' 10448 NCTIT2(I,J)=0 10449 185 CONTINUE 10450 183 CONTINUE 10451C 10452 ITITL2(1,1)='Variable' 10453 NCTIT2(1,1)=8 10454 ITITL2(1,2)='Coefficient' 10455 NCTIT2(1,2)=11 10456 ITITL2(1,3)='F Ratio' 10457 NCTIT2(1,3)=7 10458C 10459 NMAX=0 10460 NUMCOL=3 10461 DO193I=1,NUMCOL 10462 VALIGN(I)='b' 10463 ALIGN(I)='r' 10464 NTOT(I)=15 10465 NMAX=NMAX+NTOT(I) 10466 ITYPCO(I)='NUME' 10467 IF(I.EQ.1)ITYPCO(I)='ALPH' 10468 IDIGI2(I)=NUMDIG 10469 IF(I.EQ.1)THEN 10470 IDIGI2(I)=-1 10471 ELSEIF(I.EQ.3)THEN 10472 IDIGI2(I)=3 10473 ENDIF 10474 DO195J=1,MAXROW 10475 IVALUE(J,I)=' ' 10476 NCVALU(J,I)=0 10477 AMAT(J,I)=0.0 10478 195 CONTINUE 10479 193 CONTINUE 10480C 10481CCCCC NLINES = NLINES + M + ITHRE 10482CCCCC IF (NLINES.LE.NTLINE) GO TO 270 10483CCCCC CALL PAGE (IFOUR) 10484CCCCC NLINES = M + 6 10485C270 CONTINUE 10486 CALL COEF (R2,BIC,MP,KZ,A(LSUBXC),RR,MAXC,IPN(NPSUBL), 10487 1 NDEF,MM,ND, 10488 1 MD(MDSUBL),NX,IBIT,A(LSUBZC), 10489 1 AMAT,IVALUE,NCVALU,MAXROW,NUMCLI,ITITL9,NCTIT9) 10490C 10491 NUMLIN=1 10492 ICNT=MM 10493 IFRSTZ=.TRUE. 10494 ILASTZ=.TRUE. 10495 IFLAGS=.TRUE. 10496 IFLAGE=.TRUE. 10497 IF(IPRINT.EQ.'ON')THEN 10498 CALL DPDTA5(ITITLE,NCTITL, 10499 1 ITITL9,NCTIT9,ITITL2,NCTIT2, 10500 1 MAXLIN,NUMLIN,NUMCLI,NUMCOL, 10501 1 IVALUE,NCVALU,AMAT,ITYPCO,MAXROW,ICNT, 10502 1 IDIGI2,NTOT,IWHTML,IWRTF,VALIGN,ALIGN,NMAX, 10503 1 ICAPSW,ICAPTY,IFRSTZ,ILASTZ, 10504 1 IFLAGS,IFLAGE, 10505 1 ISUBRO,IBUGA3,IERROR) 10506 ENDIF 10507 ITITLE=' ' 10508 NCTITL=0 10509 ICNT9=0 10510C 10511CCCCC GO TO 310 10512 ENDIF 10513C 10514 310 CONTINUE 10515C 10516 329 CONTINUE 10517 NUMLIN=1 10518 ITITL9=' ' 10519 NCTIT9=0 10520 IFRSTZ=.TRUE. 10521 ILASTZ=.TRUE. 10522 IFLAGS=.TRUE. 10523 IFLAGE=.TRUE. 10524 IF(IPRINT.EQ.'ON' .AND. ICNT9.GT.0)THEN 10525 CALL DPDTA5(ITITLE,NCTITL, 10526 1 ITITL9,NCTIT9,ITITL2,NCTIT2, 10527 1 MAXLIN,NUMLIN,NUMCLI,NUMCOL, 10528 1 IVALUE,NCVALU,AMAT,ITYPCO,MAXROW,ICNT, 10529 1 IDIGI2,NTOT,IWHTML,IWRTF,VALIGN,ALIGN,NMAX, 10530 1 ICAPSW,ICAPTY,IFRSTZ,ILASTZ, 10531 1 IFLAGS,IFLAGE, 10532 1 ISUBRO,IBUGA3,IERROR) 10533 ENDIF 10534C 10535 320 CONTINUE 10536 NCAL = NCAL + ITWO * NREG 10537 IF(IFEEDB.EQ.'ON')THEN 10538 WRITE (ICOUT,380) NREG, NCAL 10539 CALL DPWRST('XXX','BUG ') 10540 ENDIF 10541 RETURN 10542C 10543C ================================================================== 10544C 10545C *** FORMAT STATEMENTS *** 10546C 10547 380 FORMAT(2X,I9,' REGRESSIONS',2X,I10,' OPERATIONS') 10548C999 FORMAT(1X) 10549C 10550C ================================================================== 10551C 10552 END 10553 SUBROUTINE SNSQE(FCN,JAC,IOPT,N,X,FVEC,TOL,NPRINT,INFO,WA,LWA, 10554 1 XDATA,NOBS) 10555C***BEGIN PROLOGUE SNSQE 10556C***DATE WRITTEN 800301 (YYMMDD) 10557C***REVISION DATE 880222 (YYMMDD) 10558C***CATEGORY NO. F2A 10559C***KEYWORDS EASY-TO-USE,NONLINEAR SQUARE SYSTEM,POWELL HYBRID METHOD, 10560C ZERO 10561C***AUTHOR HIEBERT, K. L., (SNLA) 10562C***PURPOSE SNSQE is the easy-to-use version of SNSQ which finds a zero 10563C of a system of N nonlinear functions in N variables by a 10564C modification of Powell hybrid method. This code is the 10565C combination of the MINPACK codes(Argonne) HYBRD1 and HYBRJ1 10566C***DESCRIPTION 10567C 10568C 1. Purpose. 10569C 10570C 10571C The purpose of SNSQE is to find a zero of a system of N non- 10572C linear functions in N variables by a modification of the Powell 10573C hybrid method. This is done by using the more general nonlinear 10574C equation solver SNSQ. The user must provide a subroutine which 10575C calculates the functions. The user has the option of either to 10576C provide a subroutine which calculates the Jacobian or to let the 10577C code calculate it by a forward-difference approximation. This 10578C code is the combination of the MINPACK codes (Argonne) HYBRD1 10579C and HYBRJ1. 10580C 10581C 10582C 2. Subroutine and Type Statements. 10583C 10584C SUBROUTINE SNSQE(FCN,JAC,IOPT,N,X,FVEC,TOL,NPRINT,INFO, 10585C * WA,LWA) 10586C INTEGER IOPT,N,NPRINT,INFO,LWA 10587C REAL TOL 10588C REAL X(N),FVEC(N),WA(LWA) 10589C EXTERNAL FCN,JAC 10590C 10591C 10592C 3. Parameters. 10593C 10594C Parameters designated as input parameters must be specified on 10595C entry to SNSQE and are not changed on exit, while parameters 10596C designated as output parameters need not be specified on entry 10597C and are set to appropriate values on exit from SNSQE. 10598C 10599C FCN is the name of the user-supplied subroutine which calculates 10600C the functions. FCN must be declared in an EXTERNAL statement 10601C in the user calling program, and should be written as follows. 10602C 10603C SUBROUTINE FCN(N,X,FVEC,IFLAG) 10604C INTEGER N,IFLAG 10605C REAL X(N),FVEC(N) 10606C ---------- 10607C Calculate the functions at X and 10608C return this vector in FVEC. 10609C ---------- 10610C RETURN 10611C END 10612C 10613C The value of IFLAG should not be changed by FCN unless the 10614C user wants to terminate execution of SNSQE. In this case, set 10615C IFLAG to a negative integer. 10616C 10617C JAC is the name of the user-supplied subroutine which calculates 10618C the Jacobian. If IOPT=1, then JAC must be declared in an 10619C EXTERNAL statement in the user calling program, and should be 10620C written as follows. 10621C 10622C SUBROUTINE JAC(N,X,FVEC,FJAC,LDFJAC,IFLAG) 10623C INTEGER N,LDFJAC,IFLAG 10624C REAL X(N),FVEC(N),FJAC(LDFJAC,N) 10625C ---------- 10626C Calculate the Jacobian at X and return this 10627C matrix in FJAC. FVEC contains the function 10628C values at X and should not be altered. 10629C ---------- 10630C RETURN 10631C END 10632C 10633C The value of IFLAG should not be changed by JAC unless the 10634C user wants to terminate execution of SNSQE. In this case, set 10635C IFLAG to a negative integer. 10636C 10637C If IOPT=2, JAC can be ignored (treat it as a dummy argument). 10638C 10639C IOPT is an input variable which specifies how the Jacobian will 10640C be calculated. If IOPT=1, then the user must supply the 10641C Jacobian through the subroutine JAC. If IOPT=2, then the 10642C code will approximate the Jacobian by forward-differencing. 10643C 10644C N is a positive integer input variable set to the number of 10645C functions and variables. 10646C 10647C X is an array of length N. On input, X must contain an initial 10648C estimate of the solution vector. On output, X contains the 10649C final estimate of the solution vector. 10650C 10651C FVEC is an output array of length N which contains the functions 10652C evaluated at the output X. 10653C 10654C TOL is a non-negative input variable. Termination occurs when 10655C the algorithm estimates that the relative error between X and 10656C the solution is at most TOL. Section 4 contains more details 10657C about TOL. 10658C 10659C NPRINT is an integer input variable that enables controlled 10660C printing of iterates if it is positive. In this case, FCN is 10661C called with IFLAG = 0 at the beginning of the first iteration 10662C and every NPRINT iteration thereafter and immediately prior 10663C to return, with X and FVEC available for printing. Appropriate 10664C print statements must be added to FCN (see example). If NPRINT 10665C is not positive, no special calls of FCN with IFLAG = 0 are 10666C made. 10667C 10668C INFO is an integer output variable. If the user has terminated 10669C execution, INFO is set to the (negative) value of IFLAG. See 10670C description of FCN and JAC. Otherwise, INFO is set as follows. 10671C 10672C INFO = 0 improper input parameters. 10673C 10674C INFO = 1 algorithm estimates that the relative error between 10675C X and the solution is at most TOL. 10676C 10677C INFO = 2 number of calls to FCN has reached or exceeded 10678C 100*(N+1) for IOPT=1 or 200*(N+1) for IOPT=2. 10679C 10680C INFO = 3 TOL is too small. No further improvement in the 10681C approximate solution X is possible. 10682C 10683C INFO = 4 iteration is not making good progress. 10684C 10685C Sections 4 and 5 contain more details about INFO. 10686C 10687C WA is a work array of length LWA. 10688C 10689C LWA is a positive integer input variable not less than 10690C (3*N**2+13*N))/2. 10691C 10692C 10693C 4. Successful Completion. 10694C 10695C The accuracy of SNSQE is controlled by the convergence parame- 10696C ter TOL. This parameter is used in a test which makes a compar- 10697C ison between the approximation X and a solution XSOL. SNSQE 10698C terminates when the test is satisfied. If TOL is less than the 10699C machine precision (as defined by the function R1MACH(4)), then 10700C SNSQE attemps only to satisfy the test defined by the machine 10701C precision. Further progress is not usually possible. Unless 10702C high precision solutions are required, the recommended value 10703C for TOL is the square root of the machine precision. 10704C 10705C The test assumes that the functions are reasonably well behaved, 10706C and, if the Jacobian is supplied by the user, that the functions 10707C and the Jacobian coded consistently. If these conditions 10708C are not satisfied, SNSQE may incorrectly indicate convergence. 10709C The coding of the Jacobian can be checked by the subroutine 10710C CHKDER. If the Jacobian is coded correctly or IOPT=2, then 10711C the validity of the answer can be checked, for example, by 10712C rerunning SNSQE with a tighter tolerance. 10713C 10714C Convergence Test. If SNRM2(Z) denotes the Euclidean norm of a 10715C vector Z, then this test attempts to guarantee that 10716C 10717C SNRM2(X-XSOL) .LE. TOL*SNRM2(XSOL). 10718C 10719C If this condition is satisfied with TOL = 10**(-K), then the 10720C larger components of X have K significant decimal digits and 10721C INFO is set to 1. There is a danger that the smaller compo- 10722C nents of X may have large relative errors, but the fast rate 10723C of convergence of SNSQE usually avoids this possibility. 10724C 10725C 10726C 5. Unsuccessful Completion. 10727C 10728C Unsuccessful termination of SNSQE can be due to improper input 10729C parameters, arithmetic interrupts, an excessive number of func- 10730C tion evaluations, errors in the functions, or lack of good prog- 10731C ress. 10732C 10733C Improper Input Parameters. INFO is set to 0 if IOPT .LT. 1, or 10734C IOPT .GT. 2, or N .LE. 0, or TOL .LT. 0.E0, or 10735C LWA .LT. (3*N**2+13*N)/2. 10736C 10737C Arithmetic Interrupts. If these interrupts occur in the FCN 10738C subroutine during an early stage of the computation, they may 10739C be caused by an unacceptable choice of X by SNSQE. In this 10740C case, it may be possible to remedy the situation by not evalu- 10741C ating the functions here, but instead setting the components 10742C of FVEC to numbers that exceed those in the initial FVEC. 10743C 10744C Excessive Number of Function Evaluations. If the number of 10745C calls to FCN reaches 100*(N+1) for IOPT=1 or 200*(N+1) for 10746C IOPT=2, then this indicates that the routine is converging 10747C very slowly as measured by the progress of FVEC, and INFO is 10748C set to 2. This situation should be unusual because, as 10749C indicated below, lack of good progress is usually diagnosed 10750C earlier by SNSQE, causing termination with INFO = 4. 10751C 10752C Errors in the Functions. When IOPT=2, the choice of step length 10753C in the forward-difference approximation to the Jacobian 10754C assumes that the relative errors in the functions are of the 10755C order of the machine precision. If this is not the case, 10756C SNSQE may fail (usually with INFO = 4). The user should 10757C then either use SNSQ and set the step length or use IOPT=1 10758C and supply the Jacobian. 10759C 10760C Lack of Good Progress. SNSQE searches for a zero of the system 10761C by minimizing the sum of the squares of the functions. In so 10762C doing, it can become trapped in a region where the minimum 10763C does not correspond to a zero of the system and, in this situ- 10764C ation, the iteration eventually fails to make good progress. 10765C In particular, this will happen if the system does not have a 10766C zero. If the system has a zero, rerunning SNSQE from a dif- 10767C ferent starting point may be helpful. 10768C 10769C 10770C 6. Characteristics of the Algorithm. 10771C 10772C SNSQE is a modification of the Powell hybrid method. Two of 10773C its main characteristics involve the choice of the correction as 10774C a convex combination of the Newton and scaled gradient direc- 10775C tions, and the updating of the Jacobian by the rank-1 method of 10776C Broyden. The choice of the correction guarantees (under reason- 10777C able conditions) global convergence for starting points far from 10778C the solution and a fast rate of convergence. The Jacobian is 10779C calculated at the starting point by either the user-supplied 10780C subroutine or a forward-difference approximation, but it is not 10781C recalculated until the rank-1 method fails to produce satis- 10782C factory progress. 10783C 10784C Timing. The time required by SNSQE to solve a given problem 10785C depends on N, the behavior of the functions, the accuracy 10786C requested, and the starting point. The number of arithmetic 10787C operations needed by SNSQE is about 11.5*(N**2) to process 10788C each evaluation of the functions (call to FCN) and 1.3*(N**3) 10789C to process each evaluation of the Jacobian (call to JAC, 10790C if IOPT = 1). Unless FCN and JAC can be evaluated quickly, 10791C the timing of SNSQE will be strongly influenced by the time 10792C spent in FCN and JAC. 10793C 10794C Storage. SNSQE requires (3*N**2 + 17*N)/2 single precision 10795C storage locations, in addition to the storage required by the 10796C program. There are no internally declared storage arrays. 10797C 10798C 10799C 7. Example. 10800C 10801C The problem is to determine the values of X(1), X(2), ..., X(9), 10802C which solve the system of tridiagonal equations 10803C 10804C (3-2*X(1))*X(1) -2*X(2) = -1 10805C -X(I-1) + (3-2*X(I))*X(I) -2*X(I+1) = -1, I=2-8 10806C -X(8) + (3-2*X(9))*X(9) = -1 10807C 10808C ********** 10809C 10810C PROGRAM TEST(INPUT,OUTPUT,TAPE6=OUTPUT) 10811C C 10812C C Driver for SNSQE example. 10813C C 10814C INTEGER J,N,IOPT,NPRINT,INFO,LWA,NWRITE 10815C REAL TOL,FNORM 10816C REAL X(9),FVEC(9),WA(180) 10817C REAL SNRM2,R1MACH 10818C EXTERNAL FCN 10819C DATA NWRITE /6/ 10820C C 10821C IOPT = 2 10822C N = 9 10823C C 10824C C The following starting values provide a rough solution. 10825C C 10826C DO 10 J = 1, 9 10827C X(J) = -1.E0 10828C 10 CONTINUE 10829C 10830C LWA = 180 10831C NPRINT = 0 10832C C 10833C C Set TOL to the square root of the machine precision. 10834C C Unless high precision solutions are required, 10835C C this is the recommended setting. 10836C C 10837C TOL = SQRT(R1MACH(4)) 10838C C 10839C CALL SNSQE(FCN,JAC,IOPT,N,X,FVEC,TOL,NPRINT,INFO,WA,LWA) 10840C FNORM = SNRM2(N,FVEC) 10841C WRITE (NWRITE,1000) FNORM,INFO,(X(J),J=1,N) 10842C STOP 10843C 1000 FORMAT (5X,' FINAL L2 NORM OF THE RESIDUALS',E15.7 // 10844C * 5X,' EXIT PARAMETER',16X,I10 // 10845C * 5X,' FINAL APPROXIMATE SOLUTION' // (5X,3E15.7)) 10846C END 10847C SUBROUTINE FCN(N,X,FVEC,IFLAG) 10848C INTEGER N,IFLAG 10849C REAL X(N),FVEC(N) 10850C INTEGER K 10851C REAL ONE,TEMP,TEMP1,TEMP2,THREE,TWO,ZERO 10852C DATA ZERO,ONE,TWO,THREE /0.E0,1.E0,2.E0,3.E0/ 10853C C 10854C DO 10 K = 1, N 10855C TEMP = (THREE - TWO*X(K))*X(K) 10856C TEMP1 = ZERO 10857C IF (K .NE. 1) TEMP1 = X(K-1) 10858C TEMP2 = ZERO 10859C IF (K .NE. N) TEMP2 = X(K+1) 10860C FVEC(K) = TEMP - TEMP1 - TWO*TEMP2 + ONE 10861C 10 CONTINUE 10862C RETURN 10863C END 10864C 10865C Results obtained with different compilers or machines 10866C may be slightly different. 10867C 10868C FINAL L2 NORM OF THE RESIDUALS 0.1192636E-07 10869C 10870C EXIT PARAMETER 1 10871C 10872C FINAL APPROXIMATE SOLUTION 10873C 10874C -0.5706545E+00 -0.6816283E+00 -0.7017325E+00 10875C -0.7042129E+00 -0.7013690E+00 -0.6918656E+00 10876C -0.6657920E+00 -0.5960342E+00 -0.4164121E+00 10877C***REFERENCES POWELL, M. J. D. 10878C A HYBRID METHOD FOR NONLINEAR EQUATIONS. 10879C NUMERICAL METHODS FOR NONLINEAR ALGEBRAIC EQUATIONS, 10880C P. RABINOWITZ, EDITOR. GORDON AND BREACH, 1970. 10881C***ROUTINES CALLED SNSQ,XERROR 10882C***END PROLOGUE SNSQE 10883 INTEGER IOPT,N,NPRINT,INFO,LWA 10884 REAL TOL 10885 REAL X(N),FVEC(N),WA(LWA),XDATA(NOBS) 10886C 10887C NOTE 12/2009: NEW INTEL 11 COMPILER BALKS ON DECLARING JAC 10888CCCCC EXTERNAL FCN,JAC 10889 EXTERNAL FCN 10890 INTEGER INDEX,J,LR,MAXFEV,ML,MODE,MU,NFEV,NJEV 10891 REAL EPSFCN,FACTOR,ONE,XTOL,ZERO 10892C 10893 INCLUDE 'DPCOMC.INC' 10894 INCLUDE 'DPCOP2.INC' 10895C 10896 DATA FACTOR,ONE,ZERO /1.0E2,1.0E0,0.0E0/ 10897C***FIRST EXECUTABLE STATEMENT SNSQE 10898 INFO = 0 10899C 10900C CHECK THE INPUT PARAMETERS FOR ERRORS. 10901C 10902 IF (IOPT .LT. 1 .OR. IOPT .GT. 2 .OR. N .LE. 0 10903 1 .OR. TOL .LT. ZERO .OR. LWA .LT. (3*N**2 +13*N)/2) 10904 2 GO TO 20 10905C 10906C CALL SNSQ. 10907C 10908 MAXFEV = 100*(N + 1) 10909 IF (IOPT .EQ. 2) MAXFEV = 2*MAXFEV 10910 XTOL = TOL 10911 ML = N - 1 10912 MU = N - 1 10913 EPSFCN = ZERO 10914 MODE = 2 10915 DO 10 J = 1, N 10916 WA(J) = ONE 10917 10 CONTINUE 10918 LR = (N*(N + 1))/2 10919 INDEX=6*N+LR 10920 CALL SNSQ(FCN,JAC,IOPT,N,X,FVEC,WA(INDEX+1),N,XTOL,MAXFEV,ML,MU, 10921 1 EPSFCN,WA(1),MODE,FACTOR,NPRINT,INFO,NFEV,NJEV, 10922 2 WA(6*N+1),LR,WA(N+1),WA(2*N+1),WA(3*N+1),WA(4*N+1), 10923 3 WA(5*N+1), 10924 4 XDATA,NOBS) 10925 IF (INFO .EQ. 5) INFO = 4 10926 20 CONTINUE 10927 IF (INFO .EQ. 0) THEN 10928CCCCC CALL XERROR( 'SNSQE -- INVALID INPUT PARAMETER.' 10929CCCCC1,34,2,1) 10930 WRITE(ICOUT,11) 10931 11 FORMAT('***** ERROR IN SNSQE NON-LINEAR SIMULTANEOUS EQUATION ', 10932 1 'SOLVER--') 10933 CALL DPWRST('XXX','BUG ') 10934 WRITE(ICOUT,13) 10935 13 FORMAT(' INVALID INPUT PARAMETER.') 10936 CALL DPWRST('XXX','BUG ') 10937 ENDIF 10938 RETURN 10939C 10940C LAST CARD OF SUBROUTINE SNSQE. 10941C 10942 END 10943 SUBROUTINE DOGLEG(N,R,LR,DIAG,QTB,DELTA,X,WA1,WA2) 10944 INTEGER N,LR 10945 REAL DELTA 10946 REAL R(LR),DIAG(N),QTB(N),X(N),WA1(N),WA2(N) 10947 INTEGER I,J,JJ,JP1,K,L 10948 REAL ALPHA,BNORM,EPSMCH,GNORM,ONE,QNORM,SGNORM,SUM,TEMP,ZERO 10949 REAL SNRM2 10950C 10951 INCLUDE 'DPCOMC.INC' 10952 INCLUDE 'DPCOP2.INC' 10953C 10954C 10955 DATA ONE,ZERO /1.0E0,0.0E0/ 10956 EPSMCH = R1MACH(4) 10957 JJ = (N*(N + 1))/2 + 1 10958 DO 50 K = 1, N 10959 J = N - K + 1 10960 JP1 = J + 1 10961 JJ = JJ - K 10962 L = JJ + 1 10963 SUM = ZERO 10964 IF (N .LT. JP1) GO TO 20 10965 DO 10 I = JP1, N 10966 SUM = SUM + R(L)*X(I) 10967 L = L + 1 10968 10 CONTINUE 10969 20 CONTINUE 10970 TEMP = R(JJ) 10971 IF (TEMP .NE. ZERO) GO TO 40 10972 L = J 10973 DO 30 I = 1, J 10974 TEMP = AMAX1(TEMP,ABS(R(L))) 10975 L = L + N - I 10976 30 CONTINUE 10977 TEMP = EPSMCH*TEMP 10978 IF (TEMP .EQ. ZERO) TEMP = EPSMCH 10979 40 CONTINUE 10980 X(J) = (QTB(J) - SUM)/TEMP 10981 50 CONTINUE 10982 DO 60 J = 1, N 10983 WA1(J) = ZERO 10984 WA2(J) = DIAG(J)*X(J) 10985 60 CONTINUE 10986 QNORM = SNRM2(N,WA2,1) 10987 IF (QNORM .LE. DELTA) GO TO 140 10988 L = 1 10989 DO 80 J = 1, N 10990 TEMP = QTB(J) 10991 DO 70 I = J, N 10992 WA1(I) = WA1(I) + R(L)*TEMP 10993 L = L + 1 10994 70 CONTINUE 10995 WA1(J) = WA1(J)/DIAG(J) 10996 80 CONTINUE 10997 GNORM = SNRM2(N,WA1,1) 10998 SGNORM = ZERO 10999 ALPHA = DELTA/QNORM 11000 IF (GNORM .EQ. ZERO) GO TO 120 11001 DO 90 J = 1, N 11002 WA1(J) = (WA1(J)/GNORM)/DIAG(J) 11003 90 CONTINUE 11004 L = 1 11005 DO 110 J = 1, N 11006 SUM = ZERO 11007 DO 100 I = J, N 11008 SUM = SUM + R(L)*WA1(I) 11009 L = L + 1 11010 100 CONTINUE 11011 WA2(J) = SUM 11012 110 CONTINUE 11013 TEMP = SNRM2(N,WA2,1) 11014 SGNORM = (GNORM/TEMP)/TEMP 11015 ALPHA = ZERO 11016 IF (SGNORM .GE. DELTA) GO TO 120 11017 BNORM = SNRM2(N,QTB,1) 11018 TEMP = (BNORM/GNORM)*(BNORM/QNORM)*(SGNORM/DELTA) 11019 TEMP = TEMP - (DELTA/QNORM)*(SGNORM/DELTA)**2 11020 1 + SQRT((TEMP-(DELTA/QNORM))**2 11021 2 +(ONE-(DELTA/QNORM)**2)*(ONE-(SGNORM/DELTA)**2)) 11022 ALPHA = ((DELTA/QNORM)*(ONE - (SGNORM/DELTA)**2))/TEMP 11023 120 CONTINUE 11024 TEMP = (ONE - ALPHA)*AMIN1(SGNORM,DELTA) 11025 DO 130 J = 1, N 11026 X(J) = TEMP*WA1(J) + ALPHA*X(J) 11027 130 CONTINUE 11028 140 CONTINUE 11029 RETURN 11030 END 11031 SUBROUTINE FDJAC1(FCN,N,X,FVEC,FJAC,LDFJAC,IFLAG,ML,MU,EPSFCN, 11032 1 WA1,WA2, 11033 1 XDATA,NOBS) 11034 INTEGER N,LDFJAC,IFLAG,ML,MU 11035 REAL EPSFCN 11036 REAL X(N),FVEC(N),FJAC(LDFJAC,N),WA1(N),WA2(N) 11037 REAL XDATA(NOBS) 11038 INTEGER I,J,K,MSUM 11039 REAL EPS,EPSMCH,H,TEMP,ZERO 11040 INCLUDE 'DPCOMC.INC' 11041 INCLUDE 'DPCOP2.INC' 11042C 11043 DATA ZERO /0.0E0/ 11044 EPSMCH = R1MACH(4) 11045 EPS = SQRT(AMAX1(EPSFCN,EPSMCH)) 11046 MSUM = ML + MU + 1 11047 IF (MSUM .LT. N) GO TO 40 11048 DO 20 J = 1, N 11049 TEMP = X(J) 11050 H = EPS*ABS(TEMP) 11051 IF (H .EQ. ZERO) H = EPS 11052 X(J) = TEMP + H 11053 CALL FCN(N,X,WA1,IFLAG,XDATA,NOBS) 11054 IF (IFLAG .LT. 0) GO TO 30 11055 X(J) = TEMP 11056 DO 10 I = 1, N 11057 FJAC(I,J) = (WA1(I) - FVEC(I))/H 11058 10 CONTINUE 11059 20 CONTINUE 11060 30 CONTINUE 11061 GO TO 110 11062 40 CONTINUE 11063 DO 90 K = 1, MSUM 11064 DO 60 J = K, N, MSUM 11065 WA2(J) = X(J) 11066 H = EPS*ABS(WA2(J)) 11067 IF (H .EQ. ZERO) H = EPS 11068 X(J) = WA2(J) + H 11069 60 CONTINUE 11070 CALL FCN(N,X,WA1,IFLAG,XDATA,NOBS) 11071 IF (IFLAG .LT. 0) GO TO 100 11072 DO 80 J = K, N, MSUM 11073 X(J) = WA2(J) 11074 H = EPS*ABS(WA2(J)) 11075 IF (H .EQ. ZERO) H = EPS 11076 DO 70 I = 1, N 11077 FJAC(I,J) = ZERO 11078 IF (I .GE. J - MU .AND. I .LE. J + ML) 11079 1 FJAC(I,J) = (WA1(I) - FVEC(I))/H 11080 70 CONTINUE 11081 80 CONTINUE 11082 90 CONTINUE 11083 100 CONTINUE 11084 110 CONTINUE 11085 RETURN 11086 END 11087 SUBROUTINE QFORM(M,N,Q,LDQ,WA) 11088 INTEGER M,N,LDQ 11089 REAL Q(LDQ,M),WA(M) 11090 INTEGER I,J,JM1,K,L,MINMN,NP1 11091 REAL ONE,SUM,TEMP,ZERO 11092 DATA ONE,ZERO /1.0E0,0.0E0/ 11093 MINMN = MIN0(M,N) 11094 IF (MINMN .LT. 2) GO TO 30 11095 DO 20 J = 2, MINMN 11096 JM1 = J - 1 11097 DO 10 I = 1, JM1 11098 Q(I,J) = ZERO 11099 10 CONTINUE 11100 20 CONTINUE 11101 30 CONTINUE 11102 NP1 = N + 1 11103 IF (M .LT. NP1) GO TO 60 11104 DO 50 J = NP1, M 11105 DO 40 I = 1, M 11106 Q(I,J) = ZERO 11107 40 CONTINUE 11108 Q(J,J) = ONE 11109 50 CONTINUE 11110 60 CONTINUE 11111 DO 120 L = 1, MINMN 11112 K = MINMN - L + 1 11113 DO 70 I = K, M 11114 WA(I) = Q(I,K) 11115 Q(I,K) = ZERO 11116 70 CONTINUE 11117 Q(K,K) = ONE 11118 IF (WA(K) .EQ. ZERO) GO TO 110 11119 DO 100 J = K, M 11120 SUM = ZERO 11121 DO 80 I = K, M 11122 SUM = SUM + Q(I,J)*WA(I) 11123 80 CONTINUE 11124 TEMP = SUM/WA(K) 11125 DO 90 I = K, M 11126 Q(I,J) = Q(I,J) - TEMP*WA(I) 11127 90 CONTINUE 11128 100 CONTINUE 11129 110 CONTINUE 11130 120 CONTINUE 11131 RETURN 11132 END 11133 SUBROUTINE QRFAC(M,N,A,LDA,PIVOT,IPVT,LIPVT,SIGMA,ACNORM,WA) 11134 INTEGER M,N,LDA,LIPVT 11135 INTEGER IPVT(LIPVT) 11136 LOGICAL PIVOT 11137 REAL A(LDA,N),SIGMA(N),ACNORM(N),WA(N) 11138 INTEGER I,J,JP1,K,KMAX,MINMN 11139 REAL AJNORM,EPSMCH,ONE,P05,SUM,TEMP,ZERO 11140 REAL SNRM2 11141 INCLUDE 'DPCOMC.INC' 11142 INCLUDE 'DPCOP2.INC' 11143C 11144 DATA ONE,P05,ZERO /1.0E0,5.0E-2,0.0E0/ 11145 EPSMCH = R1MACH(4) 11146 DO 10 J = 1, N 11147 ACNORM(J) = SNRM2(M,A(1,J),1) 11148 SIGMA(J) = ACNORM(J) 11149 WA(J) = SIGMA(J) 11150 IF (PIVOT) IPVT(J) = J 11151 10 CONTINUE 11152 MINMN = MIN0(M,N) 11153 DO 110 J = 1, MINMN 11154 IF (.NOT.PIVOT) GO TO 40 11155 KMAX = J 11156 DO 20 K = J, N 11157 IF (SIGMA(K) .GT. SIGMA(KMAX)) KMAX = K 11158 20 CONTINUE 11159 IF (KMAX .EQ. J) GO TO 40 11160 DO 30 I = 1, M 11161 TEMP = A(I,J) 11162 A(I,J) = A(I,KMAX) 11163 A(I,KMAX) = TEMP 11164 30 CONTINUE 11165 SIGMA(KMAX) = SIGMA(J) 11166 WA(KMAX) = WA(J) 11167 K = IPVT(J) 11168 IPVT(J) = IPVT(KMAX) 11169 IPVT(KMAX) = K 11170 40 CONTINUE 11171 AJNORM = SNRM2(M-J+1,A(J,J),1) 11172 IF (AJNORM .EQ. ZERO) GO TO 100 11173 IF (A(J,J) .LT. ZERO) AJNORM = -AJNORM 11174 DO 50 I = J, M 11175 A(I,J) = A(I,J)/AJNORM 11176 50 CONTINUE 11177 A(J,J) = A(J,J) + ONE 11178 JP1 = J + 1 11179 IF (N .LT. JP1) GO TO 100 11180 DO 90 K = JP1, N 11181 SUM = ZERO 11182 DO 60 I = J, M 11183 SUM = SUM + A(I,J)*A(I,K) 11184 60 CONTINUE 11185 TEMP = SUM/A(J,J) 11186 DO 70 I = J, M 11187 A(I,K) = A(I,K) - TEMP*A(I,J) 11188 70 CONTINUE 11189 IF (.NOT.PIVOT .OR. SIGMA(K) .EQ. ZERO) GO TO 80 11190 TEMP = A(J,K)/SIGMA(K) 11191 SIGMA(K) = SIGMA(K)*SQRT(AMAX1(ZERO,ONE-TEMP**2)) 11192 IF (P05*(SIGMA(K)/WA(K))**2 .GT. EPSMCH) GO TO 80 11193 SIGMA(K) = SNRM2(M-J,A(JP1,K),1) 11194 WA(K) = SIGMA(K) 11195 80 CONTINUE 11196 90 CONTINUE 11197 100 CONTINUE 11198 SIGMA(J) = -AJNORM 11199 110 CONTINUE 11200 RETURN 11201 END 11202 SUBROUTINE R1MPYQ(M,N,A,LDA,V,W) 11203 INTEGER M,N,LDA 11204 REAL A(LDA,N),V(N),W(N) 11205 INTEGER I,J,NMJ,NM1 11206 REAL COS,ONE,SIN,TEMP 11207 DATA ONE /1.0E0/ 11208C 11209 COS=0.0 11210 SIN=0.0 11211C 11212 NM1 = N - 1 11213 IF (NM1 .LT. 1) GO TO 50 11214 DO 20 NMJ = 1, NM1 11215 J = N - NMJ 11216 IF (ABS(V(J)) .GT. ONE) COS = ONE/V(J) 11217 IF (ABS(V(J)) .GT. ONE) SIN = SQRT(ONE-COS**2) 11218 IF (ABS(V(J)) .LE. ONE) SIN = V(J) 11219 IF (ABS(V(J)) .LE. ONE) COS = SQRT(ONE-SIN**2) 11220 DO 10 I = 1, M 11221 TEMP = COS*A(I,J) - SIN*A(I,N) 11222 A(I,N) = SIN*A(I,J) + COS*A(I,N) 11223 A(I,J) = TEMP 11224 10 CONTINUE 11225 20 CONTINUE 11226 DO 40 J = 1, NM1 11227 IF (ABS(W(J)) .GT. ONE) COS = ONE/W(J) 11228 IF (ABS(W(J)) .GT. ONE) SIN = SQRT(ONE-COS**2) 11229 IF (ABS(W(J)) .LE. ONE) SIN = W(J) 11230 IF (ABS(W(J)) .LE. ONE) COS = SQRT(ONE-SIN**2) 11231 DO 30 I = 1, M 11232 TEMP = COS*A(I,J) + SIN*A(I,N) 11233 A(I,N) = -SIN*A(I,J) + COS*A(I,N) 11234 A(I,J) = TEMP 11235 30 CONTINUE 11236 40 CONTINUE 11237 50 CONTINUE 11238 RETURN 11239 END 11240 SUBROUTINE R1UPDT(M,N,S,LS,U,V,W,SING) 11241 INTEGER M,N,LS 11242 LOGICAL SING 11243 REAL S(LS),U(M),V(N),W(M) 11244 INTEGER I,J,JJ,L,NMJ,NM1 11245 REAL COS,COTAN,GIANT,ONE,P5,P25,SIN,TAN,TAU,TEMP,ZERO 11246C 11247 INCLUDE 'DPCOMC.INC' 11248 INCLUDE 'DPCOP2.INC' 11249C 11250 DATA ONE,P5,P25,ZERO /1.0E0,5.0E-1,2.5E-1,0.0E0/ 11251 GIANT = R1MACH(2) 11252 JJ = (N*(2*M - N + 1))/2 - (M - N) 11253 L = JJ 11254 DO 10 I = N, M 11255 W(I) = S(L) 11256 L = L + 1 11257 10 CONTINUE 11258 NM1 = N - 1 11259 IF (NM1 .LT. 1) GO TO 70 11260 DO 60 NMJ = 1, NM1 11261 J = N - NMJ 11262 JJ = JJ - (M - J + 1) 11263 W(J) = ZERO 11264 IF (V(J) .EQ. ZERO) GO TO 50 11265 IF (ABS(V(N)) .GE. ABS(V(J))) GO TO 20 11266 COTAN = V(N)/V(J) 11267 SIN = P5/SQRT(P25+P25*COTAN**2) 11268 COS = SIN*COTAN 11269 TAU = ONE 11270 IF (ABS(COS)*GIANT .GT. ONE) TAU = ONE/COS 11271 GO TO 30 11272 20 CONTINUE 11273 TAN = V(J)/V(N) 11274 COS = P5/SQRT(P25+P25*TAN**2) 11275 SIN = COS*TAN 11276 TAU = SIN 11277 30 CONTINUE 11278 V(N) = SIN*V(J) + COS*V(N) 11279 V(J) = TAU 11280 L = JJ 11281 DO 40 I = J, M 11282 TEMP = COS*S(L) - SIN*W(I) 11283 W(I) = SIN*S(L) + COS*W(I) 11284 S(L) = TEMP 11285 L = L + 1 11286 40 CONTINUE 11287 50 CONTINUE 11288 60 CONTINUE 11289 70 CONTINUE 11290 DO 80 I = 1, M 11291 W(I) = W(I) + V(N)*U(I) 11292 80 CONTINUE 11293 SING = .FALSE. 11294 IF (NM1 .LT. 1) GO TO 140 11295 DO 130 J = 1, NM1 11296 IF (W(J) .EQ. ZERO) GO TO 120 11297 IF (ABS(S(JJ)) .GE. ABS(W(J))) GO TO 90 11298 COTAN = S(JJ)/W(J) 11299 SIN = P5/SQRT(P25+P25*COTAN**2) 11300 COS = SIN*COTAN 11301 TAU = ONE 11302 IF (ABS(COS)*GIANT .GT. ONE) TAU = ONE/COS 11303 GO TO 100 11304 90 CONTINUE 11305 TAN = W(J)/S(JJ) 11306 COS = P5/SQRT(P25+P25*TAN**2) 11307 SIN = COS*TAN 11308 TAU = SIN 11309 100 CONTINUE 11310 L = JJ 11311 DO 110 I = J, M 11312 TEMP = COS*S(L) + SIN*W(I) 11313 W(I) = -SIN*S(L) + COS*W(I) 11314 S(L) = TEMP 11315 L = L + 1 11316 110 CONTINUE 11317 W(J) = TAU 11318 120 CONTINUE 11319 IF (S(JJ) .EQ. ZERO) SING = .TRUE. 11320 JJ = JJ + (M - J + 1) 11321 130 CONTINUE 11322 140 CONTINUE 11323 L = JJ 11324 DO 150 I = N, M 11325 S(L) = W(I) 11326 L = L + 1 11327 150 CONTINUE 11328 IF (S(JJ) .EQ. ZERO) SING = .TRUE. 11329 RETURN 11330 END 11331 SUBROUTINE SNSQ(FCN,JAC,IOPT,N,X,FVEC,FJAC,LDFJAC,XTOL,MAXFEV,ML, 11332 1 MU,EPSFCN,DIAG,MODE,FACTOR,NPRINT,INFO,NFEV,NJEV,R,LR,QTF,WA1, 11333 2 WA2,WA3,WA4, 11334 3 XDATA,NOBS) 11335 INTEGER IOPT,N,MAXFEV,ML,MU,MODE,NPRINT,INFO,NFEV,LDFJAC,LR,NJEV 11336 REAL XTOL,EPSFCN,FACTOR 11337 REAL X(N),FVEC(N),DIAG(N),FJAC(LDFJAC,N),R(LR),QTF(N),WA1(N), 11338 1 WA2(N),WA3(N),WA4(N) 11339 REAL XDATA(NOBS) 11340 EXTERNAL FCN 11341 INTEGER I,IFLAG,ITER,J,JM1,L,NCFAIL,NCSUC,NSLOW1,NSLOW2 11342 INTEGER IWA(1) 11343 LOGICAL JEVAL,SING 11344 REAL ACTRED,DELTA,EPSMCH,FNORM,FNORM1,ONE,PNORM,PRERED,P1,P5, 11345 1 P001,P0001,RATIO,SUM,TEMP,XNORM,ZERO 11346 REAL SNRM2 11347C 11348 INCLUDE 'DPCOMC.INC' 11349 INCLUDE 'DPCOP2.INC' 11350C 11351 DATA ONE,P1,P5,P001,P0001,ZERO 11352 1 /1.0E0,1.0E-1,5.0E-1,1.0E-3,1.0E-4,0.0E0/ 11353 XNORM = 0.0 11354 EPSMCH = R1MACH(4) 11355 INFO = 0 11356 IFLAG = 0 11357 NFEV = 0 11358 NJEV = 0 11359 IF (IOPT .LT. 1 .OR. IOPT .GT. 2 .OR. 11360 1 N .LE. 0 .OR. XTOL .LT. ZERO .OR. MAXFEV .LE. 0 11361 2 .OR. ML .LT. 0 .OR. MU .LT. 0 .OR. FACTOR .LE. ZERO 11362 3 .OR. LDFJAC .LT. N .OR. LR .LT. (N*(N + 1))/2) GO TO 300 11363 IF (MODE .NE. 2) GO TO 20 11364 DO 10 J = 1, N 11365 IF (DIAG(J) .LE. ZERO) GO TO 300 11366 10 CONTINUE 11367 20 CONTINUE 11368 IFLAG = 1 11369 CALL FCN(N,X,FVEC,IFLAG,XDATA,NOBS) 11370 NFEV = 1 11371 IF (IFLAG .LT. 0) GO TO 300 11372 FNORM = SNRM2(N,FVEC,1) 11373 ITER = 1 11374 NCSUC = 0 11375 NCFAIL = 0 11376 NSLOW1 = 0 11377 NSLOW2 = 0 11378 30 CONTINUE 11379 JEVAL = .TRUE. 11380 IF (IOPT .EQ. 2) GO TO 31 11381CCCCC CALL JAC(N,X,FVEC,FJAC,LDFJAC,IFLAG) 11382 NJEV = NJEV+1 11383 GO TO 32 11384 31 IFLAG = 2 11385 CALL FDJAC1(FCN,N,X,FVEC,FJAC,LDFJAC,IFLAG,ML,MU,EPSFCN,WA1, 11386 1 WA2, 11387 2 XDATA,NOBS) 11388 NFEV = NFEV + MIN0(ML+MU+1,N) 11389 32 IF (IFLAG .LT. 0) GO TO 300 11390 CALL QRFAC(N,N,FJAC,LDFJAC,.FALSE.,IWA,1,WA1,WA2,WA3) 11391 IF (ITER .NE. 1) GO TO 70 11392 IF (MODE .EQ. 2) GO TO 50 11393 DO 40 J = 1, N 11394 DIAG(J) = WA2(J) 11395 IF (WA2(J) .EQ. ZERO) DIAG(J) = ONE 11396 40 CONTINUE 11397 50 CONTINUE 11398 DO 60 J = 1, N 11399 WA3(J) = DIAG(J)*X(J) 11400 60 CONTINUE 11401 XNORM = SNRM2(N,WA3,1) 11402 DELTA = FACTOR*XNORM 11403 IF (DELTA .EQ. ZERO) DELTA = FACTOR 11404 70 CONTINUE 11405 DO 80 I = 1, N 11406 QTF(I) = FVEC(I) 11407 80 CONTINUE 11408 DO 120 J = 1, N 11409 IF (FJAC(J,J) .EQ. ZERO) GO TO 110 11410 SUM = ZERO 11411 DO 90 I = J, N 11412 SUM = SUM + FJAC(I,J)*QTF(I) 11413 90 CONTINUE 11414 TEMP = -SUM/FJAC(J,J) 11415 DO 100 I = J, N 11416 QTF(I) = QTF(I) + FJAC(I,J)*TEMP 11417 100 CONTINUE 11418 110 CONTINUE 11419 120 CONTINUE 11420 SING = .FALSE. 11421 DO 150 J = 1, N 11422 L = J 11423 JM1 = J - 1 11424 IF (JM1 .LT. 1) GO TO 140 11425 DO 130 I = 1, JM1 11426 R(L) = FJAC(I,J) 11427 L = L + N - I 11428 130 CONTINUE 11429 140 CONTINUE 11430 R(L) = WA1(J) 11431 IF (WA1(J) .EQ. ZERO) SING = .TRUE. 11432 150 CONTINUE 11433 CALL QFORM(N,N,FJAC,LDFJAC,WA1) 11434 IF (MODE .EQ. 2) GO TO 170 11435 DO 160 J = 1, N 11436 DIAG(J) = AMAX1(DIAG(J),WA2(J)) 11437 160 CONTINUE 11438 170 CONTINUE 11439 180 CONTINUE 11440 IF (NPRINT .LE. 0) GO TO 190 11441 IFLAG = 0 11442 IF (MOD(ITER-1,NPRINT) .EQ. 0) 11443 1 CALL FCN(N,X,FVEC,IFLAG,XDATA,NOBS) 11444 IF (IFLAG .LT. 0) GO TO 300 11445 190 CONTINUE 11446 CALL DOGLEG(N,R,LR,DIAG,QTF,DELTA,WA1,WA2,WA3) 11447 DO 200 J = 1, N 11448 WA1(J) = -WA1(J) 11449 WA2(J) = X(J) + WA1(J) 11450 WA3(J) = DIAG(J)*WA1(J) 11451 200 CONTINUE 11452 PNORM = SNRM2(N,WA3,1) 11453 IF (ITER .EQ. 1) DELTA = AMIN1(DELTA,PNORM) 11454 IFLAG = 1 11455 CALL FCN(N,WA2,WA4,IFLAG,XDATA,NOBS) 11456 NFEV = NFEV + 1 11457 IF (IFLAG .LT. 0) GO TO 300 11458 FNORM1 = SNRM2(N,WA4,1) 11459 ACTRED = -ONE 11460 IF (FNORM1 .LT. FNORM) ACTRED = ONE - (FNORM1/FNORM)**2 11461 L = 1 11462 DO 220 I = 1, N 11463 SUM = ZERO 11464 DO 210 J = I, N 11465 SUM = SUM + R(L)*WA1(J) 11466 L = L + 1 11467 210 CONTINUE 11468 WA3(I) = QTF(I) + SUM 11469 220 CONTINUE 11470 TEMP = SNRM2(N,WA3,1) 11471 PRERED = ZERO 11472 IF (TEMP .LT. FNORM) PRERED = ONE - (TEMP/FNORM)**2 11473 RATIO = ZERO 11474 IF (PRERED .GT. ZERO) RATIO = ACTRED/PRERED 11475 IF (RATIO .GE. P1) GO TO 230 11476 NCSUC = 0 11477 NCFAIL = NCFAIL + 1 11478 DELTA = P5*DELTA 11479 GO TO 240 11480 230 CONTINUE 11481 NCFAIL = 0 11482 NCSUC = NCSUC + 1 11483 IF (RATIO .GE. P5 .OR. NCSUC .GT. 1) 11484 1 DELTA = AMAX1(DELTA,PNORM/P5) 11485 IF (ABS(RATIO-ONE) .LE. P1) DELTA = PNORM/P5 11486 240 CONTINUE 11487 IF (RATIO .LT. P0001) GO TO 260 11488 DO 250 J = 1, N 11489 X(J) = WA2(J) 11490 WA2(J) = DIAG(J)*X(J) 11491 FVEC(J) = WA4(J) 11492 250 CONTINUE 11493 XNORM = SNRM2(N,WA2,1) 11494 FNORM = FNORM1 11495 ITER = ITER + 1 11496 260 CONTINUE 11497 NSLOW1 = NSLOW1 + 1 11498 IF (ACTRED .GE. P001) NSLOW1 = 0 11499 IF (JEVAL) NSLOW2 = NSLOW2 + 1 11500 IF (ACTRED .GE. P1) NSLOW2 = 0 11501 IF (DELTA .LE. XTOL*XNORM .OR. FNORM .EQ. ZERO) INFO = 1 11502 IF (INFO .NE. 0) GO TO 300 11503 IF (NFEV .GE. MAXFEV) INFO = 2 11504 IF (P1*AMAX1(P1*DELTA,PNORM) .LE. EPSMCH*XNORM) INFO = 3 11505 IF (NSLOW2 .EQ. 5) INFO = 4 11506 IF (NSLOW1 .EQ. 10) INFO = 5 11507 IF (INFO .NE. 0) GO TO 300 11508 IF (NCFAIL .EQ. 2) GO TO 290 11509 DO 280 J = 1, N 11510 SUM = ZERO 11511 DO 270 I = 1, N 11512 SUM = SUM + FJAC(I,J)*WA4(I) 11513 270 CONTINUE 11514 WA2(J) = (SUM - WA3(J))/PNORM 11515 WA1(J) = DIAG(J)*((DIAG(J)*WA1(J))/PNORM) 11516 IF (RATIO .GE. P0001) QTF(J) = SUM 11517 280 CONTINUE 11518 CALL R1UPDT(N,N,R,LR,WA1,WA2,WA3,SING) 11519 CALL R1MPYQ(N,N,FJAC,LDFJAC,WA2,WA3) 11520 CALL R1MPYQ(1,N,QTF,1,WA2,WA3) 11521 JEVAL = .FALSE. 11522 GO TO 180 11523 290 CONTINUE 11524 GO TO 30 11525 300 CONTINUE 11526 IF (IFLAG .LT. 0) INFO = IFLAG 11527 IFLAG = 0 11528 IF (NPRINT .GT. 0) CALL FCN(N,X,FVEC,IFLAG,XDATA,NOBS) 11529C 11530C ERROR SECTION 11531C 11532 IF (INFO .LT. 0) THEN 11533CCCCC CALL XERROR( 'SNSQ -- EXECUTION TERMINATED BECA 11534CCCCC1USE USER SET IFLAG NEGATIVE.',63,1,1) 11535 WRITE(ICOUT,1001) 11536 1001 FORMAT('***** ERROR IN SNSQE NON-LINEAR SIMULTANEOUS EQUATION ', 11537 1 'SOLVER--') 11538 CALL DPWRST('XXX','BUG ') 11539 WRITE(ICOUT,1003) 11540 1003 FORMAT(' TERMINATION HALTED BECAUSE IFLAG IS NEGATIVE.') 11541 CALL DPWRST('XXX','BUG ') 11542 ENDIF 11543 IF (INFO .EQ. 0) THEN 11544CCCCC CALL XERROR( 'SNSQ -- INVALID INPUT PARAMETER.',34,2,1) 11545 WRITE(ICOUT,1001) 11546 CALL DPWRST('XXX','BUG ') 11547 WRITE(ICOUT,1004) 11548 1004 FORMAT(' INVALID INPUT PARAMETER.') 11549 CALL DPWRST('XXX','BUG ') 11550 ENDIF 11551 IF (INFO .EQ. 2) THEN 11552CCCCC CALL XERROR( 'SNSQ -- TOO MANY FUNCTION EVALUATIONS.',40,9,1) 11553 WRITE(ICOUT,1001) 11554 CALL DPWRST('XXX','BUG ') 11555 WRITE(ICOUT,1005) 11556 1005 FORMAT(' TOO MANY FUNCTION EVALUATIONS.') 11557 CALL DPWRST('XXX','BUG ') 11558 ENDIF 11559 IF (INFO .EQ. 3) THEN 11560CCCCC CALL XERROR( 'SNSQ -- XTOL TOO SMALL. NO FURTHE 11561CCCCC1R IMPROVEMENT POSSIBLE.',58,3,1) 11562 WRITE(ICOUT,1001) 11563 CALL DPWRST('XXX','BUG ') 11564 WRITE(ICOUT,1006) 11565 1006 FORMAT(' XTOL TOO SMALL. NO FURTHER IMPROVEMENT ', 11566 1 'POSSIBLE.') 11567 CALL DPWRST('XXX','BUG ') 11568 ENDIF 11569 IF (INFO .GT. 4) THEN 11570CCCCC CALL XERROR( 'SNSQ -- ITERATION NOT MAKING GOOD 11571CCCCC1 PROGRESS.',45,1,1) 11572 WRITE(ICOUT,1001) 11573 CALL DPWRST('XXX','BUG ') 11574 WRITE(ICOUT,1007) 11575 1007 FORMAT(' ITERATION NOT MAKING GOOD PROGRESS.') 11576 CALL DPWRST('XXX','BUG ') 11577 ENDIF 11578C 11579 RETURN 11580 END 11581*DECK DNSQE 11582 SUBROUTINE DNSQE (FCN, JAC, IOPT, N, X, FVEC, TOL, NPRINT, INFO, 11583 + WA, LWA, 11584 + XDATA,NOBS) 11585C***BEGIN PROLOGUE DNSQE 11586C***PURPOSE An easy-to-use code to find a zero of a system of N 11587C nonlinear functions in N variables by a modification of 11588C the Powell hybrid method. 11589C***LIBRARY SLATEC 11590C***CATEGORY F2A 11591C***TYPE DOUBLE PRECISION (SNSQE-S, DNSQE-D) 11592C***KEYWORDS EASY-TO-USE, NONLINEAR SQUARE SYSTEM, 11593C POWELL HYBRID METHOD, ZEROS 11594C***AUTHOR Hiebert, K. L. (SNLA) 11595C***DESCRIPTION 11596C 11597C 1. Purpose. 11598C 11599C The purpose of DNSQE is to find a zero of a system of N 11600C nonlinear functions in N variables by a modification of the 11601C Powell hybrid method. This is done by using the more general 11602C nonlinear equation solver DNSQ. The user must provide a 11603C subroutine which calculates the functions. The user has the 11604C option of either to provide a subroutine which calculates the 11605C Jacobian or to let the code calculate it by a forward-difference 11606C approximation. This code is the combination of the MINPACK 11607C codes (Argonne) HYBRD1 and HYBRJ1. 11608C 11609C 2. Subroutine and Type Statements. 11610C 11611C SUBROUTINE DNSQE(FCN,JAC,IOPT,N,X,FVEC,TOL,NPRINT,INFO, 11612C * WA,LWA) 11613C INTEGER IOPT,N,NPRINT,INFO,LWA 11614C DOUBLE PRECISION TOL 11615C DOUBLE PRECISION X(N),FVEC(N),WA(LWA) 11616C EXTERNAL FCN,JAC 11617C 11618C 3. Parameters. 11619C 11620C Parameters designated as input parameters must be specified on 11621C entry to DNSQE and are not changed on exit, while parameters 11622C designated as output parameters need not be specified on entry 11623C and are set to appropriate values on exit from DNSQE. 11624C 11625C FCN is the name of the user-supplied subroutine which calculates 11626C the functions. FCN must be declared in an external statement 11627C in the user calling program, and should be written as follows. 11628C 11629C SUBROUTINE FCN(N,X,FVEC,IFLAG) 11630C INTEGER N,IFLAG 11631C DOUBLE PRECISION X(N),FVEC(N) 11632C ---------- 11633C Calculate the functions at X and 11634C return this vector in FVEC. 11635C ---------- 11636C RETURN 11637C END 11638C 11639C The value of IFLAG should not be changed by FCN unless the 11640C user wants to terminate execution of DNSQE. In this case set 11641C IFLAG to a negative integer. 11642C 11643C JAC is the name of the user-supplied subroutine which calculates 11644C the Jacobian. If IOPT=1, then JAC must be declared in an 11645C external statement in the user calling program, and should be 11646C written as follows. 11647C 11648C SUBROUTINE JAC(N,X,FVEC,FJAC,LDFJAC,IFLAG) 11649C INTEGER N,LDFJAC,IFLAG 11650C DOUBLE PRECISION X(N),FVEC(N),FJAC(LDFJAC,N) 11651C ---------- 11652C Calculate the Jacobian at X and return this 11653C matrix in FJAC. FVEC contains the function 11654C values at X and should not be altered. 11655C ---------- 11656C RETURN 11657C END 11658C 11659C The value of IFLAG should not be changed by JAC unless the 11660C user wants to terminate execution of DNSQE. In this case set 11661C IFLAG to a negative integer. 11662C 11663C If IOPT=2, JAC can be ignored (treat it as a dummy argument). 11664C 11665C IOPT is an input variable which specifies how the Jacobian will 11666C be calculated. If IOPT=1, then the user must supply the 11667C Jacobian through the subroutine JAC. If IOPT=2, then the 11668C code will approximate the Jacobian by forward-differencing. 11669C 11670C N is a positive integer input variable set to the number of 11671C functions and variables. 11672C 11673C X is an array of length N. On input X must contain an initial 11674C estimate of the solution vector. On output X contains the 11675C final estimate of the solution vector. 11676C 11677C FVEC is an output array of length N which contains the functions 11678C evaluated at the output X. 11679C 11680C TOL is a nonnegative input variable. Termination occurs when 11681C the algorithm estimates that the relative error between X and 11682C the solution is at most TOL. Section 4 contains more details 11683C about TOL. 11684C 11685C NPRINT is an integer input variable that enables controlled 11686C printing of iterates if it is positive. In this case, FCN is 11687C called with IFLAG = 0 at the beginning of the first iteration 11688C and every NPRINT iterations thereafter and immediately prior 11689C to return, with X and FVEC available for printing. Appropriate 11690C print statements must be added to FCN(see example). If NPRINT 11691C is not positive, no special calls of FCN with IFLAG = 0 are 11692C made. 11693C 11694C INFO is an integer output variable. If the user has terminated 11695C execution, INFO is set to the (negative) value of IFLAG. See 11696C description of FCN and JAC. Otherwise, INFO is set as follows. 11697C 11698C INFO = 0 Improper input parameters. 11699C 11700C INFO = 1 Algorithm estimates that the relative error between 11701C X and the solution is at most TOL. 11702C 11703C INFO = 2 Number of calls to FCN has reached or exceeded 11704C 100*(N+1) for IOPT=1 or 200*(N+1) for IOPT=2. 11705C 11706C INFO = 3 TOL is too small. No further improvement in the 11707C approximate solution X is possible. 11708C 11709C INFO = 4 Iteration is not making good progress. 11710C 11711C Sections 4 and 5 contain more details about INFO. 11712C 11713C WA is a work array of length LWA. 11714C 11715C LWA is a positive integer input variable not less than 11716C (3*N**2+13*N))/2. 11717C 11718C 4. Successful Completion. 11719C 11720C The accuracy of DNSQE is controlled by the convergence parameter 11721C TOL. This parameter is used in a test which makes a comparison 11722C between the approximation X and a solution XSOL. DNSQE 11723C terminates when the test is satisfied. If TOL is less than the 11724C machine precision (as defined by the function D1MACH(4)), then 11725C DNSQE only attempts to satisfy the test defined by the machine 11726C precision. Further progress is not usually possible. Unless 11727C high precision solutions are required, the recommended value 11728C for TOL is the square root of the machine precision. 11729C 11730C The test assumes that the functions are reasonably well behaved, 11731C and, if the Jacobian is supplied by the user, that the functions 11732C and the Jacobian are coded consistently. If these conditions are 11733C not satisfied, then DNSQE may incorrectly indicate convergence. 11734C The coding of the Jacobian can be checked by the subroutine 11735C DCKDER. If the Jacobian is coded correctly or IOPT=2, then 11736C the validity of the answer can be checked, for example, by 11737C rerunning DNSQE with a tighter tolerance. 11738C 11739C Convergence Test. If DENORM(Z) denotes the Euclidean norm of a 11740C vector Z, then this test attempts to guarantee that 11741C 11742C DENORM(X-XSOL) .LE. TOL*DENORM(XSOL). 11743C 11744C If this condition is satisfied with TOL = 10**(-K), then the 11745C larger components of X have K significant decimal digits and 11746C INFO is set to 1. There is a danger that the smaller 11747C components of X may have large relative errors, but the fast 11748C rate of convergence of DNSQE usually avoids this possibility. 11749C 11750C 5. Unsuccessful Completion. 11751C 11752C Unsuccessful termination of DNSQE can be due to improper input 11753C parameters, arithmetic interrupts, an excessive number of 11754C function evaluations, errors in the functions, or lack of good 11755C progress. 11756C 11757C Improper Input Parameters. INFO is set to 0 if IOPT .LT. 1, or 11758C IOPT .GT. 2, or N .LE. 0, or TOL .LT. 0.E0, or 11759C LWA .LT. (3*N**2+13*N)/2. 11760C 11761C Arithmetic Interrupts. If these interrupts occur in the FCN 11762C subroutine during an early stage of the computation, they may 11763C be caused by an unacceptable choice of X by DNSQE. In this 11764C case, it may be possible to remedy the situation by not 11765C evaluating the functions here, but instead setting the 11766C components of FVEC to numbers that exceed those in the initial 11767C FVEC. 11768C 11769C Excessive Number of Function Evaluations. If the number of 11770C calls to FCN reaches 100*(N+1) for IOPT=1 or 200*(N+1) for 11771C IOPT=2, then this indicates that the routine is converging 11772C very slowly as measured by the progress of FVEC, and INFO is 11773C set to 2. This situation should be unusual because, as 11774C indicated below, lack of good progress is usually diagnosed 11775C earlier by DNSQE, causing termination with INFO = 4. 11776C 11777C Errors In the Functions. When IOPT=2, the choice of step length 11778C in the forward-difference approximation to the Jacobian 11779C assumes that the relative errors in the functions are of the 11780C order of the machine precision. If this is not the case, 11781C DNSQE may fail (usually with INFO = 4). The user should 11782C then either use DNSQ and set the step length or use IOPT=1 11783C and supply the Jacobian. 11784C 11785C Lack of Good Progress. DNSQE searches for a zero of the system 11786C by minimizing the sum of the squares of the functions. In so 11787C doing, it can become trapped in a region where the minimum 11788C does not correspond to a zero of the system and, in this 11789C situation, the iteration eventually fails to make good 11790C progress. In particular, this will happen if the system does 11791C not have a zero. If the system has a zero, rerunning DNSQE 11792C from a different starting point may be helpful. 11793C 11794C 6. Characteristics of The Algorithm. 11795C 11796C DNSQE is a modification of the Powell Hybrid method. Two of 11797C its main characteristics involve the choice of the correction as 11798C a convex combination of the Newton and scaled gradient 11799C directions, and the updating of the Jacobian by the rank-1 11800C method of Broyden. The choice of the correction guarantees 11801C (under reasonable conditions) global convergence for starting 11802C points far from the solution and a fast rate of convergence. 11803C The Jacobian is calculated at the starting point by either the 11804C user-supplied subroutine or a forward-difference approximation, 11805C but it is not recalculated until the rank-1 method fails to 11806C produce satisfactory progress. 11807C 11808C Timing. The time required by DNSQE to solve a given problem 11809C depends on N, the behavior of the functions, the accuracy 11810C requested, and the starting point. The number of arithmetic 11811C operations needed by DNSQE is about 11.5*(N**2) to process 11812C each evaluation of the functions (call to FCN) and 1.3*(N**3) 11813C to process each evaluation of the Jacobian (call to JAC, 11814C if IOPT = 1). Unless FCN and JAC can be evaluated quickly, 11815C the timing of DNSQE will be strongly influenced by the time 11816C spent in FCN and JAC. 11817C 11818C Storage. DNSQE requires (3*N**2 + 17*N)/2 single precision 11819C storage locations, in addition to the storage required by the 11820C program. There are no internally declared storage arrays. 11821C 11822C *Long Description: 11823C 11824C 7. Example. 11825C 11826C The problem is to determine the values of X(1), X(2), ..., X(9), 11827C which solve the system of tridiagonal equations 11828C 11829C (3-2*X(1))*X(1) -2*X(2) = -1 11830C -X(I-1) + (3-2*X(I))*X(I) -2*X(I+1) = -1, I=2-8 11831C -X(8) + (3-2*X(9))*X(9) = -1 11832C 11833C ********** 11834C 11835C PROGRAM TEST 11836C C 11837C C DRIVER FOR DNSQE EXAMPLE. 11838C C 11839C INTEGER J,N,IOPT,NPRINT,INFO,LWA,NWRITE 11840C DOUBLE PRECISION TOL,FNORM 11841C DOUBLE PRECISION X(9),FVEC(9),WA(180) 11842C DOUBLE PRECISION DENORM,D1MACH 11843C EXTERNAL FCN 11844C DATA NWRITE /6/ 11845C C 11846C IOPT = 2 11847C N = 9 11848C C 11849C C THE FOLLOWING STARTING VALUES PROVIDE A ROUGH SOLUTION. 11850C C 11851C DO 10 J = 1, 9 11852C X(J) = -1.E0 11853C 10 CONTINUE 11854C 11855C LWA = 180 11856C NPRINT = 0 11857C C 11858C C SET TOL TO THE SQUARE ROOT OF THE MACHINE PRECISION. 11859C C UNLESS HIGH PRECISION SOLUTIONS ARE REQUIRED, 11860C C THIS IS THE RECOMMENDED SETTING. 11861C C 11862C TOL = SQRT(D1MACH(4)) 11863C C 11864C CALL DNSQE(FCN,JAC,IOPT,N,X,FVEC,TOL,NPRINT,INFO,WA,LWA) 11865C FNORM = DENORM(N,FVEC) 11866C WRITE (NWRITE,1000) FNORM,INFO,(X(J),J=1,N) 11867C STOP 11868C 1000 FORMAT (5X,' FINAL L2 NORM OF THE RESIDUALS',E15.7 // 11869C * 5X,' EXIT PARAMETER',16X,I10 // 11870C * 5X,' FINAL APPROXIMATE SOLUTION' // (5X,3E15.7)) 11871C END 11872C SUBROUTINE FCN(N,X,FVEC,IFLAG) 11873C INTEGER N,IFLAG 11874C DOUBLE PRECISION X(N),FVEC(N) 11875C INTEGER K 11876C DOUBLE PRECISION ONE,TEMP,TEMP1,TEMP2,THREE,TWO,ZERO 11877C DATA ZERO,ONE,TWO,THREE /0.E0,1.E0,2.E0,3.E0/ 11878C C 11879C DO 10 K = 1, N 11880C TEMP = (THREE - TWO*X(K))*X(K) 11881C TEMP1 = ZERO 11882C IF (K .NE. 1) TEMP1 = X(K-1) 11883C TEMP2 = ZERO 11884C IF (K .NE. N) TEMP2 = X(K+1) 11885C FVEC(K) = TEMP - TEMP1 - TWO*TEMP2 + ONE 11886C 10 CONTINUE 11887C RETURN 11888C END 11889C 11890C RESULTS OBTAINED WITH DIFFERENT COMPILERS OR MACHINES 11891C MAY BE SLIGHTLY DIFFERENT. 11892C 11893C FINAL L2 NORM OF THE RESIDUALS 0.1192636E-07 11894C 11895C EXIT PARAMETER 1 11896C 11897C FINAL APPROXIMATE SOLUTION 11898C 11899C -0.5706545E+00 -0.6816283E+00 -0.7017325E+00 11900C -0.7042129E+00 -0.7013690E+00 -0.6918656E+00 11901C -0.6657920E+00 -0.5960342E+00 -0.4164121E+00 11902C 11903C***REFERENCES M. J. D. Powell, A hybrid method for nonlinear equa- 11904C tions. In Numerical Methods for Nonlinear Algebraic 11905C Equations, P. Rabinowitz, Editor. Gordon and Breach, 11906C 1988. 11907C***ROUTINES CALLED DNSQ, XERMSG 11908C***REVISION HISTORY (YYMMDD) 11909C 800301 DATE WRITTEN 11910C 890531 Changed all specific intrinsics to generic. (WRB) 11911C 890831 Modified array declarations. (WRB) 11912C 890831 REVISION DATE from Version 3.2 11913C 891214 Prologue converted to Version 4.0 format. (BAB) 11914C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ) 11915C 920501 Reformatted the REFERENCES section. (WRB) 11916C***END PROLOGUE DNSQE 11917 INTEGER INDEX, INFO, IOPT, J, LR, LWA, MAXFEV, ML, MODE, MU, N, 11918 1 NFEV, NJEV, NPRINT 11919 DOUBLE PRECISION EPSFCN, FACTOR, FVEC(*), ONE, TOL, WA(*), 11920 1 X(*), XTOL, ZERO 11921 REAL XDATA(NOBS) 11922CCCCC EXTERNAL FCN, JAC 11923 EXTERNAL FCN 11924 SAVE FACTOR, ONE, ZERO 11925C 11926 INCLUDE 'DPCOMC.INC' 11927 INCLUDE 'DPCOP2.INC' 11928C 11929 DATA FACTOR,ONE,ZERO /1.0D2,1.0D0,0.0D0/ 11930C BEGIN BLOCK PERMITTING ...EXITS TO 20 11931C***FIRST EXECUTABLE STATEMENT DNSQE 11932 INFO = 0 11933C 11934C CHECK THE INPUT PARAMETERS FOR ERRORS. 11935C 11936C ...EXIT 11937 IF (IOPT .LT. 1 .OR. IOPT .GT. 2 .OR. N .LE. 0 11938 1 .OR. TOL .LT. ZERO .OR. LWA .LT. (3*N**2 + 13*N)/2) 11939 2 GO TO 20 11940C 11941C CALL DNSQ. 11942C 11943 MAXFEV = 100*(N + 1) 11944 IF (IOPT .EQ. 2) MAXFEV = 2*MAXFEV 11945 XTOL = TOL 11946 ML = N - 1 11947 MU = N - 1 11948 EPSFCN = ZERO 11949 MODE = 2 11950 DO 10 J = 1, N 11951 WA(J) = ONE 11952 10 CONTINUE 11953 LR = (N*(N + 1))/2 11954 INDEX = 6*N + LR 11955 CALL DNSQ(FCN,JAC,IOPT,N,X,FVEC,WA(INDEX+1),N,XTOL,MAXFEV,ML, 11956 1 MU,EPSFCN,WA(1),MODE,FACTOR,NPRINT,INFO,NFEV,NJEV, 11957 2 WA(6*N+1),LR,WA(N+1),WA(2*N+1),WA(3*N+1),WA(4*N+1), 11958 3 WA(5*N+1), 11959 4 XDATA,NOBS) 11960 IF (INFO .EQ. 5) INFO = 4 11961 20 CONTINUE 11962CCCCC IF (INFO .EQ. 0) CALL XERMSG ('SLATEC', 'DNSQE', 11963CCCCC+ 'INVALID INPUT PARAMETER.', 2, 1) 11964 IF (INFO .EQ. 0) THEN 11965 WRITE(ICOUT,11) 11966 11 FORMAT('***** ERROR IN DNSQE NON-LINEAR SIMULTANEOUS EQUATION ', 11967 1 'SOLVER--') 11968 CALL DPWRST('XXX','BUG ') 11969 WRITE(ICOUT,13) 11970 13 FORMAT(' INVALID INPUT PARAMETER.') 11971 CALL DPWRST('XXX','BUG ') 11972 ENDIF 11973 RETURN 11974C 11975C LAST CARD OF SUBROUTINE DNSQE. 11976C 11977 END 11978*DECK DNSQ 11979 SUBROUTINE DNSQ (FCN, JAC, IOPT, N, X, FVEC, FJAC, LDFJAC, XTOL, 11980 + MAXFEV, ML, MU, EPSFCN, DIAG, MODE, FACTOR, NPRINT, INFO, NFEV, 11981 + NJEV, R, LR, QTF, WA1, WA2, WA3, WA4, 11982 + XDATA,NOBS) 11983C***BEGIN PROLOGUE DNSQ 11984C***PURPOSE Find a zero of a system of a N nonlinear functions in N 11985C variables by a modification of the Powell hybrid method. 11986C***LIBRARY SLATEC 11987C***CATEGORY F2A 11988C***TYPE DOUBLE PRECISION (SNSQ-S, DNSQ-D) 11989C***KEYWORDS NONLINEAR SQUARE SYSTEM, POWELL HYBRID METHOD, ZEROS 11990C***AUTHOR Hiebert, K. L. (SNLA) 11991C***DESCRIPTION 11992C 11993C 1. Purpose. 11994C 11995C The purpose of DNSQ is to find a zero of a system of N nonlinear 11996C functions in N variables by a modification of the Powell 11997C hybrid method. The user must provide a subroutine which 11998C calculates the functions. The user has the option of either to 11999C provide a subroutine which calculates the Jacobian or to let the 12000C code calculate it by a forward-difference approximation. 12001C This code is the combination of the MINPACK codes (Argonne) 12002C HYBRD and HYBRDJ. 12003C 12004C 2. Subroutine and Type Statements. 12005C 12006C SUBROUTINE DNSQ(FCN,JAC,IOPT,N,X,FVEC,FJAC,LDFJAC,XTOL,MAXFEV, 12007C * ML,MU,EPSFCN,DIAG,MODE,FACTOR,NPRINT,INFO,NFEV, 12008C * NJEV,R,LR,QTF,WA1,WA2,WA3,WA4) 12009C INTEGER IOPT,N,MAXFEV,ML,MU,MODE,NPRINT,INFO,NFEV,LDFJAC,NJEV,LR 12010C DOUBLE PRECISION XTOL,EPSFCN,FACTOR 12011C DOUBLE PRECISION 12012C X(N),FVEC(N),DIAG(N),FJAC(LDFJAC,N),R(LR),QTF(N), 12013C * WA1(N),WA2(N),WA3(N),WA4(N) 12014C EXTERNAL FCN,JAC 12015C 12016C 3. Parameters. 12017C 12018C Parameters designated as input parameters must be specified on 12019C entry to DNSQ and are not changed on exit, while parameters 12020C designated as output parameters need not be specified on entry 12021C and are set to appropriate values on exit from DNSQ. 12022C 12023C FCN is the name of the user-supplied subroutine which calculates 12024C the functions. FCN must be declared in an EXTERNAL statement 12025C in the user calling program, and should be written as follows. 12026C 12027C SUBROUTINE FCN(N,X,FVEC,IFLAG) 12028C INTEGER N,IFLAG 12029C DOUBLE PRECISION X(N),FVEC(N) 12030C ---------- 12031C CALCULATE THE FUNCTIONS AT X AND 12032C RETURN THIS VECTOR IN FVEC. 12033C ---------- 12034C RETURN 12035C END 12036C 12037C The value of IFLAG should not be changed by FCN unless the 12038C user wants to terminate execution of DNSQ. In this case set 12039C IFLAG to a negative integer. 12040C 12041C JAC is the name of the user-supplied subroutine which calculates 12042C the Jacobian. If IOPT=1, then JAC must be declared in an 12043C EXTERNAL statement in the user calling program, and should be 12044C written as follows. 12045C 12046C SUBROUTINE JAC(N,X,FVEC,FJAC,LDFJAC,IFLAG) 12047C INTEGER N,LDFJAC,IFLAG 12048C DOUBLE PRECISION X(N),FVEC(N),FJAC(LDFJAC,N) 12049C ---------- 12050C Calculate the Jacobian at X and return this 12051C matrix in FJAC. FVEC contains the function 12052C values at X and should not be altered. 12053C ---------- 12054C RETURN 12055C END 12056C 12057C The value of IFLAG should not be changed by JAC unless the 12058C user wants to terminate execution of DNSQ. In this case set 12059C IFLAG to a negative integer. 12060C 12061C If IOPT=2, JAC can be ignored (treat it as a dummy argument). 12062C 12063C IOPT is an input variable which specifies how the Jacobian will 12064C be calculated. If IOPT=1, then the user must supply the 12065C Jacobian through the subroutine JAC. If IOPT=2, then the 12066C code will approximate the Jacobian by forward-differencing. 12067C 12068C N is a positive integer input variable set to the number of 12069C functions and variables. 12070C 12071C X is an array of length N. On input X must contain an initial 12072C estimate of the solution vector. On output X contains the 12073C final estimate of the solution vector. 12074C 12075C FVEC is an output array of length N which contains the functions 12076C evaluated at the output X. 12077C 12078C FJAC is an output N by N array which contains the orthogonal 12079C matrix Q produced by the QR factorization of the final 12080C approximate Jacobian. 12081C 12082C LDFJAC is a positive integer input variable not less than N 12083C which specifies the leading dimension of the array FJAC. 12084C 12085C XTOL is a nonnegative input variable. Termination occurs when 12086C the relative error between two consecutive iterates is at most 12087C XTOL. Therefore, XTOL measures the relative error desired in 12088C the approximate solution. Section 4 contains more details 12089C about XTOL. 12090C 12091C MAXFEV is a positive integer input variable. Termination occurs 12092C when the number of calls to FCN is at least MAXFEV by the end 12093C of an iteration. 12094C 12095C ML is a nonnegative integer input variable which specifies the 12096C number of subdiagonals within the band of the Jacobian matrix. 12097C If the Jacobian is not banded or IOPT=1, set ML to at 12098C least N - 1. 12099C 12100C MU is a nonnegative integer input variable which specifies the 12101C number of superdiagonals within the band of the Jacobian 12102C matrix. If the Jacobian is not banded or IOPT=1, set MU to at 12103C least N - 1. 12104C 12105C EPSFCN is an input variable used in determining a suitable step 12106C for the forward-difference approximation. This approximation 12107C assumes that the relative errors in the functions are of the 12108C order of EPSFCN. If EPSFCN is less than the machine 12109C precision, it is assumed that the relative errors in the 12110C functions are of the order of the machine precision. If 12111C IOPT=1, then EPSFCN can be ignored (treat it as a dummy 12112C argument). 12113C 12114C DIAG is an array of length N. If MODE = 1 (see below), DIAG is 12115C internally set. If MODE = 2, DIAG must contain positive 12116C entries that serve as implicit (multiplicative) scale factors 12117C for the variables. 12118C 12119C MODE is an integer input variable. If MODE = 1, the variables 12120C will be scaled internally. If MODE = 2, the scaling is 12121C specified by the input DIAG. Other values of MODE are 12122C equivalent to MODE = 1. 12123C 12124C FACTOR is a positive input variable used in determining the 12125C initial step bound. This bound is set to the product of 12126C FACTOR and the Euclidean norm of DIAG*X if nonzero, or else to 12127C FACTOR itself. In most cases FACTOR should lie in the 12128C interval (.1,100.). 100. is a generally recommended value. 12129C 12130C NPRINT is an integer input variable that enables controlled 12131C printing of iterates if it is positive. In this case, FCN is 12132C called with IFLAG = 0 at the beginning of the first iteration 12133C and every NPRINT iterations thereafter and immediately prior 12134C to return, with X and FVEC available for printing. appropriate 12135C print statements must be added to FCN(see example). If NPRINT 12136C is not positive, no special calls of FCN with IFLAG = 0 are 12137C made. 12138C 12139C INFO is an integer output variable. If the user has terminated 12140C execution, INFO is set to the (negative) value of IFLAG. See 12141C description of FCN and JAC. Otherwise, INFO is set as follows. 12142C 12143C INFO = 0 Improper input parameters. 12144C 12145C INFO = 1 Relative error between two consecutive iterates is 12146C at most XTOL. 12147C 12148C INFO = 2 Number of calls to FCN has reached or exceeded 12149C MAXFEV. 12150C 12151C INFO = 3 XTOL is too small. No further improvement in the 12152C approximate solution X is possible. 12153C 12154C INFO = 4 Iteration is not making good progress, as measured 12155C by the improvement from the last five Jacobian 12156C evaluations. 12157C 12158C INFO = 5 Iteration is not making good progress, as measured 12159C by the improvement from the last ten iterations. 12160C 12161C Sections 4 and 5 contain more details about INFO. 12162C 12163C NFEV is an integer output variable set to the number of calls to 12164C FCN. 12165C 12166C NJEV is an integer output variable set to the number of calls to 12167C JAC. (If IOPT=2, then NJEV is set to zero.) 12168C 12169C R is an output array of length LR which contains the upper 12170C triangular matrix produced by the QR factorization of the 12171C final approximate Jacobian, stored rowwise. 12172C 12173C LR is a positive integer input variable not less than 12174C (N*(N+1))/2. 12175C 12176C QTF is an output array of length N which contains the vector 12177C (Q transpose)*FVEC. 12178C 12179C WA1, WA2, WA3, and WA4 are work arrays of length N. 12180C 12181C 12182C 4. Successful completion. 12183C 12184C The accuracy of DNSQ is controlled by the convergence parameter 12185C XTOL. This parameter is used in a test which makes a comparison 12186C between the approximation X and a solution XSOL. DNSQ 12187C terminates when the test is satisfied. If the convergence 12188C parameter is less than the machine precision (as defined by the 12189C function D1MACH(4)), then DNSQ only attempts to satisfy the test 12190C defined by the machine precision. Further progress is not 12191C usually possible. 12192C 12193C The test assumes that the functions are reasonably well behaved, 12194C and, if the Jacobian is supplied by the user, that the functions 12195C and the Jacobian are coded consistently. If these conditions 12196C are not satisfied, then DNSQ may incorrectly indicate 12197C convergence. The coding of the Jacobian can be checked by the 12198C subroutine DCKDER. If the Jacobian is coded correctly or IOPT=2, 12199C then the validity of the answer can be checked, for example, by 12200C rerunning DNSQ with a tighter tolerance. 12201C 12202C Convergence Test. If DENORM(Z) denotes the Euclidean norm of a 12203C vector Z and D is the diagonal matrix whose entries are 12204C defined by the array DIAG, then this test attempts to 12205C guarantee that 12206C 12207C DENORM(D*(X-XSOL)) .LE. XTOL*DENORM(D*XSOL). 12208C 12209C If this condition is satisfied with XTOL = 10**(-K), then the 12210C larger components of D*X have K significant decimal digits and 12211C INFO is set to 1. There is a danger that the smaller 12212C components of D*X may have large relative errors, but the fast 12213C rate of convergence of DNSQ usually avoids this possibility. 12214C Unless high precision solutions are required, the recommended 12215C value for XTOL is the square root of the machine precision. 12216C 12217C 12218C 5. Unsuccessful Completion. 12219C 12220C Unsuccessful termination of DNSQ can be due to improper input 12221C parameters, arithmetic interrupts, an excessive number of 12222C function evaluations, or lack of good progress. 12223C 12224C Improper Input Parameters. INFO is set to 0 if IOPT .LT .1, 12225C or IOPT .GT. 2, or N .LE. 0, or LDFJAC .LT. N, or 12226C XTOL .LT. 0.E0, or MAXFEV .LE. 0, or ML .LT. 0, or MU .LT. 0, 12227C or FACTOR .LE. 0.E0, or LR .LT. (N*(N+1))/2. 12228C 12229C Arithmetic Interrupts. If these interrupts occur in the FCN 12230C subroutine during an early stage of the computation, they may 12231C be caused by an unacceptable choice of X by DNSQ. In this 12232C case, it may be possible to remedy the situation by rerunning 12233C DNSQ with a smaller value of FACTOR. 12234C 12235C Excessive Number of Function Evaluations. A reasonable value 12236C for MAXFEV is 100*(N+1) for IOPT=1 and 200*(N+1) for IOPT=2. 12237C If the number of calls to FCN reaches MAXFEV, then this 12238C indicates that the routine is converging very slowly as 12239C measured by the progress of FVEC, and INFO is set to 2. This 12240C situation should be unusual because, as indicated below, lack 12241C of good progress is usually diagnosed earlier by DNSQ, 12242C causing termination with info = 4 or INFO = 5. 12243C 12244C Lack of Good Progress. DNSQ searches for a zero of the system 12245C by minimizing the sum of the squares of the functions. In so 12246C doing, it can become trapped in a region where the minimum 12247C does not correspond to a zero of the system and, in this 12248C situation, the iteration eventually fails to make good 12249C progress. In particular, this will happen if the system does 12250C not have a zero. If the system has a zero, rerunning DNSQ 12251C from a different starting point may be helpful. 12252C 12253C 12254C 6. Characteristics of The Algorithm. 12255C 12256C DNSQ is a modification of the Powell Hybrid method. Two of its 12257C main characteristics involve the choice of the correction as a 12258C convex combination of the Newton and scaled gradient directions, 12259C and the updating of the Jacobian by the rank-1 method of 12260C Broyden. The choice of the correction guarantees (under 12261C reasonable conditions) global convergence for starting points 12262C far from the solution and a fast rate of convergence. The 12263C Jacobian is calculated at the starting point by either the 12264C user-supplied subroutine or a forward-difference approximation, 12265C but it is not recalculated until the rank-1 method fails to 12266C produce satisfactory progress. 12267C 12268C Timing. The time required by DNSQ to solve a given problem 12269C depends on N, the behavior of the functions, the accuracy 12270C requested, and the starting point. The number of arithmetic 12271C operations needed by DNSQ is about 11.5*(N**2) to process 12272C each evaluation of the functions (call to FCN) and 1.3*(N**3) 12273C to process each evaluation of the Jacobian (call to JAC, 12274C if IOPT = 1). Unless FCN and JAC can be evaluated quickly, 12275C the timing of DNSQ will be strongly influenced by the time 12276C spent in FCN and JAC. 12277C 12278C Storage. DNSQ requires (3*N**2 + 17*N)/2 single precision 12279C storage locations, in addition to the storage required by the 12280C program. There are no internally declared storage arrays. 12281C 12282C *Long Description: 12283C 12284C 7. Example. 12285C 12286C The problem is to determine the values of X(1), X(2), ..., X(9), 12287C which solve the system of tridiagonal equations 12288C 12289C (3-2*X(1))*X(1) -2*X(2) = -1 12290C -X(I-1) + (3-2*X(I))*X(I) -2*X(I+1) = -1, I=2-8 12291C -X(8) + (3-2*X(9))*X(9) = -1 12292C C ********** 12293C 12294C PROGRAM TEST 12295C C 12296C C Driver for DNSQ example. 12297C C 12298C INTEGER J,IOPT,N,MAXFEV,ML,MU,MODE,NPRINT,INFO,NFEV,LDFJAC,LR, 12299C * NWRITE 12300C DOUBLE PRECISION XTOL,EPSFCN,FACTOR,FNORM 12301C DOUBLE PRECISION X(9),FVEC(9),DIAG(9),FJAC(9,9),R(45),QTF(9), 12302C * WA1(9),WA2(9),WA3(9),WA4(9) 12303C DOUBLE PRECISION DENORM,D1MACH 12304C EXTERNAL FCN 12305C DATA NWRITE /6/ 12306C C 12307C IOPT = 2 12308C N = 9 12309C C 12310C C THE FOLLOWING STARTING VALUES PROVIDE A ROUGH SOLUTION. 12311C C 12312C DO 10 J = 1, 9 12313C X(J) = -1.E0 12314C 10 CONTINUE 12315C C 12316C LDFJAC = 9 12317C LR = 45 12318C C 12319C C SET XTOL TO THE SQUARE ROOT OF THE MACHINE PRECISION. 12320C C UNLESS HIGH PRECISION SOLUTIONS ARE REQUIRED, 12321C C THIS IS THE RECOMMENDED SETTING. 12322C C 12323C XTOL = SQRT(D1MACH(4)) 12324C C 12325C MAXFEV = 2000 12326C ML = 1 12327C MU = 1 12328C EPSFCN = 0.E0 12329C MODE = 2 12330C DO 20 J = 1, 9 12331C DIAG(J) = 1.E0 12332C 20 CONTINUE 12333C FACTOR = 1.E2 12334C NPRINT = 0 12335C C 12336C CALL DNSQ(FCN,JAC,IOPT,N,X,FVEC,FJAC,LDFJAC,XTOL,MAXFEV,ML,MU, 12337C * EPSFCN,DIAG,MODE,FACTOR,NPRINT,INFO,NFEV,NJEV, 12338C * R,LR,QTF,WA1,WA2,WA3,WA4) 12339C FNORM = DENORM(N,FVEC) 12340C WRITE (NWRITE,1000) FNORM,NFEV,INFO,(X(J),J=1,N) 12341C STOP 12342C 1000 FORMAT (5X,' FINAL L2 NORM OF THE RESIDUALS',E15.7 // 12343C * 5X,' NUMBER OF FUNCTION EVALUATIONS',I10 // 12344C * 5X,' EXIT PARAMETER',16X,I10 // 12345C * 5X,' FINAL APPROXIMATE SOLUTION' // (5X,3E15.7)) 12346C END 12347C SUBROUTINE FCN(N,X,FVEC,IFLAG) 12348C INTEGER N,IFLAG 12349C DOUBLE PRECISION X(N),FVEC(N) 12350C INTEGER K 12351C DOUBLE PRECISION ONE,TEMP,TEMP1,TEMP2,THREE,TWO,ZERO 12352C DATA ZERO,ONE,TWO,THREE /0.E0,1.E0,2.E0,3.E0/ 12353C C 12354C IF (IFLAG .NE. 0) GO TO 5 12355C C 12356C C INSERT PRINT STATEMENTS HERE WHEN NPRINT IS POSITIVE. 12357C C 12358C RETURN 12359C 5 CONTINUE 12360C DO 10 K = 1, N 12361C TEMP = (THREE - TWO*X(K))*X(K) 12362C TEMP1 = ZERO 12363C IF (K .NE. 1) TEMP1 = X(K-1) 12364C TEMP2 = ZERO 12365C IF (K .NE. N) TEMP2 = X(K+1) 12366C FVEC(K) = TEMP - TEMP1 - TWO*TEMP2 + ONE 12367C 10 CONTINUE 12368C RETURN 12369C END 12370C 12371C Results obtained with different compilers or machines 12372C may be slightly different. 12373C 12374C Final L2 norm of the residuals 0.1192636E-07 12375C 12376C Number of function evaluations 14 12377C 12378C Exit parameter 1 12379C 12380C Final approximate solution 12381C 12382C -0.5706545E+00 -0.6816283E+00 -0.7017325E+00 12383C -0.7042129E+00 -0.7013690E+00 -0.6918656E+00 12384C -0.6657920E+00 -0.5960342E+00 -0.4164121E+00 12385C 12386C***REFERENCES M. J. D. Powell, A hybrid method for nonlinear equa- 12387C tions. In Numerical Methods for Nonlinear Algebraic 12388C Equations, P. Rabinowitz, Editor. Gordon and Breach, 12389C 1988. 12390C***ROUTINES CALLED D1MACH, D1MPYQ, D1UPDT, DDOGLG, DENORM, DFDJC1, 12391C DQFORM, DQRFAC, XERMSG 12392C***REVISION HISTORY (YYMMDD) 12393C 800301 DATE WRITTEN 12394C 890531 Changed all specific intrinsics to generic. (WRB) 12395C 890831 Modified array declarations. (WRB) 12396C 890831 REVISION DATE from Version 3.2 12397C 891214 Prologue converted to Version 4.0 format. (BAB) 12398C 900315 CALLs to XERROR changed to CALLs to XERMSG. (THJ) 12399C 920501 Reformatted the REFERENCES section. (WRB) 12400C***END PROLOGUE DNSQ 12401CCCCC DOUBLE PRECISION D1MACH,DENORM 12402 DOUBLE PRECISION DENORM 12403 INTEGER I, IFLAG, INFO, IOPT, ITER, IWA(1), J, JM1, L, LDFJAC, 12404 1 LR, MAXFEV, ML, MODE, MU, N, NCFAIL, NCSUC, NFEV, NJEV, 12405 2 NPRINT, NSLOW1, NSLOW2 12406 DOUBLE PRECISION ACTRED, DELTA, DIAG(*), EPSFCN, EPSMCH, FACTOR, 12407 1 FJAC(LDFJAC,*), FNORM, FNORM1, FVEC(*), ONE, P0001, P001, 12408 2 P1, P5, PNORM, PRERED, QTF(*), R(*), RATIO, SUM, TEMP, 12409 3 WA1(*), WA2(*), WA3(*), WA4(*), X(*), XNORM, XTOL, ZERO 12410 REAL XDATA(NOBS) 12411 EXTERNAL FCN 12412 LOGICAL JEVAL,SING 12413C 12414 INCLUDE 'DPCOMC.INC' 12415 INCLUDE 'DPCOP2.INC' 12416C 12417 SAVE ONE, P1, P5, P001, P0001, ZERO 12418 DATA ONE,P1,P5,P001,P0001,ZERO 12419 1 /1.0D0,1.0D-1,5.0D-1,1.0D-3,1.0D-4,0.0D0/ 12420C 12421C BEGIN BLOCK PERMITTING ...EXITS TO 320 12422C***FIRST EXECUTABLE STATEMENT DNSQ 12423 XNORM = 0.0D0 12424 EPSMCH = D1MACH(4) 12425C 12426 INFO = 0 12427 IFLAG = 0 12428 NFEV = 0 12429 NJEV = 0 12430C 12431C CHECK THE INPUT PARAMETERS FOR ERRORS. 12432C 12433C ...EXIT 12434 IF (IOPT .LT. 1 .OR. IOPT .GT. 2 .OR. N .LE. 0 12435 1 .OR. XTOL .LT. ZERO .OR. MAXFEV .LE. 0 .OR. ML .LT. 0 12436 2 .OR. MU .LT. 0 .OR. FACTOR .LE. ZERO .OR. LDFJAC .LT. N 12437 3 .OR. LR .LT. (N*(N + 1))/2) GO TO 320 12438 IF (MODE .NE. 2) GO TO 20 12439 DO 10 J = 1, N 12440C .........EXIT 12441 IF (DIAG(J) .LE. ZERO) GO TO 320 12442 10 CONTINUE 12443 20 CONTINUE 12444C 12445C EVALUATE THE FUNCTION AT THE STARTING POINT 12446C AND CALCULATE ITS NORM. 12447C 12448 IFLAG = 1 12449 CALL FCN(N,X,FVEC,IFLAG,XDATA,NOBS) 12450 NFEV = 1 12451C ...EXIT 12452 IF (IFLAG .LT. 0) GO TO 320 12453 FNORM = DENORM(N,FVEC) 12454C 12455C INITIALIZE ITERATION COUNTER AND MONITORS. 12456C 12457 ITER = 1 12458 NCSUC = 0 12459 NCFAIL = 0 12460 NSLOW1 = 0 12461 NSLOW2 = 0 12462C 12463C BEGINNING OF THE OUTER LOOP. 12464C 12465 30 CONTINUE 12466C BEGIN BLOCK PERMITTING ...EXITS TO 90 12467 JEVAL = .TRUE. 12468C 12469C CALCULATE THE JACOBIAN MATRIX. 12470C 12471 IF (IOPT .EQ. 2) GO TO 40 12472C 12473C USER SUPPLIES JACOBIAN 12474C 12475CCCCC CALL JAC(N,X,FVEC,FJAC,LDFJAC,IFLAG) 12476 NJEV = NJEV + 1 12477 GO TO 50 12478 40 CONTINUE 12479C 12480C CODE APPROXIMATES THE JACOBIAN 12481C 12482 IFLAG = 2 12483 CALL DFDJC1(FCN,N,X,FVEC,FJAC,LDFJAC,IFLAG,ML,MU, 12484 1 EPSFCN,WA1,WA2,XDATA,NOBS) 12485 NFEV = NFEV + MIN(ML+MU+1,N) 12486 50 CONTINUE 12487C 12488C .........EXIT 12489 IF (IFLAG .LT. 0) GO TO 320 12490C 12491C COMPUTE THE QR FACTORIZATION OF THE JACOBIAN. 12492C 12493 CALL DQRFAC(N,N,FJAC,LDFJAC,.FALSE.,IWA,1,WA1,WA2,WA3) 12494C 12495C ON THE FIRST ITERATION AND IF MODE IS 1, SCALE ACCORDING 12496C TO THE NORMS OF THE COLUMNS OF THE INITIAL JACOBIAN. 12497C 12498C ...EXIT 12499 IF (ITER .NE. 1) GO TO 90 12500 IF (MODE .EQ. 2) GO TO 70 12501 DO 60 J = 1, N 12502 DIAG(J) = WA2(J) 12503 IF (WA2(J) .EQ. ZERO) DIAG(J) = ONE 12504 60 CONTINUE 12505 70 CONTINUE 12506C 12507C ON THE FIRST ITERATION, CALCULATE THE NORM OF THE SCALED 12508C X AND INITIALIZE THE STEP BOUND DELTA. 12509C 12510 DO 80 J = 1, N 12511 WA3(J) = DIAG(J)*X(J) 12512 80 CONTINUE 12513 XNORM = DENORM(N,WA3) 12514 DELTA = FACTOR*XNORM 12515 IF (DELTA .EQ. ZERO) DELTA = FACTOR 12516 90 CONTINUE 12517C 12518C FORM (Q TRANSPOSE)*FVEC AND STORE IN QTF. 12519C 12520 DO 100 I = 1, N 12521 QTF(I) = FVEC(I) 12522 100 CONTINUE 12523 DO 140 J = 1, N 12524 IF (FJAC(J,J) .EQ. ZERO) GO TO 130 12525 SUM = ZERO 12526 DO 110 I = J, N 12527 SUM = SUM + FJAC(I,J)*QTF(I) 12528 110 CONTINUE 12529 TEMP = -SUM/FJAC(J,J) 12530 DO 120 I = J, N 12531 QTF(I) = QTF(I) + FJAC(I,J)*TEMP 12532 120 CONTINUE 12533 130 CONTINUE 12534 140 CONTINUE 12535C 12536C COPY THE TRIANGULAR FACTOR OF THE QR FACTORIZATION INTO R. 12537C 12538 SING = .FALSE. 12539 DO 170 J = 1, N 12540 L = J 12541 JM1 = J - 1 12542 IF (JM1 .LT. 1) GO TO 160 12543 DO 150 I = 1, JM1 12544 R(L) = FJAC(I,J) 12545 L = L + N - I 12546 150 CONTINUE 12547 160 CONTINUE 12548 R(L) = WA1(J) 12549 IF (WA1(J) .EQ. ZERO) SING = .TRUE. 12550 170 CONTINUE 12551C 12552C ACCUMULATE THE ORTHOGONAL FACTOR IN FJAC. 12553C 12554 CALL DQFORM(N,N,FJAC,LDFJAC,WA1) 12555C 12556C RESCALE IF NECESSARY. 12557C 12558 IF (MODE .EQ. 2) GO TO 190 12559 DO 180 J = 1, N 12560 DIAG(J) = MAX(DIAG(J),WA2(J)) 12561 180 CONTINUE 12562 190 CONTINUE 12563C 12564C BEGINNING OF THE INNER LOOP. 12565C 12566 200 CONTINUE 12567C 12568C IF REQUESTED, CALL FCN TO ENABLE PRINTING OF ITERATES. 12569C 12570 IF (NPRINT .LE. 0) GO TO 210 12571 IFLAG = 0 12572 IF (MOD(ITER-1,NPRINT) .EQ. 0) 12573 1 CALL FCN(N,X,FVEC,IFLAG,XDATA,NOBS) 12574C ............EXIT 12575 IF (IFLAG .LT. 0) GO TO 320 12576 210 CONTINUE 12577C 12578C DETERMINE THE DIRECTION P. 12579C 12580 CALL DDOGLG(N,R,LR,DIAG,QTF,DELTA,WA1,WA2,WA3) 12581C 12582C STORE THE DIRECTION P AND X + P. CALCULATE THE NORM OF P. 12583C 12584 DO 220 J = 1, N 12585 WA1(J) = -WA1(J) 12586 WA2(J) = X(J) + WA1(J) 12587 WA3(J) = DIAG(J)*WA1(J) 12588 220 CONTINUE 12589 PNORM = DENORM(N,WA3) 12590C 12591C ON THE FIRST ITERATION, ADJUST THE INITIAL STEP BOUND. 12592C 12593 IF (ITER .EQ. 1) DELTA = MIN(DELTA,PNORM) 12594C 12595C EVALUATE THE FUNCTION AT X + P AND CALCULATE ITS NORM. 12596C 12597 IFLAG = 1 12598 CALL FCN(N,WA2,WA4,IFLAG,XDATA,NOBS) 12599 NFEV = NFEV + 1 12600C .........EXIT 12601 IF (IFLAG .LT. 0) GO TO 320 12602 FNORM1 = DENORM(N,WA4) 12603C 12604C COMPUTE THE SCALED ACTUAL REDUCTION. 12605C 12606 ACTRED = -ONE 12607 IF (FNORM1 .LT. FNORM) ACTRED = ONE - (FNORM1/FNORM)**2 12608C 12609C COMPUTE THE SCALED PREDICTED REDUCTION. 12610C 12611 L = 1 12612 DO 240 I = 1, N 12613 SUM = ZERO 12614 DO 230 J = I, N 12615 SUM = SUM + R(L)*WA1(J) 12616 L = L + 1 12617 230 CONTINUE 12618 WA3(I) = QTF(I) + SUM 12619 240 CONTINUE 12620 TEMP = DENORM(N,WA3) 12621 PRERED = ZERO 12622 IF (TEMP .LT. FNORM) PRERED = ONE - (TEMP/FNORM)**2 12623C 12624C COMPUTE THE RATIO OF THE ACTUAL TO THE PREDICTED 12625C REDUCTION. 12626C 12627 RATIO = ZERO 12628 IF (PRERED .GT. ZERO) RATIO = ACTRED/PRERED 12629C 12630C UPDATE THE STEP BOUND. 12631C 12632 IF (RATIO .GE. P1) GO TO 250 12633 NCSUC = 0 12634 NCFAIL = NCFAIL + 1 12635 DELTA = P5*DELTA 12636 GO TO 260 12637 250 CONTINUE 12638 NCFAIL = 0 12639 NCSUC = NCSUC + 1 12640 IF (RATIO .GE. P5 .OR. NCSUC .GT. 1) 12641 1 DELTA = MAX(DELTA,PNORM/P5) 12642 IF (ABS(RATIO-ONE) .LE. P1) DELTA = PNORM/P5 12643 260 CONTINUE 12644C 12645C TEST FOR SUCCESSFUL ITERATION. 12646C 12647 IF (RATIO .LT. P0001) GO TO 280 12648C 12649C SUCCESSFUL ITERATION. UPDATE X, FVEC, AND THEIR NORMS. 12650C 12651 DO 270 J = 1, N 12652 X(J) = WA2(J) 12653 WA2(J) = DIAG(J)*X(J) 12654 FVEC(J) = WA4(J) 12655 270 CONTINUE 12656 XNORM = DENORM(N,WA2) 12657 FNORM = FNORM1 12658 ITER = ITER + 1 12659 280 CONTINUE 12660C 12661C DETERMINE THE PROGRESS OF THE ITERATION. 12662C 12663 NSLOW1 = NSLOW1 + 1 12664 IF (ACTRED .GE. P001) NSLOW1 = 0 12665 IF (JEVAL) NSLOW2 = NSLOW2 + 1 12666 IF (ACTRED .GE. P1) NSLOW2 = 0 12667C 12668C TEST FOR CONVERGENCE. 12669C 12670 IF (DELTA .LE. XTOL*XNORM .OR. FNORM .EQ. ZERO) INFO = 1 12671C .........EXIT 12672 IF (INFO .NE. 0) GO TO 320 12673C 12674C TESTS FOR TERMINATION AND STRINGENT TOLERANCES. 12675C 12676 IF (NFEV .GE. MAXFEV) INFO = 2 12677 IF (P1*MAX(P1*DELTA,PNORM) .LE. EPSMCH*XNORM) INFO = 3 12678 IF (NSLOW2 .EQ. 5) INFO = 4 12679 IF (NSLOW1 .EQ. 10) INFO = 5 12680C .........EXIT 12681 IF (INFO .NE. 0) GO TO 320 12682C 12683C CRITERION FOR RECALCULATING JACOBIAN 12684C 12685C ...EXIT 12686 IF (NCFAIL .EQ. 2) GO TO 310 12687C 12688C CALCULATE THE RANK ONE MODIFICATION TO THE JACOBIAN 12689C AND UPDATE QTF IF NECESSARY. 12690C 12691 DO 300 J = 1, N 12692 SUM = ZERO 12693 DO 290 I = 1, N 12694 SUM = SUM + FJAC(I,J)*WA4(I) 12695 290 CONTINUE 12696 WA2(J) = (SUM - WA3(J))/PNORM 12697 WA1(J) = DIAG(J)*((DIAG(J)*WA1(J))/PNORM) 12698 IF (RATIO .GE. P0001) QTF(J) = SUM 12699 300 CONTINUE 12700C 12701C COMPUTE THE QR FACTORIZATION OF THE UPDATED JACOBIAN. 12702C 12703 CALL D1UPDT(N,N,R,LR,WA1,WA2,WA3,SING) 12704 CALL D1MPYQ(N,N,FJAC,LDFJAC,WA2,WA3) 12705 CALL D1MPYQ(1,N,QTF,1,WA2,WA3) 12706C 12707C END OF THE INNER LOOP. 12708C 12709 JEVAL = .FALSE. 12710 GO TO 200 12711 310 CONTINUE 12712C 12713C END OF THE OUTER LOOP. 12714C 12715 GO TO 30 12716 320 CONTINUE 12717C 12718C TERMINATION, EITHER NORMAL OR USER IMPOSED. 12719C 12720 IF (IFLAG .LT. 0) INFO = IFLAG 12721 IFLAG = 0 12722 IF (NPRINT .GT. 0) CALL FCN(N,X,FVEC,IFLAG,XDATA,NOBS) 12723CCCCC IF (INFO .LT. 0) CALL XERMSG ('SLATEC', 'DNSQ', 12724CCCCC+ 'EXECUTION TERMINATED BECAUSE USER SET IFLAG NEGATIVE.', 1, 1) 12725CCCCC IF (INFO .EQ. 0) CALL XERMSG ('SLATEC', 'DNSQ', 12726CCCCC+ 'INVALID INPUT PARAMETER.', 2, 1) 12727CCCCC IF (INFO .EQ. 2) CALL XERMSG ('SLATEC', 'DNSQ', 12728CCCCC+ 'TOO MANY FUNCTION EVALUATIONS.', 9, 1) 12729CCCCC IF (INFO .EQ. 3) CALL XERMSG ('SLATEC', 'DNSQ', 12730CCCCC+ 'XTOL TOO SMALL. NO FURTHER IMPROVEMENT POSSIBLE.', 3, 1) 12731CCCCC IF (INFO .GT. 4) CALL XERMSG ('SLATEC', 'DNSQ', 12732CCCCC+ 'ITERATION NOT MAKING GOOD PROGRESS.', 1, 1) 12733 IF (INFO .LT. 0) THEN 12734 WRITE(ICOUT,1001) 12735 1001 FORMAT('***** ERROR IN DNSQE NON-LINEAR SIMULTANEOUS EQUATION ', 12736 1 'SOLVER--') 12737 CALL DPWRST('XXX','BUG ') 12738 WRITE(ICOUT,1003) 12739 1003 FORMAT(' TERMINATION HALTED BECAUSE IFLAG IS NEGATIVE.') 12740 CALL DPWRST('XXX','BUG ') 12741 ENDIF 12742 IF (INFO .EQ. 0) THEN 12743 WRITE(ICOUT,1001) 12744 CALL DPWRST('XXX','BUG ') 12745 WRITE(ICOUT,1004) 12746 1004 FORMAT(' INVALID INPUT PARAMETER.') 12747 CALL DPWRST('XXX','BUG ') 12748 ENDIF 12749 IF (INFO .EQ. 2) THEN 12750 WRITE(ICOUT,1001) 12751 CALL DPWRST('XXX','BUG ') 12752 WRITE(ICOUT,1005) 12753 1005 FORMAT(' TOO MANY FUNCTION EVALUATIONS.') 12754 CALL DPWRST('XXX','BUG ') 12755 ENDIF 12756 IF (INFO .EQ. 3) THEN 12757 WRITE(ICOUT,1001) 12758 CALL DPWRST('XXX','BUG ') 12759 WRITE(ICOUT,1006) 12760 1006 FORMAT(' XTOL TOO SMALL. NO FURTHER IMPROVEMENT ', 12761 1 'POSSIBLE.') 12762 CALL DPWRST('XXX','BUG ') 12763 ENDIF 12764 IF (INFO .GT. 4) THEN 12765 WRITE(ICOUT,1001) 12766 CALL DPWRST('XXX','BUG ') 12767 WRITE(ICOUT,1007) 12768 1007 FORMAT(' ITERATION NOT MAKING GOOD PROGRESS.') 12769 CALL DPWRST('XXX','BUG ') 12770 ENDIF 12771C 12772 RETURN 12773C 12774C LAST CARD OF SUBROUTINE DNSQ. 12775C 12776 END 12777*DECK DFDJC1 12778 SUBROUTINE DFDJC1 (FCN, N, X, FVEC, FJAC, LDFJAC, IFLAG, ML, MU, 12779 + EPSFCN, WA1, WA2, 12780 + XDATA,NOBS) 12781C***BEGIN PROLOGUE DFDJC1 12782C***SUBSIDIARY 12783C***PURPOSE Subsidiary to DNSQ and DNSQE 12784C***LIBRARY SLATEC 12785C***TYPE DOUBLE PRECISION (FDJAC1-S, DFDJC1-D) 12786C***AUTHOR (UNKNOWN) 12787C***DESCRIPTION 12788C 12789C This subroutine computes a forward-difference approximation 12790C to the N by N Jacobian matrix associated with a specified 12791C problem of N functions in N variables. If the Jacobian has 12792C a banded form, then function evaluations are saved by only 12793C approximating the nonzero terms. 12794C 12795C The subroutine statement is 12796C 12797C SUBROUTINE DFDJC1(FCN,N,X,FVEC,FJAC,LDFJAC,IFLAG,ML,MU,EPSFCN, 12798C WA1,WA2) 12799C 12800C where 12801C 12802C FCN is the name of the user-supplied subroutine which 12803C calculates the functions. FCN must be declared 12804C in an EXTERNAL statement in the user calling 12805C program, and should be written as follows. 12806C 12807C SUBROUTINE FCN(N,X,FVEC,IFLAG) 12808C INTEGER N,IFLAG 12809C DOUBLE PRECISION X(N),FVEC(N) 12810C ---------- 12811C Calculate the functions at X and 12812C return this vector in FVEC. 12813C ---------- 12814C RETURN 12815C 12816C The value of IFLAG should not be changed by FCN unless 12817C the user wants to terminate execution of DFDJC1. 12818C In this case set IFLAG to a negative integer. 12819C 12820C N is a positive integer input variable set to the number 12821C of functions and variables. 12822C 12823C X is an input array of length N. 12824C 12825C FVEC is an input array of length N which must contain the 12826C functions evaluated at X. 12827C 12828C FJAC is an output N by N array which contains the 12829C approximation to the Jacobian matrix evaluated at X. 12830C 12831C LDFJAC is a positive integer input variable not less than N 12832C which specifies the leading dimension of the array FJAC. 12833C 12834C IFLAG is an integer variable which can be used to terminate 12835C the execution of DFDJC1. See description of FCN. 12836C 12837C ML is a nonnegative integer input variable which specifies 12838C the number of subdiagonals within the band of the 12839C Jacobian matrix. If the Jacobian is not banded, set 12840C ML to at least N - 1. 12841C 12842C EPSFCN is an input variable used in determining a suitable 12843C step length for the forward-difference approximation. This 12844C approximation assumes that the relative errors in the 12845C functions are of the order of EPSFCN. If EPSFCN is less 12846C than the machine precision, it is assumed that the relative 12847C errors in the functions are of the order of the machine 12848C precision. 12849C 12850C MU is a nonnegative integer input variable which specifies 12851C the number of superdiagonals within the band of the 12852C Jacobian matrix. If the Jacobian is not banded, set 12853C MU to at least N - 1. 12854C 12855C WA1 and WA2 are work arrays of length N. If ML + MU + 1 is at 12856C least N, then the Jacobian is considered dense, and WA2 is 12857C not referenced. 12858C 12859C***SEE ALSO DNSQ, DNSQE 12860C***ROUTINES CALLED D1MACH 12861C***REVISION HISTORY (YYMMDD) 12862C 800301 DATE WRITTEN 12863C 890531 Changed all specific intrinsics to generic. (WRB) 12864C 890831 Modified array declarations. (WRB) 12865C 891214 Prologue converted to Version 4.0 format. (BAB) 12866C 900326 Removed duplicate information from DESCRIPTION section. 12867C (WRB) 12868C 900328 Added TYPE section. (WRB) 12869C***END PROLOGUE DFDJC1 12870CCCCC DOUBLE PRECISION D1MACH 12871 INTEGER I, IFLAG, J, K, LDFJAC, ML, MSUM, MU, N 12872 DOUBLE PRECISION EPS, EPSFCN, EPSMCH, FJAC(LDFJAC,*), 12873 1 FVEC(*), H, TEMP, WA1(*), WA2(*), X(*), ZERO 12874 SAVE ZERO 12875C 12876 REAL XDATA(NOBS) 12877 INCLUDE 'DPCOMC.INC' 12878 INCLUDE 'DPCOP2.INC' 12879C 12880 DATA ZERO /0.0D0/ 12881C 12882C EPSMCH IS THE MACHINE PRECISION. 12883C 12884C***FIRST EXECUTABLE STATEMENT DFDJC1 12885 EPSMCH = D1MACH(4) 12886C 12887 EPS = SQRT(MAX(EPSFCN,EPSMCH)) 12888 MSUM = ML + MU + 1 12889 IF (MSUM .LT. N) GO TO 40 12890C 12891C COMPUTATION OF DENSE APPROXIMATE JACOBIAN. 12892C 12893 DO 20 J = 1, N 12894 TEMP = X(J) 12895 H = EPS*ABS(TEMP) 12896 IF (H .EQ. ZERO) H = EPS 12897 X(J) = TEMP + H 12898 CALL FCN(N,X,WA1,IFLAG,XDATA,NOBS) 12899 IF (IFLAG .LT. 0) GO TO 30 12900 X(J) = TEMP 12901 DO 10 I = 1, N 12902 FJAC(I,J) = (WA1(I) - FVEC(I))/H 12903 10 CONTINUE 12904 20 CONTINUE 12905 30 CONTINUE 12906 GO TO 110 12907 40 CONTINUE 12908C 12909C COMPUTATION OF BANDED APPROXIMATE JACOBIAN. 12910C 12911 DO 90 K = 1, MSUM 12912 DO 60 J = K, N, MSUM 12913 WA2(J) = X(J) 12914 H = EPS*ABS(WA2(J)) 12915 IF (H .EQ. ZERO) H = EPS 12916 X(J) = WA2(J) + H 12917 60 CONTINUE 12918 CALL FCN(N,X,WA1,IFLAG,XDATA,NOBS) 12919 IF (IFLAG .LT. 0) GO TO 100 12920 DO 80 J = K, N, MSUM 12921 X(J) = WA2(J) 12922 H = EPS*ABS(WA2(J)) 12923 IF (H .EQ. ZERO) H = EPS 12924 DO 70 I = 1, N 12925 FJAC(I,J) = ZERO 12926 IF (I .GE. J - MU .AND. I .LE. J + ML) 12927 1 FJAC(I,J) = (WA1(I) - FVEC(I))/H 12928 70 CONTINUE 12929 80 CONTINUE 12930 90 CONTINUE 12931 100 CONTINUE 12932 110 CONTINUE 12933 RETURN 12934C 12935C LAST CARD OF SUBROUTINE DFDJC1. 12936C 12937 END 12938*DECK DQRFAC 12939 SUBROUTINE DQRFAC (M, N, A, LDA, PIVOT, IPVT, LIPVT, SIGMA, 12940 + ACNORM, WA) 12941C***BEGIN PROLOGUE DQRFAC 12942C***SUBSIDIARY 12943C***PURPOSE Subsidiary to DNLS1, DNLS1E, DNSQ and DNSQE 12944C***LIBRARY SLATEC 12945C***TYPE DOUBLE PRECISION (QRFAC-S, DQRFAC-D) 12946C***AUTHOR (UNKNOWN) 12947C***DESCRIPTION 12948C 12949C **** Double Precision version of QRFAC **** 12950C 12951C This subroutine uses Householder transformations with column 12952C pivoting (optional) to compute a QR factorization of the 12953C M by N matrix A. That is, DQRFAC determines an orthogonal 12954C matrix Q, a permutation matrix P, and an upper trapezoidal 12955C matrix R with diagonal elements of nonincreasing magnitude, 12956C such that A*P = Q*R. The Householder transformation for 12957C column K, K = 1,2,...,MIN(M,N), is of the form 12958C 12959C T 12960C I - (1/U(K))*U*U 12961C 12962C where U has zeros in the first K-1 positions. The form of 12963C this transformation and the method of pivoting first 12964C appeared in the corresponding LINPACK subroutine. 12965C 12966C The subroutine statement is 12967C 12968C SUBROUTINE DQRFAC(M,N,A,LDA,PIVOT,IPVT,LIPVT,SIGMA,ACNORM,WA) 12969C 12970C where 12971C 12972C M is a positive integer input variable set to the number 12973C of rows of A. 12974C 12975C N is a positive integer input variable set to the number 12976C of columns of A. 12977C 12978C A is an M by N array. On input A contains the matrix for 12979C which the QR factorization is to be computed. On output 12980C the strict upper trapezoidal part of A contains the strict 12981C upper trapezoidal part of R, and the lower trapezoidal 12982C part of A contains a factored form of Q (the non-trivial 12983C elements of the U vectors described above). 12984C 12985C LDA is a positive integer input variable not less than M 12986C which specifies the leading dimension of the array A. 12987C 12988C PIVOT is a logical input variable. If pivot is set .TRUE., 12989C then column pivoting is enforced. If pivot is set .FALSE., 12990C then no column pivoting is done. 12991C 12992C IPVT is an integer output array of length LIPVT. IPVT 12993C defines the permutation matrix P such that A*P = Q*R. 12994C Column J of P is column IPVT(J) of the identity matrix. 12995C If pivot is .FALSE., IPVT is not referenced. 12996C 12997C LIPVT is a positive integer input variable. If PIVOT is 12998C .FALSE., then LIPVT may be as small as 1. If PIVOT is 12999C .TRUE., then LIPVT must be at least N. 13000C 13001C SIGMA is an output array of length N which contains the 13002C diagonal elements of R. 13003C 13004C ACNORM is an output array of length N which contains the 13005C norms of the corresponding columns of the input matrix A. 13006C If this information is not needed, then ACNORM can coincide 13007C with SIGMA. 13008C 13009C WA is a work array of length N. If pivot is .FALSE., then WA 13010C can coincide with SIGMA. 13011C 13012C***SEE ALSO DNLS1, DNLS1E, DNSQ, DNSQE 13013C***ROUTINES CALLED D1MACH, DENORM 13014C***REVISION HISTORY (YYMMDD) 13015C 800301 DATE WRITTEN 13016C 890531 Changed all specific intrinsics to generic. (WRB) 13017C 890831 Modified array declarations. (WRB) 13018C 891214 Prologue converted to Version 4.0 format. (BAB) 13019C 900326 Removed duplicate information from DESCRIPTION section. 13020C (WRB) 13021C 900328 Added TYPE section. (WRB) 13022C***END PROLOGUE DQRFAC 13023 INTEGER M,N,LDA,LIPVT 13024 INTEGER IPVT(*) 13025 LOGICAL PIVOT 13026 SAVE ONE, P05, ZERO 13027 DOUBLE PRECISION A(LDA,*),SIGMA(*),ACNORM(*),WA(*) 13028 INTEGER I,J,JP1,K,KMAX,MINMN 13029 DOUBLE PRECISION AJNORM,EPSMCH,ONE,P05,SUM,TEMP,ZERO 13030CCCCC DOUBLE PRECISION D1MACH,DENORM 13031 DOUBLE PRECISION DENORM 13032C 13033 INCLUDE 'DPCOBE.INC' 13034 INCLUDE 'DPCOMC.INC' 13035 INCLUDE 'DPCOP2.INC' 13036C 13037 DATA ONE,P05,ZERO /1.0D0,5.0D-2,0.0D0/ 13038C***FIRST EXECUTABLE STATEMENT DQRFAC 13039C 13040 IF(ISUBG4.EQ.'RFAC')THEN 13041 WRITE(ICOUT,9052)LIPVT 13042 9052 FORMAT('LIPVT = ',I8) 13043 CALL DPWRST('XXX','BUG ') 13044 ENDIF 13045C 13046 EPSMCH = D1MACH(4) 13047C 13048C COMPUTE THE INITIAL COLUMN NORMS AND INITIALIZE SEVERAL ARRAYS. 13049C 13050 DO 10 J = 1, N 13051 ACNORM(J) = DENORM(M,A(1,J)) 13052 SIGMA(J) = ACNORM(J) 13053 WA(J) = SIGMA(J) 13054 IF (PIVOT) IPVT(J) = J 13055 10 CONTINUE 13056C 13057C REDUCE A TO R WITH HOUSEHOLDER TRANSFORMATIONS. 13058C 13059 MINMN = MIN(M,N) 13060 DO 110 J = 1, MINMN 13061 IF (.NOT.PIVOT) GO TO 40 13062C 13063C BRING THE COLUMN OF LARGEST NORM INTO THE PIVOT POSITION. 13064C 13065 KMAX = J 13066 DO 20 K = J, N 13067 IF (SIGMA(K) .GT. SIGMA(KMAX)) KMAX = K 13068 20 CONTINUE 13069 IF (KMAX .EQ. J) GO TO 40 13070 DO 30 I = 1, M 13071 TEMP = A(I,J) 13072 A(I,J) = A(I,KMAX) 13073 A(I,KMAX) = TEMP 13074 30 CONTINUE 13075 SIGMA(KMAX) = SIGMA(J) 13076 WA(KMAX) = WA(J) 13077 K = IPVT(J) 13078 IPVT(J) = IPVT(KMAX) 13079 IPVT(KMAX) = K 13080 40 CONTINUE 13081C 13082C COMPUTE THE HOUSEHOLDER TRANSFORMATION TO REDUCE THE 13083C J-TH COLUMN OF A TO A MULTIPLE OF THE J-TH UNIT VECTOR. 13084C 13085 AJNORM = DENORM(M-J+1,A(J,J)) 13086 IF (AJNORM .EQ. ZERO) GO TO 100 13087 IF (A(J,J) .LT. ZERO) AJNORM = -AJNORM 13088 DO 50 I = J, M 13089 A(I,J) = A(I,J)/AJNORM 13090 50 CONTINUE 13091 A(J,J) = A(J,J) + ONE 13092C 13093C APPLY THE TRANSFORMATION TO THE REMAINING COLUMNS 13094C AND UPDATE THE NORMS. 13095C 13096 JP1 = J + 1 13097 IF (N .LT. JP1) GO TO 100 13098 DO 90 K = JP1, N 13099 SUM = ZERO 13100 DO 60 I = J, M 13101 SUM = SUM + A(I,J)*A(I,K) 13102 60 CONTINUE 13103 TEMP = SUM/A(J,J) 13104 DO 70 I = J, M 13105 A(I,K) = A(I,K) - TEMP*A(I,J) 13106 70 CONTINUE 13107 IF (.NOT.PIVOT .OR. SIGMA(K) .EQ. ZERO) GO TO 80 13108 TEMP = A(J,K)/SIGMA(K) 13109 SIGMA(K) = SIGMA(K)*SQRT(MAX(ZERO,ONE-TEMP**2)) 13110 IF (P05*(SIGMA(K)/WA(K))**2 .GT. EPSMCH) GO TO 80 13111 SIGMA(K) = DENORM(M-J,A(JP1,K)) 13112 WA(K) = SIGMA(K) 13113 80 CONTINUE 13114 90 CONTINUE 13115 100 CONTINUE 13116 SIGMA(J) = -AJNORM 13117 110 CONTINUE 13118 RETURN 13119C 13120C LAST CARD OF SUBROUTINE DQRFAC. 13121C 13122 END 13123*DECK DENORM 13124 DOUBLE PRECISION FUNCTION DENORM (N, X) 13125C***BEGIN PROLOGUE DENORM 13126C***SUBSIDIARY 13127C***PURPOSE Subsidiary to DNSQ and DNSQE 13128C***LIBRARY SLATEC 13129C***TYPE DOUBLE PRECISION (ENORM-S, DENORM-D) 13130C***AUTHOR (UNKNOWN) 13131C***DESCRIPTION 13132C 13133C Given an N-vector X, this function calculates the 13134C Euclidean norm of X. 13135C 13136C The Euclidean norm is computed by accumulating the sum of 13137C squares in three different sums. The sums of squares for the 13138C small and large components are scaled so that no overflows 13139C occur. Non-destructive underflows are permitted. Underflows 13140C and overflows do not occur in the computation of the unscaled 13141C sum of squares for the intermediate components. 13142C The definitions of small, intermediate and large components 13143C depend on two constants, RDWARF and RGIANT. The main 13144C restrictions on these constants are that RDWARF**2 not 13145C underflow and RGIANT**2 not overflow. The constants 13146C given here are suitable for every known computer. 13147C 13148C The function statement is 13149C 13150C DOUBLE PRECISION FUNCTION DENORM(N,X) 13151C 13152C where 13153C 13154C N is a positive integer input variable. 13155C 13156C X is an input array of length N. 13157C 13158C***SEE ALSO DNSQ, DNSQE 13159C***ROUTINES CALLED (NONE) 13160C***REVISION HISTORY (YYMMDD) 13161C 800301 DATE WRITTEN 13162C 890531 Changed all specific intrinsics to generic. (WRB) 13163C 890831 Modified array declarations. (WRB) 13164C 891214 Prologue converted to Version 4.0 format. (BAB) 13165C 900326 Removed duplicate information from DESCRIPTION section. 13166C (WRB) 13167C 900328 Added TYPE section. (WRB) 13168C***END PROLOGUE DENORM 13169 INTEGER I, N 13170 DOUBLE PRECISION AGIANT, FLOATN, ONE, RDWARF, RGIANT, S1, S2, S3, 13171 1 X(*), X1MAX, X3MAX, XABS, ZERO 13172 SAVE ONE, ZERO, RDWARF, RGIANT 13173 DATA ONE,ZERO,RDWARF,RGIANT /1.0D0,0.0D0,3.834D-20,1.304D19/ 13174C 13175 DENORM = ZERO 13176C 13177C***FIRST EXECUTABLE STATEMENT DENORM 13178 S1 = ZERO 13179 S2 = ZERO 13180 S3 = ZERO 13181 X1MAX = ZERO 13182 X3MAX = ZERO 13183 FLOATN = N 13184 AGIANT = RGIANT/FLOATN 13185 DO 90 I = 1, N 13186 XABS = ABS(X(I)) 13187 IF (XABS .GT. RDWARF .AND. XABS .LT. AGIANT) GO TO 70 13188 IF (XABS .LE. RDWARF) GO TO 30 13189C 13190C SUM FOR LARGE COMPONENTS. 13191C 13192 IF (XABS .LE. X1MAX) GO TO 10 13193 S1 = ONE + S1*(X1MAX/XABS)**2 13194 X1MAX = XABS 13195 GO TO 20 13196 10 CONTINUE 13197 S1 = S1 + (XABS/X1MAX)**2 13198 20 CONTINUE 13199 GO TO 60 13200 30 CONTINUE 13201C 13202C SUM FOR SMALL COMPONENTS. 13203C 13204 IF (XABS .LE. X3MAX) GO TO 40 13205 S3 = ONE + S3*(X3MAX/XABS)**2 13206 X3MAX = XABS 13207 GO TO 50 13208 40 CONTINUE 13209 IF (XABS .NE. ZERO) S3 = S3 + (XABS/X3MAX)**2 13210 50 CONTINUE 13211 60 CONTINUE 13212 GO TO 80 13213 70 CONTINUE 13214C 13215C SUM FOR INTERMEDIATE COMPONENTS. 13216C 13217 S2 = S2 + XABS**2 13218 80 CONTINUE 13219 90 CONTINUE 13220C 13221C CALCULATION OF NORM. 13222C 13223 IF (S1 .EQ. ZERO) GO TO 100 13224 DENORM = X1MAX*SQRT(S1+(S2/X1MAX)/X1MAX) 13225 GO TO 130 13226 100 CONTINUE 13227 IF (S2 .EQ. ZERO) GO TO 110 13228 IF (S2 .GE. X3MAX) 13229 1 DENORM = SQRT(S2*(ONE+(X3MAX/S2)*(X3MAX*S3))) 13230 IF (S2 .LT. X3MAX) 13231 1 DENORM = SQRT(X3MAX*((S2/X3MAX)+(X3MAX*S3))) 13232 GO TO 120 13233 110 CONTINUE 13234 DENORM = X3MAX*SQRT(S3) 13235 120 CONTINUE 13236 130 CONTINUE 13237 RETURN 13238C 13239C LAST CARD OF FUNCTION DENORM. 13240C 13241 END 13242*DECK DQFORM 13243 SUBROUTINE DQFORM (M, N, Q, LDQ, WA) 13244C***BEGIN PROLOGUE DQFORM 13245C***SUBSIDIARY 13246C***PURPOSE Subsidiary to DNSQ and DNSQE 13247C***LIBRARY SLATEC 13248C***TYPE DOUBLE PRECISION (QFORM-S, DQFORM-D) 13249C***AUTHOR (UNKNOWN) 13250C***DESCRIPTION 13251C 13252C This subroutine proceeds from the computed QR factorization of 13253C an M by N matrix A to accumulate the M by M orthogonal matrix 13254C Q from its factored form. 13255C 13256C The subroutine statement is 13257C 13258C SUBROUTINE DQFORM(M,N,Q,LDQ,WA) 13259C 13260C where 13261C 13262C M is a positive integer input variable set to the number 13263C of rows of A and the order of Q. 13264C 13265C N is a positive integer input variable set to the number 13266C of columns of A. 13267C 13268C Q is an M by M array. On input the full lower trapezoid in 13269C the first MIN(M,N) columns of Q contains the factored form. 13270C On output Q has been accumulated into a square matrix. 13271C 13272C LDQ is a positive integer input variable not less than M 13273C which specifies the leading dimension of the array Q. 13274C 13275C WA is a work array of length M. 13276C 13277C***SEE ALSO DNSQ, DNSQE 13278C***ROUTINES CALLED (NONE) 13279C***REVISION HISTORY (YYMMDD) 13280C 800301 DATE WRITTEN 13281C 890531 Changed all specific intrinsics to generic. (WRB) 13282C 890831 Modified array declarations. (WRB) 13283C 891214 Prologue converted to Version 4.0 format. (BAB) 13284C 900326 Removed duplicate information from DESCRIPTION section. 13285C (WRB) 13286C 900328 Added TYPE section. (WRB) 13287C***END PROLOGUE DQFORM 13288 INTEGER I, J, JM1, K, L, LDQ, M, MINMN, N, NP1 13289 DOUBLE PRECISION ONE, Q(LDQ,*), SUM, TEMP, WA(*), ZERO 13290 SAVE ONE, ZERO 13291 DATA ONE,ZERO /1.0D0,0.0D0/ 13292C 13293C ZERO OUT UPPER TRIANGLE OF Q IN THE FIRST MIN(M,N) COLUMNS. 13294C 13295C***FIRST EXECUTABLE STATEMENT DQFORM 13296 MINMN = MIN(M,N) 13297 IF (MINMN .LT. 2) GO TO 30 13298 DO 20 J = 2, MINMN 13299 JM1 = J - 1 13300 DO 10 I = 1, JM1 13301 Q(I,J) = ZERO 13302 10 CONTINUE 13303 20 CONTINUE 13304 30 CONTINUE 13305C 13306C INITIALIZE REMAINING COLUMNS TO THOSE OF THE IDENTITY MATRIX. 13307C 13308 NP1 = N + 1 13309 IF (M .LT. NP1) GO TO 60 13310 DO 50 J = NP1, M 13311 DO 40 I = 1, M 13312 Q(I,J) = ZERO 13313 40 CONTINUE 13314 Q(J,J) = ONE 13315 50 CONTINUE 13316 60 CONTINUE 13317C 13318C ACCUMULATE Q FROM ITS FACTORED FORM. 13319C 13320 DO 120 L = 1, MINMN 13321 K = MINMN - L + 1 13322 DO 70 I = K, M 13323 WA(I) = Q(I,K) 13324 Q(I,K) = ZERO 13325 70 CONTINUE 13326 Q(K,K) = ONE 13327 IF (WA(K) .EQ. ZERO) GO TO 110 13328 DO 100 J = K, M 13329 SUM = ZERO 13330 DO 80 I = K, M 13331 SUM = SUM + Q(I,J)*WA(I) 13332 80 CONTINUE 13333 TEMP = SUM/WA(K) 13334 DO 90 I = K, M 13335 Q(I,J) = Q(I,J) - TEMP*WA(I) 13336 90 CONTINUE 13337 100 CONTINUE 13338 110 CONTINUE 13339 120 CONTINUE 13340 RETURN 13341C 13342C LAST CARD OF SUBROUTINE DQFORM. 13343C 13344 END 13345*DECK DDOGLG 13346 SUBROUTINE DDOGLG (N, R, LR, DIAG, QTB, DELTA, X, WA1, WA2) 13347C***BEGIN PROLOGUE DDOGLG 13348C***SUBSIDIARY 13349C***PURPOSE Subsidiary to DNSQ and DNSQE 13350C***LIBRARY SLATEC 13351C***TYPE DOUBLE PRECISION (DOGLEG-S, DDOGLG-D) 13352C***AUTHOR (UNKNOWN) 13353C***DESCRIPTION 13354C 13355C Given an M by N matrix A, an N by N nonsingular diagonal 13356C matrix D, an M-vector B, and a positive number DELTA, the 13357C problem is to determine the convex combination X of the 13358C Gauss-Newton and scaled gradient directions that minimizes 13359C (A*X - B) in the least squares sense, subject to the 13360C restriction that the Euclidean norm of D*X be at most DELTA. 13361C 13362C This subroutine completes the solution of the problem 13363C if it is provided with the necessary information from the 13364C QR factorization of A. That is, if A = Q*R, where Q has 13365C orthogonal columns and R is an upper triangular matrix, 13366C then DDOGLG expects the full upper triangle of R and 13367C the first N components of (Q transpose)*B. 13368C 13369C The subroutine statement is 13370C 13371C SUBROUTINE DDOGLG(N,R,LR,DIAG,QTB,DELTA,X,WA1,WA2) 13372C 13373C where 13374C 13375C N is a positive integer input variable set to the order of R. 13376C 13377C R is an input array of length LR which must contain the upper 13378C triangular matrix R stored by rows. 13379C 13380C LR is a positive integer input variable not less than 13381C (N*(N+1))/2. 13382C 13383C DIAG is an input array of length N which must contain the 13384C diagonal elements of the matrix D. 13385C 13386C QTB is an input array of length N which must contain the first 13387C N elements of the vector (Q transpose)*B. 13388C 13389C DELTA is a positive input variable which specifies an upper 13390C bound on the Euclidean norm of D*X. 13391C 13392C X is an output array of length N which contains the desired 13393C convex combination of the Gauss-Newton direction and the 13394C scaled gradient direction. 13395C 13396C WA1 and WA2 are work arrays of length N. 13397C 13398C***SEE ALSO DNSQ, DNSQE 13399C***ROUTINES CALLED D1MACH, DENORM 13400C***REVISION HISTORY (YYMMDD) 13401C 800301 DATE WRITTEN 13402C 890531 Changed all specific intrinsics to generic. (WRB) 13403C 890831 Modified array declarations. (WRB) 13404C 891214 Prologue converted to Version 4.0 format. (BAB) 13405C 900326 Removed duplicate information from DESCRIPTION section. 13406C (WRB) 13407C 900328 Added TYPE section. (WRB) 13408C***END PROLOGUE DDOGLG 13409CCCCC DOUBLE PRECISION D1MACH,DENORM 13410 DOUBLE PRECISION DENORM 13411 INTEGER I, J, JJ, JP1, K, L, LR, N 13412 DOUBLE PRECISION ALPHA, BNORM, DELTA, DIAG(*), EPSMCH, GNORM, 13413 1 ONE, QNORM, QTB(*), R(*), SGNORM, SUM, TEMP, WA1(*), 13414 2 WA2(*), X(*), ZERO 13415 SAVE ONE, ZERO 13416C 13417 INCLUDE 'DPCOBE.INC' 13418 INCLUDE 'DPCOMC.INC' 13419 INCLUDE 'DPCOP2.INC' 13420C 13421 DATA ONE,ZERO /1.0D0,0.0D0/ 13422C 13423 IF(ISUBG4.EQ.'OGLG')THEN 13424 WRITE(ICOUT,9052)LR 13425 9052 FORMAT('LR = ',I8) 13426 CALL DPWRST('XXX','BUG ') 13427 ENDIF 13428C 13429C EPSMCH IS THE MACHINE PRECISION. 13430C 13431C***FIRST EXECUTABLE STATEMENT DDOGLG 13432 EPSMCH = D1MACH(4) 13433C 13434C FIRST, CALCULATE THE GAUSS-NEWTON DIRECTION. 13435C 13436 JJ = (N*(N + 1))/2 + 1 13437 DO 50 K = 1, N 13438 J = N - K + 1 13439 JP1 = J + 1 13440 JJ = JJ - K 13441 L = JJ + 1 13442 SUM = ZERO 13443 IF (N .LT. JP1) GO TO 20 13444 DO 10 I = JP1, N 13445 SUM = SUM + R(L)*X(I) 13446 L = L + 1 13447 10 CONTINUE 13448 20 CONTINUE 13449 TEMP = R(JJ) 13450 IF (TEMP .NE. ZERO) GO TO 40 13451 L = J 13452 DO 30 I = 1, J 13453 TEMP = MAX(TEMP,ABS(R(L))) 13454 L = L + N - I 13455 30 CONTINUE 13456 TEMP = EPSMCH*TEMP 13457 IF (TEMP .EQ. ZERO) TEMP = EPSMCH 13458 40 CONTINUE 13459 X(J) = (QTB(J) - SUM)/TEMP 13460 50 CONTINUE 13461C 13462C TEST WHETHER THE GAUSS-NEWTON DIRECTION IS ACCEPTABLE. 13463C 13464 DO 60 J = 1, N 13465 WA1(J) = ZERO 13466 WA2(J) = DIAG(J)*X(J) 13467 60 CONTINUE 13468 QNORM = DENORM(N,WA2) 13469 IF (QNORM .LE. DELTA) GO TO 140 13470C 13471C THE GAUSS-NEWTON DIRECTION IS NOT ACCEPTABLE. 13472C NEXT, CALCULATE THE SCALED GRADIENT DIRECTION. 13473C 13474 L = 1 13475 DO 80 J = 1, N 13476 TEMP = QTB(J) 13477 DO 70 I = J, N 13478 WA1(I) = WA1(I) + R(L)*TEMP 13479 L = L + 1 13480 70 CONTINUE 13481 WA1(J) = WA1(J)/DIAG(J) 13482 80 CONTINUE 13483C 13484C CALCULATE THE NORM OF THE SCALED GRADIENT AND TEST FOR 13485C THE SPECIAL CASE IN WHICH THE SCALED GRADIENT IS ZERO. 13486C 13487 GNORM = DENORM(N,WA1) 13488 SGNORM = ZERO 13489 ALPHA = DELTA/QNORM 13490 IF (GNORM .EQ. ZERO) GO TO 120 13491C 13492C CALCULATE THE POINT ALONG THE SCALED GRADIENT 13493C AT WHICH THE QUADRATIC IS MINIMIZED. 13494C 13495 DO 90 J = 1, N 13496 WA1(J) = (WA1(J)/GNORM)/DIAG(J) 13497 90 CONTINUE 13498 L = 1 13499 DO 110 J = 1, N 13500 SUM = ZERO 13501 DO 100 I = J, N 13502 SUM = SUM + R(L)*WA1(I) 13503 L = L + 1 13504 100 CONTINUE 13505 WA2(J) = SUM 13506 110 CONTINUE 13507 TEMP = DENORM(N,WA2) 13508 SGNORM = (GNORM/TEMP)/TEMP 13509C 13510C TEST WHETHER THE SCALED GRADIENT DIRECTION IS ACCEPTABLE. 13511C 13512 ALPHA = ZERO 13513 IF (SGNORM .GE. DELTA) GO TO 120 13514C 13515C THE SCALED GRADIENT DIRECTION IS NOT ACCEPTABLE. 13516C FINALLY, CALCULATE THE POINT ALONG THE DOGLEG 13517C AT WHICH THE QUADRATIC IS MINIMIZED. 13518C 13519 BNORM = DENORM(N,QTB) 13520 TEMP = (BNORM/GNORM)*(BNORM/QNORM)*(SGNORM/DELTA) 13521 TEMP = TEMP - (DELTA/QNORM)*(SGNORM/DELTA)**2 13522 1 + SQRT((TEMP-(DELTA/QNORM))**2 13523 2 +(ONE-(DELTA/QNORM)**2)*(ONE-(SGNORM/DELTA)**2)) 13524 ALPHA = ((DELTA/QNORM)*(ONE - (SGNORM/DELTA)**2))/TEMP 13525 120 CONTINUE 13526C 13527C FORM APPROPRIATE CONVEX COMBINATION OF THE GAUSS-NEWTON 13528C DIRECTION AND THE SCALED GRADIENT DIRECTION. 13529C 13530 TEMP = (ONE - ALPHA)*MIN(SGNORM,DELTA) 13531 DO 130 J = 1, N 13532 X(J) = TEMP*WA1(J) + ALPHA*X(J) 13533 130 CONTINUE 13534 140 CONTINUE 13535 RETURN 13536C 13537C LAST CARD OF SUBROUTINE DDOGLG. 13538C 13539 END 13540*DECK D1UPDT 13541 SUBROUTINE D1UPDT (M, N, S, LS, U, V, W, SING) 13542C***BEGIN PROLOGUE D1UPDT 13543C***SUBSIDIARY 13544C***PURPOSE Subsidiary to DNSQ and DNSQE 13545C***LIBRARY SLATEC 13546C***TYPE DOUBLE PRECISION (R1UPDT-S, D1UPDT-D) 13547C***AUTHOR (UNKNOWN) 13548C***DESCRIPTION 13549C 13550C Given an M by N lower trapezoidal matrix S, an M-vector U, 13551C and an N-vector V, the problem is to determine an 13552C orthogonal matrix Q such that 13553C 13554C t 13555C (S + U*V )*Q 13556C 13557C is again lower trapezoidal. 13558C 13559C This subroutine determines Q as the product of 2*(N - 1) 13560C transformations 13561C 13562C GV(N-1)*...*GV(1)*GW(1)*...*GW(N-1) 13563C 13564C where GV(I), GW(I) are Givens rotations in the (I,N) plane 13565C which eliminate elements in the I-th and N-th planes, 13566C respectively. Q itself is not accumulated, rather the 13567C information to recover the GV, GW rotations is returned. 13568C 13569C The SUBROUTINE statement is 13570C 13571C SUBROUTINE D1UPDT(M,N,S,LS,U,V,W,SING) 13572C 13573C where 13574C 13575C M is a positive integer input variable set to the number 13576C of rows of S. 13577C 13578C N is a positive integer input variable set to the number 13579C of columns of S. N must not exceed M. 13580C 13581C S is an array of length LS. On input S must contain the lower 13582C trapezoidal matrix S stored by columns. On output S contains 13583C the lower trapezoidal matrix produced as described above. 13584C 13585C LS is a positive integer input variable not less than 13586C (N*(2*M-N+1))/2. 13587C 13588C U is an input array of length M which must contain the 13589C vector U. 13590C 13591C V is an array of length N. On input V must contain the vector 13592C V. On output V(I) contains the information necessary to 13593C recover the Givens rotation GV(I) described above. 13594C 13595C W is an output array of length M. W(I) contains information 13596C necessary to recover the Givens rotation GW(I) described 13597C above. 13598C 13599C SING is a LOGICAL output variable. SING is set TRUE if any 13600C of the diagonal elements of the output S are zero. Otherwise 13601C SING is set FALSE. 13602C 13603C***SEE ALSO DNSQ, DNSQE 13604C***ROUTINES CALLED D1MACH 13605C***REVISION HISTORY (YYMMDD) 13606C 800301 DATE WRITTEN 13607C 890531 Changed all specific intrinsics to generic. (WRB) 13608C 890831 Modified array declarations. (WRB) 13609C 891214 Prologue converted to Version 4.0 format. (BAB) 13610C 900326 Removed duplicate information from DESCRIPTION section. 13611C (WRB) 13612C 900328 Added TYPE section. (WRB) 13613C***END PROLOGUE D1UPDT 13614CCCCC DOUBLE PRECISION D1MACH 13615 INTEGER I, J, JJ, L, LS, M, N, NM1, NMJ 13616 DOUBLE PRECISION COS, COTAN, GIANT, ONE, P25, P5, S(*), 13617 1 SIN, TAN, TAU, TEMP, U(*), V(*), W(*), ZERO 13618 LOGICAL SING 13619 SAVE ONE, P5, P25, ZERO 13620C 13621 INCLUDE 'DPCOMC.INC' 13622 INCLUDE 'DPCOBE.INC' 13623 INCLUDE 'DPCOP2.INC' 13624C 13625 DATA ONE,P5,P25,ZERO /1.0D0,5.0D-1,2.5D-1,0.0D0/ 13626C 13627 IF(ISUBG4.EQ.'DNSQ')THEN 13628 WRITE(ICOUT,9052)LS 13629 9052 FORMAT('LS = ',I8) 13630 CALL DPWRST('XXX','BUG ') 13631 ENDIF 13632C 13633C GIANT IS THE LARGEST MAGNITUDE. 13634C 13635C***FIRST EXECUTABLE STATEMENT D1UPDT 13636 GIANT = D1MACH(2) 13637C 13638C INITIALIZE THE DIAGONAL ELEMENT POINTER. 13639C 13640 JJ = (N*(2*M - N + 1))/2 - (M - N) 13641C 13642C MOVE THE NONTRIVIAL PART OF THE LAST COLUMN OF S INTO W. 13643C 13644 L = JJ 13645 DO 10 I = N, M 13646 W(I) = S(L) 13647 L = L + 1 13648 10 CONTINUE 13649C 13650C ROTATE THE VECTOR V INTO A MULTIPLE OF THE N-TH UNIT VECTOR 13651C IN SUCH A WAY THAT A SPIKE IS INTRODUCED INTO W. 13652C 13653 NM1 = N - 1 13654 IF (NM1 .LT. 1) GO TO 70 13655 DO 60 NMJ = 1, NM1 13656 J = N - NMJ 13657 JJ = JJ - (M - J + 1) 13658 W(J) = ZERO 13659 IF (V(J) .EQ. ZERO) GO TO 50 13660C 13661C DETERMINE A GIVENS ROTATION WHICH ELIMINATES THE 13662C J-TH ELEMENT OF V. 13663C 13664 IF (ABS(V(N)) .GE. ABS(V(J))) GO TO 20 13665 COTAN = V(N)/V(J) 13666 SIN = P5/SQRT(P25+P25*COTAN**2) 13667 COS = SIN*COTAN 13668 TAU = ONE 13669 IF (ABS(COS)*GIANT .GT. ONE) TAU = ONE/COS 13670 GO TO 30 13671 20 CONTINUE 13672 TAN = V(J)/V(N) 13673 COS = P5/SQRT(P25+P25*TAN**2) 13674 SIN = COS*TAN 13675 TAU = SIN 13676 30 CONTINUE 13677C 13678C APPLY THE TRANSFORMATION TO V AND STORE THE INFORMATION 13679C NECESSARY TO RECOVER THE GIVENS ROTATION. 13680C 13681 V(N) = SIN*V(J) + COS*V(N) 13682 V(J) = TAU 13683C 13684C APPLY THE TRANSFORMATION TO S AND EXTEND THE SPIKE IN W. 13685C 13686 L = JJ 13687 DO 40 I = J, M 13688 TEMP = COS*S(L) - SIN*W(I) 13689 W(I) = SIN*S(L) + COS*W(I) 13690 S(L) = TEMP 13691 L = L + 1 13692 40 CONTINUE 13693 50 CONTINUE 13694 60 CONTINUE 13695 70 CONTINUE 13696C 13697C ADD THE SPIKE FROM THE RANK 1 UPDATE TO W. 13698C 13699 DO 80 I = 1, M 13700 W(I) = W(I) + V(N)*U(I) 13701 80 CONTINUE 13702C 13703C ELIMINATE THE SPIKE. 13704C 13705 SING = .FALSE. 13706 IF (NM1 .LT. 1) GO TO 140 13707 DO 130 J = 1, NM1 13708 IF (W(J) .EQ. ZERO) GO TO 120 13709C 13710C DETERMINE A GIVENS ROTATION WHICH ELIMINATES THE 13711C J-TH ELEMENT OF THE SPIKE. 13712C 13713 IF (ABS(S(JJ)) .GE. ABS(W(J))) GO TO 90 13714 COTAN = S(JJ)/W(J) 13715 SIN = P5/SQRT(P25+P25*COTAN**2) 13716 COS = SIN*COTAN 13717 TAU = ONE 13718 IF (ABS(COS)*GIANT .GT. ONE) TAU = ONE/COS 13719 GO TO 100 13720 90 CONTINUE 13721 TAN = W(J)/S(JJ) 13722 COS = P5/SQRT(P25+P25*TAN**2) 13723 SIN = COS*TAN 13724 TAU = SIN 13725 100 CONTINUE 13726C 13727C APPLY THE TRANSFORMATION TO S AND REDUCE THE SPIKE IN W. 13728C 13729 L = JJ 13730 DO 110 I = J, M 13731 TEMP = COS*S(L) + SIN*W(I) 13732 W(I) = -SIN*S(L) + COS*W(I) 13733 S(L) = TEMP 13734 L = L + 1 13735 110 CONTINUE 13736C 13737C STORE THE INFORMATION NECESSARY TO RECOVER THE 13738C GIVENS ROTATION. 13739C 13740 W(J) = TAU 13741 120 CONTINUE 13742C 13743C TEST FOR ZERO DIAGONAL ELEMENTS IN THE OUTPUT S. 13744C 13745 IF (S(JJ) .EQ. ZERO) SING = .TRUE. 13746 JJ = JJ + (M - J + 1) 13747 130 CONTINUE 13748 140 CONTINUE 13749C 13750C MOVE W BACK INTO THE LAST COLUMN OF THE OUTPUT S. 13751C 13752 L = JJ 13753 DO 150 I = N, M 13754 S(L) = W(I) 13755 L = L + 1 13756 150 CONTINUE 13757 IF (S(JJ) .EQ. ZERO) SING = .TRUE. 13758 RETURN 13759C 13760C LAST CARD OF SUBROUTINE D1UPDT. 13761C 13762 END 13763*DECK D1MPYQ 13764 SUBROUTINE D1MPYQ (M, N, A, LDA, V, W) 13765C***BEGIN PROLOGUE D1MPYQ 13766C***SUBSIDIARY 13767C***PURPOSE Subsidiary to DNSQ and DNSQE 13768C***LIBRARY SLATEC 13769C***TYPE DOUBLE PRECISION (R1MPYQ-S, D1MPYQ-D) 13770C***AUTHOR (UNKNOWN) 13771C***DESCRIPTION 13772C 13773C Given an M by N matrix A, this subroutine computes A*Q where 13774C Q is the product of 2*(N - 1) transformations 13775C 13776C GV(N-1)*...*GV(1)*GW(1)*...*GW(N-1) 13777C 13778C and GV(I), GW(I) are Givens rotations in the (I,N) plane which 13779C eliminate elements in the I-th and N-th planes, respectively. 13780C Q itself is not given, rather the information to recover the 13781C GV, GW rotations is supplied. 13782C 13783C The SUBROUTINE statement is 13784C 13785C SUBROUTINE D1MPYQ(M,N,A,LDA,V,W) 13786C 13787C where 13788C 13789C M is a positive integer input variable set to the number 13790C of rows of A. 13791C 13792C N IS a positive integer input variable set to the number 13793C of columns of A. 13794C 13795C A is an M by N array. On input A must contain the matrix 13796C to be postmultiplied by the orthogonal matrix Q 13797C described above. On output A*Q has replaced A. 13798C 13799C LDA is a positive integer input variable not less than M 13800C which specifies the leading dimension of the array A. 13801C 13802C V is an input array of length N. V(I) must contain the 13803C information necessary to recover the Givens rotation GV(I) 13804C described above. 13805C 13806C W is an input array of length N. W(I) must contain the 13807C information necessary to recover the Givens rotation GW(I) 13808C described above. 13809C 13810C***SEE ALSO DNSQ, DNSQE 13811C***ROUTINES CALLED (NONE) 13812C***REVISION HISTORY (YYMMDD) 13813C 800301 DATE WRITTEN 13814C 890531 Changed all specific intrinsics to generic. (WRB) 13815C 890831 Modified array declarations. (WRB) 13816C 891214 Prologue converted to Version 4.0 format. (BAB) 13817C 900326 Removed duplicate information from DESCRIPTION section. 13818C (WRB) 13819C 900328 Added TYPE section. (WRB) 13820C***END PROLOGUE D1MPYQ 13821 INTEGER I, J, LDA, M, N, NM1, NMJ 13822 DOUBLE PRECISION A(LDA,*), COS, ONE, SIN, TEMP, V(*), W(*) 13823 SAVE ONE 13824 DATA ONE /1.0D0/ 13825C 13826C APPLY THE FIRST SET OF GIVENS ROTATIONS TO A. 13827C 13828C***FIRST EXECUTABLE STATEMENT D1MPYQ 13829 NM1 = N - 1 13830 IF (NM1 .LT. 1) GO TO 50 13831 COS = 0.0 13832 SIN = 0.0 13833 DO 20 NMJ = 1, NM1 13834 J = N - NMJ 13835 IF (ABS(V(J)) .GT. ONE) COS = ONE/V(J) 13836 IF (ABS(V(J)) .GT. ONE) SIN = SQRT(ONE-COS**2) 13837 IF (ABS(V(J)) .LE. ONE) SIN = V(J) 13838 IF (ABS(V(J)) .LE. ONE) COS = SQRT(ONE-SIN**2) 13839 DO 10 I = 1, M 13840 TEMP = COS*A(I,J) - SIN*A(I,N) 13841 A(I,N) = SIN*A(I,J) + COS*A(I,N) 13842 A(I,J) = TEMP 13843 10 CONTINUE 13844 20 CONTINUE 13845C 13846C APPLY THE SECOND SET OF GIVENS ROTATIONS TO A. 13847C 13848 DO 40 J = 1, NM1 13849 IF (ABS(W(J)) .GT. ONE) COS = ONE/W(J) 13850 IF (ABS(W(J)) .GT. ONE) SIN = SQRT(ONE-COS**2) 13851 IF (ABS(W(J)) .LE. ONE) SIN = W(J) 13852 IF (ABS(W(J)) .LE. ONE) COS = SQRT(ONE-SIN**2) 13853 DO 30 I = 1, M 13854 TEMP = COS*A(I,J) + SIN*A(I,N) 13855 A(I,N) = -SIN*A(I,J) + COS*A(I,N) 13856 A(I,J) = TEMP 13857 30 CONTINUE 13858 40 CONTINUE 13859 50 CONTINUE 13860 RETURN 13861C 13862C LAST CARD OF SUBROUTINE D1MPYQ. 13863C 13864 END 13865 SUBROUTINE DECOMP(IND, LOCA, NW, W, M, LSTFI, N, LS, LV, 13866CCCCC SUBROUTINE DECOMP(IND, LOCA, IOUT, NW, W, M, LSTFI, N, LS, LV, 13867 * LLIM, LP) 13868C PART OF ACM 591 FOR ANOVA 13869C ***************************** DECOMP ***************************** DEC 10 13870C DEC 20 13871C OBTAINS A FACTORIAL DECOMPOSITION OF THE VECTOR T WHERE T CONSISTS DEC 30 13872C OF THE FIRST NCELLS LOCATIONS OF THE VECTOR A (IN ARRAY W); THE DEC 40 13873C FACTORIAL DECOMPOSITION IS FORMED IN VECTOR A AND OCCUPIES ALL THE DEC 50 13874C LOCATIONS OF THIS VECTOR. ALTERNATIVELY COMPUTES CLASSIFICATION DEC 60 13875C SUMS/MEANS IN VECTOR A FOR RESTRUCTURING DATA OR FOR THE C OPTION. DEC 70 13876C FOLLOWS THE ALGORITHM DESCRIBED IN HEMMERLE, STATISTICAL COMPUTA- DEC 80 13877C TIONS ON A DIGITAL COMPUTER 1967. DEC 90 13878C DEC 100 13879C IND = 0 (FACTORIAL DECOMPOSITION); IND = 1 (CLASSIFICATION SUMS); DEC 110 13880C IND = 2 (CLASSIFICATION MEANS) DEC 120 13881C DEC 130 13882C LOCA = BASE ADDRESS OF VECTOR A IN ARRAY W; IOUT = OUTPUT UNIT FOR DEC 140 13883C CLASSIFICATIONS MEANS. DEC 150 13884C DEC 160 13885C (SEE MAIN PROGRAM COMMENTS) FOR DESCRIPTION OF OTHER ARGUMENTS DEC 170 13886C DEC 180 13887C ****************************************************************** DEC 190 13888C NOTE: THE ARGUMENTS LS,LV,LP, AND IOUT ARE USED ONLY FOR C MEANS 13889 DOUBLE PRECISION W, TEMP, DNPM, CMEAN 13890 DIMENSION W(NW), LSTFI(M), LS(N), LV(N), LLIM(N), LP(10) 13891C 13892CCCCC CHARACTER*1 IDOT 13893C 13894 INCLUDE 'DPCOBE.INC' 13895 INCLUDE 'DPCOP2.INC' 13896C 13897CCCCC DATA IDOT /'.'/ 13898C 13899 IF(ISUBG4.EQ.'COMP')THEN 13900 WRITE(ICOUT,9051)LS,LV 13901 9051 FORMAT('LS,LV = ',2I8) 13902 CALL DPWRST('XXX','BUG ') 13903 DO9050I=1,10 13904 WRITE(ICOUT,9052)I,LP(1) 13905 9052 FORMAT('I,LP(I) = ',2I8) 13906 CALL DPWRST('XXX','BUG ') 13907 9050 CONTINUE 13908 ENDIF 13909C 13910 L = 0 13911 LL = 1 13912 MM = 1 13913 NN = 1 13914 LOCTWO = LOCA + 1 13915 10 LOCONE = LOCA + 1 13916 KK = LL 13917C FIND NUMBER OF ELEMENTS IN THIS MEAN 13918C 13919 K1 = N + 1 - NN 13920 NPM = LLIM(K1) 13921 DNPM = NPM 13922 20 LOCTWO = LOCTWO + LSTFI(MM) 13923C FIND NUMBER OF MEANS FOR EACH RESIDUAL 13924 MEANST = LSTFI(MM+1) 13925C FIND INCREMENT 13926 K1 = M + 1 - KK 13927 INC = LSTFI(K1) 13928C FORM THE ARRAY OF MEANS 13929 MD = 1 13930 NO = M - MM 13931CNIST IF (IND.EQ.2) CALL LABEL(NO, IDOT, LS, IOUT, N, LV, LP) 13932 DO 90 I=1,MEANST,INC 13933 JTWO = I + INC - 1 13934 DO 80 J=I,JTWO 13935 L = MD 13936 LD = MD 13937 I1 = LOCTWO + J - 1 13938 TEMP = 0.D0 13939 DO 30 K=1,NPM 13940 I2 = LOCONE + L - 1 13941 TEMP = TEMP + W(I2) 13942 L = L + INC 13943 30 CONTINUE 13944C DEVIATES (IND=0); SUMS (IND=1); CLASSIFICATION MEANS (IND=2) 13945 IF (IND.EQ.0) GO TO 50 13946 IF (IND.EQ.1) GO TO 40 13947 IF (TEMP.EQ.0.0) THEN 13948 WRITE (ICOUT,99999) J 13949 CALL DPWRST('XXX','BUG ') 13950 ENDIF 13951 IF (TEMP.GT.0.0) CMEAN = W(I1)/TEMP 13952 IF (TEMP.GT.0.0) THEN 13953 WRITE (ICOUT,99998) J, W(I1), TEMP, CMEAN 13954 CALL DPWRST('XXX','BUG ') 13955 ENDIF 1395699999 FORMAT (1H , I6, 4X, 29H(MISSING CLASSIFICATION CELL)) 1395799998 FORMAT (1H , I6, 1X, E16.8, F5.0, 1X, E16.8) 13958 40 W(I1) = TEMP 13959 GO TO 70 13960 50 W(I1) = TEMP/DNPM 13961C FORM DEVIATES 13962 DO 60 K=1,NPM 13963 I2 = LOCONE + LD - 1 13964 W(I2) = W(I2) - W(I1) 13965 LD = LD + INC 13966 60 CONTINUE 13967 70 MD = MD + 1 13968 80 CONTINUE 13969 MD = L - INC + 1 13970 90 CONTINUE 13971 IF (KK.EQ.1) GO TO 100 13972 KK = KK - 1 13973 MM = MM + 1 13974 K1 = LL - KK 13975 LOCONE = LOCONE + LSTFI(K1) 13976 GO TO 20 13977 100 IF (NN.EQ.N) RETURN 13978 LL = LL + LL 13979 NN = NN + 1 13980 MM = MM + 1 13981 GO TO 10 13982 END 13983 SUBROUTINE SCAN(IPT, M, LER, N, LE, LS, LV, LLIM, LP, L, IA, 13984 * IBATCH) 13985C PART OF ACM 591 FOR ANOVA 13986C ****************************** SCAN ****************************** SCA 10 13987C SCA 20 13988C PROCESSES THE MODEL/HYPOTHESIS STATEMENT TO CONSTRUCT/MODIFY THE SCA 30 13989C E/R LIST (ARRAY LER); TURNS SWITCH ISST ON FOR AN INVALID STATE- SCA 40 13990C MENT. DETERMINES THE EFFECTIVE NUMBER OF FACTORS (NSUBS); TURNS SCA 50 13991C SWITCH IXST ON WHEN THE EFFECTIVE X MATRIX IS SQUARE; COMPUTES THE SCA 60 13992C PARAMETERS NEEDED IN RESTRUCTURING DATA (LPOUT AND NO1). COMPUTES SCA 70 13993C THE DEGREES OF FREEDOM APPLICABLE TO DATA WITH NO MISSING CELLS SCA 80 13994C (IDFM AND IDFR). SCA 90 13995C SCA 100 13996C IPT = POINTER TO BEGINNING OF MODEL/HYPOTHESIS STATEMENT IN INPUT SCA 110 13997C BUFFER; IBATCH = 1 (BATCH PROCESSING) OR IBATCH = 0 (INTERACTIVE) SCA 120 13998C SCA 130 13999C (SEE MAIN PROGRAM COMMENTS FOR DESCRIPTION OF OTHER ARGUMENTS) SCA 140 14000C SCA 150 14001C ****************************************************************** SCA 160 14002 COMMON /C1/ YPY, SSRM, SSEM, IIN, IOUT, IROPT, IVOPT, IGOPT, 14003 * IPOPT, IOFLAG, IBST, IHST, IRST, ISST, IXST, ICD, NSUBS, LPOUT, 14004 * NO1, IDF, IDFM, IDFR 14005 DIMENSION LER(M), LE(N), LS(N), LV(N), LLIM(N), LP(10), IA(L) 14006 DOUBLE PRECISION YPY, SSRM, SSEM 14007C 14008CNIST CHARACTER*1 ILP, IRP, IM, IH, ISTAR, ISLASH, IBLANK, IC 14009 CHARACTER*1 IRP, IM, IH, ISTAR, ISLASH, IBLANK, IC 14010 CHARACTER*4 ICD 14011C 14012CNIST CHARACTER*1 FUNCTION IGET 14013C 14014 INCLUDE 'DPCOBE.INC' 14015 INCLUDE 'DPCOP2.INC' 14016C 14017CCCCC DATA ILP /'('/ 14018 DATA IRP /')'/ 14019 DATA IM /'M'/ 14020 DATA IH /'H'/ 14021 DATA ISTAR /'*'/ 14022 DATA ISLASH /'/'/ 14023 DATA IBLANK /' '/ 14024C 14025 IF(ISUBG4.EQ.'SCAN')THEN 14026 WRITE(ICOUT,9052)LE,LS,LV 14027 9052 FORMAT('LE,LS,LV = ',3I8) 14028 CALL DPWRST('XXX','BUG ') 14029 ENDIF 14030C 14031 ISST = 0 14032 IXST = 0 14033 M1 = M - 1 14034 II = IPT 14035 IF (II.GT.L) GO TO 350 14036CNIST IC = IGET(II,IA,L) 14037 IC = ' ' 14038 IF (ICD(1:1).EQ.IH) GO TO 20 14039 IF (IC.EQ.ISTAR) GO TO 270 14040C INITIALIZE E/R LIST TO ZEROES FOR M AND ABSOLUTE VALUES FOR H 14041 DO 10 I=1,M1 14042 LER(I) = 0 14043 10 CONTINUE 14044 LER(M) = 1 14045 20 IF (LER(M).EQ.0) GO TO 350 14046 DO 30 I=1,M1 14047 LER(I) = IABS(LER(I)) 14048 30 CONTINUE 14049 M2 = 2*M 14050C SCAN TERM TO CONSTRUCT E/R LIST; ENTER NEGATIVES FOR H TERM 14051 40 DO 50 I=1,N 14052 LP(I) = M2 14053 50 CONTINUE 14054C SUM VALUES OF FACTOR SYMBOLS FOR E/R ENTRY; ZERO LP POSITIONS 14055 NE = 0 14056 NVS = 0 14057 60 IFLAG = 0 14058 DO 70 I=1,N 14059CNIST IF (IC.NE.LE(I)) GO TO 70 14060 LP(I) = 0 14061 IFLAG = 1 14062 NE = NE + 1 14063 NVS = NVS + LV(I) 14064 70 CONTINUE 14065 IF (IFLAG.NE.1) GO TO 80 14066 IF (II.GT.L) GO TO 350 14067CNIST IC = IGET(II,IA,L) 14068 GO TO 60 14069 80 IF (NE.EQ.0) GO TO 350 14070CNIST IF (IC.NE.ILP) GO TO 350 14071C SCAN SUBSCRIPTS; SET NONZERO LP ENTRIES TO NUMERICAL VALUES 14072 NS = 0 14073 NAS = 0 14074 90 IF (II.GT.L) GO TO 350 14075CNIST IC = IGET(II,IA,L) 14076CNIST SET FOLLOWING LINE JUST TO AVOID COMPILATION WARNING. 14077CNIST REMOVE IF WE ACTIVATE THIS CODE 14078 IC=' ' 14079 IFLAG = 0 14080 DO 120 I=1,N 14081CNIST IF (IC.NE.LS(I)) GO TO 120 14082 IF (LP(I).NE.0) LP(I) = LV(I) 14083 IF (LP(I).EQ.0) NAS = NAS + 1 14084C CHECK FOR INVALID NESTED TERM 14085 DO 100 J=I,N 14086 IF (LP(J).EQ.0) GO TO 110 14087 100 CONTINUE 14088 GO TO 350 14089 110 IFLAG = 1 14090 NS = NS + 1 14091 120 CONTINUE 14092 IF (IFLAG.NE.1) GO TO 130 14093 GO TO 90 14094 130 IF (NAS.NE.NE) GO TO 350 14095 IF (IC.NE.IRP) GO TO 350 14096 IF (NS.NE.NE) GO TO 150 14097C CHECK FOR INVALID CROSSED TERM 14098 DO 140 I=1,N 14099 IF (LP(I).EQ.M2) GO TO 140 14100 IF (LP(I).NE.0) GO TO 350 14101 140 CONTINUE 14102 I = M - NVS 14103 ITEMP = 0 14104 IF (ICD(1:1).EQ.IH) ITEMP = NVS + 1 14105 IF (LER(I).NE.ITEMP) GO TO 350 14106 LER(I) = NVS + 1 14107 IF (ICD(1:1).EQ.IH) LER(I) = -LER(I) 14108 GO TO 190 14109C ENTER SUM FOR NESTED TERM INTO E/R POSITIONS TO POOL 14110 150 DO 180 I=1,M1 14111 NUM = I - NVS 14112 DO 160 J=1,N 14113 NUM = NUM - LP(J) 14114 IF (NUM.GT.0) GO TO 160 14115 IF (NUM.EQ.0) GO TO 170 14116 NUM = NUM + LP(J) 14117 160 CONTINUE 14118 GO TO 180 14119 170 K = M - I 14120 ITEMP = 0 14121 IF (ICD(1:1).EQ.IH) ITEMP = NVS + 1 14122 IF (LER(K).NE.ITEMP) GO TO 350 14123 LER(K) = NVS + 1 14124 IF (ICD(1:1).EQ.IH) LER(K) = -LER(K) 14125 180 CONTINUE 14126 190 IF (II.GT.L) GO TO 200 14127CNIST IC = IGET(II,IA,L) 14128 IF (IC.EQ.IBLANK .AND. II.GT.L) GO TO 200 14129 IF (IC.NE.ISLASH) GO TO 40 14130C READ MODEL OR HYPOTHESIS CONTINUATION CARD (SLASH FOLLOWS TERM) 14131 READ (IIN,99999) (IA(I),I=1,L) 1413299999 FORMAT (80A1) 14133 IF (IBATCH.EQ.1) THEN 14134 WRITE (ICOUT,99998) (IA(I),I=1,L) 14135 CALL DPWRST('XXX','BUG ') 14136 ENDIF 1413799998 FORMAT (1H , 80A1) 14138 II = 1 14139CNIST IC = IGET(II,IA,L) 14140 GO TO 40 14141C CHECK FOR INVALID HYPOTHESIS TERM 14142 200 DO 220 I=1,M1 14143 DO 210 J=I,M1 14144 IF (LER(I).EQ.0) GO TO 210 14145 IF (LER(I).EQ.(-LER(J))) GO TO 350 14146 210 CONTINUE 14147 220 CONTINUE 14148C CONSTRUCT LP FROM E/R; DETERMINE EFFECTIVE FACTORS 14149 NSUBS = N 14150 DO 250 I=1,N 14151 LP(I) = 0 14152 INC1 = LV(I) 14153 INC2 = LV(1)/INC1 14154 LOC = 1 14155 DO 240 J=1,INC2 14156 DO 230 K=1,INC1 14157 IF (LER(LOC).GT.0) LP(I) = LP(I) + 1 14158 LOC = LOC + 1 14159 230 CONTINUE 14160 LOC = LOC + INC1 14161 240 CONTINUE 14162 IF (LP(I).EQ.0) NSUBS = NSUBS - 1 14163 250 CONTINUE 14164C DETERMINE IF THE EFFECTIVE X MATRIX IS SQUARE 14165 IV = N - NSUBS + 1 14166 DO 260 I=1,N 14167 IF (LP(I).EQ.0) GO TO 260 14168 IF (LP(I).NE.LV(IV)) GO TO 310 14169 260 CONTINUE 14170 GO TO 300 14171C CONSTRUCT E/R LIST FOR COMPLETELY CROSSED MODEL 14172 270 DO 280 I=1,M1 14173 LER(I) = M - I + 1 14174 280 CONTINUE 14175 NSUBS = N 14176 DO 290 I=1,N 14177 LP(I) = LV(1) 14178 290 CONTINUE 14179 300 IXST = 1 14180 310 IF (IOFLAG.EQ.1) THEN 14181 WRITE (ICOUT,99997) (LER(I),I=1,M) 14182 CALL DPWRST('XXX','BUG ') 14183 ENDIF 1418499997 FORMAT (10H E/R LIST-/(1H , 16I5)) 14185C COMPUTE PARAMETERS REQUIRED TO RESTRUCTURE CELL FREQUENCY ARRAY 14186 LPOUT = 1 14187 NO1 = 1 14188 DO 320 I=1,N 14189 IF (LP(I).EQ.0) LPOUT = LPOUT*LLIM(I) 14190 IF (LP(I).NE.0) NO1 = NO1 + LV(I) 14191 320 CONTINUE 14192C COMPUTE DEGREES OF FREEDOM FOR FULL OR REDUCED MODEL 14193 IDF = 0 14194 DO 340 I=1,M 14195 IF (LER(I).LE.0) GO TO 340 14196 NO2 = M - I + 1 14197 CALL LABEL(NO2, 0, LLIM, N, LV, LP) 14198 K = 1 14199 DO 330 J=1,N 14200 IF (LP(J).NE.0) K = K*(LLIM(J)-1) 14201 330 CONTINUE 14202 IDF = IDF + K 14203 340 CONTINUE 14204 IDFR = 0 14205 IF (ICD(1:1).EQ.IH) IDFR = IDF 14206 IF (ICD(1:1).EQ.IM) IDFM = IDF 14207 RETURN 14208 350 ISST = 1 14209 RETURN 14210 END 14211 SUBROUTINE STEP(IND, C, S, NW, W, M, LSTFI, LER, N, LV, LLIM, 14212 * LT, LP) 14213C PART OF ACM 591 FOR ANOVA 14214C ****************************** STEP ****************************** STE 10 14215C STE 20 14216C PERFORMS THE FOLLOWING SUB-STEPS OPERATING UPON THE VECTORS IN THE STE 30 14217C W ARRAY STE 40 14218C STE 50 14219C 1) T = (Y-D*V)/C STE 60 14220C 2) V = V+T STE 70 14221C 3) B = B+T STE 80 14222C 4) T = R(T) STE 90 14223C 5) V = V-T STE 100 14224C 6) S = 2*Y*V-V*D*V STE 110 14225C STE 120 14226C VECTOR T CONSISTS OF THE FIRST NCELLS LOCATIONS IN VECTOR A OF W; STE 130 14227C HOWEVER, ALL LOCATIONS IN VECTOR A ARE NEEDED IN SUB-STEP 4. R(T) STE 140 14228C IS THE RESIDUAL OPERATOR APPLIED TO VECTOR T; IT IS IMPLEMENTED STE 150 14229C USING SUBROUTINES DECOMP, POOL, AND LABEL. STE 160 14230C STE 170 14231C SUB-STEPS 1 AND 6 ARE MODIFIED IN COMPUTING RANK WITH THE R OPTION STE 180 14232C AND SUB-STEP 1 IS ALSO MODIFIED WHEN SWITCH IBST IS ON; ARGUMENT STE 190 14233C IND CONTROLS THESE MODIFICATIONS. STE 200 14234C STE 210 14235C IND = 1 (ITERATION FOR SSR); IND = 2 (NON-ITERATIVE, IBST IS ON); STE 220 14236C IND = 3 (ITERATION FOR RANK) STE 230 14237C STE 240 14238C S IS EITHER SSR (IND=2), AN APPROXIMATION TO SSR, (IND=1), OR PART STE 250 14239C OF THE RANK APPROXIMATION (IND=3). C IS A SCALAR CONSTANT SELECT- STE 260 14240C ED FOR MONOTONICITY OF THE APPROXIMATION TO SSR OR FOR FASTER, BUT STE 270 14241C NOT MONOTONE, CONVERGENCE. STE 280 14242C STE 290 14243C (SEE MAIN PROGRAM COMMENTS FOR DESCRIPTION OF OTHER ARGUMENTS) STE 300 14244C STE 310 14245C ****************************************************************** STE 320 14246 DIMENSION W(NW), LSTFI(M), LER(M), LV(N), LLIM(N), LT(N), LP(10) 14247 DOUBLE PRECISION W, C, S, T1, T2 14248C 14249 INCLUDE 'DPCOP2.INC' 14250C 14251 ID1=0 14252 ID2=0 14253 IB=0 14254 S = 0 14255 NCELLS = LSTFI(1) 14256 DO 40 I=1,NCELLS 14257C INCREMENT BASE ADDRESSES OF ARRAYS 14258 ID1 = NCELLS + I 14259 ID2 = ID1 + NCELLS 14260 IV = ID2 + NCELLS 14261 IB = IV + NCELLS 14262 IA = IB + NCELLS 14263C GENERAL ITERATION (IND=1); NON-ITERATIVE (IND=2); RANK (IND=3) 14264 IF (IND.EQ.1) GO TO 20 14265 IF (IND.EQ.2) GO TO 10 14266 W(IA) = W(I) - W(IV) 14267 IF (W(ID1).EQ.0.0) W(IA) = W(I) 14268 GO TO 30 14269 10 W(IA) = -W(IV) 14270 IF (W(ID2).GT.0.0) W(IA) = W(IA) + W(I)/W(ID2) 14271 GO TO 30 14272 20 W(IA) = (W(I)-W(ID1)*W(IV))/C 14273C V=V+A; B=B+A 14274 30 W(IV) = W(IV) + W(IA) 14275 W(IB) = W(IB) + W(IA) 14276 40 CONTINUE 14277C RESIDUAL OPERATOR 14278 IA = IB 14279CCCCC CALL DECOMP(0, IB, IOUT, NW, W, M, LSTFI, N, LT, LV, LLIM, LP) 14280 CALL DECOMP(0, IB, NW, W, M, LSTFI, N, LT, LV, LLIM, LP) 14281 IFLAG = 0 14282 DO 70 I=1,M 14283 IF (LER(I).GT.0) GO TO 60 14284 IF (I.EQ.1) GO TO 50 14285 NO = M - I + 1 14286 CALL LABEL(NO, 0, LLIM, N, LV, LP) 14287 CALL POOL(IFLAG, IA, IB, NW, W, N, LLIM, LT, LP) 14288 50 IFLAG = 1 14289 60 IB = IB + LSTFI(I) 14290 70 CONTINUE 14291C V=V-T; S=2*Y*V-V*D*V 14292 DO 90 I=1,NCELLS 14293 ID1 = NCELLS + I 14294 IV = ID2 + I 14295 IA = IA + 1 14296 IF (IFLAG.EQ.1) W(IV) = W(IV) - W(IA) 14297 T1 = 2.0D0*W(I) 14298 T2 = W(ID1) 14299 IF (T2.EQ.0.0) GO TO 80 14300 IF (IND.EQ.3) T2 = 1.0D0 14301 T1 = T1 - W(IV)*T2 14302 80 S = S + T1*W(IV) 14303 90 CONTINUE 14304 RETURN 14305 END 14306 SUBROUTINE PART1(NW, W, M, LSTFI, LER, N, LV, LLIM, LT, LP, 14307 * MAXMC, Q, QT) 14308C PART OF ACM 591 FOR ANOVA 14309C ****************************** PART1 ***************************** PAR 10 14310C PAR 20 14311C RESTRUCTURES THE DATA (CELL FREQUENCIES) WHEN APPROPRIATE; CHECKS PAR 30 14312C FOR BALANCE AND ALTERNATIVE NON-ITERATIVE COMPUTATIONS; TURNS IBST PAR 40 14313C ON WHEN THE EFFECTIVE X MATRIX IS SQUARE OR THE EFFECTIVE D MATRIX PAR 50 14314C IS A SCALAR MULTIPLE OF THE IDENTITY. COMPUTES RANK WITHOUT ITERA- PAR 60 14315C TION IF POSSIBLE OR ITERATIVELY OTHERWISE WHEN THE RANK (R) OPTION PAR 70 14316C IS SPECIFIED; TURNS SWITCH IRST ON IF THE MAXIMUM NUMBER OF ITERA- PAR 80 14317C TIONS IS EXCEEDED IN COMPUTING RANK. PAR 90 14318C PAR 100 14319C ****************************************************************** PAR 110 14320 COMMON /C1/ YPY, SSRM, SSEM, IIN, IOUT, IROPT, IVOPT, IGOPT, 14321 * IPOPT, IOFLAG, IBST, IHST, IRST, ISST, IXST, ICD, NSUBS, LPOUT, 14322 * NO1, IDF, IDFM, IDFR 14323 COMMON /C2/ NCELLS, LOCD1, LOCD2, LOCV, LOCB, LOCA, IRANKM, 14324 * IRANKR, MAXIT 14325 DIMENSION W(NW), LSTFI(M), LER(M), LV(N), LLIM(N), LT(N), LP(10) 14326 DIMENSION Q(MAXMC,MAXMC), QT(MAXMC) 14327 DOUBLE PRECISION W, C, S, TRACE, TEMP, Q, QT, YPY, SSRM, SSEM 14328C 14329 CHARACTER*4 IH, IM, ICD 14330C 14331 INCLUDE 'DPCOP2.INC' 14332C 14333CCCCC DATA IH /1HH/, IM /1HM/ 14334 DATA IH /'H'/, IM /'M'/ 14335C 14336 IHST = 0 14337 IRST = 0 14338 IBST = 0 14339 IRANK = 0 14340 IF (NSUBS.EQ.N) GO TO 100 14341C FORM RESTRUCTURED CELL FREQUENCY ARRAY (EFFECTIVE D MATRIX) 14342 DO 10 I=1,NCELLS 14343 ID1 = LOCD1 + I 14344 IA = LOCA + I 14345 W(IA) = W(ID1) 14346 10 CONTINUE 14347CCCCC CALL DECOMP(1, LOCA, IOUT, NW, W, M, LSTFI, N, LT, LV, LLIM, LP) 14348 CALL DECOMP(1, LOCA, NW, W, M, LSTFI, N, LT, LV, LLIM, LP) 14349 NS = LOCA 14350 NN = M - NO1 14351 DO 20 I=1,NN 14352 NS = NS + LSTFI(I) 14353 20 CONTINUE 14354CNIST CALL LABEL(NO1, 0, LLIM, IOUT, N, LV, LP) 14355 CALL POOL(0, LOCD2, NS, NW, W, N, LLIM, LT, LP) 14356C CHECK FOR A SQUARE EFFECTIVE X MATRIX 14357 30 IF (IXST.EQ.1) GO TO 80 14358 K = LOCD2 + 1 14359 IFLAG = 0 14360 DO 40 I=1,NCELLS 14361 ID2 = LOCD2 + I 14362 IF (W(ID2).EQ.0.0) GO TO 130 14363 IF (W(ID2).NE.W(K)) IFLAG = 1 14364 40 CONTINUE 14365 IF (IFLAG.EQ.1) GO TO 70 14366C THE EFFECTIVE D MATRIX IS A SCALAR TIMES THE IDENTITY 14367 IRANK = IDF 14368 50 DO 60 I=1,NCELLS 14369 ID2 = LOCD2 + I 14370 W(ID2) = W(ID2)/FLOAT(LPOUT) 14371 60 CONTINUE 14372 C = 1.0D0 14373 IBST = 1 14374 GO TO 120 14375C ALL ELEMENTS OF THE EFFECTIVE D MATRIX ARE NONZERO 14376 70 IRANK = IDF 14377 GO TO 120 14378C THE EFFECTIVE X MATRIX IS SQUARE 14379 80 DO 90 I=1,NCELLS 14380 ID2 = LOCD2 + I 14381 IF (W(ID2).NE.0.0) IRANK = IRANK + 1 14382 90 CONTINUE 14383 IRANK = IRANK/LPOUT 14384 GO TO 50 14385 100 DO 110 I=1,NCELLS 14386 ID1 = LOCD1 + I 14387 ID2 = LOCD2 + I 14388 W(ID2) = W(ID1) 14389 110 CONTINUE 14390 GO TO 30 14391C RANK HAS BEEN DETERMINED (NONITERATIVELY OR ITERATIVELY) 14392 120 IF (ICD.EQ.IH) IRANKR = IRANK 14393 IF (ICD.EQ.IM) IRANKM = IRANK 14394 GO TO 370 14395 130 IF (ICD.EQ.IM) GO TO 140 14396 IRANKR = 0 14397 IF (IRANKM.NE.IDFM) GO TO 150 14398 IRANKR = IDFR 14399 IRANK = IDFR 14400 GO TO 370 14401 140 IRANKM = 0 14402 150 IF (IROPT.EQ.0) GO TO 380 14403C ITERATIVELY COMPUTE RANK OF FULL OR REDUCED MODEL 14404 C = 1.0D0 14405 RTOL = 0.1 14406 NMC = 0 14407 DO 160 I=1,NCELLS 14408 ID1 = LOCD1 + I 14409 ID2 = LOCD2 + I 14410 IF (W(ID1).EQ.0.0) NMC = NMC + 1 14411 W(ID2) = W(I) 14412 160 CONTINUE 14413 IF (NMC.GT.MAXMC) GO TO 310 14414C COMPUTE Q, POWERS OF Q, AND RELATED TRACES (FEW EMPTY CELLS) 14415 K = 1 14416 IVEC = 0 14417 DO 190 I=1,NCELLS 14418 ID1 = LOCD1 + I 14419 IF (W(ID1).NE.0.0) GO TO 190 14420 DO 170 J=1,NCELLS 14421 IV = LOCV + J 14422 IB = LOCB + J 14423 W(IV) = 0 14424 W(IB) = 0 14425 W(J) = 0 14426 IF (J.EQ.I) W(J) = 1.0D0 14427 170 CONTINUE 14428 CALL STEP(3, C, S, NW, W, M, LSTFI, LER, N, LV, LLIM, LT, LP) 14429 LL = 1 14430 DO 180 J=1,NCELLS 14431 ID1 = LOCD1 + J 14432 IV = LOCV + J 14433 IF (W(ID1).NE.0.0) GO TO 180 14434 Q(K,LL) = W(IV) 14435 LL = LL + 1 14436 180 CONTINUE 14437 K = K + 1 14438 190 CONTINUE 14439C POWER Q AND COMPUTE TR(I-Q**(2*K)) 14440 TEMP = IDF 14441 DO 200 I=1,NMC 14442 TEMP = TEMP - Q(I,I) 14443 200 CONTINUE 14444 IT = 0 14445 210 IF (IOFLAG.EQ.1) THEN 14446 WRITE (ICOUT,99999) IT, TEMP 14447 CALL DPWRST('XXX','BUG ') 14448 ENDIF 1444999999 FORMAT (10H ITERATION, I3, 8H, TRACE=, F16.9) 14450 DO 250 J=1,NMC 14451 DO 230 I=J,NMC 14452 QT(I) = 0 14453 DO 220 K=1,NMC 14454 QT(I) = QT(I) + Q(K,J)*Q(K,I) 14455 220 CONTINUE 14456 230 CONTINUE 14457 DO 240 K=J,NMC 14458 Q(K,J) = QT(K) 14459 240 CONTINUE 14460 250 CONTINUE 14461 TRACE = IDF 14462 DO 270 I=1,NMC 14463 TRACE = TRACE - Q(I,I) 14464 DO 260 J=I,NMC 14465 Q(I,J) = Q(J,I) 14466 260 CONTINUE 14467 270 CONTINUE 14468 IT = IT + 1 14469 TEMP = TRACE - TEMP 14470C TRACE IS MONOTONICALLY INCREASING 14471 IF (TEMP.LE.RTOL) GO TO 280 14472 IF (IT.GE.MAXIT) GO TO 360 14473 TEMP = TRACE 14474 GO TO 210 14475 280 DO 290 I=1,NCELLS 14476 ID2 = LOCD2 + I 14477 W(I) = W(ID2) 14478 290 CONTINUE 14479C ADD ONE (BASED ON MONOTONICITY) TO OBTAIN INTEGER RANK 14480 300 IRANK = INT(TRACE + 1.0D0) 14481 GO TO 120 14482C COMPUTE S FOR UNIT VECTORS (MANY EMPTY CELLS) 14483 310 TRACE = 0 14484 RTOL = RTOL/(FLOAT(NCELLS)-FLOAT(NMC)) 14485 DO 350 I=1,NCELLS 14486 ID1 = LOCD1 + I 14487 IF (W(ID1).EQ.0.0) GO TO 350 14488 DO 320 J=1,NCELLS 14489 IV = LOCV + J 14490 IB = LOCB + J 14491 W(IV) = 0 14492 W(IB) = 0 14493 W(J) = 0 14494 IF (J.EQ.I) W(J) = 1.0D0 14495 320 CONTINUE 14496 IT = 0 14497 TEMP = 0 14498 330 CALL STEP(3, C, S, NW, W, M, LSTFI, LER, N, LV, LLIM, LT, LP) 14499 IT = IT + 1 14500 TEMP = S - TEMP 14501C THE VALUE OF S IS MONOTONICALLY INCREASING 14502 IF (TEMP.LE.RTOL) GO TO 340 14503 IVEC = I 14504 IF (IT.GE.MAXIT) GO TO 360 14505 TEMP = S 14506 GO TO 330 14507 340 TRACE = TRACE + S 14508 IF (IOFLAG.EQ.1) THEN 14509 WRITE (ICOUT,99998) I, IT, TRACE 14510 CALL DPWRST('XXX','BUG ') 14511 ENDIF 1451299998 FORMAT (7H VECTOR, I4, 12H, ITERATIONS, I4, 8H, TRACE=, F16.9) 14513 350 CONTINUE 14514 GO TO 280 14515 360 CONTINUE 14516 WRITE (ICOUT,99997) MAXIT 14517 CALL DPWRST('XXX','BUG ') 1451899997 FORMAT (11H MAXIMUM OF, I4, 34H ITERATIONS EXCEEDED IN COMPUTING , 14519 * 4HRANK) 14520 WRITE (ICOUT,89997) TEMP, RTOL, IVEC 14521 CALL DPWRST('XXX','BUG ') 1452289997 FORMAT (7H DELTA=, F22.9, 10X, 8HEPSILON=, F22.9, 10X, 7HVECTOR=, 14523 * I10) 14524 IF (NMC.GT.MAXMC) TRACE = TRACE + S 14525 IRST = 1 14526 GO TO 300 14527 370 IF (IROPT.EQ.1) THEN 14528 WRITE (ICOUT,99996) ICD, IRANK 14529 CALL DPWRST('XXX','BUG ') 14530 ENDIF 1453199996 FORMAT (17H THE RANK OF THE , A1, 17H DESIGN MATRIX IS, I5) 14532 380 RETURN 14533 END 14534 SUBROUTINE PART2(NW, W, M, LSTFI, LER, N, LE, LV, LLIM, LT, LP) 14535C PART OF ACM 591 FOR ANOVA 14536C ****************************** PART2 ***************************** PAR 10 14537C PAR 20 14538C COMPUTES SSE AND SSR FOR THE FULL MODEL (ICD = M); OUTPUTS ESTI- PAR 30 14539C MATES OF EXPECTED CELL MEANS (THE VECTOR V) WHEN THE V OPTION IS PAR 40 14540C SPECIFIED; COMPUTES A G-INVERSE SOLUTION TO THE NORMAL EQUATIONS PAR 50 14541C WHEN THE G OPTION IS SPECIFIED. COMPUTES SSR FOR THE REDUCED MOD- PAR 60 14542C EL (ICD = H) AND AN F STATISTIC; COMPUTES PROBABILITY VALUES WHEN PAR 70 14543C THE P OPTION IS SPECIFIED. ALL COMPUTATIONS ARE NON-ITERATIVE IF PAR 80 14544C SWITCH IBST IS ON (IBST = 1) PAR 90 14545C PAR 100 14546C (SEE MAIN PROGRAM COMMENTS FOR A DESCRIPTION OF ARGUMENTS) PAR 110 14547C PAR 120 14548C ****************************************************************** PAR 130 14549 COMMON /C1/ YPY, SSRM, SSEM, IIN, IOUT, IROPT, IVOPT, IGOPT, 14550 * IPOPT, IOFLAG, IBST, IHST, IRST, ISST, IXST, ICD, NSUBS, LPOUT, 14551 * NO1, IDF, IDFM, IDFR 14552 COMMON /C2/ NCELLS, LOCD1, LOCD2, LOCV, LOCB, LOCA, IRANKM, 14553 * IRANKR, MAXIT 14554 COMMON /C3/ MAXDI, MINDI, FLEVEL, NOSIGD, NOBS 14555 DIMENSION W(NW), LSTFI(M), LER(M), LE(N), LV(N), LLIM(N), LT(N), 14556 * LP(10) 14557 DOUBLE PRECISION W, C, S, TEMP, YPY, SSRM, SSEM, DABS, F 14558C 14559 CHARACTER*1 IBLANK, ISTAR, IM, IH, ISIG 14560 CHARACTER*4 ICD 14561C 14562 INCLUDE 'DPCOBE.INC' 14563 INCLUDE 'DPCOP2.INC' 14564C 14565CCCCC DATA IBLANK /1H /, ISTAR /1H*/, IM /1HM/, IH /1HH/ 14566 DATA IBLANK /' '/, ISTAR /'*'/, IM /'M'/, IH /'H'/ 14567C 14568 IF(ISUBG4.EQ.'ART2')THEN 14569 WRITE(ICOUT,9052)N,LE,LV,LER,LLIM 14570 9052 FORMAT('N,LE,LV,LER,LLIM = ',5I8) 14571 CALL DPWRST('XXX','BUG ') 14572 ENDIF 14573C 14574 FTOL = .005 14575 STOL = (.05*YPY)/(10.0**NOSIGD) 14576C ZERO THE VECTORS B AND V TO INITIALIZE THE ITERATIVE ALGORITHM 14577 DO 10 I=1,NCELLS 14578 IB = LOCB + I 14579 IV = LOCV + I 14580 W(IB) = 0 14581 W(IV) = 0 14582 10 CONTINUE 14583 IT = 0 14584 TEMP = 0 14585 IF (IBST.EQ.1) GO TO 260 14586 IF (ICD(1:1).EQ.IH) GO TO 170 14587C COMPUTE SSR FOR THE FULL MODEL USING OPTIMUM C FOR CONVERGENCE 14588 C = (FLOAT(MAXDI)+FLOAT(MINDI))/2.0 14589 IF (MINDI.EQ.0) C = MAXDI 14590 20 CALL STEP(1, C, S, NW, W, M, LSTFI, LER, N, LV, LLIM, LT, LP) 14591 IT = IT + 1 14592 TEMP = S - TEMP 14593 IF (IOFLAG.EQ.1) THEN 14594 WRITE (ICOUT,99999) IT, ICD(1:1), S 14595 CALL DPWRST('XXX','BUG ') 14596 ENDIF 1459799999 FORMAT (10H ITERATION, I4, 5H, SSR, A1, 1H=, E16.8) 14598 IF (DABS(TEMP).LE.STOL) GO TO 30 14599 IF (IT.GE.MAXIT) GO TO 160 14600 TEMP = S 14601 GO TO 20 14602C APPLY THE E OPERATOR TO THE VECTOR B 14603 30 DO 40 I=1,NCELLS 14604 IB = LOCB + I 14605 IA = LOCA + I 14606 W(IA) = W(IB) 14607 40 CONTINUE 14608CCCCC CALL DECOMP(0, LOCA, IOUT, NW, W, M, LSTFI, N, LT, LV, LLIM, LP) 14609 CALL DECOMP(0, LOCA, NW, W, M, LSTFI, N, LT, LV, LLIM, LP) 14610C COMPUTE SSR AND SSE FOR THE FULL MODEL 14611 50 SSRM = S 14612 SSEM = YPY - S 14613 WRITE (ICOUT,99998) IT, SSRM 1461499998 FORMAT (10H ITERATION, I4, 18H, SSR(FULL MODEL)=, E16.8, 1H,) 14615 CALL DPWRST('XXX','BUG ') 14616 WRITE (ICOUT,89998) SSEM 1461789998 FORMAT (14X,18H SSE(FULL MODEL)=, E16.8) 14618 CALL DPWRST('XXX','BUG ') 14619 IF (IVOPT.EQ.0) GO TO 70 14620 WRITE (ICOUT,99997) 1462199997 FORMAT (' ESTIMATES OF EXPECTED CELL MEANS-') 14622 CALL DPWRST('XXX','BUG ') 14623 WRITE (ICOUT,89997) 1462489997 FORMAT (' CELL ESTIMATED MEAN') 14625 CALL DPWRST('XXX','BUG ') 14626 DO 60 I=1,NCELLS 14627 ID1 = LOCD1 + I 14628 IV = LOCV + I 14629 IF (W(ID1).EQ.0.0) THEN 14630 WRITE (ICOUT,99996) I, W(IV) 14631 CALL DPWRST('XXX','BUG ') 14632 ENDIF 14633 IF (W(ID1).GT.0.0) THEN 14634 WRITE (ICOUT,99995) I, W(IV) 14635 CALL DPWRST('XXX','BUG ') 14636 ENDIF 14637 60 CONTINUE 1463899996 FORMAT (1H , I6, 1X, E16.8, 15H (MISSING CELL)) 1463999995 FORMAT (1H , I6, 1X, E16.8) 14640 70 IF (IGOPT.EQ.0) GO TO 150 14641C COMPUTE THE G-INVERSE SOLUTION TO THE NORMAL EQUATIONS 14642 WRITE (ICOUT,99994) 1464399994 FORMAT (20H G-INVERSE SOLUTION-) 14644 CALL DPWRST('XXX','BUG ') 14645C POOL ARRAYS OF "ESTIMATES" WITH EQUAL E/R LIST VALUES 14646 NP = LOCA 14647 DO 140 I=1,M 14648 NO = LER(I) 14649 IF (NO.LE.0) GO TO 130 14650 NS = NP 14651 NOP = M - I + 1 14652CNIST CALL LABEL(NOP, 0, LLIM, IOUT, N, LV, LP) 14653C POSITIVE VALUES IN LLIM WILL CORRESPOND TO SUBSCRIPTS IN PRIMARY 14654 DO 80 K=1,N 14655 IF (LP(K).EQ.0) LLIM(K) = -LLIM(K) 14656 80 CONTINUE 14657 DO 100 J=I,M 14658 IF (J.EQ.I) GO TO 90 14659 IF (LER(J).NE.NO) GO TO 90 14660 LER(J) = -NO 14661 NOS = M - J + 1 14662C OBTAIN MAP COEFFICIENTS FOR SECONDARY ARRAY AND POOL INTO PRIMARY 14663CNIST CALL LABEL(NOS, 0, LLIM, IOUT, N, LV, LP) 14664 CALL POOL(1, NP, NS, NW, W, N, LLIM, LT, LP) 14665 90 NS = NS + LSTFI(J) 14666 100 CONTINUE 14667 DO 110 K=1,N 14668 LLIM(K) = IABS(LLIM(K)) 14669 110 CONTINUE 14670C LABEL AND OUTPUT "ESTIMATES" FOR MODEL TERM 14671CNIST CALL LABEL(NO, IBLANK, LE, IOUT, N, LV, LP) 14672 MST = LSTFI(I) 14673 DO 120 K=1,MST 14674 IA = NP + K 14675 WRITE (ICOUT,99995) K, W(IA) 14676 CALL DPWRST('XXX','BUG ') 14677 120 CONTINUE 14678 130 NP = NP + LSTFI(I) 14679 140 CONTINUE 14680 150 RETURN 14681 160 CONTINUE 14682 WRITE (ICOUT,99993) MAXIT, ICD(1:1) 1468399993 FORMAT (11H MAXIMUM OF, I4, 34H ITERATIONS EXCEEDED IN COMPUTING , 14684 * 3HSSR, A1) 14685 CALL DPWRST('XXX','BUG ') 14686 WRITE (ICOUT,89993) TEMP, STOL 1468789993 FORMAT (7H DELTA=, E16.8, 10X, 8HEPSILON=, E16.8) 14688 CALL DPWRST('XXX','BUG ') 14689 GO TO 30 14690C SELECT C FOR MONOTONICITY OF SSR AND F 14691 170 C = MAXDI 14692C COMPUTE DEGREES OF FREEDOM TO USE FOR F STATISTIC 14693 180 IF (IRANKM.EQ.0) GO TO 190 14694 IF (IRANKR.EQ.0) GO TO 190 14695 IDFD = NOBS - IRANKM 14696 IDFN = IRANKM - IRANKR 14697 WRITE (ICOUT,99992) IDFN, IDFD 1469899992 FORMAT (33H FROM RANK COMPUTATIONS- DF(NUM)=, I4, 10H, DF(DEN)=, 14699 * I5) 14700 CALL DPWRST('XXX','BUG ') 14701 GO TO 200 14702 190 IDFD = NOBS - IDFM 14703 IDFN = IDFM - IDFR 14704 WRITE (ICOUT,99991) IDFN, IDFD 1470599991 FORMAT (50H ASSUMES FULL RANK AND EQUAL LEVELS WITH- DF(NUM)=, 14706 * I4, 10H, DF(DEN)=, I5) 14707 CALL DPWRST('XXX','BUG ') 14708 200 IF (IDFD*IDFN.LE.0) GO TO 150 14709 IF (IBST.EQ.1) GO TO 220 14710C COMPUTE MONOTONICALLY DECREASING APPROXIMATION TO F 14711 210 CALL STEP(1, C, S, NW, W, M, LSTFI, LER, N, LV, LLIM, LT, LP) 14712 IT = IT + 1 14713 220 F = ((SSRM-S)/FLOAT(IDFN))/(SSEM/FLOAT(IDFD)) 14714 IF (IOFLAG.EQ.1) THEN 14715 WRITE (ICOUT,99999) IT, ICD(1:1), S 14716 CALL DPWRST('XXX','BUG ') 14717 ENDIF 14718C APPROXIMATION TO F PROBABILITY (SMILLIE AND ANSTEY) 14719 U1 = 2.0/(9.0*FLOAT(IDFN)) 14720 U2 = 2.0/(9.0*FLOAT(IDFD)) 14721 F1 = F**(1.0/3.0) 14722 U3 = ((1.0-U2)*F1-1.0+U1)/SQRT(2.0*(U2*F1*F1+U1)) 14723 U = ABS(U3) 14724 PROB = 0.5/(1.0+(((.078108*U+.000972)*U+.230389)*U+.278393)*U)**4 14725 IF (U3.LT.0.0) PROB = 1.0 - PROB 14726 IF (IBST.EQ.1) GO TO 250 14727 IF (IPOPT.EQ.1) GO TO 230 14728 IF (PROB.GE.FLEVEL) GO TO 250 14729 230 TEMP = TEMP - F 14730 IF (DABS(TEMP).LE.FTOL) GO TO 250 14731 IF (IT.GE.MAXIT) GO TO 240 14732 TEMP = F 14733 GO TO 210 14734 240 CONTINUE 14735 WRITE (ICOUT,99993) MAXIT, ICD(1:1) 14736 CALL DPWRST('XXX','BUG ') 14737 WRITE (ICOUT,89993) TEMP, FTOL 14738 CALL DPWRST('XXX','BUG ') 14739 250 ISIG = ISTAR 14740 IF (PROB.GE.FLEVEL) ISIG = IBLANK 14741 WRITE (IOUT,99990) IT, F, ISIG, PROB, FLEVEL 1474299990 FORMAT (10H ITERATION, I4, 4H, F=, F12.3, A1, 15H, PROB(F) .GT. , 14743 * F7.4, 16H VS. F LEVEL OF , F7.4) 14744 CALL DPWRST('XXX','BUG ') 14745 WRITE (IOUT,89990) S 1474689990 FORMAT (20H SSR(REDUCED MODEL)=, E16.8) 14747 CALL DPWRST('XXX','BUG ') 14748 GO TO 150 14749C BALANCED CASE; ONE ITERATION 14750 260 CALL STEP(2, C, S, NW, W, M, LSTFI, LER, N, LV, LLIM, LT, LP) 14751 IT = IT + 1 14752 IF (ICD(1:1).EQ.IM) GO TO 50 14753 GO TO 180 14754 END 14755 SUBROUTINE POOL(IND, NP, NS, NW, W, N, LLIM, LT, LP) 14756C PART OF ACM 591 FOR ANOVA 14757C ****************************** POOL ****************************** POO 10 14758C POO 20 14759C OPERATES UPON THE VECTORS IN ARRAY W, PRINCIPALLY THE ARRAYS OF A POO 30 14760C FACTORIAL DECOMPOSITION WITHIN VECTOR A OF W. EITHER MOVES THE POO 40 14761C SECONDARY ARRAY INTO THE PRIMARY ARRAY, DUPLICATING ENTRIES WHERE POO 50 14762C NEEDED, OR POOLS THE SECONDARY ARRAY AND THE PRIMARY ARRAY BY AD- POO 60 14763C DITION INTO THE PRIMARY ARRAY (FOR DESCRIPTION OF MAPPING FUNCTION POO 70 14764C SEE SCHLATER AND HEMMERLE, CACM 1966) POO 80 14765C POO 90 14766C IND = 0 (REPLACEMENT); IND = 1 (POOLING) POO 100 14767C POO 110 14768C NP = BASE ADDRESS OF PRIMARY ARRAY (WITHIN ARRAY W) POO 120 14769C NS = BASE ADDRESS OF SECONDARY ARRAY (WITHIN ARRAY W) POO 130 14770C POO 140 14771C WHEN THE PRIMARY ARRAY HAS LESS THAN N SUBSCRIPTS, THE ENTRIES IN POO 150 14772C LLIM CORRESPONDING TO THE MISSING SUBSCRIPTS MUST BE MADE NEGATIVE POO 160 14773C PRIOR TO ENTRY AND THEN SET POSITIVE AGAIN AFTER RETURN; ARRAY LP POO 170 14774C MUST CONTAIN THE COEFFICIENTS OF THE MAPPING FUNCTION UPON ENTRY. POO 180 14775C POO 190 14776C (SEE MAIN PROGRAM COMMENTS FOR DESCRIPTION OF OTHER ARGUMENTS) POO 200 14777C POO 210 14778C ****************************************************************** POO 220 14779 DIMENSION W(NW), LLIM(N), LT(N), LP(10) 14780 DOUBLE PRECISION W, TEMP 14781C 14782 INCLUDE 'DPCOP2.INC' 14783C 14784C NP=LOCATION OF PRIMARY ARRAY; NS=LOCATION OF SECONDARY ARRAY; 14785C MAP COEFFICIENTS OBTAINED FROM LP; REPLACE (IND=0); ADD (IND .NE. 0) 14786 LOC1 = NP 14787 I = 1 14788 10 DO 20 J=I,N 14789 LT(J) = 1 14790 20 CONTINUE 14791 30 LOC1 = LOC1 + 1 14792 LOC2 = NS + 1 14793 DO 40 J=1,N 14794 LOC2 = LOC2 + (LT(J)-1)*LP(J) 14795 40 CONTINUE 14796 TEMP = W(LOC2) 14797 IF (IND.NE.0) TEMP = TEMP + W(LOC1) 14798 W(LOC1) = TEMP 14799 DO 50 J=1,N 14800 K = N - J + 1 14801 IF (LLIM(K).LT.0) GO TO 50 14802 IF (LT(K).EQ.LLIM(K)) GO TO 50 14803 LT(K) = LT(K) + 1 14804 IF (K.EQ.N) GO TO 30 14805 I = K + 1 14806 GO TO 10 14807 50 CONTINUE 14808 RETURN 14809 END 14810 CHARACTER*1 FUNCTION IGET(ICURS, ISTRNG, LNGTH) 14811C PART OF ACM 591 FOR ANOVA 14812C ****************************** IGET ****************************** IGE 10 14813C IGE 20 14814C USED BY THE MAIN PROGRAM AND SCAN TO SEQUENTIALLY RETRIEVE CHARAC- IGE 30 14815C TERS FROM THE INPUT BUFFER. IGE 40 14816C IGE 50 14817C ARGUMENTS - ICURS = POSITION IN CHARACTER STRING; ISTRNG = CHARAC- IGE 60 14818C TER STRING (INPUT BUFFER); LNGTH = LENGTH OF STRING. IGE 70 14819C IGE 80 14820C ****************************************************************** IGE 90 14821 DIMENSION ISTRNG(LNGTH) 14822 CHARACTER*1 IBLANK, IPLUS, ICOMMA, ISTRNG 14823 DATA IBLANK /' '/, IPLUS /'+'/, ICOMMA /','/ 14824 10 IGET = ISTRNG(ICURS) 14825 ICURS = ICURS + 1 14826 IF (ICURS.GT.LNGTH) RETURN 14827 IF (IGET.EQ.IBLANK .OR. IGET.EQ.IPLUS) GO TO 10 14828 IF (IGET.EQ.ICOMMA) GO TO 10 14829 RETURN 14830 END 14831 SUBROUTINE LABEL(NO, ICHAR, LIST, N, LV, LOA) 14832CCCCC SUBROUTINE LABEL(NO, ICHAR, LIST, IOUT, N, LV, LOA) 14833C ROUTINE FROM ACM 591 FOR ANOVA 14834C ****************************** LABEL ***************************** LAB 10 14835C LAB 20 14836C DETERMINES THE SUBSCRIPTS OF THE PRIMARY ARRAY; CALCULATES COEFFI- LAB 30 14837C CIENTS FOR MAPPING THE SECONDARY ARRAY INTO THE PRIMARY ARRAY. LAB 40 14838C ALSO PREPARES LABELS FOR THE G-INVERSE SOLUTION AND CLASSIFICATION LAB 50 14839C MEANS; EACH LABEL IS AN ALPHANUMERIC ARRAY OF SIZE 10. LAB 60 14840C LAB 70 14841C LAB 80 14842C (OUT) ARGUMENTS (IN) LAB 90 14843C LAB 100 14844C LOA NO ICHAR LIST LAB 110 14845C LAB 120 14846C PRIMARY SUBSCRIPTS M-I+1 0 LLIM LAB 130 14847C MAP COEFFICIENTS M-I+1 0 LLIM LAB 140 14848C MODEL TERM LABEL LER(I) BLANK LE LAB 150 14849C SUBSCRIPTS LABEL M-I+1 . LS LAB 160 14850C LAB 170 14851C IN COMPUTING NO, I IS THE POSITION OF THE LAB 180 14852C ARRAY WITHIN THE M ARRAYS (IN VECTOR A OF LAB 190 14853C W) OR, FOR MODEL TERM LABELS, THE VALUE LAB 200 14854C OF THE E/R LIST (ARRAY LER) FOR THAT TERM LAB 210 14855C LAB 220 14856C (SEE MAIN PROGRAM COMMENTS FOR DESCRIPTION OF OTHER ARGUMENTS) LAB 230 14857C LAB 240 14858C ****************************************************************** LAB 250 14859 DIMENSION LIST(N), LV(N), LOA(10) 14860CCCCC CHARACTER*1 IBLANK 14861C 14862 INCLUDE 'DPCOP2.INC' 14863C 14864CCCCC DATA IBLANK /' '/ 14865C 14866C MAP COEFFICIENTS: (NO=2**N-I+1,ICHAR=0,LIST=LLIM) 14867C LABELS: MODEL TERM (NO=LER(I),ICHAR= ,LIST=LE) 14868C SUBSCRIPTS (NO=2**N-I+1,ICHAR=.,LIST=LS) 14869C 14870 NUM = NO - 1 14871 DO 10 I=N,10 14872CNIST LOA(I) = IBLANK 14873 LOA(I) = -1 14874 10 CONTINUE 14875 DO 20 I=1,N 14876 LOA(I) = ICHAR 14877 20 CONTINUE 14878 IF (NUM.EQ.0) GO TO 60 14879 I = 0 14880 J = 0 14881 30 I = I + 1 14882 40 J = J + 1 14883 NUM = NUM - LV(J) 14884 IF (NUM.GE.0) GO TO 50 14885 NUM = NUM + LV(J) 14886CNIST IF (ICHAR.NE.IBLANK) GO TO 30 14887 IF (ICHAR.NE.-1) GO TO 30 14888 GO TO 40 14889 50 LOA(I) = LIST(J) 14890 IF (NUM.NE.0) GO TO 30 14891 60 IF (ICHAR.EQ.0) GO TO 70 14892CNIST WRITE (ICOUT,99999) (LOA(K),K=1,10) 14893CNIST99999 FORMAT (1H , 10A1) 14894 CALL DPWRST('XXX','BUG ') 14895 RETURN 14896 70 DO 90 I=1,N 14897 IF (LOA(I).EQ.0) GO TO 90 14898 LOA(I) = 1 14899 DO 80 J=I,N 14900 IF (LOA(J).EQ.0) GO TO 80 14901 LOA(I) = IABS(LOA(I)*LOA(J)) 14902 80 CONTINUE 14903 90 CONTINUE 14904 RETURN 14905 END 14906