Changeset 3778 for PP/trunk/BAP/GENBAP_AWW_2.TXT
- Timestamp:
- 01/26/09 16:33:10 (4 years ago)
- File:
-
- 1 edited
-
PP/trunk/BAP/GENBAP_AWW_2.TXT (modified) (44 diffs)
Legend:
- Unmodified
- Added
- Removed
-
PP/trunk/BAP/GENBAP_AWW_2.TXT
r3777 r3778 732 732 733 733 // Padding parameters: 734 // PADSEC(1 & 2) = length of the leading and trailing pad 735 // areas, in seconds. 734 // PADSEC(1 & 2) = length of the leading and trailing pad areas, in seconds. 736 735 public static double [] padsec = new double[2]; 737 736 738 737 // TAPSEC(1 & 2) = taper length used with the datataper option. 739 // Given as number of seconds in the taper. 740 // Usually= 0.2. 738 // Given as number of seconds in the taper. Usually= 0.2. 741 739 public static double [] tapsec = new double[2]; 742 740 743 // MTAPER(1 & 2) = tapering option, one for each end of the 744 // time series. Usually = 0. 741 // MTAPER(1 & 2) = tapering option, one for each end of the time series. Usually = 0. 745 742 // = 0=> notaper, 746 743 // = 1=> zcross, … … 1568 1565 int ndamp = BapRSI.rsiDamping.length; 1569 1566 int nper = BapRSI.rsiPeriod.length; 1570 nwant6 = 2*nper + nper*ndamp;1567 int nwant6 = 2*nper + nper*ndamp; 1571 1568 1572 1569 //nwant = Math.max(nwant0,nwant1,nwant2,nwant3,nwant4,nwant5,nwant6); … … 1796 1793 if (ndone<npandd) { 1797 1794 System.out.printf(lunmsg, 2001) npandd, ndone, lenwrk; 1798 warn("*");1795 BapUtil.warn("*"); 1799 1796 npandd = ndone; 1800 1797 if (ndone>npadl+ndata) { … … 1972 1969 if (npadl!=0 || npadt!=0) { 1973 1970 System.out.printf(lunmsg, 2004) npadl, npadt; 1974 warn("*");1971 BapUtil.warn("*"); 1975 1972 } 1976 1973 LINCOR(lunusr, lunmsg, rp.dptim1,dpdelt, … … 2110 2107 // cccccccccccccccccccc (end of BAP2/BAP)cccccccccccccccccccccccccccccccccc 2111 2108 2112 WCOPY(work1,work2,npoint) { 2113 float work1(npoint), work2(npoint); 2114 // WCOPY is called from BAP2 to copy the contents of WORK1() into WORK2(). 2115 // Note that we would not need WCOPY or need to deal with 3 separate 2116 // working arrays except that we may want to keep each array 2117 // smaller than the 64K byte (=16K reals) segment limit in 2118 // 80x86 computers. See comments in BAP.FOR for more info. 2119 do 100 i =1,npoint; 2120 work2(i)=work1(i); 2121 100 continue; 2109 // WCOPY is called from BAP2 to copy the contents of WORK1() into WORK2(). 2110 // Note that we would not need WCOPY or need to deal with 3 separate 2111 // working arrays except that we may want to keep each array 2112 // smaller than the 64K byte (=16K reals) segment limit in 2113 // 80x86 computers. See comments in BAP.FOR for more info. 2114 WCOPY(float[] work1, float[] work2, npoint) { 2115 System.arraycopy(work1, 0, work2, 0, npoint); 2122 2116 } 2123 2117 // cccccccccccccccccccc (end of WCOPY/BAP2/BAP) ccccccccccccccccccccccccccc 2124 // 2118 2119 2125 2120 // IDSTEP is called from BAP2 to write information about the current 2126 2121 // processing step to the run messages file and to the user … … 2176 2171 sb.append(" Better to reduce the sampling rate in the DECIM step, which is done after the INSCOR step. ***"); 2177 2172 System.out.println(sb.toString()); 2178 warn("*");2173 BapUtil.warn("*"); 2179 2174 else if (rp.spsnew>rp.spsin && rp.spsin>0.0 && (!rp.mdo[BapSteps.khicut]) ) { 2180 2175 double x=rp.spsin/2.0; … … 2186 2181 sb.append(" But the HICUT step was *not* requested in this run. ***%n" 2187 2182 System.out.printf(sb.toString(), x); 2188 warn("*");2183 BapUtil.warn("*"); 2189 2184 } 2190 2185 } else { 2191 2186 System.out.println("*** ERROR, INTERP step is only applicable for an unevenly-sampled time series.\n" + 2192 2187 " (This restriction may be removed in future versions.) Ending Run. ***"); 2193 warn("*");2188 BapUtil.warn("*"); 2194 2189 } 2195 2190 } … … 2268 2263 rp.jpad=1; 2269 2264 System.out.printf("*** WARNING: JPAD=0 invalid when decimation is requested; jpad reset to %2d ***", rp.jpad); 2270 warn("*");2265 BapUtil.warn("*"); 2271 2266 2272 2267 // e) reset jpad if jpad = 4 is not required … … 2286 2281 if (jwas!=5) { 2287 2282 System.out.printf("*** WARNING: jpad=%2d is invalid here, jpad reset to %2d ***%n", jwas, rp.jpad); 2288 warn("*");2283 BapUtil.warn("*"); 2289 2284 } 2290 2285 } … … 2352 2347 "sampling rate is genuinely required here.) ***"); 2353 2348 2354 warn("*");2349 BapUtil.warn("*"); 2355 2350 } else if (rp.mdo[BapSteps.kintrp] ) { 2356 2351 StringBuffer sb = new StringBuffer(256); … … 2359 2354 sb.append(" But BOTH interpolations have been requested in this BAP run! ***"); 2360 2355 System.out.println(sb.toString()); 2361 warn("*");2356 BapUtil.warn("*"); 2362 2357 } 2363 2358 } else { … … 2367 2362 doit=false; 2368 2363 System.out.println(" *** NO decimation performed when ndense < 2."); 2369 warn("*");2364 BapUtil.warn("*"); 2370 2365 } else { 2371 2366 x = outValue/outMode; … … 2381 2376 System.out.printf( " Unless HICUT was previously applied or no frequencies are greater than %12.5g Hz,%n", x); 2382 2377 System.out.println(" the DECIMated time-series generated here will probably contain aliasing errors. ***"); 2383 warn("*");2378 BapUtil.warn("*"); 2384 2379 } 2385 2380 … … 2415 2410 rp.velfit=false; 2416 2411 System.out.print(" *** WARNING: the VELFIT option does not apply when the LOCUT2 option is on. ***"); 2417 warn("*");2412 BapUtil.warn("*"); 2418 2413 } 2419 2414 if (rp.motion!=1 && rp.motion!=4) rp.locut2=false; … … 2424 2419 " *** WARNING: the LOCUT2 option does not apply when the LOCUT step is off or when MOTION is not = acc. ***" 2425 2420 ); 2426 warn("*");2421 BapUtil.warn("*"); 2427 2422 } 2428 2423 } else { … … 2470 2465 System.out.printf(lunmsg, 2003); 2471 2466 2003 System.out.print(" *** WARNING: the VELFIT option should usually not be used when the LOCUT step is applied. ***"); 2472 warn("*");2467 BapUtil.warn("*"); 2473 2468 } 2474 2469 } … … 2489 2484 // cccccccccccccccccccc (end of BAP/IDSTEP) ccccccccccccccccccccccccccccccc 2490 2485 2491 warn(onec, lunusr,lunmsg) { 2492 String onec; 2493 2494 // WARN: warn user by rining terminal bell and/or stopping, depending 2495 // on the value of IWARN (in BAPINOUT.INC). 2496 // IWARN = 3 => ring bell, tell user how to change IWARN, 2497 // then stop 2498 // IWARN = 2 => IWARN = 3 if ONEC="*", = IWARN=1 otherwise 2499 // IWARN = 1 => ring bell and return 2500 // IWARN = 0 => return. 2501 2502 // On entry -- 2503 // ONEC = "+" or "*" to indicate how severe the warning is, 2504 // with "*" being more severe than "+". 2505 // LUNUSR = boolean unit number for the user terminal. 2506 // LUNMSG = " for the run messages file. 2507 2508 include "bapsteps.inc"; 2509 include "bapinout.inc"; 2510 2511 if (rp.iwarn!=0) bell(6); 2512 if (rp.iwarn>2 || (rp.iwarn==2 && onec=="*")) { 2513 System.out.printf(lunusr,1000); 2514 if (lunusr!=lunmsg) { 2515 System.out.printf(lunmsg,1001); 2516 System.out.printf(lunmsg,1000); 2517 } 2518 BapUtil.woe(-2); 2519 } 2520 return; 2521 2522 1000 System.out.print(5x,"WARN=STOP. If you wish processing to proceed despite the above warning," 2523 /17x,"reset WARN=BELLS in the BAP run parameters list, then", " rerun." /17x,"Ending Run."); 2524 1001 System.out.print(" >>> 6 bells."); 2525 } 2526 // cccccccccccccccccccc (end of warn) cccccccccccccccccccccccccccccccccccc 2527 2528 // SHOWZ: display info about the pad for DEBUG runs 2529 showz (npadl,ndata,npadt, workA, npandd) { 2530 float workA(npandd); 2531 int idebug; 2532 float debugr; 2533 equivalence (debugr, idebug); 2534 2535 nfar = 0; 2536 do 10 jjj=1,npadl; 2537 debugr = workA(jjj); 2538 if (idebug!=0) { 2539 print *, " first non-zero value: i, v=",jjj,debugr; 2540 nfar = npadl-jjj +300; 2541 if (jjj<300) nfar=npadl; 2542 goto 12; 2543 } 2544 10 continue; 2545 print *, " NO non-zero leading pad values!"; 2546 nfar = npadl; 2547 12 continue; 2548 print *, " "; 2549 do 20 jjj=npadl-nfar+1,npadl-nfar+600,50; 2550 if (jjj <=0 || jjj>npandd) goto 20; 2551 debugr = workA(jjj); 2552 System.out.printf(" Debug r&h= %7d %15.7e %10x", jjj,debugr,idebug); 2553 20 continue; 2554 print *, " "; 2555 do 30 jjj=npadl+ndata +nfar-1, 2556 npadl+ndata +nfar-601, -50; 2557 if (jjj <=0 || jjj>npandd) goto 30; 2558 debugr = workA(jjj); 2559 System.out.printf(" Debug r&h= %7d %15.7e %10x", jjj,debugr,idebug); 2560 30 continue; 2561 2562 200 continue; 2563 print *, " "; 2564 print *, " SHOWZ: npadl, ndata, npadt",npadl,ndata,npadt; 2565 print *, " npadl + ndata=", npadl+ndata; 2566 print *, " "; 2567 return; 2568 } 2569 // cccccccccccccccccccc (end of showz) ccccccccccccccccccccccccccccccccccccc 2486 2570 2487 2571 2488 BAPSET(lunans,lunusr, lundsk,lundat, luntmp,luntm2) { … … 5136 5053 n = min (130-27,ncout); 5137 5054 System.out.printf(lunmsg,1020) fmtout, filnam(1:n); 5138 warn("*");5055 BapUtil.warn("*"); 5139 5056 } 5140 5057 } … … 6529 6446 // cccccccccccccccccccc (end of QLBL/HDRLBL/BANNER) cccccccccccccccccccccc 6530 6447 6531 // BAPSPS: Linearly interpolate the BAP input time series to SPSNEW 6532 // samples per second. 6533 // Note that this subroutine does *not* apply any high-cut 6534 // filter to remove alias errors. 6448 // BAPSPS: Linearly interpolate the BAP input time series to SPSNEW samples per second. 6449 // Note that this subroutine does *not* apply any high-cut filter to remove alias errors. 6535 6450 // On entry-- 6536 6451 // SPS = input sample rate if workA() contains an evenly-sampled … … 6585 6500 // I also have not decided whether or not to just ignore back-stepping samples in an unevenly-sampled input time series. 6586 6501 6587 public static final boolean MOVET1 =false;6588 public static final boolean IGBACK = false;6589 6590 // Sanity checks:6502 public static final boolean MOVET1 = false; 6503 public static final boolean IGBACK = false; 6504 6505 // Sanity checks: 6591 6506 if (BapConstants.small > rp.spsnew) BapUtil.woe(0); 6592 6507 if (BapConstants.small > Math.abs(rp.spsnew-sps)) BapUtil.woe(0); … … 6643 6558 } 6644 6559 } 6645 warn("*");6560 BapUtil.warn("*"); 6646 6561 } 6647 6562 } … … 6684 6599 nwork -= 1; 6685 6600 System.out.printf(" *** Truncating time series at %13.5e s due to array size. Length of the array =%8d. ***%n", time, lenwrk); 6686 warn("*");6601 BapUtil.warn("*"); 6687 6602 break; 6688 6603 } … … 6815 6730 // Get the time interval at beginning and end of the t.s. in which to calculate mean value or llsqf line. 6816 6731 6817 for (int ii=0; ii ==1; ii++) {6732 for (int ii=0; ii<=1; ii++) { 6818 6733 6819 6734 ibeg = Math.min( Math.max(0, ifromt(tskew[0+ii])), ilast ); … … 6836 6751 xy0 =BapLLSQF.y0; 6837 6752 6838 for (int i=ibeg; i ==iend; i++) {6753 for (int i=ibeg; i<=iend; i++) { 6839 6754 workB[ib++] = (float) (worka[i] - xy0 - xslope*tfromi(i)); // B = A - (llsq fit line value) 6840 6755 } … … 6842 6757 } else { 6843 6758 // sum the values in the interval 6844 for (int i=ibeg; i ==iend; i++) {6759 for (int i=ibeg; i<=iend; i++) { 6845 6760 xy0 = xy0 + worka[i]; 6846 6761 } 6847 6762 xy0 = xy0/(iend-ibeg + 1); // mean value 6848 6763 6849 for (int i=ibeg; i ==iend; i++) {6764 for (int i=ibeg; i<=iend; i++) { 6850 6765 workB[ib++]= (float) (worka[i] - xy0); // B = A - (mean value) 6851 6766 } … … 6887 6802 // Find the first and last zero-crossings in the WORK() array. 6888 6803 // On entry -- 6889 // SMIDGE, WORK() ,NPTS6804 // SMIDGE, WORK() 6890 6805 // On return -- 6891 6806 // IZC1 = first sample to retain w.r.t. first zero crossing … … 6895 6810 int izc1 = -1; 6896 6811 int izcn = -1; 6897 int npts = 0; 6898 6899 public void calcZeroCrossings(double smidge, float[] work, int npts) { 6812 6813 public void calcZeroCrossings(double smidge, float[] work) { 6814 calcZeroCrossings(smidge, work, 0, work.length-1); 6815 } 6816 6817 public void calcZeroCrossings(double smidge, float[] work, int idatan) { 6818 calcZeroCrossings(smidge, work, 0, idatan); 6819 } 6820 6821 public void calcZeroCrossings(double smidge, float[] work, int idata1, int idatan) { 6822 6900 6823 int j = 0; 6901 if (work[0]==0.f || Math.abs(work[0])<smidge) { 6902 izc1=0; 6903 } else if (npts>2) { 6904 for (int i=2; i<npts-1; i++) { 6905 if (work[i]*work[0] < 0.f) { 6906 izc1=0; 6824 double dx = Math.abs(smidge); 6825 6826 int ndata = idatan-idata1+1; 6827 6828 float data1 = work[idata1]; 6829 float datan = work[idatan]; 6830 6831 if ( Math.abs(data1) < dx) { 6832 izc1= idata1; 6833 } else if (ndata>2) { 6834 for (int i=idata1+1; i <= idatan-1; i++) { 6835 if (work[i]*data1 < 0.f) { 6836 izc1=idata1; 6907 6837 j=i; 6908 6838 if (Math.abs(work[i-1]) < Math.abs(work[i])) j=i-1; 6909 if (Math.abs(work[j]) < Math.abs( work[0])) izc1=i;6839 if (Math.abs(work[j]) < Math.abs(data1)) izc1=i; 6910 6840 break; 6911 6841 } … … 6913 6843 } 6914 6844 6915 if ( work[npts-1]==0.f || Math.abs(work[npts-1])<smidge) {6916 izcn= npts-1;6917 } else if (n pts>2 && izc1 < npts-1) {6918 for i= npts-2; i=Math.max(0, izc1-1), i--) {6919 if (work[i]* work[npts-1]< 0.f) {6920 izcn= npts-1;6845 if (Math.abs(datan) < dx) { 6846 izcn=idatan; 6847 } else if (ndata>2 && izc1 < idatan) { 6848 for i= idatan-1; i >= Math.max(idata1, izc1-1), i--) { 6849 if (work[i]*datan < 0.f) { 6850 izcn=idatan; 6921 6851 j=i; 6922 6852 if (Math.abs(work[i+1]) < Math.abs(work[i])) j=i+1; 6923 if (Math.abs(work[j]) < Math.abs( work[npts-1])) izcn=i;6853 if (Math.abs(work[j]) < Math.abs(datan)) izcn=i; 6924 6854 break; 6925 6855 } 6926 6856 } 6927 6857 } 6858 6928 6859 } 6929 6860 // cccccccccccccccccccc (end of ZCROSS) ccccccccccccccccccccccccccccccccc … … 7011 6942 y0 = BapLLSQF.y0; 7012 6943 } else if (rp.mmean) { // slope=0. and y0 is mean bias over fit interval 7013 for (int i = ibegf; i ==iendf; i++) {6944 for (int i = ibegf; i<=iendf; i++) { 7014 6945 y0 += worka[i]; 7015 6946 } … … 7019 6950 // Subtract the line 7020 6951 if (slope ==0.0) { // Remove constant/bias value 7021 for (int i = ibegl; i ==iendl; ii++) {6952 for (int i = ibegl; i<=iendl; ii++) { 7022 6953 worka[i] = (float) (worka(i) - Y0); 7023 6954 } 7024 6955 } else { // remove line with slope 7025 for (int i = ibegl; i ==iendl; ii++) {6956 for (int i = ibegl; i<=iendl; ii++) { 7026 6957 worka[i] = (float) (worka[i] - Y0 - slope*(dptim1 + dpdelt*i)); 7027 6958 } … … 7424 7355 sb.append(" Leading/trailing pads truncated to %7d/%7d samples. ***%n"); 7425 7356 System.out.printf(sb.toString(), lenwrk, newpts, newz[0], newz[1]); 7426 warn("*"); // throw Exception ?7357 BapUtil.warn("*"); // throw Exception ? 7427 7358 } else if (rp.jpad==4 || rp.jpad==5) { 7428 7359 nn = Math.round(newpts*ratio); … … 7440 7371 if (morez[1] <0) BapUtil.woe(0); 7441 7372 System.out.printf(" to %8d, " and %8d points. ***%n", morez[0], morez[1]); 7442 warn("*"); // throw Exception ?7373 BapUtil.warn("*"); // throw Exception ? 7443 7374 } 7444 7375 } … … 7493 7424 // cccccccccccccccccccc (end of PADLEN) ccccccccccccccccccccccccccccccccccc 7494 7425 7495 BAPPAD(lunusr,lunmsg,mtaper,tapsec, sps,work,morelz,newlz,ndata,newtz, doit2) {7496 float work(morelz+newlz+ndata+newtz);7497 float tapsec(2);7498 int mtaper[1];7499 boolean doit2;7500 7501 7426 // BAPPAD pads the time series in WORK() with leading and trailing 7502 7427 // zeros, then smooths the discontinuity between the data and 7503 7428 // the pad areas according to the tapering option, MTAPER. 7504 7505 7429 // On entry -- 7506 // LUNMSG = lun for run messages = user terminal or disk file.7507 // LUNUSR = " = user terminal.7508 7430 // MTAPER() = tapering option, one for each end of the time-series: 7509 7431 // = 0=> notaper 7510 // = 1=> zcross = reset to zero all values for samples 7511 // that occur before the first zero 7512 // crossing or after the last zero 7513 // crossing 7514 // = 2=> datataper = apply a cosine taper at the end of 7515 // the time series. 7516 // TAPSEC() = taper length used with the datataper option, in 7517 // seconds. TAPSEC indicates the number of points to 7518 // be used in the taper, excluding the endpoints at 7519 // taper-factor = 0.0 and at taper-factor = 1.0. 7432 // = 1=> zcross = reset to zero all sample values, before the first and after the last, zero crossing 7433 // = 2=> datataper = apply a cosine taper at the ends of the time series. 7434 // TAPSEC() = taper length used with the datataper option, in seconds. 7435 // TAPSEC determines the number of points to be used in the taper, excluding endpoints 7436 // taper-factor = 0.0 and at taper-factor = 1.0 (ie. ntaper = secs*sps-2). 7520 7437 // SPS = sampling rate 7521 // WORK() = array containing a time-series plus free space for 7522 // padding. The unpadded input time series is in 7523 // locations 1 thru NDATA. 7524 // MORELZ = empty space to be left at the beginning of the padded 7525 // time series. (Will be used in the second padding 7526 // step) 7438 // WORK() = array containing a time-series plus free space for padding. 7439 // The unpadded input time series is in locations 0 thru NDATA-1. 7440 // MORELZ = empty space to be left at the beginning of the padded time series for a second padding step. 7527 7441 // NEWLZ = number of zeros requested for the leading pad. 7528 // NDATA = number of samples (beginning at WORK(1)) in the 7529 // input time series. 7442 // NDATA = number of samples (beginning at WORK[0]) in the input time series. 7530 7443 // NEWTZ = number of zeros requested for the trailing pad. 7531 7532 // NOTES: 7533 // - Before calling BAPPAD, the caller must make certain that 7534 // there is enough space in WORK() to contain NEWLZ+NDATA+NEWTZ 7535 // samples. 7536 // - NEWLZ and NEWTZ may =0 if tapering is wanted, without the 7537 // padding. (As might be appropriate when VELFIT=true) 7538 7444 // 7445 // - Before calling BAPPAD, WORK array must be long enough to contain NEWLZ+NDATA+NEWTZ samples. 7446 // - NEWLZ and NEWTZ may =0 if tapering is wanted, without the padding. (As might be appropriate when VELFIT=true) 7539 7447 // On return -- 7540 // WORK() = contains the padded time series in locations MORELZ +1 7541 // thru MORELZ + newlz + NDATA + newtz. 7542 // DOIT2 = false if there really was not any padding or tapering 7543 // applied to the time series. 7544 7545 include "bapconst.inc"; 7546 include "tempcs.inc"; 7547 public static final double pi =3.1415926535; 7548 float ntaper(2); 7549 boolean shift; 7550 7551 lztot = newlz+morelz; 7552 doit2 = true; 7448 // WORK = contains the padded time series in index locations MORELZ thru MORELZ+newlz+NDATA+newtz-1. 7449 7450 public class BapPad { 7451 7452 // Returns false if no padding or tapering was applied to the time series. 7453 public boolean pad(int[] mtaper, float[] tapsec, double sps, float[] work, int morelz, int newlz, int ndata, int newtz) { 7454 7455 // Input work(morelz+newlz+ndata+newtz); 7456 7457 boolean doit2 = true; 7458 7553 7459 if (newlz==0 && newtz==0) { 7554 if (rp.mtaper[0]==0 && rp.mtaper[1]==0) {7555 System.out.printf(lunmsg,1000);7556 if (lunusr!=lunmsg) System.out.printf(lunusr,1000);7557 }7558 7460 if (rp.mtaper[0]<=0 && rp.mtaper[1]<=0) { 7461 System.out.println("No padding requested (NEWLZ=NEWTZ=0)."); 7559 7462 doit2 = false; 7560 if (morelz<=0) return; 7561 } 7562 } 7563 7564 ntaper[0] = Math.max(0, Math.round(rp.tapsec[0]*sps) -2); 7565 ntaper[1] = Math.max(0, Math.round(rp.tapsec[1]*sps) -2); 7566 7567 data1 = work(1); 7568 datan = work(ndata); 7569 idata1 = lztot + 1; 7570 idatan = lztot + ndata; 7571 7572 // Shift the time series forward in WORK(), to leave room for the 7573 // leading pad. 7574 7575 shift = true; 7576 if (lztot<=0) shift=false; 7577 smidge = 0.; 7578 do 120 i = idatan,idata1, -1; 7579 if (shift) work[i] = work(i-lztot); 7580 if (Math.abs(work[i]) > smidge) smidge = Math.abs(work[i]); 7581 120 continue; 7582 if (!doit2) return; 7463 if (morelz<=0) return false; // no taper and no extra zeroes requested for later padding so we're done 7464 } 7465 } 7466 7467 // If adding zeroes, shift the data time series forward (to right) in WORK array, leaving room for the leading pad. 7468 int lztot = newlz+morelz; 7469 idata1 = lztot; // first sample index 7470 idatan = lztot + ndata-1; // last sample index 7471 boolean shift = (lztot > 0) ? true : false; 7472 7473 double smidge = 0.; 7474 for (int i = idatan; i>=idata1; i--) { 7475 if (shift) work[i] = work[i-lztot]; 7476 if (Math.abs(work[i]) > smidge) smidge = Math.abs(work[i]); 7477 } 7478 7479 if (! doit2) return false; // no tapers and newlz=newtz=0 7480 7481 // Set smidge as a fractional part of the largest absolute data offset 7583 7482 smidge = BapConstants.small*smidge; 7584 7483 7585 // If the "ZCROSS" taper option was specified, find the first and last 7586 // zero-crossings in the time-series. 7587 7484 // If the "ZCROSS" taper option was specified, find the first and last zero-crossings in the time-series. 7485 /* 7588 7486 izc1=-1; 7589 7487 izcn=-1; 7590 if (rp.mtaper[0]==1 || rp.mtaper[1]==1) { 7488 float data1 = work[idata1]; 7489 float datan = work[idatan]; 7490 if (rp.mtaper[0]==1 || rp.mtaper[1]==1) { // 1= ZCROSS 7591 7491 if (Math.abs(data1)<smidge) { 7592 7492 izc1=idata1; 7593 7493 } else if (ndata>2) { 7594 do 31 i=idata1+1, idatan-1; 7595 if (work[i]*data1<0.0) { 7596 izc1=idata1; 7597 j=i; 7598 if (Math.abs(work(i-1)) < Math.abs(work[i])) j=i-1; 7599 if (Math.abs(work(j)) < Math.abs(data1)) izc1=i; 7600 goto 32; 7494 for (i=idata1+1; i <= idatan-1; i++) { 7495 if (work[i]*data1<0.f) { 7496 izc1=idata1; 7497 j=i; 7498 if (Math.abs(work[i-1]) < Math.abs(work[i])) j=i-1; 7499 if (Math.abs(work[j]) < Math.abs(data1)) izc1=i; 7500 break; 7501 } 7601 7502 } 7602 31 continue;7603 32 continue;7604 7503 } 7605 7504 if (Math.abs(datan)<smidge) { 7606 7505 izcn=idatan; 7607 7506 } else if (ndata>2 && izc1 < idatan) { 7608 do 33 i= idatan-1, Math.max(idata1,izc1-1), -1; 7609 if (work[i]*datan<0.0) { 7610 izcn=idatan; 7611 j=i; 7612 if (Math.abs(work(i+1)) < Math.abs(work[i])) j=i+1; 7613 if (Math.abs(work(j)) < Math.abs(datan)) izcn=i; 7614 goto 34; 7507 for (int i= idatan-1; i >= Math.max(idata1, izc1-1); i--) { 7508 if (work[i]*datan<0.f) { 7509 izcn=idatan; 7510 j=i; 7511 if (Math.abs(work[i+1]) < Math.abs(work[i])) j=i+1; 7512 if (Math.abs(work[j]) < Math.abs(datan)) izcn=i; 7513 break; 7514 } 7615 7515 } 7616 33 continue;7617 34 continue; 7618 }7619 i f (izcn<=izc1 || izc1<0) {7620 System.out.printf(lunmsg,1101);7621 if (lunusr!=lunmsg) System.out.printf(lunusr,1101); 7622 warn("*");7623 if ((rp.mtaper[0]==1 && rp.mtaper[1]==1) ||7624 (rp.mtaper[0]==1 && izc1==-1) ||7625 (rp.mtaper[1]==1 && izcn==-1)) {7626 // +++BapUtil.woe(2) +++ do we want to continue here or croak?7516 } 7517 */ 7518 BapZCross.calcZeroCrossings(smidge, work, idata1, idatan); 7519 izc1 = BapZcross.izc1; 7520 izcn = BapZcross.izcn; 7521 7522 if (izcn <= izc1 || izc1 < 0) { 7523 System.out.println(" *** The ZCROSS option should not be used with this data; it does not contain two zero crossings!***"); 7524 BapUtil.warn("*"); 7525 if ((rp.mtaper[0]==1 && rp.mtaper[1]==1) || (rp.mtaper[0]==1 && izc1==-1) || (rp.mtaper[1]==1 && izcn==-1)) { 7526 // BapUtil.woe(2) +++ do we want to continue here or croak? 7627 7527 izc1 = idata1; 7628 7528 izcn = idatan; … … 7631 7531 } 7632 7532 7633 // Begin Loop to pad and taper each end of the time-series. 7634 7635 do 500 ipad = 1,2; 7636 itap = rp.mtaper[ipad]; 7637 nzdata = 0; 7638 k2beg = 9; 7639 if (ipad==1) { 7640 tempcs(1:8) = "leading "; 7641 tempcs(9:13)= "first"; 7642 k2end = 13; 7643 locbeg = 1; 7644 locend = lztot; 7645 npad = newlz; 7646 ilow = idata1; 7647 jdir = -1; 7648 if (itap==1) { 7649 locend = izc1 -1; 7650 nzdata = locend - lztot; 7651 } 7652 } else { 7653 tempcs(1:8) = "trailing"; 7654 tempcs(9:12)= "last"; 7655 k2end = 12; 7656 locbeg = 1 + idatan; 7657 locend = newtz + idatan; 7658 npad = newtz; 7659 ilow = idatan; 7660 jdir = 1; 7661 if (itap==1) { 7662 locbeg = izcn +1; 7663 nzdata = idatan -izcn; 7664 } 7665 } 7666 7667 // a) Pad with zeros and, if requested, extend the zeros into the 7668 // data area, up to the first zero crossing. 7669 7670 if (locbeg<locend) { 7671 do 10 i= locbeg,locend; 7672 work[i]= 0.0f; 7673 10 continue; 7674 System.out.printf(lunmsg,1002) npad, tempcs(1:8); 7675 if (lunusr!=lunmsg) System.out.printf(lunusr,1002) npad, tempcs(1:8); 7676 if (itap==1 && nzdata>0) { 7677 System.out.printf(lunmsg,1030) tempcs(k2beg:k2end), nzdata; 7678 if (lunusr!=lunmsg) System.out.printf(lunusr,1030) tempcs(k2beg:k2end), nzdata; 7679 } 7680 } else { 7681 System.out.printf(lunmsg,1001) tempcs(1:8); 7682 if (lunusr!=lunmsg) System.out.printf(lunusr,1001) tempcs(1:8); 7683 } 7684 7685 // b) If requested, apply a cosine taper at both ends of the data area. 7686 // (Math.cos(0)=1.0; Math.cos(pi/2) =0.0; Math.cos(pi)=-1.0) 7687 // Apply the taper so the lowest point in the taper (0.0) falls at 7688 // the first point in the pad. 7689 // Note that NNN counts the number of interior points in the 7690 // taper, excluding the endpoints at F=1.0 and F=0.0. The 7691 // endpoint at f=1.0 is at sample number IHIGH, the endpoint 7692 // at f=0.0 is the first point in the pad. 7693 7694 if (itap==2) { 7695 nnn= ntaper(ipad); 7696 if (nnn>=1) { 7697 System.out.printf(lunmsg,1010) tempcs(k2beg:k2end), nnn; 7698 if (lunusr!=lunmsg) System.out.printf(lunusr,1010) tempcs(k2beg:k2end), nnn; 7699 rstep = Math.PI/float(nnn+1); 7700 ihigh = ilow -jdir*(nnn); 7701 do 101 j=1,nnn; 7702 f = 0.5*(1.0+Math.cos(rstep*float(j))); 7703 i = ihigh + j*jdir; 7704 work[i] = (float) (work[i] * f); 7705 101 continue; 7706 } 7707 } 7708 7709 // End of loop. 7710 7711 500 continue; 7712 return; 7713 7714 1000 System.out.print("No padding requested (MORELZ+NEWLZ=NEWTZ=0)."); 7715 1001 System.out.print("The time series has NOT been extended with %8s zeros."); 7716 1002 System.out.print("The time series has been extended with %8d %8s zeros."); 7717 1010 System.out.print("In addition, the %s %8d input samples were weighted with a cosine taper (values at the end approach zero)."); 7718 1030 System.out.print("In addition, the "%s %8d input samples were reset to zero." ); 7719 1101 System.out.print(" *** The ZCROSS option should not be used with this data; it does not contain two zero crossings!***"/); 7533 float[] ntaper = new int[2]; 7534 ntaper[0] = Math.max(0, Math.round(rp.tapsec[0]*sps)-2); 7535 ntaper[1] = Math.max(0, Math.round(rp.tapsec[1]*sps)-2); 7536 7537 String str1 = null; 7538 String str2 = null; 7539 // Begin Loop to pad and taper each end of the time-series. 7540 int nzdata = 0; 7541 int locbeg = 0; 7542 int locend = 0; 7543 int npad = 0; 7544 int ilow = 0; 7545 int jdir = 0; 7546 7547 for (int ipad = 0; ipad < 2; ipad++) { 7548 itap = rp.mtaper[ipad]; 7549 nzdata = 0; 7550 if (ipad==1) { 7551 str1 = "leading"; 7552 str2 = "first"; 7553 locbeg = 0; // first array index 7554 locend = lztot; // total leading zeroes new+more in pad 7555 // npad = newlz; // requested zeroes for lead pad -aww changed to below: 7556 npad = lztot; // requested zeroes for lead pad plus secondary pad // added this -aww 7557 ilow = idata1; // first data sample index 7558 jdir = -1; 7559 if (itap==1) { // zcross 7560 locend = izc1 - 1; // out to 1st zero cross sample index - 1 7561 nzdata = locend - lztot; // data to zero before lead pad 7562 } 7563 } else { 7564 str1 = "trailing"; 7565 str2 = "last"; 7566 locbeg = 1 + idatan; // last data sample index +1 start of pad 7567 locend = newtz+idatan; // index at end of trailing pad 7568 npad = newtz; // requested zeroes for trailing pad 7569 ilow = idatan; // last data sample index 7570 jdir = 1; 7571 if (itap==1) { 7572 locbeg = izcn + 1; // from last zero crossing index + 1 7573 nzdata = idatan - izcn; // data to zero before trailing pad 7574 } 7575 } 7576 7577 // Pad with zeros and, if requested, extend the zeros into the data area, up to the first zero crossing. 7578 if (locbeg < locend) { 7579 for (int i = locbeg; i<=locend; i++) { 7580 work[i]= 0.f; 7581 } 7582 System.out.printf("The time series has been extended with %8d %8s zeros.%n", npad, str1); 7583 if (itap==1 && nzdata>0) { 7584 System.out.printf("In addition, the "%s %8d input samples were reset to zero.%n", str2, nzdata); 7585 } 7586 } else { 7587 System.out.printf("The time series has NOT been extended with %s zeros.%n", str1); 7588 } 7589 7590 // If requested, apply a cosine taper at both ends of the data area (cos(0)=1, cos(pi/2)=0, cos(pi)=-1). 7591 // Apply the taper so the lowest point in the taper (0.0) falls at the first point in the pad. 7592 // Note that NNN counts the number of interior points in the taper, excluding the endpoints at F=1.0 and F=0.0. 7593 // The endpoint at f=1.0 is at sample number IHIGH, the endpoint at f=0.0 is the FIRST point in the pad past the data. 7594 if (itap==2) { 7595 nnn = ntaper(ipad); 7596 if (nnn>=1) { 7597 System.out.printf("In addition, the %s %8d input samples are weighted with a cosine taper (endpoints approach zero).%n", str2, nnn); 7598 dw = Math.PI/float(nnn+1); // taper step 7599 ihigh = ilow - jdir*(nnn); // index of sample with highest taper value 7600 7601 int i = 0; 7602 for (int j=1; j<=nnn; j++) { // note endpoints excluded since values are 0. and 1. 7603 i= ihigh+(j*jdir); 7604 work[i] = (float) ( (.5 + .5*Math.cos(dw*j)) * work[i]); 7605 } 7606 } 7607 } 7608 7609 7610 } // End of loop. 7611 7612 return doit2; 7613 7720 7614 } 7721 7615 // cccccccccccccccccccc (end of BAPPAD) ccccccccccccccccccccccccccccccccccc … … 7730 7624 7731 7625 BAPPD2(float[] work, int newlz, int npadl, int ndata, int npadt, int newtz) { 7732 // Input work length must be >= (newlz+npadl+ndata+npadt+newtz)7733 7626 7734 7627 if (newlz<=0 && newtz<=0) { 7735 7628 System.out.println("No additional padding required."); 7736 7629 return; 7630 } 7631 7632 // Input work length must be >= (newlz+npadl+ndata+npadt+newtz) 7633 if (work.length < (newlz+npadl+ndata+npadt+newtz)) { 7634 System.out.println("BAPPD2 Error input work array length less than sum of data plus requested leading,trailing pads."); 7737 7635 } 7738 7636 … … 7741 7639 float [] workB = new float[npadl]; 7742 7640 System.arraycopy(work, newlz, workB, 0, workB.length); 7743 BapZCross.calcZeroCrossings(0., work(newlz), npadl); 7641 BapZCross.calcZeroCrossings(0., workB, npadl); 7642 //BapZCross.calcZeroCrossings(0., work, newlz, npadl); 7744 7643 izc = BapZCross.izc1; // should be zero if called b4 7745 7644 } … … 7763 7662 System.arraycopy(work, nbeg, workB, 0, workB.length); 7764 7663 BapZCross.calcZeroCrossings(0.0, workB, npadt); 7664 //BapZCross.calcZeroCrossings(0.0, workB, nbeg, npadt); 7765 7665 izc = BapZCross.izcn; 7766 7666 } … … 8090 7990 if (fh2 > 1.00001/(2*dpdelt) ) { 8091 7991 System.out.printf(lunmsg, 1001) fh2, 1.0/dpdelt; 8092 warn("*");7992 BapUtil.warn("*"); 8093 7993 } 8094 7994 if (fh1+1.999 >fh2) { 8095 7995 System.out.printf(lunmsg,1002) fh1, fh2; 8096 warn("*");7996 BapUtil.warn("*"); 8097 7997 } 8098 7998 if (pins > 1.0) { 8099 7999 System.out.printf(lunmsg,1003) pins; 8100 warn("*");8000 BapUtil.warn("*"); 8101 8001 } 8102 8002 if (minsc) { … … 8149 8049 if (fh1!= hitbeg || fh2!= hitend) { 8150 8050 System.out.printf(lunmsg, 1006) fh1, fh2; 8151 warn("*");8051 BapUtil.warn("*"); 8152 8052 } 8153 8053 … … 8371 8271 // ccccc (end of comments) ccccc 8372 8272 8373 BIhip(array,ndata,fcut,dt,nfs) {8374 dimension array(ndata);8375 double dt,fcut;8376 8377 8273 // BIhip: Bidirectional, high-pass Butterworth recursive filter. 8378 8379 8274 // On entry -- 8380 8275 // ARRAY() contains the time series to be filtered. … … 8389 8284 // NFS = rolloff parameter. 8390 8285 // rolloff = nfs*24 decibels/octave. 8391 8392 8286 // On return -- 8393 8287 // ARRAY() contains filtered time-series. 8394 8395 8396 8288 // Subroutine History: 8397 8289 // ================== … … 8419 8311 // - removed array.inc and LARRAY. 8420 8312 8421 DOUBLE cs, pi, temp, ts, wcp; 8422 DOUBLE f(11,3),a(11),b(11),c(11); 8423 8424 nfs1=nfs+1; 8425 if (nfs>11) BapUtil.woe(0); 8426 ts=dt; 8427 //pi=3.1415926535; 8428 wcp=Math.sin(fcut*Math.PI*ts)/Math.cos(fcut*Math.PI*ts); 8429 do 5 k=1,nfs; 8430 cs=Math.cos(float(2*(k+nfs)-1)*Math.PI/float(4*nfs)); 8431 a(k)=1./(1.+wcp*wcp-2.*wcp*cs); 8432 b(k)=2.*(wcp*wcp-1.)*a(k); 8433 5 c(k)=(1.+wcp*wcp+2.*wcp*cs)*a(k); 8434 // ...perform convolution in two directions 8435 do 30 ijk=1,2; 8436 do 6 i=1,nfs1; 8437 do 6 j=1,2; 8438 6 f(i,j)=0.; 8439 do 10 n=1,ndata; 8440 f(1,3)=array(n); 8441 do 14 i=1,nfs; 8442 temp=a(i)*(f(i,3)-2.*f(i,2)+f(i,1)); 8443 14 f(i+1,3)=temp-b(i)*f(i+1,2)-c(i)*f(i+1,1); 8444 do 16 i=1,nfs1; 8445 do 16 j=1,2; 8446 16 f(i,j)=f(i,j+1); 8447 10 array(n)=f(nfs1,3); 8448 nby2=int(float(ndata)/2.); 8449 do 20 n=1,nby2; 8450 num=ndata-n+1; 8451 temp=array(n); 8452 array(n)=array(num); 8453 20 array(num)=temp; 8454 30 continue; 8455 } 8313 float[] BIhip(float [] array, int ndata, double fcut, double dt, int nfs) { 8314 8315 int nfs1 = nfs+1; 8316 8317 double[][] f = new double [nfs1][3]; 8318 double[] a = new double [nfs1]; 8319 double[] b = new double [nfs1]; 8320 double[] c = new double [nfs1]; 8321 8322 if (nfs1>11) BapUtil.woe(0); 8323 8324 double ts = dt; 8325 double wcp=Math.sin(Math.PI*ts*fcut)/Math.cos(Math.PI*ts*fcut); 8326 double cs = 0; 8327 for (int k=0; k<nfs; k++) { 8328 cs=Math.cos(float(2*(k+nfs)-1)*Math.PI/float(4*nfs)); 8329 a[k]=1./(1.+wcp*wcp-2.*wcp*cs); 8330 b[k]=2.*(wcp*wcp-1.)*a[k]; 8331 c[k]=(1.+wcp*wcp+2.*wcp*cs)*a[k]; 8332 } 8333 8334 double temp = 0.; 8335 int ijk = 1; 8336 while (ijk <= 2) { // ...perform convolution in two directions 8337 ijk++ 8338 8339 // zero out filter buffer 8340 for (int i=0; i<nfs1; i++) { 8341 for (int j=0, j<2; j++) { 8342 f[i][j] = 0.; 8343 } 8344 } 8345 8346 // Determine filtered sample value 8347 for (int n=0; n<ndata; n++) { 8348 f[0][2]=array[n]; 8349 for (int i=0; i<nfs; i++) { 8350 temp=a[i]*(f[i][2]-2.*f[i][1]+f[i][0]); 8351 f[i+1][2]=temp-b[i]*f[i+1][1]-c[i]*f[i+1][0]; 8352 } 8353 8354 for (int i=0; i<nfs1; i++) { 8355 for (int j=0; j<2; j++) { 8356 f[i][j]=f[i][j+1]; 8357 } 8358 } 8359 8360 array[n]=f[nfs1-1][2]; 8361 } 8362 8363 nby2=(int)(ndata/2); // what if ndata is not even ? 8364 // from mid-array+1 to end of array, swap elements 8365 for int n=0, n<nby2; n++) { 8366 num=ndata-n+1; 8367 temp=array[n]; 8368 array[n]=array[num]; 8369 array[num]=temp; 8370 } 8371 } // end of while 8372 } 8456 8373 // CCCCCCCCCCCCCCCCCCCC (END OF bihip) CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 8457 8374 8458 8375 // CCCCCCCCCCCCCCCCCCCC (Begin DataSeries) CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 8459 8376 public class DataSeries { 8460 int ns = 0; 8461 double dx = 0.; 8462 float [] x = null; 8377 int ns = 0; // number of samples 8378 double dx = 0.; // interval 8379 float [] x = null; // sample values 8463 8380 8464 8381 DataSeries(int ns) { … … 9048 8965 // cccccccccccccccccccc (end of BapRSI) cccccccccccccccccccccccccccccc 9049 8966 9050 // BapRSC = response-spectra calculating and reporting subroutine for 9051 // program = BAP. 9052 // BapRSI be called before BapRSC to create DAMP() and PERIOD() arrays. 8967 // BapRSC = response-spectra calculating and reporting subroutine for program. 8968 // call BapRSI before BapRSC to create DAMP() and PERIOD() arrays. 9053 8969 // On entry -- 9054 8970 // printResp = true for printing response-spectra values, or false not to print … … 9561 9477 for (int i = 1; i<=count; i++) System.out.print("\0007"); 9562 9478 } 9479 9480 // WARN: warn user by rining terminal bell and/or stopping, depending 9481 // on the value of IWARN (in BAPINOUT.INC). 9482 // IWARN = 3 => ring bell, tell user how to change IWARN, then stop 9483 // IWARN = 2 => IWARN = 3 if ONEC="*", = IWARN=1 otherwise 9484 // IWARN = 1 => beep and return 9485 // IWARN = 0 => return. 9486 // On entry: 9487 // ONEC = "+" or "*" to indicate how severe the warning is, 9488 // with "*" being more severe than "+". 9489 public void warn(String onec) { 9490 if (rp.iwarn != 0) BapUtil.beep(); 9491 if (rp.iwarn>2 || (rp.iwarn==2 && onec=="*")) { 9492 System.out.println("WARN=STOP. If you wish processing to proceed despite the above warning,"); 9493 System.out.println("reset WARN=BELLS in the run parameter properties, then rerun. Ending Run."); 9494 BapUtil.woe(-2); 9495 } 9496 } 9497 9498 // SHOWZ: display info about the pad for DEBUG runs 9499 public void showz(int npadl, int ndata, int npadt, float[] workA, int npandd) { 9500 9501 if (workA.length < npandd) { 9502 System.out.printf("ERROR showz work length=%8d > %8d=npandd%n", workA.length, npandd); 9503 return; 9504 } 9505 9506 int nfar = npadl+ndata+npadt; 9507 if (nfar > npandd) { 9508 System.out.printf("ERROR showz (npadl+ndata+npadt)=%8d > %8d=npandd%n", nfar, npandd); 9509 return; 9510 } 9511 9512 int idebug = 0; 9513 float value = 0.f; 9514 9515 // Test leading 9516 boolean notZero = true; 9517 int icnt = 0; 9518 int lastZero = 0; 9519 for int j = 0; j<npadl; j++) { 9520 value = workA(j); 9521 if (value != 0.) { 9522 if (notZero) { 9523 System.out.printf("Showz: First non-zero leading pad value at index=%8d, npadl=%8d, value=%12.3g%n",j, npadl, value; 9524 notZero = false; 9525 } 9526 lastZero = j; 9527 icnt++ 9528 } 9529 } 9530 if (icnt > 0) System.out.printf(" non-zero leading pad value count=%8d, last zero index=%8d%n", icnt, lastZero); 9531 else System.out.println("Showz: leading pad values all zero!"); 9532 9533 // Test zero data 9534 notZero = true; 9535 icnt = 0; 9536 lastZero = 0; 9537 iend = npadl+ndata; 9538 for int j = npadl; j<iend; j++) { 9539 value = workA(j); 9540 if (value != 0.) { 9541 if (notZero) { 9542 System.out.printf("Showz: First non-zero data value starts at index=%8d, startoff=%8d, value=%12.3g%n",j, j-npadl, value; 9543 notZero = false; 9544 break; 9545 } 9546 } 9547 } 9548 notZero = true; 9549 icnt = 0; 9550 lastZero = 0; 9551 iend = npadl+ndata-1; 9552 for int j = iend; j>=ipadl; j--) { 9553 value = workA(j); 9554 if (value != 0.) { 9555 if (notZero) { 9556 System.out.printf("Showz: First non-zero data value from end is at index=%8d, endoff=%8d, value=%12.3g%n",j, iend-j, value; 9557 notZero = false; 9558 break; 9559 } 9560 } 9561 } 9562 9563 // Test trailing 9564 notZero = true; 9565 icnt = 0; 9566 lastZero = 0; 9567 iend = npadl+ndata+npadt; 9568 for int j = npadl+ndata; j<iend; j++) { 9569 value = workA(j); 9570 if (value != 0.) { 9571 if (notZero) { 9572 System.out.printf("Showz: first non-zero trailing pad value at index=%8d, npadl=%8d, value=%12.3g%n",j, npadt, value; 9573 notZero = false; 9574 } 9575 lastZero = j; 9576 icnt++ 9577 } 9578 } 9579 if (icnt > 0) System.out.printf(" non-zero trailing pad value count=%8d, last zero index=%8d%n", icnt, lastZero); 9580 else System.out.println("Showz: trailing pad values all zero!"); 9581 9582 return; 9583 } 9584 // cccccccccccccccccccc (end of showz) ccccccccccccccccccccccccccccccccccccc 9563 9585 } 9564 9586 // cccccccccccccccccccc (end of BapUtil) cccccccccccccccccccccccccccccccc
Note: See TracChangeset
for help on using the changeset viewer.
