diff --git a/common-tools/cnuphys/apache/.gitignore b/common-tools/cnuphys/apache/.gitignore deleted file mode 100644 index ae3c172604..0000000000 --- a/common-tools/cnuphys/apache/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/common-tools/cnuphys/coatjava/etc/bankdefs/hipo/FMT.json b/common-tools/cnuphys/coatjava/etc/bankdefs/hipo/FMT.json deleted file mode 100644 index a532c3f7c9..0000000000 --- a/common-tools/cnuphys/coatjava/etc/bankdefs/hipo/FMT.json +++ /dev/null @@ -1,63 +0,0 @@ - [ - { - "bank": "FMTRec::Hits", - "group": 20821, - "info": "reconstructed FMT hits", - "items": [ - {"name":"ID", "id":1, "type":"int16" , "info":"hit ID"}, - {"name":"sector", "id":2, "type":"int8" , "info":"hit sector"}, - {"name":"layer", "id":3, "type":"int8" , "info":"hit layer"}, - {"name":"strip", "id":4, "type":"int32" , "info":"hit strip"}, - {"name":"fitResidual", "id":5, "type":"float" , "info":"fitted hit residual"}, - {"name":"trkingStat", "id":6, "type":"int32" , "info":"tracking status"}, - {"name":"clusterID", "id":7, "type":"int16" , "info":"associated cluster ID"}, - {"name":"trkID", "id":8, "type":"int16" , "info":"associated track ID"} - ] - }, - { - "bank": "FMTRec::Clusters", - "group": 20822, - "info": "reconstructed FMT clusters", - "items": [ - {"name":"ID", "id":1, "type":"int16" , "info":"ID"}, - {"name":"sector", "id":2, "type":"int8" , "info":"sector"}, - {"name":"layer", "id":3, "type":"int8" , "info":"layer"}, - {"name":"size", "id":4, "type":"int16" , "info":"cluster size"}, - {"name":"ETot", "id":5, "type":"float" , "info":"cluster total energy"}, - {"name":"seedE", "id":6, "type":"float" , "info":"energy of the seed "}, - {"name":"seedStrip", "id":7, "type":"int32" , "info":"seed strip"}, - {"name":"centroid", "id":8, "type":"float" , "info":"centroid strip number"}, - {"name":"centroidResidual","id":9, "type":"float" , "info":"centroid residual"}, - {"name":"seedResidual", "id":10, "type":"float" , "info":"seed residual"}, - {"name":"Hit1_ID", "id":11, "type":"int16" , "info":"Index of hit 1 in cluster"}, - {"name":"Hit2_ID", "id":12, "type":"int16" , "info":"Index of hit 2 in cluster"}, - {"name":"Hit3_ID", "id":13, "type":"int16" , "info":"Index of hit 3 in cluster"}, - {"name":"Hit4_ID", "id":14, "type":"int16" , "info":"Index of hit 4 in cluster"}, - {"name":"Hit5_ID", "id":15, "type":"int16" , "info":"Index of hit 5 in cluster"}, - {"name":"trkID", "id":16, "type":"int16", "info":"associated track ID"}, - {"name":"Tmin", "id":17, "type":"float", "info":"min T between strips"} - ] - }, - { - "bank": "FMTRec::Crosses", - "group": 20825, - "info": "reconstructed FMT crosses", - "items": [ - {"name":"ID", "id":1, "type":"int16" , "info":"ID"}, - {"name":"sector", "id":2, "type":"int8" , "info":"sector"}, - {"name":"region", "id":3, "type":"int8" , "info":"region"}, - {"name":"x", "id":4, "type":"float" , "info":"BMT cross x-coordinate"}, - {"name":"y", "id":5, "type":"float" , "info":"BMT cross y-coordinate"}, - {"name":"z", "id":6, "type":"float" , "info":"BMT cross z-coordinate"}, - {"name":"err_x", "id":7, "type":"float" , "info":"BMT cross x-coordinate error"}, - {"name":"err_y", "id":8, "type":"float" , "info":"BMT cross y-coordinate error"}, - {"name":"err_z", "id":9, "type":"float" , "info":"BMT cross z-coordinate error"}, - {"name":"ux", "id":10, "type":"float" , "info":"BMT cross x-direction (track unit tangent vector at the cross)"}, - {"name":"uy", "id":11, "type":"float" , "info":"BMT cross y-direction (track unit tangent vector at the cross)"}, - {"name":"uz", "id":12, "type":"float" , "info":"BMT cross z-direction (track unit tangent vector at the cross)"}, - {"name":"Cluster1_ID", "id":13, "type":"int16" , "info":"ID of the cluster in the Cross"}, - {"name":"Cluster2_ID", "id":14, "type":"int16" , "info":"ID of the top layer cluster in the Cross"}, - {"name":"trkID", "id":15, "type":"int16" , "info":"associated track ID"} - ] - } - ] diff --git a/common-tools/cnuphys/numRec/ExpectedAllTests.xml b/common-tools/cnuphys/numRec/ExpectedAllTests.xml deleted file mode 100644 index 84d18c750c..0000000000 --- a/common-tools/cnuphys/numRec/ExpectedAllTests.xml +++ /dev/null @@ -1,1306 +0,0 @@ - - - - - diff --git a/common-tools/cnuphys/numRec/INSTALL.txt b/common-tools/cnuphys/numRec/INSTALL.txt deleted file mode 100644 index 1ff92a59d6..0000000000 --- a/common-tools/cnuphys/numRec/INSTALL.txt +++ /dev/null @@ -1,104 +0,0 @@ -INSTALLATION - -Java Source Code Translations of Numerical Recipes C++ Source Code ------------------------------------------------------------------- -ver. 3.04 ---------- - -This directory tree contains translations to Java source code by Huang -Wen Hui of copyrighted Numerical Recipes Third Edition C++ source -code. Please see the file LICENSE.txt for copyright and license -information. Your use of these files is subject to the terms given -there, including the Disclaimer of Warranty. - -Note that these Java translations are not a supported product of -Numerical Recipes Software, but are provided only as a convenience to -our users. - -The file NAMES.txt gives the correspondence between C++ routines as -printed in the Numerical Recipes Third Edition book or ebook and the -Java packages and classes in this distribution. For information about -the book or ebook, see http://www.nr.com . - -All the translations are in the directory src/ . If you want to -discover on your own how to use them, just dig in! However, for the -rest of us, this distribution is packaged as a self-contained full -test suite. By running this test suite, you can verify that all the -translations run correctly in your environment. Then, you can examine -any specific test routines in the test/ directory to learn how the -translation's packages and classes may be invoked. - -PREREQUISITES - -To run the test suite you need: - -1. Java SE (Java Platform Standard Edition) ver. 6 or later. If -already installed, then the command "java -version" should produce -output something like this: - java version "1.6.0_32" - Java(TM) SE Runtime Environment (build 1.6.0_32-b05) - Java HotSpot(TM) Client VM (build 20.7-b02, mixed mode, sharing) - -We downloaded Java SE from http://java.com/en/download/index.jsp - -2. JDK (Java SE Development Kit) ver. 6 or later. If already -installed, then the command "javac -version" should produce -output something like this: - javac 1.6.0_32 -(Note, however, that you might need to add the jdk bin/ directory -to your path for this check to work. It is not necessary to do -this to run the test suite.) - -We downloaded JDK from -http://www.oracle.com/technetwork/java/javase/downloads/index.html - -3. Apache Ant, a test suite driver written in Java. If already -installed, then the command "ant -version" should produce output -something like this: - Apache Ant(TM) version 1.8.3 compiled on February 26 2012 -You may need to add the ant bin/ directory to your path, and you may -need to set the environment variables ANT_HOME to the top-level ant -directory; and JAVA_HOME to the top-level JDK directory. For -example, on our Windows machine, the set command indicates: -ANT_HOME=C:\ant -JAVA_HOME=c:\Program Files\Java\jdk1.6.0_32 - -We downloaded Ant from http://ant.apache.org/ - -RUNNING THE TEST SUITE - -1. From the Java_304 directory, which contains the file build.xml, -first try the command "ant clean". You should get output like: - Buildfile: [your directory]/build.xml - clean: - BUILD SUCCESSFUL - Total time: 0 seconds - -2. Next try the command "ant build". The output should resemble: - -Buildfile: [your directory]/build.xml -init: - [mkdir] Created dir: [whatever]/Java_304/build/classes - [mkdir] Created dir: [whatever]/Java_304/build/test -build: - [echo] NR3: [whatever]/Java_304/build.xml - [javac] Compiling 257 source files to [whatever]/Java_304/build/classes - [javac] Compiling 308 source files to [whatever]/Java_304/build/test -BUILD SUCCESSFUL -Total time: 3 seconds - -3. Now for the big test. Try the command "ant AllTests". You will -get a lot of output, hopefully interspersed with many lines that say: - [junit] Passed -These lines indicate that the individual test routines gave the -expected results. To see if *all* the test routines give expected -results, locate the file junit/TEST-com.nr.test.AllTests.xml that was -produced by AllTests. Compare this to the provided file -ExpectedAllTests.xml. Your AllTests.xml file will have many extra -irrelevant lines that have been deleted from ExpectedAllTests.xml, but -all lines in common should agree. (Note that end-of-line conventions -may be different on different machines and are not significant.) - -If all of the above went well, then you are now ready to use the Java -translations of the Numerical Recipes Third Edition routines in your -own programming. diff --git a/common-tools/cnuphys/numRec/LICENSE.txt b/common-tools/cnuphys/numRec/LICENSE.txt deleted file mode 100644 index 671bc7b0d2..0000000000 --- a/common-tools/cnuphys/numRec/LICENSE.txt +++ /dev/null @@ -1,62 +0,0 @@ -COPYRIGHT AND LICENSE INFORMATION - -This directory tree contains translations to Java(TM) source code of -copyrighted Numerical Recipes(TM) Third Edition C++ source code. For -copyright purposes, the Java translations are derivative works of the -Numerical Recipes C++ source code. - -Unless otherwise indicated in individual files, all the Java source -files in this distribution are: - -Copyright (C) Numerical Recipes Software 1986-2007 -Java translations Copyright (C) Huang Wen Hui 2012 - -LICENSE - -Numerical Recipes Software grants to any licensed user of the -Numerical Recipes Third Edition source code in C++ an additional, -non-exclusive license to use these Java translations under terms and -conditions identical to that user's existing license to use the -Numerical Recipes C++ source code. This grant does not modify any -existing terms and conditions, nor does it grant any new C++ or Java -code license to users who are not already licensed to use Numerical -Recipes Third Edition source code in C++. This grant is subject to, -and conditional on, the license grant by Huang Wen Hui given below. - -For information on Numerical Recipes licenses, including both personal -single-user licenses and institutional subscriber licenses, see -http://www.nr.com/aboutNR3license.html . - -Note that owning a copy of the Numerical Recipes book, or purchasing a -subscription to the electronic book, is not the same as a code -license. A code license comes with the purchase of one of (i) a -Numerical Recipes Code CDROM as published by Cambridge University -Press, or (ii) a Code Download package as purchased from Numerical -Recipes Software (see http://www.nr.com/com/storefront.html), or (iii) -an institutional subscription (see further information at -http://www.nr.com/aboutNR3institutional.html). - -Huang Wen Hui represents to Numerical Recipes Software that he is the -author of these Java translations and has the right to license them. -Numerical Recipes Software itself makes no warranty or representation -as to the ownership of the translations (other than their being -derivative works of Numerical Recipes C++ source code). - -Subject to the above conditions and representations, and subject to -the Disclaimer of Warranty below, Huang Wen Hui grants to all users a -perpetual, non-exclusive, royalty-free license to use these Java -translations in any manner whatsoever. - -DISCLAIMER OF WARRANTY - -These Java translations are an unsupported product. Numerical Recipes -Software, the authors and publisher of the Numerical Recipes books, -and Huang Wen Hui make no warranty, express or implied, that the -computer code contained herein is free of error, or is consistent with -any particular standard of merchantability, or that it will meet your -requirements for any particular application. The code should not be -relied on for solving a problem whose incorrect solution could result -in injury to a person or loss of property. If you do use the code in -such a manner, it is entirely at your own risk. The authors and -publisher disclaim all liability for direct or consequential damages -resulting from your use of the code. diff --git a/common-tools/cnuphys/numRec/NAMES.txt b/common-tools/cnuphys/numRec/NAMES.txt deleted file mode 100644 index acc1de5edc..0000000000 --- a/common-tools/cnuphys/numRec/NAMES.txt +++ /dev/null @@ -1,330 +0,0 @@ -Numerical Recipes ver 3.04 Java Ports by Huang Wen Hui ------------------------------------------------------- -C++ to Java Naming Correspondences ----------------------------------- - -This file tells where to find the Java translations by Huang Wen Hui -of Numerical Recipes C++ routines within the distribution. - -Book Chapter to Java Package: - -chapter1 -> com.nr.util -chapter2 -> com.nr.la -chapter3 -> com.nr.interp -chapter4 -> com.nr.fi -chapter5 -> com.nr.fe -chapter6 -> com.nr.sf -chapter7 -> com.nr.ran -chapter8 -> com.nr.sort -chapter9 -> com.nr.root -chapter10 -> com.nr.min -chapter11 -> com.nr.eig -chapter12 -> com.nr.fft -chapter13 -> com.nr.sp -chapter14 -> com.nr.stat -chapter15 -> com.nr.model -chapter16 -> com.nr.ci -chapter17 -> com.nr.ode -chapter18 -> com.nr.bvp -chapter19 -> com.nr.inv -chapter20 -> com.nr.pde -chapter21 -> com.nr.cg -chapter22 -> com.nr.lna - - -C++ Include File to Java Class: - -(Note that, as printed in the book, each C++ routine -show its C++ include file name in the page margin.) - -adapt.h -> com.nr.fi.Adapt -amebsa.h -> com.nr.min.Amebsa -amoeba.h -> com.nr.min.Amoeba -anneal.h -> com.nr.min.Anneal -arithcode.h -> com.nr.lna.Arithcode -asolve.h -> com.nr.la.NRsparseLinbcg -banded.h -> com.nr.la.Bandec -bessel.h -> com.nr.sf.Bessjy - -> com.nr.sf.Bessik - -besselfrac.h -> com.nr.sf.Bessel -calendar.h -> com.nr.util.Calendar -chebyshev.h -> com.nr.fe.Chebyshev -cholesky.h -> com.nr.la.Cholesky -circumcircle.h -> com.nr.cg.Circle -cisi.h -> com.nr.sf.Integrals.cisi -convlv.h -> com.nr.sp.Fourier.convlv -correl.h -> com.nr.sp.Fourier.correl -dawson.h -> com.nr.sf.Integrals.dawson -decchk.h -> com.nr.lna.Icrc.decchk -delaunay.h -> com.nr.cg.Triel - -> com.nr.cg.Delaunay - -> com.nr.cg.Convexhull - -> com.nr.cg.Minspantree - -derule.h -> com.nr.fi.DErule -deviates.h -> com.nr.ran.Expondev - -> com.nr.ran.Logisticdev - -> com.nr.ran.Normaldev_BM - -> com.nr.ran.Cauchydev - -> com.nr.ran.Normaldev - -> com.nr.ran.Gammadev - -> com.nr.ran.Poissondev - -> com.nr.ran.Binomialdev - -dfridr.h -> com.nr.fe.Dfridr -dftintegrate.h -> com.nr.sp.Fourier.dftcor -difeq.h -> com.nr.bvp.Difeq -distributions.h -> com.nr.sf.Cauchydist - -> com.nr.sf.Expondist - -> com.nr.sf.Logisticdist - -dynpro.h -> com.nr.min.Dynpro -eclass.h -> com.nr.sort.EClass -eigen_sym.h -> com.nr.eig.Jacobi - -> com.nr.eig.Symmeig - -eigen_unsym.h -> com.nr.eig.Unsymmeig -elliptint.h -> com.nr.sf.Elliptic -erf.h -> com.nr.sf.Erf - -> com.nr.sf.Normaldist - -> com.nr.sf.Lognormaldist - -expint.h -> com.nr.sf.Integrals.expint -fasper.h -> com.nr.sp.Fourier.Fasper -fermi.h -> com.nr.sf.Fermi -fit_examples.h -> NOT translated -fitab.h -> com.nr.model.Fitab -fitexy.h -> com.nr.model.Fitexy -fitlin.h -> com.nr.model.Fitlin -fitmed.h -> com.nr.model.Fitmed -fitmrq.h -> com.nr.model.Fitmrq -fitsvd.h -> com.nr.model.Fitsvd -fourfs.h -> com.nr.fft.FFT.fourfs -fourier.h -> com.nr.ftt.FFT - -> com.nr.fft.WrapVecDoub -fourier_ndim.h -> com.nr.ftt.FFT -fred2.h -> com.nr.inv.Fred2 -fred_singular.h -> com.nr.inv.Wwghts - -> com.nr.inv.Quad_matrix - -frenel.h -> com.nr.sf.Integrals.frenel -gamma.h -> com.nr.sf.Gamma -gaumixmod.h -> com.nr.ci.Gaumixmod -gauss_wgts.h -> com.nr.fi.GaussianWeights -gauss_wgts2.h -> com.nr.fi.GaussianWeights -gaussj.h -> com.nr.la.GaussJordan.gaussj -hash.h -> com.nr.Hashfn1 - -> com.nr.Hashfn2 - -> com.nr.Hashtable - -> com.nr.Hash - -> com.nr.Mhash - -hashall.h -> com.nr.HashAll -hmm.h -> com.nr.ci.HMM -huffcode.h -> com.nr.lna.Huffcode -hypgeo.h -> com.nr.sf.Hypergeo -icrc.h -> com.nr.lna.Icrc -igray.h -> com.nr.lna.Gray -incgammabeta.h -> com.nr.sf.Gamma - -> com.nr.sf.Beta - -> com.nr.sf.Gammadist - -> com.nr.sf.Betadist - -> com.nr.sf.Studenttdist - -> com.nr.sf.Poissondist - -> com.nr.sf.Binomialdist - -> com.nr.sf.Chisqdist - -> com.nr.sf.Fdist - -interior.h -> NOT translated -interp_1d.h -> com.nr.interp.Base_interp - -> com.nr.interp.Poly_interp - -> com.nr.interp.Rat_interp - -> com.nr.interp.Spline_interp - -> com.nr.interp.BaryRat_interp - -interp_2d.h -> com.nr.interp.Bilin_interp - -> com.nr.interp.Poly2D_interp - -> com.nr.interp.Spline2D_interp - -interp_curve.h -> com.nr.interp.Curve_interp -interp_laplace.h-> com.nr.interp.Laplace_interp -interp_linear.h -> com.nr.interp.Linear_interp -interp_rbf.h -> com.nr.interp.RBF_fn - -> com.nr.interp.RBF_interp - -> com.nr.interp.RBF_multiquadric - -> com.nr.interp.RBF_thinplate - -> com.nr.interp.RBF_gauss - -> com.nr.interp.RBF_inversemultiquadric - -> com.nr.interp.Shep_interp - -iqagent.h -> com.nr.sort.IQagent -kdtree.h -> com.nr.cg.KDtree -kmeans.h -> com.nr.ci.Kmeans -krig.h -> com.nr.interp.interp.Krig -ksdist.h -> com.nr.sf.KSdist -kstests.h -> com.nr.stat.Stattests -kstests_2d.h -> com.nr.stat.Stattests -levex.h -> com.nr.fe.Levin -linbcg.h -> com.nr.la.Linbcg -linpredict.h -> com.nr.sp.Fourier -ludcmp.h -> com.nr.la.LUdcmp -machar.h -> com.nr.lna.Machar -markovgen.h -> com.nr.ci.HMM.markovgen -mcintegrate.h -> com.nr.ran.MCintegrate -mcmc.h -> com.nr.model.State - -> com.nr.model.Plog - -> com.nr.model.Proposal - -mgfas.h -> com.nr.pde.Mgfas -mglin.h -> com.nr.pde.Mglin -mins.h -> com.nr.min.Bracketmethod - -> com.nr.min.Golden - -> com.nr.min.Brent - -> com.nr.min.Dbrent - -mins_ndim.h -> com.nr.min.F1dim - -> com.nr.min.Linemethod - -> com.nr.min.Df1dim - -> com.nr.min.Dlinemethod - -> com.nr.min.Powell - -> com.nr.min.Frprmn - -miser.h -> com.nr.ran.Miser -mnewt.h -> com.nr.root.MNEWT -moment.h -> com.nr.stat.Moment -mparith.h -> com.nr.lna.MParith -multinormaldev.h-> com.nr.ran.Multinormaldev -nr3.h -> com.nr.NRUtil -odeint.h -> com.nr.ode.Output - -> com.nr.ode.Odeint - -pade.h -> com.nr.fe.Ratfn -pcshft.h -> com.nr.fe.Chebyshev -period.h -> com.nr.sp.Fourier.Period -phylo.h -> com.nr.ci.Phylagglomnode - -> com.nr.ci.Phylagglom - -> com.nr.ci.Phylo_wpgma - -> com.nr.ci.Phylo_upgma - -> com.nr.ci.Phylo_slc - -> com.nr.ci.Phylo_clc - -> com.nr.ci.Phylo_nj - -plegendre.h -> com.nr.sf.Legendre -pointbox.h -> com.nr.cg.Point - -> com.nr.cg.Box - -polcoef.h -> com.nr.interp.PolCoef -poly.h -> com.nr.fe.Poly - -> com.nr.fe.Ratfn - -polygon.h -> com.nr.cg.Polygon -primpolytest.h -> com.nr.ran.Primpolytest -psplot.h -> com.nr.lna.PSpage - -> com.nr.lna.PSplot - -psplotexample.h -> NOT translated -qgaus.h -> com.nr.fi.GaussianWeights.qgaus -qotree.h -> com.nr.cg.Qotree - -> com.nr.cg.Nearpoints - -qrdcmp.h -> com.nr.la.QRdcmp -qroot.h -> com.nr.root.Roots.qroot -quad3d.h -> com.nr.fi.NRf3 - -> com.nr.fi.NRf2 - -> com.nr.fi.NRf1 - -quadrature.h -> com.nr.fi.Quadrature - -> com.nr.fi.Trapzd - -> com.nr.fi.Midpnt - -> com.nr.fi.Midinf - -> com.nr.fi.Midsql - -> com.nr.fi.Midsqu - -> com.nr.fi.Midexp - -quadvl.h -> com.nr.stat.Quadvl -quasinewton.h -> com.nr.min.QuasiNewton -ran.h -> com.nr.ran.Ran - -> com.nr.ran.Ranq1 - -> com.nr.ran.Ranq2 - -> com.nr.ran.Ranhash - -> com.nr.ran.Ranbyte - -> com.nr.ran.Ranfib - -> com.nr.ran.Ranlim32 - -ranpt.h -> com.nr.ran.Miser -ratlsq.h -> com.nr.fe.Ratfn -rebin.h -> com.nr.ran.VEGAS.rebin -rk4.h -> com.nr.ode.Odeint.rk4 -rlft3_sharpen.h -> NOT translated -romberg.h -> com.nr.fi.Trapzd -roots.h -> com.nr.root.Roots -roots_multidim.h-> com.nr.root.Roots - -> com.nr.root.NRfdjac - -> com.nr.root.NRfmin - -roots_poly.h -> com.nr.root.Roots -savgol.h -> com.nr.stat.SavitzkyGolayFilter -scrsho.h -> com.nr.lna.PSplot -selip.h -> com.nr.sort.Sorter -series.h -> com.nr.fe.Eulsum - -> com.nr.fe.Epsalg - -> com.nr.fe.Levin - -sfroid.h -> NOT translated -shoot.h -> com.nr.bvp.Shoot -shootf.h -> com.nr.bvp.Shootf -simplex.h -> NOT translated -sobseq.h -> com.nr.ran.Sobol -solvde.h -> com.nr.bvp.Solvde -sor.h -> com.nr.pde.Relaxation -sort.h -> com.nr.sort.Sorter - -> com.nr.sort.Indexx - -> com.nr.sort.Heapselect - -sparse.h -> com.nr.la.NRsparseCol - -> com.nr.la.NRsparseMat - -> com.nr.la.ADAT - -spectrum.h -> com.nr.sp.Spectreg - -> com.nr.sp.Spectolap - -> com.nr.sp.Slepian - -> com.nr.sp.Slepwindow - -> com.nr.sp.Hann - -sphcirc.h -> com.nr.cg.Sphcirc -sphfpt.h -> NOT translated -sphoot.h -> NOT translated -stattests.h -> com.nr.stat.Stattests -stepper.h -> com.nr.ode.StepperBase -stepperbs.h -> com.nr.ode.StepperBS -stepperdopr5.h -> com.nr.ode.StepperDopr5 -stepperdopr853.h-> com.nr.ode.StepperDopr853 -stepperross.h -> com.nr.ode.StepperRoss -steppersie.h -> com.nr.ode.StepperSie -stepperstoerm.h -> com.nr.ode.StepperStoerm -stiel.h -> com.nr.fi.Stiel -stochsim.h -> com.nr.ode.Stochsim -stringalign.h -> com.nr.min.StringAlign -svd.h -> com.nr.la.SVD -svm.h -> com.nr.ci.Svmlinkernel - -> com.nr.ci.Svmlinkernel - -> com.nr.ci.Svmpolykernel - -> com.nr.ci.Svmgausskernel - -> com.nr.ci.Svm - -toeplz.h -> com.nr.la.Toepltz -tridag.h -> com.nr.la.Tridag -vander.h -> com.nr.la.Vander -vegas.h -> com.nr.ran.VEGAS -voltra.h -> com.nr.inv.Volterra -voronoi.h -> com.nr.cg.Voronoi - -> com.nr.cg.Voredge - -wavelet.h -> com.nr.sp.Wavelet - -> com.nr.sp.Daub4 - -> com.nr.sp.Daubs - -> com.nr.sp.Daub4i - -weights.h -> com.nr.pde.Weights -zrhqr.h -> com.nr.root.Roots diff --git a/common-tools/cnuphys/numRec/build.xml b/common-tools/cnuphys/numRec/build.xml deleted file mode 100644 index 9b290b2bcc..0000000000 --- a/common-tools/cnuphys/numRec/build.xml +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Building the jar for clasJlib - - - - Building numRec jar - - - - - diff --git a/common-tools/cnuphys/numRec/src/com/nr/Complex.java b/common-tools/cnuphys/numRec/src/com/nr/Complex.java deleted file mode 100644 index c51d0ccd03..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/Complex.java +++ /dev/null @@ -1,2133 +0,0 @@ -package com.nr; - -/* File: Complex.java - * -- A Java class for performing complex - * number arithmetic to double precision. - * - * Copyright (c) 1997 - 2001, Alexander Anderson. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - */ - -import java.io.Serializable; - -/** - *

- * - * @version 1.0.1
- * - * Last change: ALM 23 Mar 2001 8:56 pm - * - *

- * A Java class for performing complex number arithmetic to - * double precision. - * - *

- *

Make yours a Java enabled - * browser and OS! - *

- * This applet has been adapted
- * from a Vector - * Visualization applet by Vladimir - * Sorokin.

- *
- * - *

- * @author Sandy - * Anderson - * @author Priyantha Jayanetti - *

- * - * - *

- * 
- *         Copyright (c) 1997 - 2001, Alexander Anderson.
- *
- *         This program is free software; you can redistribute it and/or modify
- *         it under the terms of the GNU
- *         General Public License as published by the Free Software Foundation;
- *         either version 2 of the License, or (at your option) any later
- *         version.
- *
- *         This program is distributed in the hope that it will be useful, but
- *         WITHOUT ANY WARRANTY; without even the implied warranty of
- *         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- *         General Public License for more details.
- *
- *         You should have received a copy of the GNU General Public License along with this
- *         program; if not, write to the Free Software Foundation, Inc., 59
- *         Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- * 
- *         
- * - * - *

- * The latest version of this Complex class is available from - * the Netlib Repository. - *

- * Here's an example of the style the class permits:
- * - *

- * 
- *         import ORG.netlib.math.complex.Complex;
- * public class Test {
- * public boolean isInMandelbrot (Complex c, int maxIter) - * { Complex z= new Complex(0, 0);
- * for (int i= 0; i < maxIter; i++) { z= z.mul(z).add(c); - * if (z.abs() > 2) return false; }
- * return true; }
- * } - * - *
- * - * - *

- *

This class was developed by Sandy Anderson at the School - * of Electronic Engineering, Middlesex - * University, UK, and Priyantha Jayanetti at The Power Systems - * Program, the University of - * Maine, USA.
- *

- *

And many, many thanks to Mr. Daniel Hirsch, - * for his constant advice on the mathematics, his exasperating ability - * to uncover bugs blindfold, and for his persistent badgering over the - * exact wording of this documentation.
- *

- *

For instance, he starts to growl like a badger if you say - * "infinite set".

- *
"Grrr...What's that mean? Countably infinite?" - *

- *
You think for a while.

- *
"Grrr..."

- *
"Yes."

- *
"Ah! Then you mean infinitely many."

- *

- **/ - -public class Complex implements Cloneable, Serializable { - private static final long serialVersionUID = 1L; - public static final String VERSION = "1.0.1"; - public static final String DATE = "Fri 23-Mar-2001 8:56 pm"; - public static final String AUTHOR = "sandy@almide.demon.co.uk"; - public static final String REMARK = "Class available from " - + "http://www.netlib.org/"; - - /** - * Switches on debugging information. - *

- **/ - // protected static boolean debug = false; - - /** - * Whilst debugging: the nesting level when tracing method calls. - *

- **/ - // private static int trace_nesting = 0; - - /** - * Twice - * PI radians is the same thing as 360 degrees. - *

- **/ - protected static final double TWO_PI = 2.0 * Math.PI; - - /** - * A constant representing i, the famous square root of - * -1. - *

- * The other square root of -1 is - i. - *

- **/ - public static final Complex I = new Complex(0.0, 1.0); - - // private static long objectCount; // !!! - - private double re; - private double im; - - // ---------------------------------// - // CONSTRUCTORS // - // ---------------------------------// - - /** - * Constructs a Complex representing the number zero. - * - *

- **/ - - public Complex() { - this(0.0, 0.0); - }// end Complex() - - /** - * Constructs a Complex representing a real number. - * - *

- * - * @param re - * The real number - *

- * @see Complex#real(double) - **/ - - public Complex(double re) { - this(re, 0.0); - }// end Complex(double) - - /** - * Constructs a separate new Complex from an existing - * Complex. - * - *

- * - * @param z - * A Complex number - *

- **/ - - public Complex(Complex z) { - this(z.re, z.im); - }// end Complex(Complex) - - /** - * Constructs a Complex from real and imaginary parts. - * - *

- * Note: - *

- * - *

- * - * @param re - * Real part - * @param im - * Imaginary part - *

- * @see Complex#cart(double, double) - * @see Complex#polar(double, double) - **/ - - public Complex(double re, double im) { - this.re = re; - this.im = im; - - // if (debug) System.out.println(indent(trace_nesting) + - // "new Complex, #" + (++objectCount));// !!! - }// end Complex(double,double) - - // ---------------------------------// - // DEBUG // - // ---------------------------------// - - /* - * - * // BETA Debugging methods... - * - * private static void entering (String what) { - * System.out.print(indent(trace_nesting) + what); trace_nesting++; }//end - * entering(String) - * - * private static void enter (String what, double param1, double param2) { - * entering(what); System.out.println("(" + param1 + ", " + param2 + ") "); - * }//end enter(String,double,double) - * - * private static void enter (String what, double param) { entering(what); - * System.out.println("(" + param + ") "); }//end enter(String,double) - * - * private static void enter (String what, Complex z) { entering(what); - * System.out.println("(" + z + ") "); }//end enter(String,Complex) - * - * private static void enter (String what, Complex z1, Complex z2) { - * entering(what); System.out.println("(" + z1 + ", " + z2 + ") "); }//end - * enter(String,Complex,Complex) - * - * private static void enter (String what, Complex z, double x) { - * entering(what); System.out.println("(" + z + ", " + x + ") "); }//end - * enter(String,Complex,double) - * - * private static void enter (String what, Complex z, double x, double y) { - * entering(what); System.out.println("(" + z + ", " + cart(x, y) + ") "); - * }//end enter(String,Complex,double) - * - * private static void enter (String what, Complex z1, Complex z2, double x) - * { entering(what); System.out.println("(" + z1 + ", " + z2 + ", " + x + - * ") "); }//end enter(String,Complex,Complex,double) - * - * private static void leaving (String what) { trace_nesting--; - * System.out.print(indent(trace_nesting) + "is "); }//end leaving(String) - * - * private static void leave (String what, boolean result) { leaving(what); - * System.out.println(result); }//end leave(String,boolean) - * - * private static void leave (String what, double result) { leaving(what); - * System.out.println(result); }//end leave(String,double) - * - * private static void leave (String what, Complex result) { leaving(what); - * System.out.println(result); }//end leave(String,Complex) - * - * private static String indent (int nesting) { StringBuffer indention = new - * StringBuffer(""); - * - * for (int i = 0; i < nesting; i++) { indention.append(" "); }//endfor - * - * return indention.toString(); }//end indent(int) - */ - - /** - * Useful for checking up on the exact version. - * - *

- **/ - - public static void main(String[] args) { - System.out.println(); - System.out.println("Module : " + Complex.class.getName()); - System.out.println("Version: " + Complex.VERSION); - System.out.println("Date : " + Complex.DATE); - System.out.println("Author : " + Complex.AUTHOR); - System.out.println("Remark : " + Complex.REMARK); - System.out.println(); - System.out.println("Hint: use TestComplex to test the class."); - System.out.println(); - }// end main(String[]) - - // ---------------------------------// - // STATIC // - // ---------------------------------// - - /** - * Returns a Complex representing a real number. - * - *

- * - * @param real - * The real number - *

- * @return Complex representation of the real - *

- * @see Complex#re() - * @see Complex#cart(double, double) - **/ - - public static Complex real(double real) { - return new Complex(real, 0.0); - }// end real(double) - - /** - * Returns a Complex from real and imaginary parts. - * - *

- * - * @param re - * Real part - * @param im - * Imaginary part - *

- * @return Complex from Cartesian coordinates - *

- * @see Complex#re() - * @see Complex#im() - * @see Complex#polar(double, double) - * @see Complex#toString() - **/ - - public static Complex cart(double re, double im) { - return new Complex(re, im); - }// end cart(double,double) - - /** - * Returns a Complex from a size and direction. - * - *

- * - * @param r - * Size - * @param theta - * Direction (in radians) - *

- * @return Complex from Polar coordinates - *

- * @see Complex#abs() - * @see Complex#arg() - * @see Complex#cart(double, double) - **/ - - public static Complex polar(double r, double theta) { - if (r < 0.0) { - theta += Math.PI; - r = -r; - }// endif - - theta = theta % TWO_PI; - - return cart(r * Math.cos(theta), r * Math.sin(theta)); - }// end polar(double,double) - - /** - * Returns the Complex base raised to the power of the exponent. - * - *

- * - * @param base - * The base "to raise" - * @param exponent - * The exponent "by which to raise" - *

- * @return base "raised to the power of" exponent - *

- * @see Complex#pow(double, Complex) - **/ - - public static Complex pow(Complex base, double exponent) { - // return base.log().scale(exponent).exp(); - - double re = exponent * Math.log(base.abs()); - double im = exponent * base.arg(); - - double scalar = Math.exp(re); - - return cart(scalar * Math.cos(im), scalar * Math.sin(im)); - }// end pow(Complex,double) - - /** - * Returns the base raised to the power of the Complex exponent. - * - *

- * - * @param base - * The base "to raise" - * @param exponent - * The exponent "by which to raise" - *

- * @return base "raised to the power of" exponent - *

- * @see Complex#pow(Complex, Complex) - * @see Complex#exp() - **/ - - public static Complex pow(double base, Complex exponent) { - // return real(base).log().mul(exponent).exp(); - - double re = Math.log(Math.abs(base)); - double im = Math.atan2(0.0, base); - - double re2 = (re * exponent.re) - (im * exponent.im); - double im2 = (re * exponent.im) + (im * exponent.re); - - double scalar = Math.exp(re2); - - return cart(scalar * Math.cos(im2), scalar * Math.sin(im2)); - }// end pow(double,Complex) - - /** - * Returns the Complex base raised to the power of the - * Complex exponent. - * - *

- * - * @param base - * The base "to raise" - * @param exponent - * The exponent "by which to raise" - *

- * @return base "raised to the power of" exponent - *

- * @see Complex#pow(Complex, double) - * @see Complex#pow(Complex) - **/ - - public static Complex pow(Complex base, Complex exponent) { - // return base.log().mul(exponent).exp(); - - double re = Math.log(base.abs()); - double im = base.arg(); - - double re2 = (re * exponent.re) - (im * exponent.im); - double im2 = (re * exponent.im) + (im * exponent.re); - - double scalar = Math.exp(re2); - - return cart(scalar * Math.cos(im2), scalar * Math.sin(im2)); - }// end pow(Complex,Complex) - - // ---------------------------------// - // PUBLIC // - // ---------------------------------// - - /** - * Returns true if either the real or imaginary component of this - * Complex is an infinite value. - * - *

- * - * @return true if either component of the Complex object - * is infinite; false, otherwise. - *

- **/ - - public boolean isInfinite() { - return (Double.isInfinite(re) || Double.isInfinite(im)); - }// end isInfinite() - - /** - * Returns true if either the real or imaginary component of this - * Complex is a Not-a-Number (NaN) value. - * - *

- * - * @return true if either component of the Complex object - * is NaN; false, otherwise. - *

- **/ - - public boolean isNaN() { - return (Double.isNaN(re) || Double.isNaN(im)); - }// end isNaN() - - /** - * Decides if two Complex numbers are "sufficiently" alike to be - * considered equal. - * - *

- * tolerance is the maximum magnitude of the difference between - * them before they are considered not equal. - *

- * Checking for equality between two real numbers on computer hardware is a - * tricky business. Try - *

- * - *

-     * System.out.println((1.0 / 3.0 * 3.0));
-     * 
- *

- * and you'll see the nature of the problem! It's just as tricky with - * Complex numbers. - *

- * Realize that because of these complications, it's possible to find that - * the magnitude of one Complex number a is less than - * another, b, and yet a.equals(b, myTolerance) returns - * true. Be aware! - *

- * - * @param z - * The Complex to compare with - * @param tolerance - * The tolerance for equality - *

- * @return true, or false - *

- **/ - - public boolean equals(Complex z, double tolerance) { - // still true when _equal_ to tolerance? ... - return abs(re - z.re, im - z.im) <= Math.abs(tolerance); - // ...and tolerance is always non-negative - }// end equals(Complex,double) - - /** - * Test for the equality of two Complex objects. If both the real and - * imaginary parts of two complex numbers are exactly the same, and neither - * is {@code Double.NaN}, the two Complex objects are considered to be - * equal. All {@code NaN} values are considered to be equal - i.e, if either - * (or both) real and imaginary parts of the complex number are equal to - * {@code Double.NaN}, the complex number is equal to {@code NaN}. - * - * @param other - * Object to test for equality to this - * @return true if two Complex objects are equal, false if object is - * {@code null}, not an instance of Complex, or not equal to this - * Complex instance. - */ - @Override - public boolean equals(Object other) { - if (this == other) { - return true; - } - if (other instanceof Complex) { - Complex c = (Complex) other; - if (c.isNaN()) { - return c.isNaN(); - } else { - return (re == c.re) && (im == c.im); - } - } - return false; - } - - /** - * Returns a hashcode for this complex number. - */ - @Override - public int hashCode() { - return (int) (Math.exp(mod())); - } - - /** - * Overrides the {@link java.lang.Cloneable Cloneable} interface. - * - *

- * Standard override; no change in semantics. - *

- * The following Java code example illustrates how to clone, or copy, - * a Complex number: - *

- * - *

-     *     Complex z1 =  new Complex(0, 1);
-     *     Complex z2 =  (Complex) z1.clone();
-     * 
- *

- * - * @return An Object that is a copy of this Complex - * object. - *

- * @see java.lang.Cloneable - * @see java.lang.Object#clone() - **/ - - @Override - public Object clone() { - try { - return (super.clone()); - } catch (java.lang.CloneNotSupportedException e) { - return null; // This cannot happen: there would have to be a serious - // internal error in the Java runtime if this codepath - // happens! - }// endtry - }// end clone() - - /** - * Extracts the real part of a Complex as a double. - * - *

- * - *

-     *     re(x + i*y)  =  x
-     * 
- *

- * - * @return The real part - *

- * @see Complex#im() - * @see Complex#cart(double, double) - * @see Complex#real(double) - **/ - - public double re() { - return re; - }// end re() - - /** - * Extracts the imaginary part of a Complex as a double. - * - *

- * - *

-     *     im(x + i*y)  =  y
-     * 
- *

- * - * @return The imaginary part - *

- * @see Complex#re() - * @see Complex#cart(double, double) - **/ - - public double im() { - return im; - }// end im() - - /** - * Returns the square of the "length" of a Complex number. - * - *

- * - *

-     *     norm(x + i*y)  =  x*x + y*y
-     * 
- *

- * Always non-negative. - *

- * - * @return The norm - *

- * @see Complex#abs() - **/ - - public double norm() { - return (re * re) + (im * im); - }// end norm() - - /** - * Returns the magnitude of a Complex number. - * - *

- * - *

-     * abs(z) = sqrt(norm(z))
-     * 
- *

- * In other words, it's Pythagorean distance from the origin (0 + - * 0i, or zero). - *

- * The magnitude is also referred to as the "modulus" or "length". - *

- * Always non-negative. - *

- * - * @return The magnitude (or "length") - *

- * @see Complex#arg() - * @see Complex#polar(double, double) - * @see Complex#norm() - **/ - - public double abs() { - return abs(re, im); - }// end abs() - - public double mod() { - return abs(re, im); - }// end mod() - - static private double abs(double x, double y) { - // abs(z) = sqrt(norm(z)) - - // Adapted from - // "Numerical Recipes in Fortran 77: The Art of Scientific Computing" - // (ISBN 0-521-43064-X) - - double absX = Math.abs(x); - double absY = Math.abs(y); - - if (absX == 0.0 && absY == 0.0) { // !!! Numerical Recipes, mmm? - return 0.0; - } else if (absX >= absY) { - double d = y / x; - return absX * Math.sqrt(1.0 + d * d); - } else { - double d = x / y; - return absY * Math.sqrt(1.0 + d * d); - }// endif - }// end abs() - - /** - * Returns the principal angle of a Complex number, in - * radians, measured counter-clockwise from the real axis. (Think of the - * reals as the x-axis, and the imaginaries as the y-axis.) - * - *

- * There are infinitely many solutions, besides the principal solution. If - * A is the principal solution of arg(z), the others are of - * the form: - *

- * - *

-     *     A + 2*k*PI
-     * 
- *

- * where k is any integer. - *

- * arg() always returns a double between - - * PI and +PI. - *

- * Note: - *

- * - *

- * Domain Restrictions: - *

- * - *

- * - * @return Principal angle (in radians) - *

- * @see Complex#abs() - * @see Complex#polar(double, double) - **/ - - public double arg() { - return Math.atan2(im, re); - }// end arg() - - /** - * Returns the "negative" of a Complex number. - * - *

- * - *

-     *     neg(a + i*b)  =  -a - i*b
-     * 
- *

- * The magnitude of the negative is the same, but the angle is flipped - * through PI (or 180 degrees). - *

- * - * @return Negative of the Complex - *

- * @see Complex#scale(double) - **/ - - public Complex neg() { - return this.scale(-1.0); - }// end neg() - - /** - * Returns the Complex "conjugate". - * - *

- * - *

-     *     conj(x + i*y)  =  x - i*y
-     * 
- *

- * The conjugate appears "flipped" across the real axis. - *

- * - * @return The Complex conjugate - *

- **/ - - public Complex conj() { - return cart(re, -im); - }// end conj() - - static private void inv(Complex z) { - double zRe, zIm; - double scalar; - - if (Math.abs(z.re) >= Math.abs(z.im)) { - scalar = 1.0 / (z.re + z.im * (z.im / z.re)); - - zRe = scalar; - zIm = scalar * (-z.im / z.re); - } else { - scalar = 1.0 / (z.re * (z.re / z.im) + z.im); - - zRe = scalar * (z.re / z.im); - zIm = -scalar; - }// endif - - z.re = zRe; - z.im = zIm; - }// end inv(Complex) - - /** - * Returns the Complex scaled by a real number. - * - *

- * - *

-     *     scale((x + i*y), s)  =  (x*s + i*y*s)
-     * 
- *

- * Scaling by the real number 2.0, doubles the magnitude, but leaves - * the arg() unchanged. Scaling by -1.0 keeps the magnitude - * the same, but flips the arg() by PI (180 - * degrees). - *

- * - * @param scalar - * A real number scale factor - *

- * @return Complex scaled by a real number - *

- * @see Complex#mul(Complex) - * @see Complex#div(Complex) - * @see Complex#neg() - **/ - - public Complex scale(double scalar) { - return cart(scalar * re, scalar * im); - }// end scale(double) - - public Complex mul(double scalar) { - return cart(scalar * re, scalar * im); - }// end scale(double) - - /** - * To perform z1 + z2, you write z1.add(z2) . - * - *

- * - *

-     *     (a + i*b) + (c + i*d)  =  ((a+c) + i*(b+d))
-     * 
- *

- **/ - - public Complex add(Complex z) { - return cart(re + z.re, im + z.im); - }// end add(Complex) - - /** - * To perform z1 - z2, you write z1.sub(z2) . - * - *

- * - *

-     *     (a + i*b) - (c + i*d)  =  ((a-c) + i*(b-d))
-     * 
- *

- **/ - - public Complex sub(Complex z) { - return cart(re - z.re, im - z.im); - }// end sub(Complex) - - /** - * To perform z1 * z2, you write z1.mul(z2) . - * - *

- * - *

-     *     (a + i*b) * (c + i*d)  =  ( (a*c) - (b*d) + i*((a*d) + (b*c)) )
-     * 
- *

- * - * @see Complex#scale(double) - **/ - - public Complex mul(Complex z) { - return cart((re * z.re) - (im * z.im), (re * z.im) + (im * z.re)); - // return cart( (re*z.re) - (im*z.im), (re + im)*(z.re + z.im) - re*z.re - // - im*z.im); - }// end mul(Complex) - - /** - * To perform z1 / z2, you write z1.div(z2) . - * - *

- * - *

-     *     (a + i*b) / (c + i*d)  =  ( (a*c) + (b*d) + i*((b*c) - (a*d)) ) / norm(c + i*d)
-     * 
- *

- * Take care not to divide by zero! - *

- * Note: - *

- * - *

- * Domain Restrictions: - *

- * - *

- * - * @see Complex#scale(double) - **/ - - public Complex div(Complex z) { - Complex result = new Complex(this); - div(result, z.re, z.im); - return result; - }// end div(Complex) - - public Complex div(final double x) { - return new Complex(re / x, im / x); - } - - static private void div(Complex z, double x, double y) { - // Adapted from - // "Numerical Recipes in Fortran 77: The Art of Scientific Computing" - // (ISBN 0-521-43064-X) - - double zRe, zIm; - double scalar; - - if (Math.abs(x) >= Math.abs(y)) { - scalar = 1.0 / (x + y * (y / x)); - - zRe = scalar * (z.re + z.im * (y / x)); - zIm = scalar * (z.im - z.re * (y / x)); - - } else { - scalar = 1.0 / (x * (x / y) + y); - - zRe = scalar * (z.re * (x / y) + z.im); - zIm = scalar * (z.im * (x / y) - z.re); - }// endif - - z.re = zRe; - z.im = zIm; - }// end div(Complex,double,double) - - /** - * Returns a Complex representing one of the two square roots. - * - *

- * - *

-     *     sqrt(z)  =  sqrt(abs(z)) * ( cos(arg(z)/2) + i * sin(arg(z)/2) )
-     * 
- *

- * For any complex number z, sqrt(z) will return the - * complex root whose arg is arg(z)/2. - *

- * Note: - *

- * - *

- * - * @return The square root whose arg is arg(z)/2. - *

- * @see Complex#pow(Complex, double) - **/ - - public Complex sqrt() { - Complex result = new Complex(this); - sqrt(result); - return result; - }// end sqrt() - - static private void sqrt(Complex z) { - // with thanks to Jim Shapiro - // adapted from "Numerical Recipies in C" (ISBN 0-521-43108-5) - // by William H. Press et al - - double mag = z.abs(); - - if (mag > 0.0) { - if (z.re > 0.0) { - double temp = Math.sqrt(0.5 * (mag + z.re)); - - z.re = temp; - z.im = 0.5 * z.im / temp; - } else { - double temp = Math.sqrt(0.5 * (mag - z.re)); - - if (z.im < 0.0) { - temp = -temp; - }// endif - - z.re = 0.5 * z.im / temp; - z.im = temp; - }// endif - } else { - z.re = 0.0; - z.im = 0.0; - }// endif - }// end sqrt(Complex) - - /** - * Returns this Complex raised to the power of a Complex - * exponent. - * - *

- * - * @param exponent - * The exponent "by which to raise" - *

- * @return this Complex "raised to the power of" the exponent - *

- * @see Complex#pow(Complex, Complex) - **/ - - public Complex pow(Complex exponent) { - return Complex.pow(this, exponent); - }// end pow(Complex) - - /** - * Returns the number e "raised to" a Complex power. - * - *

- * - *

-     *     exp(x + i*y)  =  exp(x) * ( cos(y) + i * sin(y) )
-     * 
- *

- * Note: - *

- * - *

- * - * @return e "raised to the power of" this Complex - *

- * @see Complex#log() - * @see Complex#pow(double, Complex) - **/ - - public Complex exp() { - double scalar = Math.exp(re); // e^ix = cis x - return cart(scalar * Math.cos(im), scalar * Math.sin(im)); - }// end exp() - - /** - * Returns the principal natural logarithm of a Complex - * number. - * - *

- * - *

-     *     log(z)  =  log(abs(z)) + i * arg(z)
-     * 
- *

- * There are infinitely many solutions, besides the principal solution. If - * L is the principal solution of log(z), the others are of - * the form: - *

- * - *

-     *     L + (2*k*PI)*i
-     * 
- *

- * where k is any integer. - *

- * - * @return Principal Complex natural logarithm - *

- * @see Complex#exp() - **/ - - public Complex log() { - return cart(Math.log(this.abs()), this.arg()); // principal value - }// end log() - - /** - * Returns the principal logarithm (base 10) of a - * Complex number. - * - *

- * - *

-     * log10(z) = log(z) / log(10)
-     * 
- *

- * There are infinitely many solutions, besides the principal solution. If - * L is the principal solution of log10(z), the others are of - * the form: - *

- * - *

-     *     L + (2*k*PI)*i
-     * 
- *

- * where k is any integer. - *

- * - * @return Principal Complex logarithm (base 10) - *

- * @see Complex#exp() - * @see Complex#log() - **/ - /* - * DEPRECATED !!! public Complex log10 () { Complex result; // if (debug) - * enter("log10", this); - * - * double scalar = 1.0/Math.log(10.0); - * - * // result = this.log().scale(scalar); - * - * result = cart( scalar * Math.log(this.abs()), scalar * this.arg() ); - * - * // if (debug) leave("log10", result); return result; }//end log10() /* - */ - - /** - * Returns the sine of a Complex number. - * - *

- * - *

-     *     sin(z)  =  ( exp(i*z) - exp(-i*z) ) / (2*i)
-     * 
- *

- * - * @return The Complex sine - *

- * @see Complex#asin() - * @see Complex#sinh() - * @see Complex#cosec() - * @see Complex#cos() - * @see Complex#tan() - **/ - - public Complex sin() { - Complex result; - // sin(z) = ( exp(i*z) - exp(-i*z) ) / (2*i) - - double scalar; - double iz_re, iz_im; - double _re1, _im1; - double _re2, _im2; - - // iz: i.mul(z) ... - iz_re = -im; - iz_im = re; - - // _1: iz.exp() ... - scalar = Math.exp(iz_re); - _re1 = scalar * Math.cos(iz_im); - _im1 = scalar * Math.sin(iz_im); - - // _2: iz.neg().exp() ... - scalar = Math.exp(-iz_re); - _re2 = scalar * Math.cos(-iz_im); - _im2 = scalar * Math.sin(-iz_im); - - // _1: _1.sub(_2) ... - _re1 = _re1 - _re2; // !!! - _im1 = _im1 - _im2; // !!! - - // result: _1.div(2*i) ... - result = cart(0.5 * _im1, -0.5 * _re1); - // ... result = cart(_re1, _im1); - // div(result, 0.0, 2.0); - return result; - }// end sin() - - /** - * Returns the cosine of a Complex number. - * - *

- * - *

-     *     cos(z)  =  ( exp(i*z) + exp(-i*z) ) / 2
-     * 
- *

- * - * @return The Complex cosine - *

- * @see Complex#acos() - * @see Complex#cosh() - * @see Complex#sec() - * @see Complex#sin() - * @see Complex#tan() - **/ - - public Complex cos() { - Complex result; - // cos(z) = ( exp(i*z) + exp(-i*z) ) / 2 - - double scalar; - double iz_re, iz_im; - double _re1, _im1; - double _re2, _im2; - - // iz: i.mul(z) ... - iz_re = -im; - iz_im = re; - - // _1: iz.exp() ... - scalar = Math.exp(iz_re); - _re1 = scalar * Math.cos(iz_im); - _im1 = scalar * Math.sin(iz_im); - - // _2: iz.neg().exp() ... - scalar = Math.exp(-iz_re); - _re2 = scalar * Math.cos(-iz_im); - _im2 = scalar * Math.sin(-iz_im); - - // _1: _1.add(_2) ... - _re1 = _re1 + _re2; // !!! - _im1 = _im1 + _im2; // !!! - - // result: _1.scale(0.5) ... - result = cart(0.5 * _re1, 0.5 * _im1); - return result; - }// end cos() - - /** - * Returns the tangent of a Complex number. - * - *

- * - *

-     * tan(z) = sin(z) / cos(z)
-     * 
- *

- * Domain Restrictions: - *

- * - *

- * - * @return The Complex tangent - *

- * @see Complex#atan() - * @see Complex#tanh() - * @see Complex#cot() - * @see Complex#sin() - * @see Complex#cos() - **/ - - public Complex tan() { - Complex result; - // tan(z) = sin(z) / cos(z) - - double scalar; - double iz_re, iz_im; - double _re1, _im1; - double _re2, _im2; - double _re3, _im3; - - double cs_re, cs_im; - - // sin() ... - - // iz: i.mul(z) ... - iz_re = -im; - iz_im = re; - - // _1: iz.exp() ... - scalar = Math.exp(iz_re); - _re1 = scalar * Math.cos(iz_im); - _im1 = scalar * Math.sin(iz_im); - - // _2: iz.neg().exp() ... - scalar = Math.exp(-iz_re); - _re2 = scalar * Math.cos(-iz_im); - _im2 = scalar * Math.sin(-iz_im); - - // _3: _1.sub(_2) ... - _re3 = _re1 - _re2; - _im3 = _im1 - _im2; - - // result: _3.div(2*i) ... - result = cart(0.5 * _im3, -0.5 * _re3); - // result = cart(_re3, _im3); - // div(result, 0.0, 2.0); - - // cos() ... - - // _3: _1.add(_2) ... - _re3 = _re1 + _re2; - _im3 = _im1 + _im2; - - // cs: _3.scale(0.5) ... - cs_re = 0.5 * _re3; - cs_im = 0.5 * _im3; - - // result: result.div(cs) ... - div(result, cs_re, cs_im); - return result; - }// end tan() - - /** - * Returns the cosecant of a Complex number. - * - *

- * - *

-     * cosec(z) = 1 / sin(z)
-     * 
- *

- * Domain Restrictions: - *

- * - *

- * - * @return The Complex cosecant - *

- * @see Complex#sin() - * @see Complex#sec() - * @see Complex#cot() - **/ - - public Complex cosec() { - Complex result; - // cosec(z) = 1 / sin(z) - - double scalar; - double iz_re, iz_im; - double _re1, _im1; - double _re2, _im2; - - // iz: i.mul(z) ... - iz_re = -im; - iz_im = re; - - // _1: iz.exp() ... - scalar = Math.exp(iz_re); - _re1 = scalar * Math.cos(iz_im); - _im1 = scalar * Math.sin(iz_im); - - // _2: iz.neg().exp() ... - scalar = Math.exp(-iz_re); - _re2 = scalar * Math.cos(-iz_im); - _im2 = scalar * Math.sin(-iz_im); - - // _1: _1.sub(_2) ... - _re1 = _re1 - _re2; // !!! - _im1 = _im1 - _im2; // !!! - - // _result: _1.div(2*i) ... - result = cart(0.5 * _im1, -0.5 * _re1); - // result = cart(_re1, _im1); - // div(result, 0.0, 2.0); - - // result: one.div(_result) ... - inv(result); - return result; - }// end cosec() - - /** - * Returns the secant of a Complex number. - * - *

- * - *

-     * sec(z) = 1 / cos(z)
-     * 
- *

- * Domain Restrictions: - *

- * - *

- * - * @return The Complex secant - *

- * @see Complex#cos() - * @see Complex#cosec() - * @see Complex#cot() - **/ - - public Complex sec() { - Complex result; - // sec(z) = 1 / cos(z) - - double scalar; - double iz_re, iz_im; - double _re1, _im1; - double _re2, _im2; - - // iz: i.mul(z) ... - iz_re = -im; - iz_im = re; - - // _1: iz.exp() ... - scalar = Math.exp(iz_re); - _re1 = scalar * Math.cos(iz_im); - _im1 = scalar * Math.sin(iz_im); - - // _2: iz.neg().exp() ... - scalar = Math.exp(-iz_re); - _re2 = scalar * Math.cos(-iz_im); - _im2 = scalar * Math.sin(-iz_im); - - // _1: _1.add(_2) ... - _re1 = _re1 + _re2; - _im1 = _im1 + _im2; - - // result: _1.scale(0.5) ... - result = cart(0.5 * _re1, 0.5 * _im1); - - // result: one.div(result) ... - inv(result); - return result; - }// end sec() - - /** - * Returns the cotangent of a Complex number. - * - *

- * - *

-     * cot(z) = 1 / tan(z)
-     * 
- *

- * Domain Restrictions: - *

- * - *

- * - * @return The Complex cotangent - *

- * @see Complex#tan() - * @see Complex#cosec() - * @see Complex#sec() - **/ - - public Complex cot() { - Complex result; - // cot(z) = 1 / tan(z) = cos(z) / sin(z) - - double scalar; - double iz_re, iz_im; - double _re1, _im1; - double _re2, _im2; - double _re3, _im3; - - double sn_re, sn_im; - - // cos() ... - - // iz: i.mul(z) ... - iz_re = -im; - iz_im = re; - - // _1: iz.exp() ... - scalar = Math.exp(iz_re); - _re1 = scalar * Math.cos(iz_im); - _im1 = scalar * Math.sin(iz_im); - - // _2: iz.neg().exp() ... - scalar = Math.exp(-iz_re); - _re2 = scalar * Math.cos(-iz_im); - _im2 = scalar * Math.sin(-iz_im); - - // _3: _1.add(_2) ... - _re3 = _re1 + _re2; - _im3 = _im1 + _im2; - - // result: _3.scale(0.5) ... - result = cart(0.5 * _re3, 0.5 * _im3); - - // sin() ... - - // _3: _1.sub(_2) ... - _re3 = _re1 - _re2; - _im3 = _im1 - _im2; - - // sn: _3.div(2*i) ... - sn_re = 0.5 * _im3; // !!! - sn_im = -0.5 * _re3; // !!! - - // result: result.div(sn) ... - div(result, sn_re, sn_im); - return result; - }// end cot() - - /** - * Returns the hyperbolic sine of a Complex number. - * - *

- * - *

-     * sinh(z) = (exp(z) - exp(-z)) / 2
-     * 
- *

- * - * @return The Complex hyperbolic sine - *

- * @see Complex#sin() - * @see Complex#asinh() - **/ - - public Complex sinh() { - Complex result; - // sinh(z) = ( exp(z) - exp(-z) ) / 2 - - double scalar; - double _re1, _im1; - double _re2, _im2; - - // _1: z.exp() ... - scalar = Math.exp(re); - _re1 = scalar * Math.cos(im); - _im1 = scalar * Math.sin(im); - - // _2: z.neg().exp() ... - scalar = Math.exp(-re); - _re2 = scalar * Math.cos(-im); - _im2 = scalar * Math.sin(-im); - - // _1: _1.sub(_2) ... - _re1 = _re1 - _re2; // !!! - _im1 = _im1 - _im2; // !!! - - // result: _1.scale(0.5) ... - result = cart(0.5 * _re1, 0.5 * _im1); - return result; - }// end sinh() - - /** - * Returns the hyperbolic cosine of a Complex number. - * - *

- * - *

-     * cosh(z) = (exp(z) + exp(-z)) / 2
-     * 
- *

- * - * @return The Complex hyperbolic cosine - *

- * @see Complex#cos() - * @see Complex#acosh() - **/ - - public Complex cosh() { - Complex result; - // cosh(z) = ( exp(z) + exp(-z) ) / 2 - - double scalar; - double _re1, _im1; - double _re2, _im2; - - // _1: z.exp() ... - scalar = Math.exp(re); - _re1 = scalar * Math.cos(im); - _im1 = scalar * Math.sin(im); - - // _2: z.neg().exp() ... - scalar = Math.exp(-re); - _re2 = scalar * Math.cos(-im); - _im2 = scalar * Math.sin(-im); - - // _1: _1.add(_2) ... - _re1 = _re1 + _re2; // !!! - _im1 = _im1 + _im2; // !!! - - // result: _1.scale(0.5) ... - result = cart(0.5 * _re1, 0.5 * _im1); - return result; - }// end cosh() - - /** - * Returns the hyperbolic tangent of a Complex number. - * - *

- * - *

-     * tanh(z) = sinh(z) / cosh(z)
-     * 
- *

- * - * @return The Complex hyperbolic tangent - *

- * @see Complex#tan() - * @see Complex#atanh() - **/ - - public Complex tanh() { - Complex result; - // tanh(z) = sinh(z) / cosh(z) - - double scalar; - double _re1, _im1; - double _re2, _im2; - double _re3, _im3; - - double ch_re, ch_im; - - // sinh() ... - - // _1: z.exp() ... - scalar = Math.exp(re); - _re1 = scalar * Math.cos(im); - _im1 = scalar * Math.sin(im); - - // _2: z.neg().exp() ... - scalar = Math.exp(-re); - _re2 = scalar * Math.cos(-im); - _im2 = scalar * Math.sin(-im); - - // _3: _1.sub(_2) ... - _re3 = _re1 - _re2; - _im3 = _im1 - _im2; - - // result: _3.scale(0.5) ... - result = cart(0.5 * _re3, 0.5 * _im3); - - // cosh() ... - - // _3: _1.add(_2) ... - _re3 = _re1 + _re2; - _im3 = _im1 + _im2; - - // ch: _3.scale(0.5) ... - ch_re = 0.5 * _re3; - ch_im = 0.5 * _im3; - - // result: result.div(ch) ... - div(result, ch_re, ch_im); - return result; - }// end tanh() - - /** - * Returns the principal arc sine of a Complex number. - * - *

- * - *

-     *     asin(z)  =  -i * log(i*z + sqrt(1 - z*z))
-     * 
- *

- * There are infinitely many solutions, besides the principal solution. If - * A is the principal solution of asin(z), the others are of - * the form: - *

- * - *

-     *     k*PI + (-1)k  * A
-     * 
- *

- * where k is any integer. - *

- * - * @return Principal Complex arc sine - *

- * @see Complex#sin() - * @see Complex#sinh() - **/ - - public Complex asin() { - Complex result; - // asin(z) = -i * log(i*z + sqrt(1 - z*z)) - - double _re1, _im1; - - // _1: one.sub(z.mul(z)) ... - _re1 = 1.0 - ((re * re) - (im * im)); - _im1 = 0.0 - ((re * im) + (im * re)); - - // result: _1.sqrt() ... - result = cart(_re1, _im1); - sqrt(result); - - // _1: z.mul(i) ... - _re1 = -im; - _im1 = +re; - - // result: _1.add(result) ... - result.re = _re1 + result.re; - result.im = _im1 + result.im; - - // _1: result.log() ... - _re1 = Math.log(result.abs()); - _im1 = result.arg(); - - // result: i.neg().mul(_1) ... - result.re = _im1; - result.im = -_re1; - return result; - }// end asin() - - /** - * Returns the principal arc cosine of a Complex number. - * - *

- * - *

-     *     acos(z)  =  -i * log( z + i * sqrt(1 - z*z) )
-     * 
- *

- * There are infinitely many solutions, besides the principal solution. If - * A is the principal solution of acos(z), the others are of - * the form: - *

- * - *

-     *     2*k*PI +/- A
-     * 
- *

- * where k is any integer. - *

- * - * @return Principal Complex arc cosine - *

- * @see Complex#cos() - * @see Complex#cosh() - **/ - - public Complex acos() { - Complex result; - // acos(z) = -i * log( z + i * sqrt(1 - z*z) ) - - double _re1, _im1; - - // _1: one.sub(z.mul(z)) ... - _re1 = 1.0 - ((re * re) - (im * im)); - _im1 = 0.0 - ((re * im) + (im * re)); - - // result: _1.sqrt() ... - result = cart(_re1, _im1); - sqrt(result); - - // _1: i.mul(result) ... - _re1 = -result.im; - _im1 = +result.re; - - // result: z.add(_1) ... - result.re = re + _re1; - result.im = im + _im1; - - // _1: result.log() - _re1 = Math.log(result.abs()); - _im1 = result.arg(); - - // result: i.neg().mul(_1) ... - result.re = _im1; - result.im = -_re1; - return result; - }// end acos() - - /** - * Returns the principal arc tangent of a Complex number. - * - *

- * - *

-     *     atan(z)  =  -i/2 * log( (i-z)/(i+z) )
-     * 
- *

- * There are infinitely many solutions, besides the principal solution. If - * A is the principal solution of atan(z), the others are of - * the form: - *

- * - *

-     *     A + k*PI
-     * 
- *

- * where k is any integer. - *

- * Domain Restrictions: - *

- * - *

- * - * @return Principal Complex arc tangent - *

- * @see Complex#tan() - * @see Complex#tanh() - **/ - - public Complex atan() { - Complex result; - // atan(z) = -i/2 * log( (i-z)/(i+z) ) - - double _re1, _im1; - - // result: i.sub(z) ... - result = cart(-re, 1.0 - im); - - // _1: i.add(z) ... - _re1 = +re; - _im1 = 1.0 + im; - - // result: result.div(_1) ... - div(result, _re1, _im1); - - // _1: result.log() ... - _re1 = Math.log(result.abs()); - _im1 = result.arg(); - - // result: half_i.neg().mul(_2) ... - result.re = 0.5 * _im1; - result.im = -0.5 * _re1; - return result; - }// end atan() - - /** - * Returns the principal inverse hyperbolic sine of a - * Complex number. - * - *

- * - *

-     * asinh(z) = log(z + sqrt(z * z + 1))
-     * 
- *

- * There are infinitely many solutions, besides the principal solution. If - * A is the principal solution of asinh(z), the others are of - * the form: - *

- * - *

-     *     k*PI*i + (-1)k  * A
-     * 
- *

- * where k is any integer. - *

- * - * @return Principal Complex inverse hyperbolic sine - *

- * @see Complex#sinh() - **/ - - public Complex asinh() { - Complex result; - // asinh(z) = log(z + sqrt(z*z + 1)) - - double _re1, _im1; - - // _1: z.mul(z).add(one) ... - _re1 = ((re * re) - (im * im)) + 1.0; - _im1 = ((re * im) + (im * re)) + 0.0; - - // result: _1.sqrt() ... - result = cart(_re1, _im1); - sqrt(result); - - // result: z.add(result) ... - result.re = re + result.re; // ! - result.im = im + result.im; // ! - - // _1: result.log() ... - _re1 = Math.log(result.abs()); - _im1 = result.arg(); - - // result: _1 ... - result.re = _re1; - result.im = _im1; - - /* - * Many thanks to the mathematicians of aus.mathematics and sci.math, - * and to Zdislav V. Kovarik of the Department of Mathematics and - * Statistics, McMaster University and John McGowan - * in particular, for their advice on the current naming conventions for - * "area/argumentus sinus hyperbolicus". - */ - - return result; - }// end asinh() - - /** - * Returns the principal inverse hyperbolic cosine of a - * Complex number. - * - *

- * - *

-     * acosh(z) = log(z + sqrt(z * z - 1))
-     * 
- *

- * There are infinitely many solutions, besides the principal solution. If - * A is the principal solution of acosh(z), the others are of - * the form: - *

- * - *

-     *     2*k*PI*i +/- A
-     * 
- *

- * where k is any integer. - *

- * - * @return Principal Complex inverse hyperbolic cosine - *

- * @see Complex#cosh() - **/ - - public Complex acosh() { - Complex result; - // acosh(z) = log(z + sqrt(z*z - 1)) - - double _re1, _im1; - - // _1: z.mul(z).sub(one) ... - _re1 = ((re * re) - (im * im)) - 1.0; - _im1 = ((re * im) + (im * re)) - 0.0; - - // result: _1.sqrt() ... - result = cart(_re1, _im1); - sqrt(result); - - // result: z.add(result) ... - result.re = re + result.re; // ! - result.im = im + result.im; // ! - - // _1: result.log() ... - _re1 = Math.log(result.abs()); - _im1 = result.arg(); - - // result: _1 ... - result.re = _re1; - result.im = _im1; - return result; - }// end acosh() - - /** - * Returns the principal inverse hyperbolic tangent of a - * Complex number. - * - *

- * - *

-     * atanh(z) = 1 / 2 * log((1 + z) / (1 - z))
-     * 
- *

- * There are infinitely many solutions, besides the principal solution. If - * A is the principal solution of atanh(z), the others are of - * the form: - *

- * - *

-     *     A + k*PI*i
-     * 
- *

- * where k is any integer. - *

- * Domain Restrictions: - *

- * - *

- * - * @return Principal Complex inverse hyperbolic tangent - *

- * @see Complex#tanh() - **/ - - public Complex atanh() { - Complex result; - // atanh(z) = 1/2 * log( (1+z)/(1-z) ) - - double _re1, _im1; - - // result: one.add(z) ... - result = cart(1.0 + re, +im); - - // _1: one.sub(z) ... - _re1 = 1.0 - re; - _im1 = -im; - - // result: result.div(_1) ... - div(result, _re1, _im1); - - // _1: result.log() ... - _re1 = Math.log(result.abs()); - _im1 = result.arg(); - - // result: _1.scale(0.5) ... - result.re = 0.5 * _re1; - result.im = 0.5 * _im1; - return result; - }// end atanh() - - /** - * Converts a Complex into a {@link java.lang.String - * String} of the form (a + b - * i). - * - *

- * This enables a Complex to be easily printed. For example, if - * z was 2 - 5i, then - * - *

-     * System.out.println("z = " + z);
-     * 
- * - * would print something like - * - *
-     *     z = (2.0 - 5.0i)
-     * 
- * - * - *

- * - * @return {@link java.lang.String String} containing the cartesian - * coordinate representation - *

- * @see Complex#cart(double, double) - **/ - - @Override - public String toString() { - StringBuffer result = new StringBuffer("("); - result.append(re); - - if (im < 0.0) { // ...remembering NaN & Infinity - result.append(" - ").append(-im); - } else if (1.0 / im == Double.NEGATIVE_INFINITY) { - result.append(" - ").append(0.0); - } else { - result.append(" + ").append(+im); - }// endif - - result.append("i)"); - return result.toString(); - }// end toString() - - /* - * I know a young man called Daniel, When you meet him, you'll like him, and - * you'll Find him so true, so human and new, You'll want to live life with - * no manual. - */ - -}// end Complex - -/* - * Jim Shapiro - * - * - * Priyantha Jayanetti --------------------------- email: pidge@eece.maine.edu - * - * Dept. of Electrical & Computer Engineering University of Maine, Orono - * - * - * Mr. Daniel Hirsch - * - * - * /* C A U T I O N E X P L O S I V E B O L T S -- REMOVE BEFORE ENGAGING REPLY - * // // Kelly and Sandy Anderson - * // (alternatively kelsan_odoodle at ya who period, see oh em) // Alexander - * (Sandy) 1B5A DF3D A3D9 B932 39EB 3F1B 981F 4110 27E1 64A4 // Kelly 673F 6751 - * 6DBA 196F E8A8 6D87 4AEC F35E E9AD 099B // Homepages - * http://www.explosive-alma-services-bolts.co.uk/ - */ \ No newline at end of file diff --git a/common-tools/cnuphys/numRec/src/com/nr/NRUtil.java b/common-tools/cnuphys/numRec/src/com/nr/NRUtil.java deleted file mode 100644 index 3a96b10ff7..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/NRUtil.java +++ /dev/null @@ -1,240 +0,0 @@ -package com.nr; - -import org.netlib.util.intW; - -public class NRUtil { - private NRUtil() { - } - - public final static float FLT_EPSILON = 1.19209290E-07F; - - public final static double DBL_EPSILON = 2.2204460492503131E-16; - - public final static int FLT_RADIX = 2; - - public final static int DBL_MANT_DIG = 53; - - public final static int INT_DIGITS = 32; - - public static double SQR(final double a) { - return a * a; - } - - public static float SQR(final float a) { - return a * a; - } - - public static int SQR(final int a) { - return a * a; - } - - public static double SIGN(final double a, final double b) { - return b >= 0 ? (a >= 0 ? a : -a) : (a >= 0 ? -a : a); - } - - public static int SIGN(final int a, final int b) { - return b >= 0 ? (a >= 0 ? a : -a) : (a >= 0 ? -a : a); - } - - public static float SIGN(final float a, final double b) { - return b >= 0 ? (a >= 0 ? a : -a) : (a >= 0 ? -a : a); - } - - public static float SIGN(final double a, final float b) { - return (float) (b >= 0 ? (a >= 0 ? a : -a) : (a >= 0 ? -a : a)); - } - - /** - * Swaps x[a] with x[b]. - */ - public static void swap(double x[], int a, int b) { - double t = x[a]; - x[a] = x[b]; - x[b] = t; - } - - public static void swap(int x[], int a, int b) { - int t = x[a]; - x[a] = x[b]; - x[b] = t; - } - - public static void swap(char x[], int a, int b) { - char t = x[a]; - x[a] = x[b]; - x[b] = t; - } - - public static void swap(Object x[], int a, int b) { - Object t = x[a]; - x[a] = x[b]; - x[b] = t; - } - - public static double[] buildVector(final int n, final double a) { - double[] v = new double[n]; - for (int i = 0; i < v.length; i++) - v[i] = a; - return v; - } - - public static int[] buildVector(final int n, final int a) { - int[] v = new int[n]; - for (int i = 0; i < v.length; i++) - v[i] = a; - return v; - } - - public static double[] buildVector(final double[] b) { - double[] v = new double[b.length]; - for (int i = 0; i < v.length; i++) - v[i] = b[i]; - return v; - } - - public static int[] buildVector(final int[] b) { - int[] v = new int[b.length]; - for (int i = 0; i < v.length; i++) - v[i] = b[i]; - return v; - } - - /** - * XXX should be use in the members of the class only. - * - * @param v - * @param newn - * @return - */ - public static double[] resize(double[] v, final int newn) { - int nn = v.length; - if (newn != nn) { - nn = newn; - v = nn > 0 ? new double[nn] : null; - } - return v; - } - - public static void copyAssign(final double[] v, final double[] rhs) { - // postcondition: normal assignment via copying has been performed; - // if vector and rhs were different sizes, vector - // has been resized to match the size of rhs - int nn = v.length; - int rnn = rhs.length; - - if (v != rhs) { - if (nn != rnn) { - // nn=rnn; - // v = new double[nn]; - throw new IllegalArgumentException("Must be same size."); - } - System.arraycopy(rhs, 0, v, 0, nn); - } - return; - } - - public static double[][] buildMatrix(final int nn, final int mm, - final double a) { - double[][] v = new double[nn][mm]; - for (int i = 0; i < nn; i++) - for (int j = 0; j < mm; j++) - v[i][j] = a; - return v; - } - - public static double[][] buildMatrix(final int nn, final int mm, - final double[] b) { - double[][] v = new double[nn][mm]; - for (int i = 0; i < nn; i++) - for (int j = 0; j < mm; j++) - v[i][j] = b[i * mm + j]; - return v; - } - - public static int[][] buildMatrix(final int nn, final int mm, final int[] b) { - int[][] v = new int[nn][mm]; - for (int i = 0; i < nn; i++) - for (int j = 0; j < mm; j++) - v[i][j] = b[i * mm + j]; - return v; - } - - public static double[][] buildMatrix(final double[][] b) { - int nn = b.length; - int mm = b[0].length; - double[][] v = new double[nn][mm]; - for (int i = 0; i < nn; i++) - for (int j = 0; j < mm; j++) - v[i][j] = b[i][j]; - return v; - } - - public static void copyAssign(final double[][] v, final double[][] rhs) { - // postcondition: normal assignment via copying has been performed; - // if matrix and rhs were different sizes, matrix - // has been resized to match the size of rhs - int nn = v.length; - int mm = v[0].length; - int rnn = rhs.length; - int rmm = rhs[0].length; - if (v != rhs) { - if (nn != rnn || mm != rmm) { - throw new IllegalArgumentException("Must be same size."); - // nn=rnn; - // mm=rmm; - // v = new double[nn][mm]; - } - for (int i = 0; i < nn; i++) - for (int j = 0; j < mm; j++) - v[i][j] = rhs[i][j]; - } - return; - } - - public static double[] getRow(final double[][] v, final int nn) { - return v[nn]; - } - - public static double ldexp(final double v, final int w) { - return v * Math.pow(2.0, w); - } - - public static double frexp(final double v, final intW exp) { - if (v == 0) { - exp.val = 0; - return 0; - } - long bits = Double.doubleToLongBits(v); - double d = Double - .longBitsToDouble((0x800fffffffffffffL & bits) | 0x3fe0000000000000L); - exp.val = (int) ((0x7ff0000000000000L & bits) >> 52) - 1022; - return d; - } - - public static String toString(double[] v) { - StringBuilder sb = new StringBuilder(256); - int nn = v.length; - int nb = 10; - for (int i = 0; i < nn; i++) { - sb.append(String.format("%g", v[i])); - if (i != 0 && (i % nb) == 0) - sb.append("\n"); - else - sb.append(" "); - } - - return sb.substring(0); - } - - public static String toString(double[][] v) { - StringBuilder sb = new StringBuilder(256); - int nn = v.length; - for (int i = 0; i < nn; i++) { - for (int j = 0; j < v[i].length; j++) - sb.append(String.format(" %g", v[i][j])); - sb.append("\n"); - } - return sb.substring(0); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/RealMultiValueFun.java b/common-tools/cnuphys/numRec/src/com/nr/RealMultiValueFun.java deleted file mode 100644 index c7d2ecab24..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/RealMultiValueFun.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.nr; - -public interface RealMultiValueFun { - - public double[] funk(double[] x); - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/RealValueFun.java b/common-tools/cnuphys/numRec/src/com/nr/RealValueFun.java deleted file mode 100644 index b2d85c8a8e..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/RealValueFun.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.nr; - -public interface RealValueFun { - - public double funk(double[] x); - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/RealValueFunWithDiff.java b/common-tools/cnuphys/numRec/src/com/nr/RealValueFunWithDiff.java deleted file mode 100644 index 7d62568aed..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/RealValueFunWithDiff.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.nr; - -public interface RealValueFunWithDiff extends RealValueFun { - - public void df(double[] x, double[] df); -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/UniValRealValueFunWithDiff.java b/common-tools/cnuphys/numRec/src/com/nr/UniValRealValueFunWithDiff.java deleted file mode 100644 index 70678ff594..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/UniValRealValueFunWithDiff.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.nr; - -public interface UniValRealValueFunWithDiff extends UniVarRealValueFun { - - public double df(double x); - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/UniVarRealMultiValueFun.java b/common-tools/cnuphys/numRec/src/com/nr/UniVarRealMultiValueFun.java deleted file mode 100644 index 1f92e7f271..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/UniVarRealMultiValueFun.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.nr; - -public interface UniVarRealMultiValueFun { - - public double[] funk(double x); - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/UniVarRealValueFun.java b/common-tools/cnuphys/numRec/src/com/nr/UniVarRealValueFun.java deleted file mode 100644 index 4c39956e2e..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/UniVarRealValueFun.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.nr; - -public interface UniVarRealValueFun { - - public double funk(double x); - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/bvp/Difeq.java b/common-tools/cnuphys/numRec/src/com/nr/bvp/Difeq.java deleted file mode 100644 index 36ce1afa6e..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/bvp/Difeq.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.nr.bvp; - -public class Difeq { - final int mm, n, mpt; - final double h, c2, anorm; - final double[] x; - - public Difeq(final int mmm, final int nn, final int mptt, final double hh, - final double cc2, final double anormm, final double[] xx) { - mm = mmm; - n = nn; - mpt = mptt; - h = hh; - c2 = cc2; - this.anorm = anormm; - x = xx; - } - - public void smatrix(final int k, final int k1, final int k2, final int jsf, - final int is1, final int isf, final int[] indexv, - final double[][] s, final double[][] y) { - double temp, temp1, temp2; - - if (k == k1) { - if ((n + mm & 1) != 0) { - s[2][3 + indexv[0]] = 1.0; - s[2][3 + indexv[1]] = 0.0; - s[2][3 + indexv[2]] = 0.0; - s[2][jsf] = y[0][0]; - } else { - s[2][3 + indexv[0]] = 0.0; - s[2][3 + indexv[1]] = 1.0; - s[2][3 + indexv[2]] = 0.0; - s[2][jsf] = y[1][0]; - } - } else if (k > k2 - 1) { - s[0][3 + indexv[0]] = -(y[2][mpt - 1] - c2) / (2.0 * (mm + 1.0)); - s[0][3 + indexv[1]] = 1.0; - s[0][3 + indexv[2]] = -y[0][mpt - 1] / (2.0 * (mm + 1.0)); - s[0][jsf] = y[1][mpt - 1] - (y[2][mpt - 1] - c2) * y[0][mpt - 1] - / (2.0 * (mm + 1.0)); - s[1][3 + indexv[0]] = 1.0; - s[1][3 + indexv[1]] = 0.0; - s[1][3 + indexv[2]] = 0.0; - s[1][jsf] = y[0][mpt - 1] - anorm; - } else { - s[0][indexv[0]] = -1.0; - s[0][indexv[1]] = -0.5 * h; - s[0][indexv[2]] = 0.0; - s[0][3 + indexv[0]] = 1.0; - s[0][3 + indexv[1]] = -0.5 * h; - s[0][3 + indexv[2]] = 0.0; - temp1 = x[k] + x[k - 1]; - temp = h / (1.0 - temp1 * temp1 * 0.25); - temp2 = 0.5 * (y[2][k] + y[2][k - 1]) - c2 * 0.25 * temp1 * temp1; - s[1][indexv[0]] = temp * temp2 * 0.5; - s[1][indexv[1]] = -1.0 - 0.5 * temp * (mm + 1.0) * temp1; - s[1][indexv[2]] = 0.25 * temp * (y[0][k] + y[0][k - 1]); - s[1][3 + indexv[0]] = s[1][indexv[0]]; - s[1][3 + indexv[1]] = 2.0 + s[1][indexv[1]]; - s[1][3 + indexv[2]] = s[1][indexv[2]]; - s[2][indexv[0]] = 0.0; - s[2][indexv[1]] = 0.0; - s[2][indexv[2]] = -1.0; - s[2][3 + indexv[0]] = 0.0; - s[2][3 + indexv[1]] = 0.0; - s[2][3 + indexv[2]] = 1.0; - s[0][jsf] = y[0][k] - y[0][k - 1] - 0.5 * h - * (y[1][k] + y[1][k - 1]); - s[1][jsf] = y[1][k] - - y[1][k - 1] - - temp - * ((x[k] + x[k - 1]) * 0.5 * (mm + 1.0) - * (y[1][k] + y[1][k - 1]) - temp2 * 0.5 - * (y[0][k] + y[0][k - 1])); - s[2][jsf] = y[2][k] - y[2][k - 1]; - } - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/bvp/Shoot.java b/common-tools/cnuphys/numRec/src/com/nr/bvp/Shoot.java deleted file mode 100644 index 14877fdcad..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/bvp/Shoot.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.nr.bvp; - -import com.nr.RealMultiValueFun; -import com.nr.ode.DerivativeInf; -import com.nr.ode.Odeint; -import com.nr.ode.Output; -import com.nr.ode.StepperDopr853; - -public abstract class Shoot implements RealMultiValueFun { - int nvar; - double x1, x2; - double atol, rtol; - double h1, hmin; - double[] y; - DerivativeInf d; - - public Shoot(final int nvarr, final double xx1, final double xx2, - final DerivativeInf derivss) { - nvar = nvarr; - x1 = xx1; - x2 = xx2; - d = derivss; - atol = 1.0e-14; - rtol = atol; - hmin = 0.0; - y = new double[nvar]; - } - - @Override - public double[] funk(final double[] v) { - h1 = (x2 - x1) / 100.0; - y = load(x1, v); - Output out = new Output(); - StepperDopr853 s = new StepperDopr853(); - Odeint integ = new Odeint(y, x1, x2, atol, rtol, h1, hmin, out, d, s); - integ.integrate(); - return score(x2, y); - } - - public abstract double[] load(final double x, final double[] v); - - public abstract double[] score(final double x, final double[] v); -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/bvp/Shootf.java b/common-tools/cnuphys/numRec/src/com/nr/bvp/Shootf.java deleted file mode 100644 index 779d9bdc69..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/bvp/Shootf.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.nr.bvp; - -import static com.nr.NRUtil.*; -import com.nr.RealMultiValueFun; -import com.nr.ode.DerivativeInf; -import com.nr.ode.Odeint; -import com.nr.ode.Output; -import com.nr.ode.StepperDopr853; - -public abstract class Shootf implements RealMultiValueFun { - int nvar, n2; - double x1, x2, xf; - double atol, rtol; - double h1, hmin; - double[] y, f1, f2; - DerivativeInf d; - - public Shootf(final int nvarr, final int nn2, final double xx1, - final double xx2, final double xxf, final DerivativeInf dd) { - nvar = nvarr; - n2 = nn2; - x1 = xx1; - x2 = xx2; - xf = xxf; - d = dd; - atol = 1.0e-14; - rtol = atol; - hmin = 0.0; - y = new double[nvar]; - f1 = new double[nvar]; - f2 = new double[nvar]; - } - - @Override - public double[] funk(final double[] v) { - double[] v2 = new double[nvar - n2]; - for (int i = 0; i < v2.length; i++) - v2[i] = v[n2 + i]; - h1 = (x2 - x1) / 100.0; - y = buildVector(load1(x1, v)); - Output out = new Output(); - StepperDopr853 s1 = new StepperDopr853(); - Odeint integ1 = new Odeint(y, x1, xf, atol, rtol, h1, hmin, out, d, s1); - integ1.integrate(); - f1 = buildVector(score(xf, y)); - y = buildVector(load2(x2, v2)); - - StepperDopr853 s2 = new StepperDopr853(); - Odeint integ2 = new Odeint(y, x2, xf, atol, rtol, h1, hmin, out, d, s2); - integ2.integrate(); - f2 = buildVector(score(xf, y)); - for (int i = 0; i < nvar; i++) - f1[i] -= f2[i]; - return f1; - } - - public abstract double[] load1(final double x, final double[] v); - - public abstract double[] load2(final double x, final double[] v); - - public abstract double[] score(final double x, final double[] v); -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/bvp/Solvde.java b/common-tools/cnuphys/numRec/src/com/nr/bvp/Solvde.java deleted file mode 100644 index eaadd59cd2..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/bvp/Solvde.java +++ /dev/null @@ -1,199 +0,0 @@ -package com.nr.bvp; - -import static java.lang.Math.*; - -public class Solvde { - final int itmax; - final double conv; - final double slowc; - final double[] scalv; - final int[] indexv; - final int nb; - double[][] y; - Difeq difeq; - int ne, m; - int[] kmax; - double[] ermax; - double[][][] c; - double[][] s; - - public Solvde(final int itmaxx, final double convv, final double slowcc, - final double[] scalvv, final int[] indexvv, final int nbb, - final double[][] yy, final Difeq difeqq) { - itmax = itmaxx; - conv = convv; - slowc = slowcc; - scalv = scalvv; - indexv = indexvv; - nb = nbb; - y = yy; - difeq = difeqq; - ne = y.length; - m = y[0].length; - kmax = new int[ne]; - ermax = new double[ne]; - c = new double[ne][ne - nb + 1][m + 1]; - s = new double[ne][2 * ne + 1]; - - int jv, k, nvars = ne * m; - int k1 = 0, k2 = m; - int j1 = 0, j2 = nb, j3 = nb, j4 = ne, j5 = j4 + j1, j6 = j4 + j2, j7 = j4 - + j3, j8 = j4 + j4, j9 = j8 + j1; - int ic1 = 0, ic2 = ne - nb, ic3 = ic2, ic4 = ne, jc1 = 0, jcf = ic3; - for (int it = 0; it < itmax; it++) { - k = k1; - difeq.smatrix(k, k1, k2, j9, ic3, ic4, indexv, s, y); - pinvs(ic3, ic4, j5, j9, jc1, k1); - for (k = k1 + 1; k < k2; k++) { - int kp = k; - difeq.smatrix(k, k1, k2, j9, ic1, ic4, indexv, s, y); - red(ic1, ic4, j1, j2, j3, j4, j9, ic3, jc1, jcf, kp); - pinvs(ic1, ic4, j3, j9, jc1, k); - } - k = k2; - difeq.smatrix(k, k1, k2, j9, ic1, ic2, indexv, s, y); - red(ic1, ic2, j5, j6, j7, j8, j9, ic3, jc1, jcf, k2); - pinvs(ic1, ic2, j7, j9, jcf, k2); - bksub(ne, nb, jcf, k1, k2); - double err = 0.0; - for (int j = 0; j < ne; j++) { - jv = indexv[j]; - double errj = 0.0, vmax = 0.0; - int km = 0; - for (k = k1; k < k2; k++) { - double vz = abs(c[jv][0][k]); - if (vz > vmax) { - vmax = vz; - km = k + 1; - } - errj += vz; - } - err += errj / scalv[j]; - ermax[j] = c[jv][0][km - 1] / scalv[j]; - kmax[j] = km; - } - err /= nvars; - double fac = (err > slowc ? slowc / err : 1.0); - for (int j = 0; j < ne; j++) { - jv = indexv[j]; - for (k = k1; k < k2; k++) - y[j][k] -= fac * c[jv][0][k]; - } - /* - * cout << setw(8) << "Iter."; cout << setw(10) << "Error" << - * setw(10) << "FAC" << endl; cout << setw(6) << it; cout << fixed - * << setprecision(6) << setw(13) << err; cout << setw(12) << fac << - * endl; - */ - if (err < conv) - return; - } - throw new IllegalArgumentException("Too many iterations in solvde"); - } - - public void pinvs(final int ie1, final int ie2, final int je1, - final int jsf, final int jc1, final int k) { - int jpiv = 0, jp = 0, je2, jcoff, j, irow, ipiv = 0, id, icoff, i; - double pivinv, piv, big; - final int iesize = ie2 - ie1; - int[] indxr = new int[iesize]; - double[] pscl = new double[iesize]; - je2 = je1 + iesize; - for (i = ie1; i < ie2; i++) { - big = 0.0; - for (j = je1; j < je2; j++) - if (abs(s[i][j]) > big) - big = abs(s[i][j]); - if (big == 0.0) - throw new IllegalArgumentException( - "Singular matrix - row all 0, in pinvs"); - pscl[i - ie1] = 1.0 / big; - indxr[i - ie1] = 0; - } - for (id = 0; id < iesize; id++) { - piv = 0.0; - for (i = ie1; i < ie2; i++) { - if (indxr[i - ie1] == 0) { - big = 0.0; - for (j = je1; j < je2; j++) { - if (abs(s[i][j]) > big) { - jp = j; - big = abs(s[i][j]); - } - } - if (big * pscl[i - ie1] > piv) { - ipiv = i; - jpiv = jp; - piv = big * pscl[i - ie1]; - } - } - } - if (s[ipiv][jpiv] == 0.0) - throw new IllegalArgumentException( - "Singular matrix in routine pinvs"); - indxr[ipiv - ie1] = jpiv + 1; - pivinv = 1.0 / s[ipiv][jpiv]; - for (j = je1; j <= jsf; j++) - s[ipiv][j] *= pivinv; - s[ipiv][jpiv] = 1.0; - for (i = ie1; i < ie2; i++) { - if (indxr[i - ie1] != jpiv + 1) { - if (s[i][jpiv] != 0.0) { - double dum = s[i][jpiv]; - for (j = je1; j <= jsf; j++) - s[i][j] -= dum * s[ipiv][j]; - s[i][jpiv] = 0.0; - } - } - } - } - jcoff = jc1 - je2; - icoff = ie1 - je1; - for (i = ie1; i < ie2; i++) { - irow = indxr[i - ie1] + icoff; - for (j = je2; j <= jsf; j++) - c[irow - 1][j + jcoff][k] = s[i][j]; - } - } - - public void bksub(final int ne, final int nb, final int jf, final int k1, - final int k2) { - int nbf = ne - nb, im = 1; - for (int k = k2 - 1; k >= k1; k--) { - if (k == k1) - im = nbf + 1; - int kp = k + 1; - for (int j = 0; j < nbf; j++) { - double xx = c[j][jf][kp]; - for (int i = im - 1; i < ne; i++) - c[i][jf][k] -= c[i][j][k] * xx; - } - } - for (int k = k1; k < k2; k++) { - int kp = k + 1; - for (int i = 0; i < nb; i++) - c[i][0][k] = c[i + nbf][jf][k]; - for (int i = 0; i < nbf; i++) - c[i + nb][0][k] = c[i][jf][kp]; - } - } - - public void red(final int iz1, final int iz2, final int jz1, final int jz2, - final int jm1, final int jm2, final int jmf, final int ic1, - final int jc1, final int jcf, final int kc) { - int l, j, i; - double vx; - int loff = jc1 - jm1, ic = ic1; - for (j = jz1; j < jz2; j++) { - for (l = jm1; l < jm2; l++) { - vx = c[ic][l + loff][kc - 1]; - for (i = iz1; i < iz2; i++) - s[i][l] -= s[i][j] * vx; - } - vx = c[ic][jcf][kc - 1]; - for (i = iz1; i < iz2; i++) - s[i][jmf] -= s[i][j] * vx; - ic += 1; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/cg/Box.java b/common-tools/cnuphys/numRec/src/com/nr/cg/Box.java deleted file mode 100644 index 0f2dca8333..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/cg/Box.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.nr.cg; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -public class Box { - public Point lo, hi; - - public Box(int dim) { - lo = new Point(dim); - hi = new Point(dim); - } - - public Box(final Point mylo, final Point myhi) { - if (mylo.dim() != myhi.dim()) - throw new IllegalArgumentException("need same dim!"); - lo = new Point(mylo); - hi = new Point(myhi); - } - - public Box(final Box p) { - lo = new Point(p.lo); - hi = new Point(p.hi); - } - - public Box copyAssign(final Box p) { - lo = lo.copyAssign(p.lo); - hi = hi.copyAssign(p.hi); - return this; - } - - @Override - public Box clone() { - return new Box(lo.clone(), hi.clone()); - } - - public static double dist(final Box b, final Point p) { - if (b.lo.dim() != p.dim()) - throw new IllegalArgumentException("need same dim!"); - - int DIM = p.dim(); - - double dd = 0; - for (int i = 0; i < DIM; i++) { - if (p.x[i] < b.lo.x[i]) - dd += SQR(p.x[i] - b.lo.x[i]); - if (p.x[i] > b.hi.x[i]) - dd += SQR(p.x[i] - b.hi.x[i]); - } - return sqrt(dd); - } - - public int dim() { - return lo.dim(); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/cg/Boxnode.java b/common-tools/cnuphys/numRec/src/com/nr/cg/Boxnode.java deleted file mode 100644 index 5df146593b..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/cg/Boxnode.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.nr.cg; - -public class Boxnode extends Box { - public int mom, dau1, dau2, ptlo, pthi; - - public Boxnode(int dim) { - super(dim); - } - - public Boxnode(final Point lo, final Point hi, final int mom, - final int dau1, final int dau2, final int ptlo, final int pthi) { - super(lo, hi); - this.mom = mom; - this.dau1 = dau1; - this.dau2 = dau2; - this.ptlo = ptlo; - this.pthi = pthi; - } - - @Override - public Boxnode clone() { - return new Boxnode(this.lo.clone(), this.hi.clone(), mom, dau1, dau2, - ptlo, pthi); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/cg/Circle.java b/common-tools/cnuphys/numRec/src/com/nr/cg/Circle.java deleted file mode 100644 index fc29c3befa..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/cg/Circle.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.nr.cg; - -import static java.lang.Math.*; - -/** - * circumcircle of three points - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Circle { - public final static int DIM = 2; - public Point center; - public double radius; - - public Circle(final Point cen, final double rad) { - if (cen.dim() != DIM) - new IllegalArgumentException("Need same dim!"); - center = new Point(cen); - radius = rad; - } - - @Override - public Circle clone() { - return new Circle(center.clone(), radius); - } - - public int dim() { - return DIM; - } - - public static Circle circumcircle(final Point a, final Point b, - final Point c) { - if (a.dim() != DIM || b.dim() != DIM || c.dim() != DIM) - throw new IllegalArgumentException("Need same dim!"); - double a0, a1, c0, c1, det, asq, csq, ctr0, ctr1, rad2; - a0 = a.x[0] - b.x[0]; - a1 = a.x[1] - b.x[1]; - c0 = c.x[0] - b.x[0]; - c1 = c.x[1] - b.x[1]; - det = a0 * c1 - c0 * a1; - if (det == 0.0) - throw new IllegalArgumentException("no circle thru colinear points"); - det = 0.5 / det; - asq = a0 * a0 + a1 * a1; - csq = c0 * c0 + c1 * c1; - ctr0 = det * (asq * c1 - csq * a1); - ctr1 = det * (csq * a0 - asq * c0); - rad2 = ctr0 * ctr0 + ctr1 * ctr1; - return new Circle(new Point(DIM, new double[] { ctr0 + b.x[0], - ctr1 + b.x[1] }), sqrt(rad2)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/cg/Convexhull.java b/common-tools/cnuphys/numRec/src/com/nr/cg/Convexhull.java deleted file mode 100644 index 8465c5f4c6..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/cg/Convexhull.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.nr.cg; - -/** - * Structure for constructing the convex hull of a set of points in the plane. - * After construction, nhull is the number of points in the hull, and - * hullpoints[0..nhull-1] are integers pointing to points in the vector pvec - * that are in the hull, in CCW order. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Convexhull extends Delaunay { - public int nhull; - public int[] hullpts; - - public Convexhull(final Point[] pvec) { - super(pvec, 2); - nhull = 0; - int i, j, k, pstart = 0; - int[] nextpt = new int[npts]; - for (j = 0; j < ntree; j++) { - if (thelist[j].stat != -1) - continue; - for (i = 0, k = 1; i < 3; i++, k++) { - if (k == 3) - k = 0; - if (thelist[j].p[i] < npts && thelist[j].p[k] < npts) - break; - } - if (i == 3) - continue; - ++nhull; - nextpt[(pstart = thelist[j].p[k])] = thelist[j].p[i]; - } - if (nhull == 0) - throw new IllegalArgumentException("no hull segments found"); - hullpts = new int[nhull]; - j = 0; - i = hullpts[j++] = pstart; - while ((i = nextpt[i]) != pstart) - hullpts[j++] = i; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/cg/Delaunay.java b/common-tools/cnuphys/numRec/src/com/nr/cg/Delaunay.java deleted file mode 100644 index 5104939620..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/cg/Delaunay.java +++ /dev/null @@ -1,316 +0,0 @@ -package com.nr.cg; - -import static com.nr.cg.Triel.*; -import com.nr.ran.Hash; -import com.nr.ran.Ranhash; - -import static com.nr.NRUtil.*; - -/** - * Delaunay triangulation Copyright (C) Numerical Recipes Software 1986-2007 - * Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Delaunay { - static final int DIM = 2; - private static final double fuzz = 1.0e-6, bigscale = 1000.0; - - /** - * Random number counter - */ - private static int jran = 14921620; - public int npts, ntri, ntree, ntreemax, opt; - public double delx, dely; - public Point[] pts; - public Triel[] thelist; - - /** - * Create the hash memories with null hash function. - */ - public Hash1 linehash; - public Hash1 trihash; - public int[] perm; - - /** - * The raw hash function - */ - public Ranhash hashfn = new Ranhash(); - - public class Hash1 extends Hash { - public Hash1(final int nh, final int nm) { - super(nh, nm); - } - - @Override - public long fn(final Long k) { - return k & 0x7FFFFFFFFFFFFFFFL; - } - } - - public int dim() { - return DIM; - } - - public Delaunay(final Point[] pvec) { - this(pvec, 0); - } - - /** - * Construct Delaunay triangulation from a vector of points pvec. If bit 0 - * in options is nonzero, hash memories used in the construction are - * deleted. (Some applications may want to use them and will set options to - * 1.) - * - * @param pvec - * @param options - */ - public Delaunay(final Point[] pvec, final int options) { - for (int i = 0; i < pvec.length; i++) - if (pvec[i].dim() != DIM) - throw new IllegalArgumentException("Need same dim!"); - - npts = pvec.length; - ntri = 0; - ntree = 0; - ntreemax = 10 * npts + 1000; - opt = options; - pts = new Point[npts + 3]; - thelist = new Triel[ntreemax]; - for (int i = 0; i < ntreemax; i++) - thelist[i] = new Triel(); - - int j; - double xl, xh, yl, yh; - linehash = new Hash1(6 * npts + 12, 6 * npts + 12); - trihash = new Hash1(2 * npts + 6, 2 * npts + 6); - perm = new int[npts]; - xl = xh = pvec[0].x[0]; - yl = yh = pvec[0].x[1]; - for (j = 0; j < npts; j++) { - pts[j] = pvec[j]; - perm[j] = j; - if (pvec[j].x[0] < xl) - xl = pvec[j].x[0]; - if (pvec[j].x[0] > xh) - xh = pvec[j].x[0]; - if (pvec[j].x[1] < yl) - yl = pvec[j].x[1]; - if (pvec[j].x[1] > yh) - yh = pvec[j].x[1]; - } - delx = xh - xl; - dely = yh - yl; - pts[npts] = new Point(0.5 * (xl + xh), yh + bigscale * dely); - pts[npts + 1] = new Point(xl - 0.5 * bigscale * delx, yl - 0.5 - * bigscale * dely); - pts[npts + 2] = new Point(xh + 0.5 * bigscale * delx, yl - 0.5 - * bigscale * dely); - storetriangle(npts, npts + 1, npts + 2); - for (j = npts; j > 0; j--) { - // SWAP(perm[j-1],perm[hashfn.int64p(jran++) % j]); - int nnn = (int) (hashfn.int64p(jran++) % j); - swap(perm, j - 1, nnn); - } - for (j = 0; j < npts; j++) - insertapoint(perm[j]); - for (j = 0; j < ntree; j++) { - if (thelist[j].stat > 0) { - if (thelist[j].p[0] >= npts || thelist[j].p[1] >= npts - || thelist[j].p[2] >= npts) { - thelist[j].stat = -1; - ntri--; - } - } - } - /* - * if (!(opt & 1)) { delete [] perm; delete trihash; delete linehash; } - */ - } - - /** - * Add the point with index r incrementally to the Delaunay triangulation - * - * @param r - */ - public void insertapoint(final int r) { - int i, j, k, l, s, tno = 0, ntask, d0, d1, d2; - long key; - int[] tasks = new int[50], taski = new int[50], taskj = new int[50]; - for (j = 0; j < 3; j++) { - tno = whichcontainspt(pts[r], 1); - if (tno >= 0) - break; - pts[r].x[0] += fuzz * delx * (hashfn.doub(jran++) - 0.5); - pts[r].x[1] += fuzz * dely * (hashfn.doub(jran++) - 0.5); - } - if (j == 3) - throw new IllegalArgumentException( - "points degenerate even after fuzzing"); - ntask = 0; - i = thelist[tno].p[0]; - j = thelist[tno].p[1]; - k = thelist[tno].p[2]; - if ((opt & 2) != 0 && i < npts && j < npts && k < npts) - return; - d0 = storetriangle(r, i, j); - tasks[++ntask] = r; - taski[ntask] = i; - taskj[ntask] = j; - d1 = storetriangle(r, j, k); - tasks[++ntask] = r; - taski[ntask] = j; - taskj[ntask] = k; - d2 = storetriangle(r, k, i); - tasks[++ntask] = r; - taski[ntask] = k; - taskj[ntask] = i; - erasetriangle(i, j, k, d0, d1, d2); - while (ntask != 0) { - s = tasks[ntask]; - i = taski[ntask]; - j = taskj[ntask--]; - key = hashfn.int64(j) - hashfn.int64(i); - Integer[] l_w = new Integer[1]; - if (linehash.get(key, l_w, 0) == 0) - continue; - l = l_w[0]; - if (incircle(pts[l], pts[j], pts[s], pts[i]) > 0.0) { - d0 = storetriangle(s, l, j); - d1 = storetriangle(s, i, l); - erasetriangle(s, i, j, d0, d1, -1); - erasetriangle(l, j, i, d0, d1, -1); - key = hashfn.int64(i) - hashfn.int64(j); - linehash.erase(key); - key = 0 - key; - linehash.erase(key); - tasks[++ntask] = s; - taski[ntask] = l; - taskj[ntask] = j; - tasks[++ntask] = s; - taski[ntask] = i; - taskj[ntask] = l; - } - } - } - - public int whichcontainspt(final Point p) { - return whichcontainspt(p, 0); - } - - /** - * Given point p, return index in thelist of the triangle in the - * triangulation that contains it, or return 1 for failure. If strict is - * nonzero, require strict containment, otherwise allow the point to lie on - * an edge. - * - * @param p - * @param strict - * @return - */ - public int whichcontainspt(final Point p, final int strict) { - int i, j = 0, k = 0; - while (thelist[k].stat <= 0) { - for (i = 0; i < 3; i++) { - if ((j = thelist[k].d[i]) < 0) - continue; - if (strict != 0) { - if (thelist[j].contains(p) > 0) - break; - } else { - if (thelist[j].contains(p) >= 0) - break; - } - } - if (i == 3) - return -1; - k = j; - } - return k; - } - - /** - * Erase triangle abc in trihash and inactivate it in thelist after setting - * its daughters. - * - * @param a - * @param b - * @param c - * @param d0 - * @param d1 - * @param d2 - */ - public void erasetriangle(final int a, final int b, final int c, - final int d0, final int d1, final int d2) { - long key; - int j; - key = hashfn.int64(a) ^ hashfn.int64(b) ^ hashfn.int64(c); - Integer[] j_w = new Integer[1]; - if (trihash.get(key, j_w, 0) == 0) - throw new IllegalArgumentException("nonexistent triangle"); - j = j_w[0]; - trihash.erase(key); - thelist[j].d[0] = d0; - thelist[j].d[1] = d1; - thelist[j].d[2] = d2; - thelist[j].stat = 0; - ntri--; - } - - /** - * Store a triangle with vertices a, b, c in trihash. Store its points in - * linehash under keys to opposite sides. Add it to thelist, returning its - * index there. - * - * @param a - * @param b - * @param c - * @return - */ - public int storetriangle(final int a, final int b, final int c) { - long key; - thelist[ntree].setme(a, b, c, pts); - key = hashfn.int64(a) ^ hashfn.int64(b) ^ hashfn.int64(c); - trihash.set(key, ntree); - key = hashfn.int64(b) - hashfn.int64(c); - linehash.set(key, a); - key = hashfn.int64(c) - hashfn.int64(a); - linehash.set(key, b); - key = hashfn.int64(a) - hashfn.int64(b); - linehash.set(key, c); - if (++ntree == ntreemax) - throw new IllegalArgumentException("thelist is sized too small"); - ntri++; - return (ntree - 1); - } - - public double interpolate(final Point p, final double[] fnvals, - final double defaultval) { - int n, i, j, k; - double[] wgts = new double[3]; - int[] ipts = new int[3]; - double sum, ans = 0.0; - n = whichcontainspt(p); - if (n < 0) - return defaultval; - for (i = 0; i < 3; i++) - ipts[i] = thelist[n].p[i]; - for (i = 0, j = 1, k = 2; i < 3; i++, j++, k++) { - if (j == 3) - j = 0; - if (k == 3) - k = 0; - wgts[k] = (pts[ipts[j]].x[0] - pts[ipts[i]].x[0]) - * (p.x[1] - pts[ipts[i]].x[1]) - - (pts[ipts[j]].x[1] - pts[ipts[i]].x[1]) - * (p.x[0] - pts[ipts[i]].x[0]); - } - sum = wgts[0] + wgts[1] + wgts[2]; - if (sum == 0) - throw new IllegalArgumentException("degenerate triangle"); - for (i = 0; i < 3; i++) - ans += wgts[i] * fnvals[ipts[i]] / sum; - return ans; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/cg/KDtree.java b/common-tools/cnuphys/numRec/src/com/nr/cg/KDtree.java deleted file mode 100644 index a327f876ba..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/cg/KDtree.java +++ /dev/null @@ -1,338 +0,0 @@ -package com.nr.cg; - -import static com.nr.cg.Box.*; -import static com.nr.cg.Point.*; -import static com.nr.NRUtil.*; - -/** - * KD Trees and Nearest-Neighbor Finding Copyright (C) Numerical Recipes - * Software 1986-2007 Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class KDtree { - static final double BIG = 1.0e99; - final int DIM; - public int nboxes, npts; - public Point[] ptss; - public Boxnode[] boxes; - public int[] ptindx, rptindx; - - public double[] coords; - - public int dim() { - return DIM; - } - - public KDtree(final int dim, final Point[] pts) { - DIM = dim; - for (Point p : pts) - if (p.dim() != DIM) - throw new IllegalArgumentException("Need same dim!"); - ptss = pts; - npts = pts.length; - ptindx = new int[npts]; - rptindx = new int[npts]; - int ntmp, m, k, kk, j, nowtask, jbox, np, tmom, tdim, ptlo, pthi; - // int[] hp; - // double[] cp; - int[] taskmom = new int[50], taskdim = new int[50]; - for (k = 0; k < npts; k++) - ptindx[k] = k; - m = 1; - for (ntmp = npts; ntmp != 0; ntmp >>= 1) { - m <<= 1; - } - nboxes = 2 * npts - (m >> 1); - if (m < nboxes) - nboxes = m; - nboxes--; - boxes = new Boxnode[nboxes]; - coords = new double[DIM * npts]; - for (j = 0, kk = 0; j < DIM; j++, kk += npts) { - for (k = 0; k < npts; k++) - coords[kk + k] = pts[k].x[j]; - } - Point lo = new Point(DIM, new double[] { -BIG, -BIG, -BIG }); - Point hi = new Point(DIM, new double[] { BIG, BIG, BIG }); - boxes[0] = new Boxnode(lo, hi, 0, 0, 0, 0, npts - 1); - jbox = 0; - taskmom[1] = 0; - taskdim[1] = 0; - nowtask = 1; - while (nowtask != 0) { - tmom = taskmom[nowtask]; - tdim = taskdim[nowtask--]; - ptlo = boxes[tmom].ptlo; - pthi = boxes[tmom].pthi; - // hp = &ptindx[ptlo]; - // cp = &coords[tdim*npts]; - np = pthi - ptlo + 1; - kk = (np - 1) / 2; - selecti(kk, ptindx, ptlo, np, coords, tdim * npts); - - // XXX = change to copyAssign - hi.copyAssign(boxes[tmom].hi); - lo.copyAssign(boxes[tmom].lo); - - hi.x[tdim] = lo.x[tdim] = coords[tdim * npts + ptindx[ptlo + kk]]; - boxes[++jbox] = new Boxnode(boxes[tmom].lo, hi, tmom, 0, 0, ptlo, - ptlo + kk); - boxes[++jbox] = new Boxnode(lo, boxes[tmom].hi, tmom, 0, 0, ptlo - + kk + 1, pthi); - boxes[tmom].dau1 = jbox - 1; - boxes[tmom].dau2 = jbox; - if (kk > 1) { - taskmom[++nowtask] = jbox - 1; - taskdim[nowtask] = (tdim + 1) % DIM; - } - if (np - kk > 3) { - taskmom[++nowtask] = jbox; - taskdim[nowtask] = (tdim + 1) % DIM; - } - } - for (j = 0; j < npts; j++) - rptindx[ptindx[j]] = j; - } - - public double disti(final int jpt, final int kpt) { - if (jpt == kpt) - return BIG; - else - return dist(ptss[jpt], ptss[kpt]); - } - - public int locate(final Point pt) { - if (pt.dim() != DIM) - throw new IllegalArgumentException("Need same dim!"); - int nb, d1, jdim; - nb = jdim = 0; - while (boxes[nb].dau1 != 0) { - d1 = boxes[nb].dau1; - if (pt.x[jdim] <= boxes[d1].hi.x[jdim]) - nb = d1; - else - nb = boxes[nb].dau2; - jdim = ++jdim % DIM; - } - return nb; - } - - public int locate(final int jpt) { - int nb, d1, jh; - jh = rptindx[jpt]; - nb = 0; - while (boxes[nb].dau1 != 0) { - d1 = boxes[nb].dau1; - if (jh <= boxes[d1].pthi) - nb = d1; - else - nb = boxes[nb].dau2; - } - return nb; - } - - public int nearest(final Point pt) { - if (pt.dim() != DIM) - throw new IllegalArgumentException("Need same dim!"); - int i, k, nrst = 0, ntask; - int[] task = new int[50]; - double dnrst = BIG, d; - k = locate(pt); - for (i = boxes[k].ptlo; i <= boxes[k].pthi; i++) { - d = dist(ptss[ptindx[i]], pt); - if (d < dnrst) { - nrst = ptindx[i]; - dnrst = d; - } - } - task[1] = 0; - ntask = 1; - while (ntask != 0) { - k = task[ntask--]; - if (dist(boxes[k], pt) < dnrst) { - if (boxes[k].dau1 != 0) { - task[++ntask] = boxes[k].dau1; - task[++ntask] = boxes[k].dau2; - } else { - for (i = boxes[k].ptlo; i <= boxes[k].pthi; i++) { - d = dist(ptss[ptindx[i]], pt); - if (d < dnrst) { - nrst = ptindx[i]; - dnrst = d; - } - } - } - } - } - return nrst; - } - - public void nnearest(final int jpt, final int[] nn, final double[] dn, - final int n) { - int i, k, ntask, kp; - int[] task = new int[50]; - double d; - if (n > npts - 1) - throw new IllegalArgumentException("too many neighbors requested"); - for (i = 0; i < n; i++) - dn[i] = BIG; - kp = boxes[locate(jpt)].mom; - while (boxes[kp].pthi - boxes[kp].ptlo < n) - kp = boxes[kp].mom; - for (i = boxes[kp].ptlo; i <= boxes[kp].pthi; i++) { - if (jpt == ptindx[i]) - continue; - d = disti(ptindx[i], jpt); - if (d < dn[0]) { - dn[0] = d; - nn[0] = ptindx[i]; - if (n > 1) - sift_down(dn, nn, n); - } - } - task[1] = 0; - ntask = 1; - while (ntask != 0) { - k = task[ntask--]; - if (k == kp) - continue; - if (dist(boxes[k], ptss[jpt]) < dn[0]) { - if (boxes[k].dau1 != 0) { - task[++ntask] = boxes[k].dau1; - task[++ntask] = boxes[k].dau2; - } else { - for (i = boxes[k].ptlo; i <= boxes[k].pthi; i++) { - d = disti(ptindx[i], jpt); - if (d < dn[0]) { - dn[0] = d; - nn[0] = ptindx[i]; - if (n > 1) - sift_down(dn, nn, n); - } - } - } - } - } - return; - } - - public void sift_down(final double[] heap, final int[] ndx, final int nn) { - int n = nn - 1; - int j, jold, ia; - double a; - a = heap[0]; - ia = ndx[0]; - jold = 0; - j = 1; - while (j <= n) { - if (j < n && heap[j] < heap[j + 1]) - j++; - if (a >= heap[j]) - break; - heap[jold] = heap[j]; - ndx[jold] = ndx[j]; - jold = j; - j = 2 * j + 1; - } - heap[jold] = a; - ndx[jold] = ia; - } - - public int locatenear(final Point pt, final double r, final int[] list, - final int nmax) { - if (pt.dim() != DIM) - throw new IllegalArgumentException("Need same dim!"); - int k, i, nb, nbold, nret, ntask, jdim, d1, d2; - int[] task = new int[50]; - nb = jdim = nret = 0; - if (r < 0.0) - throw new IllegalArgumentException("radius must be nonnegative"); - while (boxes[nb].dau1 != 0) { - nbold = nb; - d1 = boxes[nb].dau1; - d2 = boxes[nb].dau2; - if (pt.x[jdim] + r <= boxes[d1].hi.x[jdim]) - nb = d1; - else if (pt.x[jdim] - r >= boxes[d2].lo.x[jdim]) - nb = d2; - jdim = ++jdim % DIM; - if (nb == nbold) - break; - } - task[1] = nb; - ntask = 1; - while (ntask != 0) { - k = task[ntask--]; - if (dist(boxes[k], pt) > r) - continue; - if (boxes[k].dau1 != 0) { - task[++ntask] = boxes[k].dau1; - task[++ntask] = boxes[k].dau2; - } else { - for (i = boxes[k].ptlo; i <= boxes[k].pthi; i++) { - if (dist(ptss[ptindx[i]], pt) <= r && nret < nmax) - list[nret++] = ptindx[i]; - if (nret == nmax) - return nmax; - } - } - } - return nret; - } - - public static int selecti(final int k, final int[] indx, final int off_i, - final int n, final double[] arr, final int off_a) { - int i, ia, ir, j, l, mid; - double a; - - l = 0; - ir = n - 1; - for (;;) { - if (ir <= l + 1) { - if (ir == l + 1 - && arr[off_a + indx[off_i + ir]] < arr[off_a - + indx[off_i + l]]) { - swap(indx, off_i + l, off_i + ir); - } - return indx[off_i + k]; - } else { - mid = (l + ir) >> 1; - swap(indx, off_i + mid, off_i + l + 1); - if (arr[off_a + indx[off_i + l]] > arr[off_a + indx[off_i + ir]]) { - swap(indx, off_i + l, off_i + ir); - } - if (arr[off_a + indx[off_i + l + 1]] > arr[off_a - + indx[off_i + ir]]) { - swap(indx, off_i + l + 1, off_i + ir); - } - if (arr[off_a + indx[off_i + l]] > arr[off_a - + indx[off_i + l + 1]]) { - swap(indx, off_i + l, off_i + l + 1); - } - i = l + 1; - j = ir; - ia = indx[off_i + l + 1]; - a = arr[off_a + ia]; - for (;;) { - do - i++; - while (arr[off_a + indx[off_i + i]] < a); - do - j--; - while (arr[off_a + indx[off_i + j]] > a); - if (j < i) - break; - swap(indx, off_i + i, off_i + j); - } - indx[off_i + l + 1] = indx[off_i + j]; - indx[off_i + j] = ia; - if (j >= k) - ir = j - 1; - if (j <= k) - l = i; - } - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/cg/Minspantree.java b/common-tools/cnuphys/numRec/src/com/nr/cg/Minspantree.java deleted file mode 100644 index 394c1f15c9..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/cg/Minspantree.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.nr.cg; - -import static com.nr.cg.Point.*; -import com.nr.sort.Indexx; - -public class Minspantree extends Delaunay { - public int nspan; - public int[] minsega, minsegb; - - public Minspantree(final Point[] pvec) { - super(pvec, 0); - nspan = npts - 1; - minsega = new int[nspan]; - minsegb = new int[nspan]; - - int i, j, k, jj, kk, m, tmp, nline, n = 0; - Triel tt; - nline = ntri + npts - 1; - int[] sega = new int[nline]; - int[] segb = new int[nline]; - double[] segd = new double[nline]; - int[] mo = new int[npts]; - for (j = 0; j < ntree; j++) { - if (thelist[j].stat == 0) - continue; - tt = thelist[j]; - for (i = 0, k = 1; i < 3; i++, k++) { - if (k == 3) - k = 0; - if (tt.p[i] > tt.p[k]) - continue; - if (tt.p[i] >= npts || tt.p[k] >= npts) - continue; - sega[n] = tt.p[i]; - segb[n] = tt.p[k]; - segd[n] = dist(pts[sega[n]], pts[segb[n]]); - n++; - } - } - Indexx idx = new Indexx(segd); - for (j = 0; j < npts; j++) - mo[j] = j; - n = -1; - for (i = 0; i < nspan; i++) { - for (;;) { - jj = j = idx.el(sega, ++n); - kk = k = idx.el(segb, n); - while (mo[jj] != jj) - jj = mo[jj]; - while (mo[kk] != kk) - kk = mo[kk]; - if (jj != kk) { - minsega[i] = j; - minsegb[i] = k; - m = mo[jj] = kk; - jj = j; - while (mo[jj] != m) { - tmp = mo[jj]; - mo[jj] = m; - jj = tmp; - } - kk = k; - while (mo[kk] != m) { - tmp = mo[kk]; - mo[kk] = m; - kk = tmp; - } - break; - } - } - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/cg/Nearpoints.java b/common-tools/cnuphys/numRec/src/com/nr/cg/Nearpoints.java deleted file mode 100644 index 094124159e..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/cg/Nearpoints.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.nr.cg; - -/** - * - * Object for constructing a QO tree containing a set of points, and for - * repeatedly querying which stored points are within a specified radius of a - * specified new point. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Nearpoints { - final int DIM; - int npts; - Qotree thetree; - Sphcirc[] sphlist; - - public Nearpoints(final int dim, final Point[] pvec) { - DIM = dim; - for (Point p : pvec) - if (p.dim() != DIM) - throw new IllegalArgumentException("Need same dim!"); - npts = pvec.length; - thetree = new Qotree(dim, npts, npts, 32 / DIM); // Set the tree's outer - // box and store all - // the points. - int j, k; - sphlist = new Sphcirc[npts]; - Point lo = pvec[0], hi = pvec[0]; // Find bounding box for the points - for (j = 1; j < npts; j++) - for (k = 0; k < DIM; k++) { - if (pvec[j].x[k] < lo.x[k]) - lo.x[k] = pvec[j].x[k]; - if (pvec[j].x[k] > hi.x[k]) - hi.x[k] = pvec[j].x[k]; - } - // Expand it by 10% so that all points are well interior. - for (k = 0; k < DIM; k++) { - lo.x[k] -= 0.1 * (hi.x[k] - lo.x[k]); - hi.x[k] += 0.1 * (hi.x[k] - lo.x[k]); - } - thetree.setouterbox(lo, hi); - for (j = 0; j < npts; j++) - thetree.qostore(new Sphcirc(pvec[j], 0.0)); - } - - public int dim() { - return DIM; - } - - /** - * - * Once the tree is constructed, this function can be called repeatedly with - * varying points pt and radii r. It returns n, the number of stored points - * within radius r of pt (but no larger than nmax), and copies those points - * into list[0..n-1]. - * - * @param pt - * @param r - * @param list - * @param nmax - * @return - */ - public int locatenear(final Point pt, final double r, final Point[] list, - final int nmax) { - int j, n; - n = thetree.qocollides(new Sphcirc(pt, r), sphlist, nmax); - for (j = 0; j < n; j++) - list[j] = sphlist[j].center; - return n; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/cg/Point.java b/common-tools/cnuphys/numRec/src/com/nr/cg/Point.java deleted file mode 100644 index 22b01bad15..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/cg/Point.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.nr.cg; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -public class Point extends Object { - - public double[] x; - - public int dim() { - return x.length; - } - - public Point(final int dim) { - this(dim, new double[dim]); - } - - public Point(final double x, final double y, final double z) { - this(3, new double[] { x, y, z }); - } - - public Point(final double x, final double y) { - this(2, new double[] { x, y }); - } - - public Point(final double x) { - this(1, new double[] { x }); - } - - public Point(final int dim, final double[] xx) { - x = new double[dim]; - x[0] = xx[0]; - if (dim > 1) - x[1] = xx[1]; - if (dim > 2) - x[2] = xx[2]; - if (dim > 3) - throw new IllegalArgumentException( - "Point not implemented for DIM > 3"); - } - - public Point(final Point p) { - x = new double[p.dim()]; - for (int i = 0; i < x.length; i++) - x[i] = p.x[i]; - } - - public Point copyAssign(final Point p) { - x = new double[p.dim()]; - for (int i = 0; i < x.length; i++) - x[i] = p.x[i]; - return this; - } - - @Override - public boolean equals(final Object obj) { - if (obj instanceof Point) { - Point po = (Point) obj; - if (po.dim() != x.length) - return false; - for (int i = 0; i < x.length; i++) - if (x[i] != po.x[i]) - return false; - return true; - } else - return false; - } - - @Override - public Point clone() { - int dim = x.length; - double[] x0 = new double[x.length]; - System.arraycopy(x, 0, x0, 0, x0.length); - return new Point(dim, x0); - } - - public static double dist(final Point p, final Point q) { - if (p.dim() != q.dim()) - throw new IllegalArgumentException("need same dim!"); - - int DIM = p.dim(); - double dd = 0.0; - for (int j = 0; j < DIM; j++) - dd += SQR(q.x[j] - p.x[j]); - return sqrt(dd); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/cg/Polygon.java b/common-tools/cnuphys/numRec/src/com/nr/cg/Polygon.java deleted file mode 100644 index d4ef2dc036..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/cg/Polygon.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.nr.cg; - -import static java.lang.Math.*; - -/** - * geometric polygon Copyright (C) Numerical Recipes Software 1986-2007 Java - * translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Polygon { - private final static int DIM = 2; - - private Polygon() { - } - - public static int polywind(final Point[] vt, final Point pt) { - for (int i = 0; i < vt.length; i++) - if (vt[i].dim() != DIM) - throw new IllegalArgumentException("Need same dim!"); - int i, np, wind = 0; - double d0, d1, p0, p1, pt0, pt1; - np = vt.length; - pt0 = pt.x[0]; - pt1 = pt.x[1]; - p0 = vt[np - 1].x[0]; - p1 = vt[np - 1].x[1]; - for (i = 0; i < np; i++) { - d0 = vt[i].x[0]; - d1 = vt[i].x[1]; - if (p1 <= pt1) { - if (d1 > pt1 - && (p0 - pt0) * (d1 - pt1) - (p1 - pt1) * (d0 - pt0) > 0) - wind++; - } else { - if (d1 <= pt1 - && (p0 - pt0) * (d1 - pt1) - (p1 - pt1) * (d0 - pt0) < 0) - wind--; - } - p0 = d0; - p1 = d1; - } - return wind; - } - - public static int ispolysimple(final Point[] vt) { - for (int i = 0; i < vt.length; i++) - if (vt[i].dim() != DIM) - throw new IllegalArgumentException("Need same dim!"); - int i, ii, j, jj, np, schg = 0, wind = 0; - double p0, p1, d0, d1, pp0, pp1, dd0, dd1, t, tp, t1, t2, crs, crsp = 0.0; - np = vt.length; - p0 = vt[0].x[0] - vt[np - 1].x[0]; - p1 = vt[0].x[1] - vt[np - 1].x[1]; - for (i = 0, ii = 1; i < np; i++, ii++) { - if (ii == np) - ii = 0; - d0 = vt[ii].x[0] - vt[i].x[0]; - d1 = vt[ii].x[1] - vt[i].x[1]; - crs = p0 * d1 - p1 * d0; - if (crs * crsp < 0) - schg = 1; - if (p1 <= 0.0) { - if (d1 > 0.0 && crs > 0.0) - wind++; - } else { - if (d1 <= 0.0 && crs < 0.0) - wind--; - } - p0 = d0; - p1 = d1; - if (crs != 0.0) - crsp = crs; - } - if (abs(wind) != 1) - return 0; - if (schg == 0) - return (wind > 0 ? 1 : -1); - for (i = 0, ii = 1; i < np; i++, ii++) { - if (ii == np) - ii = 0; - d0 = vt[ii].x[0]; - d1 = vt[ii].x[1]; - p0 = vt[i].x[0]; - p1 = vt[i].x[1]; - tp = 0.0; - for (j = i + 1, jj = i + 2; j < np; j++, jj++) { - if (jj == np) { - if (i == 0) - break; - jj = 0; - } - dd0 = vt[jj].x[0]; - dd1 = vt[jj].x[1]; - t = (dd0 - d0) * (p1 - d1) - (dd1 - d1) * (p0 - d0); - if (t * tp <= 0.0 && j > i + 1) { - pp0 = vt[j].x[0]; - pp1 = vt[j].x[1]; - t1 = (p0 - dd0) * (pp1 - dd1) - (p1 - dd1) * (pp0 - dd0); - t2 = (d0 - dd0) * (pp1 - dd1) - (d1 - dd1) * (pp0 - dd0); - if (t1 * t2 <= 0.0) - return 0; - } - tp = t; - } - } - return (wind > 0 ? 2 : -2); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/cg/Qotree.java b/common-tools/cnuphys/numRec/src/com/nr/cg/Qotree.java deleted file mode 100644 index 314c02e92f..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/cg/Qotree.java +++ /dev/null @@ -1,360 +0,0 @@ -package com.nr.cg; - -import com.nr.ran.Hash; -import com.nr.ran.Hashfn1; -import com.nr.ran.Mhash; - -public class Qotree { - final int DIM; - final int PMAX; // = 32/DIM; - final int QO; // = (1 << DIM); - final int QL; // = (QO - 2); - public int maxd; - public double[] blo; - public double[] bscale; - Mhash1 elhash; - Hash1 pophash; - - class Mhash1 extends Mhash { - Hashfn1 hfn = new Hashfn1(4); - - public Mhash1(final int nh, final int nm) { - super(nh, nm); - } - - @Override - public long fn(final Integer k) { - return hfn.fn(k); - } - } - - class Hash1 extends Hash { - Hashfn1 hfn = new Hashfn1(4); - - public Hash1(final int nh, final int nm) { - super(nh, nm); - } - - @Override - public long fn(final Integer k) { - return hfn.fn(k); - } - } - - /** - * Constructor for a quad- (DIM=2) or oc- (DIM=3) tree that can store a max - * of nv elements of type elT, using hash tables of length nh (typically - * nv). maxdep is the number of levels to be represented. - * - * @param dim - * @param nh - * @param nv - * @param maxdep - */ - public Qotree(final int dim, final int nh, final int nv, final int maxdep) { - DIM = dim; - PMAX = 32 / DIM; - QO = (1 << DIM); - QL = (QO - 2); - - blo = new double[DIM]; - bscale = new double[DIM]; - elhash = new Mhash1(nh, nv); - maxd = maxdep; - pophash = new Hash1(maxd * nh, maxd * nv); - - if (maxd > PMAX) - throw new IllegalArgumentException("maxdep too large in Qotree"); - setouterbox(new Point(DIM, new double[] { 0.0, 0.0, 0.0 }), new Point( - DIM, new double[] { 1.0, 1.0, 1.0 })); - } - - public int dim() { - return DIM; - } - - public void setouterbox(final Point lo, final Point hi) { - if (lo.dim() != DIM || hi.dim() != DIM) - throw new IllegalArgumentException("Need same dim!"); - for (int j = 0; j < DIM; j++) { - blo[j] = lo.x[j]; - bscale[j] = hi.x[j] - lo.x[j]; - } - } - - /** - * Returns the box indexed by k. - * - * @param kk - * @return - */ - public Box qobox(final int kk) { - int j, kb; - int k = kk; - Point plo = new Point(DIM), phi = new Point(DIM); - double[] offset = new double[DIM]; - double del = 1.0; - for (j = 0; j < DIM; j++) - offset[j] = 0.0; - while (k > 1) { - kb = (k + QL) % QO; - for (j = 0; j < DIM; j++) { - if ((kb & (1 << j)) != 0) - offset[j] += del; - } - k = (k + QL) >> DIM; - del *= 2.0; - } - for (j = 0; j < DIM; j++) { - plo.x[j] = blo[j] + bscale[j] * offset[j] / del; - phi.x[j] = blo[j] + bscale[j] * (offset[j] + 1.0) / del; - } - return new Box(plo, phi); - } - - /** - * Return the box number of the smallest box that can contain an element - * tobj, without regard to whether tobj is already stored in the tree. - * - * @param tobj - * @return - */ - public int qowhichbox(final Sphcirc tobj) { - int p, k, kl, kr, ks = 1; - for (p = 2; p <= maxd; p++) { - kl = QO * ks - QL; - kr = kl + QO - 1; - for (k = kl; k <= kr; k++) { - if (tobj.isinbox(qobox(k)) != 0) { - ks = k; - break; - } - } - if (k > kr) - break; - } - return ks; - } - - /** - * Store the element tobj in the Qotree, and return the box number into - * which it was stored. - * - * @param tobj - * @return - */ - public int qostore(final Sphcirc obj) { - // XXX clone object for storing. - Sphcirc tobj = obj.clone(); - int k, ks, kks, km; - ks = kks = qowhichbox(tobj); - elhash.store(ks, tobj); - Integer ppop = pophash.get(ks); - if (ppop == null) - ppop = 0; - pophash.set(ks, ppop | 1); - while (ks > 1) { - km = (ks + QL) >> DIM; - k = ks - (QO * km - QL); - ks = km; - ppop = pophash.get(ks); - if (ppop == null) - ppop = 0; - pophash.set(ks, ppop | (1 << (k + 1))); - } - return kks; - } - - /** - * Erase the element tobj, returning the box number into which it was stored - * or 0 if the element was not found in the Qotree. Note logic very similar - * to qostore. - * - * @param tobj - * @return - */ - public int qoerase(final Sphcirc tobj) { - int k, ks, kks, km; - Integer ppop; - ks = kks = qowhichbox(tobj); - if (elhash.erase(ks, tobj) == 0) - return 0; - if (elhash.count(ks) != 0) - return kks; - ppop = pophash.get(ks); - if (ppop == null) - ppop = 0; - pophash.set(ks, ppop & ~(1)); - while (ks > 1) { - if (pophash.get(ks) != 0) - break; - pophash.erase(ks); - km = (ks + QL) >> DIM; - k = ks - (QO * km - QL); - ks = km; - ppop = pophash.get(ks); - if (ppop == null) - ppop = 0; - pophash.set(ks, ppop & (~(1 << (k + 1)))); - // *ppop &= ~((Uint)(1 << (k+1))); - } - return kks; - } - - /** - * Retrieve all (or up to nmax if it is smaller) elements that are stored in - * box k of the Qotree. The elements are copied into list[0..nlist-1] and - * the value nlist (<= nmax) is returned. - * - * @param k - * @param list - * @param nmax - * @return - */ - public int qoget(final int k, final Sphcirc[] list, final int nmax) { - int ks, pop, nlist; - ks = k; - nlist = 0; - Integer[] pop_w = new Integer[1]; - pophash.get(ks, pop_w, 0); - pop = pop_w[0]; - if ((pop & 1) != 0 && elhash.getinit(ks) != 0) { - while (nlist < nmax && elhash.getnext(list, nlist) != 0) { - nlist++; - } - } - return nlist; - } - - /** - * - * @param klist - * @param list - * @param nmax - * @return - */ - public int qodump(final int[] klist, final Sphcirc[] list, final int nmax) { - int nlist, ntask, ks, pop, k; - int[] tasklist = new int[200]; - nlist = 0; - ntask = 1; - tasklist[1] = 1; - while (ntask != 0) { - ks = tasklist[ntask--]; - Integer[] pop_w = new Integer[1]; - if (pophash.get(ks, pop_w, 0) == 0) - continue; - pop = pop_w[0]; - if ((pop & 1) != 0 && elhash.getinit(ks) != 0) { - while (nlist < nmax && elhash.getnext(list, nlist) != 0) { - klist[nlist] = ks; - nlist++; - } - } - if (nlist == nmax) - break; - k = QO * ks - QL; - while ((pop >>= 1) != 0) { - if ((pop & 1) != 0) - tasklist[++ntask] = k; - k++; - } - } - return nlist; - } - - /** - * Retrieve all (or up to nmax if it is smaller) elements in Qotree that - * contain the point pt. The elements are copied into list[0..nlist-1] and - * the value nlist (<= nmax) is returned. - * - * @param pt - * @param list - * @param nmax - * @return - */ - public int qocontainspt(final Point pt, final Sphcirc[] list, final int nmax) { - int j, k, ks, pop, nlist; - double[] bblo = new double[DIM], bbscale = new double[DIM]; - for (j = 0; j < DIM; j++) { - bblo[j] = blo[j]; - bbscale[j] = bscale[j]; - } - nlist = 0; - ks = 1; - Integer[] pop_w = new Integer[1]; - while (pophash.get(ks, pop_w, 0) != 0) { - pop = pop_w[0]; - if ((pop & 1) != 0) { - elhash.getinit(ks); - - while (nlist < nmax && elhash.getnext(list, nlist) != 0) { - - if (list[nlist].contains(pt) != 0) { - nlist++; - } - } - } - if ((pop >>= 1) == 0) - break; - for (k = 0, j = 0; j < DIM; j++) { - bbscale[j] *= 0.5; - if (pt.x[j] > bblo[j] + bbscale[j]) { - k += (1 << j); - bblo[j] += bbscale[j]; - } - } - if (((pop >> k) & 1) == 0) - break; - ks = QO * ks - QL + k; - } - return nlist; - } - - /** - * Retrieve all (or up to nmax if it is smaller) elements in Qotree that - * collide with an element qt (which needn't be in the tree itself). The - * elements are copied into list[0..nlist-1] and the value nlist (Ä nmax) is - * returned. - * - * @param qt - * @param list - * @param nmax - * @return - */ - public int qocollides(final Sphcirc qt, final Sphcirc[] list, final int nmax) { - int k, ks, kks, pop, nlist, ntask; - int[] tasklist = new int[200]; - nlist = 0; - kks = ks = qowhichbox(qt); - ntask = 0; - while (ks > 0) { - tasklist[++ntask] = ks; - ks = (ks + QL) >> DIM; - } - while (ntask != 0) { - ks = tasklist[ntask--]; - Integer[] pop_w = new Integer[1]; - if (pophash.get(ks, pop_w, 0) == 0) - continue; - pop = pop_w[0]; - if ((pop & 1) != 0) { - elhash.getinit(ks); - while (nlist < nmax && elhash.getnext(list, nlist) != 0) { - if (list[nlist].collides(qt) != 0) { - nlist++; - } - } - } - if (ks >= kks) { - k = QO * ks - QL; - while ((pop >>= 1) != 0) { - if ((pop & 1) != 0) - tasklist[++ntask] = k; - k++; - } - } - } - return nlist; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/cg/Sphcirc.java b/common-tools/cnuphys/numRec/src/com/nr/cg/Sphcirc.java deleted file mode 100644 index b23bb0e52c..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/cg/Sphcirc.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.nr.cg; - -import static com.nr.cg.Point.*; - -public class Sphcirc { - public Point center; - public double radius; - - public Sphcirc(final int dim) { - center = new Point(dim); - } - - public Sphcirc(final Point mycenter, final double myradius) { - center = mycenter; - radius = myradius; - } - - public int dim() { - return center.dim(); - } - - @Override - public Sphcirc clone() { - return new Sphcirc(center.clone(), radius); - } - - @Override - public boolean equals(final Object obj) { - if (obj instanceof Sphcirc) { - Sphcirc s = (Sphcirc) obj; - return (radius == s.radius && center.equals(s.center)); - } else - return false; - } - - /** - * - * Is the circle/sphere inside a box? - * - * @param box - * @return - */ - public int isinbox(final Box box) { - if (center.dim() != box.dim()) - throw new IllegalArgumentException("Need same dim!"); - int DIM = center.dim(); - for (int i = 0; i < DIM; i++) { - if ((center.x[i] - radius < box.lo.x[i]) - || (center.x[i] + radius > box.hi.x[i])) - return 0; - } - return 1; - } - - /** - * Is a given point inside the circle/sphere? - * - * @param point - * @return - */ - public int contains(final Point point) { - if (center.dim() != point.dim()) - throw new IllegalArgumentException("Need same dim!"); - if (dist(point, center) > radius) - return 0; - else - return 1; - } - - /** - * Does it collide with another circle/sphere? - * - * @param circ - * @return - */ - public int collides(final Sphcirc circ) { - if (circ.dim() != this.dim()) - throw new IllegalArgumentException("Need same dim!"); - - if (dist(circ.center, center) > circ.radius + radius) - return 0; - else - return 1; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/cg/Triel.java b/common-tools/cnuphys/numRec/src/com/nr/cg/Triel.java deleted file mode 100644 index 4efb15330c..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/cg/Triel.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.nr.cg; - -import static com.nr.NRUtil.*; - -public class Triel { - public final static int DIM = 2; - - /** - * The array of the points. - */ - public Point[] pts; - /** - * The triangle's three vertices, always in CCW order. - */ - public int[] p = new int[3]; - - /** - * Pointers for up to three daughters. - */ - public int[] d = new int[3]; - - /** - * Nonzero if this element is "live." - */ - public int stat; - - public Triel() { - - } - - public int dim() { - return DIM; - } - - public void setme(final int a, final int b, final int c, final Point[] ptss) { - for (int i = 0; i < ptss.length; i++) - if (ptss[i].dim() != DIM) - throw new IllegalArgumentException("Need same dim!"); - pts = ptss; - p[0] = a; - p[1] = b; - p[2] = c; - d[0] = d[1] = d[2] = -1; // The values 1 mean no daughters. - stat = 1; // Create as "live." - } - - /** - * Return 1 if point is in the triangle, 0 if on boundary, 1 if outside. - * (CCW triangle is assumed.) - * - * @param point - * @return - */ - public int contains(final Point point) { - if (point.dim() != DIM) - throw new IllegalArgumentException("Need same dim!"); - double d; - int i, j, ztest = 0; - for (i = 0; i < 3; i++) { - j = (i + 1) % 3; - d = (pts[p[j]].x[0] - pts[p[i]].x[0]) - * (point.x[1] - pts[p[i]].x[1]) - - (pts[p[j]].x[1] - pts[p[i]].x[1]) - * (point.x[0] - pts[p[i]].x[0]); - if (d < 0.0) - return -1; - if (d == 0.0) - ztest = 1; - } - return (ztest != 0 ? 0 : 1); - } - - /** - * Return positive, zero, or negative value if point d is respectively - * inside, on, or outside the circle through points a, b, and c. - * - * @param d - * @param a - * @param b - * @param c - * @return - */ - public static double incircle(final Point d, final Point a, final Point b, - final Point c) { - if (d.dim() != DIM || a.dim() != DIM || c.dim() != DIM) - throw new IllegalArgumentException("Need same dim!"); - Circle cc = Circle.circumcircle(a, b, c); - double radd = SQR(d.x[0] - cc.center.x[0]) - + SQR(d.x[1] - cc.center.x[1]); - return (SQR(cc.radius) - radd); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/cg/Voronoi.java b/common-tools/cnuphys/numRec/src/com/nr/cg/Voronoi.java deleted file mode 100644 index 67f422da01..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/cg/Voronoi.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.nr.cg; - -import static com.nr.cg.Circle.*; - -/** - * Constructor for Voronoi diagram of a vector of sites pvec. Bit "1" sent to - * the Delaunay constructor tells it not to delete linehash. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Voronoi extends Delaunay { - public int nseg; - public int[] trindx; - public Voredge[] segs; - - public static class Voredge { - public Point[] p = new Point[2]; - public int nearpt; - - public Voredge(final Point pa, final Point pb, final int np) { - if (pa.dim() != DIM || pb.dim() != DIM) - throw new IllegalArgumentException("Need same dim!"); - nearpt = np; - p[0] = pa; - p[1] = pb; - } - } - - public Voronoi(final Point[] pvec) { - super(pvec, 1); - nseg = 0; - trindx = new int[npts]; - segs = new Voredge[6 * npts + 12]; - int i, j, k, p, jfirst; - long key; - Triel tt; - Point cc, ccp; - for (j = 0; j < ntree; j++) { - if (thelist[j].stat <= 0) - continue; - tt = thelist[j]; - for (k = 0; k < 3; k++) - trindx[tt.p[k]] = j; - } - for (p = 0; p < npts; p++) { - tt = thelist[trindx[p]]; - if (tt.p[0] == p) { - i = tt.p[1]; - j = tt.p[2]; - } else if (tt.p[1] == p) { - i = tt.p[2]; - j = tt.p[0]; - } else if (tt.p[2] == p) { - i = tt.p[0]; - j = tt.p[1]; - } else - throw new IllegalArgumentException("triangle should contain p"); - jfirst = j; - ccp = circumcircle(pts[p], pts[i], pts[j]).center; - while (true) { - key = hashfn.int64p(i) - hashfn.int64p(p); - Integer[] k_w = new Integer[1]; - if (linehash.get(key, k_w, 0) == 0) - throw new IllegalArgumentException("Delaunay is incomplete"); - k = k_w[0]; - cc = circumcircle(pts[p], pts[k], pts[i]).center; - segs[nseg++] = new Voredge(ccp, cc, p); - if (k == jfirst) - break; - ccp = cc; - j = i; - i = k; - } - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ci/Gaumixmod.java b/common-tools/cnuphys/numRec/src/com/nr/ci/Gaumixmod.java deleted file mode 100644 index a502517d7b..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ci/Gaumixmod.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.nr.ci; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import com.nr.la.Cholesky; - -public class Gaumixmod { - public int nn, kk, mm; - public double[][] data, means, resp; - public double[] frac, lndets; - public double[][][] sig; - public double loglike; - - public Gaumixmod(final double[][] ddata, final double[][] mmeans) { - int mmstat = ddata[0].length; - nn = ddata.length; - kk = mmeans.length; - mm = mmstat; - data = buildMatrix(ddata); - means = buildMatrix(mmeans); - resp = new double[nn][kk]; - frac = new double[kk]; - lndets = new double[kk]; - sig = new double[kk][mmstat][mmstat]; - - int i, j, k; - for (k = 0; k < kk; k++) { - frac[k] = 1. / kk; - for (i = 0; i < mm; i++) { - for (j = 0; j < mm; j++) - sig[k][i][j] = 0.; - sig[k][i][i] = 1.0e-10; - } - } - estep(); - mstep(); - } - - public double estep() { - int k, m, n; - double tmp, sum, max, oldloglike; - double[] u = new double[mm], v = new double[mm]; - oldloglike = loglike; - for (k = 0; k < kk; k++) { - Cholesky choltmp = new Cholesky(sig[k]); - lndets[k] = choltmp.logdet(); - for (n = 0; n < nn; n++) { - for (m = 0; m < mm; m++) - u[m] = data[n][m] - means[k][m]; - choltmp.elsolve(u, v); - for (sum = 0., m = 0; m < mm; m++) - sum += SQR(v[m]); - resp[n][k] = -0.5 * (sum + lndets[k]) + log(frac[k]); - } - } - loglike = 0; - for (n = 0; n < nn; n++) { - max = -99.9e99; - for (k = 0; k < kk; k++) - if (resp[n][k] > max) - max = resp[n][k]; - for (sum = 0., k = 0; k < kk; k++) - sum += exp(resp[n][k] - max); - tmp = max + log(sum); - for (k = 0; k < kk; k++) - resp[n][k] = exp(resp[n][k] - tmp); - loglike += tmp; - } - return loglike - oldloglike; - } - - public void mstep() { - int j, n, k, m; - double wgt, sum; - for (k = 0; k < kk; k++) { - wgt = 0.; - for (n = 0; n < nn; n++) - wgt += resp[n][k]; - frac[k] = wgt / nn; - for (m = 0; m < mm; m++) { - for (sum = 0., n = 0; n < nn; n++) - sum += resp[n][k] * data[n][m]; - means[k][m] = sum / wgt; - for (j = 0; j < mm; j++) { - for (sum = 0., n = 0; n < nn; n++) { - sum += resp[n][k] * (data[n][m] - means[k][m]) - * (data[n][j] - means[k][j]); - } - sig[k][m][j] = sum / wgt; - } - } - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ci/HMM.java b/common-tools/cnuphys/numRec/src/com/nr/ci/HMM.java deleted file mode 100644 index 291e8d602d..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ci/HMM.java +++ /dev/null @@ -1,218 +0,0 @@ -package com.nr.ci; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import com.nr.ran.Ran; - -/** - * hidden Markov models Copyright (C) Numerical Recipes Software 1986-2007 Java - * translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class HMM { - public double[][] a, b; - public int[] obs; - public int fbdone; - public int mstat, nobs, ksym; - public int lrnrm; - public double[][] alpha, beta, pstate; - public int[] arnrm, brnrm; - private final double BIG, BIGI; - double lhood; - - public double loglikelihood() { - return log(lhood) + lrnrm * log(BIGI); - } - - public HMM(final double[][] aa, final double[][] bb, final int[] obss) { - - a = buildMatrix(aa); - b = buildMatrix(bb); - obs = buildVector(obss); - fbdone = 0; - mstat = a.length; - nobs = obs.length; - ksym = b[0].length; - alpha = new double[nobs][mstat]; - beta = new double[nobs][mstat]; - pstate = new double[nobs][mstat]; - arnrm = new int[nobs]; - brnrm = new int[nobs]; - BIG = 1.e20; - BIGI = 1. / BIG; - - int i, j, k; - double sum; - if (a[0].length != mstat) - throw new IllegalArgumentException("transition matrix not square"); - if (b.length != mstat) - throw new IllegalArgumentException("symbol prob matrix wrong size"); - for (i = 0; i < nobs; i++) { - if (obs[i] < 0 || obs[i] >= ksym) - throw new IllegalArgumentException("bad data in obs"); - } - for (i = 0; i < mstat; i++) { - sum = 0.; - for (j = 0; j < mstat; j++) - sum += a[i][j]; - if (abs(sum - 1.) > 0.01) - throw new IllegalArgumentException( - "transition matrix not normalized"); - for (j = 0; j < mstat; j++) - a[i][j] /= sum; - } - for (i = 0; i < mstat; i++) { - sum = 0.; - for (k = 0; k < ksym; k++) - sum += b[i][k]; - if (abs(sum - 1.) > 0.01) - throw new IllegalArgumentException( - "symbol prob matrix not normalized"); - for (k = 0; k < ksym; k++) - b[i][k] /= sum; - } - } - - public void forwardbackward() { - int i, j, t; - double sum, asum, bsum; - for (i = 0; i < mstat; i++) - alpha[0][i] = b[i][obs[0]]; - arnrm[0] = 0; - for (t = 1; t < nobs; t++) { - asum = 0; - for (j = 0; j < mstat; j++) { - sum = 0.; - for (i = 0; i < mstat; i++) - sum += alpha[t - 1][i] * a[i][j] * b[j][obs[t]]; - alpha[t][j] = sum; - asum += sum; - } - arnrm[t] = arnrm[t - 1]; - if (asum < BIGI) { - ++arnrm[t]; - for (j = 0; j < mstat; j++) - alpha[t][j] *= BIG; - } - } - for (i = 0; i < mstat; i++) - beta[nobs - 1][i] = 1.; - brnrm[nobs - 1] = 0; - for (t = nobs - 2; t >= 0; t--) { - bsum = 0.; - for (i = 0; i < mstat; i++) { - sum = 0.; - for (j = 0; j < mstat; j++) - sum += a[i][j] * b[j][obs[t + 1]] * beta[t + 1][j]; - beta[t][i] = sum; - bsum += sum; - } - brnrm[t] = brnrm[t + 1]; - if (bsum < BIGI) { - ++brnrm[t]; - for (j = 0; j < mstat; j++) - beta[t][j] *= BIG; - } - } - lhood = 0.; - for (i = 0; i < mstat; i++) - lhood += alpha[0][i] * beta[0][i]; - lrnrm = arnrm[0] + brnrm[0]; - if (lhood != 0.) - while (lhood < BIGI) { - lhood *= BIG; - lrnrm++; - } - for (t = 0; t < nobs; t++) { - sum = 0.; - for (i = 0; i < mstat; i++) - sum += (pstate[t][i] = alpha[t][i] * beta[t][i]); - // sum = lhood*pow(BIGI, lrnrm - arnrm[t] - brnrm[t]); - for (i = 0; i < mstat; i++) - pstate[t][i] /= sum; - } - fbdone = 1; - } - - public void baumwelch() { - int i, j, k, t; - double num, denom, term; - double[][] bnew = new double[mstat][ksym]; - double[] powtab = new double[10]; - for (i = 0; i < 10; i++) - powtab[i] = pow(BIGI, i - 6); - if (fbdone != 1) - throw new IllegalArgumentException("must do forwardbackward first"); - for (i = 0; i < mstat; i++) { - denom = 0.; - for (k = 0; k < ksym; k++) - bnew[i][k] = 0.; - for (t = 0; t < nobs - 1; t++) { - term = (alpha[t][i] * beta[t][i] / lhood) - * powtab[arnrm[t] + brnrm[t] - lrnrm + 6]; - denom += term; - bnew[i][obs[t]] += term; - } - for (j = 0; j < mstat; j++) { - num = 0.; - for (t = 0; t < nobs - 1; t++) { - num += alpha[t][i] * b[j][obs[t + 1]] * beta[t + 1][j] - * powtab[arnrm[t] + brnrm[t + 1] - lrnrm + 6] - / lhood; - } - a[i][j] *= (num / denom); - } - for (k = 0; k < ksym; k++) - bnew[i][k] /= denom; - } - b = bnew; - fbdone = 0; - } - - public static void markovgen(final double[][] atrans, final int[] out) { - markovgen(atrans, out, 0, 1); - } - - /** - * Markov Models and Hidden Markov Modeling - * - * @param atrans - * @param out - * @param istart - * @param seed - */ - public static void markovgen(final double[][] atrans, final int[] out, - final int istart, final int seed) { - int i, ilo, ihi, ii, j, m = atrans.length, n = out.length; - double[][] cum = buildMatrix(atrans); - double r; - Ran ran = new Ran(seed); - if (m != atrans[0].length) - throw new IllegalArgumentException( - "transition matrix must be square"); - for (i = 0; i < m; i++) { - for (j = 1; j < m; j++) - cum[i][j] += cum[i][j - 1]; - if (abs(cum[i][m - 1] - 1.) > 0.01) - throw new IllegalArgumentException( - "transition matrix rows must sum to 1"); - } - j = istart; - out[0] = j; - for (ii = 1; ii < n; ii++) { - r = ran.doub() * cum[j][m - 1]; - ilo = 0; - ihi = m; - while (ihi - ilo > 1) { - i = (ihi + ilo) >> 1; - if (r > cum[j][i - 1]) - ilo = i; - else - ihi = i; - } - out[ii] = j = ilo; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ci/Kmeans.java b/common-tools/cnuphys/numRec/src/com/nr/ci/Kmeans.java deleted file mode 100644 index 96ffa64f17..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ci/Kmeans.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.nr.ci; - -import static com.nr.NRUtil.*; - -/** - * k-means classification Copyright (C) Numerical Recipes Software 1986-2007 - * Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Kmeans { - public int nn, mm, kk, nchg; - public double[][] data, means; - public int[] assign, count; - - public Kmeans(final double[][] ddata, final double[][] mmeans) { - nn = ddata.length; - mm = ddata[0].length; - kk = mmeans.length; - data = buildMatrix(ddata); - means = buildMatrix(mmeans); - assign = new int[nn]; - count = new int[kk]; - - estep(); - mstep(); - } - - public int estep() { - int k, m, n, kmin = 0; - double dmin, d; - nchg = 0; - for (k = 0; k < kk; k++) - count[k] = 0; - for (n = 0; n < nn; n++) { - dmin = 9.99e99; - for (k = 0; k < kk; k++) { - for (d = 0., m = 0; m < mm; m++) - d += SQR(data[n][m] - means[k][m]); - if (d < dmin) { - dmin = d; - kmin = k; - } - } - if (kmin != assign[n]) - nchg++; - assign[n] = kmin; - count[kmin]++; - } - return nchg; - } - - public void mstep() { - int n, k, m; - for (k = 0; k < kk; k++) - for (m = 0; m < mm; m++) - means[k][m] = 0.; - for (n = 0; n < nn; n++) - for (m = 0; m < mm; m++) - means[assign[n]][m] += data[n][m]; - for (k = 0; k < kk; k++) { - if (count[k] > 0) - for (m = 0; m < mm; m++) - means[k][m] /= count[k]; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ci/Phylagglom.java b/common-tools/cnuphys/numRec/src/com/nr/ci/Phylagglom.java deleted file mode 100644 index 5e646498d9..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ci/Phylagglom.java +++ /dev/null @@ -1,213 +0,0 @@ -package com.nr.ci; - -import static com.nr.NRUtil.*; - -import java.io.*; - -import org.netlib.util.doubleW; - -public abstract class Phylagglom { - public int n, root, fsroot; - public double seqmax, depmax; - public Phylagglomnode[] t; - - public abstract void premin(double[][] d, int[] nextp); - - public abstract double dminfn(double[][] d, int i, int j); - - public abstract double dbranchfn(double[][] d, int i, int j); - - public abstract double dnewfn(double[][] d, int k, int i, int j, int ni, - int nj); - - public abstract void drootbranchfn(double[][] d, int i, int j, int ni, - int nj, doubleW bi, doubleW bj); - - public Phylagglom(final double[][] dist) { - this(dist, -1); - } - - public Phylagglom(final double[][] dist, final int fsr) { - n = dist.length; - fsroot = fsr; - t = new Phylagglomnode[2 * n - 1]; - for (int i = 0; i < t.length; i++) - t[i] = new Phylagglomnode(); - } - - public void makethetree(final double[][] dist) { - int i, j, k, imin = 0, jmin = 0, node, ntask; // ncurr not used. - double dd, dmin; - double[][] d = buildMatrix(dist); - int[] tp = new int[n], nextp = new int[n], prevp = new int[n], tasklist = new int[2 * n + 1]; - double[] tmp = new double[n]; - for (i = 0; i < n; i++) { - nextp[i] = i + 1; - prevp[i] = i - 1; - tp[i] = i; - t[i].ldau = t[i].rdau = -1; - t[i].nel = 1; - } - prevp[0] = nextp[n - 1] = -1; - // ncurr = n; - for (node = n; node < 2 * n - 2; node++) { - premin(d, nextp); - dmin = 9.99e99; - for (i = 0; i >= 0; i = nextp[i]) { - if (tp[i] == fsroot) - continue; - for (j = nextp[i]; j >= 0; j = nextp[j]) { - if (tp[j] == fsroot) - continue; - if ((dd = dminfn(d, i, j)) < dmin) { - dmin = dd; - imin = i; - jmin = j; - } - } - } - i = imin; - j = jmin; - t[tp[i]].mo = t[tp[j]].mo = node; - t[tp[i]].modist = dbranchfn(d, i, j); - t[tp[j]].modist = dbranchfn(d, j, i); - t[node].ldau = tp[i]; - t[node].rdau = tp[j]; - t[node].nel = t[tp[i]].nel + t[tp[j]].nel; - for (k = 0; k >= 0; k = nextp[k]) { - tmp[k] = dnewfn(d, k, i, j, t[tp[i]].nel, t[tp[j]].nel); - } - for (k = 0; k >= 0; k = nextp[k]) - d[i][k] = d[k][i] = tmp[k]; - tp[i] = node; - if (prevp[j] >= 0) - nextp[prevp[j]] = nextp[j]; - if (nextp[j] >= 0) - prevp[nextp[j]] = prevp[j]; - // ncurr--; - } - i = 0; - j = nextp[0]; - root = node; - t[tp[i]].mo = t[tp[j]].mo = t[root].mo = root; - - doubleW bi = new doubleW(t[tp[i]].modist); - doubleW bj = new doubleW(t[tp[j]].modist); - drootbranchfn(d, i, j, t[tp[i]].nel, t[tp[j]].nel, bi, bj); - // t[tp[i]].modist,t[tp[j]].modist); - t[tp[i]].modist = bi.val; - t[tp[j]].modist = bj.val; - - t[root].ldau = tp[i]; - t[root].rdau = tp[j]; - t[root].modist = t[root].dep = 0.; - t[root].nel = t[tp[i]].nel + t[tp[j]].nel; - ntask = 0; - seqmax = depmax = 0.; - tasklist[ntask++] = root; - while (ntask > 0) { - i = tasklist[--ntask]; - if (i >= 0) { - t[i].dep = t[t[i].mo].dep + t[i].modist; - if (t[i].dep > depmax) - depmax = t[i].dep; - if (t[i].ldau < 0) { - t[i].seq = seqmax++; - } else { - tasklist[ntask++] = -i - 1; - tasklist[ntask++] = t[i].ldau; - tasklist[ntask++] = t[i].rdau; - } - } else { - i = -i - 1; - t[i].seq = 0.5 * (t[t[i].ldau].seq + t[t[i].rdau].seq); - } - } - } - - public int comancestor(final int leafa, final int leafb) { - int i, j; - for (i = leafa; i != root; i = t[i].mo) { - for (j = leafb; j != root; j = t[j].mo) - if (i == j) - break; - if (i == j) - break; - } - return i; - } - - public static void newick(Phylagglom p, char[][] str, String filename) - throws IOException { - java.io.PrintWriter OUT = new java.io.PrintWriter(new FileWriter( - filename)); - int i, s, ntask = 0, n = p.n, root = p.root; - int[] tasklist = new int[2 * n + 1]; - tasklist[ntask++] = (1 << 16) + root; - while (ntask-- > 0) { - s = tasklist[ntask] >> 16; - i = tasklist[ntask] & 0xffff; - if (s == 1 || s == 2) { - tasklist[ntask++] = ((s + 2) << 16) + p.t[i].mo; - if (p.t[i].ldau >= 0) { - OUT.printf("("); - tasklist[ntask++] = (2 << 16) + p.t[i].rdau; - tasklist[ntask++] = (1 << 16) + p.t[i].ldau; - } else - OUT.printf("%s:%f", - new String(str[i], 0, str[i].length - 1), - p.t[i].modist); - } else if (s == 3) { - if (ntask > 0) - OUT.printf(",\n"); - } else if (s == 4) { - if (i == root) - OUT.printf(");\n"); - else - OUT.printf("):%f", p.t[i].modist); - } - } - OUT.close(); - } - - public static void phyl2ps(String filename, Phylagglom ph, char[][] str, - int extend, double xl, double xr, double yt, double yb) - throws IOException { - int i, j; - double id, jd, xi, yi, xj, yj, seqmax, depmax; - java.io.PrintWriter OUT = new java.io.PrintWriter(new FileWriter( - filename)); - OUT.printf("%%!PS\n/Courier findfont 8 scalefont setfont\n"); - seqmax = ph.seqmax; - depmax = ph.depmax; - for (i = 0; i < 2 * (ph.n) - 1; i++) { - j = ph.t[i].mo; - id = ph.t[i].dep; - jd = ph.t[j].dep; - xi = xl + (xr - xl) * id / depmax; - yi = yt - (yt - yb) * (ph.t[i].seq + 0.5) / seqmax; - xj = xl + (xr - xl) * jd / depmax; - yj = yt - (yt - yb) * (ph.t[j].seq + 0.5) / seqmax; - OUT.printf( - "%f %f moveto %f %f lineto %f %f lineto 0 setgray stroke\n", - xj, yj, xj, yi, xi, yi); - if (extend != 0) { - if (i < ph.n) { - OUT.printf( - "%f %f moveto %f %f lineto 0.7 setgray stroke\n", - xi, yi, xr, yi); - OUT.printf("%f %f moveto (%s (%02d)) 0 setgray show\n", - xr + 3., yi - 2., new String(str[i], 0, - str[i].length - 1), i); - } - } else { - if (i < ph.n) - OUT.printf("%f %f moveto (%s (%02d)) 0 setgray show\n", - xi + 3., yi - 2., new String(str[i], 0, - str[i].length - 1), i); - } - } - OUT.printf("showpage\n\004"); - OUT.close(); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ci/Phylagglomnode.java b/common-tools/cnuphys/numRec/src/com/nr/ci/Phylagglomnode.java deleted file mode 100644 index c09f5853ef..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ci/Phylagglomnode.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.nr.ci; - -public class Phylagglomnode { - public int mo, ldau, rdau, nel; - public double modist, dep, seq; -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ci/Phylo_clc.java b/common-tools/cnuphys/numRec/src/com/nr/ci/Phylo_clc.java deleted file mode 100644 index ab2f3ffaad..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ci/Phylo_clc.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.nr.ci; - -import static java.lang.Math.*; -import org.netlib.util.doubleW; - -public class Phylo_clc extends Phylagglom { - @Override - public void premin(final double[][] d, final int[] nextp) { - } - - @Override - public double dminfn(final double[][] d, final int i, final int j) { - return d[i][j]; - } - - @Override - public double dbranchfn(final double[][] d, final int i, final int j) { - return 0.5 * d[i][j]; - } - - @Override - public double dnewfn(final double[][] d, final int k, final int i, - final int j, final int ni, final int nj) { - return max(d[i][k], d[j][k]); - } - - @Override - public void drootbranchfn(final double[][] d, final int i, final int j, - final int ni, final int nj, final doubleW bi, final doubleW bj) { - bi.val = bj.val = 0.5 * d[i][j]; - } - - public Phylo_clc(final double[][] dist) { - super(dist); - makethetree(dist); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ci/Phylo_nj.java b/common-tools/cnuphys/numRec/src/com/nr/ci/Phylo_nj.java deleted file mode 100644 index 611eb55cc5..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ci/Phylo_nj.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.nr.ci; - -import org.netlib.util.doubleW; - -public class Phylo_nj extends Phylagglom { - double[] u; - - @Override - public void premin(final double[][] d, final int[] nextp) { - int i, j, ncurr = 0; - double sum; - for (i = 0; i >= 0; i = nextp[i]) - ncurr++; - for (i = 0; i >= 0; i = nextp[i]) { - sum = 0.; - for (j = 0; j >= 0; j = nextp[j]) - if (i != j) - sum += d[i][j]; - u[i] = sum / (ncurr - 2); - } - } - - @Override - public double dminfn(final double[][] d, final int i, final int j) { - return d[i][j] - u[i] - u[j]; - } - - @Override - public double dbranchfn(final double[][] d, final int i, final int j) { - return 0.5 * (d[i][j] + u[i] - u[j]); - } - - @Override - public double dnewfn(final double[][] d, final int k, final int i, - final int j, final int ni, final int nj) { - return 0.5 * (d[i][k] + d[j][k] - d[i][j]); - } - - @Override - public void drootbranchfn(final double[][] d, final int i, final int j, - final int ni, final int nj, final doubleW bi, final doubleW bj) { - bi.val = d[i][j] * (nj - 1 + 1.e-15) / (ni + nj - 2 + 2.e-15); - bj.val = d[i][j] * (ni - 1 + 1.e-15) / (ni + nj - 2 + 2.e-15); - } - - public Phylo_nj(final double[][] dist) { - this(dist, -1); - } - - public Phylo_nj(final double[][] dist, final int fsr) { - super(dist, fsr); - u = new double[n]; - makethetree(dist); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ci/Phylo_slc.java b/common-tools/cnuphys/numRec/src/com/nr/ci/Phylo_slc.java deleted file mode 100644 index b3b2336fca..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ci/Phylo_slc.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.nr.ci; - -import static java.lang.Math.*; -import org.netlib.util.doubleW; - -public class Phylo_slc extends Phylagglom { - @Override - public void premin(final double[][] d, final int[] nextp) { - } - - @Override - public double dminfn(final double[][] d, final int i, final int j) { - return d[i][j]; - } - - @Override - public double dbranchfn(final double[][] d, final int i, final int j) { - return 0.5 * d[i][j]; - } - - @Override - public double dnewfn(final double[][] d, final int k, final int i, - final int j, final int ni, final int nj) { - return max(d[i][k], d[j][k]); - } - - @Override - public void drootbranchfn(final double[][] d, final int i, final int j, - final int ni, final int nj, final doubleW bi, final doubleW bj) { - bi.val = bj.val = 0.5 * d[i][j]; - } - - public Phylo_slc(final double[][] dist) { - super(dist); - makethetree(dist); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ci/Phylo_upgma.java b/common-tools/cnuphys/numRec/src/com/nr/ci/Phylo_upgma.java deleted file mode 100644 index e95b3c80e3..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ci/Phylo_upgma.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.nr.ci; - -import org.netlib.util.doubleW; - -public class Phylo_upgma extends Phylagglom { - @Override - public void premin(final double[][] d, final int[] nextp) { - } - - @Override - public double dminfn(final double[][] d, final int i, final int j) { - return d[i][j]; - } - - @Override - public double dbranchfn(final double[][] d, final int i, final int j) { - return 0.5 * d[i][j]; - } - - @Override - public double dnewfn(final double[][] d, final int k, final int i, - final int j, final int ni, final int nj) { - return (ni * d[i][k] + nj * d[j][k]) / (ni + nj); - } - - @Override - public void drootbranchfn(final double[][] d, final int i, final int j, - final int ni, final int nj, final doubleW bi, final doubleW bj) { - bi.val = bj.val = 0.5 * d[i][j]; - } - - public Phylo_upgma(final double[][] dist) { - super(dist); - makethetree(dist); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ci/Phylo_wpgma.java b/common-tools/cnuphys/numRec/src/com/nr/ci/Phylo_wpgma.java deleted file mode 100644 index 0c6c087ce7..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ci/Phylo_wpgma.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.nr.ci; - -import org.netlib.util.doubleW; - -public class Phylo_wpgma extends Phylagglom { - @Override - public void premin(final double[][] d, final int[] nextp) { - } - - @Override - public double dminfn(final double[][] d, final int i, final int j) { - return d[i][j]; - } - - @Override - public double dbranchfn(final double[][] d, final int i, final int j) { - return 0.5 * d[i][j]; - } - - @Override - public double dnewfn(final double[][] d, final int k, final int i, - final int j, final int ni, final int nj) { - return 0.5 * (d[i][k] + d[j][k]); - } - - @Override - public void drootbranchfn(final double[][] d, final int i, final int j, - final int ni, final int nj, final doubleW bi, final doubleW bj) { - bi.val = bj.val = 0.5 * d[i][j]; - } - - public Phylo_wpgma(final double[][] dist) { - super(dist); - makethetree(dist); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ci/Svm.java b/common-tools/cnuphys/numRec/src/com/nr/ci/Svm.java deleted file mode 100644 index 5750b62576..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ci/Svm.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.nr.ci; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; -import com.nr.ran.Ran; -import com.nr.sort.Indexx; - -/** - * Support Vector Machines Copyright (C) Numerical Recipes Software 1986-2007 - * Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Svm { - private Svmgenkernel gker; - private int m, fnz, fub, niter; - private double[] alph, alphold; - private Ran ran; - private boolean alphinit; - private double dalph; - - public Svm(final Svmgenkernel inker) { - gker = inker; - m = gker.y.length; - alph = new double[m]; - alphold = new double[m]; - ran = new Ran(21); - alphinit = false; - } - - public double relax(final double lambda, final double om) { - int iter, j, jj, k, kk; - double sum; - double[] pinsum = new double[m]; - if (alphinit == false) { - for (j = 0; j < m; j++) - alph[j] = 0.; - alphinit = true; - } - alphold = alph; - Indexx x = new Indexx(alph); - for (fnz = 0; fnz < m; fnz++) - if (alph[x.indx[fnz]] != 0.) - break; - for (j = fnz; j < m - 2; j++) { - k = j + (ran.int32p() % (m - j)); - swap(x.indx, j, k); - } - for (jj = 0; jj < m; jj++) { - j = x.indx[jj]; - sum = 0.; - for (kk = fnz; kk < m; kk++) { - k = x.indx[kk]; - sum += (gker.ker[j][k] + 1.) * gker.y[k] * alph[k]; - } - alph[j] = alph[j] - (om / (gker.ker[j][j] + 1.)) - * (gker.y[j] * sum - 1.); - alph[j] = max(0., min(lambda, alph[j])); - if (jj < fnz && alph[j] != 0) { - --fnz; - // SWAP(x.indx[--fnz],x.indx[jj]); - swap(x.indx, fnz, jj); - } - } - Indexx y = new Indexx(alph); - for (fnz = 0; fnz < m; fnz++) - if (alph[y.indx[fnz]] != 0.) - break; - for (fub = fnz; fub < m; fub++) - if (alph[y.indx[fub]] == lambda) - break; - for (j = fnz; j < fub - 2; j++) { - k = j + (ran.int32p() % (fub - j)); - swap(y.indx, j, k); - } - for (jj = fnz; jj < fub; jj++) { - j = y.indx[jj]; - sum = 0.; - for (kk = fub; kk < m; kk++) { - k = y.indx[kk]; - sum += (gker.ker[j][k] + 1.) * gker.y[k] * alph[k]; - } - pinsum[jj] = sum; - } - niter = max((int) (0.5 * (m + 1.0) * (m - fnz + 1.0) / (SQR(fub - fnz - + 1.0))), 1); - for (iter = 0; iter < niter; iter++) { - for (jj = fnz; jj < fub; jj++) { - j = y.indx[jj]; - sum = pinsum[jj]; - for (kk = fnz; kk < fub; kk++) { - k = y.indx[kk]; - sum += (gker.ker[j][k] + 1.) * gker.y[k] * alph[k]; - } - alph[j] = alph[j] - (om / (gker.ker[j][j] + 1.)) - * (gker.y[j] * sum - 1.); - alph[j] = max(0., min(lambda, alph[j])); - } - } - dalph = 0.; - for (j = 0; j < m; j++) - dalph += SQR(alph[j] - alphold[j]); - return sqrt(dalph); - } - - public double predict(final int k) { - double sum = 0.; - for (int j = 0; j < m; j++) - sum += alph[j] * gker.y[j] * (gker.ker[j][k] + 1.0); - return sum; - } - - public double predict(final double[] x) { - double sum = 0.; - for (int j = 0; j < m; j++) - sum += alph[j] * gker.y[j] * (gker.kernel(j, x) + 1.0); - return sum; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ci/Svmgausskernel.java b/common-tools/cnuphys/numRec/src/com/nr/ci/Svmgausskernel.java deleted file mode 100644 index ec215966c1..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ci/Svmgausskernel.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.nr.ci; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -public class Svmgausskernel extends Svmgenkernel { - int n; - - double sigma; - - public Svmgausskernel(final double[][] ddata, final double[] yy, - final double ssigma) { - super(yy, ddata); - n = data[0].length; - sigma = ssigma; - fill(); - } - - @Override - public double kernel(final double[] xi, final double[] xj) { - double dott = 0.; - for (int k = 0; k < n; k++) - dott += SQR(xi[k] - xj[k]); - return exp(-0.5 * dott / (sigma * sigma)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ci/Svmgenkernel.java b/common-tools/cnuphys/numRec/src/com/nr/ci/Svmgenkernel.java deleted file mode 100644 index 1e5cd658be..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ci/Svmgenkernel.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.nr.ci; - -public abstract class Svmgenkernel { - int m, kcalls; - - double[][] ker; - - double[] y; - - double[][] data; - - public Svmgenkernel(final double[] yy, final double[][] ddata) { - m = yy.length; - kcalls = 0; - ker = new double[m][m]; - y = yy; - data = ddata; - } - - public abstract double kernel(final double[] xi, final double[] xj); - - public double kernel(final int i, final double[] xj) { - return kernel(data[i], xj); - } - - public void fill() { - int i, j; - for (i = 0; i < m; i++) - for (j = 0; j <= i; j++) { - ker[i][j] = ker[j][i] = kernel(data[i], data[j]); - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ci/Svmlinkernel.java b/common-tools/cnuphys/numRec/src/com/nr/ci/Svmlinkernel.java deleted file mode 100644 index 79dd40bd13..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ci/Svmlinkernel.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.nr.ci; - -public class Svmlinkernel extends Svmgenkernel { - int n; - - double[] mu; - - public Svmlinkernel(final double[][] ddata, final double[] yy) { - super(yy, ddata); - n = data[0].length; - mu = new double[n]; - int i, j; - for (j = 0; j < n; j++) - mu[j] = 0.; - for (i = 0; i < m; i++) - for (j = 0; j < n; j++) - mu[j] += data[i][j]; - for (j = 0; j < n; j++) - mu[j] /= m; - fill(); - } - - @Override - public double kernel(final double[] xi, final double[] xj) { - double dott = 0.; - for (int k = 0; k < n; k++) - dott += (xi[k] - mu[k]) * (xj[k] - mu[k]); - return dott; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ci/Svmpolykernel.java b/common-tools/cnuphys/numRec/src/com/nr/ci/Svmpolykernel.java deleted file mode 100644 index 4bf26015a6..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ci/Svmpolykernel.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.nr.ci; - -import static java.lang.Math.*; - -public class Svmpolykernel extends Svmgenkernel { - int n; - - double a, b, d; - - public Svmpolykernel(final double[][] ddata, final double[] yy, - final double aa, final double bb, final double dd) { - super(yy, ddata); - n = data[0].length; - a = aa; - b = bb; - d = dd; - fill(); - } - - @Override - public double kernel(final double[] xi, final double[] xj) { - double dott = 0.; - for (int k = 0; k < n; k++) - dott += xi[k] * xj[k]; - return pow(a * dott + b, d); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/eig/Jacobi.java b/common-tools/cnuphys/numRec/src/com/nr/eig/Jacobi.java deleted file mode 100644 index 582d653fda..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/eig/Jacobi.java +++ /dev/null @@ -1,157 +0,0 @@ -package com.nr.eig; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -/** - * Computes all eigenvalues and eigenvectors of a real symmetric matrix by - * Jacobi's method. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Jacobi { - public final int n; - public double[][] a, v; - public double[] d; - public int nrot; - final double EPS; - - /** - * Computes all eigenvalues and eigenvectors of a real symmetric matrix - * a[0..n-1][0..n-1]. On output, d[0..n-1] contains the eigenvalues of a - * sorted into descending order, while v[0..n-1][0..n-1] is a matrix whose - * columns contain the corresponding normalized eigenvectors. nrot contains - * the number of Jacobi rotations that were required. Only the upper - * triangle of a is accessed. - * - * @param aa - */ - public Jacobi(final double[][] aa) { - n = aa.length; - a = buildMatrix(aa); - v = new double[n][n]; - d = new double[n]; - nrot = 0; - EPS = DBL_EPSILON; - - int i, j, ip, iq; - double tresh, theta, tau, t, sm, s, h, g, c; - double[] b = new double[n]; - double[] z = new double[n]; - - for (ip = 0; ip < n; ip++) { - for (iq = 0; iq < n; iq++) - v[ip][iq] = 0.0; - v[ip][ip] = 1.0; - } - for (ip = 0; ip < n; ip++) { - b[ip] = d[ip] = a[ip][ip]; - z[ip] = 0.0; - } - for (i = 1; i <= 50; i++) { - sm = 0.0; - for (ip = 0; ip < n - 1; ip++) { - for (iq = ip + 1; iq < n; iq++) - sm += abs(a[ip][iq]); - } - if (sm == 0.0) { - eigsrt(d, v); - return; - } - if (i < 4) - tresh = 0.2 * sm / (n * n); - else - tresh = 0.0; - for (ip = 0; ip < n - 1; ip++) { - for (iq = ip + 1; iq < n; iq++) { - g = 100.0 * abs(a[ip][iq]); - if (i > 4 && g <= EPS * abs(d[ip]) && g <= EPS * abs(d[iq])) - a[ip][iq] = 0.0; - else if (abs(a[ip][iq]) > tresh) { - h = d[iq] - d[ip]; - if (g <= EPS * abs(h)) - t = (a[ip][iq]) / h; - else { - theta = 0.5 * h / (a[ip][iq]); - t = 1.0 / (abs(theta) + sqrt(1.0 + theta * theta)); - if (theta < 0.0) - t = -t; - } - c = 1.0 / sqrt(1 + t * t); - s = t * c; - tau = s / (1.0 + c); - h = t * a[ip][iq]; - z[ip] -= h; - z[iq] += h; - d[ip] -= h; - d[iq] += h; - a[ip][iq] = 0.0; - for (j = 0; j < ip; j++) - rot(a, s, tau, j, ip, j, iq); - for (j = ip + 1; j < iq; j++) - rot(a, s, tau, ip, j, j, iq); - for (j = iq + 1; j < n; j++) - rot(a, s, tau, ip, j, iq, j); - for (j = 0; j < n; j++) - rot(v, s, tau, j, ip, j, iq); - ++nrot; - } - } - } - for (ip = 0; ip < n; ip++) { - b[ip] += z[ip]; - d[ip] = b[ip]; - z[ip] = 0.0; - } - } - throw new IllegalArgumentException( - "Too many iterations in routine jacobi"); - } - - public static void rot(final double[][] a, final double s, - final double tau, final int i, final int j, final int k, final int l) { - double g = a[i][j]; - double h = a[k][l]; - a[i][j] = g - s * (h + g * tau); - a[k][l] = h + s * (g - h * tau); - } - - /** - * Given the eigenvalues d[0..n-1] and (optionally) the eigenvectors - * v[0..n-1][0..n-1] as determined by Jacobi or tqli, this routine sorts the - * eigenvalues into descending order and rearranges the columns of v - * correspondingly. The method is straight insertion. - * - * @param d - * @param v - */ - public static void eigsrt(final double[] d, final double[][] v) { - int k; - int n = d.length; - for (int i = 0; i < n - 1; i++) { - double p = d[k = i]; - for (int j = i; j < n; j++) - if (d[j] >= p) - p = d[k = j]; - if (k != i) { - d[k] = d[i]; - d[i] = p; - if (v != null) - for (int j = 0; j < n; j++) { - p = v[j][i]; - v[j][i] = v[j][k]; - v[j][k] = p; - } - } - } - } - - public static void eigsrt(final double[] d) { - eigsrt(d, null); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/eig/Symmeig.java b/common-tools/cnuphys/numRec/src/com/nr/eig/Symmeig.java deleted file mode 100644 index 15bc415c01..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/eig/Symmeig.java +++ /dev/null @@ -1,237 +0,0 @@ -package com.nr.eig; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -/** - * Computes all eigenvalues and eigenvectors of a real symmetric matrix by - * reduction to tridiagonal form followed by QL iteration. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Symmeig { - public int n; - public double[][] z; - public double[] d, e; - public boolean yesvecs; - - public Symmeig(final double[][] a) { - this(a, true); - } - - /** - * Computes all eigenvalues and eigenvectors of a real symmetric matrix - * a[0..n-1][0..n-1] by reduction to tridiagonal form followed by QL - * iteration. On output, d[0..n-1] contains the eigenvalues of a sorted into - * descending order, while z[0..n-1][0..n-1] is a matrix whose columns - * contain the corresponding normalized eigenvectors. If yesvecs is input as - * true (the default), then the eigenvectors are computed. If yesvecs is - * input as false, only the eigenvalues are computed. - * - * @param a - * @param yesvec - */ - public Symmeig(final double[][] a, final boolean yesvec) { - n = a.length; - z = buildMatrix(a); - d = new double[n]; - e = new double[n]; - yesvecs = yesvec; - - tred2(); - tqli(); - sort(); - } - - /** - * Computes all eigenvalues and (optionally) eigenvectors of a real, - * symmetric, tridiagonal matrix by QL iteration. On input, dd[0..n-1] - * contains the diagonal elements of the tridi- agonal matrix. The vector - * ee[0..n-1] inputs the subdiagonal elements of the tridiagonal matrix, - * with ee[0] arbitrary. Output is the same as the constructor above. - * - * @param dd - * @param ee - */ - public Symmeig(final double[] dd, final double[] ee) { - this(dd, ee, true); - } - - public Symmeig(final double[] dd, final double[] ee, final boolean yesvec) { - n = dd.length; - d = buildVector(dd); - e = buildVector(ee); - z = new double[n][n]; - yesvecs = yesvec; - - for (int i = 0; i < n; i++) - z[i][i] = 1.0; - tqli(); - sort(); - } - - private void sort() { - if (yesvecs) - Jacobi.eigsrt(d, z); - else - Jacobi.eigsrt(d); - } - - /** - * Householder reduction of a real symmetric matrix z[0..n-1][0..n-1]. (The - * input matrix A to Symmeig is stored in z.) On output, z is replaced by - * the orthogonal matrix Q effecting the transformation. d[0..n-1] contains - * the diagonal elements of the tridiagonal matrix and e[0..n-1] the - * off-diagonal elements, with e[0]=0. If yesvecs is false, so that only - * eigenvalues will subsequently be determined, several statements are - * omitted, in which case z contains no useful information on output. - */ - private void tred2() { - int l, k, j, i; - double scale, hh, h, g, f; - for (i = n - 1; i > 0; i--) { - l = i - 1; - h = scale = 0.0; - if (l > 0) { - for (k = 0; k < i; k++) - scale += abs(z[i][k]); - if (scale == 0.0) - e[i] = z[i][l]; - else { - for (k = 0; k < i; k++) { - z[i][k] /= scale; - h += z[i][k] * z[i][k]; - } - f = z[i][l]; - g = (f >= 0.0 ? -sqrt(h) : sqrt(h)); - e[i] = scale * g; - h -= f * g; - z[i][l] = f - g; - f = 0.0; - for (j = 0; j < i; j++) { - if (yesvecs) - z[j][i] = z[i][j] / h; - g = 0.0; - for (k = 0; k < j + 1; k++) - g += z[j][k] * z[i][k]; - for (k = j + 1; k < i; k++) - g += z[k][j] * z[i][k]; - e[j] = g / h; - f += e[j] * z[i][j]; - } - hh = f / (h + h); - for (j = 0; j < i; j++) { - f = z[i][j]; - e[j] = g = e[j] - hh * f; - for (k = 0; k < j + 1; k++) - z[j][k] -= (f * e[k] + g * z[i][k]); - } - } - } else - e[i] = z[i][l]; - d[i] = h; - } - if (yesvecs) - d[0] = 0.0; - e[0] = 0.0; - for (i = 0; i < n; i++) { - if (yesvecs) { - if (d[i] != 0.0) { - for (j = 0; j < i; j++) { - g = 0.0; - for (k = 0; k < i; k++) - g += z[i][k] * z[k][j]; - for (k = 0; k < i; k++) - z[k][j] -= g * z[k][i]; - } - } - d[i] = z[i][i]; - z[i][i] = 1.0; - for (j = 0; j < i; j++) - z[j][i] = z[i][j] = 0.0; - } else { - d[i] = z[i][i]; - } - } - } - - /** - * QL algorithm with implicit shifts to determine the eigenvalues and - * (optionally) the eigenvectors of a real, symmetric, tridiagonal matrix, - * or of a real symmetric matrix previously reduced by tred2. On input, - * d[0..n-1] contains the diagonal elements of the tridiagonal matrix. On - * output, it returns the eigenvalues. The vector e[0..n-1] inputs the - * subdiagonal elements of the tridiagonal matrix, with e[0] arbitrary. On - * output e is destroyed. If the eigenvectors of a tridiagonal matrix are - * desired, the matrix z[0..n-1][0..n-1] is input as the identity matrix. If - * the eigenvectors of a matrix that has been reduced by tred2 are required, - * then z is input as the matrix output by tred2. In either case, column k - * of z returns the normalized eigenvector corresponding to d[k] - */ - private void tqli() { - int m, l, iter, i, k; - double s, r, p, g, f, dd, c, b; - final double EPS = DBL_EPSILON; - for (i = 1; i < n; i++) - e[i - 1] = e[i]; - e[n - 1] = 0.0; - for (l = 0; l < n; l++) { - iter = 0; - do { - for (m = l; m < n - 1; m++) { - dd = abs(d[m]) + abs(d[m + 1]); - if (abs(e[m]) <= EPS * dd) - break; - } - if (m != l) { - if (iter++ == 30) - throw new IllegalArgumentException( - "Too many iterations in tqli"); - g = (d[l + 1] - d[l]) / (2.0 * e[l]); - r = pythag(g, 1.0); - g = d[m] - d[l] + e[l] / (g + SIGN(r, g)); - s = c = 1.0; - p = 0.0; - for (i = m - 1; i >= l; i--) { - f = s * e[i]; - b = c * e[i]; - e[i + 1] = (r = pythag(f, g)); - if (r == 0.0) { - d[i + 1] -= p; - e[m] = 0.0; - break; - } - s = f / r; - c = g / r; - g = d[i + 1] - p; - r = (d[i] - g) * s + 2.0 * c * b; - d[i + 1] = g + (p = s * r); - g = c * r - b; - if (yesvecs) { - for (k = 0; k < n; k++) { - f = z[k][i + 1]; - z[k][i + 1] = s * z[k][i] + c * f; - z[k][i] = c * z[k][i] - s * f; - } - } - } - if (r == 0.0 && i >= l) - continue; - d[l] -= p; - e[l] = g; - e[m] = 0.0; - } - } while (m != l); - } - } - - private double pythag(final double a, final double b) { - double absa = abs(a), absb = abs(b); - return (absa > absb ? absa * sqrt(1.0 + SQR(absb / absa)) - : (absb == 0.0 ? 0.0 : absb * sqrt(1.0 + SQR(absa / absb)))); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/eig/Unsymmeig.java b/common-tools/cnuphys/numRec/src/com/nr/eig/Unsymmeig.java deleted file mode 100644 index 65c20ec8fd..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/eig/Unsymmeig.java +++ /dev/null @@ -1,658 +0,0 @@ -package com.nr.eig; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import com.nr.Complex; - -/** - * Computes all eigenvalues and eigenvectors of a real nonsymmetric matrix by - * reduction to Hes- senberg form followed by QR iteration. - PTC - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Unsymmeig { - public int n; - public double[][] a, zz; - public Complex[] wri; - public double[] scale; - public int[] perm; - public boolean yesvecs, hessen; - - public Unsymmeig(final double[][] aa) { - this(aa, true, false); - } - - /** - * Computes all eigenvalues and (optionally) eigenvectors of a real - * nonsymmetric matrix a[0..n-1][0..n-1] by reduction to Hessenberg form - * followed by QR iteration. If yesvecs is input as true (the default), then - * the eigenvectors are computed. Otherwise, only the eigenvalues are - * computed. If hessen is input as false (the default), the matrix is first - * reduced to Hessenberg form. Otherwise it is assumed that the matrix is - * already in Hessen- berg from. On output, wri[0..n-1] contains the - * eigenvalues of a sorted into descending order, while zz[0..n-1][0..n-1] - * is a matrix whose columns contain the corresponding eigenvectors. For a - * complex eigenvalue, only the eigenvector corresponding to the eigen- - * value with a positive imaginary part is stored, with the real part in - * zz[0..n-1][i] and the imaginary part in h.zz[0..n-1][i+1]. The - * eigenvectors are not normalized. - * - * @param aa - * @param yesvec - * @param hessenb - */ - public Unsymmeig(final double[][] aa, final boolean yesvec, - final boolean hessenb) { - n = aa.length; - a = buildMatrix(aa); - zz = new double[n][n]; - wri = new Complex[n]; - for (int i = 0; i < n; i++) - wri[i] = new Complex(0, 0); - scale = buildVector(n, 1.0); - perm = new int[n]; - yesvecs = yesvec; - hessen = hessenb; - - balance(); - if (!hessen) - elmhes(); - if (yesvecs) { - for (int i = 0; i < n; i++) - zz[i][i] = 1.0; - if (!hessen) - eltran(); - hqr2(); - balbak(); - sortvecs(); - } else { - hqr(); - sort(); - } - } - - /** - * Given a matrix a[0..n-1][0..n-1], this routine replaces it by a balanced - * matrix with identical eigenvalues. A symmetric matrix is already balanced - * and is unaffected by this procedure. - */ - private void balance() { - final double RADIX = FLT_RADIX; - boolean done = false; - double sqrdx = RADIX * RADIX; - while (!done) { - done = true; - for (int i = 0; i < n; i++) { - double r = 0.0, c = 0.0; - for (int j = 0; j < n; j++) - if (j != i) { - c += abs(a[j][i]); - r += abs(a[i][j]); - } - if (c != 0.0 && r != 0.0) { - double g = r / RADIX; - double f = 1.0; - double s = c + r; - while (c < g) { - f *= RADIX; - c *= sqrdx; - } - g = r * RADIX; - while (c > g) { - f /= RADIX; - c /= sqrdx; - } - if ((c + r) / f < 0.95 * s) { - done = false; - g = 1.0 / f; - scale[i] *= f; - for (int j = 0; j < n; j++) - a[i][j] *= g; - for (int j = 0; j < n; j++) - a[j][i] *= f; - } - } - } - } - } - - /** - * Forms the eigenvectors of a real nonsymmetric matrix by back transforming - * those of the corre- sponding balanced matrix determined by balance. - */ - private void balbak() { - for (int i = 0; i < n; i++) - for (int j = 0; j < n; j++) - zz[i][j] *= scale[i]; - } - - /** - * Reduction to Hessenberg form by the elimination method. Replaces the real - * nonsymmetric matrix a[0..n-1][0..n-1] by an upper Hessenberg matrix with - * identical eigenvalues. Rec- ommended, but not required, is that this - * routine be preceded by balance. On output, the Hessenberg matrix is in - * elements a[i][j] with i <= j+1. Elements with i > j+1 are to be thought - * of as zero, but are returned with random values. - */ - private void elmhes() { - for (int m = 1; m < n - 1; m++) { - double x = 0.0; - int i = m; - for (int j = m; j < n; j++) { - if (abs(a[j][m - 1]) > abs(x)) { - x = a[j][m - 1]; - i = j; - } - } - perm[m] = i; - if (i != m) { - for (int j = m - 1; j < n; j++) { - // SWAP(a[i][j],a[m][j]); - double swap = a[i][j]; - a[i][j] = a[m][j]; - a[m][j] = swap; - } - for (int j = 0; j < n; j++) { - // SWAP(a[j][i],a[j][m]); - double swap = a[j][i]; - a[j][i] = a[j][m]; - a[j][m] = swap; - } - } - if (x != 0.0) { - for (i = m + 1; i < n; i++) { - double y = a[i][m - 1]; - if (y != 0.0) { - y /= x; - a[i][m - 1] = y; - for (int j = m; j < n; j++) - a[i][j] -= y * a[m][j]; - for (int j = 0; j < n; j++) - a[j][m] += y * a[j][i]; - } - } - } - } - } - - /** - * This routine accumulates the stabilized elementary similarity - * transformations used in the reduction to upper Hessenberg form by elmhes. - * The multipliers that were used in the reduction are obtained from the - * lower triangle (below the subdiagonal) of a. The transformations are - * permuted according to the permutations stored in perm by elmhes. - */ - private void eltran() { - for (int mp = n - 2; mp > 0; mp--) { - for (int k = mp + 1; k < n; k++) - zz[k][mp] = a[k][mp - 1]; - int i = perm[mp]; - if (i != mp) { - for (int j = mp; j < n; j++) { - zz[mp][j] = zz[i][j]; - zz[i][j] = 0.0; - } - zz[i][mp] = 1.0; - } - } - } - - private void hqr() { - int nn, m, l, k, j, its, i, mmin; - double z, y, x, w, v, u, t, s, r = 0, q = 0, p = 0, anorm = 0.0; - - final double EPS = DBL_EPSILON; - for (i = 0; i < n; i++) - for (j = max(i - 1, 0); j < n; j++) - anorm += abs(a[i][j]); - nn = n - 1; - t = 0.0; - while (nn >= 0) { - its = 0; - do { - for (l = nn; l > 0; l--) { - s = abs(a[l - 1][l - 1]) + abs(a[l][l]); - if (s == 0.0) - s = anorm; - if (abs(a[l][l - 1]) <= EPS * s) { - a[l][l - 1] = 0.0; - break; - } - } - x = a[nn][nn]; - if (l == nn) { - wri[nn--] = new Complex(x + t, 0); - } else { - y = a[nn - 1][nn - 1]; - w = a[nn][nn - 1] * a[nn - 1][nn]; - if (l == nn - 1) { - p = 0.5 * (y - x); - q = p * p + w; - z = sqrt(abs(q)); - x += t; - if (q >= 0.0) { - z = p + SIGN(z, p); - wri[nn - 1] = new Complex(x + z, 0); - wri[nn] = new Complex(x + z, 0); - if (z != 0.0) - wri[nn] = new Complex(x - w / z, 0); - } else { - wri[nn] = new Complex(x + p, -z); - wri[nn - 1] = wri[nn].conj(); - } - nn -= 2; - } else { - if (its == 30) - throw new IllegalArgumentException( - "Too many iterations in hqr"); - if (its == 10 || its == 20) { - t += x; - for (i = 0; i < nn + 1; i++) - a[i][i] -= x; - s = abs(a[nn][nn - 1]) + abs(a[nn - 1][nn - 2]); - y = x = 0.75 * s; - w = -0.4375 * s * s; - } - ++its; - for (m = nn - 2; m >= l; m--) { - z = a[m][m]; - r = x - z; - s = y - z; - p = (r * s - w) / a[m + 1][m] + a[m][m + 1]; - q = a[m + 1][m + 1] - z - r - s; - r = a[m + 2][m + 1]; - s = abs(p) + abs(q) + abs(r); - p /= s; - q /= s; - r /= s; - if (m == l) - break; - u = abs(a[m][m - 1]) * (abs(q) + abs(r)); - v = abs(p) - * (abs(a[m - 1][m - 1]) + abs(z) + abs(a[m + 1][m + 1])); - if (u <= EPS * v) - break; - } - for (i = m; i < nn - 1; i++) { - a[i + 2][i] = 0.0; - if (i != m) - a[i + 2][i - 1] = 0.0; - } - for (k = m; k < nn; k++) { - if (k != m) { - p = a[k][k - 1]; - q = a[k + 1][k - 1]; - r = 0.0; - if (k + 1 != nn) - r = a[k + 2][k - 1]; - if ((x = abs(p) + abs(q) + abs(r)) != 0.0) { - p /= x; - q /= x; - r /= x; - } - } - if ((s = SIGN(sqrt(p * p + q * q + r * r), p)) != 0.0) { - if (k == m) { - if (l != m) - a[k][k - 1] = -a[k][k - 1]; - } else - a[k][k - 1] = -s * x; - p += s; - x = p / s; - y = q / s; - z = r / s; - q /= p; - r /= p; - for (j = k; j < nn + 1; j++) { - p = a[k][j] + q * a[k + 1][j]; - if (k + 1 != nn) { - p += r * a[k + 2][j]; - a[k + 2][j] -= p * z; - } - a[k + 1][j] -= p * y; - a[k][j] -= p * x; - } - mmin = nn < k + 3 ? nn : k + 3; - for (i = l; i < mmin + 1; i++) { - p = x * a[i][k] + y * a[i][k + 1]; - if (k + 1 != nn) { - p += z * a[i][k + 2]; - a[i][k + 2] -= p * r; - } - a[i][k + 1] -= p * q; - a[i][k] -= p; - } - } - } - } - } - } while (l + 1 < nn); - } - } - - private void hqr2() { - int nn, m, l, k, j, its, i, mmin, na; - double z = 0, y, x, w, v, u, t, s = 0, r = 0, q = 0, p = 0, anorm = 0.0, ra, sa, vr, vi; - - final double EPS = DBL_EPSILON; - for (i = 0; i < n; i++) - for (j = max(i - 1, 0); j < n; j++) - anorm += abs(a[i][j]); - nn = n - 1; - t = 0.0; - while (nn >= 0) { - its = 0; - do { - for (l = nn; l > 0; l--) { - s = abs(a[l - 1][l - 1]) + abs(a[l][l]); - if (s == 0.0) - s = anorm; - if (abs(a[l][l - 1]) <= EPS * s) { - a[l][l - 1] = 0.0; - break; - } - } - x = a[nn][nn]; - if (l == nn) { - wri[nn] = new Complex(x + t, 0); - a[nn][nn] = x + t; - nn--; - } else { - y = a[nn - 1][nn - 1]; - w = a[nn][nn - 1] * a[nn - 1][nn]; - if (l == nn - 1) { - p = 0.5 * (y - x); - q = p * p + w; - z = sqrt(abs(q)); - x += t; - a[nn][nn] = x; - a[nn - 1][nn - 1] = y + t; - if (q >= 0.0) { - z = p + SIGN(z, p); - wri[nn - 1] = new Complex(x + z, 0); - wri[nn] = new Complex(x + z, 0); - if (z != 0.0) - wri[nn] = new Complex(x - w / z, 0); - x = a[nn][nn - 1]; - s = abs(x) + abs(z); - p = x / s; - q = z / s; - r = sqrt(p * p + q * q); - p /= r; - q /= r; - for (j = nn - 1; j < n; j++) { - z = a[nn - 1][j]; - a[nn - 1][j] = q * z + p * a[nn][j]; - a[nn][j] = q * a[nn][j] - p * z; - } - for (i = 0; i <= nn; i++) { - z = a[i][nn - 1]; - a[i][nn - 1] = q * z + p * a[i][nn]; - a[i][nn] = q * a[i][nn] - p * z; - } - for (i = 0; i < n; i++) { - z = zz[i][nn - 1]; - zz[i][nn - 1] = q * z + p * zz[i][nn]; - zz[i][nn] = q * zz[i][nn] - p * z; - } - } else { - wri[nn] = new Complex(x + p, -z); - wri[nn - 1] = wri[nn].conj(); - } - nn -= 2; - } else { - if (its == 30) - throw new IllegalArgumentException( - "Too many iterations in hqr"); - if (its == 10 || its == 20) { - t += x; - for (i = 0; i < nn + 1; i++) - a[i][i] -= x; - s = abs(a[nn][nn - 1]) + abs(a[nn - 1][nn - 2]); - y = x = 0.75 * s; - w = -0.4375 * s * s; - } - ++its; - for (m = nn - 2; m >= l; m--) { - z = a[m][m]; - r = x - z; - s = y - z; - p = (r * s - w) / a[m + 1][m] + a[m][m + 1]; - q = a[m + 1][m + 1] - z - r - s; - r = a[m + 2][m + 1]; - s = abs(p) + abs(q) + abs(r); - p /= s; - q /= s; - r /= s; - if (m == l) - break; - u = abs(a[m][m - 1]) * (abs(q) + abs(r)); - v = abs(p) - * (abs(a[m - 1][m - 1]) + abs(z) + abs(a[m + 1][m + 1])); - if (u <= EPS * v) - break; - } - for (i = m; i < nn - 1; i++) { - a[i + 2][i] = 0.0; - if (i != m) - a[i + 2][i - 1] = 0.0; - } - for (k = m; k < nn; k++) { - if (k != m) { - p = a[k][k - 1]; - q = a[k + 1][k - 1]; - r = 0.0; - if (k + 1 != nn) - r = a[k + 2][k - 1]; - if ((x = abs(p) + abs(q) + abs(r)) != 0.0) { - p /= x; - q /= x; - r /= x; - } - } - if ((s = SIGN(sqrt(p * p + q * q + r * r), p)) != 0.0) { - if (k == m) { - if (l != m) - a[k][k - 1] = -a[k][k - 1]; - } else - a[k][k - 1] = -s * x; - p += s; - x = p / s; - y = q / s; - z = r / s; - q /= p; - r /= p; - for (j = k; j < n; j++) { - p = a[k][j] + q * a[k + 1][j]; - if (k + 1 != nn) { - p += r * a[k + 2][j]; - a[k + 2][j] -= p * z; - } - a[k + 1][j] -= p * y; - a[k][j] -= p * x; - } - mmin = nn < k + 3 ? nn : k + 3; - for (i = 0; i < mmin + 1; i++) { - p = x * a[i][k] + y * a[i][k + 1]; - if (k + 1 != nn) { - p += z * a[i][k + 2]; - a[i][k + 2] -= p * r; - } - a[i][k + 1] -= p * q; - a[i][k] -= p; - } - for (i = 0; i < n; i++) { - p = x * zz[i][k] + y * zz[i][k + 1]; - if (k + 1 != nn) { - p += z * zz[i][k + 2]; - zz[i][k + 2] -= p * r; - } - zz[i][k + 1] -= p * q; - zz[i][k] -= p; - } - } - } - } - } - } while (l + 1 < nn); - } - if (anorm != 0.0) { - for (nn = n - 1; nn >= 0; nn--) { - p = wri[nn].re(); - q = wri[nn].im(); - na = nn - 1; - if (q == 0.0) { - m = nn; - a[nn][nn] = 1.0; - for (i = nn - 1; i >= 0; i--) { - w = a[i][i] - p; - r = 0.0; - for (j = m; j <= nn; j++) - r += a[i][j] * a[j][nn]; - if (wri[i].im() < 0.0) { - z = w; - s = r; - } else { - m = i; - - if (wri[i].im() == 0.0) { - t = w; - if (t == 0.0) - t = EPS * anorm; - a[i][nn] = -r / t; - } else { - x = a[i][i + 1]; - y = a[i + 1][i]; - q = SQR(wri[i].re() - p) + SQR(wri[i].im()); - t = (x * s - z * r) / q; - a[i][nn] = t; - if (abs(x) > abs(z)) - a[i + 1][nn] = (-r - w * t) / x; - else - a[i + 1][nn] = (-s - y * t) / z; - } - t = abs(a[i][nn]); - if (EPS * t * t > 1) - for (j = i; j <= nn; j++) - a[j][nn] /= t; - } - } - } else if (q < 0.0) { - m = na; - if (abs(a[nn][na]) > abs(a[na][nn])) { - a[na][na] = q / a[nn][na]; - a[na][nn] = -(a[nn][nn] - p) / a[nn][na]; - } else { - Complex temp = new Complex(0.0, -a[na][nn]) - .div(new Complex(a[na][na] - p, q)); - a[na][na] = temp.re(); - a[na][nn] = temp.im(); - } - a[nn][na] = 0.0; - a[nn][nn] = 1.0; - for (i = nn - 2; i >= 0; i--) { - w = a[i][i] - p; - ra = sa = 0.0; - for (j = m; j <= nn; j++) { - ra += a[i][j] * a[j][na]; - sa += a[i][j] * a[j][nn]; - } - if (wri[i].im() < 0.0) { - z = w; - r = ra; - s = sa; - } else { - m = i; - if (wri[i].im() == 0.0) { - Complex temp = new Complex(-ra, -sa) - .div(new Complex(w, q)); - a[i][na] = temp.re(); - a[i][nn] = temp.im(); - } else { - x = a[i][i + 1]; - y = a[i + 1][i]; - vr = SQR(wri[i].re() - p) + SQR(wri[i].im()) - - q * q; - vi = 2.0 * q * (wri[i].re() - p); - if (vr == 0.0 && vi == 0.0) - vr = EPS - * anorm - * (abs(w) + abs(q) + abs(x) - + abs(y) + abs(z)); - Complex temp = new Complex(x * r - z * ra + q - * sa, x * s - z * sa - q * ra) - .div(new Complex(vr, vi)); - a[i][na] = temp.re(); - a[i][nn] = temp.im(); - if (abs(x) > abs(z) + abs(q)) { - a[i + 1][na] = (-ra - w * a[i][na] + q - * a[i][nn]) - / x; - a[i + 1][nn] = (-sa - w * a[i][nn] - q - * a[i][na]) - / x; - } else { - temp = new Complex(-r - y * a[i][na], -s - - y * a[i][nn]).div(new Complex(z, - q)); - a[i + 1][na] = temp.re(); - a[i + 1][nn] = temp.im(); - } - } - } - t = max(abs(a[i][na]), abs(a[i][nn])); - if (EPS * t * t > 1) - for (j = i; j <= nn; j++) { - a[j][na] /= t; - a[j][nn] /= t; - } - } - } - } - for (j = n - 1; j >= 0; j--) - for (i = 0; i < n; i++) { - z = 0.0; - for (k = 0; k <= j; k++) - z += zz[i][k] * a[k][j]; - zz[i][j] = z; - } - } - } - - private void sort() { - int i; - for (int j = 1; j < n; j++) { - Complex x = wri[j]; - for (i = j - 1; i >= 0; i--) { - if (wri[i].re() >= x.re()) - break; - wri[i + 1] = wri[i]; - } - wri[i + 1] = x; - } - } - - private void sortvecs() { - int i; - double[] temp = new double[n]; - for (int j = 1; j < n; j++) { - Complex x = wri[j]; - for (int k = 0; k < n; k++) - temp[k] = zz[k][j]; - for (i = j - 1; i >= 0; i--) { - if (wri[i].re() >= x.re()) - break; - wri[i + 1] = wri[i]; - for (int k = 0; k < n; k++) - zz[k][i + 1] = zz[k][i]; - } - wri[i + 1] = x; - for (int k = 0; k < n; k++) - zz[k][i + 1] = temp[k]; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/example/Bandec_Ex.java b/common-tools/cnuphys/numRec/src/com/nr/example/Bandec_Ex.java deleted file mode 100644 index 9e16df432e..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/example/Bandec_Ex.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.nr.example; - -import com.nr.NRUtil; -import com.nr.la.Bandec; - -public class Bandec_Ex { - - public static void main(String[] args) { - double[] a = new double[] { 1.0, 2.0, 2.0, 4.0, -4.0, -3.0, 2.0, 4.0, - 5.0, 1, 2, 3, 4, 3, 2, 1 }; - double[][] aa = NRUtil.buildMatrix(4, 4, a); - int mm1 = 1; - int mm2 = 2; - Bandec bdc = new Bandec(aa, mm1, mm2); - - double[] b = new double[] { 4.0, -4.0, -3.0, 1.0 }; - double[] x = new double[4]; - bdc.solve(b, x); - System.out.println(NRUtil.toString(x)); - System.out.println(bdc.det()); - - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/example/Chebyshev_Ex.java b/common-tools/cnuphys/numRec/src/com/nr/example/Chebyshev_Ex.java deleted file mode 100644 index f53a9b25dd..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/example/Chebyshev_Ex.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Huang Wen Hui - * ---------------------------------------------------------------------------- - * - */ - -package com.nr.example; - -import static java.lang.Math.sin; -import com.nr.UniVarRealValueFun; -import com.nr.fe.Chebyshev; - -public class Chebyshev_Ex implements UniVarRealValueFun { - - public static void main(String[] args) { - Chebyshev_Ex c_ex = new Chebyshev_Ex(); - - // final int NVAL=40; - // double[] c = new double[NVAL]; - final double PIO2 = 1.570796326794896619; - int i, mval = 50; - double a = (-PIO2), b = PIO2; - double x; - - Chebyshev cv = new Chebyshev(c_ex, a, b, mval); - - for (i = -8; i <= 8; i++) { - x = i * PIO2 / 10.0; - System.out.printf("%f %f %f\n", x, c_ex.funk(x), cv.get(x)); - } - } - - @Override - public double funk(double x) { - return x * x * (x * x - 2.0) * sin(x); - } -} \ No newline at end of file diff --git a/common-tools/cnuphys/numRec/src/com/nr/example/Cholesky_Ex.java b/common-tools/cnuphys/numRec/src/com/nr/example/Cholesky_Ex.java deleted file mode 100644 index 6a7664b09d..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/example/Cholesky_Ex.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.nr.example; - -import com.nr.NRUtil; -import com.nr.la.Cholesky; - -public class Cholesky_Ex { - - public static void main(String[] args) { - double[] a = new double[] { 1.0, 0.5, 1.0, 0.5, 2.2, -1.0, 1.0, -1.0, - 5.0 }; - double[][] aa = NRUtil.buildMatrix(3, 3, a); - double[][] inv = new double[3][3]; - double[] b = new double[] { 2.0, 4.0, 1.0 }; - double[] x = new double[3]; - - Cholesky ch = new Cholesky(aa); - ch.solve(b, x); - System.out.println(NRUtil.toString(x)); - ch.elsolve(b, x); - System.out.println(NRUtil.toString(x)); - System.out.println(ch.logdet()); - - ch.inverse(inv); - - System.out.println(NRUtil.toString(inv)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/example/Cyclic_Ex.java b/common-tools/cnuphys/numRec/src/com/nr/example/Cyclic_Ex.java deleted file mode 100644 index c6c4763808..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/example/Cyclic_Ex.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.nr.example; - -import com.nr.NRUtil; -import com.nr.la.Tridag; - -public class Cyclic_Ex { - - public static void main(String[] args) { - double[] a = new double[] { 1.0, 2.0, 2.0 }; - double[] b = new double[] { 4.0, -4.0, -3.0 }; - double[] c = new double[] { 2.0, 4.0, 5.0 }; - double[] r = new double[] { 2.0, 4.0, 5.0 }; - double[] u = new double[3]; - double alpha = 5.0; - double beta = -5.1; - Tridag.cyclic(a, b, c, alpha, beta, r, u); - System.out.println(NRUtil.toString(u)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/example/FFT_Ex.java b/common-tools/cnuphys/numRec/src/com/nr/example/FFT_Ex.java deleted file mode 100644 index 1c89d69d95..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/example/FFT_Ex.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Huang Wen Hui - * ---------------------------------------------------------------------------- - * - */ - -package com.nr.example; - -import com.nr.Complex; -import com.nr.fft.FFT; - -public class FFT_Ex { - - public static void main(String[] args) { - Complex[] vc = new Complex[8]; - vc[0] = new Complex(1, 10.1); - vc[1] = new Complex(11, 1.1); - vc[2] = new Complex(12, 12.1); - vc[3] = new Complex(13, 17.15); - vc[4] = new Complex(1.3, 1.13); - vc[5] = new Complex(1.4, 1.21); - vc[6] = new Complex(1.7, 11.1); - vc[7] = new Complex(2.0, 12.1); - FFT.four1(vc, 1); - System.out.println(vc[0]); - System.out.println(vc[1]); - System.out.println(vc[4]); - System.out.println(vc[7]); - System.out.println(); - - double[] a = { 1, 10.1, 11, 1.1, 12, 12.1, 13, 17.15, 1.3, 1.13, 1.4, - 1.21, 1.7, 11.1, 2.0, 12.1 }; - FFT.four1(a, 8, 1); - System.out.println(a[8 + 0]); - System.out.println(a[8 + 1]); - System.out.println(a[8 + 4]); - System.out.println(a[8 + 7]); - - } - -} \ No newline at end of file diff --git a/common-tools/cnuphys/numRec/src/com/nr/example/GaussJordan_Ex.java b/common-tools/cnuphys/numRec/src/com/nr/example/GaussJordan_Ex.java deleted file mode 100644 index 5c9d8b761e..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/example/GaussJordan_Ex.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.nr.example; - -import com.nr.NRUtil; -import com.nr.la.GaussJordan; - -public class GaussJordan_Ex { - - public static void main(String[] args) { - double[] a = new double[] { 1.0, 2.0, 2.0, 4.0, -4.0, -3.0, 2.0, 4.0, - 5.0 }; - // double[]a = new double[]{0.666667, 0.166667, -0.166667, - // 2.16667, -0.0833333, -0.916667, - // -2.00000, 0.00000, 1.00000}; - double[][] aa = NRUtil.buildMatrix(3, 3, a); - double b[] = { 2, 2, 2 }; - double[][] bb = NRUtil.buildMatrix(3, 1, b); - GaussJordan.gaussj(aa, bb); - System.out.println(NRUtil.toString(bb)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/example/LUdcmp_Ex.java b/common-tools/cnuphys/numRec/src/com/nr/example/LUdcmp_Ex.java deleted file mode 100644 index 2c45625847..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/example/LUdcmp_Ex.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.nr.example; - -import com.nr.NRUtil; -import com.nr.la.LUdcmp; - -public class LUdcmp_Ex { - - public static void main(String[] args) { - // double[] a = new double[]{1.0, 2.0,2.0,4.0, -4.0, -3.0, 2.0, - // 4.0,5.0}; - double[] a = new double[] { 0.666667, 0.166667, -0.166667, 2.16667, - -0.0833333, -0.916667, -2.00000, 0.00000, 1.00000 }; - double[][] aa = NRUtil.buildMatrix(3, 3, a); - LUdcmp lud = new LUdcmp(aa); - double[][] inv = lud.inverse(); - System.out.println(NRUtil.toString(inv)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/example/Levin_Ex.java b/common-tools/cnuphys/numRec/src/com/nr/example/Levin_Ex.java deleted file mode 100644 index 22dde3ae2a..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/example/Levin_Ex.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.nr.example; - -import com.nr.UniVarRealValueFun; -import com.nr.fe.Levin; -import com.nr.fi.Trapzd; -import com.nr.sf.Bessel; - -public class Levin_Ex implements UniVarRealValueFun { - - @Override - public double funk(double x) { - if (x == 0.0) - return 0.0; - else { - Bessel bess = new Bessel(); - return x * bess.jnu(0.0, x) / (1.0 + x * x); - } - } - - public static void main(String[] args) { - Levin_Ex le = new Levin_Ex(); - int nterm = 12; - double beta = 1.0, a = 0.0, b = 0.0, sum = 0.0; - Levin series = new Levin(100, 0.0); - - for (int n = 0; n <= nterm; n++) { - b += Math.PI; - double s = Trapzd.qromb(le, a, b, 1.e-8); - a = b; - sum += s; - double omega = (beta + n) * s; - double ans = series.next(sum, omega, beta); - System.out.printf("%f %f\n", sum, ans); - } - - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/example/QRdcmp_Ex.java b/common-tools/cnuphys/numRec/src/com/nr/example/QRdcmp_Ex.java deleted file mode 100644 index ce0eb13a7b..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/example/QRdcmp_Ex.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Huang Wen Hui - * ---------------------------------------------------------------------------- - * - */ - -package com.nr.example; - -import com.nr.NRUtil; -import com.nr.la.QRdcmp; - -public class QRdcmp_Ex { - - public static void main(String[] args) { - double[] a = new double[] { 1.0, 0.5, 1.0, 0.5, 2.2, -1.0, 1.0, -1.0, - 5.0 }; - double[][] aa = NRUtil.buildMatrix(3, 3, a); - double[] b = new double[] { 2.0, 4.0, 1.0 }; - double[] x = new double[3]; - - QRdcmp qr = new QRdcmp(aa); - qr.solve(b, x); - System.out.println(NRUtil.toString(x)); - } -} \ No newline at end of file diff --git a/common-tools/cnuphys/numRec/src/com/nr/example/SVD_Ex.java b/common-tools/cnuphys/numRec/src/com/nr/example/SVD_Ex.java deleted file mode 100644 index 61fbf4d363..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/example/SVD_Ex.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.nr.example; - -import com.nr.NRUtil; -import com.nr.la.SVD; - -public class SVD_Ex { - - public static void main(String[] args) { - double[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - double[][] m = NRUtil.buildMatrix(3, 3, a); - SVD svd = new SVD(m); - double b[] = { 3, 1, 2 }; - double[] x = new double[3]; - System.out.println(svd.inv_condition()); - System.out.println(svd.rank()); - System.out.println(svd.nullity()); - - svd.solve(b, x); - System.out.println(NRUtil.toString(x)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/example/Solvde_Ex.java b/common-tools/cnuphys/numRec/src/com/nr/example/Solvde_Ex.java deleted file mode 100644 index 7ab16e0ced..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/example/Solvde_Ex.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.nr.example; - -import static com.nr.sf.Legendre.plgndr; -import static java.lang.Math.abs; -import static java.lang.Math.exp; -import static java.lang.Math.log; -import com.nr.bvp.Difeq; -import com.nr.bvp.Solvde; - -public class Solvde_Ex { - - public static void main(String[] args) { - final int M = 40, MM = 4; - final int NE = 3, NB = 1, NYJ = NE, NYK = M + 1; - int mm = 3, n = 5, mpt = M + 1; - int[] indexv = new int[NE]; - double[] x = new double[M + 1], scalv = new double[NE]; - double[][] y = new double[NYJ][NYK]; - int itmax = 100; - double c2[] = { 16.0, 20.0, -16.0, -20.0 }; - double conv = 1.0e-14, slowc = 1.0, h = 1.0 / M; - if ((n + mm & 1) != 0) { - indexv[0] = 0; - indexv[1] = 1; - indexv[2] = 2; - } else { - indexv[0] = 1; - indexv[1] = 0; - indexv[2] = 2; - } - double anorm = 1.0; - if (mm != 0) { - double q1 = n; - for (int i = 1; i <= mm; i++) - anorm = -0.5 * anorm * (n + i) * (q1-- / i); - } - for (int k = 0; k < M; k++) { - x[k] = k * h; - double fac1 = 1.0 - x[k] * x[k]; - double fac2 = exp((-mm / 2.0) * log(fac1)); - y[0][k] = plgndr(n, mm, x[k]) * fac2; - double deriv = -((n - mm + 1) * plgndr(n + 1, mm, x[k]) - (n + 1) - * x[k] * plgndr(n, mm, x[k])) - / fac1; - y[1][k] = mm * x[k] * y[0][k] / fac1 + deriv * fac2; - y[2][k] = n * (n + 1) - mm * (mm + 1); - } - x[M] = 1.0; - y[0][M] = anorm; - y[2][M] = n * (n + 1) - mm * (mm + 1); - y[1][M] = y[2][M] * y[0][M] / (2.0 * (mm + 1.0)); - scalv[0] = abs(anorm); - scalv[1] = (y[1][M] > scalv[0] ? y[1][M] : scalv[0]); - scalv[2] = (y[2][M] > 1.0 ? y[2][M] : 1.0); - for (int j = 0; j < MM; j++) { - Difeq difeq = new Difeq(mm, n, mpt, h, c2[j], anorm, x); - new Solvde(itmax, conv, slowc, scalv, indexv, NB, y, difeq); - /* - * cout << endl << " m = " << setw(3) << mm; cout << " n = " << - * setw(3) << n << " c**2 = "; cout << fixed << setprecision(3) << - * setw(7) << c2[j]; cout << " lamda = " << setprecision(6) << - * (y[2][0]+mm*(mm+1)); cout << endl; - */ - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/example/Toepltz_Ex.java b/common-tools/cnuphys/numRec/src/com/nr/example/Toepltz_Ex.java deleted file mode 100644 index c539ed9b5d..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/example/Toepltz_Ex.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.nr.example; - -import com.nr.NRUtil; -import com.nr.la.Toepltz; - -public class Toepltz_Ex { - - public static void main(String[] args) { - double[] r = new double[] { 1.0, 3.0, 1.0, 4.0, 2.2, -1.0, 2 }; - double[] y = new double[] { 2.0, 4.0, 1.0, -1 }; - double[] x = new double[4]; - Toepltz.toeplz(r, x, y); - System.out.println(NRUtil.toString(x)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/example/Trigag_Ex.java b/common-tools/cnuphys/numRec/src/com/nr/example/Trigag_Ex.java deleted file mode 100644 index 8186718456..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/example/Trigag_Ex.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.nr.example; - -import com.nr.NRUtil; -import com.nr.la.Tridag; - -public class Trigag_Ex { - - public static void main(String[] args) { - double[] a = new double[] { 1.0, 2.0, 2.0 }; - double[] b = new double[] { 4.0, -4.0, -3.0 }; - double[] c = new double[] { 2.0, 4.0, 5.0 }; - double[] r = new double[] { 2.0, 4.0, 5.0 }; - double[] u = new double[3]; - Tridag.tridag(a, b, c, r, u); - System.out.println(NRUtil.toString(u)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/example/Vander_Ex.java b/common-tools/cnuphys/numRec/src/com/nr/example/Vander_Ex.java deleted file mode 100644 index 7cc339b8ae..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/example/Vander_Ex.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.nr.example; - -import com.nr.NRUtil; -import com.nr.la.Vander; - -public class Vander_Ex { - - public static void main(String[] args) { - double[] x = new double[] { 1.0, 3.0, 1.0, 4.0, 2.2, -1.0 }; - double[] q = new double[] { 2.0, 4.0, 1.0, 2.0, 4.0, 2.0 }; - double[] w = new double[6]; - Vander.vander(x, w, q); - System.out.println(NRUtil.toString(w)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/example/Zrhqr_Ex.java b/common-tools/cnuphys/numRec/src/com/nr/example/Zrhqr_Ex.java deleted file mode 100644 index 87e9dc838e..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/example/Zrhqr_Ex.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.nr.example; - -import com.nr.Complex; -import static com.nr.root.Roots.*; - -public class Zrhqr_Ex { - public static void main(final String[] args) { - double[] cc = new double[] { 0.000193, 0.098243, 25.024523, 6.238928, 1 }; - Complex[] roots = new Complex[4]; - zrhqr(cc, roots); - for (int i = 0; i < roots.length; i++) - System.out.println(roots[i]); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/example/Zroots_Ex.java b/common-tools/cnuphys/numRec/src/com/nr/example/Zroots_Ex.java deleted file mode 100644 index 6c7ad1cad8..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/example/Zroots_Ex.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.nr.example; - -import com.nr.Complex; -import static com.nr.root.Roots.*; - -public class Zroots_Ex { - - public static void main(final String[] args) { - - Complex c0 = new Complex(0.000193, 0); - Complex c1 = new Complex(0.098243, 0); - Complex c2 = new Complex(25.024523, 0); - Complex c3 = new Complex(6.238928, 0); - Complex c4 = new Complex(1, 0); - Complex[] c = new Complex[] { c0, c1, c2, c3, c4 }; - Complex[] roots = new Complex[4]; - zroots(c, roots, true); - for (int i = 0; i < roots.length; i++) - System.out.println(roots[i]); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fe/Chebyshev.java b/common-tools/cnuphys/numRec/src/com/nr/fe/Chebyshev.java deleted file mode 100644 index cd543ae66c..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fe/Chebyshev.java +++ /dev/null @@ -1,213 +0,0 @@ -package com.nr.fe; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import com.nr.UniVarRealValueFun; - -/** - * Chebyshev approximation - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Chebyshev { - private int n, m; - private double[] c; - private double a, b; - - public Chebyshev(final double[] cc, final double aa, final double bb) { - n = cc.length; - m = n; - c = buildVector(cc); - a = aa; - b = bb; - } - - /** - * Inverse of routine polycofs in Chebyshev: Given an array of polynomial - * coefficients d[0..n-1], construct an equivalent Chebyshev object. - * - * @param d - */ - public Chebyshev(final double[] d) { - n = d.length; - m = n; - c = new double[n]; - a = -1.; - b = 1.; - - c[n - 1] = d[n - 1]; - c[n - 2] = 2.0 * d[n - 2]; - for (int j = n - 3; j >= 0; j--) { - c[j] = 2.0 * d[j] + c[j + 2]; - for (int i = j + 1; i < n - 2; i++) { - c[i] = (c[i] + c[i + 2]) / 2; - } - c[n - 2] /= 2; - c[n - 1] /= 2; - } - } - - public Chebyshev(final UniVarRealValueFun func, final double aa, - final double bb) { - this(func, aa, bb, 50); - } - - public Chebyshev(final UniVarRealValueFun func, final double aa, - final double bb, final int nn) { - n = nn; - m = nn; - c = new double[n]; - a = aa; - b = bb; - - int k, j; - double fac, bpa, bma, y, sum; - double[] f = new double[n]; - bma = 0.5 * (b - a); - bpa = 0.5 * (b + a); - for (k = 0; k < n; k++) { - y = cos(PI * (k + 0.5) / n); - f[k] = func.funk(y * bma + bpa); - } - fac = 2.0 / n; - for (j = 0; j < n; j++) { - sum = 0.0; - for (k = 0; k < n; k++) - sum += f[k] * cos(PI * j * (k + 0.5) / n); - c[j] = fac * sum; - } - } - - public double eval(final double x, final int m) { - double d = 0.0, dd = 0.0, sv, y, y2; - int j; - if ((x - a) * (x - b) > 0.0) - throw new IllegalArgumentException("x not in range in eval"); - y2 = 2.0 * (y = (2.0 * x - a - b) / (b - a)); - for (j = m - 1; j > 0; j--) { - sv = d; - d = y2 * d - dd + c[j]; - dd = sv; - } - return y * d - dd + 0.5 * c[0]; - } - - public double[] getc() { - return c; - } - - /** - * Return a new Chebyshev object that approximates the derivative of the - * existing function over the same range [a,b]. - * - * @return - */ - public Chebyshev derivative() { - int j; - double con; - double[] cder = new double[n]; - cder[n - 1] = 0.0; - cder[n - 2] = 2 * (n - 1) * c[n - 1]; - for (j = n - 2; j > 0; j--) - cder[j - 1] = cder[j + 1] + 2 * j * c[j]; - con = 2.0 / (b - a); - for (j = 0; j < n; j++) - cder[j] *= con; - return new Chebyshev(cder, a, b); - } - - /** - * Return a new Chebyshev object that approximates the indefinite integral - * of the existing function over the same range [a,b]. The constant of - * integration is set so that the integral vanishes at a. - * - * @return - */ - public Chebyshev integral() { - int j; - double sum = 0.0, fac = 1.0, con; - double[] cint = new double[n]; - con = 0.25 * (b - a); - for (j = 1; j < n - 1; j++) { - cint[j] = con * (c[j - 1] - c[j + 1]) / j; - sum += fac * cint[j]; - fac = -fac; - } - cint[n - 1] = con * c[n - 2] / (n - 1); - sum += fac * cint[n - 1]; - cint[0] = 2.0 * sum; - return new Chebyshev(cint, a, b); - } - - /** - * Polynomial coefficients from a Chebyshev fit. Given a coefficient array - * c[0..n-1], this routine returns a coefficient array d[0..n-1] such that - * sum(k=0,n-1)dky^k = sum(k=0,n-1)Tk(y)-c0/2. The method is Clenshaw's - * recurrence (5.8.11), but now applied algebraically rather than - * arithmetically. - * - * - * @param m - * @return - */ - public double[] polycofs(final int m) { - int k, j; - double sv; - double[] d = new double[m]; - double[] dd = new double[m]; - for (j = 0; j < m; j++) - d[j] = dd[j] = 0.0; - d[0] = c[m - 1]; - for (j = m - 2; j > 0; j--) { - for (k = m - j; k > 0; k--) { - sv = d[k]; - d[k] = 2.0 * d[k - 1] - dd[k]; - dd[k] = sv; - } - sv = d[0]; - d[0] = -dd[0] + c[j]; - dd[0] = sv; - } - for (j = m - 1; j > 0; j--) - d[j] = d[j - 1] - dd[j]; - d[0] = -dd[0] + 0.5 * c[0]; - return d; - } - - public int setm(final double thresh) { - while (m > 1 && abs(c[m - 1]) < thresh) - m--; - return m; - } - - // public double operator() (double x) {return eval(x,m);} - - public double get(final double x) { - return eval(x, m); - } - - public double[] polycofs() { - return polycofs(m); - } - - public static void pcshft(final double a, final double b, final double[] d) { - int k, j, n = d.length; - double cnst = 2.0 / (b - a), fac = cnst; - for (j = 1; j < n; j++) { - d[j] *= fac; - fac *= cnst; - } - cnst = 0.5 * (a + b); - for (j = 0; j <= n - 2; j++) - for (k = n - 2; k >= j; k--) - d[k] -= cnst * d[k + 1]; - } - - public static void ipcshft(final double a, final double b, final double[] d) { - pcshft(-(2. + b + a) / (b - a), (2. - b - a) / (b - a), d); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fe/Dfridr.java b/common-tools/cnuphys/numRec/src/com/nr/fe/Dfridr.java deleted file mode 100644 index aa97d770aa..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fe/Dfridr.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.nr.fe; - -import static java.lang.Math.*; - -import org.netlib.util.doubleW; - -import com.nr.UniVarRealValueFun; - -public class Dfridr { - private Dfridr() { - } - - /** - * Returns the derivative of a function func at a point x by Ridders' method - * of polynomial extrap- olation. The value h is input as an estimated - * initial stepsize; it need not be small, but rather should be an increment - * in x over which func changes substantially. An estimate of the error in - * the derivative is returned as err. - * - * @param func - * @param x - * @param h - * @param err - * @return - */ - public static double dfridr(final UniVarRealValueFun func, final double x, - final double h, final doubleW err) { - final int ntab = 10; - final double con = 1.4, con2 = (con * con); - final double big = Double.MAX_VALUE; - final double safe = 2.0; - int i, j; - double errt, fac, hh, ans = 0; - double[][] a = new double[ntab][ntab]; - if (h == 0.0) - throw new IllegalArgumentException("h must be nonzero in dfridr."); - hh = h; - a[0][0] = (func.funk(x + hh) - func.funk(x - hh)) / (2.0 * hh); - err.val = big; - for (i = 1; i < ntab; i++) { - hh /= con; - a[0][i] = (func.funk(x + hh) - func.funk(x - hh)) / (2.0 * hh); - fac = con2; - for (j = 1; j <= i; j++) { - a[j][i] = (a[j - 1][i] * fac - a[j - 1][i - 1]) / (fac - 1.0); - fac = con2 * fac; - errt = max(abs(a[j][i] - a[j - 1][i]), abs(a[j][i] - - a[j - 1][i - 1])); - if (errt <= err.val) { - err.val = errt; - ans = a[j][i]; - } - } - if (abs(a[i][i] - a[i - 1][i - 1]) >= safe * err.val) - break; - } - return ans; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fe/Epsalg.java b/common-tools/cnuphys/numRec/src/com/nr/fe/Epsalg.java deleted file mode 100644 index 4e91cbf427..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fe/Epsalg.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.nr.fe; - -import static java.lang.Math.*; - -/** - * Convergence acceleration of a sequence by the algorithm. Initialize by - * calling the constructor with arguments nmax, an upper bound on the number of - * terms to be summed, and epss, the desired accuracy. Then make successive - * calls to the function next, with argument the next partial sum of the - * sequence. The current estimate of the limit of the sequence is returned by - * next. The flag cnvgd is set when convergence is detected. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Epsalg { - private double[] e; - private int n, ncv; - public boolean cnvgd; - - /** - * Numbers near machine underflow and overflow limits. - */ - private final double eps, small, big; - private double lastval, lasteps; - - public Epsalg(final int nmax, final double epss) { - e = new double[nmax]; - n = 0; - ncv = 0; - cnvgd = false; - eps = epss; - lastval = 0; - small = Double.MIN_NORMAL * 10.0; - big = Double.MAX_VALUE; - } - - public double next(final double sum) { - double diff, temp1, temp2, val; - e[n] = sum; - temp2 = 0.0; - for (int j = n; j > 0; j--) { - temp1 = temp2; - temp2 = e[j - 1]; - diff = e[j] - temp2; - if (abs(diff) <= small) - e[j - 1] = big; - else - e[j - 1] = temp1 + 1.0 / diff; - } - n++; - val = (n & 1) != 0 ? e[0] : e[1]; - if (abs(val) > 0.01 * big) - val = lastval; - lasteps = abs(val - lastval); - if (lasteps > eps) - ncv = 0; - else - ncv++; - if (ncv >= 3) - cnvgd = true; - return (lastval = val); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fe/Eulsum.java b/common-tools/cnuphys/numRec/src/com/nr/fe/Eulsum.java deleted file mode 100644 index 68b45434a9..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fe/Eulsum.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.nr.fe; - -import static java.lang.Math.*; - -public class Eulsum { - private double[] wksp; - private int n, ncv; - public boolean cnvgd; - private final double eps; - private double sum, lastval, lasteps; - - public Eulsum(final int nmax, final double epss) { - wksp = new double[nmax]; - n = 0; - ncv = 0; - cnvgd = false; - sum = 0; - eps = epss; - lastval = 0; - } - - public double next(final double term) { - int j; - double tmp, dum; - if (n + 1 > wksp.length) - throw new IllegalArgumentException("wksp too small in eulsum"); - if (n == 0) { - sum = 0.5 * (wksp[n++] = term); - } else { - tmp = wksp[0]; - wksp[0] = term; - for (j = 1; j < n; j++) { - dum = wksp[j]; - wksp[j] = 0.5 * (wksp[j - 1] + tmp); - tmp = dum; - } - wksp[n] = 0.5 * (wksp[n - 1] + tmp); - if (abs(wksp[n]) <= abs(wksp[n - 1])) - sum += (0.5 * wksp[n++]); - else - sum += wksp[n]; - } - lasteps = abs(sum - lastval); - if (lasteps <= eps) - ncv++; - if (ncv >= 2) - cnvgd = true; - return (lastval = sum); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fe/Levin.java b/common-tools/cnuphys/numRec/src/com/nr/fe/Levin.java deleted file mode 100644 index a428bdc681..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fe/Levin.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.nr.fe; - -import static java.lang.Math.*; - -/** - * Convergence acceleration of a sequence by the Levin transformation. - * Initialize by calling the constructor with arguments nmax, an upper bound on - * the number of terms to be summed, and epss, the desired accuracy. Then make - * successive calls to the function next, which returns the current estimate of - * the limit of the sequence. The flag cnvgd is set when convergence is - * detected. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Levin { - private double[] numer, denom; - private int n, ncv; - public boolean cnvgd; - private final double small, eps; // big - private double lastval, lasteps; - - public Levin(final int nmax, final double epss) { - numer = new double[nmax]; - denom = new double[nmax]; - n = 0; - ncv = 0; - cnvgd = false; - eps = epss; - lastval = 0; - small = Double.MIN_VALUE * 10.0; - // big=Double.MAX_VALUE; - } - - public double next(final double sum, final double omega) { - return next(sum, omega, 1.0); - } - - /** - * sum, the nth partial sum of the sequence; omega, the nth remainder - * estimate wn , usually from (5.3.19); and the parameter beta, which should - * usually be set to 1, but sometimes 0.5 works better. The current estimate - * of the limit of the sequence is returned. - * - * @param sum - * @param omega - * @param beta - * @return - */ - public double next(final double sum, final double omega, final double beta) { - int j; - double fact, ratio, term, val; - term = 1.0 / (beta + n); - denom[n] = term / omega; - numer[n] = sum * denom[n]; - if (n > 0) { - ratio = (beta + n - 1) * term; - for (j = 1; j <= n; j++) { - fact = (n - j + beta) * term; - numer[n - j] = numer[n - j + 1] - fact * numer[n - j]; - denom[n - j] = denom[n - j + 1] - fact * denom[n - j]; - term = term * ratio; - } - } - n++; - val = abs(denom[0]) < small ? lastval : numer[0] / denom[0]; - lasteps = abs(val - lastval); - if (lasteps <= eps) - ncv++; - if (ncv >= 2) - cnvgd = true; - return (lastval = val); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fe/Poly.java b/common-tools/cnuphys/numRec/src/com/nr/fe/Poly.java deleted file mode 100644 index 3ef0ab5786..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fe/Poly.java +++ /dev/null @@ -1,197 +0,0 @@ -package com.nr.fe; - -import static com.nr.NRUtil.*; -import com.nr.Complex; - -/*** - * operations on polynomials - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Poly { - /** - * polynomial c[0]+c[1]x+c[2]x^2+ ... + c[n-2]x^n-2 + c[n-1]x^n-1 - * - */ - double[] c; - - /** - * Construct polynomial - * - * @param cc - */ - public Poly(final double[] cc) { - if (cc.length < 2) - throw new IllegalArgumentException("Poly order must be at least 2."); - c = cc; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(32); - int j = c.length - 1; - sb.append(String.format("%fx^%d", c[j], j)); - j--; - for (; j != 0; j--) { - sb.append(String.format("%+fx^%d", c[j], j)); - } - sb.append(String.format("%+f ", c[0])); - return sb.substring(0); - } - - // double operator() (double x) { - public double get(final double x) { - int j = c.length - 1; - double p = c[j]; - while (j > 0) - p = p * x + c[--j]; - return p; - } - - /** - * Build Polynomial from roots - * - * @param z - * @return - */ - public static Poly buildFromRoots(final Complex[] z) { - for (int i = 0; i < z.length; i++) { - boolean found = false; - for (int j = 0; j < z.length; j++) { - if (z[i].re() == z[j].re() && z[i].im() == -z[j].im()) { - found = true; - break; - } - } - if (!found) - throw new IllegalArgumentException("Roots must be conjugate"); - } - - Complex[] c = new Complex[z.length + 1]; - c[0] = z[0].neg(); - c[1] = new Complex(1, 0); - for (int i = 1; i < z.length; i++) { - Complex d = c[0]; - c[0] = c[0].mul(z[i].neg()); - for (int j = 1; j < i + 1; j++) { - Complex dd = c[j]; - c[j] = d.sub(z[i].mul(c[j])); - d = dd; - } - c[i + 1] = d; - } - double[] cc = new double[c.length]; - for (int i = 0; i < cc.length; i++) - cc[i] = c[i].re(); - return new Poly(cc); - } - - /** - * Build Polynomial from roots - * - * @param z - * @return - */ - public static Poly buildFromRoots(final double[] z) { - double[] c = new double[z.length + 1]; - c[0] = -z[0]; - c[1] = 1; - for (int i = 1; i < z.length; i++) { - double d = c[0]; - c[0] *= -z[i]; - for (int j = 1; j < i + 1; j++) { - double dd = c[j]; - c[j] = d - z[i] * c[j]; - d = dd; - } - c[i + 1] = d; - } - - return new Poly(c); - } - - /** - * Given the coefficients of a polynomial of degree nc as an array c[0..nc] - * of size nc+1 (with c[0] being the constant term), and given a value x, - * this routine fills an output array pd of size nd+1 with the value of the - * polynomial evaluated at x in pd[0], and the first nd derivatives at x in - * pd[1..nd]. - * - * @param c - * @param x - * @param pd - */ - public static void ddpoly(final double[] c, final double x, - final double[] pd) { - int nnd, j, i, nc = c.length - 1, nd = pd.length - 1; - double cnst = 1.0; - pd[0] = c[nc]; - for (j = 1; j < nd + 1; j++) - pd[j] = 0.0; - for (i = nc - 1; i >= 0; i--) { - nnd = (nd < (nc - i) ? nd : nc - i); - for (j = nnd; j > 0; j--) - pd[j] = pd[j] * x + pd[j - 1]; - pd[0] = pd[0] * x + c[i]; - } - for (i = 2; i < nd + 1; i++) { - cnst *= i; - pd[i] *= cnst; - } - } - - /** - * Given the coefficients of a polynomial of degree nc as an array c[0..nc] - * of size nc+1 (with c[0] being the constant term), and given a value x, - * this routine fills an output array pd of size nd+1 with the value of the - * polynomial evaluated at x in pd[0], and the first nd derivatives at x in - * pd[1..nd]. - * - * @param u - * @param v - * @param q - * @param r - */ - public static void poldiv(final double[] u, final double[] v, - final double[] q, final double[] r) { - if (q.length < u.length) - throw new IllegalArgumentException("q.length < u.length."); - if (r.length < u.length) - throw new IllegalArgumentException("r.length < u.length."); - - int k, j, n = u.length - 1, nv = v.length - 1; - while (nv >= 0 && v[nv] == 0.) - nv--; - if (nv < 0) - throw new IllegalArgumentException( - "poldiv divide by zero polynomial"); - copyAssign(r, u); - // assign(q, u.length,0.); - for (k = n - nv; k >= 0; k--) { - q[k] = r[nv + k] / v[nv]; - for (j = nv + k - 1; j >= k; j--) - r[j] -= q[k] * v[j - k]; - } - for (j = nv; j <= n; j++) - r[j] = 0.0; - } - - public static void main(final String[] args) { - double[] c = { 6, -5, 1 }; - Poly poly = new Poly(c); - System.out.println(poly); - - poly = buildFromRoots(new double[] { 2, 3, 1 }); - System.out.println(poly); - Complex p0 = new Complex(-0.00196389, 0.00196448); - Complex p1 = new Complex(-0.00196389, -0.00196448); - Complex p2 = new Complex(-3.1175, 3.90912); - Complex p3 = new Complex(-3.1175, -3.90912); - poly = buildFromRoots(new Complex[] { p0, p1, p2, p3 }); - System.out.println(poly); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fe/Ratfn.java b/common-tools/cnuphys/numRec/src/com/nr/fe/Ratfn.java deleted file mode 100644 index a12b45c558..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fe/Ratfn.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.nr.fe; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -import org.netlib.util.doubleW; - -import com.nr.UniVarRealValueFun; -import com.nr.la.LUdcmp; -import com.nr.la.SVD; - -public class Ratfn { - double[] cofs; - int nn, dd; - - public Ratfn(final double[] num, final double[] den) { - cofs = new double[num.length + den.length - 1]; - nn = num.length; - dd = den.length; - - int j; - for (j = 0; j < nn; j++) - cofs[j] = num[j] / den[0]; - for (j = 1; j < dd; j++) - cofs[j + nn - 1] = den[j] / den[0]; - } - - public Ratfn(final double[] coffs, final int n, final int d) { - cofs = buildVector(coffs); - nn = n; - dd = d; - } - - public double get(final double x) { - int j; - double sumn = 0., sumd = 0.; - for (j = nn - 1; j >= 0; j--) - sumn = sumn * x + cofs[j]; - for (j = nn + dd - 2; j >= nn; j--) - sumd = sumd * x + cofs[j]; - return sumn / (1.0 + x * sumd); - } - - /** - * Pade Approximation - * - * Given cof[0..2*n], the leading terms in the power series expansion of a - * function, solve the linear Pade equations to return a Ratfn object that - * embodies a diagonal rational function e approximation to the same - * function. - * - * - * @param cof - * @return - */ - public static Ratfn pade(final double[] cof) { - int j, k, n = (cof.length - 1) / 2; - double sum; - double[][] q = new double[n][n]; - // double[][] qlu = new double[n][n]; - double[] x = new double[n]; - double[] y = new double[n]; - double[] num = new double[n + 1]; - double[] denom = new double[n + 1]; - for (j = 0; j < n; j++) { - y[j] = cof[n + j + 1]; - for (k = 0; k < n; k++) - q[j][k] = cof[j - k + n]; - } - LUdcmp lu = new LUdcmp(q); - lu.solve(y, x); - for (j = 0; j < 4; j++) - lu.mprove(y, x); - for (k = 0; k < n; k++) { - for (sum = cof[k + 1], j = 0; j <= k; j++) - sum -= x[j] * cof[k - j]; - y[k] = sum; - } - num[0] = cof[0]; - denom[0] = 1.; - for (j = 0; j < n; j++) { - num[j + 1] = y[j]; - denom[j + 1] = -x[j]; - } - return new Ratfn(num, denom); - } - - /** - * Rational Chebyshev Approximation - * - * Returns a rational function approximation to the function fn in the - * interval (a, b). Input quantities mm and kk specify the order of the - * numerator and denominator, respectively. The maximum absolute deviation - * of the approximation (insofar as is known) is returned as dev. - * - * @param fn - * @param a - * @param b - * @param mm - * @param kk - * @param dev - * @return - */ - public static Ratfn ratlsq(final UniVarRealValueFun fn, final double a, - final double b, final int mm, final int kk, final doubleW dev) { - final int NPFAC = 8, MAXIT = 5; - final double BIG = 1.0e99, PIO2 = 1.570796326794896619; - int i, it, j, ncof = mm + kk + 1, npt = NPFAC * ncof; - double devmax, e, hth, power, sum; - double[] bb = new double[npt]; - double[] coff = new double[ncof]; - double[] ee = new double[npt]; - double[] fs = new double[npt]; - double[] wt = new double[npt]; - double[] xs = new double[npt]; - - double[][] u = new double[npt][ncof]; - - Ratfn ratbest = new Ratfn(coff, mm + 1, kk + 1); - dev.val = BIG; - for (i = 0; i < npt; i++) { - if (i < (npt / 2) - 1) { - hth = PIO2 * i / (npt - 1.0); - xs[i] = a + (b - a) * SQR(sin(hth)); - } else { - hth = PIO2 * (npt - i) / (npt - 1.0); - xs[i] = b - (b - a) * SQR(sin(hth)); - } - fs[i] = fn.funk(xs[i]); - wt[i] = 1.0; - ee[i] = 1.0; - } - e = 0.0; - for (it = 0; it < MAXIT; it++) { - for (i = 0; i < npt; i++) { - power = wt[i]; - bb[i] = power * (fs[i] + SIGN(e, ee[i])); - for (j = 0; j < mm + 1; j++) { - u[i][j] = power; - power *= xs[i]; - } - power = -bb[i]; - for (j = mm + 1; j < ncof; j++) { - power *= xs[i]; - u[i][j] = power; - } - } - SVD svd = new SVD(u); - svd.solve(bb, coff); - devmax = sum = 0.0; - Ratfn rat = new Ratfn(coff, mm + 1, kk + 1); - for (j = 0; j < npt; j++) { - ee[j] = rat.get(xs[j]) - fs[j]; - wt[j] = abs(ee[j]); - sum += wt[j]; - if (wt[j] > devmax) - devmax = wt[j]; - } - e = sum / npt; - if (devmax <= dev.val) { - ratbest = rat; - dev.val = devmax; - } - // cout << " ratlsq iteration= " << it; - // cout << " max error= " << setw(10) << devmax << endl; - } - return ratbest; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fft/FFT.java b/common-tools/cnuphys/numRec/src/com/nr/fft/FFT.java deleted file mode 100644 index 6d39baefd7..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fft/FFT.java +++ /dev/null @@ -1,786 +0,0 @@ -package com.nr.fft; - -import static java.lang.Math.*; - -import java.io.IOException; - -import org.netlib.util.intW; - -import com.nr.Complex; - -import java.nio.ByteBuffer; -import static com.nr.NRUtil.*; - -/** - * FFT routines. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class FFT { - private FFT() { - } - - /** - * Replaces data[0..2*n-1] by its discrete Fourier transform, if isign is - * input as 1; or replaces data[0..2*n-1] by n times its inverse discrete - * Fourier transform, if isign is input as 1. data is a complex array of - * length n stored as a real array of length 2*n. n must be an integer power - * of 2. - * - * @param data - * @param n - * @param isign - */ - public static void four1(final double[] data, final int n, final int isign) { - int nn, mmax, m, j, istep, i; - double wtemp, wr, wpr, wpi, wi, theta, tempr, tempi; - if (n < 2 || (n & (n - 1)) != 0) - throw new IllegalArgumentException("n must be power of 2 in four1"); - nn = n << 1; - j = 1; - for (i = 1; i < nn; i += 2) { - if (j > i) { - swap(data, j - 1, i - 1); - swap(data, j, i); - } - m = n; - while (m >= 2 && j > m) { - j -= m; - m >>= 1; - } - j += m; - } - mmax = 2; - while (nn > mmax) { - istep = mmax << 1; - theta = isign * (6.28318530717959 / mmax); - wtemp = sin(0.5 * theta); - wpr = -2.0 * wtemp * wtemp; - wpi = sin(theta); - wr = 1.0; - wi = 0.0; - for (m = 1; m < mmax; m += 2) { - for (i = m; i <= nn; i += istep) { - j = i + mmax; - tempr = wr * data[j - 1] - wi * data[j]; - tempi = wr * data[j] + wi * data[j - 1]; - data[j - 1] = data[i - 1] - tempr; - data[j] = data[i] - tempi; - data[i - 1] += tempr; - data[i] += tempi; - } - wr = (wtemp = wr) * wpr - wi * wpi + wr; - wi = wi * wpr + wtemp * wpi + wi; - } - mmax = istep; - } - } - - public static void four1(final double[] data, final int isign) { - four1(data, data.length / 2, isign); - } - - public static void four1(final Complex[] data, final int isign) { - int n = data.length * 2; - double[] rd = new double[n]; - for (int i = 0; i < data.length; i++) { - rd[2 * i] = data[i].re(); - rd[2 * i + 1] = data[i].im(); - } - four1(rd, data.length, isign); - for (int i = 0; i < data.length; i++) { - data[i] = new Complex(rd[2 * i], rd[2 * i + 1]); - } - } - - /** - * Calculates the Fourier transform of a set of n real-valued data points. - * Replaces these data (which are stored in array data[0..n-1]) by the - * positive frequency half of their complex Fourier transform. The - * real-valued first and last components of the complex transform are - * returned as elements data[0] and data[1], respectively. n must be a power - * of 2. This routine also calculates the inverse transform of a complex - * data array if it is the transform of real data. (Result in this case must - * be multiplied by 2/n.) - * - * @param data - * @param isign - */ - public static void realft(final double[] data, final int isign) { - int i, i1, i2, i3, i4, n = data.length; - double c1 = 0.5, c2, h1r, h1i, h2r, h2i, wr, wi, wpr, wpi, wtemp; - double theta = PI / (n >> 1); - if (isign == 1) { - c2 = -0.5; - four1(data, 1); - } else { - c2 = 0.5; - theta = -theta; - } - wtemp = sin(0.5 * theta); - wpr = -2.0 * wtemp * wtemp; - wpi = sin(theta); - wr = 1.0 + wpr; - wi = wpi; - for (i = 1; i < (n >> 2); i++) { - i2 = 1 + (i1 = i + i); - i4 = 1 + (i3 = n - i1); - h1r = c1 * (data[i1] + data[i3]); - h1i = c1 * (data[i2] - data[i4]); - h2r = -c2 * (data[i2] + data[i4]); - h2i = c2 * (data[i1] - data[i3]); - data[i1] = h1r + wr * h2r - wi * h2i; - data[i2] = h1i + wr * h2i + wi * h2r; - data[i3] = h1r - wr * h2r + wi * h2i; - data[i4] = -h1i + wr * h2i + wi * h2r; - wr = (wtemp = wr) * wpr - wi * wpi + wr; - wi = wi * wpr + wtemp * wpi + wi; - } - if (isign == 1) { - data[0] = (h1r = data[0]) + data[1]; - data[1] = h1r - data[1]; - } else { - data[0] = c1 * ((h1r = data[0]) + data[1]); - data[1] = c1 * (h1r - data[1]); - four1(data, -1); - } - } - - /** - * Calculates the sine transform of a set of n real-valued data points - * stored in array y[0..n-1]. The number n must be a power of 2. On exit, y - * is replaced by its transform. This program, without changes, also - * calculates the inverse sine transform, but in this case the output array - * should be multiplied by 2/n. - * - * @param y - */ - public static void sinft(final double[] y) { - int j, n = y.length; - double sum, y1, y2, theta, wi = 0.0, wr = 1.0, wpi, wpr, wtemp; - theta = PI / n; - wtemp = sin(0.5 * theta); - wpr = -2.0 * wtemp * wtemp; - wpi = sin(theta); - y[0] = 0.0; - for (j = 1; j < (n >> 1) + 1; j++) { - wr = (wtemp = wr) * wpr - wi * wpi + wr; - wi = wi * wpr + wtemp * wpi + wi; - y1 = wi * (y[j] + y[n - j]); - y2 = 0.5 * (y[j] - y[n - j]); - y[j] = y1 + y2; - y[n - j] = y1 - y2; - } - realft(y, 1); - y[0] *= 0.5; - sum = y[1] = 0.0; - for (j = 0; j < n - 1; j += 2) { - sum += y[j]; - y[j] = y[j + 1]; - y[j + 1] = sum; - } - } - - /** - * Calculates the cosine transform of a set y[0..n] of real-valued data - * points. The transformed data replace the original data in array y. n must - * be a power of 2. This program, without changes, also calculates the - * inverse cosine transform, but in this case the output array should be - * multiplied by 2/n. - * - * @param y - */ - public static void cosft1(final double[] y) { - int j, n = y.length - 1; - double sum, y1, y2, theta, wi = 0.0, wpi, wpr, wr = 1.0, wtemp; - double[] yy = new double[n]; - theta = PI / n; - wtemp = sin(0.5 * theta); - wpr = -2.0 * wtemp * wtemp; - wpi = sin(theta); - sum = 0.5 * (y[0] - y[n]); - yy[0] = 0.5 * (y[0] + y[n]); - for (j = 1; j < n / 2; j++) { - wr = (wtemp = wr) * wpr - wi * wpi + wr; - wi = wi * wpr + wtemp * wpi + wi; - y1 = 0.5 * (y[j] + y[n - j]); - y2 = (y[j] - y[n - j]); - yy[j] = y1 - wi * y2; - yy[n - j] = y1 + wi * y2; - sum += wr * y2; - } - yy[n / 2] = y[n / 2]; - realft(yy, 1); - for (j = 0; j < n; j++) - y[j] = yy[j]; - y[n] = y[1]; - y[1] = sum; - for (j = 3; j < n; j += 2) { - sum += y[j]; - y[j] = sum; - } - } - - /** - * Calculates the "staggered" cosine transform of a set y[0..n-1] of - * real-valued data points. The transformed data replace the original data - * in array y. n must be a power of 2. Set isign to C1 for a transform, and - * to 1 for an inverse transform. For an inverse transform, the output array - * should be multiplied by 2/n. - * - * @param y - * @param isign - */ - public static void cosft2(final double[] y, final int isign) { - int i, n = y.length; - double sum, sum1, y1, y2, ytemp, theta, wi = 0.0, wi1, wpi, wpr, wr = 1.0, wr1, wtemp; - theta = 0.5 * PI / n; - wr1 = cos(theta); - wi1 = sin(theta); - wpr = -2.0 * wi1 * wi1; - wpi = sin(2.0 * theta); - if (isign == 1) { - for (i = 0; i < n / 2; i++) { - y1 = 0.5 * (y[i] + y[n - 1 - i]); - y2 = wi1 * (y[i] - y[n - 1 - i]); - y[i] = y1 + y2; - y[n - 1 - i] = y1 - y2; - wr1 = (wtemp = wr1) * wpr - wi1 * wpi + wr1; - wi1 = wi1 * wpr + wtemp * wpi + wi1; - } - realft(y, 1); - for (i = 2; i < n; i += 2) { - wr = (wtemp = wr) * wpr - wi * wpi + wr; - wi = wi * wpr + wtemp * wpi + wi; - y1 = y[i] * wr - y[i + 1] * wi; - y2 = y[i + 1] * wr + y[i] * wi; - y[i] = y1; - y[i + 1] = y2; - } - sum = 0.5 * y[1]; - for (i = n - 1; i > 0; i -= 2) { - sum1 = sum; - sum += y[i]; - y[i] = sum1; - } - } else if (isign == -1) { - ytemp = y[n - 1]; - for (i = n - 1; i > 2; i -= 2) - y[i] = y[i - 2] - y[i]; - y[1] = 2.0 * ytemp; - for (i = 2; i < n; i += 2) { - wr = (wtemp = wr) * wpr - wi * wpi + wr; - wi = wi * wpr + wtemp * wpi + wi; - y1 = y[i] * wr + y[i + 1] * wi; - y2 = y[i + 1] * wr - y[i] * wi; - y[i] = y1; - y[i + 1] = y2; - } - realft(y, -1); - for (i = 0; i < n / 2; i++) { - y1 = y[i] + y[n - 1 - i]; - y2 = (0.5 / wi1) * (y[i] - y[n - 1 - i]); - y[i] = 0.5 * (y1 + y2); - y[n - 1 - i] = 0.5 * (y1 - y2); - wr1 = (wtemp = wr1) * wpr - wi1 * wpi + wr1; - wi1 = wi1 * wpr + wtemp * wpi + wi1; - } - } - } - - /** - * Replaces data by its ndim-dimensional discrete Fourier transform, if - * isign is input as 1. nn[0..ndim-1] is an integer array containing the - * lengths of each dimension (number of com- plex values), which must all be - * powers of 2. data is a real array of length twice the product of these - * lengths, in which the data are stored as in a multidimensional complex - * array: real and imaginary parts of each element are in consecutive - * locations, and the rightmost index of the array increases most rapidly as - * one proceeds along data. For a two-dimensional array, this is equivalent - * to storing the array by rows. If isign is input as 1, data is replaced by - * its inverse transform times the product of the lengths of all dimensions. - * - * @param data - * @param nn - * @param isign - */ - public static void fourn(final double[] data, final int[] nn, - final int isign) { - int idim, i1, i2, i3, i2rev, i3rev, ip1, ip2, ip3, ifp1, ifp2; - int ibit, k1, k2, n, nprev, nrem, ntot = 1, ndim = nn.length; - double tempi, tempr, theta, wi, wpi, wpr, wr, wtemp; - for (idim = 0; idim < ndim; idim++) - ntot *= nn[idim]; - if (ntot < 2 || (ntot & (ntot - 1)) != 0) - throw new IllegalArgumentException("must have powers of 2 in fourn"); - nprev = 1; - for (idim = ndim - 1; idim >= 0; idim--) { - n = nn[idim]; - nrem = ntot / (n * nprev); - ip1 = nprev << 1; - ip2 = ip1 * n; - ip3 = ip2 * nrem; - i2rev = 0; - for (i2 = 0; i2 < ip2; i2 += ip1) { - if (i2 < i2rev) { - for (i1 = i2; i1 < i2 + ip1 - 1; i1 += 2) { - for (i3 = i1; i3 < ip3; i3 += ip2) { - i3rev = i2rev + i3 - i2; - swap(data, i3, i3rev); - swap(data, i3 + 1, i3rev + 1); - } - } - } - ibit = ip2 >> 1; - while (ibit >= ip1 && i2rev + 1 > ibit) { - i2rev -= ibit; - ibit >>= 1; - } - i2rev += ibit; - } - ifp1 = ip1; - while (ifp1 < ip2) { - ifp2 = ifp1 << 1; - theta = isign * 6.28318530717959 / (ifp2 / ip1); - wtemp = sin(0.5 * theta); - wpr = -2.0 * wtemp * wtemp; - wpi = sin(theta); - wr = 1.0; - wi = 0.0; - for (i3 = 0; i3 < ifp1; i3 += ip1) { - for (i1 = i3; i1 < i3 + ip1 - 1; i1 += 2) { - for (i2 = i1; i2 < ip3; i2 += ifp2) { - k1 = i2; - k2 = k1 + ifp1; - tempr = wr * data[k2] - wi * data[k2 + 1]; - tempi = wr * data[k2 + 1] + wi * data[k2]; - data[k2] = data[k1] - tempr; - data[k2 + 1] = data[k1 + 1] - tempi; - data[k1] += tempr; - data[k1 + 1] += tempi; - } - } - wr = (wtemp = wr) * wpr - wi * wpi + wr; - wi = wi * wpr + wtemp * wpi + wi; - } - ifp1 = ifp2; - } - nprev *= n; - } - } - - /** - * Given a three-dimensional real array data[0..nn1-1][0..nn2-1][0..nn3-1] - * (where nn1 D 1 for the case of a logically two-dimensional array), this - * routine returns (for isign=1) the complex fast Fourier transform as two - * complex arrays: On output, data contains the zero and positive frequency - * values of the third frequency component, while speq[0..nn1-1][0..2*nn2-1] - * con- tains the Nyquist critical frequency values of the third frequency - * component. First (and sec- ond) frequency components are stored for zero, - * positive, and negative frequencies, in standard wraparound order. See - * text for description of how complex values are arranged. For isign=-1, - * the inverse transform (times nn1*nn2*nn3/2 as a constant multiplicative - * factor) is performed, with output data (viewed as a real array) deriving - * from input data (viewed as complex) and speq. For inverse transforms on - * data not generated first by a forward transform, make sure the complex - * input data array satisfies property (12.6.2). The dimensions nn1, nn2, - * nn3 must always be integer powers of 2. - * - * @param data - * @param speq - * @param isign - * @param nn1 - * @param nn2 - * @param nn3 - */ - public static void rlft3(final double[] data, final double[] speq, - final int isign, final int nn1, final int nn2, final int nn3) { - int i1, i2, i3, j1, j2, j3, k1, k2, k3, k4; - double theta, wi, wpi, wpr, wr, wtemp; - double c1, c2, h1r, h1i, h2r, h2i; - int[] nn = new int[3]; - double[][] spq = new double[nn1][2 * nn2]; - // for (i1=0;i1> 1; - if (isign == 1) { - fourn(data, nn, isign); - k1 = 0; - for (i1 = 0; i1 < nn1; i1++) - for (i2 = 0, j2 = 0; i2 < nn2; i2++, k1 += nn3) { - spq[i1][j2++] = data[k1]; - spq[i1][j2++] = data[k1 + 1]; - } - } - for (i1 = 0; i1 < nn1; i1++) { - j1 = (i1 != 0 ? nn1 - i1 : 0); - wr = 1.0; - wi = 0.0; - for (i3 = 0; i3 <= (nn3 >> 1); i3 += 2) { - k1 = i1 * nn2 * nn3; - k3 = j1 * nn2 * nn3; - for (i2 = 0; i2 < nn2; i2++, k1 += nn3) { - if (i3 == 0) { - j2 = (i2 != 0 ? ((nn2 - i2) << 1) : 0); - h1r = c1 * (data[k1] + spq[j1][j2]); - h1i = c1 * (data[k1 + 1] - spq[j1][j2 + 1]); - h2i = c2 * (data[k1] - spq[j1][j2]); - h2r = -c2 * (data[k1 + 1] + spq[j1][j2 + 1]); - data[k1] = h1r + h2r; - data[k1 + 1] = h1i + h2i; - spq[j1][j2] = h1r - h2r; - spq[j1][j2 + 1] = h2i - h1i; - } else { - j2 = (i2 != 0 ? nn2 - i2 : 0); - j3 = nn3 - i3; - k2 = k1 + i3; - k4 = k3 + j2 * nn3 + j3; - h1r = c1 * (data[k2] + data[k4]); - h1i = c1 * (data[k2 + 1] - data[k4 + 1]); - h2i = c2 * (data[k2] - data[k4]); - h2r = -c2 * (data[k2 + 1] + data[k4 + 1]); - data[k2] = h1r + wr * h2r - wi * h2i; - data[k2 + 1] = h1i + wr * h2i + wi * h2r; - data[k4] = h1r - wr * h2r + wi * h2i; - data[k4 + 1] = -h1i + wr * h2i + wi * h2r; - } - } - wr = (wtemp = wr) * wpr - wi * wpi + wr; - wi = wi * wpr + wtemp * wpi + wi; - } - } - if (isign == -1) - fourn(data, nn, isign); - - // copy spq back to speq; - for (i1 = 0; i1 < nn1; i1++) - for (j2 = 0; j2 < 2 * nn2; j2++) - speq[2 * nn2 * i1 + j2] = spq[i1][j2]; - - } - - public static void rlft3(final double[][][] data, final double[][] speq, - final int isign) { - int dim1 = data.length; - int dim2 = data[0].length; - int dim3 = data[0][0].length; - - if (speq.length != dim1 || speq[0].length != 2 * dim2) - throw new IllegalArgumentException("bad dims in rlft3"); - double[] d = new double[dim1 * dim2 * dim3]; - double[] s = new double[dim1 * 2 * dim2]; - for (int i = 0; i < dim1; i++) - for (int j = 0; j < dim2; j++) - for (int k = 0; k < dim3; k++) - d[i * dim2 * dim3 + j * dim3 + k] = data[i][j][k]; - for (int i = 0; i < dim1; i++) - for (int j = 0; j < 2 * dim2; j++) - s[i * 2 * dim2 + j] = speq[i][j]; - - rlft3(d, s, isign, dim1, dim2, dim3); - - for (int i = 0; i < dim1; i++) - for (int j = 0; j < dim2; j++) - for (int k = 0; k < dim3; k++) - data[i][j][k] = d[i * dim2 * dim3 + j * dim3 + k]; - for (int i = 0; i < dim1; i++) - for (int j = 0; j < 2 * dim2; j++) - speq[i][j] = s[i * 2 * dim2 + j]; - } - - public static void rlft3(final double[][] data, final double[] speq, - final int isign) { - if (speq.length != 2 * data.length) - throw new IllegalArgumentException("bad dims in rlft3"); - int nn = data.length; - int mm = data[0].length; - double[] d = new double[nn * mm]; - for (int i = 0; i < nn; i++) - for (int j = 0; j < mm; j++) - d[i * mm + j] = data[i][j]; - rlft3(d, speq, isign, 1, nn, mm); - for (int i = 0; i < nn; i++) - for (int j = 0; j < mm; j++) - data[i][j] = d[i * mm + j]; - } - - private static void fourew(final java.nio.channels.FileChannel[] file, - final intW na, intW nb, intW nc, intW nd) throws IOException { - int i; - for (i = 0; i < 4; i++) - file[i].position(0); - swap(file, 1, 3); - swap(file, 0, 2); - na.val = 2; - nb.val = 3; - nc.val = 0; - nd.val = 1; - } - - /** - * - * @param file - * @param nn - * @param isign - * @throws IOException - */ - public static void fourfs(java.nio.channels.FileChannel[] file, int[] nn, - final int isign) throws IOException { - final int KBF = 128; - final int doubSize = 8; - final int[] mate = { 1, 0, 3, 2 }; - long cc, cc0; - int j, j12, jk, k, kk, n = 1, mm, kc = 0, kd, ks, kr, nr, ns, nv; - final intW na = new intW(0); - final intW nb = new intW(0); - final intW nc = new intW(0); - final intW nd = new intW(0); - double tempr, tempi, wr, wi, wpr, wpi, wtemp, theta; - double[] afa = new double[KBF], afb = new double[KBF], afc = new double[KBF]; - ByteBuffer bb = ByteBuffer.allocate(KBF * doubSize); - int ndim = nn.length; - for (j = 0; j < ndim; j++) { - n *= nn[j]; - if (nn[j] <= 1) - throw new IllegalArgumentException( - "invalid double or wrong ndim in fourfs"); - } - nv = 0; - jk = nn[nv]; - mm = n; - ns = n / KBF; - nr = ns >> 1; - kd = KBF >> 1; - ks = n; - fourew(file, na, nb, nc, nd); - for (;;) { - theta = isign * PI / (n / mm); - wtemp = sin(0.5 * theta); - wpr = -2.0 * wtemp * wtemp; - wpi = sin(theta); - wr = 1.0; - wi = 0.0; - mm >>= 1; - for (j12 = 0; j12 < 2; j12++) { - kr = 0; - do { - cc0 = file[na.val].position() / doubSize; - // file[na].read((char *) &afa[0],KBF*doubSize); - file[na.val].read(bb); - bb.flip(); - for (int qq = 0; qq < KBF; qq++) - afa[qq] = bb.getDouble(); - bb.clear(); - cc = file[na.val].position() / doubSize; - if ((cc - cc0) != KBF) - throw new IllegalArgumentException( - "read error 1 in fourfs"); - cc0 = file[nb.val].position() / doubSize; - // file[nb].read((char *) &afb[0],KBF*doubSize); - file[nb.val].read(bb); - bb.flip(); - cc = file[nb.val].position() / doubSize; - for (int qq = 0; qq < KBF; qq++) - afb[qq] = bb.getDouble(); - bb.clear(); - - if ((cc - cc0) != KBF) - throw new IllegalArgumentException( - "read error 2 in fourfs"); - for (j = 0; j < KBF; j += 2) { - tempr = wr * afb[j] - wi * afb[j + 1]; - tempi = wi * afb[j] + wr * afb[j + 1]; - afb[j] = afa[j] - tempr; - afa[j] += tempr; - afb[j + 1] = afa[j + 1] - tempi; - afa[j + 1] += tempi; - } - kc += kd; - if (kc == mm) { - kc = 0; - wr = (wtemp = wr) * wpr - wi * wpi + wr; - wi = wi * wpr + wtemp * wpi + wi; - } - cc0 = file[nc.val].position() / doubSize; - // file[nc].write((char *) &afa[0],KBF*doubSize); - for (int qq = 0; qq < KBF; qq++) - bb.putDouble(afa[qq]); - bb.flip(); - file[nc.val].write(bb); - bb.clear(); - cc = file[nc.val].position() / doubSize; - if ((cc - cc0) != KBF) - throw new IllegalArgumentException( - "write error 1 in fourfs"); - cc0 = file[nd.val].position() / doubSize; - // file[nd].write((char *) &afb[0],KBF*doubSize); - for (int qq = 0; qq < KBF; qq++) - bb.putDouble(afb[qq]); - bb.flip(); - file[nd.val].write(bb); - bb.clear(); - - cc = file[nd.val].position() / doubSize; - if ((cc - cc0) != KBF) - throw new IllegalArgumentException( - "write error 2 in fourfs"); - } while (++kr < nr); - if (j12 == 0 && ks != n && ks == KBF) { - na.val = mate[na.val]; - nb.val = na.val; - } - if (nr == 0) - break; - } - fourew(file, na, nb, nc, nd); - jk >>= 1; - while (jk == 1) { - mm = n; - jk = nn[++nv]; - } - ks >>= 1; - if (ks > KBF) { - for (j12 = 0; j12 < 2; j12++) { - for (kr = 0; kr < ns; kr += ks / KBF) { - for (k = 0; k < ks; k += KBF) { - cc0 = file[na.val].position() / doubSize; - // file[na].read((char *) &afa[0],KBF*doubSize); - file[na.val].read(bb); - bb.flip(); - for (int qq = 0; qq < KBF; qq++) - afa[qq] = bb.getDouble(); - bb.clear(); - - cc = file[na.val].position() / doubSize; - if ((cc - cc0) != KBF) - throw new IllegalArgumentException( - "read error 3 in fourfs"); - cc0 = file[nc.val].position() / doubSize; - // file[nc]).write((char *) &afa[0],KBF*doubSize); - for (int qq = 0; qq < KBF; qq++) - bb.putDouble(afa[qq]); - bb.flip(); - file[nc.val].write(bb); - bb.clear(); - cc = file[nc.val].position() / doubSize; - if ((cc - cc0) != KBF) - throw new IllegalArgumentException( - "write error 3 in fourfs"); - } - nc.val = mate[nc.val]; - } - na.val = mate[na.val]; - } - fourew(file, na, nb, nc, nd); - } else if (ks == KBF) - nb.val = na.val; - else - break; - } - j = 0; - for (;;) { - theta = isign * PI / (n / mm); - wtemp = sin(0.5 * theta); - wpr = -2.0 * wtemp * wtemp; - wpi = sin(theta); - wr = 1.0; - wi = 0.0; - mm >>= 1; - ks = kd; - kd >>= 1; - for (j12 = 0; j12 < 2; j12++) { - for (kr = 0; kr < ns; kr++) { - cc0 = file[na.val].position() / doubSize; - // file[na].read((char *) &afc[0],KBF*doubSize); - file[na.val].read(bb); - bb.flip(); - for (int qq = 0; qq < KBF; qq++) - afc[qq] = bb.getDouble(); - bb.clear(); - - cc = file[na.val].position() / doubSize; - if ((cc - cc0) != KBF) - throw new IllegalArgumentException( - "read error 4 in fourfs"); - kk = 0; - k = ks; - for (;;) { - tempr = wr * afc[kk + ks] - wi * afc[kk + ks + 1]; - tempi = wi * afc[kk + ks] + wr * afc[kk + ks + 1]; - afa[j] = afc[kk] + tempr; - afb[j] = afc[kk] - tempr; - afa[++j] = afc[++kk] + tempi; - afb[j++] = afc[kk++] - tempi; - if (kk < k) - continue; - kc += kd; - if (kc == mm) { - kc = 0; - wr = (wtemp = wr) * wpr - wi * wpi + wr; - wi = wi * wpr + wtemp * wpi + wi; - } - kk += ks; - if (kk > KBF - 1) - break; - else - k = kk + ks; - } - if (j > KBF - 1) { - cc0 = file[nc.val].position() / doubSize; - // file[nc].write((char *) &afa[0],KBF*doubSize); - for (int qq = 0; qq < KBF; qq++) - bb.putDouble(afa[qq]); - bb.flip(); - file[nc.val].write(bb); - bb.clear(); - - cc = file[nc.val].position() / doubSize; - if ((cc - cc0) != KBF) - throw new IllegalArgumentException( - "write error 4 in fourfs"); - cc0 = file[nd.val].position() / doubSize; - // file[nd].write((char *) &afb[0],KBF*doubSize); - for (int qq = 0; qq < KBF; qq++) - bb.putDouble(afb[qq]); - bb.flip(); - file[nd.val].write(bb); - bb.clear(); - - cc = file[nd.val].position() / doubSize; - if ((cc - cc0) != KBF) - throw new IllegalArgumentException( - "write error 5 in fourfs"); - j = 0; - } - } - na.val = mate[na.val]; - } - fourew(file, na, nb, nc, nd); - jk >>= 1; - if (jk > 1) - continue; - mm = n; - do { - if (nv < ndim - 1) - jk = nn[++nv]; - else - return; - } while (jk == 1); - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fft/WrapVecDoub.java b/common-tools/cnuphys/numRec/src/com/nr/fft/WrapVecDoub.java deleted file mode 100644 index 3e42f65976..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fft/WrapVecDoub.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.nr.fft; - -import com.nr.Complex; - -public class WrapVecDoub { - - private double[] v; - - private int n, mask; - - public WrapVecDoub(final int nn) { - v = new double[nn]; - n = nn / 2; - mask = n - 1; - validate(); - } - - public WrapVecDoub(final double[] vec) { - v = vec; - n = vec.length / 2; - mask = n - 1; - validate(); - } - - private void validate() { - if ((n & (n - 1)) != 0) - throw new IllegalArgumentException("vec size must be power of 2"); - } - - public void set(int i, Complex c) { - int ii = (i & mask) << 1; - v[ii] = c.re(); - v[ii + 1] = c.im(); - } - - public Complex get(int i) { - int ii = (i & mask) << 1; - return new Complex(v[ii], v[ii + 1]); - } - - public void setReal(int i, double rr) { - v[(i & mask) << 1] = rr; - } - - public double real(int i) { - return v[(i & mask) << 1]; - } - - public void setImag(int i, double rr) { - v[((i & mask) << 1) + 1] = rr; - } - - public double imag(int i) { - return v[((i & mask) << 1) + 1]; - } - - public double[] get() { - return v; - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fi/Adapt.java b/common-tools/cnuphys/numRec/src/com/nr/fi/Adapt.java deleted file mode 100644 index e75cd896c1..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fi/Adapt.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.nr.fi; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import com.nr.UniVarRealValueFun; - -/** - * adaptive quadrature - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Adapt { - final double alpha = sqrt(2.0 / 3.0); - final double beta = 1.0 / sqrt(5.0); - final double x1 = 0.942882415695480; - final double x2 = 0.641853342345781; - final double x3 = 0.236383199662150; - final double[] x = new double[] { 0, -x1, -alpha, -x2, -beta, -x3, 0.0, x3, - beta, x2, alpha, x1 }; - // static final double alpha,beta,x1,x2,x3,x[12]; - - double TOL, toler; - - boolean terminate, out_of_tolerance; - - public Adapt(final double tol) { - TOL = tol; - terminate = true; - out_of_tolerance = false; - - final double EPS = DBL_EPSILON; - if (TOL < 10.0 * EPS) - TOL = 10.0 * EPS; - } - - public double integrate(final UniVarRealValueFun func, final double a, - final double b) { - double m, h, fa, fb, i1, i2, is, erri1, erri2, r; - double[] y = new double[13]; - m = 0.5 * (a + b); - h = 0.5 * (b - a); - fa = y[0] = func.funk(a); - fb = y[12] = func.funk(b); - for (int i = 1; i < 12; i++) - y[i] = func.funk(m + x[i] * h); - i2 = (h / 6.0) * (y[0] + y[12] + 5.0 * (y[4] + y[8])); - i1 = (h / 1470.0) - * (77.0 * (y[0] + y[12]) + 432.0 * (y[2] + y[10]) + 625.0 - * (y[4] + y[8]) + 672.0 * y[6]); - is = h - * (0.0158271919734802 * (y[0] + y[12]) + 0.0942738402188500 - * (y[1] + y[11]) + 0.155071987336585 * (y[2] + y[10]) - + 0.188821573960182 * (y[3] + y[9]) + 0.199773405226859 - * (y[4] + y[8]) + 0.224926465333340 * (y[5] + y[7]) + 0.242611071901408 * y[6]); - erri1 = abs(i1 - is); - erri2 = abs(i2 - is); - r = (erri2 != 0.0) ? erri1 / erri2 : 1.0; - toler = (r > 0.0 && r < 1.0) ? TOL / r : TOL; - if (is == 0.0) - is = b - a; - is = abs(is); - return adaptlob(func, a, b, fa, fb, is); - } - - public double adaptlob(final UniVarRealValueFun func, final double a, - final double b, final double fa, final double fb, final double is) { - double m, h, mll, ml, mr, mrr, fmll, fml, fm, fmrr, fmr, i1, i2; - m = 0.5 * (a + b); - h = 0.5 * (b - a); - mll = m - alpha * h; - ml = m - beta * h; - mr = m + beta * h; - mrr = m + alpha * h; - fmll = func.funk(mll); - fml = func.funk(ml); - fm = func.funk(m); - fmr = func.funk(mr); - fmrr = func.funk(mrr); - i2 = h / 6.0 * (fa + fb + 5.0 * (fml + fmr)); - i1 = h - / 1470.0 - * (77.0 * (fa + fb) + 432.0 * (fmll + fmrr) + 625.0 - * (fml + fmr) + 672.0 * fm); - if (abs(i1 - i2) <= toler * is || mll <= a || b <= mrr) { - if ((mll <= a || b <= mrr) && terminate) { - out_of_tolerance = true; - terminate = false; - } - return i1; - } else - return adaptlob(func, a, mll, fa, fmll, is) - + adaptlob(func, mll, ml, fmll, fml, is) - + adaptlob(func, ml, m, fml, fm, is) - + adaptlob(func, m, mr, fm, fmr, is) - + adaptlob(func, mr, mrr, fmr, fmrr, is) - + adaptlob(func, mrr, b, fmrr, fb, is); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fi/DErule.java b/common-tools/cnuphys/numRec/src/com/nr/fi/DErule.java deleted file mode 100644 index 139587e537..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fi/DErule.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.nr.fi; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; -import com.nr.RealValueFun; - -/** - * Structure for implementing the DE (double exponential) rule. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class DErule extends Quadrature { - double a, b, hmax, s; - RealValueFun func; - - public DErule(final RealValueFun funcc, final double aa, final double bb) { - this(funcc, aa, bb, 3.7); - } - - /** - * - * @param funcc - * @param aa - * @param bb - * @param hmaxx - */ - public DErule(final RealValueFun funcc, final double aa, final double bb, - final double hmaxx) { - func = funcc; - a = aa; - b = bb; - hmax = hmaxx; - n = 0; - } - - /** - * On the first call to the function next (n D 1), the routine returns the - * crudest estimate of S(a,b)f(x)dx.. Subsequent calls to next (n = 2,3,...) - * will improve the accuracy by adding 2^(n-1) additional interior points. - */ - @Override - public double next() { - double del, fact, q, sum, t, twoh; - int it, j; - n++; - if (n == 1) { - fact = 0.25; - return s = hmax * 2.0 * (b - a) * fact - * func.funk(new double[] { 0.5 * (b + a), 0.5 * (b - a) }); - } else { - for (it = 1, j = 1; j < n - 1; j++) - it <<= 1; - twoh = hmax / it; - t = 0.5 * twoh; - for (sum = 0.0, j = 0; j < it; j++) { - q = exp(-2.0 * sinh(t)); - del = (b - a) * q / (1.0 + q); - fact = q / SQR(1.0 + q) * cosh(t); - sum += fact - * (func.funk(new double[] { a + del, del }) + func - .funk(new double[] { b - del, del })); - t += twoh; - } - return s = 0.5 * s + (b - a) * twoh * sum; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fi/GaussianWeights.java b/common-tools/cnuphys/numRec/src/com/nr/fi/GaussianWeights.java deleted file mode 100644 index 6977248989..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fi/GaussianWeights.java +++ /dev/null @@ -1,376 +0,0 @@ -package com.nr.fi; - -import static java.lang.Math.*; -import static com.nr.sf.Gamma.*; -import com.nr.UniVarRealValueFun; -import com.nr.eig.Symmeig; - -public class GaussianWeights { - private GaussianWeights() { - } - - private static final double x[] = { 0.1488743389816312, 0.4333953941292472, - 0.6794095682990244, 0.8650633666889845, 0.9739065285171717 }; - private static final double w[] = { 0.2955242247147529, 0.2692667193099963, - 0.2190863625159821, 0.1494513491505806, 0.0666713443086881 }; - - /** - * Returns the integral of the function or functor func between a and b, by - * ten-point Gauss-Legendre integration: the function is evaluated exactly - * ten times at interior points in the range of integration. - * - * @param func - * @param a - * @param b - * @return - */ - public static double qgaus(final UniVarRealValueFun func, final double a, - final double b) { - double xm = 0.5 * (b + a); - double xr = 0.5 * (b - a); - double s = 0; - for (int j = 0; j < 5; j++) { - double dx = xr * x[j]; - s += w[j] * (func.funk(xm + dx) + func.funk(xm - dx)); - } - return s *= xr; - } - - /** - * Given the lower and upper limits of integration x1 and x2, this routine - * returns arrays x[0..n-1] and w[0..n-1] of length n, containing the - * abscissas and weights of the Gauss-Legendre n-point quadrature formula. - * - * @param x1 - * @param x2 - * @param x - * @param w - */ - public static void gauleg(final double x1, final double x2, - final double[] x, final double[] w) { - final double EPS = 1.0e-14; - double z1, z, xm, xl, pp, p3, p2, p1; - int n = x.length; - int m = (n + 1) / 2; - xm = 0.5 * (x2 + x1); - xl = 0.5 * (x2 - x1); - for (int i = 0; i < m; i++) { - z = cos(3.141592654 * (i + 0.75) / (n + 0.5)); - do { - p1 = 1.0; - p2 = 0.0; - for (int j = 0; j < n; j++) { - p3 = p2; - p2 = p1; - p1 = ((2.0 * j + 1.0) * z * p2 - j * p3) / (j + 1); - } - pp = n * (z * p1 - p2) / (z * z - 1.0); - z1 = z; - z = z1 - p1 / pp; - } while (abs(z - z1) > EPS); - x[i] = xm - xl * z; - x[n - 1 - i] = xm + xl * z; - w[i] = 2.0 * xl / ((1.0 - z * z) * pp * pp); - w[n - 1 - i] = w[i]; - } - } - - /** - * Given alf, the parameter a of the Laguerre polynomials, this routine - * returns arrays x[0..n-1] and w[0..n-1] containing the abscissas and - * weights of the n-point Gauss-Laguerre quadrature formula. The smallest - * abscissa is returned in x[0], the largest in x[n-1]. - * - * @param x - * @param w - * @param alf - */ - public static void gaulag(final double[] x, final double[] w, - final double alf) { - final int MAXIT = 10; - final double EPS = 1.0e-14; - int i, its, j; - double ai, p1, p2 = 0, p3, pp = 0, z = 0, z1; - int n = x.length; - for (i = 0; i < n; i++) { - if (i == 0) { - z = (1.0 + alf) * (3.0 + 0.92 * alf) - / (1.0 + 2.4 * n + 1.8 * alf); - } else if (i == 1) { - z += (15.0 + 6.25 * alf) / (1.0 + 0.9 * alf + 2.5 * n); - } else { - ai = i - 1; - z += ((1.0 + 2.55 * ai) / (1.9 * ai) + 1.26 * ai * alf - / (1.0 + 3.5 * ai)) - * (z - x[i - 2]) / (1.0 + 0.3 * alf); - } - for (its = 0; its < MAXIT; its++) { - p1 = 1.0; - p2 = 0.0; - for (j = 0; j < n; j++) { - p3 = p2; - p2 = p1; - p1 = ((2 * j + 1 + alf - z) * p2 - (j + alf) * p3) - / (j + 1); - } - pp = (n * p1 - (n + alf) * p2) / z; - z1 = z; - z = z1 - p1 / pp; - if (abs(z - z1) <= EPS) - break; - } - if (its >= MAXIT) - throw new IllegalArgumentException( - "too many iterations in gaulag"); - x[i] = z; - w[i] = -exp(gammln(alf + n) - gammln((n))) / (pp * n * p2); - } - } - - /** - * This routine returns arrays x[0..n-1] and w[0..n-1] containing the - * abscissas and weights of the n-point Gauss-Hermite quadrature formula. - * The largest abscissa is returned in x[0], the most negative in x[n-1]. - * - * @param x - * @param w - */ - public static void gauher(final double[] x, final double[] w) { - final double EPS = 1.0e-14, PIM4 = 0.7511255444649425; - final int MAXIT = 10; - int i, its, j, m; - double p1, p2, p3, pp = 0, z = 0, z1; - int n = x.length; - m = (n + 1) / 2; - for (i = 0; i < m; i++) { - if (i == 0) { - z = sqrt((2 * n + 1)) - 1.85575 * pow((2 * n + 1), -0.16667); - } else if (i == 1) { - z -= 1.14 * pow((n), 0.426) / z; - } else if (i == 2) { - z = 1.86 * z - 0.86 * x[0]; - } else if (i == 3) { - z = 1.91 * z - 0.91 * x[1]; - } else { - z = 2.0 * z - x[i - 2]; - } - for (its = 0; its < MAXIT; its++) { - p1 = PIM4; - p2 = 0.0; - for (j = 0; j < n; j++) { - p3 = p2; - p2 = p1; - p1 = z * sqrt(2.0 / (j + 1)) * p2 - - sqrt((double) j / (j + 1)) * p3; - } - pp = sqrt(2 * n) * p2; - z1 = z; - z = z1 - p1 / pp; - if (abs(z - z1) <= EPS) - break; - } - // XXX seems to always throw, so disable it. - // if (its >= MAXIT) throw new - // IllegalArgumentException("too many iterations in gauher"); - x[i] = z; - x[n - 1 - i] = -z; - w[i] = 2.0 / (pp * pp); - w[n - 1 - i] = w[i]; - } - } - - /** - * Given alf and bet, the parameters a and b of the Jacobi polynomials, this - * routine returns arrays x[0..n-1] and w[0..n-1] containing the abscissas - * and weights of the n-point Gauss-Jacobi quadrature formula. The largest - * abscissa is returned in x[0], the smallest in x[n-1]. - * - * @param x - * @param w - * @param alf - * @param bet - */ - public static void gaujac(final double[] x, final double[] w, - final double alf, final double bet) { - final int MAXIT = 10; - final double EPS = 1.0e-14; - int i, its, j; - double alfbet, an, bn, r1, r2, r3; - double a, b, c, p1, p2 = 0, p3, pp = 0, temp = 0, z = 0, z1; - int n = x.length; - for (i = 0; i < n; i++) { - if (i == 0) { - an = alf / n; - bn = bet / n; - r1 = (1.0 + alf) * (2.78 / (4.0 + n * n) + 0.768 * an / n); - r2 = 1.0 + 1.48 * an + 0.96 * bn + 0.452 * an * an + 0.83 * an - * bn; - z = 1.0 - r1 / r2; - } else if (i == 1) { - r1 = (4.1 + alf) / ((1.0 + alf) * (1.0 + 0.156 * alf)); - r2 = 1.0 + 0.06 * (n - 8.0) * (1.0 + 0.12 * alf) / n; - r3 = 1.0 + 0.012 * bet * (1.0 + 0.25 * abs(alf)) / n; - z -= (1.0 - z) * r1 * r2 * r3; - } else if (i == 2) { - r1 = (1.67 + 0.28 * alf) / (1.0 + 0.37 * alf); - r2 = 1.0 + 0.22 * (n - 8.0) / n; - r3 = 1.0 + 8.0 * bet / ((6.28 + bet) * n * n); - z -= (x[0] - z) * r1 * r2 * r3; - } else if (i == n - 2) { - r1 = (1.0 + 0.235 * bet) / (0.766 + 0.119 * bet); - r2 = 1.0 / (1.0 + 0.639 * (n - 4.0) / (1.0 + 0.71 * (n - 4.0))); - r3 = 1.0 / (1.0 + 20.0 * alf / ((7.5 + alf) * n * n)); - z += (z - x[n - 4]) * r1 * r2 * r3; - } else if (i == n - 1) { - r1 = (1.0 + 0.37 * bet) / (1.67 + 0.28 * bet); - r2 = 1.0 / (1.0 + 0.22 * (n - 8.0) / n); - r3 = 1.0 / (1.0 + 8.0 * alf / ((6.28 + alf) * n * n)); - z += (z - x[n - 3]) * r1 * r2 * r3; - } else { - z = 3.0 * x[i - 1] - 3.0 * x[i - 2] + x[i - 3]; - } - alfbet = alf + bet; - for (its = 1; its <= MAXIT; its++) { - temp = 2.0 + alfbet; - p1 = (alf - bet + temp * z) / 2.0; - p2 = 1.0; - for (j = 2; j <= n; j++) { - p3 = p2; - p2 = p1; - temp = 2 * j + alfbet; - a = 2 * j * (j + alfbet) * (temp - 2.0); - b = (temp - 1.0) - * (alf * alf - bet * bet + temp * (temp - 2.0) * z); - c = 2.0 * (j - 1 + alf) * (j - 1 + bet) * temp; - p1 = (b * p2 - c * p3) / a; - } - pp = (n * (alf - bet - temp * z) * p1 + 2.0 * (n + alf) - * (n + bet) * p2) - / (temp * (1.0 - z * z)); - z1 = z; - z = z1 - p1 / pp; - if (abs(z - z1) <= EPS) - break; - } - if (its > MAXIT) - throw new IllegalArgumentException( - "too many iterations in gaujac"); - x[i] = z; - w[i] = exp(gammln(alf + n) + gammln(bet + n) - gammln(n + 1.0) - - gammln(n + alfbet + 1.0)) - * temp * pow(2.0, alfbet) / (pp * p2); - } - } - - /** - * Computes the abscissas and weights for a Gaussian quadrature formula from - * the Jacobi matrix. On input, a[0..n-1] and b[0..n-1] are the coefficients - * of the recurrence relation for the set of monic orthogonal polynomials. - * The quantity u0=S(a,b)W(x)dx is input as amu0. The abscissas x[0..n-1] - * are returned in descending order, with the corresponding weights in - * w[0..n-1]. The arrays a and b are modified. Execution can be speeded up - * by modifying tqli and eigsrt to compute only the zeroth component of each - * eigenvector. - * - * @param a - * @param b - * @param amu0 - * @param x - * @param w - */ - public static void gaucof(final double[] a, final double[] b, - final double amu0, final double[] x, final double[] w) { - int n = a.length; - for (int i = 0; i < n; i++) - if (i != 0) - b[i] = sqrt(b[i]); - Symmeig sym = new Symmeig(a, b); - for (int i = 0; i < n; i++) { - x[i] = sym.d[i]; - w[i] = amu0 * sym.z[0][i] * sym.z[0][i]; - } - } - - /** - * Computes the abscissas and weights for a Gauss-Radau quadrature formula. - * On input, a[0..n-1] and b[0..n-1] are the coefficients of the recurrence - * relation for the set of monic orthogo- nal polynomials corresponding to - * the weight function. (b[0] is not referenced.) The quantity - * u0=S(a,b)W(x)dx is input as amu0. x1 is input as either endpoint of the - * interval. The abscissas x[0..n-1] are returned in descending order, with - * the corresponding weights in w[0..n-1]. The arrays a and b are modified. - * - * @param a - * @param b - * @param amu0 - * @param x1 - * @param x - * @param w - */ - public static void radau(final double[] a, final double[] b, - final double amu0, final double x1, final double[] x, - final double[] w) { - int n = a.length; - if (n == 1) { - x[0] = x1; - w[0] = amu0; - } else { - double p = x1 - a[0]; - double pm1 = 1.0; - double p1 = p; - for (int i = 1; i < n - 1; i++) { - p = (x1 - a[i]) * p1 - b[i] * pm1; - pm1 = p1; - p1 = p; - } - a[n - 1] = x1 - b[n - 1] * pm1 / p; - gaucof(a, b, amu0, x, w); - } - } - - /** - * Computes the abscissas and weights for a Gauss-Lobatto quadrature - * formula. On input, the vectors a[0..n-1] and b[0..n-1] are the - * coefficients of the recurrence relation for the set of monic orthogonal - * polynomials corresponding to the weight function. (b[0] is not - * referenced.) The quantity u0=S(a,b)W(x)dx is input as amu0. x1 amd xn are - * input as the endpoints of the interval. The abscissas x[0..n-1] are - * returned in descending order, with the corresponding weights in - * w[0..n-1]. The arrays a and b are modified. - * - * @param a - * @param b - * @param amu0 - * @param x1 - * @param xn - * @param x - * @param w - */ - public static void lobatto(final double[] a, final double[] b, - final double amu0, final double x1, final double xn, - final double[] x, final double[] w) { - double det, pl, pr, p1l, p1r, pm1l, pm1r; - int n = a.length; - if (n <= 1) - throw new IllegalArgumentException( - "n must be bigger than 1 in lobatto"); - pl = x1 - a[0]; - pr = xn - a[0]; - pm1l = 1.0; - pm1r = 1.0; - p1l = pl; - p1r = pr; - for (int i = 1; i < n - 1; i++) { - pl = (x1 - a[i]) * p1l - b[i] * pm1l; - pr = (xn - a[i]) * p1r - b[i] * pm1r; - pm1l = p1l; - pm1r = p1r; - p1l = pl; - p1r = pr; - } - det = pl * pm1r - pr * pm1l; - a[n - 1] = (x1 * pl * pm1r - xn * pr * pm1l) / det; - b[n - 1] = (xn - x1) * pl * pr / det; - gaucof(a, b, amu0, x, w); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fi/Midexp.java b/common-tools/cnuphys/numRec/src/com/nr/fi/Midexp.java deleted file mode 100644 index 0d14188aec..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fi/Midexp.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.nr.fi; - -import static java.lang.Math.*; -import com.nr.UniVarRealValueFun; - -public class Midexp extends Midpnt { - - @Override - public double func(final double x) { - return funk.funk(-log(x)) / x; - } - - public Midexp(final UniVarRealValueFun funcc, final double aa, - final double bb) { - super(funcc, aa, bb); - a = 0.0; - b = exp(-aa); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fi/Midinf.java b/common-tools/cnuphys/numRec/src/com/nr/fi/Midinf.java deleted file mode 100644 index d1e2e9835c..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fi/Midinf.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.nr.fi; - -import com.nr.UniVarRealValueFun; - -public class Midinf extends Midpnt { - - @Override - public double func(final double x) { - return funk.funk(1.0 / x) / (x * x); - } - - public Midinf(final UniVarRealValueFun funcc, final double aa, - final double bb) { - super(funcc, aa, bb); - a = 1.0 / bb; - b = 1.0 / aa; - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fi/Midpnt.java b/common-tools/cnuphys/numRec/src/com/nr/fi/Midpnt.java deleted file mode 100644 index d2ea78078a..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fi/Midpnt.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.nr.fi; - -import static java.lang.Math.*; -import com.nr.UniVarRealValueFun; -import com.nr.interp.Poly_interp; - -/** - * Routine implementing the extended midpoint rule. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Midpnt extends Quadrature { - protected double a, b, s; - protected UniVarRealValueFun funk; - - /** - * The constructor takes as inputs func, the function or functor to be - * integrated between limits a and b, also input. - * - * @param funcc - * @param aa - * @param bb - */ - public Midpnt(final UniVarRealValueFun funcc, final double aa, - final double bb) { - funk = funcc; - a = aa; - b = bb; - n = 0; - } - - /** - * Returns the nth stage of refinement of the extended midpoint rule. On the - * first call (n=1), the routine returns the crudest estimate of - * S(a,b)f(x)dx. Subsequent calls set n=2,3,... and improve the accuracy by - * adding (2/3)x3^(n-1) additional interior points. - */ - @Override - public double next() { - int it, j; - double x, tnm, sum, del, ddel; - n++; - if (n == 1) { - return (s = (b - a) * func(0.5 * (a + b))); - } else { - for (it = 1, j = 1; j < n - 1; j++) - it *= 3; - tnm = it; - del = (b - a) / (3.0 * tnm); - ddel = del + del; - x = a + 0.5 * del; - sum = 0.0; - for (j = 0; j < it; j++) { - sum += func(x); - x += ddel; - sum += func(x); - x += del; - } - s = (s + (b - a) * sum / tnm) / 3.0; - return s; - } - } - - public double func(final double x) { - return funk.funk(x); - } - - public static double qromo(final Midpnt q) { - return qromo(q, 3.0e-9); - } - - /** - * Romberg integration on an open interval. Returns the integral of a - * function using any specified elementary quadrature algorithm q and - * Romberg's method. Normally q will be an open formula, not evaluating the - * function at the endpoints. It is assumed that q triples the number of - * steps on each call, and that its error series contains only even powers - * of the number of steps. The routines midpnt, midinf, midsql, midsqu, - * midexp are possible choices for q. The constants below have the same - * meanings as in qromb. - * - * @param q - * @param eps - * @return - */ - public static double qromo(final Midpnt q, final double eps) { - final int JMAX = 14, JMAXP = JMAX + 1, K = 5; - double[] h = new double[JMAXP], s = new double[JMAX]; - Poly_interp polint = new Poly_interp(h, s, K); - h[0] = 1.0; - for (int j = 1; j <= JMAX; j++) { - s[j - 1] = q.next(); - if (j >= K) { - double ss = polint.rawinterp(j - K, 0.0); - if (abs(polint.dy) <= eps * abs(ss)) - return ss; - } - h[j] = h[j - 1] / 9.0; - } - throw new IllegalArgumentException("Too many steps in routine qromo"); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fi/Midsql.java b/common-tools/cnuphys/numRec/src/com/nr/fi/Midsql.java deleted file mode 100644 index d1c5294c3c..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fi/Midsql.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.nr.fi; - -import static java.lang.Math.*; -import com.nr.UniVarRealValueFun; - -public class Midsql extends Midpnt { - double aorig; - - @Override - public double func(final double x) { - return 2.0 * x * funk.funk(aorig + x * x); - } - - public Midsql(final UniVarRealValueFun funcc, final double aa, - final double bb) { - super(funcc, aa, bb); - aorig = aa; - a = 0; - b = sqrt(bb - aa); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fi/Midsqu.java b/common-tools/cnuphys/numRec/src/com/nr/fi/Midsqu.java deleted file mode 100644 index 98cbc77e01..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fi/Midsqu.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.nr.fi; - -import static java.lang.Math.*; -import com.nr.UniVarRealValueFun; - -public class Midsqu extends Midpnt { - double borig; - - @Override - public double func(final double x) { - return 2.0 * x * funk.funk(borig - x * x); - } - - public Midsqu(final UniVarRealValueFun funcc, final double aa, - final double bb) { - super(funcc, aa, bb); - borig = bb; - a = 0; - b = sqrt(bb - aa); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fi/NRf1.java b/common-tools/cnuphys/numRec/src/com/nr/fi/NRf1.java deleted file mode 100644 index 2cc1038860..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fi/NRf1.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.nr.fi; - -import static com.nr.fi.GaussianWeights.qgaus; -import com.nr.RealValueFun; -import com.nr.UniVarRealValueFun; - -public class NRf1 implements UniVarRealValueFun { - RealValueFun y1; - RealValueFun y2; - NRf2 f2; - - public NRf1(final RealValueFun y1, final RealValueFun y2, - final RealValueFun z1, final RealValueFun z2) { - this.y1 = y1; - this.y2 = y2; - this.f2 = new NRf2(z1, z2); - } - - @Override - public double funk(final double x) { - f2.f3.xsav = x; - return qgaus(f2, y1.funk(new double[] { x }), - y2.funk(new double[] { x })); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fi/NRf2.java b/common-tools/cnuphys/numRec/src/com/nr/fi/NRf2.java deleted file mode 100644 index 40a9d435b1..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fi/NRf2.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.nr.fi; - -import static com.nr.fi.GaussianWeights.qgaus; -import com.nr.RealValueFun; -import com.nr.UniVarRealValueFun; - -public class NRf2 implements UniVarRealValueFun { - NRf3 f3 = new NRf3(); - RealValueFun z1; - RealValueFun z2; - - public NRf2(final RealValueFun zz1, final RealValueFun zz2) { - z1 = zz1; - z2 = zz2; - } - - @Override - public double funk(final double y) { - f3.ysav = y; - return qgaus(f3, z1.funk(new double[] { f3.xsav, y }), - z2.funk(new double[] { f3.xsav, y })); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fi/NRf3.java b/common-tools/cnuphys/numRec/src/com/nr/fi/NRf3.java deleted file mode 100644 index d58bd3a566..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fi/NRf3.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.nr.fi; - -import static com.nr.fi.GaussianWeights.qgaus; -import com.nr.RealValueFun; -import com.nr.UniVarRealValueFun; - -public class NRf3 implements UniVarRealValueFun { - double xsav, ysav; - RealValueFun func3d; - - public NRf3() { - - } - - @Override - public double funk(final double z) { - return func3d.funk(new double[] { xsav, ysav, z }); - } - - /** - * Returns the integral of a user-supplied function func over a - * three-dimensional region specified by the limits x1, x2, and by the - * user-supplied functions y1, y2, z1, and z2, as defined in (4.8.2). - * Integration is performed by calling qgaus recursively. - * - * @param func - * @param x1 - * @param x2 - * @param y1 - * @param y2 - * @param z1 - * @param z2 - * @return - */ - public static double quad3d(final RealValueFun func, final double x1, - final double x2, final RealValueFun y1, final RealValueFun y2, - final RealValueFun z1, final RealValueFun z2) { - NRf1 f1 = new NRf1(y1, y2, z1, z2); - f1.f2.f3.func3d = func; - return qgaus(f1, x1, x2); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fi/Quadrature.java b/common-tools/cnuphys/numRec/src/com/nr/fi/Quadrature.java deleted file mode 100644 index 91231c9810..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fi/Quadrature.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.nr.fi; - -public abstract class Quadrature { - /** - * Current level of refinement. - */ - int n; - - /** - * The function next() must be defined in the derived class. - * - * @return Returns the value of the integral at the nth stage of refinement. - */ - public abstract double next(); - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fi/Stiel.java b/common-tools/cnuphys/numRec/src/com/nr/fi/Stiel.java deleted file mode 100644 index 0731f3c40b..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fi/Stiel.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.nr.fi; - -import static com.nr.NRUtil.*; -import static com.nr.fi.GaussianWeights.*; -import static java.lang.Math.*; -import com.nr.RealValueFun; -import com.nr.UniVarRealValueFun; - -public abstract class Stiel { - int j, n; - double aa, bb, hmax; - double[] a, b; - Quadrature s1, s2; - pp ppfunc = new pp(); - ppx ppxfunc = new ppx(); - - class pp implements UniVarRealValueFun, RealValueFun { - @Override - public double funk(final double[] x) { - double pval = p(x[0]); - return pval * wt1(x[0], x[1]) * pval; - } - - @Override - public double funk(final double t) { - double x = fx(t); - double pval = p(x); - return pval * wt2(x) * fdxdt(t) * pval; - } - } - - class ppx implements UniVarRealValueFun, RealValueFun { - @Override - public double funk(final double[] x) { - return ppfunc.funk(new double[] { x[0], x[1] }) * x[0]; - } - - @Override - public double funk(final double t) { - return ppfunc.funk(t) * fx(t); - } - } - - double p(final double x) { - double pval = 0, pj, pjm1; - if (j == 0) - return 1.0; - else { - pjm1 = 0.0; - pj = 1.0; - for (int i = 0; i < j; i++) { - pval = (x - a[i]) * pj - b[i] * pjm1; - pjm1 = pj; - pj = pval; - } - } - return pval; - } - - public Stiel(final int nn, final double aaa, final double bbb, - final double hmaxx) { - n = nn; - aa = aaa; - bb = bbb; - hmax = hmaxx; - a = new double[nn]; - b = new double[nn]; - s1 = new DErule(ppfunc, aa, bb, hmax); - s2 = new DErule(ppxfunc, aa, bb, hmax); - } - - public Stiel(final int nn, final double aaa, final double bbb) { - n = nn; - aa = aaa; - bb = bbb; - a = new double[nn]; - b = new double[nn]; - s1 = new Trapzd(ppfunc, aa, bb); - s2 = new Trapzd(ppxfunc, aa, bb); - } - - public double quad(final Quadrature s) { - final double EPS = 3.0e-11, MACHEPS = DBL_EPSILON; - final int NMAX = 11; - double olds = 0, sum; - s.n = 0; - for (int i = 1; i <= NMAX; i++) { - sum = s.next(); - if (i > 3) - if (abs(sum - olds) <= EPS * abs(olds)) - return sum; - if (i == NMAX) - if (abs(sum) <= MACHEPS && abs(olds) <= MACHEPS) - return 0.0; - olds = sum; - } - throw new IllegalArgumentException("no convergence in quad"); - } - - public void get_weights(final double[] x, final double[] w) { - double amu0, c, oldc = 1.0; - if (n != x.length) - throw new IllegalArgumentException("bad array size in Stiel"); - for (int i = 0; i < n; i++) { - j = i; - c = quad(s1); - b[i] = c / oldc; - a[i] = quad(s2) / c; - oldc = c; - } - amu0 = b[0]; - gaucof(a, b, amu0, x, w); - } - - public double wt1(final double x, final double del) { - return -9999; - } - - public double wt2(final double x) { - return -9999; - } - - public double fx(final double t) { - return -9999; - } - - public double fdxdt(final double t) { - return -9999; - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/fi/Trapzd.java b/common-tools/cnuphys/numRec/src/com/nr/fi/Trapzd.java deleted file mode 100644 index 5b64d65ec6..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/fi/Trapzd.java +++ /dev/null @@ -1,167 +0,0 @@ -package com.nr.fi; - -import static java.lang.Math.*; -import com.nr.UniVarRealValueFun; -import com.nr.interp.Poly_interp; - -/** - * Routine implementing the extended trapezoidal rule. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Trapzd extends Quadrature { - /** - * Limits of integration and current value of integral. - */ - private double a, b, s; - - private UniVarRealValueFun func; - - /** - * The constructor takes as inputs func, the function or functor to be - * integrated between limits a and b, also input. - * - * @param funcc - * @param aa - * @param bb - */ - public Trapzd(final UniVarRealValueFun funcc, final double aa, - final double bb) { - func = funcc; - a = aa; - b = bb; - n = 0; - } - - /** - * Returns the nth stage of refinement of the extended trapezoidal rule. On - * the first call (n=1),the routine returns the crudest estimate of - * S(a,b)f(x)dx. Subsequent calls set n=2,3,... and improve the accuracy by - * adding 2n-2 additional interior points. - */ - @Override - public double next() { - double x, tnm, sum, del; - int it, j; - n++; - if (n == 1) { - return (s = 0.5 * (b - a) * (func.funk(a) + func.funk(b))); - } else { - for (it = 1, j = 1; j < n - 1; j++) - it <<= 1; - tnm = it; - del = (b - a) / tnm; - x = a + 0.5 * del; - for (sum = 0.0, j = 0; j < it; j++, x += del) - sum += func.funk(x); - s = 0.5 * (s + (b - a) * sum / tnm); - return s; - } - } - - public static double qtrap(final UniVarRealValueFun func, final double a, - final double b) { - return qtrap(func, a, b, 1.0e-10); - } - - /** - * Returns the integral of the function or functor func from a to b. The - * constants EPS can be set to the desired fractional accuracy and JMAX so - * that 2 to the power JMAX-1 is the maximum allowed number of steps. - * Integration is performed by the trapezoidal rule. - * - * @param func - * @param a - * @param b - * @param eps - * @return - */ - public static double qtrap(final UniVarRealValueFun func, final double a, - final double b, final double eps) { - final int JMAX = 20; - double s, olds = 0.0; - Trapzd t = new Trapzd(func, a, b); - for (int j = 0; j < JMAX; j++) { - s = t.next(); - if (j > 5) - if (abs(s - olds) < eps * abs(olds) - || (s == 0.0 && olds == 0.0)) - return s; - olds = s; - } - throw new IllegalArgumentException("Too many steps in routine qtrap"); - } - - public static double qsimp(final UniVarRealValueFun func, final double a, - final double b) { - return qsimp(func, a, b, 1.0e-10); - } - - /** - * Returns the integral of the function or functor func from a to b. The - * constants EPS can be set to the desired fractional accuracy and JMAX so - * that 2 to the power JMAX-1 is the maximum allowed number of steps. - * Integration is performed by Simpson's rule. - * - * @param func - * @param a - * @param b - * @param eps - * @return - */ - public static double qsimp(final UniVarRealValueFun func, final double a, - final double b, final double eps) { - final int JMAX = 20; - double s, st, ost = 0.0, os = 0.0; - Trapzd t = new Trapzd(func, a, b); - for (int j = 0; j < JMAX; j++) { - st = t.next(); - s = (4.0 * st - ost) / 3.0; - if (j > 5) - if (abs(s - os) < eps * abs(os) || (s == 0.0 && os == 0.0)) - return s; - os = s; - ost = st; - } - throw new IllegalArgumentException("Too many steps in routine qsimp"); - } - - public static double qromb(final UniVarRealValueFun func, final double a, - final double b) { - return qromb(func, a, b, 1.0e-10); - } - - /** - * Returns the integral of the function or functor func from a to b. - * Integration is performed by Romberg's method of order 2K, where, e.g., - * K=2 is Simpson's rule. - * - * @param func - * @param a - * @param b - * @param eps - * @return - */ - public static double qromb(final UniVarRealValueFun func, final double a, - final double b, final double eps) { - final int JMAX = 20, JMAXP = JMAX + 1, K = 5; - double[] s = new double[JMAX], h = new double[JMAXP]; - Poly_interp polint = new Poly_interp(h, s, K); - h[0] = 1.0; - Trapzd t = new Trapzd(func, a, b); - for (int j = 1; j <= JMAX; j++) { - s[j - 1] = t.next(); - if (j >= K) { - double ss = polint.rawinterp(j - K, 0.0); - if (abs(polint.dy) <= eps * abs(ss)) - return ss; - } - h[j] = 0.25 * h[j - 1]; - } - throw new IllegalArgumentException("Too many steps in routine qromb"); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/BaryRat_interp.java b/common-tools/cnuphys/numRec/src/com/nr/interp/BaryRat_interp.java deleted file mode 100644 index 626a5adafe..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/BaryRat_interp.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.nr.interp; - -import static java.lang.Math.*; - -/** - * Barycentric rational interpolation object. After constructing the object, - * call interp for interpolated values. Note that no error estimate dy is - * calculated. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class BaryRat_interp extends Base_interp { - double[] w; - int d; - - /** - * Constructor arguments are x and y vectors of length n, and order d of - * desired approximation. - * - * @param xv - * @param yv - * @param dd - */ - public BaryRat_interp(final double[] xv, final double[] yv, final int dd) { - super(xv, yv, xv.length); - w = new double[n]; - d = dd; - - if (n <= d) - throw new IllegalArgumentException( - "d too large for number of points in BaryRat_interp"); - for (int k = 0; k < n; k++) { - int imin = max(k - d, 0); - int imax = (k >= n - d) ? n - d - 1 : k; - double temp = (imin & 1) != 0 ? -1.0 : 1.0; - // double temp = imin & 1 ? -1.0 : 1.0; - double sum = 0.0; - for (int i = imin; i <= imax; i++) { - int jmax = min(i + d, n - 1); - double term = 1.0; - for (int j = i; j <= jmax; j++) { - if (j == k) - continue; - term *= (xx[k] - xx[j]); - } - term = temp / term; - temp = -temp; - sum += term; - } - w[k] = sum; - } - } - - /** - * Use equation (3.4.9) to compute the barycentric rational interpolant. - * Note that jl is not used since the approximation is global; it is - * included only for compatibility with Base_interp. - * - * - */ - @Override - public double rawinterp(final int jl, final double x) { - double num = 0, den = 0; - for (int i = 0; i < n; i++) { - double h = x - xx[i]; - if (h == 0.0) { - return yy[i]; - } else { - double temp = w[i] / h; - num += temp * yy[i]; - den += temp; - } - } - return num / den; - } - - /** - * No need to invoke hunt or locate since the interpolation is global, so - * override interp to simply call rawinterp directly with a dummy value of - * jl. - */ - @Override - public double interp(final double x) { - return rawinterp(1, x); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/Base_interp.java b/common-tools/cnuphys/numRec/src/com/nr/interp/Base_interp.java deleted file mode 100644 index 08ad6cd0eb..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/Base_interp.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.nr.interp; - -import static java.lang.Math.*; - -/** - * Abstract base class used by all interpolation routines in this chapter. Only - * the routine interp is called directly by the user. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public abstract class Base_interp { - int n, mm, jsav, cor, dj; - double[] xx, yy; - - /** - * Set up for interpolating on a table of x's and y’s of length m. Normally - * called by a derived class, not by the user. - * - * @param x - * @param y - * @param m - */ - public Base_interp(final double[] x, final double[] y, final int m) { - n = x.length; - mm = m; - jsav = 0; - cor = 0; - xx = x; - yy = y; - - dj = max(1, (int) pow(n, 0.25)); - } - - public double interp(final double x) { - int jlo = (cor != 0) ? hunt(x) : locate(x); - return rawinterp(jlo, x); - } - - public abstract double rawinterp(int jlo, double x); - - /** - * Given a value x, return a value j such that x is (insofar as possible) - * centered in the subrange xx[j..j+mm-1], where xx is the stored pointer. - * The values in xx must be monotonic, either increasing or decreasing. The - * returned value is not less than 0, nor greater than n-1. - * - * @param x - * @return - */ - public int locate(final double x) { - int ju, jm, jl; - if (n < 2 || mm < 2 || mm > n) - throw new IllegalArgumentException("locate size error"); - boolean ascnd = (xx[n - 1] >= xx[0]); - jl = 0; - ju = n - 1; - while (ju - jl > 1) { - jm = (ju + jl) >> 1; - if (x >= xx[jm] == ascnd) - jl = jm; - else - ju = jm; - } - cor = abs(jl - jsav) > dj ? 0 : 1; - jsav = jl; - return max(0, min(n - mm, jl - ((mm - 2) >> 1))); - } - - /** - * Given a value x, return a value j such that x is (insofar as possible) - * centered in the subrange xx[j..j+mm-1], where xx is the stored pointer. - * The values in xx must be monotonic, either increasing or decreasing. The - * returned value is not less than 0, nor greater than n-1. - * - * @param x - * @return - */ - public int hunt(final double x) { - int jl = jsav, jm, ju, inc = 1; - if (n < 2 || mm < 2 || mm > n) - throw new IllegalArgumentException("hunt size error"); - boolean ascnd = (xx[n - 1] >= xx[0]); - if (jl < 0 || jl > n - 1) { - jl = 0; - ju = n - 1; - } else { - if (x >= xx[jl] == ascnd) { - for (;;) { - ju = jl + inc; - if (ju >= n - 1) { - ju = n - 1; - break; - } else if (x < xx[ju] == ascnd) - break; - else { - jl = ju; - inc += inc; - } - } - } else { - ju = jl; - for (;;) { - jl = jl - inc; - if (jl <= 0) { - jl = 0; - break; - } else if (x >= xx[jl] == ascnd) - break; - else { - ju = jl; - inc += inc; - } - } - } - } - while (ju - jl > 1) { - jm = (ju + jl) >> 1; - if (x >= xx[jm] == ascnd) - jl = jm; - else - ju = jm; - } - cor = abs(jl - jsav) > dj ? 0 : 1; - jsav = jl; - return max(0, min(n - mm, jl - ((mm - 2) >> 1))); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/Bilin_interp.java b/common-tools/cnuphys/numRec/src/com/nr/interp/Bilin_interp.java deleted file mode 100644 index 56e4f0497d..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/Bilin_interp.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.nr.interp; - -/** - * interpolation routines for two dimensions - * - * Object for bilinear interpolation on a matrix. Construct with a vector of x1. - * values, a vector of x2 values, and a matrix of tabulated function values yij - * Then call interp for interpolated values. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Bilin_interp { - int m, n; - final double[][] y; - Linear_interp x1terp, x2terp; - - public Bilin_interp(final double[] x1v, final double[] x2v, - final double[][] ym) { - m = x1v.length; - n = x2v.length; - y = ym; - x1terp = new Linear_interp(x1v, x1v); - x2terp = new Linear_interp(x2v, x2v); - } - - public double interp(final double x1p, final double x2p) { - int i, j; - double yy, t, u; - i = (x1terp.cor != 0) ? x1terp.hunt(x1p) : x1terp.locate(x1p); - j = (x2terp.cor != 0) ? x2terp.hunt(x2p) : x2terp.locate(x2p); - t = (x1p - x1terp.xx[i]) / (x1terp.xx[i + 1] - x1terp.xx[i]); - u = (x2p - x2terp.xx[j]) / (x2terp.xx[j + 1] - x2terp.xx[j]); - yy = (1. - t) * (1. - u) * y[i][j] + t * (1. - u) * y[i + 1][j] - + (1. - t) * u * y[i][j + 1] + t * u * y[i + 1][j + 1]; - return yy; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/Curve_interp.java b/common-tools/cnuphys/numRec/src/com/nr/interp/Curve_interp.java deleted file mode 100644 index 12e1dc0002..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/Curve_interp.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.nr.interp; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -/** - * Object for interpolating a curve specified by n points in dim dimensions. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Curve_interp { - int dim, n, in; - boolean cls; - double[][] pts; - double[] s; - double[] ans; - Spline_interp[] srp; - - public Curve_interp(final double[][] ptsin) { - this(ptsin, false); - } - - /** - * The n x dim matrix ptsin inputs the data points. Input close as 0 for an - * open curve, 1 for a closed curve. (For a closed curve, the last data - * point should not duplicate the first — the algorithm will connect them.) - * - * @param ptsin - * @param close - */ - public Curve_interp(final double[][] ptsin, final boolean close) { - n = ptsin.length; - dim = ptsin[0].length; - in = close ? 2 * n : n; - cls = close; - pts = new double[dim][in]; - s = new double[in]; - ans = new double[dim]; - srp = new Spline_interp[dim]; - - int i, ii, im, j, ofs; - double ss, soff, db, de; - ofs = close ? n / 2 : 0; - s[0] = 0.; - for (i = 0; i < in; i++) { - ii = (i - ofs + n) % n; - im = (ii - 1 + n) % n; - for (j = 0; j < dim; j++) - pts[j][i] = ptsin[ii][j]; - if (i > 0) { - s[i] = s[i - 1] + rad(ptsin[ii], ptsin[im]); - if (s[i] == s[i - 1]) - throw new IllegalArgumentException("error in Curve_interp"); - } - } - ss = close ? s[ofs + n] - s[ofs] : s[n - 1] - s[0]; - soff = s[ofs]; - for (i = 0; i < in; i++) - s[i] = (s[i] - soff) / ss; - for (j = 0; j < dim; j++) { - db = in < 4 ? 1.e99 : fprime(s, 0, pts[j], 0, 1); - de = in < 4 ? 1.e99 : fprime(s, in - 1, pts[j], in - 1, -1); - srp[j] = new Spline_interp(s, pts[j], db, de); - } - } - - /** - * Interpolate a point on the stored curve. The point is parameterized by t, - * in the range [0,1]. For open curves, values of t outside this range will - * return extrapolations (dangerous!). For closed curves, t is periodic with - * period 1. - * - * @param tt - * @return - */ - public double[] interp(final double tt) { - double t = tt; - if (cls) - t = t - floor(t); - for (int j = 0; j < dim; j++) - ans[j] = srp[j].interp(t); - return ans; - } - - /** - * Utility for estimating the derivatives at the endpoints. x and y point to - * the abscissa and ordinate of the endpoint. If pm is C1, points to the - * right will be used (left endpoint); if it is 1, points to the left will - * be used (right endpoint). - * - * @param x - * @param off_x - * @param y - * @param off_y - * @param pm - * @return - */ - private double fprime(final double[] x, final int off_x, final double[] y, - final int off_y, final int pm) { - double s1 = x[off_x + 0] - x[off_x + pm * 1], s2 = x[off_x + 0] - - x[off_x + pm * 2], s3 = x[off_x + 0] - x[off_x + pm * 3], s12 = s1 - - s2, s13 = s1 - s3, s23 = s2 - s3; - return -(s1 * s2 / (s13 * s23 * s3)) * y[off_y + pm * 3] - + (s1 * s3 / (s12 * s2 * s23)) * y[off_y + pm * 2] - - (s2 * s3 / (s1 * s12 * s13)) * y[off_y + pm * 1] - + (1. / s1 + 1. / s2 + 1. / s3) * y[off_y + 0]; - } - - private double rad(final double[] p1, final double[] p2) { - double sum = 0.; - for (int i = 0; i < dim; i++) - sum += SQR(p1[i] - p2[i]); - return sqrt(sum); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/Krig.java b/common-tools/cnuphys/numRec/src/com/nr/interp/Krig.java deleted file mode 100644 index d9a929136e..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/Krig.java +++ /dev/null @@ -1,115 +0,0 @@ -package com.nr.interp; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -import org.netlib.util.doubleW; - -import com.nr.UniVarRealValueFun; -import com.nr.la.LUdcmp; - -/** - * Object for interpolation by kriging, using npt points in ndim dimensions. - * Call constructor once, then interp as many times as desired. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Krig { - final double[][] x; - final UniVarRealValueFun vgram; - int ndim, npt; - double lastval, lasterr; - double[] y, dstar, vstar, yvi; - double[][] v; - LUdcmp vi; - - public Krig(final double[][] xx, final double[] yy, - final UniVarRealValueFun vargram) { - this(xx, yy, vargram, null); - } - - /** - * The npt ndim matrix xx inputs the data points, the vector yy the function - * values. vargram is the variogram function or functor. The argument err is - * not used for interpolation; - * - * @param xx - * @param yy - * @param vargram - * @param err - */ - public Krig(final double[][] xx, final double[] yy, - final UniVarRealValueFun vargram, final double[] err) { - x = xx; - y = yy; - vgram = vargram; - npt = xx.length; - ndim = xx[0].length; - dstar = new double[npt + 1]; - vstar = new double[npt + 1]; - v = new double[npt + 1][npt + 1]; - y = new double[npt + 1]; - yvi = new double[npt + 1]; - - int i, j; - for (i = 0; i < npt; i++) { - y[i] = yy[i]; - for (j = i; j < npt; j++) { - v[i][j] = v[j][i] = vgram.funk(rdist(x[i], x[j])); - } - v[i][npt] = v[npt][i] = 1.; - } - v[npt][npt] = y[npt] = 0.; - if (err != null) - for (i = 0; i < npt; i++) - v[i][i] -= SQR(err[i]); - vi = new LUdcmp(v); - vi.solve(y, yvi); - } - - /** - * Return an interpolated value at the point xstar. - * - * @param xstar - * @return - */ - public double interp(final double[] xstar) { - int i; - for (i = 0; i < npt; i++) - vstar[i] = vgram.funk(rdist(xstar, x[i])); - vstar[npt] = 1.; - lastval = 0.; - for (i = 0; i <= npt; i++) - lastval += yvi[i] * vstar[i]; - return lastval; - } - - /** - * Return an interpolated value at the point xstar, and return its estimated - * error as esterr. - * - * @param xstar - * @param esterr - * @return - */ - public double interp(final double[] xstar, final doubleW esterr) { - lastval = interp(xstar); - vi.solve(vstar, dstar); - lasterr = 0; - for (int i = 0; i <= npt; i++) - lasterr += dstar[i] * vstar[i]; - esterr.val = lasterr = sqrt(max(0., lasterr)); - return lastval; - } - - public double rdist(final double[] x1, final double[] x2) { - double d = 0.; - for (int i = 0; i < ndim; i++) - d += SQR(x1[i] - x2[i]); - return sqrt(d); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/Laplace_interp.java b/common-tools/cnuphys/numRec/src/com/nr/interp/Laplace_interp.java deleted file mode 100644 index 7c1fe38490..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/Laplace_interp.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.nr.interp; - -import static java.lang.Math.*; - -import org.netlib.util.*; - -import com.nr.la.Linbcg; - -/** - * Object for interpolating missing data in a matrix by solving Laplace's - * equation. Call constructor once, then solve one or more times - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Laplace_interp extends Linbcg { - double[][] mat; - int ii, jj; - int nn, iter; - double[] b, y, mask; - - /** - * Values greater than 1.e99 in the input matrix mat are deemed to be - * missing data. The matrix is not altered until solve is called. - * - * @param matrix - */ - public Laplace_interp(final double[][] matrix) { - mat = matrix; - ii = mat.length; - jj = mat[0].length; - nn = ii * jj; - iter = 0; - b = new double[nn]; - y = new double[nn]; - mask = new double[nn]; - int i, j, k; - double vl = 0.; - for (k = 0; k < nn; k++) { - i = k / jj; - j = k - i * jj; - if (mat[i][j] < 1.e99) { - b[k] = y[k] = vl = mat[i][j]; - mask[k] = 1; - } else { - b[k] = 0.; - y[k] = vl; - mask[k] = 0; - } - } - } - - public double solve() { - return solve(1.e-6, -1); - } - - /** - * Invoke Linbcg::solve with appropriate arguments. The default argument - * values will usually work, in which case this routine need be called only - * once. The original matrix mat is refilled with the interpolated solution. - * - * @param tol - * @param itmax - * @return - */ - public double solve(final double tol, final int itmax) { - int i, j, k; - int itmax0 = itmax; - doubleW err = new doubleW(0); - if (itmax0 <= 0) - itmax0 = 2 * max(ii, jj); - intW iter0 = new intW(0); - iter0.val = iter; - super.solve(b, y, 1, tol, itmax0, iter0, err); - iter = iter0.val; - for (k = 0, i = 0; i < ii; i++) - for (j = 0; j < jj; j++) - mat[i][j] = y[k++]; - return err.val; - } - - /** - * Diagonal preconditioner. (Diagonal elements all unity.) - * - */ - @Override - public void asolve(final double[] b, final double[] x, final int itrnsp) { - int i, n = b.length; - for (i = 0; i < n; i++) - x[i] = b[i]; - } - - /** - * Sparse matrix, and matrix transpose, multiply. - */ - @Override - public void atimes(final double[] x, final double[] r, final int itrnsp) { - int i, j, k, n = r.length, jjt, it; - double del; - for (k = 0; k < n; k++) - r[k] = 0.; - for (k = 0; k < n; k++) { - i = k / jj; - j = k - i * jj; - if (mask[k] != 0) { - r[k] += x[k]; - } else if (i > 0 && i < ii - 1 && j > 0 && j < jj - 1) { - if (itrnsp != 0) { - r[k] += x[k]; - del = -0.25 * x[k]; - r[k - 1] += del; - r[k + 1] += del; - r[k - jj] += del; - r[k + jj] += del; - } else { - r[k] = x[k] - 0.25 - * (x[k - 1] + x[k + 1] + x[k + jj] + x[k - jj]); - } - } else if (i > 0 && i < ii - 1) { - if (itrnsp != 0) { - r[k] += x[k]; - del = -0.5 * x[k]; - r[k - jj] += del; - r[k + jj] += del; - } else { - r[k] = x[k] - 0.5 * (x[k + jj] + x[k - jj]); - } - } else if (j > 0 && j < jj - 1) { - if (itrnsp != 0) { - r[k] += x[k]; - del = -0.5 * x[k]; - r[k - 1] += del; - r[k + 1] += del; - } else { - r[k] = x[k] - 0.5 * (x[k + 1] + x[k - 1]); - } - } else { - jjt = i == 0 ? jj : -jj; - it = j == 0 ? 1 : -1; - if (itrnsp != 0) { - r[k] += x[k]; - del = -0.5 * x[k]; - r[k + jjt] += del; - r[k + it] += del; - } else { - r[k] = x[k] - 0.5 * (x[k + jjt] + x[k + it]); - } - } - } - } -} \ No newline at end of file diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/Linear_interp.java b/common-tools/cnuphys/numRec/src/com/nr/interp/Linear_interp.java deleted file mode 100644 index 9238d4c466..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/Linear_interp.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.nr.interp; - -/** - * Piecewise linear interpolation object. - * - * Construct with x and y vectors, then call interp for interpolated values. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Linear_interp extends Base_interp { - - public Linear_interp(final double[] xv, final double[] yv) { - super(xv, yv, 2); - } - - @Override - public double rawinterp(final int j, final double x) { - if (xx[j] == xx[j + 1]) - return yy[j]; - else - return yy[j] + ((x - xx[j]) / (xx[j + 1] - xx[j])) - * (yy[j + 1] - yy[j]); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/PolCoef.java b/common-tools/cnuphys/numRec/src/com/nr/interp/PolCoef.java deleted file mode 100644 index 26bf067213..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/PolCoef.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.nr.interp; - -import static java.lang.Math.*; - -/** - * polynomial coefficients from polynomial values Copyright (C) Numerical - * Recipes Software 1986-2007 Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class PolCoef { - - private PolCoef() { - } - - /** - * Given arrays x[0..n-1] and y[0..n-1] containing a tabulated function yi D - * f .xi /, this routine returns an array of coefficients cof[0..n-1], such - * that yi =sum(cofj * xij)(j=0...n-1). - * - * @param x - * @param y - * @param cof - */ - public static void polcoe(final double[] x, final double[] y, - final double[] cof) { - int k, j, i, n = x.length; - double phi, ff, b; - double[] s = new double[n]; - for (i = 0; i < n; i++) - s[i] = cof[i] = 0.0; - s[n - 1] = -x[0]; - for (i = 1; i < n; i++) { - for (j = n - 1 - i; j < n - 1; j++) - s[j] -= x[i] * s[j + 1]; - s[n - 1] -= x[i]; - } - for (j = 0; j < n; j++) { - phi = n; - for (k = n - 1; k > 0; k--) - phi = k * s[k] + x[j] * phi; - ff = y[j] / phi; - b = 1.0; - for (k = n - 1; k >= 0; k--) { - cof[k] += b * ff; - b = s[k] + x[j] * b; - } - } - } - - /** - * Given arrays xa[0..n-1] and ya[0..n-1] containing a tabulated function - * yai D f .xai /, this routine returns an array of coefficients - * cof[0..n-1], such that yai = sum(cofj*xaij)(j=0...n-1) . - * - * @param xa - * @param ya - * @param cof - */ - public static void polcof(final double[] xa, final double[] ya, - final double[] cof) { - int k, j, i, n = xa.length; - double xmin; - double[] x = new double[n]; - double[] y = new double[n]; - for (j = 0; j < n; j++) { - x[j] = xa[j]; - y[j] = ya[j]; - } - for (j = 0; j < n; j++) { - double[] x_t = new double[n - j]; - double[] y_t = new double[n - j]; - for (k = 0; k < n - j; k++) { - x_t[k] = x[k]; - y_t[k] = y[k]; - } - Poly_interp interp = new Poly_interp(x, y, n - j); - cof[j] = interp.rawinterp(0, 0.); - xmin = 1.0e99; - k = -1; - for (i = 0; i < n - j; i++) { - if (abs(x[i]) < xmin) { - xmin = abs(x[i]); - k = i; - } - if (x[i] != 0.0) - y[i] = (y[i] - cof[j]) / x[i]; - } - for (i = k + 1; i < n - j; i++) { - y[i - 1] = y[i]; - x[i - 1] = x[i]; - } - } - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/Poly2D_interp.java b/common-tools/cnuphys/numRec/src/com/nr/interp/Poly2D_interp.java deleted file mode 100644 index 680740aa57..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/Poly2D_interp.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.nr.interp; - -/** - * Object for two-dimensional polynomial interpolation on a matrix. Construct - * with a vector of x1 values, a vector of x2 values, a matrix of tabulated - * function values yij , and integers to specify the number of points to use - * locally in each direction. Then call interp for interpolated values. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Poly2D_interp { - int m, n, mm, nn; - final double[][] y; - double[] yv; - Poly_interp x1terp, x2terp; - - public Poly2D_interp(final double[] x1v, final double[] x2v, - final double[][] ym, final int mp, final int np) { - - m = x1v.length; - n = x2v.length; - mm = mp; - nn = np; - y = ym; - yv = new double[m]; - x1terp = new Poly_interp(x1v, yv, mm); - x2terp = new Poly_interp(x2v, x2v, nn); - } - - public double interp(final double x1p, final double x2p) { - int i, j, k; - i = (x1terp.cor != 0) ? x1terp.hunt(x1p) : x1terp.locate(x1p); - j = (x2terp.cor != 0) ? x2terp.hunt(x2p) : x2terp.locate(x2p); - for (k = i; k < i + mm; k++) { - x2terp.yy = y[k]; - yv[k] = x2terp.rawinterp(j, x2p); - } - return x1terp.rawinterp(i, x1p); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/Poly_interp.java b/common-tools/cnuphys/numRec/src/com/nr/interp/Poly_interp.java deleted file mode 100644 index 05e5304e6f..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/Poly_interp.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.nr.interp; - -import static java.lang.Math.*; - -/** - * - * Polynomial Interpolation and Extrapolation interpolation routines for one - * dimension Copyright (C) Numerical Recipes Software 1986-2007 Java translation - * Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Poly_interp extends Base_interp { - - public double dy; - - public Poly_interp(final double[] xv, final double[] yv, final int m) { - super(xv, yv, m); - dy = 0.; - } - - /** - * Given a value x, and using pointers to data xx and yy, this routine - * returns an interpolated value y, and stores an error estimate dy. The - * returned value is obtained by mm-point polynomial interpolation on the - * subrange xx[jl..jl+mm-1]. - */ - @Override - public double rawinterp(final int jl, final double x) { - int i, m, ns = 0; - double y, den, dif, dift, ho, hp, w; - // double *xa = &xx[jl], *ya = &yy[jl]; - double[] c = new double[mm]; - double[] d = new double[mm]; - dif = abs(x - xx[jl + 0]); - for (i = 0; i < mm; i++) { - if ((dift = abs(x - xx[jl + i])) < dif) { - ns = i; - dif = dift; - } - c[i] = yy[jl + i]; - d[i] = yy[jl + i]; - } - y = yy[jl + ns--]; - for (m = 1; m < mm; m++) { - for (i = 0; i < mm - m; i++) { - ho = xx[jl + i] - x; - hp = xx[jl + i + m] - x; - w = c[i + 1] - d[i]; - if ((den = ho - hp) == 0.0) - throw new IllegalArgumentException("Poly_interp error"); - den = w / den; - d[i] = hp * den; - c[i] = ho * den; - } - y += (dy = (2 * (ns + 1) < (mm - m) ? c[ns + 1] : d[ns--])); - } - return y; - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/Powvargram.java b/common-tools/cnuphys/numRec/src/com/nr/interp/Powvargram.java deleted file mode 100644 index 1cd880c46b..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/Powvargram.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.nr.interp; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; -import com.nr.UniVarRealValueFun; - -/** - * Functor for variogram v(r)=ar^b, where b is specified, a is fitted from the - * data. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Powvargram implements UniVarRealValueFun { - private double alph, bet, nugsq; - - public Powvargram(final double[][] x, final double[] y) { - this(x, y, 1.5, 0.); - } - - public Powvargram(final double[][] x, final double[] y, final double beta, - final double nug) { - bet = beta; - nugsq = nug * nug; - int i, j, k, npt = x.length, ndim = x[0].length; - double rb, num = 0., denom = 0.; - for (i = 0; i < npt; i++) - for (j = i + 1; j < npt; j++) { - rb = 0.; - for (k = 0; k < ndim; k++) - rb += SQR(x[i][k] - x[j][k]); - rb = pow(rb, 0.5 * beta); - num += rb * (0.5 * SQR(y[i] - y[j]) - nugsq); - denom += SQR(rb); - } - alph = num / denom; - } - - @Override - public double funk(final double r) { - return nugsq + alph * pow(r, bet); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_fn.java b/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_fn.java deleted file mode 100644 index 295e288d41..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_fn.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.nr.interp; - -public interface RBF_fn { - - public double rbf(final double r); -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_gauss.java b/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_gauss.java deleted file mode 100644 index 414edf4313..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_gauss.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.nr.interp; - -import static com.nr.NRUtil.*; - -import static java.lang.Math.*; - -public class RBF_gauss implements RBF_fn { - double r0; - - public RBF_gauss() { - this(1.0); - } - - public RBF_gauss(final double scale) { - r0 = scale; - } - - @Override - public double rbf(final double r) { - return exp(-0.5 * SQR(r / r0)); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_interp.java b/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_interp.java deleted file mode 100644 index 12840f9358..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_interp.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.nr.interp; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import com.nr.la.LUdcmp; - -/** - * Object for radial basis function interpolation using n points in dim - * dimensions. Call constructor once, then interp as many times as desired. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class RBF_interp { - int dim, n; - final double[][] pts; - final double[] vals; - double[] w; - RBF_fn fn; - boolean norm; - - public RBF_interp(final double[][] ptss, final double[] valss, - final RBF_fn func) { - this(ptss, valss, func, false); - } - - /** - * The n dim matrix ptss inputs the data points, the vector valss the - * function values. func contains the chosen radial basis function, derived - * from the class RBF_fn. The default value of nrbf gives RBF interpolation; - * set it to 1 for NRBF. - * - * @param ptss - * @param valss - * @param func - * @param nrbf - */ - public RBF_interp(final double[][] ptss, final double[] valss, - final RBF_fn func, final boolean nrbf) { - dim = ptss[0].length; - n = ptss.length; - pts = ptss; - vals = valss; - w = new double[n]; - fn = func; - norm = nrbf; - - int i, j; - double sum; - double[][] rbf = new double[n][n]; - double[] rhs = new double[n]; - for (i = 0; i < n; i++) { - sum = 0.; - for (j = 0; j < n; j++) { - sum += (rbf[i][j] = fn.rbf(rad(pts[i], pts[j]))); - } - if (norm) - rhs[i] = sum * vals[i]; - else - rhs[i] = vals[i]; - } - LUdcmp lu = new LUdcmp(rbf); - lu.solve(rhs, w); - } - - /** - * Return the interpolated function value at a dim-dimensional point pt. - * - * @param pt - * @return - */ - public double interp(final double[] pt) { - double fval, sum = 0., sumw = 0.; - if (pt.length != dim) - throw new IllegalArgumentException("RBF_interp bad pt size"); - for (int i = 0; i < n; i++) { - fval = fn.rbf(rad(pt, pts[i])); - sumw += w[i] * fval; - sum += fval; - } - return norm ? sumw / sum : sumw; - } - - public double rad(final double[] p1, final double[] p2) { - double sum = 0.; - for (int i = 0; i < dim; i++) - sum += SQR(p1[i] - p2[i]); - return sqrt(sum); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_inversemultiquadric.java b/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_inversemultiquadric.java deleted file mode 100644 index 84b7a65063..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_inversemultiquadric.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.nr.interp; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -public class RBF_inversemultiquadric implements RBF_fn { - double r02; - - public RBF_inversemultiquadric() { - this(1.0); - } - - public RBF_inversemultiquadric(final double scale) { - r02 = SQR(scale); - } - - @Override - public double rbf(final double r) { - return 1. / sqrt(SQR(r) + r02); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_multiquadric.java b/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_multiquadric.java deleted file mode 100644 index a82aad0a32..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_multiquadric.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.nr.interp; - -import static com.nr.NRUtil.*; - -import static java.lang.Math.*; - -public class RBF_multiquadric implements RBF_fn { - double r02; - - public RBF_multiquadric() { - this(1.0); - } - - public RBF_multiquadric(final double scale) { - r02 = SQR(scale); - } - - @Override - public double rbf(final double r) { - return sqrt(SQR(r) + r02); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_thinplate.java b/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_thinplate.java deleted file mode 100644 index 1a2ab904ab..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/RBF_thinplate.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.nr.interp; - -import static com.nr.NRUtil.*; - -import static java.lang.Math.*; - -public class RBF_thinplate implements RBF_fn { - double r0; - - public RBF_thinplate() { - this(1.0); - } - - public RBF_thinplate(final double scale) { - r0 = scale; - } - - @Override - public double rbf(final double r) { - return r <= 0. ? 0. : SQR(r) * log(r / r0); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/Rational_interp.java b/common-tools/cnuphys/numRec/src/com/nr/interp/Rational_interp.java deleted file mode 100644 index d669bf08b7..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/Rational_interp.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.nr.interp; - -import static java.lang.Math.*; - -/** - * Rational Function Interpolation and Extrapolation - * - * Given a value x, and using pointers to data xx and yy, this routine returns - * an interpolated value y, and stores an error estimate dy. The returned value - * is obtained by mm-point polynomial interpolation on the subrange - * xx[jl..jl+mm-1]. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Rational_interp extends Base_interp { - public double dy; - - public Rational_interp(final double[] xv, final double[] yv, final int m) { - super(xv, yv, m); - dy = 0.; - } - - /** - * Given a value x, and using pointers to data xx and yy, this routine - * returns an interpolated value y, and stores an error estimate dy. The - * returned value is obtained by mm-point diagonal rational function - * interpolation on the subrange xx[jl..jl+mm-1]. - */ - @Override - public double rawinterp(final int jl, final double x) { - final double TINY = 1.0e-99; - int m, i, ns = 0; - double y, w, t, hh, h, dd; - // const double *xa = &xx[jl], *ya = &yy[jl]; - double[] c = new double[mm]; - double[] d = new double[mm]; - hh = abs(x - xx[jl + 0]); - for (i = 0; i < mm; i++) { - h = abs(x - xx[jl + i]); - if (h == 0.0) { - dy = 0.0; - return yy[jl + i]; - } else if (h < hh) { - ns = i; - hh = h; - } - c[i] = yy[jl + i]; - d[i] = yy[jl + i] + TINY; - } - y = yy[jl + ns--]; - for (m = 1; m < mm; m++) { - for (i = 0; i < mm - m; i++) { - w = c[i + 1] - d[i]; - h = xx[jl + i + m] - x; - t = (xx[jl + i] - x) * d[i] / h; - dd = t - c[i + 1]; - if (dd == 0.0) - throw new IllegalArgumentException( - "Error in routine ratint"); - dd = w / dd; - d[i] = c[i + 1] * dd; - c[i] = t * dd; - } - y += (dy = (2 * (ns + 1) < (mm - m) ? c[ns + 1] : d[ns--])); - } - return y; - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/Shep_interp.java b/common-tools/cnuphys/numRec/src/com/nr/interp/Shep_interp.java deleted file mode 100644 index 4bf79de85f..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/Shep_interp.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.nr.interp; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -/** - * Object for Shepard interpolation using n points in dim dimensions. Call - * constructor once, then interp as many times as desired. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Shep_interp { - int dim, n; - final double[][] pts; - final double[] vals; - double pneg; - - public Shep_interp(final double[][] ptss, final double[] valss) { - this(ptss, valss, 2.); - } - - /** - * The n dim matrix ptss inputs the data points, the vector valss the - * function values. Set p to the desired exponent. The default value is - * typical. - * - * @param ptss - * @param valss - * @param p - */ - public Shep_interp(final double[][] ptss, final double[] valss, - final double p) { - dim = ptss[0].length; - n = ptss.length; - pts = ptss; - vals = valss; - pneg = -p; - } - - /** - * Return the interpolated function value at a dim-dimensional point pt. - * - * @param pt - * @return - */ - public double interp(final double[] pt) { - double r, w, sum = 0., sumw = 0.; - if (pt.length != dim) - throw new IllegalArgumentException("RBF_interp bad pt size"); - for (int i = 0; i < n; i++) { - if ((r = rad(pt, pts[i])) == 0.) - return vals[i]; - sum += (w = pow(r, pneg)); - sumw += w * vals[i]; - } - return sumw / sum; - } - - public double rad(final double[] p1, final double[] p2) { - double sum = 0.; - for (int i = 0; i < dim; i++) - sum += SQR(p1[i] - p2[i]); - return sqrt(sum); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/Spline2D_interp.java b/common-tools/cnuphys/numRec/src/com/nr/interp/Spline2D_interp.java deleted file mode 100644 index 27a3d1e16f..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/Spline2D_interp.java +++ /dev/null @@ -1,153 +0,0 @@ -package com.nr.interp; - -import static com.nr.NRUtil.*; - -import org.netlib.util.doubleW; - -/** - * - * Object for two-dimensional cubic spline interpolation on a matrix. Construct - * with a vector of x1 values, a vector of x2 values, and a matrix of tabulated - * function values yij. Then call interp for interpolated values. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Spline2D_interp { - int m, n; - final double[][] y; - final double[] x1; - double[] yv; - Spline_interp[] srp; - - // NRvector srp; - - public Spline2D_interp(final double[] x1v, final double[] x2v, - final double[][] ym) { - m = x1v.length; - n = x2v.length; - y = ym; - yv = new double[m]; - x1 = x1v; - srp = new Spline_interp[m]; - for (int i = 0; i < m; i++) - srp[i] = new Spline_interp(x2v, y[i]); - } - - public double interp(final double x1p, final double x2p) { - for (int i = 0; i < m; i++) - yv[i] = srp[i].interp(x2p); - Spline_interp scol = new Spline_interp(x1, yv); - return scol.interp(x1p); - } - - private static int[] wt_d = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -3, 0, 0, 3, 0, - 0, 0, 0, -2, 0, 0, -1, 0, 0, 0, 0, 2, 0, 0, -2, 0, 0, 0, 0, 1, 0, - 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, -3, 0, - 0, 3, 0, 0, 0, 0, -2, 0, 0, -1, 0, 0, 0, 0, 2, 0, 0, -2, 0, 0, 0, - 0, 1, 0, 0, 1, -3, 3, 0, 0, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, -3, 3, 0, 0, -2, -1, 0, 0, 9, -9, 9, -9, 6, - 3, -3, -6, 6, -6, -3, 3, 4, 2, 1, 2, -6, 6, -6, 6, -4, -2, 2, 4, - -3, 3, 3, -3, -2, -1, -1, -2, 2, -2, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -2, 0, 0, 1, 1, 0, 0, -6, 6, - -6, 6, -3, -3, 3, 3, -4, 4, 2, -2, -2, -2, -1, -1, 4, -4, 4, -4, 2, - 2, -2, -2, 2, -2, -2, 2, 1, 1, 1, 1 }; - - private static int[][] wt = buildMatrix(16, 16, wt_d); - - /** - * Given arrays y[0..3], y1[0..3], y2[0..3], and y12[0..3], containing the - * function, gradients, and cross-derivative at the four grid points of a - * rectangular grid cell (numbered counterclockwise from the lower left), - * and given d1 and d2, the length of the grid cell in the 1 and 2 - * directions, this routine returns the table c[0..3][0..3] that is used by - * routine bcuint for bicubic interpolation. - * - * @param y - * @param y1 - * @param y2 - * @param y12 - * @param d1 - * @param d2 - * @param c - */ - public static void bcucof(final double[] y, final double[] y1, - final double[] y2, final double[] y12, final double d1, - final double d2, final double[][] c) { - int l, k, j, i; - double xx, d1d2 = d1 * d2; - double[] cl = new double[16]; - double[] x = new double[16]; - // static Matint wt(16,16,wt_d); - for (i = 0; i < 4; i++) { - x[i] = y[i]; - x[i + 4] = y1[i] * d1; - x[i + 8] = y2[i] * d2; - x[i + 12] = y12[i] * d1d2; - } - for (i = 0; i < 16; i++) { - xx = 0.0; - for (k = 0; k < 16; k++) - xx += wt[i][k] * x[k]; - cl[i] = xx; - } - l = 0; - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) - c[i][j] = cl[l++]; - } - - /** - * Bicubic interpolation within a grid square. Input quantities are - * y,y1,y2,y12 (as described in bcucof); x1l and x1u, the lower and upper - * coordinates of the grid square in the 1 direction; x2l and x2u likewise - * for the 2 direction; and x1,x2, the coordinates of the desired point for - * the interpolation. The interpolated function value is returned as ansy, - * and the interpolated gradient values as ansy1 and ansy2. This routine - * calls bcucof. - * - * @param y - * @param y1 - * @param y2 - * @param y12 - * @param x1l - * @param x1u - * @param x2l - * @param x2u - * @param x1 - * @param x2 - * @param ansy - * @param ansy1 - * @param ansy2 - */ - public static void bcuint(final double[] y, final double[] y1, - final double[] y2, final double[] y12, final double x1l, - final double x1u, final double x2l, final double x2u, - final double x1, final double x2, final doubleW ansy, - final doubleW ansy1, final doubleW ansy2) { - int i; - double t, u, d1 = x1u - x1l, d2 = x2u - x2l; - double[][] c = new double[4][4]; - bcucof(y, y1, y2, y12, d1, d2, c); - if (x1u == x1l || x2u == x2l) - throw new IllegalArgumentException("Bad input in routine bcuint"); - t = (x1 - x1l) / d1; - u = (x2 - x2l) / d2; - ansy.val = ansy2.val = ansy1.val = 0.0; - for (i = 3; i >= 0; i--) { - ansy.val = t * ansy.val + ((c[i][3] * u + c[i][2]) * u + c[i][1]) - * u + c[i][0]; - ansy2.val = t * ansy2.val + (3.0 * c[i][3] * u + 2.0 * c[i][2]) * u - + c[i][1]; - ansy1.val = u * ansy1.val + (3.0 * c[3][i] * t + 2.0 * c[2][i]) * t - + c[1][i]; - } - ansy1.val /= d1; - ansy2.val /= d2; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/interp/Spline_interp.java b/common-tools/cnuphys/numRec/src/com/nr/interp/Spline_interp.java deleted file mode 100644 index a6389aa2cc..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/interp/Spline_interp.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.nr.interp; - -/** - * Cubic Spline Interpolation - * - * Cubic spline interpolation object. Construct with x and y vectors, and - * (optionally) values of the first derivative at the endpoints, then call - * interp for interpolated values - * - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Spline_interp extends Base_interp { - double[] y2; - - public Spline_interp(final double[] xv, final double[] yv) { - this(xv, yv, 1.e99, 1.e99); - } - - public Spline_interp(final double[] xv, final double[] yv, - final double yp1, final double ypn) { // double yp1=1.e99, double - // ypn=1.e99 - super(xv, yv, 2); - y2 = new double[xv.length]; - sety2(xv, yv, yp1, ypn); - } - - public void sety2(final double[] xv, final double[] yv) { - sety2(xv, yv, 1.e99, 1.e99); - } - - /** - * - * This routine stores an array y2[0..n-1] with second derivatives of the - * interpolating function at the tabulated points pointed to by xv, using - * function values pointed to by yv. If yp1 and/or ypn are equal to 1.0E99 - * or larger, the routine is signaled to set the corresponding boundary - * condition for a natural spline, with zero second derivative on that - * boundary; otherwise, they are the values of the first derivatives at the - * endpoints. - * - * @param xv - * @param yv - * @param yp1 - * @param ypn - */ - public void sety2(final double[] xv, final double[] yv, final double yp1, - final double ypn) { // double yp1=1.e99, double ypn=1.e99 - int i, k; - double p, qn, sig, un; - double[] u = new double[n - 1]; - if (yp1 > 0.99e99) - y2[0] = u[0] = 0.0; - else { - y2[0] = -0.5; - u[0] = (3.0 / (xv[1] - xv[0])) - * ((yv[1] - yv[0]) / (xv[1] - xv[0]) - yp1); - } - for (i = 1; i < n - 1; i++) { - sig = (xv[i] - xv[i - 1]) / (xv[i + 1] - xv[i - 1]); - p = sig * y2[i - 1] + 2.0; - y2[i] = (sig - 1.0) / p; - u[i] = (yv[i + 1] - yv[i]) / (xv[i + 1] - xv[i]) - - (yv[i] - yv[i - 1]) / (xv[i] - xv[i - 1]); - u[i] = (6.0 * u[i] / (xv[i + 1] - xv[i - 1]) - sig * u[i - 1]) / p; - } - if (ypn > 0.99e99) - qn = un = 0.0; - else { - qn = 0.5; - un = (3.0 / (xv[n - 1] - xv[n - 2])) - * (ypn - (yv[n - 1] - yv[n - 2]) / (xv[n - 1] - xv[n - 2])); - } - y2[n - 1] = (un - qn * u[n - 2]) / (qn * y2[n - 2] + 1.0); - for (k = n - 2; k >= 0; k--) - y2[k] = y2[k] * y2[k + 1] + u[k]; - } - - /** - * Given a value x, and using pointers to data xx and yy, this routine - * returns an interpolated value y, and stores an error estimate dy. The - * returned value is obtained by mm-point polynomial interpolation on the - * subrange xx[jl..jl+mm-1]. - */ - @Override - public double rawinterp(final int jl, final double x) { - int klo = jl, khi = jl + 1; - double y, h, b, a; - h = xx[khi] - xx[klo]; - if (h == 0.0) - throw new IllegalArgumentException("Bad input to routine splint"); - a = (xx[khi] - x) / h; - b = (x - xx[klo]) / h; - y = a * yy[klo] + b * yy[khi] - + ((a * a * a - a) * y2[klo] + (b * b * b - b) * y2[khi]) - * (h * h) / 6.0; - return y; - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/inv/Fred2.java b/common-tools/cnuphys/numRec/src/com/nr/inv/Fred2.java deleted file mode 100644 index b963233cbf..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/inv/Fred2.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.nr.inv; - -import static com.nr.fi.GaussianWeights.*; -import com.nr.la.LUdcmp; - -public abstract class Fred2 { - final double a, b; - final int n; - public double[] t, f, w; - - public abstract double g(double x); - - public abstract double ak(double x, double t); - - public Fred2(final double a, final double b, final int nn) { - this.a = a; - this.b = b; - this.n = nn; - t = new double[n]; - f = new double[n]; - w = new double[n]; - - double[][] omk = new double[n][n]; - gauleg(a, b, t, w); - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) { - omk[i][j] = ((i == j) ? 1 : 0) - ak(t[i], t[j]) * w[j]; - } - f[i] = g(t[i]); - } - LUdcmp alu = new LUdcmp(omk); - alu.solve(f, f); - } - - public double fredin(final double x) { - double sum = 0.0; - for (int i = 0; i < n; i++) - sum += ak(x, t[i]) * w[i] * f[i]; - return g(x) + sum; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/inv/Quad_matrix.java b/common-tools/cnuphys/numRec/src/com/nr/inv/Quad_matrix.java deleted file mode 100644 index d94d29f34f..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/inv/Quad_matrix.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.nr.inv; - -import static java.lang.Math.*; -import com.nr.UniVarRealMultiValueFun; -import com.nr.la.LUdcmp; - -public class Quad_matrix implements UniVarRealMultiValueFun { - int n; - double x; - - public Quad_matrix(final double[][] a) { - n = a.length; - double[] wt = new double[n]; - double h = PI / (n - 1); - Wwghts w = new Wwghts(h, n, this); - for (int j = 0; j < n; j++) { - x = j * h; - wt = w.weights(); - double cx = cos(x); - for (int k = 0; k < n; k++) - a[j][k] = wt[k] * cx * cos(k * h); - ++a[j][j]; - } - } - - @Override - public double[] funk(final double y) { - double d, df, clog, x2, x3, x4, y2; - double[] w = new double[4]; - if (y >= x) { - d = y - x; - df = 2.0 * sqrt(d) * d; - w[0] = df / 3.0; - w[1] = df * (x / 3.0 + d / 5.0); - w[2] = df * ((x / 3.0 + 0.4 * d) * x + d * d / 7.0); - w[3] = df - * (((x / 3.0 + 0.6 * d) * x + 3.0 * d * d / 7.0) * x + d - * d * d / 9.0); - } else { - x3 = (x2 = x * x) * x; - x4 = x2 * x2; - y2 = y * y; - d = x - y; - w[0] = d * ((clog = log(d)) - 1.0); - w[1] = -0.25 * (3.0 * x + y - 2.0 * clog * (x + y)) * d; - w[2] = (-11.0 * x3 + y * (6.0 * x2 + y * (3.0 * x + 2.0 * y)) + 6.0 - * clog * (x3 - y * y2)) / 18.0; - w[3] = (-25.0 * x4 + y - * (12.0 * x3 + y * (6.0 * x2 + y * (4.0 * x + 3.0 * y))) + 12.0 - * clog * (x4 - (y2 * y2))) / 48.0; - } - return w; - } - - public static void main(final String[] args) { - final int N = 40; - - double[] g = new double[N]; - double[][] a = new double[N][N]; - new Quad_matrix(a); - LUdcmp alu = new LUdcmp(a); - for (int j = 0; j < N; j++) - g[j] = sin(j * PI / (N - 1)); - alu.solve(g, g); - for (int j = 0; j < N; j++) { - double x = j * PI / (N - 1); - System.out.printf("%d %f %f\n", (j + 1), x, g[j]); - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/inv/Volterra.java b/common-tools/cnuphys/numRec/src/com/nr/inv/Volterra.java deleted file mode 100644 index 3f8e0e45e8..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/inv/Volterra.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.nr.inv; - -import com.nr.la.LUdcmp; - -/** - * Solves a set of m linear Volterra equations of the second kind using the - * extended trapezoidal rule. On input, t0 is the starting point of the - * integration and h is the step size. g(k,t) is a user-supplied function or - * functor that returns gk(t), while ak(k,l,t,s) is another user- supplied - * function or functor that returns the (k,l) element of the matrix K(t,s). The - * solution is returned in f[0..m-1][0..n-1], with the corresponding abscissas - * in t[0..n-1], where n-1 is the number of steps to be taken. The value of m is - * determined from the row-dimension of the solution matrix f. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public abstract class Volterra { - - public abstract double g(int k, double t); - - public abstract double ak(int k, int l, double t1, double t2); - - public void voltra(final double t0, final double h, final double[] t, - final double[][] f) { - int m = f.length; - int n = f[0].length; - double[] b = new double[m]; - double[][] a = new double[m][m]; - t[0] = t0; - for (int k = 0; k < m; k++) - f[k][0] = g(k, t[0]); - for (int i = 1; i < n; i++) { - t[i] = t[i - 1] + h; - for (int k = 0; k < m; k++) { - double sum = g(k, t[i]); - for (int l = 0; l < m; l++) { - sum += 0.5 * h * ak(k, l, t[i], t[0]) * f[l][0]; - for (int j = 1; j < i; j++) - sum += h * ak(k, l, t[i], t[j]) * f[l][j]; - if (k == l) - a[k][l] = 1.0 - 0.5 * h * ak(k, l, t[i], t[i]); - else - a[k][l] = -0.5 * h * ak(k, l, t[i], t[i]); - } - b[k] = sum; - } - LUdcmp alu = new LUdcmp(a); - alu.solve(b, b); - for (int k = 0; k < m; k++) - f[k][i] = b[k]; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/inv/Wwghts.java b/common-tools/cnuphys/numRec/src/com/nr/inv/Wwghts.java deleted file mode 100644 index f58553b140..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/inv/Wwghts.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.nr.inv; - -import com.nr.UniVarRealMultiValueFun; -import static com.nr.NRUtil.*; - -/** - * Constructs weights for the n-point equal-interval quadrature from O to (n-1)h - * of a function f(x) times an arbitrary (possibly singular) weight function - * w(x). The indefinite-integral moments Fn(y) of w(x) are provided by the - * user-supplied function kermom in the quad object. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Wwghts { - double h; - int n; - UniVarRealMultiValueFun quad; // kermom - double[] wghts; - - public Wwghts(final double hh, final int nn, final UniVarRealMultiValueFun q) { - h = hh; - n = nn; - quad = q; - wghts = new double[n]; - } - - public double[] weights() { - int k; - double fac; - double hi = 1.0 / h; - for (int j = 0; j < n; j++) - wghts[j] = 0.0; - if (n >= 4) { - double[] wold = new double[4], wnew = new double[4], w = new double[4]; - wold = buildVector(quad.funk(0.0)); - double b = 0.0; - for (int j = 0; j < n - 3; j++) { - double c = j; - double a = b; - b = a + h; - if (j == n - 4) - b = (n - 1) * h; - wnew = buildVector(quad.funk(b)); - for (fac = 1.0, k = 0; k < 4; k++, fac *= hi) - w[k] = (wnew[k] - wold[k]) * fac; - wghts[j] += (((c + 1.0) * (c + 2.0) * (c + 3.0) * w[0] - - (11.0 + c * (12.0 + c * 3.0)) * w[1] + 3.0 - * (c + 2.0) * w[2] - w[3]) / 6.0); - wghts[j + 1] += ((-c * (c + 2.0) * (c + 3.0) * w[0] - + (6.0 + c * (10.0 + c * 3.0)) * w[1] - (3.0 * c + 5.0) - * w[2] + w[3]) * 0.5); - wghts[j + 2] += ((c * (c + 1.0) * (c + 3.0) * w[0] - - (3.0 + c * (8.0 + c * 3.0)) * w[1] + (3.0 * c + 4.0) - * w[2] - w[3]) * 0.5); - wghts[j + 3] += ((-c * (c + 1.0) * (c + 2.0) * w[0] - + (2.0 + c * (6.0 + c * 3.0)) * w[1] - 3.0 * (c + 1.0) - * w[2] + w[3]) / 6.0); - for (k = 0; k < 4; k++) - wold[k] = wnew[k]; - } - } else if (n == 3) { - double[] wold = new double[3], wnew = new double[3], w = new double[3]; - wold = buildVector(quad.funk(0.0)); - wnew = buildVector(quad.funk(h + h)); - w[0] = wnew[0] - wold[0]; - w[1] = hi * (wnew[1] - wold[1]); - w[2] = hi * hi * (wnew[2] - wold[2]); - wghts[0] = w[0] - 1.5 * w[1] + 0.5 * w[2]; - wghts[1] = 2.0 * w[1] - w[2]; - wghts[2] = 0.5 * (w[2] - w[1]); - } else if (n == 2) { - double[] wold = new double[2], wnew = new double[2];// ,w=new - // double[2]; - wold = buildVector(quad.funk(0.0)); - wnew = buildVector(quad.funk(h)); - wghts[0] = wnew[0] - wold[0] - - (wghts[1] = hi * (wnew[1] - wold[1])); - } - return wghts; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/la/ADAT.java b/common-tools/cnuphys/numRec/src/com/nr/la/ADAT.java deleted file mode 100644 index f98df9c341..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/la/ADAT.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.nr.la; - -import java.util.Arrays; - -/** - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class ADAT { - final NRsparseMat a, at; - - private NRsparseMat adat; // XXX pointer to ref - - public ADAT(final NRsparseMat A, final NRsparseMat AT) { - a = A; - at = AT; - - int h, i, j, k, l, nvals, m = AT.ncols; - int[] done = new int[m]; - for (i = 0; i < m; i++) - done[i] = -1; - nvals = 0; - for (j = 0; j < m; j++) { - for (i = AT.col_ptr[j]; i < AT.col_ptr[j + 1]; i++) { - k = AT.row_ind[i]; - for (l = A.col_ptr[k]; l < A.col_ptr[k + 1]; l++) { - h = A.row_ind[l]; - if (done[h] != j) { - done[h] = j; - nvals++; - } - } - } - } - adat = new NRsparseMat(m, m, nvals); - for (i = 0; i < m; i++) - done[i] = -1; - nvals = 0; - for (j = 0; j < m; j++) { - adat.col_ptr[j] = nvals; - for (i = AT.col_ptr[j]; i < AT.col_ptr[j + 1]; i++) { - k = AT.row_ind[i]; - for (l = A.col_ptr[k]; l < A.col_ptr[k + 1]; l++) { - h = A.row_ind[l]; - if (done[h] != j) { - done[h] = j; - adat.row_ind[nvals] = h; - nvals++; - } - } - } - } - adat.col_ptr[m] = nvals; - for (j = 0; j < m; j++) { - i = adat.col_ptr[j]; - int size = adat.col_ptr[j + 1] - i; - if (size > 1) { // XXX pointer - // int[] col(size,&adat->row_ind[i]); - int[] col = new int[size]; - for (int kk = 0; kk < col.length; kk++) { - col[kk] = adat.row_ind[i + kk]; - } - Arrays.sort(col); // XXX use java sort - for (k = 0; k < size; k++) - adat.row_ind[i + k] = col[k]; - } - } - } - - public void updateD(final double[] D) { - int h, i, j, k, l, m = a.nrows, n = a.ncols; - double[] temp = new double[n]; - double[] temp2 = new double[m]; - for (i = 0; i < m; i++) { - for (j = at.col_ptr[i]; j < at.col_ptr[i + 1]; j++) { - k = at.row_ind[j]; - temp[k] = at.val[j] * D[k]; - } - for (j = at.col_ptr[i]; j < at.col_ptr[i + 1]; j++) { - k = at.row_ind[j]; - for (l = a.col_ptr[k]; l < a.col_ptr[k + 1]; l++) { - h = a.row_ind[l]; - temp2[h] += temp[k] * a.val[l]; - } - } - for (j = adat.col_ptr[i]; j < adat.col_ptr[i + 1]; j++) { - k = adat.row_ind[j]; - adat.val[j] = temp2[k]; - temp2[k] = 0.0; - } - } - } - - public NRsparseMat ref() { - return adat; - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/la/Bandec.java b/common-tools/cnuphys/numRec/src/com/nr/la/Bandec.java deleted file mode 100644 index f49673a3c8..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/la/Bandec.java +++ /dev/null @@ -1,141 +0,0 @@ -package com.nr.la; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -/** - * Band-Diagonal Systems - PTC - * - * Object for solving linear equations A*x = b for a band-diagonal matrix A, - * using LU decomposition - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Bandec { - int n, m1, m2; - /** - * Upper and lower triangular matrices, stored compactly. - */ - double[][] au, al; - int[] indx; - double d; - - public static void banmul(final double[][] a, final int m1, final int m2, - final double[] x, final double[] b) { - int i, j, k, tmploop, n = a.length; - for (i = 0; i < n; i++) { - k = i - m1; - tmploop = min(m1 + m2 + 1, (n - k)); - b[i] = 0.0; - for (j = max(0, -k); j < tmploop; j++) - b[i] += a[i][j] * x[j + k]; - } - } - - public Bandec(final double[][] a, final int mm1, final int mm2) { - n = a.length; - au = buildMatrix(a); - m1 = mm1; - m2 = mm2; - al = buildMatrix(n, m1, 0.0); - indx = new int[n]; - - final double TINY = 1.0e-40; - int i, j, k, l, mm; - double dum; - mm = m1 + m2 + 1; - l = m1; - for (i = 0; i < m1; i++) { - for (j = m1 - i; j < mm; j++) - au[i][j - l] = au[i][j]; - l--; - for (j = mm - l - 1; j < mm; j++) - au[i][j] = 0.0; - } - d = 1.0; - l = m1; - for (k = 0; k < n; k++) { - dum = au[k][0]; - i = k; - if (l < n) - l++; - for (j = k + 1; j < l; j++) { - if (abs(au[j][0]) > abs(dum)) { - dum = au[j][0]; - i = j; - } - } - indx[k] = i + 1; - if (dum == 0.0) - au[k][0] = TINY; - if (i != k) { - d = -d; - for (j = 0; j < mm; j++) { - // SWAP(au[k][j],au[i][j]); - double swap = au[k][j]; - au[k][j] = au[i][j]; - au[i][j] = swap; - } - } - for (i = k + 1; i < l; i++) { - dum = au[i][0] / au[k][0]; - al[k][i - k - 1] = dum; - for (j = 1; j < mm; j++) - au[i][j - 1] = au[i][j] - dum * au[k][j]; - au[i][mm - 1] = 0.0; - } - } - } - - /** - * Given a right-hand side vector b[0..n-1], solves the band-diagonal linear - * equations A*x = b. The solution vector x is returned as x[0..n-1]. - * - * @param b - * @param x - */ - public void solve(final double[] b, final double[] x) { - int i, j, k, l, mm; - double dum; - mm = m1 + m2 + 1; - l = m1; - for (k = 0; k < n; k++) - x[k] = b[k]; - for (k = 0; k < n; k++) { - j = indx[k] - 1; - if (j != k) { - swap(x, k, j); - } - if (l < n) - l++; - for (j = k + 1; j < l; j++) - x[j] -= al[k][j - k - 1] * x[k]; - } - l = 1; - for (i = n - 1; i >= 0; i--) { - dum = x[i]; - for (k = 1; k < l; k++) - dum -= au[i][k] * x[k + i]; - x[i] = dum / au[i][0]; - if (l < mm) - l++; - } - } - - /** - * Using the stored decomposition, return the determinant of the matrix A. - * - * @return - */ - public double det() { - double dd = d; - for (int i = 0; i < n; i++) - dd *= au[i][0]; - return dd; - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/la/Cholesky.java b/common-tools/cnuphys/numRec/src/com/nr/la/Cholesky.java deleted file mode 100644 index e3b94af3f1..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/la/Cholesky.java +++ /dev/null @@ -1,163 +0,0 @@ -package com.nr.la; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -/** - * Cholesky decomposition of a matrix A. - PTC - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Cholesky { - int n; - - /** - * Stores the decomposition - * - */ - double[][] el; - - /** - * Given a positive-definite symmetric matrix a[0..n-1][0..n-1], construct - * and store its Cholesky decomposition, A = L* Lt . - * - * @param a - */ - public Cholesky(final double[][] a) { - n = a.length; - el = buildMatrix(a); - - int i, j, k; - double sum; - if (el[0].length != n) - throw new IllegalArgumentException("need square matrix"); - for (i = 0; i < n; i++) { - for (j = i; j < n; j++) { - for (sum = el[i][j], k = i - 1; k >= 0; k--) - sum -= el[i][k] * el[j][k]; - if (i == j) { - if (sum <= 0.0) - throw new IllegalArgumentException("Cholesky failed"); - el[i][i] = sqrt(sum); - } else - el[j][i] = sum / el[i][i]; - } - } - for (i = 0; i < n; i++) - for (j = 0; j < i; j++) - el[j][i] = 0.; - } - - /** - * Solve the set of n linear equations A*x = b, where a is a - * positive-definite symmetric matrix whose Cholesky decomposition has been - * stored. b[0..n-1] is input as the right-hand side vector. The solution - * vector is returned in x[0..n-1]. - * - * @param b - * @param x - */ - public void solve(final double[] b, final double[] x) { - int i, k; - double sum; - if (b.length != n || x.length != n) - throw new IllegalArgumentException("bad lengths in Cholesky"); - for (i = 0; i < n; i++) { - for (sum = b[i], k = i - 1; k >= 0; k--) - sum -= el[i][k] * x[k]; - x[i] = sum / el[i][i]; - } - for (i = n - 1; i >= 0; i--) { - for (sum = x[i], k = i + 1; k < n; k++) - sum -= el[k][i] * x[k]; - x[i] = sum / el[i][i]; - } - } - - /** - * Multiply L y = b, where L is the lower triangular matrix in the stored - * Cholesky decomposition. y[0..n-1] is input. The result is returned in - * b[0..n-1]. - * - * @param y - * @param b - */ - public void elmult(final double[] y, final double[] b) { - int i, j; - if (b.length != n || y.length != n) - throw new IllegalArgumentException("bad lengths"); - for (i = 0; i < n; i++) { - b[i] = 0.; - for (j = 0; j <= i; j++) - b[i] += el[i][j] * y[j]; - } - } - - /** - * Solve L*y = b, where L is the lower triangular matrix in the stored - * Cholesky decomposition. b[0..n-1] is input as the right-hand side vector. - * The solution vector is returned in y[0..n-1]. - * - * @param b - * @param y - */ - public void elsolve(final double[] b, final double[] y) { - int i, j; - double sum; - if (b.length != n || y.length != n) - throw new IllegalArgumentException("bad lengths"); - for (i = 0; i < n; i++) { - for (sum = b[i], j = 0; j < i; j++) - sum -= el[i][j] * y[j]; - y[i] = sum / el[i][i]; - } - } - - /** - * Set ainv[0..n-1][0..n-1] to the matrix inverse of A, the matrix whose - * Cholesky decomposition has been stored. - * - * @param ainv - */ - public void inverse(final double[][] ainv) { - if (ainv == null || ainv[0] == null) - throw new IllegalArgumentException("Must be n x n matrix"); - if (ainv.length != n || ainv[0].length != n) - throw new IllegalArgumentException("Must be n x n matrix"); - - int i, j, k; - double sum; - // ainv = resize(ainv, n,n); - for (i = 0; i < n; i++) - for (j = 0; j <= i; j++) { - sum = (i == j ? 1. : 0.); - for (k = i - 1; k >= j; k--) - sum -= el[i][k] * ainv[j][k]; - ainv[j][i] = sum / el[i][i]; - } - for (i = n - 1; i >= 0; i--) - for (j = 0; j <= i; j++) { - sum = (i < j ? 0. : ainv[j][i]); - for (k = i + 1; k < n; k++) - sum -= el[k][i] * ainv[j][k]; - ainv[i][j] = ainv[j][i] = sum / el[i][i]; - } - } - - /** - * Return the logarithm of the determinant of A, the matrix whose Cholesky - * decomposition has been stored. - * - * @return - */ - public double logdet() { - double sum = 0.; - for (int i = 0; i < n; i++) - sum += log(el[i][i]); - return 2. * sum; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/la/GaussJordan.java b/common-tools/cnuphys/numRec/src/com/nr/la/GaussJordan.java deleted file mode 100644 index e6b4dc6b87..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/la/GaussJordan.java +++ /dev/null @@ -1,123 +0,0 @@ -package com.nr.la; - -import static java.lang.Math.*; - -public class GaussJordan { - private GaussJordan() { - } - - /** - * Gauss-Jordan decomposition - PTC - * - * - * Linear equation solution by Gauss-Jordan elimination. The input matrix is - * a[0..n-1][0..n-1]. b[0..n-1][0..m-1] is input containing the m right-hand - * side vectors. On output, a is replaced by its matrix inverse, and b is - * replaced by the corresponding set of solution vectors. - * - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation - * Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ - public static void gaussj(final double[][] a, final double[][] b) { - int i, icol = 0, irow = 0, j, k, l, ll, n = a.length, m = b[0].length; - double big, dum, pivinv; - // These integer arrays are used for bookkeeping on the pivoting - int[] indxc = new int[n]; - int[] indxr = new int[n]; - int[] ipiv = new int[n]; - for (j = 0; j < n; j++) - ipiv[j] = 0; - // This is the main loop over the columns to be reduced. - for (i = 0; i < n; i++) { - big = 0.0; - // This is the outer loop of the search for a pivot element. - for (j = 0; j < n; j++) - if (ipiv[j] != 1) - for (k = 0; k < n; k++) { - if (ipiv[k] == 0) { - if (abs(a[j][k]) >= big) { - big = abs(a[j][k]); - irow = j; - icol = k; - } - } - } - ++(ipiv[icol]); - /* - * We now have the pivot element, so we interchange rows, if needed, - * to put the pivot element on the diagonal. The columns are not - * physically interchanged, only relabeled: indxc[i], the column of - * the .i C 1/th pivot element, is the .i C 1/th column that is - * reduced, while indxr[i] is the row in which that pivot element - * was originally located. If indxr[i] ¤ indxc[i], there is an - * implied column interchange. With this form of bookkeeping, the - * solution b's will end up in the correct order, and the inverse - * matrix will be scrambled by columns. - */ - if (irow != icol) { - for (l = 0; l < n; l++) { - // SWAP(a[irow][l],a[icol][l]); - double swap = a[irow][l]; - a[irow][l] = a[icol][l]; - a[icol][l] = swap; - } - for (l = 0; l < m; l++) { - // SWAP(b[irow][l],b[icol][l]); - double swap = b[irow][l]; - b[irow][l] = b[icol][l]; - b[icol][l] = swap; - } - } - /* - * We are now ready to divide the pivot row by the pivot element, - * located at irow and icol. - */ - indxr[i] = irow; - indxc[i] = icol; - if (a[icol][icol] == 0.0) - throw new IllegalArgumentException("gaussj: Singular Matrix"); - pivinv = 1.0 / a[icol][icol]; - a[icol][icol] = 1.0; - for (l = 0; l < n; l++) - a[icol][l] *= pivinv; - for (l = 0; l < m; l++) - b[icol][l] *= pivinv; - /* - * Next, we reduce the rows..., except for the pivot one, of course. - */ - for (ll = 0; ll < n; ll++) - if (ll != icol) { - dum = a[ll][icol]; - a[ll][icol] = 0.0; - for (l = 0; l < n; l++) - a[ll][l] -= a[icol][l] * dum; - for (l = 0; l < m; l++) - b[ll][l] -= b[icol][l] * dum; - } - } - for (l = n - 1; l >= 0; l--) { - if (indxr[l] != indxc[l]) - for (k = 0; k < n; k++) { - // SWAP(a[k][indxr[l]],a[k][indxc[l]]); - double swap = a[k][indxr[l]]; - a[k][indxr[l]] = a[k][indxc[l]]; - a[k][indxc[l]] = swap; - } - } - } - - /** - * Overloaded version with no right-hand sides. Replaces a by its inverse. - * - * @param a - */ - public static void gaussj(final double[][] a) { - double[][] b = new double[a.length][0]; // Dummy vector with zero - // columns. - gaussj(a, b); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/la/LUdcmp.java b/common-tools/cnuphys/numRec/src/com/nr/la/LUdcmp.java deleted file mode 100644 index 84362e7ec7..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/la/LUdcmp.java +++ /dev/null @@ -1,210 +0,0 @@ -package com.nr.la; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -/** - * LU decomposition - PTC - * - * Iterative Improvement of a Solution to Linear Equations - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class LUdcmp { - private int n; - /** - * Stores the decomposition - */ - private double[][] lu; - - /** - * Stores the permutation. - */ - private int[] indx; - - /** - * Used by det. - */ - private double d; - - private double[][] aref; - - /** - * Given a matrix a[0..n-1][0..n-1], this routine replaces it by the LU - * decomposition of a rowwise permutation of itself. a is input. On output, - * it is arranged as in equation (2.3.14) above; indx[0..n-1] is an output - * vector that records the row permutation effected by the partial pivoting; - * d is output as +/-1 depending on whether the number of row interchanges - * was even or odd, respectively. This routine is used in combination with - * solve to solve linear equations or invert a matrix. - * - * @param a - */ - public LUdcmp(final double[][] a) { - n = a.length; - lu = buildMatrix(a); - aref = a; - indx = new int[n]; - - final double TINY = 1.0e-40; - int i, imax, j, k; - double big, temp; - double[] vv = new double[n]; - d = 1.0; - for (i = 0; i < n; i++) { - big = 0.0; - for (j = 0; j < n; j++) - if ((temp = abs(lu[i][j])) > big) - big = temp; - if (big == 0.0) - throw new IllegalArgumentException("Singular matrix in LUdcmp"); - vv[i] = 1.0 / big; - } - for (k = 0; k < n; k++) { - big = 0.0; - imax = k; - for (i = k; i < n; i++) { - temp = vv[i] * abs(lu[i][k]); - if (temp > big) { - big = temp; - imax = i; - } - } - if (k != imax) { - for (j = 0; j < n; j++) { - temp = lu[imax][j]; - lu[imax][j] = lu[k][j]; - lu[k][j] = temp; - } - d = -d; - vv[imax] = vv[k]; - } - indx[k] = imax; - if (lu[k][k] == 0.0) - lu[k][k] = TINY; - for (i = k + 1; i < n; i++) { - temp = lu[i][k] /= lu[k][k]; - for (j = k + 1; j < n; j++) - lu[i][j] -= temp * lu[k][j]; - } - } - } - - /** - * Solves the set of n linear equations A*x = b using the stored LU - * decomposition of A. b[0..n-1] is input as the right-hand side vector b, - * while x returns the solution vector x; b and x may reference the same - * vector, in which case the solution overwrites the input. This routine - * takes into account the possibility that b will begin with many zero - * elements, so it is efficient for use in matrix inversion. - * - * @param b - * @param x - */ - public void solve(final double[] b, final double[] x) { - int i, ii = 0, ip, j; - double sum; - if (b.length != n || x.length != n) - throw new IllegalArgumentException("solve bad sizes"); - for (i = 0; i < n; i++) - x[i] = b[i]; - for (i = 0; i < n; i++) { - ip = indx[i]; - sum = x[ip]; - x[ip] = x[i]; - if (ii != 0) - for (j = ii - 1; j < i; j++) - sum -= lu[i][j] * x[j]; - else if (sum != 0.0) - ii = i + 1; - x[i] = sum; - } - for (i = n - 1; i >= 0; i--) { - sum = x[i]; - for (j = i + 1; j < n; j++) - sum -= lu[i][j] * x[j]; - x[i] = sum / lu[i][i]; - } - } - - /** - * Solves m sets of n linear equations A*X = B using the stored LU - * decomposition of A. The matrix b[0..n-1][0..m-1] inputs the right-hand - * sides, while x[0..n-1][0..m-1] returns the solution A^-1* B. b and x may - * reference the same matrix, in which case the solution overwrites the - * input. - * - * @param b - * @param x - */ - public void solve(final double[][] b, final double[][] x) { - int i, j, m = b[0].length; - if (b.length != n || x.length != n || b[0].length != x[0].length) - throw new IllegalArgumentException("solve bad sizes"); - double[] xx = new double[n]; - for (j = 0; j < m; j++) { // Copy and solve each column in turn. - for (i = 0; i < n; i++) - xx[i] = b[i][j]; - solve(xx, xx); - for (i = 0; i < n; i++) - x[i][j] = xx[i]; - } - } - - /** - * Using the stored LU decomposition, return in ainv the matrix inverse - * - * @param ainv - */ - public double[][] inverse() { - int i, j; - final double[][] ainv = new double[n][n]; - for (i = 0; i < n; i++) { - for (j = 0; j < n; j++) - ainv[i][j] = 0.; - ainv[i][i] = 1.; - } - solve(ainv, ainv); - return ainv; - } - - /** - * Using the stored LU decomposition, return the determinant of the matrix - * A. - * - * @return - */ - public double det() { - double dd = d; - for (int i = 0; i < n; i++) - dd *= lu[i][i]; - return dd; - } - - /** - * Improves a solution vector x[0..n-1] of the linear set of equations A*x= - * b. The vectors b[0..n-1] and x[0..n-1] are input. On output, x[0..n-1] is - * modified, to an improved set of values. - * - * @param b - * @param x - */ - public void mprove(final double[] b, final double[] x) { - int i, j; - double[] r = new double[n]; - for (i = 0; i < n; i++) { - double sdp = -b[i]; - for (j = 0; j < n; j++) - sdp += aref[i][j] * x[j]; - r[i] = sdp; - } - solve(r, r); - for (i = 0; i < n; i++) - x[i] -= r[i]; - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/la/Linbcg.java b/common-tools/cnuphys/numRec/src/com/nr/la/Linbcg.java deleted file mode 100644 index 0e5c2294e1..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/la/Linbcg.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.nr.la; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -import org.netlib.util.doubleW; -import org.netlib.util.intW; - -/** - * Abstract base class for solving sparse linear equations by the preconditioned - * biconjugate gradient method. To use, declare a derived class in which the - * methods atimes and asolve are defined for your problem, along with any data - * that they need. Then call the solve method. - * - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public abstract class Linbcg { - public abstract void asolve(double[] b, double[] x, final int itrnsp); - - public abstract void atimes(double[] x, double[] r, final int itrnsp); - - public void solve(final double[] b, final double[] x, final int itol, - final double tol, final int itmax, final intW iter, - final doubleW err) { - double ak, akden, bk, bkden = 1.0, bknum, bnrm, dxnrm, xnrm, zm1nrm, znrm = 0; - final double EPS = 1.0e-14; - int j, n = b.length; - double[] p = new double[n]; - double[] pp = new double[n]; - double[] r = new double[n]; - double[] rr = new double[n]; - double[] z = new double[n]; - double[] zz = new double[n]; - iter.val = 0; - atimes(x, r, 0); - for (j = 0; j < n; j++) { - r[j] = b[j] - r[j]; - rr[j] = r[j]; - } - // atimes(r,rr,0); - if (itol == 1) { - bnrm = snrm(b, itol); - asolve(r, z, 0); - } else if (itol == 2) { - asolve(b, z, 0); - bnrm = snrm(z, itol); - asolve(r, z, 0); - } else if (itol == 3 || itol == 4) { - asolve(b, z, 0); - bnrm = snrm(z, itol); - asolve(r, z, 0); - znrm = snrm(z, itol); - } else - throw new IllegalArgumentException("illegal itol in linbcg"); - while (iter.val < itmax) { - ++iter.val; - asolve(rr, zz, 1); - for (bknum = 0.0, j = 0; j < n; j++) - bknum += z[j] * rr[j]; - if (iter.val == 1) { - for (j = 0; j < n; j++) { - p[j] = z[j]; - pp[j] = zz[j]; - } - } else { - bk = bknum / bkden; - for (j = 0; j < n; j++) { - p[j] = bk * p[j] + z[j]; - pp[j] = bk * pp[j] + zz[j]; - } - } - bkden = bknum; - atimes(p, z, 0); - for (akden = 0.0, j = 0; j < n; j++) - akden += z[j] * pp[j]; - ak = bknum / akden; - atimes(pp, zz, 1); - for (j = 0; j < n; j++) { - x[j] += ak * p[j]; - r[j] -= ak * z[j]; - rr[j] -= ak * zz[j]; - } - asolve(r, z, 0); - if (itol == 1) - err.val = snrm(r, itol) / bnrm; - else if (itol == 2) - err.val = snrm(z, itol) / bnrm; - else if (itol == 3 || itol == 4) { - zm1nrm = znrm; - znrm = snrm(z, itol); - if (abs(zm1nrm - znrm) > EPS * znrm) { - dxnrm = abs(ak) * snrm(p, itol); - err.val = znrm / abs(zm1nrm - znrm) * dxnrm; - } else { - err.val = znrm / bnrm; - continue; - } - xnrm = snrm(x, itol); - if (err.val <= 0.5 * xnrm) - err.val /= xnrm; - else { - err.val = znrm / bnrm; - continue; - } - } - if (err.val <= tol) - break; - } - } - - /** - * Compute one of two norms for a vector sx[0..n-1], as signaled by itol. - * Used by solve. - * - * @param sx - * @param itol - * @return - */ - public double snrm(final double[] sx, final int itol) { - int i, isamax, n = sx.length; - double ans; - if (itol <= 3) { - ans = 0.0; - for (i = 0; i < n; i++) - ans += SQR(sx[i]); - return sqrt(ans); - } else { - isamax = 0; - for (i = 0; i < n; i++) { - if (abs(sx[i]) > abs(sx[isamax])) - isamax = i; - } - return abs(sx[isamax]); - } - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/la/NRsparseCol.java b/common-tools/cnuphys/numRec/src/com/nr/la/NRsparseCol.java deleted file mode 100644 index 24ffbcab74..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/la/NRsparseCol.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.nr.la; - -import static com.nr.NRUtil.*; - -/** - * Sparse vector data structure. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class NRsparseCol { - /** - * Number of rows. - * - */ - public int nrows; - - /** - * Maximum number of nonzeros. - * - */ - public int nvals; - - /** - * Row indices of nonzeros. - * - */ - public int[] row_ind; - - /** - * Array of nonzero values. - * - */ - public double[] val; - - public NRsparseCol(final int m, final int nnvals) { - nrows = m; - nvals = nnvals; - row_ind = new int[nnvals]; - val = buildVector(nnvals, 0.0); - } - - public NRsparseCol() { - nrows = 0; - nvals = 0; - row_ind = null; - val = null; - } - - public void resize(final int m, final int nnvals) { - nrows = m; - nvals = nnvals; - row_ind = new int[nnvals]; - val = new double[nvals]; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/la/NRsparseLinbcg.java b/common-tools/cnuphys/numRec/src/com/nr/la/NRsparseLinbcg.java deleted file mode 100644 index 26a64be641..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/la/NRsparseLinbcg.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.nr.la; - -/** - * bi-conjugate gradient sparse linear solver (example) - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class NRsparseLinbcg extends Linbcg { - NRsparseMat mat; - int n; - - public NRsparseLinbcg(final NRsparseMat matrix) { - mat = matrix; - n = mat.nrows; - } - - @Override - public void atimes(final double[] x, final double[] r, final int itrnsp) { - double[] rr; - if (itrnsp > 0) - rr = mat.atx(x); - else - rr = mat.ax(x); - System.arraycopy(rr, 0, r, 0, rr.length); - } - - @Override - public void asolve(final double[] b, final double[] x, final int itrnsp) { - int i, j; - double diag; - for (i = 0; i < n; i++) { - diag = 0.0; - for (j = mat.col_ptr[i]; j < mat.col_ptr[i + 1]; j++) - if (mat.row_ind[j] == i) { - diag = mat.val[j]; - break; - } - x[i] = (diag != 0.0 ? b[i] / diag : b[i]); - } - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/la/NRsparseMat.java b/common-tools/cnuphys/numRec/src/com/nr/la/NRsparseMat.java deleted file mode 100644 index d8d5858db6..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/la/NRsparseMat.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.nr.la; - -/** - * Sparse matrix data structure for compressed column storage. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class NRsparseMat { - /** - * Number of rows. - */ - public int nrows = 0; - - /** - * Number of columns. - */ - public int ncols = 0; - - /** - * Maximum number of nonzeros. - */ - public int nvals = 0; - - /** - * Pointers to start of columns. Length is ncols+1. - */ - public int[] col_ptr = null; - - /** - * Row indices of nonzeros - */ - public int[] row_ind = null; - - /** - * Array of nonzero values. - */ - public double[] val = null; - - public NRsparseMat() { - } - - public NRsparseMat(final int m, final int n, final int nnvals) { - nrows = m; - ncols = n; - nvals = nnvals; - col_ptr = new int[n + 1]; - row_ind = new int[nnvals]; - val = new double[nnvals]; - } - - public double[] ax(final double[] x) { - double[] y = new double[nrows]; - for (int j = 0; j < ncols; j++) { - for (int i = col_ptr[j]; i < col_ptr[j + 1]; i++) - y[row_ind[i]] += val[i] * x[j]; - } - return y; - } - - public double[] atx(final double[] x) { - double[] y = new double[ncols]; - for (int i = 0; i < ncols; i++) { - y[i] = 0.0; - for (int j = col_ptr[i]; j < col_ptr[i + 1]; j++) - y[i] += val[j] * x[row_ind[j]]; - } - return y; - } - - public NRsparseMat transpose() { - int i, j, k, index, m = nrows, n = ncols; - NRsparseMat at = new NRsparseMat(n, m, nvals); - int[] count = new int[m]; - for (i = 0; i < n; i++) - for (j = col_ptr[i]; j < col_ptr[i + 1]; j++) { - k = row_ind[j]; - count[k]++; - } - for (j = 0; j < m; j++) - at.col_ptr[j + 1] = at.col_ptr[j] + count[j]; - for (j = 0; j < m; j++) - count[j] = 0; - for (i = 0; i < n; i++) - for (j = col_ptr[i]; j < col_ptr[i + 1]; j++) { - k = row_ind[j]; - index = at.col_ptr[k] + count[k]; - at.row_ind[index] = i; - at.val[index] = val[j]; - count[k]++; - } - return at; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/la/QRdcmp.java b/common-tools/cnuphys/numRec/src/com/nr/la/QRdcmp.java deleted file mode 100644 index a49e610580..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/la/QRdcmp.java +++ /dev/null @@ -1,235 +0,0 @@ -package com.nr.la; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -/** - * QR Decomposition - PTC - * - * There is another matrix factorization that is sometimes very useful, the - * so-called QR decomposition, A=Q*R Here R is upper triangular, while Q is - * orthogonal, that is, QT*Q = 1 - * - * QR decomposition can be used to solve systems of linear equations. To solve - * - * A*x=b - * - * first form QT*b and then solve R*x=QT*b by backsubstitution. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class QRdcmp { - public int n; - - /** - * Stored QT and R - */ - public double[][] qt, r; - - /** - * Indicates whether A is singular - */ - public boolean sing; - - /** - * Construct the QR decomposition of a[0..n-1][0..n-1]. The upper triangular - * matrix R and the transpose of the orthogonal matrix Q are stored. sing is - * set to true if a singularity is encountered during the decomposition, but - * the decomposition is still completed in this case; otherwise it is set to - * false. - * - * @param a - */ - public QRdcmp(final double[][] a) { - n = a.length; - qt = new double[n][n]; - r = buildMatrix(a); - sing = false; - - int i, j, k; - double[] c = new double[n]; - double[] d = new double[n]; - - double scale, sigma, sum, tau; - for (k = 0; k < n - 1; k++) { - scale = 0.0; - for (i = k; i < n; i++) - scale = max(scale, abs(r[i][k])); - if (scale == 0.0) { - sing = true; - c[k] = d[k] = 0.0; - } else { - for (i = k; i < n; i++) - r[i][k] /= scale; - for (sum = 0.0, i = k; i < n; i++) - sum += SQR(r[i][k]); - sigma = SIGN(sqrt(sum), r[k][k]); - r[k][k] += sigma; - c[k] = sigma * r[k][k]; - d[k] = -scale * sigma; - for (j = k + 1; j < n; j++) { - for (sum = 0.0, i = k; i < n; i++) - sum += r[i][k] * r[i][j]; - tau = sum / c[k]; - for (i = k; i < n; i++) - r[i][j] -= tau * r[i][k]; - } - } - } - d[n - 1] = r[n - 1][n - 1]; - if (d[n - 1] == 0.0) - sing = true; - for (i = 0; i < n; i++) { - for (j = 0; j < n; j++) - qt[i][j] = 0.0; - qt[i][i] = 1.0; - } - for (k = 0; k < n - 1; k++) { - if (c[k] != 0.0) { - for (j = 0; j < n; j++) { - sum = 0.0; - for (i = k; i < n; i++) - sum += r[i][k] * qt[i][j]; - sum /= c[k]; - for (i = k; i < n; i++) - qt[i][j] -= sum * r[i][k]; - } - } - } - for (i = 0; i < n; i++) { - r[i][i] = d[i]; - for (j = 0; j < i; j++) - r[i][j] = 0.0; - } - } - - /** - * Solve the set of n linear equations A*x = b. b[0..n-1] is input as the - * right-hand side vector, and x[0..n-1] is returned as the solution vector - * - * @param b - * @param x - */ - public void solve(final double[] b, final double[] x) { - qtmult(b, x); - rsolve(x, x); - } - - /** - * Multiply QT*b and put the result in x. Since Q is orthogonal, this is - * equivalent to solving Q*x = b for x. - * - * @param b - * @param x - */ - public void qtmult(final double[] b, final double[] x) { - int i, j; - double sum; - for (i = 0; i < n; i++) { - sum = 0.; - for (j = 0; j < n; j++) - sum += qt[i][j] * b[j]; - x[i] = sum; - } - } - - /** - * Solve the triangular set of n linear equations R*x = b. b[0..n-1] is - * input as the right-hand side vector, and x[0..n-1] is returned as the - * solution vector - * - * @param b - * @param x - */ - public void rsolve(final double[] b, final double[] x) { - int i, j; - double sum; - if (sing) - throw new IllegalArgumentException( - "attempting solve in a singular QR"); - for (i = n - 1; i >= 0; i--) { - sum = b[i]; - for (j = i + 1; j < n; j++) - sum -= r[i][j] * x[j]; - x[i] = sum / r[i][i]; - } - } - - /** - * Starting from the stored QR decomposition A = Q*R, update it to be the QR - * decomposition of the matrix Q*(R + u(+)v). Input quantities are - * u[0..n-1], and v[0..n-1]. - * - * @param u - * @param v - */ - public void update(final double[] u, final double[] v) { - int i, k; - double[] w = buildVector(u); - for (k = n - 1; k >= 0; k--) - if (w[k] != 0.0) - break; - if (k < 0) - k = 0; - for (i = k - 1; i >= 0; i--) { - rotate(i, w[i], -w[i + 1]); - if (w[i] == 0.0) - w[i] = abs(w[i + 1]); - else if (abs(w[i]) > abs(w[i + 1])) - w[i] = abs(w[i]) * sqrt(1.0 + SQR(w[i + 1] / w[i])); - else - w[i] = abs(w[i + 1]) * sqrt(1.0 + SQR(w[i] / w[i + 1])); - } - for (i = 0; i < n; i++) - r[0][i] += w[0] * v[i]; - for (i = 0; i < k; i++) - rotate(i, r[i][i], -r[i + 1][i]); - for (i = 0; i < n; i++) - if (r[i][i] == 0.0) - sing = true; - } - - /** - * Utility used by update. Given matrices r[0..n-1][0..n-1] and - * qt[0..n-1][0..n-1], carry out a Jacobi rotation on rows i and i+1 of each - * matrix. a and b are the parameters of the rotation: - * cos(Â)=a/sqrt(a*a+b*b), sin(Â)=b/sqrt(a*a+b*b). - * - * @param i - * @param a - * @param b - */ - public void rotate(final int i, final double a, final double b) { - int j; - double c, fact, s, w, y; - if (a == 0.0) { - c = 0.0; - s = (b >= 0.0 ? 1.0 : -1.0); - } else if (abs(a) > abs(b)) { - fact = b / a; - c = SIGN(1.0 / sqrt(1.0 + (fact * fact)), a); - s = fact * c; - } else { - fact = a / b; - s = SIGN(1.0 / sqrt(1.0 + (fact * fact)), b); - c = fact * s; - } - for (j = i; j < n; j++) { - y = r[i][j]; - w = r[i + 1][j]; - r[i][j] = c * y - s * w; - r[i + 1][j] = s * y + c * w; - } - for (j = 0; j < n; j++) { - y = qt[i][j]; - w = qt[i + 1][j]; - qt[i][j] = c * y - s * w; - qt[i + 1][j] = s * y + c * w; - } - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/la/SVD.java b/common-tools/cnuphys/numRec/src/com/nr/la/SVD.java deleted file mode 100644 index 1b809ae683..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/la/SVD.java +++ /dev/null @@ -1,468 +0,0 @@ -package com.nr.la; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -/** - * Object for singular value decomposition of a matrix A. - PTC - * - * A = u*w*vT - * - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class SVD { - public int m, n; - - /** - * The matrices U and V - */ - public double[][] u, v; - - /** - * The diagonal matrix W - */ - public double[] w; - public double tsh; - private final double eps; - - /** - * The single argument is A. The SVD computation is done by decompose, and - * the results are sorted by reorder. - * - * @param a - */ - public SVD(final double[][] a) { - m = a.length; - n = a[0].length; - u = buildMatrix(a); - v = new double[n][n]; - w = new double[n]; - - eps = DBL_EPSILON; - decompose(); - reorder(); - tsh = 0.5 * sqrt(m + n + 1.) * w[0] * eps; - } - - /** - * Return reciprocal of the condition number of A - * - * @return - */ - public double inv_condition() { - return (w[0] <= 0. || w[n - 1] <= 0.) ? 0. : w[n - 1] / w[0]; - } - - public void solve(final double[] b, final double[] x) { - solve(b, x, -1.); - } - - /** - * Solve A*x = b for a vector x using the pseudoinverse of A as obtained by - * SVD. If positive, thresh is the threshold value below which singular - * values are considered as zero. If thresh is negative, a default based on - * expected roundoff error is used. - * - * @param b - * @param x - * @param thresh - */ - public void solve(final double[] b, final double[] x, final double thresh) { // thresh= - // -1. - int i, j, jj; - double s; - if (b.length != m || x.length != n) - throw new IllegalArgumentException("solve bad sizes"); - double[] tmp = new double[n]; - tsh = (thresh >= 0. ? thresh : 0.5 * sqrt(m + n + 1.) * w[0] * eps); - for (j = 0; j < n; j++) { - s = 0.0; - if (w[j] > tsh) { - for (i = 0; i < m; i++) - s += u[i][j] * b[i]; - s /= w[j]; - } - tmp[j] = s; - } - for (j = 0; j < n; j++) { - s = 0.0; - for (jj = 0; jj < n; jj++) - s += v[j][jj] * tmp[jj]; - x[j] = s; - } - } - - public void solve(final double[][] b, final double[][] x) { - solve(b, x, -1.); - } - - /** - * Solves m sets of n equations A * X = B using the pseudoinverse of A. The - * right-hand sides are input as b[0..n-1][0..m-1], while x[0..n-1][0..m-1] - * returns the solutions. thresh as above. - * - * @param b - * @param x - * @param thresh - */ - public void solve(final double[][] b, final double[][] x, - final double thresh) { - int i, j, p = b[0].length; - if (b.length != m || x.length != n || x[0].length != p) - throw new IllegalArgumentException("solve bad sizes"); - double[] xx = new double[n]; - double[] bcol = new double[m]; - for (j = 0; j < p; j++) { - for (i = 0; i < m; i++) - bcol[i] = b[i][j]; - solve(bcol, xx, thresh); - for (i = 0; i < n; i++) - x[i][j] = xx[i]; - } - } - - /** - * Return the rank of A, after zeroing any singular values smaller than - * thresh. If thresh is negative, a default value based on estimated - * roundoff is used. - * - * @param thresh - * @return - */ - public int rank(final double thresh) { - int j, nr = 0; - tsh = (thresh >= 0. ? thresh : 0.5 * sqrt(m + n + 1.) * w[0] * eps); - for (j = 0; j < n; j++) - if (w[j] > tsh) - nr++; - return nr; - } - - public int rank() { - return rank(-1.); - } - - public int nullity(final double thresh) { - int j, nn = 0; - tsh = (thresh >= 0. ? thresh : 0.5 * sqrt(m + n + 1.) * w[0] * eps); - for (j = 0; j < n; j++) - if (w[j] <= tsh) - nn++; - return nn; - } - - public int nullity() { - return nullity(-1.); - } - - /** - * Give an orthonormal basis for the range of A as the columns of a returned - * matrix. thresh as above. - * - * @param thresh - * @return - */ - public double[][] range(final double thresh) { - int i, j, nr = 0; - double[][] rnge = new double[m][rank(thresh)]; - for (j = 0; j < n; j++) { - if (w[j] > tsh) { - for (i = 0; i < m; i++) - rnge[i][nr] = u[i][j]; - nr++; - } - } - return rnge; - } - - public double[][] range() { - return range(-1.); - } - - /** - * Return the nullity of A, after zeroing any singular values smaller than - * thresh. Default value as above. - * - * @param thresh - * @return - */ - public double[][] nullspace(final double thresh) { - int j, jj, nn = 0; - double[][] nullsp = new double[n][nullity(thresh)]; - for (j = 0; j < n; j++) { - if (w[j] <= tsh) { - for (jj = 0; jj < n; jj++) - nullsp[jj][nn] = v[jj][j]; - nn++; - } - } - return nullsp; - } - - public double[][] nullspace() { - return nullspace(-1.); - } - - private void decompose() { - boolean flag; - int i, its, j, jj, k, l = 0, nm = 0; - double anorm, c, f, g, h, s, scale, x, y, z; - double[] rv1 = new double[n]; - g = scale = anorm = 0.0; - for (i = 0; i < n; i++) { - l = i + 2; - rv1[i] = scale * g; - g = s = scale = 0.0; - if (i < m) { - for (k = i; k < m; k++) - scale += abs(u[k][i]); - if (scale != 0.0) { - for (k = i; k < m; k++) { - u[k][i] /= scale; - s += u[k][i] * u[k][i]; - } - f = u[i][i]; - g = -SIGN(sqrt(s), f); - h = f * g - s; - u[i][i] = f - g; - for (j = l - 1; j < n; j++) { - for (s = 0.0, k = i; k < m; k++) - s += u[k][i] * u[k][j]; - f = s / h; - for (k = i; k < m; k++) - u[k][j] += f * u[k][i]; - } - for (k = i; k < m; k++) - u[k][i] *= scale; - } - } - w[i] = scale * g; - g = s = scale = 0.0; - if (i + 1 <= m && i + 1 != n) { - for (k = l - 1; k < n; k++) - scale += abs(u[i][k]); - if (scale != 0.0) { - for (k = l - 1; k < n; k++) { - u[i][k] /= scale; - s += u[i][k] * u[i][k]; - } - f = u[i][l - 1]; - g = -SIGN(sqrt(s), f); - h = f * g - s; - u[i][l - 1] = f - g; - for (k = l - 1; k < n; k++) - rv1[k] = u[i][k] / h; - for (j = l - 1; j < m; j++) { - for (s = 0.0, k = l - 1; k < n; k++) - s += u[j][k] * u[i][k]; - for (k = l - 1; k < n; k++) - u[j][k] += s * rv1[k]; - } - for (k = l - 1; k < n; k++) - u[i][k] *= scale; - } - } - anorm = max(anorm, (abs(w[i]) + abs(rv1[i]))); - } - for (i = n - 1; i >= 0; i--) { - if (i < n - 1) { - if (g != 0.0) { - for (j = l; j < n; j++) - v[j][i] = (u[i][j] / u[i][l]) / g; - for (j = l; j < n; j++) { - for (s = 0.0, k = l; k < n; k++) - s += u[i][k] * v[k][j]; - for (k = l; k < n; k++) - v[k][j] += s * v[k][i]; - } - } - for (j = l; j < n; j++) - v[i][j] = v[j][i] = 0.0; - } - v[i][i] = 1.0; - g = rv1[i]; - l = i; - } - for (i = min(m, n) - 1; i >= 0; i--) { - l = i + 1; - g = w[i]; - for (j = l; j < n; j++) - u[i][j] = 0.0; - if (g != 0.0) { - g = 1.0 / g; - for (j = l; j < n; j++) { - for (s = 0.0, k = l; k < m; k++) - s += u[k][i] * u[k][j]; - f = (s / u[i][i]) * g; - for (k = i; k < m; k++) - u[k][j] += f * u[k][i]; - } - for (j = i; j < m; j++) - u[j][i] *= g; - } else - for (j = i; j < m; j++) - u[j][i] = 0.0; - ++u[i][i]; - } - for (k = n - 1; k >= 0; k--) { - for (its = 0; its < 30; its++) { - flag = true; - for (l = k; l >= 0; l--) { - nm = l - 1; - if (l == 0 || abs(rv1[l]) <= eps * anorm) { - flag = false; - break; - } - if (abs(w[nm]) <= eps * anorm) - break; - } - if (flag) { - c = 0.0; - s = 1.0; - for (i = l; i < k + 1; i++) { - f = s * rv1[i]; - rv1[i] = c * rv1[i]; - if (abs(f) <= eps * anorm) - break; - g = w[i]; - h = pythag(f, g); - w[i] = h; - h = 1.0 / h; - c = g * h; - s = -f * h; - for (j = 0; j < m; j++) { - y = u[j][nm]; - z = u[j][i]; - u[j][nm] = y * c + z * s; - u[j][i] = z * c - y * s; - } - } - } - z = w[k]; - if (l == k) { - if (z < 0.0) { - w[k] = -z; - for (j = 0; j < n; j++) - v[j][k] = -v[j][k]; - } - break; - } - if (its == 29) - throw new IllegalArgumentException( - "no convergence in 30 svdcmp iterations"); - x = w[l]; - nm = k - 1; - y = w[nm]; - g = rv1[nm]; - h = rv1[k]; - f = ((y - z) * (y + z) + (g - h) * (g + h)) / (2.0 * h * y); - g = pythag(f, 1.0); - f = ((x - z) * (x + z) + h * ((y / (f + SIGN(g, f))) - h)) / x; - c = s = 1.0; - for (j = l; j <= nm; j++) { - i = j + 1; - g = rv1[i]; - y = w[i]; - h = s * g; - g = c * g; - z = pythag(f, h); - rv1[j] = z; - c = f / z; - s = h / z; - f = x * c + g * s; - g = g * c - x * s; - h = y * s; - y *= c; - for (jj = 0; jj < n; jj++) { - x = v[jj][j]; - z = v[jj][i]; - v[jj][j] = x * c + z * s; - v[jj][i] = z * c - x * s; - } - z = pythag(f, h); - w[j] = z; - if (z != 0) { - z = 1.0 / z; - c = f * z; - s = h * z; - } - f = c * g + s * y; - x = c * y - s * g; - for (jj = 0; jj < m; jj++) { - y = u[jj][j]; - z = u[jj][i]; - u[jj][j] = y * c + z * s; - u[jj][i] = z * c - y * s; - } - } - rv1[l] = 0.0; - rv1[k] = f; - w[k] = x; - } - } - } - - private void reorder() { - int i, j, k, s, inc = 1; - double sw; - double[] su = new double[m]; - double[] sv = new double[n]; - do { - inc *= 3; - inc++; - } while (inc <= n); - do { - inc /= 3; - for (i = inc; i < n; i++) { - sw = w[i]; - for (k = 0; k < m; k++) - su[k] = u[k][i]; - for (k = 0; k < n; k++) - sv[k] = v[k][i]; - j = i; - while (w[j - inc] < sw) { - w[j] = w[j - inc]; - for (k = 0; k < m; k++) - u[k][j] = u[k][j - inc]; - for (k = 0; k < n; k++) - v[k][j] = v[k][j - inc]; - j -= inc; - if (j < inc) - break; - } - w[j] = sw; - for (k = 0; k < m; k++) - u[k][j] = su[k]; - for (k = 0; k < n; k++) - v[k][j] = sv[k]; - - } - } while (inc > 1); - for (k = 0; k < n; k++) { - s = 0; - for (i = 0; i < m; i++) - if (u[i][k] < 0.) - s++; - for (j = 0; j < n; j++) - if (v[j][k] < 0.) - s++; - if (s > (m + n) / 2) { - for (i = 0; i < m; i++) - u[i][k] = -u[i][k]; - for (j = 0; j < n; j++) - v[j][k] = -v[j][k]; - } - } - } - - private double pythag(final double a, final double b) { - double absa = abs(a), absb = abs(b); - return (absa > absb ? absa * sqrt(1.0 + SQR(absb / absa)) - : (absb == 0.0 ? 0.0 : absb * sqrt(1.0 + SQR(absa / absb)))); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/la/Toepltz.java b/common-tools/cnuphys/numRec/src/com/nr/la/Toepltz.java deleted file mode 100644 index 8d01aeafdc..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/la/Toepltz.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.nr.la; - -public class Toepltz { - private Toepltz() { - } - - /** - * Solves the Toeplitz system. - PTC - * - * The Toeplitz matrix need not be symmetric. y[0..n-1] and r[0..2*n-2] are - * input arrays; x[0..n-1] is the output array. - * - * @param r - * @param x - * @param y - */ - public static void toeplz(final double[] r, final double[] x, - final double[] y) { - int j, k, m, m1, m2, n1, n = y.length; - double pp, pt1, pt2, qq, qt1, qt2, sd, sgd, sgn, shn, sxn; - n1 = n - 1; - if (r[n1] == 0.0) - throw new IllegalArgumentException( - "toeplz-1 singular principal minor"); - x[0] = y[0] / r[n1]; - if (n1 == 0) - return; - double[] g = new double[n1]; - double[] h = new double[n1]; - g[0] = r[n1 - 1] / r[n1]; - h[0] = r[n1 + 1] / r[n1]; - for (m = 0; m < n; m++) { - m1 = m + 1; - sxn = -y[m1]; - sd = -r[n1]; - for (j = 0; j < m + 1; j++) { - sxn += r[n1 + m1 - j] * x[j]; - sd += r[n1 + m1 - j] * g[m - j]; - } - if (sd == 0.0) - throw new IllegalArgumentException( - "toeplz-2 singular principal minor"); - x[m1] = sxn / sd; - for (j = 0; j < m + 1; j++) - x[j] -= x[m1] * g[m - j]; - if (m1 == n1) - return; - sgn = -r[n1 - m1 - 1]; - shn = -r[n1 + m1 + 1]; - sgd = -r[n1]; - for (j = 0; j < m + 1; j++) { - sgn += r[n1 + j - m1] * g[j]; - shn += r[n1 + m1 - j] * h[j]; - sgd += r[n1 + j - m1] * h[m - j]; - } - if (sgd == 0.0) - throw new IllegalArgumentException( - "toeplz-3 singular principal minor"); - g[m1] = sgn / sgd; - h[m1] = shn / sd; - k = m; - m2 = (m + 2) >> 1; - pp = g[m1]; - qq = h[m1]; - for (j = 0; j < m2; j++) { - pt1 = g[j]; - pt2 = g[k]; - qt1 = h[j]; - qt2 = h[k]; - g[j] = pt1 - pp * qt2; - g[k] = pt2 - pp * qt1; - h[j] = qt1 - qq * pt2; - h[k--] = qt2 - qq * pt1; - } - } - throw new IllegalArgumentException("toeplz - should not arrive here!"); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/la/Tridag.java b/common-tools/cnuphys/numRec/src/com/nr/la/Tridag.java deleted file mode 100644 index 9c4d92efb7..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/la/Tridag.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.nr.la; - -/** - * Solve tridiagonal linear systems - PTC Copyright (C) Numerical Recipes - * Software 1986-2007 Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Tridag { - private Tridag() { - } - - /** - * Solves for a vector u[0..n-1] the tridiagonal linear set. a[0..n-1], - * b[0..n-1], c[0..n-1], and r[0..n-1] are input vectors and are not - * modified. - * - * @param a - * @param b - * @param c - * @param r - * @param u - */ - public static void tridag(final double[] a, final double[] b, - final double[] c, final double[] r, final double[] u) { - int j, n = a.length; - double bet; - double[] gam = new double[n]; - if (b[0] == 0.0) - throw new IllegalArgumentException("Error 1 in tridag"); - u[0] = r[0] / (bet = b[0]); - for (j = 1; j < n; j++) { - gam[j] = c[j - 1] / bet; - bet = b[j] - a[j] * gam[j]; - if (bet == 0.0) - throw new IllegalArgumentException("Error 2 in tridag"); - u[j] = (r[j] - a[j] * u[j - 1]) / bet; - } - for (j = (n - 2); j >= 0; j--) - u[j] -= gam[j + 1] * u[j + 1]; - } - - /** - * Solves for a vector x[0..n-1] the "cyclic" set of linear equations. a, b, - * c, and r are input vectors, all dimensioned as [0..n-1], while alpha and - * beta are the corner entries in the matrix. The input is not modified. - * - * @param a - * @param b - * @param c - * @param alpha - * @param beta - * @param r - * @param x - */ - public static void cyclic(final double[] a, final double[] b, - final double[] c, final double alpha, final double beta, - final double[] r, final double[] x) { - int i, n = a.length; - double fact, gamma; - if (n <= 2) - throw new IllegalArgumentException("n too small in cyclic"); - double[] bb = new double[n]; - double[] u = new double[n]; - double[] z = new double[n]; - gamma = -b[0]; - bb[0] = b[0] - gamma; - bb[n - 1] = b[n - 1] - alpha * beta / gamma; - for (i = 1; i < n - 1; i++) - bb[i] = b[i]; - tridag(a, bb, c, r, x); - u[0] = gamma; - u[n - 1] = alpha; - for (i = 1; i < n - 1; i++) - u[i] = 0.0; - tridag(a, bb, c, u, z); - fact = (x[0] + beta * x[n - 1] / gamma) - / (1.0 + z[0] + beta * z[n - 1] / gamma); - for (i = 0; i < n; i++) - x[i] -= fact * z[i]; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/la/Vander.java b/common-tools/cnuphys/numRec/src/com/nr/la/Vander.java deleted file mode 100644 index ba9beddf49..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/la/Vander.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.nr.la; - -public class Vander { - - /** - * Solves the Vandermonde linear system. - PTC Input consists of the vectors - * x[0..n-1] and q[0..n-1]; the vector w[0..n-1] is output. - * - * @param x - * @param w - * @param q - */ - public static void vander(final double[] x, final double[] w, - final double[] q) { - int i, j, k, n = q.length; - double b, s, t, xx; - double[] c = new double[n]; - if (n == 1) - w[0] = q[0]; - else { - for (i = 0; i < n; i++) - c[i] = 0.0; - c[n - 1] = -x[0]; - for (i = 1; i < n; i++) { - xx = -x[i]; - for (j = (n - 1 - i); j < (n - 1); j++) - c[j] += xx * c[j + 1]; - c[n - 1] += xx; - } - for (i = 0; i < n; i++) { - xx = x[i]; - t = b = 1.0; - s = q[n - 1]; - for (k = n - 1; k > 0; k--) { - b = c[k] + xx * b; - s += q[k - 1] * b; - t = xx * t + b; - } - w[i] = s / t; - } - } - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/lna/Arithcode.java b/common-tools/cnuphys/numRec/src/com/nr/lna/Arithcode.java deleted file mode 100644 index b794d5c238..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/lna/Arithcode.java +++ /dev/null @@ -1,138 +0,0 @@ -package com.nr.lna; - -import static java.lang.Math.max; - -import org.netlib.util.intW; - -/** - * compression by arithmetic coding - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Arithcode { - int nch, nrad, ncum; - long jdif; - int nc, minint; - int[] ilob, iupb; - int[] ncumfq; - static final int NWK = 20; - - public Arithcode(final int[] nfreq, final int nnch, final int nnrad) { - nch = nnch; - nrad = nnrad; - ilob = new int[NWK]; - iupb = new int[NWK]; - ncumfq = new int[nch + 2]; - - int j; - if (nrad > 256) - throw new IllegalArgumentException( - "output radix must be <= 256 in Arithcode"); - minint = (int) (0xFFFFFFFFL / nrad); - ncumfq[0] = 0; - for (j = 1; j <= nch; j++) - ncumfq[j] = ncumfq[j - 1] + max(nfreq[j - 1], 1); - ncum = ncumfq[nch + 1] = ncumfq[nch] + 1; - } - - public void messageinit() { - int j; - jdif = nrad - 1; - for (j = NWK - 1; j >= 0; j--) { - iupb[j] = nrad - 1; - ilob[j] = 0; - nc = j; - if (jdif > minint) - return; - jdif = (jdif + 1) * nrad - 1; - } - throw new IllegalArgumentException("NWK too small in arcode."); - } - - public void codeone(final int ich, final byte[] code, final intW lcd) { - if (ich > nch) - throw new IllegalArgumentException("bad ich in Arithcode"); - advance(ich, code, lcd, 1); - } - - public int decodeone(final byte[] code, final intW lcd) { - int ich; - int j, ihi, ja, m; - ja = code[lcd.val] - ilob[nc]; - for (j = nc + 1; j < NWK; j++) { - ja *= nrad; - ja += (code[lcd.val + j - nc]) - ilob[j]; - } - ihi = nch + 1; - ich = 0; - while (ihi - ich > 1) { - m = (ich + ihi) >>> 1; - if (ja >= multdiv(jdif, ncumfq[m], ncum)) - ich = m; - else - ihi = m; - } - if (ich != nch) - advance(ich, code, lcd, -1); - return ich; - } - - public void advance(final int ich, final byte[] code, final intW lcd, - final int isign) { - int j, k, jh, jl; - jh = multdiv(jdif, ncumfq[ich + 1], ncum); - jl = multdiv(jdif, ncumfq[ich], ncum); - jdif = jh - jl; - arrsum(ilob, iupb, jh, NWK, nrad, nc); - arrsum(ilob, ilob, jl, NWK, nrad, nc); - for (j = nc; j < NWK; j++) { - if (ich != nch && iupb[j] != ilob[j]) - break; - if (isign > 0) - code[lcd.val] = (byte) (ilob[j]); - lcd.val++; - } - if (j + 1 > NWK) - return; - nc = j; - for (j = 0; jdif < minint; j++) - jdif *= nrad; - if (j > nc) - throw new IllegalArgumentException("NWK too small in arcode."); - if (j != 0) { - for (k = nc; k < NWK; k++) { - iupb[k - j] = iupb[k]; - ilob[k - j] = ilob[k]; - } - } - nc -= j; - for (k = NWK - j; k < NWK; k++) - iupb[k] = ilob[k] = 0; - return; - } - - public int multdiv(final long j, final int k, final int m) { - return (int) (j * k / m); - } - - public void arrsum(final int[] iin, final int[] iout, final int ja0, - final int nwk, final int nrad, final int nc) { - int karry = 0, j, jtmp; - int ja = ja0; - for (j = nwk - 1; j > nc; j--) { - jtmp = ja; - ja /= nrad; - iout[j] = iin[j] + (jtmp - ja * nrad) + karry; - if (iout[j] >= nrad) { - iout[j] -= nrad; - karry = 1; - } else - karry = 0; - } - iout[nc] = iin[nc] + ja + karry; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/lna/Gray.java b/common-tools/cnuphys/numRec/src/com/nr/lna/Gray.java deleted file mode 100644 index cec8d05b92..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/lna/Gray.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.nr.lna; - -/** - * Gray Codes - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Gray { - - public int gray(final int n) { - return n ^ (n >>> 1); - } - - public int invgray(final int n) { - int ish = 1; - int ans = n, idiv; - for (;;) { - ans ^= (idiv = ans >>> ish); - if (idiv <= 1 || ish == 16) - return ans; - ish <<= 1; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/lna/Huffcode.java b/common-tools/cnuphys/numRec/src/com/nr/lna/Huffcode.java deleted file mode 100644 index 16df664624..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/lna/Huffcode.java +++ /dev/null @@ -1,168 +0,0 @@ -package com.nr.lna; - -import static com.nr.NRUtil.*; -import org.netlib.util.intW; - -/** - * Huffman Coding and Compression of Data - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Huffcode { - int nch, nodemax, mq; - int ilong, nlong; - int[] ncod, left, right; - int[] icod; - int[] setbit = new int[32]; - - /** - * Given the frequency of occurrence table nfreq[0..nnch-1] for nnch charac- - * ters, constructs the Huffman code. Also sets ilong and nlong as the - * character number that produced the longest code symbol, and the length of - * that symbol. - * - * @param nnch - * @param nfreq - */ - public Huffcode(final int nnch, final int[] nfreq) { - nch = nnch; - mq = 2 * nch - 1; - icod = new int[mq]; - ncod = new int[mq]; - left = new int[mq]; - right = new int[mq]; - - int ibit, j, node, k, n, nused; - int[] index = new int[mq]; - int[] nprob = new int[mq]; - int[] up = new int[mq]; - for (j = 0; j < 32; j++) - setbit[j] = 1 << j; - for (nused = 0, j = 0; j < nch; j++) { - nprob[j] = nfreq[j]; - icod[j] = ncod[j] = 0; - if (nfreq[j] != 0) - index[nused++] = j; - } - for (j = nused - 1; j >= 0; j--) - heep(index, nprob, nused, j); - k = nch; - while (nused > 1) { - node = index[0]; - index[0] = index[(nused--) - 1]; - heep(index, nprob, nused, 0); - nprob[k] = nprob[index[0]] + nprob[node]; - left[k] = node; - right[k++] = index[0]; - up[index[0]] = -k; - index[0] = k - 1; - up[node] = k; - heep(index, nprob, nused, 0); - } - up[(nodemax = k) - 1] = 0; - for (j = 0; j < nch; j++) { - if (nprob[j] != 0) { - for (n = 0, ibit = 0, node = up[j]; node != 0; node = up[node - 1], ibit++) { - if (node < 0) { - n |= setbit[ibit]; - node = -node; - } - } - icod[j] = n; - ncod[j] = ibit; - } - } - nlong = 0; - for (j = 0; j < nch; j++) { - if (ncod[j] > nlong) { - nlong = ncod[j]; - ilong = j; - } - } - if (nlong > INT_DIGITS) // numeric_limits::digits - throw new IllegalArgumentException( - "Code too long in Huffcode. See text."); - } - - /** - * Huffman encode the single character ich (in the range 0..nch-1), write - * the result to the byte array code starting at bit nb (whose smallest - * valid value is zero), and increment nb to the first unused bit. This - * routine is called repeatedly to encode consecutive characters in a - * message. The user is responsible for monitoring that the value of nb does - * not overrun the length of code. - * - * @param ich - * @param code - * @param nb - */ - public void codeone(final int ich, final byte[] code, final intW nb) { - int m, n, nc; - if (ich >= nch) - throw new IllegalArgumentException( - "bad ich (out of range) in Huffcode"); - if (ncod[ich] == 0) - throw new IllegalArgumentException( - "bad ich (zero prob) in Huffcode"); - for (n = ncod[ich] - 1; n >= 0; n--, ++nb.val) { - nc = nb.val >> 3; - m = nb.val & 7; - if (m == 0) - code[nc] = 0; - if ((icod[ich] & setbit[n]) != 0) - code[nc] |= setbit[m]; - } - } - - /** - * Starting at bit number nb in the byte array code, decode a single - * character (returned as ich in the range 0..nch-1) and increment nb - * appropriately. Repeated calls, starting with nb D 0, will return - * successive characters in a compressed message. The user is responsible - * for detecting EOM from the message content. - * - * @param code - * @param nb - * @return - */ - public int decodeone(final byte[] code, final intW nb) { - int nc; - int node = nodemax - 1; - for (;;) { - nc = nb.val >> 3; - node = ((code[nc] & setbit[7 & nb.val++]) != 0 ? right[node] - : left[node]); - if (node < nch) - return node; - } - } - - /** - * Used by the constructor to maintain a heap structure in the array - * index[0..m-1]. - * - * @param index - * @param nprob - * @param n - * @param m - */ - public void heep(final int[] index, final int[] nprob, final int n, - final int m) { - int i = m, j, k; - k = index[i]; - while (i < (n >> 1)) { - if ((j = 2 * i + 1) < n - 1 - && nprob[index[j]] > nprob[index[j + 1]]) - j++; - if (nprob[k] <= nprob[index[j]]) - break; - index[i] = index[j]; - i = j; - } - index[i] = k; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/lna/Icrc.java b/common-tools/cnuphys/numRec/src/com/nr/lna/Icrc.java deleted file mode 100644 index 6f4c6fba51..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/lna/Icrc.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.nr.lna; - -/** - * cyclic redundancy checksum Copyright (C) Numerical Recipes Software 1986-2007 - * Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Icrc { - int jcrc, jfill, poly; - static int[] icrctb = new int[256]; - - public Icrc(final int jpoly) { - this(jpoly, true); - } - - public Icrc(final int jpoly, final boolean fill) { - jfill = fill ? 255 : 0; - - int j; - int[] okpolys = { 0x755B, 0xA7D3, 0x8005, 0x1021, 0x5935, 0x90D9, - 0x5B93, 0x2D17 }; - poly = okpolys[jpoly & 7]; - for (j = 0; j < 256; j++) { - icrctb[j] = icrc1(j << 8, (byte) 0); - } - jcrc = (jfill | (jfill << 8)); - } - - public int crc(final byte[] bufptr) { - jcrc = (jfill | (jfill << 8)); - return concat(bufptr); - } - - public int concat(final byte[] bufptr) { - int j, cword = jcrc, len = bufptr.length; - for (j = 0; j < len; j++) { - cword = icrctb[(bufptr[j] & 0xFF) ^ hibyte(cword)] - ^ (lobyte(cword) << 8); - } - return jcrc = cword; - } - - public int icrc1(final int jcrc, final byte onech) { - int i; - int ans = (jcrc ^ onech << 8); - for (i = 0; i < 8; i++) { - if ((ans & 0x8000) != 0) - ans = (ans <<= 1) ^ poly; - else - ans <<= 1; - ans &= 0xffff; - } - return ans; - } - - public int lobyte(final int x) { - return (x & 0xff); - } - - public int hibyte(final int x) { - return (x >>> 8) & 0xff; - } - - public static boolean decchk(final byte[] str, final byte[] ch, int nn) { - byte c; - int j, k = 0, m = 0, n = str.length; - int[][] ip = { { 0, 1, 5, 8, 9, 4, 2, 7 }, { 1, 5, 8, 9, 4, 2, 7, 0 }, - { 2, 7, 0, 1, 5, 8, 9, 4 }, { 3, 6, 3, 6, 3, 6, 3, 6 }, - { 4, 2, 7, 0, 1, 5, 8, 9 }, { 5, 8, 9, 4, 2, 7, 0, 1 }, - { 6, 3, 6, 3, 6, 3, 6, 3 }, { 7, 0, 1, 5, 8, 9, 4, 2 }, - { 8, 9, 4, 2, 7, 0, 1, 5 }, { 9, 4, 2, 7, 0, 1, 5, 8 } }; - - int[][] ij = { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, - { 1, 2, 3, 4, 0, 6, 7, 8, 9, 5 }, - { 2, 3, 4, 0, 1, 7, 8, 9, 5, 6 }, - { 3, 4, 0, 1, 2, 8, 9, 5, 6, 7 }, - { 4, 0, 1, 2, 3, 9, 5, 6, 7, 8 }, - { 5, 9, 8, 7, 6, 0, 4, 3, 2, 1 }, - { 6, 5, 9, 8, 7, 1, 0, 4, 3, 2 }, - { 7, 6, 5, 9, 8, 2, 1, 0, 4, 3 }, - { 8, 7, 6, 5, 9, 3, 2, 1, 0, 4 }, - { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 } }; - - for (j = 0; j < n; j++) { - c = str[j]; - if (c >= 48 && c <= 57) - k = ij[k][ip[(c + 2) % 10][7 & m++]]; - } - for (j = 0; j < 10; j++) - if (ij[k][ip[j][m & 7]] == 0) - break; - ch[nn] = (byte) (j + 48); - return k == 0; - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/lna/MParith.java b/common-tools/cnuphys/numRec/src/com/nr/lna/MParith.java deleted file mode 100644 index 7cd47feb5c..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/lna/MParith.java +++ /dev/null @@ -1,324 +0,0 @@ -package com.nr.lna; - -import static java.lang.Math.*; -import static com.nr.fft.FFT.*; - -public class MParith { - private MParith() { - } - - public static void mpadd(char[] w, char[] u, char[] v) { - int j, n = u.length, m = v.length, p = w.length; - int n_min = min(n, m), p_min = min(n_min, p - 1); - int ireg = 0; - for (j = p_min - 1; j >= 0; j--) { - ireg = u[j] + v[j] + hibyte(ireg); - w[j + 1] = lobyte(ireg); - } - w[0] = hibyte(ireg); - if (p > p_min + 1) - for (j = p_min + 1; j < p; j++) - w[j] = 0; - } - - public static int mpsub(char[] w, char[] u, char[] v) { - int is; - int j, n = u.length, m = v.length, p = w.length; - int n_min = min(n, m), p_min = min(n_min, p - 1); - int ireg = 256; - for (j = p_min - 1; j >= 0; j--) { - ireg = 255 + u[j] - v[j] + hibyte(ireg); - w[j] = lobyte(ireg); - } - is = hibyte(ireg) - 1; - if (p > p_min) - for (j = p_min; j < p; j++) - w[j] = 0; - - return is; - } - - public static void mpsad(char[] w, char[] u, final int iv) { - int j, n = u.length, p = w.length; - int ireg = 256 * iv; - for (j = n - 1; j >= 0; j--) { - ireg = u[j] + hibyte(ireg); - if (j + 1 < p) - w[j + 1] = lobyte(ireg); - } - w[0] = hibyte(ireg); - for (j = n + 1; j < p; j++) - w[j] = 0; - } - - public static void mpsmu(char[] w, char[] u, final int iv) { - int j, n = u.length, p = w.length; - int ireg = 0; - for (j = n - 1; j >= 0; j--) { - ireg = u[j] * iv + hibyte(ireg); - if (j < p - 1) - w[j + 1] = lobyte(ireg); - } - w[0] = hibyte(ireg); - for (j = n + 1; j < p; j++) - w[j] = 0; - } - - public static int mpsdv(char[] w, char[] u, final int iv) { - int ir; - int i, j, n = u.length, p = w.length, p_min = min(n, p); - ir = 0; - for (j = 0; j < p_min; j++) { - i = 256 * ir + u[j]; - w[j] = (char) (i / iv); - ir = i % iv; - } - if (p > p_min) - for (j = p_min; j < p; j++) - w[j] = 0; - return ir; - } - - public static void mpneg(char[] u) { - int j, n = u.length; - int ireg = 256; - for (j = n - 1; j >= 0; j--) { - ireg = 255 - u[j] + hibyte(ireg); - u[j] = lobyte(ireg); - } - } - - public static void mpmov(char[] u, char[] v) { - int j, n = u.length, m = v.length, n_min = min(n, m); - for (j = 0; j < n_min; j++) - u[j] = v[j]; - if (n > n_min) - for (j = n_min; j < n - 1; j++) - u[j] = 0; - } - - public static void mplsh(char[] u) { - int j, n = u.length; - for (j = 0; j < n - 1; j++) - u[j] = u[j + 1]; - u[n - 1] = 0; - } - - private static char lobyte(int x) { - return (char) (x & 0xff); - } - - private static char hibyte(int x) { - return (char) ((x >> 8) & 0xff); - } - - public static void mpmul(char[] w, char[] u, char[] v) { - final double RX = 256.0; - int j, nn = 1, n = u.length, m = v.length, p = w.length, n_max = max(m, - n); - double cy, t; - while (nn < n_max) - nn <<= 1; - nn <<= 1; - double[] a = new double[nn], b = new double[nn]; - for (j = 0; j < n; j++) - a[j] = u[j]; - for (j = 0; j < m; j++) - b[j] = v[j]; - realft(a, 1); - realft(b, 1); - b[0] *= a[0]; - b[1] *= a[1]; - for (j = 2; j < nn; j += 2) { - b[j] = (t = b[j]) * a[j] - b[j + 1] * a[j + 1]; - b[j + 1] = t * a[j + 1] + b[j + 1] * a[j]; - } - realft(b, -1); - cy = 0.0; - for (j = nn - 1; j >= 0; j--) { - t = b[j] / (nn >> 1) + cy + 0.5; - cy = (int) (t / RX); - b[j] = t - cy * RX; - } - if (cy >= RX) - throw new IllegalArgumentException("cannot happen in mpmul"); - for (j = 0; j < p; j++) - w[j] = 0; - w[0] = (char) (cy); - for (j = 1; j < min(n + m, p); j++) - w[j] = (char) (b[j - 1]); - } - - public static void mpinv(char[] u, char[] v) { - final int MF = 4; - final double BI = 1.0 / 256.0; - int i, j, n = u.length, m = v.length, mm = min(MF, m); - double fu, fv = (v[mm - 1]); - char[] s = new char[n + m], r = new char[2 * n + m]; - for (j = mm - 2; j >= 0; j--) { - fv *= BI; - fv += v[j]; - } - fu = 1.0 / fv; - for (j = 0; j < n; j++) { - i = (int) (fu); - u[j] = (char) (i); - fu = 256.0 * (fu - i); - } - for (;;) { - mpmul(s, u, v); - mplsh(s); - mpneg(s); - s[0] += (char) (2); - s[0] &= 0xFF; // XXX one char is 2 bytes - mpmul(r, s, u); - mplsh(r); - mpmov(u, r); - for (j = 1; j < n - 1; j++) - if (s[j] != 0) - break; - if (j == n - 1) - return; - } - } - - public static void mpdiv(char[] q, char[] r, char[] u, char[] v) { - final int MACC = 1; - int i, is, mm, n = u.length, m = v.length, p = r.length, n_min = min(m, - p); - if (m > n) - throw new IllegalArgumentException( - "Divisor longer than dividend in mpdiv"); - mm = m + MACC; - char[] s = new char[mm], rr = new char[mm], ss = new char[mm + 1], qq = new char[n - - m + 1], t = new char[n]; - mpinv(s, v); - mpmul(rr, s, u); - mpsad(ss, rr, 1); - mplsh(ss); - mplsh(ss); - mpmov(qq, ss); - mpmov(q, qq); - mpmul(t, qq, v); - mplsh(t); - is = mpsub(t, u, t); - if (is != 0) - throw new IllegalArgumentException("MACC too small in mpdiv"); - for (i = 0; i < n_min; i++) - r[i] = t[i + n - m]; - if (p > m) - for (i = m; i < p; i++) - r[i] = 0; - } - - @SuppressWarnings("unused") - public static void mpsqrt(char[] w, char[] u, char[] v) { - final int MF = 3; - final double BI = 1.0 / 256.0; - int i, ir, j, n = u.length, m = v.length, mm = min(m, MF); - char[] r = new char[2 * n], x = new char[n + m], s = new char[2 * n + m], t = new char[3 - * n + m]; - double fu, fv = (v[mm - 1]); - for (j = mm - 2; j >= 0; j--) { - fv *= BI; - fv += v[j]; - } - fu = 1.0 / sqrt(fv); - for (j = 0; j < n; j++) { - i = (int) (fu); - u[j] = (char) (i); - fu = 256.0 * (fu - i); - } - for (;;) { - mpmul(r, u, u); - mplsh(r); - mpmul(s, r, v); - mplsh(s); - mpneg(s); - s[0] += (char) (3); - s[0] &= 0xFF; // XXX one char is 2 bytes - ir = mpsdv(s, s, 2); - for (j = 1; j < n - 1; j++) { - if (s[j] != 0) { - mpmul(t, s, u); - mplsh(t); - mpmov(u, t); - break; - } - } - if (j < n - 1) - continue; - mpmul(x, u, v); - mplsh(x); - mpmov(w, x); - return; - } - } - - public static String mp2dfr(char[] a) { - StringBuilder s = new StringBuilder(128); - final int IAZ = 48; - // char[] buffer = new char[4]; - int j, m; - - int n = a.length; - m = (int) (2.408 * n); - s.append(String.format("%d", a[0] & 0xFFFF)); - // s=buffer; - s.append('.'); - mplsh(a); - for (j = 0; j < m; j++) { - mpsmu(a, a, 10); - s.append((char) (a[0] + IAZ)); - mplsh(a); - } - return s.substring(0); - } - - @SuppressWarnings("unused") - public static String mppi(final int np) { - final int MACC = 2; - int ir, j, n = np + MACC; - char mm; - String s; - char[] x = new char[n], y = new char[n], sx = new char[n], sxi = new char[n], z = new char[n], t = new char[n], pi = new char[n], ss = new char[2 * n], tt = new char[2 * n]; - t[0] = 2; - for (j = 1; j < n; j++) - t[j] = 0; - mpsqrt(x, x, t); - mpadd(pi, t, x); - mplsh(pi); - mpsqrt(sx, sxi, x); - mpmov(y, sx); - for (;;) { - mpadd(z, sx, sxi); - mplsh(z); - ir = mpsdv(x, z, 2); - mpsqrt(sx, sxi, x); - mpmul(tt, y, sx); - mplsh(tt); - mpadd(tt, tt, sxi); - mplsh(tt); - x[0]++; - y[0]++; - mpinv(ss, y); - mpmul(y, tt, ss); - mplsh(y); - mpmul(tt, x, ss); - mplsh(tt); - mpmul(ss, pi, tt); - mplsh(ss); - mpmov(pi, ss); - mm = (char) (tt[0] - 1); - for (j = 1; j < n - 1; j++) - if (tt[j] != mm) - break; - if (j == n - 1) { - s = mp2dfr(pi); - int len = (int) (2.408 * np); - // s.erase((int)(2.408*np),s.length()); - return s.substring(0, len); - } - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/lna/Machar.java b/common-tools/cnuphys/numRec/src/com/nr/lna/Machar.java deleted file mode 100644 index e93a4001c8..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/lna/Machar.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.nr.lna; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -public class Machar { - public int ibeta, it, irnd, ngrd, machep, negep, iexp, minexp, maxexp; - public double eps, epsneg, xmin, xmax; - - public Machar() { - int i, itemp, iz, j, k, mx, nxres; - double a, b, beta, betah, betain, one, t, temp, temp1, tempa, two, y, z, zero; - one = (1); - two = one + one; - zero = one - one; - a = one; - do { - a += a; - temp = a + one; - temp1 = temp - a; - } while (temp1 - one == zero); - b = one; - do { - b += b; - temp = a + b; - itemp = (int) (temp - a); - } while (itemp == 0); - ibeta = itemp; - beta = (ibeta); - it = 0; - b = one; - do { - ++it; - b *= beta; - temp = b + one; - temp1 = temp - b; - } while (temp1 - one == zero); - irnd = 0; - betah = beta / two; - temp = a + betah; - if (temp - a != zero) - irnd = 1; - tempa = a + beta; - temp = tempa + betah; - if (irnd == 0 && temp - tempa != zero) - irnd = 2; - negep = it + 3; - betain = one / beta; - a = one; - for (i = 1; i <= negep; i++) - a *= betain; - b = a; - for (;;) { - temp = one - a; - if (temp - one != zero) - break; - a *= beta; - --negep; - } - negep = -negep; - epsneg = a; - machep = -it - 3; - a = b; - for (;;) { - temp = one + a; - if (temp - one != zero) - break; - a *= beta; - ++machep; - } - eps = a; - ngrd = 0; - temp = one + eps; - if (irnd == 0 && temp * one - one != zero) - ngrd = 1; - i = 0; - k = 1; - z = betain; - t = one + eps; - nxres = 0; - for (;;) { - y = z; - z = y * y; - a = z * one; - temp = z * t; - if (a + a == zero || abs(z) >= y) - break; - temp1 = temp * betain; - if (temp1 * beta == z) - break; - ++i; - k += k; - } - if (ibeta != 10) { - iexp = i + 1; - mx = k + k; - } else { - iexp = 2; - iz = ibeta; - while (k >= iz) { - iz *= ibeta; - ++iexp; - } - mx = iz + iz - 1; - } - for (;;) { - xmin = y; - y *= betain; - a = y * one; - temp = y * t; - if (a + a != zero && abs(y) < xmin) { - ++k; - temp1 = temp * betain; - if (temp1 * beta == y && temp != y) { - nxres = 3; - xmin = y; - break; - } - } else - break; - } - minexp = -k; - if (mx <= k + k - 3 && ibeta != 10) { - mx += mx; - ++iexp; - } - maxexp = mx + minexp; - irnd += nxres; - if (irnd >= 2) - maxexp -= 2; - i = maxexp + minexp; - if (ibeta == 2 && i == 0) - --maxexp; - if (i > 20) - --maxexp; - if (a != y) - maxexp -= 2; - xmax = one - epsneg; - if (xmax * one != xmax) - xmax = one - beta * epsneg; - xmax /= (xmin * beta * beta * beta); - i = maxexp + minexp + 3; - for (j = 1; j <= i; j++) { - if (ibeta == 2) - xmax += xmax; - else - xmax *= beta; - } - } - - public void report() { - System.out - .printf("quantity: numeric_limits says (we calculate)\n"); - System.out.printf("radix: %d (%d)\n", FLT_RADIX, ibeta); - System.out.printf("mantissa digits: %d (%d)\n", DBL_MANT_DIG, it); - System.out - .printf("round style: %d (%d) [our 5 == IEEE 1]\n", 1, irnd); // round_style=1 - System.out.printf("guard digits: [not in numeric_limits] (%d)\n", - ngrd); - System.out.printf("epsilon: %g (%g)\n", DBL_EPSILON, eps); - System.out.printf("neg epsilon: [not in numeric_limits] (%g)\n", - epsneg); - System.out.printf("epsilon power: [not in numeric_limits] (%d)\n", - machep); - System.out.printf( - "neg epsilon power: [not in numeric_limits] (%d)\n", negep); - System.out.printf("exponent digits: [not in numeric_limits] (%d)\n", - iexp); - System.out.printf("min exponent: %d (%d)\n", Double.MIN_EXPONENT, - minexp); - System.out.printf("max exponent: %d (%d)\n", Double.MAX_EXPONENT, - maxexp); - System.out.printf("minimum: %g (%g)\n", Double.MIN_NORMAL, xmin); - System.out.printf("maximum: %g (%g)\n", Double.MAX_VALUE, xmax); - } - - public static void main(String[] args) { - Machar machar = new Machar(); - machar.report(); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/lna/PSpage.java b/common-tools/cnuphys/numRec/src/com/nr/lna/PSpage.java deleted file mode 100644 index 0fadbb25e1..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/lna/PSpage.java +++ /dev/null @@ -1,138 +0,0 @@ -package com.nr.lna; - -import static java.lang.Math.*; -import java.io.*; - -public class PSpage { - - PrintWriter PLT; - File file; - String fontname; - double fontsize; - - public PSpage(final File filname) throws IOException { - file = filname; - PLT = new PrintWriter(new java.io.FileWriter(file)); - PLT.printf("%%!\n/mt{moveto}def /lt{lineto}def /np{newpath}def\n"); - PLT.printf("/st{stroke}def /cp{closepath}def /fi{fill}def\n"); - PLT.printf("/zp {gsave /ZapfDingbats findfont exch "); - PLT.printf("scalefont setfont moveto show grestore} def\n"); - setfont("Times-Roman", 12.); - setlinewidth(0.5); - } - - public PSpage() { - } - - public void setfont(final String fontnam, final double size) { - fontname = new String(fontnam); - fontsize = size; - PLT.printf("/%s findfont %g scalefont setfont\n", fontnam, size); - } - - public void setcolor(final int r, final int g, final int b) { - PLT.printf("%g %g %g setrgbcolor\n", r / 255., g / 255., b / 255.); - } - - public void setdash(final String patt) { - setdash(patt, 0); - } - - public void setdash(final String patt, final int phase) { - PLT.printf("[%s] %d setdash\n", patt, phase); - } - - public void setlinewidth(final double w) { - PLT.printf("%g setlinewidth\n", w); - } - - public void setgray(final double w) { - PLT.printf("%g setgray\n", w); - } - - public void gsave() { - PLT.printf("gsave\n"); - } - - public void grestore() { - PLT.printf("grestore\n"); - } - - public void rawps(final String text) { - PLT.printf("%s\n", text); - } - - public void addtext(final String text) { - PLT.printf("(%s) show ", text); - } - - public void puttext(final String text, final double x, final double y) { - puttext(text, x, y, 0.0); - } - - public void puttext(final String text, final double x, final double y, - final double rot) { - PLT.printf("gsave %g %g translate %g rotate 0 0 mt ", x, y, rot); - addtext(text); - PLT.printf("grestore \n"); - } - - public void putctext(final String text, final double x, final double y) { - putctext(text, x, y, 0.0); - } - - public void putctext(final String text, final double x, final double y, - final double rot) { - PLT.printf("gsave %g %g translate %g rotate 0 0 mt (%s) ", x, y, rot, - text); - PLT.printf("dup stringwidth pop 2 div neg 0 rmoveto show grestore\n"); - } - - public void putrtext(final String text, final double x, final double y) { - putrtext(text, x, y, 0.0); - } - - public void putrtext(final String text, final double x, final double y, - final double rot) { - PLT.printf("gsave %g %g translate %g rotate 0 0 mt (%s) ", x, y, rot, - text); - PLT.printf("dup stringwidth pop neg 0 rmoveto show grestore\n"); - } - - public void close() { - PLT.printf("showpage\n"); - PLT.close(); - PLT = null; - } - - public void pointsymbol(final double x, final double y, final int num, - final double size) { - PLT.printf("(\\%03o) %g %g %g zp\n", num, x - 0.394 * size, y - 0.343 - * size, size); - } - - public void lineseg(final double xs, final double ys, final double xf, - final double yf) { - PLT.printf("np %g %g mt %g %g lt st\n", xs, ys, xf, yf); - } - - public void polyline(final double[] x, final double[] y) { - polyline(x, y, false, false, false); - } - - public void polyline(final double[] x, final double[] y, - final boolean close, final boolean fill, final boolean clip) { - int i, n = min(x.length, y.length); - PLT.printf("np %g %g mt\n", x[0], y[0]); - for (i = 1; i < n; i++) - PLT.printf("%g %g lt\n", x[i], y[i]); - if (close || fill || clip) - PLT.printf("cp "); - if (fill) - PLT.printf("fi\n"); - else if (clip) - PLT.printf("clip\n"); - else - PLT.printf("st\n"); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/lna/PSplot.java b/common-tools/cnuphys/numRec/src/com/nr/lna/PSplot.java deleted file mode 100644 index 09fb997fed..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/lna/PSplot.java +++ /dev/null @@ -1,243 +0,0 @@ -package com.nr.lna; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -import java.io.*; - -import com.nr.UniVarRealValueFun; - -/** - * PostScript plot - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class PSplot extends PSpage { - - double pll, qll, pur, qur; - double xll, yll, xur, yur; - double[] xbox, ybox; - double majticsz, minticsz; - - public PSplot(final PSpage page, final double ppll, final double ppur, - final double qqll, final double qqur) { - pll = ppll; - qll = qqll; - pur = ppur; - qur = qqur; - xll = ppll; - yll = qqll; - xur = ppur; - yur = qqur; - xbox = new double[4]; - ybox = new double[4]; - majticsz = 8.; - minticsz = 4.; - fontname = new String(page.fontname); - fontsize = page.fontsize; - PLT = page.PLT; - setlimits(xll, xur, yll, yur); - } - - double p(final double x) { - return pll + (pur - pll) * (x - xll) / (xur - xll); - } - - double q(final double y) { - return qll + (qur - qll) * (y - yll) / (yur - yll); - } - - public void setlimits(final double xxll, final double xxur, - final double yyll, final double yyur) { - xbox[0] = xbox[3] = xll = xxll; - ybox[0] = ybox[1] = yll = yyll; - xbox[1] = xbox[2] = xur = xxur; - ybox[2] = ybox[3] = yur = yyur; - } - - @Override - public void lineseg(final double xs, final double ys, final double xf, - final double yf) { - super.lineseg(p(xs), q(ys), p(xf), q(yf)); - } - - @Override - public void polyline(final double[] x, final double[] y) { - polyline(x, y, false, false, false); - } - - public void polyline(final double[] x, final double[] y, - final boolean close, final boolean fill) { - polyline(x, y, close, fill, false); - } - - @Override - public void polyline(final double[] x, final double[] y, - final boolean close, final boolean fill, final boolean clip) { - int i; - double[] xx = buildVector(x); - double[] yy = buildVector(y); - for (i = 0; i < x.length; i++) - xx[i] = p(x[i]); - for (i = 0; i < y.length; i++) - yy[i] = q(y[i]); - super.polyline(xx, yy, close, fill, clip); - } - - public void dot(final double x, final double y) { - dot(x, y, 2); - } - - public void dot(final double x, final double y, final double size) { - super.pointsymbol(p(x), q(y), 108, size); - } - - @Override - public void pointsymbol(final double x, final double y, final int num, - final double size) { - super.pointsymbol(p(x), q(y), num, size); - } - - public void lineplot(final double[] x, final double[] y) { - polyline(x, y); - } - - public void frame() { - polyline(xbox, ybox, true, false); - } - - public void clear() { - gsave(); - setgray(1.); - polyline(xbox, ybox, true, true); - grestore(); - } - - public void clip() { - gsave(); - polyline(xbox, ybox, true, false, true); - } - - public void clip(final double[] x, final double[] y) { - gsave(); - polyline(x, y, true, false, true); - } - - public void unclip() { - grestore(); - } - - public void xlabel(final String text) { - putctext(text, 0.5 * (pll + pur), qll - 2. * fontsize - 8.); - } - - public void ylabel(final String text) { - putctext(text, pll - 3. * fontsize - 8., 0.5 * (qll + qur), 90.); - } - - public void label(final String text, final double x, final double y) { - label(text, x, y, 0); - } - - public void label(final String text, final double x, final double y, - final double rot) { - puttext(text, p(x), q(y), rot); - } - - public String scalestr(double x) { - if (abs(x) < 1.e-15) - x = 0.; - return String.format("%g", x); - } - - public void scales(final double xmajd, final double xmind, - final double ymajd, final double ymind) { - scales(xmajd, xmind, ymajd, ymind, 2, 2, 1, 1); - } - - public void scales(final double xmajd, final double xmind, - final double ymajd, final double ymind, final int dox, - final int doy, final int doxx, final int doyy) { - String str; - double x, y, xlo, ylo; - if (dox != 0 || doxx != 0) { - xlo = ceil(min(xll, xur) / xmajd) * xmajd; - for (x = xlo; x <= max(xll, xur); x += xmajd) { - str = scalestr(x); - if (dox > 1) - putctext(str, p(x), qll - fontsize - 2.); - if (dox != 0) - super.lineseg(p(x), qll, p(x), qll + majticsz); - if (doxx != 0) - super.lineseg(p(x), qur, p(x), qur - majticsz); - } - xlo = ceil(min(xll, xur) / xmind) * xmind; - for (x = xlo; x <= max(xll, xur); x += xmind) { - if (dox != 0) - super.lineseg(p(x), qll, p(x), qll + minticsz); - if (doxx != 0) - super.lineseg(p(x), qur, p(x), qur - minticsz); - } - } - if (doy != 0 || doyy != 0) { - ylo = ceil(min(yll, yur) / ymajd) * ymajd; - for (y = ylo; y <= max(yll, yur); y += ymajd) { - str = scalestr(y); - if (doy > 1) - putrtext(str, pll - 4., q(y) - 0.3 * fontsize); - if (doy != 0) - super.lineseg(pll, q(y), pll + majticsz, q(y)); - if (doyy != 0) - super.lineseg(pur, q(y), pur - majticsz, q(y)); - } - ylo = ceil(min(yll, yur) / ymind) * ymind; - for (y = ylo; y <= max(yll, yur); y += ymind) { - if (doy != 0) - super.lineseg(pll, q(y), pll + minticsz, q(y)); - if (doyy != 0) - super.lineseg(pur, q(y), pur - minticsz, q(y)); - } - } - } - - public void autoscales() { - double xmajd, xmind, ymajd, ymind; - xmajd = pow(10., ((int) (log10(abs(xur - xll)) - 1.1))); - xmind = xmajd / 5.; - ymajd = pow(10., ((int) (log10(abs(yur - yll)) - 1.1))); - ymind = ymajd / 5.; - scales(xmajd, xmind, ymajd, ymind); - } - - public static void scrsho(final UniVarRealValueFun fx, final double x1, - final double x2, final File psfile) throws IOException { - final int RES = 500; - final double XLL = 75., XUR = 525., YLL = 250., YUR = 700.; - double[] xx = new double[RES]; - double[] yy = new double[RES]; - int i; - double ymax = -9.99e99, ymin = 9.99e99, del; - for (i = 0; i < RES; i++) { - xx[i] = x1 + i * (x2 - x1) / (RES - 1.); - yy[i] = fx.funk(xx[i]); - if (yy[i] > ymax) - ymax = yy[i]; - if (yy[i] < ymin) - ymin = yy[i]; - } - del = 0.05 * ((ymax - ymin) + (ymax == ymin ? abs(ymax) : 0.)); - PSpage pg = new PSpage(psfile); - PSplot plot = new PSplot(pg, XLL, XUR, YLL, YUR); - plot.setlimits(x1, x2, ymin - del, ymax + del); - plot.frame(); - plot.autoscales(); - plot.lineplot(xx, yy); - if (ymax * ymin < 0.) - plot.lineseg(x1, 0., x2, 0.); - plot.close(); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/min/Amebsa.java b/common-tools/cnuphys/numRec/src/com/nr/min/Amebsa.java deleted file mode 100644 index 38b6f1901a..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/min/Amebsa.java +++ /dev/null @@ -1,204 +0,0 @@ -package com.nr.min; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -import org.netlib.util.intW; - -import com.nr.RealValueFun; -import com.nr.ran.Ranq1; - -/** - * Downhill simplex minimization with simulated annealing - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Amebsa { - RealValueFun funk; - final double ftol; - private Ranq1 ran; - public double yb; - public int ndim; - public double[] pb; - public int mpts; - public double[] y; - public double[][] p; - public double tt; - - public Amebsa(final double[] point, final double del, - final RealValueFun funkk, final double ftoll) { - funk = funkk; - ftol = ftoll; - ran = new Ranq1(1234); - yb = Double.MAX_VALUE; - ndim = point.length; - pb = new double[ndim]; - mpts = ndim + 1; - y = new double[mpts]; - p = new double[mpts][ndim]; - - for (int i = 0; i < mpts; i++) { - for (int j = 0; j < ndim; j++) - p[i][j] = point[j]; - if (i != 0) - p[i][i - 1] += del; - } - inity(); - } - - public Amebsa(final double[] point, final double[] dels, - final RealValueFun funkk, final double ftoll) { - funk = funkk; - ftol = ftoll; - ran = new Ranq1(1234); - yb = Double.MAX_VALUE; - ndim = point.length; - pb = new double[ndim]; - mpts = ndim + 1; - y = new double[mpts]; - p = new double[mpts][ndim]; - for (int i = 0; i < mpts; i++) { - for (int j = 0; j < ndim; j++) - p[i][j] = point[j]; - if (i != 0) - p[i][i - 1] += dels[i - 1]; - } - inity(); - } - - public Amebsa(final double[][] pp, final RealValueFun funkk, - final double ftoll) { - funk = funkk; - ftol = ftoll; - ran = new Ranq1(1234); - yb = Double.MAX_VALUE; - ndim = pp[0].length; - pb = new double[ndim]; - mpts = pp.length; - y = new double[mpts]; - p = new double[pp.length][pp[0].length]; - copyAssign(p, pp); - inity(); - } - - public void inity() { - double[] x = new double[ndim]; - for (int i = 0; i < mpts; i++) { - for (int j = 0; j < ndim; j++) - x[j] = p[i][j]; - y[i] = funk.funk(x); - } - } - - public boolean anneal(final intW iter, final double temperature) { // int[] - // simulated - // pointer. - double[] psum = new double[ndim]; - tt = -temperature; - get_psum(p, psum); - for (;;) { - int ilo = 0; - int ihi = 1; - double ylo = y[0] + tt * log(ran.doub()); - double ynhi = ylo; - double[] yhi = new double[1]; - yhi[0] = y[1] + tt * log(ran.doub()); - if (ylo > yhi[0]) { - ihi = 0; - ilo = 1; - ynhi = yhi[0]; - yhi[0] = ylo; - ylo = ynhi; - } - for (int i = 3; i <= mpts; i++) { - double yt = y[i - 1] + tt * log(ran.doub()); - if (yt <= ylo) { - ilo = i - 1; - ylo = yt; - } - if (yt > yhi[0]) { - ynhi = yhi[0]; - ihi = i - 1; - yhi[0] = yt; - } else if (yt > ynhi) { - ynhi = yt; - } - } - double rtol = 2.0 * abs(yhi[0] - ylo) / (abs(yhi[0]) + abs(ylo)); - if (rtol < ftol || iter.val < 0) { - swap(y, 0, ilo); - for (int n = 0; n < ndim; n++) { - // SWAP(p[0][n],p[ilo][n]); - double dum = p[0][n]; - p[0][n] = p[ilo][n]; - p[ilo][n] = dum; - } - if (rtol < ftol) - return true; - else - return false; - } - iter.val -= 2; - double ytry = amotsa(p, y, psum, ihi, yhi, -1.0); - if (ytry <= ylo) { - ytry = amotsa(p, y, psum, ihi, yhi, 2.0); - } else if (ytry >= ynhi) { - double ysave = yhi[0]; - ytry = amotsa(p, y, psum, ihi, yhi, 0.5); - if (ytry >= ysave) { - for (int i = 0; i < mpts; i++) { - if (i != ilo) { - for (int j = 0; j < ndim; j++) { - psum[j] = 0.5 * (p[i][j] + p[ilo][j]); - p[i][j] = psum[j]; - } - y[i] = funk.funk(psum); - } - } - iter.val -= ndim; - get_psum(p, psum); - } - } else - ++iter.val; - } - } - - public void get_psum(final double[][] p, final double[] psum) { - for (int n = 0; n < ndim; n++) { - double sum = 0.0; - for (int m = 0; m < mpts; m++) - sum += p[m][n]; - psum[n] = sum; - } - } - - public double amotsa(final double[][] p, final double[] y, - final double[] psum, final int ihi, final double[] yhi, - final double fac) { - double[] ptry = new double[ndim]; - double fac1 = (1.0 - fac) / ndim; - double fac2 = fac1 - fac; - for (int j = 0; j < ndim; j++) - ptry[j] = psum[j] * fac1 - p[ihi][j] * fac2; - double ytry = funk.funk(ptry); - if (ytry <= yb) { - for (int j = 0; j < ndim; j++) - pb[j] = ptry[j]; - yb = ytry; - } - double yflu = ytry - tt * log(ran.doub()); - if (yflu < yhi[0]) { - y[ihi] = ytry; - yhi[0] = yflu; - for (int j = 0; j < ndim; j++) { - psum[j] += ptry[j] - p[ihi][j]; - p[ihi][j] = ptry[j]; - } - } - return yflu; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/min/Amoeba.java b/common-tools/cnuphys/numRec/src/com/nr/min/Amoeba.java deleted file mode 100644 index b0b892c8f3..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/min/Amoeba.java +++ /dev/null @@ -1,157 +0,0 @@ -package com.nr.min; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import com.nr.RealValueFun; - -/** - * Downhill Simplex Method in Multidimensions - * - * downhill simplex minimization Copyright (C) Numerical Recipes Software - * 1986-2007 Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Amoeba { - final double ftol; - int nfunc; - int mpts; - int ndim; - double fmin; - double[] y; - double[][] p; - - public Amoeba(final double ftoll) { - this.ftol = ftoll; - } - - public double[] minimize(final double[] point, final double del, - final RealValueFun func) { - double[] dels = buildVector(point.length, del); - return minimize(point, dels, func); - } - - public double[] minimize(final double[] point, final double[] dels, - final RealValueFun func) { - int ndim = point.length; - double[][] pp = new double[ndim + 1][ndim]; - for (int i = 0; i < ndim + 1; i++) { - for (int j = 0; j < ndim; j++) - pp[i][j] = point[j]; - if (i != 0) - pp[i][i - 1] += dels[i - 1]; - } - return minimize(pp, func); - } - - public double[] minimize(final double[][] pp, final RealValueFun func) { - final int NMAX = 5000; - final double TINY = 1.0e-10; - int ihi, ilo, inhi; - mpts = pp.length; - ndim = pp[0].length; - double[] psum = new double[ndim]; - double[] pmin = new double[ndim]; - double[] x = new double[ndim]; - p = new double[pp.length][pp[0].length]; - copyAssign(p, pp); // XXX p=pp, in NR "=" is overloading, see "nr3.h" - // y = resize(y,mpts); - y = new double[mpts]; - for (int i = 0; i < mpts; i++) { - for (int j = 0; j < ndim; j++) - x[j] = p[i][j]; - y[i] = func.funk(x); - } - nfunc = 0; - get_psum(p, psum); - for (;;) { - ilo = 0; - - // XXX ihi = y[0]>y[1] ? (inhi=1,0) : (inhi=0,1); - ihi = 0; - if (y[0] > y[1]) { - inhi = 1; - ihi = 0; - } else { - inhi = 0; - ihi = 1; - } - - for (int i = 0; i < mpts; i++) { - if (y[i] <= y[ilo]) - ilo = i; - if (y[i] > y[ihi]) { - inhi = ihi; - ihi = i; - } else if (y[i] > y[inhi] && i != ihi) - inhi = i; - } - double rtol = 2.0 * abs(y[ihi] - y[ilo]) - / (abs(y[ihi]) + abs(y[ilo]) + TINY); - if (rtol < ftol) { - swap(y, 0, ilo); - for (int i = 0; i < ndim; i++) { - // SWAP(p[0][i],p[ilo][i]); - double dum = p[0][i]; - p[0][i] = p[ilo][i]; - p[ilo][i] = dum; - pmin[i] = p[0][i]; - } - fmin = y[0]; - return pmin; - } - if (nfunc >= NMAX) { - throw new Error("NMAX exceeded"); - } - nfunc += 2; - double ytry = amotry(p, y, psum, ihi, -1.0, func); - if (ytry <= y[ilo]) - ytry = amotry(p, y, psum, ihi, 2.0, func); - else if (ytry >= y[inhi]) { - double ysave = y[ihi]; - ytry = amotry(p, y, psum, ihi, 0.5, func); - if (ytry >= ysave) { - for (int i = 0; i < mpts; i++) { - if (i != ilo) { - for (int j = 0; j < ndim; j++) - p[i][j] = psum[j] = 0.5 * (p[i][j] + p[ilo][j]); - y[i] = func.funk(psum); - } - } - nfunc += ndim; - get_psum(p, psum); - } - } else - --nfunc; - } - } - - public void get_psum(final double[][] p, final double[] psum) { - for (int j = 0; j < ndim; j++) { - double sum = 0.0; - for (int i = 0; i < mpts; i++) - sum += p[i][j]; - psum[j] = sum; - } - } - - public double amotry(final double[][] p, final double[] y, - final double[] psum, final int ihi, final double fac, - final RealValueFun func) { - double[] ptry = new double[ndim]; - double fac1 = (1.0 - fac) / ndim; - double fac2 = fac1 - fac; - for (int j = 0; j < ndim; j++) - ptry[j] = psum[j] * fac1 - p[ihi][j] * fac2; - double ytry = func.funk(ptry); - if (ytry < y[ihi]) { - y[ihi] = ytry; - for (int j = 0; j < ndim; j++) { - psum[j] += ptry[j] - p[ihi][j]; - p[ihi][j] = ptry[j]; - } - } - return ytry; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/min/Anneal.java b/common-tools/cnuphys/numRec/src/com/nr/min/Anneal.java deleted file mode 100644 index 247b507e96..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/min/Anneal.java +++ /dev/null @@ -1,164 +0,0 @@ -package com.nr.min; - -import static java.lang.Math.*; -import com.nr.ran.Ranq1; - -/** - * simulated annealing Copyright (C) Numerical Recipes Software 1986-2007 Java - * translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Anneal { - Ranq1 myran = new Ranq1(1234); - - public Anneal() { - } - - public double order(final double[] x, final double[] y, final int[] iorder) { - final double TFACTR = 0.9; - boolean ans; - int i, i1, i2, nn; - int[] n = new int[6]; - double de, path = 0.0, t = 0.5; - int ncity = x.length; - int nover = 100 * ncity; - int nlimit = 10 * ncity; - for (i = 0; i < ncity - 1; i++) { - i1 = iorder[i]; - i2 = iorder[i + 1]; - path += alen(x[i1], x[i2], y[i1], y[i2]); - } - i1 = iorder[ncity - 1]; - i2 = iorder[0]; - path += alen(x[i1], x[i2], y[i1], y[i2]); - // cout << fixed << setprecision(6); - for (int j = 0; j < 100; j++) { - int nsucc = 0; - for (int k = 0; k < nover; k++) { - do { - n[0] = (int) (ncity * myran.doub()); - n[1] = (int) ((ncity - 1) * myran.doub()); - if (n[1] >= n[0]) - ++n[1]; - nn = (n[0] - n[1] + ncity - 1) % ncity; - } while (nn < 2); - if (myran.doub() < 0.5) { - n[2] = n[1] + (int) (abs(nn - 1) * myran.doub()) + 1; - n[2] %= ncity; - de = trncst(x, y, iorder, n); - ans = metrop(de, t); - if (ans) { - ++nsucc; - path += de; - trnspt(iorder, n); - } - } else { - de = revcst(x, y, iorder, n); - ans = metrop(de, t); - if (ans) { - ++nsucc; - path += de; - reverse(iorder, n); - } - } - if (nsucc >= nlimit) - break; - } - // cout << endl << "T = " << setw(12) << t; - // cout << " Path Length = " << setw(12) << path << endl; - // cout << "Successful Moves: " << nsucc << endl; - t *= TFACTR; - if (nsucc == 0) - return path; - } - - return path; - } - - double revcst(final double[] x, final double[] y, final int[] iorder, - final int[] n) { - double[] xx = new double[4]; - double[] yy = new double[4]; - int ncity = x.length; - n[2] = (n[0] + ncity - 1) % ncity; - n[3] = (n[1] + 1) % ncity; - for (int j = 0; j < 4; j++) { - int ii = iorder[n[j]]; - xx[j] = x[ii]; - yy[j] = y[ii]; - } - double de = -alen(xx[0], xx[2], yy[0], yy[2]); - de -= alen(xx[1], xx[3], yy[1], yy[3]); - de += alen(xx[0], xx[3], yy[0], yy[3]); - de += alen(xx[1], xx[2], yy[1], yy[2]); - return de; - } - - void reverse(final int[] iorder, final int[] n) { - int ncity = iorder.length; - int nn = (1 + ((n[1] - n[0] + ncity) % ncity)) / 2; - for (int j = 0; j < nn; j++) { - int k = (n[0] + j) % ncity; - int l = (n[1] - j + ncity) % ncity; - int itmp = iorder[k]; - iorder[k] = iorder[l]; - iorder[l] = itmp; - } - } - - double trncst(final double[] x, final double[] y, final int[] iorder, - final int[] n) { - double[] xx = new double[6]; - double[] yy = new double[6]; - int ncity = x.length; - n[3] = (n[2] + 1) % ncity; - n[4] = (n[0] + ncity - 1) % ncity; - n[5] = (n[1] + 1) % ncity; - for (int j = 0; j < 6; j++) { - int ii = iorder[n[j]]; - xx[j] = x[ii]; - yy[j] = y[ii]; - } - double de = -alen(xx[1], xx[5], yy[1], yy[5]); - de -= alen(xx[0], xx[4], yy[0], yy[4]); - de -= alen(xx[2], xx[3], yy[2], yy[3]); - de += alen(xx[0], xx[2], yy[0], yy[2]); - de += alen(xx[1], xx[3], yy[1], yy[3]); - de += alen(xx[4], xx[5], yy[4], yy[5]); - return de; - } - - public void trnspt(final int[] iorder, final int[] n) { - int ncity = iorder.length; - int[] jorder = new int[ncity]; - int m1 = (n[1] - n[0] + ncity) % ncity; - int m2 = (n[4] - n[3] + ncity) % ncity; - int m3 = (n[2] - n[5] + ncity) % ncity; - int nn = 0; - for (int j = 0; j <= m1; j++) { - int jj = (j + n[0]) % ncity; - jorder[nn++] = iorder[jj]; - } - for (int j = 0; j <= m2; j++) { - int jj = (j + n[3]) % ncity; - jorder[nn++] = iorder[jj]; - } - for (int j = 0; j <= m3; j++) { - int jj = (j + n[5]) % ncity; - jorder[nn++] = iorder[jj]; - } - for (int j = 0; j < ncity; j++) - iorder[j] = jorder[j]; - } - - public boolean metrop(final double de, final double t) { - return de < 0.0 || myran.doub() < exp(-de / t); - } - - public double alen(final double a, final double b, final double c, - final double d) { - return sqrt((b - a) * (b - a) + (d - c) * (d - c)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/min/Bracketmethod.java b/common-tools/cnuphys/numRec/src/com/nr/min/Bracketmethod.java deleted file mode 100644 index 8c380e6566..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/min/Bracketmethod.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.nr.min; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import com.nr.UniVarRealValueFun; - -/** - * Base class for one-dimensional minimization routines. Provides a routine to - * bracket a minimum and several utility functions. - * - */ -public class Bracketmethod { - public double ax, bx, cx, fa, fb, fc; - - public Bracketmethod() { - - } - - /** - * Given a function or functor func, and given distinct initial points ax - * and bx, this routine searches in the downhill direction (defined by the - * function as evaluated at the initial points) and returns new points ax, - * bx, cx that bracket a minimum of the function. Also returned are the - * function values at the three points, fa, fb, and fc. - * - * @param a - * @param b - * @param func - */ - public void bracket(final double a, final double b, - final UniVarRealValueFun func) { - final double GOLD = 1.618034, GLIMIT = 100.0, TINY = 1.0e-20; - ax = a; - bx = b; - double fu; - fa = func.funk(ax); - fb = func.funk(bx); - if (fb > fa) { - // SWAP(ax,bx); - double swap = ax; - ax = bx; - bx = swap; - // SWAP(fb,fa); - swap = fb; - fb = fa; - fa = swap; - } - cx = bx + GOLD * (bx - ax); - fc = func.funk(cx); - while (fb > fc) { - double r = (bx - ax) * (fb - fc); - double q = (bx - cx) * (fb - fa); - double u = bx - ((bx - cx) * q - (bx - ax) * r) - / (2.0 * SIGN(max(abs(q - r), TINY), q - r)); - double ulim = bx + GLIMIT * (cx - bx); - if ((bx - u) * (u - cx) > 0.0) { - fu = func.funk(u); - if (fu < fc) { - ax = bx; - bx = u; - fa = fb; - fb = fu; - return; - } else if (fu > fb) { - cx = u; - fc = fu; - return; - } - u = cx + GOLD * (cx - bx); - fu = func.funk(u); - } else if ((cx - u) * (u - ulim) > 0.0) { - fu = func.funk(u); - if (fu < fc) { - // shft3(bx,cx,u,u+GOLD*(u-cx)); - double dum = u + GOLD * (u - cx); - bx = cx; - cx = u; - u = dum; - // shft3(fb,fc,fu,func.funk(u)); - fb = fc; - fc = fu; - fu = func.funk(u); - } - } else if ((u - ulim) * (ulim - cx) >= 0.0) { - u = ulim; - fu = func.funk(u); - } else { - u = cx + GOLD * (cx - bx); - fu = func.funk(u); - } - // shft3(ax,bx,cx,u); - ax = bx; - bx = cx; - cx = u; - // shft3(fa,fb,fc,fu); - fa = fb; - fb = fc; - fc = fu; - } - } - - /* - * public static void shft2(doubleW a, doubleW b, final double c) { - * a.val=b.val; b.val=c; } - * - * public static void shft3(doubleW a, doubleW b, doubleW c, final double d) - * { a.val=b.val; b.val=c.val; c.val=d; } - * - * public static void mov3(doubleW a, doubleW b, doubleW c, final double d, - * final double e, final double f) { a.val=d; b.val=e; c.val=f; } - */ -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/min/Brent.java b/common-tools/cnuphys/numRec/src/com/nr/min/Brent.java deleted file mode 100644 index 5b73c6a29f..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/min/Brent.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.nr.min; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; -import com.nr.UniVarRealValueFun; - -/** - * Parabolic Interpolation and Brent's Method Copyright (C) Numerical Recipes - * Software 1986-2007 Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Brent extends Bracketmethod { - double xmin, fmin; - final double tol; - - public Brent() { - this(3.0e-8); - } - - public Brent(final double toll) { - tol = toll; - } - - public double minimize(final UniVarRealValueFun func) { - final int ITMAX = 100; - final double CGOLD = 0.3819660; - final double ZEPS = DBL_EPSILON * 1.0e-3; - double a, b, d = 0.0, etemp, fu, fv, fw, fx; - double p, q, r, tol1, tol2, u, v, w, x, xm; - double e = 0.0; - - a = (ax < cx ? ax : cx); - b = (ax > cx ? ax : cx); - x = w = v = bx; - fw = fv = fx = func.funk(x); - for (int iter = 0; iter < ITMAX; iter++) { - xm = 0.5 * (a + b); - tol2 = 2.0 * (tol1 = tol * abs(x) + ZEPS); - if (abs(x - xm) <= (tol2 - 0.5 * (b - a))) { - fmin = fx; - return xmin = x; - } - if (abs(e) > tol1) { - r = (x - w) * (fx - fv); - q = (x - v) * (fx - fw); - p = (x - v) * q - (x - w) * r; - q = 2.0 * (q - r); - if (q > 0.0) - p = -p; - q = abs(q); - etemp = e; - e = d; - if (abs(p) >= abs(0.5 * q * etemp) || p <= q * (a - x) - || p >= q * (b - x)) - d = CGOLD * (e = (x >= xm ? a - x : b - x)); - else { - d = p / q; - u = x + d; - if (u - a < tol2 || b - u < tol2) - d = SIGN(tol1, xm - x); - } - } else { - d = CGOLD * (e = (x >= xm ? a - x : b - x)); - } - u = (abs(d) >= tol1 ? x + d : x + SIGN(tol1, d)); - fu = func.funk(u); - if (fu <= fx) { - if (u >= x) - a = x; - else - b = x; - // shft3(v,w,x,u); - v = w; - w = x; - x = u; - // shft3(fv,fw,fx,fu); - fv = fw; - fw = fx; - fx = fu; - } else { - if (u < x) - a = u; - else - b = u; - if (fu <= fw || w == x) { - v = w; - w = u; - fv = fw; - fw = fu; - } else if (fu <= fv || v == x || v == w) { - v = u; - fv = fu; - } - } - } - throw new IllegalArgumentException("Too many iterations in brent"); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/min/Dbrent.java b/common-tools/cnuphys/numRec/src/com/nr/min/Dbrent.java deleted file mode 100644 index 9cead2d118..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/min/Dbrent.java +++ /dev/null @@ -1,136 +0,0 @@ -package com.nr.min; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import com.nr.UniValRealValueFunWithDiff; - -/** - * Brent's method to find a minimum, modified to use derivatives. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Dbrent extends Bracketmethod { - double xmin, fmin; - final double tol; - - public Dbrent() { - this(3.0e-8); - } - - public Dbrent(final double toll) { - this.tol = toll; - } - - public double minimize(final UniValRealValueFunWithDiff funcd) { - final int ITMAX = 100; - final double ZEPS = DBL_EPSILON * 1.0e-3; - boolean ok1, ok2; - double a, b, d = 0.0, d1, d2, du, dv, dw, dx, e = 0.0; - double fu, fv, fw, fx, olde, tol1, tol2, u, u1, u2, v, w, x, xm; - - a = (ax < cx ? ax : cx); - b = (ax > cx ? ax : cx); - x = w = v = bx; - fw = fv = fx = funcd.funk(x); - dw = dv = dx = funcd.df(x); - for (int iter = 0; iter < ITMAX; iter++) { - xm = 0.5 * (a + b); - tol1 = tol * abs(x) + ZEPS; - tol2 = 2.0 * tol1; - if (abs(x - xm) <= (tol2 - 0.5 * (b - a))) { - fmin = fx; - return xmin = x; - } - if (abs(e) > tol1) { - d1 = 2.0 * (b - a); - d2 = d1; - if (dw != dx) - d1 = (w - x) * dx / (dx - dw); - if (dv != dx) - d2 = (v - x) * dx / (dx - dv); - u1 = x + d1; - u2 = x + d2; - ok1 = (a - u1) * (u1 - b) > 0.0 && dx * d1 <= 0.0; - ok2 = (a - u2) * (u2 - b) > 0.0 && dx * d2 <= 0.0; - olde = e; - e = d; - if (ok1 || ok2) { - if (ok1 && ok2) - d = (abs(d1) < abs(d2) ? d1 : d2); - else if (ok1) - d = d1; - else - d = d2; - if (abs(d) <= abs(0.5 * olde)) { - u = x + d; - if (u - a < tol2 || b - u < tol2) - d = SIGN(tol1, xm - x); - } else { - d = 0.5 * (e = (dx >= 0.0 ? a - x : b - x)); - } - } else { - d = 0.5 * (e = (dx >= 0.0 ? a - x : b - x)); - } - } else { - d = 0.5 * (e = (dx >= 0.0 ? a - x : b - x)); - } - if (abs(d) >= tol1) { - u = x + d; - fu = funcd.funk(u); - } else { - u = x + SIGN(tol1, d); - fu = funcd.funk(u); - if (fu > fx) { - fmin = fx; - return xmin = x; - } - } - du = funcd.df(u); - if (fu <= fx) { - if (u >= x) - a = x; - else - b = x; - // mov3(v,fv,dv,w,fw,dw); - v = w; - fv = fw; - dv = dw; - // mov3(w,fw,dw,x,fx,dx); - w = x; - fw = fx; - dw = dx; - // mov3(x,fx,dx,u,fu,du); - x = u; - fx = fu; - dx = du; - } else { - if (u < x) - a = u; - else - b = u; - if (fu <= fw || w == x) { - // mov3(v,fv,dv,w,fw,dw); - v = w; - fv = fw; - dv = dw; - // mov3(w,fw,dw,u,fu,du); - w = u; - fw = fu; - dw = du; - } else if (fu < fv || v == x || v == w) { - // mov3(v,fv,dv,u,fu,du); - v = u; - fv = fu; - dv = du; - } - } - } - throw new IllegalArgumentException( - "Too many iterations in routine dbrent"); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/min/Df1dim.java b/common-tools/cnuphys/numRec/src/com/nr/min/Df1dim.java deleted file mode 100644 index 7814942465..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/min/Df1dim.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.nr.min; - -import com.nr.RealValueFunWithDiff; -import com.nr.UniValRealValueFunWithDiff; - -public class Df1dim implements UniValRealValueFunWithDiff { - final double[] p; - final double[] xi; - int n; - RealValueFunWithDiff funcd; - double[] xt; - double[] dft; - - public Df1dim(final double[] pp, final double[] xii, - final RealValueFunWithDiff funcdd) { - p = pp; - xi = xii; - n = pp.length; - funcd = funcdd; - xt = new double[n]; - dft = new double[n]; - } - - @Override - public double funk(final double x) { - return get(x); - } - - public double get(final double x) { - for (int j = 0; j < n; j++) - xt[j] = p[j] + x * xi[j]; - return funcd.funk(xt); - } - - @Override - public double df(final double x) { - double df1 = 0.0; - funcd.df(xt, dft); - for (int j = 0; j < n; j++) - df1 += dft[j] * xi[j]; - return df1; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/min/Dlinemethod.java b/common-tools/cnuphys/numRec/src/com/nr/min/Dlinemethod.java deleted file mode 100644 index 9e86dd8751..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/min/Dlinemethod.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.nr.min; - -import com.nr.RealValueFunWithDiff; - -/** - * Base class for line-minimization algorithms using derivative information. - * Provides the line-minimization routine linmin. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Dlinemethod { - public double[] p; - public double[] xi; - RealValueFunWithDiff func; - int n; - - public Dlinemethod(final RealValueFunWithDiff funcc) { - func = funcc; - } - - /** - * @return - */ - public double linmin() { - double ax, xx, xmin; - n = p.length; - Df1dim df1dim = new Df1dim(p, xi, func); - ax = 0.0; - xx = 1.0; - Dbrent dbrent = new Dbrent(); - dbrent.bracket(ax, xx, df1dim); - xmin = dbrent.minimize(df1dim); - for (int j = 0; j < n; j++) { - xi[j] *= xmin; - p[j] += xi[j]; - } - return dbrent.fmin; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/min/Dynpro.java b/common-tools/cnuphys/numRec/src/com/nr/min/Dynpro.java deleted file mode 100644 index e98f76eb9f..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/min/Dynpro.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.nr.min; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -/** - * Given the vector nstate whose integer values are the number of states in each - * stage (1 for the first and last stages), and given a function cost(j,k,i) - * that returns the cost of moving between state j of stage i and state k of - * stage i+1, this routine returns a vector of the same length as nstate - * containing the state numbers of the lowest cost path. States number from 0, - * and the first and last components of the returned vector will thus always be - * 0. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public abstract class Dynpro { - public Dynpro() { - } - - public abstract double cost(int jj, int kk, int ii); - - public int[] dynpro(final int[] nstate) { - final double BIG = 1.e99; - final double EPS = DBL_EPSILON; - int i, j, k, nstage = nstate.length - 1; - double a, b; - int[] answer = new int[nstage + 1]; - if (nstate[0] != 1 || nstate[nstage] != 1) - throw new IllegalArgumentException( - "One state allowed in first and last stages."); - double[][] best = new double[nstage + 1][]; - best[0] = new double[nstate[0]]; - best[0][0] = 0.; - for (i = 1; i <= nstage; i++) { - best[i] = new double[nstate[i]]; - for (k = 0; k < nstate[i]; k++) { - b = BIG; - for (j = 0; j < nstate[i - 1]; j++) { - if ((a = best[i - 1][j] + cost(j, k, i - 1)) < b) - b = a; - } - best[i][k] = b; - } - } - answer[nstage] = answer[0] = 0; - for (i = nstage - 1; i > 0; i--) { - k = answer[i + 1]; - b = best[i + 1][k]; - for (j = 0; j < nstate[i]; j++) { - double temp = best[i][j] + cost(j, k, i); - if (abs(b - temp) <= EPS * abs(temp)) - break; - } - answer[i] = j; - } - return answer; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/min/F1dim.java b/common-tools/cnuphys/numRec/src/com/nr/min/F1dim.java deleted file mode 100644 index c4f5e4f9e5..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/min/F1dim.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.nr.min; - -import com.nr.RealValueFun; -import com.nr.UniVarRealValueFun; - -public class F1dim implements UniVarRealValueFun { - final double[] p; - final double[] xi; - int n; - RealValueFun func; - double[] xt; - - public F1dim(final double[] pp, final double[] xii, final RealValueFun funcc) { - p = pp; - xi = xii; - n = pp.length; - func = funcc; - xt = new double[n]; - } - - @Override - public double funk(final double x) { - return get(x); - } - - public double get(final double x) { - for (int j = 0; j < n; j++) - xt[j] = p[j] + x * xi[j]; - return func.funk(xt); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/min/Frprmn.java b/common-tools/cnuphys/numRec/src/com/nr/min/Frprmn.java deleted file mode 100644 index 0810522833..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/min/Frprmn.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.nr.min; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import com.nr.RealValueFunWithDiff; - -public class Frprmn extends Dlinemethod { // orig is Linemethod XXX may be - // Dlinemethod is better - public int iter; - public double fret; - /* - * using Linemethod::func; using Linemethod::linmin; using - * Linemethod::p; using Linemethod::xi; - */ - final double ftol; - - public Frprmn(final RealValueFunWithDiff funcd) { - this(funcd, 3.0e-8); - } - - public Frprmn(final RealValueFunWithDiff funcd, final double ftoll) { - super(funcd); - ftol = ftoll; - } - - public double[] minimize(final double[] pp) { - final int ITMAX = 200; - final double EPS = 1.0e-18; - final double GTOL = 1.0e-8; - double gg, dgg; - int n = pp.length; - p = buildVector(pp); - double[] g = new double[n], h = new double[n]; - xi = new double[n]; - double fp = func.funk(p); - func.df(p, xi); - for (int j = 0; j < n; j++) { - g[j] = -xi[j]; - xi[j] = h[j] = g[j]; - } - for (int its = 0; its < ITMAX; its++) { - iter = its; - fret = linmin(); - if (2.0 * abs(fret - fp) <= ftol * (abs(fret) + abs(fp) + EPS)) - return p; - fp = fret; - func.df(p, xi); - double test = 0.0; - double den = max(abs(fp), 1.0); - for (int j = 0; j < n; j++) { - double temp = abs(xi[j]) * max(abs(p[j]), 1.0) / den; - if (temp > test) - test = temp; - } - if (test < GTOL) - return p; - dgg = gg = 0.0; - for (int j = 0; j < n; j++) { - gg += g[j] * g[j]; - // dgg += xi[j]*xi[j]; - dgg += (xi[j] + g[j]) * xi[j]; - } - if (gg == 0.0) - return p; - double gam = dgg / gg; - for (int j = 0; j < n; j++) { - g[j] = -xi[j]; - xi[j] = h[j] = g[j] + gam * h[j]; - } - } - throw new IllegalArgumentException("Too many iterations in frprmn"); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/min/Funcd.java b/common-tools/cnuphys/numRec/src/com/nr/min/Funcd.java deleted file mode 100644 index 1981b43c02..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/min/Funcd.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.nr.min; - -import static java.lang.Math.*; -import com.nr.RealValueFun; -import com.nr.RealValueFunWithDiff; - -public class Funcd implements RealValueFunWithDiff { - double EPS; - RealValueFun func; - double f; - - public Funcd(final RealValueFun funcc) { - EPS = 1.0e-8; - func = funcc; - } - - @Override - public double funk(final double[] x) { - return get(x); - } - - public double get(final double[] x) { - return f = func.funk(x); - } - - @Override - public void df(final double[] x, final double[] df) { - int n = x.length; - double[] xh = x; - double fold = f; - for (int j = 0; j < n; j++) { - double temp = x[j]; - double h = EPS * abs(temp); - if (h == 0.0) - h = EPS; - xh[j] = temp + h; - h = xh[j] - temp; - double fh = get(xh); - xh[j] = temp; - df[j] = (fh - fold) / h; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/min/Golden.java b/common-tools/cnuphys/numRec/src/com/nr/min/Golden.java deleted file mode 100644 index 8050251b87..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/min/Golden.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.nr.min; - -import static java.lang.Math.*; -import com.nr.UniVarRealValueFun; - -/** - * Golden Section Search in One Dimension - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Golden extends Bracketmethod { - double xmin, fmin; - final double tol; - - public Golden() { - this(3.0e-8); - } - - public Golden(final double toll) { - tol = toll; - } - - public double minimize(final UniVarRealValueFun func) { - final double R = 0.61803399, C = 1.0 - R; - double x1, x2; - double x0 = ax; - double x3 = cx; - if (abs(cx - bx) > abs(bx - ax)) { - x1 = bx; - x2 = bx + C * (cx - bx); - } else { - x2 = bx; - x1 = bx - C * (bx - ax); - } - double f1 = func.funk(x1); - double f2 = func.funk(x2); - while (abs(x3 - x0) > tol * (abs(x1) + abs(x2))) { - if (f2 < f1) { - // shft3(x0,x1,x2,R*x2+C*x3); - double dum = R * x2 + C * x3; - x0 = x1; - x1 = x2; - x2 = dum; - // shft2(f1,f2,func.funk(x2)); - f1 = f2; - f2 = func.funk(x2); - } else { - // shft3(x3,x2,x1,R*x1+C*x0); - double dum = R * x1 + C * x0; - x3 = x2; - x2 = x1; - x1 = dum; - // shft2(f2,f1,func.funk(x1)); - f2 = f1; - f1 = func.funk(x1); - } - } - if (f1 < f2) { - xmin = x1; - fmin = f1; - } else { - xmin = x2; - fmin = f2; - } - return xmin; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/min/Linemethod.java b/common-tools/cnuphys/numRec/src/com/nr/min/Linemethod.java deleted file mode 100644 index e85d5f55ff..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/min/Linemethod.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.nr.min; - -import com.nr.RealValueFun; - -public class Linemethod { - public double[] p; - public double[] xi; - RealValueFun func; - int n; - - public Linemethod(final RealValueFun funcc) { - func = funcc; - } - - /** - * @return - */ - public double linmin() { - double ax, xx, xmin; - n = p.length; - F1dim f1dim = new F1dim(p, xi, func); - ax = 0.0; - xx = 1.0; - Brent brent = new Brent(); - brent.bracket(ax, xx, f1dim); - xmin = brent.minimize(f1dim); - for (int j = 0; j < n; j++) { - xi[j] *= xmin; - p[j] += xi[j]; - } - return brent.fmin; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/min/Powell.java b/common-tools/cnuphys/numRec/src/com/nr/min/Powell.java deleted file mode 100644 index bfcc072c33..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/min/Powell.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.nr.min; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import com.nr.RealValueFun; - -public class Powell extends Linemethod { - public int iter; - public double fret; - - /* - * using Linemethod::func; using Linemethod::linmin; using - * Linemethod::p; using Linemethod::xi; - */ - final double ftol; - - public Powell(final RealValueFun func) { - this(func, 3.0e-8); - } - - public Powell(final RealValueFun func, final double ftoll) { - super(func); - ftol = ftoll; - } - - public double[] minimize(final double[] pp) { - int n = pp.length; - double[][] ximat = new double[n][n]; - for (int i = 0; i < n; i++) - ximat[i][i] = 1.0; - return minimize(pp, ximat); - } - - public double[] minimize(final double[] pp, final double[][] ximat) { - final int ITMAX = 200; - final double TINY = 1.0e-25; - double fptt; - int n = pp.length; - p = buildVector(pp); - double[] pt = new double[n], ptt = new double[n]; - // xi = resize(xi,n); - xi = new double[n]; - fret = func.funk(p); - for (int j = 0; j < n; j++) - pt[j] = p[j]; - for (iter = 0;; ++iter) { - double fp = fret; - int ibig = 0; - double del = 0.0; - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) - xi[j] = ximat[j][i]; - fptt = fret; - fret = linmin(); - if (fptt - fret > del) { - del = fptt - fret; - ibig = i + 1; - } - } - if (2.0 * (fp - fret) <= ftol * (abs(fp) + abs(fret)) + TINY) { - return p; - } - if (iter == ITMAX) - throw new IllegalArgumentException( - "powell exceeding maximum iterations."); - for (int j = 0; j < n; j++) { - ptt[j] = 2.0 * p[j] - pt[j]; - xi[j] = p[j] - pt[j]; - pt[j] = p[j]; - } - fptt = func.funk(ptt); - if (fptt < fp) { - double t = 2.0 * (fp - 2.0 * fret + fptt) - * SQR(fp - fret - del) - del * SQR(fp - fptt); - if (t < 0.0) { - fret = linmin(); - for (int j = 0; j < n; j++) { - ximat[j][ibig - 1] = ximat[j][n - 1]; - ximat[j][n - 1] = xi[j]; - } - } - } - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/min/QuasiNewton.java b/common-tools/cnuphys/numRec/src/com/nr/min/QuasiNewton.java deleted file mode 100644 index 4206e75802..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/min/QuasiNewton.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.nr.min; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; -import static com.nr.root.Roots.*; - -import org.netlib.util.*; - -import com.nr.RealValueFunWithDiff; - -public class QuasiNewton { - /** - * Quasi-Newton or Variable Metric Methods in Multidimensions - * - * @param p - * @param gtol - * @param iter - * @param fret - * @param funcd - */ - public static void dfpmin(final double[] p, final double gtol, - final intW iter, final doubleW fret, - final RealValueFunWithDiff funcd) { - final int ITMAX = 200; - final double EPS = DBL_EPSILON; - final double TOLX = 4 * EPS, STPMX = 100.0; - booleanW check = new booleanW(false); - double den, fac, fad, fae, fp, stpmax, sum = 0.0, sumdg, sumxi, temp, test; - int n = p.length; - double[] dg = new double[n]; - double[] g = new double[n]; - double[] hdg = new double[n]; - double[] pnew = new double[n]; - double[] xi = new double[n]; - double[][] hessin = new double[n][n]; - fp = funcd.funk(p); - funcd.df(p, g); - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) - hessin[i][j] = 0.0; - hessin[i][i] = 1.0; - xi[i] = -g[i]; - sum += p[i] * p[i]; - } - stpmax = STPMX * max(sqrt(sum), n); - for (int its = 0; its < ITMAX; its++) { - iter.val = its; - lnsrch(p, fp, g, xi, pnew, fret, stpmax, check, funcd); - fp = fret.val; - for (int i = 0; i < n; i++) { - xi[i] = pnew[i] - p[i]; - p[i] = pnew[i]; - } - test = 0.0; - for (int i = 0; i < n; i++) { - temp = abs(xi[i]) / max(abs(p[i]), 1.0); - if (temp > test) - test = temp; - } - if (test < TOLX) - return; - for (int i = 0; i < n; i++) - dg[i] = g[i]; - funcd.df(p, g); - test = 0.0; - den = max(abs(fret.val), 1.0); - for (int i = 0; i < n; i++) { - temp = abs(g[i]) * max(abs(p[i]), 1.0) / den; - if (temp > test) - test = temp; - } - if (test < gtol) - return; - for (int i = 0; i < n; i++) - dg[i] = g[i] - dg[i]; - for (int i = 0; i < n; i++) { - hdg[i] = 0.0; - for (int j = 0; j < n; j++) - hdg[i] += hessin[i][j] * dg[j]; - } - fac = fae = sumdg = sumxi = 0.0; - for (int i = 0; i < n; i++) { - fac += dg[i] * xi[i]; - fae += dg[i] * hdg[i]; - sumdg += SQR(dg[i]); - sumxi += SQR(xi[i]); - } - if (fac > sqrt(EPS * sumdg * sumxi)) { - fac = 1.0 / fac; - fad = 1.0 / fae; - for (int i = 0; i < n; i++) - dg[i] = fac * xi[i] - fad * hdg[i]; - for (int i = 0; i < n; i++) { - for (int j = i; j < n; j++) { - hessin[i][j] += fac * xi[i] * xi[j] - fad * hdg[i] - * hdg[j] + fae * dg[i] * dg[j]; - hessin[j][i] = hessin[i][j]; - } - } - } - for (int i = 0; i < n; i++) { - xi[i] = 0.0; - for (int j = 0; j < n; j++) - xi[i] -= hessin[i][j] * g[j]; - } - } - throw new IllegalArgumentException("too many iterations in dfpmin"); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/min/StringAlign.java b/common-tools/cnuphys/numRec/src/com/nr/min/StringAlign.java deleted file mode 100644 index 14e4921856..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/min/StringAlign.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.nr.min; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -public class StringAlign { - private StringAlign() { - } - - /** - * Given null terminated input strings ain and bin, and given penalties - * mispen, gappen, and skwpen, respectively, for mismatches, interior gaps, - * and gaps before/after either string, set null terminated output strings - * aout, bout, and summary as the aligned versions of the input strings, and - * a summary string. User must supply storage for the output strings of size - * equal to the sum of the two input strings. - * - * @param ain - * @param bin - * @param mispen - * @param gappen - * @param skwpen - * @param aout - * @param bout - * @param summary - */ - public static void stringalign(final char[] ain, final char[] bin, - final double mispen, final double gappen, final double skwpen, - final char[] aout, final char[] bout, final char[] summary) { - int i, j, k; - double dn, rt, dg; - int ia = ain.length, ib = bin.length; - double[][] cost = new double[ia + 1][ib + 1]; - cost[0][0] = 0.; - for (i = 1; i <= ia; i++) - cost[i][0] = cost[i - 1][0] + skwpen; - for (i = 1; i <= ib; i++) - cost[0][i] = cost[0][i - 1] + skwpen; - for (i = 1; i <= ia; i++) - for (j = 1; j <= ib; j++) { - dn = cost[i - 1][j] + ((j == ib) ? skwpen : gappen); - rt = cost[i][j - 1] + ((i == ia) ? skwpen : gappen); - dg = cost[i - 1][j - 1] - + ((ain[i - 1] == bin[j - 1]) ? -1. : mispen); - cost[i][j] = min(min(dn, rt), dg); - } - i = ia; - j = ib; - k = 0; - while (i > 0 || j > 0) { - dn = rt = dg = 9.99e99; - if (i > 0) - dn = cost[i - 1][j] + ((j == ib) ? skwpen : gappen); - if (j > 0) - rt = cost[i][j - 1] + ((i == ia) ? skwpen : gappen); - if (i > 0 && j > 0) - dg = cost[i - 1][j - 1] - + ((ain[i - 1] == bin[j - 1]) ? -1. : mispen); - if (dg <= min(dn, rt)) { - aout[k] = ain[i - 1]; - bout[k] = bin[j - 1]; - summary[k++] = ((ain[i - 1] == bin[j - 1]) ? '=' : '!'); - i--; - j--; - } else if (dn < rt) { - aout[k] = ain[i - 1]; - bout[k] = ' '; - summary[k++] = ' '; - i--; - } else { - aout[k] = ' '; - bout[k] = bin[j - 1]; - summary[k++] = ' '; - j--; - } - } - for (i = 0; i < k / 2; i++) { - swap(aout, i, k - 1 - i); - swap(bout, i, k - 1 - i); - swap(summary, i, k - 1 - i); - } - aout[k] = bout[k] = summary[k] = 0; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/model/FGauss.java b/common-tools/cnuphys/numRec/src/com/nr/model/FGauss.java deleted file mode 100644 index 99b69cd649..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/model/FGauss.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.nr.model; - -import static com.nr.NRUtil.SQR; -import static java.lang.Math.exp; - -import org.netlib.util.doubleW; - -public class FGauss implements MultiFuncd { - - @Override - public void funk(final double x, final double[] a, final doubleW y, - final double[] dyda) { - int i, na = a.length; - double fac, ex, arg; - y.val = 0.; - for (i = 0; i < na - 1; i += 3) { - arg = (x - a[i + 1]) / a[i + 2]; - ex = exp(-SQR(arg)); - fac = a[i] * ex * 2. * arg; - y.val += a[i] * ex; - dyda[i] = ex; - dyda[i + 1] = fac / a[i + 2]; - dyda[i + 2] = fac * arg / a[i + 2]; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/model/Fitab.java b/common-tools/cnuphys/numRec/src/com/nr/model/Fitab.java deleted file mode 100644 index 5791df51bc..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/model/Fitab.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.nr.model; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import com.nr.sf.Gamma; - -/** - * Fitting Data to a Straight Line Copyright (C) Numerical Recipes Software - * 1986-2007 Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Fitab { - int ndata; - public double a, b, siga, sigb, chi2, q, sigdat; - public double[] x, y, sig; - - public Fitab(final double[] xx, final double[] yy, final double[] ssig) { - ndata = xx.length; - x = xx; - y = yy; - sig = ssig; - chi2 = 0.; - q = 1.0; - sigdat = 0.; - - Gamma gam = new Gamma(); - int i; - double ss = 0., sx = 0., sy = 0., st2 = 0., t, wt, sxoss; - b = 0.0; - for (i = 0; i < ndata; i++) { - wt = 1.0 / SQR(sig[i]); - ss += wt; - sx += x[i] * wt; - sy += y[i] * wt; - } - sxoss = sx / ss; - for (i = 0; i < ndata; i++) { - t = (x[i] - sxoss) / sig[i]; - st2 += t * t; - b += t * y[i] / sig[i]; - } - b /= st2; - a = (sy - sx * b) / ss; - siga = sqrt((1.0 + sx * sx / (ss * st2)) / ss); - sigb = sqrt(1.0 / st2); - for (i = 0; i < ndata; i++) - chi2 += SQR((y[i] - a - b * x[i]) / sig[i]); - if (ndata > 2) - q = gam.gammq(0.5 * (ndata - 2), 0.5 * chi2); - } - - public Fitab(final double[] xx, final double[] yy) { - ndata = xx.length; - x = xx; - y = yy; - sig = xx; - chi2 = 0.; - q = 1.0; - sigdat = 0.; - int i; - double ss, sx = 0., sy = 0., st2 = 0., t, sxoss; - b = 0.0; - for (i = 0; i < ndata; i++) { - sx += x[i]; - sy += y[i]; - } - ss = ndata; - sxoss = sx / ss; - for (i = 0; i < ndata; i++) { - t = x[i] - sxoss; - st2 += t * t; - b += t * y[i]; - } - b /= st2; - a = (sy - sx * b) / ss; - siga = sqrt((1.0 + sx * sx / (ss * st2)) / ss); - sigb = sqrt(1.0 / st2); - for (i = 0; i < ndata; i++) - chi2 += SQR(y[i] - a - b * x[i]); - if (ndata > 2) - sigdat = sqrt(chi2 / (ndata - 2)); - siga *= sigdat; - sigb *= sigdat; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/model/Fitexy.java b/common-tools/cnuphys/numRec/src/com/nr/model/Fitexy.java deleted file mode 100644 index 4271ddb0c3..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/model/Fitexy.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.nr.model; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -import org.netlib.util.doubleW; - -import com.nr.UniVarRealValueFun; -import com.nr.min.Brent; -import com.nr.root.Roots; -import com.nr.sf.Gamma; -import com.nr.stat.Moment; - -public class Fitexy { - public double a, b, siga, sigb, chi2, q; - int ndat; - public double[] xx, yy, sx, sy, ww; - public double aa, offs; - - public class Chixy implements UniVarRealValueFun { - // XXX reference use it, remove it. - // double[] xx,yy,sx,sy,ww; - - // double aa,offs; - - public Chixy() { - } - - @Override - public double funk(final double bang) { - return get(bang); - } - - public double get(final double bang) { - final double BIG = 1.0e30; - int j, nn = xx.length; - double ans, avex = 0.0, avey = 0.0, sumw = 0.0, b; - b = tan(bang); - for (j = 0; j < nn; j++) { - ww[j] = SQR(b * sx[j]) + SQR(sy[j]); - sumw += (ww[j] = (ww[j] < 1.0 / BIG ? BIG : 1.0 / ww[j])); - avex += ww[j] * xx[j]; - avey += ww[j] * yy[j]; - } - avex /= sumw; - avey /= sumw; - aa = avey - b * avex; - for (ans = -offs, j = 0; j < nn; j++) - ans += ww[j] * SQR(yy[j] - aa - b * xx[j]); - return ans; - } - } - - public Fitexy(final double[] x, final double[] y, final double[] sigx, - final double[] sigy) { - ndat = x.length; - xx = new double[ndat]; - yy = new double[ndat]; - sx = new double[ndat]; - sy = new double[ndat]; - ww = new double[ndat]; - - final double POTN = 1.571000, BIG = 1.0e30, ACC = 1.0e-6; - final double PI = 3.141592653589793238; - Gamma gam = new Gamma(); - Brent brent = new Brent(ACC); - Chixy chixy = new Chixy(); - int j; - double amx, amn, scale, bmn, bmx, d1, d2, r2; - double[] ang = new double[7]; - double[] ch = new double[7]; - doubleW varx = new doubleW(0); - doubleW vary = new doubleW(0); - doubleW dum1 = new doubleW(0); - - Moment.avevar(x, dum1, varx); - Moment.avevar(y, dum1, vary); - scale = sqrt(varx.val / vary.val); - for (j = 0; j < ndat; j++) { - xx[j] = x[j]; - yy[j] = y[j] * scale; - sx[j] = sigx[j]; - sy[j] = sigy[j] * scale; - ww[j] = sqrt(SQR(sx[j]) + SQR(sy[j])); - } - Fitab fit = new Fitab(xx, yy, ww); - b = fit.b; - offs = ang[0] = 0.0; - ang[1] = atan(b); - ang[3] = 0.0; - ang[4] = ang[1]; - ang[5] = POTN; - for (j = 3; j < 6; j++) - ch[j] = chixy.get(ang[j]); - brent.bracket(ang[0], ang[1], chixy); - ang[0] = brent.ax; - ang[1] = brent.bx; - ang[2] = brent.cx; - ch[0] = brent.fa; - ch[1] = brent.fb; - ch[2] = brent.fc; - b = brent.minimize(chixy); - chi2 = chixy.get(b); - a = aa; - q = gam.gammq(0.5 * (ndat - 2), chi2 * 0.5); - r2 = 0.0; - for (j = 0; j < ndat; j++) - r2 += ww[j]; - r2 = 1.0 / r2; - bmx = bmn = BIG; - offs = chi2 + 1.0; - for (j = 0; j < 6; j++) { - if (ch[j] > offs) { - d1 = abs(ang[j] - b); - while (d1 >= PI) - d1 -= PI; - d2 = PI - d1; - if (ang[j] < b) { - // SWAP(d1,d2); - double swap = d1; - d1 = d2; - d2 = swap; - } - if (d1 < bmx) - bmx = d1; - if (d2 < bmn) - bmn = d2; - } - } - if (bmx < BIG) { - bmx = Roots.zbrent(chixy, b, b + bmx, ACC) - b; - amx = aa - a; - bmn = Roots.zbrent(chixy, b, b - bmn, ACC) - b; - amn = aa - a; - sigb = sqrt(0.5 * (bmx * bmx + bmn * bmn)) / (scale * SQR(cos(b))); - siga = sqrt(0.5 * (amx * amx + amn * amn) + r2) / scale; - } else - sigb = siga = BIG; - a /= scale; - b = tan(b) / scale; - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/model/Fitlin.java b/common-tools/cnuphys/numRec/src/com/nr/model/Fitlin.java deleted file mode 100644 index 1e0456cf21..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/model/Fitlin.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.nr.model; - -import static com.nr.NRUtil.*; -import static com.nr.la.GaussJordan.*; -import com.nr.UniVarRealMultiValueFun; - -/** - * General linear fit Copyright (C) Numerical Recipes Software 1986-2007 Java - * translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Fitlin { - int ndat, ma; - public double[] x, y, sig; - UniVarRealMultiValueFun funcs; - public boolean[] ia; - - public double[] a; - public double[][] covar; - public double chisq; - - public Fitlin(final double[] xx, final double[] yy, final double[] ssig, - final UniVarRealMultiValueFun funcs) { - ndat = xx.length; - x = xx; - y = yy; - sig = ssig; - this.funcs = funcs; - ma = funcs.funk(x[0]).length; - a = new double[ma]; - covar = new double[ma][ma]; - ia = new boolean[ma]; - - for (int i = 0; i < ma; i++) - ia[i] = true; - } - - public void hold(final int i, final double val) { - ia[i] = false; - a[i] = val; - } - - public void free(final int i) { - ia[i] = true; - } - - public void fit() { - int i, j, k, l, m, mfit = 0; - double ym, wt, sum, sig2i; - double[] afunc = new double[ma]; - for (j = 0; j < ma; j++) - if (ia[j]) - mfit++; - if (mfit == 0) - throw new IllegalArgumentException( - "lfit: no parameters to be fitted"); - double[][] temp = new double[mfit][mfit], beta = new double[mfit][1]; - for (i = 0; i < ndat; i++) { - afunc = funcs.funk(x[i]); - ym = y[i]; - if (mfit < ma) { - for (j = 0; j < ma; j++) - if (!ia[j]) - ym -= a[j] * afunc[j]; - } - sig2i = 1.0 / SQR(sig[i]); - for (j = 0, l = 0; l < ma; l++) { - if (ia[l]) { - wt = afunc[l] * sig2i; - for (k = 0, m = 0; m <= l; m++) - if (ia[m]) - temp[j][k++] += wt * afunc[m]; - beta[j++][0] += ym * wt; - } - } - } - for (j = 1; j < mfit; j++) - for (k = 0; k < j; k++) - temp[k][j] = temp[j][k]; - gaussj(temp, beta); - for (j = 0, l = 0; l < ma; l++) - if (ia[l]) - a[l] = beta[j++][0]; - chisq = 0.0; - for (i = 0; i < ndat; i++) { - afunc = funcs.funk(x[i]); - sum = 0.0; - for (j = 0; j < ma; j++) - sum += a[j] * afunc[j]; - chisq += SQR((y[i] - sum) / sig[i]); - } - for (j = 0; j < mfit; j++) - for (k = 0; k < mfit; k++) - covar[j][k] = temp[j][k]; - for (i = mfit; i < ma; i++) - for (j = 0; j < i + 1; j++) - covar[i][j] = covar[j][i] = 0.0; - k = mfit - 1; - for (j = ma - 1; j >= 0; j--) { - if (ia[j]) { - for (i = 0; i < ma; i++) { - // SWAP(covar[i][k],covar[i][j]); - double swap = covar[i][k]; - covar[i][k] = covar[i][j]; - covar[i][j] = swap; - } - for (i = 0; i < ma; i++) { - // SWAP(covar[k][i],covar[j][i]); - double swap = covar[k][i]; - covar[k][i] = covar[j][i]; - covar[j][i] = swap; - } - k--; - } - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/model/Fitmed.java b/common-tools/cnuphys/numRec/src/com/nr/model/Fitmed.java deleted file mode 100644 index 0bb047fa9f..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/model/Fitmed.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.nr.model; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import static com.nr.sort.Sorter.*; - -/** - * fit a line minimizing absolute deviation - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Fitmed { - int ndata; - public double a, b, abdev; - double[] x, y; - - public Fitmed(final double[] xx, final double[] yy) { - ndata = xx.length; - x = xx; - y = yy; - - int j; - double b1, b2, del, f, f1, f2, sigb, temp; - double sx = 0.0, sy = 0.0, sxy = 0.0, sxx = 0.0, chisq = 0.0; - for (j = 0; j < ndata; j++) { - sx += x[j]; - sy += y[j]; - sxy += x[j] * y[j]; - sxx += SQR(x[j]); - } - del = ndata * sxx - sx * sx; - a = (sxx * sy - sx * sxy) / del; - b = (ndata * sxy - sx * sy) / del; - for (j = 0; j < ndata; j++) { - temp = y[j] - (a + b * x[j]); - chisq += (temp * temp); - } - sigb = sqrt(chisq / del); - b1 = b; - f1 = rofunc(b1); - if (sigb > 0.0) { - b2 = b + SIGN(3.0 * sigb, f1); - f2 = rofunc(b2); - if (b2 == b1) { - abdev /= ndata; - return; - } - while (f1 * f2 > 0.0) { - b = b2 + 1.6 * (b2 - b1); - b1 = b2; - f1 = f2; - b2 = b; - f2 = rofunc(b2); - } - sigb = 0.01 * sigb; - while (abs(b2 - b1) > sigb) { - b = b1 + 0.5 * (b2 - b1); - if (b == b1 || b == b2) - break; - f = rofunc(b); - if (f * f1 >= 0.0) { - f1 = f; - b1 = b; - } else { - f2 = f; - b2 = b; - } - } - } - abdev /= ndata; - } - - public double rofunc(final double b) { - final double EPS = DBL_EPSILON; - int j; - double d, sum = 0.0; - double[] arr = new double[ndata]; - for (j = 0; j < ndata; j++) - arr[j] = y[j] - b * x[j]; - if ((ndata & 1) == 1) { - a = select((ndata - 1) >> 1, arr); - } else { - j = ndata >> 1; - a = 0.5 * (select(j - 1, arr) + select(j, arr)); - } - abdev = 0.0; - for (j = 0; j < ndata; j++) { - d = y[j] - (b * x[j] + a); - abdev += abs(d); - if (y[j] != 0.0) - d /= abs(y[j]); - if (abs(d) > EPS) - sum += (d >= 0.0 ? x[j] : -x[j]); - } - return sum; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/model/Fitmrq.java b/common-tools/cnuphys/numRec/src/com/nr/model/Fitmrq.java deleted file mode 100644 index 53c1882d27..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/model/Fitmrq.java +++ /dev/null @@ -1,179 +0,0 @@ -package com.nr.model; - -import static com.nr.NRUtil.*; -import static com.nr.la.GaussJordan.*; -import static java.lang.Math.*; - -import org.netlib.util.doubleW; - -/** - * Levenberg-Marquardt nonlinear fitting Copyright (C) Numerical Recipes - * Software 1986-2007 Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Fitmrq { - static final int NDONE = 4, ITMAX = 1000; - int ndat, ma, mfit; - double[] x, y, sig; - final double tol; - MultiFuncd funcs; - public boolean[] ia; - public double[] a; - public double[][] covar; - public double[][] alpha; - public double chisq; - - public Fitmrq(final double[] xx, final double[] yy, final double[] ssig, - final double[] aa, final MultiFuncd funks) { - this(xx, yy, ssig, aa, funks, 1.e-3); - } - - public Fitmrq(final double[] xx, final double[] yy, final double[] ssig, - final double[] aa, final MultiFuncd funks, final double TOL) { - ndat = xx.length; - ma = aa.length; - x = xx; - y = yy; - sig = ssig; - tol = TOL; - funcs = funks; - ia = new boolean[ma]; - alpha = new double[ma][ma]; - a = buildVector(aa); - covar = new double[ma][ma]; - for (int i = 0; i < ma; i++) - ia[i] = true; - } - - public void hold(final int i, final double val) { - ia[i] = false; - a[i] = val; - } - - public void free(final int i) { - ia[i] = true; - } - - public void fit() { - int j, k, l, iter, done = 0; - double alamda = .001, ochisq; - double[] atry = new double[ma]; - double[] beta = new double[ma]; - double[] da = new double[ma]; - ; - mfit = 0; - for (j = 0; j < ma; j++) - if (ia[j]) - mfit++; - double[][] oneda = new double[mfit][1], temp = new double[mfit][mfit]; - mrqcof(a, alpha, beta); - for (j = 0; j < ma; j++) - atry[j] = a[j]; - ochisq = chisq; - for (iter = 0; iter < ITMAX; iter++) { - if (done == NDONE) - alamda = 0.; - for (j = 0; j < mfit; j++) { - for (k = 0; k < mfit; k++) - covar[j][k] = alpha[j][k]; - covar[j][j] = alpha[j][j] * (1.0 + alamda); - for (k = 0; k < mfit; k++) - temp[j][k] = covar[j][k]; - oneda[j][0] = beta[j]; - } - gaussj(temp, oneda); - for (j = 0; j < mfit; j++) { - for (k = 0; k < mfit; k++) - covar[j][k] = temp[j][k]; - da[j] = oneda[j][0]; - } - if (done == NDONE) { - covsrt(covar); - covsrt(alpha); - return; - } - for (j = 0, l = 0; l < ma; l++) - if (ia[l]) - atry[l] = a[l] + da[j++]; - mrqcof(atry, covar, da); - if (abs(chisq - ochisq) < max(tol, tol * chisq)) - done++; - if (chisq < ochisq) { - alamda *= 0.1; - ochisq = chisq; - for (j = 0; j < mfit; j++) { - for (k = 0; k < mfit; k++) - alpha[j][k] = covar[j][k]; - beta[j] = da[j]; - } - for (l = 0; l < ma; l++) - a[l] = atry[l]; - } else { - alamda *= 10.0; - chisq = ochisq; - } - } - throw new IllegalArgumentException("Fitmrq too many iterations"); - } - - public void mrqcof(final double[] a, final double[][] alpha, - final double[] beta) { - int i, j, k, l, m; - double ymod, wt, sig2i, dy; - doubleW ymodW = new doubleW(0); - double[] dyda = new double[ma]; - for (j = 0; j < mfit; j++) { - for (k = 0; k <= j; k++) - alpha[j][k] = 0.0; - beta[j] = 0.; - } - chisq = 0.; - for (i = 0; i < ndat; i++) { - funcs.funk(x[i], a, ymodW, dyda); - ymod = ymodW.val; - sig2i = 1.0 / (sig[i] * sig[i]); - dy = y[i] - ymod; - for (j = 0, l = 0; l < ma; l++) { - if (ia[l]) { - wt = dyda[l] * sig2i; - for (k = 0, m = 0; m < l + 1; m++) - if (ia[m]) - alpha[j][k++] += wt * dyda[m]; - beta[j++] += dy * wt; - } - } - chisq += dy * dy * sig2i; - } - for (j = 1; j < mfit; j++) - for (k = 0; k < j; k++) - alpha[k][j] = alpha[j][k]; - } - - public void covsrt(final double[][] covar) { - int i, j, k; - for (i = mfit; i < ma; i++) - for (j = 0; j < i + 1; j++) - covar[i][j] = covar[j][i] = 0.0; - k = mfit - 1; - for (j = ma - 1; j >= 0; j--) { - if (ia[j]) { - for (i = 0; i < ma; i++) { - // SWAP(covar[i][k],covar[i][j]); - double swap = covar[i][k]; - covar[i][k] = covar[i][j]; - covar[i][j] = swap; - } - for (i = 0; i < ma; i++) { - // SWAP(covar[k][i],covar[j][i]); - double swap = covar[k][i]; - covar[k][i] = covar[j][i]; - covar[j][i] = swap; - } - k--; - } - } - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/model/Fitsvd.java b/common-tools/cnuphys/numRec/src/com/nr/model/Fitsvd.java deleted file mode 100644 index aae79441c9..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/model/Fitsvd.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.nr.model; - -import static com.nr.NRUtil.*; -import com.nr.RealMultiValueFun; -import com.nr.UniVarRealMultiValueFun; -import com.nr.la.SVD; - -/** - * general linear fit using SVD - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Fitsvd { - int ndat, ma; - final double tol; - // double[] *x,&y,&sig; - double[] x, y, sig; - UniVarRealMultiValueFun funcs; - public double[] a; - public double[][] covar; - public double chisq; - - double[][] xmd; - RealMultiValueFun funcsmd; - - public Fitsvd(final double[] xx, final double[] yy, final double[] ssig, - final UniVarRealMultiValueFun funks) { - this(xx, yy, ssig, funks, 1.e-12); - } - - public Fitsvd(final double[] xx, final double[] yy, final double[] ssig, - final UniVarRealMultiValueFun funks, final double TOL) { - ndat = yy.length; - x = xx; - xmd = null; - y = yy; - sig = ssig; - funcs = funks; - tol = TOL; - } - - public void fit() { - int i, j, k; - double tmp, thresh, sum; - if (x != null) - ma = funcs.funk(x[0]).length; - else - ma = funcsmd.funk(row(xmd, 0)).length; - a = new double[ma]; - covar = new double[ma][ma]; - double[][] aa = new double[ndat][ma]; - double[] b = new double[ndat], afunc = new double[ma]; - for (i = 0; i < ndat; i++) { - if (x != null) - afunc = funcs.funk(x[i]); - else - afunc = funcsmd.funk(row(xmd, i)); - tmp = 1.0 / sig[i]; - for (j = 0; j < ma; j++) - aa[i][j] = afunc[j] * tmp; - b[i] = y[i] * tmp; - } - SVD svd = new SVD(aa); - thresh = (tol > 0. ? tol * svd.w[0] : -1.); - svd.solve(b, a, thresh); - chisq = 0.0; - for (i = 0; i < ndat; i++) { - sum = 0.; - for (j = 0; j < ma; j++) - sum += aa[i][j] * a[j]; - chisq += SQR(sum - b[i]); - } - for (i = 0; i < ma; i++) { - for (j = 0; j < i + 1; j++) { - sum = 0.0; - for (k = 0; k < ma; k++) - if (svd.w[k] > svd.tsh) - sum += svd.v[i][k] * svd.v[j][k] / SQR(svd.w[k]); - covar[j][i] = covar[i][j] = sum; - } - } - } - - public Fitsvd(final double[][] xx, final double[] yy, final double[] ssig, - final RealMultiValueFun funks) { - this(xx, yy, ssig, funks, 1.e-12); - } - - public Fitsvd(final double[][] xx, final double[] yy, final double[] ssig, - final RealMultiValueFun funks, final double TOL) { - ndat = yy.length; - x = null; - xmd = xx; - y = yy; - sig = ssig; - funcsmd = funks; - tol = TOL; - } - - public double[] row(final double[][] a, final int i) { - int j, n = a[0].length; - double[] ans = new double[n]; - for (j = 0; j < n; j++) - ans[j] = a[i][j]; - return ans; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/model/MultiFuncd.java b/common-tools/cnuphys/numRec/src/com/nr/model/MultiFuncd.java deleted file mode 100644 index 003965c036..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/model/MultiFuncd.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.nr.model; - -import org.netlib.util.doubleW; - -public interface MultiFuncd { - public void funk(final double x, final double[] a, final doubleW y, - final double[] dyda); -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/model/Plog.java b/common-tools/cnuphys/numRec/src/com/nr/model/Plog.java deleted file mode 100644 index 2108481e0e..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/model/Plog.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.nr.model; - -import static com.nr.sf.Gamma.*; -import static java.lang.Math.*; - -public class Plog { - double[] dat; - int ndat; - double[] stau, slogtau; - - public Plog(final double[] data) { - dat = data; - ndat = data.length; - stau = new double[ndat]; - slogtau = new double[ndat]; - int i; - stau[0] = slogtau[0] = 0.; - for (i = 1; i < ndat; i++) { - stau[i] = dat[i] - dat[0]; - slogtau[i] = slogtau[i - 1] + log(dat[i] - dat[i - 1]); - } - } - - public double get(final State s) { - int i, ilo, ihi, n1, n2; - double st1, st2, stl1, stl2, ans; - ilo = 0; - ihi = ndat - 1; - while (ihi - ilo > 1) { - i = (ihi + ilo) >> 1; - if (s.tc > dat[i]) - ilo = i; - else - ihi = i; - } - n1 = ihi; - n2 = ndat - 1 - ihi; - st1 = stau[ihi]; - st2 = stau[ndat - 1] - st1; - stl1 = slogtau[ihi]; - stl2 = slogtau[ndat - 1] - stl1; - ans = n1 * (s.k1 * log(s.lam1) - factln(s.k1 - 1)) + (s.k1 - 1) * stl1 - - s.lam1 * st1; - ans += n2 * (s.k2 * log(s.lam2) - factln(s.k2 - 1)) + (s.k2 - 1) * stl2 - - s.lam2 * st2; - return (s.plog = ans); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/model/Proposal.java b/common-tools/cnuphys/numRec/src/com/nr/model/Proposal.java deleted file mode 100644 index c7828f0a89..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/model/Proposal.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.nr.model; - -import static java.lang.Math.*; - -import org.netlib.util.doubleW; - -import com.nr.ran.Normaldev; - -public class Proposal { - Normaldev gau; - double logstep; - - public Proposal(final int ranseed, final double lstep) { - gau = new Normaldev(0., 1., ranseed); - logstep = lstep; - } - - public void get(final State s1, final State s2, final doubleW qratio) { - double r = gau.doub(); - if (r < 0.9) { - s2.lam1 = s1.lam1 * exp(logstep * gau.dev()); - s2.lam2 = s1.lam2 * exp(logstep * gau.dev()); - s2.tc = s1.tc * exp(logstep * gau.dev()); - s2.k1 = s1.k1; - s2.k2 = s1.k2; - qratio.val = (s2.lam1 / s1.lam1) * (s2.lam2 / s1.lam2) - * (s2.tc / s1.tc); - } else { - r = gau.doub(); - if (s1.k1 > 1) { - if (r < 0.5) - s2.k1 = s1.k1; - else if (r < 0.75) - s2.k1 = s1.k1 + 1; - else - s2.k1 = s1.k1 - 1; - } else { - if (r < 0.75) - s2.k1 = s1.k1; - else - s2.k1 = s1.k1 + 1; - } - s2.lam1 = s2.k1 * s1.lam1 / s1.k1; - r = gau.doub(); - if (s1.k2 > 1) { - if (r < 0.5) - s2.k2 = s1.k2; - else if (r < 0.75) - s2.k2 = s1.k2 + 1; - else - s2.k2 = s1.k2 - 1; - } else { - if (r < 0.75) - s2.k2 = s1.k2; - else - s2.k2 = s1.k2 + 1; - } - s2.lam2 = s2.k2 * s1.lam2 / s1.k2; - s2.tc = s1.tc; - qratio.val = 1.; - } - } - - public static double mcmcstep(final int m, final State s, final Plog plog, - final Proposal propose) { - State sprop = new State(); - double alph, ran; - doubleW qratio = new doubleW(0); - int accept = 0; - plog.get(s); - for (int i = 0; i < m; i++) { - propose.get(s, sprop, qratio); - alph = min(1., qratio.val * exp(plog.get(sprop) - s.plog)); - ran = propose.gau.doub(); - if (ran < alph) { - State.copy(sprop, s); - plog.get(s); - accept++; - } - } - return accept / (double) (m); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/model/State.java b/common-tools/cnuphys/numRec/src/com/nr/model/State.java deleted file mode 100644 index c1ddc828db..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/model/State.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.nr.model; - -public class State { - public double lam1, lam2; - public double tc; - public int k1, k2; - public double plog; - - public State(final double la1, final double la2, final double t, - final int kk1, final int kk2) { - lam1 = la1; - lam2 = la2; - tc = t; - k1 = kk1; - k2 = kk2; - } - - public State() { - - } - - public static void copy(final State from, final State to) { - to.lam1 = from.lam1; - to.lam2 = from.lam2; - to.tc = from.tc; - to.k1 = from.k1; - to.k2 = from.k2; - to.plog = from.plog; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ode/DerivativeInf.java b/common-tools/cnuphys/numRec/src/com/nr/ode/DerivativeInf.java deleted file mode 100644 index 96b5e0258d..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ode/DerivativeInf.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.nr.ode; - -public interface DerivativeInf { - public void derivs(final double x, double[] y, double[] dydx); - - public void jacobian(final double x, double[] y, double[] dfdx, - double[][] dfdy); -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ode/Hypderiv.java b/common-tools/cnuphys/numRec/src/com/nr/ode/Hypderiv.java deleted file mode 100644 index e6a9fd13d2..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ode/Hypderiv.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.nr.ode; - -import com.nr.Complex; - -public class Hypderiv implements DerivativeInf { - Complex a, b, c, z0, dz; - - public Hypderiv(final Complex aa, final Complex bb, final Complex cc, - final Complex z00, final Complex dzz) { - a = aa; - b = bb; - c = cc; - z0 = z00; - dz = dzz; - - } - - @Override - public void jacobian(final double x, final double[] y, final double[] dydx, - final double[][] dfdy) { - } - - @Override - public void derivs(final double s, final double[] yy, final double[] dyyds) { - get(s, yy, dyyds); - } - - public void get(final double s, final double[] yy, final double[] dyyds) { - Complex z; - Complex[] y = new Complex[2]; - Complex[] dyds = new Complex[2]; - - y[0] = new Complex(yy[0], yy[1]); - y[1] = new Complex(yy[2], yy[3]); - z = z0.add(dz.scale(s)); - dyds[0] = y[1].mul(dz); - // dyds[1]=(a*b*y[0]-(c-(a+b+1.0)*z)*y[1])*dz/(z*(1.0-z)); - - Complex aa = c.sub((a.add(b).add(new Complex(1, 0))).mul(z)); - Complex bb = a.mul(b).mul(y[0]).sub(aa.mul(y[1])); - dyds[1] = bb.mul(dz).div(z.mul(new Complex(1.0, 0).sub(z))); - - dyyds[0] = dyds[0].re(); - dyyds[1] = dyds[0].im(); - dyyds[2] = dyds[1].re(); - dyyds[3] = dyds[1].im(); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ode/Odeint.java b/common-tools/cnuphys/numRec/src/com/nr/ode/Odeint.java deleted file mode 100644 index 7af5835ec7..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ode/Odeint.java +++ /dev/null @@ -1,151 +0,0 @@ -package com.nr.ode; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -/** - * Driver for ODE solvers with adaptive stepsize control. The template parameter - * should be one of the derived classes of StepperBase defining a particular - * integration algorithm. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Odeint { - static final int MAXSTP = 50000; - double EPS; - int nok; - int nbad; - int nvar; - double x1, x2, hmin; - - /** - * true if dense output requested by out - * - */ - boolean dense; - double[] ystart; - Output out; - - /** - * Get the type of derivs from the stepper - */ - DerivativeInf derivs; - StepperBase s; - int nstp; - double h; - - /* - * XXX ref to StepperBase double[] y,dydx; double x; - */ - /** - * Constructor sets everything up. The routine integrates starting values - * ystart[0..nvar-1] from xx1 to xx2 with absolute tolerance atol and - * relative tolerance rtol. The quantity h1 should be set as a guessed first - * stepsize, hmin as the minimum allowed stepsize (can be zero). An Output - * object out should be input to control the saving of intermediate values. - * On output, nok and nbad are the number of good and bad (but retried and - * fixed) steps taken, and ystart is replaced by values at the end of the - * integration interval. derivs is the user-supplied routine (function or - * functor) for calculating the right-hand side derivative. - * - * @param ystartt - * @param xx1 - * @param xx2 - * @param atol - * @param rtol - * @param h1 - * @param hminn - * @param outt - * @param derivss - * @param s - */ - public Odeint(final double[] ystartt, final double xx1, final double xx2, - final double atol, final double rtol, final double h1, - final double hminn, final Output outt, final DerivativeInf derivss, - final StepperBase s) { - nvar = ystartt.length; - ystart = ystartt; - double[] y = new double[nvar]; - double[] dydx = new double[nvar]; - double x = xx1; - nok = 0; - nbad = 0; - x1 = xx1; - x2 = xx2; - hmin = hminn; - dense = outt.dense; - out = outt; - derivs = derivss; - - this.s = s; - s.setParam(y, dydx, x, atol, rtol, dense); - - EPS = DBL_EPSILON; - h = SIGN(h1, x2 - x1); - for (int i = 0; i < nvar; i++) - y[i] = ystart[i]; - out.init(s.neqn, x1, x2); - } - - public void integrate() { - derivs.derivs(s.x, s.y, s.dydx); - if (dense) - out.out(-1, s.x, s.y, s, h); - else - out.save(s.x, s.y); - for (nstp = 0; nstp < MAXSTP; nstp++) { - if ((s.x + h * 1.0001 - x2) * (x2 - x1) > 0.0) - h = x2 - s.x; - s.step(h, derivs); - if (s.hdid == h) - ++nok; - else - ++nbad; - if (dense) - out.out(nstp, s.x, s.y, s, s.hdid); - else - out.save(s.x, s.y); - if ((s.x - x2) * (x2 - x1) >= 0.0) { - for (int i = 0; i < nvar; i++) - ystart[i] = s.y[i]; - if (out.kmax > 0 - && abs(out.xsave[out.count - 1] - x2) > 100.0 * abs(x2) - * EPS) - out.save(s.x, s.y); - return; - } - if (abs(s.hnext) <= hmin) - throw new IllegalArgumentException( - "Step size too small in Odeint"); - h = s.hnext; - } - throw new IllegalArgumentException("Too many steps in routine Odeint"); - } - - public static void rk4(final double[] y, final double[] dydx, - final double x, final double h, final double[] yout, - final DerivativeInf derivs) { - int n = y.length; - double[] dym = new double[n], dyt = new double[n], yt = new double[n]; - double hh = h * 0.5; - double h6 = h / 6.0; - double xh = x + hh; - for (int i = 0; i < n; i++) - yt[i] = y[i] + hh * dydx[i]; - derivs.derivs(xh, yt, dyt); - for (int i = 0; i < n; i++) - yt[i] = y[i] + hh * dyt[i]; - derivs.derivs(xh, yt, dym); - for (int i = 0; i < n; i++) { - yt[i] = y[i] + h * dym[i]; - dym[i] += dyt[i]; - } - derivs.derivs(x + h, yt, dyt); - for (int i = 0; i < n; i++) - yout[i] = y[i] + h6 * (dydx[i] + dyt[i] + 2.0 * dym[i]); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ode/Output.java b/common-tools/cnuphys/numRec/src/com/nr/ode/Output.java deleted file mode 100644 index 4b443e1a11..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ode/Output.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.nr.ode; - -import static com.nr.NRUtil.*; - -/** - * Structure for output from ODE solver such as odeint. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Output { - public int kmax; - public int nvar; - public int nsave; - public boolean dense; - public int count; - public double x1, x2, xout, dxout; - public double[] xsave; - public double[][] ysave; - - public Output() { - kmax = -1; - dense = false; - count = 0; - } - - /** - * Constructor provides dense output at nsave equally spaced intervals. If - * nsave <= 0, output is saved only at the actual integration steps. - */ - public Output(final int nsavee) { - kmax = 500; - nsave = nsavee; - count = 0; - xsave = new double[kmax]; - dense = nsave > 0 ? true : false; - } - - /** - * Called by Odeint constructor, which passes neqn, the number of equations, - * xlo, the starting point of the integration, and xhi, the ending point. - * - * @param neqn - * @param xlo - * @param xhi - */ - public void init(final int neqn, final double xlo, final double xhi) { - nvar = neqn; - if (kmax == -1) - return; - ysave = new double[nvar][kmax]; - if (dense) { - x1 = xlo; - x2 = xhi; - xout = x1; - dxout = (x2 - x1) / nsave; - } - } - - public void resize() { - int kold = kmax; - kmax *= 2; - double[] tempvec = buildVector(xsave); - xsave = new double[kmax]; - for (int k = 0; k < kold; k++) - xsave[k] = tempvec[k]; - double[][] tempmat = buildMatrix(ysave); - ysave = new double[nvar][kmax]; - for (int i = 0; i < nvar; i++) - for (int k = 0; k < kold; k++) - ysave[i][k] = tempmat[i][k]; - } - - /** - * Invokes dense_out function of stepper routine to produce output at xout. - * Normally called by out rather than directly. Assumes that xout is between - * xold and xold+h, where the stepper must keep track of xold, the location - * of the previous step, and x=xold+h, the current step. - * - * @param s - * @param xout - * @param h - */ - public void save_dense(final StepperBase s, final double xout, - final double h) { - if (count == kmax) - resize(); - for (int i = 0; i < nvar; i++) - ysave[i][count] = s.dense_out(i, xout, h); - xsave[count++] = xout; - } - - public void save(final double x, final double[] y) { - if (kmax <= 0) - return; - if (count == kmax) - resize(); - for (int i = 0; i < nvar; i++) - ysave[i][count] = y[i]; - xsave[count++] = x; - } - - public void out(final int nstp, final double x, final double[] y, - final StepperBase s, final double h) { - if (!dense) - throw new IllegalArgumentException( - "dense output not set in Output!"); - if (nstp == -1) { - save(x, y); - xout += dxout; - } else { - while ((x - xout) * (x2 - x1) > 0.0) { - save_dense(s, xout, h); - xout += dxout; - } - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ode/StepperBS.java b/common-tools/cnuphys/numRec/src/com/nr/ode/StepperBS.java deleted file mode 100644 index 0b665604d2..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ode/StepperBS.java +++ /dev/null @@ -1,449 +0,0 @@ -package com.nr.ode; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import org.netlib.util.*; - -/** - * Bulirsch-Stoer stepper base class - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class StepperBS extends StepperBase { - static final int KMAXX = 8, IMAXX = KMAXX + 1; - int k_targ; - int[] nseq; - int[] cost; - double[][] table; - double[] dydxnew; - int mu; - double[][] coeff; - double[] errfac; - double[][] ysave; - double[][] fsave; - int[] ipoint; - double[] dens; - - public StepperBS() { - - } - - public StepperBS(final double[] yy, final double[] dydxx, final double xx, - final double atoll, final double rtoll, final boolean dense) { - setParam(yy, dydxx, xx, atoll, rtoll, dense); - } - - @Override - public void setParam(final double[] yy, final double[] dydxx, - final double xx, final double atoll, final double rtoll, - final boolean dense) { - super.setParam(yy, dydxx, xx, atoll, rtoll, dense); - nseq = new int[IMAXX]; - cost = new int[IMAXX]; - table = new double[KMAXX][n]; - dydxnew = new double[n]; - coeff = new double[IMAXX][IMAXX]; - errfac = new double[2 * IMAXX + 2]; - ysave = new double[IMAXX][n]; - fsave = new double[IMAXX * (2 * IMAXX + 1)][n]; - ipoint = new int[IMAXX + 1]; - dens = new double[(2 * IMAXX + 5) * n]; - - EPS = DBL_EPSILON; - if (dense) - for (int i = 0; i < IMAXX; i++) - nseq[i] = 4 * i + 2; - else - for (int i = 0; i < IMAXX; i++) - nseq[i] = 2 * (i + 1); - cost[0] = nseq[0] + 1; - for (int k = 0; k < KMAXX; k++) - cost[k + 1] = cost[k] + nseq[k + 1]; - hnext = -1.0e99; - double logfact = -log10(max(1.0e-12, rtol)) * 0.6 + 0.5; - k_targ = max(1, min(KMAXX - 1, (int) (logfact))); - for (int k = 0; k < IMAXX; k++) { - for (int l = 0; l < k; l++) { - double ratio = ((double) nseq[k]) / nseq[l]; - coeff[k][l] = 1.0 / (ratio * ratio - 1.0); - } - } - for (int i = 0; i < 2 * IMAXX + 1; i++) { - int ip5 = i + 5; - errfac[i] = 1.0 / (ip5 * ip5); - double e = 0.5 * sqrt((i + 1) / ip5); - for (int j = 0; j <= i; j++) { - errfac[i] *= e / (j + 1); - } - } - ipoint[0] = 0; - for (int i = 1; i <= IMAXX; i++) { - int njadd = 4 * i - 2; - if (nseq[i - 1] > njadd) - njadd++; - ipoint[i] = ipoint[i - 1] + njadd; - } - } - - @Override - public double dense_out(final int i, final double x, final double h) { - double theta = (x - xold) / h; - double theta1 = 1.0 - theta; - double yinterp = dens[i] - + theta - * (dens[n + i] + theta1 - * (dens[2 * n + i] * theta + dens[3 * n + i] * theta1)); - if (mu < 0) - return yinterp; - double theta05 = theta - 0.5; - double t4 = SQR(theta * theta1); - double c = dens[n * (mu + 4) + i]; - for (int j = mu; j > 0; j--) - c = dens[n * (j + 3) + i] + c * theta05 / j; - yinterp += t4 * c; - return yinterp; - } - - public void dense_interp(final int n, final double[] y, final int imit) { - double y0, y1, yp0, yp1, ydiff, aspl, bspl, ph0, ph1, ph2, ph3, fac1, fac2; - double[] a = new double[31]; - for (int i = 0; i < n; i++) { - y0 = y[i]; - y1 = y[2 * n + i]; - yp0 = y[n + i]; - yp1 = y[3 * n + i]; - ydiff = y1 - y0; - aspl = -yp1 + ydiff; - bspl = yp0 - ydiff; - y[n + i] = ydiff; - y[2 * n + i] = aspl; - y[3 * n + i] = bspl; - if (imit < 0) - continue; - ph0 = (y0 + y1) * 0.5 + 0.125 * (aspl + bspl); - ph1 = ydiff + (aspl - bspl) * 0.25; - ph2 = -(yp0 - yp1); - ph3 = 6.0 * (bspl - aspl); - if (imit >= 1) { - a[1] = 16.0 * (y[5 * n + i] - ph1); - if (imit >= 3) { - a[3] = 16.0 * (y[7 * n + i] - ph3 + 3 * a[1]); - for (int im = 5; im <= imit; im += 2) { - fac1 = im * (im - 1) / 2.0; - fac2 = fac1 * (im - 2) * (im - 3) * 2.0; - a[im] = 16.0 * (y[(im + 4) * n + i] + fac1 * a[im - 2] - fac2 - * a[im - 4]); - } - } - } - a[0] = (y[4 * n + i] - ph0) * 16.0; - if (imit >= 2) { - a[2] = (y[n * 6 + i] - ph2 + a[0]) * 16.0; - for (int im = 4; im <= imit; im += 2) { - fac1 = im * (im - 1) / 2.0; - fac2 = im * (im - 1) * (im - 2) * (im - 3); - a[im] = (y[n * (im + 4) + i] + a[im - 2] * fac1 - a[im - 4] - * fac2) * 16.0; - } - } - for (int im = 0; im <= imit; im++) - y[n * (im + 4) + i] = a[im]; - } - } - - public void dy(final double[] y, final double htot, final int k, - final double[] yend, final intW ipt, final DerivativeInf derivs) { - double[] ym = new double[n], yn = new double[n]; - int nstep = nseq[k]; - double h = htot / nstep; - for (int i = 0; i < n; i++) { - ym[i] = y[i]; - yn[i] = y[i] + h * dydx[i]; - } - double xnew = x + h; - derivs.derivs(xnew, yn, yend); - double h2 = 2.0 * h; - for (int nn = 1; nn < nstep; nn++) { - if (dense && nn == nstep / 2) { - for (int i = 0; i < n; i++) - ysave[k][i] = yn[i]; - } - if (dense && abs(nn - nstep / 2) <= 2 * k + 1) { - ipt.val++; - for (int i = 0; i < n; i++) - fsave[ipt.val][i] = yend[i]; - } - for (int i = 0; i < n; i++) { - double swap = ym[i] + h2 * yend[i]; - ym[i] = yn[i]; - yn[i] = swap; - } - xnew += h; - derivs.derivs(xnew, yn, yend); - } - if (dense && nstep / 2 <= 2 * k + 1) { - ipt.val++; - for (int i = 0; i < n; i++) - fsave[ipt.val][i] = yend[i]; - } - for (int i = 0; i < n; i++) - yend[i] = 0.5 * (ym[i] + yn[i] + h * yend[i]); - } - - public void polyextr(final int k, final double[][] table, - final double[] last) { - int l = last.length; - for (int j = k - 1; j > 0; j--) - for (int i = 0; i < l; i++) - table[j - 1][i] = table[j][i] + coeff[k][j] - * (table[j][i] - table[j - 1][i]); - for (int i = 0; i < l; i++) - last[i] = table[0][i] + coeff[k][0] * (table[0][i] - last[i]); - } - - public void prepare_dense(final double h, final double[] dydxnew, - final double[] ysav, final double[] scale, final int k, - final doubleW error) { - mu = 2 * k - 1; - for (int i = 0; i < n; i++) { - dens[i] = ysav[i]; - dens[n + i] = h * dydx[i]; - dens[2 * n + i] = y[i]; - dens[3 * n + i] = dydxnew[i] * h; - } - for (int j = 1; j <= k; j++) { - double dblenj = nseq[j]; - for (int l = j; l >= 1; l--) { - double factor = SQR(dblenj / nseq[l - 1]) - 1.0; - for (int i = 0; i < n; i++) - ysave[l - 1][i] = ysave[l][i] - + (ysave[l][i] - ysave[l - 1][i]) / factor; - } - } - for (int i = 0; i < n; i++) - dens[4 * n + i] = ysave[0][i]; - for (int kmi = 1; kmi <= mu; kmi++) { - int kbeg = (kmi - 1) / 2; - for (int kk = kbeg; kk <= k; kk++) { - double facnj = pow(nseq[kk] / 2.0, kmi - 1); - int ipt = ipoint[kk + 1] - 2 * kk + kmi - 3; - for (int i = 0; i < n; i++) - ysave[kk][i] = fsave[ipt][i] * facnj; - } - for (int j = kbeg + 1; j <= k; j++) { - double dblenj = nseq[j]; - for (int l = j; l >= kbeg + 1; l--) { - double factor = SQR(dblenj / nseq[l - 1]) - 1.0; - for (int i = 0; i < n; i++) - ysave[l - 1][i] = ysave[l][i] - + (ysave[l][i] - ysave[l - 1][i]) / factor; - } - } - for (int i = 0; i < n; i++) - dens[(kmi + 4) * n + i] = ysave[kbeg][i] * h; - if (kmi == mu) - continue; - for (int kk = kmi / 2; kk <= k; kk++) { - int lbeg = ipoint[kk + 1] - 1; - int lend = ipoint[kk] + kmi; - if (kmi == 1) - lend += 2; - for (int l = lbeg; l >= lend; l -= 2) - for (int i = 0; i < n; i++) - fsave[l][i] = fsave[l][i] - fsave[l - 2][i]; - if (kmi == 1) { - int l = lend - 2; - for (int i = 0; i < n; i++) - fsave[l][i] = fsave[l][i] - dydx[i]; - } - } - for (int kk = kmi / 2; kk <= k; kk++) { - int lbeg = ipoint[kk + 1] - 2; - int lend = ipoint[kk] + kmi + 1; - for (int l = lbeg; l >= lend; l -= 2) - for (int i = 0; i < n; i++) - fsave[l][i] = fsave[l][i] - fsave[l - 2][i]; - } - } - dense_interp(n, dens, mu); - error.val = 0.0; - if (mu >= 1) { - for (int i = 0; i < n; i++) - error.val += SQR(dens[(mu + 4) * n + i] / scale[i]); - error.val = sqrt(error.val / n) * errfac[mu - 1]; - } - } - - static boolean first_step = true, last_step = false; - static boolean forward, reject = false, prev_reject = false; - - @Override - public void step(final double htry, final DerivativeInf derivs) { - final double STEPFAC1 = 0.65, STEPFAC2 = 0.94, STEPFAC3 = 0.02, STEPFAC4 = 4.0, KFAC1 = 0.8, KFAC2 = 0.9; - int i, k = 0; - double fac, h, hnew, hopt_int = 0; - doubleW err = new doubleW(0); - boolean firstk; - double[] hopt = new double[IMAXX], work = new double[IMAXX]; - double[] ysav = new double[n], yseq = new double[n]; - double[] scale = new double[n]; // ymid =new double[n] - work[0] = 0; - h = htry; - forward = h > 0 ? true : false; - for (i = 0; i < n; i++) - ysav[i] = y[i]; - if (h != hnext && !first_step) { - last_step = true; - } - if (reject) { - prev_reject = true; - last_step = false; - } - reject = false; - firstk = true; - hnew = abs(h); - - while (true) { - // interp_error: - while (firstk || reject) { - h = forward ? hnew : -hnew; - firstk = false; - reject = false; - if (abs(h) <= abs(x) * EPS) - throw new IllegalArgumentException( - "step size underflow in StepperBS"); - intW ipt = new intW(-1); - for (k = 0; k <= k_targ + 1; k++) { - dy(ysav, h, k, yseq, ipt, derivs); - if (k == 0) - // y=yseq; XXX - System.arraycopy(yseq, 0, y, 0, y.length); - else - for (i = 0; i < n; i++) - table[k - 1][i] = yseq[i]; - if (k != 0) { - polyextr(k, table, y); - err.val = 0.0; - for (i = 0; i < n; i++) { - scale[i] = atol + rtol - * max(abs(ysav[i]), abs(y[i])); - err.val += SQR((y[i] - table[0][i]) / scale[i]); - } - err.val = sqrt(err.val / n); - double expo = 1.0 / (2 * k + 1); - double facmin = pow(STEPFAC3, expo); - if (err.val == 0.0) - fac = 1.0 / facmin; - else { - fac = STEPFAC2 / pow(err.val / STEPFAC1, expo); - fac = max(facmin / STEPFAC4, min(1.0 / facmin, fac)); - } - hopt[k] = abs(h * fac); - work[k] = cost[k] / hopt[k]; - if ((first_step || last_step) && err.val <= 1.0) - break; - if (k == k_targ - 1 && !prev_reject && !first_step - && !last_step) { - if (err.val <= 1.0) - break; - else if (err.val > SQR(nseq[k_targ] - * nseq[k_targ + 1] / (nseq[0] * nseq[0]))) { - reject = true; - k_targ = k; - if (k_targ > 1 && work[k - 1] < KFAC1 * work[k]) - k_targ--; - hnew = hopt[k_targ]; - break; - } - } - if (k == k_targ) { - if (err.val <= 1.0) - break; - else if (err.val > SQR(nseq[k + 1] / nseq[0])) { - reject = true; - if (k_targ > 1 && work[k - 1] < KFAC1 * work[k]) - k_targ--; - hnew = hopt[k_targ]; - break; - } - } - if (k == k_targ + 1) { - if (err.val > 1.0) { - reject = true; - if (k_targ > 1 - && work[k_targ - 1] < KFAC1 - * work[k_targ]) - k_targ--; - hnew = hopt[k_targ]; - } - break; - } - } - } - if (reject) - prev_reject = true; - } - derivs.derivs(x + h, y, dydxnew); - if (dense) { - prepare_dense(h, dydxnew, ysav, scale, k, err); - hopt_int = h / max(pow(err.val, 1.0 / (2 * k + 3)), 0.01); - if (err.val > 10.0) { - hnew = abs(hopt_int); - reject = true; - prev_reject = true; - // goto interp_error; - continue; - } - } - break; - } // while(true) - - System.arraycopy(dydxnew, 0, dydx, 0, dydxnew.length); - // dydx=dydxnew; XXX - xold = x; - x += h; - hdid = h; - first_step = false; - int kopt; - if (k == 1) - kopt = 2; - else if (k <= k_targ) { - kopt = k; - if (work[k - 1] < KFAC1 * work[k]) - kopt = k - 1; - else if (work[k] < KFAC2 * work[k - 1]) - kopt = min(k + 1, KMAXX - 1); - } else { - kopt = k - 1; - if (k > 2 && work[k - 2] < KFAC1 * work[k - 1]) - kopt = k - 2; - if (work[k] < KFAC2 * work[kopt]) - kopt = min(k, KMAXX - 1); - } - if (prev_reject) { - k_targ = min(kopt, k); - hnew = min(abs(h), hopt[k_targ]); - prev_reject = false; - } else { - if (kopt <= k) - hnew = hopt[kopt]; - else { - if (k < k_targ && work[k] < KFAC2 * work[k - 1]) - hnew = hopt[k] * cost[kopt + 1] / cost[k]; - else - hnew = hopt[k] * cost[kopt] / cost[k]; - } - k_targ = kopt; - } - if (dense) - hnew = min(hnew, abs(hopt_int)); - if (forward) - hnext = hnew; - else - hnext = -hnew; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ode/StepperBase.java b/common-tools/cnuphys/numRec/src/com/nr/ode/StepperBase.java deleted file mode 100644 index 96a11dbbb8..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ode/StepperBase.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.nr.ode; - -public abstract class StepperBase { - double x; - double xold; - double[] y, dydx; - double atol, rtol; - boolean dense; - double hdid; - double hnext; - double EPS; - int n, neqn; - double[] yout, yerr; - - public StepperBase() { - - } - - /** - * Input to the constructor are the dependent variable vector y[0..n-1] and - * its derivative dydx[0..n-1] at the starting value of the independent - * variable x. Also input are the absolute and relative tolerances, atol and - * rtol, and the boolean dense, which is true if dense output is required. - * - * @param yy - * @param dydxx - * @param xx - * @param atoll - * @param rtoll - * @param dense - */ - void setParam(final double[] yy, final double[] dydxx, final double xx, - final double atoll, // XXX reference xx. - final double rtoll, final boolean dense) { - x = xx; - y = yy; - dydx = dydxx; - atol = atoll; - rtol = rtoll; - this.dense = dense; - n = y.length; - neqn = n; - yout = new double[n]; - yerr = new double[n]; - } - - public StepperBase(final double[] yy, final double[] dydxx, - final double xx, final double atoll, // XXX reference xx. - final double rtoll, final boolean dense) { - setParam(yy, dydxx, xx, atoll, rtoll, dense); - } - - public abstract void step(final double htry, final DerivativeInf derivs); - - public abstract double dense_out(final int i, final double x, final double h); - - // public abstract void dy(double[] y, final double htot, final int k, - // double[] yend, intW ipt, DInf derivs); - - // public abstract void polyextr(final int k, double[][] table, double[] - // last); - - // public abstract void prepare_dense(final double h,double[] dydxnew, - // double[] ysav, double[] scale, final int k, doubleW error); - - // public abstract void dense_interp(final int n, double[] y, final int - // imit); -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ode/StepperDopr5.java b/common-tools/cnuphys/numRec/src/com/nr/ode/StepperDopr5.java deleted file mode 100644 index b2bff6d540..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ode/StepperDopr5.java +++ /dev/null @@ -1,203 +0,0 @@ -package com.nr.ode; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import org.netlib.util.*; - -/** - * Dormand-Prince fifth-order stepper - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class StepperDopr5 extends StepperBase { - double[] k2, k3, k4, k5, k6; - double[] rcont1, rcont2, rcont3, rcont4, rcont5; - double[] dydxnew; - Controller con = new Controller(); - - public static class Controller { - static final double beta = 0.0, alpha = 0.2 - beta * 0.75, safe = 0.9, - minscale = 0.2, maxscale = 10.0; - double hnext, errold; - boolean reject; - - public Controller() { - reject = false; - errold = 1.0e-4; - } - - public boolean success(final double err, final doubleW h) { - - double scale; - if (err <= 1.0) { - if (err == 0.0) - scale = maxscale; - else { - scale = safe * pow(err, -alpha) * pow(errold, beta); - if (scale < minscale) - scale = minscale; - if (scale > maxscale) - scale = maxscale; - } - if (reject) - hnext = h.val * min(scale, 1.0); - else - hnext = h.val * scale; - errold = max(err, 1.0e-4); - reject = false; - return true; - } else { - scale = max(safe * pow(err, -alpha), minscale); - h.val *= scale; - reject = true; - return false; - } - } - } - - public StepperDopr5() { - - } - - @Override - public void setParam(final double[] yy, final double[] dydxx, - final double xx, final double atoll, final double rtoll, - final boolean dense) { - super.setParam(yy, dydxx, xx, atoll, rtoll, dense); - k2 = new double[n]; - k3 = new double[n]; - k4 = new double[n]; - k5 = new double[n]; - k6 = new double[n]; - rcont1 = new double[n]; - rcont2 = new double[n]; - rcont3 = new double[n]; - rcont4 = new double[n]; - rcont5 = new double[n]; - dydxnew = new double[n]; - - EPS = DBL_EPSILON; - } - - public StepperDopr5(final double[] yy, final double[] dydxx, - final double xx, final double atoll, final double rtoll, - final boolean dense) { - setParam(yy, dydxx, xx, atoll, rtoll, dense); - } - - @Override - public double dense_out(final int i, final double x, final double h) { - double s = (x - xold) / h; - double s1 = 1.0 - s; - return rcont1[i] - + s - * (rcont2[i] + s1 - * (rcont3[i] + s * (rcont4[i] + s1 * rcont5[i]))); - } - - private static final double c2 = 0.2, c3 = 0.3, c4 = 0.8, c5 = 8.0 / 9.0, - a21 = 0.2, a31 = 3.0 / 40.0, a32 = 9.0 / 40.0, a41 = 44.0 / 45.0, - a42 = -56.0 / 15.0, a43 = 32.0 / 9.0, a51 = 19372.0 / 6561.0, - a52 = -25360.0 / 2187.0, a53 = 64448.0 / 6561.0, - a54 = -212.0 / 729.0, a61 = 9017.0 / 3168.0, a62 = -355.0 / 33.0, - a63 = 46732.0 / 5247.0, a64 = 49.0 / 176.0, - a65 = -5103.0 / 18656.0, a71 = 35.0 / 384.0, a73 = 500.0 / 1113.0, - a74 = 125.0 / 192.0, a75 = -2187.0 / 6784.0, a76 = 11.0 / 84.0, - e1 = 71.0 / 57600.0, e3 = -71.0 / 16695.0, e4 = 71.0 / 1920.0, - e5 = -17253.0 / 339200.0, e6 = 22.0 / 525.0, e7 = -1.0 / 40.0; - - public void dy(final double h, final DerivativeInf derivs) { - double[] ytemp = new double[n]; - int i; - for (i = 0; i < n; i++) - ytemp[i] = y[i] + h * a21 * dydx[i]; - derivs.derivs(x + c2 * h, ytemp, k2); - for (i = 0; i < n; i++) - ytemp[i] = y[i] + h * (a31 * dydx[i] + a32 * k2[i]); - derivs.derivs(x + c3 * h, ytemp, k3); - for (i = 0; i < n; i++) - ytemp[i] = y[i] + h * (a41 * dydx[i] + a42 * k2[i] + a43 * k3[i]); - derivs.derivs(x + c4 * h, ytemp, k4); - for (i = 0; i < n; i++) - ytemp[i] = y[i] + h - * (a51 * dydx[i] + a52 * k2[i] + a53 * k3[i] + a54 * k4[i]); - derivs.derivs(x + c5 * h, ytemp, k5); - for (i = 0; i < n; i++) - ytemp[i] = y[i] - + h - * (a61 * dydx[i] + a62 * k2[i] + a63 * k3[i] + a64 * k4[i] + a65 - * k5[i]); - double xph = x + h; - derivs.derivs(xph, ytemp, k6); - for (i = 0; i < n; i++) - yout[i] = y[i] - + h - * (a71 * dydx[i] + a73 * k3[i] + a74 * k4[i] + a75 * k5[i] + a76 - * k6[i]); - derivs.derivs(xph, yout, dydxnew); - for (i = 0; i < n; i++) { - yerr[i] = h - * (e1 * dydx[i] + e3 * k3[i] + e4 * k4[i] + e5 * k5[i] + e6 - * k6[i] + e7 * dydxnew[i]); - } - } - - public double error() { - double err = 0.0, sk; - for (int i = 0; i < n; i++) { - sk = atol + rtol * max(abs(y[i]), abs(yout[i])); - err += SQR(yerr[i] / sk); - } - return sqrt(err / n); - } - - private static final double d1 = -12715105075.0 / 11282082432.0, - d3 = 87487479700.0 / 32700410799.0, - d4 = -10690763975.0 / 1880347072.0, - d5 = 701980252875.0 / 199316789632.0, - d6 = -1453857185.0 / 822651844.0, d7 = 69997945.0 / 29380423.0; - - public void prepare_dense(final double h, final DerivativeInf derivs) { - // double[] ytemp = new double[n]; - for (int i = 0; i < n; i++) { - rcont1[i] = y[i]; - double ydiff = yout[i] - y[i]; - rcont2[i] = ydiff; - double bspl = h * dydx[i] - ydiff; - rcont3[i] = bspl; - rcont4[i] = ydiff - h * dydxnew[i] - bspl; - rcont5[i] = h - * (d1 * dydx[i] + d3 * k3[i] + d4 * k4[i] + d5 * k5[i] + d6 - * k6[i] + d7 * dydxnew[i]); - } - } - - @Override - public void step(final double htry, final DerivativeInf derivs) { - doubleW h = new doubleW(htry); - for (;;) { - dy(h.val, derivs); - double err = error(); - if (con.success(err, h)) - break; - if (abs(h.val) <= abs(x) * EPS) - throw new IllegalArgumentException( - "stepsize underflow in StepperDopr5"); - } - if (dense) - prepare_dense(h.val, derivs); - - System.arraycopy(dydxnew, 0, dydx, 0, dydxnew.length); - System.arraycopy(yout, 0, y, 0, y.length); - // dydx=dydxnew; - // y=yout; - - xold = x; - x += (hdid = h.val); - hnext = con.hnext; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ode/StepperDopr853.java b/common-tools/cnuphys/numRec/src/com/nr/ode/StepperDopr853.java deleted file mode 100644 index 03d34c1eee..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ode/StepperDopr853.java +++ /dev/null @@ -1,433 +0,0 @@ -package com.nr.ode; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import org.netlib.util.*; - -public class StepperDopr853 extends StepperBase { - final static double c2 = 0.526001519587677318785587544488e-01; - final static double c3 = 0.789002279381515978178381316732e-01; - final static double c4 = 0.118350341907227396726757197510e+00; - final static double c5 = 0.281649658092772603273242802490e+00; - final static double c6 = 0.333333333333333333333333333333e+00; - final static double c7 = 0.25e+00; - final static double c8 = 0.307692307692307692307692307692e+00; - final static double c9 = 0.651282051282051282051282051282e+00; - final static double c10 = 0.6e+00; - final static double c11 = 0.857142857142857142857142857142e+00; - final static double c14 = 0.1e+00; - final static double c15 = 0.2e+00; - final static double c16 = 0.777777777777777777777777777778e+00; - - final static double b1 = 5.42937341165687622380535766363e-2; - final static double b6 = 4.45031289275240888144113950566e0; - final static double b7 = 1.89151789931450038304281599044e0; - final static double b8 = -5.8012039600105847814672114227e0; - final static double b9 = 3.1116436695781989440891606237e-1; - final static double b10 = -1.52160949662516078556178806805e-1; - final static double b11 = 2.01365400804030348374776537501e-1; - final static double b12 = 4.47106157277725905176885569043e-2; - - final static double bhh1 = 0.244094488188976377952755905512e+00; - final static double bhh2 = 0.733846688281611857341361741547e+00; - final static double bhh3 = 0.220588235294117647058823529412e-01; - - final static double er1 = 0.1312004499419488073250102996e-01; - final static double er6 = -0.1225156446376204440720569753e+01; - final static double er7 = -0.4957589496572501915214079952e+00; - final static double er8 = 0.1664377182454986536961530415e+01; - final static double er9 = -0.3503288487499736816886487290e+00; - final static double er10 = 0.3341791187130174790297318841e+00; - final static double er11 = 0.8192320648511571246570742613e-01; - final static double er12 = -0.2235530786388629525884427845e-01; - - final static double a21 = 5.26001519587677318785587544488e-2; - final static double a31 = 1.97250569845378994544595329183e-2; - final static double a32 = 5.91751709536136983633785987549e-2; - final static double a41 = 2.95875854768068491816892993775e-2; - final static double a43 = 8.87627564304205475450678981324e-2; - final static double a51 = 2.41365134159266685502369798665e-1; - final static double a53 = -8.84549479328286085344864962717e-1; - final static double a54 = 9.24834003261792003115737966543e-1; - final static double a61 = 3.7037037037037037037037037037e-2; - final static double a64 = 1.70828608729473871279604482173e-1; - final static double a65 = 1.25467687566822425016691814123e-1; - final static double a71 = 3.7109375e-2; - final static double a74 = 1.70252211019544039314978060272e-1; - final static double a75 = 6.02165389804559606850219397283e-2; - final static double a76 = -1.7578125e-2; - - final static double a81 = 3.70920001185047927108779319836e-2; - final static double a84 = 1.70383925712239993810214054705e-1; - final static double a85 = 1.07262030446373284651809199168e-1; - final static double a86 = -1.53194377486244017527936158236e-2; - final static double a87 = 8.27378916381402288758473766002e-3; - final static double a91 = 6.24110958716075717114429577812e-1; - final static double a94 = -3.36089262944694129406857109825e0; - final static double a95 = -8.68219346841726006818189891453e-1; - final static double a96 = 2.75920996994467083049415600797e1; - final static double a97 = 2.01540675504778934086186788979e1; - final static double a98 = -4.34898841810699588477366255144e1; - final static double a101 = 4.77662536438264365890433908527e-1; - final static double a104 = -2.48811461997166764192642586468e0; - final static double a105 = -5.90290826836842996371446475743e-1; - final static double a106 = 2.12300514481811942347288949897e1; - final static double a107 = 1.52792336328824235832596922938e1; - final static double a108 = -3.32882109689848629194453265587e1; - final static double a109 = -2.03312017085086261358222928593e-2; - - final static double a111 = -9.3714243008598732571704021658e-1; - final static double a114 = 5.18637242884406370830023853209e0; - final static double a115 = 1.09143734899672957818500254654e0; - final static double a116 = -8.14978701074692612513997267357e0; - final static double a117 = -1.85200656599969598641566180701e1; - final static double a118 = 2.27394870993505042818970056734e1; - final static double a119 = 2.49360555267965238987089396762e0; - final static double a1110 = -3.0467644718982195003823669022e0; - final static double a121 = 2.27331014751653820792359768449e0; - final static double a124 = -1.05344954667372501984066689879e1; - final static double a125 = -2.00087205822486249909675718444e0; - final static double a126 = -1.79589318631187989172765950534e1; - final static double a127 = 2.79488845294199600508499808837e1; - final static double a128 = -2.85899827713502369474065508674e0; - final static double a129 = -8.87285693353062954433549289258e0; - final static double a1210 = 1.23605671757943030647266201528e1; - final static double a1211 = 6.43392746015763530355970484046e-1; - - final static double a141 = 5.61675022830479523392909219681e-2; - final static double a147 = 2.53500210216624811088794765333e-1; - final static double a148 = -2.46239037470802489917441475441e-1; - final static double a149 = -1.24191423263816360469010140626e-1; - final static double a1410 = 1.5329179827876569731206322685e-1; - final static double a1411 = 8.20105229563468988491666602057e-3; - final static double a1412 = 7.56789766054569976138603589584e-3; - final static double a1413 = -8.298e-3; - - final static double a151 = 3.18346481635021405060768473261e-2; - final static double a156 = 2.83009096723667755288322961402e-2; - final static double a157 = 5.35419883074385676223797384372e-2; - final static double a158 = -5.49237485713909884646569340306e-2; - final static double a1511 = -1.08347328697249322858509316994e-4; - final static double a1512 = 3.82571090835658412954920192323e-4; - final static double a1513 = -3.40465008687404560802977114492e-4; - final static double a1514 = 1.41312443674632500278074618366e-1; - final static double a161 = -4.28896301583791923408573538692e-1; - final static double a166 = -4.69762141536116384314449447206e0; - final static double a167 = 7.68342119606259904184240953878e0; - final static double a168 = 4.06898981839711007970213554331e0; - final static double a169 = 3.56727187455281109270669543021e-1; - final static double a1613 = -1.39902416515901462129418009734e-3; - final static double a1614 = 2.9475147891527723389556272149e0; - final static double a1615 = -9.15095847217987001081870187138e0; - - final static double d41 = -0.84289382761090128651353491142e+01; - final static double d46 = 0.56671495351937776962531783590e+00; - final static double d47 = -0.30689499459498916912797304727e+01; - final static double d48 = 0.23846676565120698287728149680e+01; - final static double d49 = 0.21170345824450282767155149946e+01; - final static double d410 = -0.87139158377797299206789907490e+00; - final static double d411 = 0.22404374302607882758541771650e+01; - final static double d412 = 0.63157877876946881815570249290e+00; - final static double d413 = -0.88990336451333310820698117400e-01; - final static double d414 = 0.18148505520854727256656404962e+02; - final static double d415 = -0.91946323924783554000451984436e+01; - final static double d416 = -0.44360363875948939664310572000e+01; - - final static double d51 = 0.10427508642579134603413151009e+02; - final static double d56 = 0.24228349177525818288430175319e+03; - final static double d57 = 0.16520045171727028198505394887e+03; - final static double d58 = -0.37454675472269020279518312152e+03; - final static double d59 = -0.22113666853125306036270938578e+02; - final static double d510 = 0.77334326684722638389603898808e+01; - final static double d511 = -0.30674084731089398182061213626e+02; - final static double d512 = -0.93321305264302278729567221706e+01; - final static double d513 = 0.15697238121770843886131091075e+02; - final static double d514 = -0.31139403219565177677282850411e+02; - final static double d515 = -0.93529243588444783865713862664e+01; - final static double d516 = 0.35816841486394083752465898540e+02; - - final static double d61 = 0.19985053242002433820987653617e+02; - final static double d66 = -0.38703730874935176555105901742e+03; - final static double d67 = -0.18917813819516756882830838328e+03; - final static double d68 = 0.52780815920542364900561016686e+03; - final static double d69 = -0.11573902539959630126141871134e+02; - final static double d610 = 0.68812326946963000169666922661e+01; - final static double d611 = -0.10006050966910838403183860980e+01; - final static double d612 = 0.77771377980534432092869265740e+00; - final static double d613 = -0.27782057523535084065932004339e+01; - final static double d614 = -0.60196695231264120758267380846e+02; - final static double d615 = 0.84320405506677161018159903784e+02; - final static double d616 = 0.11992291136182789328035130030e+02; - - final static double d71 = -0.25693933462703749003312586129e+02; - final static double d76 = -0.15418974869023643374053993627e+03; - final static double d77 = -0.23152937917604549567536039109e+03; - final static double d78 = 0.35763911791061412378285349910e+03; - final static double d79 = 0.93405324183624310003907691704e+02; - final static double d710 = -0.37458323136451633156875139351e+02; - final static double d711 = 0.10409964950896230045147246184e+03; - final static double d712 = 0.29840293426660503123344363579e+02; - final static double d713 = -0.43533456590011143754432175058e+02; - final static double d714 = 0.96324553959188282948394950600e+02; - final static double d715 = -0.39177261675615439165231486172e+02; - final static double d716 = -0.14972683625798562581422125276e+03; - - double[] yerr2; - double[] k2, k3, k4, k5, k6, k7, k8, k9, k10; - double[] rcont1, rcont2, rcont3, rcont4, rcont5, rcont6, rcont7, rcont8; - - Controller con = new Controller(); - - public static class Controller { - double hnext, errold; - boolean reject; - - public Controller() { - reject = false; - errold = 1.0e-4; - } - - public boolean success(final double err, final doubleW h) { - final double beta = 0.0, alpha = 1.0 / 8.0 - beta * 0.2, safe = 0.9, minscale = 0.333, maxscale = 6.0; - double scale; - if (err <= 1.0) { - if (err == 0.0) - scale = maxscale; - else { - scale = safe * pow(err, -alpha) * pow(errold, beta); - if (scale < minscale) - scale = minscale; - if (scale > maxscale) - scale = maxscale; - } - if (reject) - hnext = h.val * min(scale, 1.0); - else - hnext = h.val * scale; - errold = max(err, 1.0e-4); - reject = false; - return true; - } else { - scale = max(safe * pow(err, -alpha), minscale); - h.val *= scale; - reject = true; - return false; - } - } - } - - public StepperDopr853() { - - } - - public StepperDopr853(final double[] yy, final double[] dydxx, - final double xx, final double atoll, final double rtoll, - final boolean dense) { - setParam(yy, dydxx, xx, atoll, rtoll, dense); - } - - @Override - public void setParam(final double[] yy, final double[] dydxx, - final double xx, final double atoll, final double rtoll, - final boolean dense) { - super.setParam(yy, dydxx, xx, atoll, rtoll, dense); - yerr2 = new double[n]; - k2 = new double[n]; - k3 = new double[n]; - k4 = new double[n]; - k5 = new double[n]; - k6 = new double[n]; - k7 = new double[n]; - k8 = new double[n]; - k9 = new double[n]; - k10 = new double[n]; - rcont1 = new double[n]; - rcont2 = new double[n]; - rcont3 = new double[n]; - rcont4 = new double[n]; - rcont5 = new double[n]; - rcont6 = new double[n]; - rcont7 = new double[n]; - rcont8 = new double[n]; - EPS = DBL_EPSILON; - } - - @Override - public void step(final double htry, final DerivativeInf derivs) { - double[] dydxnew = new double[n]; - doubleW h = new doubleW(htry); - for (;;) { - dy(h.val, derivs); - double err = error(h.val); - if (con.success(err, h)) - break; - if (abs(h.val) <= abs(x) * EPS) - throw new IllegalArgumentException( - "stepsize underflow in StepperDopr853"); - } - derivs.derivs(x + h.val, yout, dydxnew); - if (dense) - prepare_dense(h.val, dydxnew, derivs); - System.arraycopy(dydxnew, 0, dydx, 0, dydxnew.length); - System.arraycopy(yout, 0, y, 0, y.length); - // dydx=dydxnew; //XXX reference replace to arraycopy. - // y=yout; - xold = x; - x += (hdid = h.val); - hnext = con.hnext; - } - - public void dy(final double h, final DerivativeInf derivs) { - double[] ytemp = new double[n]; - int i; - for (i = 0; i < n; i++) - ytemp[i] = y[i] + h * a21 * dydx[i]; - derivs.derivs(x + c2 * h, ytemp, k2); - for (i = 0; i < n; i++) - ytemp[i] = y[i] + h * (a31 * dydx[i] + a32 * k2[i]); - derivs.derivs(x + c3 * h, ytemp, k3); - for (i = 0; i < n; i++) - ytemp[i] = y[i] + h * (a41 * dydx[i] + a43 * k3[i]); - derivs.derivs(x + c4 * h, ytemp, k4); - for (i = 0; i < n; i++) - ytemp[i] = y[i] + h * (a51 * dydx[i] + a53 * k3[i] + a54 * k4[i]); - derivs.derivs(x + c5 * h, ytemp, k5); - for (i = 0; i < n; i++) - ytemp[i] = y[i] + h * (a61 * dydx[i] + a64 * k4[i] + a65 * k5[i]); - derivs.derivs(x + c6 * h, ytemp, k6); - for (i = 0; i < n; i++) - ytemp[i] = y[i] + h - * (a71 * dydx[i] + a74 * k4[i] + a75 * k5[i] + a76 * k6[i]); - derivs.derivs(x + c7 * h, ytemp, k7); - for (i = 0; i < n; i++) - ytemp[i] = y[i] - + h - * (a81 * dydx[i] + a84 * k4[i] + a85 * k5[i] + a86 * k6[i] + a87 - * k7[i]); - derivs.derivs(x + c8 * h, ytemp, k8); - for (i = 0; i < n; i++) - ytemp[i] = y[i] - + h - * (a91 * dydx[i] + a94 * k4[i] + a95 * k5[i] + a96 * k6[i] - + a97 * k7[i] + a98 * k8[i]); - derivs.derivs(x + c9 * h, ytemp, k9); - for (i = 0; i < n; i++) - ytemp[i] = y[i] - + h - * (a101 * dydx[i] + a104 * k4[i] + a105 * k5[i] + a106 - * k6[i] + a107 * k7[i] + a108 * k8[i] + a109 - * k9[i]); - derivs.derivs(x + c10 * h, ytemp, k10); - for (i = 0; i < n; i++) - ytemp[i] = y[i] - + h - * (a111 * dydx[i] + a114 * k4[i] + a115 * k5[i] + a116 - * k6[i] + a117 * k7[i] + a118 * k8[i] + a119 - * k9[i] + a1110 * k10[i]); - derivs.derivs(x + c11 * h, ytemp, k2); - double xph = x + h; - for (i = 0; i < n; i++) - ytemp[i] = y[i] - + h - * (a121 * dydx[i] + a124 * k4[i] + a125 * k5[i] + a126 - * k6[i] + a127 * k7[i] + a128 * k8[i] + a129 - * k9[i] + a1210 * k10[i] + a1211 * k2[i]); - derivs.derivs(xph, ytemp, k3); - for (i = 0; i < n; i++) { - k4[i] = b1 * dydx[i] + b6 * k6[i] + b7 * k7[i] + b8 * k8[i] + b9 - * k9[i] + b10 * k10[i] + b11 * k2[i] + b12 * k3[i]; - yout[i] = y[i] + h * k4[i]; - } - for (i = 0; i < n; i++) { - yerr[i] = k4[i] - bhh1 * dydx[i] - bhh2 * k9[i] - bhh3 * k3[i]; - yerr2[i] = er1 * dydx[i] + er6 * k6[i] + er7 * k7[i] + er8 * k8[i] - + er9 * k9[i] + er10 * k10[i] + er11 * k2[i] + er12 * k3[i]; - } - } - - public void prepare_dense(final double h, final double[] dydxnew, - final DerivativeInf derivs) { - int i; - double ydiff, bspl; - double[] ytemp = new double[n]; - for (i = 0; i < n; i++) { - rcont1[i] = y[i]; - ydiff = yout[i] - y[i]; - rcont2[i] = ydiff; - bspl = h * dydx[i] - ydiff; - rcont3[i] = bspl; - rcont4[i] = ydiff - h * dydxnew[i] - bspl; - rcont5[i] = d41 * dydx[i] + d46 * k6[i] + d47 * k7[i] + d48 * k8[i] - + d49 * k9[i] + d410 * k10[i] + d411 * k2[i] + d412 * k3[i]; - rcont6[i] = d51 * dydx[i] + d56 * k6[i] + d57 * k7[i] + d58 * k8[i] - + d59 * k9[i] + d510 * k10[i] + d511 * k2[i] + d512 * k3[i]; - rcont7[i] = d61 * dydx[i] + d66 * k6[i] + d67 * k7[i] + d68 * k8[i] - + d69 * k9[i] + d610 * k10[i] + d611 * k2[i] + d612 * k3[i]; - rcont8[i] = d71 * dydx[i] + d76 * k6[i] + d77 * k7[i] + d78 * k8[i] - + d79 * k9[i] + d710 * k10[i] + d711 * k2[i] + d712 * k3[i]; - } - for (i = 0; i < n; i++) - ytemp[i] = y[i] - + h - * (a141 * dydx[i] + a147 * k7[i] + a148 * k8[i] + a149 - * k9[i] + a1410 * k10[i] + a1411 * k2[i] + a1412 - * k3[i] + a1413 * dydxnew[i]); - derivs.derivs(x + c14 * h, ytemp, k10); - for (i = 0; i < n; i++) - ytemp[i] = y[i] - + h - * (a151 * dydx[i] + a156 * k6[i] + a157 * k7[i] + a158 - * k8[i] + a1511 * k2[i] + a1512 * k3[i] + a1513 - * dydxnew[i] + a1514 * k10[i]); - derivs.derivs(x + c15 * h, ytemp, k2); - for (i = 0; i < n; i++) - ytemp[i] = y[i] - + h - * (a161 * dydx[i] + a166 * k6[i] + a167 * k7[i] + a168 - * k8[i] + a169 * k9[i] + a1613 * dydxnew[i] + a1614 - * k10[i] + a1615 * k2[i]); - derivs.derivs(x + c16 * h, ytemp, k3); - for (i = 0; i < n; i++) { - rcont5[i] = h - * (rcont5[i] + d413 * dydxnew[i] + d414 * k10[i] + d415 - * k2[i] + d416 * k3[i]); - rcont6[i] = h - * (rcont6[i] + d513 * dydxnew[i] + d514 * k10[i] + d515 - * k2[i] + d516 * k3[i]); - rcont7[i] = h - * (rcont7[i] + d613 * dydxnew[i] + d614 * k10[i] + d615 - * k2[i] + d616 * k3[i]); - rcont8[i] = h - * (rcont8[i] + d713 * dydxnew[i] + d714 * k10[i] + d715 - * k2[i] + d716 * k3[i]); - } - } - - @Override - public double dense_out(final int i, final double x, final double h) { - double s = (x - xold) / h; - double s1 = 1.0 - s; - return rcont1[i] - + s - * (rcont2[i] + s1 - * (rcont3[i] + s - * (rcont4[i] + s1 - * (rcont5[i] + s - * (rcont6[i] + s1 - * (rcont7[i] + s - * rcont8[i])))))); - } - - public double error(final double h) { - double err = 0.0, err2 = 0.0, sk, deno; - for (int i = 0; i < n; i++) { - sk = atol + rtol * max(abs(y[i]), abs(yout[i])); - err2 += SQR(yerr[i] / sk); - err += SQR(yerr2[i] / sk); - } - deno = err + 0.01 * err2; - if (deno <= 0.0) - deno = 1.0; - return abs(h) * err * sqrt(1.0 / (n * deno)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ode/StepperRoss.java b/common-tools/cnuphys/numRec/src/com/nr/ode/StepperRoss.java deleted file mode 100644 index 1cb07e7f4d..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ode/StepperRoss.java +++ /dev/null @@ -1,247 +0,0 @@ -package com.nr.ode; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import org.netlib.util.*; - -import com.nr.la.LUdcmp; - -/** - * fourth-order stiffly stable Rosenbrock stepper Copyright (C) Numerical - * Recipes Software 1986-2007 Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class StepperRoss extends StepperBase { - final static double c2 = 0.386; - final static double c3 = 0.21; - final static double c4 = 0.63; - final static double bet2p = 0.0317; - final static double bet3p = 0.0635; - final static double bet4p = 0.3438; - final static double d1 = 0.2500000000000000e+00; - final static double d2 = -0.1043000000000000e+00; - final static double d3 = 0.1035000000000000e+00; - final static double d4 = -0.3620000000000023e-01; - final static double a21 = 0.1544000000000000e+01; - final static double a31 = 0.9466785280815826e+00; - final static double a32 = 0.2557011698983284e+00; - final static double a41 = 0.3314825187068521e+01; - final static double a42 = 0.2896124015972201e+01; - final static double a43 = 0.9986419139977817e+00; - final static double a51 = 0.1221224509226641e+01; - final static double a52 = 0.6019134481288629e+01; - final static double a53 = 0.1253708332932087e+02; - final static double a54 = -0.6878860361058950e+00; - final static double c21 = -0.5668800000000000e+01; - final static double c31 = -0.2430093356833875e+01; - final static double c32 = -0.2063599157091915e+00; - final static double c41 = -0.1073529058151375e+00; - final static double c42 = -0.9594562251023355e+01; - final static double c43 = -0.2047028614809616e+02; - final static double c51 = 0.7496443313967647e+01; - final static double c52 = -0.1024680431464352e+02; - final static double c53 = -0.3399990352819905e+02; - final static double c54 = 0.1170890893206160e+02; - final static double c61 = 0.8083246795921522e+01; - final static double c62 = -0.7981132988064893e+01; - final static double c63 = -0.3152159432874371e+02; - final static double c64 = 0.1631930543123136e+02; - final static double c65 = -0.6058818238834054e+01; - final static double gam = 0.2500000000000000e+00; - final static double d21 = 0.1012623508344586e+02; - final static double d22 = -0.7487995877610167e+01; - final static double d23 = -0.3480091861555747e+02; - final static double d24 = -0.7992771707568823e+01; - final static double d25 = 0.1025137723295662e+01; - final static double d31 = -0.6762803392801253e+00; - final static double d32 = 0.6087714651680015e+01; - final static double d33 = 0.1643084320892478e+02; - final static double d34 = 0.2476722511418386e+02; - final static double d35 = -0.6594389125716872e+01; - double[][] dfdy; - double[] dfdx; - double[] k1, k2, k3, k4, k5, k6; - double[] cont1, cont2, cont3, cont4; - double[][] a; - Controller con = new Controller(); - - public static class Controller { - double hnext; - boolean reject; - boolean first_step; - double errold; - double hold; - - public Controller() { - reject = false; - first_step = true; - } - - public boolean success(final double err, final doubleW h) { - final double safe = 0.9, fac1 = 5.0, fac2 = 1.0 / 6.0; - double fac = max(fac2, min(fac1, pow(err, 0.25) / safe)); - double hnew = h.val / fac; - if (err <= 1.0) { - if (!first_step) { - double facpred = (hold / h.val) - * pow(err * err / errold, 0.25) / safe; - facpred = max(fac2, min(fac1, facpred)); - fac = max(fac, facpred); - hnew = h.val / fac; - } - first_step = false; - hold = h.val; - errold = max(0.01, err); - if (reject) - hnew = (h.val >= 0.0 ? min(hnew, h.val) : max(hnew, h.val)); - hnext = hnew; - reject = false; - return true; - } else { - h.val = hnew; - reject = true; - return false; - } - } - } - - public StepperRoss() { - - } - - public StepperRoss(final double[] yy, final double[] dydxx, - final double xx, final double atoll, final double rtoll, - final boolean dense) { - setParam(yy, dydxx, xx, atoll, rtoll, dense); - } - - @Override - public void setParam(final double[] yy, final double[] dydxx, - final double xx, final double atoll, final double rtoll, - final boolean dense) { - super.setParam(yy, dydxx, xx, atoll, rtoll, dense); - dfdy = new double[n][n]; - dfdx = new double[n]; - k1 = new double[n]; - k2 = new double[n]; - k3 = new double[n]; - k4 = new double[n]; - k5 = new double[n]; - k6 = new double[n]; - cont1 = new double[n]; - cont2 = new double[n]; - cont3 = new double[n]; - cont4 = new double[n]; - a = new double[n][n]; - EPS = DBL_EPSILON; - } - - @Override - public void step(final double htry, final DerivativeInf derivs) { - double[] dydxnew = new double[n]; - doubleW h = new doubleW(htry); - derivs.jacobian(x, y, dfdx, dfdy); - for (;;) { - dy(h.val, derivs); - double err = error(); - if (con.success(err, h)) - break; - if (abs(h.val) <= abs(x) * EPS) - throw new IllegalArgumentException( - "stepsize underflow in StepperRoss"); - } - derivs.derivs(x + h.val, yout, dydxnew); - if (dense) - prepare_dense(h.val, dydxnew); - System.arraycopy(dydxnew, 0, dydx, 0, dydxnew.length); - System.arraycopy(yout, 0, y, 0, y.length); - // dydx=dydxnew; - // y=yout; - xold = x; - x += (hdid = h.val); - hnext = con.hnext; - } - - public void dy(final double h, final DerivativeInf derivs) { - double[] ytemp = new double[n], dydxnew = new double[n]; - int i; - for (i = 0; i < n; i++) { - for (int j = 0; j < n; j++) - a[i][j] = -dfdy[i][j]; - a[i][i] += 1.0 / (gam * h); - } - LUdcmp alu = new LUdcmp(a); - for (i = 0; i < n; i++) - ytemp[i] = dydx[i] + h * d1 * dfdx[i]; - alu.solve(ytemp, k1); - for (i = 0; i < n; i++) - ytemp[i] = y[i] + a21 * k1[i]; - derivs.derivs(x + c2 * h, ytemp, dydxnew); - for (i = 0; i < n; i++) - ytemp[i] = dydxnew[i] + h * d2 * dfdx[i] + c21 * k1[i] / h; - alu.solve(ytemp, k2); - for (i = 0; i < n; i++) - ytemp[i] = y[i] + a31 * k1[i] + a32 * k2[i]; - derivs.derivs(x + c3 * h, ytemp, dydxnew); - for (i = 0; i < n; i++) - ytemp[i] = dydxnew[i] + h * d3 * dfdx[i] - + (c31 * k1[i] + c32 * k2[i]) / h; - alu.solve(ytemp, k3); - for (i = 0; i < n; i++) - ytemp[i] = y[i] + a41 * k1[i] + a42 * k2[i] + a43 * k3[i]; - derivs.derivs(x + c4 * h, ytemp, dydxnew); - for (i = 0; i < n; i++) - ytemp[i] = dydxnew[i] + h * d4 * dfdx[i] - + (c41 * k1[i] + c42 * k2[i] + c43 * k3[i]) / h; - alu.solve(ytemp, k4); - for (i = 0; i < n; i++) - ytemp[i] = y[i] + a51 * k1[i] + a52 * k2[i] + a53 * k3[i] + a54 - * k4[i]; - double xph = x + h; - derivs.derivs(xph, ytemp, dydxnew); - for (i = 0; i < n; i++) - k6[i] = dydxnew[i] - + (c51 * k1[i] + c52 * k2[i] + c53 * k3[i] + c54 * k4[i]) - / h; - alu.solve(k6, k5); - for (i = 0; i < n; i++) - ytemp[i] += k5[i]; - derivs.derivs(xph, ytemp, dydxnew); - for (i = 0; i < n; i++) - k6[i] = dydxnew[i] - + (c61 * k1[i] + c62 * k2[i] + c63 * k3[i] + c64 * k4[i] + c65 - * k5[i]) / h; - alu.solve(k6, yerr); - for (i = 0; i < n; i++) - yout[i] = ytemp[i] + yerr[i]; - } - - public void prepare_dense(final double h, final double[] dydxnew) { - for (int i = 0; i < n; i++) { - cont1[i] = y[i]; - cont2[i] = yout[i]; - cont3[i] = d21 * k1[i] + d22 * k2[i] + d23 * k3[i] + d24 * k4[i] - + d25 * k5[i]; - cont4[i] = d31 * k1[i] + d32 * k2[i] + d33 * k3[i] + d34 * k4[i] - + d35 * k5[i]; - } - } - - @Override - public double dense_out(final int i, final double x, final double h) { - double s = (x - xold) / h; - double s1 = 1.0 - s; - return cont1[i] * s1 + s * (cont2[i] + s1 * (cont3[i] + s * cont4[i])); - } - - public double error() { - double err = 0.0, sk; - for (int i = 0; i < n; i++) { - sk = atol + rtol * max(abs(y[i]), abs(yout[i])); - err += SQR(yerr[i] / sk); - } - return sqrt(err / n); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ode/StepperSie.java b/common-tools/cnuphys/numRec/src/com/nr/ode/StepperSie.java deleted file mode 100644 index 94e716fe39..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ode/StepperSie.java +++ /dev/null @@ -1,395 +0,0 @@ -package com.nr.ode; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import org.netlib.util.*; - -import com.nr.la.LUdcmp; - -/** - * semi-implicit extrapolation stepper Copyright (C) Numerical Recipes Software - * 1986-2007 Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class StepperSie extends StepperBase { - static final int KMAXX = 12, IMAXX = KMAXX + 1; - int k_targ; - int[] nseq; - double[] cost; - double[][] table; - double[][] dfdy; - double[] dfdx; - double jac_redo; - boolean calcjac; - double theta; - double[][] a; - int kright; - double[][] coeff; - double[][] fsave; - double[] dens; - double[] factrl; - - static final double costfunc = 1.0, costjac = 5.0, costlu = 1.0, - costsolve = 1.0; - - public StepperSie() { - } - - public StepperSie(final double[] yy, final double[] dydxx, final double xx, - final double atoll, final double rtoll, final boolean dense) { - setParam(yy, dydxx, xx, atoll, rtoll, dense); - } - - @Override - public void setParam(final double[] yy, final double[] dydxx, - final double xx, final double atoll, final double rtoll, - final boolean dense) { - super.setParam(yy, dydxx, xx, atoll, rtoll, dense); - nseq = new int[IMAXX]; - cost = new double[IMAXX]; - table = new double[KMAXX][n]; - dfdy = new double[n][n]; - dfdx = new double[n]; - calcjac = false; - a = new double[n][n]; - coeff = new double[IMAXX][IMAXX]; - fsave = new double[(IMAXX - 1) * (IMAXX + 1) / 2 + 2][n]; - dens = new double[(IMAXX + 2) * n]; - factrl = new double[IMAXX]; - - EPS = DBL_EPSILON; - jac_redo = min(1.0e-4, rtol); - theta = 2.0 * jac_redo; - nseq[0] = 2; - nseq[1] = 3; - for (int i = 2; i < IMAXX; i++) - nseq[i] = 2 * nseq[i - 2]; - cost[0] = costjac + costlu + nseq[0] * (costfunc + costsolve); - for (int k = 0; k < KMAXX; k++) - cost[k + 1] = cost[k] + (nseq[k + 1] - 1) * (costfunc + costsolve) - + costlu; - hnext = -1.0e99; - double logfact = -log10(rtol + atol) * 0.6 + 0.5; - k_targ = max(1, min(KMAXX - 1, (int) (logfact))); - for (int k = 0; k < IMAXX; k++) { - for (int l = 0; l < k; l++) { - double ratio = (double) (nseq[k]) / nseq[l]; - coeff[k][l] = 1.0 / (ratio - 1.0); - } - } - factrl[0] = 1.0; - for (int k = 0; k < IMAXX - 1; k++) - factrl[k + 1] = (k + 1) * factrl[k]; - } - - static boolean first_step = true, last_step = false; - static boolean forward, reject = false, prev_reject = false; - static double errold; - - @Override - public void step(final double htry, final DerivativeInf derivs) { - final double STEPFAC1 = 0.6, STEPFAC2 = 0.93, STEPFAC3 = 0.1, STEPFAC4 = 4.0, STEPFAC5 = 0.5, KFAC1 = 0.7, KFAC2 = 0.9; - int i, k = 0; - double fac, h, hnew, err = 0; - boolean firstk; - double[] hopt = new double[IMAXX], work = new double[IMAXX]; - double[] ysav = new double[n], yseq = new double[n]; - double[] scale = new double[n]; // ymid = new double[n], not use it - work[0] = 1.e30; - h = htry; - forward = h > 0 ? true : false; - for (i = 0; i < n; i++) - ysav[i] = y[i]; - if (h != hnext && !first_step) { - last_step = true; - } - if (reject) { - prev_reject = true; - last_step = false; - theta = 2.0 * jac_redo; - } - for (i = 0; i < n; i++) - scale[i] = atol + rtol * abs(y[i]); - reject = false; - firstk = true; - hnew = abs(h); - while (true) { - // compute_jac: - boolean goto_compute_jac = false; - - if (theta > jac_redo && !calcjac) { - derivs.jacobian(x, y, dfdx, dfdy); - calcjac = true; - } - while (firstk || reject) { - h = forward ? hnew : -hnew; - firstk = false; - reject = false; - if (abs(h) <= abs(x) * EPS) - throw new IllegalArgumentException( - "step size underflow in StepperSie"); - intW ipt = new intW(-1); - for (k = 0; k <= k_targ + 1; k++) { - boolean success = dy(ysav, h, k, yseq, ipt, scale, derivs); - if (!success) { - reject = true; - hnew = abs(h) * STEPFAC5; - break; - } - if (k == 0) - // y=yseq; XXX replace to arraycopy. - System.arraycopy(yseq, 0, y, 0, y.length); - else - for (i = 0; i < n; i++) - table[k - 1][i] = yseq[i]; - if (k != 0) { - polyextr(k, table, y); - err = 0.0; - for (i = 0; i < n; i++) { - scale[i] = atol + rtol * abs(ysav[i]); - err += SQR((y[i] - table[0][i]) / scale[i]); - } - err = sqrt(err / n); - if (err > 1.0 / EPS || (k > 1 && err >= errold)) { - reject = true; - hnew = abs(h) * STEPFAC5; - break; - } - errold = max(4.0 * err, 1.0); - double expo = 1.0 / (k + 1); - double facmin = pow(STEPFAC3, expo); - if (err == 0.0) - fac = 1.0 / facmin; - else { - fac = STEPFAC2 / pow(err / STEPFAC1, expo); - fac = max(facmin / STEPFAC4, min(1.0 / facmin, fac)); - } - hopt[k] = abs(h * fac); - work[k] = cost[k] / hopt[k]; - if ((first_step || last_step) && err <= 1.0) - break; - if (k == k_targ - 1 && !prev_reject && !first_step - && !last_step) { - if (err <= 1.0) - break; - else if (err > nseq[k_targ] * nseq[k_targ + 1] - * 4.0) { - reject = true; - k_targ = k; - if (k_targ > 1 && work[k - 1] < KFAC1 * work[k]) - k_targ--; - hnew = hopt[k_targ]; - break; - } - } - if (k == k_targ) { - if (err <= 1.0) - break; - else if (err > nseq[k + 1] * 2.0) { - reject = true; - if (k_targ > 1 && work[k - 1] < KFAC1 * work[k]) - k_targ--; - hnew = hopt[k_targ]; - break; - } - } - if (k == k_targ + 1) { - if (err > 1.0) { - reject = true; - if (k_targ > 1 - && work[k_targ - 1] < KFAC1 - * work[k_targ]) - k_targ--; - hnew = hopt[k_targ]; - } - break; - } - } - } - if (reject) { - prev_reject = true; - if (!calcjac) { - theta = 2.0 * jac_redo; - // goto compute_jac; - goto_compute_jac = true; - } - } - } - if (goto_compute_jac) { - goto_compute_jac = false; - continue; - } - break; - } - calcjac = false; - if (dense) { - doubleW errW = new doubleW(err); - prepare_dense(h, ysav, scale, k, errW); - err = errW.val; - } - xold = x; - x += h; - hdid = h; - first_step = false; - int kopt; - if (k == 1) - kopt = 2; - else if (k <= k_targ) { - kopt = k; - if (work[k - 1] < KFAC1 * work[k]) - kopt = k - 1; - else if (work[k] < KFAC2 * work[k - 1]) - kopt = min(k + 1, KMAXX - 1); - } else { - kopt = k - 1; - if (k > 2 && work[k - 2] < KFAC1 * work[k - 1]) - kopt = k - 2; - if (work[k] < KFAC2 * work[kopt]) - kopt = min(k, KMAXX - 1); - } - if (prev_reject) { - k_targ = min(kopt, k); - hnew = min(abs(h), hopt[k_targ]); - prev_reject = false; - } else { - if (kopt <= k) - hnew = hopt[kopt]; - else { - if (k < k_targ && work[k] < KFAC2 * work[k - 1]) - hnew = hopt[k] * cost[kopt + 1] / cost[k]; - else - hnew = hopt[k] * cost[kopt] / cost[k]; - } - k_targ = kopt; - } - if (forward) - hnext = hnew; - else - hnext = -hnew; - } - - public boolean dy(final double[] y, final double htot, final int k, - final double[] yend, final intW ipt, final double[] scale, - final DerivativeInf derivs) { - double[] del = new double[n], ytemp = new double[n], dytemp = new double[n]; - int nstep = nseq[k]; - double h = htot / nstep; - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) - a[i][j] = -dfdy[i][j]; - a[i][i] += 1.0 / h; - } - LUdcmp alu = new LUdcmp(a); - double xnew = x + h; - derivs.derivs(xnew, y, del); - for (int i = 0; i < n; i++) - ytemp[i] = y[i]; - alu.solve(del, del); - if (dense && nstep == k + 1) { - ipt.val++; - for (int i = 0; i < n; i++) - fsave[ipt.val][i] = del[i]; - } - for (int nn = 1; nn < nstep; nn++) { - for (int i = 0; i < n; i++) - ytemp[i] += del[i]; - xnew += h; - derivs.derivs(xnew, ytemp, yend); - if (nn == 1 && k <= 1) { - double del1 = 0.0; - for (int i = 0; i < n; i++) - del1 += SQR(del[i] / scale[i]); - del1 = sqrt(del1); - derivs.derivs(x + h, ytemp, dytemp); - for (int i = 0; i < n; i++) - del[i] = dytemp[i] - del[i] / h; - alu.solve(del, del); - double del2 = 0.0; - for (int i = 0; i < n; i++) - del2 += SQR(del[i] / scale[i]); - del2 = sqrt(del2); - theta = del2 / max(1.0, del1); - if (theta > 1.0) - return false; - } - alu.solve(yend, del); - if (dense && nn >= nstep - k - 1) { - ipt.val++; - for (int i = 0; i < n; i++) - fsave[ipt.val][i] = del[i]; - } - } - for (int i = 0; i < n; i++) - yend[i] = ytemp[i] + del[i]; - return true; - } - - public void polyextr(final int k, final double[][] table, - final double[] last) { - int l = last.length; - for (int j = k - 1; j > 0; j--) - for (int i = 0; i < l; i++) - table[j - 1][i] = table[j][i] + coeff[k][j] - * (table[j][i] - table[j - 1][i]); - for (int i = 0; i < l; i++) - last[i] = table[0][i] + coeff[k][0] * (table[0][i] - last[i]); - } - - public void prepare_dense(final double h, final double[] ysav, - final double[] scale, final int k, final doubleW error) { - kright = k; - for (int i = 0; i < n; i++) { - dens[i] = ysav[i]; - dens[n + i] = y[i]; - } - for (int klr = 0; klr < kright; klr++) { - if (klr >= 1) { - for (int kk = klr; kk <= k; kk++) { - int lbeg = ((kk + 3) * kk) / 2; - int lend = lbeg - kk + 1; - for (int l = lbeg; l >= lend; l--) - for (int i = 0; i < n; i++) - fsave[l][i] = fsave[l][i] - fsave[l - 1][i]; - } - } - for (int kk = klr; kk <= k; kk++) { - double facnj = nseq[kk]; - facnj = pow(facnj, klr + 1) / factrl[klr + 1]; - int ipt = ((kk + 3) * kk) / 2; - int krn = (kk + 2) * n; - for (int i = 0; i < n; i++) { - dens[krn + i] = fsave[ipt][i] * facnj; - } - } - for (int j = klr + 1; j <= k; j++) { - double dblenj = nseq[j]; - for (int l = j; l >= klr + 1; l--) { - double factor = dblenj / nseq[l - 1] - 1.0; - for (int i = 0; i < n; i++) { - int krn = (l + 2) * n + i; - dens[krn - n] = dens[krn] + (dens[krn] - dens[krn - n]) - / factor; - } - } - } - } - for (int in = 0; in < n; in++) { - for (int j = 1; j <= kright + 1; j++) { - int ii = n * j + in; - dens[ii] = dens[ii] - dens[ii - n]; - } - } - } - - @Override - public double dense_out(final int i, final double x, final double h) { - double theta = (x - xold) / h; - int k = kright; - double yinterp = dens[(k + 1) * n + i]; - for (int j = 1; j <= k; j++) - yinterp = dens[(k + 1 - j) * n + i] + yinterp * (theta - 1.0); - return dens[i] + yinterp * theta; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ode/StepperStoerm.java b/common-tools/cnuphys/numRec/src/com/nr/ode/StepperStoerm.java deleted file mode 100644 index ce4cd4c8cb..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ode/StepperStoerm.java +++ /dev/null @@ -1,279 +0,0 @@ -package com.nr.ode; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import org.netlib.util.*; - -/** - * Second-Order Conservative Equations Copyright (C) Numerical Recipes Software - * 1986-2007 Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class StepperStoerm extends StepperBS { - private double[][] ysavep; - - public StepperStoerm() { - - } - - public StepperStoerm(final double[] yy, final double[] dydxx, - final double xx, final double atoll, final double rtoll, - final boolean dense) { - setParam(yy, dydxx, xx, atoll, rtoll, dense); - } - - @Override - public void setParam(final double[] yy, final double[] dydxx, - final double xx, final double atoll, final double rtoll, - final boolean dense) { - super.setParam(yy, dydxx, xx, atoll, rtoll, dense); - ysavep = new double[IMAXX][n / 2]; - neqn = n / 2; - cost[0] = nseq[0] / 2 + 1; - for (int k = 0; k < KMAXX; k++) - cost[k + 1] = cost[k] + nseq[k + 1] / 2; - for (int i = 0; i < 2 * IMAXX + 1; i++) { - int ip7 = i + 7; - double fac = 1.5 / ip7; - errfac[i] = fac * fac * fac; - double e = 0.5 * sqrt((double) (i + 1) / ip7); - for (int j = 0; j <= i; j++) { - errfac[i] *= e / (j + 1); - } - } - } - - @Override - public void prepare_dense(final double h, final double[] dydxnew, - final double[] ysav, final double[] scale, final int k, - final doubleW error) { - double h2 = h * h; - mu = max(1, 2 * k - 3); - for (int i = 0; i < neqn; i++) { - dens[i] = ysav[i]; - dens[neqn + i] = h * ysav[neqn + i]; - dens[2 * neqn + i] = h2 * dydx[i]; - dens[3 * neqn + i] = y[i]; - dens[4 * neqn + i] = h * y[neqn + i]; - dens[5 * neqn + i] = h2 * dydxnew[i]; - } - for (int j = 1; j <= k; j++) { - double dblenj = nseq[j]; - for (int l = j; l >= 1; l--) { - double factor = SQR(dblenj / nseq[l - 1]) - 1.0; - for (int i = 0; i < neqn; i++) { - ysave[l - 1][i] = ysave[l][i] - + (ysave[l][i] - ysave[l - 1][i]) / factor; - ysavep[l - 1][i] = ysavep[l][i] - + (ysavep[l][i] - ysavep[l - 1][i]) / factor; - } - } - } - for (int i = 0; i < neqn; i++) { - dens[6 * neqn + i] = ysave[0][i]; - dens[7 * neqn + i] = h * ysavep[0][i]; - } - for (int kmi = 2; kmi <= mu; kmi++) { - int kbeg = (kmi - 2) / 2; - if (kmi == 2 * kbeg + 2) { - if (kmi == 2) { - for (int i = 0; i < neqn; i++) - ysave[0][i] = 0.5 * (dydxnew[i] + fsave[0][i]); - kbeg = 1; - } - for (int kk = kbeg; kk <= k; kk++) { - double facnj = 0.5 * pow(nseq[kk] / 2.0, kmi - 2); - int ipt = kk * kk + kk + kmi / 2 - 2; - for (int i = 0; i < neqn; i++) - ysave[kk][i] = (fsave[ipt][i] + fsave[ipt + 1][i]) - * facnj; - } - } else { - for (int kk = kbeg; kk <= k; kk++) { - double facnj = pow(nseq[kk] / 2.0, kmi - 2); - int ipt = kk * kk + kk + kbeg; - for (int i = 0; i < neqn; i++) - ysave[kk][i] = fsave[ipt][i] * facnj; - } - } - for (int j = kbeg + 1; j <= k; j++) { - double dblenj = nseq[j]; - for (int l = j; l >= kbeg + 1; l--) { - double factor = SQR(dblenj / nseq[l - 1]) - 1.0; - for (int i = 0; i < neqn; i++) - ysave[l - 1][i] = ysave[l][i] - + (ysave[l][i] - ysave[l - 1][i]) / factor; - } - } - for (int i = 0; i < neqn; i++) - dens[(kmi + 6) * neqn + i] = ysave[kbeg][i] * h2; - if (kmi == mu) - continue; - for (int kk = (kmi - 1) / 2; kk <= k; kk++) { - int lbeg = kk * kk + kmi - 2; - int lend = SQR(kk + 1) - 1; - if (kmi == 2) - lbeg++; - for (int l = lend; l >= lbeg; l--) - for (int i = 0; i < neqn; i++) - fsave[l][i] = fsave[l][i] - fsave[l - 1][i]; - if (kmi == 2) { - int l = lbeg - 1; - for (int i = 0; i < neqn; i++) - fsave[l][i] = fsave[l][i] - dydx[i]; - } - } - } - dense_interp(neqn, dens, mu); - error.val = 0.0; - if (mu >= 1) { - for (int i = 0; i < neqn; i++) - error.val += SQR(dens[(mu + 6) * neqn + i] / scale[i]); - error.val = sqrt(error.val / neqn) * errfac[mu - 1]; - } - } - - @Override - public double dense_out(final int i, final double x, final double h) { - double theta = (x - xold) / h; - double theta1 = 1.0 - theta; - int neqn = n / 2; - if (i >= neqn) - throw new IllegalArgumentException( - "no dense output for y' in StepperStoerm"); - double yinterp = dens[i] - + theta - * (dens[neqn + i] + theta1 - * (dens[2 * neqn + i] + theta - * (dens[3 * neqn + i] + theta1 - * (dens[4 * neqn + i] * theta + dens[5 - * neqn + i] - * theta1)))); - if (mu < 0) - return yinterp; - double theta05 = theta - 0.5; - double t4 = theta * theta1; - double c = dens[neqn * (mu + 6) + i]; - for (int j = mu; j > 0; j--) - c = dens[neqn * (j + 5) + i] + c * theta05 / j; - yinterp += t4 * t4 * t4 * c; - return yinterp; - } - - @Override - public void dense_interp(final int n, final double[] y, final int imit) { - double y0, y1, yp0, yp1, ypp0, ypp1, ydiff, ah, bh, ch, dh, eh, fh, gh, abh, gfh, gmf, ph0, ph1, ph2, ph3, ph4, ph5, fc1, fc2, fc3; - double[] a = new double[41]; - for (int i = 0; i < n; i++) { - y0 = y[i]; - y1 = y[3 * n + i]; - yp0 = y[n + i]; - yp1 = y[4 * n + i]; - ypp0 = y[2 * n + i] / 2.0; - ypp1 = y[5 * n + i] / 2.0; - ydiff = y1 - y0; - ah = ydiff - yp0; - bh = yp1 - ydiff; - ch = ah - ypp0; - dh = bh - ah; - eh = ypp1 - bh; - fh = dh - ch; - gh = eh - dh; - y[n + i] = ydiff; - y[2 * n + i] = -ah; - y[3 * n + i] = -dh; - y[4 * n + i] = gh; - y[5 * n + i] = fh; - if (imit < 0) - continue; - abh = ah + bh; - gfh = gh + fh; - gmf = gh - fh; - ph0 = 0.5 * (y0 + y1 + 0.25 * (-abh + 0.25 * gfh)); - ph1 = ydiff + 0.25 * (ah - bh + 0.25 * gmf); - ph2 = abh - 0.5 * gfh; - ph3 = 6.0 * (bh - ah) - 3.0 * gmf; - ph4 = 12.0 * gfh; - ph5 = 120.0 * gmf; - if (imit >= 1) { - a[1] = 64.0 * (y[7 * n + i] - ph1); - if (imit >= 3) { - a[3] = 64.0 * (y[9 * n + i] - ph3 + a[1] * 9.0 / 8.0); - if (imit >= 5) { - a[5] = 64.0 * (y[11 * n + i] - ph5 + a[3] * 15.0 / 4.0 - a[1] * 90.0); - for (int im = 7; im <= imit; im += 2) { - fc1 = im * (im - 1) * 3.0 / 16.0; - fc2 = fc1 * (im - 2) * (im - 3) * 4.0; - fc3 = im * (im - 1) * (im - 2) * (im - 3) - * (im - 4) * (im - 5); - a[im] = 64.0 * (y[(im + 6) * n + i] + fc1 - * a[im - 2] - fc2 * a[im - 4] + fc3 - * a[im - 6]); - } - } - } - } - a[0] = 64.0 * (y[6 * n + i] - ph0); - if (imit >= 2) { - a[2] = 64.0 * (y[n * 8 + i] - ph2 + a[0] * 3.0 / 8.0); - if (imit >= 4) { - a[4] = 64.0 * (y[n * 10 + i] - ph4 + a[2] * 9.0 / 4.0 - a[0] * 18.0); - for (int im = 6; im <= imit; im += 2) { - fc1 = im * (im - 1) * 3.0 / 16.0; - fc2 = fc1 * (im - 2) * (im - 3) * 4.0; - fc3 = im * (im - 1) * (im - 2) * (im - 3) * (im - 4) - * (im - 5); - a[im] = 64.0 * (y[n * (im + 6) + i] + a[im - 2] * fc1 - - a[im - 4] * fc2 + a[im - 6] * fc3); - } - } - } - for (int im = 0; im <= imit; im++) - y[n * (im + 6) + i] = a[im]; - } - } - - @Override - public void dy(final double[] y, final double htot, final int k, - final double[] yend, final intW ipt, final DerivativeInf derivs) { - double[] ytemp = new double[n]; - int nstep = nseq[k]; - double h = htot / nstep; - double h2 = 2.0 * h; - for (int i = 0; i < neqn; i++) { - ytemp[i] = y[i]; - int ni = neqn + i; - ytemp[ni] = y[ni] + h * dydx[i]; - } - double xnew = x; - int nstp2 = nstep / 2; - for (int nn = 1; nn <= nstp2; nn++) { - if (dense && nn == (nstp2 + 1) / 2) { - for (int i = 0; i < neqn; i++) { - ysavep[k][i] = ytemp[neqn + i]; - ysave[k][i] = ytemp[i] + h * ytemp[neqn + i]; - } - } - for (int i = 0; i < neqn; i++) - ytemp[i] += h2 * ytemp[neqn + i]; - xnew += h2; - derivs.derivs(xnew, ytemp, yend); - if (dense && abs(nn - (nstp2 + 1) / 2) < k + 1) { - ipt.val++; - for (int i = 0; i < neqn; i++) - fsave[ipt.val][i] = yend[i]; - } - if (nn != nstp2) { - for (int i = 0; i < neqn; i++) - ytemp[neqn + i] += h2 * yend[i]; - } - } - for (int i = 0; i < neqn; i++) { - int ni = neqn + i; - yend[ni] = ytemp[ni] + h * yend[i]; - yend[i] = ytemp[i]; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ode/Stochsim.java b/common-tools/cnuphys/numRec/src/com/nr/ode/Stochsim.java deleted file mode 100644 index a6c789778c..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ode/Stochsim.java +++ /dev/null @@ -1,155 +0,0 @@ -package com.nr.ode; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import com.nr.la.NRsparseCol; -import com.nr.ran.Ran; - -/** - * stochastic simulation of ODEs Copyright (C) Numerical Recipes Software - * 1986-2007 Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Stochsim { - public double[] s; - public double[] a; - public double[][] instate, outstate; - public NRsparseCol[] outchg, depend; - public int[] pr; - public double t, asum; - private Ran ran; - - // begin user section - static final int mm = 3; - static final int nn = 4; - - public double k0, k1, k2; - - public Stochsim(final double[] sinit) { - this(sinit, 1); - } - - public Stochsim(final double[] sinit, final int seed) { - s = sinit; - a = new double[mm]; - outchg = new NRsparseCol[mm]; - depend = new NRsparseCol[mm]; - for (int i = 0; i < mm; i++) { - outchg[i] = new NRsparseCol(); - depend[i] = new NRsparseCol(); - } - pr = new int[mm]; - t = 0; - asum = 0; - ran = new Ran(seed); - - int i, j, k, d; - describereactions(); - sparmatfill(outchg, outstate); - double[][] dep = new double[mm][mm]; - for (i = 0; i < mm; i++) - for (j = 0; j < mm; j++) { - d = 0; - for (k = 0; k < nn; k++) - d = d | ((int) instate[k][i] & (int) outstate[k][j]); - // d = d || ((int)instate[k][i] && (int)outstate[k][j]); - dep[i][j] = d; - } - sparmatfill(depend, dep); - for (i = 0; i < mm; i++) { - pr[i] = i; - if (i == 0) - a[i] = rate0(); - else if (i == 1) - a[i] = rate1(); - else - a[i] = rate2(); - asum += a[i]; - } - } - - private double rate0() { - return k0 * s[0] * s[1]; - } - - private double rate1() { - return k1 * s[1] * s[2]; - } - - private double rate2() { - return k2 * s[2]; - } - - public void describereactions() { - k0 = 0.01; - k1 = .1; - k2 = 1.; - double indat[] = { 1., 0., 0., 1., 1., 0., 0., 1., 1., 0., 0., 0. }; - instate = buildMatrix(nn, mm, indat); - double outdat[] = { -1., 0., 0., 1., -1., 0., 0., 1., -1., 0., 0., 1. }; - outstate = buildMatrix(nn, mm, outdat); - } - - // end user section - - public double step() { - int i, n, m, k = 0; - double tau, atarg, sum, anew; - if (asum == 0.) { - t *= 2.; - return t; - } - tau = -log(ran.doub()) / asum; - atarg = ran.doub() * asum; - sum = a[pr[0]]; - while (sum < atarg) - sum += a[pr[++k]]; - m = pr[k]; - if (k > 0) { - swap(pr, k, k - 1); - } - if (k == mm - 1) - asum = sum; - n = outchg[m].nvals; - for (i = 0; i < n; i++) { - k = outchg[m].row_ind[i]; - s[k] += outchg[m].val[i]; - } - n = depend[m].nvals; - for (i = 0; i < n; i++) { - k = depend[m].row_ind[i]; - if (k == 0) - anew = rate0(); - else if (k == 1) - anew = rate1(); - else - anew = rate2(); - asum += (anew - a[k]); - a[k] = anew; - } - if (t * asum < 0.1) - for (asum = 0., i = 0; i < mm; i++) - asum += a[i]; - return (t += tau); - } - - public static void sparmatfill(final NRsparseCol[] sparmat, - final double[][] fullmat) { - int n, m, nz, nn = fullmat.length, mm = fullmat[0].length; - if (sparmat.length != mm) - throw new IllegalArgumentException("bad sizes"); - for (m = 0; m < mm; m++) { - for (nz = n = 0; n < nn; n++) - if (fullmat[n][m] != 0) - nz++; - sparmat[m].resize(nn, nz); - for (nz = n = 0; n < nn; n++) - if (fullmat[n][m] != 0) { - sparmat[m].row_ind[nz] = n; - sparmat[m].val[nz++] = fullmat[n][m]; - } - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/pde/Mgfas.java b/common-tools/cnuphys/numRec/src/com/nr/pde/Mgfas.java deleted file mode 100644 index 5341c47e75..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/pde/Mgfas.java +++ /dev/null @@ -1,211 +0,0 @@ -package com.nr.pde; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -import org.netlib.util.doubleW; - -public class Mgfas { - int n, ng; - double[][] uj, uj1; - // NRvector *> rho; - double[][][] rho; - - public double[][] u; - - /** - * - * @param u - * @param maxcyc - */ - public Mgfas(final double[][] u, final int maxcyc) { - this.u = u; - n = u.length; - ng = 0; - int nn = n; - while ((nn >>>= 1) != 0) - ng++; - if ((n - 1) != (1 << ng)) - throw new IllegalArgumentException( - "n-1 must be a power of 2 in mgfas."); - nn = n; - int ngrid = ng - 1; - rho = new double[ng][][]; - // rho.resize(ng); - rho[ngrid] = new double[nn][nn]; - copyAssign(rho[ngrid], u); - while (nn > 3) { - nn = nn / 2 + 1; - rho[--ngrid] = new double[nn][nn]; - rstrct(rho[ngrid], rho[ngrid + 1]); - } - nn = 3; - uj = new double[nn][nn]; - slvsm2(uj, rho[0]); - for (int j = 1; j < ng; j++) { - nn = 2 * nn - 1; - uj1 = uj; - uj = new double[nn][nn]; - double[][] temp = new double[nn][nn]; - interp(uj, uj1); - for (int jcycle = 0; jcycle < maxcyc; jcycle++) { - doubleW trerr = new doubleW(1.0); - mg(j, uj, temp, rho, trerr); - lop(temp, uj); - matsub(temp, rho[j], temp); - double res = anorm2(temp); - if (res < trerr.val) - break; - } - } - this.u = uj; - } - - public static void matadd(final double[][] a, final double[][] b, - final double[][] c) { - int n = a.length; - for (int j = 0; j < n; j++) - for (int i = 0; i < n; i++) - c[i][j] = a[i][j] + b[i][j]; - } - - public static void matsub(final double[][] a, final double[][] b, - final double[][] c) { - int n = a.length; - for (int j = 0; j < n; j++) - for (int i = 0; i < n; i++) - c[i][j] = a[i][j] - b[i][j]; - } - - public static void slvsm2(final double[][] u, final double[][] rhs) { - double h = 0.5; - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - u[i][j] = 0.0; - double fact = 2.0 / (h * h); - double disc = sqrt(fact * fact + rhs[1][1]); - u[1][1] = -rhs[1][1] / (fact + disc); - } - - public static void relax2(final double[][] u, final double[][] rhs) { - int n = u.length; - int jsw = 1; - double h = 1.0 / (n - 1); - double h2i = 1.0 / (h * h); - double foh2 = -4.0 * h2i; - for (int ipass = 0; ipass < 2; ipass++, jsw = 3 - jsw) { - int isw = jsw; - for (int j = 1; j < n - 1; j++, isw = 3 - isw) { - for (int i = isw; i < n - 1; i += 2) { - double res = h2i - * (u[i + 1][j] + u[i - 1][j] + u[i][j + 1] - + u[i][j - 1] - 4.0 * u[i][j]) + u[i][j] - * u[i][j] - rhs[i][j]; - u[i][j] -= res / (foh2 + 2.0 * u[i][j]); - } - } - } - } - - public static void rstrct(final double[][] uc, final double[][] uf) { - int nc = uc.length; - int ncc = 2 * nc - 2; - for (int jf = 2, jc = 1; jc < nc - 1; jc++, jf += 2) { - for (int iif = 2, ic = 1; ic < nc - 1; ic++, iif += 2) { - uc[ic][jc] = 0.5 - * uf[iif][jf] - + 0.125 - * (uf[iif + 1][jf] + uf[iif - 1][jf] + uf[iif][jf + 1] + uf[iif][jf - 1]); - } - } - for (int jc = 0, ic = 0; ic < nc; ic++, jc += 2) { - uc[ic][0] = uf[jc][0]; - uc[ic][nc - 1] = uf[jc][ncc]; - } - for (int jc = 0, ic = 0; ic < nc; ic++, jc += 2) { - uc[0][ic] = uf[0][jc]; - uc[nc - 1][ic] = uf[ncc][jc]; - } - } - - public static void lop(final double[][] out, final double[][] u) { - int n = u.length; - double h = 1.0 / (n - 1); - double h2i = 1.0 / (h * h); - for (int j = 1; j < n - 1; j++) - for (int i = 1; i < n - 1; i++) - out[i][j] = h2i - * (u[i + 1][j] + u[i - 1][j] + u[i][j + 1] - + u[i][j - 1] - 4.0 * u[i][j]) + u[i][j] - * u[i][j]; - for (int i = 0; i < n; i++) - out[i][0] = out[i][n - 1] = out[0][i] = out[n - 1][i] = 0.0; - } - - public static void interp(final double[][] uf, final double[][] uc) { - int nf = uf.length; - int nc = nf / 2 + 1; - for (int jc = 0; jc < nc; jc++) - for (int ic = 0; ic < nc; ic++) - uf[2 * ic][2 * jc] = uc[ic][jc]; - for (int jf = 0; jf < nf; jf += 2) - for (int iif = 1; iif < nf - 1; iif += 2) - uf[iif][jf] = 0.5 * (uf[iif + 1][jf] + uf[iif - 1][jf]); - for (int jf = 1; jf < nf - 1; jf += 2) - for (int iif = 0; iif < nf; iif++) - uf[iif][jf] = 0.5 * (uf[iif][jf + 1] + uf[iif][jf - 1]); - } - - public static double anorm2(final double[][] a) { - double sum = 0.0; - int n = a.length; - for (int j = 0; j < n; j++) - for (int i = 0; i < n; i++) - sum += a[i][j] * a[i][j]; - return sqrt(sum) / n; - } - - public static void mg(final int j, final double[][] u, - final double[][] rhs, final double[][][] rho, final doubleW trerr) { - final int NPRE = 1, NPOST = 1; - final double ALPHA = 0.33; - doubleW dum = new doubleW(-1.0); - int nf = u.length; - int nc = (nf + 1) / 2; - double[][] temp = new double[nf][nf]; - if (j == 0) { - matadd(rhs, rho[j], temp); - slvsm2(u, temp); - } else { - double[][] v = new double[nc][nc], ut = new double[nc][nc], tau = new double[nc][nc], tempc = new double[nc][nc]; - for (int jpre = 0; jpre < NPRE; jpre++) { - if (trerr.val < 0.0) { - matadd(rhs, rho[j], temp); - relax2(u, temp); - } else - relax2(u, rho[j]); - } - rstrct(ut, u); - copyAssign(v, ut); - lop(tau, ut); - lop(temp, u); - if (trerr.val < 0.0) - matsub(temp, rhs, temp); - rstrct(tempc, temp); - matsub(tau, tempc, tau); - if (trerr.val > 0.0) - trerr.val = ALPHA * anorm2(tau); - mg(j - 1, v, tau, rho, dum); - matsub(v, ut, tempc); - interp(temp, tempc); - matadd(u, temp, u); - for (int jpost = 0; jpost < NPOST; jpost++) { - if (trerr.val < 0.0) { - matadd(rhs, rho[j], temp); - relax2(u, temp); - } else - relax2(u, rho[j]); - } - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/pde/Mglin.java b/common-tools/cnuphys/numRec/src/com/nr/pde/Mglin.java deleted file mode 100644 index 3744fd2018..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/pde/Mglin.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.nr.pde; - -import static com.nr.NRUtil.*; - -public class Mglin { - int n, ng; - double[][] uj, uj1; - - // NRvector *> rho; - double[][][] rho; - public double[][] u; - - public Mglin(final double[][] u, final int ncycle) { - this.u = u; - n = u.length; - ng = 0; - int nn = n; - while ((nn >>>= 1) != 0) - ng++; - if ((n - 1) != (1 << ng)) - throw new IllegalArgumentException( - "n-1 must be a power of 2 in mglin."); - nn = n; - int ngrid = ng - 1; - rho = new double[ng][][]; - rho[ngrid] = new double[nn][nn]; - copyAssign(rho[ngrid], u); - while (nn > 3) { - nn = nn / 2 + 1; - rho[--ngrid] = new double[nn][nn]; - rstrct(rho[ngrid], rho[ngrid + 1]); - } - nn = 3; - uj = new double[nn][nn]; - slvsml(uj, rho[0]); - for (int j = 1; j < ng; j++) { - nn = 2 * nn - 1; - uj1 = uj; - uj = new double[nn][nn]; - interp(uj, uj1); - for (int jcycle = 0; jcycle < ncycle; jcycle++) - mg(j, uj, rho[j]); - } - this.u = uj; - } - - public static void interp(final double[][] uf, final double[][] uc) { - int nf = uf.length; - int nc = nf / 2 + 1; - for (int jc = 0; jc < nc; jc++) - for (int ic = 0; ic < nc; ic++) - uf[2 * ic][2 * jc] = uc[ic][jc]; - for (int jf = 0; jf < nf; jf += 2) - for (int iif = 1; iif < nf - 1; iif += 2) - uf[iif][jf] = 0.5 * (uf[iif + 1][jf] + uf[iif - 1][jf]); - for (int jf = 1; jf < nf - 1; jf += 2) - for (int iif = 0; iif < nf; iif++) - uf[iif][jf] = 0.5 * (uf[iif][jf + 1] + uf[iif][jf - 1]); - } - - public static void addint(final double[][] uf, final double[][] uc, - final double[][] res) { - int nf = uf.length; - interp(res, uc); - for (int j = 0; j < nf; j++) - for (int i = 0; i < nf; i++) - uf[i][j] += res[i][j]; - } - - public static void slvsml(final double[][] u, final double[][] rhs) { - double h = 0.5; - for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - u[i][j] = 0.0; - u[1][1] = -h * h * rhs[1][1] / 4.0; - } - - public static void relax(final double[][] u, final double[][] rhs) { - int n = u.length; - double h = 1.0 / (n - 1); - double h2 = h * h; - for (int ipass = 0, jsw = 1; ipass < 2; ipass++, jsw = 3 - jsw) { - for (int j = 1, isw = jsw; j < n - 1; j++, isw = 3 - isw) - for (int i = isw; i < n - 1; i += 2) - u[i][j] = 0.25 * (u[i + 1][j] + u[i - 1][j] + u[i][j + 1] - + u[i][j - 1] - h2 * rhs[i][j]); - } - } - - public static void resid(final double[][] res, final double[][] u, - final double[][] rhs) { - int n = u.length; - double h = 1.0 / (n - 1); - double h2i = 1.0 / (h * h); - for (int j = 1; j < n - 1; j++) - for (int i = 1; i < n - 1; i++) - res[i][j] = -h2i - * (u[i + 1][j] + u[i - 1][j] + u[i][j + 1] - + u[i][j - 1] - 4.0 * u[i][j]) + rhs[i][j]; - for (int i = 0; i < n; i++) - res[i][0] = res[i][n - 1] = res[0][i] = res[n - 1][i] = 0.0; - } - - public static void rstrct(final double[][] uc, final double[][] uf) { - int nc = uc.length; - int ncc = 2 * nc - 2; - for (int jf = 2, jc = 1; jc < nc - 1; jc++, jf += 2) { - for (int iif = 2, ic = 1; ic < nc - 1; ic++, iif += 2) { - uc[ic][jc] = 0.5 - * uf[iif][jf] - + 0.125 - * (uf[iif + 1][jf] + uf[iif - 1][jf] + uf[iif][jf + 1] + uf[iif][jf - 1]); - } - } - for (int jc = 0, ic = 0; ic < nc; ic++, jc += 2) { - uc[ic][0] = uf[jc][0]; - uc[ic][nc - 1] = uf[jc][ncc]; - } - for (int jc = 0, ic = 0; ic < nc; ic++, jc += 2) { - uc[0][ic] = uf[0][jc]; - uc[nc - 1][ic] = uf[ncc][jc]; - } - } - - public static void mg(final int j, final double[][] u, final double[][] rhs) { - final int NPRE = 1, NPOST = 1; - int nf = u.length; - int nc = (nf + 1) / 2; - if (j == 0) - slvsml(u, rhs); - else { - double[][] res = new double[nc][nc], v = new double[nc][nc], temp = new double[nf][nf]; - for (int jpre = 0; jpre < NPRE; jpre++) - relax(u, rhs); - resid(temp, u, rhs); - rstrct(res, temp); - mg(j - 1, v, res); - addint(u, v, temp); - for (int jpost = 0; jpost < NPOST; jpost++) - relax(u, rhs); - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/pde/Relaxation.java b/common-tools/cnuphys/numRec/src/com/nr/pde/Relaxation.java deleted file mode 100644 index 9369b4eed2..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/pde/Relaxation.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.nr.pde; - -import static java.lang.Math.*; - -public class Relaxation { - private Relaxation() { - } - - public static void sor(final double[][] a, final double[][] b, - final double[][] c, final double[][] d, final double[][] e, - final double[][] f, final double[][] u, final double rjac) { - final int MAXITS = 1000; - final double EPS = 1.0e-13; - double anormf = 0.0, omega = 1.0; - int jmax = a.length; - for (int j = 1; j < jmax - 1; j++) - for (int l = 1; l < jmax - 1; l++) - anormf += abs(f[j][l]); - for (int n = 0; n < MAXITS; n++) { - double anorm = 0.0; - int jsw = 1; - for (int ipass = 0; ipass < 2; ipass++) { - int lsw = jsw; - for (int j = 1; j < jmax - 1; j++) { - for (int l = lsw; l < jmax - 1; l += 2) { - double resid = a[j][l] * u[j + 1][l] + b[j][l] - * u[j - 1][l] + c[j][l] * u[j][l + 1] + d[j][l] - * u[j][l - 1] + e[j][l] * u[j][l] - f[j][l]; - anorm += abs(resid); - u[j][l] -= omega * resid / e[j][l]; - } - lsw = 3 - lsw; - } - jsw = 3 - jsw; - omega = (n == 0 && ipass == 0 ? 1.0 / (1.0 - 0.5 * rjac * rjac) - : 1.0 / (1.0 - 0.25 * rjac * rjac * omega)); - } - if (anorm < EPS * anormf) - return; - } - throw new IllegalArgumentException("MAXITS exceeded"); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/pde/Weights.java b/common-tools/cnuphys/numRec/src/com/nr/pde/Weights.java deleted file mode 100644 index bc8bac0575..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/pde/Weights.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.nr.pde; - -import static java.lang.Math.*; - -/** - * Differentiation matrix for spectral methods - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Weights { - private Weights() { - } - - public static void weights(final double z, final double[] x, - final double[][] c) { - int n = c.length - 1; - int m = c[0].length - 1; - double c1 = 1.0; - double c4 = x[0] - z; - for (int k = 0; k <= m; k++) - for (int j = 0; j <= n; j++) - c[j][k] = 0.0; - c[0][0] = 1.0; - for (int i = 1; i <= n; i++) { - int mn = min(i, m); - double c2 = 1.0; - double c5 = c4; - c4 = x[i] - z; - for (int j = 0; j < i; j++) { - double c3 = x[i] - x[j]; - c2 = c2 * c3; - if (j == i - 1) { - for (int k = mn; k > 0; k--) - c[i][k] = c1 * (k * c[i - 1][k - 1] - c5 * c[i - 1][k]) - / c2; - c[i][0] = -c1 * c5 * c[i - 1][0] / c2; - } - for (int k = mn; k > 0; k--) - c[j][k] = (c4 * c[j][k] - k * c[j][k - 1]) / c3; - c[j][0] = c4 * c[j][0] / c3; - } - c1 = c2; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Binomialdev.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Binomialdev.java deleted file mode 100644 index 416e738643..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Binomialdev.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.nr.ran; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; -import static com.nr.sf.Gamma.*; - -/** - * Binomial Deviates - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Binomialdev extends Ran { - double pp, p, pb, expnp, np, glnp, plog, pclog, sq; - int n, swch; - long uz, uo, unfin, diff, rltp; - int[] pbits = new int[5]; - double[] cdf = new double[64]; - double[] logfact = new double[1024]; - - public Binomialdev(final int nn, final double ppp, final long i) { - super(i); - pp = ppp; - n = nn; - - int j; - pb = p = (pp <= 0.5 ? pp : 1.0 - pp); - if (n <= 64) { - uz = 0; - uo = 0xffffffffffffffffL; - rltp = 0; - for (j = 0; j < 5; j++) - pbits[j] = 1 & ((int) (pb *= 2.)); - pb -= floor(pb); - swch = 0; - } else if (n * p < 30.) { - cdf[0] = exp(n * log(1 - p)); - for (j = 1; j < 64; j++) - cdf[j] = cdf[j - 1] - + exp(gammln(n + 1.) - gammln(j + 1.) - - gammln(n - j + 1.) + j * log(p) + (n - j) - * log(1. - p)); - swch = 1; - } else { - np = n * p; - glnp = gammln(n + 1.); - plog = log(p); - pclog = log(1. - p); - sq = sqrt(np * (1. - p)); - if (n < 1024) - for (j = 0; j <= n; j++) - logfact[j] = gammln(j + 1.); - swch = 2; - } - } - - public int dev() { - int j, k, kl, km; - double y, u, v, u2, v2, b; - if (swch == 0) { - unfin = uo; - for (j = 0; j < 5; j++) { - diff = unfin & (int64() ^ (pbits[j] != 0 ? uo : uz)); - if (pbits[j] != 0) - rltp |= diff; - else - rltp = rltp & ~diff; - unfin = unfin & ~diff; - } - k = 0; - for (j = 0; j < n; j++) { - if ((unfin & 1) != 0) { - if (doub() < pb) - ++k; - } else { - if ((rltp & 1) != 0) - ++k; - } - unfin >>>= 1; - rltp >>>= 1; - } - } else if (swch == 1) { - y = doub(); - kl = -1; - k = 64; - while (k - kl > 1) { - km = (kl + k) / 2; - if (y < cdf[km]) - k = km; - else - kl = km; - } - } else { - for (;;) { - u = 0.645 * doub(); - v = -0.63 + 1.25 * doub(); - v2 = SQR(v); - if (v >= 0.) { - if (v2 > 6.5 * u * (0.645 - u) * (u + 0.2)) - continue; - } else { - if (v2 > 8.4 * u * (0.645 - u) * (u + 0.1)) - continue; - } - k = (int) (floor(sq * (v / u) + np + 0.5)); - if (k < 0 || k > n) - continue; - u2 = SQR(u); - if (v >= 0.) { - if (v2 < 12.25 * u2 * (0.615 - u) * (0.92 - u)) - break; - } else { - if (v2 < 7.84 * u2 * (0.615 - u) * (1.2 - u)) - break; - } - b = sq - * exp(glnp - + k - * plog - + (n - k) - * pclog - - (n < 1024 ? logfact[k] + logfact[n - k] - : gammln(k + 1.) + gammln(n - k + 1.))); - if (u2 < b) - break; - } - } - if (p != pp) - k = n - k; - return k; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Cauchydev.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Cauchydev.java deleted file mode 100644 index 35a0b9dd32..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Cauchydev.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.nr.ran; - -import static com.nr.NRUtil.*; - -/** - * Cauchy deviates - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Cauchydev extends Ran { - double mu, sig; - - public Cauchydev(final double mmu, final double ssig, final long i) { - super(i); - mu = mmu; - sig = ssig; - } - - public double dev() { - double v1, v2; - do { - v1 = 2.0 * doub() - 1.0; - v2 = doub(); - } while (SQR(v1) + SQR(v2) >= 1. || v2 == 0.); - return mu + sig * v1 / v2; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Expondev.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Expondev.java deleted file mode 100644 index 1cc6536fec..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Expondev.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.nr.ran; - -import static java.lang.Math.*; - -/** - * Structure for exponential deviates. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Expondev extends Ran { - double beta; - - /** - * Constructor arguments are ˇ and a random sequence seed. - * - * @param bbeta - * @param i - */ - public Expondev(final double bbeta, final long i) { - super(i); - beta = bbeta; - } - - /** - * Return an exponential deviate. - * - * @return - */ - public double dev() { - double u; - do - u = doub(); - while (u == 0.); - return -log(u) / beta; - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Gammadev.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Gammadev.java deleted file mode 100644 index cd11ec73ef..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Gammadev.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.nr.ran; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -public class Gammadev extends Normaldev { - double alph, oalph, bet; - double a1, a2; - - public Gammadev(final double aalph, final double bbet, final long i) { - super(0., 1., i); - alph = aalph; - oalph = aalph; - bet = bbet; - - if (alph <= 0.) - throw new IllegalArgumentException("bad alph in Gammadev"); - if (alph < 1.) - alph += 1.; - a1 = alph - 1. / 3.; - a2 = 1. / sqrt(9. * a1); - } - - @Override - public double dev() { - double u, v, x; - do { - do { - x = super.dev(); - v = 1. + a2 * x; - } while (v <= 0.); - v = v * v * v; - u = doub(); - } while (u > 1. - 0.331 * SQR(SQR(x)) - && log(u) > 0.5 * SQR(x) + a1 * (1. - v + log(v))); - if (alph == oalph) - return a1 * v / bet; - else { - do - u = doub(); - while (u == 0.); - return pow(u, 1. / oalph) * a1 * v / bet; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Hash.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Hash.java deleted file mode 100644 index af166eb7bc..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Hash.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.nr.ran; - -import java.util.Vector; - -public abstract class Hash extends Hashtable { - Vector els; - - public Hash(final int nh, final int nm) { - super(nh, nm); - els = new Vector(nm); - - // init Vector space. - for (int i = 0; i < nm; i++) - els.add(null); - } - - public void set(final K key, final V el) { - els.set(iset(key), el); - } - - public int get(final K key, final V[] el, final int on) { - int ll = iget(key); - if (ll < 0) - return 0; - el[on] = els.get(ll); - return 1; - } - - public V get(final K key) { - int ll = iget(key); - if (ll < 0) - return null; - return els.get(ll); - } - - public int count(final K key) { - int ll = iget(key); - return (ll < 0 ? 0 : 1); - } - - public int erase(final K key) { - return (ierase(key) < 0 ? 0 : 1); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/HashAll.java b/common-tools/cnuphys/numRec/src/com/nr/ran/HashAll.java deleted file mode 100644 index f7347f2cc2..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/HashAll.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.nr.ran; - -import org.netlib.util.intW; - -public class HashAll { - private HashAll() { - } - - /** - * Pseudo-DES hashing of the 64-bit word (lword,rword). Both 32-bit - * arguments are returned hashed on all bits. - * - * @param lword - * @param rword - */ - public static void psdes(final intW lword, final intW rword) { - final int NITER = 2; - final int[] c1 = { 0xbaa96887, 0x1e17d32c, 0x03bcdc3c, 0x0f33d1b2 }; - final int[] c2 = { 0x4b0f3b58, 0xe874f0c3, 0x6955c5a6, 0x55a7ca46 }; - int i, ia, ib, iswap, itmph = 0, itmpl = 0; - for (i = 0; i < NITER; i++) { - ia = (iswap = rword.val) ^ c1[i]; - itmpl = ia & 0xffff; - itmph = ia >>> 16; - ib = itmpl * itmpl + ~(itmph * itmph); - rword.val = lword.val - ^ (((ia = (ib >>> 16) | ((ib & 0xffff) << 16)) ^ c2[i]) + itmpl - * itmph); - lword.val = iswap; - } - } - - /** - * Replace the array arr by a same-sized hash, all of whose bits depend on - * all of the bits in arr. Uses psdes for the mutual hash of two 32-bit - * words. - * - * @param arr - */ - public static void hashall(final int[] arr) { - int m = arr.length, n = m - 1; - n |= n >> 1; - n |= n >> 2; - n |= n >> 4; - n |= n >> 8; - n |= n >> 16; - n++; - int nb = n, nb2 = n >> 1, j, jb; - if (n < 2) - throw new IllegalArgumentException("size must be > 1"); - while (nb > 1) { - for (jb = 0; jb < n - nb + 1; jb += nb) - for (j = 0; j < nb2; j++) - if (jb + j + nb2 < m) { - intW lword = new intW(arr[jb + j]); - intW rword = new intW(arr[jb + j + nb2]); - psdes(lword, rword); - arr[jb + j] = lword.val; - arr[jb + j + nb2] = rword.val; - } - nb = nb2; - nb2 >>= 1; - } - nb2 = n >> 1; - if (m != n) - for (j = nb2; j < m; j++) { - intW lword = new intW(arr[j]); - intW rword = new intW(arr[j - nb2]); - psdes(lword, rword); - arr[j] = lword.val; - arr[j - nb2] = rword.val; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Hashfn1.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Hashfn1.java deleted file mode 100644 index 311a556370..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Hashfn1.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.nr.ran; - -public class Hashfn1 { - Ranhash hasher = new Ranhash(); - - public Hashfn1(final int nn) { - } - - public long fn(final int key) { - return hasher.int64p(key); - } - - public long fn(final long key) { - return hasher.int64p(key); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Hashfn2.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Hashfn2.java deleted file mode 100644 index 298d078c71..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Hashfn2.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.nr.ran; - -public class Hashfn2 { - static long[] hashfn_tab = new long[256]; - - private long h; - - // int n; final int nn - - public Hashfn2() { // - // n = nn; - // if (n == 1) n = 0; - h = 0x544B2FBACAAF1684L; - for (int j = 0; j < 256; j++) { - for (int i = 0; i < 31; i++) { - h = (h >>> 7) ^ h; - h = (h << 11) ^ h; - h = (h >>> 10) ^ h; - } - hashfn_tab[j] = h; - } - } - - public long fn(final byte[] key) { - h = 0xBB40E64DA205B064L; - int j = 0; - while (j < key.length) { - h = (h * 7664345821815920749L) ^ hashfn_tab[key[j] & 0xFF]; - j++; - } - return h & 0x7FFFFFFFFFFFFFFFL; - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Hashtable.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Hashtable.java deleted file mode 100644 index ebd1164dfa..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Hashtable.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.nr.ran; - -public abstract class Hashtable { - int nhash, nmax, nn, ng; - int[] htable, next, garbg; - long[] thehash; - - public Hashtable(final int nh, final int nm) { - nhash = nh; - nmax = nm; - nn = 0; - ng = 0; - htable = new int[nh]; - next = new int[nm]; - garbg = new int[nm]; - thehash = new long[nm]; - for (int j = 0; j < nh; j++) { - htable[j] = -1; - } - } - - public abstract long fn(K k); - - public int iget(final K key) { - int j, k; - long pp = fn(key); - j = (int) (pp % nhash); - for (k = htable[j]; k != -1; k = next[k]) { - if (thehash[k] == pp) { - return k; - } - } - return -1; - } - - public int iset(final K key) { - int j, k, kprev = 0; - long pp = fn(key); - j = (int) (pp % nhash); - if (htable[j] == -1) { - k = ng != 0 ? garbg[--ng] : nn++; - htable[j] = k; - } else { - for (k = htable[j]; k != -1; k = next[k]) { - if (thehash[k] == pp) { - return k; - } - kprev = k; - } - k = ng != 0 ? garbg[--ng] : nn++; - next[kprev] = k; - } - if (k >= nmax) - throw new IllegalArgumentException("storing too many values"); - thehash[k] = pp; - next[k] = -1; - return k; - } - - public int ierase(final K key) { - int j, k, kprev; - long pp = fn(key); - j = (int) (pp % nhash); - if (htable[j] == -1) - return -1; - kprev = -1; - for (k = htable[j]; k != -1; k = next[k]) { - if (thehash[k] == pp) { - if (kprev == -1) - htable[j] = next[k]; - else - next[kprev] = next[k]; - garbg[ng++] = k; - return k; - } - kprev = k; - } - return -1; - } - - public int ireserve() { - int k = ng != 0 ? garbg[--ng] : nn++; - if (k >= nmax) - throw new IllegalArgumentException("reserving too many values"); - next[k] = -2; - return k; - } - - public int irelinquish(final int k) { - if (next[k] != -2) { - return -1; - } - garbg[ng++] = k; - return k; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Logisticdev.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Logisticdev.java deleted file mode 100644 index 6392ad4a4f..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Logisticdev.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.nr.ran; - -import static java.lang.Math.*; - -/** - * Structure for logistic deviates. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Logisticdev extends Ran { - double mu, sig; - - /** - * Constructor arguments are mu and sig random sequence seed. - * - * @param mmu - * @param ssig - * @param i - */ - public Logisticdev(final double mmu, final double ssig, final long i) { - super(i); - mu = mmu; - sig = ssig; - } - - public double dev() { - double u; - do - u = doub(); - while (u * (1. - u) == 0.); - return mu + 0.551328895421792050 * sig * log(u / (1. - u)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/MCintegrate.java b/common-tools/cnuphys/numRec/src/com/nr/ran/MCintegrate.java deleted file mode 100644 index cc89b0af19..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/MCintegrate.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.nr.ran; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -/** - * - * Monte Carlo integration - * - * Object for Monte Carlo integration of one or more functions in an - * ndim-dimensional region - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public abstract class MCintegrate { - private int ndim, nfun, n; - public double[] ff, fferr; - private double[] xlo, xhi, x, xx, fn, sf, sferr; - private double vol; - private Ran ran; - - boolean xmappValid = false; - - public abstract double[] funcs(final double[] x); - - public abstract boolean inregion(final double[] x); - - public abstract double[] xmap(final double[] x); - - public MCintegrate(final double[] xlow, final double[] xhigh, - final int ranseed, boolean xmappValid) { - this.xmappValid = xmappValid; - ndim = xlow.length; - n = 0; - xlo = buildVector(xlow); - xhi = buildVector(xhigh); - x = new double[ndim]; - xx = new double[ndim]; - vol = 1.; - ran = new Ran(ranseed); - if (xmappValid) - nfun = funcs(xmap(xlo)).length; - else - nfun = funcs(xlo).length; - ff = new double[nfun]; - fferr = new double[nfun]; - fn = new double[nfun]; - sf = new double[nfun]; - sferr = new double[nfun]; - for (int j = 0; j < ndim; j++) - vol *= abs(xhi[j] - xlo[j]); - } - - public void step(final int nstep) { - int i, j; - for (i = 0; i < nstep; i++) { - for (j = 0; j < ndim; j++) - x[j] = xlo[j] + (xhi[j] - xlo[j]) * ran.doub(); - if (xmappValid) - xx = xmap(x); - else - xx = x; - if (inregion(xx)) { - fn = funcs(xx); - for (j = 0; j < nfun; j++) { - sf[j] += fn[j]; - sferr[j] += SQR(fn[j]); - } - } - } - n += nstep; - } - - public void calcanswers() { - for (int j = 0; j < nfun; j++) { - ff[j] = vol * sf[j] / n; - fferr[j] = vol * sqrt((sferr[j] / n - SQR(sf[j] / n)) / n); - } - } - - public double[] torusfuncs(final double[] x) { - double den = 1.; - double[] f = new double[4]; - f[0] = den; - for (int i = 1; i < 4; i++) - f[i] = x[i - 1] * den; - return f; - } - - public boolean torusregion(final double[] x) { - return SQR(x[2]) + SQR(sqrt(SQR(x[0]) + SQR(x[1])) - 3.) <= 1.; - } - - public double[] torusmap(final double[] s) { - double[] xx = buildVector(s); - xx[2] = 0.2 * log(5. * s[2]); - return xx; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Mhash.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Mhash.java deleted file mode 100644 index 6e377acc0b..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Mhash.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.nr.ran; - -import java.util.Vector; - -public abstract class Mhash extends Hashtable { - private Vector els; - /** - * Links to next sister element under a single key. - */ - private int[] nextsis; - - private int nextget; - - public Mhash(final int nh, final int nm) { - super(nh, nm); - nextget = -1; - els = new Vector(nm); - - // init Vector space. - for (int i = 0; i < nm; i++) - els.add(null); - nextsis = new int[nm]; - for (int j = 0; j < nm; j++) { - nextsis[j] = -2; - } // Initialize to "empty". - } - - /** - * Store an element el under key. Return index in 0..nmax-1, giving the - * storage location utilized. - * - * @param key - * @param el - * @return - */ - public int store(final K key, final V el) { - int j, k; - j = iset(key); - if (nextsis[j] == -2) { - els.set(j, el); - nextsis[j] = -1; - return j; - } else { - while (nextsis[j] != -1) { - j = nextsis[j]; - } - k = ireserve(); - els.set(k, el); - nextsis[j] = k; - nextsis[k] = -1; - return k; - } - } - - /** - * Erase an element el previously stored under key. Return 1 for success, or - * 0 if no matching element is found. Note: The == operation must be defined - * for the type elT. - * - * @param key - * @param el - * @return - */ - public int erase(final K key, final V el) { - int j = -1, kp = -1, kpp = -1; - int k = iget(key); - while (k >= 0) { - if (j < 0 && el.equals(els.get(k))) - j = k; - kpp = kp; - kp = k; - k = nextsis[k]; - } - if (j < 0) - return 0; - if (kpp < 0) { - ierase(key); - nextsis[j] = -2; - } else { - if (j != kp) - els.set(j, els.get(kp)); - nextsis[kpp] = -1; - irelinquish(kp); - nextsis[kp] = -2; - } - return 1; - } - - /** - * Return the number of elements stored under key, 0 if none. - * - * @param key - * @return - */ - public int count(final K key) { - int next, n = 1; - if ((next = iget(key)) < 0) - return 0; - while ((next = nextsis[next]) >= 0) { - n++; - } - return n; - } - - /** - * Initialize nextget so that it points to the first element stored under - * key. Return 1 for success, or 0 if no such element. - * - * @param key - * @return - */ - public int getinit(final K key) { - nextget = iget(key); - return ((nextget < 0) ? 0 : 1); - } - - /** - * If nextget points validly, copy its element into el, update nextget to - * the next element with the same key, and return 1. Otherwise, do not - * modify el, and return 0. - * - * @param el - * @param on - * @return - */ - public int getnext(final V[] el, final int on) { - if (nextget < 0) { - return 0; - } - el[on] = els.get(nextget); - nextget = nextsis[nextget]; - return 1; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Miser.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Miser.java deleted file mode 100644 index 204d98aa46..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Miser.java +++ /dev/null @@ -1,133 +0,0 @@ -package com.nr.ran; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -import org.netlib.util.doubleW; - -import com.nr.RealValueFun; - -public class Miser { - private Miser() { - } - - static final int RANSEED = 5331; - static Ran ran = new Ran(RANSEED); - static int iran = 0; - - public static void ranpt(final double[] pt, final double[] regn) { - int j, n = pt.length; - for (j = 0; j < n; j++) - pt[j] = regn[j] + (regn[n + j] - regn[j]) * ran.doub(); - } - - /** - * Monte Carlo samples a user-supplied ndim-dimensional function func in a - * rectangular volume specified by regn[0..2*ndim-1], a vector consisting of - * ndim "lower-left" coordinates of the region followed by ndim - * "upper-right" coordinates. The function is sampled a total of npts times, - * at locations determined by the method of recursive stratified sampling. - * The mean value of the function in the region is returned as ave; an - * estimate of the statistical uncertainty of ave (square of standard - * deviation) is returned as var. The input parameter dith should normally - * be set to zero, but can be set to (e.g.) 0.1 if func's active region - * falls on the boundary of a power-of-two subdivision of region. - * - * @param func - * @param regn - * @param npts - * @param dith - * @param ave - * @param var - */ - public static void miser(final RealValueFun func, final double[] regn, - final int npts, final double dith, final doubleW ave, - final doubleW var) { - final int MNPT = 15, MNBS = 60; - final double PFAC = 0.1, TINY = 1.0e-30, BIG = 1.0e30; - int j, jb, n, ndim, npre, nptl, nptr; - double fracl, fval, rgl, rgm, rgr, s, sigl, siglb, sigr, sigrb; - double sum, sumb, summ, summ2; - doubleW avel = new doubleW(0); - doubleW varl = new doubleW(0); - - ndim = regn.length / 2; - double[] pt = new double[ndim]; - if (npts < MNBS) { - summ = summ2 = 0.0; - for (n = 0; n < npts; n++) { - ranpt(pt, regn); - fval = func.funk(pt); - summ += fval; - summ2 += fval * fval; - } - ave.val = summ / npts; - var.val = max(TINY, (summ2 - summ * summ / npts) / (npts * npts)); - } else { - double[] rmid = new double[ndim]; - npre = max((int) (npts * PFAC), MNPT); - double[] fmaxl = new double[ndim]; - double[] fmaxr = new double[ndim]; - double[] fminl = new double[ndim]; - double[] fminr = new double[ndim]; - for (j = 0; j < ndim; j++) { - iran = (iran * 2661 + 36979) % 175000; - s = SIGN(dith, (double) (iran - 87500)); - rmid[j] = (0.5 + s) * regn[j] + (0.5 - s) * regn[ndim + j]; - fminl[j] = fminr[j] = BIG; - fmaxl[j] = fmaxr[j] = (-BIG); - } - for (n = 0; n < npre; n++) { - ranpt(pt, regn); - fval = func.funk(pt); - for (j = 0; j < ndim; j++) { - if (pt[j] <= rmid[j]) { - fminl[j] = min(fminl[j], fval); - fmaxl[j] = max(fmaxl[j], fval); - } else { - fminr[j] = min(fminr[j], fval); - fmaxr[j] = max(fmaxr[j], fval); - } - } - } - sumb = BIG; - jb = -1; - siglb = sigrb = 1.0; - for (j = 0; j < ndim; j++) { - if (fmaxl[j] > fminl[j] && fmaxr[j] > fminr[j]) { - sigl = max(TINY, pow(fmaxl[j] - fminl[j], 2.0 / 3.0)); - sigr = max(TINY, pow(fmaxr[j] - fminr[j], 2.0 / 3.0)); - sum = sigl + sigr; - if (sum <= sumb) { - sumb = sum; - jb = j; - siglb = sigl; - sigrb = sigr; - } - } - } - if (jb == -1) - jb = (ndim * iran) / 175000; - rgl = regn[jb]; - rgm = rmid[jb]; - rgr = regn[ndim + jb]; - fracl = abs((rgm - rgl) / (rgr - rgl)); - nptl = (int) (MNPT + (npts - npre - 2 * MNPT) * fracl * siglb - / (fracl * siglb + (1.0 - fracl) * sigrb)); - nptr = npts - npre - nptl; - double[] regn_temp = new double[2 * ndim]; - for (j = 0; j < ndim; j++) { - regn_temp[j] = regn[j]; - regn_temp[ndim + j] = regn[ndim + j]; - } - regn_temp[ndim + jb] = rmid[jb]; - miser(func, regn_temp, nptl, dith, avel, varl); - regn_temp[jb] = rmid[jb]; - regn_temp[ndim + jb] = regn[ndim + jb]; - miser(func, regn_temp, nptr, dith, ave, var); - ave.val = fracl * avel.val + (1 - fracl) * ave.val; - var.val = fracl * fracl * varl.val + (1 - fracl) * (1 - fracl) - * var.val; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Multinormaldev.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Multinormaldev.java deleted file mode 100644 index 96c47b942e..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Multinormaldev.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.nr.ran; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; -import com.nr.la.Cholesky; - -public class Multinormaldev extends Ran { - int mm; - double[] mean; - double[][] var; - Cholesky chol; - double[] spt, pt; - - public Multinormaldev(final long j, final double[] mmean, - final double[][] vvar) { - super(j); - mm = mmean.length; - mean = buildVector(mmean); - var = buildMatrix(vvar); - chol = new Cholesky(var); - spt = new double[mm]; - pt = new double[mm]; - if (var[0].length != mm || var.length != mm) - throw new IllegalArgumentException("bad sizes"); - } - - public double[] dev() { - int i; - double u, v, x, y, q; - for (i = 0; i < mm; i++) { - do { - u = doub(); - v = 1.7156 * (doub() - 0.5); - x = u - 0.449871; - y = abs(v) + 0.386595; - q = SQR(x) + y * (0.19600 * y - 0.25472 * x); - } while (q > 0.27597 - && (q > 0.27846 || SQR(v) > -4. * log(u) * SQR(u))); - spt[i] = v / u; - } - chol.elmult(spt, pt); - for (i = 0; i < mm; i++) { - pt[i] += mean[i]; - } - return pt; - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Normaldev.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Normaldev.java deleted file mode 100644 index 17e11bec80..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Normaldev.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.nr.ran; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -public class Normaldev extends Ran { - double mu, sig; - - public Normaldev(final double mmu, final double ssig, final long i) { - super(i); - mu = mmu; - sig = ssig; - } - - public double dev() { - double u, v, x, y, q; - do { - u = doub(); - v = 1.7156 * (doub() - 0.5); - x = u - 0.449871; - y = abs(v) + 0.386595; - q = SQR(x) + y * (0.19600 * y - 0.25472 * x); - } while (q > 0.27597 && (q > 0.27846 || SQR(v) > -4. * log(u) * SQR(u))); - return mu + sig * v / u; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Normaldev_BM.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Normaldev_BM.java deleted file mode 100644 index a3c9a75b04..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Normaldev_BM.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.nr.ran; - -import static java.lang.Math.*; - -public class Normaldev_BM extends Ran { - double mu, sig; - double storedval; - - public Normaldev_BM(final double mmu, final double ssig, final long i) { - super(i); - mu = mmu; - sig = ssig; - storedval = 0.; - } - - public double dev() { - double v1, v2, rsq, fac; - if (storedval == 0.) { - do { - v1 = 2.0 * doub() - 1.0; - v2 = 2.0 * doub() - 1.0; - rsq = v1 * v1 + v2 * v2; - } while (rsq >= 1.0 || rsq == 0.0); - fac = sqrt(-2.0 * log(rsq) / rsq); - storedval = v1 * fac; - return mu + sig * v2 * fac; - } else { - fac = storedval; - storedval = 0.; - return mu + sig * fac; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Poissondev.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Poissondev.java deleted file mode 100644 index 8acab04a60..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Poissondev.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.nr.ran; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; -import static com.nr.sf.Gamma.*; - -public class Poissondev extends Ran { - double lambda, sqlam, loglam, lamexp, lambold; - double[] logfact; - - public Poissondev(final double llambda, final long i) { - super(i); - lambda = llambda; - logfact = buildVector(1024, -1.0); - lambold = -1; - } - - public int dev() { - double u, u2, v, v2 = 0, p, t, lfac; - int k; - if (lambda < 5.) { - if (lambda != lambold) - lamexp = exp(-lambda); - k = -1; - t = 1.; - do { - ++k; - t *= doub(); - } while (t > lamexp); - } else { - if (lambda != lambold) { - sqlam = sqrt(lambda); - loglam = log(lambda); - } - for (;;) { - u = 0.64 * doub(); - v = -0.68 + 1.28 * doub(); - if (lambda > 13.5) { - v2 = SQR(v); - if (v >= 0.) { - if (v2 > 6.5 * u * (0.64 - u) * (u + 0.2)) - continue; - } else { - if (v2 > 9.6 * u * (0.66 - u) * (u + 0.07)) - continue; - } - } - k = (int) (floor(sqlam * (v / u) + lambda + 0.5)); - if (k < 0) - continue; - u2 = SQR(u); - if (lambda > 13.5) { - if (v >= 0.) { - if (v2 < 15.2 * u2 * (0.61 - u) * (0.8 - u)) - break; - } else { - if (v2 < 6.76 * u2 * (0.62 - u) * (1.4 - u)) - break; - } - } - if (k < 1024) { - if (logfact[k] < 0.) - logfact[k] = gammln(k + 1.); - lfac = logfact[k]; - } else - lfac = gammln(k + 1.); - p = sqlam * exp(-lambda + k * loglam - lfac); - if (u2 < p) - break; - } - } - lambold = lambda; - return k; - } - - public int dev(final double llambda) { - lambda = llambda; - return dev(); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Primpolytest.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Primpolytest.java deleted file mode 100644 index b0dc262b32..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Primpolytest.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.nr.ran; - -public class Primpolytest { - int N, nfactors; - long[] factors; - int[] t, a, p; - - public Primpolytest() { - N = 32; - nfactors = 5; - factors = new long[nfactors]; - t = new int[N * N]; - a = new int[N * N]; - p = new int[N * N]; - long[] factordata = { 3, 5, 17, 257, 65537 }; - for (int i = 0; i < nfactors; i++) - factors[i] = factordata[i]; - } - - public int ispident() { - int i, j; - for (i = 0; i < N; i++) - for (j = 0; j < N; j++) { - if (i == j) { - if (p[i * N + j] != 1) - return 0; - } else { - if (p[i * N + j] != 0) - return 0; - } - } - return 1; - } - - public void mattimeseq(final int[] a, final int[] b) { - int i, j, k, sum; - int[] tmp = new int[N * N]; - for (i = 0; i < N; i++) - for (j = 0; j < N; j++) { - sum = 0; - for (k = 0; k < N; k++) - sum += a[i * N + k] * b[k * N + j]; - tmp[i * N + j] = sum & 1; - } - for (k = 0; k < N * N; k++) - a[k] = tmp[k]; - } - - public void matpow(long n) { - int k; - for (k = 0; k < N * N; k++) - p[k] = 0; - for (k = 0; k < N; k++) - p[k * N + k] = 1; - while (true) { - if ((n & 1) != 0) - mattimeseq(p, a); - n >>>= 1; - if (n == 0) - break; - mattimeseq(a, a); - } - } - - public int test(final long n) { - int i, k, j; - long pow, tnm1, nn = n; - tnm1 = ((long) 1 << N) - 1; - if (n > (tnm1 >>> 1)) - throw new IllegalArgumentException("not a polynomial of degree N"); - for (k = 0; k < N * N; k++) - t[k] = 0; - for (i = 1; i < N; i++) - t[i * N + (i - 1)] = 1; - j = 0; - while (nn != 0) { - if ((nn & 1) != 0) - t[j] = 1; - nn >>>= 1; - j++; - } - t[N - 1] = 1; - for (k = 0; k < N * N; k++) - a[k] = t[k]; - matpow(tnm1); - if (ispident() != 1) - return 0; - for (i = 0; i < nfactors; i++) { - pow = tnm1 / factors[i]; - for (k = 0; k < N * N; k++) - a[k] = t[k]; - matpow(pow); - if (ispident() == 1) - return 0; - } - return 1; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Ran.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Ran.java deleted file mode 100644 index 8be69a093f..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Ran.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.nr.ran; - -/** - * Implementation of the highest quality recommended generator. The constructor - * is called with an integer seed and creates an instance of the generator. The - * member functions int64, doub, and int32 return the next values in the random - * sequence, as a variable type indicated by their names. The period of the - * generator is 3.138E57. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Ran { - private long u; - private long v = 4101842887655102017L; - private long w = 1; - - /** - * Call with any integer seed (except value of v above). - * - * @param j - */ - public Ran(final long j) { - u = j ^ v; - int64(); - v = u; - int64(); - w = v; - int64(); - } - - /** - * Return 64-bit random integer. See text for explanation of method. - * - * @return - */ - public long int64() { - u = u * 2862933555777941757L + 7046029254386353087L; - v ^= v >>> 17; - v ^= v << 31; - v ^= v >>> 8; - w = 4294957665L * (w & 0xffffffffL) + (w >>> 32); - long x = u ^ (u << 21); - x ^= x >>> 35; - x ^= x << 4; - return (x + v) ^ w; - } - - /** - * Return random double-precision floating value in the range 0. to 1. - * - * @return - */ - public double doub() { // XXX as int64 is signed. - double r = 5.42101086242752217E-20 * int64(); - return r < 0 ? 1 + r : r; - } - - /** - * Return 32-bit random integer. - * - * @return - */ - public int int32() { - return (int) int64(); - } - - public int int32p() { - return int32() & 0x7FFFFFFF; - } - - public long int64p() { - return int64() & 0x7FFFFFFFFFFFFFFFL; - } - - public static void main(String[] args) { - Ran ran = new Ran(17); - long r = ran.int64(); - System.out.printf("%x\n", r); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Ranbyte.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Ranbyte.java deleted file mode 100644 index 0723bbe499..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Ranbyte.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.nr.ran; - -/** - * Generator for random bytes using the algorithm generally known as RC4. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Ranbyte { - private int[] s = new int[256]; - private int i, j, ss; - private int v; - - public Ranbyte(final int u) { - v = 0x85ca18e3 ^ u; // 0x85ca18e3 = 2244614371L - for (i = 0; i < 256; i++) { - s[i] = i; - } - for (j = 0, i = 0; i < 256; i++) { - ss = s[i]; - j = (j + ss + (v >>> 24)) & 0xff; - s[i] = s[j]; - s[j] = ss; - v = (v << 24) | (v >>> 8); - } - i = j = 0; - for (int k = 0; k < 256; k++) - int8(); - } - - public int int8() { - i = (i + 1) & 0xff; - ss = s[i]; - j = (j + ss) & 0xff; - s[i] = s[j]; - s[j] = ss; - return (s[(s[i] + s[j]) & 0xff]); - } - - /** - * Returns a random 32-bit integer constructed from 4 random bytes. Slow! - * - * @return - */ - public int int32() { - v = 0; - for (int k = 0; k < 4; k++) { - i = (i + 1) & 0xff; - ss = s[i]; - j = (j + ss) & 0xff; - s[i] = s[j]; - s[j] = ss; - v = (v << 8) | s[(s[i] + s[j]) & 0xff]; - } - return v; - } - - public int int32p() { - return int32() & 0x7FFFFFFF; - } - - /** - * Returns a random double-precision floating value between 0. and 1. Slow!! - * - * @return - */ - public double doub() { - double r = 2.32830643653869629E-10 * ((int32() & 0xFFFFFFFFL) + 2.32830643653869629E-10 * (int32() & 0xFFFFFFFFL)); - return r; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Ranfib.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Ranfib.java deleted file mode 100644 index aba6ebc172..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Ranfib.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.nr.ran; - -/** - * Implements Knuth's subtractive generator using only floating operations. See - * text for cautions. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Ranfib { - private double[] dtab = new double[55]; - private double dd; - private int inext = 0; - private int inextp = 31; - - public Ranfib(final long j) { - Ranq1 init = new Ranq1(j); - for (int k = 0; k < 55; k++) - dtab[k] = init.doub(); - } - - public double doub() { - if (++inext == 55) - inext = 0; - if (++inextp == 55) - inextp = 0; - dd = dtab[inext] - dtab[inextp]; - if (dd < 0) - dd += 1.0; - return (dtab[inext] = dd); - } - - /** - * Returns random 32-bit integer. Recommended only for testing purposes. - * - * @return - */ - public long int32() { - return (long) (doub() * 4294967295.0); - } - - public int int32p() { - return (int) (int32() & 0x7FFFFFFFL); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Ranhash.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Ranhash.java deleted file mode 100644 index b4692d0c6e..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Ranhash.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.nr.ran; - -/** - * High-quality random hash of an integer into several numeric types. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Ranhash { - - public long int64(final long u) { - long v = u * 3935559000370003845L + 2691343689449507681L; - v ^= v >>> 21; - v ^= v << 37; - v ^= v >>> 4; - v *= 4768777513237032717L; - v ^= v << 20; - v ^= v >>> 41; - v ^= v << 5; - return v; - } - - public int int32(final long u) { - return (int) (int64(u) & 0xffffffffL); - } - - /** - * Returns hash of u as a double-precision floating value between 0. and 1. - * - * @param u - * @return - */ - public double doub(final long u) { - double r = 5.42101086242752217E-20 * int64(u); - return r < 0 ? 1 + r : r; - } - - public int int32p(final long u) { - return int32(u) & 0x7FFFFFFF; - } - - public long int64p(final long u) { - return int64(u) & 0x7FFFFFFFFFFFFFFFL; - } - - public static void main(final String[] args) { - Ranhash rh = new Ranhash(); - long u = 1111112L; - System.out.println(rh.int64(u)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Ranlim32.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Ranlim32.java deleted file mode 100644 index 25d302a1fb..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Ranlim32.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.nr.ran; - -/** - * High-quality random generator using only 32-bit arithmetic. Same conventions - * as Ran. Period is 3.11E37 . Recommended only when 64-bit arithmetic is not - * available. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Ranlim32 { - private int u; - private int v = 0x85ca18e3; // 0x85ca18e3=2244614371; - private int w1 = 521288629; - private int w2 = 362436069; - - public Ranlim32(final int j) { - u = j ^ v; - int32(); - v = u; - int32(); - } - - public int int32() { - u = u * 0xac564b05 + 1640531513; // 0xac564b05=2891336453 - v ^= v >>> 13; - v ^= v << 17; - v ^= v >>> 5; - w1 = 33378 * (w1 & 0xffff) + (w1 >>> 16); - w2 = 57225 * (w2 & 0xffff) + (w2 >>> 16); - int x = u ^ (u << 9); - x ^= x >>> 17; - x ^= x << 6; - int y = w1 ^ (w1 << 17); - y ^= y >>> 15; - y ^= y << 5; - return (x + v) ^ (y + w2); - } - - public int int32p() { - return int32() & 0x7FFFFFFF; - } - - public double doub() { - double r = 2.32830643653869629E-10 * int32(); - return r < 0 ? 1 + r : r; - } - - public double truedoub() { - double r = 2.32830643653869629E-10 * ((int32() & 0xFFFFFFFFL) + 2.32830643653869629E-10 * (int32() & 0xFFFFFFFFL)); - return r; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Ranq1.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Ranq1.java deleted file mode 100644 index e26a31e6ca..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Ranq1.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.nr.ran; - -/** - * Recommended generator for everyday use. The period is 1.8E19. Calling - * conventions same as Ran, above. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Ranq1 { - private long v = 4101842887655102017L; - - public Ranq1(final long j) { - v ^= j; - v = int64(); - } - - public long int64() { - v ^= v >>> 21; - v ^= v << 35; - v ^= v >>> 4; - return v * 2685821657736338717L; - } - - /** - * Return random double-precision floating value in the range 0. to 1. - * - * @return - */ - public double doub() { - double r = 5.42101086242752217E-20 * int64(); - return r < 0 ? 1 + r : r; - } - - public int int32() { - return (int) int64(); - } - - public int int32p() { - return int32() & 0x7FFFFFFF; - } - - public long int64p() { - return int64() & 0x7FFFFFFFFFFFFFFFL; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Ranq2.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Ranq2.java deleted file mode 100644 index 47355dfbdd..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Ranq2.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.nr.ran; - -/** - * Backup generator if Ranq1 has too short a period and Ran is too slow. The - * period is 8.5E37. Calling conventions same as Ran, above. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Ranq2 { - private long v = 4101842887655102017L; - private long w = 1; - - public Ranq2(final long j) { - v ^= j; - w = int64(); - v = int64(); - } - - public long int64() { - v ^= v >>> 17; - v ^= v << 31; - v ^= v >>> 8; - w = 4294957665L * (w & 0xffffffffL) + (w >>> 32); - return v ^ w; - } - - /** - * Return random double-precision floating value in the range 0. to 1. - * - * @return - */ - public double doub() { - double r = 5.42101086242752217E-20 * int64(); - return r < 0 ? 1 + r : r; - } - - public int int32() { - return (int) int64(); - } - - public int int32p() { - return int32() & 0x7FFFFFFF; - } - - public long int64p() { - return int64() & 0x7FFFFFFFFFFFFFFFL; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/Sobol.java b/common-tools/cnuphys/numRec/src/com/nr/ran/Sobol.java deleted file mode 100644 index 9e156a368c..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/Sobol.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.nr.ran; - -import static java.lang.Math.*; - -/** - * Sobol quasi-random sequence - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Sobol { - private Sobol() { - } - - private static final int MAXBIT = 30, MAXDIM = 6; - private static int[] mdeg = { 1, 2, 3, 3, 4, 4 }; - private static int in; - private static int[] ix = new int[MAXDIM]; - private static int[][] iu = new int[MAXBIT][]; - private static int[] ip = { 0, 1, 1, 2, 1, 4 }; - // static int[] iv = {1,1,1,1,1,1,3,1,3,3,1,1,5,7,7,3,3,5,15,11,5,15,13,9}; - private static double fac; - - static { - for (int i = 0; i < MAXBIT; i++) - iu[i] = new int[MAXDIM]; - int[] iv = { 1, 1, 1, 1, 1, 1, 3, 1, 3, 3, 1, 1, 5, 7, 7, 3, 3, 5, 15, - 11, 5, 15, 13, 9 }; - for (int j = 0; j < 4; j++) - for (int k = 0; k < MAXDIM; k++) - iu[j][k] = iv[j * MAXDIM + k]; - } - - public static void sobseq(final int n, final double[] x) { - int j, k, l; - int i, im, ipp; - - if (n < 0) { - for (k = 0; k < MAXDIM; k++) - ix[k] = 0; - in = 0; - if (iu[0][0] != 1) - return; - // if (iv[0] != 1) return; - fac = 1.0 / (1 << MAXBIT); - // for (j=0,k=0;j> mdeg[k]); - for (l = mdeg[k] - 1; l >= 1; l--) { - if ((ipp & 1) != 0) - i ^= iu[j - l][k]; - ipp >>= 1; - } - iu[j][k] = i; - } - } - } else { - im = in++; - for (j = 0; j < MAXBIT; j++) { - if ((im & 1) == 0) - break; - im >>= 1; - } - if (j >= MAXBIT) - throw new IllegalArgumentException("MAXBIT too small in sobseq"); - im = j * MAXDIM; - for (k = 0; k < min(n, MAXDIM); k++) { - // ix[k] ^= iv[im+k]; - ix[k] ^= iu[j][k]; - x[k] = ix[k] * fac; - } - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/ran/VEGAS.java b/common-tools/cnuphys/numRec/src/com/nr/ran/VEGAS.java deleted file mode 100644 index a3a8831603..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/ran/VEGAS.java +++ /dev/null @@ -1,250 +0,0 @@ -package com.nr.ran; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import org.netlib.util.doubleW; - -/** - * Complete VEGAS Code adaptive/recursive Monte Carlo - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public abstract class VEGAS { - private final int NDMX = 50, MXDIM = 10, RANSEED = 5330; - private final double ALPH = 1.5, TINY = 1.0e-30; - private int i, it, j, k, mds, nd, ndo, ng, npg; - private double calls, dv2g, dxg, f, f2, f2b, fb, rc, ti; - private double tsi, wgt, xjac, xn, xnd, xo, schi, si, swgt; - private int[] ia = new int[MXDIM], kg = new int[MXDIM]; - private double[] dt = new double[MXDIM], dx = new double[MXDIM], - r = new double[NDMX], x = new double[MXDIM], - xin = new double[NDMX]; - private double[][] d = new double[NDMX][MXDIM], - di = new double[NDMX][MXDIM], xi = new double[MXDIM][NDMX]; - private Ran ran_vegas = new Ran(RANSEED); - - public VEGAS() { - - } - - public abstract double fxn(final double[] x, final double wgt); - - public static void rebin(final double rc, final int nd, final double[] r, - final double[] xin, final double[][] xi, final int j) { - int i, k = 0; - double dr = 0.0, xn = 0.0, xo = 0.0; - - for (i = 0; i < nd - 1; i++) { - while (rc > dr) - dr += r[(++k) - 1]; - if (k > 1) - xo = xi[j][k - 2]; - xn = xi[j][k - 1]; - dr -= rc; - xin[i] = xn - (xn - xo) * dr / r[k - 1]; - } - for (i = 0; i < nd - 1; i++) - xi[j][i] = xin[i]; - xi[j][nd - 1] = 1.0; - } - - /** - * Performs Monte Carlo integration of a user-supplied ndim-dimensional - * function fxn over a rectangular volume specified by regn[0..2*ndim-1], a - * vector consisting of ndim "lower left" coordinates of the region followed - * by ndim "upper right" coordinates. The integration consists of itmx - * iterations, each with approximately ncall calls to the function. After - * each iteration the grid is refined; more than 5 or 10 iterations are - * rarely useful. The input flag init signals whether this call is a new - * start or a subsequent call for additional iterations (see comments in the - * code). The input flag nprn (normally 0) controls the amount of diagnostic - * output. Returned answers are tgral (the best estimate of the integral), - * sd (its standard deviation), and chi2a (X^2 per degree of freedom, an - * indicator of whether consistent results are being obtained). - * - * @param regn - * @param fxn - * @param init - * @param ncall - * @param itmx - * @param nprn - * @param tgral - * @param sd - * @param chi2a - */ - public void vegas(final double[] regn, final int init, final int ncall, - final int itmx, final int nprn, final doubleW tgral, - final doubleW sd, final doubleW chi2a) { - - int ndim = regn.length / 2; - if (init <= 0) { - mds = ndo = 1; - for (j = 0; j < ndim; j++) - xi[j][0] = 1.0; - } - if (init <= 1) - si = swgt = schi = 0.0; - if (init <= 2) { - nd = NDMX; - ng = 1; - if (mds != 0) { - ng = (int) (pow(ncall / 2.0 + 0.25, 1.0 / ndim)); - mds = 1; - if ((2 * ng - NDMX) >= 0) { - mds = -1; - npg = ng / NDMX + 1; - nd = ng / npg; - ng = npg * nd; - } - } - for (k = 1, i = 0; i < ndim; i++) - k *= ng; - npg = max((ncall / k), 2); - calls = npg * k; - dxg = 1.0 / ng; - for (dv2g = 1, i = 0; i < ndim; i++) - dv2g *= dxg; - dv2g = SQR(calls * dv2g) / npg / npg / (npg - 1.0); - xnd = nd; - dxg *= xnd; - xjac = 1.0 / calls; - for (j = 0; j < ndim; j++) { - dx[j] = regn[j + ndim] - regn[j]; - xjac *= dx[j]; - } - if (nd != ndo) { - for (i = 0; i < max(nd, ndo); i++) - r[i] = 1.0; - for (j = 0; j < ndim; j++) - rebin(ndo / xnd, nd, r, xin, xi, j); - ndo = nd; - } - if (nprn >= 0) { - /* - * cout << " Input parameters for vegas"; cout << " ndim= " << - * setw(4) << ndim; cout << " ncall= " << setw(8) << calls << - * endl; cout << setw(34) << " it=" << setw(5) << it; cout << - * " itmx=" << setw(5) << itmx << endl; cout << setw(34) << - * " nprn=" << setw(5) << nprn; cout << " ALPH=" << setw(9) << - * ALPH << endl; cout << setw(34) << " mds=" << setw(5) << mds; - * cout << " nd=" << setw(5) << nd << endl; for - * (j=0;j= 0.0) - throw new IllegalArgumentException( - "Root must be bracketed for bisection in rtbis"); - // rtb = f < 0.0 ? (dx=x2-x1,x1) : (dx=x1-x2,x2); - rtb = 0; - if (f < 0.0) { - dx = x2 - x1; - rtb = x1; - } else { - dx = x1 - x2; - rtb = x2; - } - for (int j = 0; j < JMAX; j++) { - fmid = func.funk(xmid = rtb + (dx *= 0.5)); - if (fmid <= 0.0) - rtb = xmid; - if (abs(dx) < xacc || fmid == 0.0) - return rtb; - } - throw new IllegalArgumentException("Too many bisections in rtbis"); - } - - /** - * Using the false-position method, return the root of a function or functor - * func known to lie between x1 and x2. The root is refined until its - * accuracy is +/-acc - * - * @param func - * @param x1 - * @param x2 - * @param xacc - * @return - */ - public static double rtflsp(final UniVarRealValueFun func, final double x1, - final double x2, final double xacc) { - final int MAXIT = 30; - double xl, xh, del; - double fl = func.funk(x1); - double fh = func.funk(x2); - if (fl * fh > 0.0) - throw new IllegalArgumentException( - "Root must be bracketed in rtflsp"); - if (fl < 0.0) { - xl = x1; - xh = x2; - } else { - xl = x2; - xh = x1; - // SWAP(fl,fh); - double swap = fl; - fl = fh; - fh = swap; - } - double dx = xh - xl; - for (int j = 0; j < MAXIT; j++) { - double rtf = xl + dx * fl / (fl - fh); - double f = func.funk(rtf); - if (f < 0.0) { - del = xl - rtf; - xl = rtf; - fl = f; - } else { - del = xh - rtf; - xh = rtf; - fh = f; - } - dx = xh - xl; - if (abs(del) < xacc || f == 0.0) - return rtf; - } - throw new IllegalArgumentException( - "Maximum number of iterations exceeded in rtflsp"); - } - - /** - * Using the secant method, return the root of a function or functor func - * thought to lie between x1 and x2. The root is refined until its accuracy - * is +/-acc. - * - * @param func - * @param x1 - * @param x2 - * @param xacc - * @return - */ - public static double rtsec(final UniVarRealValueFun func, final double x1, - final double x2, final double xacc) { - final int MAXIT = 30; - double xl, rts; - double fl = func.funk(x1); - double f = func.funk(x2); - if (abs(fl) < abs(f)) { - rts = x1; - xl = x2; - // SWAP(fl,f); - double swap = fl; - fl = f; - f = swap; - } else { - xl = x1; - rts = x2; - } - for (int j = 0; j < MAXIT; j++) { - double dx = (xl - rts) * f / (f - fl); - xl = rts; - fl = f; - rts += dx; - f = func.funk(rts); - if (abs(dx) < xacc || f == 0.0) - return rts; - } - throw new IllegalArgumentException( - "Maximum number of iterations exceeded in rtsec"); - } - - /** - * Using Ridders' method, return the root of a function or functor func - * known to lie between x1 and x2. The root will be refined to an - * approximate accuracy xacc. - * - * @param func - * @param x1 - * @param x2 - * @param xacc - * @return - */ - public static double zriddr(final UniVarRealValueFun func, final double x1, - final double x2, final double xacc) { - final int MAXIT = 60; - double fl = func.funk(x1); - double fh = func.funk(x2); - if ((fl > 0.0 && fh < 0.0) || (fl < 0.0 && fh > 0.0)) { - double xl = x1; - double xh = x2; - double ans = -9.99e99; - for (int j = 0; j < MAXIT; j++) { - double xm = 0.5 * (xl + xh); - double fm = func.funk(xm); - double s = sqrt(fm * fm - fl * fh); - if (s == 0.0) - return ans; - double xnew = xm + (xm - xl) - * ((fl >= fh ? 1.0 : -1.0) * fm / s); - if (abs(xnew - ans) <= xacc) - return ans; - ans = xnew; - double fnew = func.funk(ans); - if (fnew == 0.0) - return ans; - if (SIGN(fm, fnew) != fm) { - xl = xm; - fl = fm; - xh = ans; - fh = fnew; - } else if (SIGN(fl, fnew) != fl) { - xh = ans; - fh = fnew; - } else if (SIGN(fh, fnew) != fh) { - xl = ans; - fl = fnew; - } else - throw new IllegalArgumentException("never get here."); - if (abs(xh - xl) <= xacc) - return ans; - } - throw new IllegalArgumentException( - "zriddr exceed maximum iterations"); - } else { - if (fl == 0.0) - return x1; - if (fh == 0.0) - return x2; - throw new IllegalArgumentException( - "root must be bracketed in zriddr."); - } - } - - /** - * Using Brent's method, return the root of a function or functor func known - * to lie between x1 and x2. The root will be refined until its accuracy is - * tol. - * - * @param func - * @param x1 - * @param x2 - * @param tol - * @return - */ - public static double zbrent(final UniVarRealValueFun func, final double x1, - final double x2, final double tol) { - final int ITMAX = 100; - final double EPS = DBL_EPSILON; - double a = x1, b = x2, c = x2, d = 0, e = 0, fa = func.funk(a), fb = func - .funk(b), fc, p, q, r, s, tol1, xm; - if ((fa > 0.0 && fb > 0.0) || (fa < 0.0 && fb < 0.0)) - throw new IllegalArgumentException( - "Root must be bracketed in zbrent"); - fc = fb; - for (int iter = 0; iter < ITMAX; iter++) { - if ((fb > 0.0 && fc > 0.0) || (fb < 0.0 && fc < 0.0)) { - c = a; - fc = fa; - e = d = b - a; - } - if (abs(fc) < abs(fb)) { - a = b; - b = c; - c = a; - fa = fb; - fb = fc; - fc = fa; - } - tol1 = 2.0 * EPS * abs(b) + 0.5 * tol; - xm = 0.5 * (c - b); - if (abs(xm) <= tol1 || fb == 0.0) - return b; - if (abs(e) >= tol1 && abs(fa) > abs(fb)) { - s = fb / fa; - if (a == c) { - p = 2.0 * xm * s; - q = 1.0 - s; - } else { - q = fa / fc; - r = fb / fc; - p = s * (2.0 * xm * q * (q - r) - (b - a) * (r - 1.0)); - q = (q - 1.0) * (r - 1.0) * (s - 1.0); - } - if (p > 0.0) - q = -q; - p = abs(p); - double min1 = 3.0 * xm * q - abs(tol1 * q); - double min2 = abs(e * q); - if (2.0 * p < (min1 < min2 ? min1 : min2)) { - e = d; - d = p / q; - } else { - d = xm; - e = d; - } - } else { - d = xm; - e = d; - } - a = b; - fa = fb; - if (abs(d) > tol1) - b += d; - else - b += SIGN(tol1, xm); - fb = func.funk(b); - } - throw new IllegalArgumentException( - "Maximum number of iterations exceeded in zbrent"); - } - - /** - * Using the Newton-Raphson method, return the root of a function known to - * lie in the interval [x1, x2]. The root will be refined until its accuracy - * is known within +/-acc. funcd is a user- supplied struct that returns the - * function value as a functor and the first derivative of the function at - * the point x as the function df. - * - * @param funcd - * @param x1 - * @param x2 - * @param xacc - * @return - */ - public static double rtnewt(final UniValRealValueFunWithDiff funcd, - final double x1, final double x2, final double xacc) { - final int JMAX = 20; - double rtn = 0.5 * (x1 + x2); - for (int j = 0; j < JMAX; j++) { - double f = funcd.funk(rtn); - double df = funcd.df(rtn); - double dx = f / df; - rtn -= dx; - if ((x1 - rtn) * (rtn - x2) < 0.0) - throw new IllegalArgumentException( - "Jumped out of brackets in rtnewt"); - if (abs(dx) < xacc) - return rtn; - } - throw new IllegalArgumentException( - "Maximum number of iterations exceeded in rtnewt"); - } - - /** - * Using a combination of Newton-Raphson and bisection, return the root of a - * function bracketed between x1 and x2. The root will be refined until its - * accuracy is known within +/-acc. funcd is a user-supplied struct that - * returns the function value as a functor and the first derivative of the - * function at the point x as the function df. - * - * @param funcd - * @param x1 - * @param x2 - * @param xacc - * @return - */ - public static double rtsafe(final UniValRealValueFunWithDiff funcd, - final double x1, final double x2, final double xacc) { - final int MAXIT = 100; - double xh, xl; - double fl = funcd.funk(x1); - double fh = funcd.funk(x2); - if ((fl > 0.0 && fh > 0.0) || (fl < 0.0 && fh < 0.0)) - throw new IllegalArgumentException( - "Root must be bracketed in rtsafe"); - if (fl == 0.0) - return x1; - if (fh == 0.0) - return x2; - if (fl < 0.0) { - xl = x1; - xh = x2; - } else { - xh = x1; - xl = x2; - } - double rts = 0.5 * (x1 + x2); - double dxold = abs(x2 - x1); - double dx = dxold; - double f = funcd.funk(rts); - double df = funcd.df(rts); - for (int j = 0; j < MAXIT; j++) { - if ((((rts - xh) * df - f) * ((rts - xl) * df - f) > 0.0) - || (abs(2.0 * f) > abs(dxold * df))) { - dxold = dx; - dx = 0.5 * (xh - xl); - rts = xl + dx; - if (xl == rts) - return rts; - } else { - dxold = dx; - dx = f / df; - double temp = rts; - rts -= dx; - if (temp == rts) - return rts; - } - if (abs(dx) < xacc) - return rts; - f = funcd.funk(rts); - df = funcd.df(rts); - if (f < 0.0) - xl = rts; - else - xh = rts; - } - throw new IllegalArgumentException( - "Maximum number of iterations exceeded in rtsafe"); - } - - /** - * Bairstow's method for complex root - * - * Given n+1 coefficients p[0..n] of a polynomial of degree n, and trial - * values for the coefficients of a quadratic factor x*x+b*x+c, improve the - * solution until the coefficients b,c change by less than eps. - * - * - * @param p - * @param b - * @param c - * @param eps - */ - public static void qroot(final double[] p, final doubleW b, - final doubleW c, final double eps) { - final int ITMAX = 20; - final double TINY = 1.0e-14; - double sc, sb, s, rc, rb, r, dv, delc, delb; - int n = p.length - 1; - double[] d = new double[3], q = new double[n + 1], qq = new double[n + 1], rem = new double[n + 1]; - d[2] = 1.0; - for (int iter = 0; iter < ITMAX; iter++) { - d[1] = b.val; - d[0] = c.val; - Poly.poldiv(p, d, q, rem); - s = rem[0]; - r = rem[1]; - Poly.poldiv(q, d, qq, rem); - sb = -c.val * (rc = -rem[1]); - rb = -b.val * rc + (sc = -rem[0]); - dv = 1.0 / (sb * rc - sc * rb); - delb = (r * sc - s * rc) * dv; - delc = (-r * sb + s * rb) * dv; - b.val += delb; - c.val += delc; - if ((abs(delb) <= eps * abs(b.val) || abs(b.val) < TINY) - && (abs(delc) <= eps * abs(c.val) || abs(c.val) < TINY)) { - return; - } - } - throw new IllegalArgumentException( - "Too many iterations in routine qroot"); - } - - /** - * polynomial roots by eigenvalue method - * - * Find all the roots of a polynomial with real coefficients, - * S(i=0,m)a[i]x^i, given the coefficients a[0..m]. The method is to - * construct an upper Hessenberg matrix whose eigenvalues are the desired - * roots and then use the routine Unsymmeig. The roots are returned in the - * complex vector rt[0..m-1], sorted in descending order by their real - * parts. - * - * @param a - * @param rt - */ - public static void zrhqr(final double[] a, final Complex[] rt) { - int m = a.length - 1; - double[][] hess = new double[m][m]; - for (int k = 0; k < m; k++) { - hess[0][k] = -a[m - k - 1] / a[m]; - for (int j = 1; j < m; j++) - hess[j][k] = 0.0; - if (k != m - 1) - hess[k + 1][k] = 1.0; - } - Unsymmeig h = new Unsymmeig(hess, false, true); - for (int j = 0; j < m; j++) - rt[j] = h.wri[j]; - } - - private static final double[] frac = { 0.0, 0.5, 0.25, 0.75, 0.13, 0.38, - 0.62, 0.88, 1.0 }; - - /** - * Given the m+1 complex coefficients a[0..m] of the polynomial - * S(i=0,m)a[i]x^i, and given a complex value x, this routine improves x by - * Laguerre's method until it converges, within the achievable roundoff - * limit, to a root of the given polynomial. The number of iterations taken - * is returned as its. - * - * @param a - * @param x - * @param its - * @return - */ - public static Complex laguer(final Complex[] a, final Complex xx, - final intW its) { - Complex x = xx; - final int MR = 8, MT = 10, MAXIT = MT * MR; - final double EPS = DBL_EPSILON; - Complex dx = new Complex(0, 0), x1 = new Complex(0, 0), b = new Complex( - 0, 0), d = new Complex(0, 0), f = new Complex(0, 0), g = new Complex( - 0, 0), h = new Complex(0, 0), sq = new Complex(0, 0), gp = new Complex( - 0, 0), gm = new Complex(0, 0), g2 = new Complex(0, 0); - int m = a.length - 1; - for (int iter = 1; iter <= MAXIT; iter++) { - its.val = iter; - b = a[m]; - double err = b.mod(); - d = new Complex(0, 0); - f = new Complex(0, 0); - double abx = x.mod(); - for (int j = m - 1; j >= 0; j--) { - f = x.mul(f).add(d); - d = x.mul(d).add(b); - b = x.mul(b).add(a[j]); - err = b.mod() + abx * err; - } - err *= EPS; - if (b.mod() <= err) - return x; - g = d.div(b); - g2 = g.mul(g); - h = g2.sub(f.div(b).mul(2.0)); - sq = (h.mul(m).sub(g2).mul(m - 1)).sqrt(); - // sq=sqrt((m-1)*(m*h-g2)); - gp = g.add(sq); - gm = g.sub(sq); - double abp = gp.mod(); - double abm = gm.mod(); - if (abp < abm) - gp = gm; - dx = max(abp, abm) > 0.0 ? new Complex(m, 0).div(gp) : Complex - .polar(1 + abx, iter); // polar - x1 = x.sub(dx); - if (x.equals(x1)) - return x; // XXX "==" must to be replace to equals - if (iter % MT != 0) - x = x1; - else { - x = x.sub(new Complex(frac[iter / MT], 0).div(dx)); - } - } - throw new IllegalArgumentException("too many iterations in laguer"); - } - - /** - * roots of a polynomial - PTC - * - * Given the m+1 complex coefficients a[0..m] of the polynomial - * S(i=0,m)a[i]x^i, this routine successively calls laguer and finds all m - * complex roots in roots[0..m-1]. The boolean variable polish should be - * input as true if polishing (also by Laguerre's method) is desired, false - * if the roots will be subsequently polished by other means. - * - * - * @param a - * @param roots - * @param polish - */ - public static void zroots(final Complex[] a, final Complex[] roots, - final boolean polish) { - final double EPS = 1.0e-14; - int i; - intW its = new intW(0); - Complex x = new Complex(0, 0), b = new Complex(0, 0), c = new Complex( - 0, 0); - int m = a.length - 1; - Complex[] ad = new Complex[m + 1]; - for (i = 0; i < ad.length; i++) - ad[i] = new Complex(0, 0); - for (int j = 0; j <= m; j++) - ad[j] = a[j]; - for (int j = m - 1; j >= 0; j--) { - x = new Complex(0.0, 0); - Complex[] ad_v = new Complex[j + 2]; - for (int jj = 0; jj < j + 2; jj++) - ad_v[jj] = ad[jj]; - x = laguer(ad_v, x, its); - if (abs(x.im()) <= 2.0 * EPS * abs(x.re())) - x = new Complex(x.re(), 0.0); - roots[j] = x; - b = ad[j + 1]; - for (int jj = j; jj >= 0; jj--) { - c = ad[jj]; - ad[jj] = b; - b = x.mul(b).add(c); - } - } - if (polish) - for (int j = 0; j < m; j++) - roots[j] = laguer(a, roots[j], its); - for (int j = 1; j < m; j++) { - x = roots[j]; - for (i = j - 1; i >= 0; i--) { - if (roots[i].re() <= x.re()) - break; - roots[i + 1] = roots[i]; - } - roots[i + 1] = x; - } - } - - /** - * Given an n-dimensional point xold[0..n-1], the value of the function and - * gradient there, fold and g[0..n-1], and a direction p[0..n-1], finds a - * new point x[0..n-1] along the direction p from xold where the function or - * functor func has decreased "sufficiently." The new function value is - * returned in f. stpmax is an input quantity that limits the length of the - * steps so that you do not try to evaluate the function in regions where it - * is undefined or subject to overflow. p is usually the Newton direction. - * The output quantity check is false on a normal exit. It is true when x is - * too close to xold. In a minimization algorithm, this usually signals - * convergence and can be ignored. However, in a zero-finding algorithm the - * calling program should check whether the convergence is spurious. - * - * @param xold - * @param fold - * @param g - * @param p - * @param x - * @param f - * @param stpmax - * @param check - * @param func - */ - public static void lnsrch(final double[] xold, final double fold, - final double[] g, final double[] p, final double[] x, - final doubleW f, final double stpmax, final booleanW check, - final RealValueFun func) { - final double ALF = 1.0e-4, TOLX = DBL_EPSILON; - double a, alam, alam2 = 0.0, alamin, b, disc, f2 = 0.0; - double rhs1, rhs2, slope = 0.0, sum = 0.0, temp, test, tmplam; - int i, n = xold.length; - check.val = false; - for (i = 0; i < n; i++) - sum += p[i] * p[i]; - sum = sqrt(sum); - if (sum > stpmax) - for (i = 0; i < n; i++) - p[i] *= stpmax / sum; - for (i = 0; i < n; i++) - slope += g[i] * p[i]; - if (slope >= 0.0) - throw new IllegalArgumentException("Roundoff problem in lnsrch."); - test = 0.0; - for (i = 0; i < n; i++) { - temp = abs(p[i]) / max(abs(xold[i]), 1.0); - if (temp > test) - test = temp; - } - alamin = TOLX / test; - alam = 1.0; - for (;;) { - for (i = 0; i < n; i++) - x[i] = xold[i] + alam * p[i]; - f.val = func.funk(x); - if (alam < alamin) { - for (i = 0; i < n; i++) - x[i] = xold[i]; - check.val = true; - return; - } else if (f.val <= fold + ALF * alam * slope) - return; - else { - if (alam == 1.0) - tmplam = -slope / (2.0 * (f.val - fold - slope)); - else { - rhs1 = f.val - fold - alam * slope; - rhs2 = f2 - fold - alam2 * slope; - a = (rhs1 / (alam * alam) - rhs2 / (alam2 * alam2)) - / (alam - alam2); - b = (-alam2 * rhs1 / (alam * alam) + alam * rhs2 - / (alam2 * alam2)) - / (alam - alam2); - if (a == 0.0) - tmplam = -slope / (2.0 * b); - else { - disc = b * b - 3.0 * a * slope; - if (disc < 0.0) - tmplam = 0.5 * alam; - else if (b <= 0.0) - tmplam = (-b + sqrt(disc)) / (3.0 * a); - else - tmplam = -slope / (b + sqrt(disc)); - } - if (tmplam > 0.5 * alam) - tmplam = 0.5 * alam; - } - } - alam2 = alam; - f2 = f.val; - alam = max(tmplam, 0.1 * alam); - } - } - - /** - * Given an initial guess x[0..n-1] for a root in n dimensions, find the - * root by a globally convergent Newton's method. The vector of functions to - * be zeroed, called fvec[0..n-1] in the routine below, is returned by the - * user-supplied function or functor vecfunc (see text). The output quantity - * check is false on a normal return and true if the routine has converged - * to a local minimum of the function fmin defined below. In this case try - * restarting from a different initial guess. - * - * @param x - * @param check - * @param vecfunc - */ - public static void newt(final double[] x, final booleanW check, - final RealMultiValueFun vecfunc) { - final int MAXITS = 200; - final double TOLF = 1.0e-8, TOLMIN = 1.0e-12, STPMX = 100.0; - final double TOLX = DBL_EPSILON; - int i, j, its, n = x.length; - double den, fold, stpmax, sum, temp, test; - doubleW f = new doubleW(0); - double[] g = new double[n], p = new double[n], xold = new double[n]; - double[][] fjac = new double[n][n]; - NRfmin fmin = new NRfmin(vecfunc); - NRfdjac fdjac = new NRfdjac(vecfunc); - f.val = fmin.funk(x); // XXX init fmin.fvec first. - double[] fvec = fmin.fvec; - test = 0.0; - for (i = 0; i < n; i++) - if (abs(fvec[i]) > test) - test = abs(fvec[i]); - if (test < 0.01 * TOLF) { - check.val = false; - return; - } - sum = 0.0; - for (i = 0; i < n; i++) - sum += SQR(x[i]); - stpmax = STPMX * max(sqrt(sum), n); - for (its = 0; its < MAXITS; its++) { - fjac = fdjac.get(x, fvec); - for (i = 0; i < n; i++) { - sum = 0.0; - for (j = 0; j < n; j++) - sum += fjac[j][i] * fvec[j]; - g[i] = sum; - } - for (i = 0; i < n; i++) - xold[i] = x[i]; - fold = f.val; - for (i = 0; i < n; i++) - p[i] = -fvec[i]; - LUdcmp alu = new LUdcmp(fjac); - alu.solve(p, p); - lnsrch(xold, fold, g, p, x, f, stpmax, check, fmin); - test = 0.0; - for (i = 0; i < n; i++) - if (abs(fvec[i]) > test) - test = abs(fvec[i]); - if (test < TOLF) { - check.val = false; - return; - } - if (check.val) { - test = 0.0; - den = max(f.val, 0.5 * n); - for (i = 0; i < n; i++) { - temp = abs(g[i]) * max(abs(x[i]), 1.0) / den; - if (temp > test) - test = temp; - } - check.val = (test < TOLMIN); - return; - } - test = 0.0; - for (i = 0; i < n; i++) { - temp = (abs(x[i] - xold[i])) / max(abs(x[i]), 1.0); - if (temp > test) - test = temp; - } - if (test < TOLX) - return; - } - throw new IllegalArgumentException("MAXITS exceeded in newt"); - } - - /** - * Given an initial guess x[0..n-1] for a root in n dimensions, find the - * root by Broyden's method embedded in a globally convergent strategy. The - * vector of functions to be zeroed, called fvec[0..n-1] in the routine - * below, is returned by the user-supplied function or functor vecfunc. The - * routines NRfdjac and NRfmin from newt are used. The output quantity check - * is false on a normal return and true if the routine has converged to a - * local minimum of the function fmin or if Broyden's method can make no - * further progress. In this case try restarting from a different initial - * guess. - * - * @param x - * @param check - * @param vecfunc - */ - public static void broydn(final double[] x, final booleanW check, - final RealMultiValueFun vecfunc) { - final int MAXITS = 200; - final double EPS = DBL_EPSILON; - final double TOLF = 1.0e-8, TOLX = EPS, STPMX = 100.0, TOLMIN = 1.0e-12; - boolean restrt, skip; - int i, its, j, n = x.length; - double den, fold, stpmax, sum, temp, test; - doubleW f = new doubleW(0); - double[] fvcold = new double[n], g = new double[n], p = new double[n], s = new double[n], t = new double[n], w = new double[n], xold = new double[n]; - QRdcmp qr = null; - NRfmin fmin = new NRfmin(vecfunc); - NRfdjac fdjac = new NRfdjac(vecfunc); - f.val = fmin.funk(x); // XXX init fmin.fvec first. - double[] fvec = fmin.fvec; - test = 0.0; - for (i = 0; i < n; i++) - if (abs(fvec[i]) > test) - test = abs(fvec[i]); - if (test < 0.01 * TOLF) { - check.val = false; - return; - } - for (sum = 0.0, i = 0; i < n; i++) - sum += SQR(x[i]); - stpmax = STPMX * max(sqrt(sum), n); - restrt = true; - for (its = 1; its <= MAXITS; its++) { - if (restrt) { - qr = new QRdcmp(fdjac.get(x, fvec)); - if (qr.sing) { - double[][] one = new double[n][n]; - for (i = 0; i < n; i++) - one[i][i] = 1.0; - qr = new QRdcmp(one); - } - } else { - for (i = 0; i < n; i++) - s[i] = x[i] - xold[i]; - for (i = 0; i < n; i++) { - for (sum = 0.0, j = i; j < n; j++) - sum += qr.r[i][j] * s[j]; - t[i] = sum; - } - skip = true; - for (i = 0; i < n; i++) { - for (sum = 0.0, j = 0; j < n; j++) - sum += qr.qt[j][i] * t[j]; - w[i] = fvec[i] - fvcold[i] - sum; - if (abs(w[i]) >= EPS * (abs(fvec[i]) + abs(fvcold[i]))) - skip = false; - else - w[i] = 0.0; - } - if (!skip) { - qr.qtmult(w, t); - for (den = 0.0, i = 0; i < n; i++) - den += SQR(s[i]); - for (i = 0; i < n; i++) - s[i] /= den; - qr.update(t, s); - if (qr.sing) - throw new IllegalArgumentException( - "singular update in broydn"); - } - } - qr.qtmult(fvec, p); - for (i = 0; i < n; i++) - p[i] = -p[i]; - for (i = n - 1; i >= 0; i--) { - for (sum = 0.0, j = 0; j <= i; j++) - sum -= qr.r[j][i] * p[j]; - g[i] = sum; - } - for (i = 0; i < n; i++) { - xold[i] = x[i]; - fvcold[i] = fvec[i]; - } - fold = f.val; - qr.rsolve(p, p); - double slope = 0.0; - for (i = 0; i < n; i++) - slope += g[i] * p[i]; - if (slope >= 0.0) { - restrt = true; - continue; - } - lnsrch(xold, fold, g, p, x, f, stpmax, check, fmin); - test = 0.0; - for (i = 0; i < n; i++) - if (abs(fvec[i]) > test) - test = abs(fvec[i]); - if (test < TOLF) { - check.val = false; - return; - } - if (check.val) { - if (restrt) { - return; - } else { - test = 0.0; - den = max(f.val, 0.5 * n); - for (i = 0; i < n; i++) { - temp = abs(g[i]) * max(abs(x[i]), 1.0) / den; - if (temp > test) - test = temp; - } - if (test < TOLMIN) { - return; - } else - restrt = true; - } - } else { - restrt = false; - test = 0.0; - for (i = 0; i < n; i++) { - temp = (abs(x[i] - xold[i])) / max(abs(x[i]), 1.0); - if (temp > test) - test = temp; - } - if (test < TOLX) { - return; - } - } - } - throw new IllegalArgumentException("MAXITS exceeded in broydn"); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Bessel.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Bessel.java deleted file mode 100644 index 1cd5da0d39..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Bessel.java +++ /dev/null @@ -1,432 +0,0 @@ -package com.nr.sf; - -import static java.lang.Math.*; - -import static com.nr.NRUtil.*; - -/** - * Bessel functions of fractional order Copyright (C) Numerical Recipes Software - * 1986-2007 Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Bessel { - private static final int NUSE1 = 7, NUSE2 = 8; - // private static final double[] c1= new double[NUSE1],c2 = new - // double[NUSE2]; - private static final double c1[] = { -1.142022680371168e0, - 6.5165112670737e-3, 3.087090173086e-4, -3.4706269649e-6, - 6.9437664e-9, 3.67795e-11, -1.356e-13 }; - private static final double c2[] = { 1.843740587300905e0, - -7.68528408447867e-2, 1.2719271366546e-3, -4.9717367042e-6, - -3.31261198e-8, 2.423096e-10, -1.702e-13, -1.49e-15 }; - - public double xjy, nujy, xik, nuik, xai, xsph; - public double jo, yo, jpo, ypo; - public double io, ko, ipo, kpo; - public double aio, bio, aipo, bipo; - public double sphjo, sphyo, sphjpo, sphypo; - public int sphno; - - public Bessel() { - xjy = 9.99e99; - nujy = 9.99e99; - xik = 9.99e99; - nuik = 9.99e99; - xai = 9.99e99; - sphno = -9999; - } - - public double jnu(final double nu, final double x) { - if (nu != nujy || x != xjy) - besseljy(nu, x); - return jo; - } - - public double ynu(final double nu, final double x) { - if (nu != nujy || x != xjy) - besseljy(nu, x); - return yo; - } - - public double inu(final double nu, final double x) { - if (nu != nuik || x != xik) - besselik(nu, x); - return io; - } - - public double knu(final double nu, final double x) { - if (nu != nuik || x != xik) - besselik(nu, x); - return ko; - } - - public double chebev(final double[] c, final int m, final double x) { - double d = 0.0, dd = 0.0, sv; - int j; - for (j = m - 1; j > 0; j--) { - sv = d; - d = 2. * x * d - dd + c[j]; - dd = sv; - } - return x * d - dd + 0.5 * c[0]; - } - - public void besseljy(final double nu, final double x) { - final int MAXIT = 10000; - final double EPS = DBL_EPSILON; // numeric_limits::epsilon(); - final double FPMIN = Double.MIN_NORMAL / EPS; - final double XMIN = 2.0, PI = 3.141592653589793; - double a, b, br, bi, c, cr, ci, d, del, del1, den, di, dlr, dli, dr, e, f, fact, fact2, fact3, ff, gam, gam1, gam2, gammi, gampl, h, p, pimu, pimu2, q, r, rjl, rjl1, rjmu, rjp1, rjpl, rjtemp, ry1, rymu, rymup, rytemp, sum, sum1, temp, w, x2, xi, xi2, xmu, xmu2, xx; - int i, isign, l, nl; - - if (x <= 0.0 || nu < 0.0) - throw new IllegalArgumentException("bad arguments in besseljy"); - nl = (x < XMIN ? (int) (nu + 0.5) : max(0, (int) (nu - x + 1.5))); - xmu = nu - nl; - xmu2 = xmu * xmu; - xi = 1.0 / x; - xi2 = 2.0 * xi; - w = xi2 / PI; - isign = 1; - h = nu * xi; - if (h < FPMIN) - h = FPMIN; - b = xi2 * nu; - d = 0.0; - c = h; - for (i = 0; i < MAXIT; i++) { - b += xi2; - d = b - d; - if (abs(d) < FPMIN) - d = FPMIN; - c = b - 1.0 / c; - if (abs(c) < FPMIN) - c = FPMIN; - d = 1.0 / d; - del = c * d; - h = del * h; - if (d < 0.0) - isign = -isign; - if (abs(del - 1.0) <= EPS) - break; - } - if (i >= MAXIT) - throw new IllegalArgumentException( - "x too large in besseljy; try asymptotic expansion"); - rjl = isign * FPMIN; - rjpl = h * rjl; - rjl1 = rjl; - rjp1 = rjpl; - fact = nu * xi; - for (l = nl - 1; l >= 0; l--) { - rjtemp = fact * rjl + rjpl; - fact -= xi; - rjpl = fact * rjtemp - rjl; - rjl = rjtemp; - } - if (rjl == 0.0) - rjl = EPS; - f = rjpl / rjl; - if (x < XMIN) { - x2 = 0.5 * x; - pimu = PI * xmu; - fact = (abs(pimu) < EPS ? 1.0 : pimu / sin(pimu)); - d = -log(x2); - e = xmu * d; - fact2 = (abs(e) < EPS ? 1.0 : sinh(e) / e); - xx = 8.0 * SQR(xmu) - 1.0; - gam1 = chebev(c1, NUSE1, xx); - gam2 = chebev(c2, NUSE2, xx); - gampl = gam2 - xmu * gam1; - gammi = gam2 + xmu * gam1; - ff = 2.0 / PI * fact * (gam1 * cosh(e) + gam2 * fact2 * d); - e = exp(e); - p = e / (gampl * PI); - q = 1.0 / (e * PI * gammi); - pimu2 = 0.5 * pimu; - fact3 = (abs(pimu2) < EPS ? 1.0 : sin(pimu2) / pimu2); - r = PI * pimu2 * fact3 * fact3; - c = 1.0; - d = -x2 * x2; - sum = ff + r * q; - sum1 = p; - for (i = 1; i <= MAXIT; i++) { - ff = (i * ff + p + q) / (i * i - xmu2); - c *= (d / i); - p /= (i - xmu); - q /= (i + xmu); - del = c * (ff + r * q); - sum += del; - del1 = c * p - i * del; - sum1 += del1; - if (abs(del) < (1.0 + abs(sum)) * EPS) - break; - } - if (i > MAXIT) - throw new IllegalArgumentException( - "bessy series failed to converge"); - rymu = -sum; - ry1 = -sum1 * xi2; - rymup = xmu * xi * rymu - ry1; - rjmu = w / (rymup - f * rymu); - } else { - a = 0.25 - xmu2; - p = -0.5 * xi; - q = 1.0; - br = 2.0 * x; - bi = 2.0; - fact = a * xi / (p * p + q * q); - cr = br + q * fact; - ci = bi + p * fact; - den = br * br + bi * bi; - dr = br / den; - di = -bi / den; - dlr = cr * dr - ci * di; - dli = cr * di + ci * dr; - temp = p * dlr - q * dli; - q = p * dli + q * dlr; - p = temp; - for (i = 1; i < MAXIT; i++) { - a += 2 * i; - bi += 2.0; - dr = a * dr + br; - di = a * di + bi; - if (abs(dr) + abs(di) < FPMIN) - dr = FPMIN; - fact = a / (cr * cr + ci * ci); - cr = br + cr * fact; - ci = bi - ci * fact; - if (abs(cr) + abs(ci) < FPMIN) - cr = FPMIN; - den = dr * dr + di * di; - dr /= den; - di /= -den; - dlr = cr * dr - ci * di; - dli = cr * di + ci * dr; - temp = p * dlr - q * dli; - q = p * dli + q * dlr; - p = temp; - if (abs(dlr - 1.0) + abs(dli) <= EPS) - break; - } - if (i >= MAXIT) - throw new IllegalArgumentException("cf2 failed in besseljy"); - gam = (p - f) / q; - rjmu = sqrt(w / ((p - f) * gam + q)); - rjmu = SIGN(rjmu, rjl); - rymu = rjmu * gam; - rymup = rymu * (p + q / gam); - ry1 = xmu * xi * rymu - rymup; - } - fact = rjmu / rjl; - jo = rjl1 * fact; - jpo = rjp1 * fact; - for (i = 1; i <= nl; i++) { - rytemp = (xmu + i) * xi2 * ry1 - rymu; - rymu = ry1; - ry1 = rytemp; - } - yo = rymu; - ypo = nu * xi * rymu - ry1; - xjy = x; - nujy = nu; - } - - public void besselik(final double nu, final double x) { - final int MAXIT = 10000; - final double EPS = DBL_EPSILON; - final double FPMIN = Double.MIN_NORMAL / EPS; - final double XMIN = 2.0, PI = 3.141592653589793; - double a, a1, b, c, d, del, del1, delh, dels, e, f, fact, fact2, ff, gam1, gam2, gammi, gampl, h, p, pimu, q, q1, q2, qnew, ril, ril1, rimu, rip1, ripl, ritemp, rk1, rkmu, rkmup, rktemp, s, sum, sum1, x2, xi, xi2, xmu, xmu2, xx; - int i, l, nl; - if (x <= 0.0 || nu < 0.0) - throw new IllegalArgumentException("bad arguments in besselik"); - nl = (int) (nu + 0.5); - xmu = nu - nl; - xmu2 = xmu * xmu; - xi = 1.0 / x; - xi2 = 2.0 * xi; - h = nu * xi; - if (h < FPMIN) - h = FPMIN; - b = xi2 * nu; - d = 0.0; - c = h; - for (i = 0; i < MAXIT; i++) { - b += xi2; - d = 1.0 / (b + d); - c = b + 1.0 / c; - del = c * d; - h = del * h; - if (abs(del - 1.0) <= EPS) - break; - } - if (i >= MAXIT) - throw new IllegalArgumentException( - "x too large in besselik; try asymptotic expansion"); - ril = FPMIN; - ripl = h * ril; - ril1 = ril; - rip1 = ripl; - fact = nu * xi; - for (l = nl - 1; l >= 0; l--) { - ritemp = fact * ril + ripl; - fact -= xi; - ripl = fact * ritemp + ril; - ril = ritemp; - } - f = ripl / ril; - if (x < XMIN) { - x2 = 0.5 * x; - pimu = PI * xmu; - fact = (abs(pimu) < EPS ? 1.0 : pimu / sin(pimu)); - d = -log(x2); - e = xmu * d; - fact2 = (abs(e) < EPS ? 1.0 : sinh(e) / e); - xx = 8.0 * SQR(xmu) - 1.0; - gam1 = chebev(c1, NUSE1, xx); - gam2 = chebev(c2, NUSE2, xx); - gampl = gam2 - xmu * gam1; - gammi = gam2 + xmu * gam1; - ff = fact * (gam1 * cosh(e) + gam2 * fact2 * d); - sum = ff; - e = exp(e); - p = 0.5 * e / gampl; - q = 0.5 / (e * gammi); - c = 1.0; - d = x2 * x2; - sum1 = p; - for (i = 1; i <= MAXIT; i++) { - ff = (i * ff + p + q) / (i * i - xmu2); - c *= (d / i); - p /= (i - xmu); - q /= (i + xmu); - del = c * ff; - sum += del; - del1 = c * (p - i * ff); - sum1 += del1; - if (abs(del) < abs(sum) * EPS) - break; - } - if (i > MAXIT) - throw new IllegalArgumentException( - "bessk series failed to converge"); - rkmu = sum; - rk1 = sum1 * xi2; - } else { - b = 2.0 * (1.0 + x); - d = 1.0 / b; - h = delh = d; - q1 = 0.0; - q2 = 1.0; - a1 = 0.25 - xmu2; - q = c = a1; - a = -a1; - s = 1.0 + q * delh; - for (i = 1; i < MAXIT; i++) { - a -= 2 * i; - c = -a * c / (i + 1.0); - qnew = (q1 - b * q2) / a; - q1 = q2; - q2 = qnew; - q += c * qnew; - b += 2.0; - d = 1.0 / (b + a * d); - delh = (b * d - 1.0) * delh; - h += delh; - dels = q * delh; - s += dels; - if (abs(dels / s) <= EPS) - break; - } - if (i >= MAXIT) - throw new IllegalArgumentException( - "besselik: failure to converge in cf2"); - h = a1 * h; - rkmu = sqrt(PI / (2.0 * x)) * exp(-x) / s; - rk1 = rkmu * (xmu + x + 0.5 - h) * xi; - } - rkmup = xmu * xi * rkmu - rk1; - rimu = xi / (f * rkmu - rkmup); - io = (rimu * ril1) / ril; - ipo = (rimu * rip1) / ril; - for (i = 1; i <= nl; i++) { - rktemp = (xmu + i) * xi2 * rk1 + rkmu; - rkmu = rk1; - rk1 = rktemp; - } - ko = rkmu; - kpo = nu * xi * rkmu - rk1; - xik = x; - nuik = nu; - } - - public void airy(final double x) { - final double ONOVRT = 0.577350269189626, THR = 1. / 3., TWOTHR = 2. * THR; - double absx, rootx, z; - absx = abs(x); - rootx = sqrt(absx); - z = TWOTHR * absx * rootx; - if (x > 0.0) { - besselik(THR, z); - aio = rootx * ONOVRT * ko / PI; - bio = rootx * (ko / PI + 2.0 * ONOVRT * io); - besselik(TWOTHR, z); - aipo = -x * ONOVRT * ko / PI; - bipo = x * (ko / PI + 2.0 * ONOVRT * io); - } else if (x < 0.0) { - besseljy(THR, z); - aio = 0.5 * rootx * (jo - ONOVRT * yo); - bio = -0.5 * rootx * (yo + ONOVRT * jo); - besseljy(TWOTHR, z); - aipo = 0.5 * absx * (ONOVRT * yo + jo); - bipo = 0.5 * absx * (ONOVRT * jo - yo); - } else { - aio = 0.355028053887817; - bio = aio / ONOVRT; - aipo = -0.258819403792807; - bipo = -aipo / ONOVRT; - } - } - - public double airy_ai(final double x) { - if (x != xai) - airy(x); - return aio; - } - - public double airy_bi(final double x) { - if (x != xai) - airy(x); - return bio; - } - - public void sphbes(final int n, final double x) { - final double RTPIO2 = 1.253314137315500251; - double factor, order; - if (n < 0 || x <= 0.0) - throw new IllegalArgumentException("bad arguments in sphbes"); - order = n + 0.5; - besseljy(order, x); - factor = RTPIO2 / sqrt(x); - sphjo = factor * jo; - sphyo = factor * yo; - sphjpo = factor * jpo - sphjo / (2. * x); - sphypo = factor * ypo - sphyo / (2. * x); - sphno = n; - } - - public double sphbesj(final int n, final double x) { - if (n != sphno || x != xsph) - sphbes(n, x); - return sphjo; - } - - public double sphbesy(final int n, final double x) { - if (n != sphno || x != xsph) - sphbes(n, x); - return sphyo; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Bessik.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Bessik.java deleted file mode 100644 index 4cbf4eaa94..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Bessik.java +++ /dev/null @@ -1,187 +0,0 @@ -package com.nr.sf; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import org.netlib.util.intW; - -/** - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Bessik { - private static final double i0p[] = { 9.999999999999997e-1, - 2.466405579426905e-1, 1.478980363444585e-2, 3.826993559940360e-4, - 5.395676869878828e-6, 4.700912200921704e-8, 2.733894920915608e-10, - 1.115830108455192e-12, 3.301093025084127e-15, - 7.209167098020555e-18, 1.166898488777214e-20, - 1.378948246502109e-23, 1.124884061857506e-26, 5.498556929587117e-30 }; - private static final double i0q[] = { 4.463598170691436e-1, - 1.702205745042606e-3, 2.792125684538934e-6, 2.369902034785866e-9, - 8.965900179621208e-13 }; - private static final double i0pp[] = { 1.192273748120670e-1, - 1.947452015979746e-1, 7.629241821600588e-2, 8.474903580801549e-3, - 2.023821945835647e-4 }; - private static final double i0qq[] = { 2.962898424533095e-1, - 4.866115913196384e-1, 1.938352806477617e-1, 2.261671093400046e-2, - 6.450448095075585e-4, 1.529835782400450e-6 }; - private static final double i1p[] = { 5.000000000000000e-1, - 6.090824836578078e-2, 2.407288574545340e-3, 4.622311145544158e-5, - 5.161743818147913e-7, 3.712362374847555e-9, 1.833983433811517e-11, - 6.493125133990706e-14, 1.693074927497696e-16, - 3.299609473102338e-19, 4.813071975603122e-22, - 5.164275442089090e-25, 3.846870021788629e-28, 1.712948291408736e-31 }; - private static final double i1q[] = { 4.665973211630446e-1, - 1.677754477613006e-3, 2.583049634689725e-6, 2.045930934253556e-9, - 7.166133240195285e-13 }; - private static final double i1pp[] = { 1.286515211317124e-1, - 1.930915272916783e-1, 6.965689298161343e-2, 7.345978783504595e-3, - 1.963602129240502e-4 }; - private static final double i1qq[] = { 3.309385098860755e-1, - 4.878218424097628e-1, 1.663088501568696e-1, 1.473541892809522e-2, - 1.964131438571051e-4, -1.034524660214173e-6 }; - private static final double k0pi[] = { 1.0, 2.346487949187396e-1, - 1.187082088663404e-2, 2.150707366040937e-4, 1.425433617130587e-6 }; - private static final double k0qi[] = { 9.847324170755358e-1, - 1.518396076767770e-2, 8.362215678646257e-5 }; - private static final double k0p[] = { 1.159315156584126e-1, - 2.770731240515333e-1, 2.066458134619875e-2, 4.574734709978264e-4, - 3.454715527986737e-6 }; - private static final double k0q[] = { 9.836249671709183e-1, - 1.627693622304549e-2, 9.809660603621949e-5 }; - private static final double k0pp[] = { 1.253314137315499, - 1.475731032429900e1, 6.123767403223466e1, 1.121012633939949e2, - 9.285288485892228e1, 3.198289277679660e1, 3.595376024148513, - 6.160228690102976e-2 }; - private static final double k0qq[] = { 1.0, 1.189963006673403e1, - 5.027773590829784e1, 9.496513373427093e1, 8.318077493230258e1, - 3.181399777449301e1, 4.443672926432041, 1.408295601966600e-1 }; - private static final double k1pi[] = { 0.5, 5.598072040178741e-2, - 1.818666382168295e-3, 2.397509908859959e-5, 1.239567816344855e-7 }; - private static final double k1qi[] = { 9.870202601341150e-1, - 1.292092053534579e-2, 5.881933053917096e-5 }; - private static final double k1p[] = { -3.079657578292062e-1, - -8.109417631822442e-2, -3.477550948593604e-3, - -5.385594871975406e-5, -3.110372465429008e-7 }; - private static final double k1q[] = { 9.861813171751389e-1, - 1.375094061153160e-2, 6.774221332947002e-5 }; - private static final double k1pp[] = { 1.253314137315502, - 1.457171340220454e1, 6.063161173098803e1, 1.147386690867892e2, - 1.040442011439181e2, 4.356596656837691e1, 7.265230396353690, - 3.144418558991021e-1 }; - private static final double k1qq[] = { 1.0, 1.125154514806458e1, - 4.427488496597630e1, 7.616113213117645e1, 5.863377227890893e1, - 1.850303673841586e1, 1.857244676566022, 2.538540887654872e-2 }; - - private double y, z, ax, term; - - public Bessik() { - } - - public double i0(final double x) { - if ((ax = abs(x)) < 15.0) { - y = x * x; - return poly(i0p, 13, y) / poly(i0q, 4, 225. - y); - } else { - z = 1.0 - 15.0 / ax; - return exp(ax) * poly(i0pp, 4, z) / (poly(i0qq, 5, z) * sqrt(ax)); - } - } - - public double i1(final double x) { - if ((ax = abs(x)) < 15.0) { - y = x * x; - return x * poly(i1p, 13, y) / poly(i1q, 4, 225. - y); - } else { - z = 1.0 - 15.0 / ax; - double ans = exp(ax) * poly(i1pp, 4, z) - / (poly(i1qq, 5, z) * sqrt(ax)); - return x > 0.0 ? ans : -ans; - } - } - - public double k0(final double x) { - if (x <= 1.0) { - z = x * x; - term = poly(k0pi, 4, z) * log(x) / poly(k0qi, 2, 1. - z); - return poly(k0p, 4, z) / poly(k0q, 2, 1. - z) - term; - } else { - z = 1.0 / x; - return exp(-x) * poly(k0pp, 7, z) / (poly(k0qq, 7, z) * sqrt(x)); - } - } - - public double k1(final double x) { - if (x <= 1.0) { - z = x * x; - term = poly(k1pi, 4, z) * log(x) / poly(k1qi, 2, 1. - z); - return x * (poly(k1p, 4, z) / poly(k1q, 2, 1. - z) + term) + 1. / x; - } else { - z = 1.0 / x; - return exp(-x) * poly(k1pp, 7, z) / (poly(k1qq, 7, z) * sqrt(x)); - } - } - - public double poly(final double[] cof, final int n, final double x) { - double ans = cof[n]; - for (int i = n - 1; i >= 0; i--) - ans = ans * x + cof[i]; - return ans; - } - - public double kn(final int n, final double x) { - int j; - double bk, bkm, bkp, tox; - if (n == 0) - return k0(x); - if (n == 1) - return k1(x); - tox = 2.0 / x; - bkm = k0(x); - bk = k1(x); - for (j = 1; j < n; j++) { - bkp = bkm + j * tox * bk; - bkm = bk; - bk = bkp; - } - return bk; - } - - public double in(final int n, final double x) { - final double ACC = 200.0; - final int IEXP = Double.MAX_EXPONENT / 2; // numeric_limits::max_exponent/2; - int j; - intW k = new intW(0); - double bi, bim, bip, dum, tox, ans; - if (n == 0) - return i0(x); - if (n == 1) - return i1(x); - if (x * x <= 8.0 * Double.MIN_NORMAL) - return 0.0; - else { - tox = 2.0 / abs(x); - bip = ans = 0.0; - bi = 1.0; - for (j = 2 * (n + (int) (sqrt(ACC * n))); j > 0; j--) { - bim = bip + j * tox * bi; - bip = bi; - bi = bim; - dum = frexp(bi, k); - dum = dum + 0; - if (k.val > IEXP) { - ans = ldexp(ans, -IEXP); - bi = ldexp(bi, -IEXP); - bip = ldexp(bip, -IEXP); - } - if (j == n) - ans = bip; - } - ans *= i0(x) / bi; - return (x < 0.0 && (n & 1) != 0) ? -ans : ans; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Bessjy.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Bessjy.java deleted file mode 100644 index 20a4508155..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Bessjy.java +++ /dev/null @@ -1,235 +0,0 @@ -package com.nr.sf; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import org.netlib.util.intW; - -public class Bessjy { - private static final double xj00 = 5.783185962946785; - private static final double xj10 = 3.047126234366209e1; - private static final double xj01 = 1.468197064212389e1; - private static final double xj11 = 4.921845632169460e1; - private static final double twoopi = 0.6366197723675813; - private static final double pio4 = 0.7853981633974483; - private static final double j0r[] = { 1.682397144220462e-4, - 2.058861258868952e-5, 5.288947320067750e-7, 5.557173907680151e-9, - 2.865540042042604e-11, 7.398972674152181e-14, 7.925088479679688e-17 }; - private static final double j0s[] = { 1.0, 1.019685405805929e-2, - 5.130296867064666e-5, 1.659702063950243e-7, 3.728997574317067e-10, - 5.709292619977798e-13, 4.932979170744996e-16 }; - private static final double j0pn[] = { 9.999999999999999e-1, - 1.039698629715637, 2.576910172633398e-1, 1.504152485749669e-2, - 1.052598413585270e-4 }; - private static final double j0pd[] = { 1.0, 1.040797262528109, - 2.588070904043728e-1, 1.529954477721284e-2, 1.168931211650012e-4 }; - private static final double j0qn[] = { -1.562499999999992e-2, - -1.920039317065641e-2, -5.827951791963418e-3, - -4.372674978482726e-4, -3.895839560412374e-6 }; - private static final double j0qd[] = { 1.0, 1.237980436358390, - 3.838793938147116e-1, 3.100323481550864e-2, 4.165515825072393e-4 }; - private static final double j1r[] = { 7.309637831891357e-5, - 3.551248884746503e-6, 5.820673901730427e-8, 4.500650342170622e-10, - 1.831596352149641e-12, 3.891583573305035e-15, 3.524978592527982e-18 }; - private static final double j1s[] = { 1.0, 9.398354768446072e-3, - 4.328946737100230e-5, 1.271526296341915e-7, 2.566305357932989e-10, - 3.477378203574266e-13, 2.593535427519985e-16 }; - private static final double j1pn[] = { 1.0, 1.014039111045313, - 2.426762348629863e-1, 1.350308200342000e-2, 9.516522033988099e-5 }; - private static final double j1pd[] = { 1.0, 1.012208056357845, - 2.408580305488938e-1, 1.309511056184273e-2, 7.746422941504713e-5 }; - private static final double j1qn[] = { 4.687499999999991e-2, - 5.652407388406023e-2, 1.676531273460512e-2, 1.231216817715814e-3, - 1.178364381441801e-5 }; - private static final double j1qd[] = { 1.0, 1.210119370463693, - 3.626494789275638e-1, 2.761695824829316e-2, 3.240517192670181e-4 }; - private static final double y0r[] = { -7.653778457189104e-3, - -5.854760129990403e-2, 3.720671300654721e-4, 3.313722284628089e-5, - 4.247761237036536e-8, -4.134562661019613e-9, - -3.382190331837473e-11, -1.017764126587862e-13, - -1.107646382675456e-16 }; - private static final double y0s[] = { 1.0, 1.125494540257841e-2, - 6.427210537081400e-5, 2.462520624294959e-7, 7.029372432344291e-10, - 1.560784108184928e-12, 2.702374957564761e-15, - 3.468496737915257e-18, 2.716600180811817e-21 }; - private static final double y0pn[] = { 9.999999999999999e-1, - 1.039698629715637, 2.576910172633398e-1, 1.504152485749669e-2, - 1.052598413585270e-4 }; - private static final double y0pd[] = { 1.0, 1.040797262528109, - 2.588070904043728e-1, 1.529954477721284e-2, 1.168931211650012e-4 }; - private static final double y0qn[] = { -1.562499999999992e-2, - -1.920039317065641e-2, -5.827951791963418e-3, - -4.372674978482726e-4, -3.895839560412374e-6 }; - private static final double y0qd[] = { 1.0, 1.237980436358390, - 3.838793938147116e-1, 3.100323481550864e-2, 4.165515825072393e-4 }; - private static final double y1r[] = { -1.041835425863234e-1, - -1.135093963908952e-5, 2.212118520638132e-4, 1.270981874287763e-6, - -3.982892100836748e-8, -4.820712110115943e-10, - -1.929392690596969e-12, -2.725259514545605e-15 }; - private static final double y1s[] = { 1.0, 1.186694184425838e-2, - 7.121205411175519e-5, 2.847142454085055e-7, 8.364240962784899e-10, - 1.858128283833724e-12, 3.018846060781846e-15, 3.015798735815980e-18 }; - private static final double y1pn[] = { 1.0, 1.014039111045313, - 2.426762348629863e-1, 1.350308200342000e-2, 9.516522033988099e-5 }; - private static final double y1pd[] = { 1.0, 1.012208056357845, - 2.408580305488938e-1, 1.309511056184273e-2, 7.746422941504713e-5 }; - private static final double y1qn[] = { 4.687499999999991e-2, - 5.652407388406023e-2, 1.676531273460512e-2, 1.231216817715814e-3, - 1.178364381441801e-5 }; - private static final double y1qd[] = { 1.0, 1.210119370463693, - 3.626494789275638e-1, 2.761695824829316e-2, 3.240517192670181e-4 }; - private double nump, denp, numq, denq, y, z, ax, xx; - - public Bessjy() { - } - - public double j0(final double x) { - if ((ax = abs(x)) < 8.0) { - rat(x, j0r, j0s, 6); - return nump * (y - xj00) * (y - xj10) / denp; - } else { - asp(j0pn, j0pd, j0qn, j0qd, 1.); - return sqrt(twoopi / ax) - * (cos(xx) * nump / denp - z * sin(xx) * numq / denq); - } - } - - public double j1(final double x) { - if ((ax = abs(x)) < 8.0) { - rat(x, j1r, j1s, 6); - return x * nump * (y - xj01) * (y - xj11) / denp; - } else { - asp(j1pn, j1pd, j1qn, j1qd, 3.); - double ans = sqrt(twoopi / ax) - * (cos(xx) * nump / denp - z * sin(xx) * numq / denq); - return x > 0.0 ? ans : -ans; - } - } - - public double y0(final double x) { - if (x < 8.0) { - double j0x = j0(x); - rat(x, y0r, y0s, 8); - return nump / denp + twoopi * j0x * log(x); - } else { - ax = x; - asp(y0pn, y0pd, y0qn, y0qd, 1.); - return sqrt(twoopi / x) - * (sin(xx) * nump / denp + z * cos(xx) * numq / denq); - } - } - - public double y1(final double x) { - if (x < 8.0) { - double j1x = j1(x); - rat(x, y1r, y1s, 7); - return x * nump / denp + twoopi * (j1x * log(x) - 1.0 / x); - } else { - ax = x; - asp(y1pn, y1pd, y1qn, y1qd, 3.); - return sqrt(twoopi / x) - * (sin(xx) * nump / denp + z * cos(xx) * numq / denq); - } - } - - public void rat(final double x, final double[] r, final double[] s, - final int n) { - y = x * x; - z = 64.0 - y; - nump = r[n]; - denp = s[n]; - for (int i = n - 1; i >= 0; i--) { - nump = nump * z + r[i]; - denp = denp * y + s[i]; - } - } - - public void asp(final double[] pn, final double[] pd, final double[] qn, - final double[] qd, final double fac) { - z = 8.0 / ax; - y = z * z; - xx = ax - fac * pio4; - nump = pn[4]; - denp = pd[4]; - numq = qn[4]; - denq = qd[4]; - for (int i = 3; i >= 0; i--) { - nump = nump * y + pn[i]; - denp = denp * y + pd[i]; - numq = numq * y + qn[i]; - denq = denq * y + qd[i]; - } - } - - public double jn(final int n, final double x) { - final double ACC = 160.0; - final int IEXP = Double.MAX_EXPONENT / 2; // numeric_limits::max_exponent/2; - boolean jsum; - int j, m; - intW k = new intW(0); - double ax, bj, bjm, bjp, dum, sum, tox, ans; - if (n == 0) - return j0(x); - if (n == 1) - return j1(x); - ax = abs(x); - if (ax * ax <= 8.0 * Double.MIN_NORMAL) - return 0.0; - else if (ax > n) { - tox = 2.0 / ax; - bjm = j0(ax); - bj = j1(ax); - for (j = 1; j < n; j++) { - bjp = j * tox * bj - bjm; - bjm = bj; - bj = bjp; - } - ans = bj; - } else { - tox = 2.0 / ax; - m = 2 * ((n + (int) (sqrt(ACC * n))) / 2); - jsum = false; - bjp = ans = sum = 0.0; - bj = 1.0; - for (j = m; j > 0; j--) { - bjm = j * tox * bj - bjp; - bjp = bj; - bj = bjm; - dum = frexp(bj, k); - dum = dum + 0; - if (k.val > IEXP) { - - bj = ldexp(bj, -IEXP); - bjp = ldexp(bjp, -IEXP); - ans = ldexp(ans, -IEXP); - sum = ldexp(sum, -IEXP); - } - if (jsum) - sum += bj; - jsum = !jsum; - if (j == n) - ans = bjp; - } - sum = 2.0 * sum - bj; - ans /= sum; - } - return (x < 0.0 && (n & 1) != 0) ? -ans : ans; - } - - public double yn(final int n, final double x) { - int j; - double by, bym, byp, tox; - if (n == 0) - return y0(x); - if (n == 1) - return y1(x); - tox = 2.0 / x; - by = y1(x); - bym = y0(x); - for (j = 1; j < n; j++) { - byp = j * tox * by - bym; - bym = by; - by = byp; - } - return by; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Beta.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Beta.java deleted file mode 100644 index 09ccc370ee..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Beta.java +++ /dev/null @@ -1,167 +0,0 @@ -package com.nr.sf; - -import static com.nr.NRUtil.*; -import static com.nr.sf.Gamma.*; -import static java.lang.Math.*; - -/** - * Object for incomplete beta function. Gauleg18 provides coefficients for - * Gauss-Legendre quadrature. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Beta implements Gauleg18 { - private static final int SWITCH = 3000; - private static final double EPS = DBL_EPSILON;; - private static final double FPMIN = Double.MIN_NORMAL / EPS; - - public static double betai(final double a, final double b, final double x) { - double bt; - if (a <= 0.0 || b <= 0.0) - throw new IllegalArgumentException("Bad a or b in routine betai"); - if (x < 0.0 || x > 1.0) - throw new IllegalArgumentException("Bad x in routine betai"); - if (x == 0.0 || x == 1.0) - return x; - if (a > SWITCH && b > SWITCH) - return betaiapprox(a, b, x); - bt = exp(gammln(a + b) - gammln(a) - gammln(b) + a * log(x) + b - * log(1.0 - x)); - if (x < (a + 1.0) / (a + b + 2.0)) - return bt * betacf(a, b, x) / a; - else - return 1.0 - bt * betacf(b, a, 1.0 - x) / b; - } - - public static double betacf(final double a, final double b, final double x) { - int m, m2; - double aa, c, d, del, h, qab, qam, qap; - qab = a + b; - qap = a + 1.0; - qam = a - 1.0; - c = 1.0; - d = 1.0 - qab * x / qap; - if (abs(d) < FPMIN) - d = FPMIN; - d = 1.0 / d; - h = d; - for (m = 1; m < 10000; m++) { - m2 = 2 * m; - aa = m * (b - m) * x / ((qam + m2) * (a + m2)); - d = 1.0 + aa * d; - if (abs(d) < FPMIN) - d = FPMIN; - c = 1.0 + aa / c; - if (abs(c) < FPMIN) - c = FPMIN; - d = 1.0 / d; - h *= d * c; - aa = -(a + m) * (qab + m) * x / ((a + m2) * (qap + m2)); - d = 1.0 + aa * d; - if (abs(d) < FPMIN) - d = FPMIN; - c = 1.0 + aa / c; - if (abs(c) < FPMIN) - c = FPMIN; - d = 1.0 / d; - del = d * c; - h *= del; - if (abs(del - 1.0) <= EPS) - break; - } - return h; - } - - public static double betaiapprox(final double a, final double b, - final double x) { - int j; - double xu, t, sum, ans; - double a1 = a - 1.0, b1 = b - 1.0, mu = a / (a + b); - double lnmu = log(mu), lnmuc = log(1. - mu); - t = sqrt(a * b / (SQR(a + b) * (a + b + 1.0))); - if (x > a / (a + b)) { - if (x >= 1.0) - return 1.0; - xu = min(1., max(mu + 10. * t, x + 5.0 * t)); - } else { - if (x <= 0.0) - return 0.0; - xu = max(0., min(mu - 10. * t, x - 5.0 * t)); - } - sum = 0; - for (j = 0; j < 18; j++) { - t = x + (xu - x) * y[j]; - sum += w[j] * exp(a1 * (log(t) - lnmu) + b1 * (log(1 - t) - lnmuc)); - } - ans = sum - * (xu - x) - * exp(a1 * lnmu - gammln(a) + b1 * lnmuc - gammln(b) - + gammln(a + b)); - return ans > 0.0 ? 1.0 - ans : -ans; - } - - public static double invbetai(final double p, final double a, final double b) { - final double EPS = 1.e-8; - double pp, t, u, err, x, al, h, w, afac, a1 = a - 1., b1 = b - 1.; - int j; - if (p <= 0.) - return 0.; - else if (p >= 1.) - return 1.; - else if (a >= 1. && b >= 1.) { - pp = (p < 0.5) ? p : 1. - p; - t = sqrt(-2. * log(pp)); - x = (2.30753 + t * 0.27061) / (1. + t * (0.99229 + t * 0.04481)) - - t; - if (p < 0.5) - x = -x; - al = (SQR(x) - 3.) / 6.; - h = 2. / (1. / (2. * a - 1.) + 1. / (2. * b - 1.)); - w = (x * sqrt(al + h) / h) - - (1. / (2. * b - 1) - 1. / (2. * a - 1.)) - * (al + 5. / 6. - 2. / (3. * h)); - x = a / (a + b * exp(2. * w)); - } else { - double lna = log(a / (a + b)), lnb = log(b / (a + b)); - t = exp(a * lna) / a; - u = exp(b * lnb) / b; - w = t + u; - if (p < t / w) - x = pow(a * w * p, 1. / a); - else - x = 1. - pow(b * w * (1. - p), 1. / b); - } - afac = -gammln(a) - gammln(b) + gammln(a + b); - for (j = 0; j < 10; j++) { - if (x == 0. || x == 1.) - return x; - err = betai(a, b, x) - p; - t = exp(a1 * log(x) + b1 * log(1. - x) + afac); - u = err / t; - x -= (t = u / (1. - 0.5 * min(1., u * (a1 / x - b1 / (1. - x))))); - if (x <= 0.) - x = 0.5 * (x + t); - if (x >= 1.) - x = 0.5 * (x + t + 1.); - if (abs(t) < EPS * x && j > 0) - break; - } - return x; - } - - /** - * Returns the value of the beta function B(z,w). - * - * @param z - * @param w - * @return - */ - public static double beta(final double z, final double w) { - return exp(gammln(z) + gammln(w) - gammln(z + w)); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Betadist.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Betadist.java deleted file mode 100644 index f3a554fbaa..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Betadist.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.nr.sf; - -import static java.lang.Math.*; -import static com.nr.sf.Gamma.*; - -public class Betadist extends Beta { - double alph, bet, fac; - - public Betadist(double aalph, double bbet) { - alph = aalph; - bet = bbet; - if (alph <= 0. || bet <= 0.) - throw new IllegalArgumentException("bad alph,bet in Betadist"); - fac = gammln(alph + bet) - gammln(alph) - gammln(bet); - } - - public double p(double x) { - if (x <= 0. || x >= 1.) - throw new IllegalArgumentException("bad x in Betadist"); - return exp((alph - 1.) * log(x) + (bet - 1.) * log(1. - x) + fac); - } - - public double cdf(double x) { - if (x < 0. || x > 1.) - throw new IllegalArgumentException("bad x in Betadist"); - return betai(alph, bet, x); - } - - public double invcdf(double p) { - if (p < 0. || p > 1.) - throw new IllegalArgumentException("bad p in Betadist"); - return invbetai(p, alph, bet); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Binomialdist.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Binomialdist.java deleted file mode 100644 index a09fd9fca0..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Binomialdist.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.nr.sf; - -import static java.lang.Math.*; -import static com.nr.sf.Gamma.*; - -public class Binomialdist extends Beta { - int n; - double pe, fac; - - public Binomialdist(int nn, double ppe) { - n = nn; - pe = ppe; - if (n <= 0 || pe <= 0. || pe >= 1.) - throw new IllegalArgumentException("bad args in Binomialdist"); - fac = gammln(n + 1.); - } - - public double p(int k) { - if (k < 0) - throw new IllegalArgumentException("bad k in Binomialdist"); - if (k > n) - return 0.; - return exp(k * log(pe) + (n - k) * log(1. - pe) + fac - gammln(k + 1.) - - gammln(n - k + 1.)); - } - - public double cdf(int k) { - if (k < 0) - throw new IllegalArgumentException("bad k in Binomialdist"); - if (k == 0) - return 0.; - if (k > n) - return 1.; - return 1. - betai(k, n - k + 1., pe); - } - - public int invcdf(double p) { - int k, kl, ku, inc = 1; - if (p <= 0. || p >= 1.) - throw new IllegalArgumentException("bad p in Binomialdist"); - k = max(0, min(n, (int) (n * pe))); - if (p < cdf(k)) { - do { - k = max(k - inc, 0); - inc *= 2; - } while (p < cdf(k)); - kl = k; - ku = k + inc / 2; - } else { - do { - k = min(k + inc, n + 1); - inc *= 2; - } while (p > cdf(k)); - ku = k; - kl = k - inc / 2; - } - while (ku - kl > 1) { - k = (kl + ku) / 2; - if (p < cdf(k)) - ku = k; - else - kl = k; - } - return kl; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Cauchydist.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Cauchydist.java deleted file mode 100644 index 534055cd56..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Cauchydist.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.nr.sf; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -/** - * Cauchy distribution. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Cauchydist { - double mu, sig; - - public Cauchydist() { - this(0., 1.); - } - - public Cauchydist(final double mmu, final double ssig) { - mu = mmu; - sig = ssig; - if (sig <= 0.) - throw new IllegalArgumentException("bad sig in Cauchydist"); - } - - public double p(final double x) { - return 0.318309886183790671 / (sig * (1. + SQR((x - mu) / sig))); - } - - public double cdf(final double x) { - return 0.5 + 0.318309886183790671 * atan2(x - mu, sig); - } - - public double invcdf(final double p) { - if (p <= 0. || p >= 1.) - throw new IllegalArgumentException("bad p in Cauchydist"); - return mu + sig * tan(3.14159265358979324 * (p - 0.5)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Chisqdist.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Chisqdist.java deleted file mode 100644 index d069339239..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Chisqdist.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.nr.sf; - -import static java.lang.Math.*; - -public class Chisqdist extends Gamma { - double nu, fac; - - public Chisqdist(double nnu) { - nu = nnu; - if (nu <= 0.) - throw new IllegalArgumentException("bad nu in Chisqdist"); - fac = 0.693147180559945309 * (0.5 * nu) + gammln(0.5 * nu); - } - - public double p(double x2) { - if (x2 <= 0.) - throw new IllegalArgumentException("bad x2 in Chisqdist"); - return exp(-0.5 * (x2 - (nu - 2.) * log(x2)) - fac); - } - - public double cdf(double x2) { - if (x2 < 0.) - throw new IllegalArgumentException("bad x2 in Chisqdist"); - return gammp(0.5 * nu, 0.5 * x2); - } - - public double invcdf(double p) { - if (p < 0. || p >= 1.) - throw new IllegalArgumentException("bad p in Chisqdist"); - return 2. * invgammp(p, 0.5 * nu); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Elliptic.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Elliptic.java deleted file mode 100644 index 1f3d7210a6..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Elliptic.java +++ /dev/null @@ -1,260 +0,0 @@ -package com.nr.sf; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import org.netlib.util.*; - -/** - * Elliptic Integrals and Jacobian Elliptic Functions Copyright (C) Numerical - * Recipes Software 1986-2007 Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Elliptic { - private Elliptic() { - } - - public static double rc(final double x, final double y) { - final double ERRTOL = 0.0012, THIRD = 1.0 / 3.0, C1 = 0.3, C2 = 1.0 / 7.0, C3 = 0.375, C4 = 9.0 / 22.0; - final double TINY = 5.0 * Double.MIN_NORMAL, BIG = 0.2 * Double.MAX_VALUE, COMP1 = 2.236 / sqrt(TINY), COMP2 = SQR(TINY - * BIG) / 25.0; - double alamb, ave, s, w, xt, yt; - if (x < 0.0 || y == 0.0 || (x + abs(y)) < TINY || (x + abs(y)) > BIG - || (y < -COMP1 && x > 0.0 && x < COMP2)) - throw new IllegalArgumentException("invalid arguments in rc"); - if (y > 0.0) { - xt = x; - yt = y; - w = 1.0; - } else { - xt = x - y; - yt = -y; - w = sqrt(x) / sqrt(xt); - } - do { - alamb = 2.0 * sqrt(xt) * sqrt(yt) + yt; - xt = 0.25 * (xt + alamb); - yt = 0.25 * (yt + alamb); - ave = THIRD * (xt + yt + yt); - s = (yt - ave) / ave; - } while (abs(s) > ERRTOL); - return w * (1.0 + s * s * (C1 + s * (C2 + s * (C3 + s * C4)))) - / sqrt(ave); - } - - public static double rd(final double x, final double y, final double z) { - final double ERRTOL = 0.0015, C1 = 3.0 / 14.0, C2 = 1.0 / 6.0, C3 = 9.0 / 22.0, C4 = 3.0 / 26.0, C5 = 0.25 * C3, C6 = 1.5 * C4; - final double TINY = 2.0 * pow(Double.MAX_VALUE, -2. / 3.), BIG = 0.1 - * ERRTOL * pow(Double.MIN_NORMAL, -2. / 3.); - double alamb, ave, delx, dely, delz, ea, eb, ec, ed, ee, fac, sqrtx, sqrty, sqrtz, sum, xt, yt, zt; - if (min(x, y) < 0.0 || min(x + y, z) < TINY || max(max(x, y), z) > BIG) - throw new IllegalArgumentException("invalid arguments in rd"); - xt = x; - yt = y; - zt = z; - sum = 0.0; - fac = 1.0; - do { - sqrtx = sqrt(xt); - sqrty = sqrt(yt); - sqrtz = sqrt(zt); - alamb = sqrtx * (sqrty + sqrtz) + sqrty * sqrtz; - sum += fac / (sqrtz * (zt + alamb)); - fac = 0.25 * fac; - xt = 0.25 * (xt + alamb); - yt = 0.25 * (yt + alamb); - zt = 0.25 * (zt + alamb); - ave = 0.2 * (xt + yt + 3.0 * zt); - delx = (ave - xt) / ave; - dely = (ave - yt) / ave; - delz = (ave - zt) / ave; - } while (max(max(abs(delx), abs(dely)), abs(delz)) > ERRTOL); - ea = delx * dely; - eb = delz * delz; - ec = ea - eb; - ed = ea - 6.0 * eb; - ee = ed + ec + ec; - return 3.0 - * sum - + fac - * (1.0 + ed * (-C1 + C5 * ed - C6 * delz * ee) + delz - * (C2 * ee + delz * (-C3 * ec + delz * C4 * ea))) - / (ave * sqrt(ave)); - } - - public static double rf(final double x, final double y, final double z) { - final double ERRTOL = 0.0025, THIRD = 1.0 / 3.0, C1 = 1.0 / 24.0, C2 = 0.1, C3 = 3.0 / 44.0, C4 = 1.0 / 14.0; - final double TINY = 5.0 * Double.MIN_NORMAL, BIG = 0.2 * Double.MAX_VALUE; - double alamb, ave, delx, dely, delz, e2, e3, sqrtx, sqrty, sqrtz, xt, yt, zt; - if (min(min(x, y), z) < 0.0 || min(min(x + y, x + z), y + z) < TINY - || max(max(x, y), z) > BIG) - throw new IllegalArgumentException("invalid arguments in rf"); - xt = x; - yt = y; - zt = z; - do { - sqrtx = sqrt(xt); - sqrty = sqrt(yt); - sqrtz = sqrt(zt); - alamb = sqrtx * (sqrty + sqrtz) + sqrty * sqrtz; - xt = 0.25 * (xt + alamb); - yt = 0.25 * (yt + alamb); - zt = 0.25 * (zt + alamb); - ave = THIRD * (xt + yt + zt); - delx = (ave - xt) / ave; - dely = (ave - yt) / ave; - delz = (ave - zt) / ave; - } while (max(max(abs(delx), abs(dely)), abs(delz)) > ERRTOL); - e2 = delx * dely - delz * delz; - e3 = delx * dely * delz; - return (1.0 + (C1 * e2 - C2 - C3 * e3) * e2 + C4 * e3) / sqrt(ave); - } - - public static double rj(final double x, final double y, final double z, - final double p) { - final double ERRTOL = 0.0015, C1 = 3.0 / 14.0, C2 = 1.0 / 3.0, C3 = 3.0 / 22.0, C4 = 3.0 / 26.0, C5 = 0.75 * C3, C6 = 1.5 * C4, C7 = 0.5 * C2, C8 = C3 - + C3; - final double TINY = pow(5.0 * Double.MIN_NORMAL, 1. / 3.), BIG = 0.3 * pow( - 0.2 * Double.MAX_VALUE, 1. / 3.); - double a = 0, alamb, alpha, ans, ave, b = 0, beta, delp, delx, dely, delz, ea, eb, ec, ed, ee, fac, pt, rcx = 0, rho, sqrtx, sqrty, sqrtz, sum, tau, xt, yt, zt; - if (min(min(x, y), z) < 0.0 - || min(min(x + y, x + z), min(y + z, abs(p))) < TINY - || max(max(x, y), max(z, abs(p))) > BIG) - throw new IllegalArgumentException("invalid arguments in rj"); - sum = 0.0; - fac = 1.0; - if (p > 0.0) { - xt = x; - yt = y; - zt = z; - pt = p; - } else { - xt = min(min(x, y), z); - zt = max(max(x, y), z); - yt = x + y + z - xt - zt; - a = 1.0 / (yt - p); - b = a * (zt - yt) * (yt - xt); - pt = yt + b; - rho = xt * zt / yt; - tau = p * pt / yt; - rcx = rc(rho, tau); - } - do { - sqrtx = sqrt(xt); - sqrty = sqrt(yt); - sqrtz = sqrt(zt); - alamb = sqrtx * (sqrty + sqrtz) + sqrty * sqrtz; - alpha = SQR(pt * (sqrtx + sqrty + sqrtz) + sqrtx * sqrty * sqrtz); - beta = pt * SQR(pt + alamb); - sum += fac * rc(alpha, beta); - fac = 0.25 * fac; - xt = 0.25 * (xt + alamb); - yt = 0.25 * (yt + alamb); - zt = 0.25 * (zt + alamb); - pt = 0.25 * (pt + alamb); - ave = 0.2 * (xt + yt + zt + pt + pt); - delx = (ave - xt) / ave; - dely = (ave - yt) / ave; - delz = (ave - zt) / ave; - delp = (ave - pt) / ave; - } while (max(max(abs(delx), abs(dely)), max(abs(delz), abs(delp))) > ERRTOL); - ea = delx * (dely + delz) + dely * delz; - eb = delx * dely * delz; - ec = delp * delp; - ed = ea - 3.0 * ec; - ee = eb + 2.0 * delp * (ea - ec); - ans = 3.0 - * sum - + fac - * (1.0 + ed * (-C1 + C5 * ed - C6 * ee) + eb - * (C7 + delp * (-C8 + delp * C4)) + delp * ea - * (C2 - delp * C3) - C2 * delp * ec) - / (ave * sqrt(ave)); - if (p <= 0.0) - ans = a * (b * ans + 3.0 * (rcx - rf(xt, yt, zt))); - return ans; - } - - public static double ellf(final double phi, final double ak) { - double s = sin(phi); - return s * rf(SQR(cos(phi)), (1.0 - s * ak) * (1.0 + s * ak), 1.0); - } - - public static double elle(final double phi, final double ak) { - double cc, q, s; - s = sin(phi); - cc = SQR(cos(phi)); - q = (1.0 - s * ak) * (1.0 + s * ak); - return s * (rf(cc, q, 1.0) - (SQR(s * ak)) * rd(cc, q, 1.0) / 3.0); - } - - public static double ellpi(final double phi, final double en, - final double ak) { - double cc, enss, q, s; - s = sin(phi); - enss = en * s * s; - cc = SQR(cos(phi)); - q = (1.0 - s * ak) * (1.0 + s * ak); - return s * (rf(cc, q, 1.0) - enss * rj(cc, q, 1.0, 1.0 + enss) / 3.0); - } - - public static void sncndn(final double uu, final double emmc, - final doubleW sn, final doubleW cn, final doubleW dn) { - final double CA = 1.0e-8; - boolean bo; - int i, ii, l = 0; - double a, b, c = 0, d = 0, emc, u; - double[] em = new double[13]; - double[] en = new double[13]; - emc = emmc; - u = uu; - if (emc != 0.0) { - bo = (emc < 0.0); - if (bo) { - d = 1.0 - emc; - emc /= -1.0 / d; - u *= (d = sqrt(d)); - } - a = 1.0; - dn.val = 1.0; - for (i = 0; i < 13; i++) { - l = i; - em[i] = a; - en[i] = (emc = sqrt(emc)); - c = 0.5 * (a + emc); - if (abs(a - emc) <= CA * a) - break; - emc *= a; - a = c; - } - u *= c; - sn.val = sin(u); - cn.val = cos(u); - if (sn.val != 0.0) { - a = cn.val / sn.val; - c *= a; - for (ii = l; ii >= 0; ii--) { - b = em[ii]; - a *= c; - c *= dn.val; - dn.val = (en[ii] + a) / (b + a); - a = c / b; - } - a = 1.0 / sqrt(c * c + 1.0); - sn.val = (sn.val >= 0.0 ? a : -a); - cn.val = c * sn.val; - } - if (bo) { - a = dn.val; - dn.val = cn.val; - cn.val = a; - sn.val /= d; - } - } else { - cn.val = 1.0 / cosh(u); - dn.val = cn.val; - sn.val = tanh(u); - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Erf.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Erf.java deleted file mode 100644 index ac2da7c9ab..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Erf.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.nr.sf; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -/** - * Error function and related distributions Copyright (C) Numerical Recipes - * Software 1986-2007 Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Erf { - private static final int ncof = 28; - private static final double[] cof = { -1.3026537197817094, - 6.4196979235649026e-1, 1.9476473204185836e-2, - -9.561514786808631e-3, -9.46595344482036e-4, 3.66839497852761e-4, - 4.2523324806907e-5, -2.0278578112534e-5, -1.624290004647e-6, - 1.303655835580e-6, 1.5626441722e-8, -8.5238095915e-8, - 6.529054439e-9, 5.059343495e-9, -9.91364156e-10, -2.27365122e-10, - 9.6467911e-11, 2.394038e-12, -6.886027e-12, 8.94487e-13, - 3.13092e-13, -1.12708e-13, 3.81e-16, 7.106e-15, -1.523e-15, - -9.4e-17, 1.21e-16, -2.8e-17 }; - - public Erf() { - } - - public double erf(final double x) { - if (x >= 0.) - return 1.0 - erfccheb(x); - else - return erfccheb(-x) - 1.0; - } - - public double erfc(final double x) { - if (x >= 0.) - return erfccheb(x); - else - return 2.0 - erfccheb(-x); - } - - public double erfccheb(final double z) { - int j; - double t, ty, tmp, d = 0., dd = 0.; - if (z < 0.) - throw new IllegalArgumentException( - "erfccheb requires nonnegative argument"); - t = 2. / (2. + z); - ty = 4. * t - 2.; - for (j = ncof - 1; j > 0; j--) { - tmp = d; - d = ty * d - dd + cof[j]; - dd = tmp; - } - return t * exp(-z * z + 0.5 * (cof[0] + ty * d) - dd); - } - - public double inverfc(final double p) { - double x, err, t, pp; - if (p >= 2.0) - return -100.; - if (p <= 0.0) - return 100.; - pp = (p < 1.0) ? p : 2. - p; - t = sqrt(-2. * log(pp / 2.)); - x = -0.70711 - * ((2.30753 + t * 0.27061) / (1. + t * (0.99229 + t * 0.04481)) - t); - for (int j = 0; j < 2; j++) { - err = erfc(x) - pp; - x += err / (1.12837916709551257 * exp(-SQR(x)) - x * err); - } - return (p < 1.0 ? x : -x); - } - - public double inverf(final double p) { - return inverfc(1. - p); - } - - public static double erfcc(final double x) { - double t, z = abs(x), ans; - t = 2. / (2. + z); - ans = t - * exp(-z - * z - - 1.26551223 - + t - * (1.00002368 + t - * (0.37409196 + t - * (0.09678418 + t - * (-0.18628806 + t - * (0.27886807 + t - * (-1.13520398 + t - * (1.48851587 + t - * (-0.82215223 + t * 0.17087277))))))))); - return (x >= 0.0 ? ans : 2.0 - ans); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Expondist.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Expondist.java deleted file mode 100644 index 4d633b75f4..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Expondist.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.nr.sf; - -import static java.lang.Math.*; - -public class Expondist { - double bet; - - public Expondist(final double bbet) { - bet = bbet; - if (bet <= 0.) - throw new IllegalArgumentException("bad bet in Expondist"); - } - - public double p(final double x) { - if (x < 0.) - throw new IllegalArgumentException("bad x in Expondist"); - return bet * exp(-bet * x); - } - - public double cdf(final double x) { - if (x < 0.) - throw new IllegalArgumentException("bad x in Expondist"); - return 1. - exp(-bet * x); - } - - public double invcdf(final double p) { - if (p < 0. || p >= 1.) - throw new IllegalArgumentException("bad p in Expondist"); - return -log(1. - p) / bet; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Fdist.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Fdist.java deleted file mode 100644 index ef9172b250..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Fdist.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.nr.sf; - -import static java.lang.Math.*; -import static com.nr.sf.Gamma.*; - -public class Fdist extends Beta { - double nu1, nu2; - double fac; - - public Fdist(double nnu1, double nnu2) { - nu1 = nnu1; - nu2 = nnu2; - if (nu1 <= 0. || nu2 <= 0.) - throw new IllegalArgumentException("bad nu1,nu2 in Fdist"); - fac = 0.5 * (nu1 * log(nu1) + nu2 * log(nu2)) - + gammln(0.5 * (nu1 + nu2)) - gammln(0.5 * nu1) - - gammln(0.5 * nu2); - } - - public double p(double f) { - if (f <= 0.) - throw new IllegalArgumentException("bad f in Fdist"); - return exp((0.5 * nu1 - 1.) * log(f) - 0.5 * (nu1 + nu2) - * log(nu2 + nu1 * f) + fac); - } - - public double cdf(double f) { - if (f < 0.) - throw new IllegalArgumentException("bad f in Fdist"); - return betai(0.5 * nu1, 0.5 * nu2, nu1 * f / (nu2 + nu1 * f)); - } - - public double invcdf(double p) { - if (p <= 0. || p >= 1.) - throw new IllegalArgumentException("bad p in Fdist"); - double x = invbetai(p, 0.5 * nu1, 0.5 * nu2); - return nu2 * x / (nu1 * (1. - x)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Fermi.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Fermi.java deleted file mode 100644 index eb7d931569..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Fermi.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.nr.sf; - -import static java.lang.Math.*; -import com.nr.RealValueFun; -import com.nr.UniVarRealValueFun; -import com.nr.fi.DErule; -import com.nr.fi.Trapzd; - -/** - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Fermi implements UniVarRealValueFun, RealValueFun { - double kk, etaa, thetaa; - - public Fermi() { - } - - public double get(final double t) { - double x; - x = exp(t - exp(-t)); - return x * (1.0 + exp(-t)) * pow(x, kk) * sqrt(1.0 + thetaa * 0.5 * x) - / (exp(x - etaa) + 1.0); - } - - @Override - public double funk(final double t) { - return get(t); - } - - @Override - public double funk(final double[] x) { - return get(x[0], x[1]); - } - - public double get(final double x, final double del) { - if (x < 1.0) - return pow(del, kk) * sqrt(1.0 + thetaa * 0.5 * x) - / (exp(x - etaa) + 1.0); - else - return pow(x, kk) * sqrt(1.0 + thetaa * 0.5 * x) - / (exp(x - etaa) + 1.0); - } - - public double val(final double k, final double eta, final double theta) { - final double EPS = 3.0e-9; - final int NMAX = 11; - double a, aa, b, bb, hmax, olds = 0, sum; - kk = k; - etaa = eta; - thetaa = theta; - if (eta <= 15.0) { - a = -4.5; - b = 5.0; - Trapzd s = new Trapzd(this, a, b); - for (int i = 1; i <= NMAX; i++) { - sum = s.next(); - if (i > 3) - if (abs(sum - olds) <= EPS * abs(olds)) - return sum; - olds = sum; - } - } else { - a = 0.0; - b = eta; - aa = eta; - bb = eta + 60.0; - hmax = 4.3; - DErule s = new DErule(this, a, b, hmax); - DErule ss = new DErule(this, aa, bb, hmax); - for (int i = 1; i <= NMAX; i++) { - sum = s.next() + ss.next(); - if (i > 3) - if (abs(sum - olds) <= EPS * abs(olds)) - return sum; - olds = sum; - } - } - throw new IllegalArgumentException("no convergence in fermi"); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Gamma.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Gamma.java deleted file mode 100644 index 2fd16a87de..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Gamma.java +++ /dev/null @@ -1,219 +0,0 @@ -package com.nr.sf; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -public class Gamma implements Gauleg18 { - private static final int ASWITCH = 100; - private static final double EPS = DBL_EPSILON;; - private static final double FPMIN = Double.MIN_NORMAL / EPS; - private double gln; - - public double gammp(final double a, final double x) { - if (x < 0.0 || a <= 0.0) - throw new IllegalArgumentException("bad args in gammp"); - if (x == 0.0) - return 0.0; - else if ((int) a >= ASWITCH) - return gammpapprox(a, x, 1); - else if (x < a + 1.0) - return gser(a, x); - else - return 1.0 - gcf(a, x); - } - - public double gammq(final double a, final double x) { - if (x < 0.0 || a <= 0.0) - throw new IllegalArgumentException("bad args in gammq"); - if (x == 0.0) - return 1.0; - else if ((int) a >= ASWITCH) - return gammpapprox(a, x, 0); - else if (x < a + 1.0) - return 1.0 - gser(a, x); - else - return gcf(a, x); - } - - public double gser(final double a, final double x) { - double sum, del, ap; - gln = gammln(a); - ap = a; - del = sum = 1.0 / a; - for (;;) { - ++ap; - del *= x / ap; - sum += del; - if (abs(del) < abs(sum) * EPS) { - return sum * exp(-x + a * log(x) - gln); - } - } - } - - public double gcf(final double a, final double x) { - int i; - double an, b, c, d, del, h; - gln = gammln(a); - b = x + 1.0 - a; - c = 1.0 / FPMIN; - d = 1.0 / b; - h = d; - for (i = 1;; i++) { - an = -i * (i - a); - b += 2.0; - d = an * d + b; - if (abs(d) < FPMIN) - d = FPMIN; - c = b + an / c; - if (abs(c) < FPMIN) - c = FPMIN; - d = 1.0 / d; - del = d * c; - h *= del; - if (abs(del - 1.0) <= EPS) - break; - } - return exp(-x + a * log(x) - gln) * h; - } - - public double gammpapprox(final double a, final double x, final int psig) { - int j; - double xu, t, sum, ans; - double a1 = a - 1.0, lna1 = log(a1), sqrta1 = sqrt(a1); - gln = gammln(a); - if (x > a1) - xu = max(a1 + 11.5 * sqrta1, x + 6.0 * sqrta1); - else - xu = max(0., min(a1 - 7.5 * sqrta1, x - 5.0 * sqrta1)); - sum = 0; - for (j = 0; j < ngau; j++) { - t = x + (xu - x) * y[j]; - sum += w[j] * exp(-(t - a1) + a1 * (log(t) - lna1)); - } - ans = sum * (xu - x) * exp(a1 * (lna1 - 1.) - gln); - return (psig != 0 ? (x > a1 ? 1.0 - ans : -ans) : (x > a1 ? ans - : 1.0 + ans)); - } - - public double invgammp(final double p, final double a) { - int j; - double x, err, t, u, pp, lna1 = 0, afac = 0, a1 = a - 1; - final double EPS = 1.e-8; - gln = gammln(a); - if (a <= 0.) - throw new IllegalArgumentException("a must be pos in invgammap"); - if (p >= 1.) - return max(100., a + 100. * sqrt(a)); - if (p <= 0.) - return 0.0; - if (a > 1.) { - lna1 = log(a1); - afac = exp(a1 * (lna1 - 1.) - gln); - pp = (p < 0.5) ? p : 1. - p; - t = sqrt(-2. * log(pp)); - x = (2.30753 + t * 0.27061) / (1. + t * (0.99229 + t * 0.04481)) - - t; - if (p < 0.5) - x = -x; - x = max(1.e-3, a * pow(1. - 1. / (9. * a) - x / (3. * sqrt(a)), 3)); - } else { - t = 1.0 - a * (0.253 + a * 0.12); - if (p < t) - x = pow(p / t, 1. / a); - else - x = 1. - log(1. - (p - t) / (1. - t)); - } - for (j = 0; j < 12; j++) { - if (x <= 0.0) - return 0.0; - err = gammp(a, x) - p; - if (a > 1.) - t = afac * exp(-(x - a1) + a1 * (log(x) - lna1)); - else - t = exp(-x + a1 * log(x) - gln); - u = err / t; - x -= (t = u / (1. - 0.5 * min(1., u * ((a - 1.) / x - 1)))); - if (x <= 0.) - x = 0.5 * (x + t); - if (abs(t) < EPS * x) - break; - } - return x; - } - - private static final double[] cof = { 57.1562356658629235, - -59.5979603554754912, 14.1360979747417471, -0.491913816097620199, - .339946499848118887e-4, .465236289270485756e-4, - -.983744753048795646e-4, .158088703224912494e-3, - -.210264441724104883e-3, .217439618115212643e-3, - -.164318106536763890e-3, .844182239838527433e-4, - -.261908384015814087e-4, .368991826595316234e-5 }; - private static double[] a = new double[171]; - - private static final int NTOP = 2000; - private static double[] aa = new double[NTOP]; - - static { - a[0] = 1.; - for (int i = 1; i < 171; i++) - a[i] = i * a[i - 1]; - - for (int i = 0; i < NTOP; i++) - aa[i] = gammln(i + 1.); - } - - public static double gammln(final double xx) { - int j; - double x, tmp, y, ser; - if (xx <= 0) - throw new IllegalArgumentException("bad arg in gammln"); - y = x = xx; - tmp = x + 5.24218750000000000; // Rational 671/128 - tmp = (x + 0.5) * log(tmp) - tmp; - ser = 0.999999999999997092; - for (j = 0; j < 14; j++) - ser += cof[j] / ++y; - return tmp + log(2.5066282746310005 * ser / x); - } - - /** - * Returns the value n! as a floating-point number. - * - * @param n - * @return - */ - public static double factrl(final int n) { - if (n < 0 || n > 170) - throw new IllegalArgumentException("factrl out of range"); - return a[n]; - } - - /** - * Returns ln(n!) - * - * @param n - * @return - */ - public static double factln(final int n) { - if (n < 0) - throw new IllegalArgumentException("negative arg in factln"); - if (n < NTOP) - return aa[n]; - return gammln(n + 1.); - } - - /** - * Returns the binomial coefficient (n,k) as a floating-point number. - * - * @param n - * @param k - * @return - */ - public static double bico(final int n, final int k) { - if (n < 0 || k < 0 || k > n) - throw new IllegalArgumentException("bad args in bico"); - if (n < 171) - return floor(0.5 + factrl(n) / (factrl(k) * factrl(n - k))); - return floor(0.5 + exp(factln(n) - factln(k) - factln(n - k))); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Gammadist.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Gammadist.java deleted file mode 100644 index f72e4e4aa0..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Gammadist.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.nr.sf; - -import static java.lang.Math.*; - -public class Gammadist extends Gamma { - double alph, bet, fac; - - public Gammadist(double aalph) { - this(aalph, 1.); - } - - public Gammadist(double aalph, double bbet) { - alph = aalph; - bet = bbet; - - if (alph <= 0. || bet <= 0.) - throw new IllegalArgumentException("bad alph,bet in Gammadist"); - fac = alph * log(bet) - gammln(alph); - } - - public double p(double x) { - if (x <= 0.) - throw new IllegalArgumentException("bad x in Gammadist"); - return exp(-bet * x + (alph - 1.) * log(x) + fac); - } - - public double cdf(double x) { - if (x < 0.) - throw new IllegalArgumentException("bad x in Gammadist"); - return gammp(alph, bet * x); - } - - public double invcdf(double p) { - if (p < 0. || p >= 1.) - throw new IllegalArgumentException("bad p in Gammadist"); - return invgammp(p, alph) / bet; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Gauleg18.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Gauleg18.java deleted file mode 100644 index df115b5514..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Gauleg18.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.nr.sf; - -interface Gauleg18 { - static final int ngau = 18; - static final double[] y = { 0.0021695375159141994, 0.011413521097787704, - 0.027972308950302116, 0.051727015600492421, 0.082502225484340941, - 0.12007019910960293, 0.16415283300752470, 0.21442376986779355, - 0.27051082840644336, 0.33199876341447887, 0.39843234186401943, - 0.46931971407375483, 0.54413605556657973, 0.62232745288031077, - 0.70331500465597174, 0.78649910768313447, 0.87126389619061517, - 0.95698180152629142 }; - static final double[] w = { 0.0055657196642445571, 0.012915947284065419, - 0.020181515297735382, 0.027298621498568734, 0.034213810770299537, - 0.040875750923643261, 0.047235083490265582, 0.053244713977759692, - 0.058860144245324798, 0.064039797355015485, 0.068745323835736408, - 0.072941885005653087, 0.076598410645870640, 0.079687828912071670, - 0.082187266704339706, 0.084078218979661945, 0.085346685739338721, - 0.085983275670394821 }; -} \ No newline at end of file diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Hypergeo.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Hypergeo.java deleted file mode 100644 index 12c64621fb..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Hypergeo.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.nr.sf; - -import com.nr.Complex; -import com.nr.ode.Hypderiv; -import com.nr.ode.Odeint; -import com.nr.ode.Output; -import com.nr.ode.StepperBS; - -/** - * Hypergeometric Functions - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Hypergeo { - private Complex series, deriv; - - private Hypergeo() { - } - - private void hypser(final Complex a, final Complex b, final Complex c, - final Complex z) { - deriv = new Complex(0.0, 0.0); - Complex fac = new Complex(1.0, 0.0); - Complex temp = fac; - Complex aa = a; - Complex bb = b; - Complex cc = c; - for (int n = 1; n <= 1000; n++) { - fac = fac.mul(aa.mul(bb).div(cc)); - deriv = deriv.add(fac); - fac = fac.mul(z.mul(1.0 / n)); - series = temp.add(fac); - if (series.equals(temp)) - return; - temp = series; - aa = aa.add(new Complex(1.0, 0)); - bb = bb.add(new Complex(1.0, 0)); - cc = cc.add(new Complex(1.0, 0)); - } - throw new IllegalArgumentException("convergence failure in hypser"); - } - - private Complex hypgeo0(final Complex a, final Complex b, final Complex c, - final Complex z) { - final double atol = 1.0e-14, rtol = 1.0e-14; - Complex ans = new Complex(0, 0), dz = new Complex(0, 0), z0 = new Complex( - 0, 0); - Complex[] y = new Complex[2]; - double[] yy = new double[4]; - if (z.norm() <= 0.25) { - hypser(a, b, c, z); - ans = series; - y[1] = deriv; - return ans; - } else if (z.re() < 0.0) - z0 = new Complex(-0.5, 0.0); - else if (z.re() <= 1.0) - z0 = new Complex(0.5, 0.0); - else - z0 = new Complex(0.0, z.im() >= 0.0 ? 0.5 : -0.5); - dz = z.sub(z0); - hypser(a, b, c, z0); - y[0] = series; - y[1] = deriv; - yy[0] = y[0].re(); - yy[1] = y[0].im(); - yy[2] = y[1].re(); - yy[3] = y[1].im(); - Hypderiv d = new Hypderiv(a, b, c, z0, dz); - Output out = new Output(); - StepperBS s = new StepperBS(); - Odeint ode = new Odeint(yy, 0.0, 1.0, atol, rtol, 0.1, 0.0, out, d, s); - ode.integrate(); - y[0] = new Complex(yy[0], yy[1]); - return y[0]; - } - - public static Complex hypgeo(final Complex a, final Complex b, - final Complex c, final Complex z) { - Hypergeo h = new Hypergeo(); - return h.hypgeo0(a, b, c, z); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Integrals.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Integrals.java deleted file mode 100644 index 39a9168c14..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Integrals.java +++ /dev/null @@ -1,325 +0,0 @@ -package com.nr.sf; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import com.nr.Complex; - -public class Integrals { - private Integrals() { - } - - /** - * Exponential Integrals - * - * @param n - * @param x - * @return - */ - public static double expint(final int n, final double x) { - final int MAXIT = 100; - final double EULER = 0.577215664901533, EPS = DBL_EPSILON, BIG = Double.MAX_VALUE - * EPS; - int i, ii, nm1 = n - 1; - double a, b, c, d, del, fact, h, psi, ans; - if (n < 0 || x < 0.0 || (x == 0.0 && (n == 0 || n == 1))) - throw new IllegalArgumentException("bad arguments in expint"); - if (n == 0) - ans = exp(-x) / x; - else { - if (x == 0.0) - ans = 1.0 / nm1; - else { - if (x > 1.0) { - b = x + n; - c = BIG; - d = 1.0 / b; - h = d; - for (i = 1; i <= MAXIT; i++) { - a = -i * (nm1 + i); - b += 2.0; - d = 1.0 / (a * d + b); - c = b + a / c; - del = c * d; - h *= del; - if (abs(del - 1.0) <= EPS) { - ans = h * exp(-x); - return ans; - } - } - throw new IllegalArgumentException( - "continued fraction failed in expint"); - } else { - ans = (nm1 != 0 ? 1.0 / nm1 : -log(x) - EULER); - fact = 1.0; - for (i = 1; i <= MAXIT; i++) { - fact *= -x / i; - if (i != nm1) - del = -fact / (i - nm1); - else { - psi = -EULER; - for (ii = 1; ii <= nm1; ii++) - psi += 1.0 / ii; - del = fact * (-log(x) + psi); - } - ans += del; - if (abs(del) < abs(ans) * EPS) - return ans; - } - throw new IllegalArgumentException( - "series failed in expint"); - } - } - } - return ans; - } - - /** - * Exponential Integrals - * - * @param x - * @return - */ - public static double ei(final double x) { - final int MAXIT = 100; - final double EULER = 0.577215664901533, EPS = DBL_EPSILON, FPMIN = Double.MIN_NORMAL - / EPS; - int k; - double fact, prev, sum, term; - if (x <= 0.0) - throw new IllegalArgumentException("Bad argument in ei"); - if (x < FPMIN) - return log(x) + EULER; - if (x <= -log(EPS)) { - sum = 0.0; - fact = 1.0; - for (k = 1; k <= MAXIT; k++) { - fact *= x / k; - term = fact / k; - sum += term; - if (term < EPS * sum) - break; - } - if (k > MAXIT) - throw new IllegalArgumentException("Series failed in ei"); - return sum + log(x) + EULER; - } else { - sum = 0.0; - term = 1.0; - for (k = 1; k <= MAXIT; k++) { - prev = term; - term *= k / x; - if (term < EPS) - break; - if (term < prev) - sum += term; - else { - sum -= prev; - break; - } - } - return exp(x) * (1.0 + sum) / x; - } - } - - /** - * Fermi-Dirac integrals - * - * @param x - * @return - */ - public static Complex frenel(final double x) { - final int MAXIT = 100; - final double PIBY2 = (PI / 2.0), XMIN = 1.5, EPS = DBL_EPSILON, FPMIN = Double.MIN_NORMAL, BIG = Double.MAX_VALUE - * EPS; - boolean odd; - int k, n; - double a, ax, fact, pix2, sign, sum, sumc, sums, term, test; - Complex b, cc, d, h, del, cs; - if ((ax = abs(x)) < sqrt(FPMIN)) { - cs = new Complex(ax, 0); - } else if (ax <= XMIN) { - sum = sums = 0.0; - sumc = ax; - sign = 1.0; - fact = PIBY2 * ax * ax; - odd = true; - term = ax; - n = 3; - for (k = 1; k <= MAXIT; k++) { - term *= fact / k; - sum += sign * term / n; - test = abs(sum) * EPS; - if (odd) { - sign = -sign; - sums = sum; - sum = sumc; - } else { - sumc = sum; - sum = sums; - } - if (term < test) - break; - odd = !odd; - n += 2; - } - if (k > MAXIT) - throw new IllegalArgumentException("series failed in frenel"); - cs = new Complex(sumc, sums); - } else { - pix2 = PI * ax * ax; - b = new Complex(1.0, -pix2); - cc = new Complex(BIG, 0); - d = new Complex(1.0, 0).div(b); - h = new Complex(1.0, 0).div(b); - - n = -1; - for (k = 2; k <= MAXIT; k++) { - n += 2; - a = -n * (n + 1); - b = b.add(new Complex(4.0, 0)); - d = new Complex(1.0, 0).div(new Complex(a, 0).mul(d).add(b)); // d=1.0/(a*d+b); - cc = b.add(new Complex(a, 0).div(cc)); - del = cc.mul(d); - h = h.mul(del); - if (abs(del.re() - 1.0) + abs(del.im()) <= EPS) - break; - } - if (k > MAXIT) - throw new IllegalArgumentException("cf failed in frenel"); - h = h.mul(new Complex(ax, -ax)); - cs = new Complex(0.5, 0.5) - .mul((new Complex(1.0, 0).sub((new Complex(cos(0.5 * pix2), - sin(0.5 * pix2)).mul(h))))); - } - if (x < 0.0) - cs = cs.neg(); - return cs; - } - - /** - * cosine and sine integrals - * - * @param x - * @return - */ - public static Complex cisi(final double x) { - final int MAXIT = 100; - final double EULER = 0.577215664901533, PIBY2 = 1.570796326794897, TMIN = 2.0, EPS = DBL_EPSILON, FPMIN = Double.MIN_NORMAL * 4.0, BIG = Double.MAX_VALUE - * EPS; - int i, k; - boolean odd; - double a, err, fact, sign, sum, sumc, sums, t, term; - Complex h, b, c, d, del, cs; - if ((t = abs(x)) == 0.0) - return new Complex(-BIG, 0); - if (t > TMIN) { - b = new Complex(1.0, t); - c = new Complex(BIG, 0.0); - d = new Complex(1.0, 0).div(b); - h = new Complex(1.0, 0).div(b); - for (i = 1; i < MAXIT; i++) { - a = -i * i; - b = b.add(new Complex(2.0, 0)); - d = new Complex(1.0, 0).div(new Complex(a, 0).mul(d).add(b)); // d=1.0/(a*d+b); - c = b.add(new Complex(a, 0).div(c)); // c=b+a/c; - del = c.mul(d); - h = h.mul(del); - if (abs(del.re() - 1.0) + abs(del.im()) <= EPS) - break; - } - if (i >= MAXIT) - throw new IllegalArgumentException("cf failed in cisi"); - h = new Complex(cos(t), -sin(t)).mul(h); - // cs= -conj(h)+Complex(0.0,PIBY2); - cs = new Complex(0.0, PIBY2).sub(h.conj()); - } else { - if (t < sqrt(FPMIN)) { - sumc = 0.0; - sums = t; - } else { - sum = sums = sumc = 0.0; - sign = fact = 1.0; - odd = true; - for (k = 1; k <= MAXIT; k++) { - fact *= t / k; - term = fact / k; - sum += sign * term; - err = term / abs(sum); - if (odd) { - sign = -sign; - sums = sum; - sum = sumc; - } else { - sumc = sum; - sum = sums; - } - if (err < EPS) - break; - odd = !odd; - } - if (k > MAXIT) - throw new IllegalArgumentException( - "maxits exceeded in cisi"); - } - cs = new Complex(sumc + log(t) + EULER, sums); - } - if (x < 0.0) - cs = cs.conj(); - return cs; - } - - private static final int NMAX = 6; - private static double[] c = new double[NMAX]; - static { - final double H = 0.4; - for (int i = 0; i < NMAX; i++) - c[i] = exp(-SQR((2.0 * i + 1.0) * H)); - } - - /** - * Dawson's integral - * - * @param x - * @return - */ - public static double dawson(final double x) { - final double H = 0.4, A1 = 2.0 / 3.0, A2 = 0.4, A3 = 2.0 / 7.0; - int i, n0; - double d1, d2, e1, e2, sum, x2, xp, xx, ans; - if (abs(x) < 0.2) { - x2 = x * x; - ans = x * (1.0 - A1 * x2 * (1.0 - A2 * x2 * (1.0 - A3 * x2))); - } else { - xx = abs(x); - n0 = 2 * (int) (0.5 * xx / H + 0.5); - xp = xx - n0 * H; - e1 = exp(2.0 * xp * H); - e2 = e1 * e1; - d1 = n0 + 1; - d2 = d1 - 2.0; - sum = 0.0; - for (i = 0; i < NMAX; i++, d1 += 2.0, d2 -= 2.0, e1 *= e2) - sum += c[i] * (e1 / d1 + 1.0 / (d2 * e1)); - ans = 0.5641895835 * SIGN(exp(-xp * xp), x) * sum; - } - return ans; - } - - public static double invxlogx(final double y) { - final double ooe = 0.367879441171442322; - double t, u, to = 0.; - if (y >= 0. || y <= -ooe) - throw new IllegalArgumentException("no such inverse value"); - if (y < -0.2) - u = log(ooe - sqrt(2 * ooe * (y + ooe))); - else - u = -10.; - do { - u += (t = (log(y / u) - u) * (u / (1. + u))); - if (t < 1.e-8 && abs(t + to) < 0.01 * abs(t)) - break; - to = t; - } while (abs(t / u) > 1.e-15); - return exp(u); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/KSdist.java b/common-tools/cnuphys/numRec/src/com/nr/sf/KSdist.java deleted file mode 100644 index b31b7dda77..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/KSdist.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.nr.sf; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -/** - * Kolmogorov-Smirnov cumulative distribution functions and their inverses. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class KSdist { - - public double pks(final double z) { - if (z < 0.) - throw new IllegalArgumentException("bad z in KSdist"); - if (z < 0.042) - return 0.; - if (z < 1.18) { - double y = exp(-1.23370055013616983 / SQR(z)); - return 2.25675833419102515 * sqrt(-log(y)) - * (y + pow(y, 9) + pow(y, 25) + pow(y, 49)); - } else { - double x = exp(-2. * SQR(z)); - return 1. - 2. * (x - pow(x, 4) + pow(x, 9)); - } - } - - public double qks(final double z) { - if (z < 0.) - throw new IllegalArgumentException("bad z in KSdist"); - if (z == 0.) - return 1.; - if (z < 1.18) - return 1. - pks(z); - double x = exp(-2. * SQR(z)); - return 2. * (x - pow(x, 4) + pow(x, 9)); - } - - public double invqks(final double q) { - double y, logy, x, xp, f, ff, u, t; // yp - if (q <= 0. || q > 1.) - throw new IllegalArgumentException("bad q in KSdist"); - if (q == 1.) - return 0.; - if (q > 0.3) { - f = -0.392699081698724155 * SQR(1. - q); - y = Integrals.invxlogx(f); - do { - // yp = y; // yp not used - logy = log(y); - ff = f / SQR(1. + pow(y, 4) + pow(y, 12)); - u = (y * logy - ff) / (1. + logy); - y = y - (t = u / max(0.5, 1. - 0.5 * u / (y * (1. + logy)))); - } while (abs(t / y) > 1.e-15); - return 1.57079632679489662 / sqrt(-log(y)); - } else { - x = 0.03; - do { - xp = x; - x = 0.5 * q + pow(x, 4) - pow(x, 9); - if (x > 0.06) - x += pow(x, 16) - pow(x, 25); - } while (abs((xp - x) / x) > 1.e-15); - return sqrt(-0.5 * log(x)); - } - } - - public double invpks(final double p) { - return invqks(1. - p); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Legendre.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Legendre.java deleted file mode 100644 index 7bc72513ee..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Legendre.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.nr.sf; - -import static java.lang.Math.*; - -/** - * Legendre functions and spherical harmonics Copyright (C) Numerical Recipes - * Software 1986-2007 Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Legendre { - private Legendre() { - } - - public static double plegendre(final int l, final int m, final double x) { - int i, ll; - double fact, oldfact, pll = 0, pmm, pmmp1, omx2; - if (m < 0 || m > l || abs(x) > 1.0) - throw new IllegalArgumentException( - "Bad arguments in routine plgndr"); - pmm = 1.0; - if (m > 0) { - omx2 = (1.0 - x) * (1.0 + x); - fact = 1.0; - for (i = 1; i <= m; i++) { - pmm *= omx2 * fact / (fact + 1.0); - fact += 2.0; - } - } - pmm = sqrt((2 * m + 1) * pmm / (4.0 * PI)); - if ((m & 1) != 0) - pmm = -pmm; - if (l == m) - return pmm; - else { - pmmp1 = x * sqrt(2.0 * m + 3.0) * pmm; - if (l == (m + 1)) - return pmmp1; - else { - oldfact = sqrt(2.0 * m + 3.0); - for (ll = m + 2; ll <= l; ll++) { - fact = sqrt((4.0 * ll * ll - 1.0) / (ll * ll - m * m)); - pll = (x * pmmp1 - pmm / oldfact) * fact; - oldfact = fact; - pmm = pmmp1; - pmmp1 = pll; - } - return pll; - } - } - } - - public static double plgndr(final int l, final int m, final double x) { - if (m < 0 || m > l || abs(x) > 1.0) - throw new IllegalArgumentException( - "Bad arguments in routine plgndr"); - double prod = 1.0; - for (int j = l - m + 1; j <= l + m; j++) - prod *= j; - return sqrt(4.0 * PI * prod / (2 * l + 1)) * plegendre(l, m, x); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Logisticdist.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Logisticdist.java deleted file mode 100644 index 7e5422df00..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Logisticdist.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.nr.sf; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -public class Logisticdist { - double mu, sig; - - public Logisticdist() { - this(0., 1.); - } - - public Logisticdist(final double mmu, final double ssig) { - mu = mmu; - sig = ssig; - if (sig <= 0.) - throw new IllegalArgumentException("bad sig in Logisticdist"); - } - - public double p(final double x) { - double e = exp(-abs(1.81379936423421785 * (x - mu) / sig)); - return 1.81379936423421785 * e / (sig * SQR(1. + e)); - } - - public double cdf(final double x) { - double e = exp(-abs(1.81379936423421785 * (x - mu) / sig)); - if (x >= mu) - return 1. / (1. + e); - else - return e / (1. + e); - } - - public double invcdf(final double p) { - if (p <= 0. || p >= 1.) - throw new IllegalArgumentException("bad p in Logisticdist"); - return mu + 0.551328895421792049 * sig * log(p / (1. - p)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Lognormaldist.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Lognormaldist.java deleted file mode 100644 index 8ae6db7b11..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Lognormaldist.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.nr.sf; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -public class Lognormaldist extends Erf { - double mu, sig; - - public Lognormaldist() { - this(0., 1.); - } - - public Lognormaldist(final double mmu, final double ssig) { - mu = mmu; - sig = ssig; - if (sig <= 0.) - throw new IllegalArgumentException("bad sig in Lognormaldist"); - } - - public double p(final double x) { - if (x < 0.) - throw new IllegalArgumentException("bad x in Lognormaldist"); - if (x == 0.) - return 0.; - return (0.398942280401432678 / (sig * x)) - * exp(-0.5 * SQR((log(x) - mu) / sig)); - } - - public double cdf(final double x) { - if (x < 0.) - throw new IllegalArgumentException("bad x in Lognormaldist"); - if (x == 0.) - return 0.; - return 0.5 * erfc(-0.707106781186547524 * (log(x) - mu) / sig); - } - - public double invcdf(final double p) { - if (p <= 0. || p >= 1.) - throw new IllegalArgumentException("bad p in Lognormaldist"); - return exp(-1.41421356237309505 * sig * inverfc(2. * p) + mu); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Normaldist.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Normaldist.java deleted file mode 100644 index b29bf81cba..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Normaldist.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.nr.sf; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -public class Normaldist extends Erf { - double mu, sig; - - public Normaldist() { - this(0., 1.); - } - - public Normaldist(final double mmu, final double ssig) { - mu = mmu; - sig = ssig; - if (sig <= 0.) - throw new IllegalArgumentException("bad sig in Normaldist"); - } - - public double p(final double x) { - return (0.398942280401432678 / sig) * exp(-0.5 * SQR((x - mu) / sig)); - } - - public double cdf(final double x) { - return 0.5 * erfc(-0.707106781186547524 * (x - mu) / sig); - } - - public double invcdf(final double p) { - if (p <= 0. || p >= 1.) - throw new IllegalArgumentException("bad p in Normaldist"); - return -1.41421356237309505 * sig * inverfc(2. * p) + mu; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Poissondist.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Poissondist.java deleted file mode 100644 index e899d668a9..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Poissondist.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.nr.sf; - -import static java.lang.Math.*; - -public class Poissondist extends Gamma { - double lam; - - public Poissondist(double llam) { - lam = llam; - if (lam <= 0.) - throw new IllegalArgumentException("bad lam in Poissondist"); - } - - public double p(int n) { - if (n < 0) - throw new IllegalArgumentException("bad n in Poissondist"); - return exp(-lam + n * log(lam) - gammln(n + 1.)); - } - - public double cdf(int n) { - if (n < 0) - throw new IllegalArgumentException("bad n in Poissondist"); - if (n == 0) - return 0.; - return gammq(n, lam); - } - - public int invcdf(double p) { - int n, nl, nu, inc = 1; - if (p <= 0. || p >= 1.) - throw new IllegalArgumentException("bad p in Poissondist"); - if (p < exp(-lam)) - return 0; - n = (int) max(sqrt(lam), 5.); - if (p < cdf(n)) { - do { - n = max(n - inc, 0); - inc *= 2; - } while (p < cdf(n)); - nl = n; - nu = n + inc / 2; - } else { - do { - n += inc; - inc *= 2; - } while (p > cdf(n)); - nu = n; - nl = n - inc / 2; - } - while (nu - nl > 1) { - n = (nl + nu) / 2; - if (p < cdf(n)) - nu = n; - else - nl = n; - } - return nl; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sf/Studenttdist.java b/common-tools/cnuphys/numRec/src/com/nr/sf/Studenttdist.java deleted file mode 100644 index da284afcf3..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sf/Studenttdist.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.nr.sf; - -import static java.lang.Math.*; -import static com.nr.sf.Gamma.*; -import static com.nr.NRUtil.*; - -public class Studenttdist extends Beta { - double nu, mu, sig, np, fac; - - public Studenttdist(double nnu) { - this(nnu, 0., 1.); - } - - public Studenttdist(double nnu, double mmu, double ssig) { - nu = nnu; - mu = mmu; - sig = ssig; - - if (sig <= 0. || nu <= 0.) - throw new IllegalArgumentException("bad sig,nu in Studentdist"); - np = 0.5 * (nu + 1.); - fac = gammln(np) - gammln(0.5 * nu); - } - - public double p(double t) { - return exp(-np * log(1. + SQR((t - mu) / sig) / nu) + fac) - / (sqrt(3.14159265358979324 * nu) * sig); - } - - public double cdf(double t) { - double p = 0.5 * betai(0.5 * nu, 0.5, nu / (nu + SQR((t - mu) / sig))); - if (t >= mu) - return 1. - p; - else - return p; - } - - public double invcdf(double p) { - if (p <= 0. || p >= 1.) - throw new IllegalArgumentException("bad p in Studentdist"); - double x = invbetai(2. * min(p, 1. - p), 0.5 * nu, 0.5); - x = sig * sqrt(nu * (1. - x) / x); - return (p >= 0.5 ? mu + x : mu - x); - } - - public double aa(double t) { - if (t < 0.) - throw new IllegalArgumentException("bad t in Studentdist"); - return 1. - betai(0.5 * nu, 0.5, nu / (nu + SQR(t))); - } - - public double invaa(double p) { - if (p < 0. || p >= 1.) - throw new IllegalArgumentException("bad p in Studentdist"); - double x = invbetai(1. - p, 0.5 * nu, 0.5); - return sqrt(nu * (1. - x) / x); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sort/EClass.java b/common-tools/cnuphys/numRec/src/com/nr/sort/EClass.java deleted file mode 100644 index d86d0c12fa..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sort/EClass.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.nr.sort; - -/** - * Find equivalence classes Copyright (C) Numerical Recipes Software 1986-2007 - * Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class EClass { - private EClass() { - } - - public static void eclass(final int[] nf, final int[] lista, - final int[] listb) { - int l, k, j, n = nf.length, m = lista.length; - for (k = 0; k < n; k++) - nf[k] = k; - for (l = 0; l < m; l++) { - j = lista[l]; - while (nf[j] != j) - j = nf[j]; - k = listb[l]; - while (nf[k] != k) - k = nf[k]; - if (j != k) - nf[j] = k; - } - for (j = 0; j < n; j++) - while (nf[j] != nf[nf[j]]) - nf[j] = nf[nf[j]]; - } - - public static void eclazz(final int[] nf, final EquivalenceInf eq) { - int kk, jj, n = nf.length; - nf[0] = 0; - for (jj = 1; jj < n; jj++) { - nf[jj] = jj; - for (kk = 0; kk < jj; kk++) { - nf[kk] = nf[nf[kk]]; - if (eq.equiv(jj + 1, kk + 1)) - nf[nf[nf[kk]]] = jj; - } - } - for (jj = 0; jj < n; jj++) - nf[jj] = nf[nf[jj]]; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sort/EquivalenceInf.java b/common-tools/cnuphys/numRec/src/com/nr/sort/EquivalenceInf.java deleted file mode 100644 index 363748c0d6..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sort/EquivalenceInf.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.nr.sort; - -public interface EquivalenceInf { - public boolean equiv(final int jj, final int kk); -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sort/Heapselect.java b/common-tools/cnuphys/numRec/src/com/nr/sort/Heapselect.java deleted file mode 100644 index 309d8091a1..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sort/Heapselect.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.nr.sort; - -import static com.nr.NRUtil.*; -import static java.lang.Math.min; - -public class Heapselect { - int m, n, srtd; - double[] heap; - - public Heapselect(int mm) { - m = mm; - n = 0; - srtd = 0; - heap = buildVector(mm, 1.e99); - } - - public void add(double val) { - int j, k; - if (n < m) { - heap[n++] = val; - if (n == m) - Sorter.sort(heap); - } else { - if (val > heap[0]) { - heap[0] = val; - for (j = 0;;) { - k = (j << 1) + 1; - if (k > m - 1) - break; - if (k != (m - 1) && heap[k] > heap[k + 1]) - k++; - if (heap[j] <= heap[k]) - break; - swap(heap, k, j); - j = k; - } - } - n++; - } - srtd = 0; - } - - public double report(int k) { - int mm = min(n, m); - if (k > mm - 1) - throw new IllegalArgumentException("Heapselect k too big"); - if (k == m - 1) - return heap[0]; - if (srtd == 0) { - Sorter.sort(heap); - srtd = 1; - } - return heap[mm - 1 - k]; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sort/IQagent.java b/common-tools/cnuphys/numRec/src/com/nr/sort/IQagent.java deleted file mode 100644 index 313a895ff0..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sort/IQagent.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.nr.sort; - -import static java.lang.Math.*; - -import java.util.Arrays; - -/** - * Object for estimating arbitrary quantile values from a continuing stream of - * data values. - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class IQagent { - static final int nbuf = 1000; - int nq, nt, nd; - double[] pval, dbuf, qile; - double q0, qm; - - public IQagent() { - nq = 251; - nt = 0; - nd = 0; - pval = new double[nq]; - dbuf = new double[nbuf]; - qile = new double[nq]; - q0 = 1.e99; - qm = -1.e99; - - for (int j = 85; j <= 165; j++) - pval[j] = (j - 75.) / 100.; - /* - * Set general purpose array of p-values ranging from 1.0e-6 to - * 1~1.0e-6. You can change this if you want. - */ - for (int j = 84; j >= 0; j--) { - pval[j] = 0.87191909 * pval[j + 1]; - pval[250 - j] = 1. - pval[j]; - } - } - - /** - * Assimilate a new value from the stream. - * - * @param datum - */ - public void add(final double datum) { - dbuf[nd++] = datum; - if (datum < q0) { - q0 = datum; - } - if (datum > qm) { - qm = datum; - } - if (nd == nbuf) - update(); - } - - /** - * Batch update. - * - * This function is called by add or report and should not be called - * directly by the user. - */ - private void update() { - int jd = 0, jq = 1, iq; - double target, told = 0., tnew = 0., qold, qnew; - double[] newqile = new double[nq]; - Arrays.sort(dbuf, 0, nd); - qold = qnew = qile[0] = newqile[0] = q0; - qile[nq - 1] = newqile[nq - 1] = qm; - pval[0] = min(0.5 / (nt + nd), 0.5 * pval[1]); - pval[nq - 1] = max(1. - 0.5 / (nt + nd), 0.5 * (1. + pval[nq - 2])); - for (iq = 1; iq < nq - 1; iq++) { - target = (nt + nd) * pval[iq]; - if (tnew < target) - for (;;) { - if (jq < nq && (jd >= nd || qile[jq] < dbuf[jd])) { - qnew = qile[jq]; - tnew = jd + nt * pval[jq++]; - if (tnew >= target) - break; - } else { - qnew = dbuf[jd]; - tnew = told; - if (qile[jq] > qile[jq - 1]) - tnew += nt * (pval[jq] - pval[jq - 1]) - * (qnew - qold) / (qile[jq] - qile[jq - 1]); - jd++; - if (tnew >= target) - break; - told = tnew++; - qold = qnew; - if (tnew >= target) - break; - } - told = tnew; - qold = qnew; - } - if (tnew == told) - newqile[iq] = 0.5 * (qold + qnew); - else - newqile[iq] = qold + (qnew - qold) * (target - told) - / (tnew - told); - told = tnew; - qold = qnew; - } - qile = newqile; - nt += nd; - nd = 0; - } - - /** - * Return estimated p-quantile for the data seen so far. (E.g., p D 0:5 for - * median.) - * - * @param p - * @return - */ - public double report(final double p) { - double q; - if (nd > 0) - update(); - int jl = 0, jh = nq - 1, j; - while (jh - jl > 1) { - j = (jh + jl) >> 1; - if (p > pval[j]) - jl = j; - else - jh = j; - } - j = jl; - q = qile[j] + (qile[j + 1] - qile[j]) * (p - pval[j]) - / (pval[j + 1] - pval[j]); - return max(qile[0], min(qile[nq - 1], q)); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sort/Indexx.java b/common-tools/cnuphys/numRec/src/com/nr/sort/Indexx.java deleted file mode 100644 index e9e85d8ede..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sort/Indexx.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.nr.sort; - -import static com.nr.NRUtil.*; - -public class Indexx { - private int n; - - public int[] indx; - - public Indexx(final double[] arr) { - index(arr, arr.length); - } - - public Indexx() { - } - - public void sort(final double[] brr) { - if (brr.length != n) - throw new IllegalArgumentException("bad size in Index sort"); - double[] tmp = buildVector(brr); - for (int j = 0; j < n; j++) - brr[j] = tmp[indx[j]]; - } - - public void sort(final int[] brr) { - if (brr.length != n) - throw new IllegalArgumentException("bad size in Index sort"); - int[] tmp = buildVector(brr); - for (int j = 0; j < n; j++) - brr[j] = tmp[indx[j]]; - } - - public int el(final int[] brr, final int j) { - return brr[indx[j]]; - } - - public double el(final double[] brr, final int j) { - return brr[indx[j]]; - } - - public void setEl(final int[] brr, final int j, final int v) { - brr[indx[j]] = v; - } - - public void setEl(final double[] brr, final int j, final double v) { - brr[indx[j]] = v; - } - - public void rank(final int[] irank) { - for (int j = 0; j < n; j++) - irank[indx[j]] = j; - } - - public void index(final double[] arr, final int nn) { - final int M = 7, NSTACK = 64; - int i, indxt, ir, j, k, jstack = -1, l = 0; - double a; - int[] istack = new int[NSTACK]; - n = nn; - indx = new int[n]; - ir = n - 1; - for (j = 0; j < n; j++) - indx[j] = j; - for (;;) { - if (ir - l < M) { - for (j = l + 1; j <= ir; j++) { - indxt = indx[j]; - a = arr[indxt]; - for (i = j - 1; i >= l; i--) { - if (arr[indx[i]] <= a) - break; - indx[i + 1] = indx[i]; - } - indx[i + 1] = indxt; - } - if (jstack < 0) - break; - ir = istack[jstack--]; - l = istack[jstack--]; - } else { - k = (l + ir) >> 1; - swap(indx, k, l + 1); - if (arr[indx[l]] > arr[indx[ir]]) { - swap(indx, l, ir); - } - if (arr[indx[l + 1]] > arr[indx[ir]]) { - swap(indx, l + 1, ir); - } - if (arr[indx[l]] > arr[indx[l + 1]]) { - swap(indx, l, l + 1); - } - i = l + 1; - j = ir; - indxt = indx[l + 1]; - a = arr[indxt]; - for (;;) { - do - i++; - while (arr[indx[i]] < a); - do - j--; - while (arr[indx[j]] > a); - if (j < i) - break; - swap(indx, i, j); - } - indx[l + 1] = indx[j]; - indx[j] = indxt; - jstack += 2; - if (jstack >= NSTACK) - throw new IllegalArgumentException( - "NSTACK too small in index."); - if (ir - i + 1 >= j - l) { - istack[jstack] = ir; - istack[jstack - 1] = i; - ir = j - 1; - } else { - istack[jstack] = j - 1; - istack[jstack - 1] = l; - l = i; - } - } - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sort/Sorter.java b/common-tools/cnuphys/numRec/src/com/nr/sort/Sorter.java deleted file mode 100644 index 30058a8305..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sort/Sorter.java +++ /dev/null @@ -1,365 +0,0 @@ -package com.nr.sort; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -public class Sorter { - private Sorter() { - } - - public static void sort(final double[] arr) { - sort(arr, -1); - } - - public static void sort(final double[] arr, final int m) { - final int M = 7, NSTACK = 64; - int i, ir, j, k, jstack = -1, l = 0, n = arr.length; - double a; - int[] istack = new int[NSTACK]; - if (m > 0) - n = min(m, n); - ir = n - 1; - for (;;) { - if (ir - l < M) { - for (j = l + 1; j <= ir; j++) { - a = arr[j]; - for (i = j - 1; i >= l; i--) { - if (arr[i] <= a) - break; - arr[i + 1] = arr[i]; - } - arr[i + 1] = a; - } - if (jstack < 0) - break; - ir = istack[jstack--]; - l = istack[jstack--]; - } else { - k = (l + ir) >> 1; - swap(arr, k, l + 1); - if (arr[l] > arr[ir]) { - swap(arr, l, ir); - } - if (arr[l + 1] > arr[ir]) { - swap(arr, l + 1, ir); - } - if (arr[l] > arr[l + 1]) { - swap(arr, l, l + 1); - } - i = l + 1; - j = ir; - a = arr[l + 1]; - for (;;) { - do - i++; - while (arr[i] < a); - do - j--; - while (arr[j] > a); - if (j < i) - break; - swap(arr, i, j); - } - arr[l + 1] = arr[j]; - arr[j] = a; - jstack += 2; - if (jstack >= NSTACK) - throw new IllegalArgumentException( - "NSTACK too small in sort."); - if (ir - i + 1 >= j - l) { - istack[jstack] = ir; - istack[jstack - 1] = i; - ir = j - 1; - } else { - istack[jstack] = j - 1; - istack[jstack - 1] = l; - l = i; - } - } - } - } - - public static void hpsort(final double[] ra) { - int i, n = ra.length; - for (i = n / 2 - 1; i >= 0; i--) - sift_down(ra, i, n - 1); - for (i = n - 1; i > 0; i--) { - swap(ra, 0, i); - sift_down(ra, 0, i - 1); - } - } - - private static void sift_down(final double[] ra, final int l, final int r) { - int j, jold; - double a; - a = ra[l]; - jold = l; - j = 2 * l + 1; - while (j <= r) { - if (j < r && ra[j] < ra[j + 1]) - j++; - if (a >= ra[j]) - break; - ra[jold] = ra[j]; - jold = j; - j = 2 * j + 1; - } - ra[jold] = a; - } - - public static void piksrt(double[] arr) { - int i, j, n = arr.length; - double a; - for (j = 1; j < n; j++) { - a = arr[j]; - i = j; - while (i > 0 && arr[i - 1] > a) { - arr[i] = arr[i - 1]; - i--; - } - arr[i] = a; - } - } - - public static void piksr2(double[] arr, double[] brr) { - int i, j, n = arr.length; - double a; - double b; - for (j = 1; j < n; j++) { - a = arr[j]; - b = brr[j]; - i = j; - while (i > 0 && arr[i - 1] > a) { - arr[i] = arr[i - 1]; - brr[i] = brr[i - 1]; - i--; - } - arr[i] = a; - brr[i] = b; - } - } - - public static double select(final int k, final double[] arr) { - int i, ir, j, l, mid, n = arr.length; - double a; - l = 0; - ir = n - 1; - for (;;) { - if (ir <= l + 1) { - if (ir == l + 1 && arr[ir] < arr[l]) { - swap(arr, l, ir); - } - return arr[k]; - } else { - mid = (l + ir) >> 1; - swap(arr, mid, l + 1); - if (arr[l] > arr[ir]) { - swap(arr, l, ir); - } - if (arr[l + 1] > arr[ir]) { - swap(arr, l + 1, ir); - } - if (arr[l] > arr[l + 1]) { - swap(arr, l, l + 1); - } - i = l + 1; - j = ir; - a = arr[l + 1]; - for (;;) { - do - i++; - while (arr[i] < a); - do - j--; - while (arr[j] > a); - if (j < i) - break; - swap(arr, i, j); - } - arr[l + 1] = arr[j]; - arr[j] = a; - if (j >= k) - ir = j - 1; - if (j <= k) - l = i; - } - } - } - - public static void shell(final double[] a) { - shell(a, -1); - } - - public static void shell(final double[] a, final int m) { - int i, j, inc, n = a.length; - double v; - if (m > 0) - n = Math.min(m, n); - inc = 1; - do { - inc *= 3; - inc++; - } while (inc <= n); - do { - inc /= 3; - for (i = inc; i < n; i++) { - v = a[i]; - j = i; - while (a[j - inc] > v) { - a[j] = a[j - inc]; - j -= inc; - if (j < inc) - break; - } - a[j] = v; - } - } while (inc > 1); - } - - public static void sort2(final double[] arr, final double[] brr) { - final int M = 7, NSTACK = 64; - int i, ir, j, k, jstack = -1, l = 0, n = arr.length; - double a; - double b; - int[] istack = new int[NSTACK]; - ir = n - 1; - for (;;) { - if (ir - l < M) { - for (j = l + 1; j <= ir; j++) { - a = arr[j]; - b = brr[j]; - for (i = j - 1; i >= l; i--) { - if (arr[i] <= a) - break; - arr[i + 1] = arr[i]; - brr[i + 1] = brr[i]; - } - arr[i + 1] = a; - brr[i + 1] = b; - } - if (jstack < 0) - break; - ir = istack[jstack--]; - l = istack[jstack--]; - } else { - k = (l + ir) >> 1; - swap(arr, k, l + 1); - swap(brr, k, l + 1); - if (arr[l] > arr[ir]) { - swap(arr, l, ir); - swap(brr, l, ir); - } - if (arr[l + 1] > arr[ir]) { - swap(arr, l + 1, ir); - swap(brr, l + 1, ir); - } - if (arr[l] > arr[l + 1]) { - swap(arr, l, l + 1); - swap(brr, l, l + 1); - } - i = l + 1; - j = ir; - a = arr[l + 1]; - b = brr[l + 1]; - for (;;) { - do - i++; - while (arr[i] < a); - do - j--; - while (arr[j] > a); - if (j < i) - break; - swap(arr, i, j); - swap(brr, i, j); - } - arr[l + 1] = arr[j]; - arr[j] = a; - brr[l + 1] = brr[j]; - brr[j] = b; - jstack += 2; - if (jstack >= NSTACK) - throw new IllegalArgumentException( - "NSTACK too small in sort2."); - if (ir - i + 1 >= j - l) { - istack[jstack] = ir; - istack[jstack - 1] = i; - ir = j - 1; - } else { - istack[jstack] = j - 1; - istack[jstack - 1] = l; - l = i; - } - } - } - } - - /** - * select Mth largest in place - * - */ - public static double selip(final int k, final double[] arr) { - final int M = 64; - final double BIG = .99e99; - int i, j, jl, jm, ju, kk, mm, nlo, nxtmm, n = arr.length; - double ahi, alo, sum; - int[] isel = new int[M + 2]; - double[] sel = new double[M + 2]; - if (k < 0 || k > n - 1) - throw new IllegalArgumentException("bad input to selip"); - kk = k; - ahi = BIG; - alo = -BIG; - for (;;) { - mm = nlo = 0; - sum = 0.0; - nxtmm = M + 1; - for (i = 0; i < n; i++) { - if (arr[i] >= alo && arr[i] <= ahi) { - mm++; - if (arr[i] == alo) - nlo++; - if (mm <= M) - sel[mm - 1] = arr[i]; - else if (mm == nxtmm) { - nxtmm = mm + mm / M; - sel[(i + 2 + mm + kk) % M] = arr[i]; - } - sum += arr[i]; - } - } - if (kk < nlo) { - return alo; - } else if (mm < M + 1) { - Sorter.shell(sel, mm); - ahi = sel[kk]; - return ahi; - } - sel[M] = sum / mm; - Sorter.shell(sel, M + 1); - sel[M + 1] = ahi; - for (j = 0; j < M + 2; j++) - isel[j] = 0; - for (i = 0; i < n; i++) { - if (arr[i] >= alo && arr[i] <= ahi) { - jl = 0; - ju = M + 2; - while (ju - jl > 1) { - jm = (ju + jl) / 2; - if (arr[i] >= sel[jm - 1]) - jl = jm; - else - ju = jm; - } - isel[ju - 1]++; - } - } - j = 0; - while (kk >= isel[j]) { - alo = sel[j]; - kk -= isel[j++]; - } - ahi = sel[j]; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sp/BartlettWin.java b/common-tools/cnuphys/numRec/src/com/nr/sp/BartlettWin.java deleted file mode 100644 index e45f2abb90..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sp/BartlettWin.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.nr.sp; - -import static java.lang.Math.*; - -public class BartlettWin implements WindowFun { - - @Override - public double window(final int j, final int n) { - return 1. - abs(2. * j / (n - 1.) - 1.); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sp/Daub4.java b/common-tools/cnuphys/numRec/src/com/nr/sp/Daub4.java deleted file mode 100644 index 5dd7dad32c..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sp/Daub4.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.nr.sp; - -/** - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Daub4 extends Wavelet { - - @Override - public void filt(final double[] a, final int n, final int isign) { - final double C0 = 0.4829629131445341, C1 = 0.8365163037378077, C2 = 0.2241438680420134, C3 = -0.1294095225512603; - int nh, i, j; - if (n < 4) - return; - double[] wksp = new double[n]; - nh = n >> 1; - if (isign >= 0) { - for (i = 0, j = 0; j < n - 3; j += 2, i++) { - wksp[i] = C0 * a[j] + C1 * a[j + 1] + C2 * a[j + 2] + C3 - * a[j + 3]; - wksp[i + nh] = C3 * a[j] - C2 * a[j + 1] + C1 * a[j + 2] - C0 - * a[j + 3]; - } - wksp[i] = C0 * a[n - 2] + C1 * a[n - 1] + C2 * a[0] + C3 * a[1]; - wksp[i + nh] = C3 * a[n - 2] - C2 * a[n - 1] + C1 * a[0] - C0 - * a[1]; - } else { - wksp[0] = C2 * a[nh - 1] + C1 * a[n - 1] + C0 * a[0] + C3 * a[nh]; - wksp[1] = C3 * a[nh - 1] - C0 * a[n - 1] + C1 * a[0] - C2 * a[nh]; - for (i = 0, j = 2; i < nh - 1; i++) { - wksp[j++] = C2 * a[i] + C1 * a[i + nh] + C0 * a[i + 1] + C3 - * a[i + nh + 1]; - wksp[j++] = C3 * a[i] - C0 * a[i + nh] + C1 * a[i + 1] - C2 - * a[i + nh + 1]; - } - } - for (i = 0; i < n; i++) - a[i] = wksp[i]; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sp/Daub4i.java b/common-tools/cnuphys/numRec/src/com/nr/sp/Daub4i.java deleted file mode 100644 index 26cfb7e271..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sp/Daub4i.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.nr.sp; - -public class Daub4i extends Wavelet { - @Override - public void filt(final double[] a, final int n, final int isign) { - final double C0 = 0.4829629131445341, C1 = 0.8365163037378077, C2 = 0.2241438680420134, C3 = -0.1294095225512603; - final double R00 = 0.603332511928053, R01 = 0.690895531839104, R02 = -0.398312997698228, R10 = -0.796543516912183, R11 = 0.546392713959015, R12 = -0.258792248333818, R20 = 0.0375174604524466, R21 = 0.457327659851769, R22 = 0.850088102549165, R23 = 0.223820356983114, R24 = -0.129222743354319, R30 = 0.0100372245644139, R31 = 0.122351043116799, R32 = 0.227428111655837, R33 = -0.836602921223654, R34 = 0.483012921773304, R43 = 0.443149049637559, R44 = 0.767556669298114, R45 = 0.374955331645687, R46 = 0.190151418429955, R47 = -0.194233407427412, R53 = 0.231557595006790, R54 = 0.401069519430217, R55 = -0.717579999353722, R56 = -0.363906959570891, R57 = 0.371718966535296, R65 = 0.230389043796969, R66 = 0.434896997965703, R67 = 0.870508753349866, R75 = -0.539822500731772, R76 = 0.801422961990337, R77 = -0.257512919478482; - int nh, i, j; - if (n < 8) - return; - double[] wksp = new double[n]; - nh = n >> 1; - if (isign >= 0) { - wksp[0] = R00 * a[0] + R01 * a[1] + R02 * a[2]; - wksp[nh] = R10 * a[0] + R11 * a[1] + R12 * a[2]; - wksp[1] = R20 * a[0] + R21 * a[1] + R22 * a[2] + R23 * a[3] + R24 - * a[4]; - wksp[nh + 1] = R30 * a[0] + R31 * a[1] + R32 * a[2] + R33 * a[3] - + R34 * a[4]; - for (i = 2, j = 3; j < n - 4; j += 2, i++) { - wksp[i] = C0 * a[j] + C1 * a[j + 1] + C2 * a[j + 2] + C3 - * a[j + 3]; - wksp[i + nh] = C3 * a[j] - C2 * a[j + 1] + C1 * a[j + 2] - C0 - * a[j + 3]; - } - wksp[nh - 2] = R43 * a[n - 5] + R44 * a[n - 4] + R45 * a[n - 3] - + R46 * a[n - 2] + R47 * a[n - 1]; - wksp[n - 2] = R53 * a[n - 5] + R54 * a[n - 4] + R55 * a[n - 3] - + R56 * a[n - 2] + R57 * a[n - 1]; - wksp[nh - 1] = R65 * a[n - 3] + R66 * a[n - 2] + R67 * a[n - 1]; - wksp[n - 1] = R75 * a[n - 3] + R76 * a[n - 2] + R77 * a[n - 1]; - } else { - wksp[0] = R00 * a[0] + R10 * a[nh] + R20 * a[1] + R30 * a[nh + 1]; - wksp[1] = R01 * a[0] + R11 * a[nh] + R21 * a[1] + R31 * a[nh + 1]; - wksp[2] = R02 * a[0] + R12 * a[nh] + R22 * a[1] + R32 * a[nh + 1]; - if (n == 8) { - wksp[3] = R23 * a[1] + R33 * a[5] + R43 * a[2] + R53 * a[6]; - wksp[4] = R24 * a[1] + R34 * a[5] + R44 * a[2] + R54 * a[6]; - } else { - wksp[3] = R23 * a[1] + R33 * a[nh + 1] + C0 * a[2] + C3 - * a[nh + 2]; - wksp[4] = R24 * a[1] + R34 * a[nh + 1] + C1 * a[2] - C2 - * a[nh + 2]; - wksp[n - 5] = C2 * a[nh - 3] + C1 * a[n - 3] + R43 * a[nh - 2] - + R53 * a[n - 2]; - wksp[n - 4] = C3 * a[nh - 3] - C0 * a[n - 3] + R44 * a[nh - 2] - + R54 * a[n - 2]; - } - for (i = 2, j = 5; i < nh - 3; i++) { - wksp[j++] = C2 * a[i] + C1 * a[i + nh] + C0 * a[i + 1] + C3 - * a[i + nh + 1]; - wksp[j++] = C3 * a[i] - C0 * a[i + nh] + C1 * a[i + 1] - C2 - * a[i + nh + 1]; - } - wksp[n - 3] = R45 * a[nh - 2] + R55 * a[n - 2] + R65 * a[nh - 1] - + R75 * a[n - 1]; - wksp[n - 2] = R46 * a[nh - 2] + R56 * a[n - 2] + R66 * a[nh - 1] - + R76 * a[n - 1]; - wksp[n - 1] = R47 * a[nh - 2] + R57 * a[n - 2] + R67 * a[nh - 1] - + R77 * a[n - 1]; - } - for (i = 0; i < n; i++) - a[i] = wksp[i]; - } - - @Override - public void condition(final double[] a, final int n, final int isign) { - double t0, t1, t2, t3; - if (n < 4) - return; - if (isign >= 0) { - t0 = 0.324894048898962 * a[0] + 0.0371580151158803 * a[1]; - t1 = 1.00144540498130 * a[1]; - t2 = 1.08984305289504 * a[n - 2]; - t3 = -0.800813234246437 * a[n - 2] + 2.09629288435324 * a[n - 1]; - a[0] = t0; - a[1] = t1; - a[n - 2] = t2; - a[n - 1] = t3; - } else { - t0 = 3.07792649138669 * a[0] - 0.114204567242137 * a[1]; - t1 = 0.998556681198888 * a[1]; - t2 = 0.917563310922261 * a[n - 2]; - t3 = 0.350522032550918 * a[n - 2] + 0.477032578540915 * a[n - 1]; - a[0] = t0; - a[1] = t1; - a[n - 2] = t2; - a[n - 1] = t3; - } - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sp/Daubs.java b/common-tools/cnuphys/numRec/src/com/nr/sp/Daubs.java deleted file mode 100644 index 25ab099dd7..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sp/Daubs.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.nr.sp; - -public class Daubs extends Wavelet { - int ncof, ioff, joff; - double[] cc, cr; - final static double[] c4 = { 0.4829629131445341, 0.8365163037378079, - 0.2241438680420134, -0.1294095225512604 }; - final static double[] c12 = { 0.111540743350, 0.494623890398, - 0.751133908021, 0.315250351709, -0.226264693965, -0.129766867567, - 0.097501605587, 0.027522865530, -0.031582039318, 0.000553842201, - 0.004777257511, -0.001077301085 }; - final static double[] c20 = { 0.026670057901, 0.188176800078, - 0.527201188932, 0.688459039454, 0.281172343661, -0.249846424327, - -0.195946274377, 0.127369340336, 0.093057364604, -0.071394147166, - -0.029457536822, 0.033212674059, 0.003606553567, -0.010733175483, - 0.001395351747, 0.001992405295, -0.000685856695, -0.000116466855, - 0.000093588670, -0.000013264203 }; - - public Daubs(final int n) { - ncof = n; - cc = new double[n]; - cr = new double[n]; - int i; - ioff = joff = -(n >> 1); - // ioff = -2; joff = -n + 2; - if (n == 4) - for (i = 0; i < n; i++) - cc[i] = c4[i]; - else if (n == 12) - for (i = 0; i < n; i++) - cc[i] = c12[i]; - else if (n == 20) - for (i = 0; i < n; i++) - cc[i] = c20[i]; - else - throw new IllegalArgumentException("n not yet implemented in Daubs"); - double sig = -1.0; - for (i = 0; i < n; i++) { - cr[n - 1 - i] = sig * cc[i]; - sig = -sig; - } - } - - @Override - public void filt(final double[] a, final int n, final int isign) { - double ai, ai1; - int i, ii, j, jf, jr, k, n1, ni, nj, nh, nmod; - if (n < 4) - return; - double[] wksp = new double[n]; - nmod = ncof * n; - n1 = n - 1; - nh = n >> 1; - for (j = 0; j < n; j++) - wksp[j] = 0.0; - if (isign >= 0) { - for (ii = 0, i = 0; i < n; i += 2, ii++) { - ni = i + 1 + nmod + ioff; - nj = i + 1 + nmod + joff; - for (k = 0; k < ncof; k++) { - jf = n1 & (ni + k + 1); - jr = n1 & (nj + k + 1); - wksp[ii] += cc[k] * a[jf]; - wksp[ii + nh] += cr[k] * a[jr]; - } - } - } else { - for (ii = 0, i = 0; i < n; i += 2, ii++) { - ai = a[ii]; - ai1 = a[ii + nh]; - ni = i + 1 + nmod + ioff; - nj = i + 1 + nmod + joff; - for (k = 0; k < ncof; k++) { - jf = n1 & (ni + k + 1); - jr = n1 & (nj + k + 1); - wksp[jf] += cc[k] * ai; - wksp[jr] += cr[k] * ai1; - } - } - } - for (j = 0; j < n; j++) - a[j] = wksp[j]; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sp/DftInt.java b/common-tools/cnuphys/numRec/src/com/nr/sp/DftInt.java deleted file mode 100644 index c6b2b29812..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sp/DftInt.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.nr.sp; - -import org.netlib.util.doubleW; - -import com.nr.fft.*; -import static java.lang.Math.*; -import com.nr.UniVarRealValueFun; -import com.nr.interp.Poly_interp; - -/** - * Example program illustrating how to use the routine dftcor. The user supplies - * an external function func that returns the quantity h(t). The routine then - * returns S(a,b, cos(wt)*h(t)*dt as cosint and S(a,b, sin(wt)*h(t)*dt as - * sinint. - * - */ -public class DftInt { - final int M = 64, NDFT = 1024, MPOL = 6; - double aold = -1.e30, bold = -1.e30, delta; - int init = 0; - double[] data = new double[NDFT]; - double[] endpts = new double[8]; - UniVarRealValueFun funcold; - - public void dftint(final UniVarRealValueFun func, final double a, - final double b, final double w, final doubleW cosint, - final doubleW sinint) { - final double TWOPI = 6.283185307179586476; - int j, nn; - double c, cdft, en, s, sdft; - doubleW corfac = new doubleW(0); - doubleW corim = new doubleW(0); - doubleW corre = new doubleW(0); - double[] cpol = new double[MPOL]; - double[] spol = new double[MPOL]; - double[] xpol = new double[MPOL]; - if (init != 1 || a != aold || b != bold || func != funcold) { - init = 1; - aold = a; - bold = b; - funcold = func; - delta = (b - a) / M; - for (j = 0; j < M + 1; j++) - data[j] = func.funk(a + j * delta); - for (j = M + 1; j < NDFT; j++) - data[j] = 0.0; - for (j = 0; j < 4; j++) { - endpts[j] = data[j]; - endpts[j + 4] = data[M - 3 + j]; - } - FFT.realft(data, 1); - data[1] = 0.0; - } - en = w * delta * NDFT / TWOPI + 1.0; - nn = min(max((int) (en - 0.5 * MPOL + 1.0), 1), NDFT / 2 - MPOL + 1); - for (j = 0; j < MPOL; j++, nn++) { - cpol[j] = data[2 * nn - 2]; - spol[j] = data[2 * nn - 1]; - xpol[j] = nn; - } - cdft = new Poly_interp(xpol, cpol, MPOL).interp(en); - sdft = new Poly_interp(xpol, spol, MPOL).interp(en); - Fourier.dftcor(w, delta, a, b, endpts, corre, corim, corfac); - cdft *= corfac.val; - sdft *= corfac.val; - cdft += corre.val; - sdft += corim.val; - c = delta * cos(w * a); - s = delta * sin(w * a); - cosint.val = c * cdft - s * sdft; - sinint.val = s * cdft + c * sdft; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sp/Fourier.java b/common-tools/cnuphys/numRec/src/com/nr/sp/Fourier.java deleted file mode 100644 index a3800863e9..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sp/Fourier.java +++ /dev/null @@ -1,595 +0,0 @@ -package com.nr.sp; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -import org.netlib.util.doubleW; - -import com.nr.Complex; - -import com.nr.fft.FFT; -import com.nr.root.Roots; -import com.nr.stat.Moment; - -/** - * Fourier integrals using FFT Copyright (C) Numerical Recipes Software - * 1986-2007 Java translation Copyright (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class Fourier { - private Fourier() { - } - - /** - * For an integral approximated by a discrete Fourier transform, this - * routine computes the correction factor that multiplies the DFT and the - * endpoint correction to be added. Input is the angular frequency w, - * stepsize delta, lower and upper limits of the integral a and b, while the - * array endpts contains the first 4 and last 4 function values. The - * correction factor W .Â/ is returned as corfac, while the real and - * imaginary parts of the endpoint correction are returned as corre and - * corim. - * - * @param w - * @param delta - * @param a - * @param b - * @param endpts - * @param corre - * @param corim - * @param corfac - */ - public static void dftcor(final double w, final double delta, - final double a, final double b, final double[] endpts, - final doubleW corre, final doubleW corim, final doubleW corfac) { - double a0i, a0r, a1i, a1r, a2i, a2r, a3i, a3r, arg, c, cl, cr, s, sl, sr, t, t2, t4, t6, cth, ctth, spth2, sth, sth4i, stth, th, th2, th4, tmth2, tth4i; - th = w * delta; - if (a >= b || th < 0.0e0 || th > 3.1416e0) - throw new IllegalArgumentException("bad arguments to dftcor"); - if (abs(th) < 5.0e-2) { - t = th; - t2 = t * t; - t4 = t2 * t2; - t6 = t4 * t2; - corfac.val = 1.0 - (11.0 / 720.0) * t4 + (23.0 / 15120.0) * t6; - a0r = (-2.0 / 3.0) + t2 / 45.0 + (103.0 / 15120.0) * t4 - - (169.0 / 226800.0) * t6; - a1r = (7.0 / 24.0) - (7.0 / 180.0) * t2 + (5.0 / 3456.0) * t4 - - (7.0 / 259200.0) * t6; - a2r = (-1.0 / 6.0) + t2 / 45.0 - (5.0 / 6048.0) * t4 + t6 / 64800.0; - a3r = (1.0 / 24.0) - t2 / 180.0 + (5.0 / 24192.0) * t4 - t6 - / 259200.0; - a0i = t - * (2.0 / 45.0 + (2.0 / 105.0) * t2 - (8.0 / 2835.0) * t4 + (86.0 / 467775.0) - * t6); - a1i = t - * (7.0 / 72.0 - t2 / 168.0 + (11.0 / 72576.0) * t4 - (13.0 / 5987520.0) - * t6); - a2i = t - * (-7.0 / 90.0 + t2 / 210.0 - (11.0 / 90720.0) * t4 + (13.0 / 7484400.0) - * t6); - a3i = t - * (7.0 / 360.0 - t2 / 840.0 + (11.0 / 362880.0) * t4 - (13.0 / 29937600.0) - * t6); - } else { - cth = cos(th); - sth = sin(th); - ctth = cth * cth - sth * sth; - stth = 2.0e0 * sth * cth; - th2 = th * th; - th4 = th2 * th2; - tmth2 = 3.0e0 - th2; - spth2 = 6.0e0 + th2; - sth4i = 1.0 / (6.0e0 * th4); - tth4i = 2.0e0 * sth4i; - corfac.val = tth4i * spth2 * (3.0e0 - 4.0e0 * cth + ctth); - a0r = sth4i - * (-42.0e0 + 5.0e0 * th2 + spth2 * (8.0e0 * cth - ctth)); - a0i = sth4i * (th * (-12.0e0 + 6.0e0 * th2) + spth2 * stth); - a1r = sth4i * (14.0e0 * tmth2 - 7.0e0 * spth2 * cth); - a1i = sth4i * (30.0e0 * th - 5.0e0 * spth2 * sth); - a2r = tth4i * (-4.0e0 * tmth2 + 2.0e0 * spth2 * cth); - a2i = tth4i * (-12.0e0 * th + 2.0e0 * spth2 * sth); - a3r = sth4i * (2.0e0 * tmth2 - spth2 * cth); - a3i = sth4i * (6.0e0 * th - spth2 * sth); - } - cl = a0r * endpts[0] + a1r * endpts[1] + a2r * endpts[2] + a3r - * endpts[3]; - sl = a0i * endpts[0] + a1i * endpts[1] + a2i * endpts[2] + a3i - * endpts[3]; - cr = a0r * endpts[7] + a1r * endpts[6] + a2r * endpts[5] + a3r - * endpts[4]; - sr = -a0i * endpts[7] - a1i * endpts[6] - a2i * endpts[5] - a3i - * endpts[4]; - arg = w * (b - a); - c = cos(arg); - s = sin(arg); - corre.val = cl + c * cr - s * sr; - corim.val = sl + s * cr + c * sr; - } - - /** - * Correlation and Autocorrelation Using the FFT - * - * Computes the correlation of two real data sets data1[0..n-1] and - * data2[0..n-1] (including any user-supplied zero padding). n must be an - * integer power of 2. The answer is returned in ans[0..n-1] stored in - * wraparound order, i.e., correlations at increasingly negative lags are in - * ans[n-1] on down to ans[n/2], while correlations at increasingly positive - * lags are in ans[0] (zero lag) on up to ans[n/2-1]. Sign convention of - * this routine: if data1 lags data2, i.e., is shifted to the right of it, - * then ans will show a peak at positive lags. - * - * @param data1 - * @param data2 - * @param ans - */ - public static void correl(final double[] data1, final double[] data2, - final double[] ans) { - int no2, i, n = data1.length; - double tmp; - double[] temp = new double[n]; - for (i = 0; i < n; i++) { - ans[i] = data1[i]; - temp[i] = data2[i]; - } - FFT.realft(ans, 1); - FFT.realft(temp, 1); - no2 = n >> 1; - for (i = 2; i < n; i += 2) { - tmp = ans[i]; - ans[i] = (ans[i] * temp[i] + ans[i + 1] * temp[i + 1]) / no2; - ans[i + 1] = (ans[i + 1] * temp[i] - tmp * temp[i + 1]) / no2; - } - ans[0] = ans[0] * temp[0] / no2; - ans[1] = ans[1] * temp[1] / no2; - FFT.realft(ans, -1); - } - - /** - * Convolution and Deconvolution Using the FFT - * - * Convolves or deconvolves a real data set data[0..n-1] (including any - * user-supplied zero padding) with a response function respns[0..m-1], - * where m is an odd integer <= n. The response function must be stored in - * wraparound order: The first half of the array respns contains the impulse - * response function at positive times, while the second half of the array - * contains the impulse response function at negative times, counting down - * from the highest element respns[m-1]. On input isign is C1 for - * convolution, 1 for deconvolution. The answer is returned in ans[0..n-1]. - * n must be an integer power of 2. - * - * @param data - * @param respns - * @param isign - * @param ans - */ - public static void convlv(final double[] data, final double[] respns, - final int isign, final double[] ans) { - int i, no2, n = data.length, m = respns.length; - double mag2, tmp; - double[] temp = new double[n]; - temp[0] = respns[0]; - for (i = 1; i < (m + 1) / 2; i++) { - temp[i] = respns[i]; - temp[n - i] = respns[m - i]; - } - for (i = (m + 1) / 2; i < n - (m - 1) / 2; i++) - temp[i] = 0.0; - for (i = 0; i < n; i++) - ans[i] = data[i]; - FFT.realft(ans, 1); - FFT.realft(temp, 1); - no2 = n >> 1; - if (isign == 1) { - for (i = 2; i < n; i += 2) { - tmp = ans[i]; - ans[i] = (ans[i] * temp[i] - ans[i + 1] * temp[i + 1]) / no2; - ans[i + 1] = (ans[i + 1] * temp[i] + tmp * temp[i + 1]) / no2; - } - ans[0] = ans[0] * temp[0] / no2; - ans[1] = ans[1] * temp[1] / no2; - } else if (isign == -1) { - for (i = 2; i < n; i += 2) { - if ((mag2 = SQR(temp[i]) + SQR(temp[i + 1])) == 0.0) - throw new IllegalArgumentException( - "Deconvolving at response zero in convlv"); - tmp = ans[i]; - ans[i] = (ans[i] * temp[i] + ans[i + 1] * temp[i + 1]) / mag2 - / no2; - ans[i + 1] = (ans[i + 1] * temp[i] - tmp * temp[i + 1]) / mag2 - / no2; - } - if (temp[0] == 0.0 || temp[1] == 0.0) - throw new IllegalArgumentException( - "Deconvolving at response zero in convlv"); - ans[0] = ans[0] / temp[0] / no2; - ans[1] = ans[1] / temp[1] / no2; - } else - throw new IllegalArgumentException("No meaning for isign in convlv"); - FFT.realft(ans, -1); - } - - /** - * - * @param y - * @param yy - * @param x - * @param m - */ - public static void spread(final double y, final double[] yy, - final double x, final int m) { - int[] nfac = { 0, 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880 }; - int ihi, ilo, ix, j, nden, n = yy.length; - double fac; - if (m > 10) - throw new IllegalArgumentException( - "factorial table too small in spread"); - ix = (int) (x); - if (x == (ix)) - yy[ix - 1] += y; - else { - ilo = min(max((int) (x - 0.5 * m), 0), (n - m)); - ihi = ilo + m; - nden = nfac[m]; - fac = x - ilo - 1; - for (j = ilo + 1; j < ihi; j++) - fac *= (x - j - 1); - yy[ihi - 1] += y * fac / (nden * (x - ihi)); - for (j = ihi - 1; j > ilo; j--) { - nden = (nden / (j - ilo)) * (j - ihi); - yy[j - 1] += y * fac / (nden * (x - j)); - } - } - } - - /** - * Fast evaluation of Lomb periodogram Given n data points with abscissas - * x[0..n-1] (which need not be equally spaced) and ordinates y[0..n-1], and - * given a desired oversampling factor ofac (a typical value being 4 or - * larger), this routine fills array px[0..nout-1] with an increasing - * sequence of frequencies (not angular frequencies) up to hifac times the - * "average" Nyquist frequency, and fills array py[0..nout-1] with the - * values of the Lomb normalized periodogram at those frequencies. The - * arrays x and y are not altered. The vectors px and py are resized to nout - * (eq. 13.8.9) if their initial size is less than this; otherwise, only - * their first nout components are filled. The routine also returns jmax - * such that py[jmax] is the maximum element in py, and prob, an estimate of - * the significance of that maximum against the hypothesis of random noise. - * A small value of prob indicates that a significant periodic signal is - * present. - * - * @param x - * @param y - * @param ofac - * @param hifac - * @param pxw - * @param pyw - * @param nout - * @param jmax - * @param prob - */ - public static class Fasper { - public double[] px, py; - public int nout, jmax; - public double prob; - - public Fasper(double[] px, double[] py) { - this.px = px; - this.py = py; - } - - public void fasper(final double[] x, final double[] y, - final double ofac, final double hifac) { - final int MACC = 4; - int j, k, nwk, nfreq, nfreqt, n = x.length, np = px.length; - double ck, ckk, cterm, cwt, den, df, effm, expy, fac, fndim, hc2wt, hs2wt, hypo, pmax, sterm, swt, xdif, xmax, xmin; - doubleW ave = new doubleW(0); - doubleW var = new doubleW(0); - - nout = (int) (0.5 * ofac * hifac * n); - nfreqt = (int) (ofac * hifac * n * MACC); - nfreq = 64; - while (nfreq < nfreqt) - nfreq <<= 1; - nwk = nfreq << 1; - if (np < nout) { - px = resize(px, nout); - py = resize(py, nout); - } - Moment.avevar(y, ave, var); - if (var.val == 0.0) - throw new IllegalArgumentException("zero variance in fasper"); - xmin = x[0]; - xmax = xmin; - for (j = 1; j < n; j++) { - if (x[j] < xmin) - xmin = x[j]; - if (x[j] > xmax) - xmax = x[j]; - } - xdif = xmax - xmin; - double[] wk1 = new double[nwk]; - double[] wk2 = new double[nwk]; - fac = nwk / (xdif * ofac); - fndim = nwk; - for (j = 0; j < n; j++) { - ck = IEEEremainder((x[j] - xmin) * fac, fndim); - ckk = 2.0 * (ck++); - ckk = IEEEremainder(ckk, fndim); - ++ckk; - spread(y[j] - ave.val, wk1, ck, MACC); - spread(1.0, wk2, ckk, MACC); - } - FFT.realft(wk1, 1); - FFT.realft(wk2, 1); - df = 1.0 / (xdif * ofac); - pmax = -1.0; - for (k = 2, j = 0; j < nout; j++, k += 2) { - hypo = sqrt(wk2[k] * wk2[k] + wk2[k + 1] * wk2[k + 1]); - hc2wt = 0.5 * wk2[k] / hypo; - hs2wt = 0.5 * wk2[k + 1] / hypo; - cwt = sqrt(0.5 + hc2wt); - swt = SIGN(sqrt(0.5 - hc2wt), hs2wt); - den = 0.5 * n + hc2wt * wk2[k] + hs2wt * wk2[k + 1]; - cterm = SQR(cwt * wk1[k] + swt * wk1[k + 1]) / den; - sterm = SQR(cwt * wk1[k + 1] - swt * wk1[k]) / (n - den); - px[j] = (j + 1) * df; - py[j] = (cterm + sterm) / (2.0 * var.val); - if (py[j] > pmax) { - jmax = j; - pmax = py[jmax]; - } - } - expy = exp(-pmax); - effm = 2.0 * nout / ofac; - prob = effm * expy; - if (prob > 0.01) - prob = 1.0 - pow(1.0 - expy, effm); - } - } - - /** - * Lomb periodogram for spectral analysis - * - * Given n data points with abscissas x[0..n-1] (which need not be equally - * spaced) and ordinates y[0..n-1], and given a desired oversampling factor - * ofac (a typical value being 4 or larger), this routine fills array - * px[0..nout-1] with an increasing sequence of frequencies (not angular - * frequencies) up to hifac times the "average" Nyquist frequency, and fills - * array py[0..nout-1] with the values of the Lomb normalized periodogram at - * those frequencies. The arrays x and y are not altered. The vectors px and - * py are resized to nout (eq. 13.8.9) if their initial size is less than - * this; otherwise, only their first nout components are filled. The routine - * also returns jmax such that py[jmax] is the maximum element in py, and - * prob, an estimate of the significance of that maximum against the - * hypothesis of random noise. A small value of prob indicates that a - * significant periodic signal is present. - */ - public static class Period { - public double[] px, py; - public int nout, jmax; - public double prob; - - public Period(double[] px, double[] py) { - this.px = px; - this.py = py; - } - - public void period(final double[] x, final double[] y, - final double ofac, final double hifac) { - final double TWOPI = 6.283185307179586476; - int i, j, n = x.length, np = px.length; - double c, cc, cwtau, effm, expy, pnow, pymax, s, ss, sumc, sumcy, sums, sumsh, sumsy, swtau, wtau, xave, xdif, xmax, xmin, yy, arg, wtemp; - doubleW ave = new doubleW(0); - doubleW var = new doubleW(0); - - double[] wi = new double[n]; - double[] wpi = new double[n]; - double[] wpr = new double[n]; - double[] wr = new double[n]; - nout = (int) (0.5 * ofac * hifac * n); - if (np < nout) { - px = resize(px, nout); - py = resize(py, nout); - } - Moment.avevar(y, ave, var); - if (var.val == 0.0) - throw new IllegalArgumentException("zero variance in period"); - xmax = xmin = x[0]; - for (j = 0; j < n; j++) { - if (x[j] > xmax) - xmax = x[j]; - if (x[j] < xmin) - xmin = x[j]; - } - xdif = xmax - xmin; - xave = 0.5 * (xmax + xmin); - pymax = 0.0; - pnow = 1.0 / (xdif * ofac); - for (j = 0; j < n; j++) { - arg = TWOPI * ((x[j] - xave) * pnow); - wpr[j] = -2.0 * SQR(sin(0.5 * arg)); - wpi[j] = sin(arg); - wr[j] = cos(arg); - wi[j] = wpi[j]; - } - for (i = 0; i < nout; i++) { - px[i] = pnow; - sumsh = sumc = 0.0; - for (j = 0; j < n; j++) { - c = wr[j]; - s = wi[j]; - sumsh += s * c; - sumc += (c - s) * (c + s); - } - wtau = 0.5 * atan2(2.0 * sumsh, sumc); - swtau = sin(wtau); - cwtau = cos(wtau); - sums = sumc = sumsy = sumcy = 0.0; - for (j = 0; j < n; j++) { - s = wi[j]; - c = wr[j]; - ss = s * cwtau - c * swtau; - cc = c * cwtau + s * swtau; - sums += ss * ss; - sumc += cc * cc; - yy = y[j] - ave.val; - sumsy += yy * ss; - sumcy += yy * cc; - wr[j] = ((wtemp = wr[j]) * wpr[j] - wi[j] * wpi[j]) + wr[j]; - wi[j] = (wi[j] * wpr[j] + wtemp * wpi[j]) + wi[j]; - } - py[i] = 0.5 * (sumcy * sumcy / sumc + sumsy * sumsy / sums) - / var.val; - if (py[i] >= pymax) { - jmax = i; - pymax = py[jmax]; - } - pnow += 1.0 / (ofac * xdif); - } - expy = exp(-pymax); - effm = 2.0 * nout / ofac; - prob = effm * expy; - if (prob > 0.01) - prob = 1.0 - pow(1.0 - expy, effm); - } - } - - /** - * Given a real vector of data[0..n-1], this routine returns m linear - * prediction coefficients as d[0..m-1], and returns the mean square - * discrepancy as xms. - * - * @param data - * @param xms - * @param d - */ - public static void memcof(final double[] data, final doubleW xms, - final double[] d) { - int k, j, i, n = data.length, m = d.length; - double p = 0.0; - double[] wk1 = new double[n]; - double[] wk2 = new double[n]; - double[] wkm = new double[n]; - for (j = 0; j < n; j++) - p += SQR(data[j]); - xms.val = p / n; - wk1[0] = data[0]; - wk2[n - 2] = data[n - 1]; - for (j = 1; j < n - 1; j++) { - wk1[j] = data[j]; - wk2[j - 1] = data[j]; - } - for (k = 0; k < m; k++) { - double num = 0.0, denom = 0.0; - for (j = 0; j < (n - k - 1); j++) { - num += (wk1[j] * wk2[j]); - denom += (SQR(wk1[j]) + SQR(wk2[j])); - } - d[k] = 2.0 * num / denom; - xms.val *= (1.0 - SQR(d[k])); - for (i = 0; i < k; i++) - d[i] = wkm[i] - d[k] * wkm[k - 1 - i]; - if (k == m - 1) - return; - for (i = 0; i <= k; i++) - wkm[i] = d[i]; - for (j = 0; j < (n - k - 2); j++) { - wk1[j] -= (wkm[k] * wk2[j]); - wk2[j] = wk2[j + 1] - wkm[k] * wk1[j + 1]; - } - } - throw new IllegalArgumentException("never get here in memcof"); - } - - /** - * Given the LP coefficients d[0..m-1], this routine finds all roots of the - * characteristic polynomial (13.6.14), reflects any roots that are outside - * the unit circle back inside, and then returns a modified set of - * coefficients d[0..m-1]. - * - * @param d - */ - public static void fixrts(final double[] d) { - boolean polish = true; - int i, j, m = d.length; - Complex[] a = new Complex[m + 1]; - Complex[] roots = new Complex[m]; - a[m] = new Complex(1.0, 0.0); - for (j = 0; j < m; j++) - a[j] = new Complex(-d[m - 1 - j], 0.0); - Roots.zroots(a, roots, polish); - for (j = 0; j < m; j++) - if (roots[j].mod() > 1.0) - roots[j] = new Complex(1.0, 0).div(roots[j].conj()); - a[0] = roots[0].neg(); - a[1] = new Complex(1.0, 0); - for (j = 1; j < m; j++) { - a[j + 1] = new Complex(1.0, 0); - for (i = j; i >= 1; i--) - a[i] = a[i - 1].sub(roots[j].mul(a[i])); - a[0] = roots[j].neg().mul(a[0]); - } - for (j = 0; j < m; j++) - d[m - 1 - j] = -a[j].re(); - } - - /** - * Given data[0..ndata-1], and given the data's LP coefficients d[0..m-1], - * this routine applies equation (13.6.11) to predict the next nfut data - * points, which it returns in the array future[0..nfut-1]. Note that the - * routine references only the last m values of data, as initial values for - * the prediction. - * - * @param data - * @param d - * @param future - */ - public static void predic(final double[] data, final double[] d, - final double[] future) { - int k, j, ndata = data.length, m = d.length, nfut = future.length; - double sum, discrp; - double[] reg = new double[m]; - for (j = 0; j < m; j++) - reg[j] = data[ndata - 1 - j]; - for (j = 0; j < nfut; j++) { - discrp = 0.0; - sum = discrp; - for (k = 0; k < m; k++) - sum += d[k] * reg[k]; - for (k = m - 1; k >= 1; k--) - reg[k] = reg[k - 1]; - future[j] = reg[0] = sum; - } - } - - /** - * Given d[0..m-1] and xms as returned by memcof, this function returns the - * power spectrum estimate P(f) as a function of fdt = fd - * - * @param fdt - * @param d - * @param xms - * @return - */ - public static double evlmem(final double fdt, final double[] d, - final double xms) { - int i; - double sumr = 1.0, sumi = 0.0, wr = 1.0, wi = 0.0, wpr, wpi, wtemp, theta; - - int m = d.length; - theta = 6.28318530717959 * fdt; - wpr = cos(theta); - wpi = sin(theta); - for (i = 0; i < m; i++) { - wr = (wtemp = wr) * wpr - wi * wpi; - wi = wi * wpr + wtemp * wpi; - sumr -= d[i] * wr; - sumi -= d[i] * wi; - } - return xms / (sumr * sumr + sumi * sumi); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sp/Hann.java b/common-tools/cnuphys/numRec/src/com/nr/sp/Hann.java deleted file mode 100644 index 94637bc397..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sp/Hann.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.nr.sp; - -import static java.lang.Math.*; - -public class Hann implements WindowFun { - private int nn; - private double[] win; - - public Hann(final int n) { - nn = n; - win = new double[n]; - double twopi = 8. * atan(1.); - for (int i = 0; i < nn; i++) - win[i] = 0.5 * (1. - cos(i * twopi / (nn - 1.))); - } - - @Override - public double window(final int j, final int n) { - if (n != nn) - throw new IllegalArgumentException("incorrect n for this Hann"); - return win[j]; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sp/Slepian.java b/common-tools/cnuphys/numRec/src/com/nr/sp/Slepian.java deleted file mode 100644 index 10fe3f85a8..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sp/Slepian.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.nr.sp; - -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -public class Slepian extends Spectreg { - - int jres, kt; - double[][] dpss; - double p, pp, d, dd; - - public Slepian(final int em, final int jjres, final int kkt) { - super(em); - jres = jjres; - kt = kkt; - dpss = new double[kkt][2 * em]; - - if (jres < 1 || kt >= 2 * jres) - throw new IllegalArgumentException("kt too big or jres too small"); - filltable(); - } - - public void renorm(final int n) { - p = ldexp(p, n); - pp = ldexp(pp, n); - d = ldexp(d, n); - dd = ldexp(dd, n); - } - - public void adddataseg(final double[] data) { - int k; - if (data.length != m2) - throw new IllegalArgumentException("wrong size data segment"); - for (k = 0; k < kt; k++) { - Slepwindow window = new Slepwindow(k, dpss); - super.adddataseg(data, window); - } - } - - public void filltable() { - final double EPS = 1.e-10, PI = 4. * atan(1.); - double xx, xnew = 0, xold, sw, ppp, ddd, sum, bet, ssub, ssup;// ,*u; - int i, j, k, nl; - double[] dg = new double[m2], dgg = new double[m2], gam = new double[m2], sup = new double[m2 - 1], sub = new double[m2 - 1]; - sw = 2. * SQR(sin(jres * PI / m2)); - dg[0] = 0.25 * (2 * m2 + sw * SQR(m2 - 1.) - 1.); - for (i = 1; i < m2; i++) { - dg[i] = 0.25 * (sw * SQR(m2 - 1. - 2 * i) + (2 * (m2 - i) - 1.) - * (2 * i + 1.)); - sub[i - 1] = sup[i - 1] = -i * (double) (m2 - i) / 2.; - } - xx = -0.10859 - 0.068762 / jres + 1.5692 * jres; - xold = xx + 0.47276 + 0.20273 / jres - 3.1387 * jres; - for (k = 0; k < kt; k++) { - // u = &dpss[k][0]; - for (i = 0; i < 20; i++) { - pp = 1.; - p = dg[0] - xx; - dd = 0.; - d = -1.; - for (j = 1; j < m2; j++) { - ppp = pp; - pp = p; - ddd = dd; - dd = d; - p = pp * (dg[j] - xx) - ppp * SQR(sup[j - 1]); - d = -pp + dd * (dg[j] - xx) - ddd * SQR(sup[j - 1]); - if (abs(p) > 1.e30) - renorm(-100); - else if (abs(p) < 1.e-30) - renorm(100); - } - xnew = xx - p / d; - if (abs(xx - xnew) < EPS * abs(xnew)) - break; - xx = xnew; - } - xx = xnew - (xold - xnew); - xold = xnew; - for (i = 0; i < m2; i++) - dgg[i] = dg[i] - xnew; - nl = m2 / 3; - dgg[nl] = 1.; - ssup = sup[nl]; - ssub = sub[nl - 1]; - // u[0] = sup[nl] = sub[nl-1] = 0.; - dpss[k][0] = sup[nl] = sub[nl - 1] = 0.; - bet = dgg[0]; - for (i = 1; i < m2; i++) { - gam[i] = sup[i - 1] / bet; - bet = dgg[i] - sub[i - 1] * gam[i]; - // u[i] = ((i==nl? 1. : 0.) - sub[i-1]*u[i-1])/bet; - dpss[k][i] = ((i == nl ? 1. : 0.) - sub[i - 1] * dpss[k][i - 1]) - / bet; - } - for (i = m2 - 2; i >= 0; i--) - dpss[k][i] -= gam[i + 1] * dpss[k][i + 1]; - sup[nl] = ssup; - sub[nl - 1] = ssub; - sum = 0.; - for (i = 0; i < m2; i++) - sum += SQR(dpss[k][i]); - sum = (dpss[k][3] > 0.) ? sqrt(sum) : -sqrt(sum); - for (i = 0; i < m2; i++) - dpss[k][i] /= sum; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sp/Slepwindow.java b/common-tools/cnuphys/numRec/src/com/nr/sp/Slepwindow.java deleted file mode 100644 index 48acb8d7b3..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sp/Slepwindow.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.nr.sp; - -public class Slepwindow implements WindowFun { - private int k; - private double[][] dps; - - public Slepwindow(final int kkt, final double[][] dpss) { - k = kkt; - dps = dpss; - } - - @Override - public double window(final int j, final int n) { - return dps[k][j]; - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sp/Spectolap.java b/common-tools/cnuphys/numRec/src/com/nr/sp/Spectolap.java deleted file mode 100644 index d5383d861f..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sp/Spectolap.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.nr.sp; - -public class Spectolap extends Spectreg { - - int first; - double[] fullseg; - - public Spectolap(final int em) { - super(em); - first = 1; - fullseg = new double[2 * em]; - } - - @Override - public void adddataseg(final double[] data, final WindowFun wf) { - int i; - if (data.length != m) - throw new IllegalArgumentException("wrong size data segment"); - if (first != 0) { - for (i = 0; i < m; i++) - fullseg[i + m] = data[i]; - first = 0; - } else { - for (i = 0; i < m; i++) { - fullseg[i] = fullseg[i + m]; - fullseg[i + m] = data[i]; - } - super.adddataseg(fullseg, wf); - } - } - - public void addlongdata(final double[] data, final WindowFun wf) { - int i, k, noff, nt = data.length, nk = (nt - 1) / m; - double del = nk > 1 ? (nt - m2) / (nk - 1.) : 0.; - if (nt < m2) - throw new IllegalArgumentException("data length too short"); - for (k = 0; k < nk; k++) { - noff = (int) (k * del + 0.5); - for (i = 0; i < m2; i++) - fullseg[i] = data[noff + i]; - super.adddataseg(fullseg, wf); - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sp/Spectreg.java b/common-tools/cnuphys/numRec/src/com/nr/sp/Spectreg.java deleted file mode 100644 index aaad97118d..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sp/Spectreg.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.nr.sp; - -import static com.nr.NRUtil.*; -import com.nr.fft.FFT; - -public class Spectreg { - int m, m2, nsum; - double[] specsum, wksp; - - public Spectreg(final int em) { - m = em; - m2 = 2 * m; - nsum = 0; - specsum = new double[m + 1]; - wksp = new double[m2]; - - if ((m & (m - 1)) != 0) - throw new IllegalArgumentException("m must be power of 2"); - } - - public void adddataseg(final double[] data, final WindowFun wf) { - int i; - double w, fac, sumw = 0.; - if (data.length != m2) - throw new IllegalArgumentException("wrong size data segment"); - for (i = 0; i < m2; i++) { - w = wf.window(i, m2); - wksp[i] = w * data[i]; - sumw += SQR(w); - } - fac = 2. / (sumw * m2); - FFT.realft(wksp, 1); - specsum[0] += 0.5 * fac * SQR(wksp[0]); - for (i = 1; i < m; i++) - specsum[i] += fac * (SQR(wksp[2 * i]) + SQR(wksp[2 * i + 1])); - specsum[m] += 0.5 * fac * SQR(wksp[1]); - nsum++; - } - - public double[] spectrum() { - double[] spec = new double[m + 1]; - if (nsum == 0) - throw new IllegalArgumentException("no data yet"); - for (int i = 0; i <= m; i++) - spec[i] = specsum[i] / nsum; - return spec; - } - - public double[] frequencies() { - double[] freq = new double[m + 1]; - for (int i = 0; i <= m; i++) - freq[i] = i * 0.5 / m; - return freq; - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sp/SquareWin.java b/common-tools/cnuphys/numRec/src/com/nr/sp/SquareWin.java deleted file mode 100644 index 7356e09d92..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sp/SquareWin.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.nr.sp; - -public class SquareWin implements WindowFun { - - @Override - public double window(final int j, final int n) { - return 1.; - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sp/Wavelet.java b/common-tools/cnuphys/numRec/src/com/nr/sp/Wavelet.java deleted file mode 100644 index 28c761c504..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sp/Wavelet.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.nr.sp; - -public abstract class Wavelet { - public abstract void filt(double[] a, final int n, final int isign); - - public void condition(final double[] a, final int n, final int isign) { - } - - public static void wt1(final double[] a, final int isign, final Wavelet wlet) { - int nn, n = a.length; - if (n < 4) - return; - if (isign >= 0) { - wlet.condition(a, n, 1); - for (nn = n; nn >= 4; nn >>= 1) - wlet.filt(a, nn, isign); - } else { - for (nn = 4; nn <= n; nn <<= 1) - wlet.filt(a, nn, isign); - wlet.condition(a, n, -1); - } - } - - public static void wtn(final double[] a, final int[] nn, final int isign, - final Wavelet wlet) { - int idim, i1, i2, i3, k, n, nnew, nprev = 1, nt, ntot = 1; - int ndim = nn.length; - for (idim = 0; idim < ndim; idim++) - ntot *= nn[idim]; - if ((ntot & (ntot - 1)) != 0) - throw new IllegalArgumentException( - "all lengths must be powers of 2 in wtn"); - for (idim = 0; idim < ndim; idim++) { - n = nn[idim]; - double[] wksp = new double[n]; - nnew = n * nprev; - if (n > 4) { - for (i2 = 0; i2 < ntot; i2 += nnew) { - for (i1 = 0; i1 < nprev; i1++) { - for (i3 = i1 + i2, k = 0; k < n; k++, i3 += nprev) - wksp[k] = a[i3]; - if (isign >= 0) { - wlet.condition(wksp, n, 1); - for (nt = n; nt >= 4; nt >>= 1) - wlet.filt(wksp, nt, isign); - } else { - for (nt = 4; nt <= n; nt <<= 1) - wlet.filt(wksp, nt, isign); - wlet.condition(wksp, n, -1); - } - for (i3 = i1 + i2, k = 0; k < n; k++, i3 += nprev) - a[i3] = wksp[k]; - } - } - } - nprev = nnew; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sp/WelchWin.java b/common-tools/cnuphys/numRec/src/com/nr/sp/WelchWin.java deleted file mode 100644 index d7be48dbe0..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sp/WelchWin.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.nr.sp; - -import static com.nr.NRUtil.*; - -public class WelchWin implements WindowFun { - - @Override - public double window(final int j, final int n) { - return 1. - SQR(2. * j / (n - 1.) - 1.); - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/sp/WindowFun.java b/common-tools/cnuphys/numRec/src/com/nr/sp/WindowFun.java deleted file mode 100644 index 7f173c40ef..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/sp/WindowFun.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.nr.sp; - -public interface WindowFun { - - public double window(int j, int n); - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/stat/Moment.java b/common-tools/cnuphys/numRec/src/com/nr/stat/Moment.java deleted file mode 100644 index c71a9fe492..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/stat/Moment.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.nr.stat; - -import org.netlib.util.doubleW; -import static java.lang.Math.*; - -public class Moment { - private Moment() { - } - - public static void moment(final double[] data, final doubleW ave, - final doubleW adev, final doubleW sdev, final doubleW var, - final doubleW skew, final doubleW curt) { - int j, n = data.length; - double ep = 0.0, s, p; - if (n <= 1) - throw new IllegalArgumentException("n must be at least 2 in moment"); - s = 0.0; - for (j = 0; j < n; j++) - s += data[j]; - ave.val = s / n; - adev.val = var.val = skew.val = curt.val = 0.0; - for (j = 0; j < n; j++) { - // adev.val += abs(s=data[j]-ave.val); - s = data[j] - ave.val; - adev.val += abs(s); - ep += s; - var.val += (p = s * s); - skew.val += (p *= s); - curt.val += (p *= s); - } - adev.val /= n; - var.val = (var.val - ep * ep / n) / (n - 1); - sdev.val = sqrt(var.val); - if (var.val != 0.0) { - skew.val /= (n * var.val * sdev.val); - curt.val = curt.val / (n * var.val * var.val) - 3.0; - } else - throw new IllegalArgumentException( - "No skew/kurtosis when variance = 0 (in moment)"); - } - - public static void avevar(final double[] data, final doubleW ave, - final doubleW var) { - double s, ep; - int j, n = data.length; - ave.val = 0.0; - for (j = 0; j < n; j++) - ave.val += data[j]; - ave.val /= n; - var.val = ep = 0.0; - for (j = 0; j < n; j++) { - s = data[j] - ave.val; - ep += s; - var.val += s * s; - } - var.val = (var.val - ep * ep / n) / (n - 1); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/stat/Quadvl.java b/common-tools/cnuphys/numRec/src/com/nr/stat/Quadvl.java deleted file mode 100644 index 31df70781f..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/stat/Quadvl.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.nr.stat; - -import org.netlib.util.doubleW; -import static java.lang.Math.*; - -public class Quadvl implements QuadvlInf { - @Override - public void quadvl(final double x, final double y, doubleW fa, doubleW fb, - doubleW fc, doubleW fd) { - double qa, qb, qc, qd; - qa = min(2.0, max(0.0, 1.0 - x)); - qb = min(2.0, max(0.0, 1.0 - y)); - qc = min(2.0, max(0.0, x + 1.0)); - qd = min(2.0, max(0.0, y + 1.0)); - fa.val = 0.25 * qa * qb; - fb.val = 0.25 * qb * qc; - fc.val = 0.25 * qc * qd; - fd.val = 0.25 * qd * qa; - } - -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/stat/QuadvlInf.java b/common-tools/cnuphys/numRec/src/com/nr/stat/QuadvlInf.java deleted file mode 100644 index a16c2896d2..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/stat/QuadvlInf.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.nr.stat; - -import org.netlib.util.doubleW; - -public interface QuadvlInf { - public void quadvl(final double x, final double y, doubleW fa, doubleW fb, - doubleW fc, doubleW fd); -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/stat/SavitzkyGolayFilter.java b/common-tools/cnuphys/numRec/src/com/nr/stat/SavitzkyGolayFilter.java deleted file mode 100644 index 0ed9389a75..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/stat/SavitzkyGolayFilter.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.nr.stat; - -import static java.lang.Math.*; -import com.nr.la.LUdcmp; - -/** - * - * Copyright (C) Numerical Recipes Software 1986-2007 Java translation Copyright - * (C) Huang Wen Hui 2012 - * - * @author hwh - * - */ -public class SavitzkyGolayFilter { - private SavitzkyGolayFilter() { - } - - /** - * Returns in c[0..np-1], in wraparound order (N.B.!) consistent with the - * argument respns in routine convlv, a set of Savitzky-Golay filter - * coefficients. nl is the number of leftward (past) data points used, while - * nr is the number of rightward (future) data points, making the total - * number of data points used nl+nr+1. ld is the order of the derivative - * desired (e.g., ld D 0 for smoothed function. For the derivative of order - * k, you must multiply the array c by k!) m is the order of the smoothing - * polynomial, also equal to the highest conserved moment; usual values are - * m=2 or m=4 - * - * @param c - * @param np - * @param nl - * @param nr - * @param ld - * @param m - */ - public static void savgol(final double[] c, final int np, final int nl, - final int nr, final int ld, final int m) { - int j, k, imj, ipj, kk, mm; - double fac, sum; - if (np < nl + nr + 1 || nl < 0 || nr < 0 || ld > m || nl + nr < m) - throw new IllegalArgumentException("bad args in savgol"); - double[][] a = new double[m + 1][m + 1]; - double[] b = new double[m + 1]; - for (ipj = 0; ipj <= (m << 1); ipj++) { - sum = (ipj != 0 ? 0.0 : 1.0); - for (k = 1; k <= nr; k++) - sum += pow(k, ipj); - for (k = 1; k <= nl; k++) - sum += pow(-k, ipj); - mm = min(ipj, 2 * m - ipj); - for (imj = -mm; imj <= mm; imj += 2) - a[(ipj + imj) / 2][(ipj - imj) / 2] = sum; - } - LUdcmp alud = new LUdcmp(a); - for (j = 0; j < m + 1; j++) - b[j] = 0.0; - b[ld] = 1.0; - alud.solve(b, b); - for (kk = 0; kk < np; kk++) - c[kk] = 0.0; - for (k = -nl; k <= nr; k++) { - sum = b[0]; - fac = 1.0; - for (mm = 1; mm <= m; mm++) - sum += b[mm] * (fac *= k); - kk = (np - k) % np; - c[kk] = sum; - } - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/stat/Stattests.java b/common-tools/cnuphys/numRec/src/com/nr/stat/Stattests.java deleted file mode 100644 index b5f5087e4f..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/stat/Stattests.java +++ /dev/null @@ -1,524 +0,0 @@ -package com.nr.stat; - -import java.util.Arrays; - -import org.netlib.util.doubleW; - -import com.nr.UniVarRealValueFun; -import com.nr.sf.Beta; -import com.nr.sf.Gamma; -import com.nr.sf.KSdist; -import static com.nr.sf.Erf.*; -import static com.nr.sort.Sorter.*; -import static com.nr.stat.Moment.*; -import static java.lang.Math.*; -import static com.nr.NRUtil.*; - -public class Stattests { - private Stattests() { - } - - public static void ttest(final double[] data1, final double[] data2, - final doubleW t, final doubleW prob) { - double svar, df; - doubleW ave1 = new doubleW(0); - doubleW ave2 = new doubleW(0); - doubleW var1 = new doubleW(0); - doubleW var2 = new doubleW(0); - - int n1 = data1.length, n2 = data2.length; - avevar(data1, ave1, var1); - avevar(data2, ave2, var2); - df = n1 + n2 - 2; - svar = ((n1 - 1) * var1.val + (n2 - 1) * var2.val) / df; - t.val = (ave1.val - ave2.val) / sqrt(svar * (1.0 / n1 + 1.0 / n2)); - prob.val = Beta.betai(0.5 * df, 0.5, df / (df + t.val * t.val)); - } - - public static void tutest(final double[] data1, final double[] data2, - final doubleW t, final doubleW prob) { - doubleW ave1 = new doubleW(0); - doubleW ave2 = new doubleW(0); - doubleW var1 = new doubleW(0); - doubleW var2 = new doubleW(0); - double df; - int n1 = data1.length, n2 = data2.length; - avevar(data1, ave1, var1); - avevar(data2, ave2, var2); - t.val = (ave1.val - ave2.val) / sqrt(var1.val / n1 + var2.val / n2); - df = SQR(var1.val / n1 + var2.val / n2) - / (SQR(var1.val / n1) / (n1 - 1) + SQR(var2.val / n2) - / (n2 - 1)); - prob.val = Beta.betai(0.5 * df, 0.5, df / (df + SQR(t.val))); - } - - public static void tptest(final double[] data1, final double[] data2, - final doubleW t, final doubleW prob) { - doubleW ave1 = new doubleW(0); - doubleW ave2 = new doubleW(0); - doubleW var1 = new doubleW(0); - doubleW var2 = new doubleW(0); - - int j, n = data1.length; - double sd, df, cov = 0.0; - avevar(data1, ave1, var1); - avevar(data2, ave2, var2); - for (j = 0; j < n; j++) - cov += (data1[j] - ave1.val) * (data2[j] - ave2.val); - cov /= (df = n - 1); - sd = sqrt((var1.val + var2.val - 2.0 * cov) / n); - t.val = (ave1.val - ave2.val) / sd; - prob.val = Beta.betai(0.5 * df, 0.5, df / (df + t.val * t.val)); - } - - public static void ftest(final double[] data1, final double[] data2, - final doubleW f, final doubleW prob) { - doubleW ave1 = new doubleW(0); - doubleW ave2 = new doubleW(0); - doubleW var1 = new doubleW(0); - doubleW var2 = new doubleW(0); - - double df1, df2; - int n1 = data1.length, n2 = data2.length; - avevar(data1, ave1, var1); - avevar(data2, ave2, var2); - if (var1.val > var2.val) { - f.val = var1.val / var2.val; - df1 = n1 - 1; - df2 = n2 - 1; - } else { - f.val = var2.val / var1.val; - df1 = n2 - 1; - df2 = n1 - 1; - } - prob.val = 2.0 * Beta.betai(0.5 * df2, 0.5 * df1, df2 - / (df2 + df1 * f.val)); - if (prob.val > 1.0) - prob.val = 2. - prob.val; - } - - public static void chsone(final double[] bins, final double[] ebins, - final doubleW df, final doubleW chsq, final doubleW prob) { - chsone(bins, ebins, df, chsq, prob, 1); - } - - public static void chsone(final double[] bins, final double[] ebins, - final doubleW df, final doubleW chsq, final doubleW prob, - final int knstrn) { - Gamma gam = new Gamma(); - int j, nbins = bins.length; - double temp; - df.val = nbins - knstrn; - chsq.val = 0.0; - for (j = 0; j < nbins; j++) { - if (ebins[j] < 0.0 || (ebins[j] == 0. && bins[j] > 0.)) - throw new IllegalArgumentException( - "Bad expected number in chsone"); - if (ebins[j] == 0.0 && bins[j] == 0.0) { - --df.val; - } else { - temp = bins[j] - ebins[j]; - chsq.val += temp * temp / ebins[j]; - } - } - prob.val = gam.gammq(0.5 * df.val, 0.5 * chsq.val); - } - - public static void chstwo(final double[] bins1, final double[] bins2, - final doubleW df, final doubleW chsq, final doubleW prob) { - chstwo(bins1, bins2, df, chsq, prob, 1); - } - - public static void chstwo(final double[] bins1, final double[] bins2, - final doubleW df, final doubleW chsq, final doubleW prob, - final int knstrn) { - Gamma gam = new Gamma(); - int j, nbins = bins1.length; - double temp; - df.val = nbins - knstrn; - chsq.val = 0.0; - for (j = 0; j < nbins; j++) - if (bins1[j] == 0.0 && bins2[j] == 0.0) - --df.val; - else { - temp = bins1[j] - bins2[j]; - chsq.val += temp * temp / (bins1[j] + bins2[j]); - } - prob.val = gam.gammq(0.5 * df.val, 0.5 * chsq.val); - } - - public static void cntab(final int[][] nn, final doubleW chisq, - final doubleW df, final doubleW prob, final doubleW cramrv, - final doubleW ccc) { - final double TINY = 1.0e-30; - Gamma gam = new Gamma(); - int i, j, nnj, nni, minij, ni = nn.length, nj = nn[0].length; - double sum = 0.0, expctd, temp; - double[] sumi = new double[ni], sumj = new double[nj]; - nni = ni; - nnj = nj; - for (i = 0; i < ni; i++) { - sumi[i] = 0.0; - for (j = 0; j < nj; j++) { - sumi[i] += nn[i][j]; - sum += nn[i][j]; - } - if (sumi[i] == 0.0) - --nni; - } - for (j = 0; j < nj; j++) { - sumj[j] = 0.0; - for (i = 0; i < ni; i++) - sumj[j] += nn[i][j]; - if (sumj[j] == 0.0) - --nnj; - } - df.val = nni * nnj - nni - nnj + 1; - chisq.val = 0.0; - for (i = 0; i < ni; i++) { - for (j = 0; j < nj; j++) { - expctd = sumj[j] * sumi[i] / sum; - temp = nn[i][j] - expctd; - chisq.val += temp * temp / (expctd + TINY); - } - } - prob.val = gam.gammq(0.5 * df.val, 0.5 * chisq.val); - minij = nni < nnj ? nni - 1 : nnj - 1; - cramrv.val = sqrt(chisq.val / (sum * minij)); - ccc.val = sqrt(chisq.val / (chisq.val + sum)); - } - - public static void pearsn(final double[] x, final double[] y, - final doubleW r, final doubleW prob, final doubleW z) { - final double TINY = 1.0e-20; - int j, n = x.length; - double yt, xt, t, df; - double syy = 0.0, sxy = 0.0, sxx = 0.0, ay = 0.0, ax = 0.0; - for (j = 0; j < n; j++) { - ax += x[j]; - ay += y[j]; - } - ax /= n; - ay /= n; - for (j = 0; j < n; j++) { - xt = x[j] - ax; - yt = y[j] - ay; - sxx += xt * xt; - syy += yt * yt; - sxy += xt * yt; - } - r.val = sxy / (sqrt(sxx * syy) + TINY); - z.val = 0.5 * log((1.0 + r.val + TINY) / (1.0 - r.val + TINY)); - df = n - 2; - t = r.val * sqrt(df / ((1.0 - r.val + TINY) * (1.0 + r.val + TINY))); - prob.val = Beta.betai(0.5 * df, 0.5, df / (df + t * t)); - // prob=erfcc(abs(z*sqrt(n-1.0))/1.4142136); - } - - public static void crank(final double[] w, final doubleW s) { - int j = 1, ji, jt, n = w.length; - double t, rank; - s.val = 0.0; - while (j < n) { - if (w[j] != w[j - 1]) { - w[j - 1] = j; - ++j; - } else { - for (jt = j + 1; jt <= n && w[jt - 1] == w[j - 1]; jt++) - ; - rank = 0.5 * (j + jt - 1); - for (ji = j; ji <= (jt - 1); ji++) - w[ji - 1] = rank; - t = jt - j; - s.val += (t * t * t - t); - j = jt; - } - } - if (j == n) - w[n - 1] = n; - } - - public static void spear(final double[] data1, final double[] data2, - final doubleW d, final doubleW zd, final doubleW probd, - final doubleW rs, final doubleW probrs) { - int j, n = data1.length; - double vard, t, fac, en3n, en, df, aved; - doubleW sf = new doubleW(0); - doubleW sg = new doubleW(0); - - double[] wksp1 = new double[n], wksp2 = new double[n]; - for (j = 0; j < n; j++) { - wksp1[j] = data1[j]; - wksp2[j] = data2[j]; - } - sort2(wksp1, wksp2); - crank(wksp1, sf); - sort2(wksp2, wksp1); - crank(wksp2, sg); - d.val = 0.0; - for (j = 0; j < n; j++) - d.val += SQR(wksp1[j] - wksp2[j]); - en = n; - en3n = en * en * en - en; - aved = en3n / 6.0 - (sf.val + sg.val) / 12.0; - fac = (1.0 - sf.val / en3n) * (1.0 - sg.val / en3n); - vard = ((en - 1.0) * en * en * SQR(en + 1.0) / 36.0) * fac; - zd.val = (d.val - aved) / sqrt(vard); - probd.val = erfcc(abs(zd.val) / 1.4142136); - rs.val = (1.0 - (6.0 / en3n) * (d.val + (sf.val + sg.val) / 12.0)) - / sqrt(fac); - fac = (rs.val + 1.0) * (1.0 - rs.val); - if (fac > 0.0) { - t = rs.val * sqrt((en - 2.0) / fac); - df = en - 2.0; - probrs.val = Beta.betai(0.5 * df, 0.5, df / (df + t * t)); - } else - probrs.val = 0.0; - } - - public static void kendl1(final double[] data1, final double[] data2, - final doubleW tau, final doubleW z, final doubleW prob) { - int is = 0, j, k, n2 = 0, n1 = 0, n = data1.length; - double svar, aa, a2, a1; - for (j = 0; j < n - 1; j++) { - for (k = j + 1; k < n; k++) { - a1 = data1[j] - data1[k]; - a2 = data2[j] - data2[k]; - aa = a1 * a2; - if (aa != 0.0) { - ++n1; - ++n2; - if (aa > 0.0) - ++is; - else - --is; - } else { - if (a1 != 0.0) - ++n1; - if (a2 != 0.0) - ++n2; - } - } - } - tau.val = is / (sqrt(n1) * sqrt(n2)); - svar = (4.0 * n + 10.0) / (9.0 * n * (n - 1.0)); - z.val = tau.val / sqrt(svar); - prob.val = erfcc(abs(z.val) / 1.4142136); - } - - public static void kendl2(final double[][] tab, final doubleW tau, - final doubleW z, final doubleW prob) { - int k, l, nn, mm, m2, m1, lj, li, kj, ki, i = tab.length, j = tab[0].length; - double svar, s = 0.0, points, pairs, en2 = 0.0, en1 = 0.0; - nn = i * j; - points = tab[i - 1][j - 1]; - for (k = 0; k <= nn - 2; k++) { - ki = (k / j); - kj = k - j * ki; - points += tab[ki][kj]; - for (l = k + 1; l <= nn - 1; l++) { - li = l / j; - lj = l - j * li; - mm = (m1 = li - ki) * (m2 = lj - kj); - pairs = tab[ki][kj] * tab[li][lj]; - if (mm != 0) { - en1 += pairs; - en2 += pairs; - s += (mm > 0 ? pairs : -pairs); - } else { - if (m1 != 0) - en1 += pairs; - if (m2 != 0) - en2 += pairs; - } - } - } - tau.val = s / sqrt(en1 * en2); - svar = (4.0 * points + 10.0) / (9.0 * points * (points - 1.0)); - z.val = tau.val / sqrt(svar); - prob.val = erfcc(abs(z.val) / 1.4142136); - } - - /** - * Kolmogorov-Smirnov tests in one dimension - */ - public static void ksone(final double[] data, - final UniVarRealValueFun func, final doubleW d, final doubleW prob) { - int j, n = data.length; - double dt, en, ff, fn, fo = 0.0; - KSdist ks = new KSdist(); - Arrays.sort(data); - en = n; - d.val = 0.0; - for (j = 0; j < n; j++) { - fn = (j + 1) / en; - ff = func.funk(data[j]); - dt = max(abs(fo - ff), abs(fn - ff)); - if (dt > d.val) - d.val = dt; - fo = fn; - } - en = sqrt(en); - prob.val = ks.qks((en + 0.12 + 0.11 / en) * d.val); - } - - /** - * Kolmogorov-Smirnov tests in one dimension - */ - public static void kstwo(final double[] data1, final double[] data2, - final doubleW d, final doubleW prob) { - int j1 = 0, j2 = 0, n1 = data1.length, n2 = data2.length; - double d1, d2, dt, en1, en2, en, fn1 = 0.0, fn2 = 0.0; - KSdist ks = new KSdist(); - Arrays.sort(data1); - Arrays.sort(data2); - en1 = n1; - en2 = n2; - d.val = 0.0; - while (j1 < n1 && j2 < n2) { - if ((d1 = data1[j1]) <= (d2 = data2[j2])) - do - fn1 = ++j1 / en1; - while (j1 < n1 && d1 == data1[j1]); - if (d2 <= d1) - do - fn2 = ++j2 / en2; - while (j2 < n2 && d2 == data2[j2]); - if ((dt = abs(fn2 - fn1)) > d.val) - d.val = dt; - } - en = sqrt(en1 * en2 / (en1 + en2)); - prob.val = ks.qks((en + 0.12 + 0.11 / en) * d.val); - } - - public static void quadct(final double x, final double y, - final double[] xx, final double[] yy, final doubleW fa, - final doubleW fb, final doubleW fc, final doubleW fd) { - int k, na, nb, nc, nd, nn = xx.length; - double ff; - na = nb = nc = nd = 0; - for (k = 0; k < nn; k++) { - if (yy[k] == y && xx[k] == x) - continue; - if (yy[k] > y) - if (xx[k] > x) - ++na; - else - ++nb; - else if (xx[k] > x) - ++nd; - else - ++nc; - } - ff = 1.0 / nn; - fa.val = ff * na; - fb.val = ff * nb; - fc.val = ff * nc; - fd.val = ff * nd; - } - - public static void ks2d1s(final double[] x1, final double[] y1, - final QuadvlInf quadvl, final doubleW d1, final doubleW prob) { - int j, n1 = x1.length; - double rr, sqen; - doubleW dum = new doubleW(0); - doubleW dumm = new doubleW(0); - doubleW r1 = new doubleW(0); - - doubleW fa = new doubleW(0); - doubleW fb = new doubleW(0); - doubleW fc = new doubleW(0); - doubleW fd = new doubleW(0); - - doubleW ga = new doubleW(0); - doubleW gb = new doubleW(0); - doubleW gc = new doubleW(0); - doubleW gd = new doubleW(0); - - KSdist ks = new KSdist(); - d1.val = 0.0; - for (j = 0; j < n1; j++) { - quadct(x1[j], y1[j], x1, y1, fa, fb, fc, fd); - quadvl.quadvl(x1[j], y1[j], ga, gb, gc, gd); - if (fa.val > ga.val) - fa.val += 1.0 / n1; - if (fb.val > gb.val) - fb.val += 1.0 / n1; - if (fc.val > gc.val) - fc.val += 1.0 / n1; - if (fd.val > gd.val) - fd.val += 1.0 / n1; - d1.val = max(d1.val, abs(fa.val - ga.val)); - d1.val = max(d1.val, abs(fb.val - gb.val)); - d1.val = max(d1.val, abs(fc.val - gc.val)); - d1.val = max(d1.val, abs(fd.val - gd.val)); - } - pearsn(x1, y1, r1, dum, dumm); - sqen = sqrt(n1); - rr = sqrt(1.0 - r1.val * r1.val); - prob.val = ks.qks(d1.val * sqen / (1.0 + rr * (0.25 - 0.75 / sqen))); - } - - public static void ks2d2s(final double[] x1, final double[] y1, - final double[] x2, final double[] y2, final doubleW d, - final doubleW prob) { - int j, n1 = x1.length, n2 = x2.length; - doubleW dum = new doubleW(0); - doubleW dumm = new doubleW(0); - doubleW r1 = new doubleW(0); - doubleW r2 = new doubleW(0); - - doubleW fa = new doubleW(0); - doubleW fb = new doubleW(0); - doubleW fc = new doubleW(0); - doubleW fd = new doubleW(0); - - doubleW ga = new doubleW(0); - doubleW gb = new doubleW(0); - doubleW gc = new doubleW(0); - doubleW gd = new doubleW(0); - - double d1, d2, rr, sqen; - KSdist ks = new KSdist(); - d1 = 0.0; - for (j = 0; j < n1; j++) { - quadct(x1[j], y1[j], x1, y1, fa, fb, fc, fd); - quadct(x1[j], y1[j], x2, y2, ga, gb, gc, gd); - if (fa.val > ga.val) - fa.val += 1.0 / n1; - if (fb.val > gb.val) - fb.val += 1.0 / n1; - if (fc.val > gc.val) - fc.val += 1.0 / n1; - if (fd.val > gd.val) - fd.val += 1.0 / n1; - d1 = max(d1, abs(fa.val - ga.val)); - d1 = max(d1, abs(fb.val - gb.val)); - d1 = max(d1, abs(fc.val - gc.val)); - d1 = max(d1, abs(fd.val - gd.val)); - } - d2 = 0.0; - for (j = 0; j < n2; j++) { - quadct(x2[j], y2[j], x1, y1, fa, fb, fc, fd); - quadct(x2[j], y2[j], x2, y2, ga, gb, gc, gd); - if (ga.val > fa.val) - ga.val += 1.0 / n1; - if (gb.val > fb.val) - gb.val += 1.0 / n1; - if (gc.val > fc.val) - gc.val += 1.0 / n1; - if (gd.val > fd.val) - gd.val += 1.0 / n1; - d2 = max(d2, abs(fa.val - ga.val)); - d2 = max(d2, abs(fb.val - gb.val)); - d2 = max(d2, abs(fc.val - gc.val)); - d2 = max(d2, abs(fd.val - gd.val)); - } - d.val = 0.5 * (d1 + d2); - sqen = sqrt(n1 * n2 / (n1 + n2)); - pearsn(x1, y1, r1, dum, dumm); - pearsn(x2, y2, r2, dum, dumm); - rr = sqrt(1.0 - 0.5 * (r1.val * r1.val + r2.val * r2.val)); - prob.val = ks.qks(d.val * sqen / (1.0 + rr * (0.25 - 0.75 / sqen))); - } -} diff --git a/common-tools/cnuphys/numRec/src/com/nr/util/Calendar.java b/common-tools/cnuphys/numRec/src/com/nr/util/Calendar.java deleted file mode 100644 index 6764f22ebd..0000000000 --- a/common-tools/cnuphys/numRec/src/com/nr/util/Calendar.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.nr.util; - -import static java.lang.Math.*; - -import org.netlib.util.doubleW; -import org.netlib.util.intW; - -public class Calendar { - private Calendar() { - } - - public static int julday(final int mm, final int id, final int iyyy) { - final int IGREG = 15 + 31 * (10 + 12 * 1582); - int ja, jul, jy = iyyy, jm; - if (jy == 0) - throw new IllegalArgumentException("julday: there is no year zero."); - if (jy < 0) - ++jy; - if (mm > 2) { - jm = mm + 1; - } else { - --jy; - jm = mm + 13; - } - jul = (int) (floor(365.25 * jy) + floor(30.6001 * jm) + id + 1720995); - if (id + 31 * (mm + 12 * iyyy) >= IGREG) { - ja = (int) (0.01 * jy); - jul += 2 - ja + (int) (0.25 * ja); - } - return jul; - } - - public static void caldat(final int julian, final intW mm, final intW id, - final intW iyyy) { - final int IGREG = 2299161; - int ja, jalpha, jb, jc, jd, je; - - if (julian >= IGREG) { - jalpha = (int) ((julian - 1867216 - 0.25) / 36524.25); - ja = julian + 1 + jalpha - (int) (0.25 * jalpha); - } else if (julian < 0) { - ja = julian + 36525 * (1 - julian / 36525); - } else - ja = julian; - jb = ja + 1524; - jc = (int) (6680.0 + (jb - 2439870 - 122.1) / 365.25); - jd = (int) (365 * jc + (0.25 * jc)); - je = (int) ((jb - jd) / 30.6001); - id.val = jb - jd - (int) (30.6001 * je); - mm.val = je - 1; - if (mm.val > 12) - mm.val -= 12; - iyyy.val = jc - 4715; - if (mm.val > 2) - --iyyy.val; - if (iyyy.val <= 0) - --iyyy.val; - if (julian < 0) - iyyy.val -= 100 * (1 - julian / 36525); - } - - public static void flmoon(final int n, final int nph, final intW jd, - final doubleW frac) { - final double RAD = 3.141592653589793238 / 180.0; - int i; - double am, as, c, t, t2, xtra; - c = n + nph / 4.0; - t = c / 1236.85; - t2 = t * t; - as = 359.2242 + 29.105356 * c; - am = 306.0253 + 385.816918 * c + 0.010730 * t2; - jd.val = 2415020 + 28 * n + 7 * nph; - xtra = 0.75933 + 1.53058868 * c + ((1.178e-4) - (1.55e-7) * t) * t2; - if (nph == 0 || nph == 2) - xtra += (0.1734 - 3.93e-4 * t) * sin(RAD * as) - 0.4068 - * sin(RAD * am); - else if (nph == 1 || nph == 3) - xtra += (0.1721 - 4.0e-4 * t) * sin(RAD * as) - 0.6280 - * sin(RAD * am); - else - throw new IllegalArgumentException("nph is unknown in flmoon"); - i = (int) (xtra >= 0.0 ? floor(xtra) : ceil(xtra - 1.0)); - jd.val += i; - frac.val = xtra - i; - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/AllTests.java b/common-tools/cnuphys/numRec/test/com/nr/test/AllTests.java deleted file mode 100644 index 8cef90dcb6..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/AllTests.java +++ /dev/null @@ -1,342 +0,0 @@ -package com.nr.test; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - -import com.nr.test.test_chapter1.*; -import com.nr.test.test_chapter2.*; -import com.nr.test.test_chapter3.*; -import com.nr.test.test_chapter4.*; -import com.nr.test.test_chapter5.*; -import com.nr.test.test_chapter6.*; -import com.nr.test.test_chapter7.*; -import com.nr.test.test_chapter8.*; -import com.nr.test.test_chapter9.*; -import com.nr.test.test_chapter10.*; -import com.nr.test.test_chapter11.*; -import com.nr.test.test_chapter12.*; -import com.nr.test.test_chapter13.*; -import com.nr.test.test_chapter14.*; -import com.nr.test.test_chapter15.*; -import com.nr.test.test_chapter16.*; -import com.nr.test.test_chapter17.*; -import com.nr.test.test_chapter18.*; -import com.nr.test.test_chapter19.*; -import com.nr.test.test_chapter20.*; -import com.nr.test.test_chapter21.*; -import com.nr.test.test_chapter22.*; - - -@RunWith(Suite.class) -@SuiteClasses({ - Test_caldat.class, - Test_flmoon.class, - Test_julday.class, - Test_Amebsa.class, - Test_Amoeba.class, - Test_Anneal.class, - Test_Bracketmethod.class, - Test_Brent.class, - Test_Dbrent.class, - Test_Frprmn.class, - Test_Golden.class, - Test_Linemethod.class, - Test_Powell.class, - Test_dfpmin.class, - Test_dynpro.class, - Test_fdfunc.class, - Test_stringalign.class, - Test_Jacobi.class, - Test_Symmeig.class, - Test_Unsymmeig.class, - Test_WrapVecDoub.class, - Test_cosft1.class, - Test_cosft2.class, - Test_four1.class, - Test_fourfs.class, - Test_fourn.class, - Test_realft.class, - Test_rlft3.class, - Test_sinft.class, - Test_Daub4.class, - Test_Daub4i.class, - Test_Daubs.class, - Test_Hann.class, - Test_Slepian.class, - Test_Spectolap.class, - Test_Spectreg.class, - Test_Square.class, - Test_bartlett.class, - Test_convlv.class, - Test_correl.class, - Test_dftint.class, - Test_evlmem.class, - Test_fasper.class, - Test_fixrts.class, - Test_memcof.class, - Test_period.class, - Test_predic.class, - Test_spread.class, - Test_welch.class, - Test_wt0.class, - Test_wtn.class, - Test_avevar.class, - Test_chsone.class, - Test_chstwo.class, - Test_cntab.class, - Test_crank.class, - Test_ftest.class, - Test_kendl1.class, - Test_kendl2.class, - Test_ks2d1s.class, - Test_ks2d2s.class, - Test_ksone.class, - Test_kstwo.class, - Test_moment.class, - Test_pearsn.class, - Test_quadct.class, - Test_quadvl.class, - Test_savgol.class, - Test_spear.class, - Test_tptest.class, - Test_ttest.class, - Test_tutest.class, - Test_Fitab.class, - Test_Fitexy.class, - Test_Fitlin.class, - Test_Fitmed.class, - Test_Fitmrq.class, - Test_Fitsvd.class, - Test_fleg.class, - Test_fpoly.class, - com.nr.test.test_chapter15.Test_mcmc.class, - Test_Gaumixmod.class, - Test_HMM.class, - Test_Kmeans.class, - Test_Phylo_clc.class, - Test_Phylo_nj.class, - Test_Phylo_slc.class, - Test_Phylo_upgma.class, - Test_Phylo_wpgma.class, - Test_Svm.class, - Test_markovgen.class, - Test_newick.class, - Test_StepperBS.class, - Test_StepperDopr5.class, - Test_StepperDopr853.class, - Test_StepperRoss.class, - Test_StepperSie.class, - Test_StepperStoerm.class, - Test_Stochsim.class, - Test_rk4.class, - Test_Shoot.class, - Test_Shootf.class, - Test_Solvde.class, - Test_sfroid.class, - Test_Fred2.class, - Test_Fredex.class, - Test_Wwghts.class, - Test_voltra.class, - Test_ADAT.class, - Test_Bandec.class, - Test_Cholesky.class, - Test_LUdcmp.class, - Test_Linbcg.class, - Test_NRsparseCol.class, - Test_NRsparseMat.class, - Test_QRdcmp.class, - Test_SVD.class, - Test_cyclic.class, - Test_gaussj.class, - Test_mprove.class, - Test_toeplz.class, - Test_tridag.class, - Test_vander.class, - Test_Mgfas.class, - Test_Mglin.class, - Test_sor.class, - Test_weights.class, - Test_Box.class, - Test_Boxnode.class, - Test_Circle.class, - Test_Convexhull.class, - Test_Delaunay.class, - Test_KDtree.class, - Test_Minspantree.class, - Test_Nearpoints.class, - Test_Point.class, - Test_Qotree.class, - Test_Sphcirc.class, - Test_Triel.class, - Test_Voredge.class, - Test_Voronoi.class, - Test_circumcircle.class, - Test_dist.class, - Test_incircle.class, - Test_ispolysimple.class, - Test_polywind.class, - Test_Arithcode.class, - Test_Gray.class, - Test_Huffcode.class, - Test_Icrc.class, - Test_MParith.class, - Test_Machar.class, - Test_PSpage.class, - Test_PSplot.class, - Test_decchk.class, - Test_BaryRat_interp.class, - Test_Bilin_interp.class, - Test_Curve_interp.class, - Test_Krig.class, - Test_Laplace_interp.class, - Test_Linear_interp.class, - Test_Poly2D_interp.class, - Test_Poly_interp.class, - Test_RBF_interp.class, - Test_Rat_interp.class, - Test_Shep_interp.class, - Test_Spline2D_interp.class, - Test_Spline_interp.class, - Test_bcuint.class, - Test_polcoe.class, - Test_polcof.class, - Test_Adapt.class, - Test_Stiel.class, - Test_derule.class, - Test_gaucof.class, - Test_gauher.class, - Test_gaujac.class, - Test_gaulag.class, - Test_gauleg.class, - Test_lobatto.class, - Test_midexp.class, - Test_midinf.class, - Test_midpnt.class, - Test_midsql.class, - Test_midsqu.class, - Test_qgaus.class, - Test_qromb.class, - Test_qromo.class, - Test_qsimp.class, - Test_qtrap.class, - Test_quad3d.class, - Test_radau.class, - Test_trapzd.class, - Test_Chebyshev.class, - Test_Epsalg.class, - Test_Eulsum.class, - Test_Levin.class, - Test_Poly.class, - Test_Ratfn.class, - Test_ddpoly.class, - Test_dfridr.class, - Test_ipcshft.class, - Test_levex.class, - Test_pade.class, - Test_pcshft.class, - Test_poldiv.class, - Test_ratlsq.class, - Test_Bessel.class, - Test_Bessik.class, - Test_Bessjy.class, - Test_Betadist.class, - Test_Binomialdist.class, - Test_Cauchydist.class, - Test_Chisqdist.class, - Test_Erf.class, - Test_Expondist.class, - Test_Fdist.class, - Test_Fermi.class, - Test_Gamma.class, - Test_Gammadist.class, - Test_KSdist.class, - Test_Logisticdist.class, - Test_Lognormaldist.class, - Test_Normaldist.class, - Test_Poissondist.class, - Test_Studenttdist.class, - Test_beta.class, - Test_betai.class, - Test_bico.class, - Test_cisi.class, - Test_dawson.class, - Test_ei.class, - Test_elle.class, - Test_ellf.class, - Test_ellpi.class, - Test_erfcc.class, - Test_expint.class, - Test_factln.class, - Test_factrl.class, - Test_frenel.class, - Test_gammln.class, - Test_hypgeo.class, - Test_invxlogx.class, - Test_plegendre.class, - Test_rc.class, - Test_rd.class, - Test_rf.class, - Test_rj.class, - Test_sncndn.class, - Test_Binomialdev.class, - Test_Cauchydev.class, - Test_Expondev.class, - Test_Gammadev.class, - Test_Hash.class, - Test_Hashtable.class, - Test_Logisticdev.class, - Test_MCintegrate.class, - Test_Mhash.class, - Test_Multinormaldev.class, - Test_Normaldev.class, - Test_Normaldev_BM.class, - Test_Poissondev.class, - Test_Primpolytest.class, - Test_Ran.class, - Test_Ranbyte.class, - Test_Ranfib.class, - Test_Ranhash.class, - Test_Ranlim32.class, - Test_Ranq1.class, - Test_Ranq2.class, - Test_hashall.class, - com.nr.test.test_chapter7.Test_mcmc.class, - Test_miser.class, - Test_psdes.class, - Test_sobseq.class, - Test_vegas.class, - Test_Heapselect.class, - Test_IQagent.class, - Test_Indexx.class, - Test_eclass.class, - Test_eclazz.class, - Test_hpsort.class, - Test_piksr2.class, - Test_piksrt.class, - Test_select.class, - Test_selip.class, - Test_shell.class, - Test_sort.class, - Test_sort2.class, - Test_broydn.class, - Test_laguer.class, - Test_lnsrch.class, - Test_mnewt.class, - Test_newt.class, - Test_qroot.class, - Test_rtbis.class, - Test_rtflsp.class, - Test_rtnewt.class, - Test_rtsafe.class, - Test_rtsec.class, - Test_zbrac.class, - Test_zbrak.class, - Test_zbrent.class, - Test_zrhqr.class, - Test_zriddr.class, - Test_zroots.class - }) -public class AllTests { - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/NRTestUtil.java b/common-tools/cnuphys/numRec/test/com/nr/test/NRTestUtil.java deleted file mode 100644 index 443879c88e..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/NRTestUtil.java +++ /dev/null @@ -1,219 +0,0 @@ -package com.nr.test; - -import com.nr.ran.Ran; -import static java.lang.Math.*; - -public class NRTestUtil { - public static Ran ran = new Ran(10101); // global ranno generator - - private NRTestUtil(){} - - public static void ranmat(double[][] a) { // fill matrix with ran - ranmat(a, 0.); - } - - public static void ranmat(double[][] a, double dadd) { // fill matrix with ran - int m = a.length, n=a[0].length; - for (int i=0;i max) max = abs(a[i][j]); - } - return max; - } - - - public static double maxel(final double[] a) { - int i,m=a.length; - double max = 0.; - for (i=0;i max) max = abs(a[i]); - } - return max; - } - - - public static double[][] ident(int n, double dum) { - double[][] c; - //c.assign(n,n,(T)0); - c = new double[n][n]; - for (int i=0;i max) max = abs(a[i][j]); - } - return max; - } - - - public static int maxel(final int[] a) { - int i,m=a.length; - int max = 0; - for (i=0;i max) max = abs(a[i]); - } - return max; - } - - - public static int[][] ident(int n, int dum) { - int[][] c; - //c.assign(n,n,(T)0); - c = new int[n][n]; - for (int i=0;i= j2.val ? 0.5 : -0.5)); - for (i=0;i < 12;i++) { - n++; - flmoon(n,nph,j2,frac); - frac.val=24.0*frac.val; - if (frac.val < 0.0) { - j2.val--; - frac.val += 24.0; - } - if (frac.val > 12.0) { - j2.val++; - frac.val -= 12.0; - } else - frac.val += 12.0; - i1=(int)(frac.val); // hours - i2=(int)(60.0*(frac.val-i1)); // minutes - caldat(j2.val,im,id,iy); - - localflag = (im.val != i+1); - globalflag = globalflag || localflag; - if (localflag) { - System.out.println("*** flmoon: There should be a full moon in each month"); - - } - - localflag = (id.val != nday[i]); - globalflag = globalflag || localflag; - if (localflag) { - System.out.println("*** flmoon: Day of full moon disagrees with U.S. Naval Observatory"); - - } - -// System.out.printf(frac-(nhour[i]+nmin[i]/60.0) << endl; - localflag = abs(frac.val-(nhour[i]+nmin[i]/60.0)) > 1.0; - globalflag = globalflag || localflag; - if (localflag) { - System.out.println("*** flmoon: Time of full moon disagrees with U.S. Naval Observatory by > 2 hrs"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter1/Test_julday.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter1/Test_julday.java deleted file mode 100644 index ba50495952..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter1/Test_julday.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.nr.test.test_chapter1; - - -import static com.nr.util.Calendar.*; -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class Test_julday { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,id,im,iy,nrjday,N=16; - /* - char *event[]={"End of millenium","One day later", - "Day before Gregorian calendar","Gregorian calendar adopted", - "Benjamin Franklin born","Abraham Lincoln shot", - "San Francisco earthquake","Sinking of the Lusitania", - "Pancho Villa assassinated","Bonnie and Clyde subdued", - "John Dillinger shot","Bruno Hauptman electrocuted", - "Hindenburg disaster","Sinking of the Andrea Doria", - "Teton dam collapse","Julian Day 2440000"};*/ - int nmonth[]={12,1,10,10,1,4,4,5,7,5,7,4,5,7,6,5}; - int nday[]={31,01,04,15,17,14,18,7,20,23,22,3,6,26,5,23}; - int nyear[]={-1,1,1582,1582,1706,1865,1906,1915,1923,1934, - 1934,1936,1937,1956,1976,1968}; - // Corresponding Julian days from U.S. Naval Observatory - int expect[]={1721423,1721424,2299160,2299161,2344180, - 2402341,2417319,2420625,2423621,2427581,2427641, - 2428262,2428660,2435681,2442935,2440000}; - boolean localflag, globalflag=false; - - - // Test julday - System.out.println("Testing julday"); - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Amebsa, interface 1: Incorrect minimum function value"); - - } - - sbeps=1.e-4; - localflag = false; - for (i=0;i<4;i++) - localflag = localflag || abs(amb1.pb[i]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Amebsa, interface 1: Did not converge to the global minumum at the origin"); - - } - - // Test interface #2 - Amebsa amb2 = new Amebsa(point,dels,func_amebsa,FTOL); - - iter.val=1000; - temperature=100.0; - for (j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Amebsa, interface 2: Incorrect minimum function value"); - - } - - sbeps=1.e-4; - localflag = false; - for (i=0;i<4;i++) - localflag = localflag || abs(amb2.pb[i]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Amebsa, interface 2: Did not converge to the global minumum at the origin"); - - } - - // Test interface #3 - - Amebsa amb3 =new Amebsa(p,func_amebsa,FTOL); - - iter.val=1000; - temperature=100.0; - for (j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Amebsa, interface 3: Incorrect minimum function value"); - - } - - sbeps=1.e-4; - localflag = false; - for (i=0;i<4;i++) - localflag = localflag || abs(amb3.pb[i]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Amebsa, interface 3: Did not converge to the global minumum at the origin"); - - } - - localflag = false; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Amebsa: **********************"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class func_amebsa implements RealValueFun { - public double funk(double[] p){ - int j,N=4; - double q,r,sumd=0.0,sumr=0.0,RAD=0.3,AUG=2.0; - double wwid[]={1.0,3.0,10.0,30.0}; - double[] wid=buildVector(wwid); - - for (j=0;j= 0 ? (int)(q+0.5) : -(int)(0.5-q)); - sumr += q*q; - sumd += (q-r)*(q-r); - } - return 1.0+sumr*(1.0+(sumd > RAD*RAD ? AUG : AUG*sumd/(RAD*RAD))); - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Amoeba.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Amoeba.java deleted file mode 100644 index 6431691fe5..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Amoeba.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.nr.test.test_chapter10; - -import static java.lang.Math.abs; -import static java.lang.Math.pow; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.RealValueFun; -import com.nr.UniVarRealValueFun; -import com.nr.min.Amoeba; -import com.nr.sf.Bessjy; - -public class Test_Amoeba { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=20,M=2; - double tol=1.e-12,del=1.0,sbeps=0.; - double[] point=new double[M],min=new double[M]; - boolean localflag=false, globalflag=false; - - Func_Amoeba Func_Amoeba= new Func_Amoeba(); - Bessj1_Amoeba Bessj1_Amoeba = new Bessj1_Amoeba(); - - // Test Amoeba - System.out.println("Testing Amoeba, interface1"); - Amoeba amb1=new Amoeba(tol); - for (i=0;i sbeps) - || (abs(2*min[1]) > sbeps); - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Amoeba, interface1: Gradient not zero at one of the identified minima"); - - } - - System.out.println("Testing Amoeba, interface2"); - Amoeba amb2 = new Amoeba(tol); - double[] dels=new double[M]; - dels[0]=del; - dels[1]=0.5*del; - for (i=0;i sbeps) - || (abs(2*min[1]) > sbeps); - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Amoeba, interface2: Gradient not zero at one of the identified minima"); - - } - - System.out.println("Testing Amoeba, interface3"); - Amoeba amb3 = new Amoeba(tol); - double[][] pp = new double[3][2]; - for (i=0;i sbeps) - || (abs(2*min[1]) > sbeps); - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Amoeba, interface3: Gradient not zero at one of the identified minima"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - class Func_Amoeba implements RealValueFun { - public double funk(final double[] x) { - Bessjy b = new Bessjy(); - return(b.j0(x[0])+pow(x[1],2.0)); - } - } - class Bessj1_Amoeba implements UniVarRealValueFun { - public double funk(final double x) { - Bessjy b = new Bessjy(); - return(b.j1(x)); - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Anneal.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Anneal.java deleted file mode 100644 index 89ba3437c2..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Anneal.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.nr.test.test_chapter10; - -import static com.nr.NRUtil.SQR; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.min.Anneal; -import com.nr.ran.Ran; - -public class Test_Anneal { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,k,N=100,M=10; - double length,linit,rms,ave; - int[] iorder= new int[N]; - double[] x= new double[N],y= new double[N],l=new double[M]; - boolean localflag, globalflag=false; - - - - // Test Anneal - System.out.println("Testing Anneal"); - - Ran myran=new Ran(17); - for (i=0;i 0.10); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Anneal: Successive runs did not result is substantially same path length"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Bracketmethod.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Bracketmethod.java deleted file mode 100644 index f9c7848fa6..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Bracketmethod.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.nr.test.test_chapter10; - -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.min.Bracketmethod; -import com.nr.ran.Ran; -import com.nr.sf.Bessjy; - -public class Test_Bracketmethod implements UniVarRealValueFun{ - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=100; - double a,b,span=1.0; - boolean localflag=false, globalflag=false; - - - - // Test Bracketmethod - System.out.println("Testing Bracketmethod"); - - Ran myran=new Ran(17); - Bracketmethod br = new Bracketmethod(); - for (i=0;isbeps - || abs(br.fb - funk(br.bx))>sbeps - || abs(br.fc - funk(br.cx))>sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bracketmethod: Function values don't agree with coordinates"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - public double funk(final double x) { - Bessjy b = new Bessjy(); - return(b.j0(x)); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Brent.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Brent.java deleted file mode 100644 index ad07b70e61..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Brent.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.nr.test.test_chapter10; - -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.min.Brent; -import com.nr.sf.Bessjy; - -public class Test_Brent implements UniVarRealValueFun{ - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=50; - double a,b,min,span=1.0,sbeps=1.0e-7; - boolean localflag=false, globalflag=false; - - - - // Test Brent - System.out.println("Testing Brent"); - - Brent br = new Brent(); - for (i=0;i sbeps); - } - - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Brent: Identified minimum is not a zero of the function derivative"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - public double funk(final double x) { - return Bessj0_Brent(x); - } - double Bessj0_Brent(final double x) { - Bessjy b = new Bessjy(); - return(b.j0(x)); - } - - double Bessj1_Brent(final double x) { - Bessjy b = new Bessjy(); - return(b.j1(x)); - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Dbrent.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Dbrent.java deleted file mode 100644 index 3920f24fb4..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Dbrent.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.nr.test.test_chapter10; - -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniValRealValueFunWithDiff; -import com.nr.min.Dbrent; -import com.nr.sf.Bessjy; - -public class Test_Dbrent { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=50; - double a,b,min,span=1.0,sbeps=1.0e-7; - boolean localflag=false, globalflag=false; - - - - // Test Dbrent - System.out.println("Testing Dbrent"); - - Funcd_Dbrent funcd = new Funcd_Dbrent(); - Dbrent dbr = new Dbrent(); - for (i=0;i sbeps); - } - - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Dbrent: Identified minimum is not a zero of the function derivative"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - class Funcd_Dbrent implements UniValRealValueFunWithDiff{ - Bessjy b = new Bessjy(); - public double funk (final double x) { - return b.j0(x); - } - public double df(final double x) { - return -b.j1(x); - } - }; -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Frprmn.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Frprmn.java deleted file mode 100644 index 57d5c9e444..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Frprmn.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.nr.test.test_chapter10; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.RealValueFunWithDiff; -import com.nr.min.Frprmn; -import com.nr.sf.Bessjy; - -public class Test_Frprmn { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=20; - double theta,phi,f0,f,d0,d,pi=acos(-1.0); - double sbeps1=1.0e-7,sbeps2=5.0e-16; - double[] p = new double[3]; - boolean localflag=false, globalflag=false; - - - - // Test Frprmn - System.out.println("Testing Frprmn"); - - Funcd_Frprmn fd = new Funcd_Frprmn(); - Frprmn frprmn = new Frprmn(fd); - p[0]=p[1]=p[2]=0.1; - p=frprmn.minimize(p); - f0=frprmn.fret; - d0=sqrt(SQR(p[0])+SQR(p[1])+SQR(p[2])); - - for (i=0;i sbeps1; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Frprmn: First minimum of radial function reported at different radius for different starting points"); - - } - - localflag = localflag || abs(f-f0) > sbeps2; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Frprmn: Reported function value at first minimum is different for different starting points"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Funcd_Frprmn implements RealValueFunWithDiff{ - Bessjy b = new Bessjy(); - double u; - public double funk (double[] x) { - return(b.j0(sqrt(SQR(x[0])+SQR(x[1])+SQR(x[2])))); - } - public void df(double[] x, double[] deriv) { - u=sqrt(SQR(x[0])+SQR(x[1])+SQR(x[2])); - deriv[0]= -x[0]*b.j1(u)/u; - deriv[1]= -x[1]*b.j1(u)/u; - deriv[2]= -x[2]*b.j1(u)/u; - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Golden.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Golden.java deleted file mode 100644 index 419888750a..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Golden.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.nr.test.test_chapter10; - -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.min.Golden; -import com.nr.sf.Bessjy; - -public class Test_Golden implements UniVarRealValueFun{ - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=50; - double a,b,min,span=1.0,sbeps=1.0e-7; - boolean localflag=false, globalflag=false; - - - - // Test Golden - System.out.println("Testing Golden"); - - Golden gold = new Golden(); - for (i=0;i sbeps); - } - - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Golden: Identified minimum is not a zero of the function derivative"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - public double funk(final double x) { - return Bessj0_Golden(x); - } - double Bessj0_Golden(final double x) { - Bessjy b = new Bessjy();; - return(b.j0(x)); - } - - double Bessj1_Golden(final double x) { - Bessjy b = new Bessjy(); - return(b.j1(x)); - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Linemethod.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Linemethod.java deleted file mode 100644 index 936a4f4ab8..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Linemethod.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.nr.test.test_chapter10; - -import static com.nr.NRUtil.SQR; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.cos; -import static java.lang.Math.sin; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.RealValueFun; -import com.nr.min.Linemethod; -import com.nr.sf.Bessjy; - -public class Test_Linemethod implements RealValueFun{ - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=20; - double theta,phi,f0,f,d0,d,pi=acos(-1.0); - double sbeps1=5.0e-8,sbeps2=1.0e-15; - double[] p=new double[3],xi=new double[3]; - boolean localflag=false, globalflag=false; - - - - // Test Linemethod - System.out.println("Testing Linemethod"); - Linemethod line=new Linemethod(this); - - p[0]=p[1]=p[2]=0.0; - xi[0]=1.0; - xi[1]=xi[2]=0.0; - line.p=p; - line.xi=xi; - f0=line.linmin(); - d0=sqrt(SQR(line.p[0])+SQR(line.p[1])+SQR(line.p[2])); - - for (i=0;i sbeps1; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Linemethod: First minimum of radial function reported at different radius for different xi[]"); - - } - - localflag = localflag || abs(f-f0) > sbeps2; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Linemethod: Reported function value at first minimum is different for different xi[i]"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - public double funk(final double[] x) { - Bessjy b = new Bessjy(); - return(b.j0(sqrt(SQR(x[0])+SQR(x[1])+SQR(x[2])))); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Powell.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Powell.java deleted file mode 100644 index cec929c8b0..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_Powell.java +++ /dev/null @@ -1,123 +0,0 @@ -package com.nr.test.test_chapter10; - -import static com.nr.NRUtil.SQR; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.cos; -import static java.lang.Math.sin; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.RealValueFun; -import com.nr.min.Powell; -import com.nr.sf.Bessjy; - -public class Test_Powell implements RealValueFun { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=20; - double theta,phi,f0,f,d0,d,pi=acos(-1.0); - double sbeps1=5.0e-8,sbeps2=1.0e-15; - double[] p=new double[3]; - double[][] ximat = new double[3][3]; - boolean localflag=false, globalflag=false; - - - - // Test Powell - System.out.println("Testing Powell, interface1"); - - Powell pow1 = new Powell(this); - p[0]=p[1]=p[2]=0.0; - p=pow1.minimize(p); - f0=pow1.fret; - d0=sqrt(SQR(p[0])+SQR(p[1])+SQR(p[2])); - - for (i=0;i sbeps1; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Powell, interface1: First minimum of radial function reported at different radius for different starting points"); - - } - - localflag = localflag || abs(f-f0) > sbeps2; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Powell, interface1: Reported function value at first minimum is different for different starting points"); - - } - } - - System.out.println("Testing Powell, interface2"); - Powell pow2 = new Powell(this); - for (i=0;i sbeps1; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Powell, interface2: First minimum of radial function reported at different radius for different xi[]"); - - } - - localflag = localflag || abs(f-f0) > sbeps2; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Powell, interface2: Reported function value at first minimum is different for different xi[i]"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - public double funk(double[] x) { - return Bessj0_Powell(x); - } - - double Bessj0_Powell(double[] x) { - Bessjy b = new Bessjy(); - return(b.j0(sqrt(SQR(x[0])+SQR(x[1])+SQR(x[2])))); - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_dfpmin.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_dfpmin.java deleted file mode 100644 index 3df0a435a9..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_dfpmin.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.nr.test.test_chapter10; -import static com.nr.NRUtil.SQR; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.cos; -import static java.lang.Math.sin; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; -import org.netlib.util.intW; - -import com.nr.RealValueFunWithDiff; -import com.nr.min.QuasiNewton; -import com.nr.sf.Bessjy; - -public class Test_dfpmin { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=20; - intW iter = new intW(0); - doubleW f0=new doubleW(0),f=new doubleW(0); - double theta,phi,d0,d,pi=acos(-1.0); - double sbeps1=5.0e-8,sbeps2=5.0e-16,gtol=5.0e-8; - double[] p = new double[3]; - boolean localflag=false, globalflag=false; - - - - // Test dfpmin - System.out.println("Testing dfpmin"); - - Funcd_dfpmin fd = new Funcd_dfpmin(); - p[0]=p[1]=p[2]=0.5; - QuasiNewton.dfpmin(p,gtol,iter,f0,fd); - d0=sqrt(SQR(p[0])+SQR(p[1])+SQR(p[2])); - - for (i=0;i sbeps1; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** dfpmin: First minimum of radial function reported at different radius for different starting points"); - - } - - localflag = localflag || abs(f.val-f0.val) > sbeps2; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** dfpmin: Reported function value at first minimum is different for different starting points"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - class Funcd_dfpmin implements RealValueFunWithDiff{ - Bessjy b = new Bessjy(); - double u; - public double funk (double[] x) { - return(b.j0(sqrt(SQR(x[0])+SQR(x[1])+SQR(x[2])))); - } - public void df(double[] x, double[] deriv) { - u=sqrt(SQR(x[0])+SQR(x[1])+SQR(x[2])); - deriv[0]= -x[0]*b.j1(u)/u; - deriv[1]= -x[1]*b.j1(u)/u; - deriv[2]= -x[2]*b.j1(u)/u; - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_dynpro.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_dynpro.java deleted file mode 100644 index 46825e2b3f..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_dynpro.java +++ /dev/null @@ -1,129 +0,0 @@ -package com.nr.test.test_chapter10; - -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.min.Dynpro; -import com.nr.ran.Ran; - -public class Test_dynpro { - Ran myran=new Ran(17); - Penalty pen = new Penalty(); - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,k,m,n,NSTAGE=6,NTRIAL=10; - double test0,test1,testmin,sbeps; - int[] nstate=new int[NSTAGE],path=new int[NSTAGE]; - boolean localflag, globalflag=false; - - - - // Test dynpro - System.out.println("Testing dynpro"); - - int[] v; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** dynpro: Calculated cost in exhaustive search was lower"); - - } - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - public double cost(int j, int k, int i){ - return pen.c[j][k][i]; - } - - class Penalty { - double[][][] c = new double[10][10][6]; - - Penalty() { - fillmatrix(); - } - - void fillmatrix() { - int i,j,k; - for (i=0;i<10;i++) - for (j=0;j<10;j++) - for (k=0;k<6;k++) - c[i][j][k]=myran.doub(); - } - - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_fdfunc.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_fdfunc.java deleted file mode 100644 index a2eedf73a0..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_fdfunc.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.nr.test.test_chapter10; - -import static com.nr.NRUtil.SQR; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.cos; -import static java.lang.Math.sin; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; -import org.netlib.util.intW; - -import com.nr.RealValueFun; -import com.nr.min.Funcd; -import com.nr.min.QuasiNewton; -import com.nr.sf.Bessjy; - -public class Test_fdfunc implements RealValueFun{ - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=20; - intW iter = new intW(0); - doubleW f0=new doubleW(0),f=new doubleW(0); - double theta,phi,d0,d,pi=acos(-1.0); - double sbeps1=5.0e-8,sbeps2=5.0e-16,gtol=1.0e-8; - double[] p=new double[3]; - boolean localflag=false, globalflag=false; - - - - // Test fdfunc - System.out.println("Testing fdfunc"); - - Funcd fd = new Funcd(this); - p[0]=p[1]=p[2]=0.5; - QuasiNewton.dfpmin(p,gtol,iter,f0,fd); - d0=sqrt(SQR(p[0])+SQR(p[1])+SQR(p[2])); - - for (i=0;i sbeps1; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** fdfunc: First minimum of radial function reported at different radius for different starting points"); - - } - - localflag = localflag || abs(f.val-f0.val) > sbeps2; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** fdfunc: Reported function value at first minimum is different for different starting points"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - public double funk(final double[] x) { - Bessjy b=new Bessjy(); - return(b.j0(sqrt(SQR(x[0])+SQR(x[1])+SQR(x[2])))); - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_stringalign.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_stringalign.java deleted file mode 100644 index 7740b7c1d6..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter10/Test_stringalign.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.nr.test.test_chapter10; - -import static com.nr.min.StringAlign.stringalign; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Ran; - -public class Test_stringalign { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,k,N1=100,N2=64; - char protein[]={'A','C','T','G'}; - char[] string1,string2,string3,aout,bout,summary; - boolean localflag, globalflag=false; - - - - // Test stringalign - System.out.println("Testing stringalign"); - - string1=new char[N1+1]; - string2=new char[N2+1]; - string3=new char[N2+1]; - string1[N1]='\0'; - string2[N2]='\0'; - string3[N2]='\0'; - - Ran myran = new Ran(17); - for (i=0;i sbeps); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** pearsn: Probability modified when arrays swapped"); - - } - - localflag = (abs(z2.val-z1.val) > sbeps); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** pearsn: Fisher's z modified when arrays swapped"); - - } - - localflag = (abs(z2.val-0.5*log((1+r2.val)/(1-r2.val)))) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** pearsn: Fisher's z not compatible with correlation coefficient"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_quadct.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_quadct.java deleted file mode 100644 index 98acdb5129..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_quadct.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.nr.test.test_chapter14; - -import static com.nr.stat.Stattests.quadct; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -import com.nr.ran.Ran; - -public class Test_quadct { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=8192; - doubleW fa=new doubleW(0),fb = new doubleW(0); - doubleW fc = new doubleW(0),fd = new doubleW(0); - double x=0.5,y=0.5; - double ffa=0.25/4.0,ffb=0.25*3.0/4.0,ffc=0.25*9.0/4.0,ffd=0.25*3.0/4.0; - double[] xx=new double[N],yy=new double[N]; - boolean localflag=false,globalflag=false; - - - - // Test quadct - System.out.println("Testing quadct"); - - Ran myran=new Ran(17); - j=0; - for (i=0;i 0.02) || (abs(fb.val-ffb) > 0.02) || (abs(fc.val-ffc) > 0.02) || (abs(fd.val-ffd) > 0.02); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** quadct: Fractions do not agree adequately with uniform distribution"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_quadvl.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_quadvl.java deleted file mode 100644 index 6d37f886b8..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_quadvl.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.nr.test.test_chapter14; - -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -import com.nr.ran.Ran; -import com.nr.stat.Quadvl; - -public class Test_quadvl { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,NTRIES=100; - doubleW faW=new doubleW(0),fbW = new doubleW(0); - doubleW fcW = new doubleW(0),fdW = new doubleW(0); - double x,y,fa,fb,fc,fd,sbeps; - boolean localflag,globalflag=false; - - - - // Test quadvl - System.out.println("Testing quadvl"); - - Ran myran = new Ran(16); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** quadvl: Sum of reported fractions is not 1.0"); - - } - - localflag = abs(fa-0.25*(1.0-x)*(1.0-y)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** quadvl: Quadrant 1 reporting wrong fraction"); - - } - - localflag = abs(fb-0.25*(x+1.0)*(1.0-y)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** quadvl: Quadrant 2 reporting wrong fraction"); - - } - - localflag = abs(fc-0.25*(x+1.0)*(y+1.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** quadvl: Sum of reported fractions is not 1.0"); - - } - - localflag = abs(fd-0.25*(1.0-x)*(y+1.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** quadvl: Sum of reported fractions is not 1.0"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_savgol.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_savgol.java deleted file mode 100644 index f3db6dc8bb..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_savgol.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.nr.test.test_chapter14; - -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import java.util.Scanner; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.stat.SavitzkyGolayFilter; - -public class Test_savgol { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int NMAX=1000,NTEST=6; - int mtest[]={2,2,2,2,4,4}; - int nltest[]={2,3,4,5,4,5}; - int nrtest[]={2,1,0,5,4,5}; - String ans[]={ - " -0.086 0.343 0.486 0.343 -0.086", - " -0.143 0.171 0.343 0.371 0.257", - " 0.086 -0.143 -0.086 0.257 0.886", - " -0.084 0.021 0.103 0.161 0.196 0.207 0.196 0.161 0.103 0.021 -0.084", - " 0.035 -0.128 0.070 0.315 0.417 0.315 0.070 -0.128 0.035", - " 0.042 -0.105 -0.023 0.140 0.280 0.333 0.280 0.140 -0.023 -0.105 0.042"}; - int i,j,m,nl,np,nr; - double sum,sbeps; - double[] c=new double[NMAX]; - boolean localflag,globalflag=false; - - - - // Test savgol - System.out.println("Testing savgol"); - - // Test against table from the book - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** savgol: Sum of coefficients was not 1.0 for case "+ i); - - } - - Scanner sc = new Scanner(ans[i]); - localflag=false; - sbeps=1.e-3; - double r; - for (j=nl;j>=0;j--) { - r = sc.nextDouble(); -// System.out.printf(c[j] << " %f\n", w << " %f\n", abs(c[j]-atof(w.c_str()))); - localflag = localflag || abs(c[j]-r) > sbeps; - } - for (j=0;j sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** savgol: Computed coefficients do not agree with book for case "+ i); - - } - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_spear.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_spear.java deleted file mode 100644 index 1d14c92a39..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_spear.java +++ /dev/null @@ -1,239 +0,0 @@ -package com.nr.test.test_chapter14; - -import static com.nr.NRUtil.buildVector; -import static com.nr.stat.Stattests.spear; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -public class Test_spear { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - doubleW d1=new doubleW(0),zd1 = new doubleW(0),probd1 = new doubleW(0); - doubleW rs1=new doubleW(0),probrs1 = new doubleW(0); - doubleW d2=new doubleW(0),zd2 = new doubleW(0),probd2 = new doubleW(0); - doubleW rs2=new doubleW(0),probrs2 = new doubleW(0); - - double sbeps=1.e-6; - double adata[]={0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0}; - double bdata[]={9.0,8.0,7.0,6.0,5.0,4.0,3.0,2.0,1.0,0.0}; - double cdata[]={1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,0.0}; // Note 0.0 at end - double edata[]={1.0,2.0,1.0,2.0,1.0,2.0,1.0,2.0,1.0,2.0}; - double fdata[]={2.0,1.0,2.0,1.0,2.0,1.0,2.0,1.0,2.0,1.0}; - // Expected results for each test case - double ae[]={0.0,-3.0,0.0026998,1.0,0.0}; - double be[]={330.0,3.0,0.0026998,-1.0,0.0}; - double ce[]={90.0,-1.363636,0.172682,0.454545,0.186905}; - double ee[]={250.0,3.0,0.0026998,-1.0,0.0}; - double[] a=buildVector(adata),b=buildVector(bdata),c=buildVector(cdata); - double[] e=buildVector(edata),f=buildVector(fdata); - boolean localflag=false,globalflag=false; - - - - // Test spear - System.out.println("Testing spear"); - - // Test 1 - spear(a,a,d1,zd1,probd1,rs1,probrs1); -// System.out.printf(d1 << " %f\n", zd1 << " %f\n", probd1 << " %f\n", rs1 << " %f\n", probrs1); - localflag = localflag || (d1.val != ae[0]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Squared difference of ranks not zero for identical distributions"); - - } - - localflag = localflag || (zd1.val != ae[1]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Unexpected standard deviation (should be -3) for special case"); - - } - - localflag = localflag || abs(probd1.val-ae[2]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Unexpected probability for d, given the standard deviation"); - - } - - localflag = localflag || (rs1.val != ae[3]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Spearman's rank correlation should be 1 for identical distributions"); - - } - - localflag = localflag || (probrs1.val != ae[4]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Probrs should be zero for identical distributions"); - - } - - // Test 2 - spear(a,b,d1,zd1,probd1,rs1,probrs1); -// System.out.printf(d1 << " %f\n", zd1 << " %f\n", probd1 << " %f\n", rs1 << " %f\n", probrs1); - localflag = localflag || (d1.val != be[0]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Sum squared difference of ranks should be 2*(81+49+25+9+1)=330"); - - } - - localflag = localflag || (zd1.val != be[1]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Standard deviation should be (330/55)-3=3"); - - } - - localflag = localflag || abs(probd1.val-be[2]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Unexpected probability for d, given the standard deviation"); - - } - - localflag = localflag || (rs1.val != be[3]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Spearman's rank correlation should be -1 for perfect anticorrelation"); - - } - - localflag = localflag || abs(probrs1.val - be[4])>1.e-16; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Probrs should be zero for perfect anticorrelation"); - - } - - // Test 3 - spear(b,a,d2,zd2,probd2,rs2,probrs2); -// System.out.printf(d2 << " %f\n", zd2 << " %f\n", probd2 << " %f\n", rs2 << " %f\n", probrs2); - localflag = localflag || (d1.val != d2.val) || (zd1.val != zd2.val) || - (probd1.val != probd2.val) || (rs1.val != rs2.val) || (probrs1.val != probrs2.val); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Results changed when two arrays were swapped (case 1)"); - - } - - // Test 4 - spear(a,c,d1,zd1,probd1,rs1,probrs1); -// System.out.printf(d1 << " %f\n", zd1 << " %f\n", probd1 << " %f\n", rs1 << " %f\n", probrs1); - localflag = localflag || (d1.val != ce[0]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Sum squared difference of ranks should be 9*(1^2)+1*(9^2)=90"); - - } - - localflag = localflag || abs(zd1.val-ce[1]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Standard deviation should be (90/55)-3=-1.363636"); - - } - - localflag = localflag || abs(probd1.val-ce[2]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Unexpected probability for d, given the standard deviation"); - - } - - localflag = localflag || abs(rs1.val-ce[3]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Spearman's rank correlation should be 1-6*90/990=0.454545"); - - } - - localflag = localflag || abs(probrs1.val-ce[4]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Unexpected probability for rs, given the rank correlation"); - - } - - // Test 5 - spear(c,a,d2,zd2,probd2,rs2,probrs2); -// System.out.printf(d2 << " %f\n", zd2 << " %f\n", probd2 << " %f\n", rs2 << " %f\n", probrs2); - localflag = localflag || (d1.val != d2.val) || (zd1.val != zd2.val) || - (probd1.val != probd2.val) || (rs1.val != rs2.val) || (probrs1.val != probrs2.val); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Results changed when two arrays were swapped (case 2)"); - - } - - // Test 6 - spear(e,f,d1,zd1,probd1,rs1,probrs1); -// System.out.printf(d1 << " %f\n", zd1 << " %f\n", probd1 << " %f\n", rs1 << " %f\n", probrs1); - localflag = localflag || (d1.val != ee[0]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Sum squared difference of ranks should be 10*(8-3)^2=250"); - - } - - localflag = localflag || (zd1.val != ee[1]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Standard deviation should be (250-125)/55/(1-240/990)=3"); - - } - - localflag = localflag || abs(probd1.val-ee[2]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Unexpected probability for d, given the standard deviation"); - - } - - localflag = localflag || (rs1.val != ee[3]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Spearman's rank correlation should be -1 for perfect anticorrelation (case 2)"); - - } - - localflag = localflag || (probrs1.val != ee[4]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Probrs should be zero for perfect anticorrelation (case 2)"); - - } - - // Test 7 - spear(f,e,d2,zd2,probd2,rs2,probrs2); -// System.out.printf(d2 << " %f\n", zd2 << " %f\n", probd2 << " %f\n", rs2 << " %f\n", probrs2); - localflag = localflag || (d1.val != d2.val) || (zd1.val != zd2.val) || - (probd1.val != probd2.val) || (rs1.val != rs2.val) || (probrs1.val != probrs2.val); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** spear: Results changed when two arrays were swapped (case 3)"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_tptest.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_tptest.java deleted file mode 100644 index 6e55294ae9..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_tptest.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.nr.test.test_chapter14; - -import static com.nr.NRUtil.buildVector; -import static com.nr.stat.Moment.avevar; -import static com.nr.stat.Stattests.tptest; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -import com.nr.ran.Normaldev; - -public class Test_tptest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,NPTS=10000,NSHFT=10; - doubleW ave1=new doubleW(0),ave2 = new doubleW(0); - doubleW var1 = new doubleW(0), var2 = new doubleW(0); - double cov,sd,EPS=0.01,sbeps; - double fingerprint[]={0.012206481763442537,0.044962205835956524, - 0.13262719786074151,0.31606378510286803,0.61616056459021917, - 1.0,0.61616056459021917,0.31606378510286803,0.13262719786074151, - 0.044962205835956524,0.012206481763442537}; - double[] data1=new double[NPTS],data2=new double[NPTS]; - double[] t=new double[NSHFT+1],prob=new double[NSHFT+1],texpect= new double[NSHFT+1]; - double[] fp=buildVector(fingerprint); - boolean localflag=false,globalflag=false; - - - - // Test tptest - System.out.println("Testing tptest"); - - Normaldev ndev = new Normaldev(0.0,1.0,17); - // Generate identical data but with a shift - for (j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** tptest: Incorrect returned values for Student's t"); - - } - - sbeps=1.e-15; - localflag=false; - for (i=1;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** tptest: Probabilities unsymmetrical for symmetrical shifts"); - - } - - //Fingerprint test - sbeps=3.e-12; - localflag = maxel(vecsub(prob,fp)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** tptest: Probabilities do not match fingerprint"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_ttest.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_ttest.java deleted file mode 100644 index d920acf636..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_ttest.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.nr.test.test_chapter14; - -import static com.nr.stat.Moment.avevar; -import static com.nr.stat.Stattests.ttest; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -import com.nr.ran.Normaldev; - -public class Test_ttest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j; - int NPTS=10000,NSHFT=10; - doubleW ave1=new doubleW(0),ave2 = new doubleW(0); - doubleW var1 = new doubleW(0), var2 = new doubleW(0); - double sd,EPS=0.005,sbeps; - double fingerprint[]={0.076341,0.156226,0.287591,0.478354,0.722981, - 1.0,0.722981,0.478354,0.287591,0.156226,0.076341}; - double[] data1=new double[NPTS],data2=new double[NPTS]; - double[] t=new double[NSHFT+1],prob=new double[NSHFT+1],tt= new double[NSHFT+1]; - boolean localflag=false, globalflag=false; - - - - // Test ttest - System.out.println("Testing ttest"); - - // Generate gaussian distributed data - Normaldev ndev=new Normaldev(0.0,1.0,17); - // Special case: identical distributions - for (i=0;i sbeps); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ttest: Returned t statistic incorrect for special case of identical distributions"); - - } - - for (i=0;i<=NSHFT/2;i++) - localflag = localflag || abs(t[i]+t[NSHFT-i]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ttest: Returned t statistic has incorrect symmetry"); - - } - - sbeps=1.e-6; - for (i=0;isbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ttest: Return probabilities don't match fingerprint"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_tutest.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_tutest.java deleted file mode 100644 index aeb8fec4a7..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter14/Test_tutest.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.nr.test.test_chapter14; - -import static com.nr.stat.Moment.avevar; -import static com.nr.stat.Stattests.tutest; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -import com.nr.ran.Normaldev; - -public class Test_tutest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,NPTS=10000,NSHFT=10; - doubleW ave1=new doubleW(0),ave2 = new doubleW(0); - doubleW var1 = new doubleW(0), var2 = new doubleW(0); - double EPS=0.01,sd,sbeps; - double fingerprint[]={0.024980,0.072904,0.178591,0.369851,0.653879, - 1.0,0.653879,0.369851,0.178591,0.072904,0.024980}; - double[] data1=new double[NPTS],data2=new double[NPTS]; - double[] t=new double[NSHFT+1],prob=new double[NSHFT+1],tt= new double[NSHFT+1]; - boolean localflag=false,globalflag=false; - - - - // Test tutest - System.out.println("Testing tutest"); - - // Generate two gaussian distributions of different variance - Normaldev ndev = new Normaldev(0.0,1.0,17); - for (i=0;i sbeps); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** tutest: Returned t statistic incorrect for special case of scaled distributions"); - - } - - for (i=0;i<=NSHFT/2;i++) - localflag = localflag || abs(t[i]+t[NSHFT-i]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** tutest: Returned t statistic has incorrect symmetry"); - - } - - sbeps=1.e-6; - for (i=0;isbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** tutest: Return probabilities don't match fingerprint"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter15/Test_Fitab.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter15/Test_Fitab.java deleted file mode 100644 index 7d956158ed..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter15/Test_Fitab.java +++ /dev/null @@ -1,183 +0,0 @@ -package com.nr.test.test_chapter15; - -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.model.Fitab; -import com.nr.ran.Normaldev; -import com.nr.ran.Ran; -public class Test_Fitab { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=100,M=10; - double pi=acos(-1.0),sumx2,sa=0,sb=0,sbeps; - double[] x= new double[N],y= new double[N],yy= new double[N],sig= new double[N]; - boolean localflag, globalflag=false; - - - - // Test Fitab - System.out.println("Testing Fitab"); - - Ran myran =new Ran(17); - sumx2=0; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitab: Fitted constant term a has incorrect value"); - - } - - localflag = abs(fit1.b-pi) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitab: Fitted slope b has incorrect value"); - - } - - localflag = fit1.chi2 > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitab: Chi^2 not zero for perfect linear data"); - - } - - localflag = abs(fit1.q-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitab: Probability not 1.0 for perfect linear data"); - - } - - localflag = abs(fit1.siga/fit1.sigb - sqrt(sumx2/N)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitab: Ratio of siga/sigb incorrect for special case"); - - } - - // Test 2 - for (j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitab,Test2: Fitted constant term a has incorrect value"); - - } - - localflag = abs(fit.b-pi) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitab,Test2: Fitted slope b has incorrect value"); - - } - - localflag = fit.chi2 > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitab,Test2: Chi^2 not zero for perfect linear data"); - - } - - localflag = abs(fit.q-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitab,Test2: Probability not 1.0 for perfect linear data"); - - } - - if (j == 0) { - sa=fit.siga; - sb=fit.sigb; - } else { - localflag = (fit.siga/sa - (j+1)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitab,Test2: siga did not scale properly with data errors"); - - } - - localflag = (fit.sigb/sb - (j+1)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitab,Test2: sigb did not scale properly with data errors"); - - } - } - } - - // Test 3 - Normaldev ndev=new Normaldev(0.0,1.0,17); - for (j=0;j 3.0*fit3.siga; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitab,Test3: Fitted constant term a, or error siga, may be incorrect"); - - } - - localflag = abs(fit3.b-pi) > 3.0*fit3.sigb; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitab,Test3: Fitted slope b, or error sigb, may be incorrect"); - - } - - localflag = fit3.chi2 > 1.3*N; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitab,Test3: Chi^2 is unexpectedly high"); - - } - - localflag = abs(fit3.q) < 0.1; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitab,Test3: Probability q suggests a possibly bad fit"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter15/Test_Fitexy.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter15/Test_Fitexy.java deleted file mode 100644 index 9d28014955..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter15/Test_Fitexy.java +++ /dev/null @@ -1,242 +0,0 @@ -package com.nr.test.test_chapter15; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import com.nr.ran.*; -import com.nr.model.*; - -public class Test_Fitexy { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=100,M=10; - double pi=acos(-1.0),sumx2,sa=0,sb=0,sbeps; - double[] x= new double[N],y= new double[N],yy= new double[N],sigx= new double[N],sigy= new double[N]; - boolean localflag, globalflag=false; - - - - // Test Fitexy - System.out.println("Testing Fitexy"); - - Ran myran=new Ran(17); - sumx2=0; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy: Fitted constant term a has incorrect value"); - - } - - localflag = abs(fit1.b-pi) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy: Fitted slope b has incorrect value"); - - } - - localflag = fit1.chi2 > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy: Chi^2 not zero for perfect linear data"); - - } - - localflag = abs(fit1.q-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy: Probability not 1.0 for perfect linear data"); - - } - -// System.out.printf(fit1.siga/fit1.sigb << " %f\n", sqrt(sumx2/N)); - localflag = abs(fit1.siga/fit1.sigb - sqrt(sumx2/N)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy: Ratio of siga/sigb incorrect for special case"); - - } - - // Test 2 - for (j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy,Test2: Fitted constant term a has incorrect value"); - - } - - localflag = abs(fit.b-pi) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy,Test2: Fitted slope b has incorrect value"); - - } - - localflag = fit.chi2 > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy,Test2: Chi^2 not zero for perfect linear data"); - - } - - localflag = abs(fit.q-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy,Test2: Probability not 1.0 for perfect linear data"); - - } - - if (j == 0) { - sa=fit.siga; - sb=fit.sigb; - } else { - localflag = (fit.siga/sa - (j+1)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy,Test2: siga did not scale properly with data errors"); - - } - - // System.out.printf(fit.sigb/sb << " %f\n", j+1); - localflag = (fit.sigb/sb - (j+1)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy,Test2: sigb did not scale properly with data errors"); - - } - } - } - - // Test 3 - for (j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy,Test3: Fitted constant term a has incorrect value"); - - } - - localflag = abs(fit.b-pi) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy,Test3: Fitted slope b has incorrect value"); - - } - - localflag = fit.chi2 > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy,Test3: Chi^2 not zero for perfect linear data"); - - } - - localflag = abs(fit.q-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy,Test3: Probability not 1.0 for perfect linear data"); - - } - - if (j == 0) { - sa=fit.siga; - sb=fit.sigb; - } else { - localflag = (fit.siga/sa - (j+1)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy,Test3: siga did not scale properly with data errors"); - - } - - // System.out.printf(fit.sigb/sb << " %f\n", j+1); - localflag = (fit.sigb/sb - (j+1)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy,Test3: sigb did not scale properly with data errors"); - - } - } - } - - // Test 4 - Normaldev ndev=new Normaldev(0.0,1.0,17); - for (j=0;j 3.0*fit4.siga; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy,Test4: Fitted constant term a, or error siga, may be incorrect"); - - } - - localflag = abs(fit4.b-pi) > 3.0*fit4.sigb; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy,Test4: Fitted slope b, or error sigb, may be incorrect"); - - } - - localflag = fit4.chi2 > 1.3*N; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy,Test4: Chi^2 is unexpectedly high"); - - } - - localflag = abs(fit4.q) < 0.1; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitexy,Test4: Probability q suggests a possibly bad fit"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter15/Test_Fitlin.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter15/Test_Fitlin.java deleted file mode 100644 index b2a28c06c5..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter15/Test_Fitlin.java +++ /dev/null @@ -1,232 +0,0 @@ -package com.nr.test.test_chapter15; - -import static java.lang.Math.abs; -import static java.lang.Math.sin; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealMultiValueFun; -import com.nr.model.Fitlin; -import com.nr.ran.Normaldev; -public class Test_Fitlin implements UniVarRealMultiValueFun{ - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,ma,N=100; - double stdev,amp[]={1.0,0.1,1.0,0.3,0.1}; - double[] x=new double[N],y= new double[N],sig= new double[N]; - boolean localflag, globalflag=false; - - - - // Test Fitlin - System.out.println("Testing Fitlin"); - - double[] f=Fitlin_funcs(x[0]); - ma=f.length; - stdev=0.02; - Normaldev ndev=new Normaldev(0.0,stdev,17); - - for (i=0;i 2.0*sqrt(myfit.covar[j][j]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitlin: Fitted parameters not within estimated uncertainty"); - - } - } - -// System.out.printf(fixed << setprecision(6); -// for (i=0;i 2.0*sqrt(myfit.covar[j][j]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitlin: Fitted parameters (with 2 parameters held) not within estimated uncertainty"); - - } - } - - localflag=false; - for (i=0;i 2.0*sqrt(myfit.covar[j][j]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitlin: Fitted parameter (with 1 parameters held) not within estimated uncertainty"); - - } - } - - localflag=false; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitmed: Fitted constant term a has incorrect value"); - - } - - localflag = abs(fit1.b-pi) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitmed: Fitted slope b has incorrect value"); - - } - - localflag = fit1.abdev > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitmed: abdev not zero for perfect linear data"); - - } - - // Test 2 - for (j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitmed,Test2: Fitted constant term a is incorrect"); - - } - - sbeps=5.e-5; - localflag = abs(fit2.b-(pi+0.1*j/M/x[N-1])) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitmed,Test2: Fitted slope b is incorrect"); - - } - - localflag = fit2.abdev > 0.05; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitmed,Test2: Calculated abdev is too high"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter15/Test_Fitmrq.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter15/Test_Fitmrq.java deleted file mode 100644 index 6fd566482a..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter15/Test_Fitmrq.java +++ /dev/null @@ -1,214 +0,0 @@ -package com.nr.test.test_chapter15; - -import static com.nr.NRUtil.SQR; -import static com.nr.NRUtil.buildVector; -import static java.lang.Math.abs; -import static java.lang.Math.exp; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.model.FGauss; -import com.nr.model.Fitmrq; -import com.nr.ran.Normaldev; - -public class Test_Fitmrq { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=100,MA=6; - double aa[]={5.0,2.0,3.0,2.0,5.0,3.0}; - double gguess[]={4.5,2.2,2.8,2.5,4.9,2.8}; - double SPREAD=0.01; - double[] x= new double[N],y= new double[N],sig= new double[N]; - double[] a=buildVector(aa),guess=buildVector(gguess); - boolean localflag, globalflag=false; - - - - // Test Fitmrq - System.out.println("Testing Fitmrq"); - - Normaldev ndev=new Normaldev(0.0,1.0,17); - // First try a sum of two Gaussians - for (i=0;i 2.0*sqrt(myfit.covar[j][j]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitmrq: Fitted parameters not within estimated uncertainty"); - - } - } - - // Test the hold() method on parameters 1 and 4 - myfit.hold(1,2.0); - myfit.hold(4,5.0); - myfit.fit(); - -// System.out.printf(setw(18) << "chi-squared:%f\n", setw(13) << myfit.chisq); -// for (i=0;i 2.0*sqrt(myfit.covar[j][j]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitmrq: Fitted parameters (with 2 parameters held) not within estimated uncertainty"); - - } - } - - localflag=false; - for (i=0;i 2.0*sqrt(myfit.covar[j][j]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitlin: Fitted parameter (with 1 parameters held) not within estimated uncertainty"); - - } - } - - localflag=false; - for (i=0;i 2.0*sqrt(mysvdfit.covar[j][j]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitsvd: Fitted parameters not within estimated uncertainty"); - - } - } - - Fitlin mylinfit = new Fitlin(x,y,sig,this); - mylinfit.fit(); - sbeps=TOL; - for (j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitsvd: SVD fit does not agree with Fitlin on parameters"); - - } - - localflag = abs(sqrt(mysvdfit.covar[j][j])-sqrt(mylinfit.covar[j][j])) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fitsvd: SVD fit does not agree with Fitlin on uncertainties"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - public double[] funk(final double x) { - return Fitsvd_funcs(x); - } - - double[] Fitsvd_funcs(final double x) { - int i; - double[] ans=new double[5]; - - ans[0]=1.0; - ans[1]=x; - for (i=2;i<5;i++) ans[i]=sin((i-1)*x); - return ans; - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter15/Test_fleg.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter15/Test_fleg.java deleted file mode 100644 index e6e32e460d..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter15/Test_fleg.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.nr.test.test_chapter15; - -import static java.lang.Math.abs; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealMultiValueFun; -import com.nr.model.Fitsvd; -import com.nr.ran.Normaldev; -public class Test_fleg implements UniVarRealMultiValueFun{ - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=100; - double stdev,TOL=1.e-12; - double amp[]={1.0,2.0,3.0,2.0,1.0,0.0,0.0,0.0,0.0,0.0}; - double[] x= new double[N],y= new double[N],sig= new double[N]; - boolean localflag, globalflag=false; - - - - // Test fleg - System.out.println("Testing fleg"); - - stdev=1.e-3; - double[] f=fleg(x[0]); - int NP=f.length; - Normaldev ndev = new Normaldev(0.0,stdev,17); - - for (i=0;i 2.0*sqrt(myfit.covar[j][j]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** fleg: Fitted parameters not within estimated uncertainty"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - public double[] funk(final double x) { - return fleg(x); - } - - double[] fleg(final double x) { - final int fleg_nl = 10; - - int j; - double twox,f2,f1,d; - double[] pl =new double[fleg_nl]; - pl[0]=1.; - pl[1]=x; - if (fleg_nl > 2) { - twox=2.*x; - f2=x; - d=1.; - for (j=2;j 2.0*sqrt(myfit.covar[j][j]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** fpoly: Fitted parameters not within estimated uncertainty"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - public double[] funk(final double x) { - return fpoly(x); - } - - double[] fpoly(final double x) { - final int fpoly_np=10; - int j; - double[] p=new double[fpoly_np]; - p[0]=1.0; - for (j=1;j 0.05; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** mcmc: Model parameter lambda1 was not correctly determined"); - - } - - localflag = abs(lam2ave-lambda2)/lambda2 > 0.05; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** mcmc: Model parameter lambda2 was not correctly determined"); - - } - - localflag = kk1 != k1; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** mcmc: Model parameter k1 was not correctly determined"); - - } - - localflag = kk2 != k2; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** mcmc: Model parameter k2 was not correctly determined"); - - } - - localflag = abs(tcave-tc)/tc > 0.01; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** mcmc: Critical time tc was not accurately determined"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Gaumixmod.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Gaumixmod.java deleted file mode 100644 index 457b0127e9..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Gaumixmod.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.nr.test.test_chapter16; - -import static com.nr.NRUtil.SQR; -import static com.nr.NRUtil.*; -import static com.nr.test.NRTestUtil.*; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ci.Gaumixmod; -import com.nr.ran.Normaldev; - -public class Test_Gaumixmod { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,k,NDIM=2,NMEANS=4,NPT=1000; - double flag=0,sqrt2=sqrt(2.0),d0,d1,sbeps; - double ffrac[]={0.25,0.25,0.25,0.25}; - double mmeans[]={0.0,0.0,0.75,0.0,-0.25,-0.25,0.33,0.66}; - double gguess[]={0.1,0.1,0.7,0.1,-0.2,-0.3,0.3,0.5}; - double ssigma[]={0.1,0.1,0.02,0.2,0.01,0.1,0.1,0.05}; - double vvec1[]={1.0,0.0,1.0,0.0,sqrt2,sqrt2,sqrt2,sqrt2}; - double vvec2[]={0.0,1.0,0.0,1.0,-sqrt2,sqrt2,-sqrt2,sqrt2}; - double[] frac=buildVector(ffrac),offset = new double[NMEANS]; - double[][] guess=buildMatrix(NMEANS,NDIM,gguess); - double[][] means=buildMatrix(NMEANS,NDIM,mmeans),sigma=buildMatrix(NMEANS,NDIM,ssigma); - double[][] vec1=buildMatrix(NMEANS,NDIM,vvec1),vec2=buildMatrix(NMEANS,NDIM,vvec2),x=new double[NPT][NDIM]; - boolean localflag, globalflag=false; - - - - // Test Gaumixmod - System.out.println("Testing Gaumixmod"); - - Normaldev ndev=new Normaldev(0.0,1.0,17); - - // Generate four groups of data - k=0; - for (i=0;i<4;i++) { - for (j=0;j<(int)(NPT*frac[i]);j++) { - d0=sigma[i][0]*ndev.dev(); - d1=sigma[i][1]*ndev.dev(); - x[k][0]=means[i][0]+d0*vec1[i][0]+d1*vec2[i][0]; - x[k][1]=means[i][1]+d0*vec1[i][1]+d1*vec2[i][1]; - k++; - } - } - - Gaumixmod gmix = new Gaumixmod(x,guess); - - for (i=0;i<100;i++) { - flag=gmix.estep(); - if (flag < 1.e-6) break; - gmix.mstep(); - } - - // check for convergence - // System.out.println(" flag: %f\n", flag); - localflag = flag > 1.e-6; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gaumixmod: No solution with 100 iterations"); - - } - - // Check for correct determination of population fractions - // System.out.printf(maxel(vecsub(gmix.frac,frac))); - sbeps=0.005; - localflag = maxel(vecsub(gmix.frac,frac)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gaumixmod: Population fractions not accurately determined"); - - } - - // Check for correct determination of means - for (i=0;i 0.01; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gaumixmod: Means are incorrectly identified"); - - } - - // Check for correct determination of covariance matrices - for (i=0;i test) { - test=hmm.pstate[i][j]; - jmax=j; - } - } -// System.out.printf(state[i] << " %f\n", jmax); - if (jmax == state[i]) ncorrect++; - } - System.out.printf("Fraction correct: %f\n", (double)(ncorrect)/N); - localflag = (double)(ncorrect)/N < 0.75; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** HMM: Actual state was not the top probability more than 25% of the time"); - - } - - // Inspect reconstructed transition matrix - int jpen=0; - ncorrect=0; - for (i=0;i test) { - test=hmm.pstate[i][j]; - jmax=j; - } - } - - // Find second largest - test=0.0; - for (j=0;j test) { - test=hmm.pstate[i][j]; - jpen=j; - } - } - } - -// System.out.printf(state[i] << " %f\n", jmax); - if (jmax == state[i] || jpen == state[i]) ncorrect++; - } - System.out.printf("Fraction correct: %f\n", (double)(ncorrect)/N); - double beforeBW=(double)(ncorrect)/N; - localflag = (double)(ncorrect)/N < 0.95; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** HMM: Actual state was not in top 2 probabilities more than 5% of the time"); - - } - -// System.out.println("Log-likelihood: %f\n", hmm.loglikelihood()); - - // Test Baum-Welch reestimation - for (i=0;i<100;i++) { - hmm.baumwelch(); - hmm.forwardbackward(); -// System.out.println("Log-likelihood: %f\n", hmm.loglikelihood()); - } - - // Inspect reconstructed transition matrix - ncorrect=0; - for (i=0;i test) { - test=hmm.pstate[i][j]; - jmax=j; - } - } - - // Find second largest - test=0.0; - for (j=0;j test) { - test=hmm.pstate[i][j]; - jpen=j; - } - } - } - -// System.out.printf(state[i] << " %f\n", jmax); - if (jmax == state[i] || jpen == state[i]) ncorrect++; - } - System.out.printf("Fraction correct after Baum-Welch: %f\n", (double)(ncorrect)/N); - double afterBW=(double)(ncorrect)/N; - localflag = afterBW <= beforeBW; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** HMM: Baum-Welch reestimation did not improve model"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Kmeans.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Kmeans.java deleted file mode 100644 index 33c87a127d..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Kmeans.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.nr.test.test_chapter16; - -import static com.nr.NRUtil.SQR; -import static com.nr.NRUtil.buildMatrix; -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ci.Kmeans; -import com.nr.ran.Normaldev; - -public class Test_Kmeans { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,k,flag=0,NDIM=2,NMEANS=4,NPT=1000; - double sqrt2=sqrt(2.0),d0,d1,sbeps; - double ffrac[]={0.25,0.25,0.25,0.25}; - double mmeans[]={0.0,0.0,0.75,0.0,-0.25,-0.25,0.33,0.66}; - double gguess[]={0.1,0.1,0.7,0.1,-0.2,-0.3,0.3,0.5}; - double ssigma[]={0.1,0.1,0.02,0.2,0.01,0.1,0.1,0.05}; - double vvec1[]={1.0,0.0,1.0,0.0,sqrt2,sqrt2,sqrt2,sqrt2}; - double vvec2[]={0.0,1.0,0.0,1.0,-sqrt2,sqrt2,-sqrt2,sqrt2}; - int[] count=new int[NMEANS],error=new int[NMEANS]; - double[] frac=buildVector(ffrac),offset=new double[NMEANS]; - double[][] guess=buildMatrix(NMEANS,NDIM,gguess); - double[][] means=buildMatrix(NMEANS,NDIM,mmeans),sigma=buildMatrix(NMEANS,NDIM,ssigma); - double[][] vec1=buildMatrix(NMEANS,NDIM,vvec1),vec2=buildMatrix(NMEANS,NDIM,vvec2),x=new double[NPT][NDIM]; - boolean localflag, globalflag=false; - - - - // Test Kmeans - System.out.println("Testing Kmeans"); - - Normaldev ndev = new Normaldev(0.0,1.0,17); - - // Generate four groups of data - k=0; - for (i=0;i<4;i++) { - count[i]=(int)(NPT*frac[i]); - for (j=0;j 0; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Kmeans: No solution with 100 iterations"); - - } - - // Check for correct populations -// for (i=0;i 0 ? error[i] : -error[i]) > 15; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Kmeans: Populations are not the correct approximate size"); - - } - } - - // Check group assignments - k=0; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Kmeans: Means are incorrectly identified"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Phylo_clc.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Phylo_clc.java deleted file mode 100644 index eee1e013fe..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Phylo_clc.java +++ /dev/null @@ -1,194 +0,0 @@ -package com.nr.test.test_chapter16; - -import static com.nr.NRUtil.buildMatrix; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ci.Phylo_clc; - -public class Test_Phylo_clc { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,k,hamming,mother,ndif,NSEQ=16,NCHAR=16; - double sbeps=1.e-15; - // char base[]={'C','G','T','A'}; - int ssequence[]={ - 3,1,1,1,1,1,1,1,0,1,1,1,1,1,2,2, - 3,1,1,1,1,1,1,1,0,1,1,1,1,1,2,3, - 3,0,1,1,1,1,1,1,0,1,1,1,1,1,3,1, - 3,3,1,1,1,1,1,1,0,1,1,1,1,1,3,1, - 3,1,1,1,2,1,1,1,2,1,1,3,1,1,1,1, - 3,1,1,1,0,1,1,1,2,1,1,3,1,1,1,1, - 3,1,1,1,1,1,1,1,2,2,1,0,1,1,1,1, - 3,1,1,1,1,1,1,1,2,0,1,0,1,1,1,1, - 2,1,1,0,1,1,3,1,1,1,1,1,3,1,1,1, - 2,1,1,0,1,1,3,1,1,1,1,1,2,1,1,1, - 2,1,1,0,1,1,0,1,1,1,0,1,1,1,1,1, - 2,1,1,0,1,1,0,1,1,1,3,1,1,1,1,1, - 2,1,3,2,1,1,1,0,1,1,1,1,1,1,1,1, - 2,1,0,2,1,1,1,0,1,1,1,1,1,1,1,1, - 2,1,1,2,1,3,1,3,1,1,1,1,1,1,1,1, - 2,1,1,2,1,0,1,3,1,1,1,1,1,1,1,1 - }; - int[][] sequence = buildMatrix(NSEQ,NCHAR,ssequence); - double[][] dist=new double[NSEQ][NSEQ]; - boolean localflag, globalflag=false; - - - - // Test Phylo_clc - System.out.println("Testing Phylo_clc"); - - // Printout sequences for testing -// for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_clc: Hamming distance between two daughters is not twice the mother distance"); - - } - } - -// System.out.println("Tree:"); -// print_tree(tree,tree.root); - -// System.out.println("Check expected order of leafs on tree:"); - Check_tree ct = new Check_tree(tree); - ct.test(tree.root); - - localflag = ct.flag; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_clc: Leaves of the tree were not encountered in the expected order"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - - } - class Check_tree { - int i; - boolean flag; - Phylo_clc tree; - - Check_tree(Phylo_clc ttree) { - tree = ttree; - i=0; - flag = false; - } - void test(int node) { - if (tree.t[node].ldau != -1) { - test(tree.t[node].ldau); - } else { - flag = flag || (node != i++); -// System.out.printf(node << " %f\n", flag); - return; - } - - if (tree.t[node].rdau != -1) { - test(tree.t[node].rdau); - } else { - flag = flag || (node != i++); -// System.out.printf(node << " %f\n", flag); - return; - } - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Phylo_nj.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Phylo_nj.java deleted file mode 100644 index 56887b0563..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Phylo_nj.java +++ /dev/null @@ -1,294 +0,0 @@ -package com.nr.test.test_chapter16; - -import static com.nr.NRUtil.buildMatrix; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import java.io.IOException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ci.Phylagglom; -import com.nr.ci.Phylo_nj; -public class Test_Phylo_nj { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() throws IOException { - int i,j,k,hamming,mother,ndif,NSEQ=16,NCHAR=16; - double sbeps=1.e-15; - char base[]={'C','G','T','A'}; - int ssequence[]={ - 3,1,1,1,1,1,1,1,0,1,1,1,1,1,2,2, - 3,1,1,1,1,1,1,1,0,1,1,1,1,1,2,3, - 3,0,1,1,1,1,1,1,0,1,1,1,1,1,3,1, - 3,3,1,1,1,1,1,1,0,1,1,1,1,1,3,1, - 3,1,1,1,2,1,1,1,2,1,1,3,1,1,1,1, - 3,1,1,1,0,1,1,1,2,1,1,3,1,1,1,1, - 3,1,1,1,1,1,1,1,2,2,1,0,1,1,1,1, - 3,1,1,1,1,1,1,1,2,0,1,0,1,1,1,1, - 2,1,1,0,1,1,3,1,1,1,1,1,3,1,1,1, - 2,1,1,0,1,1,3,1,1,1,1,1,2,1,1,1, - 2,1,1,0,1,1,0,1,1,1,0,1,1,1,1,1, - 2,1,1,0,1,1,0,1,1,1,3,1,1,1,1,1, - 2,1,3,2,1,1,1,0,1,1,1,1,1,1,1,1, - 2,1,0,2,1,1,1,0,1,1,1,1,1,1,1,1, - 2,1,1,2,1,3,1,3,1,1,1,1,1,1,1,1, - 2,1,1,2,1,0,1,3,1,1,1,1,1,1,1,1 - }; - char[][] str=new char[NSEQ][NCHAR+1]; - int[][] sequence=buildMatrix(NSEQ,NCHAR,ssequence); - double[][] dist=new double[NSEQ][NSEQ]; - boolean localflag, globalflag=false; - - - - // Test Phylo_nj - System.out.println("Testing Phylo_nj"); - - // Printout sequences used for the test -// for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_nj: Mother distances should be 0.5 for all leaves"); - - } - } - - localflag = abs(tree.t[29].modist) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_nj: Mother distances of node 29 should be zero"); - - } - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_nj: Distance of two daughters is not the sum of the mother distances"); - - } - } - -// System.out.println("Tree:"); -// print_tree(tree,tree.root); - -// System.out.println("Check expected order of leaves on tree:"); - Check_tree ct=new Check_tree(tree); - ct.test(tree.root); - - localflag = ct.flag; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_nj: Leaves of the tree were not encountered in the expected order"); - - } - - i=tree.comancestor(0,7); -// System.out.println("Common ancestor of 0,7: %f\n", i); - Phylo_nj rerootedtree=new Phylo_nj(dist,i); - -// System.out.println("Rerooted Tree:"); -// print_tree(rerootedtree,rerootedtree.root); - - // System.out.println("parents"); -// for (i=0;i<30;i++) { -// System.out.printf(i << " %f\n", rerootedtree.t[i].mo); -// } - - // Inspect the tree - localflag = (rerootedtree.t[rerootedtree.root].nel != NSEQ); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_nj: Root node does not contain all the elements"); - - } - -// System.out.printf(rerootedtree.t[rerootedtree.t[rerootedtree.root].ldau].nel); - localflag = (rerootedtree.t[rerootedtree.t[rerootedtree.root].ldau].nel != NSEQ/2); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_nj: Left side of rerooted tree does not report half the elements"); - - } - -// System.out.printf(rerootedtree.t[rerootedtree.t[rerootedtree.root].rdau].nel); - localflag = (rerootedtree.t[rerootedtree.t[rerootedtree.root].rdau].nel != NSEQ/2); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_nj: Right side of rerooted tree does not report half the elements"); - - } - - localflag = (rerootedtree.t[rerootedtree.root].modist != 0.0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_nj: Mother distance of root is not zero"); - - } - - // Tree is now symmetric - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_nj: Left and right daughter of a node reported different mother distances"); - - } - - localflag = abs(rerootedtree.t[i].modist-0.5) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_nj: Mother distance should be 0.5 for all leaves"); - - } - - ndif=0; - for (j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_nj: Distance of two daughters is not twice the mother distance"); - - } - } - - for (i=0;i<2*NSEQ-2;i++) { - localflag = abs(rerootedtree.t[rerootedtree.t[rerootedtree.t[i].mo].ldau].modist- - rerootedtree.t[rerootedtree.t[rerootedtree.t[i].mo].rdau].modist) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_nj: Left and right daughter of a node reported different mother distances"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - class Check_tree { - int i; - boolean flag; - Phylo_nj tree; - - Check_tree(Phylo_nj ttree) { - tree = ttree; - i=0; - flag=false; - } - - void test(int node) { - if (tree.t[node].ldau != -1) { - test(tree.t[node].ldau); - } else { - flag = flag || (node != i++); -// System.out.printf(node << " %f\n", flag); - return; - } - - if (tree.t[node].rdau != -1) { - test(tree.t[node].rdau); - } else { - flag = flag || (node != i++); -// System.out.printf(node << " %f\n", flag); - return; - } - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Phylo_slc.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Phylo_slc.java deleted file mode 100644 index ca9f21443f..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Phylo_slc.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.nr.test.test_chapter16; - -import static com.nr.NRUtil.buildMatrix; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ci.Phylo_slc; - -public class Test_Phylo_slc { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,k,hamming,mother,ndif,NSEQ=16,NCHAR=16; - double sbeps=1.e-15; - // char base[]={'C','G','T','A'}; - int ssequence[]={ - 3,1,1,1,1,1,1,1,0,1,1,1,1,1,2,2, - 3,1,1,1,1,1,1,1,0,1,1,1,1,1,2,3, - 3,0,1,1,1,1,1,1,0,1,1,1,1,1,3,1, - 3,3,1,1,1,1,1,1,0,1,1,1,1,1,3,1, - 3,1,1,1,2,1,1,1,2,1,1,3,1,1,1,1, - 3,1,1,1,0,1,1,1,2,1,1,3,1,1,1,1, - 3,1,1,1,1,1,1,1,2,2,1,0,1,1,1,1, - 3,1,1,1,1,1,1,1,2,0,1,0,1,1,1,1, - 2,1,1,0,1,1,3,1,1,1,1,1,3,1,1,1, - 2,1,1,0,1,1,3,1,1,1,1,1,2,1,1,1, - 2,1,1,0,1,1,0,1,1,1,0,1,1,1,1,1, - 2,1,1,0,1,1,0,1,1,1,3,1,1,1,1,1, - 2,1,3,2,1,1,1,0,1,1,1,1,1,1,1,1, - 2,1,0,2,1,1,1,0,1,1,1,1,1,1,1,1, - 2,1,1,2,1,3,1,3,1,1,1,1,1,1,1,1, - 2,1,1,2,1,0,1,3,1,1,1,1,1,1,1,1 - }; - int[][] sequence=buildMatrix(NSEQ,NCHAR,ssequence); - double[][] dist=new double[NSEQ][NSEQ]; - boolean localflag, globalflag=false; - - - - // Test Phylo_slc - System.out.println("Testing Phylo_slc"); - - // Printout sequences for testing -// for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_slc: Hamming distance between two daughters is not twice the mother distance"); - - } - } - -// System.out.println("Tree:"); -// print_tree(tree,tree.root); - -// System.out.println("Check expected order of leafs on tree:"); - Check_tree ct=new Check_tree(tree); - ct.test(tree.root); - - localflag = ct.flag; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_slc: Leaves of the tree were not encountered in the expected order"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - class Check_tree { - int i; - boolean flag; - Phylo_slc tree; - - Check_tree(Phylo_slc ttree) { - tree=ttree; - i=0; - flag=false; - } - void test(int node) { - if (tree.t[node].ldau != -1) { - test(tree.t[node].ldau); - } else { - flag = flag || (node != i++); -// System.out.printf(node << " %f\n", flag); - return; - } - - if (tree.t[node].rdau != -1) { - test(tree.t[node].rdau); - } else { - flag = flag || (node != i++); -// System.out.printf(node << " %f\n", flag); - return; - } - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Phylo_upgma.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Phylo_upgma.java deleted file mode 100644 index 18525d4dd2..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Phylo_upgma.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.nr.test.test_chapter16; - -import static com.nr.NRUtil.buildMatrix; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ci.Phylo_upgma; - -public class Test_Phylo_upgma { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,k,hamming,mother,ndif,NSEQ=16,NCHAR=16; - double sbeps=1.e-15; - // char base[]={'C','G','T','A'}; - int ssequence[]={ - 3,1,1,1,1,1,1,1,0,1,1,1,1,1,2,2, - 3,1,1,1,1,1,1,1,0,1,1,1,1,1,2,3, - 3,0,1,1,1,1,1,1,0,1,1,1,1,1,3,1, - 3,3,1,1,1,1,1,1,0,1,1,1,1,1,3,1, - 3,1,1,1,2,1,1,1,2,1,1,3,1,1,1,1, - 3,1,1,1,0,1,1,1,2,1,1,3,1,1,1,1, - 3,1,1,1,1,1,1,1,2,2,1,0,1,1,1,1, - 3,1,1,1,1,1,1,1,2,0,1,0,1,1,1,1, - 2,1,1,0,1,1,3,1,1,1,1,1,3,1,1,1, - 2,1,1,0,1,1,3,1,1,1,1,1,2,1,1,1, - 2,1,1,0,1,1,0,1,1,1,0,1,1,1,1,1, - 2,1,1,0,1,1,0,1,1,1,3,1,1,1,1,1, - 2,1,3,2,1,1,1,0,1,1,1,1,1,1,1,1, - 2,1,0,2,1,1,1,0,1,1,1,1,1,1,1,1, - 2,1,1,2,1,3,1,3,1,1,1,1,1,1,1,1, - 2,1,1,2,1,0,1,3,1,1,1,1,1,1,1,1 - }; - int[][] sequence=buildMatrix(NSEQ,NCHAR,ssequence); - double[][] dist=new double[NSEQ][NSEQ]; - boolean localflag, globalflag=false; - - - - // Test Phylo_upgma - System.out.println("Testing Phylo_upgma"); - - // Printout sequences for testing -// for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_upgma: Hamming distance between two daughters is not twice the mother distance"); - - } - } - -// System.out.println("Tree:"); -// print_tree(tree,tree.root); - -// System.out.println("Check expected order of leaves on tree:"); - Check_tree ct=new Check_tree(tree); - ct.test(tree.root); - - localflag = ct.flag; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_upgma: Leaves of the tree were not encountered in the expected order"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - class Check_tree { - int i; - boolean flag; - Phylo_upgma tree; - - Check_tree(Phylo_upgma ttree) { - tree=ttree; - i=0; - flag=false; - } - void test(int node) { - if (tree.t[node].ldau != -1) { - test(tree.t[node].ldau); - } else { - flag = flag || (node != i++); -// System.out.printf(node << " %f\n", flag); - return; - } - - if (tree.t[node].rdau != -1) { - test(tree.t[node].rdau); - } else { - flag = flag || (node != i++); -// System.out.printf(node << " %f\n", flag); - return; - } - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Phylo_wpgma.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Phylo_wpgma.java deleted file mode 100644 index 159e489129..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Phylo_wpgma.java +++ /dev/null @@ -1,194 +0,0 @@ -package com.nr.test.test_chapter16; - -import static com.nr.NRUtil.buildMatrix; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ci.Phylo_wpgma; - -public class Test_Phylo_wpgma { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,k,hamming,mother,ndif,NSEQ=16,NCHAR=16; - double sbeps=1.e-15; - // char base[]={'C','G','T','A'}; - int ssequence[]={ - 3,1,1,1,1,1,1,1,0,1,1,1,1,1,2,2, - 3,1,1,1,1,1,1,1,0,1,1,1,1,1,2,3, - 3,0,1,1,1,1,1,1,0,1,1,1,1,1,3,1, - 3,3,1,1,1,1,1,1,0,1,1,1,1,1,3,1, - 3,1,1,1,2,1,1,1,2,1,1,3,1,1,1,1, - 3,1,1,1,0,1,1,1,2,1,1,3,1,1,1,1, - 3,1,1,1,1,1,1,1,2,2,1,0,1,1,1,1, - 3,1,1,1,1,1,1,1,2,0,1,0,1,1,1,1, - 2,1,1,0,1,1,3,1,1,1,1,1,3,1,1,1, - 2,1,1,0,1,1,3,1,1,1,1,1,2,1,1,1, - 2,1,1,0,1,1,0,1,1,1,0,1,1,1,1,1, - 2,1,1,0,1,1,0,1,1,1,3,1,1,1,1,1, - 2,1,3,2,1,1,1,0,1,1,1,1,1,1,1,1, - 2,1,0,2,1,1,1,0,1,1,1,1,1,1,1,1, - 2,1,1,2,1,3,1,3,1,1,1,1,1,1,1,1, - 2,1,1,2,1,0,1,3,1,1,1,1,1,1,1,1 - }; - int[][] sequence=buildMatrix(NSEQ,NCHAR,ssequence); - double[][] dist=new double[NSEQ][NSEQ]; - boolean localflag, globalflag=false; - - - - // Test Phylo_wpgma - System.out.println("Testing Phylo_wpgma"); - - // Printout sequences for testing -// for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_wpgma: Hamming distance between two daughters is not twice the mother distance"); - - } - } - -// System.out.println("Tree:"); -// print_tree(tree,tree.root); - -// System.out.println("Check expected order of leafs on tree:"); - Check_tree ct=new Check_tree(tree); - ct.test(tree.root); - - localflag = ct.flag; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Phylo_wpgma: Leaves of the tree were not encountered in the expected order"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Check_tree { - int i; - boolean flag; - Phylo_wpgma tree; - - Check_tree(Phylo_wpgma ttree){ - tree=ttree; - i=0; - flag=false; - } - void test(int node) { - if (tree.t[node].ldau != -1) { - test(tree.t[node].ldau); - } else { - flag = flag || (node != i++); -// System.out.printf(node << " %f\n", flag); - return; - } - - if (tree.t[node].rdau != -1) { - test(tree.t[node].rdau); - } else { - flag = flag || (node != i++); -// System.out.printf(node << " %f\n", flag); - return; - } - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Svm.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Svm.java deleted file mode 100644 index aff409be82..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_Svm.java +++ /dev/null @@ -1,285 +0,0 @@ -package com.nr.test.test_chapter16; - -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ci.Svm; -import com.nr.ci.Svmgausskernel; -import com.nr.ci.Svmlinkernel; -import com.nr.ci.Svmpolykernel; -import com.nr.ran.Normaldev; -import com.nr.ran.Ran; - -public class Test_Svm { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,k,M=1000,N=2; - double a,b,lambda,omega=1.3,test,yy; - double[]x=new double[2]; - double[] y=new double[M]; - double[][] data=new double[M][N]; - boolean localflag, globalflag=false; - - - - // Test Svm - System.out.println("Testing Svm"); - - // Create two disjoint sets of points - Ran myran=new Ran(17); - for (i=0;i 1.e-3 && k < 100); - int nerror=0; - for (i=0;i= 1.0)); -// if ((y[i] == 1.0) != (linsvm.predict(i) >= 1.0)) -// System.out.printf(data[i][0] << " %f\n", data[i][1] << " %f\n", y[i] << " %f\n", linsvm.predict(i)); - nerror += ((y[i]==1.0) != (linsvm.predict(i) >= 0.0) ? 1 : 0); - } - System.out.printf("Errors: %d\n", nerror); - - // Polynomial kernel - Svmpolykernel polykernel=new Svmpolykernel(data,y,1.0,1.0,2.0); - Svm polysvm=new Svm(polykernel); - lambda=10; - k=0; - do { - test=polysvm.relax(lambda,omega); -// System.out.printf(test); - k++; - } while (test > 1.e-3 && k < 100); - nerror=0; - for (i=0;i= 0.0) ? 1 : 0); - } - System.out.printf("Errors: %d\n", nerror); - - // Gaussian kernel - Svmgausskernel gausskernel=new Svmgausskernel(data,y,1.0); - Svm gausssvm=new Svm(gausskernel); - lambda=10; - k=0; - do { - test=gausssvm.relax(lambda,omega); -// System.out.printf(test); - k++; - } while (test > 1.e-3 && k < 100); - nerror=0; - for (i=0;i= 0.0) ? 1 : 0); - } - System.out.printf("Errors: %d\n", nerror); - - - // Need to add tests for harder test case and resolve issue that the two - // support vectors give an erroneous indication for two of the kernels above - - // Example similar to the book - Normaldev ndev=new Normaldev(0.0,0.5,17); - for (j=0;j<4;j++) { // Four quadrants - for (i=0;i 1.e-3 && k < 100); - nerror=0; - for (i=0;i= 0.0) ? 1 : 0); - } - System.out.printf("%d ",nerror); - // Test new data - nerror=0; - for (j=0;j<4;j++) { // Four quadrants - for (i=0;i= 0.0) ? 1 : 0); - } - } - System.out.printf("%d ",nerror); - } - System.out.println(); - - // Polynomial kernel - Svmpolykernel polykernel2 = new Svmpolykernel(data,y,1.0,1.0,4.0); - Svm polysvm2=new Svm(polykernel2); - System.out.printf("Errors: "); - for (lambda=0.001;lambda<10000;lambda *= 10) { - k=0; - do { - test=polysvm2.relax(lambda,omega); -// System.out.printf(test); - k++; - } while (test > 1.e-3 && k < 100); - // Test training set - nerror=0; - for (i=0;i= 0.0) ? 1 : 0); - } - System.out.printf("%d ",nerror); - // Test new data - nerror=0; - for (j=0;j<4;j++) { // Four quadrants - for (i=0;i= 0.0) ? 1 : 0); - } - } - System.out.printf("%d ",nerror); - } - System.out.println(); - - // Gaussian kernel - Svmgausskernel gausskernel2=new Svmgausskernel(data,y,1.0); - Svm gausssvm2=new Svm(gausskernel2); - System.out.printf("Errors: "); - for (lambda=0.001;lambda<10000;lambda *= 10) { - k=0; - do { - test=gausssvm2.relax(lambda,omega); -// System.out.printf(test); - k++; - } while (test > 1.e-3 && k < 100); - nerror=0; - for (i=0;i= 0.0) ? 1 : 0); - } - System.out.printf("%d ",nerror); - // Test new data - nerror=0; - for (j=0;j<4;j++) { // Four quadrants - for (i=0;i= 0.0) ? 1 : 0); - } - } - System.out.printf("%d ",nerror); - } - System.out.println(); - - // Test the algorithm on test data after learning - // Do a scan over lambda to find best value - - localflag = false; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Svm: *************************"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_markovgen.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_markovgen.java deleted file mode 100644 index 98dfd9707c..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter16/Test_markovgen.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.nr.test.test_chapter16; - -import static com.nr.NRUtil.buildMatrix; -import static com.nr.test.NRTestUtil.matsub; -import static com.nr.test.NRTestUtil.maxel; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ci.HMM; - -public class Test_markovgen { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=10000,M=5; - double sbeps,aatrans[]={ - 0.0,0.7,0.1,0.0,0.2, - 0.2,0.4,0.0,0.2,0.2, - 0.0,1.0,0.0,0.0,0.0, - 0.0,0.3,0.0,0.7,0.0, - 0.1,0.1,0.0,0.0,0.8 - }; - int[] state=new int[N]; - double[][] atrans=buildMatrix(M,M,aatrans); - boolean localflag, globalflag=false; - - - - // Test markovgen - System.out.println("Testing markovgen"); - - HMM.markovgen(atrans,state,0,17); - -// for (i=0;i<10;i++) { -// for (j=0;j<10;j++) -// System.out.printf(state[10*i+j] << " "; -// System.out.printf(endl; -// } -// System.out.printf(endl; - - // Measure the transition probabilities in the result - int[][] measure=new int[M][M]; - int[] ntimes=new int[M]; - for (i=1;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** markovgen: Transistion probabilities don't agree with specification"); - - } - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** StepperBS: Inaccurate integration"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class rhs_StepperBS implements DerivativeInf { - public void derivs(final double x,double[] y,double[] dydx) { - dydx[0]= -y[1]; - dydx[1]=y[0]-(1.0/x)*y[1]; - dydx[2]=y[1]-(2.0/x)*y[2]; - dydx[3]=y[2]-(3.0/x)*y[3]; - } - public void jacobian(final double x, double[] y, double[] dfdx, double[][] dfdy){} - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter17/Test_StepperDopr5.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter17/Test_StepperDopr5.java deleted file mode 100644 index 141591a3de..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter17/Test_StepperDopr5.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.nr.test.test_chapter17; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ode.DerivativeInf; -import com.nr.ode.Odeint; -import com.nr.ode.Output; -import com.nr.ode.StepperDopr5; -import com.nr.sf.Bessjy; - -public class Test_StepperDopr5 { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,nvar=4; - final double atol=1.0e-6,rtol=atol,h1=0.01,hmin=0.0,x1=1.0,x2=2.0; - double sbeps; - //dydx= new double[nvar] - double[] y= new double[nvar],yout= new double[nvar],yexp= new double[nvar]; - boolean localflag, globalflag=false; - - - - // Test StepperDopr5 - System.out.println("Testing StepperDopr5"); - - Bessjy bess = new Bessjy(); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** StepperDopr5: Inaccurate integration"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class rhs_StepperDopr5 implements DerivativeInf { - public void derivs (final double x, final double[] y, final double[]dydx) { - dydx[0]= -y[1]; - dydx[1]=y[0]-(1.0/x)*y[1]; - dydx[2]=y[1]-(2.0/x)*y[2]; - dydx[3]=y[2]-(3.0/x)*y[3]; - } - public void jacobian(final double x, double[] y, double[] dfdx, double[][] dfdy){} - - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter17/Test_StepperDopr853.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter17/Test_StepperDopr853.java deleted file mode 100644 index 0b2ad78ca2..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter17/Test_StepperDopr853.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.nr.test.test_chapter17; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ode.DerivativeInf; -import com.nr.ode.Odeint; -import com.nr.ode.Output; -import com.nr.ode.StepperDopr853; -import com.nr.sf.Bessjy; - -public class Test_StepperDopr853 { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,nvar=4; - final double atol=1.0e-6,rtol=atol,h1=0.01,hmin=0.0,x1=1.0,x2=2.0; - double sbeps; - // dydx= new double[nvar], - double[] y= new double[nvar],yout= new double[nvar],yexp= new double[nvar]; - boolean localflag, globalflag=false; - - - - // Test StepperDopr853 - System.out.println("Testing StepperDopr853"); - - Bessjy bess = new Bessjy(); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** StepperDopr853: Inaccurate integration"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - class rhs_StepperDopr853 implements DerivativeInf{ - public void derivs(final double x,double[] y,double[] dydx) { - dydx[0]= -y[1]; - dydx[1]=y[0]-(1.0/x)*y[1]; - dydx[2]=y[1]-(2.0/x)*y[2]; - dydx[3]=y[2]-(3.0/x)*y[3]; - } - public void jacobian(final double x, double[] y, double[] dfdx, double[][] dfdy){} - - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter17/Test_StepperRoss.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter17/Test_StepperRoss.java deleted file mode 100644 index e456c7801e..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter17/Test_StepperRoss.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.nr.test.test_chapter17; - -import static java.lang.Math.abs; -import static java.lang.Math.exp; -import static java.lang.Math.pow; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ode.DerivativeInf; -import com.nr.ode.Odeint; -import com.nr.ode.Output; -import com.nr.ode.StepperRoss; - -public class Test_StepperRoss { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,nvar=3; - final double atol=1.0e-6,rtol=atol,h1=2.9e-4,hmin=0.0,x1=0.0,x2=50.0; - double sbeps; - //dydx= new double[nvar] - double[] y= new double[nvar],yout= new double[nvar]; - boolean localflag, globalflag=false; - - - - // Test StepperRoss - System.out.println("Testing StepperRoss"); - - y[0]=1.0; y[1]=1.0; y[2]=0.0; - Output out=new Output(20); - rhs_StepperRoss d = new rhs_StepperRoss(); - StepperRoss s = new StepperRoss(); - Odeint ode = new Odeint(y,x1,x2,atol,rtol,h1,hmin,out,d,s); - ode.integrate(); - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** StepperRoss: Inaccurate relationship #1 among y[i] components"); - - } - - System.out.println(abs(yout[1]-pow(yout[0]*exp(0.013*x2),2.5))); - localflag = abs(yout[1]-pow(yout[0]*exp(0.013*x2),2.5)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** StepperRoss: Inaccurate relationship #2 among y[i] components"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class rhs_StepperRoss implements DerivativeInf{ - public void derivs(final double x,double[] y,double[] dydx) { - dydx[0]= -0.013*y[0]-1000.0*y[0]*y[2]; - dydx[1]= -2500.0*y[1]*y[2]; - dydx[2]= -0.013*y[0]-1000.0*y[0]*y[2]-2500.0*y[1]*y[2]; - } - - public void jacobian(final double x,double[] y,double[] dfdx,double[][] dfdy) { - int n=y.length; - for (int i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** StepperSie: Inaccurate relationship #1 among yout[i] components"); - - } - - System.out.println(abs(yout[1]-pow(yout[0]*exp(0.013*x2),2.5))); - localflag = abs(yout[1]-pow(yout[0]*exp(0.013*x2),2.5)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** StepperSie: Inaccurate relationship #2 among y[i] components"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class rhs_StepperSie implements DerivativeInf{ - public void derivs(final double x,double[] y,double[] dydx) { - dydx[0]= -0.013*y[0]-1000.0*y[0]*y[2]; - dydx[1]= -2500.0*y[1]*y[2]; - dydx[2]= -0.013*y[0]-1000.0*y[0]*y[2]-2500.0*y[1]*y[2]; - } - - public void jacobian(final double x,double[] y,double[] dfdx,double[][] dfdy) { - int n=y.length; - for (int i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** StepperStoerm: Inaccurate integration #1"); - - } - - y[0]=1.0/pow(3.0,2.0/3.0)/exp(gammln(2.0/3.0)); // Ai(x) - y[nvar]=-1.0/pow(3.0,1.0/3.0)/exp(gammln(1.0/3.0)); - dydx[0]=0.0; - y[1]=1.0/pow(3.0,1.0/6.0)/exp(gammln(2.0/3.0)); // Bi(x) - y[nvar+1]=pow(3.0,1.0/6.0)/exp(gammln(1.0/3.0)); - dydx[1]=0.0; - - x1=0.0;x2=-1.0; - StepperStoerm s2 = new StepperStoerm(); - Odeint ode2 = new Odeint(y,x1,x2,atol,rtol,h1,hmin,out,d,s2); - ode2.integrate(); - yexp[0]=bess.airy_ai(-1.0); - yexp[1]=bess.airy_bi(-1.0); - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** StepperStoerm: Inaccurate integration #2"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class rhs_StepperStoerm implements DerivativeInf{ - public void derivs(final double x,double[] y,double[] dydx) { - dydx[0]=x*y[0]; - dydx[1]=x*y[1]; - } - public void jacobian(final double x,double[] y,double[] dfdx,double[][] dfdy) {} - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter17/Test_Stochsim.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter17/Test_Stochsim.java deleted file mode 100644 index d9ff2f9965..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter17/Test_Stochsim.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.nr.test.test_chapter17; - -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ode.Stochsim; -public class Test_Stochsim { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,k,NVAR=4,M=420; - double t; - double[] sinit=new double[NVAR],tsav=new double[M/10],smax=new double[NVAR]; - double[][] ssav=new double[M/10][NVAR]; - boolean localflag, globalflag=false; - - - - // Test Stochsim - System.out.println("Testing Stochsim"); - - sinit[0]=150.0; - sinit[1]=10.0; - sinit[2]=10.0; - sinit[3]=0.0; - Stochsim stoch = new Stochsim(sinit); - - for (k=0;k smax[k]) smax[k]=stoch.s[k]; - if (i % 10 == 0) { - j=i/10; - tsav[j]=t; -// System.out.printf(tsav[j]; - for (k=0;k sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rk4: Inaccurate Runge-Kutta step"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - void rk4_derivs(final double x,final double[] y,final double[] dydx) { - dydx[0]= -y[1]; - dydx[1]=y[0]-(1.0/x)*y[1]; - dydx[2]=y[1]-(2.0/x)*y[2]; - dydx[3]=y[2]-(3.0/x)*y[3]; - } - - class RK4_derivs implements DerivativeInf { - public void derivs(final double x, double[] y, double[] dydx){ - rk4_derivs(x,y,dydx); - } - public void jacobian(final double x, double[] y, double[] dfdx, double[][] dfdy){} - } - - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter18/Test_Shoot.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter18/Test_Shoot.java deleted file mode 100644 index 7f93bd2b2a..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter18/Test_Shoot.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.nr.test.test_chapter18; - -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.booleanW; - -import com.nr.bvp.Shoot; -import com.nr.ode.DerivativeInf; -import com.nr.root.Roots; - -public class Test_Shoot { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - booleanW check=new booleanW(false); - int i,j,nvar=3,N2=1; - int n[]={2,2,2,5,5,11,8,10,12}; - int m[]={2,2,2,2,2,4,7,9,11}; - double result=0,dx=1.0e-8; - double c2[]={0.1,1.0,4.0,1.0,16.0,-1.0,0.0,1.0,-1.0}; - double expect[]={6.01426631394,6.14094899057,6.54249527439, - 30.43614538636,36.9962674974,131.560080919, - 72.0000000000,110.130237996,155.888762517}; - double[] v=new double[N2]; - double gmma,q1,x1,x2,sbeps=1.e-10; - boolean localflag, globalflag=false; - - - - // Test Shoot - System.out.println("Testing Shoot"); - - for (j=0;j<9;j++) { - gmma=1.0; - q1=n[j]; - for (i=1;i<=m[j];i++) gmma *= -0.5*(n[j]+i)*(q1--/i); - v[0]=n[j]*(n[j]+1)-m[j]*(m[j]+1)+c2[j]/2.0; - x1= -1.0+dx; - x2=0.0; - final Load load = new Load(n[j],m[j],gmma,c2[j],dx); - Rhs d = new Rhs(m[j],c2[j]); - final Score score = new Score(n[j],m[j]); - Shoot shoot =new Shoot(nvar,x1,x2, d) { - - @Override - public double[] load(double x, double[] v) { - return load.load(x, v); - } - - @Override - public double[] score(double x, double[] v) { - return score.score(x, v); - } - - }; - - //Shoot shoot(nvar,x1,x2,load,d,score); - Roots.newt(v,check,shoot); - if (check.val) { - System.out.println("shoot failed; bad initial guess"); - } else { -// System.out.println(" %f\n", "mu(m,n)"); - result=v[0]+m[j]*(m[j]+1); - System.out.println( result); - } - -// System.out.printf(abs(result/expect[j]-1.0)); - localflag = abs(result/expect[j]-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Shoot: Did not achieve expected accuracy in the eigenvalue"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Rhs implements DerivativeInf{ - int m; - double c2; - - Rhs(final int mm, final double cc2) { - m =mm; - c2 =cc2; - } - public void derivs (final double x, final double[] y, final double[] dydx) - { - dydx[0]=y[1]; - dydx[1]=(2.0*x*(m+1.0)*y[1]-(y[2]-c2*x*x)*y[0])/(1.0-x*x); - dydx[2]=0.0; - } - public void jacobian(final double x, final double[] y, final double[] dfdx, final double[][] dfdy) { - // TODO Auto-generated method stub - - } - } - - class Load { - int n,m; - double gmma,c2,dx; - double[] y; - - Load(final int nn, final int mm, final double gmmaa, double cc2, final double dxx) { - n=nn; - m=mm; - gmma=gmmaa; - c2=cc2; - dx=dxx; - y =new double[3]; - } - - double[] load(final double x1, final double[] v) - { - double y1 = ((n-m & 1) != 0 ? -gmma : gmma); - y[2]=v[0]; - y[1] = -(y[2]-c2)*y1/(2*(m+1)); - y[0]=y1+y[1]*dx; - return y; - } - } - - class Score { - int n,m; - double[] f; - - Score(final int nn,final int mm) { - n=nn; - m=mm; - f=new double[1]; - } - - double[] score(final double xf, final double[] y) - { - f[0]=((n-m & 1) != 0 ? y[0] : y[1]); - return f; - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter18/Test_Shootf.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter18/Test_Shootf.java deleted file mode 100644 index fe1619c11c..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter18/Test_Shootf.java +++ /dev/null @@ -1,176 +0,0 @@ -package com.nr.test.test_chapter18; - -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.booleanW; - -import com.nr.bvp.Shootf; -import com.nr.ode.DerivativeInf; -import com.nr.root.Roots; - -public class Test_Shootf { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - booleanW check=new booleanW(false); - int i,j,N1=2,N2=1,NTOT=N1+N2,nvar=NTOT,n2=N2; - int n[]= {2,2,2,5,5,11,8,10,12}; - int m[]= {2,2,2,2,2,4,7,9,11}; - double c2[]={0.1,1.0,4.0,1.0,16.0,-1.0,0.0,1.0,-1.0}; - double expect[]={6.01426631394,6.14094899057,6.54249527439, - 30.43614538636,36.9962674974,131.560080919, - 72.0000000000,110.130237996,155.888762517}; - double gmma,q1,result=0,dx=1.0e-7,sbeps=1.e-10; - double[] v=new double[NTOT]; - boolean localflag, globalflag=false; - - - - // Test Shootf - System.out.println("Testing Shootf"); - - for (j=0;j<9;j++) { - gmma=1.0; - q1=n[j]; - for (i=1;i<=m[j];i++) gmma *= -0.5*(n[j]+i)*(q1--/i); - v[0]=n[j]*(n[j]+1)-m[j]*(m[j]+1)+c2[j]/2.0; - v[2]=v[0]; - v[1]=gmma*(1.0-(v[2]-c2[j])*dx/(2*(m[j]+1))); - double x1=-1.0+dx; - double x2=1.0-dx; - double xf=0.0; - final Load1 load1 = new Load1(n[j],m[j],gmma,c2[j],dx); - final Load2 load2 =new Load2(m[j],c2[j]); - Rhs d = new Rhs(m[j],c2[j]); - final Score score = new Score(); - Shootf shootf = new Shootf(nvar,n2,x1,x2,xf,d){ - - @Override - public double[] load1(double x, double[] v) { - return load1.load(x,v); - } - - @Override - public double[] load2(double x, double[] v) { - return load2.load(x, v); - } - - @Override - public double[] score(double x, double[] v) { - return score.score(x,v); - } - - }; - Roots.newt(v,check,shootf); - if (check.val) { - System.out.println("shootf failed; bad initial guess"); - } else { -// System.out.println(" %f\n", "mu(m,n)"); - result=v[0]+m[j]*(m[j]+1); - System.out.println( result); - } - -// System.out.printf(abs(result/expect[j]-1.0)); - localflag = abs(result/expect[j]-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Shootf: Did not achieve expected accuracy in the eigenvalue"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Rhs implements DerivativeInf{ - int m; - double c2; - - Rhs(int mm, double cc2) { - m=mm; - c2=cc2; - } - - public void derivs (final double x, double[] y, double[] dydx) - { - dydx[0]=y[1]; - dydx[1]=(2.0*x*(m+1.0)*y[1]-(y[2]-c2*x*x)*y[0])/(1.0-x*x); - dydx[2]=0.0; - } - - public void jacobian(double x, double[] y, double[] dfdx, double[][] dfdy) { - // TODO Auto-generated method stub - - } - } - - class Load1 { - int n,m; - double gmma,c2,dx; - double[] y; - - Load1(int nn, int mm, double gmmaa, double cc2, double dxx){ - n=nn; - m=mm; - gmma=gmmaa; - c2=cc2; - dx=dxx; - y = new double[3]; - } - - public double[] load (final double xx1, double[] v1) - { - double y1 = ((n-m & 1) != 0 ? -gmma : gmma); - y[2]=v1[0]; - y[1] = -(y[2]-c2)*y1/(2*(m+1)); - y[0]=y1+y[1]*dx; - return y; - } - } - - class Load2 { - int m; - double c2; - double[] y; - - Load2(int mm, double cc2) { - m=mm; - c2=cc2; - y=new double[3]; - } - - double[] load (final double x2, double[] v2) - { - y[2]=v2[1]; - y[0]=v2[0]; - y[1]=(y[2]-c2)*y[0]/(2*(m+1)); - return y; - } - } - - class Score { - double[] f; - - Score() { - f=new double[3]; - } - double[] score (final double xf, double[] y) - { - for (int i=0;i<3;i++) f[i]=y[i]; - return f; - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter18/Test_Solvde.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter18/Test_Solvde.java deleted file mode 100644 index 7cba536ef7..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter18/Test_Solvde.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.nr.test.test_chapter18; - -import static com.nr.sf.Legendre.plgndr; -import static java.lang.Math.abs; -import static java.lang.Math.exp; -import static java.lang.Math.log; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.bvp.Difeq; -import com.nr.bvp.Solvde; - -public class Test_Solvde { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int M=100,NE=3,NB=1,NYJ=NE,NYK=M+1; - int i,mpt=M+1,itmax=100; - int n[]={2,2,2,5,5,11,8,10,12}; - int mm[]={2,2,2,2,2,4,7,9,11}; - double anorm,q1,fac1,fac2,deriv,conv=1.0e-15,slowc=1.0; - double h=1.0/M,result,sbeps=1.e-4; - double c2[]={0.1,1.0,4.0,1.0,16.0,-1.0,0.0,1.0,-1.0}; - double expect[]={6.01426631394,6.14094899057,6.54249527439, - 30.43614538636,36.9962674974,131.560080919, - 72.0000000000,110.130237996,155.888762517}; - int[] indexv=new int[NE]; - double[] x=new double[M+1],scalv=new double[NE]; - double[][] y=new double[NYJ][NYK]; - boolean localflag, globalflag=false; - - - - // Test Solvde - System.out.println("Testing Solvde"); - - for (i=0;i<9;i++) { - if ((n[i]+mm[i] & 1) != 0) { - indexv[0]=0; - indexv[1]=1; - indexv[2]=2; - } else { - indexv[0]=1; - indexv[1]=0; - indexv[2]=2; - } - anorm=1.0; - if (mm[i] != 0) { - q1=n[i]; - for (int k=1;k<=mm[i];k++) anorm = -0.5*anorm*(n[i]+k)*(q1--/k); - } - for (int k=0;k scalv[0] ? y[1][M] : scalv[0]); - scalv[2]=(y[2][M] > 1.0 ? y[2][M] : 1.0); - Difeq difeq = new Difeq(mm[i],n[i],mpt,h,c2[i],anorm,x); - new Solvde(itmax,conv,slowc,scalv,indexv,NB,y,difeq); - result=y[2][0]+mm[i]*(mm[i]+1); - System.out.printf(" m = %d n = %d c**2 = %f lamda = %f\n", - mm[i], n[i], c2[i],result); - -// System.out.printf(abs(result/expect[i]-1.0)); - localflag = abs(result/expect[i]-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Solvde: Did not achieve expected accuracy in eigenvalue"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter18/Test_sfroid.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter18/Test_sfroid.java deleted file mode 100644 index 2cadbf170a..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter18/Test_sfroid.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.nr.test.test_chapter18; - -import static java.lang.Math.abs; -import static java.lang.Math.exp; -import static java.lang.Math.log; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.bvp.Difeq; -import com.nr.bvp.Solvde; -import static com.nr.sf.Legendre.*; - -public class Test_sfroid { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - boolean localflag,globalflag=false; - - // Test sfroid - System.out.println("Testing sfroid"); - - localflag = main_sfroid() != 0; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** sfroid : Program did not indicate successful completion"); - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - int main_sfroid() - { - final int M=40,MM=4; - final int NE=3,NB=1,NYJ=NE,NYK=M+1; - int mm=3,n=5,mpt=M+1; - int[] indexv=new int[NE]; - double[] x=new double[M+1],scalv=new double[NE]; - double[][] y=new double[NYJ][NYK]; - int itmax=100; - double c2[]={16.0,20.0,-16.0,-20.0}; - double conv=1.0e-14,slowc=1.0,h=1.0/M; - if ((n+mm & 1) != 0) { - indexv[0]=0; - indexv[1]=1; - indexv[2]=2; - } else { - indexv[0]=1; - indexv[1]=0; - indexv[2]=2; - } - double anorm=1.0; - if (mm != 0) { - double q1=n; - for (int i=1;i<=mm;i++) anorm = -0.5*anorm*(n+i)*(q1--/i); - } - for (int k=0;k scalv[0] ? y[1][M] : scalv[0]); - scalv[2]=(y[2][M] > 1.0 ? y[2][M] : 1.0); - for (int j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fred2: Unexpected or imprecise abscissas"); - - } - - sbeps = 5.0e-6; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fred2: Unexpected or imprecise weights"); - - } - - sbeps = 2.0e-6; - System.out.println(maxel(vecsub(f,fexp))); - localflag = maxel(vecsub(f,fexp)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fred2: Imprecise result from integral equation at Gaussian quadrature abscissas "); - - } - - // Test method fredin() - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fred2 (fredin): Imprecise interpolation of Fredholm result"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - class Gfunc { - public double funk (double t) { - return sqrt(t)-pow(PI/2.0,2.25)*pow(t,0.75)/2.25; - } - }; - - class Kernel { - public double funk (final double t, final double s) { - return pow(t*s,0.75); - } - }; -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter19/Test_Fredex.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter19/Test_Fredex.java deleted file mode 100644 index 09b9354c12..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter19/Test_Fredex.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.nr.test.test_chapter19; - -import static java.lang.Math.PI; -import static java.lang.Math.sin; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.inv.Quad_matrix; -import com.nr.la.LUdcmp; - -public class Test_Fredex { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - boolean localflag, globalflag=false; - - - - // Test Fredex - System.out.println("Testing Fredex"); - - localflag = main_fredex() != 0; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fredex : Program did not indicate successful completion"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - int main_fredex() - { - final int N=40; - double[] g=new double[N]; - double[][] a=new double[N][N]; - new Quad_matrix(a); - LUdcmp alu = new LUdcmp(a); - for (int j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Wwghts: 2-point weights do not add to 1.0"); - - } - - // Check integral of 1+x => x + x^2/2 - expect=1.0+0.5; - sum=w2[0]*1.0+w2[1]*2.0; -// System.out.printf(expect << " %f\n", sum); - localflag = abs(sum/expect-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Wwghts: 2-point weights fail on linear function"); - - } - - Wwghts weight3 = new Wwghts(1.0/2.0,3,quad); - w3=weight3.weights(); -// for (i=0;i<3;i++) System.out.printf(w3[i] << " "; -// System.out.printf(endl; - - sum=0.0; - for (i=0;i<3;i++) sum += w3[i]; -// System.out.printf(abs(sum-1.0)); - localflag = abs(sum-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Wwghts: 3-point weights do not add to 1.0"); - - } - - // Check integral of 1+x+x^2 => x + x^2/2 + x^3/3 - expect=1.0+0.5+1.0/3.0; - sum=w3[0]*1.0+w3[1]*(1.0+0.5*(1.0+0.5))+w3[2]*3.0; -// System.out.printf(expect << " %f\n", sum); - localflag = abs(sum/expect-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Wwghts: 3-point weights fail on quadratic function"); - - } - - Wwghts weight4 = new Wwghts(1.0/3.0,4,quad); - w4=weight4.weights(); -// for (i=0;i<4;i++) System.out.printf(w4[i] << " "; -// System.out.printf(endl; - - sum=0.0; - for (i=0;i<4;i++) sum += w4[i]; -// System.out.printf(abs(sum-1.0)); - localflag = abs(sum-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Wwghts: 4-point weights do not add to 1.0"); - - } - - // Check integral of 1+x+x^2+x^3 => x + x^2/2 + x^3/3 + x^4/4 - expect=1.0+0.5+1.0/3.0+0.25; - sum=w4[0]*1.0 - +w4[1]*(1.0+(1.0/3.0)*(1.0+(1.0/3.0)*(1.0+(1.0/3.0)))) - +w4[2]*(1.0+(2.0/3.0)*(1.0+(2.0/3.0)*(1.0+(2.0/3.0)))) - +w4[3]*4.0; -// System.out.printf(expect << " %f\n", sum); - localflag = abs(sum/expect-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Wwghts: 4-point weights fail on cubic polynomial"); - - } - - Wwghts weight5=new Wwghts(1.0/4.0,5,quad); - w5=weight5.weights(); -// for (i=0;i<5;i++) System.out.printf(w5[i] << " "; -// System.out.printf(endl; - - sum=0.0; - for (i=0;i<5;i++) sum += w5[i]; -// System.out.printf(abs(sum-1.0)); - localflag = abs(sum-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Wwghts: 5-point weights do not add to 1.0"); - - } - - // Check integral of 1+x+x^2+x^3 => x + x^2/2 + x^3/3 + x^4/4 - expect=1.0+0.5+1.0/3.0+0.25; - sum=w5[0]*1.0 - +w5[1]*(1.0+0.25*(1.0+0.25*1.25)) - +w5[2]*(1.0+0.50*(1.0+0.50*1.50)) - +w5[3]*(1.0+0.75*(1.0+0.75*1.75)) - +w5[4]*4.0; -// System.out.printf(expect << " %f\n", sum); - localflag = abs(sum/expect-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Wwghts: 5-point weights fail on cubic polynomial"); - - } - - Wwghts weight6=new Wwghts(1.0/5.0,6,quad); - w6=weight6.weights(); -// for (i=0;i<6;i++) System.out.printf(w6[i] << " "; -// System.out.printf(endl; - - sum=0.0; - for (i=0;i<6;i++) sum += w6[i]; -// System.out.printf(abs(sum-1.0)); - localflag = abs(sum-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Wwghts: 6-point weights do not add to 1.0"); - - } - - // Check integral of 1+x+x^2+x^3 => x + x^2/2 + x^3/3 + x^4/4 - expect=1.0+0.5+1.0/3.0+0.25; - sum=w6[0]*1.0 - +w6[1]*(1.0+0.2*(1.0+0.2*1.2)) - +w6[2]*(1.0+0.4*(1.0+0.4*1.4)) - +w6[3]*(1.0+0.6*(1.0+0.6*1.6)) - +w6[4]*(1.0+0.8*(1.0+0.8*1.8)) - +w6[5]*4.0; -// System.out.printf(expect << " %f\n", sum); - localflag = abs(sum/expect-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Wwghts: 6-point weights fail on fifth-order polynomial"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Quad implements UniVarRealMultiValueFun{ - public double[] funk(final double y) { - int i; - double[] w=new double[4]; - for (i=0;i<4;i++) - w[i]=pow(y,1.0*(i+1))/(i+1.0); - return w; - } - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter19/Test_voltra.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter19/Test_voltra.java deleted file mode 100644 index 33a674a122..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter19/Test_voltra.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.nr.test.test_chapter19; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static com.nr.test.NRTestUtil.*; -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import com.nr.inv.*; - -public class Test_voltra { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=20,M=2; - double h=0.05,t0=0.0,sbeps; - double[] t=new double[N],fac1= new double[N],fac2= new double[N]; - double[][] f=new double[M][N]; - boolean localflag, globalflag=false; - - - - // Test voltra - System.out.println("Testing voltra"); - - final Gfunc gfun = new Gfunc(); - final Kernel ker =new Kernel(); - - Volterra voltra = new Volterra(){ - - @Override - public double g(int k, double t) { - return gfun.funk(k, t); - } - - @Override - public double ak(int k, int l, double t, double s) { - return ker.funk(k, l, t, s); - } - - }; - voltra.voltra(t0, h, t, f); - - // exact soln is f[1]=exp(-t), f[2]=2sin(t) - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** voltra: Imprecise result for function exp(-t)"); - - } - - sbeps = 2.0e-3; - System.out.println(maxel(fac2)); - localflag = maxel(fac2) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** voltra: Imprecise result for function 2.0*sin(t)"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - class Gfunc - { - public double funk (final int k, final double t) { - return (k == 0 ? cosh(t)+t*sin(t) : - 2.0*sin(t)+t*(SQR(sin(t))+exp(t))); - } - }; - - class Kernel - { - public double funk (final int k, final int l, final double t, final double s) { - return ((k == 0) ? (l == 0 ? -exp(t-s) : -cos(t-s)) : - (l == 0 ? -exp(t+s) : -t*cos(s))); - } - }; - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_ADAT.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_ADAT.java deleted file mode 100644 index 373bdadf31..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_ADAT.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.nr.test.test_chapter2; - -import static com.nr.test.NRTestUtil.*; -import static org.junit.Assert.fail; -import static java.lang.Math.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.la.ADAT; -import com.nr.la.NRsparseMat; -import com.nr.ran.Ran; - -public class Test_ADAT { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps=1.e-12; - int i,j,k,nvals,N=30,M=50; - double[][] a =new double[N][M]; - boolean localflag, globalflag=false; - - - - // Test ADAT - System.out.println("Testing ADAT (and NRsparseMat)"); - Ran myran = new Ran(17); - nvals=N+M; // Create a sparse matrix with random non-zero entries - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ADAT: Matrix entries differ between sparse matrix and brute force result."); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_Bandec.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_Bandec.java deleted file mode 100644 index 49a879834e..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_Bandec.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.nr.test.test_chapter2; - -import com.nr.la.Bandec; -import static com.nr.test.NRTestUtil.*; -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class Test_Bandec { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps; - double[] r =new double[50],y =new double[50],rr =new double[50]; - boolean localflag, globalflag=false; - - - - // Test banmul and bandec - System.out.println("Testing bandec and banmul"); - double[][] c = new double[50][17]; - ranmat(c); - Bandec clu = new Bandec(c,9,7); - ranvec(r); - clu.solve(r,y); - Bandec.banmul(c,9,7,y,rr); - sbeps = 5.e15; - localflag = maxel(vecsub(r,rr)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** bandec,banmul: Inconsistent solution vector"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_Cholesky.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_Cholesky.java deleted file mode 100644 index 36a2f622a8..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_Cholesky.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.nr.test.test_chapter2; - -import static com.nr.NRUtil.*; -import static com.nr.test.NRTestUtil.*; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.la.Cholesky; - -public class Test_Cholesky { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps, diag=10.0; - double[][] a = new double[50][50]; - double[] r=new double[50],y=new double[50]; - boolean localflag, globalflag=false; - ranmat(a,diag); - ranvec(r); - - - - // Test cholesky - System.out.println("Testing cholesky"); - double[][] aposdef = matmul(a,transpose(a)); - Cholesky ach = new Cholesky(aposdef); - ach.solve(r,y); - sbeps = 5.e-15; - localflag = maxel(vecsub(matmul(aposdef,y),r)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** cholesky: Error in solve() method"); - - } - - ranvec(y); - double[] yy = new double[y.length]; - ach.elmult(y,r); - ach.elsolve(r,yy); - sbeps = 5.e-15; - localflag = maxel(vecsub(y,yy)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** cholesky: Error in method elmult() or elsolve()"); - - } - - double[][] ainv = buildMatrix(a); - ach.inverse(ainv); - sbeps = 5.e-15; - localflag = maxel(matsub(matmul(ainv,aposdef),ident(aposdef.length,1.))) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** cholesky: Error in method inverse()"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_LUdcmp.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_LUdcmp.java deleted file mode 100644 index 57b714e979..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_LUdcmp.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.nr.test.test_chapter2; - -import static com.nr.test.NRTestUtil.*; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.la.LUdcmp; - -public class Test_LUdcmp { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps, diag=10.0; - double[][] a = new double[50][50],b = new double[50][30]; - boolean localflag, globalflag=false; - ranmat(a,diag); - ranmat(b); - - - - // Test ludcmp - System.out.println("Testing ludcmp"); - LUdcmp alu = new LUdcmp(a); - double[][] x = new double[b.length][b[0].length]; - alu.solve(b,x); - sbeps=5.e-15; - double maxel = maxel(matsub(matmul(a,x),b)); - localflag = maxel > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ludcmp: test of solution vector failed: "+ maxel); - - } - - // Test inverse - double[][] ainv; // = buildMatrix(a); not need it - ainv = alu.inverse(); - sbeps = 5.e-15; - localflag = maxel(matsub(matmul(ainv,a),ident(a.length,1.))) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ludcmp: Test of inverse failed"); - - } - - // Test determinant - LUdcmp ainvlu = new LUdcmp(ainv); - sbeps = 5.e-15; - localflag = (alu.det()*ainvlu.det()-1.) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ludcmp: Test of determinant failed"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_Linbcg.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_Linbcg.java deleted file mode 100644 index b02e9e245c..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_Linbcg.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.nr.test.test_chapter2; - -import static com.nr.NRUtil.*; -import static com.nr.test.NRTestUtil.*; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; -import org.netlib.util.intW; - -import com.nr.la.Linbcg; -import com.nr.la.NRsparseMat; - -public class Test_Linbcg { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps; - int i,j; - boolean localflag, globalflag=false; - - - - // Test Linbcg (and NRsparseMat) - System.out.println("Testing Linbcg (and NRsparseMat)"); - final int NP=20; - final int NSIZE=58; - NRsparseMat sa = new NRsparseMat(NP,NP,NSIZE); - sa.col_ptr[1]=2; - for (i=1;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Linbcg: Derived class gives inconsistent solution vector"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - - class TestLinbcg extends Linbcg { - NRsparseMat a; - - TestLinbcg(NRsparseMat sa) { - a = sa; - } - - public void asolve(final double[] b, final double[] x, final int itrnsp) { - for (int i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** NRsparseCol: Reconstructed matrix is not correct"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_NRsparseMat.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_NRsparseMat.java deleted file mode 100644 index 8bdc26c1e5..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_NRsparseMat.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.nr.test.test_chapter2; - -import static com.nr.test.NRTestUtil.matsub; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.ranvec; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.la.NRsparseMat; -import com.nr.ran.Ran; - -public class Test_NRsparseMat { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double val,sbeps; - int i,j,k,N=50,M=30,nvals; - boolean localflag, globalflag=false; - - - - // Test NRsparseMat - System.out.println("Testing NRsparseMat"); - Ran myran = new Ran(17); - double[][] a = new double[N][M]; - nvals=N+M; - - // XXX java not support unsigned int. - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** NRsparseMat: Reconstructed matrix is incorrect"); - - } - - // Test multiplication of sparse matrix by vector - double[] c = new double[as.ncols]; - ranvec(c); - double[] d=as.ax(c); // Sparse multiplication by vector - // Find same result by brute force - double[] e = new double[as.nrows]; - for (i=0;i sbeps); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** NRsparseMat: Multiplication of sparse matrix by vector failed."); - - } - - // Test multiplication of sparse transpose by vector - double[] f = new double[as.nrows]; - ranvec(f); - double[] g=as.atx(f); // Sparse transpose multiplied by vector - // Find same result by brute force - double[] h= new double[as.ncols]; - for (i=0;i sbeps); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** NRsparseMat: Multiplication of sparse transpose by vector failed."); - - } - - // Note: Member function transpose() is tested in routine test_ADAT - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_QRdcmp.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_QRdcmp.java deleted file mode 100644 index 6ff57af62c..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_QRdcmp.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.nr.test.test_chapter2; - -import static com.nr.NRUtil.*; -import static com.nr.test.NRTestUtil.*; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.la.QRdcmp; - -public class Test_QRdcmp { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps, diag=10.0; - int i,j; - double[][] a = new double[50][50]; - double[] r = new double[50], y = new double[50]; - boolean localflag, globalflag=false; - ranmat(a,diag); - - - - // Test QRdcmp - System.out.println("Testing QRdcmp"); - QRdcmp aqr = new QRdcmp(a); - sbeps = 5.e-14; - localflag = maxel(matsub(matmul(transpose(aqr.qt),aqr.r),a)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** QRdcmp: QR decomposition was unsuccessful"); - - } - - localflag = maxel(matsub(matmul(transpose(aqr.qt),aqr.qt),ident(a.length,1.))) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** QRdcmp: Matrix aqr.qt is not orthogonal"); - - } - - ranvec(r); - aqr.solve(r,y); - localflag = maxel(vecsub(matmul(a,y),r)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** QRdcmp: Error in solve() method"); - - } - - // test update - double[][] aa = buildMatrix(a); - double[] s = new double[aa.length],t = new double[aa.length]; - ranvec(s); ranvec(t); - double[] u = new double[aa.length],v = buildVector(t); - aqr.qtmult(s,u); - aqr.update(u,v); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** QRdcmp: Error in method qtmult() or update()"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_SVD.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_SVD.java deleted file mode 100644 index 8e6975463d..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_SVD.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.nr.test.test_chapter2; - -import static com.nr.test.NRTestUtil.matmul; -import static com.nr.test.NRTestUtil.matsub; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.ranmat; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.la.SVD; - -public class Test_SVD { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps, diag=10.0; - int N=50,i; // M=30 not use it. - double[][] a = new double[N][N],b = new double[N][N]; - boolean localflag, globalflag=false; - ranmat(a,diag); - ranmat(b); - - - - // Test SVD (not very deeply, however) - System.out.println("Testing SVD"); - SVD svd = new SVD(a); - double[][] x = new double[b.length][b[0].length]; - svd.solve(b,x); - sbeps = 1.e-14; - localflag = maxel(matsub(matmul(a,x),b)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** SVD: Inconsistent solution vector"); - - } - -// System.out.println("svd: rank = " << svd.rank() << " nullity = " << svd.nullity() << endl; - localflag = (svd.rank() != 50 || svd.nullity() != 0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** SVD: Unexpected rank or nullity in original matrix"); - - } - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** cyclic: Inconsistant solution vector.\n"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_gaussj.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_gaussj.java deleted file mode 100644 index 4f8bb72b7a..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_gaussj.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.nr.test.test_chapter2; - -import static com.nr.la.GaussJordan.gaussj; -import static com.nr.test.NRTestUtil.*; -import static com.nr.NRUtil.*; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class Test_gaussj { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps, diag=10.0; - double[][] a = new double[50][50],b =new double[50][30]; - boolean localflag, globalflag=false; - ranmat(a,diag); - ranmat(b); - double[][] aa = buildMatrix(a),bb = buildMatrix(b); // saved original values - -// System.out.println("Matrices a,b initialized with maxels " << maxel(a) << maxel(b) << endl; - - - - // Test gaussj - System.out.println("Testing gaussj"); - - gaussj(a,b); - // test inverse matrix - sbeps = 5.e-15; - localflag = maxel(matsub(matmul(a,aa),ident(a.length,1.))) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** gaussj: Test of inverse failed"); - - } - - // Test rhs's - sbeps = 5.e-15; - localflag = maxel(matsub(matmul(aa,b),bb)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** gaussj: Test of RHS failed"); - - } - - // restore original a - a = buildMatrix(aa); - - // Test inverse with no rhs's - gaussj(a); - sbeps = 5.e-15; - localflag = maxel(matsub(matmul(a,aa),ident(a.length,1.))) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** gaussj: test of inverse with no RHS failed"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_mprove.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_mprove.java deleted file mode 100644 index f31f147073..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_mprove.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.nr.test.test_chapter2; - -import static com.nr.test.NRTestUtil.*; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.la.LUdcmp; - -public class Test_mprove { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps, diag=10.0; - int i; - double[][] a = new double[50][50]; - double[] r = new double[50],y = new double[50]; - boolean localflag, globalflag=false; - ranmat(a,diag); - - - - // Test mprove - System.out.println("Testing mprove"); - - ranvec(r); - LUdcmp alu = new LUdcmp(a); - alu.solve(r,y); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** mprove: Attempt to recover accurate solution failed"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_toeplz.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_toeplz.java deleted file mode 100644 index 18f690a530..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_toeplz.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.nr.test.test_chapter2; - -import static com.nr.la.Toepltz.*; -import static com.nr.test.NRTestUtil.*; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class Test_toeplz { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps; - int i,j,N=10; - double[] r =new double[2*N-1],x = new double[N],y= new double[N],yy= new double[N]; - boolean localflag, globalflag=false; - ranvec(r); - ranvec(y); - - - - // Test toeplz - System.out.println("Testing toeplz"); - toeplz(r,x,y); - // test solution w[] - sbeps = 5.e-14; - for(i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** toeplz: Inconsistant solution vector.\n"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_tridag.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_tridag.java deleted file mode 100644 index 240a475f76..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_tridag.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.nr.test.test_chapter2; - -import static com.nr.test.NRTestUtil.*; -import static com.nr.la.Tridag.*; -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class Test_tridag { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps,diag=10.0; - int i; - double[] a=new double[50],b=new double[50],c=new double[50],r=new double[50],u=new double[50],rr=new double[50]; - boolean localflag, globalflag=false; - ranvec(a); - ranvec(b); - ranvec(c); - ranvec(r); - for(i=0;i<50;i++) b[i] += diag; - - - - // Test tridag - System.out.println("Testing tridag"); - tridag(a,b,c,r,u); - // test solution u[] - sbeps = 5.e-15; - rr[0]=b[0]*u[0]+c[0]*u[1]; - rr[49]=a[49]*u[48]+b[49]*u[49]; - for(i=1;i<49;i++) rr[i]=a[i]*u[i-1]+b[i]*u[i]+c[i]*u[i+1]; - localflag = maxel(vecsub(rr,r)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** tridag: Inconsistant solution vector.\n"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_vander.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_vander.java deleted file mode 100644 index e94cee16a9..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter2/Test_vander.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.nr.test.test_chapter2; - -import static com.nr.la.Vander.*; -import static com.nr.test.NRTestUtil.*; - -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -public class Test_vander { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps; - int i,j,N=5; - double[] x = new double[N],q = new double[N],w = new double[N],qq = new double[N]; - boolean localflag, globalflag=false; - ranvec(x); - ranvec(q); - - // Test vander - System.out.println("Testing vander"); - vander(x,w,q); - // test solution w[] - sbeps = 1.e-6; - for(i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** vander: Inconsistant solution vector.\n"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter20/Test_Mgfas.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter20/Test_Mgfas.java deleted file mode 100644 index cf869a37d9..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter20/Test_Mgfas.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.nr.test.test_chapter20; - -import static com.nr.NRUtil.SQR; -import static java.lang.Math.abs; -import static java.lang.Math.pow; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.pde.Mgfas; - -public class Test_Mgfas { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int JMAX=33; - int i,j; - double diff,maxdiff,sumsq,rms,sbeps; - double[][] f=new double[JMAX][JMAX], u=new double[JMAX][JMAX],expect=new double[JMAX][JMAX]; - boolean localflag, globalflag=false; - - - // Test Mgfas - System.out.println("Testing Mgfas"); - - for (i=0;i maxdiff) maxdiff=abs(diff); - sumsq += pow(diff,2.0); - } - } - rms=sqrt(sumsq/(JMAX-2)/(JMAX-2)); - System.out.printf("max difference = %f\n", maxdiff); - System.out.printf("rms error = %f\n", rms); - - sbeps=1.e-3; - localflag = rms > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Mgfas: RMS error is unexpectedly large"); - - } - - sbeps=1.e-2; - localflag = maxdiff > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Mgfas: Maximum deviation is unexpectedly large"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter20/Test_Mglin.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter20/Test_Mglin.java deleted file mode 100644 index 7a0285c5e4..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter20/Test_Mglin.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.nr.test.test_chapter20; - -import static com.nr.NRUtil.SQR; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.pde.Mglin; - -public class Test_Mglin { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int JMAX=33; - int i,j,midl=JMAX/2; - double sbeps; - double[][] f=new double[JMAX][JMAX], u=new double[JMAX][JMAX]; - boolean localflag, globalflag=false; - - - - // Test Mglin - System.out.println("Testing Mglin"); - - u[midl][midl]=2.0; - Mglin mglin = new Mglin(u,20);u=mglin.u; - -// System.out.printf(endl << " Test that solution satisfies difference equations:"; -// System.out.printf(endl; -// System.out.printf(setprecision(2); -// for (i=NSTEP;i sbeps; - else - localflag = localflag || abs(f[i][j]-2.0) > sbeps; - } - } - - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Mglin: Solution u[i][j] does not satisfy the original difference equations"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter20/Test_sor.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter20/Test_sor.java deleted file mode 100644 index c735994c98..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter20/Test_sor.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.nr.test.test_chapter20; - -import static com.nr.NRUtil.SQR; -import static com.nr.NRUtil.buildMatrix; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.cos; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.pde.Relaxation; - -public class Test_sor { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,midl,JMAX=33; - double rjac,sbeps,PI=acos(-1.0); - double[][] a=buildMatrix(JMAX,JMAX,1.0),b=buildMatrix(JMAX,JMAX,1.0),c=buildMatrix(JMAX,JMAX,1.0); - double[][] d=buildMatrix(JMAX,JMAX,1.0),e=buildMatrix(JMAX,JMAX,-4.0),f=buildMatrix(JMAX,JMAX,0.0); - double[][] u=buildMatrix(JMAX,JMAX,0.0); - boolean localflag, globalflag=false; - - - - // Test sor - System.out.println("Testing sor"); - - midl=JMAX/2; - f[midl][midl]=2000.0/SQR(JMAX-1.0); - rjac=cos(PI/JMAX); - Relaxation.sor(a,b,c,d,e,f,u,rjac); - -// System.out.printf(endl << " Test that solution satisfies difference equations:"; -// System.out.printf(endl; -// System.out.printf(setprecision(2); -// for (i=NSTEP;i sbeps; - else - localflag = localflag || abs(f[i][j]-2000.0/SQR(JMAX-1.0)) > sbeps; - } - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** sor: Solution u[i][j] does not satisfy the original difference equations"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter20/Test_weights.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter20/Test_weights.java deleted file mode 100644 index 1756a11727..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter20/Test_weights.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.nr.test.test_chapter20; - -import static java.lang.Math.abs; -import static java.lang.Math.atan; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.pde.Weights; -import com.nr.ran.Ran; -import com.nr.sf.Bessjy; - -public class Test_weights { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=17,M=3; - double scale,y,f,f1,f2,sbeps; - double[] x=new double[N]; - double[][] c=new double[N][M]; // ,d1=new double[N][N],d2=new double[N][N]; - boolean localflag, globalflag=false; - - - - // Test weights - System.out.println("Testing weights"); - - // Choose some collocation points - scale=3.0/N; - for (i=0;i<=N/2;i++) { - x[i]=10.0*atan((N/2-i)*scale); - x[N-1-i]= -x[i]; - } -// for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** weights: Evaluation of function was inaccurate"); - - } - - sbeps=1.e-3; - localflag = abs(0.5*(bess.jn(4,y)-bess.jn(6,y))-f1) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** weights: Evaluation of first derivative was inaccurate"); - - } - - sbeps=1.e-3; - localflag = abs(0.25*(bess.jn(3,y)-2.0*bess.jn(5,y)+bess.jn(7,y))-f2) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** weights: Evaluation of second derivative was inaccurate"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Box.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Box.java deleted file mode 100644 index 776b1bf072..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Box.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.nr.test.test_chapter21; - -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.cg.Box; -import com.nr.cg.Point; - -public class Test_Box { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - Point zero2=new Point(0.0,0.0),one2=new Point(1.0,1.0); - Point zero3=new Point(0.0,0.0,0.0),one3=new Point(1.0,1.0,1.0); - boolean localflag, globalflag=false; - - - - // Test Box - System.out.println("Testing Box"); - - // Test constructor defaults for 1,2,3 dimensions - Box b2 = new Box(2); - Box b3 = new Box(3); - - localflag = false; - localflag = !(b2.lo.equals(zero2)) || !(b2.hi.equals(zero2)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Box: Faulty default constructor for 2D"); - - } - - localflag = false; - localflag = !(b3.lo.equals(zero3)) || !(b3.hi.equals(zero3)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Box: Faulty default constructor for 3D"); - - } - - // Test constructor with arguments - Box c2=new Box(zero2,one2); - Box c3=new Box(zero3,one3); - - localflag = false; - localflag = !(c2.lo.equals(zero2)) || !(c2.hi.equals(one2)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Box: Faulty assignment of lo or hi for 2D constructor"); - - } - - localflag = false; - localflag = !(c3.lo.equals(zero3)) || !(c3.hi.equals(one3)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Box: Faulty assignment of lo or hi for 3D constructor"); - - } - - // Test assignment operator - b2= b2.copyAssign(c2); - b3=b3.copyAssign(c3); - - localflag = false; - localflag = !(b2.lo.equals(zero2)) || !(b2.hi.equals(one2)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Box: Failure of assignment operator for 2D"); - - } - - localflag = false; - localflag = !(b3.lo.equals(zero3)) || !(b3.hi.equals(one3)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Box: Failure of assignment operator for 3D"); - - } - - // Test copy constructor - - Box d2 = new Box(c2); - Box d3 = new Box(c3); - - localflag = false; - localflag = !(d2.lo.equals(c2.lo)) || !(d2.hi.equals(c2.hi)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Box: Failure of copy constructor for 2D"); - - } - - localflag = false; - localflag = !(d3.lo.equals(c3.lo)) || !(d3.hi.equals(c3.hi)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Box: Failure of copy constructor for 3D"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Boxnode.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Boxnode.java deleted file mode 100644 index dc07fb0a9c..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Boxnode.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.nr.test.test_chapter21; - -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.cg.Boxnode; -import com.nr.cg.Point; -import com.nr.ran.Ran; - -public class Test_Boxnode { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,NBOX=7; - double d1,d2,a,b,c,d,expect1,expect2,sbeps=1.e-15; - boolean localflag, globalflag=false; - - - - // Test Boxnode - System.out.println("Testing Boxnode"); - - // Create a tree of Boxnodes: 0 -> 1,2 ; 1 -> 3,4 ; 2 -> 5,6 - // With 2 points in each box - - Boxnode boxes2[]=new Boxnode[NBOX]; - Point[] points2=new Point[2*NBOX]; - - Ran myran=new Ran(17); - for (i=0;i sbeps) || (abs(d-expect2) > sbeps); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Boxnode: Coordinate 0 of daughter-daughter path failed"); - - } - - a=boxes2[boxes2[boxes2[0].dau1].dau2].lo.x[1]; - b=boxes2[boxes2[boxes2[0].dau1].dau2].hi.x[1]; -// System.out.printf(a << " %f\n", a+0.3*(b-a) << " %f\n", a+0.6*(b-a) << " %f\n", b); - c=points2[boxes2[4].ptlo].x[1]; - d=points2[boxes2[4].pthi].x[1]; -// System.out.printf(c << " %f\n", d); - - expect1=a+0.3*(b-a); - expect2=a+0.6*(b-a); - localflag = (abs(c-expect1) > sbeps) || (abs(d-expect2) > sbeps); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Boxnode: Coordinate 1 of daughter-daughter path failed"); - - } - - // Track through mothers and daughters - a=boxes2[boxes2[boxes2[boxes2[NBOX-1].mom].mom].dau1].lo.x[0]; - b=boxes2[boxes2[boxes2[boxes2[NBOX-1].mom].mom].dau1].hi.x[0]; -// System.out.printf(a << " %f\n", a+0.3*(b-a) << " %f\n", a+0.6*(b-a) << " %f\n", b); - c=points2[boxes2[1].ptlo].x[0]; - d=points2[boxes2[1].pthi].x[0]; -// System.out.printf(c << " %f\n", d); - - expect1=a+0.3*(b-a); - expect2=a+0.6*(b-a); - localflag = (abs(c-expect1) > sbeps) || (abs(d-expect2) > sbeps); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Boxnode: Coordinate 0 of mother-mother-daughter path failed"); - - } - - a=boxes2[boxes2[boxes2[boxes2[NBOX-1].mom].mom].dau1].lo.x[1]; - b=boxes2[boxes2[boxes2[boxes2[NBOX-1].mom].mom].dau1].hi.x[1]; -// System.out.printf(a << " %f\n", a+0.3*(b-a) << " %f\n", a+0.6*(b-a) << " %f\n", b); - c=points2[boxes2[1].ptlo].x[1]; - d=points2[boxes2[1].pthi].x[1]; -// System.out.printf(c << " %f\n", d); - - expect1=a+0.3*(b-a); - expect2=a+0.6*(b-a); - localflag = (abs(c-expect1) > sbeps) || (abs(d-expect2) > sbeps); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Boxnode: Coordinate 1 of mother-mother-daughter path failed"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Circle.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Circle.java deleted file mode 100644 index 40d164b128..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Circle.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.nr.test.test_chapter21; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.cg.Circle; -import com.nr.cg.Point; - -public class Test_Circle { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - Point center=new Point(2); - double radius,sbeps=1.e-16; - boolean localflag, globalflag=false; - - - - // Test Circle - System.out.println("Testing Circle"); - - center.x[0]=1.5; - center.x[1]=2.5; - radius=3.5; - - Circle cir = new Circle(center,radius); - - localflag = Point.dist(center,cir.center) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Circle: Circle does not have correct center"); - - } - - sbeps=1.0e-15; - localflag = abs(radius-cir.radius) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Circle: Circle does not have correct radius"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Convexhull.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Convexhull.java deleted file mode 100644 index 246be30c2e..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Convexhull.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.nr.test.test_chapter21; - -import static com.nr.test.NRTestUtil.maxel; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.cg.Convexhull; -import com.nr.cg.Point; -import com.nr.cg.Polygon; -import com.nr.ran.Ran; - - -public class Test_Convexhull { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,nwind,N=10000; - Point p=new Point(2); - Point[] pvec = new Point[N]; - for(i=0;i 0.02; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Convexhull: Convex hull unexpectedly far from unit square"); - - } - - Point[] hull = new Point[cvx.nhull]; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Delaunay, interpolate(): Unexpectedly inaccurate interpolated value "); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_KDtree.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_KDtree.java deleted file mode 100644 index 72e84dadcc..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_KDtree.java +++ /dev/null @@ -1,387 +0,0 @@ -package com.nr.test.test_chapter21; - -import static com.nr.NRUtil.SQR; -import static com.nr.NRUtil.buildVector; -import static com.nr.cg.Point.dist; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import java.util.Arrays; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.cg.KDtree; -import com.nr.cg.Point; -import com.nr.ran.Ran; - - - -public class Test_KDtree { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @SuppressWarnings("unused") - @Test - public void test() { - boolean debug=false; - int i,N=1000,M=100; - double sbeps; - Point[] kd2=new Point[N]; // vector of 2D Points - Point[] kd3=new Point[N]; // vector of 3D Points - boolean localflag=false, globalflag=false; - - - - // Test KDtree - System.out.println("Testing KDtree"); - - Ran myran=new Ran(17); - - // Test KDtree in 2D - for (i=0;i tree2.boxes[nb].hi.x[0]); - localflag = localflag || (y.x[1] < tree2.boxes[nb].lo.x[1]); - localflag = localflag || (y.x[1] > tree2.boxes[nb].hi.x[1]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** KDtree<2>,locate(Point): The located box does not contain selected point"); - - } - } - - // Test locate(int) method - int n0; - localflag=false; - for (i=0;i tree2.boxes[nb].hi.x[0]); - localflag = localflag || (kd2[n0].x[1] < tree2.boxes[nb].lo.x[1]); - localflag = localflag || (kd2[n0].x[1] > tree2.boxes[nb].hi.x[1]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** KDtree<2>,locate(int): The located box does not contain selected point"); - - } - } - - // Test disti() method - int n1,n2; - sbeps=1.e-15; - localflag=false; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** KDtree<2>,disti(): The disti() method gave an incorrect result"); - - } - } - - // Test nearest() method - int j,n3; - double dis2sq; - localflag=false; - for (i=0;i,nearest(): Exhaustive search found closer point"); - - } - } - - // Test nnearest() method - int n4,n,nfar,K=5; - boolean test; - double far; - int[]nn=new int[K]; - double[] dn=new double[K]; - localflag=false; - for (i=0;i far) { - far=dn[j]; - nfar=nn[j]; - } - test=false; - for (j=0;j,nnearest(): Found a nearer point than the supposed n nearest"); - - } - } - } - - // Test locatenear() method - int nmax=N/10; - int[] list=new int[nmax]; - double r=0.1; - y.x[0]=0.5; - y.x[1]=0.5; - int nret=tree2.locatenear(y,r,list,nmax); - // Check the result by brute force - int[] list2=new int[nmax]; - int nret2=0; - for (i=0;i,locatenear(): Found different number of points closer than radius r"); - - } - - // Make sure list[] and list2[] are the same - int[] llist=buildVector(list),llist2=buildVector(list2); - Arrays.sort(llist); - Arrays.sort(llist2); - localflag=false; - for (i=0;i,locatenear(): The list of nearby points is not correct"); - - } - - // Repeat all the tests in 3D - // Test KDtree in 3D - for (i=0;i tree3.boxes[nb].hi.x[0]); - localflag = localflag || (yy.x[1] < tree3.boxes[nb].lo.x[1]); - localflag = localflag || (yy.x[1] > tree3.boxes[nb].hi.x[1]); - localflag = localflag || (yy.x[2] < tree3.boxes[nb].lo.x[2]); - localflag = localflag || (yy.x[2] > tree3.boxes[nb].hi.x[2]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** KDtree<3>,locate(Point): The located box does not contain selected point"); - - } - } - - // Test locate(int) method in 3D - localflag=false; - for (i=0;i tree3.boxes[nb].hi.x[0]); - localflag = localflag || (kd3[n0].x[1] < tree3.boxes[nb].lo.x[1]); - localflag = localflag || (kd3[n0].x[1] > tree3.boxes[nb].hi.x[1]); - localflag = localflag || (kd3[n0].x[2] < tree3.boxes[nb].lo.x[2]); - localflag = localflag || (kd3[n0].x[2] > tree3.boxes[nb].hi.x[2]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** KDtree<3>,locate(int): The located box does not contain selected point"); - - } - } - - // Test disti() method in 3D - sbeps=1.e-15; - localflag=false; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** KDtree<3>,disti(): The disti() method gave an incorrect result"); - - } - } - - // Test nearest() method in 3D - double dis3sq; - localflag=false; - for (i=0;i,nearest(): Exhaustive search found closer point"); - - } - } - - // Test nnearest() method in 3D - localflag=false; - for (i=0;i far) { - far=dn[j]; - nfar=nn[j]; - } - test=false; - for (j=0;j,nnearest(): Found a nearer point than the supposed n nearest"); - - } - } - } - - // Test locatenear() method in 3D - r=0.2; - yy.x[0]=0.5; - yy.x[1]=0.5; - yy.x[2]=0.5; - nret=tree3.locatenear(yy,r,list,nmax); - // Check the result by brute force - nret2=0; - for (i=0;i,locatenear(): Found different number of points closer than radius r"); - - } - - // Make sure list[] and list2[] are the same - int[] llist3=buildVector(list),llist4=buildVector(list2); - Arrays.sort(llist3); - Arrays.sort(llist4); - localflag=false; - for (i=0;i,locatenear(): The list of nearby points is not correct"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Minspantree.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Minspantree.java deleted file mode 100644 index 7d09a7ff22..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Minspantree.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.nr.test.test_chapter21; - -import static com.nr.cg.Point.dist; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.cg.Minspantree; -import com.nr.cg.Point; -import com.nr.ran.Ran; - - -public class Test_Minspantree { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,min,N=1000; - Point[] pvec=new Point[N],qvec=new Point[N]; - for(i=0;i dist(pvec[minspan.minsega[i+1]],pvec[minspan.minsegb[i+1]]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Minspantree: Segments of tree are not in order of length"); - - } - } - - // Check whether every point is actually in the tree - // (i.e. whether the combination of all minsega and minsegb - // include all numbers from 1 to N - int[] flags=new int[N]; - for (i=0;i dist(qvec[minspan2.minsega[i+1]],qvec[minspan2.minsegb[i+1]]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Minspantree: Segments of second tree are not in order of length"); - - } - } - - // Check whether every point is actually in the tree - // (i.e. whether the combination of all minsega and minsegb - // include all numbers from 1 to N - int[] flags2=new int[N]; - for (i=0;i N-i for the two trees (meaning that the two trees are - // really the same). Note: minsega and minsegb also get swapped. - for (i=0;i in 2D - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Nearpoints,2D: A point identified by KDtree was not found by Nearpoints"); - - } - } - } - - // Create KDtree and Qotree of same Points<3> in 3D - Point test3pt=new Point(3); - Point[] p3vec=new Point[N]; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Nearpoints: A point identified by KDtree was not found by Nearpoints"); - - } - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Point.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Point.java deleted file mode 100644 index d51c37987f..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Point.java +++ /dev/null @@ -1,174 +0,0 @@ -package com.nr.test.test_chapter21; - -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.cg.Point; - -public class Test_Point { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - boolean localflag, globalflag=false; - - - - // Test Point - System.out.println("Testing Point"); - - // Test constructor defaults for 1,2,3 dimensions - Point x1= new Point(1); - Point x2= new Point(2); - Point x3= new Point(3); - - localflag = false; - localflag = (x1.x[0] != 0.0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Point: Faulty default constructor for 1D"); - - } - - localflag = false; - localflag = (x2.x[0] != 0.0) || (x2.x[1] != 0.0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Point: Faulty default constructor for 2D"); - - } - - localflag = false; - localflag = (x3.x[0] != 0.0) || (x3.x[1] != 0.0) || (x3.x[2] != 0.0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Point: Faulty default constructor for 3D"); - - } - - Point x11=new Point(1,1.0); - Point x21=new Point(1.0,1.0); - Point x31=new Point(1.0,1.0,1.0); - - localflag = false; - localflag = (x11.x[0] != 1.0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Point: Faulty element assignments for 1D constructor"); - - } - - localflag = false; - localflag = (x21.x[0] != 1.0) || (x21.x[1] != 1.0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Point: Faulty element assignments for 2D constructor"); - - } - - localflag = false; - localflag = (x31.x[0] != 1.0) || (x31.x[1] != 1.0) || (x31.x[2] != 1.0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Point: Faulty element assignments for 3D constructor"); - - } - - // Test assignment operator - x1.copyAssign(x11); - x2.copyAssign(x21); - x3.copyAssign(x31); - - localflag = false; - localflag = (x1.x[0] != 1.0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Point: Failure of assignment operator for 1D"); - - } - - localflag = false; - localflag = (x2.x[0] != 1.0) || (x2.x[1] != 1.0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Point: Failure of assignment operator for 2D"); - - } - - localflag = false; - localflag = (x3.x[0] != 1.0) || (x3.x[1] != 1.0) || (x3.x[2] != 1.0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Point: Failure of assignment operator for 3D"); - - } - - // Test boolean equality operator - localflag = false; - localflag = !(x11.equals(x1)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Point: Failure of boolean equality operator for 1D"); - - } - - localflag = false; - localflag = !(x21.equals(x2)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Point: Failure of boolean equality operator for 2D"); - - } - - localflag = false; - localflag = !(x31.equals(x3)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Point: Failure of boolean equality operator for 3D"); - - } - - // Test copy constructor - Point y1=new Point(x1); - Point y2=new Point(x2); - Point y3=new Point(x3); - - localflag = false; - localflag = !(y1.equals(x1)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Point: Failure of copy constructor for 1D"); - - } - - localflag = false; - localflag = !(y2.equals(x2)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Point: Failure of copy constructor for 2D"); - - } - - localflag = false; - localflag = !(y3.equals(x3)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Point: Failure of copy constructor for 3D"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Qotree.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Qotree.java deleted file mode 100644 index 4b000fc272..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Qotree.java +++ /dev/null @@ -1,455 +0,0 @@ -package com.nr.test.test_chapter21; - -import static com.nr.cg.Point.dist; -import static java.lang.Math.pow; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.cg.Box; -import com.nr.cg.Point; -import com.nr.cg.Qotree; -import com.nr.cg.Sphcirc; - - -public class Test_Qotree { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,nbox,nlist,N=100; - double sbeps=1.e-15; - boolean localflag, globalflag=false; - - - - // Test Qotree - System.out.println("Testing Qotree"); - - // Ran myran=new Ran(17); - - // Test Qotree in 2D - Qotree qotree2 = new Qotree(2,N,N,5); - - // Test setouterbox in 2D - Point lo2=new Point(0.0,0.0),hi2=new Point(1.0,1.0); - qotree2.setouterbox(lo2,hi2); - - // Test qobox in 2D - Box b2=new Box(2); - b2=qotree2.qobox(1); -// System.out.printf(dist(b2.lo,lo2)); - localflag = dist(b2.lo,lo2) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,2D: Outer box lower corner improperly set"); - - } - -// System.out.printf(dist(b2.hi,hi2)); - localflag = dist(b2.hi,hi2) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,2D: Outer box upper corner improperly set"); - - } - - Point half=new Point(hi2.x[0]/2.0,hi2.x[1]/2.0); - - b2=qotree2.qobox(2); -// System.out.printf(dist(b2.hi,half)); - localflag = dist(b2.hi,half) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,2D: Box 2 upper corner should be in center of outer box"); - - } - - b2=qotree2.qobox(5); -// System.out.printf(dist(b2.lo,half)); - localflag = dist(b2.lo,half) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,2D: Box 5 lower corner should be in center of outer box"); - - } - - // Test qowhichbox in 2D - Sphcirc s2 = new Sphcirc(2); - s2.center=new Point(5.5/16.0,10.5/16.0); - int ans[]={1,4,15,239}; - for (i=0;i<4;i++) { - s2.radius=0.25/pow(2.0,i); - nbox=qotree2.qowhichbox(s2); -// System.out.printf(s2.radius << " %f\n", nbox); - - localflag = (nbox != ans[i]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,2D: Method qowhichbox() identified wrong box for specified circle"); - - } - } - - // Test qostore in 2D - s2.center=new Point(5.5/16.0,10.5/16.0); - for (i=0;i<4;i++) { - s2.radius=0.25/pow(2.0,i); - nbox=qotree2.qostore(s2); -// System.out.println("box: %f\n", nbox); - - localflag = (nbox != ans[i]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,2D: Method qostore() stored specified circle in wrong box"); - - } - } - - // Test qoerase in 2D - s2.center=new Point(5.5/16.0,10.5/16.0); - for (i=0;i<4;i++) { - s2.radius=0.25/pow(2.0,i); - nbox=qotree2.qoerase(s2); -// System.out.printf(nbox); - - localflag = (nbox != ans[i]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,2D: Method qoerase() removed circle from wrong box"); - - } - } - - // Store 16 circles in the tree - s2.center=new Point(5.5/16.0,10.5/16.0); - for (i=0;i<4;i++) { - s2.radius=0.25/pow(2.0,i); - qotree2.qostore(s2); - } - s2.center=new Point(10.5/16.0,10.5/16.0); - for (i=0;i<4;i++) { - s2.radius=0.25/pow(2.0,i); - qotree2.qostore(s2); - } - s2.center=new Point(10.5/16.0,5.5/16.0); - for (i=0;i<4;i++) { - s2.radius=0.25/pow(2.0,i); - qotree2.qostore(s2); - } - s2.center=new Point(5.5/16.0,5.5/16.0); - for (i=0;i<4;i++) { - s2.radius=0.25/pow(2.0,i); - qotree2.qostore(s2); - } - - // Test qoget in 2D - Sphcirc[]list2=new Sphcirc[N]; - nlist=qotree2.qoget(1,list2,N); - System.out.println(nlist); - for (i=0;i list2[i].radius; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,2D: Method qodump() returned a circle that does not contain the given point"); - - } - } - - // Test qocollides in 2D - s2.center=new Point(0.75,0.75); - s2.radius=0.10; - nlist=qotree2.qocollides(s2,list2,N); -// System.out.printf(nlist); - - localflag = (nlist != 3); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,2D: Method qocollides() did not find 3 circles that collide with target"); - - } - - for (i=0;i list2[i].radius+s2.radius); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,2D: Incorrect collision detection by method qocollides()"); - - } - } - - // Test Qotree in 3D - Qotree qotree3=new Qotree(3,N,N,5); - - // Test setouterbox in 3D - Point lo3=new Point(0.0,0.0,0.0),hi3=new Point(1.0,1.0,1.0); - qotree3.setouterbox(lo3,hi3); - - // Test qobox in 3D - Box b3=new Box(3); - b3=qotree3.qobox(1); -// System.out.printf(dist(b3.lo,lo3)); - localflag = dist(b3.lo,lo3) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,3D: Outer box lower corner improperly set"); - - } - -// System.out.printf(dist(b3.hi,hi3)); - localflag = dist(b3.hi,hi3) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,3D: Outer box upper corner improperly set"); - - } - - Point half3=new Point(hi3.x[0]/2.0,hi3.x[1]/2.0,hi3.x[2]/2.0); - - b3=qotree3.qobox(2); -// System.out.printf(dist(b3.hi,half3)); - localflag = dist(b3.hi,half3) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,3D: Box 2 upper corner should be in center of outer box"); - - } - - b3=qotree3.qobox(9); -// System.out.printf(dist(b3.lo,half3)); - localflag = dist(b3.lo,half3) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,3D: Box 9 lower corner should be in center of outer box"); - - } - - // Test qowhichbox in 3D - Sphcirc s3=new Sphcirc(3); - int ans3[]={1,8,59,3771}; - s3.center=new Point(5.5/16.0,10.5/16.0,10.5/16.0); - for (i=0;i<4;i++) { - s3.radius=0.25/pow(2.0,i); - nbox=qotree3.qowhichbox(s3); -// System.out.printf(s3.radius << " %f\n", nbox); - - localflag = (nbox != ans3[i]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,3D: Method qowhichbox() identified wrong box for specified sphere"); - - } - } - - // Test qostore in 3D - s3.center=new Point(5.5/16.0,10.5/16.0,10.5/16.0); - for (i=0;i<4;i++) { - s3.radius=0.25/pow(2.0,i); - nbox=qotree3.qostore(s3); -// System.out.println("box: %f\n", nbox); - - localflag = (nbox != ans3[i]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,3D: Method qostore() stored specified sphere in wrong box"); - - } - } - - // Test qoerase in 3D - s3.center=new Point(5.5/16.0,10.5/16.0,10.5/16.0); - for (i=0;i<4;i++) { - s3.radius=0.25/pow(2.0,i); - nbox=qotree3.qoerase(s3); -// System.out.printf(nbox); - - localflag = (nbox != ans3[i]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,3D: Method qoerase() removed sphere from wrong box"); - - } - } - - // Store 32 circles in the tree - s3.center=new Point(5.5/16.0,5.5/16.0,5.5/16.0); - for (i=0;i<4;i++) { - s3.radius=0.25/pow(2.0,i); - qotree3.qostore(s3); - } - s3.center=new Point(5.5/16.0,5.5/16.0,10.5/16.0); - for (i=0;i<4;i++) { - s3.radius=0.25/pow(2.0,i); - qotree3.qostore(s3); - } - s3.center=new Point(5.5/16.0,10.5/16.0,5.5/16.0); - for (i=0;i<4;i++) { - s3.radius=0.25/pow(2.0,i); - qotree3.qostore(s3); - } - s3.center=new Point(5.5/16.0,10.5/16.0,10.5/16.0); - for (i=0;i<4;i++) { - s3.radius=0.25/pow(2.0,i); - qotree3.qostore(s3); - } - s3.center=new Point(10.5/16.0,5.5/16.0,5.5/16.0); - for (i=0;i<4;i++) { - s3.radius=0.25/pow(2.0,i); - qotree3.qostore(s3); - } - s3.center=new Point(10.5/16.0,5.5/16.0,10.5/16.0); - for (i=0;i<4;i++) { - s3.radius=0.25/pow(2.0,i); - qotree3.qostore(s3); - } - s3.center=new Point(10.5/16.0,10.5/16.0,5.5/16.0); - for (i=0;i<4;i++) { - s3.radius=0.25/pow(2.0,i); - qotree3.qostore(s3); - } - s3.center=new Point(10.5/16.0,10.5/16.0,10.5/16.0); - for (i=0;i<4;i++) { - s3.radius=0.25/pow(2.0,i); - qotree3.qostore(s3); - } - - // Test qoget in 3D - Sphcirc[] list3=new Sphcirc[N]; - nlist=qotree3.qoget(1,list3,N); -// System.out.printf(nlist); -// for (i=0;i list3[i].radius; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,3D: Method qodump() returned a sphere that does not contain the given point"); - - } - } - - // Test qocollides in 3D - s3.center=new Point(0.75,0.75,0.75); - s3.radius=0.10; - nlist=qotree3.qocollides(s3,list3,N); -// System.out.printf(nlist); - - localflag = (nlist != 3); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,3D: Method qocollides() did not find 3 spheres that collide with target"); - - } - - for (i=0;i list3[i].radius+s3.radius); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Qotree,3D: Incorrect collision detection by method qocollides()"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Sphcirc.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Sphcirc.java deleted file mode 100644 index 6ae0120cf8..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Sphcirc.java +++ /dev/null @@ -1,249 +0,0 @@ -package com.nr.test.test_chapter21; - -import static com.nr.cg.Point.dist; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.cg.Box; -import com.nr.cg.Point; -import com.nr.cg.Sphcirc; -import com.nr.ran.Ran; - - -public class Test_Sphcirc { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - boolean test; - int i,j,N=1000; - double radius1,radius2; - Point p21=new Point(2),p22=new Point(2); - Point p31=new Point(3),p32=new Point(3); - boolean localflag, globalflag=false; - - - - // Test Sphcirc - System.out.println("Testing Sphcirc"); - - Ran myran=new Ran(17); - - // Test method operator== in 2D - Sphcirc[] circ=new Sphcirc[N]; - - for (i=0;i 1,2,3 ; 1 -> 4,5,6 ; 2 -> 7,8,9 ; 3 -> 10,11,12 - - Point []points=new Point[NPTS]; - for (i=0;i ptest; -// for (i=0;i 0.0); -// System.out.printf(z.x[0] << " %f\n", test); - - localflag = (test != (z.x[0] < 1.0)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Triel: A point that should be inside a tringle was identified as outside all of them"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Voredge.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Voredge.java deleted file mode 100644 index c647d70b46..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Voredge.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.nr.test.test_chapter21; - -import static com.nr.cg.Point.dist; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.cg.Point; -import com.nr.cg.Voronoi; -import com.nr.ran.Ran; - - - -public class Test_Voredge { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,NPTS=3; - double sbeps=1.e-15; - boolean localflag, globalflag=false; - - - - // Test Voredge - System.out.println("Testing Voredge"); - - Ran myran=new Ran(17); - Point[] points=new Point[NPTS]; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Voredge: First endpoint of edge improperly initialized"); - - } - - localflag = dist(v.p[1],points[1]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Voredge: Second endpoint of edge improperly initialized"); - - } - - localflag = v.nearpt != 2; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Voredge: integer pointer to nearby point is improperly initialized"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Voronoi.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Voronoi.java deleted file mode 100644 index e5a76071a1..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_Voronoi.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.nr.test.test_chapter21; - -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.cg.Point; -import com.nr.cg.Triel; -import com.nr.cg.Voronoi; -import com.nr.ran.Ran; - - -public class Test_Voronoi { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @SuppressWarnings("unused") - @Test - public void test() { - int i,j,k,mm,N=1000,M=100; - long key; - double sbeps=1.e-15; - Point[] pvec=new Point[N]; - for(i=0;i sbeps) && (dotprodj > sbeps); - key=vor.hashfn.int64(i)-vor.hashfn.int64(nsite); - Integer[] k_w = new Integer[1]; - vor.linehash.get(key,k_w,0);k=k_w[0]; - if (k == jfirst) break; - j=i; - i=k; - } - - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Voronoi: Chosen Voronoi edge is not perpendicular to any local Delaunay edge"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_circumcircle.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_circumcircle.java deleted file mode 100644 index f2004d86fd..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_circumcircle.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.nr.test.test_chapter21; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static com.nr.test.NRTestUtil.*; -import com.nr.ran.*; - -import com.nr.cg.*; -import static com.nr.cg.Circle.*; - - -public class Test_circumcircle { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=10; - double sbeps=1.e-15; - Point a =new Point(2),b =new Point(2),c =new Point(2); - Circle cir=new Circle(a,0.0); // placeholder - double[] d=new double[3]; - boolean localflag, globalflag=false; - - - - // Test circumcircle - System.out.println("Testing circumcircle"); - - Ran myran=new Ran(17); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** circumcircle: At least one point is not on supposed circumcircle"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_dist.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_dist.java deleted file mode 100644 index de10969ee0..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_dist.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.nr.test.test_chapter21; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static com.nr.test.NRTestUtil.*; -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -import com.nr.ran.*; - -import com.nr.cg.*; -import static com.nr.cg.Point.*; - - -public class Test_dist { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=100; - double sbeps; - double[] d=new double[100],dexp=new double[100]; - boolean localflag, globalflag=false; - - - - // Test dist - System.out.println("Testing dist"); - - // Distance between two points in 2D - Ran myran=new Ran(17); - Point x=new Point(2),y=new Point(2); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** dist: Error in distance between two Points in 2D"); - - } - - // Distance between two points in 3D - Point xx=new Point(3),yy=new Point(3); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** dist: Error in distance between two Points in 3D"); - - } - - // Distance between a Point and a Box in 2D - x.x[0]=0.25; - x.x[1]=0.25; - y.x[0]=0.75; - y.x[1]=0.75; - Box box=new Box(x,y); - for (i=0;i box.hi.x[j]) - dexp[i] += SQR(box.hi.x[j]-x.x[j]); - } - dexp[i]=sqrt(dexp[i]); - d[i]=Box.dist(box,x); - } - sbeps=1.0e-15; - localflag = maxel(vecsub(d,dexp)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** dist: Error in distance between a Point and Box in 2D"); - - } - - // Distance between a Point and a Box in 3D - xx.x[0]=0.25; - xx.x[1]=0.25; - xx.x[2]=0.25; - yy.x[0]=0.75; - yy.x[1]=0.75; - yy.x[2]=0.75; - Box bbox=new Box(xx,yy); - for (i=0;i bbox.hi.x[j]) - dexp[i] += SQR(bbox.hi.x[j]-xx.x[j]); - } - dexp[i]=sqrt(dexp[i]); - d[i]=Box.dist(bbox,xx); - } - sbeps=1.0e-15; - localflag = maxel(vecsub(d,dexp)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** dist: Error in distance between a Point and Box in 3D"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_incircle.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_incircle.java deleted file mode 100644 index 0930533a0a..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_incircle.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.nr.test.test_chapter21; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static com.nr.NRUtil.*; -import static java.lang.Math.*; - -import com.nr.ran.*; - -import com.nr.cg.*; - - -public class Test_incircle { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=1000; - double cx,cy,radius,pio2,result,d,sbeps=4.e-13; - Point a=new Point(2),b=new Point(2),c=new Point(2),test=new Point(2); - double[] theta=new double[3]; - boolean localflag, globalflag=false; - - - - // Test incircle - System.out.println("Testing incircle"); - - // Points on circle at center=(0.5,0.5), radius=0.4 - Ran myran=new Ran(17); - pio2=acos(-1.0); - cx=0.5; - cy=0.5; - radius=0.4; - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** incircle: Incorrect returned value"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_ispolysimple.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_ispolysimple.java deleted file mode 100644 index fcc1d518d1..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter21/Test_ispolysimple.java +++ /dev/null @@ -1,171 +0,0 @@ -package com.nr.test.test_chapter21; - -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.cg.Point; -import com.nr.cg.Polygon; - -public class Test_ispolysimple { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,ntest,N1=14,N2=6,N3=8,N4=8; - // Polygon 1, complex - double x0[]={-1.0,-1.0,1.0,1.0,-0.75,-0.75,0.75,0.75,-0.5,-0.5,0.5,0.5,0.0,0.0}; - double x1[]={0.0,1.0,1.0,-1.0,-1.0,0.75,0.75,-0.75,-0.75,0.5,0.5,-0.5,-0.5,0.0}; - // Polygon 2, simple and convex - double x2[]={-1.0,0.0,1.0,1.0,1.0,0.0}; - double x3[]={0.0,1.0,1.0,0.0,-1.0,-1.0}; - // Polygon 3, simple and concave - double x4[]={-1.0,-0.5,0.0,0.5,1.0,0.5,0.0,-0.5}; - double x5[]={0.0,1.0,0.5,1.0,0.0,-1.0,-0.5,-1.0}; - // Polygon 4, complex - double x6[]={-1.0,-0.5,0.0,0.5,1.0,0.5,0.0,-0.5}; - double x7[]={0.0,1.0,-0.1,1.0,0.0,-1.0,0.1,-1.0}; - Point[] poly1=new Point[N1],poly2=new Point[N2],poly3=new Point[N3],poly4=new Point[N4]; - for(i=0;i6 we get inaccuracy errors below - String s1,s2,s3,s4; - double x1=0,x2=0,x3=0,x4,sbeps; - char[] w =new char[N],u=new char[N],v=new char[N]; - boolean localflag, globalflag=false; - - - - // Test MParith - System.out.println("Testing MParith"); - - Ran myran=new Ran(17); - - // Test mpadd() - System.out.println(" Test mpadd()"); - localflag=false; - sbeps=1.e-15; - char[] w2=new char[N+1]; - for (j=0;j=0;i--) { - x1=x1/256+(int)(u[i]); - x2=x2/256+(int)(v[i]); - } - for (i=N;i>0;i--) - x3=x3/256+(int)(w2[i]); - x3 += 256*(int)(w2[0]); // Note!! w2 is right-shifted by the algorithm -// System.out.printf(x1 << " %f\n", x2 << " %f\n", x3 << " %f\n", abs(1.0-(x1+x2)/x3)); - localflag=localflag || abs(1.0-(x1+x2)/x3) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MParith: Multiple precision addition was inaccurate."); - - } - - // Test mpsub() - System.out.println(" Test mpsub()"); - localflag=false; - sbeps=1.e-14; - for (j=0;j=0;i--) { - x1=x1/256+(int)(u[i]); - x2=x2/256+(int)(v[i]); - x3=x3/256+(int)(w[i]); - } -// System.out.printf(abs(x3-abs(x1-x2))); - localflag=localflag || abs(x3-abs(x1-x2)) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MParith: Multiple precision subtraction was inaccurate."); - - } - - // Test mpsad() - System.out.println(" Test mpsad()"); - localflag=false; - sbeps=1.e-15; - for (j=0;j<=M;j++) { - for (i=0;i=0;i--) { - x1=x1/256+(int)(u[i]); - x2=x2/256+(i==(N-1) ? iv : 0); - } - for (i=N;i>0;i--) { - x3=x3/256+(int)(w2[i]); - } - x3 += 256*(int)(w2[0]); // Note!! w2 is right-shifted by the algorithm -// System.out.printf(abs(1.0-(x2+x1)/x3)); - localflag=localflag || abs(1.0-(x2+x1)/x3) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MParith: Multiple precision short addition was inaccurate."); - - } - - // Test mpsmu() - System.out.println(" Test mpsmu()"); - localflag=false; - sbeps=1.e-15; - for (j=0;j=0;i--) - x1=x1/256+(int)(u[i]); - x2=(int)(iv); - for (i=N;i>0;i--) - x3=x3/256+(int)(w2[i]); - x3 += 256*(int)(w2[0]); // Note!! w2 is right-shifted by the algorithm -// System.out.printf(abs(1.0-x2*x1/x3)); - localflag=localflag || abs(1.0-x2*x1/x3) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MParith: Multiple precision short multiplication was inaccurate."); - - } - - // Test mpsdv() - System.out.println(" Test mpsdv()"); - localflag=false; - sbeps=1.e-14; - for (j=0;j=0;i--) { - x1=x1/256+(int)(u[i]); - x3=x3/256+(int)(w[i]); - x4=x4/256+(i==(N-1) ? (int)(ir) : 0.0); - } - x2=(int)(iv); -// System.out.printf(1.0-(x3*x2+x4)/x1 << " %f\n", x4); - localflag=localflag || abs(1.0-(x3*x2+x4)/x1) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MParith: Multiple precision short division was inaccurate."); - - } - - // Test mpneg() - System.out.println(" Test mpneg()"); - localflag=false; - sbeps=1.e-15; - for (j=0;j=0;i--) { - x1=x1/256+(int)(u[i]); - x2=x2/256+(int)(v[i]); - } -// System.out.printf(x1 << " %f\n", x2 << " %f\n", abs(1.0-(x1+x2)/256.0)); - localflag=localflag || abs(1.0-(x1+x2)/256.0) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MParith: Multiple precision twos-complement negation is inaccurate."); - - } - - // Test mpmov() - System.out.println(" Test mpmov()"); - localflag=false; - for (j=0;j=0;i--) { - x1=x1/256+(int)(u[i]); - x2=x2/256+(int)(v[i]); - } - for (i=2*N-2;i>0;i--) - x3=x3/256+(int)(w3[i]); - x3 += 256*(int)(w3[0]); // w3[] was effectively right shifted to include all digits of result -// System.out.printf(x1 << " %f\n", x2 << " %f\n", x3 << " %f\n", abs(1.0-x1*x2/x3)); - localflag = localflag || abs(1.0-x1*x2/x3) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MParith: Multiple precision long multiplication in inaccurate."); - - } - - // Test mpinv() - System.out.println(" Test mpinv()"); - localflag=false; - sbeps=1.e-14; - for (j=0;j=0;i--) { - x1=x1/256+(int)(v[i]); - x2=x2/256+(int)(u[i]); - } -// System.out.printf(x1 << " %f\n", x2 << " %f\n", abs(x1*x2-1.0)); - localflag = localflag || abs(x1*x2-1.0) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MParith: Multiple precision inverse in inaccurate."); - } - - // Test mpdiv() - System.out.println(" Test mpdiv()"); - localflag=false; - sbeps=1.e-14; - char[] v2=new char[N-2]; - char[] q=new char[3],r=new char[N-2]; - for (j=0;j=0;i--) - x1=x1/256+(int)(u[i]); - for (i=N-3;i>=0;i--) - x2=x2/256+(int)(v2[i]); - for (i=2;i>=0;i--) - x3=x3/256+(int)(q[i]); - for (i=N-3;i>=0;i--) - x4=x4/256+(int)(r[i]); -// System.out.printf(x1 << " %f\n", x2 << " %f\n", x3 << " %f\n", x4 << " %f\n", abs(1.0-x2*x3/x1-(x4/x1/256/256))); - localflag=localflag || abs(1.0-x2*x3/x1-(x4/x1/256/256)) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MParith: Multiple precision long division is inaccurate."); - } - - // Test mpsqrt() - System.out.println(" Test mpsqrt()"); - localflag=false; - sbeps=1.e-14; - for (j=0;j=0;i--) { - x1=x1/256+(int)(v[i]); - x2=x2/256+(int)(w[i]); - x3=x3/256+(int)(u[i]); - } -// System.out.printf(x1 << " %f\n", x2 << " %f\n", x3 << " %f\n", abs(1.0-x2*x2/x1) << " %f\n", abs(1.0-x2*x3)); - localflag = localflag || abs(1.0-x2*x2/x1) > sbeps || abs(1.0-x2*x3) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MParith: Multiple precision square root is inaccurate."); - - } - - // Test mp2dfr() - System.out.println(" Test mp2dfr()"); - x1=0.0; - for (i=0;i=0;i--) - x1=x1/256+(int)(v[i]); - s1=mp2dfr(v); - s1=s1.substring(0, 17); //.erase(17,s1.length()); - String s6 = String.format("%20.18f",x1); - s6=s6.substring(0, 17); - // System.out.println(s1); - // System.out.println(s6); - localflag = (!s1.equals(s6)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MParith: Method mp2dfr() did not produce the correct string"); - - } - - // Test mppi() - System.out.println(" Test mppi()"); - String pi1="3.1415926535897932384626433832795028"; - String pi2="841971693993751058209749445923078164"; - String pi3=pi1+pi2; - s1=mppi(30); -// System.out.printf(s1 << " %f\n", pi3); - localflag = (!s1.equals(pi3)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MParith: method mppi() gives inaccurate value for PI"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter22/Test_Machar.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter22/Test_Machar.java deleted file mode 100644 index 90462ebf26..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter22/Test_Machar.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.nr.test.test_chapter22; - -import static com.nr.NRUtil.DBL_EPSILON; -import static com.nr.NRUtil.DBL_MANT_DIG; -import static com.nr.NRUtil.FLT_RADIX; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.lna.Machar; - -public class Test_Machar { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - boolean localflag=false, globalflag=false; - - - - // Test Machar - System.out.println("Testing Machar"); - - Machar mch=new Machar(); -// mch.report(); - - localflag = mch.ibeta != FLT_RADIX; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Machar: Calculated radix does not agree with numeric_limits"); - - } - - localflag = mch.it != DBL_MANT_DIG; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Machar: Calculated number of mantissa digits does not agree with numeric_limits"); - - } - - /* - localflag = (mch.irnd==5); // && (numeric_limits::round_style != 1); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Machar: Calculated rounding method does not agree with numeric_limits"); - } - */ - - localflag = mch.eps != DBL_EPSILON; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Machar: Calculated smallest step around 1.0 does not agree with numeric_limits"); - - } - - localflag = mch.minexp != Double.MIN_EXPONENT; //numeric_limits::min_exponent; // WHP added +1 - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Machar: Calculated minimum exponent does not agree with numeric_limits"); - - } - - localflag = mch.maxexp != Double.MAX_EXPONENT+1; //numeric_limits::max_exponent; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Machar: Calculated maximum exponent does not agree with numeric_limits"); - - } - - localflag = mch.xmin != Double.MIN_NORMAL; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Machar: Calculated minimum normalized value does not agree with numeric_limits"); - - } - - localflag = mch.xmax != Double.MAX_VALUE; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Machar: Calculated maximum finite value does not agree with numeric_limits"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter22/Test_PSpage.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter22/Test_PSpage.java deleted file mode 100644 index 6cf06dd05c..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter22/Test_PSpage.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.nr.test.test_chapter22; - -import static com.nr.NRUtil.buildVector; - -import java.io.IOException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.lna.PSpage; - -public class Test_PSpage { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() throws IOException { - boolean globalflag=false; - - - - // Test PSpage - System.out.println("Testing PSpage"); - - PSpage pg=new PSpage(new java.io.File("PSpage_output.ps")); - pg.puttext("Hello",100,100,0.0); -// pg.addtext(" World"); - pg.putctext("Hello World",200,100,0.0); - pg.putrtext("Hello World",300,100,0.0); - pg.lineseg(400,100,500,100); - pg.pointsymbol(550,100,72,16.0); - - pg.setlinewidth(3.0); - pg.setdash("4 4"); - pg.puttext("Hello",100,200,90.0); -// pg.addtext(" World"); - pg.putctext("Hello World",200,200,90.0); - pg.putrtext("Hello World",300,200,90.0); - pg.lineseg(400,200,500,200); - pg.pointsymbol(550,200,108,20.0); - - pg.setdash(""); - pg.puttext("Hello",100,300,45.0); -// pg.addtext(" World"); - pg.putctext("Hello World",200,300,45.0); - pg.putrtext("Hello World",300,300,45.0); - pg.lineseg(400,300,500,300); - pg.pointsymbol(550,300,115,20.0); - - pg.gsave(); - pg.setgray(0.7); - pg.puttext("Hello",100,400,45.0); -// pg.addtext(" World"); - pg.putctext("Hello World",200,400,45.0); - pg.putrtext("Hello World",300,400,45.0); - pg.lineseg(400,400,500,400); - pg.pointsymbol(550,400,110,20.0); - - pg.grestore(); - pg.puttext("Hello",100,500,45.0); -// pg.addtext(" World"); - pg.putctext("Hello World",200,500,45.0); - pg.putrtext("Hello World",300,500,45.0); - pg.lineseg(400,500,500,500); - pg.pointsymbol(550,500,112,12.0); - - pg.puttext("Hello",100,600,45.0); - pg.rawps("gsave 200.0 600.0 translate 90.0 rotate 0 0 mt "); - pg.addtext(" World"); - pg.rawps("grestore\n"); - - double xx[]={300.0,350.0,400.0,350.0,300.0}; - double yy[]={650.0,650.0,600.0,550.0,550.0}; - double[] x=buildVector(xx),y=buildVector(yy); - pg.polyline(x,y,true,false,false); - - pg.setcolor(255,0,0); - double xx2[]={450.0,500.0,550.0,500.0,450.0}; - double yy2[]={650.0,650.0,600.0,550.0,550.0}; - double[] x2=buildVector(xx2),y2=buildVector(yy2); - pg.polyline(x2,y2,true,true,false); - - pg.close(); - // pg.display(); - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter22/Test_PSplot.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter22/Test_PSplot.java deleted file mode 100644 index 79571fdc4b..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter22/Test_PSplot.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.nr.test.test_chapter22; - -import static com.nr.NRUtil.SQR; -import static java.lang.Math.cos; -import static java.lang.Math.exp; -import static java.lang.Math.sin; -import static java.lang.Math.sqrt; - -import java.io.IOException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.lna.PSpage; -import com.nr.lna.PSplot; - -public class Test_PSplot { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() throws IOException{ - double[] x1=new double[500],x2=new double[500],y1=new double[500],y2=new double[500],y3=new double[500],y4=new double[500]; - boolean globalflag=false; - - - - // Test PSplot - System.out.println("Testing PSplot"); - - for (int i=0;i<500;i++) { - x1[i] = 5.*i/499.; - y1[i] = exp(-0.5*x1[i]); - y2[i] = exp(-0.5*SQR(x1[i])); - y3[i] = exp(-0.5*sqrt(5.-x1[i])); - x2[i] = cos(0.062957*i); - y4[i] = sin(0.088141*i); - } - - PSpage pg=new PSpage(new java.io.File("PSplot_output.ps")); - PSplot plot1=new PSplot(pg,100.,500.,100.,500.); - - plot1.setlimits(0.,5.,0.,1.); - plot1.frame(); - plot1.autoscales(); - plot1.xlabel("abscissa"); - plot1.ylabel("ordinate"); - plot1.lineplot(x1,y1); - plot1.setdash("2 4"); - plot1.lineplot(x1,y2); - plot1.setdash("6 2 4 2"); - plot1.lineplot(x1,y3); - plot1.setdash(""); - - plot1.pointsymbol(1.,exp(-0.5),72,16.); - plot1.pointsymbol(2.,exp(-1.),108,12.); - plot1.pointsymbol(2.,exp(-2.),115,12.); - plot1.label("dingbat 72",1.1,exp(-0.5)); - plot1.label("dingbat 108",2.1,exp(-1.)); - plot1.label("dingbat 115",2.1,exp(-2.)); - - PSplot plot2=new PSplot(pg,325.,475.,325.,475.); - plot2.clear(); - plot2.setlimits(-1.2,1.2,-1.2,1.2); - plot2.frame(); - plot2.scales(1.,0.5,1.,0.5); - plot2.lineplot(x2,y4); - - pg.close(); - // pg.display(); - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter22/Test_decchk.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter22/Test_decchk.java deleted file mode 100644 index 56626b6427..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter22/Test_decchk.java +++ /dev/null @@ -1,201 +0,0 @@ -package com.nr.test.test_chapter22; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static com.nr.lna.Icrc.*; -public class Test_decchk { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,k,nbad,ntot,N=7; - byte[] ch = new byte[1]; - boolean localflag=false, globalflag=false; - - - - // Test decchk - System.out.println("Testing decchk"); - - byte[] s1="8635741".getBytes(); - byte[] s2="0".getBytes(); - byte[] s3; - - // Test for functionality of the check digit - ntot=nbad=0; - for (i=0;i 86jki41 where i != j - ntot=nbad=0; - for (i='0';i<='9';i++) { - for (j='0';j<='9';j++) { - for (k='0';k<='9';k++) { - s3=new String(s1).getBytes(); - s3[3]=(byte)k; - if (i != j) { - ntot++; - s3[2]=(byte)i; - s3[4]=(byte)j; - decchk(s3,s2,0); - s3=(new String(s3)+new String(s2)).getBytes(); - s3[2]=(byte)j; // Transpose digits - s3[4]=(byte)i; - if (!decchk(s3,ch,0)) nbad++; // See if it works with transposition - } - } - } - } -// System.out.println("Jump Transitions:"); -// System.out.println(" Total tries:%f\n", " %f\n", ntot); -// System.out.println(" Bad tries:%f\n", " %f\n", nbad); - localflag = localflag || (nbad != 848); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** decchk: Failure to identify 848 of the possible 900 Jump Transition errors"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_BaryRat_interp.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_BaryRat_interp.java deleted file mode 100644 index 457479e841..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_BaryRat_interp.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.nr.test.test_chapter3; - -import static com.nr.test.NRTestUtil.*; -import static java.lang.Math.*; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.interp.BaryRat_interp; -import com.nr.ran.Ran; - -public class Test_BaryRat_interp { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - double func_BaryRat(double x) - { - return (1.0-x*(0.5-0.1*x))/(1.0+(x-2.0)*(x-2.0)); - } - - @Test - public void test() { - int i,j,N=20,M=6; - double ymax,dy,sbeps; - double[] x=new double[N],y=new double[N],xx=new double[N],yy=new double[N],zz=new double[N]; - boolean localflag, globalflag=false; - - - - // Test BaryRat_interp - System.out.println("Testing BaryRat_interp"); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** BaryRat_interp: Inaccurate interpolation of rational function."); - - } - } - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Bilin_interp.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Bilin_interp.java deleted file mode 100644 index eb5f1eb3dd..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Bilin_interp.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.nr.test.test_chapter3; - -import static com.nr.test.NRTestUtil.*; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.interp.Bilin_interp; -import com.nr.ran.Ran; - -public class Test_Bilin_interp { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps,xx1,xx2; - int i,j,N=20; - double[] x1=new double[N],x2=new double[N],yy=new double[N],zz=new double[N]; - double[][] y = new double[N][N]; - boolean localflag, globalflag=false; - - - - // Test Bilin_interp - System.out.println("Testing Bilin_interp"); - for(i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bilin_interp: Inaccurate interpolation of 2D linear function."); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Curve_interp.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Curve_interp.java deleted file mode 100644 index 1a8612b5a9..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Curve_interp.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.nr.test.test_chapter3; - -import static com.nr.NRUtil.*; -import static com.nr.test.NRTestUtil.*; -import static java.lang.Math.*; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.interp.Curve_interp; - -public class Test_Curve_interp { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps; - int i,NDIM=3,NPTS=20; - boolean close; - double vec[]={2.0/sqrt(29.0),3.0/sqrt(29.0),4.0/sqrt(29.0)}; - double[] target = new double[NDIM]; - double[][] ptsin = new double[NPTS][NDIM]; - boolean localflag, globalflag=false; - - - - // Test Curve_interp - System.out.println("Testing Curve_interp"); - - // Test straight line - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Curve_interp: Does not work for data on a 3D straight line."); - - } - - // Test closed circle - double a[]={0.0,vec[2],-vec[1]}; // vec x (1,0,0) - double norm=sqrt(SQR(vec[2])+SQR(vec[1])); // normalize a[] - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Curve_interp: Does not work for data on a 3D circle."); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Krig.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Krig.java deleted file mode 100644 index 8444ccefa6..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Krig.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.nr.test.test_chapter3; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.cos; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.interp.Krig; -import com.nr.interp.Powvargram; -import com.nr.ran.Ran; - -public class Test_Krig { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,k,NPTS=100,NDIM=2,N=10,M=10; - double sbeps=0.01; // p=5.0, - double[][] pts = new double[NPTS][NDIM]; - double[] y = new double[NPTS],actual = new double[M],estim = new double[M],ppt = new double[2]; - boolean localflag, globalflag=false; - - - - // Test Krig (and Powvargram) - System.out.println("Testing Krig (and Powvargram)"); - Ran myran = new Ran(17); - double[][] pt = new double[M][2]; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Krig, Powvargram: Inaccurate Krig interpolation."); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Laplace_interp.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Laplace_interp.java deleted file mode 100644 index 797343cef9..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Laplace_interp.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.nr.test.test_chapter3; - -import static com.nr.NRUtil.*; -import static com.nr.test.NRTestUtil.*; -import static java.lang.Math.*; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.interp.Laplace_interp; -import com.nr.ran.Ran; - -public class Test_Laplace_interp { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,p,q,N=100,M=100,NBAD=1000; - double sbeps=0.01; - double[][] actual = new double[N][M]; - boolean localflag, globalflag=false; - - - - // Test Laplace_interp - System.out.println("Laplace_interp"); - Ran myran = new Ran(17); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Laplace_interp: Inaccurate Laplace interpolation of missing matrix data."); - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Linear_interp.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Linear_interp.java deleted file mode 100644 index caf3f1c153..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Linear_interp.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.nr.test.test_chapter3; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.interp.Linear_interp; -import com.nr.ran.Ran; - -public class Test_Linear_interp { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps=5.e-15; - int i,N=10; - double[] x=new double[N],y=new double[N],xx=new double[N],yy=new double[N],zz=new double[N]; - boolean localflag, globalflag=false; - - - - // Test Linear_interp - System.out.println("Testing Linear_interp"); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Linear_interp: interpolation of linear function unsuccessful."); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Poly2D_interp.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Poly2D_interp.java deleted file mode 100644 index 5820d43dfc..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Poly2D_interp.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.nr.test.test_chapter3; - -import static com.nr.NRUtil.buildVector; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.interp.Poly2D_interp; - -public class Test_Poly2D_interp { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps=5.e-15; - int i,j; - double xx1[]={1.0,2.0,3.0,4.0},xx2[]={1.0,2.0,3.0,4.0}; - double[] x1 = buildVector(xx1),x2 = buildVector(xx2); - double[][] y = new double[4][4]; - for(i=0;i<4;i++) for(j=0;j<4;j++) y[i][j]=xx1[i]+xx2[j]; - boolean localflag, globalflag=false; - - - - // Test Poly2D_interp - System.out.println("Testing Poly2D_interp"); - Poly2D_interp z = new Poly2D_interp(x1,x2,y,3,3); - localflag = abs(z.interp(2.5,2.5)-5.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Poly2D_interp: Inaccurate 2D polynomial interpolation."); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Poly_interp.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Poly_interp.java deleted file mode 100644 index ae2063fad4..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Poly_interp.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.nr.test.test_chapter3; - -import static com.nr.test.NRTestUtil.*; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.interp.Poly_interp; -import com.nr.ran.Ran; - -public class Test_Poly_interp { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps; - int i,N=20; - double[] x= new double[N],y= new double[N],xx= new double[N],yy= new double[N],zz= new double[N],dyy= new double[N]; - boolean localflag, globalflag=false; - - - - // Test Poly_interp - System.out.println("Testing Poly_interp"); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Poly_interp: interpolation of 4th-order polynomial unsuccessful."); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_RBF_interp.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_RBF_interp.java deleted file mode 100644 index 1f805216f0..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_RBF_interp.java +++ /dev/null @@ -1,193 +0,0 @@ -package com.nr.test.test_chapter3; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.cos; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.interp.RBF_gauss; -import com.nr.interp.RBF_interp; -import com.nr.interp.RBF_inversemultiquadric; -import com.nr.interp.RBF_multiquadric; -import com.nr.interp.RBF_thinplate; -import com.nr.ran.Ran; - -public class Test_RBF_interp { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,k,NPTS=100,NDIM=2,N=10,M=10; - double scale,sbeps=0.05; - double[][] pts =new double[NPTS][NDIM]; - double[] y = new double[NPTS],actual = new double[M],estim = new double[M],ppt = new double[2]; - boolean localflag, globalflag=false; - - - - // Test RBF_interp - Ran myran = new Ran(17); - double[][] pt = new double[M][2]; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** RBF_interp,multiquadric: Inaccurate multquadric interpolation with no normalization."); - - } - - System.out.println("Testing RBF_interp with thinplate function"); - scale=2.0; - RBF_thinplate thinplate = new RBF_thinplate(scale); - RBF_interp myRBFtpf = new RBF_interp(pts,y,thinplate,false); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** RBF_interp,thinplate: Inaccurate thinplate interpolation with no normalization."); - - } - - System.out.println("Testing RBF_interp with gauss function"); - scale=5.0; - RBF_gauss gauss = new RBF_gauss(scale); - RBF_interp myRBFgf = new RBF_interp (pts,y,gauss,false); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** RBF_interp,gauss: Inaccurate gauss interpolation with no normalization."); - - } - - System.out.println("Testing RBF_interp with inversemultiquadric function"); - scale=3.0; - RBF_inversemultiquadric inversemultiquadric = new RBF_inversemultiquadric(scale); - RBF_interp myRBFimqf =new RBF_interp(pts,y,inversemultiquadric,false); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** RBF_interp,inversemultiquadric: Inaccurate inversemultiquadric interpolation with no normalization."); - - } - - // Test same interpolators with normalization turned on - scale=3.0; - System.out.println("Testing RBF_interp with multiquadric function"); - RBF_interp myRBFmqt = new RBF_interp(pts,y,multiquadric,true); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** RBF_interp,multiquadric: Inaccurate multiquadric interpolation with normalization."); - - } - - System.out.println("Testing RBF_interp with thinplate function"); - scale=2.0; - RBF_interp myRBFtpt =new RBF_interp(pts,y,thinplate,true); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** RBF_interp,thinplate: Inaccurate thinplate interpolation with normalization."); - - } - - System.out.println("Testing RBF_interp with gauss function"); - scale=5.0; - RBF_interp myRBFgt = new RBF_interp(pts,y,gauss,true); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** RBF_interp,gauss: Inaccurate gauss interpolation with normalization."); - - } - - System.out.println("Testing RBF_interp with inversemultiquadric function"); - scale=2.0; - RBF_interp myRBFimqt = new RBF_interp(pts,y,inversemultiquadric,true); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** RBF_interp,inversemultiquadric: Inaccurate inversemultiquadric interpolation with normalization."); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Rat_interp.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Rat_interp.java deleted file mode 100644 index c531b0fec8..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Rat_interp.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.nr.test.test_chapter3; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.interp.Rational_interp; -import com.nr.ran.Ran; - -public class Test_Rat_interp { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps; - int i,N=20; - double[] x= new double[N],y= new double[N],xx= new double[N],yy= new double[N],zz= new double[N],dyy= new double[N]; - boolean localflag, globalflag=false; - - - - // Test Rat_interp - System.out.println("Testing Rat_interp"); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Rat_interp: Inaccurate interpolation of rational function."); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Shep_interp.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Shep_interp.java deleted file mode 100644 index f0741ecce5..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Shep_interp.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.nr.test.test_chapter3; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.cos; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.interp.Shep_interp; -import com.nr.ran.Ran; - -public class Test_Shep_interp { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,k,NPTS=100,NDIM=2,N=10,M=10; - double p=5.0,sbeps=0.05; - double[][] pts = new double[NPTS][NDIM]; - double[] y = new double[NPTS],actual = new double[M],estim = new double[M],ppt = new double[2]; - boolean localflag, globalflag=false; - - - - // Test Shep_interp - System.out.println("Testing Shep_interp"); - Ran myran = new Ran(17); - double[][] pt = new double[M][2]; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Shepard: Inaccurate Shepard interpolation."); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Spline2D_interp.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Spline2D_interp.java deleted file mode 100644 index fec8a4d14b..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Spline2D_interp.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.nr.test.test_chapter3; - -import static com.nr.NRUtil.buildVector; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.interp.Spline2D_interp; - -public class Test_Spline2D_interp { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps=5.e-15; - int i,j; - double xx1[]={1.0,2.0,3.0,4.0},xx2[]={1.0,2.0,3.0,4.0}; - double[] x1 = buildVector(xx1),x2 = buildVector(xx2); - double[][] y =new double[4][4]; - boolean localflag, globalflag=false; - - - - // Test Spline2D_interp - System.out.println("Testing Spline2D_interp"); - for(i=0;i<4;i++) - for(j=0;j<4;j++) - y[i][j]=xx1[i]+xx2[j]; - Spline2D_interp z = new Spline2D_interp(x1,x2,y); - localflag = abs(z.interp(2.5,2.5)-5.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Spline2D_interp: ."); - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Spline_interp.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Spline_interp.java deleted file mode 100644 index 522b930477..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_Spline_interp.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.nr.test.test_chapter3; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.acos; -import static java.lang.Math.sin; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.interp.Spline_interp; -import com.nr.ran.Ran; - -public class Test_Spline_interp { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps; - int i,N=20; - double yp1,ypn,pi; - double[] x= new double[N],y= new double[N],xx= new double[N],yy= new double[N],zz= new double[N]; - boolean localflag, globalflag=false; - - - - // Test Spline_interp - System.out.println("Testing Spline_interp"); - pi=acos(-1.0); - for(i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Spline_interp: Inaccurate interpolation of sin() function."); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_bcuint.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_bcuint.java deleted file mode 100644 index a67e717567..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_bcuint.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.nr.test.test_chapter3; - -import static com.nr.NRUtil.*; -import static com.nr.interp.Spline2D_interp.bcuint; -import static com.nr.test.NRTestUtil.*; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -public class Test_bcuint { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i; // N=10; - double x1l,x1u,x2l,x2u,uv,sbeps=1.e-16; - double u[]={0.0,0.5,0.5,0.0}; - double v[]={0.0,0.0,0.5,0.5}; - double[] yy=new double[4],yy1=new double[4],yy2=new double[4],yy12=new double[4]; - boolean localflag, globalflag=false; - - - - // Test bcucof and bcuint - System.out.println("Testing bcucof and bcuint"); - x1l=u[0]; - x1u=u[1]; - x2l=v[0]; - x2u=v[3]; - for (i=0;i<4;i++) { - uv=u[i]*v[i]; - yy[i]=uv*uv; - yy1[i]=2.0*v[i]*uv; - yy2[i]=2.0*u[i]*uv; - yy12[i]=4.0*uv; - } - double[] y = buildVector(yy),y1 = buildVector(yy1),y2 = buildVector(yy2),y12 = buildVector(yy12); - double x1[]={0.1,0.2,0.3,0.4,0.5}; - double x2[]={0.2,0.4,0.1,0.3,0.3}; - double act[]={0.0004,0.0064,0.0009,0.0144,0.0225}; - double[] ansy=new double[5],ansy1=new double[5],ansy2=new double[5]; - for (i=0;i<5;i++) { - doubleW ansyW = new doubleW(ansy[i]); - doubleW ansy1W = new doubleW(ansy1[i]); - doubleW ansy2W = new doubleW(ansy2[i]); - - bcuint(y,y1,y2,y12,x1l,x1u,x2l,x2u,x1[i],x2[i],ansyW,ansy1W,ansy2W); - ansy[i] = ansyW.val; - ansy1[i] = ansy1W.val; - ansy2[i] = ansy2W.val; - } - - double[] actual = buildVector(act),answer=buildVector(ansy); - localflag = maxel(vecsub(actual,answer)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** bcucof,bcuint: Inaccurate bicubic interpolation."); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_polcoe.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_polcoe.java deleted file mode 100644 index e7753bcbe9..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_polcoe.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.nr.test.test_chapter3; - -import static com.nr.test.NRTestUtil.*; -import static com.nr.interp.PolCoef.*; -import static java.lang.Math.*; -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class Test_polcoe { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double pi,sbeps; - int i,j,N=10; - double[] x= new double[N],y= new double[N],z= new double[N]; - double[] cof= new double[N]; - boolean localflag, globalflag=false; - - - - // Test Linear_interp - System.out.println("Testing polcoe"); - pi=acos(-1.0); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** polcoe: Inaccurate polynomial approximation of sin() function."); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_polcof.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_polcof.java deleted file mode 100644 index 1221e90a9f..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter3/Test_polcof.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.nr.test.test_chapter3; - -import static com.nr.test.NRTestUtil.*; -import static com.nr.interp.PolCoef.*; -import static java.lang.Math.*; -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class Test_polcof { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double pi,sbeps; - int i,j,N=10; - double[] x= new double[N],y= new double[N],cof= new double[N],z= new double[N]; - boolean localflag, globalflag=false; - - - - // Test Linear_interp - System.out.println("Testing polcof"); - pi=acos(-1.0); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** polcof: ."); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_Adapt.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_Adapt.java deleted file mode 100644 index 53755f64e9..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_Adapt.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.fi.Adapt; -import com.nr.sf.Bessjy; - -public class Test_Adapt { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=10; - double x1,x2,sbeps=1.e-14; - double[] y= new double[N],yy= new double[N]; - boolean localflag, globalflag=false; - - // Test Adapt - System.out.println("Testing Adapt"); - Bessj0_Adapt bj0 = new Bessj0_Adapt(); - Bessj1_Adapt bj1 = new Bessj1_Adapt(); - Adapt adp = new Adapt(0.0); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Adapt: Failure to achieve advertised accuracy in integral"); - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Bessj0_Adapt implements UniVarRealValueFun{ - public double funk (double x) { - Bessjy b = new Bessjy(); - return(b.j0(x)); - } - }; - - class Bessj1_Adapt implements UniVarRealValueFun{ - public double funk (double x) { - Bessjy b = new Bessjy(); - return(b.j1(x)); - } - }; - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_Stiel.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_Stiel.java deleted file mode 100644 index 60f1c4cae9..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_Stiel.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.fi.GaussianWeights.gaulag; -import static com.nr.fi.GaussianWeights.gauleg; -import static com.nr.sort.Sorter.sort2; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.exp; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.fi.Stiel; - -public class Test_Stiel { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int N=10; - double sbeps; - double[] x1= new double[N],w1= new double[N],x2= new double[N],w2= new double[N]; - boolean localflag, globalflag=false; - - - - // Test Stiel - System.out.println("Testing Stiel"); - - MyStiel ss1 = new MyStiel(N,-1.0,1.0,3.7); - ss1.get_weights(x1,w1); // Largest abscissas are first - sort2(x1,w1); - - gauleg(-1.0,1.0,x2,w2); - - sbeps=1.e-15; -// System.out.printf(maxel(vecsub(x1,x2)) << endl; - localflag = maxel(vecsub(x1,x2)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Stiel: Incorrect abscissas for Gauss-Legendre"); - - } - - sbeps=1.e-14; -// System.out.printf(maxel(vecsub(w1,w2)) << endl; - localflag = maxel(vecsub(w1,w2)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Stiel: Incorrect weights for Gauss-Legendre"); - - } - - MyStiel ss2 = new MyStiel(N,-5.0,5.0); - ss2.get_weights(x1,w1); - sort2(x1,w1); - - gaulag(x2,w2,1.0); - - sbeps=5.e-14; -// System.out.printf(maxel(vecsub(x1,x2)) << endl; - localflag = maxel(vecsub(x1,x2)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Stiel: Incorrect abscissas for Gauss-Laguerre"); - - } - - sbeps=1.e-14; -// System.out.printf(maxel(vecsub(w1,w2)) << endl; - localflag = maxel(vecsub(w1,w2)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Stiel: Incorrect weights for Gauss-Laguerre"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class MyStiel extends Stiel { - - public MyStiel(int nn, double aaa, double bbb) { - super(nn, aaa, bbb); - } - - public MyStiel(final int nn, final double aaa, final double bbb, - final double hmaxx) { - super(nn, aaa, bbb, hmaxx); - } - - @Override - public double wt1(final double x, final double del) { - return 1.0; // Gauss-Legendre - } - - @Override - public double wt2(final double x) { - return x * exp(-x); - } - - @Override - public double fx(final double t) { - return exp(t - exp(-t)); - } - - @Override - public double fdxdt(final double t) { - double s = exp(-t); - return exp(t - s) * (1.0 + s); - } - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_derule.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_derule.java deleted file mode 100644 index 2c8b899648..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_derule.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.nr.test.test_chapter4; - -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.log; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.RealValueFun; -import com.nr.fi.DErule; - -public class Test_derule { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,M=10; - double PI=acos(-1.0); // ,INFTY=1.0e99; - double a,b,s=0,sold,expect,sbeps; - boolean localflag, globalflag=false; - - // Test DErule - System.out.println("Testing DErule"); - - a=0.0; - b=1.0; - func_DErule func_DErule = new func_DErule(); - DErule derule = new DErule(func_DErule,a,b); - expect=2.0-PI*PI/6.0; - - sold=derule.next(); - sbeps=1.e-15; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** DErule,case 2: Failure to achieve expected accuracy in improper integral"); - - } - - a=0.0; - b=1.0; - - func_DErule2 func_DErule2 = new func_DErule2(); - DErule derule2 = new DErule(func_DErule2,a,b,4.5); - expect=PI; - - sold=derule2.next(); - sbeps=1.e-15; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** DErule,case 2: Failure to achieve expected accuracy in improper integral"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - //Test functions - class func_DErule implements RealValueFun { - public double funk(double[] x) {//final double x, final double delta) - return log(x[0])*log(1.0-x[0]); - } - } - - class func_DErule2 implements RealValueFun { - public double funk(final double[] xx) { //final double x, final double delta) - double x = xx[0], delta = xx[1]; - if (x < 0.1) return (1.0/sqrt(delta)/sqrt(1.0-x)); - else if (x > 0.9) return (1.0/sqrt(x)/sqrt(delta)); - else return (1.0/sqrt(x)/sqrt(1.0-x)); - } - } - - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_gaucof.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_gaucof.java deleted file mode 100644 index 9fedbfc557..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_gaucof.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.fi.GaussianWeights.gaucof; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class Test_gaucof { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=10; - double amu0,check,PI=acos(-1.0),sbeps; - double[] a= new double[N],b= new double[N],x= new double[N],w= new double[N]; - boolean localflag, globalflag=false; - - // Test gaucof - System.out.println("Testing gaucof"); - - // Test with Gauss-Hermite - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** gaucof: Gaussian weights do not sum to correct value"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_gauher.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_gauher.java deleted file mode 100644 index e86942318f..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_gauher.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.NRUtil.SQR; -import static com.nr.fi.GaussianWeights.gauher; -import static com.nr.fi.Trapzd.qsimp; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.exp; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.sf.Bessjy; - -public class Test_gauher { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,k,N=8,M=20; - double val,sbeps=1.e-14; - double[] y= new double[N],yy= new double[N],x = new double[M],w = new double[M]; - boolean localflag, globalflag=false; - - // Test gauher - System.out.println("Testing gauher"); - Bessjn_gauher bjn = new Bessjn_gauher(); - gauher(x,w); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** gauher: Failure to achieve accurate integral"); - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Bessjn_gauher { - double get(int n,double x) { - Bessjy b = new Bessjy(); - return(b.jn(n,x)); - } - }; - - class Func_gauher implements UniVarRealValueFun { - int n; - - Func_gauher(int nn) {n = nn;} - - public double funk (double x) { - Bessjn_gauher bjn = new Bessjn_gauher() ; - return(exp(-SQR(x))*bjn.get(n,x)); - } - }; - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_gaujac.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_gaujac.java deleted file mode 100644 index 71cd339061..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_gaujac.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.fi.GaussianWeights.gaujac; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.sf.Bessjy; - -public class Test_gaujac { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=8,M=20; - double alfa,beta,val,sbeps=1.e-11; - double[] y= new double[N],yy= new double[N],x= new double[M],w= new double[M]; - boolean localflag, globalflag=false; - - // Test gaujac - System.out.println("Testing gaujac"); - Bessj0_gaujac bj0 = new Bessj0_gaujac(); - Bessj1_gaujac bj1 = new Bessj1_gaujac(); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** gaujac: Failure to achieve accurate integral"); - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Bessj0_gaujac implements UniVarRealValueFun{ - public double funk (double x) { - Bessjy b = new Bessjy(); - return(b.j0(x)); - } - }; - - class Bessj1_gaujac implements UniVarRealValueFun{ - public double funk (double x) { - Bessjy b = new Bessjy(); - return(b.j1(x)); - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_gaulag.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_gaulag.java deleted file mode 100644 index 060f95ad3f..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_gaulag.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.fi.GaussianWeights.gaulag; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.sf.Bessjy; - -public class Test_gaulag { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=8,M=20; - double alf,val,sbeps=1.e-8; - double[] y= new double[N],yy= new double[N],x= new double[M],w= new double[M]; - boolean localflag, globalflag=false; - - - - // Test gaulag - System.out.println("Testing gaulag"); - Bessj0_gaulag bj0 = new Bessj0_gaulag(); - Bess_sum bs = new Bess_sum(); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** gaulag: Failure to achieve accurate integral"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - class Bessj0_gaulag implements UniVarRealValueFun{ - public double funk(double x) { - Bessjy b = new Bessjy(); - return(b.j0(x)); - } - }; - - class Bessj1_gaulag implements UniVarRealValueFun{ - public double funk (double x) { - Bessjy b= new Bessjy(); - return(b.j1(x)); - } - }; - - class Bess_sum implements UniVarRealValueFun{ - public double funk(double x) { - Bessj0_gaulag b0 = new Bessj0_gaulag(); - Bessj1_gaulag b1 = new Bessj1_gaulag(); - return(b0.funk(x)+b1.funk(x)); - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_gauleg.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_gauleg.java deleted file mode 100644 index 4b813d4729..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_gauleg.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.fi.GaussianWeights.gauleg; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.sf.Bessjy; - -public class Test_gauleg { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=10,M=10; - double x1,x2,val,sbeps=51.e-14; - double[] y= new double[N],yy= new double[N],x= new double[M],w= new double[M]; - boolean localflag, globalflag=false; - - - - // Test gauleg - System.out.println("Testing gauleg"); - Bessj0_gauleg bj0 = new Bessj0_gauleg(); - Bessj1_gauleg bj1 = new Bessj1_gauleg(); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** gauleg: Failure to achieve accurate integral"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - class Bessj0_gauleg implements UniVarRealValueFun{ - public double funk (double x) { - Bessjy b=new Bessjy(); - return(b.j0(x)); - } - }; - - class Bessj1_gauleg implements UniVarRealValueFun{ - public double funk (double x) { - Bessjy b =new Bessjy(); - return(b.j1(x)); - } - }; -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_lobatto.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_lobatto.java deleted file mode 100644 index 946ecba52d..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_lobatto.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.fi.GaussianWeights.lobatto; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class Test_lobatto { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=10; - double amu0,check,sbeps,PI=acos(-1.0); - double[] a= new double[N],b= new double[N],x= new double[N],w= new double[N]; - boolean localflag, globalflag=false; - - - - // Test lobatto - System.out.println("Testing lobatto"); - // Test with Gauss-Chebyshev - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** lobatto: Gaussian quadrature weights to not add to the correct value"); - - } - - sbeps=1.e-15; -// System.out.printf(abs(x[0]-1.0) << endl; - localflag = abs(x[0]-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** lobatto: First element of x[] is not the requested value of 1.0"); - - } - - sbeps=1.e-15; -// System.out.printf(abs(x[N-1]+1.0) << endl; - localflag = abs(x[N-1]+1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** lobatto: Last element of x[] is not the requested value of -1.0"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_midexp.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_midexp.java deleted file mode 100644 index 75f89f1a7e..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_midexp.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.fi.Midpnt.qromo; -import static java.lang.Math.abs; -import static java.lang.Math.exp; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.fi.Midexp; - -public class Test_midexp implements UniVarRealValueFun{ - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - // int i,j,M=14; - double INFTY=1.e99; - double a,b,s,expect,eps=3.0e-10,sbeps=1.e-6; - boolean localflag, globalflag=false; - - - - // Test midexp - System.out.println("Testing midexp"); - - a=1.0; - b=INFTY; - Midexp midexp = new Midexp(this,a,b); - s=qromo(midexp,eps); - - expect=2.0/exp(1.0); - -// System.out.printf(s << " %f\n", expect << endl; - - System.out.printf("midexp: Maximum discrepancy = %f\n", abs(s-expect)); - localflag = abs(s-expect) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** midexp: Failure to achieve expected accuracy in improper integral"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - //Test function - public double funk(final double x) { - return x*exp(-x); - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_midinf.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_midinf.java deleted file mode 100644 index ec0a83972c..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_midinf.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.fi.Midpnt.qromo; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.exp; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.fi.Midinf; - -public class Test_midinf { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - // int i,j,M=14; - double INFTY=1.e20,PI=acos(-1.0); - double a,b,s1,s2,expect,sbeps=1.e-6; - boolean localflag, globalflag=false; - - - - // Test midinf - System.out.println("Testing midinf"); - - expect=sqrt(PI)/2.0/exp(1.0); - - a=-INFTY; - b=-1.0; - func_midinf1 func_midinf1 =new func_midinf1(); - Midinf midinf1 = new Midinf(func_midinf1,a,b); - s1=qromo(midinf1); - - System.out.printf("midinf,case 1: Maximum discrepancy = %f\n", abs(s1-expect)); - localflag = abs(s1-expect) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** midinf,case 1: Failure to achieve expected accuracy in improper integral"); - - } - - a=1.0; - b=INFTY; - func_midinf2 func_midinf2 = new func_midinf2(); - Midinf midinf2 = new Midinf(func_midinf2,a,b); - s2=qromo(midinf2); - - System.out.printf("midinf,case 2: Maximum discrepancy = %f\n", abs(s2-expect)); - localflag = abs(s2-expect) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** midinf,case 2: Failure to achieve expected accuracy in improper integral"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - // Test function - class func_midinf1 implements UniVarRealValueFun { - public double funk(final double x) { - return sqrt(-x - 1) * exp(x); - } - } - - class func_midinf2 implements UniVarRealValueFun { - public double funk(final double x) { - return sqrt(x - 1) * exp(-x); - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_midpnt.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_midpnt.java deleted file mode 100644 index ea564514cb..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_midpnt.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.nr.test.test_chapter4; - -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.cos; -import static java.lang.Math.sin; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.fi.Midpnt; - -public class Test_midpnt { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int j,M=14; - double a,b,s=0,expect,PI=acos(-1.0),sbeps=1.e-10; - boolean localflag, globalflag=false; - - - - // Test midpnt - System.out.println("Testing midpnt"); - -// a=0.0; -// b=1.0; - a=0.0; - b=PI; - func_midpnt func_midpnt = new func_midpnt(); - Midpnt mpt = new Midpnt(func_midpnt,a,b); - - for (j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** midpnt: Failure to achieve expected accuracy in improper integral"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class func_midpnt implements UniVarRealValueFun { - public double funk(final double x) { - return sin(x); - } - } - - //integral of test function - double fint_midpnt(final double x) - { - return -cos(x); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_midsql.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_midsql.java deleted file mode 100644 index 0b1674f89d..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_midsql.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.fi.Midpnt.qromo; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.fi.Midsql; - -public class Test_midsql implements UniVarRealValueFun{ - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - // int i,j,M=14; - double PI=acos(-1.0); - double a,b,s,sbeps=1.e-10; // expect - boolean localflag, globalflag=false; - - - - // Test Nidsql - System.out.println("Testing Midsql"); - - a=0.0; - b=0.5; - Midsql msql = new Midsql(this,a,b); - s=qromo(msql); - -// System.out.printf(s << endl; - - System.out.printf("Midsql: Maximum discrepancy = %f\n", abs(s-PI/2.0)); - localflag = abs(s-PI/2.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Midsql: Failure to achieve expected accuracy in improper integral"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - // Test function - public double funk(final double x) { - return 1.0 / sqrt(x) / sqrt(1.0 - x); - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_midsqu.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_midsqu.java deleted file mode 100644 index 0b9d72d091..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_midsqu.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.fi.Midpnt.qromo; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.fi.Midsqu; - -public class Test_midsqu implements UniVarRealValueFun{ - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - // int i,j,M=14; - double PI=acos(-1.0); - double a,b,s,sbeps=1.e-10; //expect - boolean localflag, globalflag=false; - - - - // Test midsqu - System.out.println("Testing midsqu"); - - a=0.5; - b=1.0; - Midsqu midsqu = new Midsqu(this,a,b); - s=qromo(midsqu); - -// System.out.printf(s << endl; - - System.out.printf("midsqu: Maximum discrepancy = %f\n", abs(s-PI/2.0)); - localflag = abs(s-PI/2.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** midsqu: Failure to achieve expected accuracy in improper integral"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - // Test function - public double funk(final double x) { - return 1.0 / sqrt(x) / sqrt(1.0 - x); - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_qgaus.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_qgaus.java deleted file mode 100644 index ad1f56fe4b..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_qgaus.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.fi.GaussianWeights.qgaus; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.sf.Bessjy; - -public class Test_qgaus { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=10; - double x1,x2,sbeps=5.e-15; - double[] y= new double[N],yy= new double[N]; - boolean localflag, globalflag=false; - - - - // Test qgaus - System.out.println("Testing qgaus"); - Bessj0_qgaus bj0 = new Bessj0_qgaus(); - Bessj1_qgaus bj1 = new Bessj1_qgaus(); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** qgaus: Failure to achieve accurate integral"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - class Bessj0_qgaus implements UniVarRealValueFun{ - public double funk(double x) { - Bessjy b = new Bessjy(); - return(b.j0(x)); - } - }; - - class Bessj1_qgaus implements UniVarRealValueFun{ - public double funk(double x) { - Bessjy b = new Bessjy(); - return(b.j1(x)); - } - }; -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_qromb.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_qromb.java deleted file mode 100644 index 3b94a9ac65..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_qromb.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.fi.Trapzd.qromb; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.sf.Bessjy; - -public class Test_qromb { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=10; - double x1,x2,sbeps=1.e-10; - double[] y= new double[N],yy= new double[N]; - boolean localflag, globalflag=false; - - - - // Test qromb - System.out.println("Testing qromb"); - Bessj0_qromb bj0 = new Bessj0_qromb(); - Bessj1_qromb bj1 = new Bessj1_qromb(); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** qromb: Failure to achieve advertised accuracy in integral"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Bessj0_qromb implements UniVarRealValueFun{ - public double funk(double x) { - Bessjy b = new Bessjy(); - return(b.j0(x)); - } - }; - - class Bessj1_qromb implements UniVarRealValueFun{ - public double funk (double x) { - Bessjy b = new Bessjy(); - return(b.j1(x)); - } - }; -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_qromo.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_qromo.java deleted file mode 100644 index d15bf99eef..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_qromo.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.fi.Midpnt.qromo; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.cos; -import static java.lang.Math.sin; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.fi.Midpnt; - -public class Test_qromo implements UniVarRealValueFun{ - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - // int i,j,M=14; - double a,b,s,expect,PI=acos(-1.0),sbeps=1.e-11; - boolean localflag, globalflag=false; - - - - // Test qromo - System.out.println("Testing qromo"); - - a=0.0; - b=PI; - Midpnt mpt = new Midpnt(this,a,b); - s=qromo(mpt); - - expect=fint_qromo(b)-fint_qromo(a); -// System.out.printf(setw(9) << expect << endl; - - System.out.printf("qromo: Maximum discrepancy = %f\n", abs(s-expect)); - localflag = abs(s-expect) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** qromo: Failure to achieve expected accuracy in improper integral"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } -//Test function -public double funk(final double x) -{ - return sin(x); -} - -//integral of test function -double fint_qromo(final double x) -{ - return -cos(x); -} - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_qsimp.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_qsimp.java deleted file mode 100644 index 737a231de7..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_qsimp.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.fi.Trapzd.qsimp; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.sf.Bessjy; - -public class Test_qsimp { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=10; - double x1,x2,sbeps=1.e-10; - double[] y= new double[N],yy= new double[N]; - boolean localflag, globalflag=false; - - // Test qsimp - System.out.println("Testing qsimp"); - Bessj0_qsimp bj0 = new Bessj0_qsimp(); - Bessj1_qsimp bj1 = new Bessj1_qsimp(); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** qsimp: Failure to achieve advertised accuracy in integral"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Bessj0_qsimp implements UniVarRealValueFun { - public double funk(double x) { - Bessjy b = new Bessjy(); - return(b.j0(x)); - } - }; - - class Bessj1_qsimp implements UniVarRealValueFun{ - public double funk (double x) { - Bessjy b = new Bessjy(); - return(b.j1(x)); - } - }; -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_qtrap.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_qtrap.java deleted file mode 100644 index 5f26ebbe56..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_qtrap.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.fi.Trapzd.qtrap; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.sf.Bessjy; - -public class Test_qtrap { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=10; - double x1,x2,sbeps=1.e-10; - double[] y= new double[N],yy= new double[N]; - boolean localflag, globalflag=false; - - - - // Test qtrap - System.out.println("Testing qtrap"); - Bessj0_qtrap bj0 = new Bessj0_qtrap(); - Bessj1_qtrap bj1 = new Bessj1_qtrap(); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** qtrap: Failure to achieve advertised accuracy in integral"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Bessj0_qtrap implements UniVarRealValueFun{ - public double funk (double x) { - Bessjy b = new Bessjy(); - return(b.j0(x)); - } - }; - - class Bessj1_qtrap implements UniVarRealValueFun{ - public double funk(double x) { - Bessjy b= new Bessjy(); - return(b.j1(x)); - } - }; - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_quad3d.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_quad3d.java deleted file mode 100644 index 33aad889e7..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_quad3d.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.NRUtil.SQR; -import static com.nr.fi.NRf3.quad3d; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.exp; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.RealValueFun; - -public class Test_quad3d { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double s,expect,sbeps,PI=acos(-1.0); - boolean localflag, globalflag=false; - - - - // Test quad3d - System.out.println("Testing quad3d"); - func func = new func(); - func2 func2 = new func2(); - y1 y1 = new y1(); - y2 y2 = new y2(); - z1 z1 = new z1(); - z2 z2 = new z2(); - - s=quad3d(func,-1.0,1.0,y1,y2,z1,z2); - expect=2.0*PI/3.0; - -// System.out.printf(s << " %f\n", expect << endl; - - sbeps=1.e-3; -// System.out.printf(fabs(s-expect)/expect << endl; - localflag = abs(s-expect)/expect > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** quad3d: integral of hemispherical volume was inaccurate"); - - } - - s=quad3d(func2,-1.0,1.0,y1,y2,z1,z2); - expect=2.0*PI*(2.0-5.0/exp(1.0)); - -// System.out.printf(s << " %f\n", expect << endl; - - sbeps=1.e-3; -// System.out.printf(abs(s-expect)/expect << endl; - localflag = abs(s-expect)/expect > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** quad3d: Weighted integral over hemispherical volume was inaccurate"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class y1 implements RealValueFun { - public double funk(final double[] xx) { - double x = xx[0]; - return -sqrt(1.0 - SQR(x)); - } - } - - class y2 implements RealValueFun { - public double funk(final double[] xx) { - double x = xx[0]; - return sqrt(1.0 - SQR(x)); - } - } - - class z1 implements RealValueFun { - public double funk(final double[] x) { - return 0.0; - } - } - - class z2 implements RealValueFun { - public double funk(final double[] xx) { - double x = xx[0], y = xx[1]; - - return sqrt(1.0 - SQR(x) - SQR(y)); - } - } - - class func implements RealValueFun { - public double funk(final double[] x) { - return 1.0; - } - } - - class func2 implements RealValueFun { - public double funk(final double[] xx) { - double x = xx[0], y = xx[1], z = xx[2]; - - double r; - - r = sqrt(SQR(x) + SQR(y) + SQR(z)); - return exp(-r); - } - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_radau.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_radau.java deleted file mode 100644 index eb6471564e..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_radau.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.fi.GaussianWeights.radau; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class Test_radau { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=10; - double amu0,check,sbeps,PI=acos(-1.0); - double[] a= new double[N],b= new double[N],x= new double[N],w= new double[N]; - boolean localflag, globalflag=false; - - - - // Test radau - System.out.println("Testing radau"); - - // Test with Gauss-Chebyshev - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** radau: Gaussian weights do not sum to correct value"); - - } - - sbeps=1.e-15; - localflag = abs(x[0]-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** radau: First element of x[] is not the requested value of 1.0"); - - } - - // Since arrays a[],b[] are modified, we recompute them - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** radau: Gaussian weights do not sum to correct value"); - - } - - sbeps=1.e-15; - localflag = abs(x[N-1]+1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** radau: Last element of x[] is not the requested value of -1.0"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_trapzd.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_trapzd.java deleted file mode 100644 index 4b680f52b9..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter4/Test_trapzd.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.nr.test.test_chapter4; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.fi.Trapzd; -import com.nr.sf.Bessjy; - -public class Test_trapzd { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=10,M=16; - double x1,x2,val=0,sbeps=1.e-9; - double[] y=new double[N],yy=new double[N]; - boolean localflag, globalflag=false; - - - - // Test trapzd - System.out.println("Testing trapzd"); - Bessj0_trapzd bj0 = new Bessj0_trapzd(); - Bessj1_trapzd bj1 = new Bessj1_trapzd(); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** trapzd: Incorrect integral value"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Bessj0_trapzd implements UniVarRealValueFun { - public double funk(double x) { - Bessjy b = new Bessjy(); - return(b.j0(x)); - } - }; - - class Bessj1_trapzd implements UniVarRealValueFun{ - public double funk (double x) { - Bessjy b = new Bessjy(); - return(b.j1(x)); - } - }; - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Chebyshev.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Chebyshev.java deleted file mode 100644 index 1d1d2f270b..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Chebyshev.java +++ /dev/null @@ -1,149 +0,0 @@ -package com.nr.test.test_chapter5; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.fe.Chebyshev; -import com.nr.sf.Bessjy; - -public class Test_Chebyshev { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=5,NN=50,m,MM=11; - double x,xx,aa=-5.0,bb=5.0,val,thresh=1.e-6,sbeps=1.e-6; - double[] y = new double[MM],yy = new double[MM]; - Bessjy b = new Bessjy(); - boolean localflag, globalflag=false; - - - - // Test Chebyshev (eval) - System.out.println("Testing Chebyshev (eval)"); - bjn bjn = new bjn(); - Chebyshev cheb = new Chebyshev(bjn,aa,bb,NN); - m=cheb.setm(thresh); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Chebyshev (eval): Chebyshev approximation does not evaluate to accurate function values"); - - } - - // Test Chebyshev (polycofs) - System.out.println("Testing Chebyshev (polycofs)"); - double[] d=cheb.polycofs(m); - for (i=0;i=0;j--) val=val*xx+d[j]; - yy[i]=val; -// System.out.printf(y[i] << " %f\n", yy[i] << endl; - } - System.out.printf("Chebyshev (polycofs): Maximum discrepancy = %f\n", maxel(vecsub(y,yy))); - localflag = maxel(vecsub(y,yy)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Chebyshev (polycofs): Polynomial coefficients do not yield correct function values"); - - } - - // Test Chebyshev (derivative) - System.out.println("Testing Chebyshev (derivative)"); - Chebyshev cder=cheb.derivative(); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Chebyshev (derivative): Chebyshev derivative has incorrect values"); - - } - - // Test Chebyshev (integral) - System.out.println("Testing Chebyshev (integral)"); - bj1 bj1 = new bj1(); - Chebyshev cheb1 = new Chebyshev(bj1,aa,bb,NN); - Chebyshev cint=cheb1.integral(); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Chebyshev (integral): Chebyshev integral has incorrect values"); - - } - - // Test Chebyshev (construct from polynomial) - System.out.println("Testing Chebyshev (construct from polynomial)"); - Chebyshev chebnew = new Chebyshev(d); - double[] z = new double[m],zz = new double[m]; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Chebyshev (integral): Chebyshev (construct from polynomial): Reconstructed Chebyshev coeffiecients not the same as originals"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class bjn implements UniVarRealValueFun{ - public double funk(final double x) { - int N=5; - - Bessjy b = new Bessjy(); - return(b.jn(N,x)); - } - } - - class bj1 implements UniVarRealValueFun{ - public double funk(final double x) { - int N=1; - - Bessjy b = new Bessjy(); - return(b.jn(N,x)); - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Epsalg.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Epsalg.java deleted file mode 100644 index 43a0472660..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Epsalg.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.nr.test.test_chapter5; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.pow; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.fe.Epsalg; - -public class Test_Epsalg { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,k,N=9,M=100; - double x,partialsum,val=0,eps=1.e-15,sbeps=5.e-15; - double[] y=new double[N],yy=new double[N]; - boolean localflag, globalflag=false; - - - - // Test Epsalg - System.out.println("Testing Epsalg"); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Epsalg: Inaccurate estimate of series value"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Eulsum.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Eulsum.java deleted file mode 100644 index a950d7a87f..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Eulsum.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.nr.test.test_chapter5; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.fe.Eulsum; - -public class Test_Eulsum { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=9,M=100; - double x,term,val=0,eps=1.e-15,sbeps=5.e-15; - double[] y=new double[N],yy=new double[N]; - boolean localflag, globalflag=false; - - - - // Test Eulsum - System.out.println("Testing Eulsum"); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Eulsum: Inaccurate estimate of series value"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Levin.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Levin.java deleted file mode 100644 index 345d4ffe59..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Levin.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.nr.test.test_chapter5; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.fe.Levin; - -public class Test_Levin { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,k,N=9,M=100; - double x,partialsum,omega,beta=1.0,val=0,eps=1.e-14,sbeps=5.e-14; - double[] y=new double[N],yy=new double[N]; - boolean localflag, globalflag=false; - - - - // Test Levin - System.out.println("Testing Levin"); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Levin: Inaccurate estimate of series value"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Poly.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Poly.java deleted file mode 100644 index 8deff84f20..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Poly.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.nr.test.test_chapter5; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.pow; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.fe.Poly; - -public class Test_Poly { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,M=11; - double x,sbeps=1.e-15; - double c[]={-1.0,5.0,-10.0,10.0,-5.0,1.0}; // Coefficients of (x-1.0)^5; - double[] cc = buildVector(c),y= new double[M],yy= new double[M]; - boolean localflag, globalflag=false; - - - - // Test Poly - System.out.println("Testing Poly"); - Poly p = new Poly(cc); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Poly: Polynomial returns incorrect values"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Ratfn.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Ratfn.java deleted file mode 100644 index 97f3d190da..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_Ratfn.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.nr.test.test_chapter5; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.pow; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.fe.Ratfn; - -public class Test_Ratfn { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,M=10; - double x,sbeps=1.e-15; - double b[]={-3.0,15.0,-30.0,30.0,-15.0,3.0}; // Coefficients of 3.0*(x-1.0)^5; - double c[]={-2.0,6.0,-6.0,2.0}; // Coefficients of 2.0*(x-1.0)^3 - double d[]={1.5,-7.5,15.0,-15.0,7.5,-1.5,-3.0,3.0,-1.0}; - double[] bb = buildVector(b),cc = buildVector(c),dd = buildVector(d),y= new double[M],yy= new double[M]; - boolean localflag, globalflag=false; - - - - // Test Ratfn - System.out.println("Testing Ratfn: constructor #1"); - Ratfn rp1 = new Ratfn(bb,cc); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Ratfn: Rational function returns incorrect values"); - - } - - System.out.println("Testing Ratfn: constructor #2"); - Ratfn rp2= new Ratfn(dd,6,4); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Ratfn: Rational function returns incorrect values"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_ddpoly.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_ddpoly.java deleted file mode 100644 index 49343a597a..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_ddpoly.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.nr.test.test_chapter5; - -import static com.nr.test.NRTestUtil.*; -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import com.nr.fe.Poly; -public class Test_ddpoly { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,M=11; - double x,sbeps=1.e-15; - double c[]={-1.0,5.0,-10.0,10.0,-5.0,1.0}; // Coefficients of (x-1.0)^5; - double[] cc = buildVector(c),pd = new double[6],p = new double[6],y = new double[M]; - boolean localflag, globalflag=false; - - - - // Test ddpoly - System.out.println("Testing ddpoly"); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ddpoly: Incorrect values for function or derivatives"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_dfridr.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_dfridr.java deleted file mode 100644 index 265b12b8f6..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_dfridr.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.nr.test.test_chapter5; - -import static com.nr.fe.Dfridr.dfridr; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -import com.nr.UniVarRealValueFun; -import com.nr.sf.Bessjy; - -public class Test_dfridr { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,M=10; - double x,h=0.2,sbeps=5.e-14; - doubleW err = new doubleW(0); - double[] y= new double[M],yy= new double[M]; - boolean localflag, globalflag=false; - - - - // Test dfridr - System.out.println("Testing dfridr"); - - // Test with function - bj0_dfridr bj0_dfridr = new bj0_dfridr(); - bj1_dfridr bj1_dfridr = new bj1_dfridr(); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** dfridr: Derivative returns incorrect values with function"); - - } - - // Test with functor - Bessj0_dfridr bj0 = new Bessj0_dfridr(); - Bessj1_dfridr bj1 = new Bessj1_dfridr(); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** dfridr: Derivative returns incorrect values with functor"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Bessj0_dfridr implements UniVarRealValueFun{ - Bessjy b = new Bessjy(); - public double funk (final double x) { - return(b.j0(x)); - } - }; - - class Bessj1_dfridr implements UniVarRealValueFun{ - Bessjy b = new Bessjy(); - public double funk (final double x) { - return(b.j1(x)); - } - }; - - class bj0_dfridr implements UniVarRealValueFun{ - public double funk(final double x) { - Bessjy b = new Bessjy(); - return(b.j0(x)); - } - } - class bj1_dfridr implements UniVarRealValueFun{ - public double funk(final double x) { - Bessjy b = new Bessjy(); - return(b.j1(x)); - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_ipcshft.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_ipcshft.java deleted file mode 100644 index c3b23e56a6..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_ipcshft.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.nr.test.test_chapter5; - -import static com.nr.NRUtil.buildVector; -import static com.nr.fe.Chebyshev.ipcshft; -import static com.nr.fe.Chebyshev.pcshft; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class Test_ipcshft { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - // int M=6; - double a=1.0,b=3.0,sbeps=1.e-13; - double d[]={-1,6.0,-10.0,10.0,-6.0,1.0}; - double[] dd = buildVector(d); - boolean localflag, globalflag=false; - - - - // Test ipcshft - System.out.println("Testing ipcshft"); - double[] g = buildVector(dd); - pcshft(a,b,g); - double[] h = buildVector(g); - ipcshft(a,b,h); - - localflag = maxel(vecsub(g,dd)) < 1.0; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ipcshft: Polynomial was not shifted"); - - } - - localflag = maxel(vecsub(h,g)) < 1.0; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ipcshft: Polynomial was not inverse shifted"); - - } - - System.out.printf("ipcshft: Maximum discrepancy = %f\n", maxel(vecsub(h,dd))); - localflag = maxel(vecsub(h,dd)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ipcshft: Inverse shift did not undo the shift properly"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_levex.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_levex.java deleted file mode 100644 index 768a6b5894..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_levex.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.nr.test.test_chapter5; - -import static java.lang.Math.*; - -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.fe.Levin; -import com.nr.sf.Bessel; -import static com.nr.fi.Trapzd.qromb; - -public class Test_levex implements UniVarRealValueFun{ - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - boolean localflag, globalflag=false; - - - - // Test levex - System.out.println("Testing levex"); - - localflag = main_levex() != 0; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Levex : Program did not indicate successful completion"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - - public double funk(final double x) - { - if (x == 0.0) - return 0.0; - else { - Bessel bess = new Bessel(); - return x*bess.jnu(0.0,x)/(1.0+x*x); - } - } - - int main_levex(){ - int nterm=12; - double beta=1.0,a=0.0,b=0.0,sum=0.0; - Levin series = new Levin(100,0.0); - //cout << setw(5) << "N" << setw(19) << "Sum (direct)" << setw(21) - // << "Sum (Levin)" << endl; - for (int n=0; n<=nterm; n++) { - b+=PI; - double s=qromb(this,a,b,1.e-8); - a=b; - sum+=s; - double omega=(beta+n)*s; - double ans=series.next(sum,omega,beta); - //cout << setw(5) << n << fixed << setprecision(14) << setw(21) - // << sum << setw(21) << ans << endl; - System.out.printf("%f %f\n", sum, ans); - } - return 0; - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_pade.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_pade.java deleted file mode 100644 index 91470d8e76..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_pade.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.nr.test.test_chapter5; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.log; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.fe.Ratfn; - -public class Test_pade { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=10,M=12; - double val,fac,d1,d2,x,sbeps=1.e-6; - double[] c= new double[M],y=new double[N],yy=new double[N],yyy=new double[N]; - boolean localflag, globalflag=false; - - - - // Test pade - System.out.println("Testing pade"); - fac=1.0; - for (i=0;i=0;j--) { - val=val*x+c[j]; - } - yyy[i]=val; - } - System.out.printf("pade: Maximum error of Pade approximant = %f\n", (d1=maxel(vecsub(y,yy)))); - localflag = maxel(vecsub(y,yy)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** pade: Pade approximant is inaccurate"); - - } - System.out.printf("pade: Maximum discrepancy of power series = %f\n", (d2=maxel(vecsub(y,yyy)))); - localflag = d1 > d2; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** pade: Pade approximant is less accurate than power series"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - double Func_pade(double x) { - return(x==0.0 ? 1.0 : log(1.0+x)/x); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_pcshft.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_pcshft.java deleted file mode 100644 index 10ef2e3f5b..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_pcshft.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.nr.test.test_chapter5; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.fe.Chebyshev; - -public class Test_pcshft { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=11,M=6; - double x,xx,a=1.0,b=3.0,val,sbeps=1.e-13; - double d[]={-1,6.0,-10.0,10.0,-6.0,1.0}; - double[] dd = buildVector(d),y=new double[N],yy=new double[N]; - boolean localflag, globalflag=false; - - - - // Test pcshft - System.out.println("Testing pcshft"); - double[] g = buildVector(dd); - Chebyshev.pcshft(a,b,g); - for (i=0;i=0;j--) val=val*x+g[j]; - y[i]=val; - val=dd[M-1]; - for (j=M-2;j>=0;j--) val=val*xx+dd[j]; - yy[i]=val; - } - localflag = maxel(vecsub(g,dd)) < 1.0; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** pcshft: Polynomial was not shifted"); - - } - - System.out.printf("pcshft: Maximum discrepancy = %f\n", maxel(vecsub(y,yy))); - localflag = maxel(vecsub(y,yy)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** pcshft: Shifted polynomial does not return the same values"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_poldiv.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_poldiv.java deleted file mode 100644 index b0fe3222d2..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_poldiv.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.nr.test.test_chapter5; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.fe.Poly; - -public class Test_poldiv { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double sbeps=2.e-15; - double u[]={1.0,7.0,-10.0,10.0,-5.0,1.0}; // Coefficients of (x-1.0)^5+2.0*(x+1); - double v[]={-3.0,9.0,-9.0,3.0}; // Coefficients of 3.0*(x-1)^3 - double q[]={1.0/3.0,-2.0/3.0,1.0/3.0,0.0,0.0,0.0}; // Quotient is (1/3)*(x-1.0)^2; - double r[]={2.0,2.0,0.0,0.0,0.0,0.0}; // Remainter is 2.0*(x+1) - double[] uu = buildVector(u),vv = buildVector(v),qq=buildVector(q),rr = buildVector(r),s = new double[6],t = new double[6]; - boolean localflag, globalflag=false; - - - - // Test poldiv - System.out.println("Testing poldiv"); - Poly.poldiv(uu,vv,s,t); - System.out.printf("poldiv: Maximum discrepancy in quotient = %f\n", maxel(vecsub(s,qq))); - localflag = maxel(vecsub(s,qq)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** poldiv: Division returns incorrect quotient"); - - } - - System.out.printf("poldiv: Maximum discrepancy in remainder = %f\n", maxel(vecsub(t,rr))); - localflag = maxel(vecsub(t,rr)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** poldiv: Division returns incorrect remainder"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_ratlsq.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_ratlsq.java deleted file mode 100644 index 6a8ae14eca..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter5/Test_ratlsq.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.nr.test.test_chapter5; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.log; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -import com.nr.UniVarRealValueFun; -import com.nr.fe.Ratfn; - -public class Test_ratlsq implements UniVarRealValueFun{ - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=11,M=12; - double fac,x,sbeps=2.e-13; - doubleW dev = new doubleW(0); - double[] c = new double[2*M],y=new double[N],yy=new double[N]; - boolean localflag, globalflag=false; - - - - // Test ratlsq - System.out.println("Testing ratlsq"); - fac=1.0; - for (i=0;i<2*M;i++) { // Series coefficients - c[i]=fac/(double)(i+1); - fac = -fac; - } - Ratfn q=Ratfn.ratlsq(this,0.0,2.0,M,M,dev); // Diagonal works best for this function - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ratlsq: Ratlsq approximation is inaccurate"); - - } - - System.out.printf("ratlsq: Reported maximum absolute deviation from ratlsq = %f\n", dev.val); - localflag = maxel(vecsub(y,yy)) > dev.val; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ratlsq: Error exceeds reported maximum absolute deviation"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - public double funk(double x) { - return(x==0.0 ? 1.0 : log(1.0+x)/x); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Bessel.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Bessel.java deleted file mode 100644 index f5d4d30367..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Bessel.java +++ /dev/null @@ -1,325 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.sf.Bessel; -import com.nr.sf.Bessik; -import com.nr.sf.Bessjy; - -public class Test_Bessel { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @SuppressWarnings("unused") - @Test - public void test() { - int i,j,N=16; - double nnu,xx,sbeps=1.e-14; - double nu[]={0.5,0.5,0.5,0.5,1.5,1.5,1.5,1.5,2.5,2.5,2.5,2.5,3.5,4.5,5.5,6.5}; - double x[]={0.2,0.5,1.0,2.0,0.2,0.5,1.0,2.0,0.2,0.5,1.0,2.0,2.0,2.0,2.0,2.0}; - double u1[]={0.354450744211401103,0.540973789934528091,0.671396707141803090, - 0.513016136561827752,0.0236933040951292395,0.0917016996256513026, - 0.240297839123427011,0.491293778687162345,0.000948817215537489923, - 0.00923640781937972450,0.0494968102284779423,0.223924531468915766, - 0.0685175499851270696,0.0158868934790289778,0.00297347067050333037, - 0.000467195208739339254}; - double u2[]={-1.74856041696187628,-0.990245880243404880,-0.431098868018376080, - 0.234785710406248469,-9.09725282902078249,-2.52146555042133785, - -1.10249557516017917,-0.395623281358703517,-134.710232018349861, - -14.1385474222846222,-2.87638785746216143,-0.828220632444303745, - -1.67492829975205584,-5.03402841668789171,-20.9781995753434569, - -110.346069247701121}; - double u3[]={0.359208417583361390,0.587993086790416325,0.937674888245487647, - 2.04623686308905504,0.0238836108689015129,0.0964034738340167409, - 0.293525326347479800,1.09947318863310968,0.000954254549838696096, - 0.00957224378631588027,0.0570989092030482474,0.397027080139390523, - 0.106905488284633367,0.0228578711431737382,0.00404506814035154520, - 0.000609996371240239640}; - double u4[]={2.29448933979847487,1.07504760349992024,0.461068504447894558, - 0.119937771968061447,13.7669360387908492,3.22514281049976072, - 0.922137008895789117,0.179906657952092171,208.798529921661213, - 20.4259044664984845,3.22747953113526191,0.389797758896199704, - 1.15440105519259143,4.43020145207026971,21.0903075895088051, - 120.426893194368698}; - double[] uu1=buildVector(u1),uu2=buildVector(u2),uu3=buildVector(u3),uu4=buildVector(u4),zz=new double[N],zz1=new double[N],zz2=new double[N]; - boolean localflag, globalflag=false; - - Bessel bess = new Bessel(); - Bessjy bjy = new Bessjy(); - Bessik bik = new Bessik(); - - // Test Bessel (besseljy and besselik) - System.out.println("Testing Bessel (besseljy)"); - - // Test for integer values of nu - sbeps=1.e-10; - for (i=0;i<5;i++) { - nnu=(double)(i); - - for (j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessel (besseljy,jnu): Incorrect function values, integer order"); - - } - - for (j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessel (besseljy,ynu): Incorrect function values, integer order"); - - } - - for (j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessel (besselik,inu): Incorrect function values, integer order"); - - } - - for (j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessel (besselik,knu): Incorrect function values, integer order"); - - } - } - - // Test some non-integer values of nu - // Test Bessel (besseljy) - System.out.println("Testing Bessel (besseljy),jnu"); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessel (besselij),jnu: Incorrect function values, non-integer order"); - - } - - System.out.println("Testing Bessel (besseljy),ynu"); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessel (besseljy),ynu: Incorrect function values, non-integer order"); - - } - - // Test Bessel (besselik) - System.out.println("Testing Bessel (besselik),inu"); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessel (besselik),inu: Incorrect function values, non-integer order"); - - } - - System.out.println("Testing Bessel (besselik),knu"); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessel (besselik),knu: Incorrect function values, non-integer order"); - - } - - N=17; - double x3[]={-64.0,-32.0,-16.0,-8.0,-4.0,-2.0,-1.0,-0.5,0.0, - 0.5,1.0,2.0,4.0,8.0,16.0,32.0,64.0}; - double y3[]={6.181292862603287e-2,2.066697536442034e-1,-1.430579316691003e-1, - -5.270505035638810e-2,-7.026553294929175e-2,2.274074282016857e-1, - 5.355608832923522e-1,4.757280916105395e-1,3.550280538878172e-1, - 2.316936064808334e-1,1.352924163128815e-1,3.492413042327446e-2, - 9.515638512048023e-4,4.692207616099237e-8,4.156888828917034e-020, - 4.606731112410277e-054,-5.748819722355254e-150}; - double y4[]={-1.896519810390566e-1,-1.164350222348790e-1,2.431231514282269e-1, - -3.312515807511406e-1,3.922347057070000e-1,-4.123025879563988e-1, - 1.039973894969446e-1,3.803526597510537e-1,6.149266274460007e-1, - 8.542770431031557e-1,1.207423594952871,3.298094999978216, - 8.384707140846841e1,1.199586004124440e6,9.572123906049169e17, - 6.107371662410141e51,3.460602472409225e+147}; - double y5[]={1.517458208520610e0,6.602736519705829e-1,-9.747644416212706e-1, - 9.355609381983173e-1,-7.906285753685707e-1,6.182590207416919e-1, - -1.016056711664515e-2,-2.040816703395474e-1,-2.588194037928068e-1, - -2.249105326646840e-1,-1.591474412967932e-1,-5.309038443365637e-2, - -1.958640950204180e-3,-1.341439297906788e-7,-1.669188676838185e-19, - -2.609547331124277e-53,-4.601298677332503e-149}; - double y6[]={4.937628983497952e-1,1.168196625671367e0,-5.684556059761371e-1, - -1.594504978129538e-1,-1.166705674383235e-1,2.787951669211703e-1, - 5.923756264227923e-1,5.059337136238472e-1,4.482883573538264e-1, - 5.445725641405924e-1,9.324359333927754e-1,4.100682049932892e0, - 1.619266835046139e2,3.354342312744483e6,3.813743507121854e+018, - 3.450063137771686e+052,2.767128525086472e+148}; - double[] yy3=buildVector(y3),yy4=buildVector(y4),yy5=buildVector(y5),yy6=buildVector(y6),one=buildVector(N,1.0), - zz3=new double[N],zz4=new double[N],zz5=new double[N],zz6=new double[N]; - - /* - - Bessel2 bess2 = new Bessel2(); - - // Test Bessel (airy) - sbeps=1.e-12; - System.out.println("Testing Bessel (airy_ai, airy_bi, airy_aip, airy_bip)"); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessel (airy_ai): Incorrect function values"); - - } - System.out.printf("Bessel (airy_bi): Maximum discrepancy = %f\n", maxel(vecsub(one,zz4))); - localflag = maxel(vecsub(one,zz4)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessel (airy_bi): Incorrect function values"); - - } - System.out.printf("Bessel (airy_aip): Maximum discrepancy = %f\n", maxel(vecsub(zz5,yy5))); - localflag = maxel(vecsub(zz5,yy5)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessel (airy_aip): Incorrect function values"); - - } - System.out.printf("Bessel (airy_bip): Maximum discrepancy = %f\n", maxel(vecsub(one,zz6))); - localflag = maxel(vecsub(one,zz6)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessel (airy_bip): Incorrect function values"); - - } - - // Test Bessel (sphbes) - System.out.println("Testing Bessel (sphbes)"); - - int M=5; - N=10; - double[] yy7=new double[N],yy8=new double[N],zz7=new double[N],zz8=new double[N]; - double sqrtpio2=sqrt(acos(-1.0)/2); - sbeps=6.e-11; - for (j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessel (sphbes), Jnu: Incorrect function values"); - - } - - // Spherical Bessel function yn - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessel (sphbes), Ynu: Incorrect function values"); - - } - } - */ - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Bessel2 extends Bessel - { - double airy_aip(final double x) { - // Simple interface returning Ai'(x) - // if (x != xo) airy(x); // XXX HWH disable it - return aipo; - } - - double airy_bip(final double x) { - // Simple interface returning Bi'(x) - // if (x != xo) airy(x); // XXX HWH disable it - return bipo; - } - }; -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Bessik.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Bessik.java deleted file mode 100644 index d7afd31277..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Bessik.java +++ /dev/null @@ -1,176 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.sf.Bessik; - -public class Test_Bessik { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=17; - double sbeps=1.e-15; - double x[]={-32.0,-16.0,-8.0,-4.0,-2.0,-1.0,-0.5,-0.1,0.0, - 0.1,0.5,1.0,2.0,4.0,8.0,16.0,32.0}; - double y1[]={5.590908381350871e12,8.934462279201048e5,4.275641157218047e2, - 1.130192195213633e1,2.279585302336067,1.266065877752008, - 1.063483370741324,1.002501562934095,1.000000000000000, - 1.002501562934095,1.063483370741324,1.266065877752008, - 2.279585302336067,1.130192195213633e1,4.275641157218047e2, - 8.934462279201048e5,5.590908381350871e12}; - double y2[]={-5.502845511211247e12,-8.650594358548392e5,-3.998731367825601e2, - -9.759465153704449e0,-1.590636854637329e0,-5.651591039924850e-1, - -2.578943053908963e-1,-5.006252604709272e-2,0.0,5.006252604709272e-2, - 2.578943053908963e-1,5.651591039924850e-1,1.590636854637329e0, - 9.759465153704449e0,3.998731367825601e2,8.650594358548392e5, - 5.502845511211247e12}; - double[] yy1=buildVector(y1),yy2=buildVector(y2),zz1=new double[N],zz2=new double[N]; - boolean localflag, globalflag=false; - - - - // Test Bessik (i0) - System.out.println("Testing Bessik (i0)"); - localflag=false; - Bessik bess = new Bessik(); - sbeps=1.e-15; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessik (i0): Incorrect function values"); - - } - - // Test Bessik (i1) - System.out.println("Testing Bessik (i1)"); - localflag=false; - sbeps=1.e-15; - for (i=0;i sbeps; - } - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessik (i1): Incorrect function values"); - - } - - N=10; - double x3[]={0.001,0.01,0.1,0.5,1.0,2.0,4.0,8.0,16.0,32.0}; - double y3[]={7.023688800562382,4.721244730161095,2.427069024702017, - 9.244190712276657e-1,4.210244382407083e-1,1.138938727495334e-1, - 1.115967608585303e-2,1.464707052228154e-4,3.499411663936500e-8, - 2.795057518761980e-15}; - double y4[]={9.999962381560855e2,9.997389411829624e1,9.853844780870606, - 1.656441120003301,6.019072301972346e-1,1.398658818165225e-1, - 1.248349888726843e-2,1.553692118050012e-4,3.607157117528780e-8, - 2.838399271974671e-15}; - double[] yy3=buildVector(y3),yy4=buildVector(y4),zz3=new double[N],zz4=new double[N]; - - // Test Bessik (k0) - System.out.println("Testing Bessik (k0)"); - localflag=false; - sbeps=5.e-15; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessik (k0): Incorrect function values"); - - } - - // Test Bessik (k1) - System.out.println("Testing Bessik (k1)"); - localflag=false; - sbeps=5.e-15; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessik (k1): Incorrect function values"); - - } - - N=16; - int n5[]={2,2,2,2,5,5,5,5,10,10,10,10,20,20,20,20}; - double x5[]={0.01,0.1,1.0,10.0,0.01,0.1,1.0,10.0,0.01,0.1,1.0,10.0,0.01,0.1,1.0,10.0,}; - double y5[]={1.250010416699221e-5,1.251041992241759e-3,1.357476697670383e-1, - 2.281518967726005e3,2.604177517380490e-14,2.605251929893700e-9, - 2.714631559569721e-4,7.771882864032602e2,2.691150571711139e-30, - 2.691756142922153e-20,2.752948039836874e-10,2.189170616372337e1, - 3.919909016180170e-65,3.920371031419948e-45,3.966835985819000e-25, - 1.250799735644947e-4}; - double y6[]={1.999950006838941e4,1.995039646421141e2,1.624838898635177, - 2.150981700693276e-5,3.839976000100000e12,3.837600999583593e7, - 3.609605896012407e2,5.754184998531225e-5,1.857940439048064e28, - 1.857429584630401e18,1.807132899010295e8,1.614255300390669e-3, - 6.377698248601134e62,6.376867526661186e42,6.294369360424536e22, - 1.787442782077055e2}; - double[] yy5=buildVector(y5),yy6=buildVector(y6),zz5=new double[N],zz6=new double[N]; - - - - // Test Bessik (in) - System.out.println("Testing Bessik (in)"); - - localflag=false; - sbeps=5.e-14; - for (i=0;i sbeps; - } - - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessik (in): Incorrect function values"); - - } - - // Test Bessik (kn) - System.out.println("Testing Bessik (kn)"); - localflag=false; - sbeps=5.e-15; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessik (kn): Incorrect function values"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Bessjy.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Bessjy.java deleted file mode 100644 index 73d837572f..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Bessjy.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.sf.Bessjy; - -public class Test_Bessjy { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=17; - double sbeps; - double x[]={-32.0,-16.0,-8.0,-4.0,-2.0,-1.0,-0.5,-0.1,0.0, - 0.1,0.5,1.0,2.0,4.0,8.0,16.0,32.0}; - double y1[]={1.380790097465560e-1,-1.748990739836292e-1,1.716508071375539e-1, - -3.971498098638472e-1,2.238907791412356e-1,7.651976865579666e-1, - 9.384698072408130e-1,9.975015620660401e-1,1.0,9.975015620660401e-1, - 9.384698072408130e-1,7.651976865579666e-1,2.238907791412356e-1, - -3.971498098638472e-1,1.716508071375539e-1,-1.748990739836292e-1, - 1.380790097465560e-1}; //,-5.767248077568736e-1 XXX remove it. - double y2[]={2.658902847590528e-2,-9.039717566130416e-2,-2.346363468539147e-1, - 6.604332802354906e-2,-5.767248077568736e-001,-4.400505857449336e-1, - -2.422684576748739e-1,-4.993752603624202e-2,0.0,4.993752603624202e-2, - 2.422684576748739e-1,4.400505857449336e-1,5.767248077568736e-001, - -6.604332802354906e-2,2.346363468539147e-1,9.039717566130416e-2, - -2.658902847590528e-2}; - double[] yy1=buildVector(y1),yy2=buildVector(y2),zz1=new double[N],zz2=new double[N]; - boolean localflag, globalflag=false; - - // Test Bessjy (j0) - System.out.println("Testing Bessjy (j0)"); - Bessjy bess = new Bessjy(); - sbeps=1.e-15; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessjy (j0): Incorrect function values"); - - } - - // Test Bessjy (j1) - System.out.println("Testing Bessjy (j1)"); - sbeps=1.e-15; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessjy (j1): Incorrect function values"); - - } - - N=10; - double x3[]={0.001,0.01,0.1,0.5,1.0,2.0,4.0,8.0,16.0,32.0}; - double y3[]={-4.471416611375924,-3.005455637083646,-1.534238651350367, - -4.445187335067066e-1,8.825696421567700e-2,5.103756726497453e-1, - -1.694073932506495e-2,2.235214893875663e-1,9.581099708071243e-2, - -2.874248465443332e-2}; - double y4[]={-6.366221672311394e+002,-6.367859628206066e+001,-6.458951094702027, - -1.471472392670243,-7.812128213002889e-1,-1.070324315409375e-1, - 3.979257105571000e-1,-1.580604617312476e-1,1.779751689394169e-1, - -1.385448315327238e-1}; - double[] yy3=buildVector(y3),yy4=buildVector(y4),zz3=new double[N],zz4=new double[N]; - - // Test Bessjy (y0) - System.out.println("Testing Bessjy (y0)"); - sbeps=1.e-14; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessjy (y0): Incorrect function values"); - - } - - // Test Bessjy (y1) - System.out.println("Testing Bessjy (y1)"); - sbeps=1.5e-13; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessjy (y1): Incorrect function values"); - - } - - N=16; - int n5[]={2,2,2,2,5,5,5,5,10,10,10,10,50,50,50,50}; - double x5[]={0.01,0.1,1.0,10.0,0.01,0.1,1.0,10.0,0.01,0.1,1.0,10.0,0.01,0.1,1.0,10.0,}; - double y5[]={1.249989583365887e-5,1.248958658799919e-3,1.149034849319005e-1, - 2.546303136851206e-1,2.604155815991601e-14,2.603081790964445e-9, - 2.497577302112346e-4,-2.340615281867936e-1,2.691138339236341e-30, - 2.690532895434228e-20,2.630615123687453e-10,2.074861066333589e-1, - 2.920284285406856e-180,2.920142569099765e-130,2.906004948173220e-80, - 1.784513607871616e-30}; - double y6[]={-1.273271380077505e+4,-1.276447832426902e+2,-1.650682606816255, - -5.868082442208572e-3,-2.444635204829711e12,-2.446148450230391e7, - -2.604058666258123e2,1.354030476893622e-1,-1.182808190517663e28, - -1.183133513204520e18,-1.216180142786892e8,-3.598141521834027e-1, - -2.179992503765307e+177,-2.180102618471610e+127,-2.191142812605340e77, - -3.641066501800778e27}; - double[] yy5=buildVector(y5),yy6=buildVector(y6),zz5=new double[N],zz6=new double[N]; - - - - // Test Bessjy (jn) - System.out.println("Testing Bessjy (jn)"); - - sbeps=5.e-14; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessjy (jn): Incorrect function values"); - - } - - // Test Bessjy (yn) - System.out.println("Testing Bessjy (yn)"); - sbeps=5.e-14; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Bessjy (yn): Incorrect function values"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Betadist.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Betadist.java deleted file mode 100644 index 28db246209..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Betadist.java +++ /dev/null @@ -1,183 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.fi.Midpnt; -import com.nr.ran.Ran; -import com.nr.sf.Betadist; -import static com.nr.fi.Midpnt.qromo; - -public class Test_Betadist { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=19; - double alpha,beta,u,a,b,integral,sbeps=2.e-15; - double xx[]={0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.65,0.7,0.75,0.8,0.85,0.9,0.95}; - double ppexp[]={0.055499225064202982,0.15278874536821926,0.27278247243349879, - 0.40743665431525133,0.55132889542179109,0.70016599098719778, - 0.85021518016199371,0.99801190557910335,1.1401716162949527, - 1.2732395447351601,1.3935430865827199,1.4970178583686551, - 1.5789710488722741,1.6337206456367952,1.6539866862653729, - 1.6297466172610049,1.5457673437898269,1.3750987083139725, - 1.0544852762198569}; - double[] x=buildVector(xx),pexp=buildVector(ppexp),p=new double[N],c=new double[N],d=new double[N]; - boolean localflag=false, globalflag=false; - - - - // Test Betadist - System.out.println("Testing Betadist"); - - // Test special cases - alpha=1.0; beta=1.0; u=0.5; - Betadist norm1 = new Betadist(alpha,beta); - localflag = abs(norm1.p(u)-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Betadist: Special case #1 failed"); - - } - - alpha=1.0; beta=2.0; u=0.5; - Betadist norm2=new Betadist(alpha,beta); - localflag = abs(norm2.p(u)-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Betadist: Special case #2 failed"); - - } - - alpha=2.0; beta=1.0; u=0.5; - Betadist norm3=new Betadist(alpha,beta); - localflag = abs(norm3.p(u)-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Betadist: Special case #3 failed"); - - } - - alpha=2.0; beta=2.0; u=0.5; - Betadist norm4=new Betadist(alpha,beta); - localflag = abs(norm4.p(u)-3.0/2.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Betadist: Special case #4 failed"); - - } - - alpha=2.0; beta=2.0; u=1.0/3.0; - Betadist norm5=new Betadist(alpha,beta); - localflag = abs(norm5.p(u)-4.0/3.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Betadist: Special case #5 failed"); - - } - - // integral of distribution is one - sbeps=2.e-6; - alpha=2.5; beta=1.5; - func_Betadist dist = new func_Betadist(alpha,beta); - Midpnt q2 = new Midpnt(dist,0.0,1.0); - integral=qromo(q2); - localflag = abs(1.0-integral) > sbeps; -// System.out.printf(setprecision(15) << 1.0-integral); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Betadist: Distribution is not normalized to 1.0"); - - } - - // cdf agrees with incomplete integral - sbeps=5.e-6; - alpha=2.5; beta=1.5; - func_Betadist dist2 = new func_Betadist(alpha,beta); - Betadist normcdf =new Betadist(alpha,beta); - localflag=false; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Betadist: cdf does not agree with result of quadrature"); - - } - - // inverse cdf agrees with cdf - alpha=2.5; beta=1.5; - Betadist normc = new Betadist(alpha,beta); - Ran myran = new Ran(17); - sbeps=5.0e-14; - localflag=false; - for (i=0;i<1000;i++) { - u=myran.doub(); - a=normc.cdf(u); - b=normc.invcdf(a); -// if (abs(u-b) > sbeps) { -// System.out.printf(setprecision(15) << u << " %f\n", b << " %f\n", abs(u-b)); -// } - localflag = localflag || abs(u-b) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Betadist: Inverse cdf does not accurately invert the cdf"); - - } - - // Fingerprint test - alpha=2.5; beta=1.5; - Betadist normf = new Betadist(alpha,beta); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Betadist: Fingerprint does not match expectations"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class func_Betadist implements UniVarRealValueFun{ - double alpha,beta; - Betadist normi; - func_Betadist(double aalpha, double bbeta) { - alpha = aalpha; - beta = bbeta; - normi = new Betadist(alpha,beta); - } - - public double funk(final double x) { - return normi.p(x); - } - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Binomialdist.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Binomialdist.java deleted file mode 100644 index d2737da9bf..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Binomialdist.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.sf.Binomialdist; - -public class Test_Binomialdist { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,n,ju,jb,M=21; - double p,a,sum,sbeps=2.e-15; - // int kk[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}; - double ppexp[]={3.6561584400629632e-005,0.00048748779200839343,0.0030874226827198371, - 0.012349690730879482,0.034990790404158277,0.074647019528871122, - 0.12441169921478451,0.16588226561971309,0.17970578775468887, - 0.1597384780041681,0.11714155053638949,0.070994879112963691, - 0.035497439556481721,0.014563052125736135,0.0048543507085786804, - 0.0012944935222876605,0.00026968615047659553,4.2303709878681877e-005, - 4.700412208742411e-006,3.2985348833279697e-007,1.0995116277760029e-008}; - // int[] k = buildVector(kk); - double[] pexp=buildVector(ppexp),pp=new double[M],c=new double[M],d=new double[M]; - boolean localflag=false, globalflag=false; - - - - - // Test Binomialdist - System.out.println("Testing Binomialdist"); - - // Test special cases - - n=1; p=0.5; ju=1; - Binomialdist norm2 = new Binomialdist(n,p); - localflag = abs(norm2.p(ju)-0.5) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Binomialdist: Special case #1 failed"); - - } - - n=2; p=0.5; ju=1; - Binomialdist norm3 = new Binomialdist(n,p); - localflag = abs(norm3.p(ju)-0.5) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Binomialdist: Special case #2 failed"); - - } - - n=2; p=0.5; ju=2; - Binomialdist norm4 = new Binomialdist(n,p); - localflag = abs(norm4.p(ju)-0.25) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Binomialdist: Special case #3 failed"); - - } - - n=3; p=1.0/3.0; ju=2; - Binomialdist norm5 = new Binomialdist(n,p); - localflag = abs(norm5.p(ju)-2.0/9.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Binomialdist: Special case #4 failed"); - - } - - // Sum of distribution is one - sbeps=1.e-14; - n=10; p=0.4; - Binomialdist dist1 = new Binomialdist(n,p); - sum=0.0; - for (i=0;i<=n;i++) - sum += dist1.p(i); - localflag = abs(1.0-sum) > sbeps; -// System.out.printf(setprecision(15) << 1.0-sum); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Binomialdist: Distribution is not normalized to 1.0"); - - } - - // cdf agrees with incomplete integral - sbeps=1.e-14; - n=10; p=0.4; - Binomialdist dist3 =new Binomialdist(n,p); - sum=0.0; - localflag=false; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Binomialdist: cdf does not agree with summation"); - - } - - // inverse cdf agrees with cdf - n=10; p=0.4; - Binomialdist normc=new Binomialdist(n,p); - sbeps=5.0e-14; - localflag=false; - for (i=1;i<10;i++) { - a=normc.cdf(i); - jb=normc.invcdf(a); -// if (abs(i-jb) > sbeps) { -// System.out.printf(setprecision(15) << i << " %f\n", jb << " %f\n", abs(i-jb)); -// } - localflag = localflag || (i-jb) != 0 && (i-jb-1) != 0; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Binomialdist: Inverse cdf does not accurately invert the cdf"); - - } - - // Fingerprint test - n=M-1; p=0.4; - sbeps=2.e-15; - Binomialdist normf=new Binomialdist(n,p); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Binomialdist: Fingerprint does not match expectations"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Cauchydist.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Cauchydist.java deleted file mode 100644 index 0c404d2131..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Cauchydist.java +++ /dev/null @@ -1,199 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static org.junit.Assert.fail; -import static com.nr.fi.Midpnt.qromo; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.fi.Midinf; -import com.nr.fi.Midpnt; -import com.nr.ran.Ran; -import com.nr.sf.Cauchydist; - -public class Test_Cauchydist { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=15; - double pi=acos(-1.0),oneoverpi,m,s,u,a,b,integral,sbeps; - double xx[]={-3.0,-2.5,-2.0,-1.5,-1.0,-0.5,0.0,0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0}; - double ppexp[]={0.032928608915564553,0.042441318157838762,0.056172332855963063, - 0.076394372684109771,0.1061032953945969,0.14691225516174955, - 0.19098593171027439,0.21220659078919379,0.19098593171027439, - 0.14691225516174955,0.1061032953945969,0.076394372684109771, - 0.056172332855963063,0.042441318157838762,0.032928608915564553}; - double[] x=buildVector(xx),pexp=buildVector(ppexp),p= new double[N],c= new double[N],d= new double[N]; - boolean localflag=false, globalflag=false; - - - - // Test Cauchydist - System.out.println("Testing Cauchydist"); - - oneoverpi=1.0/pi; - - sbeps=1.e-15; - // Test special cases - m=0; s=1; u=0; - Cauchydist norm1=new Cauchydist(m,s); - localflag = abs(norm1.p(u)-oneoverpi) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Cauchydist: Special case #1 failed"); - - } - - m=1; s=1; u=m; - Cauchydist norm2=new Cauchydist(m,s); - localflag = abs(norm2.p(u)-oneoverpi) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Cauchydist: Special case #2 failed"); - - } - - m=1; s=1; u=0; - Cauchydist norm3=new Cauchydist(m,s); - localflag = abs(norm3.p(u)-oneoverpi/2.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Cauchydist: Special case #3 failed"); - - } - - m=1; s=2; u=1; - Cauchydist norm4=new Cauchydist(m,s); - localflag = abs(norm4.p(u)-oneoverpi/2.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Cauchydist: Special case #4 failed"); - - } - - m=1; s=2; u=0; - Cauchydist norm5=new Cauchydist(m,s); - localflag = abs(norm5.p(u)-oneoverpi/2.0/(1+1.0/4.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Cauchydist: Special case #5 failed"); - - } - - // integral of distribution is one - sbeps=1.e-8; - m=1.0;s=2.0; - func_Cauchydist dist=new func_Cauchydist(m,s); - Midinf q1 = new Midinf(dist,-1.0e99,-1.0); - Midpnt q2 = new Midpnt(dist,-1.0,1.0); - Midinf q3 = new Midinf(dist,1.0,1.0e99); - integral=qromo(q1)+qromo(q2)+qromo(q3); - localflag = abs(1.0-integral) > sbeps; -// System.out.printf(setprecision(15) << 1.0-integral); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Cauchydist: Distribution is not normalized to 1.0"); - - } - - // cdf agrees with incomplete integral - sbeps=1.e-7; - m=0.5;s=1.5; - func_Cauchydist dist2=new func_Cauchydist(m,s); - Cauchydist normcdf = new Cauchydist(m,s); - localflag=false; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Cauchydist: cdf does not agree with result of quadrature"); - - } - - // inverse cdf agrees with cdf - m=0.5;s=1.5; - Cauchydist normc=new Cauchydist(m,s); - Ran myran = new Ran(17); - sbeps=1.0e-14; - localflag=false; - for (i=0;i<1000;i++) { - u=m-3.0*s+6.0*s*myran.doub(); - a=normc.cdf(u); - b=normc.invcdf(a); -// System.out.printf(setprecision(15) << u << " %f\n", b << " %f\n", abs(u-b)); - localflag = localflag || abs(u-b) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Cauchydist: Inverse cdf does not accurately invert the cdf"); - - } - - // Fingerprint test - m=0.5;s=1.5; - Cauchydist normf=new Cauchydist(m,s); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Cauchydist: Fingerprint does not match expectations"); - - } - - // Symmetry test - localflag=false; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Chisqdist: Special case #1 failed"); - - } - - df=10.0; chisq=2.0; - Chisqdist norm2=new Chisqdist(df); - localflag = abs(norm2.p(chisq)-pow(chisq,df/2.-1.)*exp(-chisq/2.)/pow(2.,df/2.)/factrl((int)(df/2.-1.))) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Chisqdist: Special case #2 failed"); - - } - - df=10.0; chisq=3.0; - Chisqdist norm3=new Chisqdist(df); - localflag = abs(norm3.p(chisq)-pow(chisq,df/2.-1.)*exp(-chisq/2.)/pow(2.,df/2.)/factrl((int)(df/2.-1.))) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Chisqdist: Special case #3 failed"); - - } - - df=6.0; chisq=1.0; - Chisqdist norm4=new Chisqdist(df); - localflag = abs(norm4.p(chisq)-pow(chisq,df/2.-1.)*exp(-chisq/2.)/pow(2.,df/2.)/factrl((int)(df/2.-1.))) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Chisqdist: Special case #4 failed"); - - } - - // integral of distribution is one - sbeps=1.e-8; - df=100.; - func_Chisqdist dist = new func_Chisqdist(df); - Midpnt q2=new Midpnt(dist,0.0,4.0); - Midinf q3=new Midinf(dist,4.0,1.0e99); - integral=qromo(q2)+qromo(q3); - localflag = abs(1.0-integral) > sbeps; -// System.out.printf(setprecision(15) << 1.0-integral); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Chisqdist: Distribution is not normalized to 1.0"); - - } - - // cdf agrees with incomplete integral - sbeps=1.e-7; - df=100.; - func_Chisqdist dist2 = new func_Chisqdist(df); - Chisqdist normcdf=new Chisqdist(df); - localflag=false; - - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Chisqdist: cdf does not agree with result of quadrature"); - - } - - // inverse cdf agrees with cdf - df=100.; - Chisqdist normc=new Chisqdist(df); - Ran myran = new Ran(17); - sbeps=2.0e-12; // XXX 1.0e-12 not pass. - localflag=false; - for (i=0;i<1000;i++) { - chisq=df-3.0*sqrt(df)+6.0*sqrt(df)*myran.doub(); - a=normc.cdf(chisq); - b=normc.invcdf(a); - if (abs(chisq-b) > sbeps) { - System.out.printf("%f %f %f\n",chisq, b ,abs(chisq-b)); - } - localflag = localflag || abs(chisq-b) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Chisqdist: Inverse cdf does not accurately invert the cdf"); - - } - - // Fingerprint test - df=100.; - Chisqdist normf=new Chisqdist(df); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Chisqdist: Fingerprint does not match expectations"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class func_Chisqdist implements UniVarRealValueFun{ - double df; - Chisqdist normi; - func_Chisqdist(double ddf) { - df = ddf; - normi = new Chisqdist(df); - } - public double funk(final double x) { - return normi.p(x); - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Erf.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Erf.java deleted file mode 100644 index cf91cf2b06..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Erf.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.sf.Erf; - -public class Test_Erf { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=13; - double sbeps; - double x[]={-4.0,-3.0,-2.0,-1.0,-0.5,-0.1,0.0,0.1,0.5,1.0,2.0,3.0,4.0}; - double y1[]={-9.999999845827421e-1,-9.999779095030015e-1,-9.953222650189527e-1, - -8.427007929497148e-1,-5.204998778130465e-1,-1.124629160182849e-1,0.0, - 1.124629160182849e-1,5.204998778130465e-1,8.427007929497148e-1, - 9.953222650189527e-1,9.999779095030015e-1,9.999999845827421e-1}; - double y2[]={1.999999984582742e+000,1.999977909503002e+000,1.995322265018953e+000, - 1.842700792949715e+000,1.520499877813047e+000,1.112462916018285e+000,1.0, - 8.875370839817152e-001,4.795001221869535e-001,1.572992070502852e-001, - 4.677734981047265e-003,2.209049699858543e-005,1.541725790028003e-008}; - double[] xx=buildVector(x),yy1=buildVector(y1),yy2=buildVector(y2),zz1= new double[N],zz2= new double[N],zz3= new double[N],zz4= new double[N]; - boolean localflag, globalflag=false; - - - - // Test Erf - System.out.println("Testing Erf"); - - Erf e = new Erf(); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Erf, erf(): Incorrect function values"); - - } - - sbeps=5.e-15; - System.out.printf("Erf, erfc(): Maximum discrepancy = %f\n", maxel(vecsub(zz2,yy2))); - localflag = maxel(vecsub(zz2,yy2)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Erf, erfc(): Incorrect function values"); - - } - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Erf, inverf(): Inversion does not return to original arguments"); - - } - - sbeps=1.e-9; - System.out.printf("Erf, inverfc(): Maximum discrepancy = %f\n", maxel(vecsub(zz4,xx))); - localflag = maxel(vecsub(zz4,xx)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Erf, inverfc(): Inversion does not return to original arguments"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Expondist.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Expondist.java deleted file mode 100644 index e4f169f724..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Expondist.java +++ /dev/null @@ -1,174 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static java.lang.Math.exp; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.fi.Midinf; -import com.nr.fi.Midpnt; -import com.nr.ran.Ran; -import com.nr.sf.Expondist; -import static com.nr.fi.Midpnt.qromo; - -public class Test_Expondist { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=21; - double beta,u,a,b,integral,sbeps=1.e-15; - double xx[]={0.0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.0,2.2,2.4,2.6,2.8,3.0,3.2,3.4,3.6,3.8,4.0}; - double ppexp[]={1.5,1.1112273310225769,0.82321745414103953, - 0.60985448961089872,0.45179131786830307,0.33469524022264474, - 0.24794833233237984,0.18368464237947291,0.13607692993411871, - 0.10080826910962463,0.074680602551795913,0.055324751101859991, - 0.040985583670938852,0.030362867168706571,0.022493365230716576, - 0.016663494807363458,0.012344620573530035,0.0091451198482734569, - 0.0067748714139189989,0.0050189481862069124,0.0037181282649995377}; - double[] x=buildVector(xx),pexp=buildVector(ppexp),p= new double[N],c= new double[N],d= new double[N]; - boolean localflag=false, globalflag=false; - - - - // Test Expondist - System.out.println("Testing Expondist"); - - // Test special cases - beta=1.0; u=0.0; - Expondist norm1=new Expondist(beta); - localflag = abs(norm1.p(u)-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Expondist: Special case #1 failed"); - - } - - beta=1.0; u=1.0; - Expondist norm2=new Expondist(beta); - localflag = abs(norm2.p(u)-exp(-1.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Expondist: Special case #2 failed"); - - } - - beta=2.0; u=0.0; - Expondist norm3=new Expondist(beta); - localflag = abs(norm3.p(u)-2.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Expondist: Special case #3 failed"); - - } - - beta=2.0; u=1.0; - Expondist norm4=new Expondist(beta); - localflag = abs(norm4.p(u)-2.0*exp(-2.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Expondist: Special case #4 failed"); - - } - - // integral of distribution is one - sbeps=1.e-8; - beta=1.5; - func_Expondist dist =new func_Expondist(beta); - Midpnt q2 = new Midpnt(dist,0.0,4.0); - Midinf q3 = new Midinf(dist,4.0,1.0e99); - integral=qromo(q2)+qromo(q3); - localflag = abs(1.0-integral) > sbeps; -// System.out.printf(setprecision(15) << 1.0-integral); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Expondist: Distribution is not normalized to 1.0"); - - } - - // cdf agrees with incomplete integral - sbeps=1.e-7; - beta=1.5; - func_Expondist dist2 = new func_Expondist(beta); - Expondist normcdf=new Expondist(beta); - localflag=false; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Expondist: cdf does not agree with result of quadrature"); - } - - // inverse cdf agrees with cdf - beta=1.5; - Expondist normc=new Expondist(beta); - Ran myran=new Ran(17); - sbeps=5.0e-14; - localflag=false; - for (i=0;i<1000;i++) { - u=3.0*myran.doub(); - a=normc.cdf(u); - b=normc.invcdf(a); -// if (abs(u-b) > sbeps) { -// System.out.printf(setprecision(15) << u << " %f\n", b << " %f\n", abs(u-b)); -// } - localflag = localflag || abs(u-b) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Expondist: Inverse cdf does not accurately invert the cdf"); - - } - - // Fingerprint test - beta=1.5; - Expondist normf=new Expondist(beta); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Expondist: Fingerprint does not match expectations"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class func_Expondist implements UniVarRealValueFun{ - double beta; - Expondist normi; - func_Expondist(double bbeta) { - beta = bbeta; - normi = new Expondist(beta); - } - - public double funk(final double x) { - return normi.p(x); - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Fdist.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Fdist.java deleted file mode 100644 index 519d8d0d72..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Fdist.java +++ /dev/null @@ -1,188 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.fi.Midpnt.qromo; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.pow; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.fi.Midinf; -import com.nr.fi.Midpnt; -import com.nr.ran.Ran; -import com.nr.sf.Fdist; -public class Test_Fdist { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=20; - double pi,nu1,nu2,u,a,b,integral,sbeps=1.e-15; - double xx[]={0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.0,2.2,2.4,2.6,2.8,3.0,3.2,3.4,3.6,3.8,4.0}; - double ppexp[]={0.65903939205294171,0.58692958722433863,0.48156597192304679, - 0.39054186195729862,0.31830988618379047,0.26197671666380806, - 0.21795679194590994,0.18326522386704397,0.15563320920200663, - 0.13338019498623788,0.11526607892303817,0.10037116939735392, - 0.088007419281388721,0.077654806187662545,0.068916111927723928, - 0.061484724623014866,0.055121565493375241,0.049638410886319047, - 0.044885720465175881,0.040743665431525217}; - double[] x=buildVector(xx),pexp=buildVector(ppexp),p= new double[N],c= new double[N],d= new double[N]; - boolean localflag=false, globalflag=false; - - - - // Test Fdist - System.out.println("Testing Fdist"); - - pi=acos(-1.0); - - // Test special cases - nu1=1.0; nu2=1.0; u=1.0; - Fdist norm1=new Fdist(nu1,nu2); - localflag = abs(norm1.p(u)-0.5/pi) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fdist: Special case #1 failed"); - - } - - nu1=1.0; nu2=2.0; u=1.0; - Fdist norm2=new Fdist(nu1,nu2); - localflag = abs(norm2.p(u)-1.0/pow(3.0,1.5)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fdist: Special case #2 failed"); - - } - - nu1=2.0; nu2=1.0; u=1.0; - Fdist norm3=new Fdist(nu1,nu2); - localflag = abs(norm3.p(u)-1.0/pow(3.0,1.5)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fdist: Special case #3 failed"); - - } - - nu1=2.0; nu2=2.0; u=1.0; - Fdist norm4=new Fdist(nu1,nu2); - localflag = abs(norm4.p(u)-0.25) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fdist: Special case #4 failed"); - - } - - nu1=2.0; nu2=2.0; u=2.0; - Fdist norm5=new Fdist(nu1,nu2); - localflag = abs(norm5.p(u)-1.0/9.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fdist: Special case #5 failed"); - - } - - // integral of distribution is one - sbeps=5.e-7; - nu1=5.0; nu2=5.0; - func_Fdist dist = new func_Fdist(nu1,nu2); - Midpnt q2 = new Midpnt(dist,0.0,10.0); - Midinf q3 = new Midinf(dist,10.0,1.0e99); - integral=qromo(q2)+qromo(q3); - localflag = abs(1.0-integral) > sbeps; -// System.out.printf(setprecision(15) << 1.0-integral); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fdist: Distribution is not normalized to 1.0"); - - } - - // cdf agrees with incomplete integral - sbeps=1.e-6; - nu1=5.0; nu2=5.0; - func_Fdist dist2 = new func_Fdist(nu1,nu2); - Fdist normcdf=new Fdist(nu1,nu2); - localflag=false; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fdist: cdf does not agree with result of quadrature"); - - } - - // inverse cdf agrees with cdf - nu1=5.0; nu2=5.0; - Fdist normc=new Fdist(nu1,nu2); - Ran myran = new Ran(17); - sbeps=5.0e-14; - localflag=false; - for (i=0;i<1000;i++) { - u=3.0*myran.doub(); - a=normc.cdf(u); - b=normc.invcdf(a); -// if (abs(u-b) > sbeps) { -// System.out.printf(setprecision(15) << u << " %f\n", b << " %f\n", abs(u-b)); -// } - localflag = localflag || abs(u-b) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fdist: Inverse cdf does not accurately invert the cdf"); - - } - - // Fingerprint test - nu1=3.0; nu2=3.0; - Fdist normf=new Fdist(nu1,nu2); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fdist: Fingerprint does not match expectations"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class func_Fdist implements UniVarRealValueFun{ - double nu1,nu2; - Fdist normi; - - func_Fdist(double nnu1, double nnu2) { - nu1 = nnu1; - nu2 = nnu2; - normi = new Fdist(nu1,nu2); - } - - public double funk(final double x) { - return normi.p(x); - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Fermi.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Fermi.java deleted file mode 100644 index 6130f47313..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Fermi.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.SQR; -import static com.nr.NRUtil.buildVector; -import static com.nr.sf.Gamma.gammln; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static java.lang.Math.exp; -import static java.lang.Math.log; -import static java.lang.Math.pow; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.sf.Fermi; - -public class Test_Fermi { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=35; - double x,y,u,theta,arg,err,maxerr,sbeps; - double k[]={-0.5,-0.5,-0.5,-0.5,-0.5,0.0,0.0,0.0,0.0,0.0, - 0.5,0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0,1.0, - 1.5,1.5,1.5,1.5,1.5,2.0,2.0,2.0,2.0,2.0, - 2.5,2.5,2.5,2.5,2.5}; - double eta[]={-4.0,-2.0,0.0,2.0,4.0,-4.0,-2.0,0.0,2.0,4.0, - -4.0,-2.0,0.0,2.0,4.0,-4.0,-2.0,0.0,2.0,4.0, - -4.0,-2.0,0.0,2.0,4.0,-4.0,-2.0,0.0,2.0,4.0, - -4.0,-2.0,0.0,2.0,4.0}; - double llerchphi[]={0.98723954437218395070,0.91377221699828150158,0.60489864342163037025, - 0.19817072295601367000,0.040035599911294837599,0.99095248754732942653, - 0.93787819412221284129,0.69314718055994530942,0.28784840479838595436, - 0.073594983080535873137,0.99358824548351926869,0.95539396843037045842, - 0.76514702462540794537,0.38214911885839316878,0.119263520628480860315, - 0.99545798433477938115,0.96805859921517155120,0.82246703342411321824, - 0.47555757258932435467,0.17631919052265099404,0.99678355180598445962, - 0.97717889296141227425,0.86719988901218413819,0.56372754572416136561, - 0.24287431294359210786,0.99772287456821212285,0.98372520603432318369, - 0.90154267736969571405,0.64369983563986970788,0.31621358700726185813, - 0.99838823665214391464,0.98841134290237239108,0.92755357777394803511, - 0.71384242344355014277,0.39321310731185353334}; - double[] zz= new double[N],lerchphi=buildVector(llerchphi),expect= new double[N]; - boolean localflag, globalflag=false; - - - - // Test Fermi - System.out.println("Testing Fermi"); - - // Test cases with theta=0 - // Fermi(k,eta,0)=exp(eta)*LerchPhi(exp(eta),k+1,1) - Fermi dirac = new Fermi(); - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fermi: Incorrect function values"); - - } - - // Limiting cases for large eta and k=1/2 - maxerr=0.0; - for (i=0;i maxerr) maxerr=err; -// System.out.printf(setw(15) << theta << setw(15) << expect[i] << setw(15) << zz[i]; -// System.out.printf(setw(15) << abs(zz[i]/expect[i]-1.0)); - } - sbeps=1.e-4; -// System.out.printf(maxerr); - localflag = maxerr > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Fermi: Incorrect dependence on theta for k=1/2 and large eta"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Gamma.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Gamma.java deleted file mode 100644 index e8c1d1e725..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Gamma.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecadd; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.sf.Gamma; - -public class Test_Gamma { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N; - double sbeps; - boolean localflag, globalflag=false; - - - - // Test Gamma - System.out.println("Testing Gamma (gammp, gammq, gser, gcf, invgammp)"); - - Gamma gam = new Gamma(); - - // Test Gamma.gammp, Gamma.gammq (as well as gser, gcf) - N=12; - double a[]={0.5,0.5,0.5,1.0,1.0,1.0,3.0,3.0,3.0,10.0,10.0,10.0}; //,110.0,200.0 - double x[]={0.5,1.0,2.0,0.5,1.0,2.5,2.0,3.5,5.0,7.0,10.0,12.5}; //,100.0,220.0 - double y[]={6.826894921370857e-1,8.427007929497149e-1,9.544997361036406e-1, - 3.934693402873665e-1,6.321205588285578e-1,9.179150013761013e-1, - 3.233235838169363e-1,6.791528011378658e-1,8.753479805169189e-1, - 1.695040627613259e-1,5.420702855281473e-1,7.985688950544638e-1}; - double[] xx=buildVector(x),yy=buildVector(y),zz= new double[N],uu= new double[N],vv= new double[N],c=buildVector(N,1.); - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gamma.gammp: Incorrect function values"); - - } - - System.out.printf("Gamma.gammq: Maximum discrepancy = %f\n", maxel(vecsub(vecadd(zz,uu),c))); - sbeps=5.e-15; - localflag = maxel(vecsub(vecadd(zz,uu),c)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gamma.gammq: gammp and gammq do not sum to 1.0"); - - } - - System.out.printf("Gamma.invgammp: Maximum discrepancy = %f\n", maxel(vecsub(xx,vv))); - sbeps=5.e-14; - localflag = maxel(vecsub(xx,vv)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gamma.invgammp: Inverse does not return to original argument x[i]"); - - } - - xx =new double[2];yy =new double[2];zz =new double[2];uu =new double[2];vv =new double[2]; - double[] aa = new double[2],cc=buildVector(2,1.0); - aa[0]=110.0; aa[1]=200.0; - xx[0]=100.0; xx[1]=210.0; - yy[0]=1.705598979081085e-1; yy[1]=7.639696745011632e-1; - zz[0]=gam.gammp(aa[0],xx[0]); zz[1]=gam.gammp(aa[1],xx[1]); - uu[0]=gam.gammq(aa[0],xx[0]); uu[1]=gam.gammq(aa[1],xx[1]); - vv[0]=gam.invgammp(zz[0],aa[0]); vv[1]=gam.invgammp(zz[1],aa[1]); - - System.out.printf("Gamma.gammp from gammpapprox: Maximum discrepancy = %f\n", maxel(vecsub(zz,yy))); - sbeps=5.e-14; - localflag = maxel(vecsub(zz,yy)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gamma.gammp from gammpapprox: Incorrect function values"); - - } - - System.out.printf("Gamma.gammq from gammpapprox: Maximum discrepancy = %f\n", maxel(vecsub(vecadd(zz,uu),cc))); - sbeps=5.e-15; - localflag = maxel(vecsub(vecadd(zz,uu),cc)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gamma.gammq from gammpapprox: gammp and gammq do not sum to 1.0"); - - } - - System.out.printf("Gamma.invgammp: Maximum discrepancy = %f\n", maxel(vecsub(xx,vv))); - sbeps=5.e-13; - localflag = maxel(vecsub(xx,vv)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gamma.invgammp with large a: Inverse does not return to original argument x[i]"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Gammadist.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Gammadist.java deleted file mode 100644 index 7dd100bd73..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Gammadist.java +++ /dev/null @@ -1,187 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static java.lang.Math.exp; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.fi.Midinf; -import com.nr.fi.Midpnt; -import com.nr.ran.Ran; -import com.nr.sf.Gammadist; -import static com.nr.fi.Midpnt.qromo; - -public class Test_Gammadist { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=20; - double alpha,beta,u,a,b,integral,sbeps=1.e-15; - double xx[]={0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0}; - double ppexp[]={0.056421908930476883,0.13735630417827352,0.21719074405218716, - 0.28780958001849588,0.34619922631227434,0.39170019681318374, - 0.42484430595288569,0.4467592468238949,0.45883671466221931, - 0.46254098941130778,0.45929855649326967,0.45043668078371302, - 0.43715226875054808,0.42049960233268446,0.40138972612974905, - 0.38059682877263284,0.35876857953338254,0.33643843523417555, - 0.31403863132501508,0.29191303997784868}; - double[] x=buildVector(xx),pexp=buildVector(ppexp),p= new double[N],c= new double[N],d= new double[N]; - boolean localflag=false, globalflag=false; - - - - // Test Gammadist - System.out.println("Testing Gammadist"); - - // Test special cases - alpha=1.0; beta=1.0; u=1.0; - Gammadist norm1 = new Gammadist(alpha,beta); - localflag = abs(norm1.p(u)-exp(-1.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gammadist: Special case #1 failed"); - - } - - alpha=1.0; beta=2.0; u=1.0; - Gammadist norm2 = new Gammadist(alpha,beta); -// System.out.printf(abs(norm2.p(u)-2.0*exp(-2.0)); - localflag = abs(norm2.p(u)-2.0*exp(-2.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gammadist: Special case #2 failed"); - - } - - alpha=2.0; beta=1.0; u=1.0; - Gammadist norm3 = new Gammadist(alpha,beta); -// System.out.printf(abs(norm3.p(u)-x*exp(-1.0)); - localflag = abs(norm3.p(u)-u*exp(-1.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gammadist: Special case #3 failed"); - - } - - alpha=3.0; beta=1.0; u=1.0; - Gammadist norm4 = new Gammadist(alpha,beta); - localflag = abs(norm4.p(u)-u*u*exp(-1.0)/2.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gammadist: Special case #4 failed"); - - } - - alpha=2.0; beta=2.0; u=2.0; - Gammadist norm5 = new Gammadist(alpha,beta); - localflag = abs(norm5.p(u)-4.0*u*exp(-4.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gammadist: Special case #5 failed"); - - } - - // integral of distribution is one - sbeps=2.e-7; - alpha=2.5; beta=1.5; - func_Gammadist dist = new func_Gammadist(alpha,beta); - Midpnt q2 = new Midpnt(dist,0.0,2.0); - Midinf q3 = new Midinf(dist,2.0,1.0e99); - integral=qromo(q2)+qromo(q3); - localflag = abs(1.0-integral) > sbeps; -// System.out.printf(setprecision(15) << 1.0-integral); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gammadist: Distribution is not normalized to 1.0"); - - } - - // cdf agrees with incomplete integral - sbeps=5.e-7; - alpha=2.5; beta=1.5; - func_Gammadist dist2 = new func_Gammadist(alpha,beta); - Gammadist normcdf = new Gammadist(alpha,beta); - localflag=false; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gammadist: cdf does not agree with result of quadrature"); - - } - - // inverse cdf agrees with cdf - alpha=2.5; beta=1.5; - Gammadist normc = new Gammadist(alpha,beta); - Ran myran = new Ran(17); - sbeps=5.0e-14; - localflag=false; - for (i=0;i<1000;i++) { - u=3.0*myran.doub(); - a=normc.cdf(u); - b=normc.invcdf(a); -// if (abs(u-b) > sbeps) { -// System.out.printf(setprecision(15) << u << " %f\n", b << " %f\n", abs(u-b)); -// } - localflag = localflag || abs(u-b) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gammadist: Inverse cdf does not accurately invert the cdf"); - - } - - // Fingerprint test - alpha=2.5; beta=1.5; - Gammadist normf = new Gammadist(alpha,beta); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gammadist: Fingerprint does not match expectations"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class func_Gammadist implements UniVarRealValueFun{ - double alpha,beta; - Gammadist normi; - func_Gammadist(double aalpha, double bbeta) { - alpha=aalpha; - beta=bbeta; - normi = new Gammadist(alpha,beta); - } - - public double funk(final double x) { - return normi.p(x); - } - }; -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_KSdist.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_KSdist.java deleted file mode 100644 index f17975479e..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_KSdist.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static java.lang.Math.exp; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Ran; -import com.nr.sf.KSdist; - -public class Test_KSdist { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=21; - double z,a,b,sbeps=1.e-13; // integral - double xx[]={0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,2.1,2.2,2.3}; - double ppksexp[]={9.3058013345666361e-006,0.0028076732227017387,0.036054756335124914, - 0.13571722094939573,0.28876480497031071,0.45585758842580204, - 0.60726929205934577,0.73000032832264539,0.82228180739359891, - 0.887750333329275,0.93190777815523362,0.96031812046188558, - 0.97778203738347491,0.98804795676080337,0.99382256936555591, - 0.99693237865242035,0.99853639516281267,0.99932907474422028, - 0.99970450327953686,0.99987495699245044,0.99994916130696765}; - double qqksexp[]={0.99999069419866549,0.9971923267772983,0.96394524366487511, - 0.86428277905060424,0.71123519502968935,0.54414241157419796, - 0.39273070794065423,0.26999967167735461,0.17771819260640109, - 0.11224966667072496,0.068092221844766362,0.039681879538114403, - 0.022217962616525127,0.011952043239196616,0.0061774306344441286, - 0.0030676213475797059,0.0014636048371873506,0.00067092525577969533, - 0.00029549672046311421,0.00012504300754960976,5.0838693032397749e-005}; - double[] x=buildVector(xx),pksexp=buildVector(ppksexp),qksexp=buildVector(qqksexp),pks= new double[N],qks= new double[N]; //,c= new double[N],d= new double[N]; - boolean localflag=false, globalflag=false; - - - - // Test KSdist - System.out.println("Testing KSdist"); - - // Test special cases - z=0.0; - KSdist norm = new KSdist(); - localflag = abs(norm.pks(z)-0.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** KSdist: Special case #1 failed for Pks"); - - } - - localflag = abs(norm.qks(z)-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** KSdist: Special case #1 failed for Qks"); - - } - - z=1.0; -// System.out.printf(setprecision(17) << norm.pks(z) << " %f\n", 1-2.0*exp(-2.0)+2.0*exp(-8.0)-2.0*exp(-18.0)); - localflag = abs(norm.pks(z)-1+2.0*exp(-2.0)-2.0*exp(-8.0)+2.0*exp(-18.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** KSdist: Special case #2 failed for Pks"); - - } - - localflag = abs(norm.qks(z)-2.0*exp(-2.0)+2.0*exp(-8.0)-2.0*exp(-18.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** KSdist: Special case #2 failed for Qks"); - - } - - z=100.0; - localflag = abs(norm.pks(z)-1.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** KSdist: Special case #3 failed for Pks"); - - } - - localflag = abs(norm.qks(z)-0.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** KSdist: Special case #3 failed for Qks"); - - } - - // Pks correctly related to Qks - localflag=false; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** KSdist: Pks and Qks do not add to 1.0 in all cases"); - - } - - // inverse of Pks agrees with Pks - Ran myran = new Ran(17); - localflag=false; - sbeps=6.e-10; // XXX 5.e-10 not pass - for (i=0;i<10;i++) { - z=0.3+3.0*myran.doub(); - a=norm.pks(z); - b=norm.invpks(a); -// if (abs(z-b) > sbeps) { -// System.out.printf(setprecision(15) << z << " %f\n", b << " %f\n", abs(z-b)); -// } - localflag = localflag || abs(z-b) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** KSdist: invPks does not accurately invert the Pks"); - - } - - // inverse of Qks agrees with Qks - localflag=false; - sbeps=5.e-10; - for (i=0;i<1000;i++) { - z=0.3+3.0*myran.doub(); - a=norm.qks(z); - b=norm.invqks(a); -// if (abs(z-b) > sbeps) { -// System.out.printf(setprecision(15) << z << " %f\n", b << " %f\n", abs(z-b)); -// } - localflag = localflag || abs(z-b) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** KSdist: invQks does not accurately invert the Qks"); - - } - - // Fingerprint test for Pks - sbeps=1.e-15; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** KSdist: Fingerprint does not match expectations"); - - } - - // Fingerprint test for Qks - sbeps=1.e-15; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** KSdist: Fingerprint does not match expectations"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Logisticdist.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Logisticdist.java deleted file mode 100644 index 1c15337db2..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Logisticdist.java +++ /dev/null @@ -1,206 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.SQR; -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.cosh; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.fi.Midinf; -import com.nr.fi.Midpnt; -import com.nr.ran.Ran; -import com.nr.sf.Logisticdist; -import static com.nr.fi.Midpnt.qromo; - -public class Test_Logisticdist { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=15; - double pi=acos(-1.0),pio4sqrt3,m,s,u,a,b,integral,sbeps=1.e-15; - double xx[]={-3.0,-2.5,-2.0,-1.5,-1.0,-0.5,0.0,0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0}; - double ppexp[]={0.017059092664760158,0.030497647063658831,0.053500875984749827, - 0.090801643627527795,0.14574392339674236,0.21404650800280242, - 0.27627401928012629,0.30229989403903629,0.27627401928012629, - 0.21404650800280242,0.14574392339674236,0.090801643627527795, - 0.053500875984749827,0.030497647063658831,0.017059092664760158}; - double[] x=buildVector(xx),pexp=buildVector(ppexp),p= new double[N],c= new double[N],d= new double[N]; - boolean localflag=false, globalflag=false; - - - - // Test Logisticdist - System.out.println("Testing Logisticdist"); - - pio4sqrt3=pi/4.0/sqrt(3.0); - - // Test special cases - m=0; s=1; u=0; - Logisticdist norm1 = new Logisticdist(m,s); - localflag = abs(norm1.p(u)-pio4sqrt3/s) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Logisticdist: Special case #1 failed"); - - } - - m=1; s=1; u=m; - Logisticdist norm2 = new Logisticdist(m,s); - localflag = abs(norm2.p(u)-pio4sqrt3) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Logisticdist: Special case #2 failed"); - - } - - m=1; s=1; u=0; - Logisticdist norm3 = new Logisticdist(m,s); -// System.out.printf(abs(norm3.p(u) - pio4sqrt3*SQR(1.0/cosh(2.0*pio4sqrt3)))); - localflag = abs(norm3.p(u)-pio4sqrt3*SQR(1.0/cosh(2.0*pio4sqrt3))) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Logisticdist: Special case #3 failed"); - - } - - m=1; s=2; u=1; - Logisticdist norm4 = new Logisticdist(m,s); - localflag = abs(norm4.p(u)-pio4sqrt3/s) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Logisticdist: Special case #4 failed"); - - } - - m=1; s=2; u=0; - Logisticdist norm5 = new Logisticdist(m,s); - localflag = abs(norm5.p(u)-pio4sqrt3/s/SQR(cosh(pio4sqrt3))) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Logisticdist: Special case #5 failed"); - - } - - // integral of distribution is one - sbeps=1.e-8; - m=1.0;s=2.0; - func_Logisticdist dist = new func_Logisticdist(m,s); - Midinf q1 = new Midinf(dist,-1.0e99,-1.0); - Midpnt q2 = new Midpnt(dist,-1.0,1.0); - Midinf q3 = new Midinf(dist,1.0,1.0e99); - integral=qromo(q1)+qromo(q2)+qromo(q3); - localflag = abs(1.0-integral) > sbeps; -// System.out.printf(setprecision(15) << 1.0-integral); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Logisticdist: Distribution is not normalized to 1.0"); - - } - - // cdf agrees with incomplete integral - sbeps=1.e-7; - m=0.5;s=1.5; - func_Logisticdist dist2 = new func_Logisticdist(m,s); - Logisticdist normcdf = new Logisticdist(m,s); - localflag=false; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Logisticdist: cdf does not agree with result of quadrature"); - - } - - // inverse cdf agrees with cdf - m=0.5;s=1.5; - Logisticdist normc = new Logisticdist(m,s); - Ran myran = new Ran(17); - sbeps=5.0e-14; - localflag=false; - for (i=0;i<1000;i++) { - u=m-3.0*s+6.0*s*myran.doub(); - a=normc.cdf(u); - b=normc.invcdf(a); -// if (abs(u-b) > sbeps) { -// System.out.printf(setprecision(15) << u << " %f\n", b << " %f\n", abs(u-b)); -// } - localflag = localflag || abs(u-b) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Logisticdist: Inverse cdf does not accurately invert the cdf"); - - } - - // Fingerprint test - m=0.5;s=1.5; - Logisticdist normf = new Logisticdist(m,s); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Logisticdist: Fingerprint does not match expectations"); - - } - - // Symmetry test - localflag=false; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Lognormaldist: Special case #1 failed"); - - } - - m=0.0; s=1.0; u=exp(1.0); - Lognormaldist norm2 = new Lognormaldist(m,s); -// System.out.printf(abs(norm2.p(u)-oneoversqt2pi*exp(-0.5)/u)); - localflag = abs(norm2.p(u)-oneoversqt2pi*exp(-0.5)/u) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Lognormaldist: Special case #2 failed"); - - } - - m=1.0; s=1.0; u=exp(0.0); - Lognormaldist norm3 = new Lognormaldist(m,s); -// System.out.printf(abs(norm3.p(u)-oneoversqt2pi*exp(-0.5)/u)); - localflag = abs(norm3.p(u)-oneoversqt2pi*exp(-0.5)/u) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Lognormaldist: Special case #3 failed"); - - } - - m=1.0; s=1.0; u=exp(m); - Lognormaldist norm4 = new Lognormaldist(m,s); - localflag = abs(norm4.p(u)-oneoversqt2pi/u) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Lognormaldist: Special case #4 failed"); - - } - - m=1.0; s=2.0; u=exp(0.0); - Lognormaldist norm5 = new Lognormaldist(m,s); - localflag = abs(norm5.p(u)-oneoversqt2pi*exp(-0.5/SQR(s))/s) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Lognormaldist: Special case #5 failed"); - - } - - // integral of distribution is one - sbeps=5.e-8; - m=0.5; s=1.5; - func_Lognormaldist dist= new func_Lognormaldist(m,s); - Midpnt q2 = new Midpnt(dist,0.0,10.0); - Midinf q3 = new Midinf(dist,10.0,1.0e99); - integral=qromo(q2)+qromo(q3); - localflag = abs(1.0-integral) > sbeps; -// System.out.printf(setprecision(15) << 1.0-integral); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Lognormaldist: Distribution is not normalized to 1.0"); - - } - - // cdf agrees with incomplete integral - sbeps=2.e-7; - m=0.5; s=1.5; - func_Lognormaldist dist2= new func_Lognormaldist(m,s); - Lognormaldist normcdf = new Lognormaldist(m,s); - localflag=false; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Lognormaldist: cdf does not agree with result of quadrature"); - - } - - // inverse cdf agrees with cdf - m=0.5; s=1.5; - Lognormaldist normc = new Lognormaldist(m,s); - Ran myran = new Ran(17); - sbeps=5.0e-14; - localflag=false; - for (i=0;i<1000;i++) { - u=3.0*myran.doub(); - a=normc.cdf(u); - b=normc.invcdf(a); -// if (abs(u-b) > sbeps) { -// System.out.printf(setprecision(15) << u << " %f\n", b << " %f\n", abs(u-b)); -// } - localflag = localflag || abs(u-b) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Lognormaldist: Inverse cdf does not accurately invert the cdf"); - - } - - // Fingerprint test - m=0.5; s=1.5; - Lognormaldist normf = new Lognormaldist(m,s); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Lognormaldist: Fingerprint does not match expectations"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class func_Lognormaldist implements UniVarRealValueFun{ - double m,s; - Lognormaldist normi; - func_Lognormaldist(double mm, double ss) { - m=mm; s=ss; - normi = new Lognormaldist(m,s); - } - public double funk(final double x) { - return normi.p(x); - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Normaldist.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Normaldist.java deleted file mode 100644 index 6ec4e4c03c..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Normaldist.java +++ /dev/null @@ -1,185 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.exp; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.ran.Ran; -import com.nr.sf.Normaldist; -import static com.nr.fi.Trapzd.qsimp; - -public class Test_Normaldist { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=15; - double pi=acos(-1.0),invsq2pi,m,s,u,a,b,sbeps; - double xx[]={-3.0,-2.5,-2.0,-1.5,-1.0,-0.5,0.0,0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0}; - double ppexp[]={0.017481259395806324,0.035993977675458706,0.066318092528499115, - 0.10934004978399577,0.1613138163460956,0.2129653370149015, - 0.25158881846199549,0.26596152026762182,0.25158881846199549, - 0.2129653370149015,0.1613138163460956,0.10934004978399577, - 0.066318092528499115,0.035993977675458706,0.017481259395806324}; - double[] x=buildVector(xx),pexp=buildVector(ppexp),p= new double[N],c= new double[N],d= new double[N]; - boolean localflag=false, globalflag=false; - - - - // Test Normaldist - System.out.println("Testing Normaldist"); - - invsq2pi=1.0/sqrt(2.0*pi); - - // Test special cases - sbeps=1.e-15; - m=0; s=1; u=0; - Normaldist norm1 = new Normaldist(m,s); - localflag = localflag || abs(norm1.p(u) - invsq2pi) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Normaldist: Special case #1 failed"); - - } - - m=1; s=1; u=m; - Normaldist norm2 = new Normaldist(m,s); - localflag = localflag || abs(norm2.p(u) - invsq2pi) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Normaldist: Special case #2 failed"); - - } - - m=1; s=1; u=0; - Normaldist norm3 = new Normaldist(m,s); - localflag = localflag || abs(norm3.p(u) - invsq2pi*exp(-0.5)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Normaldist: Special case #3 failed"); - - } - - m=1; s=2; u=1; - Normaldist norm4 = new Normaldist(m,s); - localflag = localflag || abs(norm4.p(u) - invsq2pi/2.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Normaldist: Special case #4 failed"); - - } - - m=1; s=2; u=0; - Normaldist norm5 = new Normaldist(m,s); - localflag = localflag || abs(norm5.p(u) - invsq2pi/2.0*exp(-1.0/8.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Normaldist: Special case #5 failed"); - - } - - // integral of distribution is one - sbeps=1.e-10; - m=1.0;s=2.0; - func_Normaldist dist = new func_Normaldist(m,s); - localflag = abs(1.0-qsimp(dist,-20.0,20.0)) > sbeps; - // System.out.printf(setprecision(15) << 1.0-qsimp(dist,-20.0,20.0)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Normaldist: Distribution is not normalized to 1.0"); - - } - - // cdf agrees with incomplete integral - sbeps=1.e-10; - m=0.5;s=1.5; - func_Normaldist dist2 =new func_Normaldist(m,s); - Normaldist normcdf = new Normaldist(m,s); - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Normaldist: cdf does not agree with result of quadrature"); - - } - - // inverse cdf agrees with cdf - m=0.5;s=1.5; - Normaldist normc = new Normaldist(m,s); - Ran myran = new Ran(17); - sbeps=5.0e-14; - for (i=0;i<1000;i++) { - u=m-3.0*s+6.0*s*myran.doub(); - a=normc.cdf(u); - b=normc.invcdf(a); -// System.out.printf(setprecision(15) << u << " %f\n", b << " %f\n", abs(u-b)); - localflag = localflag || abs(u-b) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Normaldist: Inverse cdf does not accurately invert the cdf"); - - } - - // Fingerprint test - m=0.5;s=1.5; - Normaldist normf = new Normaldist(m,s); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Normaldist: Fingerprint does not match expectations"); - - } - - // Symmetry test - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Poissondist: Special case #1 failed"); - - } - - lambda=1.0; ju=1; - Poissondist norm2 = new Poissondist(lambda); - localflag = abs(norm2.p(ju)-exp(-1.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Poissondist: Special case #2 failed"); - - } - - lambda=2.0; ju=0; - Poissondist norm3 = new Poissondist(lambda); - localflag = abs(norm3.p(ju)-exp(-2.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Poissondist: Special case #3 failed"); - - } - - lambda=2.0; ju=1; - Poissondist norm4 = new Poissondist(lambda); - localflag = abs(norm4.p(ju)-2.0*exp(-2.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Poissondist: Special case #4 failed"); - - } - - lambda=1.0; ju=2; - Poissondist norm5 = new Poissondist(lambda); - localflag = abs(norm5.p(ju)-0.5*exp(-1.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Poissondist: Special case #5 failed"); - - } - - lambda=2.0; ju=2; - Poissondist norm6 = new Poissondist(lambda); - localflag = abs(norm6.p(ju)-2.0*exp(-2.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Poissondist: Special case #6 failed"); - - } - - // Sum over k is one - sbeps=1.e-15; - lambda=5.0; - sum=0.0; - Poissondist dist = new Poissondist(lambda); - for (i=0;i<50;i++) - sum += dist.p(i); - localflag = abs(1.0-sum) > sbeps; -// System.out.printf(setprecision(15) << 1.0-sum); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Poissondist: Distribution is not normalized to 1.0"); - - } - - // cdf agrees with truncated sum - sbeps=1.e-15; - lambda=5.0; - Poissondist dist2 = new Poissondist(lambda); - localflag=false; - sum=0.0; - for (i=0;i<20;i++) { - sum += dist2.p(i); - c[i]=sum; - d[i]=dist2.cdf(i+1); -// System.out.printf(c[i]-d[i]); - localflag = localflag || abs(c[i]-d[i]) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Poissondist: cdf does not agree with result of quadrature"); - - } - - // inverse cdf agrees with cdf - lambda=10.0; - Poissondist normc = new Poissondist(lambda); - sbeps=1.0e-12; - localflag=false; - for (i=1;i<20;i++) { - a=normc.cdf(i); - b=normc.invcdf(a); - localflag = localflag || (i-b != 0) && (i-b-1 != 0) ; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Poissondist: Inverse cdf does not accurately invert the cdf"); - - } - - // Fingerprint test - lambda=10.0; - Poissondist normf = new Poissondist(lambda); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Poissondist: Fingerprint does not match expectations"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Studenttdist.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Studenttdist.java deleted file mode 100644 index 0190a63931..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_Studenttdist.java +++ /dev/null @@ -1,236 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.fi.Midpnt.qromo; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.fi.Midinf; -import com.nr.fi.Midpnt; -import com.nr.ran.Ran; -import com.nr.sf.Studenttdist; -public class Test_Studenttdist { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=15; - double pi=acos(-1.0),oneoverpi,m,s,n,u,a,b,integral,sbeps=1.e-15; - double xx[]={-3.0,-2.5,-2.0,-1.5,-1.0,-0.5,0.0,0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0}; - double ppexp[]={0.0328216417673656,0.045360921162651474,0.063836610836904312, - 0.090793368604857677,0.12830005981991693,0.17443694974549953, - 0.21734122156158497,0.23570226039551601,0.21734122156158497, - 0.17443694974549953,0.12830005981991693,0.090793368604857677, - 0.063836610836904312,0.045360921162651474,0.0328216417673656}; - double[] x=buildVector(xx),pexp=buildVector(ppexp),p= new double[N],c= new double[N],d= new double[N]; - boolean localflag=false, globalflag=false; - - - - // Test Studenttdist - System.out.println("Testing Studenttdist"); - - oneoverpi=1.0/pi; - - // Test special cases - n=1.0;m=0.0;s=1.0;u=0.0; - Studenttdist norm1 = new Studenttdist(n,m,s); -// System.out.printf(norm1.p(u) << " %f\n", oneoverpi << " %f\n", norm1.p(u)-oneoverpi); - localflag = abs(norm1.p(u)-oneoverpi) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Studenttdist: Special case #1 failed"); - - } - - n=1.0;m=1.0;s=1.0;u=m; - Studenttdist norm2 = new Studenttdist(n,m,s); - localflag = abs(norm2.p(u)-oneoverpi) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Studenttdist: Special case #2 failed"); - - } - - n=1.0;m=1.0;s=1.0;u=0.0; - Studenttdist norm3 = new Studenttdist(n,m,s); - localflag = abs(norm3.p(u)-oneoverpi/2.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Studenttdist: Special case #3 failed"); - - } - - n=1.0;m=1.0;s=2.0;u=1.0; - Studenttdist norm4 = new Studenttdist(n,m,s); - localflag = abs(norm4.p(u)-oneoverpi/2.0) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Studenttdist: Special case #4 failed"); - - } - - n=1.0;m=1.0;s=2.0;u=0.0; - Studenttdist norm5 = new Studenttdist(n,m,s); - localflag = abs(norm5.p(u)-oneoverpi/2.0/(1+1.0/4.0)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Studenttdist: Special case #5 failed"); - - } - - // integral of distribution is one - sbeps=1.e-10; - n=2.0;m=1.0;s=2.0; - func_Studenttdist dist = new func_Studenttdist(n,m,s); - Midinf q1 = new Midinf(dist,-1.0e99,-1.0); - Midpnt q2 = new Midpnt(dist,-1.0,1.0); - Midinf q3 = new Midinf(dist,1.0,1.0e99); - integral=qromo(q1)+qromo(q2)+qromo(q3); - localflag = abs(1.0-integral) > sbeps; -// System.out.printf(setprecision(15) << 1.0-integral); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Studenttdist: Distribution is not normalized to 1.0"); - - } - - // cdf agrees with incomplete integral - sbeps=1.e-8; - n=2.0;m=0.5;s=1.5; - func_Studenttdist dist2 = new func_Studenttdist(n,m,s); - Studenttdist normcdf = new Studenttdist(n,m,s); - localflag=false; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Studenttdist: cdf does not agree with result of quadrature"); - - } - - // inverse cdf agrees with cdf - n=2.0;m=0.5;s=1.5; - Studenttdist normc = new Studenttdist(n,m,s); - Ran myran = new Ran(17); - sbeps=1.0e-13; - localflag=false; - for (i=0;i<1000;i++) { - u=m-3.0*s+6.0*s*myran.doub(); - a=normc.cdf(u); - b=normc.invcdf(a); -// System.out.printf(setprecision(15) << u << " %f\n", b << " %f\n", abs(u-b)); - localflag = localflag || abs(u-b) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Studenttdist: Inverse cdf does not accurately invert the cdf"); - - } - - // Function aa() agrees with incomplete integral - sbeps=1.e-7; - n=2.0;m=0.0;s=1.0; - func_Studenttdist dist3 = new func_Studenttdist(n,m,s); - Studenttdist normaa = new Studenttdist(n,m,s); - localflag=false; - for (i=0;i<10;i++) { - u = 0.5*i; - Midpnt qq1 = new Midpnt(dist3,-u,u); - c[i]=qromo(qq1); - d[i]=normaa.aa(u); -// System.out.printf(setprecision(6) << c[i] << " %f\n", d[i] << " %f\n", c[i]-d[i]); - localflag = localflag || abs(c[i]-d[i]) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Studenttdist: aa() does not agree with result of direct quadrature"); - - } - - // inverse invaa() agrees with aa() - n=2.0;m=0.5;s=1.5; - Studenttdist normaa2 = new Studenttdist(n,m,s); - sbeps=1.0e-13; - localflag=false; - for (i=0;i<1000;i++) { - u=m+3.0*s*myran.doub(); - a=normaa2.aa(u); - b=normaa2.invaa(a); -// System.out.printf(setprecision(15) << u << " %f\n", b << " %f\n", abs(u-b)); - localflag = localflag || abs(u-b) > sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Studenttdist: Inverse invaa() does not accurately invert aa()"); - - } - - // Fingerprint test - n=2.0;m=0.5;s=1.5; - Studenttdist normf = new Studenttdist(n,m,s); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Studenttdist: Fingerprint does not match expectations"); - - } - - // Symmetry test - localflag=false; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** beta: Incorrect function values"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_betai.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_betai.java deleted file mode 100644 index 14b4e80bda..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_betai.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Ran; -import com.nr.sf.Beta; - -public class Test_betai { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=21,M=100; - double c,d,u,r,uu,sbeps; - double a[]={0.1,0.1,0.1,0.5,0.5,0.5,1.0,1.0,1.0,2.0,2.0,2.0, - 5.0,5.0,5.0,10.0,10.0,10.0,20.0,20.0,20.0}; - double b[]={0.1,2.0,5.0,0.1,2.0,5.0,0.1,2.0,5.0,0.1,2.0,5.0, - 0.1,2.0,5.0,0.1,2.0,5.0,0.1,2.0,5.0}; - double x[]={0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,0.0, - 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9}; - double y[]={0.0,0.8658177758494670,0.9766004939306013, - 0.1073414121635943,0.8221921916437793,0.9898804402645663, - 8.755646344451919e-2,0.9099999999999999,0.9996800000000000, - 0.1341822241505331,1.0,0.0, - 2.646501824334656e-7,1.600000000000003e-3,9.880866000000001e-2, - 2.079166305336834e-6,5.859375000000002e-3,0.2792569872383998, - 1.527902462384040e-5,5.764607523034282e-2,0.9149251141213293}; - double[] yy=buildVector(y),zz = new double[N]; - boolean localflag, globalflag=false; - - - - // Test betai - System.out.println("Testing betai, invbetai"); - - // Beta bi = new Beta(); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** betai: Incorrect function values"); - - } - - // Round trip test - Ran myran = new Ran(17); - sbeps=1.e-8; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** betai: Failure in round-trip test"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_bico.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_bico.java deleted file mode 100644 index eb86667839..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_bico.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.sf.Gamma.bico; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class Test_bico { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=50; - double sbeps=1.e-12; - double y[]={1.0,5.0,10.0,10.0,5.0,1.0}; - double[] x= new double[N],z= new double[N]; - boolean localflag, globalflag=false; - - - - // Test bico - System.out.println("Testing bico"); - - // Test some small values - localflag = bico(0,0) != 1.0; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** bico: Incorrect value for special case bico(0,0)=1"); - - } - - localflag = bico(1,1) != 1.0; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** bico: Incorrect value for special case bico(1,1)=1"); - - } - - for (i=0;i<6;i++) { - localflag = localflag || bico(5,i) != y[i]; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** bico: Test of bico with small arguments failed"); - - } - } - - // Test recursion in k, for n < 171 - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** bico: Test of recursion in k for n < 171 failed"); - - } - - // Test recursion in k, for n > 171 - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** bico: Test of recursion in k for n > 171 failed"); - - } - - // Test recursion in n - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** bico: Test of recursion in n failed"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_cisi.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_cisi.java deleted file mode 100644 index cb05e523ad..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_cisi.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.Complex; -import static com.nr.NRUtil.*; -import static com.nr.sf.Integrals.*; - -public class Test_cisi { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=16; - double sbeps=1.0e-15; - Complex zz1,zz2; - double x[]={0.5,0.6,0.7,0.8,0.9,1.0,1.2,1.4,1.6,1.8,2.0,2.5,3.0,3.5,4.0,4.5}; - double u[]={-0.1777840788066129,-0.02227070695927976,0.1005147070088978, - 0.1982786159524672,0.2760678304677729,0.3374039229009681, - 0.4204591828942405,0.4620065850946773,0.4717325169318778, - 0.4568111294183369,0.4229808287748650,0.2858711963653835, - 0.1196297860080003,-0.03212854851248112,-0.1409816978869304, - -0.1934911221017388}; - double v[]={0.4931074180430667,0.5881288096080801,0.6812222391166113, - 0.7720957854819966,0.8604707107452929,0.9460830703671830, - 1.108047199013719,1.256226732779218,1.389180485870438, - 1.505816780255579,1.605412976802695,1.778520173443827, - 1.848652527999468,1.833125398665997,1.758203138949053, - 1.654140414379244}; - double[] uu=buildVector(u),vv=buildVector(v),zreal = new double[N],zimag = new double[N]; - Complex[] zz = new Complex[N]; - boolean localflag=false, globalflag=false; - - - - // Test cisi - System.out.println("Testing cisi"); - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** cisi: Incorrect function values for cosine integral"); - - } - - System.out.printf("cisi: Maximum discrepancy of sine integral = %f\n", maxel(vecsub(zimag,vv))); - localflag = maxel(vecsub(zimag,vv)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** cisi: Incorrect function values for sine integral"); - - } - - // Test symmetries - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** dawson: Incorrect function values"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_ei.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_ei.java deleted file mode 100644 index 7f846e7edf..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_ei.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.nr.test.test_chapter6; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static com.nr.test.NRTestUtil.*; -import static com.nr.NRUtil.*; -import static com.nr.sf.Integrals.*; - -public class Test_ei { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=10; - double sbeps=1.e-15; - double x[]={0.5e-292,0.5,1.0,2.0,4.0,8.0,16.0,32.0,64.0,128.0}; - double y[]={-6.724707786699197e+002,4.542199048631735e-1,1.895117816355937, - 4.954234356001890,1.963087447005622e1,4.403798995348382e2, - 5.955609986708373e5,2.550043566357786e12,9.899640925974459e25, - 3.061380614342898e+053}; - double[] zz = new double[N],cc =buildVector(N,1.); - boolean localflag, globalflag=false; - - - - // Test ei - System.out.println("Testing ei"); - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ei: Incorrect function values"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_elle.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_elle.java deleted file mode 100644 index b892980102..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_elle.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.nr.test.test_chapter6; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static com.nr.test.NRTestUtil.*; -import static com.nr.sf.Elliptic.*; - -public class Test_elle { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=16,M=10; - double sbeps; - double elle1[]={0.0,0.0998334166468281523,0.198669330795061215,0.295520206661339575, - 0.389418342308650492,0.479425538604203000,0.564642473395035357, - 0.644217687237691054,0.717356090899522762,0.783326909627483388, - 0.841470984807896507,0.891207360061435340,0.932039085967226350, - 0.963558185417192965,0.985449729988460181,0.997494986604054431}; - double elle2[]={0.523598776000000000,0.522691528960261784,0.519952907231629841, - 0.515330345767519975,0.508729236913189576,0.500000000347883381, - 0.488913351004473020,0.475110551307264258,0.457989419291834486, - 0.436367226265627954}; - double elle3[]={0.0,0.0499165830243987898,0.0993306265758595741,0.147729048734116570, - 0.194575897058209209,0.239295761817418877,0.281248556340456227, - 0.319686389142797354,0.353669004307650793,0.381861529207714857, - 0.401819480553494865}; - double[] a= new double[N],b= new double[N],c=new double[M],d=new double[M]; - boolean localflag, globalflag=false; - - - - // Test elle - System.out.println("Testing elle"); - - // Test values vs. phi for k=1 - sbeps=5.e-15; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** elle: Incorrect function of phi for k=1"); - - } - - // Test values vs. k for phi=0.523598776 (approx 30 deg) - sbeps=1.e-15; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** elle: Incorrect function of k for phi=0.523598776 (30 deg)"); - - } - - // Test values vs. k for phi=0.523598776 (approx 30 deg) - sbeps=1.e-15; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** elle: Incorrect function of phi for k=2"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_ellf.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_ellf.java deleted file mode 100644 index 528a26b065..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_ellf.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.nr.test.test_chapter6; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static com.nr.test.NRTestUtil.*; -import static com.nr.sf.Elliptic.*; - -public class Test_ellf { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=16,M=10; - double sbeps; - double ellf1[]={0.0,0.100167084547480182,0.201346823567727507,0.304603974401704104, - 0.411114219868596574,0.522238103278440330,0.639622515807764521, - 0.765350458597682954,0.902176698545870355,1.05392311374108558, - 1.22619117088351707,1.42776351721775348,1.67369924955824305, - 1.99339831974637447,2.45799559037297901,3.34067754279831100}; - double ellf2[]={0.523598776000000000,0.524508805698164762,0.527290159585071990, - 0.532106526205558691,0.539268044529137392,0.549306144797899353, - 0.563134596139227132,0.582430260118548007,0.610720592279546591, - 0.657851366229664988}; - double ellf3[]={0.0,0.0500836684734863288,0.1006775690197592557,0.152335159818448609, - 0.205707351112816793,0.261624740315344007,0.321243014549783015, - 0.386340279820085692,0.460042170380593855,0.549140322320619453, - 0.677417538203930387}; - double[] a= new double[N],b= new double[N],c=new double[M],d=new double[M]; - boolean localflag, globalflag=false; - - - - // Test ellf - System.out.println("Testing ellf"); - - // Test values vs. phi for k=1 - sbeps=5.e-15; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ellf: Incorrect function of phi for k=1"); - - } - - // Test values vs. k for phi=0.523598776 (approx 30 deg) - sbeps=1.e-15; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ellf: Incorrect function of k for phi=0.523598776 (30 deg)"); - - } - - // Test values vs. k for phi=0.523598776 (approx 30 deg) - sbeps=1.e-15; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ellf: Incorrect function of phi for k=2"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_ellpi.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_ellpi.java deleted file mode 100644 index 6b085bf24a..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_ellpi.java +++ /dev/null @@ -1,152 +0,0 @@ -package com.nr.test.test_chapter6; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static com.nr.test.NRTestUtil.*; -import static com.nr.sf.Elliptic.*; - -public class Test_ellpi { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=16,M=10; - double sbeps,en; - double ellpi1[]={0.0,0.100502764417104114,0.204089873528317272,0.314201094547181115, - 0.435071344871511048,0.572373236468860396,0.734271021897322517, - 0.933304100500074239,1.19002091819793195,1.54058608179260362, - 2.05433293325624867,2.87964064018147283,4.38603767215661825, - 7.72963041510352791,18.2848934716992433,101.345047515285793}; - double ellpi2[]={0.577350269725227267,0.578430405929852887,0.581733633663630267, - 0.5874607596963754851,0.595993115974939418,0.607986406118820100, - 0.624573540241628753,0.647846914950448347,0.682245757590558980, - 0.740309437183358951}; - double ellpi3[]={0.0,0.0501255025975285727,0.1010163386701090373, - 0.153502472640551107,0.208558872308446512,0.267425749123095321, - 0.331818001829399680,0.404347204331590915,0.489536097087013840, - 0.597017539786347541,0.759657207054964912}; - double ellpi4[]={0.0,0.0998354001533643479,0.198731283496840194, - 0.295972908157878589,0.391232663483947057,0.484645541930822404, - 0.576819001486806192,0.668825019188343865,0.762228160389261813, - 0.859207265936498094,0.962856407616018361,1.077849756916385261, - 1.211968082663659937,1.380119771567129244,1.61803271724411808, - 2.06241081470741402}; - double ellpi5[]={0.484169591972923381,0.484961714960443253,0.487381591588874436, - 0.491568024729042223,0.497783554574451842,0.506476877038506087, - 0.518416731663483363,0.535007150197453044,0.559183303289873315, - 0.599067832583639964}; - double ellpi6[]={0.0,0.0500419596493322059,0.100342838645592538, - 0.151198919592696644,0.202989354783613223,0.256242731928117456, - 0.311751967994650342,0.370807081967643963,0.435763040026915024, - 0.511863662072828734,0.617791316339181780}; - double[] a= new double[N],b= new double[N],c=new double[M],d=new double[M]; - boolean localflag, globalflag=false; - - - - // Test ellpi - System.out.println("Testing ellpi"); - - // Test values vs. phi for k=1 and n=-1 - en=-1.0; - sbeps=1.e-13; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ellpi: Incorrect function of phi for k=1 and n=-1"); - - } - - // Test values vs. k for phi=0.523598776 (approx 30 deg) and n=-1 - sbeps=1.e-15; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ellpi: Incorrect function of k for phi=0.523598776 (30 deg) and n=-1"); - - } - - // Test values vs. k for phi=0.523598776 (approx 30 deg) and n=-1 - sbeps=1.e-15; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ellpi: Incorrect function of phi for k=2 and n=-1"); - - } - - // Test values vs. phi for k=1 and n=+1 - en=+1.0; - sbeps=1.e-14; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ellpi: Incorrect function of phi for k=1 and n=+1"); - - } - - // Test values vs. k for phi=0.523598776 (approx 30 deg) and n=+1 - sbeps=1.e-15; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ellpi: Incorrect function of k for phi=0.523598776 (30 deg) and n=+1"); - - } - - // Test values vs. k for phi=0.523598776 (approx 30 deg) and n=+1 - sbeps=1.e-15; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** ellpi: Incorrect function of phi for k=2 and n=+1"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_erfcc.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_erfcc.java deleted file mode 100644 index df8f4545a2..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_erfcc.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.sf.Erf; - -public class Test_erfcc { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=13; - double sbeps=2.e-7; - double x[]={-4.0,-3.0,-2.0,-1.0,-0.5,-0.1,0.0,0.1,0.5,1.0,2.0,3.0,4.0}; - double[] yy= new double[N],zz= new double[N]; - boolean localflag, globalflag=false; - - - - // Test erfcc - System.out.println("Testing erfcc"); - - Erf e = new Erf(); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** erfcc: Error exceeds single precision accuracy"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_expint.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_expint.java deleted file mode 100644 index 5ec33ddc8c..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_expint.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.nr.test.test_chapter6; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static com.nr.test.NRTestUtil.*; -import static com.nr.NRUtil.*; -import static java.lang.Math.*; -import static com.nr.sf.Integrals.*; - -public class Test_expint { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,m,N=22; - double a,b,expect,sbeps=5.e-15; - int n[]={0,0,0,0,0,1,1,1,1,1,2,2,2,2,3,3,4,4,5,5,10,10}; - double x[]={0.01,0.1,0.5,1.0,2.0,0.01,0.1,0.5,1.0,2.0, - 0.0,0.5,1.0,2.0,0.0,1.0,0.0,1.0,0.0,1.0,0.0,1.0}; - double y[]={9.900498337491680e1,9.048374180359595,1.213061319425267, - 3.678794411714423e-1,6.766764161830635e-2,4.037929576538114, - 1.822923958419390,5.597735947761607e-1,2.193839343955203e-1, - 4.890051070806113e-2,1.0,0.32664386232455301773, - 0.14849550677592204,0.037534261820490452,0.5, - 0.10969196719776013,0.33333333333333333,0.086062491324560728, - 0.250,0.070454237461720398,0.11111111111111111, - 0.036393994031416401634}; - double[] yy=buildVector(y),zz = new double[N]; - boolean localflag, globalflag=false; - - - - // Test expint - System.out.println("Testing expint"); - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** expint: Incorrect function values"); - - } - - // Test special cases - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** expint: Failure of special case n=0"); - - } - } - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** expint: Failure of special case x=0.0"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_factln.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_factln.java deleted file mode 100644 index e58fd68399..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_factln.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.nr.test.test_chapter6; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static com.nr.test.NRTestUtil.*; -import static com.nr.NRUtil.*; -import static com.nr.sf.Gamma.*; -public class Test_factln { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=9; - double sbeps=1.e-13; - int x[]={0,1,2,4,8,16,32,64,128}; - double y[]={0.0,0.0,0.6931471805599453,3.178053830347946,1.060460290274525e1, - 3.067186010608067e1,8.155795945611504e1,2.051681994826412e2, - 4.964054784872176e2}; - double[] yy =buildVector(y),z = new double[N]; - boolean localflag, globalflag=false; - - - - // Test factln - System.out.println("Testing factln"); - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** factln: Incorrect function values"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_factrl.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_factrl.java deleted file mode 100644 index 0d96612b65..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_factrl.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.nr.test.test_chapter6; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static com.nr.test.NRTestUtil.*; -import static com.nr.NRUtil.*; -import static com.nr.sf.Gamma.*; - -public class Test_factrl { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=9; - double sbeps=5.e-15; - int x[]={0,1,2,4,8,16,32,64,128}; - double y[]={1.0,1.0,2.0,24.0,40320.0,2.092278988800000e13, - 2.631308369336935e35,1.268869321858842e89, - 3.856204823625803e+215}; - double[] z = new double[N],c = buildVector(N,1.0); - boolean localflag, globalflag=false; - - - - // Test factrl - System.out.println("Testing factrl"); - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** factrl: Incorrect function values"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_frenel.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_frenel.java deleted file mode 100644 index d6e082dafa..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_frenel.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.sf.Integrals.frenel; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.Complex; - -public class Test_frenel { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=16; - double sbeps=1.0e-15; - double xx[]={0.0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.0,2.2,2.4,2.6,2.8,3.0}; - double cc[]={0.0,0.1999210575944531,0.3974807591723594,0.5810954469916523, - 0.7228441718963561,0.7798934003768228,0.7154377229230734, - 0.5430957835462564,0.3654616834404877,0.3336329272215571, - 0.4882534060753408,0.6362860449033195,0.5549614058564281, - 0.3889374961919690,0.4674916516989060,0.6057207892976856}; - double ss[]={0.0,0.004187609161656762,0.03335943266061318,0.1105402073593870, - 0.2493413930539178,0.4382591473903548,0.6234009185462497, - 0.7135250773634121,0.6388876835093809,0.4509387692675831, - 0.3434156783636982,0.4557046121246569,0.6196899649456836, - 0.5499893231527195,0.3915284435431718,0.4963129989673750}; - double[] x=buildVector(xx),c=buildVector(cc),s=buildVector(ss),zreal= new double[N],zimag= new double[N]; - Complex[] z= new Complex[N]; - boolean localflag, globalflag=false; - - - - // Test frenel - System.out.println("Testing frenel"); - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** frenel: Incorrect function values for C(x)"); - - } - - System.out.printf("frenel: Maximum discrepancy in S(x) = %f\n", maxel(vecsub(zimag,s))); - localflag = maxel(vecsub(zimag,s)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** frenel: Incorrect function values for S(x)"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_gammln.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_gammln.java deleted file mode 100644 index 899d82eff4..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_gammln.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.nr.test.test_chapter6; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import static com.nr.test.NRTestUtil.*; -import static com.nr.NRUtil.*; -import com.nr.sf.Gamma; -public class Test_gammln { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=10; - double sbeps=5.e-15; - double x[]={0.5,1.0,1.5,2.0,3.0,4.0,5.0,7.0,10.0,20.0}; - double y[]={0.5723649429247001,0.0,-0.1207822376352453,0.0,0.6931471805599454, - 1.791759469228055,3.178053830347945,6.579251212010101,12.80182748008147, - 39.33988418719950}; - double[] yy=buildVector(y),zz = new double[N]; - boolean localflag, globalflag=false; - - - - // Test gammln - System.out.println("Testing gammln"); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** gammln: Incorrect function values"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_hypgeo.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_hypgeo.java deleted file mode 100644 index 78060bb7ed..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_hypgeo.java +++ /dev/null @@ -1,210 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.sf.Hypergeo.hypgeo; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.Complex; - -public class Test_hypgeo { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=20,M=100; - double err,errmax,sbeps; - Complex aa,bb,cc,zz,res1,res2; - Complex a[]={new Complex(1.0,0.0), new Complex(0.0,1.0),new Complex(1.0,0.0),new Complex(1.0,0.0), - new Complex(1.0,0.0),new Complex(2.0,0.0),new Complex(3.0,0.0),new Complex(2.0,0.0), - new Complex(2.0,0.0),new Complex(3.0,0.0),new Complex(3.0,0.0),new Complex(2.0,0.0), - new Complex(1.0,0.0),new Complex(0.0,1.0),new Complex(1.0,0.0),new Complex(1.0,0.0), - new Complex(5.0,0.0),new Complex(0.0,3.0),new Complex(0.0,-4.0),new Complex(-5.0,0.0)}; - Complex b[]={new Complex(1.0,0.0),new Complex(1.0,0.0),new Complex(0.0,1.0),new Complex(1.0,0.0), - new Complex(1.0,0.0),new Complex(2.0,0.0),new Complex(3.0,0.0),new Complex(2.0,0.0), - new Complex(2.0,0.0),new Complex(3.0,0.0),new Complex(3.0,0.0),new Complex(2.0,0.0), - new Complex(1.0,0.0),new Complex(0.0,1.0),new Complex(0.0,1.0),new Complex(1.0,0.0), - new Complex(0.0,5.0),new Complex(2.0,0.0),new Complex(0.0,-1.0),new Complex(3.0,0.0)}; - Complex c[]={new Complex(1.0,0.0),new Complex(1.0,0.0),new Complex(1.0,0.0),new Complex(0.0,1.0), - new Complex(1.0,0.0),new Complex(2.0,0.0),new Complex(3.0,0.0),new Complex(2.0,0.0), - new Complex(2.0,0.0),new Complex(3.0,0.0),new Complex(3.0,0.0),new Complex(2.0,0.0), - new Complex(1.0,0.0),new Complex(0.0,1.0),new Complex(1.0,0.0),new Complex(0.0,1.0), - new Complex(0.0,-2.0),new Complex(0.0,-2.0),new Complex(7.0,0.0),new Complex(0.0,7.0)}; - Complex z[]={new Complex(0.5,0.0),new Complex(0.5,0.0),new Complex(0.5,0.0),new Complex(0.5,0.0), - new Complex(0.0,1.0),new Complex(0.0,1.0),new Complex(0.0,1.0),new Complex(0.0,0.0), - new Complex(0.5,0.0),new Complex(0.5,0.0),new Complex(-0.5,0.0),new Complex(-0.5,0.0), - new Complex(-0.5,0.0),new Complex(0.0,1.0),new Complex(1.0,1.0),new Complex(1.0,1.0), - new Complex(1.0,1.0),new Complex(1.0,3.0),new Complex(2.0,-3.0),new Complex(5.0,7.0)}; - Complex eexpect[]={new Complex(2.0,0.0), - new Complex(0.76923890136397212658,0.63896127631363480115), - new Complex(0.76923890136397212658,0.63896127631363480115), - new Complex(0.18874993960184887345,-0.73280804956611519935), - new Complex(0.5,0.5),new Complex(0.0,0.5),new Complex(-0.25,0.25), - new Complex(1.0,0.0),new Complex(4.0,0.0),new Complex(8.0,0.0), - new Complex(0.29629629629629629630,0.0), - new Complex(0.44444444444444444444,0.0), - new Complex(0.66666666666666666667,0.0), - new Complex(0.42882900629436784932,-0.15487175246424677819), - new Complex(0.20787957635076190855,0.0), - new Complex(2.4639512200927103386,5.0258643859042736965), - new Complex(0.000782175555099748119,0.065075199065027035764), - new Complex(-0.31205397840397702583,-0.04344693995132976350), - new Complex(0.34836454596486382673,0.65394630061667130711), - new Complex(617.9369000550522997,2595.6638964158808010)}; - Complex[] y=new Complex[N],expect=new Complex[N]; - System.arraycopy(eexpect, 0,expect,0, N);; - boolean localflag, globalflag=false; - - - - // Test selected values - System.out.println("Testing hypgeo"); - errmax=0.0; - for (i=0;i errmax) errmax=err; - } -// System.out.println("hypgeo: Maximum fractional discrepancy = %f\n", errmax); - sbeps=1.e-10; - localflag = errmax > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** hypgeo: Incorrect function values"); - - } - - // Test symmetry of a and b - sbeps=1.e-15; - localflag=false; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** hypgeo: Lack of symmetry in first two arguments"); - - } - - // Test case a=c, b=1 where hypgeo=1/(1-z) - sbeps=1.e-12; - localflag=false; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** hypgeo: Failure of special case a=c, b=1"); - - } - - // Test a contiguous relationship for aa (Abromowitz & Stegun, 15.2.13) - sbeps=1.e-12; - localflag=false; - for (i=0;i sbeps; - - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** hypgeo: Failure of contiguous relationship for aa"); - - } - - // Test a contiguous relationship for cc (Abromowitz & Stegun, 15.2.27) - sbeps=1.e-10; - localflag=false; - for (i=0;i sbeps; - - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** hypgeo: Failure of contiguous relationship for cc"); - - } - - // Test of mirror symmetry - sbeps=1.e-15; - localflag=false; - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** hypgeo: Function does not follow mirror symmetry rule"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_invxlogx.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_invxlogx.java deleted file mode 100644 index e30545a64c..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_invxlogx.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.sf.Integrals.invxlogx; -import static java.lang.Math.abs; -import static java.lang.Math.exp; -import static java.lang.Math.log; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Ran; - -public class Test_invxlogx { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=100000; - double x,y1,y2,sbeps=1.0e-15; - boolean localflag, globalflag=false; - - - - // Test invxlogx - System.out.println("Testing invxlogx"); - - Ran myran = new Ran(17); - for (i=0;isbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** invxlogx: Incorrect function value for y=y1"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_plegendre.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_plegendre.java deleted file mode 100644 index d553e9dec3..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_plegendre.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.sf.Legendre; - -public class Test_plegendre { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=15; - double sbeps=1.0e-15; - int l[]={0,1,1,2,2,2,3,3,3,3,5,10,15,20,25}; - int m[]={0,0,1,0,1,2,0,1,2,3,3,5,7,5,3}; - double x[]={0.5,-0.5,0.2,-0.4,0.6,0.2,-0.4,0.6,-0.8,0.7,-0.7,0.4,-0.4,0.1,0.5}; - double y[]={2.820947917738781e-001,-2.443012559514600e-001,-3.385137501286538e-001, - -1.640036139313104e-001,-3.708232339422620e-001,3.708232339422620e-001, - 3.283951726793016e-001,-2.068353178330564e-001,-2.943318172127853e-001, - -1.519582778329822e-001,-4.296502741348962e-001,2.127192227262643e-001, - -2.877479076870877e-001, 2.957240266476461e-001,2.658533041450948e-001}; - double[] yy = buildVector(y),zz = new double[N]; - boolean localflag, globalflag=false; - - - - // Test plegendre - System.out.println("Testing plegendre"); - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** plegendre: Incorrect function values"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_rc.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_rc.java deleted file mode 100644 index 3c0721f433..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_rc.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.sf.Elliptic.rc; -import static com.nr.sf.Elliptic.rf; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Ran; -public class Test_rc { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=1000,M=15; - double x,y,sbeps; - double xx[]={0.5,0.5,0.5,1.0,1.0,1.0,2.0,2.0,2.0, - 5.0,5.0,5.0,10.0,10.0,10.0}; - double yy[]={0.5,5.0,10.0,0.5,5.0,10.0,0.5,5.0,10.0, - 0.5,5.0,10.0,0.5,5.0,10.0}; - double fingerprint[]={1.4142135623730949,0.58880582378346324,0.43646741450163296, - 1.246450480280461,0.55357435889704532,0.41634859079941822, - 1.0752916200648814,0.51157686594443497,0.39143618306709632, - 0.85722388169844077,0.44721359549995793,0.35124073655203636, - 0.70672482712931073,0.39416225082970491,0.31622776601683794}; - double[] f1= new double[N],f2= new double[N],ff1 = new double[M],expect = buildVector(fingerprint); - boolean localflag, globalflag=false; - - - - // Test rc - System.out.println("Testing rc"); - - // Test values against those of rf(x,y,z); - Ran myran = new Ran(17); - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rc: Function rc(x,y) does not equal rf(x,y,y)"); - - } - - // Fingerprint test - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rc: Fuction does not match previously computed fingerprint"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_rd.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_rd.java deleted file mode 100644 index 81d94de05a..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_rd.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.sf.Elliptic.rd; -import static com.nr.sf.Elliptic.rj; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Ran; - -public class Test_rd { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=1000,M=15; - double x,y,z,sbeps; - double xx[]={0.5,0.5,0.5,1.0,1.0,1.0,2.0,2.0,2.0, - 5.0,5.0,5.0,10.0,10.0,10.0}; - double yy[]={0.5,5.0,10.0,0.5,5.0,10.0,0.5,5.0,10.0, - 0.5,5.0,10.0,0.5,5.0,10.0}; - double zz[]={0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0, - 0.5,1.0,1.5,2.0,2.5,3.0,3.5}; - double fingerprint[]={2.828427124746189,0.6761446800665275,0.3561311564429841, - 0.61767396750725501,0.25585876344175834,0.16707403783066954, - 0.28683033981461781,0.14094109198361518,0.57990472541731197, - 0.6761446800665275,0.24574380041928576,0.1516469228750387, - 0.22495805526027765,0.10980936208850103,0.076942538498807111}; - double[] f1= new double[N],f2= new double[N],ff1 = new double[M],expect = buildVector(fingerprint); - boolean localflag, globalflag=false; - - - - // Test rd - System.out.println("Testing rd"); - - // Test values against those of rj(x,y,z); - Ran myran = new Ran(17); - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rd: Function rd(x,y,z) does not equal rf(x,y,z,z)"); - - } - - // Fingerprint test - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rd: Fuction does not match previously computed fingerprint"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_rf.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_rf.java deleted file mode 100644 index dd58fe23b6..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_rf.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.sf.Elliptic.rf; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Ran; -public class Test_rf { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=1000,M=15; - double x,y,z,lambda,sbeps; - double xx[]={0.5,0.5,0.5,1.0,1.0,1.0,2.0,2.0,2.0, - 5.0,5.0,5.0,10.0,10.0,10.0}; - double yy[]={0.5,5.0,10.0,0.5,5.0,10.0,0.5,5.0,10.0, - 0.5,5.0,10.0,0.5,5.0,10.0}; - double zz[]={0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0, - 0.5,1.0,1.5,2.0,2.5,3.0,3.5}; - double fingerprint[]={1.4142135623730949,0.78318403980915063,0.61671477142548603, - 0.96885765327245232,0.62910156611289225,0.52066873070659714, - 0.76120858506833289,0.532702194896431,0.59067521087321406, - 0.78318403980915063,0.52979548043855929,0.44484198345350334, - 0.56995656023418362,0.42344785821702513,0.36781365041076669}; - double[] f1= new double[N],f2= new double[N],f3= new double[N],ff1 = new double[M],expect = buildVector(fingerprint); - boolean localflag, globalflag=false; - - - - // Test rf - System.out.println("Testing rf"); - - Ran myran = new Ran(17); - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rf: Function rf(x,y,z) does not follow duplication theorem rule 1"); - - } - - sbeps=1.e-14; - localflag = maxel(vecsub(f1,f3)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rf: Function rf(x,y,z) does not follow duplication theorem rule 2"); - - } - - // Test rf(x,x,x) = 1/sqrt(x) - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rf: Function rf(x,x,x) is not equal to 1/sqrt(x)"); - - } - - // Symmetry test - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rf: Function rf(x,y,z) is not equal to rf(y,x,z)"); - - } - - // Symmetry of y and z - System.out.printf("rf: maximum discrepance with swap of y,z = %f\n", maxel(vecsub(f1,f3))); - - sbeps=1.e-14; - localflag = maxel(vecsub(f1,f3)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rf: Function rf(x,y,z) is not equal to rf(x,z,y)"); - - } - - // Fingerprint test - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rf: Fuction does not match previously computed fingerprint"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_rj.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_rj.java deleted file mode 100644 index 388c0c204b..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_rj.java +++ /dev/null @@ -1,162 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.buildVector; -import static com.nr.sf.Elliptic.rj; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.pow; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Ran; - -public class Test_rj { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=1000,M=15; - double x,y,z,p,sbeps; // lambda not used. - double xx[]={0.5,0.5,0.5,1.0,1.0,1.0,2.0,2.0,2.0, - 5.0,5.0,5.0,10.0,10.0,10.0}; - double yy[]={0.5,5.0,10.0,0.5,5.0,10.0,0.5,5.0,10.0, - 0.5,5.0,10.0,0.5,5.0,10.0}; - double zz[]={0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0, - 0.5,1.0,1.5,2.0,2.5,3.0,3.5}; - double pp[]={0.5,0.5,1.0,1.0,2.0,2.0,5.0,5.0,10.0,10.0, - 0.5,1.0,2.0,5.0,10.0}; - double fingerprint[]={2.8284271247461894,0.98504492018034995,0.44793650058808648, - 0.96012401711294937,0.29241747858151068,0.21151911434681123, - 0.22347653672793238,0.12251370089051629,0.093064515580572826, - 0.13984765109852496,0.41094690289468627,0.21220982894638879, - 0.25740492084525707,0.082096126702519048,0.041707103324323758}; - double[] f1= new double[N],f2= new double[N],f3= new double[N],ff1 = new double[M],expect = buildVector(fingerprint); - boolean localflag, globalflag=false; - - - - // Test rj - System.out.println("Testing rj"); - - Ran myran = new Ran(17); - - // Test rj(x,x,x,x) = 1/x^(3/2) - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rj: Function rj(x,x,x,x) is not equal to 1/x^(3/2)"); - - } - - // Symmetry test - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rj: Function rj(x,y,z,p) is not equal to rj(y,x,z,p)"); - - } - - // Symmetry of y and z - System.out.printf("rj: maximum discrepance with swap of y,z = %f\n", maxel(vecsub(f1,f3))); - - sbeps=1.e-14; - localflag = maxel(vecsub(f1,f3)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rj: Function rj(x,y,z,p) is not equal to rj(x,z,y,p)"); - - } - - // Test symmetry with respect to p - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rj: Function rj(x,x,z,p) is not equal to rj(p,p,z,x)"); - - } - - // Test symmetry with respect to p - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rj: Function rj(x,y,y,p) is not equal to rj(x,p,p,y)"); - - } - - // Fingerprint test - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rj: Fuction does not match previously computed fingerprint"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_sncndn.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_sncndn.java deleted file mode 100644 index 00ca729870..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter6/Test_sncndn.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.nr.test.test_chapter6; - -import static com.nr.NRUtil.SQR; -import static com.nr.NRUtil.buildVector; -import static com.nr.sf.Elliptic.sncndn; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -public class Test_sncndn { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=20; - double sbeps=1.e-15; - double u[]={0.1,0.2,0.5,1.0,2.0,0.1,0.2,0.5,1.0,2.0,0.1,0.2,0.5,1.0,2.0,4.0,-0.2,-0.5,-1.0,-2.0}; - double ksquare[]={0.0,0.0,0.0,0.0,0.0,0.5,0.5,0.5,0.5,0.5,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}; - double y1[]={0.09983341664682815,0.1986693307950612,0.4794255386042030, - 0.8414709848078965,0.9092974268256817,0.09975068547462484, - 0.1980217429819704,0.4707504736556573,0.8030018248956439, - 0.9946623253580177,0.09966799462495582,0.1973753202249040, - 0.4621171572600098,0.7615941559557649,0.9640275800758169, - 0.9993292997390670,-0.1973753202249040,-0.4621171572600098, - -0.7615941559557649,-0.9640275800758169}; - double y2[]={0.9950041652780258,0.9800665778412416,0.8775825618903727, - 0.5403023058681397,-0.4161468365471424,0.9950124626090582, - 0.9801976276784098,0.8822663948904403,0.5959765676721407, - -0.1031836155277618,0.9950207489532265,0.9803279976447253, - 0.8868188839700739,0.6480542736638854,0.2658022288340797, - 0.03661899347368653,0.9803279976447253,0.8868188839700739, - 0.6480542736638854,0.2658022288340797}; - double y3[]={1.000000000000000,1.000000000000000,1.000000000000000, - 1.000000000000000,1.000000000000000,0.9975093485144243, - 0.9901483195224800,0.9429724257773857,0.8231610016315963, - 0.7108610477840873,0.9950207489532265,0.9803279976447253, - 0.8868188839700739,0.6480542736638854,0.2658022288340797, - 0.03661899347368653,0.9803279976447253,0.8868188839700739, - 0.6480542736638854,0.2658022288340797}; - double[] yy1=buildVector(y1),yy2=buildVector(y2),yy3=buildVector(y3),zz1= new double[N],zz2= new double[N],zz3= new double[N]; - double[] one=buildVector(N,1.0),test1= new double[N],test2= new double[N]; - boolean localflag, globalflag=false; - - - - // Test sncndn - System.out.println("Testing sncndn"); - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** sncndn: Test for relation between sn and cn failed"); - - } - - System.out.printf("test2: Maximum discrepancy = %f\n", maxel(vecsub(one,test2))); - localflag = maxel(vecsub(one,test2)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** sncndn: Test for relation between sn and dn failed"); - - } - - System.out.printf("sncndn (sn): Maximum discrepancy = %f\n", maxel(vecsub(zz1,yy1))); - localflag = maxel(vecsub(zz1,yy1)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** sncndn: Incorrect function values for sn"); - - } - - System.out.printf("sncndn (cn): Maximum discrepancy = %f\n", maxel(vecsub(zz2,yy2))); - localflag = maxel(vecsub(zz2,yy2)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** sncndn: Incorrect function values for cn"); - - } - - System.out.printf("sncndn (dn): Maximum discrepancy = %f\n", maxel(vecsub(zz3,yy3))); - localflag = maxel(vecsub(zz3,yy3)) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** sncndn: Incorrect function values for dn"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Binomialdev.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Binomialdev.java deleted file mode 100644 index f6b6f876c8..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Binomialdev.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.nr.test.test_chapter7; - -import static com.nr.NRUtil.buildVector; -import static com.nr.stat.Stattests.chsone; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -import com.nr.ran.Binomialdev; -import com.nr.sf.Binomialdist; - -public class Test_Binomialdev { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,nbin,N=100000,M=20; - doubleW df = new doubleW(0); - doubleW chisq = new doubleW(0); - doubleW prob = new doubleW(0); - - double pp; - int fpr[]={12,10,9,8,9,13,5,10,9,7}; - int[] fingerprint =buildVector(fpr); - double[] bins = new double[M],ebins = new double[M]; // x=new double[M] - boolean localflag, globalflag=false; - - - - // Test Binomialdev - System.out.println("Testing Binomialdev"); - - // Check fingerprint of doub() - pp=0.5; - Binomialdev myran = new Binomialdev(M,pp,17); - localflag=false; - for (i=0;i<10;i++) -// System.out.printf(setw(25) << setprecision(20) << myran.dev()); - localflag=localflag || (myran.dev() != fingerprint[i]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Binomialdev: dev() does not match fingerprint"); - - } - - // Check statistics - Binomialdist expect = new Binomialdist(M,pp); - for (i=0;i= 0) && (nbin < M)) bins[nbin] += 1; - } - chsone(bins,ebins,df,chisq,prob); - System.out.printf(" chisq,dev(): %f\n prob: %f\n",chisq.val, prob.val); - localflag = (prob.val < 0.05); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Binomialdev: dev() does not give distribution with correct variance"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Cauchydev.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Cauchydev.java deleted file mode 100644 index fba3868a08..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Cauchydev.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.nr.test.test_chapter7; - -import static com.nr.NRUtil.buildVector; -import static com.nr.stat.Stattests.chsone; -import static java.lang.Math.abs; -import static java.lang.Math.floor; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -import com.nr.ran.Cauchydev; -import com.nr.sf.Cauchydist; - -public class Test_Cauchydev { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @SuppressWarnings("unused") - @Test - public void test() { - int i,nbin,N=100000,M=1000; - doubleW df = new doubleW(0); - doubleW chisq = new doubleW(0); - doubleW prob = new doubleW(0); - double range=10.0,xl,xu,mu,sig,binsize,sbeps=1.e-15; - double fpr[]={-5.4660758319305183,-0.30564072790788632,-0.44755371579220488, - -1.9442849501644124,0.66387554413406102,-0.004358322069596801, - 0.50260252584448173,9.5625234809339883,0.33471895222248255, - -0.18486043134925173}; - double[] fingerprint = buildVector(fpr); - double[] x = new double[M],bins = new double[M],ebins = new double[M]; - boolean localflag, globalflag=false; - - - - // Test Cauchydev - System.out.println("Testing Cauchydev"); - - // Check fingerprint of doub() - mu=0.0; - sig=1.0; - Cauchydev myran = new Cauchydev(mu,sig,17); - localflag=false; - for (i=0;i<10;i++) { - //System.out.printf("%.20f %.20f\n", myran.dev(), fingerprint[i]); - localflag=localflag || abs(myran.dev()-fingerprint[i])>sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - // fail("*** Cauchydev: dev() does not match fingerprint"); - - } - - // Check statistics - Cauchydist expect = new Cauchydist(mu,sig); - xl=mu-range/2.0; - xu=mu+range/2.0; - binsize=range/(M); - for (i=0;i= 0) && (nbin < M)) bins[nbin] += 1; - } - chsone(bins,ebins,df,chisq,prob); - System.out.printf(" chisq,dev(): %f prob: %f\n",chisq.val, prob.val); - localflag = (prob.val < 0.05); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Cauchydev: dev() does not give distribution with correct variance"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Expondev.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Expondev.java deleted file mode 100644 index 27aa69cde5..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Expondev.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.nr.test.test_chapter7; - -import static com.nr.NRUtil.buildVector; -import static com.nr.stat.Stattests.chsone; -import static java.lang.Math.abs; -import static java.lang.Math.floor; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -import com.nr.ran.Expondev; -import com.nr.sf.Expondist; -public class Test_Expondev { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,nbin,N=100000,M=1000; - doubleW df = new doubleW(0); - doubleW chisq = new doubleW(0); - doubleW prob = new doubleW(0); - double range=10.0,binsize,beta=1.0,sbeps=1.e-15; - double fpr[]={4.2243978049659718,0.90295803506245254,0.12403099453814931, - 0.079329948033191738,1.3165010419652894,2.4667405038323449, - 0.95549662657685031,0.28104150659487703,4.8108667409405195, - 0.82390385975005687}; - double[] fingerprint = buildVector(fpr); - double[] x = new double[M],bins =new double[M],ebins = new double[M]; - boolean localflag, globalflag=false; - - - - // Test Expondev - System.out.println("Testing Expondev"); - - // Check fingerprint of doub() - Expondev myran = new Expondev(beta,17); - localflag=false; - for (i=0;i<10;i++) - localflag=localflag || abs(myran.dev()-fingerprint[i])>sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Expondev: dev() does not match fingerprint"); - - } - - // Check statistics - Expondist expect = new Expondist(beta); - binsize=range/(M); - for (i=0;isbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gammadev: dev() does not match fingerprint"); - - } - - // Check statistics - Gammadist expect=new Gammadist(alpha,beta); - binsize=range/M; - for (i=0;i= 0) && (nbin < M)) bins[nbin] += 1; - } - chsone(bins,ebins,df,chisq,prob); - System.out.printf(" chisq,dev(): %f prob: %f\n",chisq.val, prob.val); - localflag = (prob.val < 0.05); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Gammadev: dev() does not give distribution with correct variance"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Hash.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Hash.java deleted file mode 100644 index 0c43d081a9..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Hash.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.nr.test.test_chapter7; - -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Hash; -import com.nr.ran.Hashfn2; - -public class Test_Hash { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=8; - String names[]={"Charles Babbage","Marie Antoinette","Jane Austen", - "Andrew Jackson","Ludwig van Beethoven","Samuel Morse", - "John Quincy Adams","James Buchanan"}; - int dates[]={1791,1755,1775,1767,1770,1791,1767,1791}; - boolean localflag, globalflag=false; - - - - // Test Hash - System.out.println("Testing Hash"); - - Hash year = new Hash(100,100){ - Hashfn2 hashfn2 = new Hashfn2(); - public long fn(String k){ - return hashfn2.fn(k.getBytes()); - } - }; - - // Test operator[] - for (i=0;i hash = new Hashtable(N,2*N){ - Hashfn2 hashfn2 = new Hashfn2(); - public long fn(atom k) { - - return hashfn2.fn(k.toByte()); - } - }; - - // Test simple iset(), iget() - i=hash.iset(chart[5]); -// System.out.printf(i); - localflag = (i != 0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Hashtable: First iset() did not return index 0"); - - } - - i=hash.iget(chart[5]); -// System.out.printf(i); - localflag = (i != 0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Hashtable: iget() did not return correct index"); - - } - - // Test simple ierase() - i=hash.ierase(chart[5]); - localflag = (i != 0); -// System.out.printf(i); - localflag = (i != 0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Hashtable: ierase() did not return correct index"); - - } - - i=hash.iget(chart[5]); -// System.out.printf(i); - localflag = (i != -1); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Hashtable: iget() from erased key should return -1"); - - } - - // Test garbage collector - i=hash.iset(chart[5]); // Return hashes for 3 keys -// System.out.printf(i); - i=hash.iset(chart[2]); -// System.out.printf(i); - i=hash.iset(chart[7]); -// System.out.printf(i); - ia=hash.ierase(chart[2]); // erase two keys -// System.out.printf(i); - ib=hash.ierase(chart[7]); -// System.out.printf(i); - - // Following two iset()'s should use indices just erased - i=hash.iset(chart[1]); // store two more keys -// System.out.printf(i); - localflag = (i != ib); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Hashtable: iset() should use hash of last erased key"); - - } - - i=hash.iset(chart[9]); -// System.out.printf(i); - localflag = (i != ia); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Hashtable: iset() should use hash of penultimate erased key"); - - } - - // Test multiple iset() on same keys. They should return same index. - Ran myran = new Ran(17); - int j; - for (i=0;i<100;i++) { - j=myran.int32p()%N; - hash.iset(chart[j]); - } - - // N keys should always use only the first N indices - int[] expect =buildVector(N,1); - int[] check = buildVector(N,0); - for (i=0;isbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Logisticdev: dev() does not match fingerprint"); - - } - - // Check statistics - Logisticdist expect = new Logisticdist(mu,sig); - xl=mu-range/2.0; - xu=mu+range/2.0; - binsize=range/M; - for (i=0;i= 0) && (nbin < M)) bins[nbin] += 1; - } - chsone(bins,ebins,df,chisq,prob); - System.out.printf(" chisq,dev(): %f prob: %f\n", chisq.val, prob.val); - localflag = (prob.val < 0.05); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Logisticdev: dev() does not give distribution with correct variance"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_MCintegrate.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_MCintegrate.java deleted file mode 100644 index 01a5357bd5..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_MCintegrate.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.nr.test.test_chapter7; - -import static com.nr.NRUtil.SQR; -import static com.nr.NRUtil.buildVector; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.pow; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.MCintegrate; - -public class Test_MCintegrate { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - double R1=3.0,R2=1.0,PI=acos(-1.0); - double[] xlo = new double[3],xhi = new double[3],slo = new double[3],shi = new double[3]; - boolean localflag, globalflag=false; - - - - // Test MCintegrate - System.out.println("Testing MCintegrate"); - - xlo[0]=0.0; - xhi[0]=4.0; - xlo[1]=-4.0; - xhi[1]=4.0; - xlo[2]=-1.0; - xhi[2]=1.0; - MCintegrate mymc = new MCintegrate(xlo,xhi,17,false){ - - @Override - public double[] funcs(final double[] x){ - return torusfuncs(x); - } - - @Override - public boolean inregion(final double[] x) { - return torusregion(x); - } - - @Override - public double[] xmap(final double[] x){ - return null; - } - }; - mymc.step(1000000); - mymc.calcanswers(); -// for (i=0;i<4;i++) -// System.out.printf(mymc.ff[i] << " %f\n", mymc.fferr[i]); - - localflag = abs(mymc.ff[0]-SQR(PI)*R1*SQR(R2)) > 2.0*mymc.fferr[0]; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MCintegrate: Calculation of hemitorus volume is inaccurate"); - - } - - localflag = abs(mymc.ff[1]-2.0*PI*SQR(R1)*SQR(R2)*(1+SQR(R2/R1)/4.0)) > 2.0*mymc.fferr[1]; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MCintegrate: Calculation of x moment of hemitorus is inaccurate"); - - } - - localflag = abs(mymc.ff[2]) > 2.0*mymc.fferr[2]; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MCintegrate: Calculation of y moment of hemitorus is inaccurate"); - - } - - localflag=abs(mymc.ff[3]) > 2.0*mymc.fferr[3]; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MCintegrate: Calculation of z moment of hemitorus is inaccurate"); - - } - - // Test MCintegrate with change of variables for weighting by z^2 - slo[0]=0.0; - shi[0]=4.0; - slo[1]=-4.0; - shi[1]=4.0; - slo[2]=-1.0/3.0; - shi[2]=1.0/3.0; - //MCintegrate mymc2(slo,shi,torusfuncs,torusregion,torusmap2,17); - MCintegrate mymc2 = new MCintegrate(xlo,xhi,17,true){ - - @Override - public double[] funcs(final double[] x){ - return torusfuncs(x); - } - - @Override - public boolean inregion(final double[] x) { - return torusregion(x); - } - - @Override - public double[] xmap(final double[] x){ - return torusmap2(x); - } - }; - mymc2.step(1000000); - mymc2.calcanswers(); -// for (i=0;i<4;i++) -// System.out.printf(mymc2.ff[i] << " %f\n", mymc2.fferr[i]); - - localflag = abs(mymc2.ff[0]-SQR(PI)*R1*SQR(SQR(R2))/4.0) > 2.0*mymc2.fferr[0]; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MCintegrate: Incorrect weighted volume calculation with change of variables"); - - } - - localflag = abs(mymc2.ff[1]-PI*SQR(R1)*SQR(SQR(R2))*(1+SQR(R2/R1)/6.0)/2.0) > 2.0*mymc2.fferr[1]; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MCintegrate: Incorrect weighted x moment with change of variables"); - - } - - localflag = abs(mymc2.ff[2]) > 2.0*mymc2.fferr[2]; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MCintegrate: Incorrect weighted y moment with change of variables"); - - } - - localflag=abs(mymc2.ff[3]) > 2.0*mymc2.fferr[3]; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** MCintegrate: Incorrect weighted z moment with change of variables"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - double[] torusmap2(final double[] s) { - double[] xx = buildVector(s); - xx[2]=(s[2] < 0.0 ? -pow(abs(3.0*s[2]),1.0/3.0) : pow(3.0*s[2],1.0/3.0)); - return xx; - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Mhash.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Mhash.java deleted file mode 100644 index f62e3c9122..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Mhash.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.nr.test.test_chapter7; - -import static com.nr.NRUtil.buildVector; -import static org.junit.Assert.fail; -import static com.nr.test.NRTestUtil.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Hashfn2; -import com.nr.ran.Mhash; - -public class Test_Mhash { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,count,N=8; - String[] str = new String[1]; - String names[]={"Charles Babbage","Marie Antoinette","Jane Austen", - "Andrew Jackson","Ludwig van Beethoven","Samuel Morse", - "John Quincy Adams","James Buchanan"}; - int dates[]={1791,1755,1775,1767,1770,1791,1767,1791}; - boolean localflag, globalflag=false; - - - - // Test Mhash - System.out.println("Testing Mhash"); - - //Mhash person(100,100); - Mhash person = new Mhash(100,100){ - Hashfn2 hashfn2 = new Hashfn2(); - public long fn(Integer k){ - int kk = k; - byte[] b = new byte[4]; - b[0] = (byte)(kk >>>24); - b[1] = (byte)(kk >>>16); - b[2] = (byte)(kk >>>8); - b[3] = (byte)kk; - - return hashfn2.fn(b); - } - }; - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Multinormaldev: Mean value of x does not match target value"); - - } - - localflag = abs(1.0-yave/mean[1]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Multinormaldev: Mean value of y does not match target value"); - - } - - localflag = abs(1.0-zave/mean[2]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Multinormaldev: Mean value of z does not match target value"); - - } - - localflag = abs(1.0-xvar/covar[0][0]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Multinormaldev: Variance of x does not match target value"); - - } - - localflag = abs(1.0-yvar/covar[1][1]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Multinormaldev: Variance of y does not match target value"); - - } - - localflag = abs(1.0-zvar/covar[2][2]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Multinormaldev: Variance of z does not match target value"); - - } - - localflag = abs(1.0-covxy/covar[0][1]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Multinormaldev: Covariance does not match target value"); - - } - - localflag = abs(1.0-covxz/covar[0][2]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Multinormaldev: Covariance does not match target value"); - - } - - localflag = abs(1.0-covyz/covar[1][2]) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Multinormaldev: Covariance does not match target value"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Normaldev.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Normaldev.java deleted file mode 100644 index 89f20161e6..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Normaldev.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.nr.test.test_chapter7; - -import static com.nr.NRUtil.buildVector; -import static com.nr.stat.Stattests.chsone; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -import com.nr.ran.Normaldev; -import com.nr.sf.Normaldist; -import static java.lang.Math.*; - -public class Test_Normaldev { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @SuppressWarnings("unused") - @Test - public void test() { - int i,nbin,N=100000,M=1000; - doubleW df = new doubleW(0); - doubleW chisq = new doubleW(0); - doubleW prob = new doubleW(0); - double range=10.0,xl,xu,mu,sig,binsize,sbeps=1.e-15; - double fpr[]={1.1374125522420115,-0.35950397273931667,-1.6105670258529632, - 0.42167950591239073,0.42086816489557621,0.71359860938979924, - 0.56718836082663404,0.10148179520762551,0.47465403328436934, - -0.4866388952851291}; - double[] fingerprint=buildVector(fpr); - double[] x=new double[M],bins =new double[M],ebins =new double[M]; - boolean localflag, globalflag=false; - - - - // Test Normaldev - System.out.println("Testing Normaldev"); - - // Check fingerprint of doub() - mu=0.0; - sig=1.0; - Normaldev myran = new Normaldev(mu,sig,17); - localflag=false; - for (i=0;i<10;i++) -// System.out.printf(setw(25) << setprecision(20) << myran.dev()); - localflag=localflag || abs(myran.dev()-fingerprint[i])>sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Normaldev: dev() does not match fingerprint"); - - } - - // Check statistics - Normaldist expect = new Normaldist(mu,sig); - xl=mu-range/2.0; - xu=mu+range/2.0; - binsize=range/M; - for (i=0;i= 0) && (nbin < M)) bins[nbin] += 1; - } - chsone(bins,ebins,df,chisq,prob); - System.out.printf(" chisq,dev(): %f prob: %f\n", chisq.val, prob.val); - localflag = (prob.val < 0.05); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Normaldev: dev() does not give distribution with correct variance"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Normaldev_BM.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Normaldev_BM.java deleted file mode 100644 index 6ed6135f3d..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Normaldev_BM.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.nr.test.test_chapter7; - -import static com.nr.NRUtil.buildVector; -import static com.nr.stat.Stattests.chsone; -import static java.lang.Math.abs; -import static java.lang.Math.floor; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -import com.nr.ran.Normaldev_BM; -import com.nr.sf.Normaldist; -public class Test_Normaldev_BM { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @SuppressWarnings("unused") - @Test - public void test() { - int i,nbin,N=100000,M=1000; - doubleW df = new doubleW(0); - doubleW chisq = new doubleW(0); - doubleW prob = new doubleW(0); - double range=10.0,xl,xu,mu,sig,binsize,sbeps=1.e-15; - double fpr[]={-0.040234259938936714,-0.20636252953342041,-0.39109108994808306, - -0.2184933724157597,1.3879841011885372,-0.62802347682638449, - -0.023082200554415865,-0.18525427215527071,-1.5890668800145005, - -1.728054800100431}; - double[] fingerprint=buildVector(fpr); - double[] x=new double[M],bins =new double[M],ebins =new double[M]; - boolean localflag, globalflag=false; - - - - // Test Normaldev_BM - System.out.println("Testing Normaldev_BM"); - - // Check fingerprint of doub() - mu=0.0; - sig=1.0; - Normaldev_BM myran = new Normaldev_BM(mu,sig,17); - localflag=false; - for (i=0;i<10;i++) -// System.out.printf(setw(25) << setprecision(20) << myran.dev()); - localflag=localflag || abs(myran.dev()-fingerprint[i])>sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Normaldev_BM: dev() does not match fingerprint"); - - } - - // Check statistics - Normaldist expect = new Normaldist(mu,sig); - xl=mu-range/2.0; - xu=mu+range/2.0; - binsize=range/M; - for (i=0;i= 0) && (nbin < M)) bins[nbin] += 1; - } - chsone(bins,ebins,df,chisq,prob); - System.out.printf(" chisq,dev(): %f prob: %f\n",chisq.val, prob.val); - localflag = (prob.val < 0.05); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Normaldev_BM: dev() does not give distribution with correct variance"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Poissondev.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Poissondev.java deleted file mode 100644 index 31951a037b..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Poissondev.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.nr.test.test_chapter7; - -import static com.nr.NRUtil.buildVector; -import static com.nr.stat.Stattests.chsone; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -import com.nr.ran.Poissondev; -import com.nr.sf.Poissondist; - -public class Test_Poissondev { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,nbin,N=100000,M=10; - doubleW df = new doubleW(0); - doubleW chisq = new doubleW(0); - doubleW prob = new doubleW(0); - double lambda; - int fpr[]={0,4,2,3,4,4,3,3,7,2}; - int[] fingerprint=buildVector(fpr); - double[] bins =new double[M],ebins =new double[M]; // x is not used - - boolean localflag, globalflag=false; - - - - // Test Poissondev - System.out.println("Testing Poissondev"); - - // Check fingerprint of doub() - lambda=3.0; - Poissondev myran = new Poissondev(lambda,17); - localflag=false; - for (i=0;i<10;i++) -// System.out.printf(setw(25) << setprecision(20) << myran.dev()); - localflag=localflag || (myran.dev() != fingerprint[i]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Poissondev: dev() does not match fingerprint"); - - } - - // Check statistics - Poissondist expect = new Poissondist(lambda); - for (i=0;i= 0) && (nbin < M)) bins[nbin] += 1; - } - chsone(bins,ebins,df,chisq,prob); - System.out.printf(" chisq,dev(): %f prob: %f\n",chisq.val, prob.val); - localflag = (prob.val < 0.05); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Poissondev: dev() does not give distribution with correct variance"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Primpolytest.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Primpolytest.java deleted file mode 100644 index bd7ce424a0..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_Primpolytest.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.nr.test.test_chapter7; - -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Primpolytest; -import com.nr.ran.Ran; - -public class Test_Primpolytest { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,nflag,N=11; - long mask; - int pp[]={2046052277,1186898897,221421833,55334070,1225518245, - 216563424,1532859853,1735381519,2049267032,1363072601, - 130420448}; - // double sbeps=5.e-15; not used - boolean localflag=false, globalflag=false; - - - - // Test Primpolytest - System.out.println("Testing Primpolytest"); - - Primpolytest ptest = new Primpolytest(); - for (i=0;i> 1); - for (i=0;i sbeps; - } - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Ran: doub() does not match fingerprint"); - } - - // Check statistics - for (i=0;isbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Ranbyte: doub() does not match fingerprint"); - - } - - // Check statistics - for (i=0;isbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Ranfib: doub() does not match fingerprint"); - - } - - // Check statistics - for (i=0;isbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Ranhash: doub() does not match fingerprint"); - - } - - // Check statistics - for (i=0;isbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Ranlim32: doub() does not match fingerprint"); - - } - - // Check statistics - for (i=0;isbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Ranq1: doub() does not match fingerprint"); - - } - - // Check statistics - for (i=0;isbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Ranq2: doub() does not match fingerprint"); - - } - - // Check statistics - for (i=0;i 0.1; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** mcmc: Inaccurate estimate for rate lambda1"); - - } - - localflag = abs(s.lam2-lambda2)/lambda2 > 0.1; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** mcmc: Inaccurate estimate for rate lambda2"); - - } - - localflag = (s.k1 != k1); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** mcmc: integer parameter k1 was not correctly determined"); - - } - - localflag = (s.k2 != k2); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** mcmc: integer parameter k2 was not correctly determined"); - - } - - localflag = abs(s.tc-tc)/tc > 0.1; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** mcmc: Inaccurate estimate for critical time tc"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_miser.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_miser.java deleted file mode 100644 index 1417cd64fc..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_miser.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.nr.test.test_chapter7; - -import static com.nr.NRUtil.SQR; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -import com.nr.RealValueFun; -import com.nr.ran.Miser; - -public class Test_miser { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i; - doubleW ave= new doubleW(0),var= new doubleW(0); - double tgral,vol,sd,PI=acos(-1.0),R1=3.0,R2=1.0; - double[] regn = new double[6]; - boolean localflag, globalflag=false; - - - - // Test miser - System.out.println("Testing miser"); - - regn[0]=0.0; - regn[1]=-4.0; - regn[2]=-1.0; - regn[3]=4.0; - regn[4]=4.0; - regn[5]=1.0; - vol=1.0; - for (i=0;i<3;i++) vol *= (regn[i+3]-regn[i]); - - torusfunc1 torusfunc1 = new torusfunc1(); - // Test #1: Compute volume of hemitorus - Miser.miser(torusfunc1,regn,1000000,0.0,ave,var); - tgral=ave.val*vol; - sd=sqrt(var.val)*vol; - -// System.out.printf(tgral << " %f\n", sd); -// System.out.printf(SQR(PI)*R1*SQR(R2)); - localflag = abs(tgral-SQR(PI)*R1*SQR(R2)) > 2.0*sd; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** miser: Computation of hemitoroid volume is inaccurate"); - - } - - torusfunc2 torusfunc2 = new torusfunc2(); - // Test #2: Weight the integral by x - Miser.miser(torusfunc2,regn,1000000,0.0,ave,var); - tgral=ave.val*vol; - sd=sqrt(var.val)*vol; - -// System.out.printf(tgral << " %f\n", sd); -// System.out.printf(2.0*PI*SQR(R1)*SQR(R2)*(1+SQR(R2/R1)/4.0)); - localflag = abs(tgral-2.0*PI*SQR(R1)*SQR(R2)*(1+SQR(R2/R1)/4.0)) > 2.0*sd; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** miser: Computation of hemitoroid weighted by x is inaccurate"); - - } - - torusfunc3 torusfunc3 = new torusfunc3(); - // Test #3: Weight the integral by z^2 - Miser.miser(torusfunc3,regn,1000000,0.0,ave,var); - tgral=ave.val*vol; - sd=sqrt(var.val)*vol; - -// System.out.printf(tgral << " %f\n", sd); -// System.out.printf(SQR(PI)*R1*SQR(SQR(R2))/4.0); - localflag = abs(tgral-SQR(PI)*R1*SQR(SQR(R2))/4.0) > 2.0*sd; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** miser: Computation of hemitoroid weighted by z^2 is inaccurate"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - - class torusfunc1 implements RealValueFun { - public double funk(final double[] x) { - double R1 = 3.0, R2 = 1.0; - - if (SQR(x[2]) + SQR(sqrt(SQR(x[0]) + SQR(x[1])) - R1) <= R2) - return 1.0; - else - return 0.; - } - } - - class torusfunc2 implements RealValueFun { - public double funk(final double[] x) { - double R1 = 3.0, R2 = 1.0; - - if (SQR(x[2]) + SQR(sqrt(SQR(x[0]) + SQR(x[1])) - R1) <= R2) - return x[0]; - else - return 0.; - } - } - - class torusfunc3 implements RealValueFun { - public double funk(final double[] x) { - double R1 = 3.0, R2 = 1.0; - - if (SQR(x[2]) + SQR(sqrt(SQR(x[0]) + SQR(x[1])) - R1) <= R2) - return SQR(x[2]); - else - return 0.; - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_psdes.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_psdes.java deleted file mode 100644 index 1bb6ba8188..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_psdes.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.nr.test.test_chapter7; - -import static com.nr.NRUtil.buildVector; -import static com.nr.stat.Stattests.chsone; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; -import org.netlib.util.intW; - -import com.nr.ran.HashAll; -public class Test_psdes { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @SuppressWarnings("unused") - @Test - public void test() { - int i,M=1024,N=100*M; - intW lword = new intW(0),rword = new intW(0); - doubleW dfW=new doubleW(0),chisqW=new doubleW(0),probW=new doubleW(0); - double df,chisq,prob,average; - double[] bins = new double[M]; - boolean localflag, globalflag=false; - - - - // Test psdes - System.out.println("Testing psdes"); - - average=N/(double)(M); - double[] ebins = buildVector(M,average); - - for (i=0;i 0.02; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** sobseq: Error in volume calculation is not approaching 1/N"); - - } - - localflag = sumerr[3]/sumerr[1] > 0.02; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** sobseq: Error in integral calculation is not approaching 1/N"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_vegas.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_vegas.java deleted file mode 100644 index 6d74861f5d..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter7/Test_vegas.java +++ /dev/null @@ -1,147 +0,0 @@ -package com.nr.test.test_chapter7; - -import static com.nr.NRUtil.SQR; -import static java.lang.Math.abs; -import static java.lang.Math.acos; -import static java.lang.Math.sqrt; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -import com.nr.ran.VEGAS; - -public class Test_vegas { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - doubleW tgral= new doubleW(0),sd= new doubleW(0),chi2a= new doubleW(0); - double R1=3.0,R2=1,PI=acos(-1.0); - double[] regn =new double[6]; - boolean localflag, globalflag=false; - - - - // Test vegas - System.out.println("Testing vegas"); - - regn[0]=0.0; - regn[1]=-4.0; - regn[2]=-1.0; - regn[3]=4.0; - regn[4]=4.0; - regn[5]=1.0; - - // Test #1: Compute volume of hemitorus - VEGAS vegas = new VEGAS() { - public double fxn(final double[] x, final double wgt){ - return torusfunc1(x, wgt); - } - }; - vegas.vegas(regn,0,1000,100,-1,tgral,sd,chi2a); -// System.out.printf(chi2a); - localflag = chi2a.val > 1.2; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** vegas: chi-square for test #1 is too high"); - - } - - vegas.vegas(regn,1,100000,1,-1,tgral,sd,chi2a); - -// System.out.printf(tgral << " %f\n", sd << " %f\n", chi2a); -// System.out.printf(SQR(PI)*R1*SQR(R2)); - localflag = abs(tgral.val-SQR(PI)*R1*SQR(R2)) > 2.0*sd.val; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** vegas: Computation of hemitoroid volume is inaccurate"); - - } - - // Test #2: Weight the integral by x - vegas = new VEGAS() { - public double fxn(final double[] x, final double wgt){ - return torusfunc2(x, wgt); - } - }; - vegas.vegas(regn,0,1000,100,-1,tgral,sd,chi2a); -// System.out.printf(chi2a); - localflag = chi2a.val > 1.2; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** vegas: chi-square for test #2 is too high"); - - } - - vegas.vegas(regn,1,100000,1,-1,tgral,sd,chi2a); - -// System.out.printf(tgral << " %f\n", sd << " %f\n", chi2a); -// System.out.printf(2.0*PI*SQR(R1)*SQR(R2)*(1+SQR(R2/R1)/4.0)); - localflag = abs(tgral.val-2.0*PI*SQR(R1)*SQR(R2)*(1+SQR(R2/R1)/4.0)) > 2.0*sd.val; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** vegas: Computation of hemitoroid weighted by x is inaccurate"); - - } - - // Test #3: Weight the integral by z^2 - vegas = new VEGAS() { - public double fxn(final double[] x, final double wgt){ - return torusfunc3(x, wgt); - } - }; - vegas.vegas(regn,0,1000,100,-1,tgral,sd,chi2a); -// System.out.printf(chi2a); - localflag = chi2a.val > 1.2; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** vegas: chi-square for test #3 is too high"); - - } - - vegas.vegas(regn,1,100000,1,-1,tgral,sd,chi2a); - -// System.out.printf(tgral << " %f\n", sd << " %f\n", chi2a); -// System.out.printf(SQR(PI)*R1*SQR(SQR(R2))/4.0); - localflag = abs(tgral.val-SQR(PI)*R1*SQR(SQR(R2))/4.0) > 2.0*sd.val; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** vegas: Computation of hemitoroid weighted by z^2 is inaccurate"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - double torusfunc1(final double[] x, final double wgt) { - double R1=3.0,R2=1.0; - - if (SQR(x[2])+SQR(sqrt(SQR(x[0])+SQR(x[1]))-R1) <= R2) return 1.0; - else return 0.; - } - - double torusfunc2(final double[] x, final double wgt) { - double R1=3.0,R2=1.0; - - if (SQR(x[2])+SQR(sqrt(SQR(x[0])+SQR(x[1]))-R1) <= R2) return x[0]; - else return 0.; - } - - double torusfunc3(final double[] x, final double wgt) { - double R1=3.0,R2=1.0; - - if (SQR(x[2])+SQR(sqrt(SQR(x[0])+SQR(x[1]))-R1) <= R2) return SQR(x[2]); - else return 0.; - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_Heapselect.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_Heapselect.java deleted file mode 100644 index 8292cab1dc..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_Heapselect.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.nr.test.test_chapter8; - -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Ran; -import com.nr.sort.Heapselect; -import com.nr.sort.Sorter; - -public class Test_Heapselect { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=1000,M=100; - double xm,val; - double[] x = new double[M],y = new double[M]; - boolean localflag, globalflag=false; - - - - // Test Heapselect - System.out.println("Testing Heapselect"); - Heapselect heap = new Heapselect(M); - Ran myran = new Ran(17); - // Find top 100 values in 1000 random numbers - for (i=0;i= xm) { - if (j < M) y[j]=val; - j++; - } - } - localflag = (j != M); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Heapselect: The Mth largest was not correctly identified"); - - } - - Sorter.sort(y); - localflag = (maxel(vecsub(x,y))!=0.0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Heapselect: The M largest elements are not correctly ordered"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_IQagent.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_IQagent.java deleted file mode 100644 index a5a1e188dd..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_IQagent.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.nr.test.test_chapter8; - -import static com.nr.NRUtil.buildVector; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Ran; -import com.nr.sort.IQagent; - -public class Test_IQagent { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=1000,M=100; - double var,sbeps; - double uu[]={1.0,25.0,50.0,75.0,100.0}; - double[] u=buildVector(uu),x = new double[11],y=new double[11],z = new double[5]; - boolean localflag, globalflag=false; - - - - // Test IQagent - System.out.println("Testing IQagent"); - IQagent iq = new IQagent(); - Ran myran = new Ran(17); - for (j=0;j sbeps); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** IQagent: Percentiles of uniform distribution are suspiciously nonuniform"); - - } - - // Artificial distribution - IQagent iq2 = new IQagent(); - for (j=0;j xx[i+1]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Indexx: Array sorted according to index is incorrectly ordered"); - - } - - // Test member function sort() on another array - for (i=0;i yy[i]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Indexx: Independent array sorted according to index is incorrectly ordered"); - - } - - // Test member function el() - for (i=0;i sbeps); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Indexx: Member function el() does not sort inverted array into reverse order"); - - } - - // Test l-value version of member function el() - for (i=0;i sbeps); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** Indexx: l-value version of member function el() does not sort inverted array into reverse order"); - - } - - // Test member function rank() - idx.rank(zi); - idx.sort(zi); - for (i=0;i x[i+1]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** hpsort: Sorted values are not correctly ordered"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_piksr2.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_piksr2.java deleted file mode 100644 index b87a59e493..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_piksr2.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.nr.test.test_chapter8; - -import static com.nr.NRUtil.buildVector; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Ran; -import com.nr.sort.Sorter; - -public class Test_piksr2 { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=100; - double[] x= new double[N],y= new double[N]; - boolean localflag=false, globalflag=false; - - - - // Test piksr2 - System.out.println("Testing piksr2"); - Ran myran = new Ran(17); - for (i=0;i x[i+1]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** piksr2: First array is not correctly ordered"); - - } - - for (i=0;i x[i+1]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** piksrt: Sorted values are not correctly ordered"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_select.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_select.java deleted file mode 100644 index 30574169b8..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_select.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.nr.test.test_chapter8; - -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Ran; -import com.nr.sort.Sorter; - -public class Test_select { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,k,N=100,M=20; - double xsel; - double[] x=new double[N]; - boolean localflag, globalflag=false; - - - - // Test select - System.out.println("Testing select"); - Ran myran = new Ran(17); - for (i=0;i x[k]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** select: Some array positions below k have values above a[k]"); - - } - - localflag = false; - for (j=k+1;j xsel) count++; - localflag = (count != (N-k-1)); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** selip: There are not k values less or equal to selected value"); - - } - - // Test that array was not altered - localflag = (maxel(vecsub(x,xx)) != 0.0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** selip: Array was altered by selip"); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_shell.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_shell.java deleted file mode 100644 index 06487a5303..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_shell.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.nr.test.test_chapter8; - -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Ran; -import com.nr.sort.Sorter; - -public class Test_shell { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=100; - double[] x= new double[N],y= new double[N]; - boolean localflag,globalflag=false; - - - - // Test shell - System.out.println("Testing shell"); - localflag=false; - Ran myran = new Ran(17); - for (i=0;i x[i+1]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** shell: Sorted values are not correctly ordered"); - - } - - localflag=false; - for (i=0;i y[i+1]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** shell: First half of array is not correctly ordered"); - - } - - localflag=false; - for (i=N/2;i y[i]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** shell: Second half of array is not correctly ordered"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_sort.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_sort.java deleted file mode 100644 index 8a31f78083..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_sort.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.nr.test.test_chapter8; - -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Ran; -import com.nr.sort.Sorter; - -public class Test_sort { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=100; - double[] x= new double[N],y= new double[N]; - boolean localflag,globalflag=false; - - - - // Test sort - System.out.println("Testing sort"); - localflag=false; - Ran myran = new Ran(17); - for (i=0;i x[i+1]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** sort: Sorted values are not correctly ordered"); - - } - - localflag=false; - for (i=0;i y[i+1]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** sort: First half of array is not correctly ordered"); - - } - - localflag=false; - for (i=N/2;i y[i]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** sort: Second half of array is not correctly ordered"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_sort2.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_sort2.java deleted file mode 100644 index bd93c5ae5e..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter8/Test_sort2.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.nr.test.test_chapter8; - -import static com.nr.NRUtil.buildVector; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.ran.Ran; -import com.nr.sort.Sorter; - -public class Test_sort2 { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=100; - double[] x= new double[N],y= new double[N]; - boolean localflag=false, globalflag=false; - - - - // Test sort2 - System.out.println("Testing sort2"); - Ran myran = new Ran(17); - for (i=0;i x[i+1]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** sort2: First array is not correctly ordered"); - - } - - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** broydn: Inaccurate roots"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Func_broydn implements RealMultiValueFun { - public double[] funk(final double[] x) { - double[] fvec = new double[4]; - - fvec[0] = -SQR(x[0])-SQR(x[1])-SQR(x[2])+x[3]; - fvec[1] = SQR(x[0])+SQR(x[1])+SQR(x[2])+SQR(x[3])-1.0; - fvec[2] = x[0]-x[1]; - fvec[3] = x[1]-x[2]; - return fvec; - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_laguer.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_laguer.java deleted file mode 100644 index 23ccc2e2ea..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_laguer.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.nr.test.test_chapter9; - -import static com.nr.root.Roots.laguer; -import static com.nr.test.NRTestUtil.maxel; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.intW; - -import com.nr.Complex; -import com.nr.ran.Ran; - -public class Test_laguer { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - intW its = new intW(0); - int i,M=5,N=20; - double sbeps=1.e-14; - Complex x = new Complex(),re1 = new Complex(1.0,0.0),im1=new Complex(0.0,1.0); - Complex a[]={ - re1.mul(2.0).add(im1), - im1.mul(2.0), - re1.mul(3.0).add(im1), - re1.add(im1.mul(2.0)), - re1.sub(im1), - new Complex(1.0) - }; - Complex[] aa = new Complex[M+1];System.arraycopy(a, 0, aa, 0 , M+1); - double[] dy = new double[N]; - boolean localflag, globalflag=false; - - - - // Test laguer - System.out.println("Testing laguer"); - // Roots of polynomial x^5+(1-i)x^4+(1+2i)x^3+(3+i)x^2+(2i)x+(2+i)" - // Roots are x=i, x=-i, x=sqrt(2i), x=-i*sqrt(2i), x=(i-1) - Ran myran =new Ran(17); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** laguer: Incorrect roots"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_lnsrch.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_lnsrch.java deleted file mode 100644 index 9739ad1f06..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_lnsrch.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.nr.test.test_chapter9; - -import static com.nr.NRUtil.SQR; -import static com.nr.root.Roots.lnsrch; -import static com.nr.test.NRTestUtil.maxel; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.booleanW; -import org.netlib.util.doubleW; - -import com.nr.RealMultiValueFun; -import com.nr.RealValueFun; - -public class Test_lnsrch { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,NDIM=4,M=10; // NTRIAL=6, not used. - doubleW fnew = new doubleW(0); - double fold,stpmax=1.0,sbeps=1.e-14; - double x0[]={0.5,-0.5,1.0,1.0,1.0,0.5,-1.0,-1.0,-1.0,-0.5}; - double x1[]={0.5,-0.5,1.0,1.0,0.5,1.0,-1.0,-1.0,-0.5,-1.0}; - double x2[]={0.5,-0.5,1.0,0.5,1.0,1.0,-1.0,-0.5,-1.0,-1.0}; - double x3[]={0.5,-0.5,0.9,1.0,1.0,1.0,-0.9,-1.0,-1.0,-1.0}; - double p0[]={1.0,-1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,-1.0}; - double p1[]={1.0,-1.0,0.0,0.0,1.0,0.0,0.0,0.0,-1.0,0.0}; - double p2[]={1.0,-1.0,0.0,1.0,0.0,0.0,0.0,-1.0,0.0,0.0}; - double p3[]={1.0,-1.0,1.0,0.0,0.0,0.0,-1.0,0.0,0.0,0.0}; - double[] xold=new double[NDIM],gold=new double[NDIM],p=new double[NDIM],xnew=new double[NDIM]; - double[] dy = new double[(M)]; - boolean localflag, globalflag=false; - - - - // Test lnsrch - System.out.println("Testing lnsrch"); - - Func_lnsrch f = new Func_lnsrch(); // function - Funcd_lnsrch g = new Funcd_lnsrch(); // gradiant - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** lnsrch: Inaccurate minima"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Func_lnsrch implements RealValueFun{ - public double funk(final double[] x) { - return(SQR(x[0]-x[1])+SQR(x[1]-x[2])+SQR(x[2]-x[3])+SQR(x[3]-1)*SQR(x[3]+1)); - } // Minima of 0.0 at x0=x1=x2=x3= +- 1; - }; - - class Funcd_lnsrch implements RealMultiValueFun { - public double[] funk(final double[] x) { - double[] g = new double[4]; - g[0]= 2.0*(x[0]-x[1]); - g[1]= -2.0*(x[0]-x[1])+2.0*(x[1]-x[2]); - g[2]= -2.0*(x[1]-x[2])+2.0*(x[2]-x[3]); - g[3]= -2.0*(x[2]-x[3])+2.0*(x[3]-1)*SQR(x[3]+1)+2.0*(x[3]+1)*SQR(x[3]-1); - return(g); - } - }; -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_mnewt.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_mnewt.java deleted file mode 100644 index 237b7c8ebb..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_mnewt.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.nr.test.test_chapter9; - -import static com.nr.NRUtil.SQR; -import static com.nr.test.NRTestUtil.maxel; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.root.MNEWT; - -public class Test_mnewt { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,NTRIAL=6,NDIM=4,M=8; - double tolx=1.0e-14,tolf=1.0e-14,sbeps=1.e-14; - double x0[]={0.5,0.4,0.6,0.5,-0.5,-0.4,-0.5,-0.4}; - double x1[]={0.6,0.6,0.4,0.4,-0.4,-0.5,-0.6,-0.6}; - double x2[]={0.4,0.5,0.5,0.6,-0.6,-0.6,-0.4,-0.5}; - double x3[]={0.0,1.4,0.0,1.6,0.0,1.3,0.0,1.7}; - double[] fvec=new double[NDIM],x=new double[NDIM],dy = new double[M]; - double[][] fjac=new double[NDIM][NDIM]; - boolean localflag, globalflag=false; - - - - // Test mnewt - System.out.println("Testing mnewt"); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** mnewt: Inaccurate roots"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - void usrfun(double[] x, double[] fvec, double[][] fjac) { - int i; - - int n=x.length; - fjac[0][0] = -2.0*x[0]; - fjac[0][1] = -2.0*x[1]; - fjac[0][2] = -2.0*x[2]; - fjac[0][3] = 1.0; - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** newt: Inaccurate roots"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Func_newt implements RealMultiValueFun { - public double[] funk(final double[] x) { - double[] fvec =new double[4]; - - fvec[0] = -SQR(x[0])-SQR(x[1])-SQR(x[2])+x[3]; - fvec[1] = SQR(x[0])+SQR(x[1])+SQR(x[2])+SQR(x[3])-1.0; - fvec[2] = x[0]-x[1]; - fvec[3] = x[1]-x[2]; - return fvec; - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_qroot.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_qroot.java deleted file mode 100644 index 645506e7f7..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_qroot.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.nr.test.test_chapter9; - -import static com.nr.NRUtil.buildVector; -import static com.nr.root.Roots.qroot; -import static com.nr.root.Roots.zroots; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -import com.nr.Complex; - -public class Test_qroot { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int j,N=6; - boolean polish=true; - double eps=1.e-10,err,sbeps=1.e-14; - doubleW b = new doubleW(0); - doubleW c = new doubleW(0); - - Complex pp[]={ - new Complex(2.0), - new Complex(-2.0), - new Complex(7.0), - new Complex(1.0), - new Complex(-3.0), - new Complex(5.0)}; - double ppr[]={2.0,-2.0,7.0,1.0,-3.0,5.0}; - Complex[] p=new Complex[N];System.arraycopy(pp, 0, p, 0, N); - double[] pr=buildVector(ppr); - Complex[] rts=new Complex[N-1],rts2 =new Complex[2]; - boolean localflag, globalflag=false; - - - - // Test qroot - System.out.println("Testing qroot"); - // Ran myran = new Ran(17); not use it - zroots(p,rts,!polish); // Find actual roots - // for (j=0;j sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** qroot: Quadratic is not a factor of the polynomial"); - } - - c.val=1.3; // Constructed another guess from actual roots - b.val=-1.4; - qroot(pr,b,c,eps); - a[0]=new Complex(c.val); a[1]=new Complex(b.val); a[2]=new Complex(1.0); // Now test result - zroots(a,rts2,polish); - err=0.0; - for (j=0;j<2;j++) { - Complex r = p[4].add(rts2[j].mul(p[5])); - r = p[3].add(rts2[j].mul(r)); - r = p[2].add(rts2[j].mul(r)); - r = p[1].add(rts2[j].mul(r)); - r = p[0].add(rts2[j].mul(r)); - err += r.abs(); - } - System.out.printf("qroot: Discrepancy = %f\n", abs(err)); - localflag = abs(err) > sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** qroot: Quadratic is not a factor of the polynomial"); - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_rtbis.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_rtbis.java deleted file mode 100644 index e58e88d176..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_rtbis.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.nr.test.test_chapter9; - -import static com.nr.NRUtil.buildVector; -import static com.nr.root.Roots.rtbis; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.root.Roots.Zbrak; -import com.nr.sf.Bessjy; - -public class Test_rtbis { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i; - int nroot = 0; - double[] xb1,xb2; - double sbeps=1.e-12,xacc=0.0; - double x1=1.0,x2=50.0; - double y[]={2.404825557695773,5.520078110286311,8.653727912911013, - 1.179153443901428e1,1.493091770848779e1,1.807106396791092e1, - 2.121163662987926e1,2.435247153074930e1,2.749347913204025e1, - 3.063460646843198e1,3.377582021357357e1,3.691709835366405e1, - 4.005842576462825e1,4.319979171317673e1,4.634118837166182e1, - 4.948260989739782e1}; - double[] yy =buildVector(y); - boolean localflag, globalflag=false; - - - - // Test rtbis - System.out.println("Testing rtbis"); - Func_rtbis fx = new Func_rtbis(); - Zbrak z = new Zbrak(); z.zbrak(fx,x1,x2,100); - xb1= z.xb1;xb2=z.xb2;nroot = z.nroot; - double[] root = new double[nroot]; - for (i=0;i xacc; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rtbis: Incorrect roots"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Func_rtbis implements UniVarRealValueFun { - Bessjy b = new Bessjy(); - public double funk (final double x) { - return b.j0(x); - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_rtflsp.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_rtflsp.java deleted file mode 100644 index 16c1966163..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_rtflsp.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.nr.test.test_chapter9; - -import static com.nr.NRUtil.buildVector; -import static com.nr.root.Roots.rtflsp; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.root.Roots.Zbrak; -import com.nr.sf.Bessjy; - -public class Test_rtflsp { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i; - int nroot = 0; - double[] xb1,xb2; - double sbeps=1.e-13,xacc=0.0; - double x1=1.0,x2=50.0; - double y[]={2.404825557695773,5.520078110286311,8.653727912911013, - 1.179153443901428e1,1.493091770848779e1,1.807106396791092e1, - 2.121163662987926e1,2.435247153074930e1,2.749347913204025e1, - 3.063460646843198e1,3.377582021357357e1,3.691709835366405e1, - 4.005842576462825e1,4.319979171317673e1,4.634118837166182e1, - 4.948260989739782e1}; - double[] yy = buildVector(y); - boolean localflag, globalflag=false; - - - - // Test rtflsp - System.out.println("Testing rtflsp"); - Func_rtflsp fx = new Func_rtflsp(); - Zbrak z = new Zbrak(); z.zbrak(fx,x1,x2,100); - xb1= z.xb1;xb2=z.xb2;nroot = z.nroot; - - double[] root = new double[nroot]; - for (i=0;i xacc; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rtflsp: Incorrect roots"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Func_rtflsp implements UniVarRealValueFun{ - Bessjy b = new Bessjy(); - public double funk (final double x) { - return b.j0(x); - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_rtnewt.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_rtnewt.java deleted file mode 100644 index e830f5a172..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_rtnewt.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.nr.test.test_chapter9; - -import static com.nr.NRUtil.buildVector; -import static com.nr.root.Roots.rtnewt; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniValRealValueFunWithDiff; -import com.nr.root.Roots.Zbrak; -import com.nr.sf.Bessjy; - -public class Test_rtnewt { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i; - int nroot = 0; - double[] xb1,xb2; - double sbeps=1.e-12,xacc=0.; - double x1=1.0,x2=50.0; - double y[]={2.404825557695773,5.520078110286311,8.653727912911013, - 1.179153443901428e1,1.493091770848779e1,1.807106396791092e1, - 2.121163662987926e1,2.435247153074930e1,2.749347913204025e1, - 3.063460646843198e1,3.377582021357357e1,3.691709835366405e1, - 4.005842576462825e1,4.319979171317673e1,4.634118837166182e1, - 4.948260989739782e1}; - double[] yy=buildVector(y); - boolean localflag, globalflag=false; - - - - // Test rtnewt - System.out.println("Testing rtnewt"); - Funcd_rtnewt fxd = new Funcd_rtnewt(); - Zbrak z = new Zbrak(); z.zbrak(fxd,x1,x2,100); - xb1= z.xb1;xb2=z.xb2;nroot = z.nroot; - double[] root = new double[nroot]; - for (i=0;i xacc; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rtnewt: Incorrect roots"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - class Funcd_rtnewt implements UniValRealValueFunWithDiff{ - Bessjy b = new Bessjy(); - public double funk (final double x) { - return b.j0(x); - } - public double df(final double x) { - return -b.j1(x); - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_rtsafe.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_rtsafe.java deleted file mode 100644 index f3d9b145a4..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_rtsafe.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.nr.test.test_chapter9; - -import static com.nr.NRUtil.buildVector; -import static com.nr.root.Roots.rtsafe; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniValRealValueFunWithDiff; -import com.nr.root.Roots.Zbrak; -import com.nr.sf.Bessjy; - -public class Test_rtsafe { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i; - int nroot = 0; - double[] xb1,xb2; - double sbeps=1.e-13,xacc=0.0; - double x1=1.0,x2=50.0; - double y[]={2.404825557695773,5.520078110286311,8.653727912911013, - 1.179153443901428e1,1.493091770848779e1,1.807106396791092e1, - 2.121163662987926e1,2.435247153074930e1,2.749347913204025e1, - 3.063460646843198e1,3.377582021357357e1,3.691709835366405e1, - 4.005842576462825e1,4.319979171317673e1,4.634118837166182e1, - 4.948260989739782e1}; - double[] yy=buildVector(y); - boolean localflag, globalflag=false; - - // Test rtsafe - System.out.println("Testing rtsafe"); - Funcd_rtsafe fxd = new Funcd_rtsafe(); - Zbrak z = new Zbrak(); z.zbrak(fxd,x1,x2,100); - xb1= z.xb1;xb2=z.xb2;nroot = z.nroot; - double[] root = new double[nroot]; - for (i=0;i xacc; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rtsafe: Incorrect roots"); - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Funcd_rtsafe implements UniValRealValueFunWithDiff { - Bessjy b = new Bessjy(); - public double funk (final double x) { - return b.j0(x); - } - public double df(final double x) { - return -b.j1(x); - } - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_rtsec.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_rtsec.java deleted file mode 100644 index 4fe0adcc73..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_rtsec.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.nr.test.test_chapter9; - -import static com.nr.NRUtil.buildVector; -import static com.nr.root.Roots.rtsec; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.root.Roots.Zbrak; -import com.nr.sf.Bessjy; - -public class Test_rtsec { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i; - int nroot = 0; - double[] xb1,xb2; - double sbeps=1.e-12,xacc=0.; - double x1=1.0,x2=50.0; - double y[]={2.404825557695773,5.520078110286311,8.653727912911013, - 1.179153443901428e1,1.493091770848779e1,1.807106396791092e1, - 2.121163662987926e1,2.435247153074930e1,2.749347913204025e1, - 3.063460646843198e1,3.377582021357357e1,3.691709835366405e1, - 4.005842576462825e1,4.319979171317673e1,4.634118837166182e1, - 4.948260989739782e1}; - double[] yy=buildVector(y); - boolean localflag, globalflag=false; - - - - // Test rtsec - System.out.println("Testing rtsec"); - Func_rtsec fx = new Func_rtsec(); - Zbrak z = new Zbrak(); z.zbrak(fx,x1,x2,100); - xb1= z.xb1;xb2=z.xb2;nroot = z.nroot; - double[] root = new double[nroot]; - for (i=0;i xacc; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** rtsec: Incorrect roots"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Func_rtsec implements UniVarRealValueFun { - Bessjy b = new Bessjy(); - public double funk (final double x) { - return b.j0(x); - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zbrac.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zbrac.java deleted file mode 100644 index 5000350cab..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zbrac.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.nr.test.test_chapter9; - -import static com.nr.root.Roots.zbrac; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.netlib.util.doubleW; - -import com.nr.UniVarRealValueFun; -import com.nr.sf.Bessjy; - -public class Test_zbrac { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - boolean success; - int i,j,N=16,M=50; - doubleW x1=new doubleW(0),x2=new doubleW(0); - double y[]={2.404825557695773,5.520078110286311,8.653727912911013, - 1.179153443901428e1,1.493091770848779e1,1.807106396791092e1, - 2.121163662987926e1,2.435247153074930e1,2.749347913204025e1, - 3.063460646843198e1,3.377582021357357e1,3.691709835366405e1, - 4.005842576462825e1,4.319979171317673e1,4.634118837166182e1, - 4.948260989739782e1}; - boolean localflag, globalflag=false; - - - - // Test zbrac - System.out.println("Testing zbrac"); - Func_zbrac fx = new Func_zbrac(); - for (i=1;i= 0.0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** zbrac: An identified bracketing interval does not actually bracket a root."); - - } - - for (j=0;j x1.val) && (y[j] < x2.val); - localflag = !localflag; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** zbrac: No known root of bessj0 falls witning one of the identified brackets."); - - } - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Func_zbrac implements UniVarRealValueFun{ - Bessjy b =new Bessjy(); - public double funk (final double x) { - return b.j0(x); - } - } -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zbrak.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zbrak.java deleted file mode 100644 index 3f93e49654..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zbrak.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.nr.test.test_chapter9; - -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.root.Roots.Zbrak; -import com.nr.sf.Bessjy; - -public class Test_zbrak { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i; - int nroot = 0; - double[] xb1,xb2; - double x1=1.0,x2=50.0; - double y[]={2.404825557695773,5.520078110286311,8.653727912911013, - 1.179153443901428e1,1.493091770848779e1,1.807106396791092e1, - 2.121163662987926e1,2.435247153074930e1,2.749347913204025e1, - 3.063460646843198e1,3.377582021357357e1,3.691709835366405e1, - 4.005842576462825e1,4.319979171317673e1,4.634118837166182e1, - 4.948260989739782e1}; - - - boolean localflag=false, globalflag=false; - - - - // Test zbrak - System.out.println("Testing zbrak"); - Func_zbrak fx = new Func_zbrak(); - Zbrak z = new Zbrak(); z.zbrak(fx,x1,x2,100); - xb1= z.xb1;xb2=z.xb2;nroot = z.nroot; - for (i=0;i= 0.0); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** zbrak: One of the returned intervals does not contain a root."); - - } - - for (i=0;i xb2[i]); - globalflag = globalflag || localflag; - if (localflag) { - fail("*** zbrak: A known root of bessj0 does not fall in the identified intervals."); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Func_zbrak implements UniVarRealValueFun { - Bessjy b = new Bessjy(); - - public double funk (final double x) { - return b.j0(x); - } - }; -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zbrent.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zbrent.java deleted file mode 100644 index 9d4babfbfe..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zbrent.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.nr.test.test_chapter9; - -import static com.nr.NRUtil.buildVector; -import static com.nr.root.Roots.zbrent; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.root.Roots.Zbrak; -import com.nr.sf.Bessjy; -public class Test_zbrent { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i; - int nroot = 0; - double[] xb1,xb2; - double sbeps=1.e-15,xacc=0; - double x1=1.0,x2=50.0; - double y[]={2.404825557695773,5.520078110286311,8.653727912911013, - 1.179153443901428e1,1.493091770848779e1,1.807106396791092e1, - 2.121163662987926e1,2.435247153074930e1,2.749347913204025e1, - 3.063460646843198e1,3.377582021357357e1,3.691709835366405e1, - 4.005842576462825e1,4.319979171317673e1,4.634118837166182e1, - 4.948260989739782e1}; - double[] yy = buildVector(y); - boolean localflag, globalflag=false; - - - - // Test zbrent - System.out.println("Testing zbrent"); - Func_zbrent fx = new Func_zbrent(); - Zbrak z = new Zbrak(); z.zbrak(fx,x1,x2,100); - xb1= z.xb1;xb2=z.xb2;nroot = z.nroot; - double[] root=new double[nroot]; - for (i=0;i xacc; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** zbrent: Incorrect roots"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - class Func_zbrent implements UniVarRealValueFun { - Bessjy b = new Bessjy(); - public double funk (final double x) { - return b.j0(x); - } - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zrhqr.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zrhqr.java deleted file mode 100644 index d2b1b3d273..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zrhqr.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.nr.test.test_chapter9; - -import static com.nr.NRUtil.buildVector; -import static com.nr.root.Roots.zrhqr; -import static com.nr.test.NRTestUtil.maxel; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.Complex; - -public class Test_zrhqr { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,j,N=5; - double sbeps=5.e-14; - double a[]={2.0,-2.0,7.0,1.0,-3.0,5.0}; - Complex b = new Complex(); - double[] aa= buildVector(a),dy = new double[N]; - Complex[] rts = new Complex[N]; - boolean localflag, globalflag=false; - - // Test zrhqr - System.out.println("Testing zrhqr"); - // Roots of polynomial - zrhqr(aa,rts); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** zrhqr: Incorrect roots"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zriddr.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zriddr.java deleted file mode 100644 index 27f482366c..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zriddr.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.nr.test.test_chapter9; - -import static com.nr.NRUtil.buildVector; -import static com.nr.root.Roots.zriddr; -import static com.nr.test.NRTestUtil.maxel; -import static com.nr.test.NRTestUtil.vecsub; -import static java.lang.Math.abs; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.UniVarRealValueFun; -import com.nr.root.Roots.Zbrak; -import com.nr.sf.Bessjy; - -public class Test_zriddr { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i; - int nroot = 0; - double[] xb1,xb2; - - double sbeps=1.e-15,xacc=0.; - double x1=1.0,x2=50.0; - - double y[]={2.404825557695773,5.520078110286311,8.653727912911013, - 1.179153443901428e1,1.493091770848779e1,1.807106396791092e1, - 2.121163662987926e1,2.435247153074930e1,2.749347913204025e1, - 3.063460646843198e1,3.377582021357357e1,3.691709835366405e1, - 4.005842576462825e1,4.319979171317673e1,4.634118837166182e1, - 4.948260989739782e1}; - double[] yy = buildVector(y); - boolean localflag, globalflag=false; - - - // Test zriddr - System.out.println("Testing zriddr"); - Func_zriddr fx = new Func_zriddr(); - Zbrak z = new Zbrak(); z.zbrak(fx,x1,x2,100); - xb1= z.xb1;xb2=z.xb2;nroot = z.nroot; - double[] root =new double[(nroot)]; - for (i=0;i xacc; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** zriddr: Incorrect roots"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - - class Func_zriddr implements UniVarRealValueFun{ - Bessjy b = new Bessjy(); - public double funk (final double x) { - return b.j0(x); - } - }; -} diff --git a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zroots.java b/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zroots.java deleted file mode 100644 index 41dc826f13..0000000000 --- a/common-tools/cnuphys/numRec/test/com/nr/test/test_chapter9/Test_zroots.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.nr.test.test_chapter9; - -import static com.nr.root.Roots.zroots; -import static com.nr.test.NRTestUtil.maxel; -import static org.junit.Assert.fail; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.nr.Complex; - - -public class Test_zroots { - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void test() { - int i,N=5; - boolean polish=true; - double sbeps=1.e-14; - Complex re1 = new Complex(1.0,0.0),im1=new Complex(0.0,1.0); - Complex a[]={ - re1.mul(2.0).add(im1), - im1.mul(2.0), - re1.mul(3.0).add(im1), - re1.add(im1.mul(2.0)), - re1.sub(im1), - new Complex(1.0) - }; - - Complex[] aa = new Complex[N+1];System.arraycopy(a, 0, aa, 0 , N+1); - - Complex[] rts = new Complex[N]; - double[] dy=new double[N]; - boolean localflag, globalflag=false; - - - - // Test zroots - System.out.println("Testing zroots"); - // Roots of polynomial x^5+(1-i)x^4+(1+2i)x^3+(3+i)x^2+(2i)x+(2+i)" - // Roots are x=i, x=-i, x=sqrt(2i), x=-i*sqrt(2i), x=(i-1) - zroots(aa,rts,polish); - for (i=0;i sbeps; - globalflag = globalflag || localflag; - if (localflag) { - fail("*** zroots: Incorrect roots"); - - } - - if (globalflag) System.out.println("Failed\n"); - else System.out.println("Passed\n"); - } - -} diff --git a/common-tools/cnuphys/pom.xml b/common-tools/cnuphys/pom.xml index 3b1dcca529..4e52549016 100644 --- a/common-tools/cnuphys/pom.xml +++ b/common-tools/cnuphys/pom.xml @@ -14,7 +14,6 @@ - splot snr magfield swimmer diff --git a/common-tools/cnuphys/splot/.gitignore b/common-tools/cnuphys/splot/.gitignore deleted file mode 100644 index ae3c172604..0000000000 --- a/common-tools/cnuphys/splot/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/common-tools/cnuphys/splot/build.xml b/common-tools/cnuphys/splot/build.xml deleted file mode 100644 index 9e08458773..0000000000 --- a/common-tools/cnuphys/splot/build.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - Building splot class and images jar - - - - - Building splot jar - - - - - diff --git a/common-tools/cnuphys/splot/images/Thumbs.db b/common-tools/cnuphys/splot/images/Thumbs.db deleted file mode 100644 index df04c84eeb..0000000000 Binary files a/common-tools/cnuphys/splot/images/Thumbs.db and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/blankimage.gif b/common-tools/cnuphys/splot/images/blankimage.gif deleted file mode 100644 index 1f685dca48..0000000000 Binary files a/common-tools/cnuphys/splot/images/blankimage.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/box_zoom.gif b/common-tools/cnuphys/splot/images/box_zoom.gif deleted file mode 100644 index 35ed2aef58..0000000000 Binary files a/common-tools/cnuphys/splot/images/box_zoom.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/box_zoomcursor.gif b/common-tools/cnuphys/splot/images/box_zoomcursor.gif deleted file mode 100644 index 18a3f284b8..0000000000 Binary files a/common-tools/cnuphys/splot/images/box_zoomcursor.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/box_zoomenabled.gif b/common-tools/cnuphys/splot/images/box_zoomenabled.gif deleted file mode 100644 index fd1454fcfa..0000000000 Binary files a/common-tools/cnuphys/splot/images/box_zoomenabled.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/camera.gif b/common-tools/cnuphys/splot/images/camera.gif deleted file mode 100644 index 9a18bdf939..0000000000 Binary files a/common-tools/cnuphys/splot/images/camera.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/center.gif b/common-tools/cnuphys/splot/images/center.gif deleted file mode 100644 index a1cbec782e..0000000000 Binary files a/common-tools/cnuphys/splot/images/center.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/centercursor.png b/common-tools/cnuphys/splot/images/centercursor.png deleted file mode 100644 index 0dbb37b032..0000000000 Binary files a/common-tools/cnuphys/splot/images/centercursor.png and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/centerenabled.gif b/common-tools/cnuphys/splot/images/centerenabled.gif deleted file mode 100644 index 41e00d5080..0000000000 Binary files a/common-tools/cnuphys/splot/images/centerenabled.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/cnuicon.png b/common-tools/cnuphys/splot/images/cnuicon.png deleted file mode 100644 index b873d23fcc..0000000000 Binary files a/common-tools/cnuphys/splot/images/cnuicon.png and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/crosshair16x16.png b/common-tools/cnuphys/splot/images/crosshair16x16.png deleted file mode 100644 index ac9e5666fd..0000000000 Binary files a/common-tools/cnuphys/splot/images/crosshair16x16.png and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/delete.gif b/common-tools/cnuphys/splot/images/delete.gif deleted file mode 100644 index c4904fe8a8..0000000000 Binary files a/common-tools/cnuphys/splot/images/delete.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/edit.png b/common-tools/cnuphys/splot/images/edit.png deleted file mode 100644 index fb5b0306ca..0000000000 Binary files a/common-tools/cnuphys/splot/images/edit.png and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/lassofunnel.png b/common-tools/cnuphys/splot/images/lassofunnel.png deleted file mode 100644 index a77a7081f0..0000000000 Binary files a/common-tools/cnuphys/splot/images/lassofunnel.png and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/lassofunnelenabled.png b/common-tools/cnuphys/splot/images/lassofunnelenabled.png deleted file mode 100644 index 37e212eb57..0000000000 Binary files a/common-tools/cnuphys/splot/images/lassofunnelenabled.png and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/lassorect.gif b/common-tools/cnuphys/splot/images/lassorect.gif deleted file mode 100644 index a8d745e3c4..0000000000 Binary files a/common-tools/cnuphys/splot/images/lassorect.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/lassorectenabled.gif b/common-tools/cnuphys/splot/images/lassorectenabled.gif deleted file mode 100644 index 4d7bf7466e..0000000000 Binary files a/common-tools/cnuphys/splot/images/lassorectenabled.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/minusBox.gif b/common-tools/cnuphys/splot/images/minusBox.gif deleted file mode 100644 index 56b07bcb17..0000000000 Binary files a/common-tools/cnuphys/splot/images/minusBox.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/minusBoxSub.gif b/common-tools/cnuphys/splot/images/minusBoxSub.gif deleted file mode 100644 index 29c5591706..0000000000 Binary files a/common-tools/cnuphys/splot/images/minusBoxSub.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/pan.gif b/common-tools/cnuphys/splot/images/pan.gif deleted file mode 100644 index 1fd145f55f..0000000000 Binary files a/common-tools/cnuphys/splot/images/pan.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/panenabled.gif b/common-tools/cnuphys/splot/images/panenabled.gif deleted file mode 100644 index 3245ce2211..0000000000 Binary files a/common-tools/cnuphys/splot/images/panenabled.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/plusBox.gif b/common-tools/cnuphys/splot/images/plusBox.gif deleted file mode 100644 index f12250382f..0000000000 Binary files a/common-tools/cnuphys/splot/images/plusBox.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/pointer.gif b/common-tools/cnuphys/splot/images/pointer.gif deleted file mode 100644 index 3c87e43d17..0000000000 Binary files a/common-tools/cnuphys/splot/images/pointer.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/pointer13.png b/common-tools/cnuphys/splot/images/pointer13.png deleted file mode 100644 index 9f1f73c58e..0000000000 Binary files a/common-tools/cnuphys/splot/images/pointer13.png and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/pointercursor.gif b/common-tools/cnuphys/splot/images/pointercursor.gif deleted file mode 100644 index 5371513863..0000000000 Binary files a/common-tools/cnuphys/splot/images/pointercursor.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/pointerenabled.gif b/common-tools/cnuphys/splot/images/pointerenabled.gif deleted file mode 100644 index 4a032ca92c..0000000000 Binary files a/common-tools/cnuphys/splot/images/pointerenabled.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/polylineenabled.gif b/common-tools/cnuphys/splot/images/polylineenabled.gif deleted file mode 100644 index bf26b1394d..0000000000 Binary files a/common-tools/cnuphys/splot/images/polylineenabled.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/printer.gif b/common-tools/cnuphys/splot/images/printer.gif deleted file mode 100644 index bfc201255e..0000000000 Binary files a/common-tools/cnuphys/splot/images/printer.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/refresh.gif b/common-tools/cnuphys/splot/images/refresh.gif deleted file mode 100644 index 4e18702851..0000000000 Binary files a/common-tools/cnuphys/splot/images/refresh.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/undo_zoom.gif b/common-tools/cnuphys/splot/images/undo_zoom.gif deleted file mode 100644 index f28a982c35..0000000000 Binary files a/common-tools/cnuphys/splot/images/undo_zoom.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/world.gif b/common-tools/cnuphys/splot/images/world.gif deleted file mode 100644 index 71a2530fad..0000000000 Binary files a/common-tools/cnuphys/splot/images/world.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/zoom_in.gif b/common-tools/cnuphys/splot/images/zoom_in.gif deleted file mode 100644 index d35628cc72..0000000000 Binary files a/common-tools/cnuphys/splot/images/zoom_in.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/images/zoom_out.gif b/common-tools/cnuphys/splot/images/zoom_out.gif deleted file mode 100644 index fce91cb56a..0000000000 Binary files a/common-tools/cnuphys/splot/images/zoom_out.gif and /dev/null differ diff --git a/common-tools/cnuphys/splot/pom.xml b/common-tools/cnuphys/splot/pom.xml deleted file mode 100644 index 8532c89440..0000000000 --- a/common-tools/cnuphys/splot/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - 4.0.0 - - cnuphys - splot - 14.2.4-SNAPSHOT - jar - - - cnuphys - clas12 - 14.2.4-SNAPSHOT - - - - - cnuphys - numRec - 1.0 - - - cnuphys - f2jutil - 1.0 - - - - diff --git a/common-tools/cnuphys/splot/src/main/java/build.xml b/common-tools/cnuphys/splot/src/main/java/build.xml deleted file mode 100644 index fc8ef50771..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/build.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - Building splot image jar - - - - - Building splot jar - - - - - - - - - - - - - diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/.gitignore b/common-tools/cnuphys/splot/src/main/java/cnuphys/.gitignore deleted file mode 100644 index ae3c172604..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/.gitignore b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/.gitignore deleted file mode 100644 index 1888bce86c..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/.gitignore +++ /dev/null @@ -1,26 +0,0 @@ -/ButtonPanel.class -/ColorDialog$1.class -/ColorDialog.class -/ColorLabel$1.class -/ColorLabel.class -/ColorPanel$1.class -/ColorPanel.class -/CurveDataModel.class -/CurveEditorDialog.class -/CurveEditorPanel$1.class -/CurveEditorPanel$2.class -/CurveEditorPanel.class -/CurveTable$1.class -/CurveTable$2.class -/CurveTable$3.class -/CurveTable$4.class -/CurveTable.class -/DataEditor.class -/DialogUtilities.class -/IColorChangeListener.class -/PlotPreferencesDialog.class -/SimpleDialog$1.class -/SimpleDialog$2.class -/SimpleDialog.class -/VerticalFlowLayout$AlignedComponent.class -/VerticalFlowLayout.class diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/AxesLimitsPanel.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/AxesLimitsPanel.java deleted file mode 100644 index 08e242ccf8..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/AxesLimitsPanel.java +++ /dev/null @@ -1,42 +0,0 @@ -package cnuphys.splot.edit; - -import java.awt.GridLayout; - -import javax.swing.JPanel; - -import cnuphys.splot.plot.CommonBorder; -import cnuphys.splot.plot.PlotCanvas; - -public class AxesLimitsPanel extends JPanel { - - //the plot canvas - private PlotCanvas _canvas; - - //the two panels for t x and y axes - private OneAxisLimitsPanel _xPanel; - private OneAxisLimitsPanel _yPanel; - - /** - * Create the panel for editing the axes limits - * @param canvas - */ - public AxesLimitsPanel(PlotCanvas canvas) { - _canvas = canvas; - - setLayout(new GridLayout(2, 1, 4, 4)); - - _xPanel = new OneAxisLimitsPanel(canvas, OneAxisLimitsPanel.Axis.X); - _yPanel = new OneAxisLimitsPanel(canvas, OneAxisLimitsPanel.Axis.Y); - - setBorder(new CommonBorder("Axes Limits")); - - add(_xPanel); - add(_yPanel); - } - - /** Apply any changes */ - public void apply() { - _xPanel.apply(); - _yPanel.apply(); - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/ButtonPanel.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/ButtonPanel.java deleted file mode 100644 index a0612340ab..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/ButtonPanel.java +++ /dev/null @@ -1,277 +0,0 @@ -package cnuphys.splot.edit; - -import java.awt.FlowLayout; -import java.awt.Insets; -import java.awt.event.ActionListener; -import java.util.Vector; - -import javax.swing.JButton; -import javax.swing.JPanel; - -public class ButtonPanel extends JPanel { - - /** - * Bits indicating use OK, Cancel, ... - */ - - public static final int USE_OK = 01; - - public static final int USE_CANCEL = 02; - - public static final int USE_APPLY = 04; - - public static final int USE_DELETE = 010; - - /** - * Bit indicating using combinations OK and CANCEL - */ - public static final int USE_OKCANCEL = USE_OK | USE_CANCEL; - - public static final int USE_OKCANCELAPPLY = USE_OK | USE_CANCEL | USE_APPLY; - - public static final int USE_OKCANCELDELETE = USE_OK | USE_CANCEL | USE_DELETE; - - /** - * Constant indicating an "OK" response - */ - - public static final int OK_RESPONSE = 0; - - /** - * Constant indicating a "cancel" response - */ - - public static final int CANCEL_RESPONSE = 1; - - /** - * Constant indicating an "apply" response - */ - - public static final int APPLY_RESPONSE = 2; - - /* - * Constant indicating a "delete" response - */ - - public static final int DELETE_RESPONSE = 3; - - /** - * Constant string for "ok" label - */ - - public static final String OK_LABEL = " OK "; - - /** - * Constant string for "cancel" label - */ - - public static final String CANCEL_LABEL = " Cancel "; - - /** - * Constant string for "apply" label - */ - - public static final String APPLY_LABEL = " Apply "; - - /** - * Constant string for "delete" label - */ - - public static final String DELETE_LABEL = " Delete "; - - /** - * The buttons - */ - - protected JButton[] buttons = null; - - /** - * The labels - */ - - protected String[] labels = null; - - /** - * The constructor. - * - * @param labels The button labels. - */ - - public ButtonPanel(String labels[]) { - this(labels, null, -1); - } - - /** - * The constructor. - * - * @param labels The button labels. - * @param alist Optional action listener. - */ - - public ButtonPanel(String labels[], ActionListener alist) { - this(labels, alist, 4, -1); - } - - /** - * The constructor. - * - * @param labels The button labels. - * @param alist Optional action listener. - * @param spacing The spacing between labels. - */ - - public ButtonPanel(String labels[], ActionListener alist, int spacing) { - - this(labels, alist, spacing, FlowLayout.CENTER); - } - - /** - * The constructor. - * - * @param labels the button labels. - * @param alist optional action listener. - * @param spacing the spacing between labels. - * @param alignment the layout alignment - */ - - public ButtonPanel(String labels[], ActionListener alist, int spacing, int alignment) { - - super(new FlowLayout(alignment, spacing, 0)); - this.labels = labels; - - userSetup(); - - if (this.labels == null) { - return; - } - - addButtons(alist); - } - - /** - * Place for subclasses to add something else - */ - - protected void userSetup() { - } - - /** - * Add the buttons to the panel. - * - * @param alist An action listener. - */ - - protected void addButtons(ActionListener alist) { - - buttons = new JButton[labels.length]; - - for (int i = 0; i < labels.length; i++) { - if (labels[i] != null) { - buttons[i] = new JButton(labels[i]); - add(buttons[i]); - if (alist != null) { - buttons[i].addActionListener(alist); - } - } - else { - buttons[i] = null; - } - } - } - - /** - * Enable or disable a button. - * - * @param index the index of the button. If -1, applies to all. - * @param state if true, enable, else disable. - */ - - public void setEnabled(int index, boolean state) { - - if (index < 0) { - for (int i = 0; i < buttons.length; i++) { - if (buttons[i] != null) { - buttons[i].setEnabled(state); - } - } - } - else if (index < buttons.length) { - if (buttons[index] != null) { - buttons[index].setEnabled(state); - } - } - } - - /** - * Set tooltip - * - * @param index The index of the button. - * @param tip tooltip string - */ - - public void setToolTip(int index, String tip) { - if (buttons[index] != null) { - buttons[index].setToolTipText(tip); - } - } - - @Override - public Insets getInsets() { - Insets def = super.getInsets(); - return new Insets(def.top + 2, def.left + 2, def.bottom + 2, def.right + 2); - } - - /** - * Makes a button panel with combinations of OK, Save, Save As, Cancel, Apply, - * and Delete - * - * @param opt Bitwise combination of USE_OK, USE_CANCEL, USE_APPLY, - * USE_DELETE - * @param actionListener Action listener for button clicks - * @param spacing The spacing between labels. - */ - - public static ButtonPanel closeOutPanel(int opt, ActionListener actionListener, int spacing) { - - Vector vl = new Vector(7); - - if (checkBit(opt, USE_OK)) { - vl.addElement(OK_LABEL); - } - - if (checkBit(opt, USE_CANCEL)) { - vl.addElement(CANCEL_LABEL); - } - - if (checkBit(opt, USE_APPLY)) { - vl.addElement(APPLY_LABEL); - } - - if (checkBit(opt, USE_DELETE)) { - vl.addElement(DELETE_LABEL); - } - - int num = vl.size(); - - if (num < 1) { - return null; - } - - String[] labels = new String[num]; - - for (int i = 0; i < num; i++) { - labels[i] = (vl.elementAt(i)); - } - - return new ButtonPanel(labels, actionListener, spacing); - } - - /** - * Method to see if a bit is set. - */ - - private static boolean checkBit(int opt, int bit) { - return ((opt & bit) == bit); - } - -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/ColorDialog.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/ColorDialog.java deleted file mode 100644 index 6cfe7ec193..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/ColorDialog.java +++ /dev/null @@ -1,138 +0,0 @@ -package cnuphys.splot.edit; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Container; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JDialog; - -@SuppressWarnings("serial") -public class ColorDialog extends JDialog { - protected ColorPanel colorPanel = null; - protected int answer = -1; - - /** - * Constructor (transparency disabled). - * - * @param title probably a description of what is having its color - * changed - * @param initColor the initial color - * @param allowNoColor if true, user can select "no color" - */ - - public ColorDialog(String title, Color initColor, boolean allowNoColor) { - this(title, initColor, allowNoColor, false); - } - - /** - * Constructor (transparency disabled). - * - * @param title probably a description of what is having its color - * changed - * @param initColor the initial color - * @param allowNoColor if true, user can select "no color" - * @param allowTransparency if true, alpha color slider is enabled. - */ - - public ColorDialog(String title, Color initColor, boolean allowNoColor, boolean allowTransparency) { - setTitle((title != null) ? title : "Color Selection"); - - setModal(true); - setup(); - addColorPanel(initColor, allowNoColor, allowTransparency); - pack(); - DialogUtilities.centerDialog(this); - } - - /** - * Create the color panel - * - * @param initColor The initial color - * @param allowNoColor If true, user can select "no color" - * @param allowTransparency It true, alpha color slider is enabled. - */ - - private void addColorPanel(Color initColor, boolean allowNoColor, boolean allowTransparency) { - Container cp = getContentPane(); - colorPanel = new ColorPanel(); - cp.add("Center", colorPanel); - colorPanel.setColor(initColor); - colorPanel.enableNoColor(allowNoColor); - colorPanel.setNoColor(initColor == null); - colorPanel.enableTransparency(allowTransparency); - } - - /** - * Add the components to the dialog - */ - - protected void setup() { - - Container cp = getContentPane(); - cp.setLayout(new BorderLayout(2, 2)); - - // closeout buttons-- use OK and CANCEL - - // buttons - - ActionListener alist = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - String command = e.getActionCommand(); - - if (ButtonPanel.OK_LABEL.equals(command)) { - doClose(DialogUtilities.OK_RESPONSE); - } - - if (ButtonPanel.CANCEL_LABEL.equals(command)) { - doClose(DialogUtilities.CANCEL_RESPONSE); - } - - } - - }; - - ButtonPanel bp = ButtonPanel.closeOutPanel(ButtonPanel.USE_OKCANCEL, alist, 6); - - cp.add("South", bp); - - } - - /** - * Get the selected color - * - * @return the selected color - */ - public Color getColor() { - if (colorPanel.isNoColorSelected()) { - return null; - } - return colorPanel.getColor(); - } - - /** - * Close the dialog - * - * @param reason the reason it closed - */ - protected void doClose(int reason) { - answer = reason; - setVisible(false); - - if (answer == DialogUtilities.OK_RESPONSE) { - } - } - - /** - * Get the reason the dialog closed - * - * @return the reason it closed - */ - public int getAnswer() { - return answer; - } - -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/ColorLabel.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/ColorLabel.java deleted file mode 100644 index 6e7943f7c9..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/ColorLabel.java +++ /dev/null @@ -1,134 +0,0 @@ -package cnuphys.splot.edit; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -import javax.swing.JComponent; - -public class ColorLabel extends JComponent { - - // the current color - private Color _currentColor; - - // the listener for color changes - private IColorChangeListener _colorChangeListener; - - // the prompt label - private String _prompt; - - // preferred total width for the label - private int _desiredWidth = -1; - - // the size of the color box - private int _rectSize = 12; - - // used for sizing - private Dimension _size; - - /** - * Create an inert color label. - * - * @param color the color. - * @param prompt the prompt string. - */ - public ColorLabel(IColorChangeListener listener, Color color, Font font, String prompt) { - - _currentColor = color; - setFont(font); - _prompt = prompt; - _colorChangeListener = listener; - - FontMetrics fm = this.getFontMetrics(font); - int sw = fm.stringWidth(prompt); - _size = new Dimension(sw + _rectSize + 10, 18); - - MouseAdapter ma = new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { -// if (!isEnabled()) { -// return; -// } - - ColorDialog cd = new ColorDialog(_prompt, _currentColor, true, true); - - cd.setVisible(true); - - if (cd.answer == DialogUtilities.OK_RESPONSE) { - setColor(cd.getColor()); - repaint(); - } - - } - }; - - addMouseListener(ma); - - } - - /** - * Set the color change listener - * - * @param listener the color change listener - */ - public void setColorListener(IColorChangeListener listener) { - _colorChangeListener = listener; - } - - @Override - public void paintComponent(Graphics g) { - FontMetrics fm = getFontMetrics(getFont()); - g.setFont(getFont()); - boolean enabled = isEnabled(); - - if (_currentColor == null) { - g.setColor(Color.red); - g.drawLine(4, 4, _rectSize, _rectSize); - g.drawLine(4, _rectSize, _rectSize, 4); - } - else { - g.setColor(enabled ? _currentColor : Color.gray); - g.fillRect(2, 2, _rectSize, _rectSize); - } - g.setColor(enabled ? Color.black : Color.gray); - g.drawRect(2, 2, _rectSize, _rectSize); - - g.drawString(_prompt, _rectSize + 6, fm.getHeight()); - } - - @Override - public Dimension getPreferredSize() { - if (_size == null) { - return super.getPreferredSize(); - } - return _size; - } - - /** - * Return the current color. - * - * @return the current color. - */ - public Color getColor() { - return _currentColor; - } - - /** - * Set the new color. - * - * @param newColor the new color index. - */ - public void setColor(Color newColor) { - _currentColor = newColor; - setBackground(_currentColor); - if (_colorChangeListener != null) { - _colorChangeListener.colorChanged(this, _currentColor); - } - repaint(); - } - -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/ColorPanel.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/ColorPanel.java deleted file mode 100644 index e4dd8119da..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/ColorPanel.java +++ /dev/null @@ -1,249 +0,0 @@ -package cnuphys.splot.edit; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.GridLayout; -import java.awt.Insets; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.util.Hashtable; - -import javax.swing.JCheckBox; -import javax.swing.JColorChooser; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JSlider; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - -public class ColorPanel extends JPanel implements ItemListener, ChangeListener { - - /** - * "No color" checkbox--used to select no color (if enabled) - */ - - protected JCheckBox nocolorcb; - - /** - * Transparency slider - */ - - protected JSlider transparencySlider; - - /** - * Label showing the old color - */ - - /** - * Label showing the new color - */ - - protected JLabel oldcolorlabel; - - protected JLabel newcolorlabel; - - protected static int minw = 440; - - protected static int minh = 340; - - protected JPanel previewPanel; - - protected JColorChooser colorChooser; - - public ColorPanel() { - setLayout(new BorderLayout()); - colorChooser = new JColorChooser(); - colorChooser.getSelectionModel().addChangeListener(this); - - add("Center", colorChooser); - - previewPanel = createPreviewPanel(); - colorChooser.setPreviewPanel(previewPanel); - } - - @SuppressWarnings("unchecked") - public JPanel createPreviewPanel() { - - JPanel previewPanel = new JPanel() { - - /** - * Override insets for nicer appearance - */ - @Override - public Insets getInsets() { - Insets def = super.getInsets(); - return new Insets(def.top + 2, def.left + 2, def.bottom + 2, def.right + 2); - } - - /** - * Override getMinimumSize for nicer appearance - * - * @return Minimum size for panel - */ - @Override - public Dimension getMinimumSize() { - return new Dimension(minw - 20, 80); - } - - /** - * Override getPreferredSize for nicer appearance - * - * @return Preferred size for panel - */ - @Override - public Dimension getPreferredSize() { - return getMinimumSize(); - } - }; - - previewPanel.setLayout(new BorderLayout(20, 4)); - - nocolorcb = new JCheckBox("No Color"); - nocolorcb.addItemListener(this); - // nocolorcb.setEnabled(nocolor); - - previewPanel.add("West", nocolorcb); - - JPanel sp = new JPanel(); - sp.setLayout(new GridLayout(2, 2, 10, 2)); - - newcolorlabel = new JLabel(" "); - oldcolorlabel = new JLabel(" "); - - sp.add(new JLabel("New Color:")); - sp.add(newcolorlabel); - sp.add(new JLabel("Old Color:")); - sp.add(oldcolorlabel); - - // make the transparency slider - - JPanel tpanel = new JPanel(new BorderLayout(2, 0)); - // tpanel.add("North", new JLabel("Transparency")); - - transparencySlider = new JSlider(0, 100, 100); - transparencySlider.setMajorTickSpacing(25); - transparencySlider.setPaintTicks(true); - - Hashtable ht = transparencySlider.createStandardLabels(25); - transparencySlider.setLabelTable(ht); - transparencySlider.setPaintLabels(true); - - tpanel.add("East", new JLabel("Opaque")); - tpanel.add("West", new JLabel("Transparent")); - tpanel.add("Center", transparencySlider); - - previewPanel.add("South", tpanel); - - newcolorlabel.setOpaque(true); - oldcolorlabel.setOpaque(true); - - previewPanel.add("East", sp); - return previewPanel; - } - - @Override - public Dimension getMinimumSize() { - return new Dimension(minw, minh); - } - - @Override - public Dimension getPreferredSize() { - return getMinimumSize(); - } - - @Override - public Insets getInsets() { - Insets def = super.getInsets(); - return new Insets(def.top + 6, def.left + 6, def.bottom + 6, def.right + 6); - } - - @Override - public void itemStateChanged(ItemEvent e) { - if (nocolorcb != null) { - colorChooser.setEnabled(!noColor()); - } - } - - /** - * Check whether "no color" was selected - * - * @return true if no color was selected - */ - - public boolean noColor() { - return nocolorcb.isSelected(); - } - - /** - * Set whether user is allowed to select "no color" - * - * @param anc - */ - - public void enableNoColor(boolean anc) { - nocolorcb.setEnabled(anc); - } - - /** - * Set whether user is allowed to set gtransparency level - * - * @param anc If true, use can select transparency - */ - - public void enableTransparency(boolean anc) { - transparencySlider.setEnabled(anc); - } - - public void setColor(Color c) { - colorChooser.setColor(c); - oldcolorlabel.setBackground(c); - - if (c != null) { - int alpha = c.getAlpha(); - alpha = (int) (alpha / 2.5); - alpha = Math.max(0, Math.min(100, alpha)); - transparencySlider.setValue(alpha); - } - } - - @Override - public void stateChanged(ChangeEvent e) { - setNoColor(false); - Color newColor = colorChooser.getColor(); - newcolorlabel.setBackground(newColor); - } - - public boolean isNoColorSelected() { - return nocolorcb.isSelected(); - } - - public void setNoColor(boolean nocol) { - nocolorcb.setSelected(nocol); - colorChooser.setEnabled(!nocol); - } - - /** - * Get the selected color, modified for transparency if necessary - * - * @return the color - */ - - public Color getColor() { - if (nocolorcb.isEnabled() && nocolorcb.isSelected()) { - return null; - } - - Color bcolor = colorChooser.getColor(); - if (transparencySlider.isEnabled()) { - int alpha = (int) (2.5 * (transparencySlider.getValue())); - alpha = Math.max(0, Math.min(255, alpha)); - return new Color(bcolor.getRed(), bcolor.getGreen(), bcolor.getBlue(), alpha); - - } - else { - return bcolor; - } - } - -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/CurveDataModel.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/CurveDataModel.java deleted file mode 100644 index 7363c328ec..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/CurveDataModel.java +++ /dev/null @@ -1,177 +0,0 @@ -package cnuphys.splot.edit; - -import java.util.Vector; - -import javax.swing.table.DefaultTableModel; - -import cnuphys.splot.pdata.DataColumn; - -public class CurveDataModel extends DefaultTableModel { - - /** - * Constant used to designate display column; - */ - public static final int VIS_COLUMN = 0; - - /** - * Constant used to designate name column; - */ - public static final int NAME_COLUMN = 1; - - // the names of the columns - protected static final String colNames[] = { "Vis", "Curve Name" }; - - // the widths of the columns - protected static final int columnWidths[] = { 30, 220 }; - - // the model data - protected Vector _data; - - /** - * Constructor - */ - public CurveDataModel() { - super(colNames, 2); - } - - /** - * Constructor - */ - public CurveDataModel(Vector curves) { - super(colNames, 2); - setData(curves); - } - - /** - * Get the number of columns - * - * @return the number of columns - */ - @Override - public int getColumnCount() { - return columnWidths.length; - } - - /** - * Get the number of rows - * - * @return the number of rows - */ - @Override - public int getRowCount() { - if (_data == null) { - return 0; - } - return _data.size(); - } - - /** - * Set the value at a given row and column. - * - * @param value The string to set. - * @param row The zero based row. - * @param col The zero based column. - */ - - @Override - public void setValueAt(Object value, int row, int col) { - DataColumn curve = _data.elementAt(row); - switch (col) { - - case VIS_COLUMN: - curve.setVisible((Boolean) value); - break; - - case NAME_COLUMN: - curve.setName((String) value); - break; - } - - } - - /** - * Get the value at a given row and column - * - * @return the value at a given row and column - */ - @Override - public Object getValueAt(int row, int col) { - - DataColumn curve = _data.elementAt(row); - - if (curve == null) { - return null; - } - - switch (col) { - - case VIS_COLUMN: - return curve.isVisible(); - - case NAME_COLUMN: - return curve.getName(); - } - - return null; - } - - /** - * Add a new curve into the table. - * - * @param curve the new object to add to the model. - */ - public synchronized void add(DataColumn curve) { - if (curve != null) { - _data.add(curve); - } - } - - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - return true; - } - - /** - * remove an curve from the table. - * - * @param curve the curveto remove. - */ - public synchronized void remove(DataColumn curve) { - if (curve != null) { - _data.remove(curve); - } - } - - /** - * Clear all the data - */ - public synchronized void clear() { - if (_data != null) { - _data.clear(); - } - } - - /** - * @param data the data to set - */ - public synchronized void setData(Vector data) { - _data = data; - } - - /** - * Get the curve (DataColumn) in the model at the given row. - * - * @param row the zero based row - * @return the curve corresponding to the row. - */ - public DataColumn getCurveAtRow(int row) { - if ((_data == null) || (row < 0)) { - return null; - } - if (row >= _data.size()) { - return null; - } - return _data.elementAt(row); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/CurveEditorDialog.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/CurveEditorDialog.java deleted file mode 100644 index 5d79e8ef72..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/CurveEditorDialog.java +++ /dev/null @@ -1,63 +0,0 @@ -package cnuphys.splot.edit; - -import java.awt.BorderLayout; -import cnuphys.splot.plot.PlotCanvas; - -public class CurveEditorDialog extends SimpleDialog { - - // the plot canvas - protected PlotCanvas _plotCanvas; - - // button labels - protected static final String CLOSE = "Close"; - - // curve editor panel - protected CurveEditorPanel _curvePanel; - - /** - * Edit the plot preferences - * - * @param plotCanvas the plot being edited - */ - public CurveEditorDialog(PlotCanvas plotCanvas) { - super("Curve Editor", plotCanvas, true, CLOSE); - - // note components already created by super constructor - _plotCanvas = plotCanvas; - - _curvePanel = new CurveEditorPanel(_plotCanvas); - add(_curvePanel, BorderLayout.CENTER); - pack(); - } - - /** - * can do preparation--for example a component might be added on - * "createCenterComponent" but a reference needed in "addNorthComponent" - */ - @Override - protected void prepare() { - _plotCanvas = (PlotCanvas) _userObject; - } - - /** - * Select the first curve - */ - public void selectFirstCurve() { - if (_curvePanel != null) { - _curvePanel.selectFirstCurve(); - } - } - - /** - * A button was hit. The default behavior is to shutdown the dialog. - * - * @param command the label on the button that was hit. - */ - @Override - protected void handleCommand(String command) { - if (CLOSE.equals(command)) { - setVisible(false); - } - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/CurveEditorPanel.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/CurveEditorPanel.java deleted file mode 100644 index af36b65489..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/CurveEditorPanel.java +++ /dev/null @@ -1,402 +0,0 @@ -package cnuphys.splot.edit; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.Collection; - -import javax.swing.DefaultListModel; -import javax.swing.JEditorPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; - -import cnuphys.splot.fit.Fit; -import cnuphys.splot.fit.FitEditorPanel; -import cnuphys.splot.fit.FitType; -import cnuphys.splot.pdata.DataColumn; -import cnuphys.splot.pdata.DataColumnType; -import cnuphys.splot.pdata.HistoData; -import cnuphys.splot.plot.CommonBorder; -import cnuphys.splot.plot.Environment; -import cnuphys.splot.plot.PlotCanvas; -import cnuphys.splot.style.EnumComboBox; -import cnuphys.splot.style.IStyled; -import cnuphys.splot.style.LineStyle; -import cnuphys.splot.style.StyleEditorPanel; -import cnuphys.splot.style.SymbolType; - -/** - * Used to edit parameters for curves on a plot - * - * @author heddle - * - */ -public class CurveEditorPanel extends JPanel implements ActionListener, PropertyChangeListener { - - // the underlying plot canvas - protected PlotCanvas _plotCanvas; - - // list font - protected static Font _listFont = Environment.getInstance().getCommonFont(12); - protected static Font _textFont = Environment.getInstance().getCommonFont(10); - - // curve table - private CurveTable _curveTable; - - // style panel - protected StyleEditorPanel _stylePanel; - - // fit editor - protected FitEditorPanel _fitPanel; - - // text area for fit info - protected JEditorPane _textArea; - - /** - * A panel for editing data sets - * - * @param plotCanvas the plot being edited - */ - public CurveEditorPanel(PlotCanvas plotCanvas) { - // note components already created by super constructor - _plotCanvas = plotCanvas; - _plotCanvas.addPropertyChangeListener(this); - Environment.getInstance().commonize(this, null); - setBorder(new CommonBorder()); - addContent(); - } - - @Override - public void setEnabled(boolean enabled) { - _fitPanel.setEnabled(enabled); - _stylePanel.setEnabled(enabled); - // _showCurve.setEnabled(enabled); - } - - // new curve has been selected - private void curveChanged(DataColumn curve) { - // a new curve was selected, which might be null - // set all editors accordingly - - setEnabled(curve != null); - if (curve != null) { - // _showCurve.setSelected(curve.isVisible()); - _stylePanel.setStyle(curve.getStyle()); - _fitPanel.setFit(curve); - _fitPanel.fitSpecific(curve.getFit().getFitType()); - } - - _fitPanel.reconfigure(curve); - validate(); - _fitPanel.repaint(); - setTextArea(); - } - - /** - * Add the content to the panel - */ - protected void addContent() { - setLayout(new BorderLayout()); - - JPanel sp = getOpaquePanel(); - sp.setLayout(new VerticalFlowLayout()); - addList(sp); - addStyle(sp); - addFit(sp); - - add(sp, BorderLayout.NORTH); - addTextArea(); - } - - // add the curve list - protected void addList(JPanel addPanel) { - - JPanel nPanel = getOpaquePanel(); - nPanel.setLayout(new BorderLayout(0, 4)); - - Collection ycols = _plotCanvas.getDataSet().getAllColumnsByType(DataColumnType.Y); - final DefaultListModel model = new DefaultListModel(); - for (DataColumn dc : ycols) { - model.addElement(dc); - } - - _curveTable = new CurveTable(_plotCanvas); - ListSelectionListener lsl = new ListSelectionListener() { - - @Override - public void valueChanged(ListSelectionEvent e) { - if (!e.getValueIsAdjusting()) { - DataColumn curve = _curveTable.getSelectedCurve(); - // might be null! - - if (curve != null) { - System.err.println("selected curve " + curve.getName()); - } - curveChanged(curve); - } - } - - }; - - _curveTable.getSelectionModel().addListSelectionListener(lsl); - JScrollPane scrollPane = _curveTable.getScrollPane(); - scrollPane.setBorder(new CommonBorder("Curves")); - - nPanel.add(scrollPane, BorderLayout.CENTER); - addPanel.add(nPanel); - } - - /** - * Select the first curve - */ - public void selectFirstCurve() { - if (_curveTable != null) { - try { - _curveTable.getSelectionModel().setSelectionInterval(0, 0); - } - catch (Exception e) { - e.printStackTrace(); - } - } - } - - // add the style editor - private void addStyle(JPanel addPanel) { - _stylePanel = new StyleEditorPanel(_plotCanvas.getDataSet().getType()); - - if (_stylePanel.getSymbolSelector() != null) { - _stylePanel.getSymbolSelector().addActionListener(this); - } - - if (_stylePanel.getBorderSelector() != null) { - _stylePanel.getBorderSelector().addActionListener(this); - } - - if (_stylePanel.getSymbolSizeSelector() != null) { - _stylePanel.getSymbolSizeSelector().addPropertyChangeListener(this); - } - if (_stylePanel.getLineWidthSelector() != null) { - _stylePanel.getLineWidthSelector().addPropertyChangeListener(this); - } - - IColorChangeListener iccl = new IColorChangeListener() { - - @Override - public void colorChanged(Component component, Color color) { - DataColumn curve = _curveTable.getSelectedCurve(); - if (curve != null) { - - if (component == _stylePanel.getSymbolColor()) { - curve.getStyle().setFillColor(_stylePanel.getSymbolColor().getColor()); - } - else if (component == _stylePanel.getBorderColor()) { - curve.getStyle().setBorderColor(_stylePanel.getBorderColor().getColor()); - } - else if (component == _stylePanel.getFitLineColor()) { - curve.getStyle().setFitLineColor(_stylePanel.getFitLineColor().getColor()); - } - _plotCanvas.repaint(); - } - - } - - }; - - if (_stylePanel.getSymbolColor() != null) { - _stylePanel.getSymbolColor().setColorListener(iccl); - } - if (_stylePanel.getBorderColor() != null) { - _stylePanel.getBorderColor().setColorListener(iccl); - } - if (_stylePanel.getFitLineColor() != null) { - _stylePanel.getFitLineColor().setColorListener(iccl); - } - - _stylePanel.setEnabled(false); - addPanel.add(_stylePanel); - } - - // add the fit editor - private void addFit(JPanel addPanel) { - _fitPanel = new FitEditorPanel(); - _fitPanel.setEnabled(false); - _fitPanel.getPolynomialOrderSelector().addPropertyChangeListener(this); - _fitPanel.getNumGaussianSelector().addPropertyChangeListener(this); - _fitPanel.getNumRMSCheckBox().addPropertyChangeListener(this); - _fitPanel.getStatErrorCheckBox().addPropertyChangeListener(this); - - _fitPanel.getFitSelector().addActionListener(this); - - addPanel.add(_fitPanel); - } - - // add th text area - private void addTextArea() { - - _textArea = new JEditorPane(); - _textArea.setEditable(false); - _textArea.setContentType("text/html"); - - if (Environment.getInstance().isLinux()) { - _textArea.setText("CNU sPlot"); - } - else { - _textArea.setText("CNU sPlot"); - } - JScrollPane scrollPane = new JScrollPane(_textArea); - scrollPane.setBorder(new CommonBorder("Fit Parameters")); - - Dimension d = scrollPane.getPreferredSize(); - d.height = 350; - scrollPane.setPreferredSize(d); - add(scrollPane, BorderLayout.CENTER); - } - - // put the text in the text area - private void setTextArea() { - _textArea.setText(""); - DataColumn curve = _curveTable.getSelectedCurve(); - if (curve != null) { - _textArea.setText(curve.getFit().getFitString(curve)); - } - } - - @Override - public void actionPerformed(ActionEvent e) { - - DataColumn curve = _curveTable.getSelectedCurve(); - if (curve == null) { - return; - } - - Object source = e.getSource(); - if (source == _stylePanel.getSymbolSelector()) { - EnumComboBox ecb = (EnumComboBox) source; - SymbolType stype = SymbolType.getValue((String) ecb.getSelectedItem()); - - if (curve.getStyle().getSymbolType() != stype) { - curve.getStyle().setSymbolType(stype); - _plotCanvas.repaint(); - } - - } - else if (source == _stylePanel.getBorderSelector()) { - EnumComboBox ecb = (EnumComboBox) source; - LineStyle lineStyle = LineStyle.getValue((String) ecb.getSelectedItem()); - - if (curve.getStyle().getFitLineStyle() != lineStyle) { - curve.getStyle().setFitLineStyle(lineStyle); - _plotCanvas.repaint(); - } - - } - else if (source == _fitPanel.getFitSelector()) { - EnumComboBox ecb = (EnumComboBox) source; - FitType fitType = FitType.getValue((String) ecb.getSelectedItem()); - - if (curve.getFit().getFitType() != fitType) { - curve.getFit().setFitType(fitType); - _fitPanel.fitSpecific(curve.getFit().getFitType()); - - _fitPanel.reconfigure(curve); - validate(); - _fitPanel.repaint(); - _plotCanvas.repaint(); - } - - } - - } - - /** - * The canvas or a widget has fired a property change. This is used as a simple - * notification mechanism. - */ - @Override - public void propertyChange(PropertyChangeEvent evt) { - - if (PlotCanvas.DONEDRAWINGPROP.equals(evt.getPropertyName())) { - setTextArea(); - return; - } - else if (PlotCanvas.DATACLEAREDPROP.equals(evt.getPropertyName())) { - // all plot data cleared - _curveTable.clear(); - return; - } - - // all other props rely on having a non null curve - DataColumn curve = _curveTable.getSelectedCurve(); - if (curve == null) { - return; - } - - if (StyleEditorPanel.SYMBOLSIZEPROP.equals(evt.getPropertyName())) { - int ssize = (Integer) evt.getNewValue(); - IStyled style = curve.getStyle(); - if (style.getSymbolSize() != ssize) { - style.setSymbolSize(ssize); - _plotCanvas.repaint(); - } - } - - if (StyleEditorPanel.LINEWIDTHPROP.equals(evt.getPropertyName())) { - int lwidth = (Integer) evt.getNewValue(); - float fwidth = (lwidth / 2.f); - IStyled style = curve.getStyle(); - System.err.println("Setting line width to: " + fwidth); - if (style.getFitLineWidth() != fwidth) { - style.setFitLineWidth(fwidth); - _plotCanvas.repaint(); - } - } - - else if (FitEditorPanel.POLYNOMIALORDERPROP.equals(evt.getPropertyName())) { - int porder = (Integer) evt.getNewValue(); - Fit fit = curve.getFit(); - if (fit.getPolynomialOrder() != porder) { - fit.setPolynomialOrder(porder); - _plotCanvas.repaint(); - } - } - - else if (FitEditorPanel.GAUSSIANNUMPROP.equals(evt.getPropertyName())) { - int ngauss = (Integer) evt.getNewValue(); - Fit fit = curve.getFit(); - if (fit.getNumGaussian() != ngauss) { - fit.setNumGaussian(ngauss); - _plotCanvas.repaint(); - } - } - - else if (FitEditorPanel.USERMSPROP.equals(evt.getPropertyName())) { - boolean useRMS = (Boolean) evt.getNewValue(); - HistoData hd = curve.getHistoData(); - hd.setRmsInHistoLegend(useRMS); - _plotCanvas.repaint(); - } - - else if (FitEditorPanel.STATERRPROP.equals(evt.getPropertyName())) { - boolean statErr = (Boolean) evt.getNewValue(); - HistoData hd = curve.getHistoData(); - hd.setDrawStatisticalErrors(statErr); - _plotCanvas.repaint(); - } - - } - - private JPanel getOpaquePanel() { - JPanel panel = new JPanel(); - Environment.getInstance().commonize(panel, null); - return panel; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/CurveTable.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/CurveTable.java deleted file mode 100644 index 9229d31ddc..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/CurveTable.java +++ /dev/null @@ -1,206 +0,0 @@ -package cnuphys.splot.edit; - -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontMetrics; -import java.util.Vector; - -import javax.swing.DefaultCellEditor; -import javax.swing.JCheckBox; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.ListSelectionModel; -import javax.swing.event.CellEditorListener; -import javax.swing.event.ChangeEvent; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableColumn; - -import cnuphys.splot.pdata.DataColumn; -import cnuphys.splot.pdata.DataColumnType; -import cnuphys.splot.plot.Environment; -import cnuphys.splot.plot.PlotCanvas; - -public class CurveTable extends JTable { - - private DefaultTableCellRenderer def_renderer = new DefaultTableCellRenderer(); - - private PlotCanvas _canvas; - - // a scroll pane for this table - private JScrollPane _scrollPane; - - protected static Font _listFont = Environment.getInstance().getCommonFont(12); - - private static final Color _unselectedColor = new Color(240, 240, 240); - - /** - * Create a table for toggling visibility (probably of logical layers) - * - * @param plotCanvas the plot - */ - public CurveTable(PlotCanvas plotCanvas) { - super(new CurveDataModel((Vector) plotCanvas.getDataSet().getAllColumnsByType(DataColumnType.Y))); - - _canvas = plotCanvas; - setFont(_listFont); - - setRowHeight(getFontMetrics(_listFont).getHeight() + 6); - getCurveModel().addTableModelListener(this); - // single selection - setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - setCellSelectionEnabled(true); - - // set preferred widths - for (int i = 0; i < getColumnCount(); i++) { - TableColumn column = getColumnModel().getColumn(i); - column.setMinWidth(CurveDataModel.columnWidths[i]); - // column.setPreferredWidth(CurveDataModel.columnWidths[i]); - } - - // don't show vertical line? - showVerticalLines = true; - - // def_renderer.setHorizontalAlignment(SwingConstants.LEFT); - initVisColumn(); - initNameColumn(); - - // no reordering - getTableHeader().setReorderingAllowed(false); - } - - /** - * Get the curve data model - * - * @return the curve data model - */ - public CurveDataModel getCurveModel() { - return (CurveDataModel) getModel(); - } - - /** - * Clear the data - */ - public void clear() { - getCurveModel().clear(); - } - - private void initVisColumn() { - // check box renderer - DefaultTableCellRenderer checkBoxRenderer = new DefaultTableCellRenderer() { - @Override - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, - boolean hasFocus, int row, int column) { - JCheckBox cb = new JCheckBox(); - cb.setSelected((Boolean) value); - // cb.setBackground(Color.white); - return cb; - - } - - }; - - CellEditorListener visListener = new CellEditorListener() { - @Override - public void editingStopped(ChangeEvent e) { - _canvas.repaint(); - } - - @Override - public void editingCanceled(ChangeEvent e) { - } - }; - - // change renderer for value column - JCheckBox cb = new JCheckBox(); - TableColumn column = getColumnModel().getColumn(CurveDataModel.VIS_COLUMN); - column.setCellRenderer(checkBoxRenderer); - column.setCellEditor(new DefaultCellEditor(cb)); - column.getCellEditor().addCellEditorListener(visListener); - - } - - private void initNameColumn() { - // check box renderer - DefaultTableCellRenderer textRenderer = new DefaultTableCellRenderer() { - @Override - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, - boolean hasFocus, int row, int column) { - JTextField jtf = new JTextField((String) value); - jtf.setFont(_listFont); - - boolean rowSelected = table.getSelectedRow() == row; - if (!rowSelected) { - jtf.setBackground(_unselectedColor); - } - else { - jtf.setBackground(Color.yellow); - } - return jtf; - - } - - }; - - CellEditorListener nameListener = new CellEditorListener() { - @Override - public void editingStopped(ChangeEvent e) { - _canvas.repaint(); - } - - @Override - public void editingCanceled(ChangeEvent e) { - } - }; - - JTextField jtf = new JTextField(); - jtf.setBackground(Color.yellow); - jtf.setFont(_listFont); - TableColumn column = getColumnModel().getColumn(CurveDataModel.NAME_COLUMN); - column.setCellRenderer(textRenderer); - column.setCellEditor(new DefaultCellEditor(jtf)); - column.getCellEditor().addCellEditorListener(nameListener); - - } - - /** - * Get the selected curve - * - * @return the selected curve - */ - public DataColumn getSelectedCurve() { - int selectedRow = getSelectedRow(); - return getCurveModel().getCurveAtRow(selectedRow); - } - - /** - * Get the scroll pane for this data table - * - * @return the scroll pane for this data table - */ - public JScrollPane getScrollPane() { - if (_scrollPane == null) { - _scrollPane = new JScrollPane(this); - Environment.getInstance().commonize(_scrollPane, null); - - int totalWidth = 0; - for (int i = 0; i < getColumnCount(); i++) { - TableColumn column = getColumnModel().getColumn(i); - column.setPreferredWidth(CurveDataModel.columnWidths[i]); - totalWidth += CurveDataModel.columnWidths[i]; - } - - Dimension d = _scrollPane.getPreferredSize(); - d.width = totalWidth + 10; - FontMetrics fm = getFontMetrics(_listFont); - int height = (1 + getRowCount()) * (fm.getHeight() + 8) + 30; - d.height = Math.max(80, height); - _scrollPane.setPreferredSize(d); - - } - return _scrollPane; - } - -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/DataEditor.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/DataEditor.java deleted file mode 100644 index dc87dc0f76..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/DataEditor.java +++ /dev/null @@ -1,155 +0,0 @@ -package cnuphys.splot.edit; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.FlowLayout; -import java.awt.Font; - -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; - -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataTable; -import cnuphys.splot.plot.DoubleFormat; -import cnuphys.splot.plot.Environment; -import cnuphys.splot.plot.PlotCanvas; - -public class DataEditor extends SimpleDialog implements TableModelListener { - - // underlying plot canvas - protected PlotCanvas _plotCanvas; - - // button labels - protected static final String APPLY = "Apply"; - protected static final String CLOSE = "Close"; - - // the table - protected DataTable _table; - - // num row and col label - protected JLabel _rowColLabel; - - // range label - protected JLabel _rangeLabel; - - private static Font _font = Environment.getInstance().getCommonFont(12); - - /** - * Edit the plot preferences - * - * @param plotCanvas the plot being edited - */ - public DataEditor(PlotCanvas plotCanvas) { - super("Plot Data", plotCanvas, true, APPLY, CLOSE); - - // note components already created by super constructor - _plotCanvas = plotCanvas; - - addNorth(); - pack(); - setLabels(); - } - - /** - * Get the table - * - * @return the underlying table - */ - public DataTable getTable() { - return _table; - } - - /** - * can do preparation--for example a component might be added on - * "createCenterComponent" but a reference needed in "addNorthComponent" - */ - @Override - protected void prepare() { - _plotCanvas = (PlotCanvas) _userObject; - _table = new DataTable(_plotCanvas.getDataSet()); - _table.getModel().addTableModelListener(this); - } - - /** - * Override to create the component that goes in the center. Usually this is the - * "main" component. - * - * @return the component that is placed in the center - */ - @Override - protected Component createCenterComponent() { - return _table.getScrollPane(); - } - - /** - * A button was hit. The default behavior is to shutdown the dialog. - * - * @param command the label on the button that was hit. - */ - @Override - protected void handleCommand(String command) { - if (CLOSE.equals(command)) { - setVisible(false); - } - else if (APPLY.equals(command)) { - } - } - - protected Component addNorth() { - JPanel npanel = new JPanel(); - npanel.setLayout(new VerticalFlowLayout()); - - JPanel npanel1 = new JPanel(); - npanel1.setLayout(new FlowLayout(FlowLayout.CENTER)); - - JLabel label1 = new JLabel(_plotCanvas.getParameters().getPlotTitle()); - npanel1.add(label1); - - JPanel npanel2 = new JPanel(); - npanel2.setLayout(new FlowLayout(FlowLayout.CENTER)); - - String str2 = "Number of rows: 000" + " Number of columns: 000"; - _rowColLabel = new JLabel(str2); - _rowColLabel.setFont(_font); - npanel2.add(_rowColLabel); - - JPanel npanel3 = new JPanel(); - npanel3.setLayout(new FlowLayout(FlowLayout.CENTER)); - - String str3 = "X Range: [XXXXX.XX, XXXXX.XX]" + " Y Range: [XXXXX.XX, XXXXX.XX]"; - _rangeLabel = new JLabel(str3); - _rangeLabel.setFont(_font); - npanel3.add(_rangeLabel); - - npanel.add(npanel1); - npanel.add(npanel2); - npanel.add(npanel3); - add(npanel, BorderLayout.NORTH); - return npanel; - } - - @Override - public void tableChanged(TableModelEvent e) { - setLabels(); - } - - private void setLabels() { - String str = "Number of rows: " + _table.getModel().getRowCount() + " Number of columns: " - + _table.getModel().getColumnCount(); - _rowColLabel.setText(str); - - DataSet ds = _plotCanvas.getDataSet(); - String xminString = DoubleFormat.doubleFormat(ds.getXmin(), 4, 3); - String xmaxString = DoubleFormat.doubleFormat(ds.getXmax(), 4, 3); - String yminString = DoubleFormat.doubleFormat(ds.getYmin(), 4, 3); - String ymaxString = DoubleFormat.doubleFormat(ds.getYmax(), 4, 3); - - String str2 = String.format("X Range: [%s, %s]" + "   Y Range: [%s, %s]", - xminString, xmaxString, yminString, ymaxString); - - _rangeLabel.setText(str2); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/DialogUtilities.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/DialogUtilities.java deleted file mode 100644 index 22e4fdca0c..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/DialogUtilities.java +++ /dev/null @@ -1,157 +0,0 @@ -package cnuphys.splot.edit; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.FontMetrics; -import javax.swing.Box; -import javax.swing.JDialog; -import javax.swing.JOptionPane; -import javax.swing.JPanel; - -import cnuphys.splot.plot.GraphicsUtilities; -import cnuphys.splot.plot.ImageManager; - -public class DialogUtilities { - - /** - * Dialog "Reason" constant - */ - - public static final int OK_RESPONSE = 0; - - /** - * Dialog "Reason" constant - */ - - public static final int CANCEL_RESPONSE = 1; - - /** - * Current answer string - */ - - protected String outputdata = null; - - /** - * Dialog "Reason" constant - */ - - public static final int APPLY_RESPONSE = 2; - - /** - * Dialog "Reason" constant - */ - - public static final int DONE_RESPONSE = 0; - - /** - * Dialog "Reason" constant - */ - - public static final int YES_RESPONSE = 0; - - /** - * Dialog "Reason" constant - */ - - public static final int NO_RESPONSE = 1; - - /** - * Center a dialog - * - * @param dialog the dialog to center - */ - - public static void centerDialog(JDialog dialog) { - GraphicsUtilities.centerComponent(dialog); - } - - /** - * Convenience routine for padding a string using the default font. - * - * @param inp The string to be padded. - * @param tstr The test string-- try to return a string the same length - */ - - public String padString(Component c, String inp, String tstr) { - - String str; - int oldgap; - int newgap; - - if (inp == null) { - str = new String(""); - } - else { - str = new String(inp); - } - - FontMetrics fm = c.getFontMetrics(c.getFont()); - - int sw = fm.stringWidth(tstr); - oldgap = Math.abs(sw - fm.stringWidth(str)); - - while (true) { - String str2 = str += " "; - newgap = Math.abs(sw - fm.stringWidth(str2)); - if (newgap < oldgap) { - str = str2; - oldgap = newgap; - } - else { - break; - } - } - - return str; - } - - /** - * Create a nice padded panel. - * - * @param hpad the pixel pad on the left and right - * @param vpad the pixel pad on the top and bottom - * @param component the main component placed in the center. - * @return the padded panel - */ - public static JPanel paddedPanel(int hpad, int vpad, Component component) { - JPanel panel = new JPanel(); - panel.setLayout(new BorderLayout()); - - if (hpad > 0) { - panel.add(Box.createHorizontalStrut(hpad), BorderLayout.WEST); - panel.add(Box.createHorizontalStrut(hpad), BorderLayout.EAST); - } - if (hpad > 0) { - panel.add(Box.createVerticalStrut(vpad), BorderLayout.NORTH); - panel.add(Box.createVerticalStrut(vpad), BorderLayout.SOUTH); - } - - panel.add(component, BorderLayout.CENTER); - return panel; - } - - /** - * Create a dialog with a prompt and a set of options - * - * @param prompt - * @param options - * @return a result indicating yes or no. - */ - public static int yesNoDialog(String prompt, String... options) { - - JOptionPane pane = new JOptionPane(prompt); - pane.setIcon(ImageManager.cnuIcon); - - pane.setOptions(options); - JDialog dialog = pane.createDialog(null, "Dialog"); - dialog.setVisible(true); - Object obj = pane.getValue(); - for (int k = 0; k < options.length; k++) { - if (options[k].equals(obj)) { - return k; - } - } - return -1; - } - -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/IColorChangeListener.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/IColorChangeListener.java deleted file mode 100644 index 4146d1a6e1..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/IColorChangeListener.java +++ /dev/null @@ -1,9 +0,0 @@ -package cnuphys.splot.edit; - -import java.awt.Color; -import java.awt.Component; - -public interface IColorChangeListener { - - public void colorChanged(Component component, Color color); -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/OneAxisLimitsPanel.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/OneAxisLimitsPanel.java deleted file mode 100644 index 3cf64c1c31..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/OneAxisLimitsPanel.java +++ /dev/null @@ -1,215 +0,0 @@ -package cnuphys.splot.edit; - -import java.awt.BorderLayout; -import java.awt.FlowLayout; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.text.NumberFormat; - -import javax.swing.JFormattedTextField; -import javax.swing.JLabel; -import javax.swing.JPanel; - -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.plot.LimitsMethod; -import cnuphys.splot.plot.PlotCanvas; -import cnuphys.splot.plot.PlotParameters; -import cnuphys.splot.style.EnumComboBox; - -public class OneAxisLimitsPanel extends JPanel implements ActionListener { - - public enum Axis {X, Y} - - - //the plot canvas - private PlotCanvas _canvas; - - //which axis - private Axis _axis; - - //current method - private LimitsMethod _method1; - - //current manual limits - private double _min1; - private double _max1; - - //the data set - private DataSet _dataSet; - - //current data limits - private double _dataMin; - private double _dataMax; - - //text fields for limits - private JFormattedTextField _minTF; - private JFormattedTextField _maxTF; - - - //the method combo box - private EnumComboBox _methodSelector; - - //plot parameters - private PlotParameters _params; - - - /** - * Edit the axes limits - * @param canvas the plot canvas - * @param axis which axis - */ - public OneAxisLimitsPanel(PlotCanvas canvas, Axis axis) { - _canvas = canvas; - _params = _canvas.getParameters(); - _dataSet = _canvas.getDataSet(); - _axis = axis; - setLayout(new BorderLayout(4, 4)); - - addNorth(); - addCenter(); - fix(); - } - - private void addNorth() { - JPanel p = new JPanel(); - p.setLayout(new FlowLayout(FlowLayout.LEFT, 8, 4)); - JLabel label = null; - - switch (_axis) { - case X: - _method1 = _params.getXLimitsMethod(); - _min1 = _params.getManualXMin(); - _max1 = _params.getManualXMax(); - - _dataMin = _dataSet.getXmin(); - _dataMax = _dataSet.getXmax(); - label = new JLabel("X axis method"); - break; - - case Y: - _method1 = _params.getYLimitsMethod(); - _min1 = _params.getManualYMin(); - _max1 = _params.getManualYMax(); - - _dataMin = _dataSet.getYmin(); - _dataMax = _dataSet.getYmax(); - label = new JLabel("Y axis method"); - break; - } - - double dataDel = 0.05 * (_dataMax - _dataMin); - if (Double.isNaN(_min1)) { - _min1 = _dataMin - dataDel; - } - if (Double.isNaN(_max1)) { - _max1 = _dataMax + dataDel; - } - - addCombo(p); - p.add(label); - add(p, BorderLayout.NORTH); - } - - private void addCenter() { - JPanel p = new JPanel(); - p.setLayout(new GridLayout(2, 1, 4, 4)); - - JPanel spMin = new JPanel(); - spMin.setLayout(new FlowLayout(FlowLayout.LEFT, 8, 4)); - _minTF = createTF(_min1); - spMin.add(_minTF); - spMin.add(new JLabel(_axis.name() + "min (manual)")); - // spMin.add(Box.createHorizontalStrut(8)); - - - JPanel spMax = new JPanel(); - spMax.setLayout(new FlowLayout(FlowLayout.LEFT, 8, 4)); - _maxTF = createTF(_max1); - spMax.add(_maxTF); - spMax.add(new JLabel(_axis.name() + "max (manual)")); - - - p.add(spMin); - p.add(spMax); - add(p, BorderLayout.CENTER); - - } - - private void fix() { - - _minTF.setEnabled(_method1 == LimitsMethod.MANUALLIMITS); - _maxTF.setEnabled(_method1 == LimitsMethod.MANUALLIMITS); - - } - - //add the method combo box - private void addCombo(JPanel p) { - _methodSelector = LimitsMethod.getComboBox(_method1); - _methodSelector.addActionListener(this); - p.add(_methodSelector); - } - - private JFormattedTextField createTF(double defValue) { - NumberFormat numberFormat = NumberFormat.getNumberInstance(); - numberFormat.setMaximumFractionDigits(4); - numberFormat.setGroupingUsed(false); - - JFormattedTextField tf = new JFormattedTextField(numberFormat); - tf.setValue(defValue); - tf.setColumns(8); - - return tf; - - } - - /** apply changes */ - public void apply() { - switch (_axis) { - case X: - _params.setXLimitsMethod(_method1); - - if (_method1 == LimitsMethod.MANUALLIMITS) { - _min1 = getValue(_minTF, _min1); - _max1 = getValue(_maxTF, _max1); - _params.setXRange(_min1, _max1); - } - break; - - case Y: - _params.setYLimitsMethod(_method1); - if (_method1 == LimitsMethod.MANUALLIMITS) { - _min1 = getValue(_minTF, _min1); - _max1 = getValue(_maxTF, _max1); - _params.setYRange(_min1, _max1); - } - break; - } - - } - - private double getValue(JFormattedTextField tf, double v) { - - try { - return Double.parseDouble(tf.getText()); - } - catch (Exception e) { - tf.setText(""+v); - return v; - } - } - - @Override - public void actionPerformed(ActionEvent e) { - - LimitsMethod method = (LimitsMethod) _methodSelector.getSelectedEnum(); - if (method == _method1) { - return; - } - - _method1 = method; - fix(); - } - - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/PlotPreferencesDialog.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/PlotPreferencesDialog.java deleted file mode 100644 index cff3802693..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/PlotPreferencesDialog.java +++ /dev/null @@ -1,92 +0,0 @@ -package cnuphys.splot.edit; - -import java.awt.BorderLayout; -import java.awt.Component; - -import cnuphys.splot.plot.GeneralPlotParamPanel; -import cnuphys.splot.plot.PlotCanvas; - -public class PlotPreferencesDialog extends SimpleDialog { - - protected PlotCanvas _plotCanvas; - - // button labels - protected static final String APPLY = "Apply"; - protected static final String CLOSE = "Close"; - - // plot labels and title - protected GeneralPlotParamPanel _genPanel; - - //axes limits - private AxesLimitsPanel _axesPanel; - - /** - * Edit the plot preferences - * - * @param plotCanvas the plot being edited - */ - public PlotPreferencesDialog(PlotCanvas plotCanvas) { - super("Plot Preferences", plotCanvas, true, APPLY, CLOSE); - - // note components already created by super constructor - _plotCanvas = plotCanvas; - addCenter(); - addNorth(); - pack(); - } - - /** - * can do preparation--for example a component might be added on - * "createCenterComponent" but a reference needed in "addNorthComponent" - */ - @Override - protected void prepare() { - _plotCanvas = (PlotCanvas) _userObject; - } - - /** - * Override to create the component that goes in the center. Usually this is the - * "main" component. - * - * @return the component that is placed in the center - */ - private Component addNorth() { - // _tabbedPane = new JTabbedPane(); - - _genPanel = new GeneralPlotParamPanel(_plotCanvas); - - add(_genPanel, BorderLayout.NORTH); - return _genPanel; - } - - /** - * Override to create the component that goes in the center. Usually this is the - * "main" component. - * - * @return the component that is placed in the center - */ - protected Component addCenter() { - _axesPanel = new AxesLimitsPanel(_plotCanvas); - add(_axesPanel, BorderLayout.CENTER); - return _axesPanel; - } - - /** - * A button was hit. The default behavior is to shutdown the dialog. - * - * @param command the label on the button that was hit. - */ - @Override - protected void handleCommand(String command) { - if (CLOSE.equals(command)) { - setVisible(false); - } - else if (APPLY.equals(command)) { - _genPanel.apply(); - _axesPanel.apply(); - _plotCanvas.setWorldSystem(); - _plotCanvas.repaint(); - } - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/SimpleDialog.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/SimpleDialog.java deleted file mode 100644 index 48611dd47b..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/SimpleDialog.java +++ /dev/null @@ -1,324 +0,0 @@ -package cnuphys.splot.edit; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.Container; -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - -import javax.swing.AbstractButton; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JPanel; - -/** - * A simple dialog template. The dialog is given a Border layout, and component - * creators for the different directions are called. They should be overridden - * to provide actual content. - * - * @author heddle - * - */ -@SuppressWarnings("serial") -public class SimpleDialog extends JDialog implements ActionListener { - - // the components of the dialog - protected Component northComponent; - protected Component southComponent; - protected Component eastComponent; - protected Component westComponent; - protected Component centerComponent; - - // the labels for the closeout buttons - protected String _closeout[]; - - // the reason the dialog closed. - protected String reason; - - // convenient access to south button panel (if exists) - protected JPanel buttonPanel; - - protected Object _userObject; - - /** - * Create a SimpleDialog - * - * @param title the title of the dialog - * @param modal if true the dialog is modal - * @param closeout a set of closeout labels - */ - public SimpleDialog(String title, Object userObject, boolean modal, String... closeout) { - super(); - setTitle(title); - setModal(modal); - _closeout = closeout; - _userObject = userObject; - - // close is like a close - WindowAdapter wa = new WindowAdapter() { - @Override - public void windowClosing(WindowEvent we) { - setVisible(false); - } - }; - addWindowListener(wa); - - setLayout(new BorderLayout(4, 4)); - - // can do preparation--for example a component might be - // added on "createCenterComponent" but a reference needed - // in "addNorthComponent" - prepare(); - - // create the components. The create methods, with the exception - // of south, return null by default - northComponent = createNorthComponent(); - southComponent = createSouthComponent(); - eastComponent = createEastComponent(); - westComponent = createWestComponent(); - centerComponent = createCenterComponent(); - - conditionalAdd(northComponent, BorderLayout.NORTH); - conditionalAdd(southComponent, BorderLayout.SOUTH); - conditionalAdd(eastComponent, BorderLayout.EAST); - conditionalAdd(westComponent, BorderLayout.WEST); - conditionalAdd(centerComponent, BorderLayout.CENTER); - - // add menus - addMenus(); - - sizeDialog(); - DialogUtilities.centerDialog(this); - } - - /** - * Add menus to the dialog. The default implementation does nothing. - */ - protected void addMenus() { - } - - /** - * Check the enabled state of all the buttons. Default implementation does - * nothing. - */ - protected void checkButtons() { - - } - - /** - * This can be overridden to provide the size of the dialog. The default - * implementation is to call pack. - */ - protected void sizeDialog() { - pack(); - } - - /** - * Add a component if the given borderlayout direction as long as it is not - * null. - * - * @param component the component to add (oftent a panel with other components) - * @param direction the BorderLayout direction. - */ - private void conditionalAdd(Component component, String direction) { - if (component != null) { - add(component, direction); - } - } - - /** - * Override to create the component that goes in the north. - * - * @return the component that is placed in the north - */ - protected Component createNorthComponent() { - return null; - } - - /** - * Override to create the component that goes in the south. - * - * @return the component that is placed in the south. The default implementation - * creates a row of closeout buttons. - */ - protected Component createSouthComponent() { - if (_closeout != null) { - buttonPanel = new JPanel(); - buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); - buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); - buttonPanel.add(Box.createHorizontalGlue()); - - int lenm1 = _closeout.length - 1; - for (int index = 0; index <= lenm1; index++) { - JButton button = new JButton(_closeout[index]); - button.addActionListener(this); - buttonPanel.add(button); - if (index != lenm1) { - buttonPanel.add(Box.createRigidArea(new Dimension(10, 0))); - } - } - return buttonPanel; - } - return null; - } - - /** - * Get the first button on this dialog with the given label. This will search - * all buttons, not just the closout buttons, so it is safe only if no more than - * one button has the given label. - * - * @param label the label to search for. - * @return the first button among its components that has the given label, or - * null. - */ - public AbstractButton getButton(String label) { - return getButton(this, label); - } - - // search all children - private AbstractButton getButton(Container container, String label) { - - if (label == null) { - return null; - } - - Component components[] = container.getComponents(); - - for (Component c : components) { - if (c instanceof AbstractButton) { - AbstractButton button = (AbstractButton) c; - String blabel = button.getText(); - if (label.equals(blabel)) { - return button; - } - } - else if (c instanceof Container) { - AbstractButton button = getButton((Container) c, label); - if (button != null) { - return button; - } - } - } - - return null; - } - - /** - * Enable or disable a button with a given label. Assumes no more than one - * button has the given label. - * - * @param label the label to match - * @param enabled the enable flag - */ - public void setButtonEnabled(String label, boolean enabled) { - AbstractButton button = getButton(this, label); - if (button != null) { - button.setEnabled(enabled); - } - } - - /** - * can do preparation--for example a component might be added on - * "createCenterComponent" but a reference needed in "addNorthComponent" - */ - protected void prepare() { - } - - /** - * Override to create the component that goes in the east. - * - * @return the component that is placed in the east - */ - protected Component createEastComponent() { - return null; - } - - /** - * Override to create the component that goes in the west. - * - * @return the component that is placed in the west. - */ - protected Component createWestComponent() { - return null; - } - - /** - * Override to create the component that goes in the center. Usually this is the - * "main" component. - * - * @return the component that is placed in the center - */ - protected Component createCenterComponent() { - return null; - } - - /* - * (non-Javadoc) - * - * @see - * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) - */ - @Override - public void actionPerformed(ActionEvent e) { - reason = e.getActionCommand(); - handleCommand(reason); - checkButtons(); - } - - /** - * Get the reason that the dialog was closed, which is just the label of the - * last button hit. - * - * @return the label of the last button hit. - */ - public String getReason() { - return reason; - } - - /** - * A closeout button was hit. The default behavior is to shutdown the dialog. - * - * @param command the label on the button that was hit. - */ - protected void handleCommand(String command) { - setVisible(false); - } - - /** - * Set the wait cursor - */ - public void waitCursor() { - setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - } - - /** - * Restore the default cursor - */ - public void defaultCursor() { - setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); - } - - public static void main(String arg[]) { - String closeout[] = { "OK", "Apply", "Cancel" }; - SimpleDialog sd = new SimpleDialog("Sample Dialog", null, true, closeout) { - - @Override - public void handleCommand(String command) { - if (!command.equals("Apply")) { - setVisible(false); - } - } - }; - - sd.setVisible(true); - - System.exit(0); - } -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/VerticalFlowLayout.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/VerticalFlowLayout.java deleted file mode 100644 index 34818e5e36..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/edit/VerticalFlowLayout.java +++ /dev/null @@ -1,615 +0,0 @@ -package cnuphys.splot.edit; - -import java.awt.Component; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.Insets; -import java.awt.LayoutManager; -import java.awt.LayoutManager2; -import java.io.Serializable; -import java.util.Enumeration; -import java.util.Vector; - -public class VerticalFlowLayout implements LayoutManager2, Serializable { - - /** - * The center layout constraint. - */ - public static final String CENTER = "Center"; - - /** - * The left layout constraint. - */ - public static final String LEFT = "Left"; - - /** - * The right layout constraint. - */ - public static final String RIGHT = "Right"; - - /** - * The actual components. - */ - private Vector components; - - /** - * Use uniform widths? - */ - private boolean bUniformWidths; - - private int m_vGap; - - private int m_externalPadLeft; - - private int m_externalPadRight; - - private int m_externalPadTop; - - private int m_externalPadBottom; - - private int m_internalPadX; - - private int m_internalPadY; - - private int m_widestWidth; - - private Dimension m_preferredSize; - - private Insets m_insets; - - /** - * Dirty flag, signaling that preferred sizes need to be recalculated because a - * component has been added or removed. - */ - - private boolean m_bDirty = false; - - /** - * This inner class pairs up a component with an alignment value. Each component - * in the VerticalFlowLayout can be aligned to the Left, Center, or Right. - */ - - private class AlignedComponent implements Serializable { - Component m_comp; - - String m_alignment; - - public AlignedComponent(Component comp, String alignment) { - m_comp = comp; - m_alignment = alignment; - } - - public Component getComponent() { - return m_comp; - } - - public String getAlignment() { - return m_alignment; - } - }// class AlignedComponent - - /** - * Constructs a new VerticalFlowLayout. - */ - public VerticalFlowLayout() { - bUniformWidths = true; - m_vGap = 3; - m_externalPadLeft = 0; - m_externalPadRight = 0; - m_externalPadTop = 0; - m_externalPadBottom = 0; - m_internalPadX = 0; - m_internalPadY = 0; - - components = new Vector(); - } - - /** - * Constructs a new VerticalFlowLayout with your own width sizing type and - * vertical gap values. - * - * @param uniformWidths size the widths of the component to be uniform or not - * @param vGap vertical gap - */ - public VerticalFlowLayout(boolean uniformWidths, int vGap) { - bUniformWidths = uniformWidths; - m_vGap = vGap; - - components = new Vector(); - } - - /** - * Adds the specified component to the layout. - * - * @param name this is ignored - * @param comp the component to be added - * @exception IllegalArgumentException Invalid component or constraint. - */ - @Override - public void addLayoutComponent(String name, Component comp) { - // Make sure we have a valid component - if (comp == null) { - // No, not valid - throw new IllegalArgumentException("Cannot add component: component is null."); - } - - // Special case: treat null the same as "Left" - if (name == null || name.length() == 0) { - // D.out ("Assuming Left Layout"); - name = LEFT; - } - - // Make sure we have a valid constraint - if (name.equals(CENTER) || name.equals(LEFT) || name.equals(RIGHT)) { - // Yes, valid - AlignedComponent alcomp = new AlignedComponent(comp, name); - components.add(alcomp); - } - else { - // No, not valid - throw new IllegalArgumentException("Cannot add component: constraint is invalid."); - } - - // This signals the preferredLayoutSize to recalculate based on this - // new addition - m_bDirty = true; - } - - /** - * Remove the specified component. - * - * @param comp the component to be removed - * @exception IllegalArgumentException Invalid component. - */ - @Override - public void removeLayoutComponent(Component comp) { - if (comp != null) { - Enumeration enumer = components.elements(); - - if (enumer != null) { - while (enumer.hasMoreElements()) { - // Get the component/alignment pair - AlignedComponent alcomp = enumer.nextElement(); - - // Pull just the component out and see if there's a match - Component currComp = alcomp.getComponent(); - if (comp == currComp) { - // Found the component, get rid of it - components.remove(alcomp); - - // This signals the preferredLayoutSize to recalculate - // based - // on this deletion - m_bDirty = true; - break; - } - } - } - } - else { - throw new IllegalArgumentException("Cannot remove component: component is null."); - } - } - - /** - * Gets the minimum dimensions needed to lay out the component contained in the - * specified target container. - * - * @param parent the Container on which to do the layout - * @see Container - * @see #preferredLayoutSize - * @return minimum layout size - */ - @Override - public Dimension minimumLayoutSize(Container parent) { - return parent.getSize(); - } - - /** - * Gets the preferred dimensions for this layout given the components in the - * specified target container. - *

- * - * @param parent the Container on which to do the layout - * @see Container - * @see #minimumLayoutSize - * @return preferred preferred layout size - */ - @Override - public Dimension preferredLayoutSize(Container parent) { - // see if insets/border has changed. If so, recompute - if (m_insets == null || m_insets != parent.getInsets()) { - m_bDirty = true; - } - - // if new components, recalculate preferred size - if (m_preferredSize == null || m_bDirty) { - int height = 0; - m_widestWidth = 0; - m_preferredSize = null; - - // compute size of any border/insets - int xx = 0; - int yy = 0; - - m_insets = parent.getInsets(); - if (m_insets != null) { - xx = m_insets.left + m_insets.right; - yy = m_insets.bottom + m_insets.top; - } - // D.out("Parent container insets: "+insets.toString()); - - // Go through all of the components and add things up - Enumeration enumer = components.elements(); - if (enumer != null) { - while (enumer.hasMoreElements()) { - // Get component/alignment pair - AlignedComponent alcomp = enumer.nextElement(); - - // Pull just the component out - Dimension compSize = alcomp.getComponent().getPreferredSize(); - - int width = compSize.width; - if (width > m_widestWidth) { - // Keep track of the widest component - m_widestWidth = width; - } - - // Add the height, padding, and vertical gap to the - // overall height tally - height += compSize.height + (m_internalPadY * 2) + m_vGap; - } - - // Everything is tallied; now create a new preferred size - // figuring in the external padding. - m_preferredSize = new Dimension( - m_widestWidth + m_externalPadLeft + m_externalPadRight + (m_internalPadX * 2), - height + m_externalPadTop + m_externalPadBottom); - - // add in any insets - m_preferredSize.width += xx; - m_preferredSize.height += yy; - - } - else { - // just set preferred size to size of border. - m_preferredSize = new Dimension(xx, yy); - } - - // Indicate preferred size is valid - m_bDirty = false; - - } // recompute preferred size - - // D.out("Preferred size for "+parent.getName()+": - // "+m_preferredSize.toString()); - return m_preferredSize; - - }// preferredLayoutSize - - /** - * Layout the components within the specified container - * - * @param parent the container that is being layed out - * @see Container - */ - @Override - public void layoutContainer(Container parent) { - int yPos = m_externalPadTop; - int yBot = m_externalPadBottom; - int xPos = m_externalPadLeft; - int xRight = m_externalPadRight; - int compWidth = 0; - int parentWidth = 0; - - // see if insets/border has changed. If so, recompute - if (m_insets == null || m_insets != parent.getInsets()) { - m_bDirty = true; - } - - // get preferred size - if (m_bDirty) { - preferredLayoutSize(parent); - } - - // get parent container's minimum size - Dimension d = parent.getMinimumSize(); - if (d != null) { - parentWidth = d.width; - } - - // adjust starting pos for insets - if (m_insets != null) { - yPos += m_insets.top; - yBot += m_insets.bottom; - xPos += m_insets.left; - xRight += m_insets.right; - } - - // Go through all of the components and place them vertically. - Enumeration enumer = components.elements(); - if (enumer != null) { - while (enumer.hasMoreElements()) { - AlignedComponent alcomp = enumer.nextElement(); - Component comp = alcomp.getComponent(); - String alignment = alcomp.getAlignment(); - - if (comp.isVisible()) { - - // compute height for this component = preferred height + - // 2*internal pady - int height = comp.getPreferredSize().height + (m_internalPadY * 2); - - // compute width for this component + 2*m_internalPadX - if (bUniformWidths == true) { - // get the width of the widest component - compWidth = m_widestWidth + (m_internalPadX * 2); - } - else { - // compute width based on preferred size - compWidth = comp.getPreferredSize().width + (m_internalPadX * 2); - } - - if ((alignment.equals(LEFT)) || (parentWidth == 0) || (compWidth > parentWidth)) { - // left margin - comp.setLocation(xPos, yPos); - } - else if (alignment.equals(RIGHT)) { - // right margin - comp.setLocation(parentWidth - xRight - compWidth, yPos); - } - else { - // centered between margins - int centerPos = xPos + (parentWidth - xPos - xRight) / 2; - comp.setLocation(centerPos - (compWidth / 2), yPos); - } - - comp.setSize(compWidth, height); - - yPos += height + m_vGap; - // D.out("alignment = "+alignment+" height = "+height+" - // width = "+compWidth+" xpos = "+xPos+" ypos = "+yPos); - } - } - } - }// layoutContainer - - /** - * Adds the specified component to the layout, using the specified constraint - * object. - * - * @param comp the component to be added - * @param constraints where/how the component is added to the layout. - */ - @Override - public void addLayoutComponent(Component comp, Object constraints) { - if ((constraints == null) || (constraints instanceof String)) { - addLayoutComponent((String) constraints, comp); - } - else { - throw new IllegalArgumentException("cannot add to layout: constraint must be a string (or null)"); - } - } - - /** - * Returns the maximum size of this component. - * - * @see java.awt.Component#getMinimumSize() - * @see java.awt.Component#getPreferredSize() - * @see LayoutManager - */ - @Override - public Dimension maximumLayoutSize(Container target) { - return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); - } - - /** - * Returns the alignment along the x axis. This specifies how the component - * would like to be aligned relative to other components. The value should be a - * number between 0 and 1 where 0 represents alignment along the origin, 1 is - * aligned the furthest away from the origin, 0.5 is centered, etc. - */ - @Override - public float getLayoutAlignmentX(Container target) { - return 0.5f; - } - - /** - * Returns the alignment along the y axis. This specifies how the component - * would like to be aligned relative to other components. The value should be a - * number between 0 and 1 where 0 represents alignment along the origin, 1 is - * aligned the furthest away from the origin, 0.5 is centered, etc. - */ - @Override - public float getLayoutAlignmentY(Container target) { - return 0.5f; - } - - /** - * Invalidates the layout, indicating that if the layout manager has cached - * information it should be discarded. - */ - @Override - public void invalidateLayout(Container target) { - } - - // ************************************************************************ - // Accessor methods - // ************************************************************************ - - /** - * See if the widths are set to uniform. - * - * @return uniform width flag - */ - public boolean areWidthsUniform() { - return bUniformWidths; - } - - /** - * Get the vertical gap value. - * - * @return vertical gap - */ - public int getVerticalGap() { - return m_vGap; - } - - /** - * Returns the left external horizontal padding. This is the space between the - * widest component in the column and the left edge. - * - * @return Left external horizontal padding. - */ - public int getExternalPadLeft() { - return m_externalPadLeft; - } - - /** - * Returns the right external horizontal padding. This is the space between the - * widest component in the column and the left right edge. - * - * @return Right external horizontal padding. - */ - public int getExternalPadRight() { - return m_externalPadRight; - } - - /** - * Returns the top external vertical padding. This is the space between the top - * component and the top edge. - * - * @return Top external vertical padding. - */ - public int getExternalPadTop() { - return m_externalPadTop; - } - - /** - * Returns the bottom external vertical padding. This is the space between the - * bottom component and the bottom edge. - * - * @return Bottom external vertical padding. - */ - public int getExternalPadBottom() { - return m_externalPadBottom; - } - - /** - * Get the internal horizontal padding. This is a simple way to grow the - * horizontal preferred size of all of the components by a certain amount. It - * works great on buttons, because their preferred size is usually not wide - * enough to look good. - * - * @return internal horizontal padding - */ - public int getInternalPadX() { - return m_internalPadX; - } - - /** - * Get the internal vertical padding. This is a simple way to grow the vertical - * preferred size of all of the components by a certain amount. It works great - * on buttons, because their preferred size is usually too short. - * - * @return internal vertical padding - */ - public int getInternalPadY() { - return m_internalPadY; - } - - /** - * Set the uniform width flag. If you set this to true, the alignment value is - * ignored. - * - * @param uniformWidths - * - */ - public void setUniformWidths(boolean uniformWidths) { - bUniformWidths = uniformWidths; - } - - /** - * Set the vertical gap value. - * - * @param vGap vertical gap - */ - public void setVerticalGap(int vGap) { - m_vGap = vGap; - } - - /** - * Set the left external horizontal padding. This is the space between the - * widest component in the column and the edge. - * - * @param padding the amount of padding in pixels. - */ - public void setExternalPadLeft(int padding) { - m_externalPadLeft = padding; - } - - /** - * Set the right external horizontal padding. This is the space between the - * widest component in the column and the edge. - * - * @param padding the amount of padding in pixels. - */ - public void setExternalPadRight(int padding) { - m_externalPadRight = padding; - } - - /** - * Set the top external vertical padding. This is the space between the top and - * the top edge. - * - * @param padding the amount of padding in pixels. - */ - public void setExternalPadTop(int padding) { - m_externalPadTop = padding; - } - - /** - * Set the bottom external vertical padding. This is the space between the - * bottom and the bottom edge. - * - * @param padding the amount of padding in pixels. - */ - public void setExternalPadBottom(int padding) { - m_externalPadBottom = padding; - } - - /** - * Set the internal horizontal padding. This is a simple way to grow the - * horizontal preferred size of all of the components by a certain amount. It - * works great on buttons, because their preferred size is usually not wide - * enough to look good. - * - * @param padding internal horizontal padding - */ - public void setInternalPadX(int padding) { - m_internalPadX = padding; - } - - /** - * Set the internal vertical padding. This is a simple way to grow the vertical - * preferred size of all of the components by a certain amount. It works great - * on buttons, because their preferred size is usually too short. - * - * @param padding internal vertical padding - */ - public void setInternalPadY(int padding) { - m_internalPadY = padding; - } - -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/.gitignore b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/.gitignore deleted file mode 100644 index 381c7714e2..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/.gitignore +++ /dev/null @@ -1,36 +0,0 @@ -/AExample$1.class -/AExample.class -/APlotDialog.class -/AnotherGaussian$1.class -/AnotherGaussian.class -/ErfTest$1.class -/ErfTest.class -/ErfcTest$1.class -/ErfcTest.class -/Gaussians$1.class -/Gaussians.class -/Grid.class -/GrowingHisto.class -/Histo.class -/LineWithXAndYErrors$1.class -/LineWithXAndYErrors.class -/MemoryUsageDialog.class -/OneXThreeY$1.class -/OneXThreeY.class -/Scatter$1.class -/Scatter.class -/StraightLine$1.class -/StraightLine.class -/StripChart$1.class -/StripChart.class -/TripleGaussian$1.class -/TripleGaussian.class -/TwoHisto.class -/TwoLinesWithErrors$1.class -/TwoLinesWithErrors.class -/Grid$1.class -/Grid$2.class -/Grid$3.class -/GrowingHisto$1.class -/Histo$1.class -/TwoHisto$1.class diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/AExample.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/AExample.java deleted file mode 100644 index f5530ef3fa..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/AExample.java +++ /dev/null @@ -1,106 +0,0 @@ -package cnuphys.splot.example; - -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - -import javax.swing.JFrame; -import javax.swing.JMenuBar; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.plot.Environment; -import cnuphys.splot.plot.GraphicsUtilities; -import cnuphys.splot.plot.PlotCanvas; -import cnuphys.splot.plot.PlotPanel; -import cnuphys.splot.plot.SplotMenus; - -/** - * A template class for plot examples - * - * @author heddle - * - */ -public abstract class AExample extends JFrame { - - // the plot canvas - protected PlotCanvas _canvas; - - // the menus and items - protected SplotMenus _menus; - - public AExample() { - super("sPlot"); - - // Initialize look and feel - GraphicsUtilities.initializeLookAndFeel(); - - System.out.println("Environment: " + Environment.getInstance()); - - // set up what to do if the window is closed - WindowAdapter windowAdapter = new WindowAdapter() { - @Override - public void windowClosing(WindowEvent event) { - System.exit(1); - } - }; - addWindowListener(windowAdapter); - - try { - _canvas = new PlotCanvas(createDataSet(), getPlotTitle(), getXAxisLabel(), getYAxisLabel()); - } - catch (DataSetException e) { - e.printStackTrace(); - return; - } - - // add the menu bar - JMenuBar mb = new JMenuBar(); - setJMenuBar(mb); - _menus = new SplotMenus(_canvas, mb, true); - fillData(); - setPreferences(); - final PlotPanel ppanel = new PlotPanel(_canvas); - - ppanel.setPreferredSize(new Dimension(750, 700)); - - add(ppanel, BorderLayout.CENTER); - - // add a curve panel - addEast(); - pack(); - GraphicsUtilities.centerComponent(this); - } - - /** - * Get the plot canvas - * - * @return the plot canvas - */ - public PlotCanvas getPlotCanvas() { - return _canvas; - } - - // add the east component - private void addEast() { - // _curveEditor = new CurveEditorPanel(_canvas); - // add(_curveEditor, BorderLayout.EAST); - } - - protected abstract DataSet createDataSet() throws DataSetException; - - protected abstract String[] getColumnNames(); - - protected abstract String getXAxisLabel(); - - protected abstract String getYAxisLabel(); - - protected abstract String getPlotTitle(); - - // fill the plot data - public abstract void fillData(); - - // set the preferences - public abstract void setPreferences(); - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/APlotDialog.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/APlotDialog.java deleted file mode 100644 index a2a1d7e9a7..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/APlotDialog.java +++ /dev/null @@ -1,128 +0,0 @@ -package cnuphys.splot.example; - -import java.awt.BorderLayout; -import java.awt.Insets; -import java.util.Properties; - -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JMenuBar; - -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.plot.GraphicsUtilities; -import cnuphys.splot.plot.PlotCanvas; -import cnuphys.splot.plot.PlotPanel; -import cnuphys.splot.plot.SplotMenus; - -public abstract class APlotDialog extends JDialog { - - // the plot canvas - protected PlotCanvas _canvas; - - // the menus and items - protected SplotMenus _menus; - - protected Properties _properties; - - public APlotDialog(JFrame owner, String title, boolean modal, Properties properties) { - super(owner, title, modal); - _properties = properties; - setLayout(new BorderLayout(4, 4)); - - // Initialize look and feel - GraphicsUtilities.initializeLookAndFeel(); - - // System.out.println("Environment: " + Environment.getInstance()); - - try { - - DataSet dataSet = createDataSet(); - String plotTitle = getPlotTitle(); - String xLabel = getXAxisLabel(); - String yLabel = getYAxisLabel(); - _canvas = new PlotCanvas(dataSet, plotTitle, xLabel, yLabel); - } - catch (DataSetException e) { - e.printStackTrace(); - return; - } - - // add the menu bar - JMenuBar mb = new JMenuBar(); - setJMenuBar(mb); - _menus = new SplotMenus(_canvas, mb, true); - fillData(); - setPreferences(); - final PlotPanel ppanel = new PlotPanel(_canvas); - - // ppanel.setPreferredSize(new Dimension(750, 700)); - - add(ppanel, BorderLayout.CENTER); - - // add user compoenents - addNorth(); - addSouth(); - addEast(); - addWest(); - - pack(); - GraphicsUtilities.centerComponent(this); - } - - /** - * Add a north component - */ - protected void addNorth() { - } - - /** - * Add a south component - */ - protected void addSouth() { - } - - /** - * Add an east component - */ - protected void addEast() { - } - - /** - * Add a west component - */ - protected void addWest() { - } - - @Override - public Insets getInsets() { - Insets def = super.getInsets(); - return new Insets(def.top + 2, def.left + 2, def.bottom + 2, def.right + 2); - } - - /** - * Get the plot canvas - * - * @return the plot canvas - */ - public PlotCanvas getPlotCanvas() { - return _canvas; - } - - protected abstract DataSet createDataSet() throws DataSetException; - - protected abstract String[] getColumnNames(); - - protected abstract String getXAxisLabel(); - - protected abstract String getYAxisLabel(); - - protected abstract String getPlotTitle(); - - // fill the plot data - public abstract void fillData(); - - // set the preferences - public abstract void setPreferences(); - -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/AnotherGaussian.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/AnotherGaussian.java deleted file mode 100644 index 01dc6c1929..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/AnotherGaussian.java +++ /dev/null @@ -1,207 +0,0 @@ -package cnuphys.splot.example; - -import java.util.Collection; - -import cnuphys.splot.fit.FitType; -import cnuphys.splot.pdata.DataColumn; -import cnuphys.splot.pdata.DataColumnType; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.DataSetType; - -public class AnotherGaussian extends AExample { - - // static double rawData[] = { - // 0.500000, 0.000000, 0.000000, - // 1.500000, 0.000000, 0.000000, - // 2.500000, 0.000000, 0.000000, - // 3.500000, 0.000000, 0.000000, - // 4.500000, 0.000000, 0.000000, - // 5.500000, 0.000000, 0.000000, - // 6.500000, 0.000000, 0.000000, - // 7.500000, 0.000000, 0.000000, - // 8.500000, 0.000000, 0.000000, - // 9.500000, 0.000000, 0.000000, - // 10.500000, 0.000000, 0.000000, - // 11.500000, 0.000000, 0.000000, - // 12.500000, 0.000000, 0.000000, - // 13.500000, 0.000000, 0.000000, - // 14.500000, 0.000000, 0.000000, - // 15.500000, 0.000000, 0.000000, - // 16.500000, 0.000000, 0.000000, - // 17.500000, 0.000000, 0.000000, - // 18.500000, 0.000000, 0.000000, - // 19.500000, 0.000000, 0.000000, - // 20.500000, 0.000000, 0.000000, - // 21.500000, 0.000000, 0.000000, - // 22.500000, 0.000000, 0.000000, - // 23.500000, 0.000000, 0.000000, - // 24.500000, 0.000000, 0.000000, - // 25.500000, 0.000000, 0.000000, - // 26.500000, 0.000000, 0.000000, - // 27.500000, 0.000000, 0.000000, - // 28.500000, 0.000000, 0.000000, - // 29.500000, 0.000000, 0.000000, - // 30.500000, 0.000000, 0.000000, - // 31.500000, 0.000000, 0.000000, - // 32.500000, 0.000000, 0.000000, - // 33.500000, 0.000000, 0.000000, - // 34.500000, 0.000000, 0.000000, - // 35.500000, 0.000000, 0.000000, - // 36.500000, 0.000000, 0.000000, - // 37.500000, 0.000000, 0.000000, - // 38.500000, 0.000000, 0.000000, - // 39.500000, 0.000000, 0.000000, - // 40.500000, 0.000000, 0.000000, - // 41.500000, 0.000000, 0.000000, - // 42.500000, 0.000000, 0.000000, - // 43.500000, 0.000000, 0.000000, - // 44.500000, 0.000000, 0.000000, - // 45.500000, 0.000000, 0.000000, - // 46.500000, 0.000000, 0.000000, - // 47.500000, 0.000000, 0.000000, - // 48.500000, 0.000000, 0.000000, - // 49.500000, 0.000000, 0.000000, - // 50.500000, 0.000000, 0.000000, - // 51.500000, 0.000000, 0.000000, - // 52.500000, 0.000000, 0.000000, - // 53.500000, 0.000000, 0.000000, - // 54.500000, 0.000000, 0.000000, - // 55.500000, 0.000000, 0.000000, - // 56.500000, 0.000000, 0.000000, - // 57.500000, 0.000000, 0.000000, - // 58.500000, 0.000000, 0.000000, - // 59.500000, 0.000000, 0.000000, - // 60.500000, 0.000000, 0.000000, - // 61.500000, 0.000000, 0.000000, - // 62.500000, 0.000000, 0.000000, - // 63.500000, 0.000000, 0.000000, - // 64.500000, 0.000000, 0.000000, - // 65.500000, 0.000000, 0.000000, - // 66.500000, 0.000000, 0.000000, - // 67.500000, 0.000000, 0.000000, - // 68.500000, 0.000000, 0.000000, - // 69.500000, 0.000000, 0.000000, - // 70.500000, 0.000000, 0.000000, - // 71.500000, 0.000000, 0.000000, - // 72.500000, 0.000000, 0.000000, - // 73.500000, 0.000000, 0.000000, - // 74.500000, 0.000000, 0.000000, - // 75.500000, 0.000000, 0.000000, - // 76.500000, 0.000000, 0.000000, - // 77.500000, 0.000000, 0.000000, - // 78.500000, 0.000000, 0.000000, - // 79.500000, 2.000000, 1.414214, - // 80.500000, 8.000000, 2.828427, - // 81.500000, 6.000000, 2.449490, - // 82.500000, 8.000000, 2.828427, - // 83.500000, 22.000000, 4.690416, - // 84.500000, 28.000000, 5.291503, - // 85.500000, 29.000000, 5.385165, - // 86.500000, 21.000000, 4.582576, - // 87.500000, 4.000000, 2.000000, - // 88.500000, 0.000000, 0.000000, - // 89.500000, 0.000000, 0.000000, - // 90.500000, 0.000000, 0.000000, - // 91.500000, 0.000000, 0.000000, - // 92.500000, 0.000000, 0.000000, - // 93.500000, 0.000000, 0.000000, - // 94.500000, 0.000000, 0.000000, - // 95.500000, 0.000000, 0.000000, - // 96.500000, 0.000000, 0.000000, - // 97.500000, 0.000000, 0.000000, - // 98.500000, 0.000000, 0.000000, - // 99.500000, 0.000000, 0.000000, - // 100.500000, 0.000000, 0.000000, - // 101.500000, 0.000000, 0.000000, - // 102.500000, 0.000000, 0.000000, - // 103.500000, 0.000000, 0.000000, - // 104.500000, 0.000000, 0.000000, - // 105.500000, 0.000000, 0.000000, - // 106.500000, 0.000000, 0.000000, - // 107.500000, 0.000000, 0.000000, - // 108.500000, 0.000000, 0.000000, - // 109.500000, 0.000000, 0.000000 - // }; - - static double rawData[] = { 17200.000000, 0.000000, 0.000000, 17600.000000, 0.000000, 0.000000, 18000.000000, - 0.000000, 0.000000, 18400.000000, 0.000000, 0.000000, 18800.000000, 0.000000, 0.000000, 19200.000000, - 0.000000, 0.000000, 19600.000000, 0.000000, 0.000000, 20000.000000, 0.000000, 0.000000, 20400.000000, - 0.000000, 0.000000, 20800.000000, 0.000000, 0.000000, 21200.000000, 0.000000, 0.000000, 21600.000000, - 0.000000, 0.000000, 22000.000000, 0.000000, 0.000000, 22400.000000, 0.000000, 0.000000, 22800.000000, - 1.000000, 1.000000, 23200.000000, 2.000000, 1.414214, 23600.000000, 7.000000, 2.645751, 24000.000000, - 32.000000, 5.656854, 24400.000000, 33.000000, 5.744563, 24800.000000, 28.000000, 5.291503, 25200.000000, - 20.000000, 4.472136, 25600.000000, 3.000000, 1.732051, 26000.000000, 2.000000, 1.414214, 26400.000000, - 0.000000, 0.000000, 26800.000000, 0.000000, 0.000000, 27200.000000, 0.000000, 0.000000, 27600.000000, - 0.000000, 0.000000, 28000.000000, 0.000000, 0.000000, 28400.000000, 0.000000, 0.000000, 28800.000000, - 0.000000, 0.000000, 29200.000000, 0.000000, 0.000000, 29600.000000, 0.000000, 0.000000, 30000.000000, - 0.000000, 0.000000, 30400.000000, 0.000000, 0.000000, 30800.000000, 0.000000, 0.000000, 31200.000000, - 0.000000, 0.000000, 31600.000000, 0.000000, 0.000000, 32000.000000, 0.000000, 0.000000, 32400.000000, - 0.000000, 0.000000, 32800.000000, 0.000000, 0.000000 }; - - @Override - protected DataSet createDataSet() throws DataSetException { - return new DataSet(DataSetType.XYEXYE, getColumnNames()); - } - - @Override - protected String[] getColumnNames() { - String names[] = { "X", "Y", "E" }; - return names; - } - - @Override - protected String getXAxisLabel() { - return "Channel"; - } - - @Override - protected String getYAxisLabel() { - return "Counts"; - } - - @Override - protected String getPlotTitle() { - return "Fit to Gaussian"; - } - - @Override - public void fillData() { - DataSet ds = _canvas.getDataSet(); - - for (int i = 0; i < rawData.length; i += 3) { - - try { - ds.add(rawData[i], rawData[i + 1], rawData[i + 2]); - } - catch (DataSetException e) { - e.printStackTrace(); - System.exit(1); - } - } - } - - @Override - public void setPreferences() { - DataSet ds = _canvas.getDataSet(); - Collection ycols = ds.getAllColumnsByType(DataColumnType.Y); - for (DataColumn dc : ycols) { - dc.getFit().setFitType(FitType.GAUSSIANS); - dc.getFit().setNumGaussian(1); - } - - } - - public static void main(String arg[]) { - final AnotherGaussian example = new AnotherGaussian(); - - javax.swing.SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - example.setVisible(true); - } - }); - - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/ErfTest.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/ErfTest.java deleted file mode 100644 index 68b991df28..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/ErfTest.java +++ /dev/null @@ -1,113 +0,0 @@ -package cnuphys.splot.example; - -import java.awt.Color; -import java.util.Collection; - -import cnuphys.splot.fit.FitType; -import cnuphys.splot.pdata.DataColumn; -import cnuphys.splot.pdata.DataColumnType; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.DataSetType; -import cnuphys.splot.plot.HorizontalLine; -import cnuphys.splot.plot.PlotParameters; - -public class ErfTest extends AExample { - - public static double _rawdata[] = { 25.0, 1.000900900900901, 0.01733697900764091, 26.0, 1.000900900900901, - 0.01733697900764091, 27.0, 1.000900900900901, 0.01733697900764091, 28.0, 1.000900900900901, - 0.01733697900764091, 29.0, 1.000900900900901, 0.01733697900764091, 30.0, 1.000900900900901, - 0.01733697900764091, 31.0, 1.000900900900901, 0.01733697900764091, 32.0, 1.000900900900901, - 0.01733697900764091, 33.0, 1.000900900900901, 0.01733697900764091, 34.0, 1.000900900900901, - 0.01733697900764091, 35.0, 1.000900900900901, 0.01733697900764091, 36.0, 1.000900900900901, - 0.01733697900764091, 37.0, 1.000900900900901, 0.01733697900764091, 38.0, 1.000900900900901, - 0.01733697900764091, 39.0, 1.000900900900901, 0.01733697900764091, 40.0, 1.000900900900901, - 0.01733697900764091, 41.0, 1.000900900900901, 0.01733697900764091, 42.0, 0.9996996996996997, - 0.017326572656758746, 43.0, 1.0003003003003004, 0.017331776613222914, 44.0, 1.0006006006006005, - 0.017334378005599775, 45.0, 0.9990990990990991, 0.017321367136840526, 46.0, 0.9972972972972973, - 0.017305741182250943, 47.0, 0.9927927927927928, 0.017266614428186246, 48.0, 0.9927927927927928, - 0.017266614428186246, 49.0, 0.9888888888888889, 0.017232632715199488, 50.0, 0.9774774774774775, - 0.017132915105820917, 51.0, 0.9621621621621622, 0.016998164201903792, 52.0, 0.9597597597597598, - 0.016976929759882967, 53.0, 0.9414414414414415, 0.016814135350353657, 54.0, 0.8996996996996997, - 0.016437155775860673, 55.0, 0.8687687687687687, 0.016152136767399645, 56.0, 0.8369369369369369, - 0.015853466923502115, 57.0, 0.7672672672672672, 0.015179281628949083, 58.0, 0.7018018018018019, - 0.014517275633960144, 59.0, 0.6336336336336337, 0.013794215108535558, 60.0, 0.578978978978979, - 0.013185884924985075, 61.0, 0.4921921921921922, 0.01215752701501331, 62.0, 0.4297297297297297, - 0.01135992811974639, 63.0, 0.3483483483483483, 0.010227859679235077, 64.0, 0.26036036036036037, - 0.008842301420021296, 65.0, 0.1990990990990991, 0.007732368282032272, 66.0, 0.15195195195195196, - 0.006755088215736933, 67.0, 0.12252252252252252, 0.006065768731748996, 68.0, 0.09759759759759759, - 0.005413740653849834, 69.0, 0.05795795795795796, 0.004171905101936878, 70.0, 0.04924924924924925, - 0.0038457202627224314, 71.0, 0.030930930930930932, 0.003047715184712378, 72.0, 0.02132132132132132, - 0.002530375307260168, 73.0, 0.014414414414414415, 0.002080541510593246, 74.0, 0.0075075075075075074, - 0.0015015015015015015, 75.0, 0.0045045045045045045, 0.0011630580619241492, 76.0, 0.0036036036036036037, - 0.001040270755296623, 77.0, 0.0015015015015015015, 6.71491885135072E-4, 78.0, 0.0015015015015015015, - 6.71491885135072E-4, 79.0, 9.009009009009009E-4, 5.201353776483115E-4, 80.0, 0, 0, 81.0, 0, 0, 82.0, 0, - 0, }; - - @Override - protected DataSet createDataSet() throws DataSetException { - return new DataSet(DataSetType.XYEXYE, getColumnNames()); - } - - @Override - protected String[] getColumnNames() { - String names[] = { "X", "Y", "E" }; - return names; - } - - @Override - protected String getXAxisLabel() { - return "DAC Threshold"; - } - - @Override - protected String getYAxisLabel() { - return "Occupancy"; - } - - @Override - protected String getPlotTitle() { - return "p4 U1, BCO 128ns, BLR on, low gain, 125 ns, chan 0"; - } - - @Override - public void fillData() { - DataSet ds = _canvas.getDataSet(); - for (int i = 0; i < _rawdata.length - 2; i += 3) { - try { - ds.add(_rawdata[i], _rawdata[i + 1], _rawdata[i + 2]); - } - catch (DataSetException e) { - e.printStackTrace(); - System.exit(1); - } - // ds.add(i, i); - } - } - - @Override - public void setPreferences() { - DataSet ds = _canvas.getDataSet(); - Collection ycols = ds.getAllColumnsByType(DataColumnType.Y); - for (DataColumn dc : ycols) { - dc.getFit().setFitType(FitType.ERF); - } - PlotParameters params = _canvas.getParameters(); - params.addPlotLine(new HorizontalLine(_canvas, 0)); - params.addPlotLine(new HorizontalLine(_canvas, 1)); - params.setLegendDrawing(false); - _canvas.getDataSet().getCurveStyle(0).setFillColor(new Color(0, 0, 240, 128)); - } - - public static void main(String arg[]) { - final ErfTest example = new ErfTest(); - - javax.swing.SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - example.setVisible(true); - } - }); - - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/ErfcTest.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/ErfcTest.java deleted file mode 100644 index 6d15078f2e..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/ErfcTest.java +++ /dev/null @@ -1,113 +0,0 @@ -package cnuphys.splot.example; - -import java.awt.Color; -import java.util.Collection; - -import cnuphys.splot.fit.FitType; -import cnuphys.splot.pdata.DataColumn; -import cnuphys.splot.pdata.DataColumnType; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.DataSetType; -import cnuphys.splot.plot.HorizontalLine; -import cnuphys.splot.plot.PlotParameters; - -public class ErfcTest extends AExample { - - static double _rawdata[] = { 25.0, 1.000900900900901, 0.01733697900764091, 26.0, 1.000900900900901, - 0.01733697900764091, 27.0, 1.000900900900901, 0.01733697900764091, 28.0, 1.000900900900901, - 0.01733697900764091, 29.0, 1.000900900900901, 0.01733697900764091, 30.0, 1.000900900900901, - 0.01733697900764091, 31.0, 1.000900900900901, 0.01733697900764091, 32.0, 1.000900900900901, - 0.01733697900764091, 33.0, 1.000900900900901, 0.01733697900764091, 34.0, 1.000900900900901, - 0.01733697900764091, 35.0, 1.000900900900901, 0.01733697900764091, 36.0, 1.000900900900901, - 0.01733697900764091, 37.0, 1.000900900900901, 0.01733697900764091, 38.0, 1.000900900900901, - 0.01733697900764091, 39.0, 1.000900900900901, 0.01733697900764091, 40.0, 1.000900900900901, - 0.01733697900764091, 41.0, 1.000900900900901, 0.01733697900764091, 42.0, 0.9996996996996997, - 0.017326572656758746, 43.0, 1.0003003003003004, 0.017331776613222914, 44.0, 1.0006006006006005, - 0.017334378005599775, 45.0, 0.9990990990990991, 0.017321367136840526, 46.0, 0.9972972972972973, - 0.017305741182250943, 47.0, 0.9927927927927928, 0.017266614428186246, 48.0, 0.9927927927927928, - 0.017266614428186246, 49.0, 0.9888888888888889, 0.017232632715199488, 50.0, 0.9774774774774775, - 0.017132915105820917, 51.0, 0.9621621621621622, 0.016998164201903792, 52.0, 0.9597597597597598, - 0.016976929759882967, 53.0, 0.9414414414414415, 0.016814135350353657, 54.0, 0.8996996996996997, - 0.016437155775860673, 55.0, 0.8687687687687687, 0.016152136767399645, 56.0, 0.8369369369369369, - 0.015853466923502115, 57.0, 0.7672672672672672, 0.015179281628949083, 58.0, 0.7018018018018019, - 0.014517275633960144, 59.0, 0.6336336336336337, 0.013794215108535558, 60.0, 0.578978978978979, - 0.013185884924985075, 61.0, 0.4921921921921922, 0.01215752701501331, 62.0, 0.4297297297297297, - 0.01135992811974639, 63.0, 0.3483483483483483, 0.010227859679235077, 64.0, 0.26036036036036037, - 0.008842301420021296, 65.0, 0.1990990990990991, 0.007732368282032272, 66.0, 0.15195195195195196, - 0.006755088215736933, 67.0, 0.12252252252252252, 0.006065768731748996, 68.0, 0.09759759759759759, - 0.005413740653849834, 69.0, 0.05795795795795796, 0.004171905101936878, 70.0, 0.04924924924924925, - 0.0038457202627224314, 71.0, 0.030930930930930932, 0.003047715184712378, 72.0, 0.02132132132132132, - 0.002530375307260168, 73.0, 0.014414414414414415, 0.002080541510593246, 74.0, 0.0075075075075075074, - 0.0015015015015015015, 75.0, 0.0045045045045045045, 0.0011630580619241492, 76.0, 0.0036036036036036037, - 0.001040270755296623, 77.0, 0.0015015015015015015, 6.71491885135072E-4, 78.0, 0.0015015015015015015, - 6.71491885135072E-4, 79.0, 9.009009009009009E-4, 5.201353776483115E-4, 80.0, 0, 0, 81.0, 0, 0, 82.0, 0, - 0, }; - - @Override - protected DataSet createDataSet() throws DataSetException { - return new DataSet(DataSetType.XYEXYE, getColumnNames()); - } - - @Override - protected String[] getColumnNames() { - String names[] = { "X", "Y", "E" }; - return names; - } - - @Override - protected String getXAxisLabel() { - return "DAC Threshold"; - } - - @Override - protected String getYAxisLabel() { - return "Occupancy"; - } - - @Override - protected String getPlotTitle() { - return "p4 U1, BCO 128ns, BLR on, low gain, 125 ns, chan 0"; - } - - @Override - public void fillData() { - DataSet ds = _canvas.getDataSet(); - for (int i = 0; i < _rawdata.length - 2; i += 3) { - try { - ds.add(_rawdata[i], _rawdata[i + 1], _rawdata[i + 2]); - } - catch (DataSetException e) { - e.printStackTrace(); - System.exit(1); - } - // ds.add(i, i); - } - } - - @Override - public void setPreferences() { - DataSet ds = _canvas.getDataSet(); - Collection ycols = ds.getAllColumnsByType(DataColumnType.Y); - for (DataColumn dc : ycols) { - dc.getFit().setFitType(FitType.ERFC); - } - PlotParameters params = _canvas.getParameters(); - params.addPlotLine(new HorizontalLine(_canvas, 0)); - params.addPlotLine(new HorizontalLine(_canvas, 1)); - params.setLegendDrawing(false); - _canvas.getDataSet().getCurveStyle(0).setFillColor(new Color(0, 0, 240, 128)); - } - - public static void main(String arg[]) { - final ErfcTest example = new ErfcTest(); - - javax.swing.SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - example.setVisible(true); - } - }); - - } -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/Gaussians.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/Gaussians.java deleted file mode 100644 index 81f461e6c8..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/Gaussians.java +++ /dev/null @@ -1,123 +0,0 @@ -package cnuphys.splot.example; - -import java.util.Collection; - -import cnuphys.splot.fit.FGaussian; -import cnuphys.splot.fit.FitType; -import cnuphys.splot.pdata.DataColumn; -import cnuphys.splot.pdata.DataColumnType; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.DataSetType; -import cnuphys.splot.plot.PlotParameters; - -public class Gaussians extends AExample { - - @Override - protected DataSet createDataSet() throws DataSetException { - return new DataSet(DataSetType.XYEXYE, getColumnNames()); - } - - @Override - protected String[] getColumnNames() { - String names[] = { "X1", "Y1", "E1", "X2", "Y2", "E2", "X3", "Y3", "E3" }; - return names; - } - - @Override - protected String getXAxisLabel() { - return "x data"; - } - - @Override - protected String getYAxisLabel() { - return "y data"; - } - - @Override - protected String getPlotTitle() { - return "Fit to Gaussians"; - } - - @Override - public void fillData() { - - int numCurve = 3; - - double y[] = new double[numCurve]; - double sig[] = new double[numCurve]; - double x[] = new double[numCurve]; - - double a1[] = { 1.0, 1.0, 1.5 }; - double a2[] = { 0.8, 0.9, 1.2, 1.5, 4.0, 0.8 }; - double a3[] = { 0.6, 1.1, 1.5, 1.6, 3.9, 0.7, 1.1, 7.0, 0.6 }; - - FGaussian gauss[] = new FGaussian[numCurve]; - gauss[0] = new FGaussian(a1); - gauss[1] = new FGaussian(a2); - gauss[2] = new FGaussian(a3); - - int num = 50; - double dx = 10.0 / num; - DataSet ds = _canvas.getDataSet(); - - for (int i = 0; i < 40; i++) { - - for (int j = 0; j < numCurve; j++) { - x[j] = i * dx + 0.25 * j * dx; - y[j] = gauss[j].value(x[j]); - sig[j] = 0.25 * Math.random(); - - // add a linear background - if (j == 2) { - y[j] = y[j] + (0.2 + 0.00833 * x[j]); - } - } - - try { - ds.add(x[0], spreadFactor() * y[0], sig[0], x[1], spreadFactor() * y[1], sig[1], x[2], - spreadFactor() * y[2], sig[2]); - } - catch (DataSetException e) { - e.printStackTrace(); - System.exit(1); - } - // ds.add(i, i); - } - } - - // introduce some jitter - private double spreadFactor() { - return (1.0 + 0.05 * Math.random()); - } - - @Override - public void setPreferences() { - DataSet ds = _canvas.getDataSet(); - Collection ycols = ds.getAllColumnsByType(DataColumnType.Y); - for (DataColumn dc : ycols) { - dc.getFit().setFitType(FitType.GAUSSIANS); - } - PlotParameters params = _canvas.getParameters(); - params.mustIncludeXZero(true); - params.mustIncludeYZero(true); - - String extra[] = { "This is an extra string", "This is a longer extra string", - "This is an even longer extra string" }; - params.setExtraStrings(extra); - - } - - public static void main(String arg[]) { - final Gaussians example = new Gaussians(); - - javax.swing.SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - example.setVisible(true); - } - }); - - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/Grid.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/Grid.java deleted file mode 100644 index 9e22a7ef24..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/Grid.java +++ /dev/null @@ -1,504 +0,0 @@ -package cnuphys.splot.example; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Toolkit; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.Collection; - -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; - -import com.nr.ran.Normaldev; - -import cnuphys.splot.fit.FGaussian; -import cnuphys.splot.fit.FitType; -import cnuphys.splot.fit.IValueGetter; -import cnuphys.splot.pdata.DataColumn; -import cnuphys.splot.pdata.DataColumnType; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.DataSetType; -import cnuphys.splot.pdata.HistoData; -import cnuphys.splot.pdata.StripData; -import cnuphys.splot.plot.Environment; -import cnuphys.splot.plot.GraphicsUtilities; -import cnuphys.splot.plot.HorizontalLine; -import cnuphys.splot.plot.LimitsMethod; -import cnuphys.splot.plot.PlotCanvas; -import cnuphys.splot.plot.PlotGrid; -import cnuphys.splot.plot.PlotParameters; -import cnuphys.splot.plot.VerticalLine; -import cnuphys.splot.style.SymbolType; - -@SuppressWarnings("serial") -public class Grid extends JFrame implements IValueGetter { - - private static int NUMPLOTS = 6; - - private PlotGrid _plotGrid; - - private PlotCanvas[] _canvases = new PlotCanvas[NUMPLOTS]; - - private Font _titleFont = Environment.getInstance().getCommonFont(12); - private Font _statusFont = Environment.getInstance().getCommonFont(9); - private Font _axesFont = Environment.getInstance().getCommonFont(10); - private Font _legendFont = Environment.getInstance().getCommonFont(10); - - public Grid() { - - super("sPlot"); - - // Initialize look and feel - GraphicsUtilities.initializeLookAndFeel(); - - System.out.println("Environment: " + Environment.getInstance()); - - // set up what to do if the window is closed - WindowAdapter windowAdapter = new WindowAdapter() { - @Override - public void windowClosing(WindowEvent event) { - System.exit(0); - } - }; - addWindowListener(windowAdapter); - - // add the menu bar - JMenuBar mb = new JMenuBar(); - setJMenuBar(mb); - JMenu fileMenu = new JMenu("File"); - JMenuItem quitItem = new JMenuItem("Quit"); - - ActionListener al = new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - System.exit(0); - } - - }; - quitItem.addActionListener(al); - fileMenu.add(quitItem); - mb.add(fileMenu); - - _plotGrid = new PlotGrid(2, 3); - add(_plotGrid, BorderLayout.CENTER); - - // add some plots - for (int index = 0; index < NUMPLOTS; index++) { - try { - _canvases[index] = new PlotCanvas(createDataSet(index), getPlotTitle(index), getXAxisLabel(index), - getYAxisLabel(index)); - - fillData(_canvases[index], index); - setPreferences(_canvases[index], index); - - _plotGrid.addPlotCanvas(_canvases[index]); - } - catch (DataSetException e) { - e.printStackTrace(); - return; - } - - _canvases[index].setWorldSystem(); - } - - // test -// for (int row = 0; row < 2; row++) { -// for (int col = 0; col < 3; col++) { -// System.out.println("Plot at row: " + row + " col: " + col + " has title: " -// + _plotGrid.getPlotCanvas(row, col).getTitle()); -// } -// } - sizeToScreen(0.85); - } - - /** - * Size and center a JFrame relative to the screen. - * - * @param frame the frame to size. - * @param fractionalSize the fraction desired of the screen--e.g., 0.85 for 85%. - */ - private void sizeToScreen(double fractionalSize) { - Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); - d.width = (int) (fractionalSize * d.width); - d.height = (int) (fractionalSize * d.height); - setSize(d); - } - - //get the dataset based in the plot index - protected DataSet createDataSet(int index) throws DataSetException { - switch (index) { - case 0: - return new DataSet(DataSetType.XYEXYE, getColumnNames(index)); - - case 1: - return new DataSet(DataSetType.XYEEXYEE, getColumnNames(index)); - - case 2: - StripData sd = new StripData("Memory", 25, this, 2000); - return new DataSet(sd, "time", "Memory Usage (MB)"); - - case 3: - return new DataSet(DataSetType.XYEXYE, getColumnNames(index)); - - case 4: - HistoData h1 = new HistoData("Histo 1", 0.0, 100.0, 50); - HistoData h2 = new HistoData("Histo 2", 0.0, 150.0, 50); - return new DataSet(h1, h2); - - case 5: - return new DataSet(DataSetType.XYXY, getColumnNames(index)); - - } - - return null; - } - - //get the column names based on plot index - protected String[] getColumnNames(int index) { - switch (index) { - case 0: - String names0[] = { "X", "Y", "E" }; - return names0; - - case 1: - String names1[] = { "X", "Y", "Xerr", "Yerr" }; - return names1; - - case 2: - break; - - case 3: - String names3[] = { "X1", "Y1", "E1", "X2", "Y2", "E2", "X3", "Y3", "E3" }; - return names3; - - case 4: - break; - - case 5: - String names5[] = { "X", "Y" }; - return names5; - - } - - return null; - } - - //get the x axis label based on plot index - protected String getXAxisLabel(int index) { - switch (index) { - case 0: - return "DAC Threshold"; - - case 1: - return "x data XM2"; - - case 2: - return "Time (s)"; - - case 3: - return "x data"; - - case 4: - return "some measured value"; - - case 5: - return "X Data"; - - } - - return null; - } - - - //get the y axis label based on index - protected String getYAxisLabel(int index) { - switch (index) { - case 0: - return "Occupancy"; - - case 1: - return "y data YQ2"; - - case 2: - return "Heap Memory (MB)"; - - case 3: - return "y data"; - - case 4: - return "Counts"; - - case 5: - return "Y Data"; - - } - - return null; - } - - //get the plot title based on index - protected String getPlotTitle(int index) { - switch (index) { - case 0: - return "p4 U1, BCO 128ns, BLR on, low gain, 125 ns, chan 0"; - - case 1: - return "Line with X and Y errors"; - - case 2: - return "Sample Strip Chart"; - - case 3: - return "Fit to Gaussians"; - - case 4: - return "Sample 1D Histograms"; - - case 5: - return "Scatter Plot"; - - } - - return null; - } - - // fill the plot data based on index - public void fillData(PlotCanvas canvas, int index) { - - DataSet ds = canvas.getDataSet(); - - switch (index) { - case 0: - for (int i = 0; i < ErfTest._rawdata.length - 2; i += 3) { - try { - double x = ErfTest._rawdata[i]; - double y = ErfTest._rawdata[i+1]; - double e = ErfTest._rawdata[i+2]; - // System.out.println("Plot [" + index + "] (x, y, e) = (" + x + ", " + y + ", " + e + ")"); - ds.add(x, y, e); - } - catch (DataSetException e) { - e.printStackTrace(); - System.exit(1); - } - // ds.add(i, i); - } - break; - - case 1: - for (int i = 0; i < LineWithXAndYErrors.x.length; i++) { - try { - ds.add(LineWithXAndYErrors.x[i], LineWithXAndYErrors.y[i], LineWithXAndYErrors.xSig[i], - LineWithXAndYErrors.ySig[i]); - } - catch (DataSetException e) { - e.printStackTrace(); - } - } - break; - - case 2: - break; - - case 3: - - int numCurve = 3; - - double y[] = new double[numCurve]; - double sig[] = new double[numCurve]; - double x[] = new double[numCurve]; - - double a1[] = { 1.0, 1.0, 1.5 }; - double a2[] = { 0.8, 0.9, 1.2, 1.5, 4.0, 0.8 }; - double a3[] = { 0.6, 1.1, 1.5, 1.6, 3.9, 0.7, 1.1, 7.0, 0.6 }; - - FGaussian gauss[] = new FGaussian[numCurve]; - gauss[0] = new FGaussian(a1); - gauss[1] = new FGaussian(a2); - gauss[2] = new FGaussian(a3); - - int num = 50; - double dx = 10.0 / num; - - for (int i = 0; i < 40; i++) { - - for (int j = 0; j < numCurve; j++) { - x[j] = i * dx + 0.25 * j * dx; - y[j] = gauss[j].value(x[j]); - sig[j] = 0.25 * Math.random(); - - // add a linear background - if (j == 2) { - y[j] = y[j] + (0.2 + 0.00833 * x[j]); - } - } - - try { - ds.add(x[0], spreadFactor() * y[0], sig[0], x[1], spreadFactor() * y[1], sig[1], x[2], - spreadFactor() * y[2], sig[2]); - } - catch (DataSetException e) { - e.printStackTrace(); - System.exit(1); - } - } - break; - - case 4: - int n = 10000; - Normaldev normDev1; - double mu = 50.0; - double ssig = 10.0; - int seed = 33557799; - normDev1 = new Normaldev(mu, ssig, seed); - - Normaldev normDev2; - mu = 100.0; - ssig = 20.0; - normDev2 = new Normaldev(mu, ssig, seed); - - for (int i = 0; i < n; i++) { - double y1 = normDev1.dev(); - double y2 = normDev2.dev(); - try { - ds.add(y1, y2); - } - catch (DataSetException e) { - e.printStackTrace(); - } - } - break; - - case 5: - for (int i = 0; i < 1000; i++) { - // demo that the data can be added out of order - double xx = -0.5 + Math.random(); - double yy = xx + 0.2 * (Math.random() - 0.5); - - try { - ds.add(xx, yy); - } - catch (DataSetException e) { - e.printStackTrace(); - } - } - break; - - } - - } - - // set the preferences - public void setPreferences(PlotCanvas canvas, int index) { - - DataSet ds = canvas.getDataSet(); - PlotParameters params = canvas.getParameters(); - - params.setTitleFont(_titleFont); - params.setAxesFont(_axesFont); - params.setStatusFont(_statusFont); - params.setStatusFont(_legendFont); - params.setLegendLineLength(40); - - switch (index) { - case 0: - Collection ycols = ds.getAllColumnsByType(DataColumnType.Y); - for (DataColumn dc : ycols) { - dc.getFit().setFitType(FitType.ERF); - } - params.addPlotLine(new HorizontalLine(canvas, 0)); - params.addPlotLine(new HorizontalLine(canvas, 1)); - params.setLegendDrawing(false); - canvas.getDataSet().getCurveStyle(0).setFillColor(new Color(0, 0, 240, 128)); - break; - - case 1: - break; - - case 2: - ds.getCurveStyle(0).setBorderColor(Color.red); - ds.getCurveStyle(0).setFitLineColor(Color.red); - ds.getCurveStyle(0).setFillColor(new Color(128, 0, 0, 48)); - ds.getCurveStyle(0).setSymbolType(SymbolType.NOSYMBOL); - params.setMinExponentY(6); - params.setNumDecimalY(0); - params.setXLimitsMethod(LimitsMethod.USEDATALIMITS); - params.mustIncludeYZero(true); - break; - - case 3: - ycols = ds.getAllColumnsByType(DataColumnType.Y); - for (DataColumn dc : ycols) { - dc.getFit().setFitType(FitType.GAUSSIANS); - } - params.mustIncludeXZero(true); - params.mustIncludeYZero(true); - break; - - case 4: - ds.getCurveStyle(0).setFillColor(new Color(196, 196, 196, 64)); - ds.getCurveStyle(0).setBorderColor(Color.black); - ds.getCurveStyle(0).setBorderColor(Color.black); - ds.getCurve(0).getFit().setFitType(FitType.GAUSSIANS); - - ds.getCurveStyle(1).setFillColor(new Color(196, 196, 196, 64)); - ds.getCurveStyle(1).setBorderColor(Color.red); - ds.getCurve(1).getFit().setFitType(FitType.GAUSSIANS); - - params.setMinExponentY(6); - params.setNumDecimalY(0); - break; - - case 5: - Color fillColor = new Color(255, 0, 0, 96); - ycols = ds.getAllColumnsByType(DataColumnType.Y); - - for (DataColumn dc : ycols) { - dc.getFit().setFitType(FitType.NOLINE); - dc.getStyle().setSymbolType(SymbolType.CIRCLE); - dc.getStyle().setSymbolSize(4); - dc.getStyle().setFillColor(fillColor); - dc.getStyle().setBorderColor(null); - } - - // many options controlled via plot parameters - params.mustIncludeXZero(true); - params.mustIncludeYZero(true); - params.addPlotLine(new HorizontalLine(canvas, 0)); - params.addPlotLine(new VerticalLine(canvas, 0)); - break; - - } - } - - // introduce some jitter - private double spreadFactor() { - return (1.0 + 0.05 * Math.random()); - } - - @Override - public double value(double x) { - return 10000 * Math.random(); - } - - public static void main(String arg[]) { - final Grid example = new Grid(); - - javax.swing.SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - example.setVisible(true); - } - }); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/GrowingHisto.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/GrowingHisto.java deleted file mode 100644 index afdbe4941e..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/GrowingHisto.java +++ /dev/null @@ -1,95 +0,0 @@ -package cnuphys.splot.example; - -import java.awt.Color; - -import cnuphys.splot.fit.FitType; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.HistoData; -import cnuphys.splot.plot.PlotParameters; - -import com.nr.ran.Normaldev; - -public class GrowingHisto extends AExample { - - @Override - protected DataSet createDataSet() throws DataSetException { - HistoData h1 = new HistoData("Histo 1", 0.0, 100.0, 50); - return new DataSet(h1); - } - - @Override - protected String[] getColumnNames() { - return null; - } - - @Override - protected String getXAxisLabel() { - return "some measured value"; - } - - @Override - protected String getYAxisLabel() { - return "Counts"; - } - - @Override - protected String getPlotTitle() { - return "Sample 1D Histogram"; - } - - @Override - public void fillData() { - } - - @Override - public void setPreferences() { - DataSet ds = _canvas.getDataSet(); - ds.getCurveStyle(0).setFillColor(new Color(196, 196, 196, 64)); - ds.getCurveStyle(0).setFitLineColor(Color.black); - ds.getCurve(0).getFit().setFitType(FitType.GAUSSIANS); - PlotParameters params = _canvas.getParameters(); - params.setMinExponentY(6); - params.setNumDecimalY(0); - } - - public static void main(String arg[]) { - final GrowingHisto example = new GrowingHisto(); - - javax.swing.SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - example.setVisible(true); - } - }); - - System.err.println("Ready..."); - - int n = 10000; - Normaldev normDev; - double mu = 50.0; - double sig = 10.0; - int seed = 33557799; - normDev = new Normaldev(mu, sig, seed); - - final DataSet ds = example.getPlotCanvas().getDataSet(); - - while (true) { - try { - double y = normDev.dev(); - try { - ds.add(y); - example.getPlotCanvas().needsRedraw(true); - } - catch (DataSetException e) { - e.printStackTrace(); - } - Thread.sleep(250); - } - catch (InterruptedException e) { - e.printStackTrace(); - } - } - - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/Histo.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/Histo.java deleted file mode 100644 index ba0bdb61c7..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/Histo.java +++ /dev/null @@ -1,87 +0,0 @@ -package cnuphys.splot.example; - -import java.awt.Color; - -import com.nr.ran.Normaldev; - -import cnuphys.splot.fit.FitType; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.HistoData; -import cnuphys.splot.plot.PlotParameters; - -public class Histo extends AExample { - - @Override - protected DataSet createDataSet() throws DataSetException { - HistoData h1 = new HistoData("Histo 1", 0.0, 100.0, 50); - return new DataSet(h1); - } - - @Override - protected String[] getColumnNames() { - return null; - } - - @Override - protected String getXAxisLabel() { - return "some measured value"; - } - - @Override - protected String getYAxisLabel() { - return "Counts"; - } - - @Override - protected String getPlotTitle() { - return "Sample 1D Histogram"; - } - - @Override - public void fillData() { - int n = 10000; - Normaldev normDev; - double mu = 50.0; - double sig = 10.0; - int seed = 33557799; - normDev = new Normaldev(mu, sig, seed); - - DataSet ds = _canvas.getDataSet(); - for (int i = 0; i < n; i++) { - double y = normDev.dev(); - try { - ds.add(y); - } - catch (DataSetException e) { - e.printStackTrace(); - } - } - } - - @Override - public void setPreferences() { - DataSet ds = _canvas.getDataSet(); - ds.getCurveStyle(0).setFillColor(new Color(196, 196, 196, 64)); - ds.getCurveStyle(0).setBorderColor(Color.black); - ds.getCurve(0).getFit().setFitType(FitType.GAUSSIANS); - PlotParameters params = _canvas.getParameters(); - params.setMinExponentY(6); - params.setNumDecimalY(0); - - // test gradient - params.setGradientDrawing(true); - } - - public static void main(String arg[]) { - final Histo example = new Histo(); - - javax.swing.SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - example.setVisible(true); - } - }); - - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/Histo2D.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/Histo2D.java deleted file mode 100644 index 4694937e29..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/Histo2D.java +++ /dev/null @@ -1,93 +0,0 @@ -package cnuphys.splot.example; - -import com.nr.ran.Normaldev; - -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.Histo2DData; -import cnuphys.splot.plot.PlotParameters; - -public class Histo2D extends AExample { - @Override - protected DataSet createDataSet() throws DataSetException { - Histo2DData h1 = new Histo2DData("Histo 2D Example", "X variable", "Y variable", 0.0, 100.0, 80, 0.0, 50.0, 60); - return new DataSet(h1); - } - - @Override - protected String[] getColumnNames() { - return null; - } - - @Override - protected String getXAxisLabel() { - return null; - } - - @Override - protected String getYAxisLabel() { - return null; - } - - @Override - protected String getPlotTitle() { - return "2D Histogram"; - } - - @Override - public void fillData() { - int n = 1000000; - double mu = 50.0; - double sig = 20.0; - int seed = 33557799; - Normaldev normDevX = new Normaldev(mu, sig, seed); - - mu = 35; - seed = 777555; - Normaldev normDevY = new Normaldev(mu, sig, seed); - - DataSet ds = _canvas.getDataSet(); - for (int i = 0; i < n; i++) { - double x = normDevX.dev(); - double y = normDevY.dev(); -// System.err.print("X, Y: " + x + ", " + y); - try { - ds.add(x, y); - } - catch (DataSetException e) { - e.printStackTrace(); - } - } - } - - @Override - public void setPreferences() { - PlotParameters params = _canvas.getParameters(); - - Histo2DData h2d = _canvas.getDataSet().getColumn(0).getHistoData2D(); - - params.setMinExponentY(6); - params.setNumDecimalY(0); - - params.setPlotTitle(h2d.getName()); - params.setXLabel(h2d.getXName()); - params.setYLabel(h2d.getYName()); - - params.setXRange(h2d.getMinX(), h2d.getMaxX()); - params.setYRange(h2d.getMinY(), h2d.getMaxY()); - params.setLegendDrawing(false); - params.setGradientDrawing(true); - } - - public static void main(String arg[]) { - final Histo2D example = new Histo2D(); - - javax.swing.SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - example.setVisible(true); - } - }); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/LineWithXAndYErrors.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/LineWithXAndYErrors.java deleted file mode 100644 index a5b7a9b5b9..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/LineWithXAndYErrors.java +++ /dev/null @@ -1,69 +0,0 @@ -package cnuphys.splot.example; - -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.DataSetType; - -public class LineWithXAndYErrors extends AExample { - - public static double x[] = { 3, 4, 5 }; - public static double y[] = { 228.380525, 303.564738, 379.971954 }; - public static double xSig[] = { 0.07, 0.08, 0.09 }; - public static double ySig[] = { 0.218365, 0.227791, 0.222510 }; - - @Override - protected DataSet createDataSet() throws DataSetException { - return new DataSet(DataSetType.XYEEXYEE, getColumnNames()); - } - - @Override - protected String[] getColumnNames() { - String names[] = { "X", "Y", "Xerr", "Yerr" }; - return names; - } - - @Override - protected String getXAxisLabel() { - return "x data XM2"; - } - - @Override - protected String getYAxisLabel() { - return "y data YQ2"; - } - - @Override - protected String getPlotTitle() { - return "Line with X and Y errors"; - } - - @Override - public void fillData() { - DataSet ds = _canvas.getDataSet(); - for (int i = 0; i < x.length; i++) { - try { - ds.add(x[i], y[i], xSig[i], ySig[i]); - } - catch (DataSetException e) { - e.printStackTrace(); - } - } - } - - @Override - public void setPreferences() { - } - - public static void main(String arg[]) { - final LineWithXAndYErrors example = new LineWithXAndYErrors(); - - javax.swing.SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - example.setVisible(true); - } - }); - - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/MemoryUsageDialog.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/MemoryUsageDialog.java deleted file mode 100644 index b870af1363..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/MemoryUsageDialog.java +++ /dev/null @@ -1,82 +0,0 @@ -package cnuphys.splot.example; - -import java.awt.Color; -import java.awt.Font; - -import javax.swing.JFrame; - -import cnuphys.splot.fit.IValueGetter; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.StripData; -import cnuphys.splot.plot.Environment; -import cnuphys.splot.plot.LimitsMethod; -import cnuphys.splot.plot.PlotParameters; -import cnuphys.splot.style.SymbolType; - -public class MemoryUsageDialog extends APlotDialog implements IValueGetter { - - private static Font _titleFont = Environment.getInstance().getCommonFont(12); - private static Font _statusFont = Environment.getInstance().getCommonFont(9); - private static Font _axesFont = Environment.getInstance().getCommonFont(10); - private static Font _legendFont = Environment.getInstance().getCommonFont(10); - - public MemoryUsageDialog(JFrame owner) { - super(owner, "Memory Usage", false, null); - setSize(500, 400); - } - - @Override - protected DataSet createDataSet() throws DataSetException { - StripData sd = new StripData("Memory", 25, this, 2000); - return new DataSet(sd, "time", "Memory Usage (MB)"); - } - - @Override - protected String[] getColumnNames() { - return null; - } - - @Override - protected String getXAxisLabel() { - return "Time (s)"; - } - - @Override - protected String getYAxisLabel() { - return "Memory (MB)"; - } - - @Override - protected String getPlotTitle() { - return "Memory Usage (MB)"; - } - - @Override - public void fillData() { - } - - @Override - public void setPreferences() { - DataSet ds = _canvas.getDataSet(); - ds.getCurveStyle(0).setBorderColor(Color.red); - ds.getCurveStyle(0).setFillColor(new Color(128, 0, 0, 48)); - ds.getCurveStyle(0).setSymbolType(SymbolType.NOSYMBOL); - PlotParameters params = _canvas.getParameters(); - params.setTitleFont(_titleFont); - params.setAxesFont(_axesFont); - params.setStatusFont(_statusFont); - params.setStatusFont(_legendFont); - params.setMinExponentY(3); - params.setNumDecimalY(0); - params.setXLimitsMethod(LimitsMethod.USEDATALIMITS); - params.mustIncludeYZero(true); - } - - @Override - public double value(double x) { - // memory in mb - return (Runtime.getRuntime().totalMemory()) / 1048576.; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/OneXThreeY.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/OneXThreeY.java deleted file mode 100644 index 77f109c265..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/OneXThreeY.java +++ /dev/null @@ -1,86 +0,0 @@ -package cnuphys.splot.example; - -import java.util.Collection; - -import cnuphys.splot.fit.FitType; -import cnuphys.splot.pdata.DataColumn; -import cnuphys.splot.pdata.DataColumnType; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.DataSetType; -import cnuphys.splot.plot.PlotParameters; - -public class OneXThreeY extends AExample { - - @Override - protected DataSet createDataSet() throws DataSetException { - return new DataSet(DataSetType.XYY, getColumnNames()); - } - - @Override - protected String[] getColumnNames() { - String names[] = { "X", "Y1", "Y2", "Y3" }; - return names; - } - - @Override - protected String getXAxisLabel() { - return "Shared X Data"; - } - - @Override - protected String getYAxisLabel() { - return "Three Y's Sharing X"; - } - - @Override - protected String getPlotTitle() { - return "Shared X Data"; - } - - @Override - public void fillData() { - DataSet ds = _canvas.getDataSet(); - for (int i = 0; i < 100; i++) { - // demo that the data can be added out of order - double x = Math.random(); - - try { - ds.add(x, x, x * x, x * x * x); - } - catch (DataSetException e) { - e.printStackTrace(); - } - } - } - - @Override - public void setPreferences() { - DataSet ds = _canvas.getDataSet(); - Collection ycols = ds.getAllColumnsByType(DataColumnType.Y); - - int order = 1; - for (DataColumn dc : ycols) { - dc.getFit().setFitType(FitType.POLYNOMIAL); - dc.getFit().setPolynomialOrder(order++); - } - - // many options controlled via plot parameters - PlotParameters params = _canvas.getParameters(); - params.mustIncludeXZero(true); - params.mustIncludeYZero(true); - } - - public static void main(String arg[]) { - final OneXThreeY example = new OneXThreeY(); - - javax.swing.SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - example.setVisible(true); - } - }); - - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/Scatter.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/Scatter.java deleted file mode 100644 index 8b2bd50b01..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/Scatter.java +++ /dev/null @@ -1,99 +0,0 @@ -package cnuphys.splot.example; - -import java.awt.Color; -import java.util.Collection; - -import cnuphys.splot.fit.FitType; -import cnuphys.splot.pdata.DataColumn; -import cnuphys.splot.pdata.DataColumnType; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.DataSetType; -import cnuphys.splot.plot.HorizontalLine; -import cnuphys.splot.plot.PlotParameters; -import cnuphys.splot.plot.VerticalLine; -import cnuphys.splot.style.SymbolType; - -public class Scatter extends AExample { - - @Override - protected DataSet createDataSet() throws DataSetException { - return new DataSet(DataSetType.XYXY, getColumnNames()); - } - - @Override - protected String[] getColumnNames() { - String names[] = { "X", "Y" }; - return names; - } - - @Override - protected String getYAxisLabel() { - return "Y Data"; - } - - @Override - protected String getPlotTitle() { - return "Scatter Plot"; - } - - @Override - protected String getXAxisLabel() { - return "X Data"; - } - - @Override - public void fillData() { - DataSet ds = _canvas.getDataSet(); - for (int i = 0; i < 1000; i++) { - // demo that the data can be added out of order - double x = -0.5 + Math.random(); - double y = x + 0.2 * (Math.random() - 0.5); - - try { - ds.add(x, y); - } - catch (DataSetException e) { - e.printStackTrace(); - } - } - } - - @Override - public void setPreferences() { - Color fillColor = new Color(255, 0, 0, 96); - DataSet ds = _canvas.getDataSet(); - Collection ycols = ds.getAllColumnsByType(DataColumnType.Y); - - for (DataColumn dc : ycols) { - dc.getFit().setFitType(FitType.LINE); - dc.getStyle().setSymbolType(SymbolType.CIRCLE); - dc.getStyle().setSymbolSize(4); - dc.getStyle().setFillColor(fillColor); - dc.getStyle().setBorderColor(null); - dc.getStyle().setFitLineColor(Color.black); - dc.getStyle().setFitLineWidth(2.0f); - } - - // many options controlled via plot parameters - PlotParameters params = _canvas.getParameters(); - params.mustIncludeXZero(true); - params.mustIncludeYZero(true); - params.addPlotLine(new HorizontalLine(_canvas, 0)); - params.addPlotLine(new VerticalLine(_canvas, 0)); - params.setLegendDrawing(true); - } - - public static void main(String arg[]) { - final Scatter example = new Scatter(); - - javax.swing.SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - example.setVisible(true); - } - }); - - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/StraightLine.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/StraightLine.java deleted file mode 100644 index 08b7645e63..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/StraightLine.java +++ /dev/null @@ -1,68 +0,0 @@ -package cnuphys.splot.example; - -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.DataSetType; - -public class StraightLine extends AExample { - - static double x[] = { 3, 4, 5 }; - static double y[] = { 238.065830, 323.394672, 409.656607 }; - static double sig[] = { 0.085087, 0.086192, 0.087027 }; - - @Override - protected DataSet createDataSet() throws DataSetException { - return new DataSet(DataSetType.XYEXYE, getColumnNames()); - } - - @Override - protected String[] getColumnNames() { - String names[] = { "X1", "Y1", "E1" }; - return names; - } - - @Override - protected String getXAxisLabel() { - return "x data XM2"; - } - - @Override - protected String getYAxisLabel() { - return "y data YQ2"; - } - - @Override - protected String getPlotTitle() { - return "Sample Plot X2 vs. Q2"; - } - - @Override - public void fillData() { - DataSet ds = _canvas.getDataSet(); - for (int i = 0; i < x.length; i++) { - try { - ds.add(x[i], y[i], sig[i]); - } - catch (DataSetException e) { - e.printStackTrace(); - } - } - } - - @Override - public void setPreferences() { - } - - public static void main(String arg[]) { - final StraightLine example = new StraightLine(); - - javax.swing.SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - example.setVisible(true); - } - }); - - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/StripChart.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/StripChart.java deleted file mode 100644 index db2b99705d..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/StripChart.java +++ /dev/null @@ -1,75 +0,0 @@ -package cnuphys.splot.example; - -import java.awt.Color; - -import cnuphys.splot.fit.IValueGetter; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.StripData; -import cnuphys.splot.plot.LimitsMethod; -import cnuphys.splot.plot.PlotParameters; -import cnuphys.splot.style.SymbolType; - -public class StripChart extends AExample implements IValueGetter { - - @Override - protected DataSet createDataSet() throws DataSetException { - StripData sd = new StripData("Memory", 25, this, 2000); - return new DataSet(sd, "time", "Memory Usage (MB)"); - } - - @Override - protected String[] getColumnNames() { - return null; - } - - @Override - protected String getXAxisLabel() { - return "Time (s)"; - } - - @Override - protected String getYAxisLabel() { - return "Heap Memory (MB)"; - } - - @Override - protected String getPlotTitle() { - return "Sample Strip Chart"; - } - - @Override - public void fillData() { - } - - @Override - public void setPreferences() { - DataSet ds = _canvas.getDataSet(); - ds.getCurveStyle(0).setFitLineColor(Color.red); - ds.getCurveStyle(0).setFillColor(new Color(128, 0, 0, 48)); - ds.getCurveStyle(0).setSymbolType(SymbolType.NOSYMBOL); - PlotParameters params = _canvas.getParameters(); - params.setMinExponentY(6); - params.setNumDecimalY(2); - params.setXLimitsMethod(LimitsMethod.USEDATALIMITS); - params.mustIncludeYZero(true); - } - - @Override - public double value(double x) { - return 10000 * Math.random(); - } - - public static void main(String arg[]) { - final StripChart example = new StripChart(); - - javax.swing.SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - example.setVisible(true); - } - }); - - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/TripleGaussian.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/TripleGaussian.java deleted file mode 100644 index f36a2a904a..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/TripleGaussian.java +++ /dev/null @@ -1,103 +0,0 @@ -package cnuphys.splot.example; - -import java.util.Collection; - -import cnuphys.splot.fit.FGaussian; -import cnuphys.splot.fit.FitType; -import cnuphys.splot.pdata.DataColumn; -import cnuphys.splot.pdata.DataColumnType; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.DataSetType; -import cnuphys.splot.plot.HorizontalLine; -import cnuphys.splot.plot.PlotParameters; -import cnuphys.splot.plot.VerticalLine; - -public class TripleGaussian extends AExample { - - @Override - protected DataSet createDataSet() throws DataSetException { - return new DataSet(DataSetType.XYEXYE, getColumnNames()); - } - - @Override - protected String[] getColumnNames() { - String names[] = { "X", "Y", "E" }; - return names; - } - - @Override - protected String getXAxisLabel() { - return "x data"; - } - - @Override - protected String getYAxisLabel() { - return "y data"; - } - - @Override - protected String getPlotTitle() { - return "Fit to Gaussians"; - } - - @Override - public void fillData() { - - double aa[] = { 0.6, 1.1, 1.5, 1.6, 3.9, 0.7, 1.1, 7.0, 0.6 }; - - FGaussian gauss = new FGaussian(aa); - - int num = 50; - double dx = 10.0 / num; - DataSet ds = _canvas.getDataSet(); - - for (int i = 0; i < 50; i++) { - - double x = i * dx; - double y = gauss.value(x); - double sig = 0.25 * Math.random(); - - try { - ds.add(x, -spreadFactor() * y, sig); - } - catch (DataSetException e) { - e.printStackTrace(); - System.exit(1); - } - // ds.add(i, i); - } - } - - private double spreadFactor() { - return (1.0 + 0.05 * Math.random()); - } - - @Override - public void setPreferences() { - DataSet ds = _canvas.getDataSet(); - Collection ycols = ds.getAllColumnsByType(DataColumnType.Y); - for (DataColumn dc : ycols) { - dc.getFit().setFitType(FitType.GAUSSIANS); - dc.getFit().setNumGaussian(3); - } - - // many options controlled via plot parameters - PlotParameters params = _canvas.getParameters(); - params.addPlotLine(new HorizontalLine(_canvas, 0)); - params.addPlotLine(new VerticalLine(_canvas, 0)); - } - - public static void main(String arg[]) { - final TripleGaussian example = new TripleGaussian(); - - javax.swing.SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - example.setVisible(true); - } - }); - - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/TwoHisto.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/TwoHisto.java deleted file mode 100644 index 7a3a7ab129..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/TwoHisto.java +++ /dev/null @@ -1,97 +0,0 @@ -package cnuphys.splot.example; - -import java.awt.Color; - -import cnuphys.splot.fit.FitType; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.HistoData; -import cnuphys.splot.plot.PlotParameters; - -import com.nr.ran.Normaldev; - -public class TwoHisto extends AExample { - - @Override - protected DataSet createDataSet() throws DataSetException { - HistoData h1 = new HistoData("Histo 1", 0.0, 100.0, 50); - HistoData h2 = new HistoData("Histo 2", 0.0, 150.0, 50); - return new DataSet(h1, h2); - } - - @Override - protected String[] getColumnNames() { - return null; - } - - @Override - protected String getXAxisLabel() { - return "some measured value"; - } - - @Override - protected String getYAxisLabel() { - return "Counts"; - } - - @Override - protected String getPlotTitle() { - return "Sample 1D Histograms"; - } - - @Override - public void fillData() { - int n = 10000; - Normaldev normDev1; - double mu = 50.0; - double sig = 10.0; - int seed = 33557799; - normDev1 = new Normaldev(mu, sig, seed); - - Normaldev normDev2; - mu = 100.0; - sig = 20.0; - normDev2 = new Normaldev(mu, sig, seed); - - DataSet ds = _canvas.getDataSet(); - for (int i = 0; i < n; i++) { - double y1 = normDev1.dev(); - double y2 = normDev2.dev(); - try { - ds.add(y1, y2); - } - catch (DataSetException e) { - e.printStackTrace(); - } - } - } - - @Override - public void setPreferences() { - DataSet ds = _canvas.getDataSet(); - - ds.getCurveStyle(0).setFillColor(new Color(196, 196, 196, 64)); - ds.getCurveStyle(0).setBorderColor(Color.black); - ds.getCurve(0).getFit().setFitType(FitType.GAUSSIANS); - - ds.getCurveStyle(1).setFillColor(new Color(196, 196, 196, 64)); - ds.getCurveStyle(1).setBorderColor(Color.red); - ds.getCurve(1).getFit().setFitType(FitType.GAUSSIANS); - - PlotParameters params = _canvas.getParameters(); - params.setMinExponentY(6); - params.setNumDecimalY(0); - } - - public static void main(String arg[]) { - final TwoHisto example = new TwoHisto(); - - javax.swing.SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - example.setVisible(true); - } - }); - - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/TwoLinesWithErrors.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/TwoLinesWithErrors.java deleted file mode 100644 index 9a0bae7631..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/example/TwoLinesWithErrors.java +++ /dev/null @@ -1,88 +0,0 @@ -package cnuphys.splot.example; - -import java.util.Collection; - -import cnuphys.splot.fit.FitType; -import cnuphys.splot.pdata.DataColumn; -import cnuphys.splot.pdata.DataColumnType; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.DataSetType; -import cnuphys.splot.plot.PlotParameters; - -public class TwoLinesWithErrors extends AExample { - - @Override - protected DataSet createDataSet() throws DataSetException { - return new DataSet(DataSetType.XYEXYE, getColumnNames()); - } - - @Override - protected String[] getColumnNames() { - String names[] = { "X1", "Y1", "E1", "X2", "Y2", "E2" }; - return names; - } - - @Override - protected String getXAxisLabel() { - return "x data XM2"; - } - - @Override - protected String getYAxisLabel() { - return "y data YQ2"; - } - - @Override - protected String getPlotTitle() { - return "Sample Plot X2 vs. Q2"; - } - - @Override - public void fillData() { - DataSet ds = _canvas.getDataSet(); - for (int i = 0; i < 15; i++) { - try { - if (i < 10) { - ds.add(i, i + 2 * Math.random(), 2.0 * Math.random(), i + 0.5, 10 - i + 2 * Math.random(), - 2.0 * Math.random()); - } - else { - ds.add(i, i + 2 * Math.random(), 2.0 * Math.random()); - } - } - catch (DataSetException e) { - e.printStackTrace(); - System.exit(1); - } - // ds.add(i, i); - } - } - - @Override - public void setPreferences() { - DataSet ds = _canvas.getDataSet(); - Collection ycols = ds.getAllColumnsByType(DataColumnType.Y); - for (DataColumn dc : ycols) { - dc.getFit().setFitType(FitType.POLYNOMIAL); - } - - // many options controlled via plot parameters - PlotParameters params = _canvas.getParameters(); - params.mustIncludeXZero(true); - params.mustIncludeYZero(true); - } - - public static void main(String arg[]) { - final TwoLinesWithErrors example = new TwoLinesWithErrors(); - - javax.swing.SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - example.setVisible(true); - } - }); - - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/.gitignore b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/.gitignore deleted file mode 100644 index b3a616fed4..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/.gitignore +++ /dev/null @@ -1,35 +0,0 @@ -/ANonlinearFit.class -/AltPolynomialFit.class -/CubicSpline.class -/ErfFit.class -/ErfcFit.class -/FErf.class -/FErfc.class -/FGaussPoly.class -/FGaussian.class -/FPoly.class -/Fit$ErrorType.class -/Fit.class -/FitEditorPanel$1.class -/FitEditorPanel$2.class -/FitEditorPanel$3.class -/FitEditorPanel$4.class -/FitEditorPanel$5.class -/FitEditorPanel.class -/FitHold.class -/FitType.class -/FitUtilities$1.class -/FitUtilities.class -/GaussianFit.class -/IValueGetter.class -/LineFit.class -/LinearExyFit.class -/PolyAndGaussianFit.class -/PolyFit.class -/Polynomial.class -/CubicSpline$1.class -/CubicSpline$2.class -/CubicSpline$3.class -/PolyFit$1.class -/Polynomial$1.class -/Polynomial$2.class diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/ANonlinearFit.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/ANonlinearFit.java deleted file mode 100644 index 21a6adcdaa..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/ANonlinearFit.java +++ /dev/null @@ -1,87 +0,0 @@ -package cnuphys.splot.fit; - -import org.netlib.util.doubleW; - -import com.nr.model.Fitmrq; -import com.nr.model.MultiFuncd; - -public abstract class ANonlinearFit implements IValueGetter { - - // the underlying Numerical Recipe nonlinear fitter - private Fitmrq _fitmrq; - - // the user supplied fitting function - private MultiFuncd _func; - - /** - * Create a Error function Fit - * - * @param fit the fit data - */ - public ANonlinearFit(Fit fit) throws IllegalArgumentException { - - _func = getFunc(); - _fitmrq = new Fitmrq(fit.getX(), fit.getY(), fit.getSigmaY(), initialGuess(fit), _func, fit.getTolerance()); - - // set any holds - for (FitHold fh : fit.getHolds()) { - _fitmrq.hold(fh.index, fh.value); - } - - // call for the actual fit - _fitmrq.fit(); - - // cache the fit - fit.setFit(this); - } - - /** - * Get the fit parameters - * - * @return the fit parameters - */ - public double[] getFitParameters() { - return _fitmrq.a; - } - - /** - * Get the covariance matrix - * - * @return the covariance matrix - */ - public double[][] getCovarianceMatrix() { - return _fitmrq.covar; - } - - /** - * Get the chi square of the fit - * - * @return the chi square - */ - public double getChiSquare() { - return _fitmrq.chisq; - } - - /** - * This method is an "after the fact" evaluator. After the fit is complete is - * should be able to use the resulting fit parameters to simply evaluate the - * function at a given x. The default implementation uses the fitting function - * _func. This is good in that it guarantees consistency, but the fitting - * function also computes the derivatives so there is an inefficiency. NOTE: - * this function is NOT used by the fitting process. It is only for convenience, - * afterward, such as in plotting. - */ - @Override - public double value(double x) { - final doubleW y = new doubleW(0); - final double a[] = getFitParameters(); - final double dyda[] = new double[a.length]; - _func.funk(x, a, y, dyda); - return y.val; - } - - protected abstract double[] initialGuess(Fit fit); - - protected abstract MultiFuncd getFunc(); - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/AltPolynomialFit.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/AltPolynomialFit.java deleted file mode 100644 index afe6d8a706..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/AltPolynomialFit.java +++ /dev/null @@ -1,72 +0,0 @@ -package cnuphys.splot.fit; - -import com.nr.model.Fitmrq; - -public class AltPolynomialFit extends Fitmrq implements IValueGetter { - - /** - * Create an alternate polynomial fit that uses the nonlinear fitter rather than - * generalized least squares. - * - * @param fit the fit data - */ - public AltPolynomialFit(Fit fit) { - super(fit.getX(), fit.getY(), fit.getSigmaY(), initialGuess(fit), createFPoly(fit.getPolynomialOrder() + 1), - fit.getTolerance()); - - // set holds, then fit - for (FitHold fh : fit.getHolds()) { - hold(fh.index, fh.value); - } - try { - fit(); - fit.setFit(this); - } - catch (IllegalArgumentException e) { - System.err.println("Alt Polynomial fit failed."); - e.printStackTrace(); - } - } - - private static double[] initialGuess(Fit fit) { - int n = fit.getPolynomialOrder() + 1; - double aa[] = new double[n]; - for (int i = 0; i < n; i++) { - aa[i] = 1.0; - } - - return aa; - } - - // public void funk(final double x, final double[]a, final doubleW y, final - // double[] dyda){ - - @Override - public double value(double x) { - - double y = 0.; - int numPoly = a.length; - - // now the poly - if (numPoly > 0) { - - double[] p = new double[numPoly]; - p[0] = 1.0; - for (int j = 1; j < numPoly; j++) { - p[j] = p[j - 1] * x; - } - - for (int i = 0; i < numPoly; i++) { - y += a[i] * p[i]; - } - } - - return y; - } - - public static FPoly createFPoly(final int numPoly) { - FPoly fpoly = new FPoly(numPoly); - return fpoly; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/CubicSpline.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/CubicSpline.java deleted file mode 100644 index 7a49c78e6a..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/CubicSpline.java +++ /dev/null @@ -1,161 +0,0 @@ -package cnuphys.splot.fit; - -import java.awt.Point; -import java.util.Arrays; -import java.util.Comparator; - -import org.netlib.util.doubleW; - -import com.nr.UniVarRealValueFun; -import com.nr.fe.Dfridr; -import com.nr.interp.Spline_interp; -import com.nr.root.Roots; -import com.nr.root.Roots.Zbrak; - -public class CubicSpline implements IValueGetter { - - private Spline_interp _nrspline; - - double _x[]; - double _y[]; - - public CubicSpline(final double x[], final double y[]) { - _x = x; - _y = y; - _nrspline = new Spline_interp(x, y); - } - - @Override - public double value(double x) { - return _nrspline.interp(x); - } - - /** - * Obtain cubic spline for the derivative by numeric differentiation - * - * @return - */ - public CubicSpline derivative() { - int n = _x.length; - final double h = (_x[n - 1] - _x[0]) / 20; - - final UniVarRealValueFun func = new UniVarRealValueFun() { - - @Override - public double funk(double x) { - return value(x); - } - - }; - - final doubleW err = new doubleW(0); - - final double deriv[] = new double[n]; - for (int i = 0; i < n; i++) { - final double x = _x[i]; - deriv[i] = Dfridr.dfridr(func, _x[i], h, err); - } - - return new CubicSpline(_x, deriv); - } - - /** - * Find the roots of the polynomial in a range - * - * @param xmin the min value of the range - * @param xmax the max value of the range - * @return an array of roots, or null - */ - public double[] findRoots(double xmin, double xmax) { - - UniVarRealValueFun fx = new UniVarRealValueFun() { - - @Override - public double funk(double x) { - return value(x); - } - - }; - - Zbrak zb = new Zbrak(); - zb.zbrak(fx, xmin, xmax, 100); - - double roots[] = null; - if (zb.nroot > 0) { - roots = new double[zb.nroot]; - for (int i = 0; i < zb.nroot; i++) { - double x1 = zb.xb1[i]; - double x2 = zb.xb2[i]; - roots[i] = Roots.rtsec(fx, x1, x2, 1.0e-6); - } - } - return roots; - } - - /** - * Find the xy values of the maxima of the interpolated function in a given - * range - * - * @param xmin the min value of the range - * @param xmax the max value of the range - * @return and array of xy values, or null - */ - public Point.Double[] findXValsOfMaxima(double xmin, double xmax) { - - // find zeroes of derivatives - CubicSpline firstDeriv = derivative(); - double roots[] = firstDeriv.findRoots(xmin, xmax); - if (roots == null) { - return null; - } - - // get second deriv - CubicSpline secondDeriv = firstDeriv.derivative(); - // count maxim - int count = 0; - for (double x : roots) { - if (secondDeriv.value(x) < 0.) { - count++; - } - } - - if (count < 1) { - return null; - } - - double xvals[] = new double[count]; - int ncount = 0; - for (double x : roots) { - if (secondDeriv.value(x) < 0.) { - xvals[ncount] = x; - ncount++; - if (ncount == count) { - break; - } - } - } - - Point.Double results[] = new Point.Double[count]; - - for (int i = 0; i < count; i++) { - results[i] = new Point.Double(); - results[i].x = xvals[i]; - results[i].y = value(xvals[i]); - } - - if (count > 1) { - Comparator comp = new Comparator() { - - @Override - public int compare(java.awt.geom.Point2D.Double p0, java.awt.geom.Point2D.Double p1) { - return Double.compare(p1.y, p0.y); - } - - }; - Arrays.sort(results, comp); - } - - return results; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/ErfFit.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/ErfFit.java deleted file mode 100644 index d4dfce36bc..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/ErfFit.java +++ /dev/null @@ -1,181 +0,0 @@ -package cnuphys.splot.fit; - -//import org.apache.commons.math3.special.Erf; -import com.nr.model.Fitmrq; -import com.nr.sf.Erf; - -/** - * For fitting a single error function to a curve (DataColumn) - * - * @author heddle - * - */ -public class ErfFit extends Fitmrq implements IValueGetter { - - // function that evaluates the Erf - private static FErf _funcs = new FErf(); - private static Erf _erf = new Erf(); - - /** - * Create a Error function Fit and perform the fit - * - * @param fit the fit data - */ - public ErfFit(Fit fit) throws IllegalArgumentException { - super(fit.getX(), fit.getY(), fit.getSigmaY(), initialGuess(fit), _funcs, fit.getTolerance()); - - fit.setFitType(FitType.ERF); - // set holds, then fit - for (FitHold fh : fit.getHolds()) { - hold(fh.index, fh.value); - } - fit(); - fit.setFit(this); - } - - /** - * A method to generate an initial guess - * - * @param fit the fit data - * @return initial guess - */ - public static double[] initialGuess(Fit fit) { - - double xx[] = fit.getX(); - double yy[] = fit.getY(); - - double result[] = FitUtilities.stats(yy); - double aa[] = new double[4]; - - double mean = result[0]; - aa[0] = mean; - double delY = result[2] - result[1]; - aa[1] = (yy[yy.length - 1] - yy[0]) / 2; // half the deltaY - - // find the x that produces a y - double varmin = Double.POSITIVE_INFINITY; - int iimag = 0; - for (int i = 0; i < (yy.length - 1); i++) { - double var = (0.5) * (yy[i] + yy[i]); - var = Math.abs(var - mean); - if (var < varmin) { - varmin = var; - iimag = i; - } - } - - aa[2] = xx[iimag]; - - // now try to estimate the spread - int imin = iimag; - int imax = iimag; - - double fact = 0.25 * delY; - for (int i = iimag; i >= 0; i--) { - if (Math.abs(yy[i] - mean) > fact) { - imin = i; - break; - } - } - for (int i = iimag; i < yy.length; i++) { - if (Math.abs(yy[i] - mean) > fact) { - imax = i; - break; - } - } - - if (imin == imax) { - if (imin > 0) { - imin--; - } - else if (imax < (yy.length - 1)) { - imax++; - } - } - - double spread = Math.abs(xx[imax] - xx[imin]); - aa[3] = spread; - - return aa; - } - - // /** - // * A method to generate an initial guess - // * @param xx the x data - // * @param yy the y data - // * @return initial guess - // */ - // public static double[] initialGuess2(double xx[], double yy[]) { - // double aa[] = new double[4]; - // - // double result[] = stats(yy); - // aa[0] = result[0]; - // // aa[1] = (result[2] - result[1])/2.; - // aa[1] = (yy[yy.length-1] - yy[0])/2; - // - // //algorithm. - // //1) get cubic spline. - // //2) get deriv of cubic spline - // //3) fit to gaussian - // - // CubicSpline cs = new CubicSpline(xx, yy); - // CubicSpline deriv = cs.derivative(); - // - // double yyy[] = new double[xx.length]; - // for (int i = 0; i < yyy.length; i++) { - // yyy[i] = Math.abs(deriv._y[i]); - // if (yyy[i] < 1.0e-8) { - // yyy[i] = 0.0; - // } - // } - // - // try { - // Fitmrq gf = FitUtilities.fitGaussianNoErrors(xx, yyy, 1, 1.0e-3); - // aa[2] = gf.a[1]; - // aa[3] = gf.a[2]; - // } catch (Exception e) { - // System.err.println("Error Gaussian fit for Erf Fit initial guess " - // + e.getMessage()); - // } - // - // return aa; - // } - - /** - * Get the fit parameters - * - * @return the fit parameters - */ - public double[] getFitParameters() { - return a; - } - - /** - * Get the covariance matrix - * - * @return the covariance matrix - */ - public double[][] getCovarianceMatrix() { - return covar; - } - - /** - * Get the chi square of the fit - * - * @return the chi square - */ - public double getChiSquare() { - return chisq; - } - - @Override - public double value(double x) { - double A = a[0]; - double B = a[1]; - double MU = a[2]; - double S = a[3]; - - return A + B * _erf.erf((x - MU) / S); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/ErfcFit.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/ErfcFit.java deleted file mode 100644 index fee264d927..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/ErfcFit.java +++ /dev/null @@ -1,134 +0,0 @@ -package cnuphys.splot.fit; - -//import org.apache.commons.math3.special.Erf; - -import com.nr.model.Fitmrq; -import com.nr.sf.Erf; - -public class ErfcFit extends Fitmrq implements IValueGetter { - - // function that evaluates the Erf - private static FErfc _funcs = new FErfc(); - private static Erf _erf = new Erf(); - - /** - * Create a Error function Fit - * - * @param fit the fit data - */ - public ErfcFit(Fit fit) throws IllegalArgumentException { - super(fit.getX(), fit.getY(), fit.getSigmaY(), initialGuess(fit), _funcs, fit.getTolerance()); - - fit.setFitType(FitType.ERFC); - for (FitHold fh : fit.getHolds()) { - hold(fh.index, fh.value); - } - - fit(); - fit.setFit(this); - } - - /** - * A method to generate an initial guess - * - * @param fit the fit data - * @return initial guess - */ - public static double[] initialGuess(Fit fit) { - - double xx[] = fit.getX(); - double yy[] = fit.getY(); - - double result[] = FitUtilities.stats(yy); - double aa[] = new double[4]; - - double mean = result[0]; - aa[0] = mean - 1; - double delY = result[2] - result[1]; - aa[1] = (yy[yy.length - 1] - yy[0]) / 2; // half the deltaY - - // find the x that produces a y - double varmin = Double.POSITIVE_INFINITY; - int iimag = 0; - for (int i = 0; i < (yy.length - 1); i++) { - double var = (0.5) * (yy[i] + yy[i]); - var = Math.abs(var - mean); - if (var < varmin) { - varmin = var; - iimag = i; - } - } - - aa[2] = xx[iimag]; - - // now try to estimate the spread - int imin = iimag; - int imax = iimag; - - double fact = 0.25 * delY; - for (int i = iimag; i >= 0; i--) { - if (Math.abs(yy[i] - mean) > fact) { - imin = i; - break; - } - } - for (int i = iimag; i < yy.length; i++) { - if (Math.abs(yy[i] - mean) > fact) { - imax = i; - break; - } - } - - if (imin == imax) { - if (imin > 0) { - imin--; - } - else if (imax < (yy.length - 1)) { - imax++; - } - } - - double spread = Math.abs(xx[imax] - xx[imin]); - aa[3] = spread; - - return aa; - } - - /** - * Get the fit parameters - * - * @return the fit parameters - */ - public double[] getFitParameters() { - return a; - } - - /** - * Get the covariance matrix - * - * @return the covariance matrix - */ - public double[][] getCovarianceMatrix() { - return covar; - } - - /** - * Get the chi square of the fit - * - * @return the chi square - */ - public double getChiSquare() { - return chisq; - } - - @Override - public double value(double x) { - double A = a[0]; - double B = a[1]; - double MU = a[2]; - double S = a[3]; - - return A + B * _erf.erfc((x - MU) / S); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FErf.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FErf.java deleted file mode 100644 index f3df6a0337..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FErf.java +++ /dev/null @@ -1,41 +0,0 @@ -package cnuphys.splot.fit; - -//import org.apache.commons.math3.special.Erf; -import org.netlib.util.doubleW; - -import com.nr.model.MultiFuncd; -import com.nr.sf.Erf; - -public class FErf implements MultiFuncd { - - private static double _fact = 2. / Math.sqrt(Math.PI); - private static Erf _erf = new Erf(); - - /** - * Evaluates the Erf function - * - * @param x the independent variable - * @param a the function parameter array - * @param y the dependent variable - * @param dyda must be filled with the derivatives with respect to the fit - * parameters - */ - @Override - public void funk(final double x, final double[] a, final doubleW y, final double[] dyda) { - - double A = a[0]; - double B = a[1]; - double MU = a[2]; - double S = a[3]; - double z = (x - MU) / S; - double erf = _erf.erf(z); - double f = -_fact * B; - double g = Math.exp(-z * z); - y.val = A + B * erf; - dyda[0] = 1; - dyda[1] = erf; - dyda[2] = f * g / S; - dyda[3] = dyda[2] * z; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FErfc.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FErfc.java deleted file mode 100644 index 59c1a7d240..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FErfc.java +++ /dev/null @@ -1,40 +0,0 @@ -package cnuphys.splot.fit; - -//import org.apache.commons.math3.special.Erf; -import org.netlib.util.doubleW; - -import com.nr.model.MultiFuncd; -import com.nr.sf.Erf; - -public class FErfc implements MultiFuncd { - - private static double _fact = 2. / Math.sqrt(Math.PI); - private static Erf _erf = new Erf(); - - /** - * Evaluates the Erf function - * - * @param x the independent variable - * @param a the function parameter array - * @param y the dependent variable - * @param dyda must be filled with the derivatives with respect to the fit - * parameters - */ - @Override - public void funk(final double x, final double[] a, final doubleW y, final double[] dyda) { - - double A = a[0]; - double B = a[1]; - double MU = a[2]; - double S = a[3]; - double z = (x - MU) / S; - double erfc = _erf.erfc(z); - double f = -_fact * B; - double g = Math.exp(-z * z); - y.val = A + B * erfc; - dyda[0] = 1; - dyda[1] = erfc; - dyda[2] = -f * g / S; - dyda[3] = dyda[2] * z; - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FGaussPoly.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FGaussPoly.java deleted file mode 100644 index ffa5595ffa..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FGaussPoly.java +++ /dev/null @@ -1,61 +0,0 @@ -package cnuphys.splot.fit; - -import static com.nr.NRUtil.SQR; -import static java.lang.Math.exp; - -import org.netlib.util.doubleW; - -import com.nr.model.MultiFuncd; - -public class FGaussPoly implements MultiFuncd { - public final int numGauss; - public final int numPoly; - - /** - * Function evaluator for combined guassians and polynomial - * - * @param numGauss - * @param numPoly one more than the order, e.g. 3 for quadratic - */ - public FGaussPoly(final int numGauss, final int numPoly) { - this.numGauss = numGauss; - this.numPoly = numPoly; - } - - @Override - public void funk(final double x, final double[] a, final doubleW y, final double[] dyda) { - - double fac, ex, arg; - y.val = 0.; - int ng3 = 3 * numGauss; - int ntot = ng3 + numPoly; - - // first the gaussian - for (int i = 0; i < ng3; i += 3) { - arg = (x - a[i + 1]) / a[i + 2]; - ex = exp(-SQR(arg)); - fac = a[i] * ex * 2. * arg; - y.val += a[i] * ex; - dyda[i] = ex; - dyda[i + 1] = fac / a[i + 2]; - dyda[i + 2] = fac * arg / a[i + 2]; - } - - // now the poly - - if (numPoly > 0) { - double[] p = new double[numPoly]; - p[0] = 1.0; - for (int j = 1; j < numPoly; j++) { - p[j] = p[j - 1] * x; - } - - for (int i = ng3; i < ntot; i++) { - int j = i - ng3; - y.val += a[i] * p[j]; - dyda[i] = p[j]; - } - } - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FGaussian.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FGaussian.java deleted file mode 100644 index 5a6946f2e6..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FGaussian.java +++ /dev/null @@ -1,34 +0,0 @@ -package cnuphys.splot.fit; - -import static com.nr.NRUtil.SQR; -import static java.lang.Math.exp; - -public class FGaussian implements IValueGetter { - - /** - * Evaluate a sum of gaussians. - * - * @param a should have 3N parameters where N is the number of gaussians - */ - - private double _a[]; - - public FGaussian(double a[]) { - _a = a; - } - - @Override - public double value(double x) { - int na = _a.length; - double ex, arg; - - double y = 0; - for (int i = 0; i < na - 1; i += 3) { - arg = (x - _a[i + 1]) / _a[i + 2]; - ex = exp(-SQR(arg)); - y += _a[i] * ex; - } - return y; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FPoly.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FPoly.java deleted file mode 100644 index 32995c04d1..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FPoly.java +++ /dev/null @@ -1,37 +0,0 @@ -package cnuphys.splot.fit; - -import org.netlib.util.doubleW; - -import com.nr.model.MultiFuncd; - -public class FPoly implements MultiFuncd { - public final int numPoly; - - /** - * - * @param numPoly one more than the order, e.g. 3 for quadratic - */ - public FPoly(final int numPoly) { - this.numPoly = numPoly; - } - - @Override - public void funk(final double x, final double[] a, final doubleW y, final double[] dyda) { - - y.val = 0.; - - if (numPoly > 0) { - double[] p = new double[numPoly]; - p[0] = 1.0; - for (int j = 1; j < numPoly; j++) { - p[j] = p[j - 1] * x; - } - - for (int i = 0; i < numPoly; i++) { - y.val += a[i] * p[i]; - dyda[i] = p[i]; - } - } - } - -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/Fit.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/Fit.java deleted file mode 100644 index 87a02ab4e2..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/Fit.java +++ /dev/null @@ -1,486 +0,0 @@ -package cnuphys.splot.fit; - -import java.util.Vector; - -import cnuphys.splot.pdata.DataColumn; -import cnuphys.splot.pdata.HistoData; -import cnuphys.splot.plot.Environment; -import cnuphys.splot.plot.UnicodeSupport; - -/** - * General Fit container class. It holds all the information for a fit, but the - * actual fit is performed by the object held in the _fit instance - * variable, which is a numerical recipes fit object. - * - * @author heddle - * - */ - -public class Fit { - - protected enum ErrorType { - Y_Errors, X_Errors, XY_Errors, Massaged_Zeroes, No_Errors - }; - - // the fit type - private FitType _type = FitType.LINE; - - // the order for polynomial fit - private int _order = 2; - - // default number of gaussians if relevant - private int _numGauss = 1; - - // the tolerance - private double _tolerance = 1.0e-8; - - // how errors were used - private ErrorType _errorType; - - // the x data used for the fit - private double _x[]; - - // the y data used for the fit - private double _y[]; - - // the y error data used for the fit - private double _sigmaY[]; - - // the x error data used for the fit - private double _sigmaX[]; - - // holds on the fit parameters - private Vector _holds = new Vector(); - - // this holds the fit object. It is probably an NR object like a Fitmrq - // or a Fitsvd - private Object _fit; - - public Fit() { - } - - public Fit(double x[], double y[], double sigmaY[]) { - this(x, y, sigmaY, 1.0e-8); - } - - /** - * Create a fit which is someone poorly named. It is really just a container - * that holds all the data for a fit. It will be used in the constructor of an - * actual fit. - * - * @param x the x data - * @param y the y data - * @param sigmaY the y errors - * @param tolerance accuracy parameter (for nonlinear fits) - */ - public Fit(double x[], double y[], double sigmaY[], double tolerance) { - this(x, y, null, sigmaY, tolerance); - } - - /** - * Create a fit which is someone poorly named. It is really just a container - * that holds all the data for a fit. It will be used in the constructor of an - * actual fit. - * - * @param x the x data - * @param y the y data - * @param sigmaX the x errors - * @param sigmaY the y errors - * @param tolerance accuracy parameter (for nonlinear fits) - */ - public Fit(double x[], double y[], double sigmaX[], double sigmaY[], double tolerance) { - _x = x; - _y = y; - _sigmaX = sigmaX; - _sigmaY = sigmaY; - _tolerance = tolerance; - FitUtilities.fixNullSig(this); - } - - /** - * The x and y data arrays should be the same size. This returns the smaller of - * the two sizes. - * - * @return the minimum size of the data arrays - */ - public int size() { - int xsize = (_x == null) ? 0 : _x.length; - int ysize = (_y == null) ? 0 : _y.length; - - if (xsize != ysize) { - System.err.println("Different x and y array sizes in Fit."); - System.err.println("x size: " + xsize + " ysize: " + ysize); - } - - return Math.min(xsize, ysize); - } - - /** - * Set a hold on a fit parameter. If there already is one it will be overwritten - * using the new value. - * - * @param index the index of the parameter - * @param val the value at which the parameter is held. - */ - public void hold(int index, double val) { - - // already one for that index? - for (FitHold fh : _holds) { - if (fh.index == index) { - fh.value = val; - return; - } - } - - // wasn't one, so create it - FitHold fh = new FitHold(index, val); - _holds.add(fh); - } - - /** - * Get the fit parameter holds - * - * @return the fit parameter holds - */ - protected Vector getHolds() { - return _holds; - } - - /** - * Check whether a parameter was held - * - * @param index the index of the parameter - * @return true if the index was held - */ - public boolean isHeld(int index) { - for (FitHold fh : _holds) { - if (fh.index == index) { - return true; - } - } - return false; - } - - /** - * Get the x data for the fit - * - * @return the x data for the fit - */ - public double[] getX() { - return _x; - } - - /** - * Get the y data for the fit - * - * @return the y data for the fit - */ - public double[] getY() { - return _y; - } - - /** - * Get the y error data for the fit - * - * @return the y error data for the fit - */ - public double[] getSigmaY() { - return _sigmaY; - } - - /** - * Get the x error data for the fit - * - * @return the x error data for the fit - */ - public double[] getSigmaX() { - return _sigmaX; - } - - /** - * Set the x data for the fit - * - * @param x the x data - */ - public void setX(double x[]) { - _x = x; - } - - /** - * Set the y data for the fit - * - * @param y the y data - */ - public void setY(double y[]) { - _y = y; - } - - /** - * Set the y error data for the fit - * - * @param sigma the y error data - */ - public void setSigmaY(double sigma[]) { - _sigmaY = sigma; - } - - /** - * Set the x error data for the fit - * - * @param sigma the x error data - */ - public void setSigmaX(double sigma[]) { - _sigmaX = sigma; - } - - /** - * Set the error type used by the fitting. The client does no set this, the - * methods that call the fits in FitUtilities set this. If the type is "Massaged - * zeroes" it meant that error of zero were given fake fakes (equal to the mean - * error) to prevent the fits from failing. - * - * @param errorType the way the errors were used. - */ - protected void setErrorType(ErrorType errorType) { - _errorType = errorType; - } - - /** - * Get the error type that was used in the fitting - * - * @return the error type that was used in the fitting - */ - public ErrorType getErrorType() { - return _errorType; - } - - /** - * Get the polynomial order--the power of the highest power - * - * @param order the polynomial order--the power of the highest power - */ - public void setPolynomialOrder(int order) { - if (order != _order) { - _order = order; - setDirty(); - } - } - - /** - * Get the polynomial order, the polynomial order--the power of the highest - * power - * - * @return the polynomial order - */ - public int getPolynomialOrder() { - return _order; - } - - /** - * Get the number of gaussians - * - * @return the number of gaussians - */ - public int getNumGaussian() { - return _numGauss; - } - - /** - * Set the number of gaussians - * - * @param numGauss the new number of gaussians - */ - public void setNumGaussian(int numGauss) { - if (numGauss != _numGauss) { - _numGauss = numGauss; - setDirty(); - } - } - - /** - * Set the tolerance - * - * @param tolerance the value of the tolerance - */ - public void setTolerance(double tolerance) { - if (tolerance != _tolerance) { - _tolerance = tolerance; - setDirty(); - } - } - - /** - * Get the tolerance - * - * @return the tolerance - */ - public double getTolerance() { - return _tolerance; - } - - /** - * Returns the fit object, which is most likely a numerical recipes fit - * - * @return the fit object. - */ - public Object getFit() { - return _fit; - } - - /** - * Set the fit - * - * @param fit the new fit object, which is most likely a numerical recipes fit - */ - public void setFit(Object fit) { - _fit = fit; - } - - /** - * Set the fit to be dirty. Perhaps more data have been added - */ - public void setDirty() { - _fit = null; - } - - /** - * Check whether fit needs to be recomputed - * - * @return true if fit must be recomputed - */ - public boolean isDirty() { - return (_fit == null); - } - - /** - * Get the fit type - * - * @return the fit type - */ - public FitType getFitType() { - return _type; - } - - /** - * Set the fit type - * - * @param type the fit type - */ - public void setFitType(FitType type) { - if (type != _type) { - _type = type; - setDirty(); - } - } - - /** - * Get a report on the fit parameters in html - * - * @param curve the active curve - * @return the html fit string description - */ - public String getFitString(DataColumn curve) { - - StringBuffer sb = new StringBuffer(1024); - - sb.append(curve.getName() + "
"); - if (curve.isHistogram1D()) { - HistoData hd = curve.getHistoData(); - String cntStr = String.format( - "Total counts: %d
Good counts: %d
Over counts: %d
Under counts: %d", hd.getTotalCount(), - hd.getGoodCount(), hd.getUnderCount(), hd.getOverCount()); - sb.append(cntStr + "
"); - - double results[] = hd.getBasicStatistics(); - String statStr = String.format(UnicodeSupport.SMALL_MU + " = %9.3g  " - + colorStr("rms = %9.3g  ", "red") + UnicodeSupport.SMALL_SIGMA + " = %9.3g", results[0], - results[2], results[1]); - sb.append(statStr + "
"); - } - sb.append(FitType.getFitString(this)); - - if (Environment.getInstance().isLinux()) { - return "" + sb.toString() + ""; - } - else { - return "" + sb.toString() + ""; - } - } - - // create an html colored string - private String colorStr(String s, String color) { - return "" + s + ""; - } - - public static void main(String arg[]) { - double rawdata[] = { 25.0, 1.000900900900901, 0.01733697900764091, 26.0, 1.000900900900901, 0.01733697900764091, - 27.0, 1.000900900900901, 0.01733697900764091, 28.0, 1.000900900900901, 0.01733697900764091, 29.0, - 1.000900900900901, 0.01733697900764091, 30.0, 1.000900900900901, 0.01733697900764091, 31.0, - 1.000900900900901, 0.01733697900764091, 32.0, 1.000900900900901, 0.01733697900764091, 33.0, - 1.000900900900901, 0.01733697900764091, 34.0, 1.000900900900901, 0.01733697900764091, 35.0, - 1.000900900900901, 0.01733697900764091, 36.0, 1.000900900900901, 0.01733697900764091, 37.0, - 1.000900900900901, 0.01733697900764091, 38.0, 1.000900900900901, 0.01733697900764091, 39.0, - 1.000900900900901, 0.01733697900764091, 40.0, 1.000900900900901, 0.01733697900764091, 41.0, - 1.000900900900901, 0.01733697900764091, 42.0, 0.9996996996996997, 0.017326572656758746, 43.0, - 1.0003003003003004, 0.017331776613222914, 44.0, 1.0006006006006005, 0.017334378005599775, 45.0, - 0.9990990990990991, 0.017321367136840526, 46.0, 0.9972972972972973, 0.017305741182250943, 47.0, - 0.9927927927927928, 0.017266614428186246, 48.0, 0.9927927927927928, 0.017266614428186246, 49.0, - 0.9888888888888889, 0.017232632715199488, 50.0, 0.9774774774774775, 0.017132915105820917, 51.0, - 0.9621621621621622, 0.016998164201903792, 52.0, 0.9597597597597598, 0.016976929759882967, 53.0, - 0.9414414414414415, 0.016814135350353657, 54.0, 0.8996996996996997, 0.016437155775860673, 55.0, - 0.8687687687687687, 0.016152136767399645, 56.0, 0.8369369369369369, 0.015853466923502115, 57.0, - 0.7672672672672672, 0.015179281628949083, 58.0, 0.7018018018018019, 0.014517275633960144, 59.0, - 0.6336336336336337, 0.013794215108535558, 60.0, 0.578978978978979, 0.013185884924985075, 61.0, - 0.4921921921921922, 0.01215752701501331, 62.0, 0.4297297297297297, 0.01135992811974639, 63.0, - 0.3483483483483483, 0.010227859679235077, 64.0, 0.26036036036036037, 0.008842301420021296, 65.0, - 0.1990990990990991, 0.007732368282032272, 66.0, 0.15195195195195196, 0.006755088215736933, 67.0, - 0.12252252252252252, 0.006065768731748996, 68.0, 0.09759759759759759, 0.005413740653849834, 69.0, - 0.05795795795795796, 0.004171905101936878, 70.0, 0.04924924924924925, 0.0038457202627224314, 71.0, - 0.030930930930930932, 0.003047715184712378, 72.0, 0.02132132132132132, 0.002530375307260168, 73.0, - 0.014414414414414415, 0.002080541510593246, 74.0, 0.0075075075075075074, 0.0015015015015015015, 75.0, - 0.0045045045045045045, 0.0011630580619241492, 76.0, 0.0036036036036036037, 0.001040270755296623, 77.0, - 0.0015015015015015015, 6.71491885135072E-4, 78.0, 0.0015015015015015015, 6.71491885135072E-4, 79.0, - 9.009009009009009E-4, 5.201353776483115E-4, - // 80.0, 0, 0, - // 81.0, 0, 0, - // 82.0, 0, 0, - }; - - int len = rawdata.length / 3; - double x[] = new double[len]; - double y[] = new double[len]; - double sigma[] = new double[len]; - - for (int i = 0; i < len; i++) { - int j = i * 3; - x[i] = rawdata[j]; - y[i] = rawdata[j + 1]; - sigma[i] = rawdata[j + 2]; - } - - Fit fit = new Fit(x, y, sigma, 1.0e-4); - // fit.hold(0, 0.5); - // fit.hold(1, -0.5); - ErfFit efit = new ErfFit(fit); - - double a[] = efit.getFitParameters(); - System.out.println("\nErf Fit"); - System.out.println("A = " + a[0]); - System.out.println("B = " + a[1]); - System.out.println("mu = " + a[2]); - System.out.println("S = " + a[3] / Math.sqrt(2)); - System.out.println("chisq = " + efit.getChiSquare()); - - System.out.println("\nLinear Fit"); - - double xx[] = { 1, 2, 3, 4, 5, 6, 7 }; - double yy[] = { 1, 2, 3, 4, 5, 6, 7 }; - double sig[] = { .1, .2, .1, .2, .05, .05, .2 }; - Fit fit2 = new Fit(xx, yy, sig); - LineFit lfit = new LineFit(fit2); - System.out.println("slope = " + lfit.getSlope() + " +- " + lfit.getSlopeSigma()); - System.out.println("intercept = " + lfit.getIntercept() + " +- " + lfit.getInterceptSigma()); - - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FitEditorPanel.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FitEditorPanel.java deleted file mode 100644 index 3885166c28..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FitEditorPanel.java +++ /dev/null @@ -1,332 +0,0 @@ -package cnuphys.splot.fit; - -import java.awt.Component; -import java.awt.FlowLayout; -import java.awt.Font; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; - -import javax.swing.JCheckBox; -import javax.swing.JPanel; -import cnuphys.splot.edit.VerticalFlowLayout; -import cnuphys.splot.pdata.DataColumn; -import cnuphys.splot.pdata.HistoData; -import cnuphys.splot.plot.CommonBorder; -import cnuphys.splot.plot.Environment; -import cnuphys.splot.plot.TextFieldSlider; -import cnuphys.splot.style.EnumComboBox; - -public class FitEditorPanel extends JPanel { - - // properties changed - public static final String POLYNOMIALORDERPROP = "Polynomial Order"; - public static final String GAUSSIANNUMPROP = "Number of Gaussians"; - public static final String USERMSPROP = "Use RMS in Legend"; - public static final String STATERRPROP = "Show Stat Errors"; - - private static final Font _font = Environment.getInstance().getCommonFont(10); - private static final Font _font2 = Environment.getInstance().getCommonFont(9); - - // change fit style - EnumComboBox _fitSelector; - - // polynomial order - protected TextFieldSlider _polynomialOrderSelector; - - // number of gaussians - protected TextFieldSlider _gaussianCountSelector; - - // use rms or sigma for histo - protected JCheckBox _rmsOrCB; - // stat error button - protected JCheckBox _statErrorCB; - // panel for two checkboxes - protected JPanel _histoCBPanel; - - /** - * A Fit editing panel - */ - public FitEditorPanel() { - addContent(); - setBorder(new CommonBorder("Fit")); - Environment.getInstance().commonize(this, null); - } - - // add the components - private void addContent() { - // setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - - setLayout(new VerticalFlowLayout()); - - _fitSelector = FitType.getComboBox(FitType.LINE); - - createPolySelector(); - createNumGaussSelector(); - createRMSOrSigmaCB(); - createStatErrorCB(); - - _histoCBPanel = new JPanel(); - _histoCBPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 4, 1)); - _histoCBPanel.add(_rmsOrCB); - _histoCBPanel.add(_statErrorCB); - - JPanel sp = new JPanel(); - sp.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); - sp.add(_fitSelector); - add(sp); - } - - // create the selector for the number of polygons - private void createPolySelector() { - - String labels[] = { "0", "2", "4", "6", "8", "10", "12", "14", "16" }; - _polynomialOrderSelector = new TextFieldSlider(0, 16, 2, _font, 1, labels, 180, 40, "Polynomial Order") { - - @Override - public double sliderValueToRealValue() { - return getValue(); - } - - @Override - public int realValueToSliderValue(double val) { - return (int) val; - } - - @Override - public String valueString(double val) { - return "" + getValue(); - } - - @Override - public void valueChanged() { - firePropertyChange(POLYNOMIALORDERPROP, -1, _polynomialOrderSelector.getValue()); - } - - }; - } - - private void createRMSOrSigmaCB() { - _rmsOrCB = new JCheckBox("RMS in Legend", true); - _rmsOrCB.setFont(_font2); - - ItemListener il = new ItemListener() { - - @Override - public void itemStateChanged(ItemEvent e) { - boolean selected = _rmsOrCB.isSelected(); - _rmsOrCB.firePropertyChange(USERMSPROP, !selected, selected); - } - - }; - - _rmsOrCB.addItemListener(il); - } - - private void createStatErrorCB() { - _statErrorCB = new JCheckBox("Statistical Errors", false); - _statErrorCB.setFont(_font2); - - ItemListener il = new ItemListener() { - - @Override - public void itemStateChanged(ItemEvent e) { - boolean selected = _statErrorCB.isSelected(); - _statErrorCB.firePropertyChange(STATERRPROP, !selected, selected); - } - - }; - - _statErrorCB.addItemListener(il); - } - - // create the selector for the number of gaussians - private void createNumGaussSelector() { - - String labels[] = { "1", "2", "3", "4", "5", "6" }; - _gaussianCountSelector = new TextFieldSlider(1, 6, 1, _font, 1, labels, 180, 40, "Number of Gaussians") { - - @Override - public double sliderValueToRealValue() { - return getValue(); - } - - @Override - public int realValueToSliderValue(double val) { - return (int) val; - } - - @Override - public String valueString(double val) { - return "" + getValue(); - } - - @Override - public void valueChanged() { - firePropertyChange(GAUSSIANNUMPROP, -1, _gaussianCountSelector.getValue()); - } - - }; - } - - /** - * Reconfigure fit widgets based on fit type - * - * @param curve the active curve - */ - public void reconfigure(DataColumn curve) { - if (curve == null) { - remove(_polynomialOrderSelector); - remove(_gaussianCountSelector); - remove(_histoCBPanel); - } - else { - - if (curve.isHistogram1D()) { - HistoData hd = curve.getHistoData(); - carefulAdd(_histoCBPanel); - } - - switch (curve.getFit().getFitType()) { - - case POLYNOMIAL: - case ALTPOLYNOMIAL: - remove(_gaussianCountSelector); - carefulAdd(_polynomialOrderSelector); - break; - - case GAUSSIANS: - remove(_polynomialOrderSelector); - carefulAdd(_gaussianCountSelector); - break; - - case POLYPLUSGAUSS: - carefulAdd(_gaussianCountSelector); - carefulAdd(_polynomialOrderSelector); - break; - - default: - remove(_polynomialOrderSelector); - remove(_gaussianCountSelector); - break; - } - } - - // super.validate(); - } - - // set components enabled - @Override - public void setEnabled(boolean enabled) { - super.setEnabled(enabled); - _fitSelector.setEnabled(enabled); - _polynomialOrderSelector.setEnabled(enabled); - _gaussianCountSelector.setEnabled(enabled); - _rmsOrCB.setEnabled(enabled); - _statErrorCB.setEnabled(enabled); - } - - private void carefulAdd(Component comp) { - for (Component c : this.getComponents()) { - if (c == comp) { - return; - } - } - add(comp); - } - - /** - * FitEditorPanel Set the choices - * - * @param curve the new choices - */ - public void setFit(DataColumn curve) { - - if (curve.isHistogram1D()) { - HistoData hd = curve.getHistoData(); - _rmsOrCB.setSelected(hd.useRmsInHistoLegend()); - } - - Fit fit = curve.getFit(); - if (fit != null) { - _fitSelector.setSelectedItem(fit.getFitType().getName()); - _polynomialOrderSelector.setValue(fit.getPolynomialOrder()); - _gaussianCountSelector.setValue(fit.getNumGaussian()); - } - } - - /** - * Further enable/disable based on fit type - * - * @param type - */ - public void fitSpecific(FitType type) { - switch (type) { - case POLYNOMIAL: - case ALTPOLYNOMIAL: - _polynomialOrderSelector.setEnabled(true); - _gaussianCountSelector.setEnabled(false); - break; - - case GAUSSIANS: - _polynomialOrderSelector.setEnabled(false); - _gaussianCountSelector.setEnabled(true); - break; - - case POLYPLUSGAUSS: - _polynomialOrderSelector.setEnabled(true); - _gaussianCountSelector.setEnabled(true); - break; - - default: - _polynomialOrderSelector.setEnabled(false); - _gaussianCountSelector.setEnabled(false); - break; - } - } - - /** - * Get the line selector - * - * @return the line selector - */ - public EnumComboBox getFitSelector() { - return _fitSelector; - } - - /** - * Get the polynomial order slider - * - * @return polynomial order slider - */ - public TextFieldSlider getPolynomialOrderSelector() { - return _polynomialOrderSelector; - } - - /** - * Get the number of gaussian slider - * - * @return number of gaussian slider - */ - public TextFieldSlider getNumGaussianSelector() { - return _gaussianCountSelector; - } - - /** - * Get the rms or sigma check box - * - * @return the rms or sigma check box - */ - public JCheckBox getNumRMSCheckBox() { - return _rmsOrCB; - } - - /** - * Get the draw stat error check box - * - * @return the draw stat error checkbox - */ - public JCheckBox getStatErrorCheckBox() { - return _statErrorCB; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FitHold.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FitHold.java deleted file mode 100644 index 9801675e40..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FitHold.java +++ /dev/null @@ -1,31 +0,0 @@ -package cnuphys.splot.fit; - -/** - * This class is used to place holds on fit parameters - * - * @author heddle - * - */ -public class FitHold { - - // the index of the fit parameter to be held - protected int index; - - // the value it is held at - protected double value; - - /** - * Create a hold on a fitting parameter. When the fit is performed, any - * parameters that are "held" will be set to a fixed value and no changed in the - * optimization - * - * @param index the parameter index. All fits have a parameter array (usually - * called a[]. This is an index into that array. - * @param value the value that should be held. - */ - protected FitHold(int index, double value) { - this.index = index; - this.value = value; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FitType.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FitType.java deleted file mode 100644 index 79a93e2e64..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FitType.java +++ /dev/null @@ -1,366 +0,0 @@ -package cnuphys.splot.fit; - -import java.util.EnumMap; - -import com.nr.model.Fitab; -import com.nr.model.Fitexy; -import com.nr.model.Fitsvd; - -import cnuphys.splot.plot.DoubleFormat; -import cnuphys.splot.plot.UnicodeSupport; -import cnuphys.splot.plot.X11Colors; -import cnuphys.splot.style.EnumComboBox; - -public enum FitType { - - NOLINE, CONNECT, STAIRS, LINE, POLYNOMIAL, GAUSSIANS, POLYPLUSGAUSS, ERF, ERFC, ALTPOLYNOMIAL, CUBICSPLINE; - - // some hex colors - private static final String WHEAT = X11Colors.getX11ColorAsHex("WHEAT"); - private static final String DARKRED = X11Colors.getX11ColorAsHex("Dark RED"); - private static final String DARKGREEN = X11Colors.getX11ColorAsHex("Dark GREEN"); - - /** - * A map for the names of the fit types - */ - public static EnumMap names = new EnumMap(FitType.class); - - static { - names.put(CONNECT, "Simple Connect"); - names.put(STAIRS, "Stairs"); - names.put(LINE, "Line Fit"); - names.put(CUBICSPLINE, "Cubic Spline"); - names.put(POLYNOMIAL, "Polynomial"); - names.put(GAUSSIANS, "Gaussians"); - names.put(POLYPLUSGAUSS, "Poly & Gaussians"); - names.put(ERF, "Erf Function"); - names.put(ERFC, "Erfc Function"); - names.put(ALTPOLYNOMIAL, "Alt Polynomial"); - names.put(NOLINE, "No Line"); - } - - private static final String _MU = UnicodeSupport.SMALL_MU; - private static final String _SUM = UnicodeSupport.CAPITAL_SIGMA; - private static final String _EOL = "
"; - private static final String _SP = " "; - - /** - * Get the nice name of the enum. - * - * @return the nice name, for combo boxes, menus, etc. - */ - public String getName() { - return names.get(this); - } - - /** - * Returns the enum value from the name. - * - * @param name the name to match. - * @return the FitType that corresponds to the name. Returns - * null if no match is found. - */ - public static FitType getValue(String name) { - if (name == null) { - return null; - } - - for (FitType val : values()) { - // check the nice name - if (name.equalsIgnoreCase(val.getName())) { - return val; - } - // check the base name - if (name.equalsIgnoreCase(val.name())) { - return val; - } - } - return null; - } - - /** - * Get an html string the describes the fit - * - * @param curveFit the fit object that will have to be cast appropriately - * @return an html string the describes the fit - */ - public static String getFitString(Fit curveFit) { - StringBuffer sb = new StringBuffer(1024); - - FitType type = curveFit.getFitType(); - Object fit = curveFit.getFit(); // must be cast - - switch (type) { - - case NOLINE: - sb.append("No line."); - break; - - case CONNECT: - sb.append("Connect the points."); - break; - - case STAIRS: - sb.append("Staircase connection."); - break; - - case CUBICSPLINE: - sb.append("Natural cubic spline interpolation"); - break; - - case LINE: - sb.append(header("Linear Fit:") + descript("y = a + b x")); - - if (fit != null) { - - if (fit instanceof Fitab) { - Fitab fab = (Fitab) fit; - sb.append(pmString("a", fab.a, fab.siga) + "
"); - sb.append(pmString("b", fab.b, fab.sigb) + "
"); - sb.append(errorType(curveFit)); - sb.append(chiSqString(fab.chi2)); - } - else if (fit instanceof Fitexy) { - Fitexy fitexy = (Fitexy) fit; - sb.append(pmString("a", fitexy.a, fitexy.siga) + "
"); - sb.append(pmString("b", fitexy.b, fitexy.sigb) + "
"); - sb.append(errorType(curveFit)); - sb.append(chiSqString(fitexy.chi2)); - } - } - else { - sb.append(warning("LINEAR FIT PROBLEM")); - } - break; // LINE - - case POLYNOMIAL: - sb.append(header("Polynomial Fit") + descript("y = " + _SUM + sub("A", "n") + " xn")); - sb.append(info("Polynomial Order: " + curveFit.getPolynomialOrder())); - - if (fit != null) { - Fitsvd fsvd = (Fitsvd) fit; - - for (int i = 0; i < fsvd.a.length; i++) { - sb.append(pmString("A" + i + "", fsvd.a[i], Math.sqrt(fsvd.covar[i][i])) + "
"); - } - sb.append(errorType(curveFit)); - sb.append(chiSqString(fsvd.chisq)); - } - else { - sb.append(warning("POLYNOMIAL FIT PROBLEM")); - } - break; // POLYNOMIAL - - case ERF: - sb.append(header("Erf Fit:") + descript("y = A + B Erf[(x-" + _MU + ")/S" + "]")); - - if (fit != null) { - ErfFit efit = (ErfFit) fit; - - double a[] = efit.getFitParameters(); - double covar[][] = efit.getCovarianceMatrix(); - double chisq = efit.getChiSquare(); - - sb.append(pmString("A", a[0], Math.sqrt(covar[0][0])) + _EOL); - sb.append(pmString("B", a[1], Math.sqrt(covar[1][1])) + _EOL); - sb.append(pmString(_MU, a[2], Math.sqrt(covar[2][2])) + _EOL); - sb.append(pmString("S", a[3], Math.sqrt(covar[3][3])) + _EOL); - sb.append(colorStr("S/" + UnicodeSupport.SQRT + "2 = " + valStr(a[3] / Math.sqrt(2)), "gray") + _EOL); - sb.append(errorType(curveFit)); - sb.append(chiSqString(chisq)); - } - else { - sb.append(warning("ERF FIT PROBLEM")); - } - break; // ERF - - case ERFC: - sb.append(header("Erfc Fit:") + descript("y = A + B Erfc[(x-" + _MU + ")/S" + "]")); - - if (fit != null) { - ErfcFit ecfit = (ErfcFit) fit; - - double a[] = ecfit.getFitParameters(); - double covar[][] = ecfit.getCovarianceMatrix(); - double chisq = ecfit.getChiSquare(); - - sb.append(paramStr("A", a[0], covar[0][0], curveFit.isHeld(0))); - sb.append(paramStr("B", a[1], covar[1][1], curveFit.isHeld(1))); - sb.append(paramStr(_MU, a[2], covar[2][2], curveFit.isHeld(2))); - sb.append(paramStr("S", a[3], covar[3][3], curveFit.isHeld(3))); - sb.append(colorStr("S/" + UnicodeSupport.SQRT + "2 = " + valStr(a[3] / Math.sqrt(2)), "gray") + _EOL); - sb.append(errorType(curveFit)); - sb.append(chiSqString(chisq)); - } - else { - sb.append(warning("ERFC FIT PROBLEM")); - } - break; // ERFC - - case ALTPOLYNOMIAL: - sb.append( - header("Alt Polynomial Fit:") + descript("y = " + _SUM + sub("A", "n") + " xn")); - sb.append(info("Polynomial Order: " + curveFit.getPolynomialOrder())); - - if (fit != null) { - AltPolynomialFit faltp = (AltPolynomialFit) fit; - - for (int i = 0; i < faltp.a.length; i++) { - sb.append(pmString(sub("A", i), faltp.a[i], Math.sqrt(faltp.covar[i][i])) + "
"); - } - sb.append(errorType(curveFit)); - sb.append(chiSqString(faltp.chisq)); - } - else { - sb.append(warning("ALTERNATE POLY FIT PROBLEM")); - } - break; // ALTPOLYNOMIAL - - case GAUSSIANS: - sb.append(header("Gaussian Fit:") + descript(" y = " + _SUM + sub("A", "n") + " exp{-[(x-" - + sub(_MU, "n") + ")/" + sub("S", "n") + "]2}")); - sb.append(info("Number of Gaussians: " + curveFit.getNumGaussian())); - - if (fit != null) { - GaussianFit fg = (GaussianFit) fit; - - for (int i = 0; i < fg.a.length / 3; i++) { - int j = 3 * i; - sb.append(pmString(sub("A", i), fg.a[j], Math.sqrt(fg.covar[j][j])) + _EOL); - j++; - sb.append(pmString(sub(_MU, i), fg.a[j], Math.sqrt(fg.covar[j][j])) + _EOL); - j++; - sb.append(pmString(sub("S", i), fg.a[j], Math.sqrt(fg.covar[j][j])) + _EOL); - } - sb.append(errorType(curveFit)); - sb.append(chiSqString(fg.chisq)); - } - else { - sb.append(warning("GAUSSIAN FIT PROBLEM")); - } - break; // GAUSSIANS - - case POLYPLUSGAUSS: - sb.append(header("Gaussian & Polynomial Fit:") - + descript("y = " + _SUM + sub("A", "n") + " exp{-[(x-" + sub(_MU, "n") + ")/" - + sub("S", "n") + "]2} + " + _SUM + sub("D", "m") + " xm")); - sb.append(info("Number of Gaussians: " + curveFit.getNumGaussian())); - sb.append(info("Polynomial Order: " + curveFit.getPolynomialOrder())); - sb.append(colorStr("Gaussian Parameters", "blue") + "
"); - - if (fit != null) { - PolyAndGaussianFit fpg = (PolyAndGaussianFit) fit; - - for (int i = 0; i < fpg._numGauss; i++) { - int j = 3 * i; - sb.append(pmString(sub("A", i), fpg.a[j], Math.sqrt(fpg.covar[j][j])) + "
"); - j++; - sb.append(pmString(sub(_MU, i), fpg.a[j], Math.sqrt(fpg.covar[j][j])) + "
"); - j++; - sb.append(pmString(sub("S", i), fpg.a[j], Math.sqrt(fpg.covar[j][j])) + "
"); - } - // now the poly - sb.append(colorStr("Polynomial Parameters", "blue") + _EOL); - for (int i = 3 * fpg._numGauss; i < fpg.a.length; i++) { - int j = i - 3 * fpg._numGauss; - sb.append(pmString(sub("D", j), fpg.a[i], Math.sqrt(fpg.covar[i][i])) + _EOL); - - } - - sb.append(errorType(curveFit)); - sb.append(chiSqString(fpg.chisq)); - } - else { - sb.append(warning("GAUSSIAN PLUS POLY FIT PROBLEM")); - } - break; - - } - - return sb.toString(); - } - - // next - private static String colorStr(String s, String fg, String bg) { - String htmlstr = "" + s + ""; - return htmlstr; - } - - private static String paramStr(String name, double val, double var, boolean held) { - String s = ""; - if (held) { - s = colorStr(_SP + "[HELD]" + _SP, "yellow", "black") + _SP; - } - return s + pmString(name, val, Math.sqrt(var)) + _EOL; - } - - // header string - private static String header(String s) { - return colorStr("" + s + "" + _EOL, "black", WHEAT); - } - - private static String descript(String s) { - return colorStr(s + _EOL, DARKRED, "white"); - } - - private static String info(String s) { - return colorStr(s + _EOL, DARKGREEN, "white"); - } - - private static String warning(String s) { - return colorStr("" + s + "" + _EOL, "red", "yellow"); - } - - private static String colorStr(String s, String color) { - return "" + s + ""; - } - - private static String errorType(Fit fit) { - return colorStr("Errors: " + fit.getErrorType().name() + _EOL, "black"); - } - - // convert a value and an error into a a +- b string - private static String pmString(String vname, double val, double sig) { - - String vstr = valStr(val); - String vsigstr = valStr(sig); - - return vname + " = " + vstr + colorStr(" ± " + vsigstr, "black"); - } - - // generate a chi-sq string - private static String chiSqString(double val) { - return UnicodeSupport.SMALL_CHI + "2 = " + valStr(val); - } - - // generate a value string - private static String valStr(double val) { - if (Double.isNaN(val)) { - return "Nan"; - } - else if (Double.isInfinite(val)) { - return UnicodeSupport.INFINITY; - } - return DoubleFormat.doubleFormat(val, 4, 3); - } - - // subscript - private static String sub(String s, int i) { - return s + "" + i + ""; - } - - // subscript - private static String sub(String s, String ss) { - return s + "" + ss + ""; - } - - /** - * Obtain a combo box of choices. - * - * @param defaultChoice - * @return the combo box of fit types - */ - public static EnumComboBox getComboBox(FitType defaultChoice) { - return new EnumComboBox(names, defaultChoice); - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FitUtilities.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FitUtilities.java deleted file mode 100644 index a6e97f50c2..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/FitUtilities.java +++ /dev/null @@ -1,400 +0,0 @@ -package cnuphys.splot.fit; - -import java.util.Arrays; -import java.util.Comparator; - -public class FitUtilities { - - /** - * A Straight line fit with errors in y - * - * @param fit - */ - public static void fitStraightLine(Fit fit) { - fixNullSig(fit); - - if (fit.getSigmaX() != null) { - System.err.println("Fitting with X Errors"); - new LinearExyFit(fit); - } - else { - new LineFit(fit); - } - } - - /** - * A Polynomial fit with errors - * - * @param fit the fit data - */ - public static void fitPoly(Fit fit) { - fixNullSig(fit); - new PolyFit(fit); // errors - } - - /** - * An alternate polynomial fit with errors - * - * @param fit the fit data - */ - public static void fitAltPoly(Fit fit) { - fixNullSig(fit); - new AltPolynomialFit(fit); // errors - } - - /** - * Where the fitting is actually done - * - * @param fit - * @param className - */ - // public static void doFit(Fit fit, String className) { - // fixNullSig(fit); - // Class clazz; - // try { - // clazz = Class.forName(className); - // Constructor ctor = clazz.getConstructor(Fit.class); - // Object object = ctor.newInstance(new Object[] { fit }); - // } catch (ClassNotFoundException e) { - // e.printStackTrace(); - // } catch (NoSuchMethodException e) { - // e.printStackTrace(); - // } catch (SecurityException e) { - // e.printStackTrace(); - // } catch (InstantiationException e) { - // e.printStackTrace(); - // } catch (IllegalAccessException e) { - // e.printStackTrace(); - // } catch (IllegalArgumentException e) { - // e.printStackTrace(); - // } catch (InvocationTargetException e) { - // e.printStackTrace(); - // } - // } - - /** - * Erf fit with errors - * - * @param fit the fit data - */ - public static void fitErf(Fit fit) throws IllegalArgumentException { - fixNullSig(fit); - new ErfFit(fit); // errors - } - - /** - * Ercf fit with errors - * - * @param fit the fit data - */ - public static void fitErfc(Fit fit) throws IllegalArgumentException { - fixNullSig(fit); - new ErfcFit(fit); // errors - } - - /** - * A Gaussian fit with errors - * - * @param fit the fit data - */ - public static void fitGaussians(Fit fit) throws IllegalArgumentException { - System.err.println("Fitting Gaussians"); - fixNullSig(fit); - GaussianFit gf = new GaussianFit(fit); - if (fit.getFit() == null) { - System.err.println("Null fit in fitGausians"); - System.err.println("gf = " + gf); - } - } - - /** - * A Gaussian and polynomial fit with errors - * - * @param fit the fit data - */ - public static void fitGaussPlusPoly(Fit fit) throws IllegalArgumentException { - fixNullSig(fit); - new PolyAndGaussianFit(fit); // errors - } - - /** - * Checks whether an array is sorted in ascending order - * - * @param val the array to check - * @return true if the array is sorted - */ - public static boolean isSorted(double val[]) { - if ((val == null) || (val.length < 1)) { - return true; - } - - for (int i = 1, n = val.length; i < n; i++) { - if (val[i - 1] > val[i]) - return false; - } - return true; - } - - /** - * Index sort of an array - * - * @param val the array to sort - * @return the sorted index array - */ - public static Integer[] indexSort(final double val[]) { - if ((val == null) || (val.length < 1)) { - return null; - } - Integer iarry[] = new Integer[val.length]; - for (int i = 0; i < val.length; i++) { - iarry[i] = i; - } - - Comparator comp = new Comparator() { - - @Override - public int compare(Integer i0, Integer i1) { - return Double.compare(val[i0], val[i1]); - } - - }; - Arrays.sort(iarry, comp); - return iarry; - } - - /** - * Sort a set of parallel arrays. The first one is the one that will end up - * sorted. Does nothing if the first array is sorted. - * - * @param da a set of arrays - */ - public static void parallelSort(double[]... da) { - if (isSorted(da[0])) { - return; // done - } - - Integer iarry[] = indexSort(da[0]); - for (double[] darry : da) { - rearranged(iarry, darry); - } - } - - /** - * Rearrange an array based on an index array - * - * @param iarry the index array - * @param vals the array that will be rearranged - */ - private static void rearranged(Integer iarry[], double vals[]) { - double[] newvals = new double[vals.length]; - - for (int i = 0; i < vals.length; i++) { - newvals[i] = vals[iarry[i]]; - } - for (int i = 0; i < vals.length; i++) { - vals[i] = newvals[i]; - } - } - - /** - * Compute the "standard" standard deviation (divide variance by N) using an - * accurate one-pass method. - * - * @param x the data - * @return the standard deviation - */ - public static double standardDev(double x[]) { - if ((x == null) || (x.length == 0)) { - return Double.NaN; - } - - int n = x.length; - if (n == 1) { - return 0; - } - - double m = x[0]; - double q = 0; - for (int k = 2; k <= n; k++) { - double fac = (x[k - 1] - m); - double fac2 = fac / k; - m = m + fac2; - q = q + (k - 1) * fac * fac2; - } - double var = q / n; - - if (var <= 0.) { - return 0.0; - } - return Math.sqrt(var); - - } - - /** - * Get the mean, min and max of an array. - * - * @param v the array - * @return a double[3] containing, in order, the mean, min and max - */ - public static double[] stats(double v[]) { - - double result[] = { Double.NaN, Double.NaN, Double.NaN }; - - if ((v != null) && (v.length > 0)) { - - double sum = 0; - double vmin = Double.POSITIVE_INFINITY; - double vmax = Double.NEGATIVE_INFINITY; - for (double val : v) { - sum += val; - vmin = Math.min(vmin, val); - vmax = Math.max(vmax, val); - } - - result[0] = sum / v.length; // mean - result[1] = vmin; - result[2] = vmax; - } - return result; - } - - /** - * Another stats convenience method - * - * @param v the input array - * @return a double[4] containing, in order, the mean, min, max, and standard - * deviation - */ - public static double[] muSigma(double v[]) { - double result0[] = stats(v); - double result[] = new double[4]; - for (int i = 0; i < 3; i++) { - result[i] = result0[i]; - } - result[3] = standardDev(v); - return result; - } - - /** - * Get a weighted x mean - * - * @param x the x values - * @param y the x values - * @return the weighted x mean - */ - public static double[] getWeightedXAverage(double x[], double y[]) { - // average will be in 0, stddev in 1 - double result[] = { Double.NaN, Double.NaN }; - - int n = Math.min(x.length, y.length); - - if (n == 0) { - return result; - } - else if (n == 1) { - result[0] = x[0]; - result[1] = 0; - return result; - } - - double sumX = 0.; - double sumY = 0.; - double sumXY = 0.; - double xy[] = new double[n]; - for (int i = 0; i < n; i++) { - double yabs = Math.abs(y[i]); - sumX += x[i]; - sumY += yabs; - xy[i] = x[i] * yabs; - sumXY += xy[i]; - } - - if (sumY < 1.0e-20) { - result[0] = sumX / n; - result[1] = standardDev(x); - } - result[0] = sumXY / sumY; - result[1] = n * standardDev(xy) / sumY; - return result; - } - - /** - * This deals with missing or bad error data. If the sigma array is null, it - * creates a new array and assigns a value of 1 to each error. It does the same - * if the sigma array has all zero values. The real troubling case is when sigma - * has some zero values. This will cause many fits to fail. So in that case it - * repleaces all zero values with the mean value. At that point the fit should - * be considered suspect. - * - * @param fit - */ - protected static void fixNullSig(Fit fit) { - - double sigY[] = fit.getSigmaY(); - double sigX[] = fit.getSigmaX(); - - boolean hasXErr = (sigX != null); - boolean hasYErr = (sigY != null); - - if (hasXErr && hasYErr) { - fit.setErrorType(Fit.ErrorType.XY_Errors); - } - else if (hasXErr && !hasYErr) { - fit.setErrorType(Fit.ErrorType.X_Errors); - } - else if (!hasXErr && hasYErr) { - fit.setErrorType(Fit.ErrorType.Y_Errors); - } - else { - fit.setErrorType(Fit.ErrorType.No_Errors); - } - - if (sigY == null) { - int n = fit.getX().length; - sigY = new double[n]; - for (int i = 0; i < n; i++) { - sigY[i] = 1; - } - - fit.setSigmaY(sigY); - } - - else { - // just check there are n0 zero errors - double result[] = stats(sigY); - double mean = result[0]; - - // zero errors will cause the fit to fail. - // Use a minimum error based on mean error - double minsig = 1.0e-8 * mean; - for (int i = 0; i < sigY.length; i++) { - if (sigY[i] < minsig) { - sigY[i] = mean; - fit.setErrorType(Fit.ErrorType.Massaged_Zeroes); - } - } - } - - // don't give it x errors if missing, but do fix zeroes - if (hasXErr) { - double result[] = stats(sigX); - double mean = result[0]; - - // zero errors will cause the fit to fail. - // Use a minimum error based on mean error - double minsig = 1.0e-8 * mean; - for (int i = 0; i < sigX.length; i++) { - if (sigX[i] < minsig) { - sigX[i] = mean; - fit.setErrorType(Fit.ErrorType.Massaged_Zeroes); - } - } - parallelSort(fit.getX(), fit.getY(), fit.getSigmaX(), fit.getSigmaY()); - } - else { - parallelSort(fit.getX(), fit.getY(), fit.getSigmaY()); - } - - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/GaussianFit.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/GaussianFit.java deleted file mode 100644 index e88470967d..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/GaussianFit.java +++ /dev/null @@ -1,290 +0,0 @@ -package cnuphys.splot.fit; - -import static com.nr.NRUtil.SQR; -import static java.lang.Math.exp; - -import java.awt.Point; - -import com.nr.model.FGauss; -import com.nr.model.Fitmrq; - -/** - * For fitting a sum of Gaussians to a curve (DataColumn) - * - * @author heddle - * - */ -public class GaussianFit extends Fitmrq implements IValueGetter { - - // function that evaluates the Gaussians - private static FGauss _funcs = new FGauss(); - - /** - * Create a Gaussian Fit - * - * @param fit the fit data - */ - public GaussianFit(Fit fit) throws IllegalArgumentException { - super(fit.getX(), fit.getY(), fit.getSigmaY(), initialGuess(fit), _funcs, fit.getTolerance()); - // set holds, then fit - fit.setFitType(FitType.GAUSSIANS); - for (FitHold fh : fit.getHolds()) { - hold(fh.index, fh.value); - } - fit(); - fit.setFit(this); - } - - private static final double TINY = 1.0e-20; - - private static boolean tinyDiff(double x1, double x2) { - return Math.abs(x2 - x1) < TINY; - } - - /** - * A method to generate an initial guess - * - * @param fit - * @return - */ - public static double[] initialGuess(Fit fit) { - - // System.err.println("INIT GUESS"); - - double xx[] = fit.getX(); - double yy[] = fit.getY(); - - // get rid of long tails - int start = 0; - int stop = xx.length - 1; - - double y = yy[0]; - - for (int j = 1; j < xx.length; j++) { - if (!tinyDiff(y, yy[j])) { - start = Math.max(0, j - 2); - break; - } - } - - for (int j = xx.length - 2; j >= 0; j--) { - if (!tinyDiff(y, yy[j])) { - stop = Math.min(xx.length - 1, j + 2); - break; - } - } - - double xxx[] = xx; - double yyy[] = yy; - if ((start > 0) || (stop < (xx.length - 1))) { - // System.err.println("Trimming"); - int length = (stop - start + 1); - xxx = new double[length]; - yyy = new double[length]; - System.arraycopy(xx, start, xxx, 0, length); - System.arraycopy(yy, start, yyy, 0, length); - } - - int len = yyy.length; - double yabs[] = new double[len]; - - for (int i = 0; i < len; i++) { - yabs[i] = Math.abs(yyy[i]); - } - - int numGauss = fit.getNumGaussian(); - CubicSpline cs = new CubicSpline(xxx, yabs); - - // the algorithm. The method findXValsOfMaxima will fit a cubic to - // the data, which is good at fitting the peaks. It will then find - // and return the x values and y values of the peaks in descending - // order, - // i.e. pp[0] is the x and y of the highest maximum. It will then use - // that info - // as a very good guess of the gaussian means () - Point.Double pp[] = cs.findXValsOfMaxima(xxx[0], xxx[xxx.length - 1]); - - // lets hope this doesn't happen - if ((pp == null) || (pp.length < numGauss)) { - System.err.println("Gaussian initial guess algorithm failed."); - fit.setNumGaussian(numGauss); - return secondaryInitialGuess(fit); - } - - int ng3 = 3 * numGauss; - double aa[] = new double[ng3]; - - double stats[] = getWeightedcStdDev(xxx, yyy); - - // re cubic w/o abs vals - cs = new CubicSpline(xxx, yyy); - - for (int i = 0; i < numGauss; i++) { - int j = 3 * i; - // aa[j] = pp[i].y; - aa[j] = cs.value(pp[i].x); - - // System.err.println(pp[i].x + " " + pp[i].y + " " + - // cs.value(pp[i].x) + " " + stats[1]); - aa[j + 1] = pp[i].x; - // aa[j+2] = 1.0; - aa[j + 2] = stats[1] / 2; - } - - return aa; - } - - /** - * A method to generate an initial guess - * - * @param fit - * @return - */ - public static double[] secondaryInitialGuess(Fit fit) { - System.err.println("trying secondary initial guess got Gaussians"); - fit.setPolynomialOrder(fit.getNumGaussian() + 3); - FitUtilities.fitPoly(fit); - Polynomial poly = new Polynomial(((PolyFit) (fit.getFit())).a); - - // the algorithm. The method findXValsOfMaxima will fit a polynomial to - // the data, which is usually good at fitting the peaks. It will then - // find - // and return the x values and y values of the peaks in descending - // order, - // i.e. pp[0] is the x and y of the highest maximum. It will then use - // that info - // as a very good guess of the gaussian means () - double xx[] = fit.getX(); - Point.Double pp[] = poly.findXValsOfMaxima(xx[0], xx[xx.length - 1]); - - // lets hope this doesn't happen - if ((pp == null) || (pp.length < fit.getNumGaussian())) { - System.err.println("Gaussian secondary guess algorithm failed."); - return tertiaryInitialGuess(fit); - } - - int ng3 = 3 * fit.getNumGaussian(); - double aa[] = new double[ng3]; - - for (int i = 0; i < fit.getNumGaussian(); i++) { - int j = 3 * i; - aa[j] = pp[i].y; - aa[j + 1] = pp[i].x; - aa[j + 2] = 1.0; - } - - return aa; - } - - // a less reliable initial guess strategy bases on some statistics - private static double[] tertiaryInitialGuess(Fit fit) { - System.err.println("trying tertiary initial guess got Gaussians"); - - double xx[] = fit.getX(); - double yy[] = fit.getY(); - int numGauss = fit.getNumGaussian(); - int ng3 = 3 * numGauss; - double result[] = FitUtilities.getWeightedXAverage(xx, yy); - - double ypeak = 0.0; - for (int i = 0; i < yy.length; i++) { - ypeak = Math.max(ypeak, Math.abs(yy[i])); - } - - double aa[] = new double[ng3]; - if (!Double.isNaN(result[0])) { - double delX = result[1] / (numGauss + 1); - double xmin = result[1] - delX; - for (int i = 0; i < ng3; i += 3) { - aa[i] = ypeak; - aa[i + 1] = xmin + delX * (i / 3); - aa[i + 2] = result[1] / numGauss; - } - } - else { - for (int i = 0; i < ng3; i++) { - aa[i] = 1.; - } - } - - return aa; - } - - /** - * Get the fit parameters - * - * @return the fit parameters - */ - public double[] getFitParameters() { - return a; - } - - /** - * Get the covariance matrix - * - * @return the covariance matrix - */ - public double[][] getCovarianceMatrix() { - return covar; - } - - /** - * Get the chi square of the fit - * - * @return the chi square - */ - public double getChiSquare() { - return chisq; - } - - // public void funk(final double x, final double[]a, final doubleW y, final - // double[] dyda){ - - @Override - public double value(double x) { - int na = a.length; - double ex, arg; - double y = 0.; - for (int i = 0; i < na - 1; i += 3) { - arg = (x - a[i + 1]) / a[i + 2]; - ex = exp(-SQR(arg)); - y += a[i] * ex; - } - return y; - } - - /** - * Get the means and standard deviation - * - * @return an array with the mean in the 0 index and standard deviation is the 1 - * index - */ - private static double[] getWeightedcStdDev(double xx[], double yy[]) { - - double stats[] = new double[2]; - stats[0] = Double.NaN; - stats[1] = Double.NaN; - - int n = xx.length; - - double sum = 0; - double sumsq = 0; - double ysum = 0; - for (int i = 0; i < n; i++) { - double yabs = Math.abs(yy[i]); - double x = xx[i]; - double wx = yabs * x; - sum += wx; - sumsq += x * wx; - ysum += yabs; - } - - double avgSq = sumsq / ysum; - - stats[0] = sum / ysum; // mean - stats[1] = Math.sqrt(avgSq - (stats[0] * stats[0])); // stdDev - - return stats; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/IValueGetter.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/IValueGetter.java deleted file mode 100644 index 72ba030897..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/IValueGetter.java +++ /dev/null @@ -1,6 +0,0 @@ -package cnuphys.splot.fit; - -public interface IValueGetter { - - public double value(double x); -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/LineFit.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/LineFit.java deleted file mode 100644 index de779d38a5..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/LineFit.java +++ /dev/null @@ -1,70 +0,0 @@ -package cnuphys.splot.fit; - -import com.nr.model.Fitab; - -public class LineFit extends Fitab implements IValueGetter { - - /** - * Create a Error function Fit and perform the fit. This is for data with y - * errors only. If there are x errors too, use LinearExyFit. - * - * @param fit the fit data - */ - public LineFit(Fit fit) throws IllegalArgumentException { - super(fit.getX(), fit.getY(), fit.getSigmaY()); - - fit.setFitType(FitType.LINE); - fit.setFit(this); - } - - /** - * Get the slope of the fit - * - * @return the slope of the fit - */ - public double getSlope() { - return b; - } - - /** - * Get the intercept of the fit - * - * @return the intercept of the fit - */ - public double getIntercept() { - return a; - } - - /** - * Get the error estimate in the slope - * - * @return the error estimate in the slope - */ - public double getSlopeSigma() { - return sigb; - } - - /** - * Get the intercept estimate - * - * @return the intercept estimate - */ - public double getInterceptSigma() { - return siga; - } - - /** - * Get the chi square of the fit - * - * @return the chi square - */ - public double getChiSquare() { - return chi2; - } - - @Override - public double value(double x) { - return a + b * x; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/LinearExyFit.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/LinearExyFit.java deleted file mode 100644 index 058bc0eeac..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/LinearExyFit.java +++ /dev/null @@ -1,87 +0,0 @@ -package cnuphys.splot.fit; - -import com.nr.model.Fitexy; - -public class LinearExyFit extends Fitexy implements IValueGetter { - - /** - * Create a Error function Fit and perform the fit. This is for data with y - * errors only. If there are x errors too, use LinearXYE. - * - * @param fit the fit data - */ - public LinearExyFit(Fit fit) throws IllegalArgumentException { - super(fit.getX(), fit.getY(), fit.getSigmaX(), fit.getSigmaY()); - fit.setFitType(FitType.LINE); - fit.setFit(this); - } - - /** - * Get the slope of the fit - * - * @return the slope of the fit - */ - public double getSlope() { - return b; - } - - /** - * Get the intercept of the fit - * - * @return the intercept of the fit - */ - public double getIntercept() { - return a; - } - - /** - * Get the error estimate in the slope - * - * @return the error estimate in the slope - */ - public double getSlopeSigma() { - return sigb; - } - - /** - * Get the intercept estimate - * - * @return the intercept estimate - */ - public double getInterceptSigma() { - return siga; - } - - /** - * Get the chi square of the fit - * - * @return the chi square - */ - public double getChiSquare() { - return chi2; - } - - @Override - public double value(double x) { - return a + b * x; - } - - public static void main(String arg[]) { - // 3.000000 228.380525 0.070000 0.218365 - // 4.000000 303.564738 0.080000 0.227791 - // 5.000000 379.971954 0.090000 0.222510 - - double x[] = { 3, 4, 5 }; - double y[] = { 228.380525, 303.564738, 379.971954 }; - double xSig[] = { 0.07, 0.08, 0.09 }; - double ySig[] = { 0.218365, 0.227791, 0.222510 }; - - Fit fit = new Fit(x, y, xSig, ySig, 0); - LinearExyFit fitExy = new LinearExyFit(fit); - - System.out.println("slope = " + fitExy.getSlope() + " +- " + fitExy.getSlopeSigma()); - System.out.println("intercept = " + fitExy.getIntercept() + " +- " + fitExy.getInterceptSigma()); - - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/PolyAndGaussianFit.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/PolyAndGaussianFit.java deleted file mode 100644 index 52aec78840..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/PolyAndGaussianFit.java +++ /dev/null @@ -1,129 +0,0 @@ -package cnuphys.splot.fit; - -import static com.nr.NRUtil.SQR; -import static java.lang.Math.exp; - -import com.nr.model.Fitmrq; - -public class PolyAndGaussianFit extends Fitmrq implements IValueGetter { - - int _numGauss; - int _numPoly; - - /** - * - * @param fit the fit data - */ - public PolyAndGaussianFit(Fit fit) { - super(fit.getX(), fit.getY(), fit.getSigmaY(), initialGuess(fit), - createFGaussPoly(fit.getNumGaussian(), fit.getPolynomialOrder() + 1), fit.getTolerance()); - _numGauss = fit.getNumGaussian(); - _numPoly = fit.getPolynomialOrder() + 1; - - fit.setFitType(FitType.POLYPLUSGAUSS); - // set holds, then fit - for (FitHold fh : fit.getHolds()) { - hold(fh.index, fh.value); - } - - try { - fit(); - fit.setFit(this); - } - catch (IllegalArgumentException e) { - System.err.println("Gaussian plus Polynomial fit failed."); - } - } - - /** - * A method to generate an initial guess - * - * @param xx the x data - * @param yy the y data - * @param numGauss the number of gaussians - * @param np number of terms in poly (order + 1) - * @return - */ - private static double[] initialGuess(Fit fit) { - double bb[] = GaussianFit.initialGuess(fit); - - int ng3 = 3 * fit.getNumGaussian(); - int ntot = ng3 + fit.getPolynomialOrder() + 1; - double aa[] = new double[ntot]; - for (int i = 0; i < ntot; i++) { - if (i < ng3) { - aa[i] = bb[i]; - } - else { - aa[i] = 1.0; - } - } - return aa; - } - - // public void funk(final double x, final double[]a, final doubleW y, final - // double[] dyda){ - - @Override - public double value(double x) { - int ng3 = _numGauss * 3; - double ex, arg; - double y = 0.; - for (int i = 0; i < ng3 - 1; i += 3) { - arg = (x - a[i + 1]) / a[i + 2]; - ex = exp(-SQR(arg)); - y += a[i] * ex; - } - - // now the poly - if (_numPoly > 0) { - int ntot = ng3 + _numPoly; - - double[] p = new double[_numPoly]; - p[0] = 1.0; - for (int j = 1; j < _numPoly; j++) { - p[j] = p[j - 1] * x; - } - - for (int i = ng3; i < ntot; i++) { - int j = i - ng3; - y += a[i] * p[j]; - } - } - - return y; - } - - /** - * Get the fit parameters - * - * @return the fit parameters - */ - public double[] getFitParameters() { - return a; - } - - /** - * Get the covariance matrix - * - * @return the covariance matrix - */ - public double[][] getCovarianceMatrix() { - return covar; - } - - /** - * Get the chi square of the fit - * - * @return the chi square - */ - public double getChiSquare() { - return chisq; - } - - public static FGaussPoly createFGaussPoly(final int numGauss, final int numPoly) { - FGaussPoly fpoly = new FGaussPoly(numGauss, numPoly); - return fpoly; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/PolyFit.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/PolyFit.java deleted file mode 100644 index fc1eebcb0b..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/PolyFit.java +++ /dev/null @@ -1,84 +0,0 @@ -package cnuphys.splot.fit; - -import com.nr.UniVarRealMultiValueFun; -import com.nr.model.Fitsvd; - -public class PolyFit extends Fitsvd implements IValueGetter { - - private int _n; - private UniVarRealMultiValueFun _funcs; - - /** - * - * @param fit the fit data - */ - public PolyFit(Fit fit) { - super(fit.getX(), fit.getY(), fit.getSigmaY(), getFuncs(fit.getPolynomialOrder() + 1), fit.getTolerance()); - _funcs = getFuncs(fit.getPolynomialOrder() + 1); - _n = fit.getPolynomialOrder() + 1; - fit.setFitType(FitType.POLYNOMIAL); - - try { - fit(); - fit.setFit(this); - } - catch (IllegalArgumentException e) { - System.err.println("Polynomial fit failed."); - } - } - - /** - * Get the fit parameters - * - * @return the fit parameters - */ - public double[] getFitParameters() { - return a; - } - - /** - * Get the covariance matrix - * - * @return the covariance matrix - */ - public double[][] getCovarianceMatrix() { - return covar; - } - - /** - * Get the chi square of the fit - * - * @return the chi square - */ - public double getChiSquare() { - return chisq; - } - - @Override - public double value(double x) { - double p[] = _funcs.funk(x); - - double sum = 0; - for (int i = 0; i < _n; i++) { - sum += a[i] * p[i]; - } - return sum; - } - - private static UniVarRealMultiValueFun getFuncs(final int n) { - UniVarRealMultiValueFun funcs = new UniVarRealMultiValueFun() { - - @Override - public double[] funk(double x) { - double[] p = new double[n]; - p[0] = 1.0; - for (int j = 1; j < n; j++) { - p[j] = p[j - 1] * x; - } - return p; - } - }; - - return funcs; - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/Polynomial.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/Polynomial.java deleted file mode 100644 index e541f06559..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/fit/Polynomial.java +++ /dev/null @@ -1,194 +0,0 @@ -package cnuphys.splot.fit; - -import java.awt.Point; -import java.util.Arrays; -import java.util.Comparator; - -import com.nr.UniVarRealValueFun; -import com.nr.root.Roots; -import com.nr.root.Roots.Zbrak; - -public class Polynomial implements IValueGetter { - - // the coefficients. Poly is a[0] + a[1]x + a[2]x^2 +... - private double _a[]; - - // coeficients for the derivative - private double _aderiv[]; - - public Polynomial(double a[]) { - _a = a; - - // get the derivative - int n = _a.length; - if (n > 1) { - int m = n - 1; - _aderiv = new double[m]; - for (int i = 1; i < n; i++) { - _aderiv[i - 1] = i * _a[i]; - } - } - } - - @Override - public double value(double x) { - double[] p = new double[_a.length]; - p[0] = 1.0; - for (int i = 1; i < _a.length; i++) { - p[i] = p[i - 1] * x; - } - - double sum = 0; - for (int i = 0; i < _a.length; i++) { - sum += _a[i] * p[i]; - } - return sum; - } - - /** - * Find the roots of the polynomial in a range - * - * @param xmin the min value of the range - * @param xmax the max value of the range - * @return an array of roots, or null - */ - public double[] findRoots(double xmin, double xmax) { - - UniVarRealValueFun fx = new UniVarRealValueFun() { - - @Override - public double funk(double x) { - return value(x); - } - - }; - - Zbrak zb = new Zbrak(); - zb.zbrak(fx, xmin, xmax, 100); - - double roots[] = null; - if (zb.nroot > 0) { - roots = new double[zb.nroot]; - for (int i = 0; i < zb.nroot; i++) { - double x1 = zb.xb1[i]; - double x2 = zb.xb2[i]; - roots[i] = Roots.rtsec(fx, x1, x2, 1.0e-6); - } - } - return roots; - } - - /** - * Find the xy values of the maxima of the polynomial in a given range - * - * @param xmin the min value of the range - * @param xmax the max value of the range - * @return and array of xy values, or null - */ - public Point.Double[] findXValsOfMaxima(double xmin, double xmax) { - int n = _a.length; - if (n < 3) { - return null; - } - - // find zeroes of derivatives - Polynomial firstDeriv = getDerivative(); - double roots[] = firstDeriv.findRoots(xmin, xmax); - if (roots == null) { - return null; - } - - // get second deriv - Polynomial secondDeriv = firstDeriv.getDerivative(); - // count maxim - int count = 0; - for (double x : roots) { - if (secondDeriv.value(x) < 0.) { - count++; - } - } - - if (count < 1) { - return null; - } - - double xvals[] = new double[count]; - int ncount = 0; - for (double x : roots) { - if (secondDeriv.value(x) < 0.) { - xvals[ncount] = x; - ncount++; - if (ncount == count) { - break; - } - } - } - - Point.Double results[] = new Point.Double[count]; - - for (int i = 0; i < count; i++) { - results[i] = new Point.Double(); - results[i].x = xvals[i]; - results[i].y = value(xvals[i]); - } - - if (count > 1) { - Comparator comp = new Comparator() { - - @Override - public int compare(java.awt.geom.Point2D.Double p0, java.awt.geom.Point2D.Double p1) { - return Double.compare(p1.y, p0.y); - } - - }; - Arrays.sort(results, comp); - } - - return results; - } - - public int getMaxNumberOfPositiveRoots() { - return maxNumPositiveRoots(_a); - } - - public Polynomial getDerivative() { - if (_a.length < 2) { - return null; - } - return new Polynomial(_aderiv); - } - - public static int maxNumPositiveRoots(double a[]) { - int n = a.length; - if (n < 2) { - return 0; - } - - // get first nonzero a - double sign = 0; - int inz = n; - - for (int i = 0; i < (n - 1); i++) { - sign = Math.signum(a[i]); - if (sign != 0.) { - inz = i; - break; - } - } - if (inz >= (n - 1)) { - return 0; - } - - int count = 0; - - for (int i = inz + 1; i < n; i++) { - double nsign = Math.signum(a[i]); - if ((nsign != 0) && (nsign != sign)) { - count++; - sign = nsign; - } - } - return count; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/.gitignore b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/.gitignore deleted file mode 100644 index fbfa9d2b9d..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/.gitignore +++ /dev/null @@ -1,14 +0,0 @@ -/DataChangeListener.class -/DataColumn.class -/DataColumnType.class -/DataSet.class -/DataSetException.class -/DataSetType.class -/DataTable$1.class -/DataTable$MyTableCellEditor.class -/DataTable.class -/GrowableArray.class -/HistoData.class -/NiceScale.class -/StripData$1.class -/StripData.class diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataChangeListener.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataChangeListener.java deleted file mode 100644 index b9c5b7a484..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataChangeListener.java +++ /dev/null @@ -1,13 +0,0 @@ -package cnuphys.splot.pdata; - -import java.util.EventListener; - -public interface DataChangeListener extends EventListener { - - /** - * A data set changed - * - * @param dataSet the dataSet that changed - */ - public void dataSetChanged(DataSet dataSet); -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataColumn.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataColumn.java deleted file mode 100644 index 9dba324666..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataColumn.java +++ /dev/null @@ -1,393 +0,0 @@ -package cnuphys.splot.pdata; - -import cnuphys.splot.fit.Fit; -import cnuphys.splot.style.Styled; - -public class DataColumn extends GrowableArray { - - // diagnostic counter - private static int _count = 0; - - // drawing style - private Styled _style; - - // the fit (Y columns only) - protected Fit _fit; - - // the column name - protected String _name; - - // data type - protected DataColumnType _type; - - // determines whether this column is shown. Only relevant - // for Y columns. Can be used to hide a curve - protected boolean _visible = true; - - // keep some running sums for getting variance - private double _sumVal; - private double _M; - private double _Q; - - // used by 1D histograms - private HistoData _histoData1D; - - // used by 2D histograms - private Histo2DData _histoData2D; - - // set if this is a 1D histogram - private boolean _isHisto1D = false; - - // set if this is a 2D histogram - private boolean _isHisto2D = false; - - /** - * Creates a DataColumn with initial capacity 100 and increment 100. - * - * @param name the column name - */ - public DataColumn(DataColumnType type, String name) { - this(type, name, 100, 100); - } - - /** - * Create a DataColumn - * - * @param name the column name - * @param initCap the initial capacity - * @param increment the increment when the array grows. - */ - public DataColumn(DataColumnType type, String name, int initCap, int increment) { - super(initCap, increment); - _type = type; - _name = name; - clear(); - } - - /** - * This gets the histogram data, which for non-histograms will be - * null. - * - * @return the histogram data - */ - public HistoData getHistoData() { - return _histoData1D; - } - - /** - * Set the histogram data container - * - * @param histo the histogram data - */ - protected void setHistoData(HistoData histo) { - if (histo != null) { - _isHisto1D = true; - _isHisto2D = false; - _histoData1D = histo; - } - } - - /** - * This gets the histogram 2D data, which for non-histograms will be - * null. - * - * @return the histogram 2D data - */ - public Histo2DData getHistoData2D() { - return _histoData2D; - } - - /** - * Set the histogram 2D data container - * - * @param histo2D the histogram 2D data - */ - protected void setHistoData2D(Histo2DData histo2D) { - if (histo2D != null) { - _isHisto1D = false; - _isHisto2D = true; - _histoData2D = histo2D; - } - } - - /** - * Checks whether this is a 1D histogram - * - * @return true if this is a 1D histogram - */ - public boolean isHistogram1D() { - return _isHisto1D; - } - - /** - * Checks whether this is a 2D histogram - * - * @return true if this is a 2D histogram - */ - public boolean isHistogram2D() { - return _isHisto2D; - } - - /** - * Check whether this "curve" is visible. Only relevant for Y columns. - * - * @return the visibility flag - */ - public boolean isVisible() { - return _visible; - } - - /** - * Set the name - * - * @param name the name of the data column - */ - public void setName(String name) { - _name = name; - if (_isHisto1D) { - _histoData1D.setName(name); - } - else if (_isHisto2D) { - _histoData2D.setName(name); - } - } - - /** - * Get the name of the array - * - * @return the name of the array - */ - public String getName() { - return (_name != null) ? _name : ""; - } - - /** - * Set whether this "curve" is visible. Only relevant for Y columns. - * - * @param visible the visibility flag. - */ - public void setVisible(boolean visible) { - _visible = visible; - } - - /** - * Get the type of this data column - * - * @return the type of this data column - */ - public DataColumnType getType() { - return _type; - } - - /** - * Init the style sort of randomly - */ - protected void initStyle() { - _style = new Styled(_count++); - } - - /** - * Initialize a fit object - */ - protected void initFit() { - _fit = new Fit(); - } - - /** - * Set the style - * - * @param style the new style - */ - protected void setStyle(Styled style) { - _style = style; - } - - /** - * Get the style for this column - * - * @return the style for this column - */ - public Styled getStyle() { - return _style; - } - - /** - * Get a string representation - * - * @return a string representation - */ - @Override - public String toString() { - return _name; - } - - /** - * Get the Fit - * - * @return the fit - */ - public Fit getFit() { - return _fit; - } - - /** - * Add used only by 2D histograms - * - * @param xval the x value - * @param yval the y value - */ - public void histo2DAdd(double xval, double yval) { - if (_isHisto2D) { - if (_histoData2D != null) { - _histoData2D.add(xval, yval); - } - } - else { - System.err.println("In DataColumn, histo2DAdd(x,y) inexplicably called for non-2D histogram"); - } - } - - /** - * Add a value to the array, growing it if necessary. - * - * @param val the value to add - */ - @Override - public void add(double val) { - - if (_isHisto1D) { - _histoData1D.add(val); - } - else { - super.add(val); - } - - if (_fit != null) { - _fit.setDirty(); - } - - // some running sums for statistics - - long n; - if (_isHisto1D) { - n = _histoData1D.getTotalCount(); - } - else { - n = size(); - } - _sumVal += val; - - if (n == 1) { - _M = val; - _Q = 0; - } - else { - double fac = (val - _M); - double fac2 = fac / n; - _M = _M + fac2; - _Q = _Q + (n - 1) * fac * fac2; - } - } - - /** - * Get the mean - * - * @return the mean - */ - public double getMean() { - long n; - if (_isHisto1D) { - n = _histoData1D.getTotalCount(); - } - else { - n = size(); - } - - if (n == 0) { - return Double.NaN; - } - return _sumVal / n; - } - - /** - * Get the variance. Note: divides by N, not N-1 - * - * @return the variance. - */ - public double getVariance() { - long n; - if (_isHisto1D) { - n = _histoData1D.getTotalCount(); - } - else { - n = size(); - } - - if (n == 0) { - return Double.NaN; - } - else if (n == 1) { - return 0.; - } - else { - return _Q / n; - } - } - - /** - * Get the standard deviation - * - * @return the standard deviation - */ - public double getStandardDeviation() { - double var = getVariance(); - - if (Double.isNaN(var)) { - return Double.NaN; - } - if (var <= 0.) { - return 0.0; - } - - return Math.sqrt(var); - } - - /** - * Reset the data array to the initial capacity and fill with all NaNs. - */ - @Override - public void clear() { - super.clear(); - if (_isHisto1D) { - _histoData1D.clear(); - } - else if (_isHisto2D) { - _histoData2D.clear(); - } - - if (_fit != null) { - _fit.setDirty(); - } - } - - /** - * Set the value at the given index - * - * @param index the index - * @param val the value at the index - */ - @Override - public void set(int index, double val) { - - if (_isHisto2D) { - System.err.println("DataColumn,set inexlpicably called for 2D histo"); - return; - } - // TODO something for histograms this is called from datatable - super.set(index, val); - if (_fit != null) { - _fit.setDirty(); - } - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataColumnType.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataColumnType.java deleted file mode 100644 index 14486c8b49..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataColumnType.java +++ /dev/null @@ -1,17 +0,0 @@ -package cnuphys.splot.pdata; - -/** - * Different types of columns - *
    - *
  • X x data - *
  • Y y data - *
  • XERR horizontal error bars - *
  • YERR vertical error bars - *
- * - * @author heddle - * - */ -public enum DataColumnType { - X, Y, XERR, YERR; -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataSet.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataSet.java deleted file mode 100644 index 6fd00ba54a..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataSet.java +++ /dev/null @@ -1,945 +0,0 @@ -package cnuphys.splot.pdata; - -import java.math.BigDecimal; -import java.util.Collection; -import java.util.Vector; - -import javax.swing.event.EventListenerList; -import javax.swing.table.DefaultTableModel; -import cnuphys.splot.fit.Fit; -import cnuphys.splot.fit.FitType; -import cnuphys.splot.plot.DoubleFormat; -import cnuphys.splot.style.IStyled; -import cnuphys.splot.style.Styled; -import cnuphys.splot.style.SymbolType; - -/** - * This is essentially a table of not necessarily equal length columns. - * - * @author heddle - * - */ -public class DataSet extends DefaultTableModel { - - // the data - Vector _columns = new Vector(); - - // List of dataset change listeners - private EventListenerList _listenerList; - - // the dataset type - private DataSetType _type = DataSetType.UNKNOWN; - - // most sets do not have x errors - private boolean _hasXErrors; - - /** - * This constructor is for a 2D histogram - * - * @param h2d - */ - public DataSet(Histo2DData h2d) throws DataSetException { - if (h2d == null) { - throw (new DataSetException("Must supply at least one histogram data object.")); - } - - _type = DataSetType.H2D; - - // just one column - _columns.add(new DataColumn(DataColumnType.Y, h2d.getName())); - getColumn(0).setHistoData2D(h2d); - getColumn(0).initStyle(); - getColumn(0).getStyle().setSymbolType(SymbolType.NOSYMBOL); - getColumn(0).initFit(); - - } - - /** - * This constructor is used for 1D histograms - * - * @param histos an array of histo data objects - */ - public DataSet(HistoData... histos) throws DataSetException { - if ((histos == null) || (histos.length < 1)) { - throw (new DataSetException("Must supply at least one histogram data object.")); - } - _type = DataSetType.H1D; - - int colCount = histos.length; - - // create a y column for each histogram - for (int i = 0; i < colCount; i++) { - HistoData hd = histos[i]; - if (hd != null) { - _columns.add(new DataColumn(DataColumnType.Y, hd.getName())); - getColumn(i).setHistoData(hd); - getColumn(i).initStyle(); - getColumn(i).getStyle().setSymbolType(SymbolType.NOSYMBOL); - getColumn(i).initFit(); - } - } - } - - /** - * Create a dataset for a simple strip chart - * - * @param stripData the StripData data object - * @param colNames should be just two of them - */ - public DataSet(StripData stripData, String... colNames) { - _type = DataSetType.STRIP; - _columns.add(new DataColumn(DataColumnType.X, colNames[0])); - _columns.add(new DataColumn(DataColumnType.Y, colNames[1])); - getColumn(1).initStyle(); - getColumn(1).initFit(); - getColumn(1).getFit().setFitType(FitType.STAIRS); - stripData.setDataSet(this); - } - - /** - * Create a dataset of a specific type - * - * @param type the dataset type - * @param colNames the column names. There should be one name for every expected - * column based on the type. - * @throws DataSetException When the number of columns is inconsistent with the - * type - */ - public DataSet(DataSetType type, String... colNames) throws DataSetException { - super(colNames, 0); - _type = type; - int colCount = (colNames == null) ? 0 : colNames.length; - - switch (type) { - - case XYY: // shared x, any number of y - _columns.add(new DataColumn(DataColumnType.X, colNames[0])); - // the y columns, if any - for (int i = 1; i < colCount; i++) { - _columns.add(new DataColumn(DataColumnType.Y, colNames[i])); - getColumn(i).initStyle(); - getColumn(i).initFit(); - } - break; - - case XYXY: - // repeated x,y columns. Number of columns should be divisible by - // two - - if ((colCount % 2) != 0) { - throw new DataSetException("The number of columns " + colCount + " is not divisible by 2."); - } - for (int i = 0; i < colCount / 2; i++) { - int j = i * 2; - _columns.add(new DataColumn(DataColumnType.X, colNames[j])); - _columns.add(new DataColumn(DataColumnType.Y, colNames[j + 1])); - getColumn(j + 1).initStyle(); - getColumn(j + 1).initFit(); - } - break; - - case XYEXYE: - // repeated x,y,yerr. Number of columns should be divisible by three - - if ((colCount % 3) != 0) { - throw new DataSetException( - "The number of columns for type XYEXYE " + colCount + " is not divisible by 3."); - } - for (int i = 0; i < colCount / 3; i++) { - int j = i * 3; - _columns.add(new DataColumn(DataColumnType.X, colNames[j])); - _columns.add(new DataColumn(DataColumnType.Y, colNames[j + 1])); - _columns.add(new DataColumn(DataColumnType.YERR, colNames[j + 2])); - getColumn(j + 1).initStyle(); - getColumn(j + 1).initFit(); - } - break; - - case XYEEXYEE: - // repeated x,y,xerr, yerr. Number of columns should be divisible by - // four - - _hasXErrors = true; - if ((colCount % 4) != 0) { - throw new DataSetException( - "The number of columns for type XYEEXYEE " + colCount + " is not divisible by 4."); - } - for (int i = 0; i < colCount / 4; i++) { - int j = i * 3; - _columns.add(new DataColumn(DataColumnType.X, colNames[j])); - _columns.add(new DataColumn(DataColumnType.Y, colNames[j + 1])); - _columns.add(new DataColumn(DataColumnType.XERR, colNames[j + 2])); - _columns.add(new DataColumn(DataColumnType.YERR, colNames[j + 3])); - getColumn(j + 1).initStyle(); - getColumn(j + 1).initFit(); - } - break; - - case H1D: - throw (new DataSetException("Use DataSet(HistoData[]) constructor for 1D histograms.")); - - default: - break; - } - } - - /** - * Get the number of data points in the first column of - * a plot. - * @return the number of data points - */ - public long size() { - - long count = -1; - if (getColumnCount() != 0) { - DataColumn dc = _columns.firstElement(); - - if (is1DHistoSet()) { - HistoData hd = dc.getHistoData(); - count = hd.getTotalCount(); - } - else if (is2DHistoSet()) { - Histo2DData h2d = dc.getHistoData2D(); - count = h2d.getTotalCount(); - } - else { - count = dc.size(); - } - } - return count; - } - - - // XYY, XYXY, XYEXYE, XYEEXYEE, H1D, UNKNOWN; - - /** - * Add a curve to an existing data set. For now limited to type XYXY only. - * - * @param xname the name for the new xdata (ignored for some types) - * @param yname the name for the new y data - */ - public DataColumn addCurve(String xname, String yname) { - - DataColumn newCurve = null; - - switch (getType()) { - case XYY: - System.err.println("[sPlot] Can not add curve for type: " + getType()); - break; - - case XYXY: - addColumn(xname); - addColumn(yname); - _columns.add(new DataColumn(DataColumnType.X, xname)); - - newCurve = new DataColumn(DataColumnType.Y, yname); - newCurve.initFit(); - newCurve.initStyle(); - _columns.add(newCurve); - break; - - case XYEXYE: - System.err.println("[sPlot] Can not add curve for type: " + getType()); - break; - - case XYEEXYEE: - System.err.println("[sPlot] Can not add curve for type: " + getType()); - break; - - case H1D: - System.err.println("[sPlot] Can not add curve for type: " + getType()); - break; - - case STRIP: - System.err.println("[sPlot] Can not add curve for type: " + getType()); - break; - - case UNKNOWN: - System.err.println("[sPlot] Can not add curve for type: " + getType()); - break; - } - - // Vector colNames = new Vector(); - // for (DataColumn dc : _columns) { - // colNames.add(dc.getName()); - // } - // setColumnIdentifiers(colNames); - - return newCurve; - } - - /** - * Add data to a specific curve. For now limited to type XYXY only. - * - */ - public void addToCurve(int curveIndex, double... vals) throws DataSetException { - - int count = getColumnCount(); - - switch (getType()) { - case XYY: - System.err.println("[sPlot] Can not add to curve for type: " + getType()); - break; - - case XYXY: - int curveCount = count / 2; - if (curveIndex < curveCount) { - DataColumn xcol = _columns.get(2 * curveIndex); - DataColumn ycol = _columns.get(2 * curveIndex + 1); - xcol.add(vals[0]); - ycol.add(vals[1]); - } - else { - System.err.println("[sPlot] Curve index out of range for type: " + getType()); - } - break; - - case XYEXYE: - System.err.println("[sPlot] Can not add to curve for type: " + getType()); - break; - - case XYEEXYEE: - System.err.println("[sPlot] Can not add to curve for type: " + getType()); - break; - - case H1D: - System.err.println("[sPlot] Can not add to curve for type: " + getType()); - break; - - case H2D: - System.err.println("[sPlot] Can not add to curve for type: " + getType()); - break; - - case STRIP: - System.err.println("[sPlot] Can not add to curve for type: " + getType()); - break; - - case UNKNOWN: - System.err.println("[sPlot] Can not add to curve for type: " + getType()); - break; - } - notifyListeners(); - } - - /** - * Check to see if this data set has x errors - * - * @return true if this set has x errors - */ - public boolean hasXErrors() { - return _hasXErrors; - } - - /** - * Check to see if this data set is for 1D Histograms - * - * @return true if this is for 1D histograms - */ - public boolean is1DHistoSet() { - return (_type == DataSetType.H1D); - } - - /** - * Check to see if this data set is for 2D Histograms - * - * @return true if this is for 2D histograms - */ - public boolean is2DHistoSet() { - return (_type == DataSetType.H2D); - } - - /** - * Set all fits to dirty. - */ - public void setAllFitsDirty() { - for (DataColumn dc : _columns) { - if (dc.getFit() != null) { - dc.getFit().setDirty(); - } - } - } - - /** - * Get a curve from an index. E.g., f the index is 0 it will return the 1st Y - * column. Y Columns are also known as "curves". - * - * @param index the index - * @return the corresponding curve - */ - public DataColumn getCurve(int index) { - Vector ycols = (Vector) getAllColumnsByType(DataColumnType.Y); - - if ((ycols == null) || (index >= ycols.size())) { - return null; - } - - return ycols.get(index); - } - - /** - * Get a x column from an index. E.g., f the index is 0 it will return the 1st X - * column. - * - * @param index the index - * @return the corresponding X column - */ - public DataColumn getXColumn(int index) { - Vector xcols = (Vector) getAllColumnsByType(DataColumnType.X); - - if ((xcols == null) || (index >= xcols.size())) { - return null; - } - - return xcols.get(index); - } - - /** - * Get the style for the curve at the given index. - * - * @param index the curve index. - * @return the style - */ - public IStyled getCurveStyle(int index) { - DataColumn curve = getCurve(index); - return (curve == null) ? null : curve.getStyle(); - } - - /** - * Compute the "standard" standard deviation (divide variance by N) using an - * accurate one-pass method. - * - * @param x the data - * @return the standard deviation - */ - public static double standardDev(double x[]) { - if ((x == null) || (x.length == 0)) { - return Double.NaN; - } - - int n = x.length; - if (n == 1) { - return 0; - } - - double m = x[0]; - double q = 0; - for (int k = 2; k <= n; k++) { - double fac = (x[k - 1] - m); - double fac2 = fac / k; - m = m + fac2; - q = q + (k - 1) * fac * fac2; - } - double var = q / n; - - if (var <= 0.) { - return 0.0; - } - return Math.sqrt(var); - - } - - /** - * Get the DataSet type - * - * @return the data set type - */ - public DataSetType getType() { - return _type; - } - - /** - * Get the minimum value of a column - * - * @param index the index of the column - * @return the minimum value of the x data - */ - public double getColumnMin(int index) { - return getColumn(index).getMinValue(); - } - - /** - * Get the maximum value of a column - * - * @param index the index of the column - * @return the maximum value of the x data - */ - public double getColumnMax(int index) { - return getColumn(index).getMaxValue(); - } - - /** - * Get a collection of all the curves that are set visible. - * - * @return a collection of all the curves that are set visible. - */ - public Collection getAllVisibleCurves() { - Vector v = new Vector(); - for (DataColumn col : _columns) { - if (col.getType() == DataColumnType.Y) { - if (col.isVisible()) { - v.add(col); - } - } - } - return v; - } - - /** - * Get all curves, visible or not - * - * @return a collection of all the curves, visible or not - */ - public Collection getAllCurves() { - Vector v = new Vector(); - for (DataColumn col : _columns) { - if (col.getType() == DataColumnType.Y) { - v.add(col); - } - } - return v; - } - - /** - * Get a count of all the curves - * - * @return a count of all the curves - */ - public int getCurveCount() { - Collection v = getAllCurves(); - return v.size(); - } - - /** - * Has any data been added - * - * @return {@code true} if any data has been added. - */ - public boolean dataAdded() { - for (DataColumn col : _columns) { - if (col.getType() == DataColumnType.Y) { - if (col.size() > 0) { - return true; - } - } - } - return false; - } - - /** - * Get all the columns of a given type. For example, all the Y columns - * - * @param type the type to match - * @return all the matching columns - */ - public Collection getAllColumnsByType(DataColumnType type) { - Vector v = new Vector(); - for (DataColumn col : _columns) { - if (col.getType() == type) { - v.add(col); - } - } - return v; - } - - /** - * Get all the histo data - * - * @return a collection of the histo data - */ - public Vector getAllHistos() { - Vector v = new Vector(); - if (is1DHistoSet()) { - Collection ycols = getAllColumnsByType(DataColumnType.Y); - if (!ycols.isEmpty()) { - for (DataColumn yc : ycols) { - if (yc.isHistogram1D()) { - v.add(yc.getHistoData()); - } - else { - System.err.println("All Y columns in a HistoDataset must be hitograms"); - System.exit(1); - } - } - } - } - else { - System.err.println("Should not be asking for histos in a non-histo dataset."); - System.exit(1); - } - return v; - } - - /** - * Convenience method to get the minimum value of the x data - * - * @return the minimum value of the x data - */ - public double getXmin() { - double xmin = Double.POSITIVE_INFINITY; - if (is1DHistoSet()) { - Vector histos = getAllHistos(); - if (!histos.isEmpty()) { - for (HistoData hd : histos) { - xmin = Math.min(xmin, hd.getMinX()); - } - } - } - else { - xmin = getDataMin(DataColumnType.X); - } - return xmin; - } - - /** - * Convenience method to get the maximum value of the x data - * - * @return the minimum value of the x data - */ - public double getXmax() { - - double xmax = Double.NEGATIVE_INFINITY; - if (is1DHistoSet()) { - Vector histos = getAllHistos(); - if (!histos.isEmpty()) { - for (HistoData hd : histos) { - xmax = Math.max(xmax, hd.getMaxX()); - } - } - } - else { - xmax = getDataMax(DataColumnType.X); - } - return xmax; - } - - /** - * Convenience function to get the minimum value of the y data. If there is more - * than one y column, it returns the overall minimum. - * - * @return the minimum value of the y data - */ - public double getYmin() { - double ymin = Double.POSITIVE_INFINITY; - if (is1DHistoSet()) { - Vector histos = getAllHistos(); - if (!histos.isEmpty()) { - for (HistoData hd : histos) { - ymin = Math.min(ymin, hd.getMinY()); - } - } - } - else { - ymin = getDataMin(DataColumnType.Y); - } - return ymin; - } - - /** - * Convenience function to get the maximum value of the y data. If there is more - * than one y column, it returns the overall maximum. - * - * @return the maximum value of the y data - */ - public double getYmax() { - double ymax = Double.NEGATIVE_INFINITY; - if (is1DHistoSet()) { - Vector histos = getAllHistos(); - if (!histos.isEmpty()) { - for (HistoData hd : histos) { - ymax = Math.max(ymax, hd.getMaxY()); - } - } - } - else { - ymax = getDataMax(DataColumnType.Y); - } - return ymax; - } - - /** - * Get the overall min for all columns of the given type - * - * @param type the type to match - * @return the overall min for the given type - */ - public double getDataMin(DataColumnType type) { - if (is1DHistoSet()) { - System.err.println("Should not be calling \"getDataMin\" for histo datasets"); - System.exit(1); - } - - double vmin = Double.POSITIVE_INFINITY; - - for (DataColumn dc : _columns) { - if (dc.getType() == type) { - vmin = Math.min(vmin, dc.getMinValue()); - } - } - return vmin; - } - - /** - * Get the overall max for all columns of the given type - * - * @param type the type to match - * @return the overall max for the given type - */ - public double getDataMax(DataColumnType type) { - if (is1DHistoSet()) { - System.err.println("Should not be calling \"getDataMax\" for histo datasets"); - System.exit(1); - } - - double vmax = Double.NEGATIVE_INFINITY; - - for (DataColumn dc : _columns) { - if (dc.getType() == type) { - vmax = Math.max(vmax, dc.getMaxValue()); - } - } - return vmax; - } - - /** - * Get the minimal array of a column. The minimal array is a copy from the - * underlying GrowableArray that is the same size as the amount of real data. - * - * @param index the column index - * @return the minimal array - */ - public double[] getMinimalArray(int index) { - return getColumn(index).getMinimalCopy(); - } - - /** - * Get the size of the real data, This is the same as the row count. - * - * @return the data count - */ - public int getSize() { - return getRowCount(); - } - - /** - * Get the fit for a given column - * - * @param index the column index - * @return the fit for the column - */ - public Fit getFit(int index) { - return getColumn(index).getFit(); - } - - /** - * Add data values. This is the only entry point. - * - * @param vals a variable number of entries for the columns - */ - public void add(double... vals) throws DataSetException { - - int count = (vals == null) ? 0 : vals.length; - - if (_type == DataSetType.H2D) { - if (count == 2) { - getColumn(0).histo2DAdd(vals[0], vals[1]); - } - return; - } - - if (count > getColumnCount()) { - String msg = "Expected " + getColumnCount() + " values in add, but got: " + count; - throw new DataSetException(msg); - } - - for (int i = 0; i < count; i++) { - getColumn(i).add(vals[i]); - } - - notifyListeners(); - } - - /** - * Add data value to a specific column. - * - * @param column the column - * @param val the value - */ - public void add(int column, double val) throws DataSetException { - - if (column >= getColumnCount()) { - String msg = "In DataSet add, only " + getColumnCount() + " columns, but got column index of : " + column; - throw new DataSetException(msg); - } - - getColumn(column).add(val); - - notifyListeners(); - } - - /** - * Clear all the data. - */ - public void clear() { - for (DataColumn dc : _columns) { - dc.clear(); - } - notifyListeners(); - } - - // notify listeners of a change in the data - public void notifyListeners() { - -// fireTableDataChanged(); - - if (_listenerList == null) { - return; - } - - // Guaranteed to return a non-null array - Object[] listeners = _listenerList.getListenerList(); - - // This weird loop is the bullet proof way of notifying all listeners. - // for (int i = listeners.length - 2; i >= 0; i -= 2) { - // order is flipped so it goes in order as added - for (int i = 0; i < listeners.length; i += 2) { - if (listeners[i] == DataChangeListener.class) { - DataChangeListener listener = (DataChangeListener) listeners[i + 1]; - listener.dataSetChanged(this); - } - - } - } - - /** - * Add a data change listener - * - * @param DataChangeListener the listener to add - */ - public void addDataChangeListener(DataChangeListener DataChangeListener) { - - if (_listenerList == null) { - _listenerList = new EventListenerList(); - } - - // avoid adding duplicates - _listenerList.remove(DataChangeListener.class, DataChangeListener); - _listenerList.add(DataChangeListener.class, DataChangeListener); - } - - /** - * Remove a DataChangeListener. - * - * @param DataChangeListener the DataChangeListener to remove. - */ - - public void removeDataChangeListener(DataChangeListener DataChangeListener) { - - if ((DataChangeListener == null) || (_listenerList == null)) { - return; - } - - _listenerList.remove(DataChangeListener.class, DataChangeListener); - } - - /** - * Get the style for a column - * - * @param index the column index - * @return the style for this dataset - */ - public Styled getColumnStyle(int index) { - return getColumn(index).getStyle(); - } - - /** - * Get all the data columns - * - * @return all the data columns - */ - public Collection getColumns() { - return _columns; - } - - /** - * Get the column at a specific index - * - * @param index the column index - * @return the column at a specific index - */ - public DataColumn getColumn(int index) { - return _columns.get(index); - } - - @Override - public int getRowCount() { - - int rowCount = 0; - if (getColumnCount() != 0) { - DataColumn dc = _columns.firstElement(); - - if (is1DHistoSet()) { - HistoData hd = dc.getHistoData(); - return hd.getNumberBins(); - } - else if (is2DHistoSet()) { - Histo2DData h2d = dc.getHistoData2D(); - return (h2d == null) ? 0 : 1; - } - else { - rowCount = dc.size(); - } - } - return rowCount; - } - - @Override - public int getColumnCount() { - return _columns == null ? 0 : _columns.size(); - } - - @Override - public Class getColumnClass(int columnIndex) { - return DataColumn.class; - } - - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - if (columnIndex >= getColumnCount()) { - return false; - } - DataColumn col = getColumn(columnIndex); - return rowIndex < col.size(); - } - - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - DataColumn dc = getColumn(columnIndex); - - if (rowIndex >= dc.size()) { - return ""; - } - - double val = dc.get(rowIndex); - - if (Double.isNaN(val)) { - return ""; - } - - double split[] = intFract(-val); - boolean asInt = (split[0] != 0.) && Math.abs(split[1]) < 1.0e-6; - - String s = asInt ? DoubleFormat.doubleFormat(val, 0) : DoubleFormat.doubleFormat(val, 4, 2); - return s; - } - - private static double[] intFract(double d) { - BigDecimal bd = BigDecimal.valueOf(d); - return new double[] { bd.intValue(), bd.remainder(BigDecimal.ONE).doubleValue() }; - } - - @Override - public void setValueAt(Object aValue, int rowIndex, int columnIndex) { - DataColumn dc = getColumn(columnIndex); - dc.set(rowIndex, (Double) aValue); - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataSetException.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataSetException.java deleted file mode 100644 index 19be761d86..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataSetException.java +++ /dev/null @@ -1,8 +0,0 @@ -package cnuphys.splot.pdata; - -public class DataSetException extends Exception { - - public DataSetException(String message) { - super(message); - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataSetType.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataSetType.java deleted file mode 100644 index ccbdf2d551..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataSetType.java +++ /dev/null @@ -1,20 +0,0 @@ -package cnuphys.splot.pdata; - -/** - * Types of data sets - * - * @author heddle These are the different types of data sets. - *
    - *
  • XYY An arbitrary number of y sets sharing the same x - *
  • XYXY An arbitrary number of (x, y) columns - *
  • XYEXYE An arbitrary number of (x, y, yerr) columns - *
  • XYEEXYEE An arbitrary number of (x, y, xerr, yerr) - * columns - *
  • H1D Data values for a 1D histogram - *
  • H2D Data values for a 2D histogram - *
  • STRIP xy strip chart - */ -public enum DataSetType { - XYY, XYXY, XYEXYE, XYEEXYEE, H1D, H2D, STRIP, UNKNOWN; - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataTable.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataTable.java deleted file mode 100644 index 78fd697533..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/DataTable.java +++ /dev/null @@ -1,216 +0,0 @@ -package cnuphys.splot.pdata; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Font; - -import javax.swing.AbstractCellEditor; -import javax.swing.BorderFactory; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.ListSelectionModel; -import javax.swing.SwingConstants; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.DefaultTableModel; -import javax.swing.table.JTableHeader; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableColumn; - -import cnuphys.splot.plot.Environment; - -public class DataTable extends JTable { - - private double _currentValue = Double.NaN; - - // a scroll pane for this table - private JScrollPane _scrollPane; - - // the table font - protected static Font _tableFont = Environment.getInstance().getCommonFont(10); - - public DataTable(DataSet dataSet) { - super(dataSet); - getFontMetrics(_tableFont).stringWidth(" 9.99999E-99 "); - setFont(_tableFont); - - // listen for clicks on header so we can sort - JTableHeader header = getTableHeader(); - - setRowHeight(getFontMetrics(_tableFont).getHeight() + 4); - - // selection - setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - setRowSelectionAllowed(false); - setColumnSelectionAllowed(false); - setCellSelectionEnabled(true); - - // header rendering - header.setPreferredSize(new Dimension(100, 20)); - header.setBackground(Color.orange); - header.setBorder(BorderFactory.createLineBorder(Color.black)); - DefaultTableCellRenderer dtcr = (DefaultTableCellRenderer) header.getDefaultRenderer(); - dtcr.setHorizontalAlignment(SwingConstants.CENTER); - header.setDefaultRenderer(dtcr); - - getTableHeader().setResizingAllowed(true); - setShowGrid(true); - setGridColor(Color.gray); - - if (dataSet != null) { - for (int i = 0; i < dataSet.getColumnCount(); i++) { - TableColumn col = getColumnModel().getColumn(i); - dtcr = new DefaultTableCellRenderer(); - dtcr.setHorizontalAlignment(SwingConstants.CENTER); - col.setCellRenderer(dtcr); - col.setCellEditor(new MyTableCellEditor()); - } - } - - ListSelectionListener sl = new ListSelectionListener() { - - @Override - public void valueChanged(ListSelectionEvent e) { - if (e.getValueIsAdjusting()) { - return; - } - int row = getSelectedRow(); - int col = getSelectedColumn(); - - if ((row >= 0) && (col >= 0)) { - selectedCell(row, col); - } - - } - - }; - - // yes you have to do both - getSelectionModel().addListSelectionListener(sl); - getColumnModel().getSelectionModel().addListSelectionListener(sl); - - } - - protected void selectedCell(int row, int col) { - try { - _currentValue = Double.parseDouble((String) getModel().getValueAt(row, col)); - } - catch (Exception e) { - _currentValue = Double.NaN; - } - } - - /** - * Get the scroll pane for this data table - * - * @return the scroll pane for this data table - */ - public JScrollPane getScrollPane() { - if (_scrollPane == null) { - _scrollPane = new JScrollPane(this); - } - return _scrollPane; - } - - // @Override - // public Dimension getPreferredSize() { - // return new Dimension(getModel().getColumnCount()*DEFCOLWIDTH, 500); - // } - - /** - * main program for testing. - * - * @param args - */ - public static void main(String[] args) { - javax.swing.JFrame testFrame = new javax.swing.JFrame("test frame"); - java.awt.Container cp = testFrame.getContentPane(); - testFrame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); - - cp.setLayout(new BorderLayout(4, 0)); - - String names[] = { "X1", "Y1", "E1", "X2", "Y2", "E2" }; - DataSet ds = null; - try { - ds = new DataSet(DataSetType.XYEXYE, names); - } - catch (DataSetException e1) { - e1.printStackTrace(); - System.exit(1); - } - - for (int i = 0; i < 15; i++) { - try { - if (i < 10) { - ds.add(i, i + 2 * Math.random(), 2.0 * Math.random(), i + 0.5, 10 - i + 2 * Math.random(), - 2.0 * Math.random()); - } - else { - ds.add(i, i + 2 * Math.random(), 2.0 * Math.random()); - } - } - catch (DataSetException e) { - e.printStackTrace(); - System.exit(1); - } - // ds.add(i, i); - } - - DataTable table = new DataTable(ds); - cp.add(table.getScrollPane(), BorderLayout.CENTER); - - testFrame.pack(); - testFrame.setVisible(true); - } - - public class MyTableCellEditor extends AbstractCellEditor implements TableCellEditor { - - // This is the component that will handle the editing of the cell value - JTextField component = new JTextField(); - - int column; - - // This method is called when a cell value is edited by the user. - @Override - public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int rowIndex, - int colIndex) { - - column = colIndex; - component.setFont(_tableFont); - component.setHorizontalAlignment(SwingConstants.CENTER); - Environment.getInstance().commonize(component, Color.yellow); - - // Configure the component with the specified value - component.setText((String) value); - - // Return the configured component - return component; - } - - // This method is called when editing is completed. - // It must return the new value to be stored in the cell. - @Override - public Object getCellEditorValue() { - double val = Double.NaN; - try { - val = Double.parseDouble(component.getText()); - - if (val != _currentValue) { - ((DefaultTableModel) getModel()).fireTableDataChanged(); - DataColumn dc = null; - DataSet ds = (DataSet) getModel(); - ds.setAllFitsDirty(); - } - } - catch (NumberFormatException e) { - val = _currentValue; - } - return val; - } - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/GrowableArray.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/GrowableArray.java deleted file mode 100644 index 0ca90d04fd..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/GrowableArray.java +++ /dev/null @@ -1,185 +0,0 @@ -package cnuphys.splot.pdata; - -/** - * This class supports named arrays that grow. They are an alternative to - * Vectors or ArrayLists. The advantages are speed and usage for those cases - * where arrays are more convenient. Clients only have access to minimal copies - * which can be used as "just the right size" arrays. - * - * @author heddle - * - */ -public class GrowableArray { - - // the actual array - protected double _data[]; - - // the current size (amount of data, not capacity) of the array - // this will be the size of the minimal copy - protected int _dataLen; - - // the increment when the array must grow - protected int _increment; - - // the initial capacity - protected int _initCap; - - // min and max data values - protected double _minValue; - protected double _maxValue; - - /** - * Creates a GrowableArray with initial capacity 100 and increment 100. - */ - public GrowableArray() { - this(100, 100); - } - - /** - * Create a GrowableArray - * - * @param initCap the initial capacity - * @param increment the increment when the array grows. - */ - public GrowableArray(int initCap, int increment) { - _initCap = initCap; - _increment = increment; - clear(); - } - - /** - * Get the number of real data in the array, which in general is less than the - * length of the array. This is the effective length of the array, so loops - * should go from 0 to this value minus 1. - * - * @return the number of real data. - */ - public int size() { - return _dataLen; - } - - /** - * Get the minimal copy of the data array. This copies the actual data into a - * new array of just the right size. This new array can be used normally, i.e., - * it is safe to use its length. - * - * @return a copy of the data array of just the right length - */ - public double[] getMinimalCopy() { - if (_dataLen == 0) { - return null; - } - double acopy[] = new double[_dataLen]; - - try { - System.arraycopy(_data, 0, acopy, 0, _dataLen); - } - catch (Exception e) { - - System.err.println("Exception in GrowableArray.getMinimalCopy: " + e.getMessage()); - System.err.println("_dataLen: " + _dataLen); - } - return acopy; - } - - /** - * removes the first entry and moves all other entries up one - */ - public void removeFirst() { - if (_dataLen > 0) { - _dataLen--; - - _minValue = Double.POSITIVE_INFINITY; - _maxValue = Double.NEGATIVE_INFINITY; - for (int i = 0; i < _dataLen; i++) { - _data[i] = _data[i + 1]; - _minValue = Math.min(_data[i], _minValue); - _maxValue = Math.max(_data[i], _maxValue); - } - _data[_dataLen] = Double.NaN; - } - } - - /** - * Add a value to the array, growing it if necessary. - * - * @param val the value to add - */ - public void add(double val) { - if (_dataLen == _data.length) { - double newArray[] = new double[_dataLen + _increment]; - System.arraycopy(_data, 0, newArray, 0, _dataLen); - - // fill empty space with NaNs - for (int i = _dataLen; i < newArray.length; i++) { - newArray[i] = Double.NaN; - } - _data = newArray; - } - _data[_dataLen] = val; - _dataLen++; - - // fix min and max vals - if (_dataLen == 1) { - _minValue = val; - _maxValue = val; - } - else { - _minValue = Math.min(_minValue, val); - _maxValue = Math.max(_maxValue, val); - } - } - - /** - * Get the minimum data value - * - * @return the minimum data value - */ - public double getMinValue() { - return _minValue; - } - - /** - * Get the maximum data value - * - * @return the maximum data value - */ - public double getMaxValue() { - return _maxValue; - } - - /** - * Reset the data array to the initial capacity and fill with all NaNs. - */ - public void clear() { - _data = new double[_initCap]; - _dataLen = 0; - for (int i = 0; i < _initCap; i++) { - _data[i] = Double.NaN; - } - - _minValue = Double.NaN; - _maxValue = Double.NaN; - } - - /** - * Get the value at the given index - * - * @param index the index - * @return the value at the index - */ - public double get(int index) { - return _data[index]; - } - - /** - * Set the value at the given index - * - * @param index the index - * @param val the value at the index - */ - public void set(int index, double val) { - _data[index] = val; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/Histo2DData.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/Histo2DData.java deleted file mode 100644 index b4d634ad28..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/Histo2DData.java +++ /dev/null @@ -1,556 +0,0 @@ -package cnuphys.splot.pdata; - -import java.awt.Point; -import java.awt.geom.Rectangle2D; -import java.util.Arrays; - -import cnuphys.splot.plot.DoubleFormat; -import cnuphys.splot.plot.PlotCanvas; -import cnuphys.splot.plot.PlotParameters; - -public class Histo2DData { - - private static int OUTOFRANGE = -100; - - // this is the over all name - private String _name; - - // the x an y variable names - private String _xName; - private String _yName; - - // some counts - private long _outOfRangeCount; - - // the X bins--it includes the limits so there is one more number - // that the number of bins, eg {0, 1, 3, 7} means 3 bins. Note - // equal spacing is not required. - private double _gridX[]; - - // the Y bins--it includes the limits so there is one more number - // that the number of bins, eg {0, 1, 3, 7} means 3 bins. Note - // equal spacing is not required. - private double _gridY[]; - - // the counts - private long[][] _counts; - - // the bin with the max counts - private long _maxCount; - - /** - * The data for a 2D histogram where the bin spacing is uniform. - * - * @param name the name - * @param xname the x variable name - * @param yname the y variable name - * @param valMinX - * @param valMaxX - * @param numBinsX - * @param valMinY - * @param valMaxY - * @param numBinsY - */ - public Histo2DData(String name, String xname, String yname, double valMinX, double valMaxX, int numBinsX, - double valMinY, double valMaxY, int numBinsY) { - - this(name, xname, yname, evenBins(valMinX, valMaxX, numBinsX), evenBins(valMinY, valMaxY, numBinsY)); - } - - /** - * The data for a 2D histogram where the bin spacing is arbitrary (i.e., not - * uniform) - * - * @param name the curve name of the histogram - * @param xname the x variable name - * @param yname the y variable name - * @param gridX the binning grid. It must be in ascending order but is otherwise - * arbitrary. - * @param gridY the binning grid. It must be in ascending order but is otherwise - * arbitrary. - */ - public Histo2DData(String name, String xname, String yname, double[] gridX, double[] gridY) { - _name = name; - _xName = xname; - _yName = yname; - _gridX = gridX; - _gridY = gridY; - clear(); - } - - /** - * Get the name of the histogram - * - * @return the name of the histogram - */ - public String getName() { - return _name; - } - - /** - * Set the name - * - * @param name the name of the histogram - */ - public void setName(String name) { - _name = name; - } - - // reset some data - private void reset() { - _outOfRangeCount = 0; - _maxCount = 0; - _counts = null; - int nbinX = getNumberBinsX(); - int nbinY = getNumberBinsY(); - - if ((nbinX > 0) && (nbinY > 0)) { - _counts = new long[nbinX][nbinY]; - for (int i = 0; i < nbinX; i++) { - for (int j = 0; j < nbinY; j++) { - _counts[i][j] = 0; - } - } - } - } - - - /** - * Clear the data - */ - public void clear() { - reset(); - } - - // get an array of equally spaced bins - // suitable for most histograms - private static double[] evenBins(double vmin, double vmax, int numBins) { - double grid[] = new double[numBins + 1]; - double del = (vmax - vmin) / numBins; - - grid[0] = vmin; - grid[numBins] = vmax; - for (int i = 1; i < numBins; i++) { - grid[i] = vmin + i * del; - } - return grid; - } - - /** - * Get the counts - * - * @return the counts array - */ - public long[][] getCounts() { - return _counts; - } - - /** - * Get the number on entries in the histogram (excluding out of range) - * - * @return the number of entries - */ - public long getGoodCount() { - - long sum = 0; - if (_counts != null) { - int nbinX = getNumberBinsX(); - int nbinY = getNumberBinsY(); - - for (int i = 0; i < nbinX; i++) { - for (int j = 0; j < nbinY; j++) { - sum += _counts[i][j]; - } - } - } - return sum; - } - - /** - * Get the total count, including the out of range - * - * @return the total count, including the out of range - */ - public long getTotalCount() { - return getGoodCount() + getOutOfRangeCount(); - } - - /** - * Get the number on entries in the histogram that were out of range - * - * @return the number of entries out of range - */ - public long getOutOfRangeCount() { - return _outOfRangeCount; - } - - /** - * Get the minimum "x" value. This is the minimum of the range being binned. - * - * @return the minimum "x" value - */ - public double getMinX() { - return (_gridX == null) ? Double.NaN : _gridX[0]; - } - - /** - * Get the maximum "x" value. This is the maximum of the range being binned. - * - * @return the maximum "x" value - */ - public double getMaxX() { - return (_gridX == null) ? Double.NaN : _gridX[_gridX.length - 1]; - } - - /** - * Get the minimum "y" value. This is the minimum of the range being binned. - * - * @return the minimum "x" value - */ - public double getMinY() { - return (_gridY == null) ? Double.NaN : _gridY[0]; - } - - /** - * Get the maximum y value. This is the maximum of the range being binned. - * - * @return the maximum "y" value - */ - public double getMaxY() { - return (_gridY == null) ? Double.NaN : _gridY[_gridY.length - 1]; - } - - /** - * Get the minimum "z" value. The z axis corresponds to "counts", so this always - * returns 0 - */ - public double getMinZ() { - return 0.; - } - - /** - * Get the maximum count of any bin - * - * @return the count of the bin with the most counts. - */ - public long getMaxCount() { - return _maxCount; - } - - /** - * Add a value to the histogram - * - * @param valueX the value to add - * @param valueY the value to add - */ - public void add(double valueX, double valueY) { - - int binX = getBinX(valueX); - if (binX == OUTOFRANGE) { - _outOfRangeCount++; - return; - } - int binY = getBinY(valueY); - if (binY == OUTOFRANGE) { - _outOfRangeCount++; - return; - } - - // System.err.println(" BINX, BINY: " + binX + ", " + binY); - _counts[binX][binY]++; - - _maxCount = Math.max(_maxCount, _counts[binX][binY]); - } - - /** - * Get the number of x bins - * - * @return the number of x bins - */ - public int getNumberBinsX() { - return (_gridX == null) ? 0 : _gridX.length - 1; - } - - /** - * Get the number of x bins - * - * @return the number of x bins - */ - public int getNumberBinsY() { - return (_gridY == null) ? 0 : _gridY.length - 1; - } - - /** - * Get the "x" value of the middle of the bin - * - * @param bin the bin in question - * @return the x mid value - */ - public double getBinMidValueX(int bin) { - if ((bin < 0) || (bin >= getNumberBinsX())) { - return Double.NaN; - } - return 0.5 * (_gridX[bin] + _gridX[bin + 1]); - } - - /** - * Get the "y" value of the middle of the bin - * - * @param bin the bin in question - * @return the y mid value - */ - public double getBinMidValueY(int bin) { - if ((bin < 0) || (bin >= getNumberBinsY())) { - return Double.NaN; - } - return 0.5 * (_gridY[bin] + _gridY[bin + 1]); - } - - /** - * Get the "y" value of the right side of the bin - * - * @param bin the bin in question - * @return the y value of the right side - */ - public double getBinMaxY(int bin) { - if ((bin < 0) || (bin >= getNumberBinsY())) { - return Double.NaN; - } - return _gridY[bin + 1]; - } - - /** - * Get the "x" value of the right side of the bin - * - * @param bin the bin in question - * @return the x value of the right side - */ - public double getBinMaxX(int bin) { - if ((bin < 0) || (bin >= getNumberBinsX())) { - return Double.NaN; - } - return _gridX[bin + 1]; - } - - /** - * Get the "x" value of the left side of the bin - * - * @param bin the bin in question - * @return the x value of the left side - */ - public double getBinMinX(int bin) { - if ((bin < 0) || (bin >= getNumberBinsX())) { - return Double.NaN; - } - return _gridX[bin]; - } - - /** - * Get the "y" value of the left side of the bin - * - * @param bin the bin in question - * @return the y value of the left side - */ - public double getBinMinY(int bin) { - if ((bin < 0) || (bin >= getNumberBinsY())) { - return Double.NaN; - } - return _gridY[bin]; - } - - /** - * Get the x bin for a given x value. Will return the zero-based bin number or - * OUTOFRANGE. - * - * @param val the x value. - * @return return the x bin: [0..(numBinX-1)] or an error - */ - public int getBinX(double val) { - if (val < getMinX()) { - return OUTOFRANGE; - } - else if (val > getMaxX()) { - return OUTOFRANGE; - } - - int index = Arrays.binarySearch(_gridX, val); - // unlikely, but maybe we are exactly on a value - if (index < 0) { - index = -(index + 1); // now the insertion point. - } - int bin = index - 1; - - return bin; - } - - /** - * Get the y bin for a given y value. Will return the zero-based bin number or - * OUTOFRANGE. - * - * @param val the y value. - * @return return the y bin: [0..(numBinY-1)] or an error - */ - public int getBinY(double val) { - if (val < getMinY()) { - return OUTOFRANGE; - } - else if (val > getMaxY()) { - return OUTOFRANGE; - } - - int index = Arrays.binarySearch(_gridY, val); - // unlikely, but maybe we are exactly on a value - if (index < 0) { - index = -(index + 1); // now the insertion point. - } - int bin = index - 1; - - return bin; - } - - /** - * Get the world rectangle containing the given x and y values - * - * @param x the x value - * @param y the y value - * @return the world rectangle, or null. - */ - public Rectangle2D.Double getRectangle(double x, double y) { - int binX = getBinX(x); - int binY = getBinY(y); - return getRectangle(binX, binY); - } - - /** - * Get the world rectangle corresponding to the given bins - * - * @param binX the x bin - * @param binY the y bin - * @return the world rectangle, or null. - */ - public Rectangle2D.Double getRectangle(int binX, int binY) { - - if ((binX < 0) || (binY < 0)) { - return null; - } - - double xmin = getBinMinX(binX); - if (Double.isNaN(xmin)) { - return null; - } - - double xmax = getBinMaxX(binX); - if (Double.isNaN(xmax)) { - return null; - } - - double ymin = getBinMinY(binY); - if (Double.isNaN(ymin)) { - return null; - } - - double ymax = getBinMaxY(binY); - if (Double.isNaN(ymax)) { - return null; - } - - return new Rectangle2D.Double(xmin, ymin, (xmax - xmin), (ymax - ymin)); - } - - /** - * Get the fractional value (fraction of max value) for use in a plot - * - * @param binX the x bin - * @param binY the y bin - * @return the fractional value (fraction of max value). - */ - public double getFractionalValue(int binX, int binY) { - if (_maxCount < 1) { - return 0; - } - - if ((binX < 0) || (binY < 0)) { - return 0; - } - - long count = _counts[binX][binY]; - - return ((double) count) / ((double) _maxCount); - - } - - /** - * Get the status string - * - * @param canvas the plot canvas - * @param histo the histo data object - * @param mousePoint where the mouse is - * @param wp the data coordinates of the mouse - * @return a status string - */ - public static String statusString(PlotCanvas canvas, Histo2DData histo, Point mousePoint, Point.Double wp) { - String s = "[" + histo.getName() + "] "; - int xBin = histo.getBinX(wp.x); - int yBin = histo.getBinY(wp.y); - - if ((xBin > -1) && (yBin > -1)) { - PlotParameters params = canvas.getParameters(); - String xMinStr = DoubleFormat.doubleFormat(histo.getBinMinX(xBin), params.getNumDecimalX(), - params.getMinExponentX()); - String xMaxStr = DoubleFormat.doubleFormat(histo.getBinMaxX(xBin), params.getNumDecimalX(), - params.getMinExponentX()); - - String yMinStr = DoubleFormat.doubleFormat(histo.getBinMinY(yBin), params.getNumDecimalY(), - params.getMinExponentY()); - String yMaxStr = DoubleFormat.doubleFormat(histo.getBinMaxY(yBin), params.getNumDecimalY(), - params.getMinExponentY()); - - s += histo.getName() + "] xbin: " + xBin + " [" + xMinStr + " - " + xMaxStr + "] ybin: " + yBin + " [" - + yMinStr + " - " + yMaxStr + "]"; - s += " counts: " + histo.getCount(xBin, yBin); - } - - return s; - } - - /** - * Get the count for a given bin double - * - * @param xbin the x bin - * @param ybin the y bin - * @return the count for that bin double - */ - public long getCount(int xbin, int ybin) { - if (_counts == null) { - return 0; - } - - if ((xbin < 0) || (xbin >= this.getNumberBinsX())) { - return 0; - } - - if ((ybin < 0) || (ybin >= this.getNumberBinsY())) { - return 0; - } - return _counts[xbin][ybin]; - } - - /** - * Get the name for the x axis variable - * - * @return the name for the x axis variable - */ - public String getXName() { - return _xName; - } - - /** - * Get the name for the y axis variable - * - * @return the name for the y axis variable - */ - public String getYName() { - return _yName; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/HistoData.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/HistoData.java deleted file mode 100644 index 14b9271614..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/HistoData.java +++ /dev/null @@ -1,554 +0,0 @@ -package cnuphys.splot.pdata; - -import java.awt.Point; -import java.awt.Polygon; -import java.util.Arrays; -import cnuphys.splot.plot.DoubleFormat; -import cnuphys.splot.plot.PlotCanvas; -import cnuphys.splot.plot.PlotParameters; -import cnuphys.splot.plot.UnicodeSupport; - -/** - * Xontainer class for histogram data - * - * @author heddle - * - */ -public class HistoData { - - /** The XML root element name */ - public static final String XmlRootElementName = "HistoData"; - - // cached statistical results - // an array with the mean in the 0 index, - // standard deviation is the 1 index, and rms in the 2 index - private double _stats[]; - - // out of range constants - private static int UNDERFLOW = -200; - private static int OVERFLOW = -100; - - // this is the "curve" name - private String _name; - - // some counts - private long _underCount; - private long _overCount; - - // true for even bin spacing - private boolean _uniformBins; - - // use rms or sigma in legend - private boolean _rmsInHistoLegend = true; - - // draw sqrt(n) statistical errors - private boolean _statErrors; - - // the bins--it includes the limits so there is one more number - // that the number of bins, eg {0, 1, 3, 7} means 3 bins. Note - // equal spacing is not required. - private double _grid[]; - - // the counts - private long[] _counts; - - /** - * The data for a 1D histogram where the bin spacing is uniform. - * - * @param name the curve name of the histogram - * @param valMin the data min - * @param valMax the data max - * @param numBins the number of bins - */ - public HistoData(String name, double valMin, double valMax, int numBins) { - this(name, evenBins(valMin, valMax, numBins)); - _uniformBins = true; - } - - - /** - * The data for a 1D histogram where the bin spacing is arbitrary (i.e., not - * uniform) - * - * @param name the curve name of the histogram - * @param grid the binning grid. It must be in ascending order but is otherwise - * arbitrary. - */ - public HistoData(String name, double[] grid) { - _name = name; - _grid = grid; - clear(); - } - - /** - * Get the name of the histogram - * - * @return the name of the histogram - */ - public String getName() { - return _name; - } - - /** - * Set the name - * - * @param name the name of the histogram - */ - public void setName(String name) { - _name = name; - } - - // reset some data - private void reset() { - _underCount = 0; - _overCount = 0; - _stats = null; - int nbin = getNumberBins(); - if (nbin > 0) { - _counts = new long[nbin]; - for (int i = 0; i < nbin; i++) { - _counts[i] = 0; - } - } - } - - /** - * Get the count for a given bin - * - * @param bin the bin - * @return the count for that bin - */ - public long getCount(int bin) { - if (_counts == null) { - return 0; - } - - if ((bin < 0) || (bin >= _counts.length)) { - return 0; - } - - return _counts[bin]; - } - - /** - * Clear the data - */ - public void clear() { - reset(); - } - - // get an array of equally spaced bins - // suitable for most histograms - private static double[] evenBins(double vmin, double vmax, int numBins) { - double grid[] = new double[numBins + 1]; - double del = (vmax - vmin) / numBins; - - grid[0] = vmin; - grid[numBins] = vmax; - for (int i = 1; i < numBins; i++) { - grid[i] = vmin + i * del; - } - return grid; - } - - /** - * Get the means and standard deviation - * - * @return an array with the mean in the 0 index, standard deviation is the 1 - * index, and rms in the 2 index - */ - public double[] getBasicStatistics() { - - if (_stats != null) { - return _stats; - } - - _stats = new double[3]; - _stats[0] = Double.NaN; - _stats[1] = Double.NaN; - _stats[2] = Double.NaN; - int nbin = getNumberBins(); - long totcount = getGoodCount(); - if ((nbin > 0) && (totcount > 0)) { - - double sum = 0; - double sumsq = 0; - for (int bin = 0; bin < nbin; bin++) { - double x = getBinMidValue(bin); - double wx = _counts[bin] * x; - sum += wx; - sumsq += x * wx; - } - - double avgSq = sumsq / totcount; - - _stats[0] = sum / totcount; // mean - _stats[1] = Math.sqrt(avgSq - (_stats[0] * _stats[0])); // stdDev - _stats[2] = Math.sqrt(avgSq); // rms - } - - return _stats; - } - - /** - * A string displaying some statistics - * - * @return a string with statistics info - */ - public String statStr() { - double res[] = getBasicStatistics(); - if (_rmsInHistoLegend) { - return String.format(UnicodeSupport.SMALL_MU + ": %-4.2g " + "rms: %-4.2g under: %d over: %d", res[0], res[2], _underCount, _overCount); - } - else { - return String.format(UnicodeSupport.SMALL_MU + ": %-4.2g " + UnicodeSupport.SMALL_SIGMA + ": %-4.2g under: %d over: %d", - res[0], res[1], _underCount, _overCount); - } - } - - /** - * Get the counts - * - * @return the counts array - */ - public long[] getCounts() { - return _counts; - } - - /** - * Get the number on entries in the histogram (excluding underflows and - * overflows) - * - * @return the number of entries - */ - public long getGoodCount() { - - long sum = 0; - if (_counts != null) { - for (long lv : _counts) { - sum += lv; - } - } - return sum; - } - - /** - * Get the total count, including the unders and overs - * - * @return the total count, including the unders and overs - */ - public long getTotalCount() { - return getGoodCount() + getUnderCount() + getOverCount(); - } - - /** - * Get the number on entries in the histogram that were below the minimum value - * - * @return the number of entries below the minimum value - */ - public long getUnderCount() { - return _underCount; - } - - /** - * Get the number on entries in the histogram that were above the maximum value - * - * @return the number of entries above the maximum value - */ - public long getOverCount() { - return _overCount; - } - - /** - * Get the minimum "x" value. This is the minimum of the range being binned. - * - * @return the minimum "x" value - */ - public double getMinX() { - return (_grid == null) ? Double.NaN : _grid[0]; - } - - /** - * Get the minimum value. This is the maximum of the range being binned. - * - * @return the minimum "x" value - */ - public double getMaxX() { - return (_grid == null) ? Double.NaN : _grid[_grid.length - 1]; - } - - /** - * Get the minimum "y" value. The y axis corresponds to "counts", so this always - * returns 0 - */ - public double getMinY() { - return 0.; - } - - /** - * Get the maximum "y" value. The y axis corresponds to "counts", so this always - * returns the count of the bin with the most counts. - */ - public double getMaxY() { - if (_counts == null) { - return 1; - } - - long maxCount = 1; - for (long bc : _counts) { - maxCount = Math.max(maxCount, bc); - } - - return maxCount; - } - - /** - * Add a value to the histogram - * - * @param value the value to ad - */ - public void add(double value) { - _stats = null; - int bin = getBin(value); - if (bin == UNDERFLOW) { - _underCount++; - } - else if (bin == OVERFLOW) { - _overCount++; - } - else { - _counts[bin]++; - } - - } - - /** - * Set a bin to a given count - * - * @param val the x val will determine bin - * @param count the count - */ - public void setCount(double val, int count) { - _stats = null; - int bin = getBin(val); - if (bin == UNDERFLOW) { - _underCount += count; - } - else if (bin == OVERFLOW) { - _overCount += count; - } - else { - _counts[bin] = count; - } - } - - /** - * Get the number of bins - * - * @return the number of bins - */ - public int getNumberBins() { - return (_grid == null) ? 0 : _grid.length - 1; - } - - /** - * Get the "x" value of the middle of the bin - * - * @param bin the bin in question - * @return the mid value - */ - public double getBinMidValue(int bin) { - if ((bin < 0) || (bin >= getNumberBins())) { - return Double.NaN; - } - return 0.5 * (_grid[bin] + _grid[bin + 1]); - } - - /** - * Get the "x" value of the right side of the bin - * - * @param bin the bin in question - * @return the x value of the right side - */ - public double getBinMaxX(int bin) { - if ((bin < 0) || (bin >= getNumberBins())) { - return Double.NaN; - } - return _grid[bin + 1]; - } - - /** - * Get the "x" value of the left side of the bin - * - * @param bin the bin in question - * @return the x value of the left side - */ - public double getBinMinX(int bin) { - if ((bin < 0) || (bin >= getNumberBins())) { - return Double.NaN; - } - return _grid[bin]; - } - - /** - * Get the bin for a given value. Will return the zero-based bin number or - * UNDERFLOW or OVERFLOW. - * - * @param val the value. - * @return return the bin: [0..(numBin-1)] or an error - */ - public int getBin(double val) { - if (val < getMinX()) { - return UNDERFLOW; - } - else if (val > getMaxX()) { - return OVERFLOW; - } - - int index = Arrays.binarySearch(_grid, val); - // unlikely, but maybe we are exactly on a value - if (index < 0) { - index = -(index + 1); // now the insertion point. - } - int bin = index - 1; - - if (bin < 0) { - // System.err.println("Fix negative bin " + bin); - bin = 0; - } - return bin; - } - - /** - * Get the status string - * - * @param canvas the plot canvas - * @param histo the histo data object - * @param mousePoint where the mouse is - * @param wp the data coordinates of the mouse - * @return a status string - */ - public static String statusString(PlotCanvas canvas, HistoData histo, Point mousePoint, Point.Double wp) { - String s = null; - - Polygon poly = GetPolygon(canvas, histo); - if (poly.contains(mousePoint)) { - int bin = histo.getBin(wp.x); - - PlotParameters params = canvas.getParameters(); - String minstr = DoubleFormat.doubleFormat(histo.getBinMinX(bin), params.getNumDecimalX(), - params.getMinExponentX()); - String maxstr = DoubleFormat.doubleFormat(histo.getBinMaxX(bin), params.getNumDecimalX(), - params.getMinExponentX()); - - String name = histo.getName(); - if ((name != null) && (name.length() > 0)) { - name = "[" + name + "]"; - } - else { - name = ""; - } - - s = name + " bin: " + bin + " [" + minstr + " - " + maxstr + "]"; - s += " counts: " + histo.getCount(bin); - } - - return s; - } - - /** - * Get the drawing polygon - * - * @param canvas the drawing canvas - * @param histo the histo data - * @return the polygon - */ - public static Polygon GetPolygon(PlotCanvas canvas, HistoData histo) { - Polygon poly = new Polygon(); - long counts[] = histo.getCounts(); - Point pp = new Point(); - Point.Double wp = new Point.Double(); - - for (int bin = 0; bin < histo.getNumberBins(); bin++) { - double xmin = histo.getBinMinX(bin); - double xmax = histo.getBinMaxX(bin); - double y = counts[bin]; - - if (bin == 0) { - wp.setLocation(xmin, 0); - canvas.worldToLocal(pp, wp); - poly.addPoint(pp.x, pp.y); - } - - wp.setLocation(xmin, y); - canvas.worldToLocal(pp, wp); - poly.addPoint(pp.x, pp.y); - wp.setLocation(xmax, y); - canvas.worldToLocal(pp, wp); - poly.addPoint(pp.x, pp.y); - - if (bin == (histo.getNumberBins() - 1)) { - wp.setLocation(xmax, 0); - canvas.worldToLocal(pp, wp); - poly.addPoint(pp.x, pp.y); - } - } - return poly; - } - - /** - * Set whether we use rms or sigma in histogram legends - * - * @param useRMS if true use rms, else use sigma - */ - public void setRmsInHistoLegend(boolean useRMS) { - _rmsInHistoLegend = useRMS; - } - - /** - * Check whether we use rms or sigma in histogram legends - * - * @return true use rms, else use sigma - */ - public boolean useRmsInHistoLegend() { - return _rmsInHistoLegend; - } - - /** - * Set whether we draw sqrt(n) statistical errors - * - * @param statErr if true draw statistical errors - */ - public void setDrawStatisticalErrors(boolean statErr) { - _statErrors = statErr; - } - - /** - * Check whether we draw sqrt(n) statistical errors - * - * @return true if true draw statistical errors - */ - public boolean drawStatisticalErrors() { - return _statErrors; - } - - public String maxBinString() { - long maxCount = -1; - long counts[] = getCounts(); - for (long lv : counts) { - maxCount = Math.max(maxCount, lv); - } - if (maxCount < 1) { - return ""; - } - - String s = "Max count: " + maxCount + " in 1-based bin(s):"; - for (int bin = 0; bin < getNumberBins(); bin++) { - - if (counts[bin] == maxCount) { - s += " " + (bin + 1); // make it 1-based - } - } - return s; - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/NiceScale.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/NiceScale.java deleted file mode 100644 index 737b1c3241..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/NiceScale.java +++ /dev/null @@ -1,144 +0,0 @@ -package cnuphys.splot.pdata; - -public class NiceScale { - - private double _min; - private double _max; - private int _numTicks = 10; // includes ends - private double _tickSpacing; - private double _niceMin; - private double _niceMax; - private boolean _includeZero; - - /** - * Instantiates a new instance of the NiceScale class. - * - * @param min the minimum data point on the axis - * @param max the maximum data point on the axis - * @param numTicks the number of ticks including the ends - */ - public NiceScale(double min, double max, int numTicks, boolean includeZero) { - _min = min; - _max = max; - _numTicks = numTicks; - _includeZero = includeZero; - - if (includeZero) { - _min = Math.min(_min, 0); - _max = Math.max(_max, 0); - } - calculate(); - } - - /** - * Calculate and update values for tick spacing and nice minimum and maximum - * data points on the axis. - */ - private void calculate() { - double range = niceNum(_max - _min, false); - _tickSpacing = niceNum(range / (_numTicks - 1), true); - _niceMin = Math.floor(_min / _tickSpacing) * _tickSpacing; - _niceMax = Math.ceil(_max / _tickSpacing) * _tickSpacing; - } - - /** - * Get the tick spacing - * - * @return the tick spacing - */ - public double getTickSpacing() { - return _tickSpacing; - } - - /** - * Get the nice plot min - * - * @return the nice plot min - */ - public double getNiceMin() { - return _niceMin; - } - - /** - * Get the nice plot max - * - * @return the nice plot max - */ - public double getNiceMax() { - return _niceMax; - } - - /** - * Returns a "nice" number approximately equal to range Rounds the number if - * round = true Takes the ceiling if round = false. - * - * @param range the data range - * @param round whether to round the result - * @return a "nice" number to be used for the data range - */ - private double niceNum(double range, boolean round) { - double exponent; - /** exponent of range */ - double fraction; - /** fractional part of range */ - double niceFraction; - /** nice, rounded fraction */ - - exponent = Math.floor(Math.log10(range)); - fraction = range / Math.pow(10, exponent); - - if (round) { - if (fraction < 1.5) - niceFraction = 1; - else if (fraction < 3) - niceFraction = 2; - else if (fraction < 7) - niceFraction = 5; - else - niceFraction = 10; - } - else { - if (fraction <= 1) - niceFraction = 1; - else if (fraction <= 2) - niceFraction = 2; - else if (fraction <= 5) - niceFraction = 5; - else - niceFraction = 10; - } - - return niceFraction * Math.pow(10, exponent); - } - - /** - * Sets the minimum and maximum data points for the axis. - * - * @param min the minimum data point on the axis - * @param max the maximum data point on the axis - */ - public void setMinMaxPoints(double min, double max) { - _min = min; - _max = max; - calculate(); - } - - /** - * Sets maximum number of tick marks we're comfortable with - * - * @param maxTicks the maximum number of tick marks for the axis - */ - public void setMaxTicks(int maxTicks) { - _numTicks = maxTicks; - calculate(); - } - - /** - * Get the number of ticks (including the ends) - * - * @return the number of ticks - */ - public int getNumTicks() { - return _numTicks; - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/StripData.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/StripData.java deleted file mode 100644 index e80745ba48..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/pdata/StripData.java +++ /dev/null @@ -1,89 +0,0 @@ -package cnuphys.splot.pdata; - -import java.util.Timer; -import java.util.TimerTask; - -import cnuphys.splot.fit.IValueGetter; - -public class StripData { - - // this is the "curve" name - private String _name; - - // the capacity before data starts falling off the (left) edge - private int _capacity; - - // retrieves the next value - private IValueGetter _valueGetter; - - // update timer - private Timer _timer; - - // Data set - private DataSet _dataSet; - - // time when data collection started - private long _startTime; - - // update interval ms - private long _interval; - - // x and y columns - private DataColumn _xColumn; - private DataColumn _yColumn; - - public StripData(String name, int capacity, IValueGetter getter, long interval) { - _name = name; - _capacity = capacity; - _valueGetter = getter; - _interval = interval; - } - - public void setDataSet(final DataSet ds) { - if (_dataSet != null) { - return; - } - - _dataSet = ds; - - _xColumn = _dataSet.getXColumn(0); - _yColumn = _dataSet.getCurve(0); - - TimerTask task = new TimerTask() { - - @Override - public void run() { - double t = (System.currentTimeMillis() - _startTime) / 1000; - double val = _valueGetter.value(t); - - // do we have to bump left? - if (_xColumn.size() == _capacity) { - _xColumn.removeFirst(); - _yColumn.removeFirst(); - } - - try { - _dataSet.add(t, val); - } - catch (DataSetException e) { - e.printStackTrace(); - } - } - - }; - - _startTime = System.currentTimeMillis(); - - _timer = new Timer(); - _timer.scheduleAtFixedRate(task, _interval, _interval); - } - - /** - * Stop the accumulation - */ - public void stop() { - if (_timer != null) { - _timer.cancel(); - } - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/.gitignore b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/.gitignore deleted file mode 100644 index 214190be67..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/.gitignore +++ /dev/null @@ -1,34 +0,0 @@ -/APreferencePanel.class -/CommonBorder.class -/CurveDrawer.class -/DataDrawer.class -/DoubleFormat.class -/Draggable.class -/Environment.class -/FloatingLabel.class -/GeneralPlotParamPanel.class -/GraphicsUtilities.class -/HorizontalLine.class -/ImageManager.class -/Legend.class -/PlotCanvas$1.class -/PlotCanvas$2.class -/PlotCanvas.class -/PlotGrid.class -/PlotGridDialog.class -/PlotLine.class -/PlotPanel$1.class -/PlotPanel$2.class -/PlotPanel$3.class -/PlotPanel.class -/PlotParameters.class -/PlotPopupMenu.class -/PlotTicks.class -/PrintUtilities.class -/SplotMenus.class -/TextFieldSlider$1.class -/TextFieldSlider.class -/UnicodeSupport.class -/VerticalLabelUI.class -/VerticalLine.class -/X11Colors.class diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/APreferencePanel.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/APreferencePanel.java deleted file mode 100644 index 5bbf2561c1..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/APreferencePanel.java +++ /dev/null @@ -1,72 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; - -import javax.swing.JPanel; - -/** - * A base class for panels that will be used as tabs on the Preferences dialog - * - * @author heddle - * - */ -public abstract class APreferencePanel extends JPanel implements KeyListener { - - // the plot canvas - protected PlotCanvas _canvas; - - /** - * Create a panel for use in editing plot preferences - * - * @param canvas the plot canvas - * @param tabname the name that will appear on the editor tab - */ - public APreferencePanel(PlotCanvas canvas, String tabname) { - _canvas = canvas; - setName(tabname); - } - - // get a titled panel - protected JPanel titledPanel(String title) { - JPanel pan = new JPanel(); - pan.setBorder(new CommonBorder(title)); - Environment.getInstance().commonize(pan, null); - return pan; - } - - /** - * Default implementation is to do nothing - * - * @param kev the Key Event - */ - @Override - public void keyTyped(KeyEvent kev) { - } - - /** - * Default implementation is to do nothing - * - * @param kev the Key Event - */ - @Override - public void keyPressed(KeyEvent kev) { - } - - /** - * Default implementation is call apply() if the hey was "Enter" - * - * @param kev the Key Event - */ - @Override - public void keyReleased(KeyEvent kev) { - if (kev.getKeyCode() == KeyEvent.VK_ENTER) { - apply(); - } - } - - /** - * Apply all the changes - */ - public abstract void apply(); -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/ColorScaleModel.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/ColorScaleModel.java deleted file mode 100644 index d2d89a4db0..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/ColorScaleModel.java +++ /dev/null @@ -1,248 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Color; - -/** - * Used for color scales, such as on magnetic field plots - * - * @author heddle - * - */ -public class ColorScaleModel { - - // a standard color scale - private static ColorScaleModel _blueToRed; - - /** - * The array of colors - */ - protected Color _colors[] = null; - - /** - * Constant used for "smallness" check - */ - private static final double TINY = 1.0e-6; - - // Color returned for a too-small - private Color _tooSmallColor = new Color(240, 240, 240, 64); - - // Color returned for a too-big value - private Color _tooBigColor = new Color(64, 64, 64, 64); - - private Color _zeroColor = Color.white; - - private double _minVal; - - private double _maxVal; - - /** - * This creates a ColorScaleModel for converting a value into a color. - * - * @param minVal the minimum value; - * @param maxVal the maximum value the array of colors. - */ - private ColorScaleModel(double minVal, double maxVal, Color[] colors) { - _colors = colors; - _minVal = minVal; - _maxVal = maxVal; - } - - /** - * Get a standard blue to red colors scale - * - * @return a standard blue to red color scale - */ - public static synchronized ColorScaleModel blueToRed() { - if (_blueToRed == null) { - Color colors[] = { - // new Color(0, 0, 139), - // new Color(0, 0, 255), - // new Color(0, 128, 255), - new Color(240, 240, 255), new Color(128, 255, 255), new Color(0, 255, 255), new Color(86, 255, 86), // - new Color(173, 255, 47), new Color(255, 255, 0), new Color(255, 165, 0), new Color(255, 69, 0), - new Color(255, 0, 0), - // new Color(139, 0, 0), - new Color(127, 0, 127) }; - _blueToRed = new ColorScaleModel(0.0, 1.0, colors); - } - - return _blueToRed; - } - - /** - * Get a color via getColor but add an alpha value - * - * @param value the value - * @param alpha the alpha value [0..255] - * @return the color corresponding to the value. - */ - public Color getAlphaColor(double value, int alpha) { - Color c = getColor(value); - Color color = new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha); - return color; - } - - /** - * Given a value, returns the corresponding color. Example: - *

    - * values: {0, 2, 4, 6, 8} - *

    - * colors: {R, G, B, Y} - *

    - * then - *

    - * value = 1.77 -> R - *

    - * value = -1 -> tooSmallColor - *

    - * value = 8.01 -> tooBigColor - *

    - * value = 4 (exactly) -> G - * - * @param value the for which we want the color. - * @return the color corresponding to the value. - */ - public Color getColor(double value) { - - if (Double.isNaN(value)) { - // System.err.println("NULL COLOR"); - return null; - } - - int collen = _colors.length; - - if (relativeDifference(value, _minVal) < TINY) { - return _zeroColor; - } - else if (relativeDifference(value, _maxVal) < TINY) { - return _colors[collen - 1]; - } - else if (value < _minVal) { - return _tooSmallColor; - } - else if (value > _maxVal) { - return _tooBigColor; - } - - double fract = (value - _minVal) / (_maxVal - _minVal); - - int index = (int) ((collen - 1) * fract); - - if (index < 0) { - return _tooSmallColor; - } - if (index >= collen) { - return _tooBigColor; - } - - double partFract = (collen - 1) * fract - index; - - Color c1 = _colors[index]; - Color c2 = _colors[index + 1]; - - Color interpColor = getInterpretedColor(c1, c2, partFract); -// System.err.println(DoubleFormat.doubleFormat(partFract, 3) + -// " red: " + c1.getRed() + ", " + c2.getRed() + ", " + interpColor.getRed() + -// " green: " + c1.getGreen() + ", " + c2.getGreen() + ", " + interpColor.getGreen() + -// " blue: " + c1.getBlue() + ", " + c2.getBlue() + ", " + interpColor.getBlue()); - - return interpColor; - } - - /** - * Compute the fraction difference between two points, normalized to the full - * scale. - * - * @param v1 one value. - * @param v2 the other value. - * @return the fractional difference. - */ - private double relativeDifference(double v1, double v2) { - - double minv = _minVal; - double maxv = _maxVal; - - if (minv == maxv) { - return 1.0; - } - else { - return Math.abs((v1 - v2) / (maxv - minv)); - } - } - - /** - * Get the color array. - * - * @return the color array. - */ - public Color[] getColors() { - return _colors; - } - - /** - * Get the too-big color. - * - * @return the color used for a "too big" value. - */ - public Color getTooBigColor() { - return _tooBigColor; - } - - /** - * Get the too-small color. - * - * @return the color used for a "too small" value. - */ - public Color getTooSmallColor() { - return _tooSmallColor; - } - - /** - * @param tooSmallColor the tooSmallColor to set - */ - public void setTooSmallColor(Color tooSmallColor) { - _tooSmallColor = tooSmallColor; - } - - /** - * @param tooBigColor the tooBigColor to set - */ - public void setTooBigColor(Color tooBigColor) { - _tooBigColor = tooBigColor; - } - - /** - * Get the color based on the fract. - * - * @param c1 - * @param c2 - * @param fract - * @return - */ - private Color getInterpretedColor(Color c1, Color c2, double fract) { - if (fract < 0.02) { - return c1; - } - if (fract > 0.98) { - return c2; - } - - int r1 = c1.getRed(); - int g1 = c1.getGreen(); - int b1 = c1.getBlue(); - int a1 = c1.getAlpha(); - - int r2 = c2.getRed(); - int g2 = c2.getGreen(); - int b2 = c2.getBlue(); - int a2 = c2.getAlpha(); - - int r3 = r1 + (int) (fract * (r2 - r1)); - int g3 = g1 + (int) (fract * (g2 - g1)); - int b3 = b1 + (int) (fract * (b2 - b1)); - int a3 = a1 + (int) (fract * (a2 - a1)); - - return new Color(r3, g3, b3, a3); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/CommonBorder.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/CommonBorder.java deleted file mode 100644 index 808caf2257..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/CommonBorder.java +++ /dev/null @@ -1,24 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Color; -import java.awt.Font; - -import javax.swing.BorderFactory; -import javax.swing.border.TitledBorder; - -@SuppressWarnings("serial") -public class CommonBorder extends TitledBorder { - - public Font font = Environment.getInstance().getCommonFont(9); - - public CommonBorder() { - super(BorderFactory.createEtchedBorder()); - setTitleColor(Color.blue); - setTitleFont(font); - } - - public CommonBorder(String title) { - this(); - setTitle(title); - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/CurveDrawer.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/CurveDrawer.java deleted file mode 100644 index adf9cca9ba..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/CurveDrawer.java +++ /dev/null @@ -1,527 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Color; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Point; -import java.awt.Polygon; -import java.awt.Rectangle; -import java.awt.Stroke; -import java.awt.geom.Path2D; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; - -import cnuphys.splot.fit.AltPolynomialFit; -import cnuphys.splot.fit.CubicSpline; -import cnuphys.splot.fit.ErfFit; -import cnuphys.splot.fit.ErfcFit; -import cnuphys.splot.fit.Fit; -import cnuphys.splot.fit.FitType; -import cnuphys.splot.fit.FitUtilities; -import cnuphys.splot.fit.GaussianFit; -import cnuphys.splot.fit.IValueGetter; -import cnuphys.splot.fit.LineFit; -import cnuphys.splot.fit.LinearExyFit; -import cnuphys.splot.fit.PolyAndGaussianFit; -import cnuphys.splot.fit.PolyFit; -import cnuphys.splot.pdata.DataColumn; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.Histo2DData; -import cnuphys.splot.pdata.HistoData; -import cnuphys.splot.style.IStyled; -import cnuphys.splot.style.Styled; -import cnuphys.splot.style.SymbolDraw; -import cnuphys.splot.style.SymbolType; - -public class CurveDrawer { - - private static final Color _transGray = new Color(80, 80, 80, 16); - - public static void drawHisto2D(Graphics g, PlotCanvas canvas, DataColumn histoColumn) { - Histo2DData hd2 = histoColumn.getHistoData2D(); - - long maxCount = hd2.getMaxCount(); - if (maxCount < 1) { - return; - } - - long counts[][] = hd2.getCounts(); - - Gradient gradient = canvas.getGradient(); - - Rectangle r = new Rectangle(); - for (int xbin = 0; xbin < hd2.getNumberBinsX(); xbin++) { - for (int ybin = 0; ybin < hd2.getNumberBinsY(); ybin++) { - long count = counts[xbin][ybin]; - double fract = ((double) count) / maxCount; - - Color color = gradient.getColor(fract); - - Rectangle2D.Double wrect = hd2.getRectangle(xbin, ybin); -// System.err.println("WR: " + wrect); - canvas.worldToLocal(r, wrect); - - g.setColor(color); - ; - g.fillRect(r.x, r.y, r.width, r.height); - - } - } - } - - /** - * Draw a 1D histogram - * - * @param g the graphics context - * @param canvas the plot canvas - * @param histoColumn the column (should contain a HistData object) - */ - public static void drawHisto1D(Graphics g, PlotCanvas canvas, DataColumn histoColumn) { - - if (!histoColumn.isVisible()) { - return; - } - - HistoData hd = histoColumn.getHistoData(); - - Polygon poly = HistoData.GetPolygon(canvas, hd); - IStyled style = histoColumn.getStyle(); - - g.setColor(style.getFillColor()); - g.fillPolygon(poly); - - Color borderColor = style.getBorderColor(); - if (borderColor == null) { - borderColor = _transGray; - } - else { - // borderColor = new Color(borderColor.getRed(), borderColor.getGreen(), - // borderColor.getBlue(), 16); - } - g.setColor(borderColor); - g.drawPolygon(poly); - - long counts[] = hd.getCounts(); - int numBin = hd.getNumberBins(); - double x[] = new double[numBin]; - double y[] = new double[numBin]; - double err[] = new double[numBin]; - for (int bin = 0; bin < numBin; bin++) { - x[bin] = hd.getBinMidValue(bin); - y[bin] = counts[bin]; - err[bin] = Math.sqrt(y[bin]); - } - - // draw a fit - Fit yfit = histoColumn.getFit(); - if (yfit != null) { - yfit.setX(x); - yfit.setY(y); - yfit.setSigmaY(null); - if (fitDrawable(histoColumn)) { - drawFit(g, canvas, yfit, histoColumn.getStyle()); - } - } - - // draw statistical errors - if (hd.drawStatisticalErrors()) { - Point p0 = new Point(); - Point p1 = new Point(); - Point.Double wp = new Point.Double(); - - for (int bin = 0; bin < numBin; bin++) { - if (hd.getCount(bin) > 0) { - double ymin = y[bin] - err[bin]; - double ymax = y[bin] + err[bin]; - wp.setLocation(x[bin], ymin); - canvas.worldToLocal(p0, wp); - wp.setLocation(x[bin], ymax); - canvas.worldToLocal(p1, wp); - g.drawLine(p0.x, p0.y, p1.x, p1.y); - g.drawLine(p0.x - 2, p0.y, p0.x + 2, p0.y); - g.drawLine(p1.x - 2, p1.y, p1.x + 2, p1.y); - } - } - - } - - // draw the bin borders - // TODO make optional - Rectangle b = canvas.getActiveBounds(); - int n = poly.npoints; - g.setColor(borderColor); - for (int i = 0; i < n; i++) { - g.drawLine(poly.xpoints[i], poly.ypoints[i], poly.xpoints[i], b.y + b.height); - } - - } - - /** - * Draw a curve with no error bars - * - * @param g the graphics context - * @param plotCanvas the plot canvas - * @param xcol the x data column - * @param ycol the y data column - */ - public static void drawCurve(Graphics g, PlotCanvas plotCanvas, DataColumn xcol, DataColumn ycol) { - drawCurve(g, plotCanvas, xcol, ycol, null, null); - } - - /** - * Draw a curve with x and y error bars - * - * @param g the graphics context - * @param plotCanvas the plot canvas - * @param xcol the x data column - * @param ycol the y data column - * @param xerrCol the x error bar column (often null) - * @param yerrCol the y error bar column - */ - public static void drawCurve(Graphics g, PlotCanvas plotCanvas, DataColumn xcol, DataColumn ycol, - DataColumn xerrCol, DataColumn yerrCol) { - - if (!ycol.isVisible()) { - return; - } - - Point2D.Double wp = new Point2D.Double(); - Point p0 = new Point(); - Point p1 = new Point(); - - double x[] = xcol.getMinimalCopy(); - double y[] = ycol.getMinimalCopy(); - - if ((x == null) || (x.length < 1)) { - return; - } - if ((y == null) || (y.length < 1)) { - return; - } - - double ysig[] = null; - double xsig[] = null; - if (xerrCol != null) { - xsig = xerrCol.getMinimalCopy(); - } - if (yerrCol != null) { - ysig = yerrCol.getMinimalCopy(); - } - - // is there a fit? - Fit yfit = ycol.getFit(); - if (yfit != null) { - if (yfit.isDirty()) { - yfit.setX(x); - yfit.setY(y); - yfit.setSigmaX(xsig); - yfit.setSigmaY(ysig); - } - if (fitDrawable(ycol)) { - drawFit(g, plotCanvas, yfit, ycol.getStyle()); - } - } - - // symbols? - Styled style = ycol.getStyle(); - - if (style == null) { - return; - } - - if (style.getSymbolType() != SymbolType.NOSYMBOL) { - for (int i = 0; i < x.length; i++) { - - if (xsig != null) { - double x0 = x[i] - xsig[i]; - double x1 = x[i] + xsig[i]; - wp.setLocation(x0, y[i]); - plotCanvas.worldToLocal(p0, wp); - wp.setLocation(x1, y[i]); - plotCanvas.worldToLocal(p1, wp); - g.drawLine(p0.x, p0.y, p1.x, p1.y); - } - - if (ysig != null) { - double y0 = y[i] - ysig[i]; - double y1 = y[i] + ysig[i]; - wp.setLocation(x[i], y0); - plotCanvas.worldToLocal(p0, wp); - wp.setLocation(x[i], y1); - plotCanvas.worldToLocal(p1, wp); - g.drawLine(p0.x, p0.y, p1.x, p1.y); - } - - wp.setLocation(x[i], y[i]); - plotCanvas.worldToLocal(p0, wp); - SymbolDraw.drawSymbol(g, p0.x, p0.y, style); - - } - } - - } - - // check whether a fit is drawable - private static boolean fitDrawable(DataColumn ycol) { - if (ycol == null) { - return false; - } - - Fit fit = ycol.getFit(); - - if (fit == null) { - return false; - } - - if (ycol.isHistogram1D()) { - HistoData hd = ycol.getHistoData(); - if ((hd == null) || (hd.getGoodCount() < 3)) { - return false; - } - } - - int size = fit.size(); - if (fit.getFitType() == FitType.LINE) { - return (size > 1); - } - else { - return (size > 2); - } - } - - // draw the fit - private static void drawFit(Graphics g, PlotCanvas plotCanvas, Fit yfit, IStyled style) { - - if (yfit.size() < 2) { - return; - } - - Point2D.Double wp = new Point2D.Double(); - Point p0 = new Point(); - Point p1 = new Point(); - - Graphics2D g2 = (Graphics2D) g; - - Stroke oldStroke = g2.getStroke(); - g2.setStroke(GraphicsUtilities.getStroke(style.getFitLineWidth(), style.getFitLineStyle())); - - Color fitColor = style.getFitLineColor(); - if (fitColor == null) { - return; - } - g2.setColor(fitColor); - - double x[] = yfit.getX(); - double y[] = yfit.getY(); - - FitType fitType = yfit.getFitType(); - - switch (fitType) { - case NOLINE: - break; - - case CONNECT: - FitUtilities.parallelSort(x, y); - wp.setLocation(x[0], y[0]); - plotCanvas.worldToLocal(p0, wp); - - for (int i = 1; i < x.length; i++) { - wp.setLocation(x[i], y[i]); - plotCanvas.worldToLocal(p1, wp); - g2.drawLine(p0.x, p0.y, p1.x, p1.y); - p0.setLocation(p1); - } - break; - - case STAIRS: - FitUtilities.parallelSort(x, y); - wp.setLocation(x[0], y[0]); - plotCanvas.worldToLocal(p0, wp); - - Rectangle rr = plotCanvas.getActiveBounds(); - int bottom = rr.y + rr.height; - - for (int i = 1; i < x.length; i++) { - wp.setLocation(x[i], y[i]); - plotCanvas.worldToLocal(p1, wp); - - g2.setColor(style.getFillColor()); - g.fillRect(p0.x, p0.y, p1.x - p0.x, bottom - p0.y); - - g2.setColor(style.getFitLineColor()); - g2.drawLine(p0.x, p0.y, p1.x, p0.y); - g2.drawLine(p1.x, p0.y, p1.x, p1.y); - p0.setLocation(p1); - } - break; - - case LINE: - if (yfit.isDirty()) { - try { - FitUtilities.fitStraightLine(yfit); - } - catch (Exception e) { - System.err.println("Line Fit FAILED"); - yfit.setDirty(); - return; - } - } - if (plotCanvas.getDataSet().hasXErrors()) { - LinearExyFit lexyfit = (LinearExyFit) yfit.getFit(); - drawValueGetter(g2, plotCanvas, lexyfit); - } - else { - LineFit lfit = (LineFit) yfit.getFit(); - drawValueGetter(g2, plotCanvas, lfit); - } - break; - - case ERF: - if (yfit.isDirty()) { - try { - // FitUtilities.doFit(yfit, "cnuphys.splot.fit.ErfFit"); - FitUtilities.fitErf(yfit); - } - catch (Exception e) { - System.err.println("Erf Fit FAILED"); - yfit.setDirty(); - return; - } - } - - ErfFit efit = (ErfFit) yfit.getFit(); - drawValueGetter(g2, plotCanvas, efit); - - break; - - case ERFC: - if (yfit.isDirty()) { - try { - yfit.hold(0, 0); - yfit.hold(1, 0.5); - // FitUtilities.doFit(yfit, "cnuphys.splot.fit.ErfcFit"); - FitUtilities.fitErfc(yfit); - } - catch (Exception e) { - System.err.println("Erfc Fit FAILED"); - yfit.setDirty(); - return; - } - } - - ErfcFit ecfit = (ErfcFit) yfit.getFit(); - drawValueGetter(g2, plotCanvas, ecfit); - - break; - - case GAUSSIANS: - if (yfit.isDirty()) { - System.err.println("Gaussian fit with errors num: " + yfit.getNumGaussian()); - try { - // FitUtilities.doFit(yfit, - // "cnuphys.splot.fit.GaussianFit"); - FitUtilities.fitGaussians(yfit); - } - catch (Exception e) { - System.err.println("Gaussian Fit FAILED: " + e.getMessage()); - yfit.setDirty(); - return; - } - } - - GaussianFit ngfit = (GaussianFit) yfit.getFit(); - drawValueGetter(g2, plotCanvas, ngfit); - break; - - case CUBICSPLINE: - FitUtilities.parallelSort(x, y); - if (yfit.isDirty()) { - yfit.setFit(new CubicSpline(x, y)); - } - CubicSpline nrcubic = (CubicSpline) yfit.getFit(); - drawValueGetter(g2, plotCanvas, nrcubic); - break; - - case POLYNOMIAL: - if (yfit.isDirty()) { - FitUtilities.fitPoly(yfit); - } - - PolyFit nrpfit = (PolyFit) yfit.getFit(); - drawValueGetter(g2, plotCanvas, nrpfit); - break; - - case ALTPOLYNOMIAL: - if (yfit.isDirty()) { - FitUtilities.fitAltPoly(yfit); - // FitUtilities.doFit(yfit, - // "cnuphys.splot.fit.AltPolynomialFit"); - } - - AltPolynomialFit altfit = (AltPolynomialFit) yfit.getFit(); - drawValueGetter(g2, plotCanvas, altfit); - break; - - case POLYPLUSGAUSS: - if (yfit.isDirty()) { - FitUtilities.fitGaussPlusPoly(yfit); - // FitUtilities.doFit(yfit, - // "cnuphys.splot.fit.PolyAndGaussianFit"); - } - PolyAndGaussianFit npgfit = (PolyAndGaussianFit) yfit.getFit(); - drawValueGetter(g2, plotCanvas, npgfit); - break; - } - - g2.setStroke(oldStroke); - } - - // draw a value getter - private static void drawValueGetter(Graphics2D g, PlotCanvas plotCanvas, IValueGetter ivg) { - - if (ivg == null) { - return; - } - - // the plot screen rectangle - Rectangle rect = plotCanvas.getActiveBounds(); - int iy = rect.y; - Path2D poly = null; - - Point pp = new Point(); - Point.Double wp = new Point.Double(); - - DataSet ds = plotCanvas.getDataSet(); - double ymid = 0.5 * (ds.getYmin() + ds.getYmax()); - - wp.setLocation(ds.getXmin(), ymid); - plotCanvas.worldToLocal(pp, wp); - int xsmin = pp.x; - wp.setLocation(ds.getXmax(), ymid); - plotCanvas.worldToLocal(pp, wp); - int xsmax = pp.x; - - // xsmin = Math.max(rect.x, xsmin); - // xsmax = Math.min(rect.x + rect.width, xsmax); - xsmin = rect.x; - xsmax = rect.x + rect.width; - - for (int ix = xsmin; ix <= xsmax + rect.width; ix++) { - pp.setLocation(ix, iy); - plotCanvas.localToWorld(pp, wp); - wp.y = ivg.value(wp.x); - plotCanvas.worldToLocal(pp, wp); - - if (poly == null) { - poly = new Path2D.Float(); - poly.moveTo(pp.x, pp.y); - - } - else { - poly.lineTo(pp.x, pp.y); - } - } - g.draw(poly); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/DataDrawer.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/DataDrawer.java deleted file mode 100644 index cb023217eb..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/DataDrawer.java +++ /dev/null @@ -1,111 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Graphics; -import java.awt.Rectangle; -import java.awt.Shape; -import java.util.Vector; - -import cnuphys.splot.pdata.DataSet; - -public class DataDrawer { - - // the owner canvas - private PlotCanvas _plotCanvas; - - /** - * Create a DataDrawer - * - * @param plotCanvas the owner canvas - */ - public DataDrawer(PlotCanvas plotCanvas) { - _plotCanvas = plotCanvas; - } - - /** - * Draw a data set on the canvas - * - * @param g the graphics context - * @param ds the DataSet to draw. - */ - public void draw(Graphics g, DataSet ds) { - - if ((ds == null) || ds.getSize() < 1) { - return; - } - - if (!(g.getClip().intersects(_plotCanvas.getActiveBounds()))) { -// System.err.println("CLIP SKIP"); - return; - } - - Rectangle clipRect = GraphicsUtilities.minClip(g.getClip(), _plotCanvas.getActiveBounds()); - if ((clipRect == null) || (clipRect.width == 0) || (clipRect.height == 0)) { - return; - } - - // save the clip, set clip to active area - Shape oldClip = g.getClip(); - - g.setClip(clipRect); - - // any fixed lines? - Vector lines = _plotCanvas.getParameters().getPlotLines(); - if (!lines.isEmpty()) { - for (PlotLine line : lines) { - line.draw(g); - } - } - - switch (ds.getType()) { - case XYEXYE: - for (int i = 0; i < ds.getColumnCount() / 3; i++) { - int j = 3 * i; - CurveDrawer.drawCurve(g, _plotCanvas, ds.getColumn(j), ds.getColumn(j + 1), null, ds.getColumn(j + 2)); - } - break; - - case XYEEXYEE: - for (int i = 0; i < ds.getColumnCount() / 4; i++) { - int j = 4 * i; - CurveDrawer.drawCurve(g, _plotCanvas, ds.getColumn(j), ds.getColumn(j + 1), ds.getColumn(j + 2), - ds.getColumn(j + 3)); - } - break; - - case H1D: - for (int i = 0; i < ds.getColumnCount(); i++) { - CurveDrawer.drawHisto1D(g, _plotCanvas, ds.getColumn(i)); - } - break; - - case H2D: - CurveDrawer.drawHisto2D(g, _plotCanvas, ds.getColumn(0)); - break; - - case XYY: // share an x column - for (int i = 1; i < ds.getColumnCount(); i++) { - CurveDrawer.drawCurve(g, _plotCanvas, ds.getColumn(0), ds.getColumn(i)); - } - break; - - case XYXY: - for (int i = 0; i < ds.getColumnCount() / 2; i++) { - int j = 2 * i; - CurveDrawer.drawCurve(g, _plotCanvas, ds.getColumn(j), ds.getColumn(j + 1)); - } - break; - - case STRIP: - CurveDrawer.drawCurve(g, _plotCanvas, ds.getColumn(0), ds.getColumn(1)); - break; - - case UNKNOWN: - System.err.println("Cannot draw UNKNOWN data set type"); - break; - } - - // restore the old clip - g.setClip(oldClip); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/DoubleFormat.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/DoubleFormat.java deleted file mode 100644 index c2ce875d9c..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/DoubleFormat.java +++ /dev/null @@ -1,125 +0,0 @@ -package cnuphys.splot.plot; - -import java.text.DecimalFormat; -import java.util.Hashtable; - -public class DoubleFormat { - - /** - * cache formats which are few and often repeated to avoid recreating - */ - private static Hashtable formats = new Hashtable(143); - - /** - * Format a double - * - * @param value the value to format. - * @param numdec the number of digits right of the decimal. - */ - public static String doubleFormat(double value, int numdec) { - return doubleFormat(value, numdec, false); - } - - /** - * Format a double - * - * @param value the value to format. - * @param numdec the number of digits right of the decimal. - * @param scinot if true, use scientific notation. - */ - public static String doubleFormat(double value, int numdec, boolean scinot) { - - StringBuffer pattern = new StringBuffer(); - if (numdec < 1) { - pattern.append("0"); - } - else { - pattern.append("0."); - } - - for (int i = 0; i < numdec; i++) { - pattern.append("0"); - } - - if (scinot) { - pattern.append("E0"); - } - - String patternStr = pattern.toString(); - DecimalFormat df = null; - df = (formats.get(patternStr)); - - if (df == null) { - df = new DecimalFormat(patternStr); - formats.put(patternStr, df); - } - - return df.format(value); - - } - - /** - * Format a double, switching from fixed to scientific notation. - *

    - * Example:
    - * - * numdec = 6
    - * minExponent = 2
    - * value starts at 12345.67 and keep dividing by 10 gives
    - * 1.234567E4
    - * 1.234567E3
    - * 1.234567E2
    - * 12.345670
    - * 1.234567
    - * 0.123457
    - * 1.234567E-2
    - * 1.234567E-3
    - * 1.234567E-4
    - * 1.234567E-5
    - * 1.234567E-6
    - * 1.234567E-7
    - *
    - * - * @param value the value to format. - * @param numdec the number of digits right of the decimal. If the - * exponenent is {@code >= n} or {@code <= -n} it will use sci notation. - * @param minExponent the minimum (absolute value) index for scientific - * notation. - */ - - public static String doubleFormat(double value, int numdec, int minExponent) { - - if (Math.abs(value) < 1.0e-30) { - return "0.0"; - } - - int exponent = (int) Math.log10(Math.abs(value)); - if (exponent < 0) { - exponent = -exponent + 1; - } - - if (exponent < minExponent) { - return doubleFormat(value, numdec, false); - } - else { // use sci not - return doubleFormat(value, numdec, true); - } - - } - - /** - * main program for testing. - * - * @param args command line arguments (ignored.) - */ - public static void main(String[] args) { - double d = 12345.67; - - for (int i = 0; i < 12; i++) { - System.err.println(doubleFormat(d, 6, 2)); - // System.err.println(doubleFormat(-d, 6, 3)); - d = d / 10; - } - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/Draggable.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/Draggable.java deleted file mode 100644 index c6f65a97c0..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/Draggable.java +++ /dev/null @@ -1,20 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Point; - -public interface Draggable { - - public boolean contains(Point p); - - public boolean isDraggingPrimed(); - - public boolean isDragging(); - - public void setDraggingPrimed(boolean primed); - - public void setDragging(boolean dragging); - - public void setCurrentPoint(Point p); - - public Point getCurrentPoint(); -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/DraggableRectangle.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/DraggableRectangle.java deleted file mode 100644 index dd7c0c0c9d..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/DraggableRectangle.java +++ /dev/null @@ -1,55 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Point; -import java.awt.Rectangle; - -public class DraggableRectangle extends Rectangle implements Draggable { - - // are we being dragged - protected boolean _dragging; - - // is dragging primed - protected boolean _draggingPrimed; - - // current point - protected Point _currentPoint; - - protected boolean _beenMoved; - - @Override - public boolean isDraggingPrimed() { - return _draggingPrimed; - } - - @Override - public boolean isDragging() { - return _dragging; - } - - @Override - public void setDraggingPrimed(boolean primed) { - _draggingPrimed = primed; - } - - @Override - public void setDragging(boolean dragging) { - _dragging = dragging; - _beenMoved = true; - } - - @Override - public void setCurrentPoint(Point p) { - if (p == null) { - _currentPoint = null; - } - else { - _currentPoint = new Point(p); - } - } - - @Override - public Point getCurrentPoint() { - return _currentPoint; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/Environment.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/Environment.java deleted file mode 100644 index 203cbccba4..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/Environment.java +++ /dev/null @@ -1,290 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Color; -import java.awt.Font; -import java.util.Iterator; - -import javax.imageio.ImageIO; -import javax.imageio.ImageWriter; -import javax.swing.JComponent; -import javax.swing.UIManager; - -public final class Environment { - - // singleton - private static Environment instance; - - // User's home directory. - private String _homeDirectory; - - // Current working directory - private String _currentWorkingDirectory; - - // user name - private String _userName; - - // operating system name - private String _osName; - - // temporary directory - private String _tempDirectory; - - // the java class path - private String _classPath; - - // png image writer, if there is one - private ImageWriter _pngWriter; - - // default panel background color - private Color _defaultPanelBackgroundColor; - - // common fonts - private Font _commonFonts[] = new Font[50]; - private String _commonFontName; - - /** - * Private constructor for the singleton. - */ - private Environment() { - _homeDirectory = getProperty("user.home"); - _currentWorkingDirectory = getProperty("user.dir"); - _userName = getProperty("user.name"); - _osName = getProperty("os.name"); - - _tempDirectory = getProperty("java.io.tmpdir"); - _classPath = getProperty("java.class.path"); - - // any png image writers? - Iterator iterator = ImageIO.getImageWritersByFormatName("png"); - if ((iterator == null) || !iterator.hasNext()) { - System.err.println("no png writer"); - } - else { - _pngWriter = iterator.next(); // take the first - } - } - - /** - * Convenience method for sharing common fonts - * - * @param size the size of the font - * @return the common font - */ - public Font getCommonFont(int size) { - - if (_commonFontName == null) { - _commonFontName = "SansSerif"; - } - - if (isLinux()) { - size = size - 1; - } - - if (size >= _commonFonts.length) { - return new Font(_commonFontName, Font.PLAIN, size); - } - - if (_commonFonts[size] == null) { - _commonFonts[size] = new Font(_commonFontName, Font.PLAIN, size); - } - return _commonFonts[size]; - } - - /** - * Public access for the singleton. - * - * @return the singleton object. - */ - public static synchronized Environment getInstance() { - if (instance == null) { - instance = new Environment(); - } - return instance; - } - - /** - * Convenience routine for getting a system property. - * - * @param keyName the key name of the property - * @return the property, or null. - */ - private String getProperty(String keyName) { - try { - return System.getProperty(keyName); - } - catch (Exception e) { - return null; - } - } - - /** - * Get the JAVA class path. - * - * @return the JAVA class path. - */ - public String getClassPath() { - return _classPath; - } - - /** - * Get the current working directory. - * - * @return the currentWorkingDirectory. - */ - public String getCurrentWorkingDirectory() { - return _currentWorkingDirectory; - } - - /** - * Gets the user's home directory. - * - * @return the user's home directory. - */ - public String getHomeDirectory() { - return _homeDirectory; - } - - /** - * Gets the operating system name. - * - * @return the operating system name.. - */ - public String getOsName() { - return _osName; - } - - /** - * Gets the temp directory. - * - * @return the tempDirectory. - */ - public String getTempDirectory() { - return _tempDirectory; - } - - /** - * Gets the user name. - * - * @return the userName. - */ - public String getUserName() { - return _userName; - } - - /** - * Convert to a string representation. - * - * @return a string representation of the Environment object. - */ - - @Override - public String toString() { - StringBuffer sb = new StringBuffer(1024); - sb.append("Environment: \n"); - - sb.append("User Name: " + getUserName() + "\n"); - sb.append("Temp Directory: " + getTempDirectory() + "\n"); - sb.append("OS Name: " + getOsName() + "\n"); - sb.append("Home Directory: " + getHomeDirectory() + "\n"); - sb.append("Current Working Directory: " + getCurrentWorkingDirectory() + "\n"); - sb.append("Class Path: " + getClassPath() + "\n"); - sb.append("PNG Writer: " + ((_pngWriter == null) ? "none" : _pngWriter) + "\n"); - return sb.toString(); - } - - /** - * Check whether we are running on linux - * - * @return true if we are running on linux - */ - public boolean isLinux() { - return getOsName().toLowerCase().contains("linux"); - } - - /** - * Check whether we are running on Windows - * - * @return true if we are running on Windows - */ - public boolean isWindows() { - return getOsName().toLowerCase().contains("windows"); - } - - /** - * Check whether we are running on a Mac - * - * @return true if we are running on a Mac - */ - public boolean isMac() { - return getOsName().toLowerCase().startsWith("mac"); - } - - /** - * @return the pngWriter - */ - public ImageWriter getPngWriter() { - return _pngWriter; - } - - /** - * Singleton objects cannot be cloned, so we override clone to throw a - * CloneNotSupportedException. - */ - @Override - public Object clone() throws CloneNotSupportedException { - throw new CloneNotSupportedException(); - } - - /** - * Get the UIManager's choice for panel background color - * - * @return the UIManager's choice for panel background color - */ - public Color getDefaultPanelBackgroundColor() { - if (_defaultPanelBackgroundColor == null) { - _defaultPanelBackgroundColor = UIManager.getColor("Panel.background"); - if (_defaultPanelBackgroundColor == null) { - _defaultPanelBackgroundColor = new Color(238, 238, 238); - } - } - - return _defaultPanelBackgroundColor; - } - - /** - * Useful for making common look components - * - * @param component the component - * @param color the background color--if null use default. - */ - public void commonize(JComponent component, Color color) { - component.setOpaque(true); - color = (color == null) ? _defaultPanelBackgroundColor : color; - component.setBackground(color); - } - - /** - * Print a memory report - * - * @param message a message to add on - */ - public static void memoryReport(String message) { - System.gc(); - System.gc(); - double total = (Runtime.getRuntime().totalMemory()) / 1048576.; - double free = Runtime.getRuntime().freeMemory() / 1048576.; - double used = total - free; - System.err.println("\n==== Memory Report ====="); - if (message != null) { - System.err.println(message); - } - System.err.println("Total memory in JVM: " + DoubleFormat.doubleFormat(total, 1) + "MB"); - System.err.println(" Free memory in JVM: " + DoubleFormat.doubleFormat(free, 1) + "MB"); - System.err.println(" Used memory in JVM: " + DoubleFormat.doubleFormat(used, 1) + "MB"); - System.err.println(); - } - - public static void main(String arg[]) { - System.out.println(Environment.getInstance()); - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/ExtraText.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/ExtraText.java deleted file mode 100644 index 21a22c162c..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/ExtraText.java +++ /dev/null @@ -1,111 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.Rectangle; - -/** - * A legend like rectangle for extra text - * - * @author heddle - * - */ -public class ExtraText extends DraggableRectangle { - - // the owner plot panel - private PlotCanvas _canvas; - - // the plot parameters - private PlotParameters _params; - - // gap before text - private final int HGAP = 8; - - // extra v gap - private final int VGAP = 2; - - /** - * Create a Extra Text rectangle - * - * @param canvas the parent plot canvas - */ - public ExtraText(PlotCanvas canvas) { - _canvas = canvas; - _params = canvas.getParameters(); - } - - /** - * Draw the extra text - * - * @param g the graphics context - */ - public void draw(Graphics g) { - - String[] extraStrings = _params.getExtraStrings(); - if ((extraStrings == null) || (extraStrings.length < 1)) { - return; - } - - width = getExtraWidth(); - height = getExtraHeight(); - - if ((width < 2) || (height < 2)) { - return; - } - - // if never dragged, keep at upper right default location - if (!_beenMoved) { - Rectangle actRect = _canvas.getActiveBounds(); - int right = actRect.x + actRect.width; - x = right - width - 10; - } - - g.setColor(_params.getExtraBackground()); - g.setFont(_params.getExtraFont()); - g.fillRect(x, y, width, height); - - g.setColor(_params.getExtraForeground()); - FontMetrics fm = _canvas.getFontMetrics(_params.getExtraFont()); - - int xs = x + HGAP; - int ys = y + VGAP + fm.getHeight(); - for (String s : extraStrings) { - g.drawString(s, xs, ys); - ys += fm.getHeight(); - } - - if (_params.isExtraBorder()) { - g.setColor(_params.getExtraBorderColor()); - g.drawRect(x, y, width, height); - } - - } - - // get required width of the extra box - private int getExtraWidth() { - FontMetrics fm = _canvas.getFontMetrics(_params.getExtraFont()); - String[] extraStrings = _params.getExtraStrings(); - if ((extraStrings == null) || (extraStrings.length < 1)) { - return 0; - } - - int maxStringWidth = 0; - for (String s : extraStrings) { - maxStringWidth = Math.max(maxStringWidth, fm.stringWidth(s)); - } - - return maxStringWidth + 2 * HGAP; - } - - // get required height of the extra text rectangle - private int getExtraHeight() { - FontMetrics fm = _canvas.getFontMetrics(_params.getExtraFont()); - String[] extraStrings = _params.getExtraStrings(); - if ((extraStrings == null) || (extraStrings.length < 1)) { - return 0; - } - - return VGAP + (extraStrings.length) * (VGAP + fm.getHeight()); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/FloatingLabel.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/FloatingLabel.java deleted file mode 100644 index 98c68d7d7e..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/FloatingLabel.java +++ /dev/null @@ -1,19 +0,0 @@ -package cnuphys.splot.plot; - -import javax.swing.JLabel; - -public class FloatingLabel extends JLabel { - - // the owner plot panel - private PlotCanvas _canvas; - - // the plot parameters - private PlotParameters _params; - - public FloatingLabel(PlotCanvas canvas) { - _canvas = canvas; - _params = canvas.getParameters(); - setOpaque(true); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/GeneralPlotParamPanel.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/GeneralPlotParamPanel.java deleted file mode 100644 index 01197b29b7..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/GeneralPlotParamPanel.java +++ /dev/null @@ -1,74 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.BorderLayout; -import java.awt.FlowLayout; -import java.awt.GridLayout; - -import javax.swing.JPanel; -import javax.swing.JTextField; - -public class GeneralPlotParamPanel extends APreferencePanel { - - // title text field - private JTextField _plotTitle; - - // x label text field - private JTextField _xLabel; - - // ylabel text field - private JTextField _yLabel; - - /** - * For editing basic parameters - * - * @param canvas the plot canvas - */ - public GeneralPlotParamPanel(PlotCanvas canvas) { - super(canvas, "Labels"); - setLayout(new BorderLayout(4, 4)); - addNorth(); - } - - // add the north panel - private void addNorth() { - - JPanel panel = new JPanel(); - Environment.getInstance().commonize(panel, null); - panel.setLayout(new GridLayout(3, 1)); - - // plot title - JPanel nPanel1 = titledPanel("plot title"); - nPanel1.setLayout(new FlowLayout(FlowLayout.CENTER)); - _plotTitle = new JTextField(_canvas.getParameters().getPlotTitle(), 40); - nPanel1.add(_plotTitle); - - // x label - JPanel nPanel2 = titledPanel("x axis label"); - nPanel2.setLayout(new FlowLayout(FlowLayout.CENTER)); - _xLabel = new JTextField(_canvas.getParameters().getXLabel(), 40); - nPanel2.add(_xLabel); - - // y label - JPanel nPanel3 = titledPanel("y axis label"); - nPanel3.setLayout(new FlowLayout(FlowLayout.CENTER)); - _yLabel = new JTextField(_canvas.getParameters().getYLabel(), 40); - nPanel3.add(_yLabel); - - _plotTitle.addKeyListener(this); - _xLabel.addKeyListener(this); - _yLabel.addKeyListener(this); - - panel.add(nPanel1); - panel.add(nPanel2); - panel.add(nPanel3); - add(panel, BorderLayout.NORTH); - } - - @Override - public void apply() { - _canvas.getParameters().setPlotTitle(_plotTitle.getText()); - _canvas.getParameters().setXLabel(_xLabel.getText()); - _canvas.getParameters().setYLabel(_yLabel.getText()); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/Gradient.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/Gradient.java deleted file mode 100644 index acf6d1a9bd..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/Gradient.java +++ /dev/null @@ -1,125 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Color; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.Rectangle; - -public class Gradient extends DraggableRectangle { - - // height of gradient - private static int GRAD_HEIGHT = 250; - - // width of gradient not including labels - private static int GRAD_WIDTH = 20; - - // the underlying color color scale model - private ColorScaleModel _colorModel; - - // the owner plot panel - private PlotCanvas _canvas; - - // the plot parameters - private PlotParameters _params; - - // is it a relative 0 to 1 scale? - private boolean _zeroMaxScale; - - // gap before text - private final int HGAP = 2; - - /** - * Create a gradient rectangle rectangle using the standard blue to red gradient - * with 0 to 1 value range relative range - * - * @param canvas the parent plot canvas - */ - public Gradient(PlotCanvas canvas) { - _canvas = canvas; - _params = canvas.getParameters(); - _colorModel = ColorScaleModel.blueToRed(); - _zeroMaxScale = true; - } - - /** - * Draw the gradient - * - * @param g the Graphics context - */ - public void draw(Graphics g) { - - width = getGradientWidth(); - height = getGradientHeight(); - - if ((width < 2) || (height < 2)) { - return; - } - - // if never dragged, keep at lower right default location - if (!_beenMoved) { - Rectangle actRect = _canvas.getActiveBounds(); - int right = actRect.x + actRect.width; - int bottom = actRect.y + actRect.height; - x = right - width - 10; - y = bottom - height - 10; - } - - int bottom = y + height; - -// g.setColor(_params.getTextBackground()); - g.setFont(_params.getTextFont()); -// g.fillRect(x, y, width, height); - - g.setColor(_params.getTextForeground()); - FontMetrics fm = _canvas.getFontMetrics(_params.getTextFont()); - g.drawString("0", x + GRAD_WIDTH + HGAP, bottom); - g.drawString("max", x + GRAD_WIDTH + HGAP, y + fm.getAscent()); - - for (int i = 0; i < height; i += 2) { - double val = ((double) i) / height; - Color c = getColor(val); - g.setColor(c); - g.fillRect(x, bottom - i, GRAD_WIDTH, 2); - } - - g.setColor(Color.black); - g.drawRect(x, y + 1, GRAD_WIDTH, GRAD_HEIGHT + 1); - } - - /** - * Get the height of the gradient - * - * @return the height of the gradient - */ - protected int getGradientHeight() { - return GRAD_HEIGHT; - } - - protected int getGradientWidth() { - int w = GRAD_WIDTH; - - // now account for text - FontMetrics fm = _canvas.getFontMetrics(_params.getTextFont()); - - if (_zeroMaxScale) { - w = w + HGAP + fm.stringWidth("max"); - } - else { - // TODO implement - } - - return w; - } - - /** - * Get the color for the give value. Interpolation is used. - * - * @param value the vale - * @return the color - */ - public Color getColor(double value) { - // use interpolation - return _colorModel.getColor(value); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/GraphicsUtilities.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/GraphicsUtilities.java deleted file mode 100644 index 92cbd83503..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/GraphicsUtilities.java +++ /dev/null @@ -1,1437 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.BasicStroke; -import java.awt.Color; -import java.awt.Component; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; -import java.awt.GraphicsEnvironment; -import java.awt.Point; -import java.awt.Polygon; -import java.awt.Rectangle; -import java.awt.RenderingHints; -import java.awt.Shape; -import java.awt.Stroke; -import java.awt.Toolkit; -import java.awt.Transparency; -import java.awt.Window; -import java.awt.geom.AffineTransform; -import java.awt.geom.NoninvertibleTransformException; -import java.awt.geom.Point2D; -import java.awt.image.BufferedImage; -import java.util.Hashtable; - -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JInternalFrame; -import javax.swing.SwingUtilities; -import javax.swing.UIDefaults; -import javax.swing.UIManager; -import javax.swing.UIManager.LookAndFeelInfo; -import javax.swing.plaf.metal.MetalIconFactory; - -import cnuphys.splot.style.LineStyle; - -public class GraphicsUtilities { - - /** - * One default color for highlighted drawing. - */ - public static Color highlightColor1 = Color.red; - - /** - * Second default color for highlighted drawing. - */ - public static Color highlightColor2 = Color.yellow; - - /** - * Slop value for checking line selection - */ - private static final double SELECTRES = 3.01; - - /** - * Stipple used for highlight drawing. - */ - final private static float DASH[] = { 8.0f }; - - /** - * A stroke used for highlight drawing. - */ - final public static BasicStroke dash1 = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 8.0f, - DASH, 0.0f); - - /** - * Another stroke used for highlight drawing. - */ - final public static BasicStroke dash2 = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 8.0f, - DASH, DASH[0]); - - /** - * A stroke used for highlight drawing. - */ - final public static BasicStroke dash1_2 = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 8.0f, - DASH, 0.0f); - - /** - * Another stroke used for highlight drawing. - */ - final public static BasicStroke dash2_2 = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 8.0f, - DASH, DASH[0]); - - /** - * A stroke used for common dashed lines. - */ - final public static BasicStroke simpleDash = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, - 8.0f, DASH, DASH[0]); - - final public static BasicStroke simpleDash2 = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, - 8.0f, DASH, 0.5f); - - /** - * Hashtable of strokes. As strokes are created, they are cached so that they - * aren't created over and over again. There should not be many--each linewidth - * and solid or dashed combination--probably no more than six or eight. - */ - protected static Hashtable strokes = new Hashtable(47); - - /** - * Set component to small size variant. Probably only works on Mac. - * - * @param component the component to change size - */ - public static void setSizeSmall(JComponent component) { - component.putClientProperty("JComponent.sizeVariant", "small"); - } - - /** - * Set component to mini size variant. Probably only works on Mac. - * - * @param component the component to change size - */ - public static void setSizeMini(JComponent component) { - component.putClientProperty("JComponent.sizeVariant", "mini"); - } - - /** - * Set button for square style. For mac so you don't have to use those wasteful - * oval buttons when space is tight - * - * @param button the button to change style - */ - public static void setSquareButton(JButton button) { - button.putClientProperty("JButton.buttonType", "square"); - } - - /** - * Set button for textured style. For mac so you don't have to use those - * wasteful oval buttons when space is tight - * - * @param button the button to change style - */ - public static void setTexturedButton(JButton button) { - button.putClientProperty("JButton.buttonType", "textured"); - } - - /** - * Compute a minimal clip from the intersection of the bounds of the current - * clip and a rectangle - * - * @param currentClip the current clip - * @param rect the rectangle of interest - * @return the intersection bounding rect, or null - */ - public static Rectangle minClip(Shape currentClip, Rectangle rect) { - if ((currentClip == null) || (rect == null)) { - return null; - } - - if ((rect.width == 0) || (rect.height == 0)) { - return null; - } - - Rectangle cb = currentClip.getBounds(); - if ((cb == null) || (cb.width == 0) || (cb.height == 0)) { - return null; - } - - SwingUtilities.computeIntersection(rect.x, rect.y, rect.width, rect.height, cb); - return cb; - } - - /** - * Gets a stroke appropriate for the line width and line type. Try the hash - * table first, if not found create the Stroke and place it in the hashtable for - * future use. - * - * @param lineWidth the desired line width in pixels. - * @param lineStyle the desired line style. - * @return the appropriate stroke. - */ - public static Stroke getStroke(float lineWidth, LineStyle lineStyle) { - - String hashKey = "STROKE_LW_" + lineWidth + "_LT_" + lineStyle; - Stroke stroke = null; - - if (strokes != null) { - stroke = (strokes.get(hashKey)); - } - - if (stroke == null) { // not in hashtable - float fLineWidth = lineWidth; - if (lineStyle.equals(LineStyle.SOLID)) { - stroke = new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); - } - else if (lineStyle.equals(LineStyle.DASH)) { - stroke = new BasicStroke(fLineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 8.0f, - new float[] { 10.0f, 10.0f }, 0.0f); - } - else if (lineStyle.equals(LineStyle.DOT_DASH)) { - stroke = new BasicStroke(fLineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 8.0f, - new float[] { 4.0f, 4.0f, 10.0f, 4.0f }, 0.0f); - } - else if (lineStyle.equals(LineStyle.DOT)) { - stroke = new BasicStroke(fLineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 8.0f, - new float[] { 4.0f, 4f }, 0.0f); - } - else if (lineStyle.equals(LineStyle.DOUBLE_DASH)) { - stroke = new BasicStroke(fLineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 8.0f, - new float[] { 10.0f, 4.0f, 10.0f, 10.0f }, 0.0f); - } - else if (lineStyle.equals(LineStyle.LONG_DASH)) { - stroke = new BasicStroke(fLineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 8.0f, - new float[] { 15.0f, 15.0f }, 0.0f); - } - else if (lineStyle.equals(LineStyle.LONG_DOT_DASH)) { - stroke = new BasicStroke(fLineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 8.0f, - new float[] { 6.0f, 4.0f, 15.0f, 4.0f }, 0.0f); - } - else { - stroke = new BasicStroke(lineWidth); - } - - strokes.put(hashKey, stroke); - } - return stroke; - } - - /** - * Create four points corresponding to the corners of a rectangle. Useful for - * item selection points. - * - * @param rect the rectangle in question. - * @return points corresponding to the corners. - */ - public static Point[] rectangleToPoints(Rectangle rect) { - Point pp[] = new Point[4]; - int l = rect.x; - int t = rect.y; - int r = l + rect.width; - int b = t + rect.height; - - pp[0] = new Point(l, t); - pp[1] = new Point(r, t); - pp[2] = new Point(r, b); - pp[3] = new Point(l, b); - - return pp; - } - - /** - * Obtain a translucent buffer big enough for offscreen drawing. - * - * @param c the component being rendered offscreen. - * @return a translucent buffer big enough for offscreen drawing. - */ - public static BufferedImage getComponentTranslucentImageBuffer(Component c) { - if (c == null) { - return null; - } - Dimension size = c.getSize(); - if ((size.width < 1) || (size.height < 1)) { - return null; - } - BufferedImage myImage = new BufferedImage(size.width, size.height, Transparency.TRANSLUCENT); - return myImage; - } - - /** - * Obtain a buffer big enough for offscreen drawing. This does not do the - * drawing. - * - * @param c the component to be rendered offscreen. - * @return an image big enough for the job. - */ - public static BufferedImage getComponentImageBuffer(Component c) { - if (c == null) { - return null; - } - Dimension size = c.getSize(); - if ((size.width < 1) || (size.height < 1)) { - return null; - } - - BufferedImage myImage = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); - return myImage; - } - - /** - * Paints the component on an existing image. - * - * @param c the component to paint. - * @param image the image to paint on, already created. - */ - public static void paintComponentOnImage(Component c, BufferedImage image) { - if ((c == null) || (image == null)) { - return; - } - Dimension size = c.getSize(); - - if ((size.width < 1) || (size.height < 1)) { - return; - } - Graphics2D g2 = image.createGraphics(); - c.paint(g2); - g2.dispose(); - } - - /** - * return an image resulting from offscreen drawing. - * - * @param c the component being rendered. - * @return an image upon which the component was drawn. - */ - public static BufferedImage getComponentImage(Component c) { - BufferedImage image = getComponentImageBuffer(c); - paintComponentOnImage(c, image); - return image; - } - - /** - * Center a component. - * - * @param component The Component to center - */ - public static void centerComponent(Component component) { - centerComponent(component, 0, 0); - } - - /** - * Center a component. - * - * @param component The Component to center. - * @param dh offset from horizontal center. - * @param dv offset from vertical center. - */ - public static void centerComponent(Component component, int dh, int dv) { - - if (component == null) - return; - - try { - - GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); - GraphicsDevice[] allScreens = env.getScreenDevices(); - GraphicsConfiguration gc = allScreens[0].getDefaultConfiguration(); - - Rectangle bounds = gc.getBounds(); - Dimension componentSize = component.getSize(); - if (componentSize.height > bounds.height) { - componentSize.height = bounds.height; - } - if (componentSize.width > bounds.width) { - componentSize.width = bounds.width; - } - - int x = bounds.x + ((bounds.width - componentSize.width) / 2) + dh; - int y = bounds.y + ((bounds.height - componentSize.height) / 2) + dv; - - component.setLocation(x, y); - - } - catch (Exception e) { - component.setLocation(200, 200); - e.printStackTrace(); - } - } - - /** - * Returns a dimension that is a specified fraction of the screen size. This is - * useful, for example, to make a farme 85% of the screen. - * - * @param fraction the fraction desired, e.g., 0.85. No check for reasonableness - * is made. - * @return the requested dimension. - */ - public static Dimension screenFraction(double fraction) { - Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); - d.width = (int) (fraction * d.width); - d.height = (int) (fraction * d.height); - return d; - } - - /** - * Adjust a second point so that the rectangle it forms with the first point - * matches an aspect ratio of a given rectangle. Useful for rubber banding when - * you want to preserve the aspect ratio. - * - * @param r the rectangle whose aspect ration will be mayched. - * @param p0 anchor point - * @param p will be adjusted so that p0, p form a rectangle with the same - * aspected ratio as r. - */ - - public static void rectangleARFixedAdjust(Rectangle r, Point p0, Point p) { - if (r == null) { - return; - } - - double rw = r.getWidth(); - double rh = r.getHeight(); - - if (rw < rh) { - int sign_x = (p.x > p0.x) ? 1 : -1; - double ar = rw / rh; - double pw = sign_x * ar * Math.abs(p.y - p0.y); - p.x = p0.x + (int) pw; - } - else { - int sign_y = (p.y > p0.y) ? 1 : -1; - double ar = rh / rw; - double ph = sign_y * ar * Math.abs(p.x - p0.x); - p.y = p0.y + (int) ph; - } - - } - - /** - * Get a rectangle with the same apsect ratio. Useful for rubber banding when - * you want to preserve the sapect ratio. - */ - public static Rectangle rectangleARFixed(Rectangle r, Point p0, Point p) { - rectangleARFixedAdjust(r, p0, p); - return rectangleFromPoints(p0, p); - } - - /** - * Given two points, return the rectangle - * - * @param p1 one point - * @param p2 the other point - * @return the rectangle created from two points - */ - - public static Rectangle rectangleFromPoints(Point p1, Point p2) { - - if ((p1 == null) && (p2 == null)) { - return null; - } - - if (p1 == null) { - return new Rectangle(p2.x, p2.y, 0, 0); - } - else if (p2 == null) { - return new Rectangle(p1.x, p1.y, 0, 0); - } - - int w = Math.abs(p2.x - p1.x); - int h = Math.abs(p2.y - p1.y); - int x = Math.min(p1.x, p2.x); - int y = Math.min(p1.y, p2.y); - return new Rectangle(x, y, w, h); - } - - /** - * Size and center a JFrame relative to the screen. - * - * @param frame the frame to size. - * @param fractionalSize the fraction desired of the screen--e.g., 0.85 for 85%. - */ - public void sizeToScreen(JFrame frame, double fractionalSize) { - Dimension d = screenFraction(fractionalSize); - frame.setSize(d); - centerComponent(frame); - } - - /** - * Draw an oval with a 3D etching. - * - * @param g the Graphics context. - * @param r the bounding rectangle. - * @param fc an optional fill color. - * @param ic an optional inner fill color. - * @param outsie if true, the 3D effect is "out", otherwise "in". - */ - static public void drawSimple3DOval(Graphics g, Rectangle r, Color fc, Color ic, boolean outsie) { - - Color tc; - Color bc; - - if (fc != null) { - g.setColor(fc); - g.fillArc(r.x, r.y, r.width - 1, r.height - 1, 0, 360); - } - - if (ic != null) { - g.setColor(ic); - g.fillArc(r.x + 3, r.y + 3, r.width - 7, r.height - 7, 0, 360); - g.setColor(Color.gray); - g.drawArc(r.x + 3, r.y + 3, r.width - 7, r.height - 7, 0, 360); - } - - // choose tc & bc to generate outsies or insies - - if (outsie) { - tc = Color.white; - bc = Color.black; - } - else { - tc = Color.black; - bc = Color.white; - } - - // manually draw the lines that give the 3D effect - - g.setColor(tc); - g.drawArc(r.x, r.y, r.width - 1, r.height - 1, 45, 180); - g.setColor(bc); - g.drawArc(r.x, r.y, r.width - 1, r.height - 1, 45, -180); - } - - /** - * Draw a 3d "etching" around a rectangular area.. - * - * @param g the Graphics context. - * @param x the left of the rectangle. - * @param y the top of the rectangle. - * @param w the width of the rectangle. - * @param h the height of the rectangle. - * @param outsie if true, the 3D effect is "out", otherwise "in". - */ - - static public void drawSimple3DRect(Graphics g, int x, int y, int w, int h, boolean outsie) { - drawSimple3DRect(g, x, y, w, h, null, outsie); - } - - /** - * Draw a 3d rectangle. - * - * @param g the Graphics context. - * @param x the left of the rectangle. - * @param y the top of the rectangle. - * @param w the width of the rectangle. - * @param h the height of the rectangle. - * @param fc the fill color (if null, no fill). - * @param outsie if true, the 3D effect is "out", otherwise "in". - */ - - static public void drawSimple3DRect(Graphics g, int x, int y, int w, int h, Color fc, boolean outsie) { - - Color tc; - Color bc; - Color oldcolor = g.getColor(); - - if (fc != null) { - g.setColor(fc); - g.fillRect(x, y, w, h); - } - - // choose tc & bc to generate outsies or insies - - if (outsie) { - tc = Color.white; - bc = Color.black; - } - else { - tc = Color.black; - bc = Color.white; - } - - // manually draw the lines that give the 3D effect - - int x2 = x + w; - int y2 = y + h; - g.setColor(tc); - g.drawLine(x, y, x2, y); - g.drawLine(x, y, x, y2); - g.setColor(bc); - g.drawLine(x, y2, x2, y2); - g.drawLine(x2, y2, x2, y); - g.setColor(oldcolor); - } - - /** - * Draw a 3d rectangle. - * - * @param g the Graphics context. - * @param r the rectangle. - * @param fc the fill color. - * @param outsie if true, the 3D effect is "out", otherwise "in". - */ - - static public void drawSimple3DRect(Graphics g, Rectangle r, Color fc, boolean outsie) { - - drawSimple3DRect(g, r.x, r.y, r.width - 1, r.height - 1, fc, outsie); - } - - /** - * Fill and frame a rectangle - * - * @param g the Graphics context. - * @param r the bounding rectangle. - * @param fill the fill color. - * @param frame the frame (line) color. - */ - - public static void fillAndFrameRect(Graphics g, Rectangle r, Color fill, Color frame) { - - Color old = g.getColor(); - - if (fill != null) { - g.setColor(fill); - g.fillRect(r.x, r.y, r.width, r.height); - } - - if (frame != null) { - g.setColor(frame); - g.drawRect(r.x, r.y, r.width, r.height); - } - - g.setColor(old); - - } - - /** - * Draw a 3d diamond. - * - * @param g the Graphics context. - * @param r the bounding rectangle. - * @param fc the fill color. - * @param outsie if true, the 3D effect is "out", otherwise "in". - */ - - static public void drawSimple3DDiamond(Graphics g, Rectangle r, Color fc, boolean outsie) { - Color tc; - Color bc; - int x[] = new int[4]; - int y[] = new int[4]; - int xp[] = new int[3]; - int yp[] = new int[3]; - - // choose tc & bc to generate outsies or insies - - if (outsie) { - tc = Color.white; - bc = Color.black; - } - else { - tc = Color.black; - bc = Color.white; - } - - int xc = r.x + r.width / 2; - int yc = r.y + r.height / 2; - - x[0] = r.x; - y[0] = yc; - x[1] = xc; - y[1] = r.y; - x[2] = r.x + r.width; - y[2] = yc; - x[3] = xc; - y[3] = r.y + r.height; - - xp[0] = r.x; - yp[0] = yc; - xp[1] = xc; - yp[1] = r.y; - xp[2] = r.x + r.width; - yp[2] = yc; - - g.setColor(tc); - g.drawPolygon(xp, yp, 3); - - xp[0] = r.x + r.width; - yp[0] = yc; - xp[1] = xc; - yp[1] = r.y + r.height; - xp[2] = r.x; - yp[2] = yc; - - g.setColor(bc); - g.drawPolygon(xp, yp, 3); - - x[0]++; - - g.setColor(fc); - g.fillPolygon(x, y, 4); - - } - - /** - * Draw a simple rectangle symbol. - * - * @param g the Graphics context. - * @param x the horizontal center. - * @param y the vertical center. - * @param w2 the half width. - * @param h2 the half height. - * @param lc the line color. - * @param fc the fill color. - */ - - public static void drawRectangle(Graphics g, int x, int y, int w2, int h2, Color lc, Color fc) { - - // this will ensure all symbols correct size - if (lc == null) { - lc = fc; - } - - if (fc != null) { - g.setColor(fc); - g.fillRect(x - w2, y - h2, 2 * w2, 2 * h2); - } - if (lc != null) { - g.setColor(lc); - g.drawRect(x - w2, y - h2, 2 * w2, 2 * h2); - } - } - - /** - * Draw a simple oval symbol. - * - * @param g the Graphics context. - * @param x the horizontal center. - * @param y the vertical center. - * @param w2 the half width. - * @param h2 the half height. - * @param lc the line color. - * @param fc the fill color. - */ - - public static void drawOval(Graphics g, int x, int y, int w2, int h2, Color lc, Color fc) { - - // this will ensure all symbols correct size - if (lc == null) { - lc = fc; - } - - if (fc != null) { - g.setColor(fc); - g.fillOval(x - w2, y - h2, 2 * w2, 2 * h2); - } - if (lc != null) { - g.setColor(lc); - g.drawOval(x - w2, y - h2, 2 * w2, 2 * h2); - } - } - - /** - * Draw a simple up triangle symbol. - * - * @param g the Graphics context. - * @param x the horizontal center. - * @param y the vertical center. - * @param s2 the half width. - * @param lc the line color. - * @param fc the fill color. - */ - - public static void drawUpTriangle(Graphics g, int x, int y, int s2, Color lc, Color fc) { - - // this will ensure all symbols correct size - if (lc == null) { - lc = fc; - } - - int l = x - s2; - int t = y - s2; - int r = x + s2; - int b = y + s2; - Polygon poly = new Polygon(); - poly.addPoint(l, b); - poly.addPoint(x, t); - poly.addPoint(r, b); - if (fc != null) { - g.setColor(fc); - g.fillPolygon(poly); - } - if (lc != null) { - g.setColor(lc); - g.drawPolygon(poly); - } - } - - /** - * Draw a simple down triangle symbol. - * - * @param g the Graphics context. - * @param x the horizontal center. - * @param y the vertical center. - * @param s2 the half width. - * @param lc the line color. - * @param fc the fill color. - */ - - public static void drawDownTriangle(Graphics g, int x, int y, int s2, Color lc, Color fc) { - - // this will ensure all symbols correct size - if (lc == null) { - lc = fc; - } - - int l = x - s2; - int t = y - s2; - int r = x + s2; - int b = y + s2; - Polygon poly = new Polygon(); - poly.addPoint(l, t); - poly.addPoint(r, t); - poly.addPoint(x, b); - if (fc != null) { - g.setColor(fc); - g.fillPolygon(poly); - } - if (lc != null) { - g.setColor(lc); - g.drawPolygon(poly); - } - } - - /** - * Draw a simple cross symbol. - * - * @param g the Graphics context. - * @param x the horizontal center. - * @param y the vertical center. - * @param s2 the half width. - * @param lc the line color. - */ - - public static void drawCross(Graphics g, int x, int y, int s2, Color lc) { - - if (lc != null) { - g.setColor(lc); - g.drawLine(x - s2, y, x + s2, y); - g.drawLine(x, y - s2, x, y + s2); - } - } - - /** - * Draw a simple "X" symbol. - * - * @param g the Graphics context. - * @param x the horizontal center. - * @param y the vertical center. - * @param s2 the half width. - * @param lc the line color. - */ - - public static void drawX(Graphics g, int x, int y, int s2, Color lc) { - - if (lc != null) { - g.setColor(lc); - g.drawLine(x - s2, y - s2, x + s2, y + s2); - g.drawLine(x - s2, y + s2, x + s2, y - s2); - } - } - - /** - * Draws a highlighted rectangle using default colors. - * - * @param g the graphics context. - * @param r the rectangle being highlighted. - */ - - public static void drawHighlightedRectangle(Graphics g, Rectangle r) { - drawHighlightedRectangle(g, r, highlightColor1, highlightColor2); - } - - /** - * Draws a highlighted rectangle. - * - * @param g the graphics context. - * @param r the rectangle being highlighted. - * @param color1 one color for the alternating dash. - * @param color2 the other color for the alternating dash. - */ - - public static void drawHighlightedRectangle(Graphics g, Rectangle r, Color color1, Color color2) { - if ((g == null) || (r == null)) { - return; - } - - Graphics2D g2 = (Graphics2D) g; - - Stroke oldStroke = g2.getStroke(); - - g2.setStroke(dash1); - g2.setColor(color1); - g2.drawRect(r.x, r.y, r.width, r.height); - g2.setStroke(dash2); - - g2.setColor(color2); - g2.drawRect(r.x, r.y, r.width, r.height); - - // restore the stroke - g2.setStroke(oldStroke); - - } - - /** - * @param g - * @param x1 - * @param y1 - * @param x2 - * @param y2 - * @param color1 - * @param color2 - */ - public static void drawHighlightedLine(Graphics g, int x1, int y1, int x2, int y2, Color color1, Color color2) { - - Graphics2D g2 = (Graphics2D) g; - - Stroke oldStroke = g2.getStroke(); - - g2.setStroke(dash1_2); - g2.setColor(color1); - g2.drawLine(x1, y1, x2, y2); - g2.setStroke(dash2_2); - - g2.setColor(color2); - g2.drawLine(x1, y1, x2, y2); - - // restore the stroke - g2.setStroke(oldStroke); - - } - - public static void drawHighlightedArc(Graphics g, int x, int y, int width, int height, int startAngle, int arcAngle, - Color color1, Color color2) { - Graphics2D g2 = (Graphics2D) g; - - Stroke oldStroke = g2.getStroke(); - - g2.setStroke(dash1); - g2.setColor(color1); - g2.drawArc(x, y, width, height, startAngle, arcAngle); - g2.setStroke(dash2); - - g2.setColor(color2); - g2.drawArc(x, y, width, height, startAngle, arcAngle); - - // restore the stroke - g2.setStroke(oldStroke); - - } - - /** - * Draws a highlighted rectangle using default colors. - * - * @param g the graphics context. - * @param r the rectangle bounding the oval being highlighted. - */ - - public static void drawHighlightedOval(Graphics g, Rectangle r) { - drawHighlightedOval(g, r, highlightColor1, highlightColor2); - } - - /** - * Draws a highlighted oval. - * - * @param g the graphics context. - * @param r the rectangle bounding the oval being highlighted. - * @param color1 one color for the alternating dash. - * @param color2 the other color for the alternating dash. - */ - - public static void drawHighlightedOval(Graphics g, Rectangle r, Color color1, Color color2) { - if ((g == null) || (r == null)) { - return; - } - - Graphics2D g2 = (Graphics2D) g; - - Stroke oldStroke = g2.getStroke(); - - g2.setStroke(dash1); - g2.setColor(color1); - g2.drawOval(r.x, r.y, r.width, r.height); - g2.setStroke(dash2); - - g2.setColor(color2); - g2.drawOval(r.x, r.y, r.width, r.height); - - // restore the stroke - g2.setStroke(oldStroke); - - } - - /** - * Draws a highlighted polyline (set of unclosed points) using default colors. - * - * @param g the graphics context. - * @param x the x coordinate array. - * @param y the y coordinate array. - * @param n the number of points to draw. - */ - - public static void drawHighlightedPolyline(Graphics g, int x[], int y[], int n) { - drawHighlightedPolyline(g, x, y, n, highlightColor1, highlightColor2); - } - - /** - * Draws a highlighted polyline (set of unclosed points). - * - * @param g the graphics context. - * @param x the x coordinate array. - * @param y the y coordinate array. - * @param n the number of points to draw. - * @param color1 one color for the alternating dash. - * @param color2 the other color for the alternating dash. - */ - - public static void drawHighlightedPolyline(Graphics g, int x[], int y[], int n, Color color1, Color color2) { - - Graphics2D g2 = (Graphics2D) g; - - Stroke oldStroke = g2.getStroke(); - - g2.setStroke(dash1); - g.setColor(color1); - g2.drawPolyline(x, y, n); - g2.setStroke(dash2); - - g.setColor(color2); - g2.drawPolyline(x, y, n); - - // restore the stroke - g2.setStroke(oldStroke); - - } - - /** - * Draws a highlighted shape using default colors. - * - * @param g the graphics context. - * @param shape the shape being highlighted. - */ - - public static void drawHighlightedShape(Graphics g, Shape shape) { - drawHighlightedShape(g, shape, highlightColor1, highlightColor2); - } - - /** - * Draws a highlighted shape. - * - * @param g the graphics context. - * @param shape the shape being highlighted. - * @param color1 one color for the alternating dash. - * @param color2 the other color for the alternating dash. - */ - - public static void drawHighlightedShape(Graphics g, Shape shape, Color color1, Color color2) { - if ((g == null) || (shape == null)) { - return; - } - - Graphics2D g2 = (Graphics2D) g; - - Stroke oldStroke = g2.getStroke(); - - g2.setStroke(dash1); - g.setColor(color1); - g2.draw(shape); - g2.setStroke(dash2); - - g.setColor(color2); - g2.draw(shape); - - // restore the stroke - g2.setStroke(oldStroke); - } - - /** - * Returns true if the point is on the line, with an amount of slop - * controlled by the class constant SELECTRES. - * - * @param px the x coordinate of the point to test. - * @param py the y coordinate of the point to test. - * @param startx the x coordinate of the start of the line. - * @param starty the y coordinate of the start of the line. - * @param endx the x coordinate of the end of the line. - * @param endy the y coordinate of the end of the line. - * @return true if the point is on the line. - */ - public static boolean pointOnLine(int px, int py, int startx, int starty, int endx, int endy) { - - int delx = endx - startx; - int dely = endy - starty; - - int fdelx = Math.abs(delx); - int fdely = Math.abs(dely); - - if ((fdelx < 2) && (fdely < 2)) { - return false; - } - - double x = px; - double y = py; - - double x1 = startx; - double y1 = starty; - - double t; - double dx = delx; - double dy = dely; - - if (fdelx > fdely) { - t = (x - x1) / dx; - if ((t < 0.0) || (t > 1.0)) { - return false; - } - - double yt = y1 + t * dy; - - if (Math.abs(yt - y) < SELECTRES) { - return true; - - } - } - else { - t = (y - y1) / dy; - if ((t < 0.0) || (t > 1.0)) { - return false; - } - - double xt = x1 + t * dx; - - if (Math.abs(xt - x) < SELECTRES) { - return true; - - } - - } - - return false; - } - - /** - * Returns true if the point is on the line, with an amount of slop - * controlled by the class constant SELECTRES. - * - * @param p the point to test. - * @param start the start of the line. - * @param end the end of the line. - * @return true if the point is on the line. - */ - public static boolean pointOnLine(Point p, Point start, Point end) { - if ((p == null) || (start == null) || (end == null)) { - return false; - } - return pointOnLine(p.x, p.y, start.x, start.y, end.x, end.y); - } - - /** - * Draw rotated text. - * - * @param g the Graphics context. - * @param s the text to draw. - * @param x the x pixel coordinate of baseline. - * @param y the y pixel coordinate of baseline. - * @param angleDegrees the angle of rotation in decimal degrees. - */ - public static void drawRotatedText(Graphics2D g, String s, Font font, int x, int y, double angleDegrees) { - - drawRotatedText(g, s, font, x, y, 0, 0, angleDegrees); - } - - /** - * Draw rotated text. - * - * @param g the Graphics context. - * @param s the text to draw. - * @param xo the x pixel coordinate of rotation point. - * @param yo the y pixel coordinate of rotation point. - * @param delX unrotated offset from rotation anchor - * @param delY unrotated offset from rotation anchor - * @param angleDegrees the angle of rotation in decimal degrees. - */ - public static void drawRotatedText(Graphics2D g, String s, Font font, int xo, int yo, int delX, int delY, - double angleDegrees) { - - g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - - if (Math.abs(angleDegrees) < 0.5) { - g.setFont(font); - g.drawString(s, xo + delX, yo + delY); - return; - } - - AffineTransform rotation = new AffineTransform(); - rotation.rotate(Math.toRadians(angleDegrees)); - - Point2D.Double offset = new Point2D.Double(delX, delY); - Point2D.Double rotOffset = new Point2D.Double(); - rotation.transform(offset, rotOffset); - - AffineTransform translation = AffineTransform.getTranslateInstance(xo + rotOffset.x, yo + rotOffset.y); - - g.transform(translation); - - Font rotatedFont = font.deriveFont(rotation); - g.setFont(rotatedFont); - g.drawString(s, 0, 0); - try { - g.transform(translation.createInverse()); - } - catch (NoninvertibleTransformException e) { - e.printStackTrace(); - } - } - - /** - * Draws an arrow on the given Graphics2D context - * - * @param g1 The Graphics context to draw on - * @param x The x location of the "tail" of the arrow - * @param y The y location of the "tail" of the arrow - * @param xx The x location of the "head" of the arrow - * @param yy The y location of the "head" of the arrow - */ - public static void drawArrow(Graphics g1, int x, int y, int xx, int yy) { - drawArrow(g1, x, y, xx, yy, false, null, null); - } - - /** - * Draws an arrow on the given Graphics2D context - * - * @param g1 The Graphics context to draw on - * @param x The x location of the "tail" of the arrow - * @param y The y location of the "tail" of the arrow - * @param xx The x location of the "head" of the arrow - * @param yy The y location of the "head" of the arrow - */ - public static void drawArrow(Graphics g1, int x, int y, int xx, int yy, boolean highlight, Color c1, Color c2) { - - if ((Math.abs(x - xx) < 4) && (Math.abs(y - yy) < 4)) { - return; - } - - Graphics2D g = (Graphics2D) g1; - - float arrowWidth = 8.0f; - float theta = 0.423f; - int[] xPoints = new int[3]; - int[] yPoints = new int[3]; - float[] vecLine = new float[2]; - float[] vecLeft = new float[2]; - float fLength; - float th; - float ta; - float baseX, baseY; - - xPoints[0] = xx; - yPoints[0] = yy; - - // build the line vector - vecLine[0] = (float) xPoints[0] - x; - vecLine[1] = (float) yPoints[0] - y; - - // build the arrow base vector - normal to the line - vecLeft[0] = -vecLine[1]; - vecLeft[1] = vecLine[0]; - - // setup length parameters - fLength = (float) Math.sqrt(vecLine[0] * vecLine[0] + vecLine[1] * vecLine[1]); - th = arrowWidth / (2.0f * fLength); - ta = arrowWidth / (2.0f * ((float) Math.tan(theta) / 2.0f) * fLength); - - // find the base of the arrow - baseX = (xPoints[0] - ta * vecLine[0]); - baseY = (yPoints[0] - ta * vecLine[1]); - - // build the points on the sides of the arrow - xPoints[1] = (int) (baseX + th * vecLeft[0]); - yPoints[1] = (int) (baseY + th * vecLeft[1]); - xPoints[2] = (int) (baseX - th * vecLeft[0]); - yPoints[2] = (int) (baseY - th * vecLeft[1]); - - if (highlight) { - c1 = (c1 == null) ? highlightColor1 : c1; - c2 = (c2 == null) ? highlightColor2 : c2; - drawHighlightedLine(g, x, y, (int) baseX, (int) baseY, c1, c2); - - } - else { - g.drawLine(x, y, (int) baseX, (int) baseY); - } - g.fillPolygon(xPoints, yPoints, 3); - - g.setColor(g.getColor().darker()); - g.drawPolygon(xPoints, yPoints, 3); - } - - /** - * Draw a styled line - * - * @param g the graphics context - * @param lineColor - * @param lineWidth - * @param lineStyle - * @param x1 starting x - * @param y1 starting y - * @param x2 ending x - * @param y2 ending y - */ - public static void drawStyleLine(Graphics g, Color lineColor, float lineWidth, LineStyle lineStyle, int x1, int y1, - int x2, int y2) { - Graphics2D g2 = (Graphics2D) g; - g2.setColor(lineColor); - - Stroke oldStroke = g2.getStroke(); - g2.setStroke(GraphicsUtilities.getStroke(lineWidth, lineStyle)); - - g2.drawLine(x1, y1, x2, y2); - g2.setStroke(oldStroke); - } - - /** - * Get the hex format of the color in the form #rrggbbaa - * - * @param color the color to convert - * @return the hex string for the color - */ - public static String colorToHex(Color color) { - if (color == null) { - return "#000000ff"; - } - - int r = color.getRed(); - int g = color.getGreen(); - int b = color.getBlue(); - int a = color.getAlpha(); - - return String.format("#%02x%02x%02x%02x", r, g, b, a); - } - - /** - * Obtain a color from a hex string in common internet format #rrggbbaa. The "#" - * and the aa are optional - * - * @param hex the hex string - * @return the corresponding color or black on error. - */ - public static Color colorFromHex(String hex) { - if (hex == null) { - return Color.black; - } - - // remove leading # if present - if (hex.startsWith("#")) { - hex = hex.substring(1); - } - - while (hex.length() < 6) { - hex += "0"; - } - while (hex.length() < 8) { - hex += "f"; - } - - try { - int r = Integer.parseInt(hex.substring(0, 2), 16); - int g = Integer.parseInt(hex.substring(2, 4), 16); - int b = Integer.parseInt(hex.substring(4, 6), 16); - int a = Integer.parseInt(hex.substring(6, 8), 16); - return new Color(r, g, b, a); - } - catch (Exception e) { - e.printStackTrace(); - return Color.black; - } - } - - public static Container getParentContainer(Component c) { - if (c == null) { - return null; - } - - Container container = c.getParent(); - while (container != null) { - if (container instanceof JInternalFrame) { - return container; - } - if (container instanceof JFrame) { - return container; - } - if (container instanceof JDialog) { - return container; - } - if (container instanceof Window) { - return container; - } - - container = container.getParent(); - } - - return null; - } - - /** - * Initialize the look and feel. - */ - public static void initializeLookAndFeel() { - - LookAndFeelInfo[] lnfinfo = UIManager.getInstalledLookAndFeels(); - - String preferredLnF[] = { "Mac OS X", "Windows", "Nimbus", "CDE/Motif", "Metal", - UIManager.getCrossPlatformLookAndFeelClassName() }; - - if ((lnfinfo == null) || (lnfinfo.length < 1)) { - return; - } - - for (String targetLnF : preferredLnF) { - for (int i = 0; i < lnfinfo.length; i++) { - if (lnfinfo[i].getName().indexOf(targetLnF) >= 0) { - try { - UIManager.setLookAndFeel(lnfinfo[i].getClassName()); - UIDefaults defaults = UIManager.getDefaults(); - - // replace the horrible windows check icon - if ("Windows".equalsIgnoreCase(lnfinfo[i].getName())) { - // defaults.put("RadioButtonMenuItem.checkIcon", - // defaults.get("RadioButton.icon")); - defaults.put("RadioButtonMenuItem.checkIcon", - MetalIconFactory.getRadioButtonMenuItemIcon()); - } - return; - } - catch (Exception e) { - e.printStackTrace(); - } - } - } - } - } - - public static void main(String arg[]) { - Color colors[] = { Color.red, Color.blue, Color.green, new Color(16, 32, 64, 128) }; - - for (Color c : colors) { - String s = colorToHex(c); - Color tc = colorFromHex(s); - - System.out.println(s); - System.out.println(tc.toString()); - } - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/HorizontalLine.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/HorizontalLine.java deleted file mode 100644 index c24bb15e4b..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/HorizontalLine.java +++ /dev/null @@ -1,33 +0,0 @@ -package cnuphys.splot.plot; - -public class HorizontalLine extends PlotLine { - - // the y value of the horizontal line - private double _y; - - public HorizontalLine(PlotCanvas canvas, double y) { - super(canvas); - _y = y; - } - - @Override - public double getX0() { - return _canvas.getWorld().getMinX(); - } - - @Override - public double getX1() { - return _canvas.getWorld().getMaxX(); - } - - @Override - public double getY0() { - return _y; - } - - @Override - public double getY1() { - return _y; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/ImageManager.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/ImageManager.java deleted file mode 100644 index e9fd486ea2..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/ImageManager.java +++ /dev/null @@ -1,249 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Component; -import java.awt.Image; -import java.awt.MediaTracker; -import java.awt.Toolkit; -import java.awt.image.BufferedImage; -import java.io.File; -import java.net.URL; -import java.util.Hashtable; - -import javax.swing.ImageIcon; - -public class ImageManager { - - public static ImageIcon cnuIcon = ImageManager.getInstance().loadImageIcon("images/cnuicon.png"); - - /** - * A memory only cache for Images (not ImageIcons). - */ - private Hashtable imageHashtable = new Hashtable(137); - - /** - * A memory only cache for ImageIcons (not Images). - */ - private Hashtable imageIconHashtable = new Hashtable(193); - - /** - * singleton - */ - private static ImageManager imageManager = getInstance(); - - /** - * This constructor takes no arguments. It is the private constructor used to - * make the singleton. - */ - private ImageManager() { - } - - /** - * Access to the image manager singleton - * - * @return the image manager singleton. - */ - public static synchronized ImageManager getInstance() { - if (imageManager == null) { - try { - imageManager = new ImageManager(); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - return imageManager; - } - - /** - * Load an image from file or the jar file. - * - * @param imageFileName the image files name. - * @param component a component to serve as an ImageObserver(any component - * should do). - * @return the image - */ - public Image loadImage(String imageFileName, Component component) { - - URL imageURL = getClass().getClassLoader().getResource(imageFileName); - Image image = null; - - if (imageURL != null) { - - // try the hashtable first - image = (imageHashtable.get(imageURL)); - - if (image == null) { - image = loadImageFromURL(imageURL, component); - if (image != null) { - imageHashtable.put(imageURL, image); - } - } - } - - return image; - } - - /** - * Load an image icon from a buffered image. - * - * @param bufferedImage the buffered image. - * @param hashKey the hashtable key. - * @return the image icon. - */ - public ImageIcon loadImageIcon(BufferedImage bufferedImage, String hashKey) { - if (bufferedImage == null) { - return null; - } - - ImageIcon icon = imageIconHashtable.get(hashKey); - if (icon != null) { - return icon; - } - - if (icon == null) { - icon = new ImageIcon(bufferedImage); - - if (icon != null) { - imageIconHashtable.put(hashKey, icon); - } - } - - return icon; - } - - /** - * Load an image icon from file or the jar file. - * - * @param imageFileName the image file name, relative to class path. - * @return the loaded ImageIcon, or null. - */ - public ImageIcon loadImageIcon(String imageFileName) { - - // try the image icon cache - ImageIcon icon = imageIconHashtable.get(imageFileName); - if (icon != null) { - return icon; - } - - // try from local file - File file = new File(imageFileName); - if (file.exists() && file.canRead()) { - icon = new ImageIcon(imageFileName); - if (icon != null) { - imageIconHashtable.put(imageFileName, icon); - return icon; - } - } - - URL imageURL = getClass().getClassLoader().getResource(imageFileName); - - if (imageURL != null) { - - icon = new ImageIcon(imageURL); - if (icon != null) { - imageIconHashtable.put(imageFileName, icon); - } - } - - return icon; - } - - /** - * Load an image from a local file. - * - * @param fileName the name of the file holding the image. It will first treat - * this as an absolute path. If that fails, it will try to uses - * it relative to the current working directory. If that fails, - * relative to the home directory. If that fails, we cave. - * @param component a component to use as an observer. Any component should do. - * @return the loaded image, or null. - */ - public Image loadImageFromFile(String fileName, Component component) { - - File file = new File(fileName); - if (!file.exists() || !file.canRead()) { - file = new File(Environment.getInstance().getCurrentWorkingDirectory(), fileName); - if (!file.exists() || !file.canRead()) { - file = new File(Environment.getInstance().getHomeDirectory(), fileName); - if (!file.exists() || !file.canRead()) { - Throwable t = new Throwable("Could not find image file: " + fileName); - t.printStackTrace(); - return null; - } - } - } - - Image image = Toolkit.getDefaultToolkit().getImage(file.getPath()); - - try { - int id = 0; - MediaTracker tracker = new MediaTracker(component); - tracker.addImage(image, id); - tracker.waitForAll(); - - } - catch (Exception e) { - e.printStackTrace(); - } - - return image; - } - - /** - * Load an image from a URL - * - * @param url The url of the image - * @param c A component to use as an observer - * @return the image found at the url - */ - public Image loadImageFromURL(URL url, Component c) { - Image image = Toolkit.getDefaultToolkit().getImage(url); - - try { - - int id = 0; - MediaTracker tracker = new MediaTracker(c); - tracker.addImage(image, id); - tracker.waitForAll(); - - } - catch (Exception e) { - e.printStackTrace(); - } - - return image; - } - - /** - * Try to obtain an ImageIcon from the cache. - * - * @param key the has key. - * @return an ImageIcom from the key, or null. - */ - public ImageIcon get(String key) { - return imageIconHashtable.get(key); - } - - /** - * Place an ImageIcon into the cache. - * - * @param key the hask key to use. - * @param imageIcon the ImageIcon to cache. - */ - public void put(String key, ImageIcon imageIcon) { - if (imageIcon != null) { - imageIconHashtable.put(key, imageIcon); - } - } - - /** - * Singleton objects cannot be cloned, so we override clone to throw a - * CloneNotSupportedException. - */ - @Override - public Object clone() throws CloneNotSupportedException { - throw new CloneNotSupportedException(); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/Legend.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/Legend.java deleted file mode 100644 index d7042c9253..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/Legend.java +++ /dev/null @@ -1,182 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.util.Collection; -import cnuphys.splot.fit.Fit; -import cnuphys.splot.fit.FitType; -import cnuphys.splot.pdata.DataColumn; -import cnuphys.splot.pdata.DataColumnType; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.style.Styled; -import cnuphys.splot.style.SymbolDraw; -import cnuphys.splot.style.SymbolType; - -public class Legend extends DraggableRectangle { - - // the owner plot panel - private PlotCanvas _canvas; - - // the plot parameters - private PlotParameters _params; - - // gap before text - private final int HGAP = 8; - - // extra v gap - private final int VGAP = 6; - - private int _maxStringWidth; - private int _extra; - - private int _numVisCurves; - - /** - * Create a Legend rectangle - * - * @param canvas the parent plot canvas - */ - public Legend(PlotCanvas canvas) { - _canvas = canvas; - _params = canvas.getParameters(); - } - - /** - * Draw the legend - * - * @param g the graphics context - */ - public void draw(Graphics g) { - // System.err.println(toString()); - DataSet ds = _canvas.getDataSet(); - - if (ds == null) { - return; - } - - if (ds.getAllVisibleCurves().isEmpty()) { - return; - } - - _numVisCurves = ds.getAllVisibleCurves().size(); - - if (_numVisCurves == 1) { - DataColumn dc = ds.getCurve(0); - if (!dc.isHistogram1D()) { - return; - } - } - - width = getLegendWidth(); - height = getLegendHeight(); - - g.setColor(_params.getTextBackground()); - g.fillRect(x, y, width, height); - - if (_params.isLegendBorder()) { - g.setColor(_params.getTextBorderColor()); - g.drawRect(x, y, width, height); - } - - int yi = y + VGAP; - - Collection ycols = ds.getAllColumnsByType(DataColumnType.Y); - for (DataColumn curve : ycols) { - if (curve.isVisible()) { - yi = drawColumnLegendInfo(g, yi, curve); - } - } - } - - // draw the info for the given y column - private int drawColumnLegendInfo(Graphics g, int y, DataColumn curve) { - FontMetrics fm = _canvas.getFontMetrics(_params.getTextFont()); - g.setFont(_params.getTextFont()); - g.setColor(_params.getTextForeground()); - - Styled style = curve.getStyle(); - Fit fit = curve.getFit(); - int space = spaceNeeded(curve); - int yc = y + space / 2; - - String legStr = curve.getName(); - if (legStr == null) { - legStr = ""; - } - - if (curve.isHistogram1D()) { - legStr += (" " + curve.getHistoData().statStr()); - } - - g.drawString(legStr, x + width - _maxStringWidth - HGAP, yc + fm.getHeight() / 2); - - if ((_numVisCurves > 1) && fit.getFit() != FitType.NOLINE) { - GraphicsUtilities.drawStyleLine(g, style.getFitLineColor(), style.getFitLineWidth(), - style.getFitLineStyle(), x + HGAP, yc, x + HGAP + _params.getLegendLineLength(), yc); - } - - SymbolDraw.drawSymbol(g, x + HGAP + _extra / 2, yc, curve.getStyle()); - - return y + space + VGAP; - } - - // get required width of the legend - private int getLegendWidth() { - FontMetrics fm = _canvas.getFontMetrics(_params.getTextFont()); - DataSet ds = _canvas.getDataSet(); - - _maxStringWidth = 0; - _extra = 0; - - Collection ycols = ds.getAllColumnsByType(DataColumnType.Y); - for (DataColumn dc : ycols) { - if (dc.isVisible()) { - - Fit fit = dc.getFit(); - if ((_numVisCurves > 1) && fit.getFitType() != FitType.NOLINE) { - _extra = _params.getLegendLineLength(); - } - else { - Styled style = dc.getStyle(); - if (style.getSymbolType() != SymbolType.NOSYMBOL) { - _extra = Math.max(_extra, style.getSymbolSize()); - } - } - - String legStr = dc.getName(); - if (dc.isHistogram1D()) { - legStr += (" " + dc.getHistoData().statStr()); - } - - int sw = fm.stringWidth(legStr); - - _maxStringWidth = Math.max(_maxStringWidth, sw); - } - - } - - return _extra + _maxStringWidth + 3 * HGAP; - } - - // get required height of the legend - private int getLegendHeight() { - DataSet ds = _canvas.getDataSet(); - - int height = VGAP; - Collection ycols = ds.getAllColumnsByType(DataColumnType.Y); - for (DataColumn curve : ycols) { - if (curve.isVisible()) { - height += (VGAP + spaceNeeded(curve)); - } - } - - return height; - } - - // get the vertical space needed for a curve - private int spaceNeeded(DataColumn curve) { - FontMetrics fm = _canvas.getFontMetrics(_params.getTextFont()); - return Math.max(fm.getHeight(), curve.getStyle().getSymbolSize()); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/LimitsMethod.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/LimitsMethod.java deleted file mode 100644 index 4c4adc9056..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/LimitsMethod.java +++ /dev/null @@ -1,74 +0,0 @@ -package cnuphys.splot.plot; - -import java.util.EnumMap; - -import cnuphys.splot.style.EnumComboBox; - - -/** - * How we want to choose axes limits - * @author heddle - * - */ - -public enum LimitsMethod { - - MANUALLIMITS, ALGORITHMICLIMITS, USEDATALIMITS; - - /** - * A map for the names of the limit methods - */ - public static EnumMap names = new EnumMap(LimitsMethod.class); - - static { - names.put(MANUALLIMITS, "Manually enter limits"); - names.put(ALGORITHMICLIMITS, "Algorithmic limits"); - names.put(USEDATALIMITS, "Use data limits"); - } - - - /** - * Get the nice name of the enum. - * - * @return the nice name, for combo boxes, menus, etc. - */ - public String getName() { - return names.get(this); - } - - /** - * Returns the enum value from the name. - * - * @param name the name to match. - * @return the LimitsMethod that corresponds to the name. Returns - * null if no match is found. - */ - public static LimitsMethod getValue(String name) { - if (name == null) { - return null; - } - - for (LimitsMethod val : values()) { - // check the nice name - if (name.equalsIgnoreCase(val.getName())) { - return val; - } - // check the base name - if (name.equalsIgnoreCase(val.name())) { - return val; - } - } - return null; - } - - /** - * Obtain a combo box of choices. - * - * @param defaultChoice - * @return the combo box of limit methods - */ - public static EnumComboBox getComboBox(LimitsMethod defaultChoice) { - return new EnumComboBox(names, defaultChoice); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotCanvas.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotCanvas.java deleted file mode 100644 index 7fd2c9131a..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotCanvas.java +++ /dev/null @@ -1,1062 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Color; -import java.awt.Component; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.awt.geom.AffineTransform; -import java.awt.geom.NoninvertibleTransformException; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; -import java.io.File; -import java.util.Vector; - -import javax.imageio.ImageIO; -import javax.imageio.stream.ImageOutputStream; -import javax.swing.JComponent; -import javax.swing.JFileChooser; -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; -import javax.swing.Timer; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; -import javax.swing.filechooser.FileNameExtensionFilter; -import cnuphys.splot.edit.DataEditor; -import cnuphys.splot.edit.PlotPreferencesDialog; -import cnuphys.splot.pdata.DataChangeListener; -import cnuphys.splot.pdata.DataColumn; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.DataSetType; -import cnuphys.splot.pdata.Histo2DData; -import cnuphys.splot.pdata.HistoData; -import cnuphys.splot.pdata.NiceScale; -import cnuphys.splot.rubberband.IRubberbanded; -import cnuphys.splot.rubberband.Rubberband; -import cnuphys.splot.toolbar.CommonToolBar; -import cnuphys.splot.toolbar.IToolBarListener; -import cnuphys.splot.toolbar.ToolBarButton; -import cnuphys.splot.toolbar.ToolBarToggleButton; - -public class PlotCanvas extends JComponent - implements MouseListener, MouseMotionListener, IRubberbanded, IToolBarListener, TableModelListener, DataChangeListener { - - public static final String DONEDRAWINGPROP = "Done Drawing"; - public static final String TITLECHANGEPROP = "Plot Title Change"; - public static final String XLABELCHANGEPROP = "X Label Change"; - public static final String YLABELCHANGEPROP = "Y Label Change"; - public static final String DATACLEAREDPROP = "Data Cleared"; - - // used to fire property changes. Transient. - private long drawCount = 0; - - // default values for margins - private int _topMargin = 10; -// private int _leftMargin = 30; -// private int _bottomMargin = 30; - private int _rightMargin = 10; - - // for saving files - private static String _dataFilePath; - - // the bounds of the plot - private Rectangle _activeBounds; - - // redraw check for dynamic data adding - private boolean _needsRedraw; - private boolean _needsRescale; - - // the world system of the active area - private Rectangle2D.Double _worldSystem = new Rectangle2D.Double(0, 0, 1, 1); - - // convert from screen to data - protected AffineTransform _localToWorld; - protected AffineTransform _worldToLocal; - - // dataset being plotted - protected DataSet _dataSet; - - // plot parameters - protected PlotParameters _parameters; - - // work point - private Point2D.Double _workPoint = new Point2D.Double(); - - // plot ticks - private PlotTicks _plotTicks; - - // if this has a parent (optional), print applies to the - // parent. For example, the parent might be a PlotPanel - private Component _parent; - - // legend and floating label dragging - private Legend _legend; - - // extra and floating label dragging - private ExtraText _extra; - - // color gradient - private Gradient _gradient; - - // data drawer - private DataDrawer _dataDrawer; - - // for rubberbanding - private Rubberband _rubberband; - - // gives xy of mouse in plot coordinates - private String _locationString = " "; - - // toolbar controlling plot - private CommonToolBar _toolbar; - - // popup menu - private PlotPopupMenu _plotPopup; - - /** - * Create a plot canvas for plotting a dataset - * - * @param dataSet the dataset to plot. It might contain many curves - * @param plotTitle the plot title - * @param xLabel the x axis label - * @param yLabel the y axis label - */ - public PlotCanvas(DataSet dataSet, String plotTitle, String xLabel, String yLabel) { - - if (_dataFilePath == null) { - _dataFilePath = Environment.getInstance().getHomeDirectory(); - } - - setBackground(Color.white); - _parameters = new PlotParameters(this); - _parameters.setPlotTitle(plotTitle); - _parameters.setXLabel(xLabel); - _parameters.setYLabel(yLabel); - _plotTicks = new PlotTicks(this); - - // default to xy plot no errors - if (dataSet == null) { - try { - dataSet = new DataSet(DataSetType.XYY, "X", "Y"); - } - catch (DataSetException e) { - e.printStackTrace(); - } - } - - setDataSet(dataSet); - - ComponentAdapter componentAdapter = new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent ce) { - setAffineTransforms(); - repaint(); - } - }; - - _legend = new Legend(this); - _extra = new ExtraText(this); - _gradient = new Gradient(this); - _dataDrawer = new DataDrawer(this); - _plotPopup = new PlotPopupMenu(this); - setComponentPopupMenu(_plotPopup); - - if (dataSet != null) { - dataSet.addTableModelListener(this); - } - - addComponentListener(componentAdapter); - addMouseListener(this); - addMouseMotionListener(this); - - // every canvas has a swing timer - int delay = 1000; // milliseconds - ActionListener taskPerformer = new ActionListener() { - @Override - public void actionPerformed(ActionEvent evt) { - if (_needsRedraw) { - if (_needsRescale) { - setWorldSystem(); - } - repaint(); - } - _needsRescale = false; - _needsRedraw = false; - } - }; - new Timer(delay, taskPerformer).start(); - - } - - /** - * Get the DataSet type - * - * @return the data set type - */ - public DataSetType getType() { - if (_dataSet == null) { - return DataSetType.UNKNOWN; - } - return _dataSet.getType(); - } - - /** - * Get the plot title - * - * @return the plot title - */ - public String getTitle() { - return _parameters.getPlotTitle(); - } - - /** - * Get the plot parameters - * - * @return the plot parameters - */ - public PlotParameters getParameters() { - return _parameters; - } - - /** - * Set the parent component, probably a PlotPanel - * - * @param parent the optional parent component - */ - public void setParent(Component parent) { - _parent = parent; - } - - /** - * Set a new data set for the canvas - * - * @param ds the new dataset - */ - public void setDataSet(DataSet ds) { - - _dataSet = ds; - - ds.removeDataChangeListener(this); - ds.addDataChangeListener(this); - - - if (_dataSet != null) { - _dataSet.notifyListeners(); - } -// setWorldSystem(); - repaint(); - } - -// /** -// * Clear the plot of all data. It will have a null dataset. -// */ -// public void clearPlot() { -// _dataSet = null; -// setWorldSystem(); -// _parameters.setPlotTitle("No Plot"); -// -// firePropertyChange(DATACLEAREDPROP, 0, 1); -// repaint(); -// } - - /** - * Get the underlying dataset - * - * @return the underlying dataset - */ - public DataSet getDataSet() { - return _dataSet; - } - - /** - * Get the world boundary - * - * @return the world boundary - */ - public Rectangle.Double getWorld() { - return _worldSystem; - } - - /** - * Set the world system based on the dataset This is where the plot limits are - * set. - */ - public void setWorldSystem() { - - if (_worldSystem == null) { - _worldSystem = new Rectangle2D.Double(); - } - - // watch for no dataset - if (_dataSet == null) { - _worldSystem.setFrame(0, 0, 1, 1); - return; - } - - double xmin = _dataSet.getXmin(); - if (Double.isNaN(xmin)) { - return; - } - - double xmax = _dataSet.getXmax(); - double ymin = _dataSet.getYmin(); - double ymax = _dataSet.getYmax(); - - PlotParameters params = getParameters(); - - LimitsMethod xMethod = params.getXLimitsMethod(); - LimitsMethod yMethod = params.getYLimitsMethod(); - - switch (xMethod) { - case MANUALLIMITS: - xmin = params.getManualXMin(); - xmax = params.getManualXMax(); - break; - - case ALGORITHMICLIMITS: - NiceScale ns = new NiceScale(xmin, xmax, _plotTicks.getNumMajorTickX() + 2, _parameters.includeXZero()); - xmin = ns.getNiceMin(); - xmax = ns.getNiceMax(); - break; - - case USEDATALIMITS: //do nothing - break; - } - - switch (yMethod) { - case MANUALLIMITS: - ymin = params.getManualYMin(); - ymax = params.getManualYMax(); - break; - - case ALGORITHMICLIMITS: - NiceScale ns = new NiceScale(ymin, ymax, _plotTicks.getNumMajorTickY() + 2, _parameters.includeYZero()); - ymin = ns.getNiceMin(); - ymax = ns.getNiceMax(); - break; - - case USEDATALIMITS: //do nothing - break; - } - - _worldSystem.setFrame(xmin, ymin, xmax - xmin, ymax - ymin); - } - - /** - * Paint the canvas - * - * @param g the graphics context - */ - @Override - public void paintComponent(Graphics g) { - super.paintComponent(g); - - Rectangle b = getBounds(); - - g.setColor(getBackground()); - g.fillRect(0, 0, b.width, b.height); - - // super.paintComponent(g); - setAffineTransforms(); - - // draw the data - _dataDrawer.draw(g, _dataSet); - - // frame the active area - g.setColor(Color.black); - g.drawRect(_activeBounds.x, _activeBounds.y, _activeBounds.width, _activeBounds.height); - - // draw the ticks and legend - _plotTicks.draw(g); - - if (_parameters.isLegendDrawn()) { - _legend.draw(g); - } - - if (_parameters.extraDrawing()) { - _extra.draw(g); - } - - if (_parameters.gradientDrawing()) { - _gradient.draw(g); - } - - firePropertyChange(DONEDRAWINGPROP, drawCount, ++drawCount); - - } - - /** - * Data is being added, possibly very quickly, so lets schedule a redraw - * - * @param rescale if true the world system will also be rescaled - */ - public void needsRedraw(boolean rescale) { - _needsRedraw = true; - _needsRescale = _needsRescale || rescale; - } - - /** - * Get the active plot area - * - * @return the active plot area - */ - public Rectangle getActiveBounds() { - return _activeBounds; - } - - // set the active bounds from the component bounds and the margins - private void setActiveBounds() { - Rectangle bounds = getBounds(); - if (bounds == null) { - _activeBounds = null; - } - else { - int left = 0; - int top = 0; - int right = left + bounds.width; - int bottom = top + bounds.height; - - int bottomMargin = 25; - int leftMargin = 25; - - if (_parameters.getAxesFont() != null) { - FontMetrics fm = getFontMetrics(_parameters.getAxesFont()); - bottomMargin = 6 + fm.getHeight(); - leftMargin = 6 + fm.getHeight(); - } - - left += leftMargin; - top += _topMargin; - right -= _rightMargin; - bottom -= bottomMargin; - - if (_activeBounds == null) { - _activeBounds = new Rectangle(); - } - _activeBounds.setBounds(left, top, right - left, bottom - top); - } - - } - - // Get the transforms for world to local and vice versa - protected void setAffineTransforms() { - Rectangle bounds = getBounds(); - - if ((bounds == null) || (bounds.width < 1) || (bounds.height < 1)) { - _localToWorld = null; - _worldToLocal = null; - _activeBounds = null; - return; - } - - setActiveBounds(); - - if (_worldSystem == null) { - return; - } - - double scaleX = _worldSystem.width / _activeBounds.width; - double scaleY = _worldSystem.height / _activeBounds.height; - - _localToWorld = AffineTransform.getTranslateInstance(_worldSystem.x, _worldSystem.getMaxY()); - _localToWorld.concatenate(AffineTransform.getScaleInstance(scaleX, -scaleY)); - _localToWorld.concatenate(AffineTransform.getTranslateInstance(-_activeBounds.x, -_activeBounds.y)); - - try { - _worldToLocal = _localToWorld.createInverse(); - } - catch (NoninvertibleTransformException e) { - // e.printStackTrace(); - } - } - - /** - * The mouse has been dragged over the plot canvas - * - * @param e the mouseEvent - */ - @Override - public void mouseDragged(MouseEvent e) { - if (_legend.isDraggingPrimed()) { - _legend.setDragging(true); - } - - if (_legend.isDragging()) { - int dx = e.getX() - _legend.getCurrentPoint().x; - int dy = e.getY() - _legend.getCurrentPoint().y; - _legend.x += dx; - _legend.y += dy; - _legend.setCurrentPoint(e.getPoint()); - repaint(); - } - - if (_extra.isDraggingPrimed()) { - _extra.setDragging(true); - } - - if (_extra.isDragging()) { - int dx = e.getX() - _extra.getCurrentPoint().x; - int dy = e.getY() - _extra.getCurrentPoint().y; - _extra.x += dx; - _extra.y += dy; - _extra.setCurrentPoint(e.getPoint()); - repaint(); - } - - if (_gradient.isDraggingPrimed()) { - _gradient.setDragging(true); - } - - if (_gradient.isDragging()) { - int dx = e.getX() - _gradient.getCurrentPoint().x; - int dy = e.getY() - _gradient.getCurrentPoint().y; - _gradient.x += dx; - _gradient.y += dy; - _gradient.setCurrentPoint(e.getPoint()); - repaint(); - } - - } - - /** - * The mouse has moved over the plot canvas - * - * @param e the mouseEvent - */ - @Override - public void mouseMoved(MouseEvent e) { - - // System.err.println("Plot Canvas MMoved"); - if (_dataSet == null) { - return; - } - - Point pp = e.getPoint(); - - if ((_activeBounds == null) || (_worldSystem == null)) { - _locationString = " "; - } - - else if (!activeBoundsContains(pp.x, pp.y)) { - _locationString = " "; - } - else { - // pp.x -= _activeBounds.x; - // pp.y -= _activeBounds.y; - localToWorld(pp, _workPoint); - _locationString = String.format("(x, y) = (%7.2g, %-7.2g)
    count = %d", _workPoint.x, _workPoint.y, _dataSet.size()); - - if (_dataSet.is1DHistoSet()) { - Vector ycols = (Vector) _dataSet.getAllVisibleCurves(); - int size = ycols.size(); - - for (int i = 0; i < size; i++) { - HistoData hd = ycols.get(i).getHistoData(); - String s = HistoData.statusString(this, hd, pp, _workPoint); - if (s != null) { - Color lc = ycols.get(i).getStyle().getFitLineColor(); - _locationString += "  " + colorStr(s, GraphicsUtilities.colorToHex(lc)); - // break; - } - } - } - else if (_dataSet.is2DHistoSet()) { - Histo2DData h2d = _dataSet.getColumn(0).getHistoData2D(); - String s = Histo2DData.statusString(this, h2d, pp, _workPoint); - if (s != null) { - Color lc = Color.red; - _locationString += "  " + colorStr(s, GraphicsUtilities.colorToHex(lc)); - // break; - } - } - - } - } - - private String colorStr(String s, String color) { - return "" + s + ""; - } - - // this method includes the border - private boolean activeBoundsContains(int x, int y) { - if (_activeBounds == null) { - return false; - } - int l = _activeBounds.x; - if (x < l) { - return false; - } - - int t = _activeBounds.y; - if (y < t) { - return false; - } - - int r = l + _activeBounds.width; - if (x > r) { - return false; - } - - int b = t + _activeBounds.height; - if (y > b) { - return false; - } - - return true; - } - - /** - * Get the last updated location string - * - * @return - */ - public String getLocationString() { - return _locationString; - } - - /** - * The mouse has been clicked on the plot canvas - * - * @param e the mouseEvent - */ - @Override - public void mouseClicked(MouseEvent e) { - - if (_rubberband != null) { - return; - } - if (_parameters.isLegendDrawn() && _legend.contains(e.getPoint())) { - return; - } - - String command = toolbarCommand(); - - if (CommonToolBar.CENTER.equals(command)) { - recenterAtClick(e.getPoint()); - } - else if ((SwingUtilities.isLeftMouseButton(e) && e.isControlDown())) { - if (CommonToolBar.POINTER.equals(command)) { - _plotPopup.show(e.getComponent(), e.getX(), e.getY()); - } - - } - } - - private boolean isPointer() { - return (_toolbar == null) || _toolbar.isDefaultActivated(); - } - - /** - * The mouse has been pressed on plot canvas - * - * @param e the mouseEvent - */ - @Override - public void mousePressed(MouseEvent e) { - - String command = toolbarCommand(); - - if (isPointer() && _parameters.isLegendDrawn() && _legend.contains(e.getPoint())) { - _legend.setDraggingPrimed(true); - _legend.setCurrentPoint(e.getPoint()); - } - else if (isPointer() && _parameters.extraDrawing() && _extra.contains(e.getPoint())) { - _extra.setDraggingPrimed(true); - _extra.setCurrentPoint(e.getPoint()); - } - else if (isPointer() && _parameters.gradientDrawing() && _gradient.contains(e.getPoint())) { - _gradient.setDraggingPrimed(true); - _gradient.setCurrentPoint(e.getPoint()); - } - - else { - - if (CommonToolBar.BOXZOOM.equals(command) && (_rubberband == null)) { - - if (getDataSet().is1DHistoSet()) { - - if (e.isShiftDown()) { - _rubberband = new Rubberband(this, this, Rubberband.Policy.XONLY); - } - else { - _rubberband = new Rubberband(this, this, Rubberband.Policy.YONLY); - } - - } - else { - _rubberband = new Rubberband(this, this, Rubberband.Policy.RECTANGLE); - } - _rubberband.setActive(true); - _rubberband.startRubberbanding(e.getPoint()); - } - - } - - } - - // get the active toolbar toggle butto command - private String toolbarCommand() { - return (_toolbar != null) ? _toolbar.getActiveCommand() : CommonToolBar.POINTER; - } - - /** - * The mouse has been released on plot canvas. A release comes before the click - * - * @param e the mouseEvent - */ - @Override - public void mouseReleased(MouseEvent e) { - _legend.setDragging(false); - _legend.setDraggingPrimed(false); - _legend.setCurrentPoint(null); - _extra.setDragging(false); - _extra.setDraggingPrimed(false); - _extra.setCurrentPoint(null); - _gradient.setDragging(false); - _gradient.setDraggingPrimed(false); - _gradient.setCurrentPoint(null); - } - - /** - * The mouse has entered the area of the plot canvas - * - * @param e the mouseEvent - */ - @Override - public void mouseEntered(MouseEvent e) { - - } - - /** - * The mouse has exited the area of the plot canvas - * - * @param e the mouseEvent - */ - @Override - public void mouseExited(MouseEvent e) { - } - - /** - * This converts a screen or pixel point to a world point. - * - * @param pp contains the local (screen-pixel) point. - * @param wp will hold the resultant world point. - */ - public void localToWorld(Point pp, Point.Double wp) { - if (_localToWorld != null) { - _localToWorld.transform(pp, wp); - } - } - - /** - * This converts a screen or pixel rectangle to a world rectangle. - * - * @param pr contains the local (screen-pixel) rectangle. - * @param wr will hold the resultant world rectangle. - */ - public void localToWorld(Rectangle pr, Rectangle2D.Double wr) { - if (_localToWorld != null) { - int l = pr.x; - int t = pr.y; - int r = l + pr.width; - int b = t + pr.height; - Point pplt = new Point(l, t); - Point pprb = new Point(r, b); - Point.Double wplt = new Point.Double(); - Point.Double wprb = new Point.Double(); - _localToWorld.transform(pplt, wplt); - _localToWorld.transform(pprb, wprb); - wr.x = Math.min(wplt.x, wprb.x); - wr.y = Math.min(wplt.y, wprb.y); - wr.width = Math.abs(wplt.x - wprb.x); - wr.height = Math.abs(wplt.y - wprb.y); - } - } - - /** - * This converts a world point to a screen or pixel point. - * - * @param pp will hold the resultant local (screen-pixel) point. - * @param wp contains world point. - */ - public void worldToLocal(Point pp, Point.Double wp) { - if (_worldToLocal != null) { - _worldToLocal.transform(wp, pp); - } - } - - public void worldToLocal(Rectangle r, Rectangle.Double wr) { - // New version to accommodate world with x decreasing right - Point2D.Double wp0 = new Point2D.Double(wr.getMinX(), wr.getMinY()); - Point2D.Double wp1 = new Point2D.Double(wr.getMaxX(), wr.getMaxY()); - Point p0 = new Point(); - Point p1 = new Point(); - worldToLocal(p0, wp0); - worldToLocal(p1, wp1); - - // Old version - // Point2D.Double wp0 = new Point2D.Double(wr.x, wr.y); - // Point2D.Double wp1 = new Point2D.Double(wr.x + wr.width, wr.y + - // wr.height); - // Point p0 = new Point(); - // Point p1 = new Point(); - // worldToLocal(p0, wp0); - // worldToLocal(p1, wp1); - - int x = Math.min(p0.x, p1.x); - int y = Math.min(p0.y, p1.y); - int w = Math.abs(p1.x - p0.x); - int h = Math.abs(p1.y - p0.y); - r.setBounds(x, y, w, h); - } - - // /** - // * The data set has changed, so we must redraw. - // * - // * @param dataset the dataset that changed. - // */ - // @Override - // public void dataSetChanged(DataSet dataSet) { - // setWorldSystem(); - // repaint(); - // } - - @Override - public void doneRubberbanding() { - _toolbar.resetDefaultSelection(); - Rectangle rbrect = _rubberband.getRubberbandBounds(); - if ((rbrect.width < 15) || (rbrect.height < 15)) { - return; - } - - localToWorld(rbrect, _worldSystem); - -// if (getDataSet().is1DHistoSet()) { -// // preserve full y -// double y = _worldSystem.y; -// double h = _worldSystem.height; -// localToWorld(rbrect, _worldSystem); -// _worldSystem.y = y; -// _worldSystem.height = h; -// } -// else { -// } - _rubberband = null; - repaint(); - } - - /** - * Center the plot world at the click. - * - * @param pp - */ - public void recenterAtClick(Point pp) { - Point.Double wp = new Point.Double(); - localToWorld(pp, wp); - - _worldSystem.x = wp.x - _worldSystem.width / 2; - _worldSystem.y = wp.y - _worldSystem.height / 2; - repaint(); - } - - /** - * Scale the canvas by a given amount - * - * @param amount the factor to scale by - */ - public void scale(double amount) { - double xc = _worldSystem.getCenterX(); - double w = _worldSystem.width * amount; - double x = xc - w / 2; - - double h; - double y; - - h = _worldSystem.height * amount; - double yc = _worldSystem.getCenterY(); - y = yc - h / 2; - _worldSystem.setFrame(x, y, w, h); - repaint(); - } - - @Override - public void buttonPressed(CommonToolBar toolbar, ToolBarButton button) { - _toolbar = toolbar; - doButtonAction(button.getActionCommand()); - } - - public void doButtonAction(String command) { - if (CommonToolBar.ZOOMIN.equals(command)) { - scale(0.85); - } - if (CommonToolBar.ZOOMOUT.equals(command)) { - scale(1. / 0.85); - } - if (CommonToolBar.WORLD.equals(command)) { - setWorldSystem(); - repaint(); - } - if (CommonToolBar.PRINT.equals(command)) { - print(); - } - - if (CommonToolBar.PNG.equals(command)) { - takePicture(); - } - } - - /** - * Print - */ - public void print() { - PrintUtilities.printComponent((_parent != null) ? _parent : this); - } - - public File getSavePngFile() { - FileNameExtensionFilter filter = new FileNameExtensionFilter("PNG File", "png", "PNG"); - - File selectedFile = null; - JFileChooser chooser = new JFileChooser(_dataFilePath); - chooser.setSelectedFile(null); - chooser.setFileFilter(filter); - int returnVal = chooser.showSaveDialog(this); - if (returnVal == JFileChooser.APPROVE_OPTION) { - selectedFile = chooser.getSelectedFile(); - if (selectedFile != null) { - - if (selectedFile.exists()) { - int answer = JOptionPane.showConfirmDialog(null, - selectedFile.getAbsolutePath() + " already exists. Do you want to overwrite it?", - "Overwite Existing File?", JOptionPane.YES_NO_OPTION); - - if (answer != JFileChooser.APPROVE_OPTION) { - selectedFile = null; - } - } // end file exists check - } - } - - return selectedFile; - } - - /** - * Take a picture, sanve as png - */ - public void takePicture() { - try { - - // try making a png - if (Environment.getInstance().getPngWriter() != null) { - - File file = getSavePngFile(); - if (file == null) { - return; - } - - // Buffered image object to be written to depending on the view - // type - BufferedImage bi; - - ImageOutputStream ios = ImageIO.createImageOutputStream(file); - Environment.getInstance().getPngWriter().setOutput(ios); - - bi = GraphicsUtilities.getComponentImage((_parent != null) ? _parent : this); - - Environment.getInstance().getPngWriter().write(bi); - ios.close(); - } - } - catch (Exception e) { - e.printStackTrace(); - } - - } - - @Override - public void toggleButtonActivated(CommonToolBar toolbar, ToolBarToggleButton button) { - _toolbar = toolbar; - } - - /** - * Show the plot preferences dialog - */ - public void showPreferencesEditor() { - PlotPreferencesDialog prefEditor = new PlotPreferencesDialog(this); - prefEditor.setVisible(true); - prefEditor.toFront(); - } - - /** - * Show the data editor - */ - public void showDataEditor() { - DataEditor dataEditor = new DataEditor(this); - dataEditor.setVisible(true); - dataEditor.toFront(); - } - - /** - * Used so another object can tell the plot canvas to fire a propert change - * event - * - * @param propName - * @param oldValue - * @param newValue - */ - public void remoteFirePropertyChange(String propName, Object oldValue, Object newValue) { - firePropertyChange(propName, oldValue, newValue); - } - - @Override - public void tableChanged(TableModelEvent e) { - setWorldSystem(); - needsRedraw(false); - } - - /** - * Get the canavas's plot ticks - * - * @return the plot ticks - */ - public PlotTicks getPlotTicks() { - return _plotTicks; - } - - /** - * Get the canvas's color gradient - * - * @return the color gradient - */ - public Gradient getGradient() { - return _gradient; - } - - /** - * Set which toggle button is selected - */ - public void setSelectedToggle(String s) { - if ((_parent != null) && (_parent instanceof PlotPanel)) { - PlotPanel ppan = (PlotPanel) _parent; - if (ppan._toolbar != null) { - ppan._toolbar.setSelectedToggle(s); - } - } - } - - @Override - public void dataSetChanged(DataSet dataSet) { - setWorldSystem(); - needsRedraw(false); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotGrid.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotGrid.java deleted file mode 100644 index 869b670fa9..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotGrid.java +++ /dev/null @@ -1,97 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.GridLayout; -import java.util.Vector; - -import javax.swing.JPanel; - -import cnuphys.splot.pdata.DataSet; - -public class PlotGrid extends JPanel { - - private int _numRow; - private int _numCol; - private Vector _panels = new Vector(); - - /** - * Create a plot grid of independent canvases - * - * @param numRow the number of rows - * @param numCol the number of columns - */ - public PlotGrid(int numRow, int numCol) { - _numRow = numRow; - _numCol = numCol; - setLayout(new GridLayout(numRow, numCol, 2, 2)); - } - - /** - * Add a plot panel to the grid - * - * @param panel the plot panel - */ - public void addPlotPanel(PlotPanel panel) { - if (panel != null) { - add(panel); - _panels.add(panel); - } - } - - /** - * Add a plot canvas to the grid - * - * @param canvas the plot canvas - */ - public void addPlotCanvas(PlotCanvas canvas) { - if (canvas != null) { - PlotPanel panel = new PlotPanel(canvas); - addPlotPanel(panel); - } - } - - // convert row and col to index - private int rowColToIndex(int row, int col) { - return row * _numCol + col; - } - - /** - * Obtain the plot panel from the 0-based row and column - * - * @param row the row index - * @param col the column index - * @return the plot panel or null. - */ - public PlotPanel getPlotPanel(int row, int col) { - int index = rowColToIndex(row, col); - - if ((index < 0) || (index >= _panels.size())) { - return null; - } - return _panels.get(index); - } - - /** - * Obtain the plot canvas from the 0-based row and column - * - * @param row the row index - * @param col the column index - * @return the plot canvas or null. - */ - public PlotCanvas getPlotCanvas(int row, int col) { - PlotPanel panel = getPlotPanel(row, col); - return (panel == null) ? null : panel.getCanvas(); - } - - /** - * Obtain the data from the 0-based row and column - * - * @param row the row index - * @param col the column index - * @return the dataset or null. - */ - public DataSet getDataSet(int row, int col) { - PlotCanvas canvas = getPlotCanvas(row, col); - return (canvas == null) ? null : canvas.getDataSet(); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotGridDialog.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotGridDialog.java deleted file mode 100644 index 39be8c252e..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotGridDialog.java +++ /dev/null @@ -1,34 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.BorderLayout; -import java.awt.Font; -import javax.swing.JDialog; -import javax.swing.JFrame; - -public class PlotGridDialog extends JDialog { - - protected Font _titleFont = Environment.getInstance().getCommonFont(12); - protected Font _statusFont = Environment.getInstance().getCommonFont(9); - protected Font _axesFont = Environment.getInstance().getCommonFont(10); - protected Font _legendFont = Environment.getInstance().getCommonFont(10); - - protected PlotGrid _plotGrid; - - /** - * - * @param owner - * @param title - * @param modal - * @param numRow the number of rows - * @param numCol the number of columns - */ - public PlotGridDialog(JFrame owner, String title, boolean modal, int numRow, int numCol, int width, int height) { - super(owner, title, modal); - - _plotGrid = new PlotGrid(numRow, numCol); - add(_plotGrid, BorderLayout.CENTER); - - setSize(width, height); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotLine.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotLine.java deleted file mode 100644 index d6345f8469..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotLine.java +++ /dev/null @@ -1,78 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Graphics; -import java.awt.Point; - -import cnuphys.splot.style.Styled; - -/** - * Just a straight line to be drawn on the plot, e.g. a y = 0 line - * - * @author heddle - * - */ -public abstract class PlotLine { - -// public Styled(Color fillColor, Color borderColor, Color fitLineColor, Color auxLineColor, LineStyle fitLineStyle, -// LineStyle auxLineStyle, float fitLineWidth, float auxLineWidth, SymbolType symbolType, int symbolSize) { - - // default style - protected static Styled _defaultStyle = new Styled(); - - // the plot canvas - protected PlotCanvas _canvas; - - // init style to default - protected Styled _style = _defaultStyle; - - // work points - protected Point p0 = new Point(); - protected Point p1 = new Point(); - protected Point.Double wp = new Point.Double(); - - public PlotLine(PlotCanvas canvas) { - _canvas = canvas; - } - - /** - * Set the line drawing style - * - * @param style the new style - */ - public void setStyle(Styled style) { - _style = style; - } - - /** - * Get the line style - * - * @return the line style - */ - public Styled getStyle() { - return _style; - } - - /** - * Draw the line - * - * @param g the graphis context - */ - public void draw(Graphics g) { - wp.setLocation(getX0(), getY0()); - _canvas.worldToLocal(p0, wp); - wp.setLocation(getX1(), getY1()); - _canvas.worldToLocal(p1, wp); - - GraphicsUtilities.drawStyleLine(g, _style.getAuxLineColor(), _style.getAuxLineWidth(), _style.getAuxLineStyle(), - p0.x, p0.y, p1.x, p1.y); - } - - public abstract double getX0(); - - public abstract double getX1(); - - public abstract double getY0(); - - public abstract double getY1(); - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotPanel.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotPanel.java deleted file mode 100644 index 85d3f44641..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotPanel.java +++ /dev/null @@ -1,330 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.Insets; -import java.awt.event.MouseEvent; -import java.awt.event.MouseMotionAdapter; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; - -import javax.swing.BorderFactory; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.SwingConstants; -import javax.swing.border.Border; - -import cnuphys.splot.toolbar.CommonToolBar; - -public class PlotPanel extends JPanel implements PropertyChangeListener { - - // the underlying plot canvas - private PlotCanvas _canvas; - - // title related - private JLabel _titleLabel; - - // status label - private JLabel _status; - - // axes labels - private JLabel _xLabel; - private JLabel _yLabel; - - // how adorned - public static int VERYBARE = -2; - public static int BARE = 1; - public static int STANDARD = 0; - - // toolbar - protected CommonToolBar _toolbar; - - protected int _decorations; - - /** - * Create a plot panel for a single xy dataset and a toolbar - * - * @param canvas - */ - public PlotPanel(PlotCanvas canvas) { - this(canvas, STANDARD); - } - - /** - * Create a plot panel for a single xy dataset - * - * @param canvas - * @param decorations (stripped down panel?) - */ - public PlotPanel(PlotCanvas canvas, int decorations) { - _canvas = canvas; - _canvas.setParent(this); - _decorations = decorations; - - Environment.getInstance().commonize(this, null); - setLayout(new BorderLayout(0, 0)); - - _canvas.addPropertyChangeListener(this); - add(_canvas, BorderLayout.CENTER); - - addSouth(); - addNorth(); - addWest(); - - if (_decorations == STANDARD) { - // update the status line with the mouse plot coordinates of the - // mouse - MouseMotionAdapter mma = new MouseMotionAdapter() { - @Override - public void mouseMoved(MouseEvent me) { - if (_status != null) { - _status.setText(_canvas.getLocationString()); - } - } - }; - - _canvas.addMouseMotionListener(mma); - } - - } - - @Override - public Insets getInsets() { - Insets def = super.getInsets(); - return new Insets(def.top + 2, def.left + 2, def.bottom + 2, def.right + 2); - } - - private void addSouth() { - // south panel for x axis and status - JPanel spanel = new JPanel(); - Environment.getInstance().commonize(spanel, null); - - spanel.setLayout(new BorderLayout()); - spanel.setOpaque(true); - spanel.setBackground(Color.white); - PlotParameters parameters = _canvas.getParameters(); - - // axes labels - _xLabel = makeJLabel(parameters.getXLabel(), parameters.getAxesFont(), SwingConstants.CENTER, Color.white, null, - false); - _xLabel.setAlignmentX(Component.CENTER_ALIGNMENT); - spanel.add(_xLabel, BorderLayout.CENTER); - - // status label - if (_decorations == STANDARD) { - - _status = makeStatusLabel(); - -// _status = makeJLabel(" ", parameters.getStatusFont(), -// SwingConstants.CENTER, new Color(240, 240, 240), -// Color.blue, true); - - _status.setAlignmentX(Component.CENTER_ALIGNMENT); - spanel.add(_status, BorderLayout.SOUTH); - } - - add(spanel, BorderLayout.SOUTH); - } - - // add the north component - private void addNorth() { - PlotParameters parameters = _canvas.getParameters(); - - // toolbar - _toolbar = new CommonToolBar(SwingConstants.HORIZONTAL) { - @Override - public void paint(Graphics g) { - // exclude from print - if (!PrintUtilities.isPrinting()) { - super.paint(g); - } - } - }; - _toolbar.addToolBarListener(_canvas); - - JPanel npanel = new JPanel(); - npanel.setOpaque(true); - npanel.setBackground(Color.white); - Environment.getInstance().commonize(npanel, null); - npanel.setLayout(new BorderLayout()); - - // title label - _titleLabel = makeJLabel(_canvas.getParameters().getPlotTitle(), parameters.getTitleFont(), - SwingConstants.CENTER, Color.white, null, false); - _titleLabel.setAlignmentX(Component.CENTER_ALIGNMENT); - _toolbar.setAlignmentX(Component.LEFT_ALIGNMENT); - - // if verybare, tool bar is hidden - if (_decorations != VERYBARE) { - npanel.add(_toolbar, BorderLayout.NORTH); - } - npanel.add(_titleLabel, BorderLayout.CENTER); - add(npanel, BorderLayout.NORTH); - } - - // add the west component - private void addWest() { - PlotParameters parameters = _canvas.getParameters(); - _yLabel = makeRotatedLabel(_canvas.getParameters().getYLabel(), parameters.getAxesFont(), Color.white, null); - add(_yLabel, BorderLayout.WEST); - } - - private JLabel makeStatusLabel() { - Font font = _canvas.getParameters().getStatusFont(); - FontMetrics fm = getFontMetrics(font); - final int height = 4 + 3 * (fm.getHeight() + 2); - Color bg = X11Colors.getX11Color("alice blue"); - - JLabel label = new JLabel() { - @Override - public void paint(Graphics g) { - // exclude from print - if (!PrintUtilities.isPrinting()) { - super.paint(g); - } - } - - @Override - public Dimension getPreferredSize() { - Dimension d = super.getPreferredSize(); - d.height = height; - return d; - } - - @Override - public Dimension getMinimumSize() { - Dimension d = super.getMinimumSize(); - d.height = height; - return d; - } - - @Override - public Dimension getMaximumSize() { - Dimension d = super.getMaximumSize(); - d.height = height; - return d; - } - - }; - - label.setFont(font); - label.setOpaque(true); - label.setBackground(bg); - label.setForeground(Color.black); - label.setHorizontalAlignment(SwingConstants.LEFT); - label.setVerticalAlignment(SwingConstants.CENTER); - - Border commonBorder = new CommonBorder(); - Border emptyBorder = BorderFactory.createLineBorder(bg, 2); - - label.setBorder(BorderFactory.createCompoundBorder(commonBorder, emptyBorder)); - - return label; - } - - // convenience function for making a label - private JLabel makeJLabel(String text, Font font, int alignment, Color bg, Color fg, boolean excludeFromPrint) { - - JLabel lab = null; - if (excludeFromPrint) { - lab = new JLabel(text != null ? text : " ") { - @Override - public void paint(Graphics g) { - // exclude from print - if (!PrintUtilities.isPrinting()) { - super.paint(g); - } - } - }; - } - else { - lab = new JLabel(text != null ? text : " "); - } - lab.setFont(font); - lab.setOpaque(true); - if (bg != null) { - lab.setBackground(bg); - } - if (fg != null) { - lab.setForeground(fg); - } - lab.setHorizontalAlignment(alignment); - lab.setVerticalAlignment(SwingConstants.CENTER); - return lab; - } - - // convenience function for making a rotated label for y axis label - private JLabel makeRotatedLabel(String text, Font font, Color bg, Color fg) { - JLabel lab = new JLabel(text); - lab.setFont(font); - lab.setOpaque(true); - lab.setUI(new VerticalLabelUI()); - lab.setHorizontalAlignment(SwingConstants.CENTER); - - if (bg != null) { - lab.setBackground(bg); - } - if (fg != null) { - lab.setForeground(bg); - } - return lab; - } - - /** - * Get the underlying plot canvas - * - * @return the plot canvas - */ - public PlotCanvas getCanvas() { - return _canvas; - } - - /** - * Get the plot parameters - * - * @return the plot parameters - */ - public PlotParameters getParameters() { - return _canvas.getParameters(); - } - - public void setColor(Color bg) { - super.setBackground(bg); - _canvas.setBackground(bg); - _titleLabel.setBackground(bg); - _xLabel.setBackground(bg); - _yLabel.setBackground(bg); - } - - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (PlotCanvas.TITLECHANGEPROP.equals(evt.getPropertyName())) { - _titleLabel.setText((String) evt.getNewValue()); - _titleLabel.repaint(); - } - else if (PlotCanvas.XLABELCHANGEPROP.equals(evt.getPropertyName())) { - _xLabel.setText((String) evt.getNewValue()); - _xLabel.repaint(); - } - else if (PlotCanvas.YLABELCHANGEPROP.equals(evt.getPropertyName())) { - _yLabel.setText((String) evt.getNewValue()); - _yLabel.repaint(); - } - - } - - /** - * Set which toggle button is selected - */ - public void setSelectedToggle(String s) { - if (_toolbar != null) { - _toolbar.setSelectedToggle(s); - } - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotParameters.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotParameters.java deleted file mode 100644 index acc0f250f7..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotParameters.java +++ /dev/null @@ -1,697 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Color; -import java.awt.Font; -import java.util.Vector; - -public class PlotParameters { - - // for legend - private Font _textFont = Environment.getInstance().getCommonFont(10); - private Color _textFillColor = new Color(248, 248, 248, 224); - private Color _textTextColor = Color.black; - private Color _textBorderColor = Color.black; - - // for extra text - private Font _extraFont = Environment.getInstance().getCommonFont(10); - private Color _extraFillColor = new Color(248, 248, 248, 224); - private Color _extraTextColor = Color.black; - private Color _extraBorderColor = Color.black; - - // force include zero on plots? - private boolean _includeYzero = false; - private boolean _includeXzero = false; - - //how axis limits are determined - private LimitsMethod _xLimitsMethod = LimitsMethod.ALGORITHMICLIMITS; - private LimitsMethod _yLimitsMethod = LimitsMethod.ALGORITHMICLIMITS; - - - // legend related - private int _legendLineLength = 70; - private boolean _legendBorder = true; - private boolean _drawLegend = true; - - // extra text - private boolean _extraBorder = true; - private boolean _drawExtra = true; - private String[] _extraStrings; - - // color scale - private boolean _drawGradient = false; - - private Font _titleFont = Environment.getInstance().getCommonFont(20); - private Font _axesLabelFont = Environment.getInstance().getCommonFont(14); - private String _plotTitle = "No Plot"; - private String _xLabel = "X Data"; - private String _yLabel = "Y Data"; - private Font _statusFont = Environment.getInstance().getCommonFont(10); - - // annotating lines - private Vector _lines = new Vector(); - - // the canvas - private PlotCanvas _canvas; - - // for tick values - private int _numDecimalX = 2; - private int _minExponentX = 2; - private int _numDecimalY = 2; - private int _minExponentY = 2; - - // if we set ranges manually - private double _manualXmin = Double.NaN; - private double _manualXmax = Double.NaN; - - private double _manualYmin = Double.NaN; - private double _manualYmax = Double.NaN; - - /** - * Create plot parameters for a canvas - * - * @param canvas the canvas - */ - public PlotParameters(PlotCanvas canvas) { - _canvas = canvas; - } - - /** - * Force the plot to include x = 0 - * - * @param incZero the flag - */ - public void mustIncludeXZero(boolean incZero) { - _includeXzero = incZero; - } - - /** - * Force the plot to include y = 0 - * - * @param incZero the flag - */ - public void mustIncludeYZero(boolean incZero) { - _includeYzero = incZero; - } - - /** - * Get the extra strings for a second legend like display - * - * @return the extra strings - */ - public String[] getExtraStrings() { - return _extraStrings; - } - - /** - * Set the extra strings for a second legend like display - * - * @param extraStrings the new extra strings array - */ - public void setExtraStrings(String... extraStrings) { - _extraStrings = extraStrings; - } - - /** - * Check whether the extra text border is drawn - * - * @return true if the extra text border is drawn. - */ - public boolean isExtraBorder() { - return _extraBorder; - } - - /** - * Set whether the extra text border is drawn - * - * @param extraBorder true if the extra text border is drawn. - */ - public void setExtraBorder(boolean extraBorder) { - _extraBorder = extraBorder; - } - - /** - * Check whether the legend border is drawn - * - * @return true if the legend border is drawn. - */ - public boolean isLegendBorder() { - return _legendBorder; - } - - /** - * Set whether the legend border is drawn - * - * @param legBorder true if the legend border is drawn. - */ - public void setLegendBorder(boolean legBorder) { - _legendBorder = legBorder; - } - - /** - * Set the legend fill color - * - * @param color the legendfill color - */ - public void setTextBackground(Color color) { - _textFillColor = color; - } - - /** - * Get the legend fill color - * - * @return the legend fill color - */ - public Color getTextBackground() { - return _textFillColor; - } - - /** - * Set the legend text color - * - * @param color the legend text color - */ - public void setTextForeground(Color color) { - _textTextColor = color; - } - - /** - * Get the legend text color - * - * @return the legend text color - */ - public Color getTextForeground() { - return _textTextColor; - } - - /** - * Get the legend border color - * - * @return the legend border color - */ - public Color getTextBorderColor() { - return _textBorderColor; - } - - /** - * Set the legend border color - * - * @param color the legend border color - */ - public void setTextBorderColor(Color color) { - _textBorderColor = color; - } - - /** - * Set the legend font - * - * @param font the legend font - */ - public void setTextFont(Font font) { - _textFont = font; - } - - /** - * Get the legend font - * - * @return the legend font - */ - public Font getTextFont() { - return _textFont; - } - - /** - * Set the extra text fill color - * - * @param color the extra text fill color - */ - public void setExtraBackground(Color color) { - _extraFillColor = color; - } - - /** - * Get the extra text fill color - * - * @return the extra text fill color - */ - public Color getExtraBackground() { - return _extraFillColor; - } - - /** - * Set the extra text color - * - * @param color the extra text color - */ - public void setExtraForeground(Color color) { - _extraTextColor = color; - } - - /** - * Get the extra text color - * - * @return the extra text color - */ - public Color getExtraForeground() { - return _extraTextColor; - } - - /** - * Get the extra text border color - * - * @return the extra text border color - */ - public Color getExtraBorderColor() { - return _extraBorderColor; - } - - /** - * Set the extra text border color - * - * @param color the extra text border color - */ - public void setExtraBorderColor(Color color) { - _extraBorderColor = color; - } - - /** - * Set the extra text font - * - * @param font the new extra text font - */ - public void setExtraFont(Font font) { - _extraFont = font; - } - - /** - * Get the extra text font - * - * @return the extra text font - */ - public Font getExtraFont() { - return _extraFont; - } - - /** - * Set the title font - * - * @param font the new title font - */ - public void setTitleFont(Font font) { - _titleFont = font; - } - - /** - * Get the title font - * - * @return the title font - */ - public Font getTitleFont() { - return _titleFont; - } - - /** - * Set the axes font - * - * @param font the new axes font - */ - public void setAxesFont(Font font) { - _axesLabelFont = font; - } - - /** - * Get the axes font - * - * @return the axes font - */ - public Font getAxesFont() { - return _axesLabelFont; - } - - /** - * Set the status font - * - * @param font the new status font - */ - public void setStatusFont(Font font) { - _statusFont = font; - } - - /** - * Get the status font - * - * @return the status font - */ - public Font getStatusFont() { - return _statusFont; - } - - /** - * Set the legend line length - * - * @param legLineLen the line length in pixels - */ - public void setLegendLineLength(int legLineLen) { - _legendLineLength = legLineLen; - } - - /** - * Get the legend line length - * - * @return legLineLen the line length in pixels - */ - public int getLegendLineLength() { - return _legendLineLength; - } - - /** - * Check whether to include x = 0 - * - * @return true if we should include x = 0 - */ - public boolean includeXZero() { - return _includeXzero; - } - - /** - * Check whether to include y = 0 - * - * @return true if we should include y = 0 - */ - public boolean includeYZero() { - return _includeYzero; - } - - /** - * Add a plot line to the plot - * - * @param line the line to add - */ - public void addPlotLine(PlotLine line) { - _lines.remove(line); - _lines.add(line); - } - - /** - * Remove a plot line from the plot - * - * @param line the line to remove - */ - public void removePlotLine(PlotLine line) { - _lines.remove(line); - } - - /** - * Get all the plot lines - * - * @return all the plot lines - */ - public Vector getPlotLines() { - return _lines; - } - - /** - * Get the plot title - * - * @return the plot title - */ - public String getPlotTitle() { - return _plotTitle; - } - - /** - * Set the plot title - * - * @param title the plot title - */ - public void setPlotTitle(String title) { - _canvas.remoteFirePropertyChange(PlotCanvas.TITLECHANGEPROP, getPlotTitle(), title); - _plotTitle = title; - } - - /** - * Get the label for the x axis - * - * @return the label for the x axis - */ - public String getXLabel() { - return _xLabel; - } - - /** - * Get the label for the y axis - * - * @return the label for the y axis - */ - public String getYLabel() { - return _yLabel; - } - - /** - * Set the x axis label - * - * @param label the plot x axis label - */ - public void setXLabel(String label) { - _canvas.remoteFirePropertyChange(PlotCanvas.XLABELCHANGEPROP, getXLabel(), label); - _xLabel = label; - } - - /** - * Set the y axis label - * - * @param label the plot y axis label - */ - public void setYLabel(String label) { - _canvas.remoteFirePropertyChange(PlotCanvas.YLABELCHANGEPROP, getYLabel(), label); - _yLabel = label; - } - - /** - * Check whether we should draw extra text - * - * @return whether we should draw the extra text - */ - public boolean extraDrawing() { - return _drawExtra; - } - - /** - * Set whether we should draw the extra text - * - * @param draw the new drawing flag - */ - public void setExtraDrawing(boolean draw) { - _drawExtra = draw; - } - - /** - * Check whether we should draw a legend - * - * @return whether we should draw a legend - */ - public boolean isLegendDrawn() { - return _drawLegend; - } - - /** - * Set whether we should draw a legend - * - * @param draw the new drawing flag - */ - public void setLegendDrawing(boolean draw) { - _drawLegend = draw; - } - - /** - * Check whether we should draw a gradient - * - * @return whether we should draw a legend - */ - public boolean gradientDrawing() { - return _drawGradient; - } - - /** - * Set whether we should draw a gradient - * - * @param draw the new drawing flag - */ - public void setGradientDrawing(boolean draw) { - _drawGradient = draw; - } - - /** - * The number of decimals for tick values on x axis - * - * @return the numDecimalX - */ - public int getNumDecimalX() { - return _numDecimalX; - } - - /** - * Set the number of decimals for tick values on x axis - * - * @param numDecimalX the numDecimalX to set - */ - public void setNumDecimalX(int numDecimalX) { - _numDecimalX = numDecimalX; - } - - /** - * The exponent where we switch to scientific notation on the x axis - * - * @return the minExponentX - */ - public int getMinExponentX() { - return _minExponentX; - } - - /** - * Set the exponent where we switch to scientific notation on the x axis - * - * @param minExponentX the minExponentX to set - */ - public void setMinExponentX(int minExponentX) { - _minExponentX = minExponentX; - } - - /** - * The number of decimals for tick values on y axis - * - * @return the numDecimalY - */ - public int getNumDecimalY() { - return _numDecimalY; - } - - /** - * Set the number of decimals for tick values on y axis - * - * @param numDecimalY the numDecimalY to set - */ - public void setNumDecimalY(int numDecimalY) { - _numDecimalY = numDecimalY; - } - - /** - * The exponent where we switch to scientific notation on the y axis - * - * @return the minExponentY - */ - public int getMinExponentY() { - return _minExponentY; - } - - /** - * Set the exponent where we switch to scientific notation on the y axis - * - * @param minExponentY the minExponentY to set - */ - public void setMinExponentY(int minExponentY) { - _minExponentY = minExponentY; - } - - /** - * Manually set the x range - * - * @param xmin the minimum x - * @param xmax the maximum x - */ - public void setXRange(double xmin, double xmax) { - setXLimitsMethod(LimitsMethod.MANUALLIMITS); - _manualXmin = xmin; - _manualXmax = xmax; - _canvas.setWorldSystem(); - } - - /** - * Manually set the y range - * - * @param ymin the minimum y - * @param ymax the maximum y - */ - public void setYRange(double ymin, double ymax) { - setYLimitsMethod(LimitsMethod.MANUALLIMITS); - _manualYmin = ymin; - _manualYmax = ymax; - _canvas.setWorldSystem(); - } - - - /** - * Get the minimum value for a manual X range - * - * @return the value for a manual X range - */ - public double getManualXMin() { - return _manualXmin; - } - - /** - * Get the maximum value for a manual X range - * - * @return the value for a manual X range - */ - public double getManualXMax() { - return _manualXmax; - } - - /** - * Get the minimum value for a manual Y range - * - * @return the value for a manual Y range - */ - public double getManualYMin() { - return _manualYmin; - } - - /** - * Get the maximum value for a manual Y range - * - * @return the value for a manual Y range - */ - public double getManualYMax() { - return _manualYmax; - } - - /** - * Get the limit method for the x axis - * @return the limit method for the x axis - */ - public LimitsMethod getXLimitsMethod() { - return _xLimitsMethod; - } - - /** - * Set the limits method for the x axis - * - * @param method the method - */ - public void setXLimitsMethod(LimitsMethod method) { - if (_xLimitsMethod != method) { - _xLimitsMethod = method; - } - } - - /** - * Get the limit method for the y axis - * @return the limit method for the y axis - */ - public LimitsMethod getYLimitsMethod() { - return _yLimitsMethod; - } - - /** - * Set the limits method for the y axis - * - * @param method the method - */ - public void setYLimitsMethod(LimitsMethod method) { - if (_yLimitsMethod != method) { - _yLimitsMethod = method; - } - } - - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotPopupMenu.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotPopupMenu.java deleted file mode 100644 index 70bff290c9..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotPopupMenu.java +++ /dev/null @@ -1,18 +0,0 @@ -package cnuphys.splot.plot; - -import javax.swing.JPopupMenu; - -public class PlotPopupMenu extends JPopupMenu { - - // the owner canvas - protected PlotCanvas _plotCanvas; - - // all the menus and items - protected SplotMenus _menus; - - public PlotPopupMenu(PlotCanvas plotCanvas) { - _plotCanvas = plotCanvas; - _menus = new SplotMenus(_plotCanvas, this, false); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotTicks.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotTicks.java deleted file mode 100644 index 73f6d3f693..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PlotTicks.java +++ /dev/null @@ -1,258 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Color; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.geom.Point2D; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.HistoData; - -public class PlotTicks { - - private int majorTickLen = 6; - private int minorTickLen = 2; - private int numMajorTickX = 4; // interior ticks - private int numMinorTickX = 4; // interior ticks - private int numMajorTickY = 4; // interior ticks - private int numMinorTickY = 4; // interior ticks - - // draw 1-based bin instead of value - private boolean drawBinValue; - - private Color _tickColor = Color.black; - - private Font _tickFont = Environment.getInstance().getCommonFont(11); - - // plot owner - private PlotCanvas _plotCanvas; - - // work points - private Point _pp = new Point(); - private Point2D.Double _wp = new Point2D.Double(); - - public PlotTicks(PlotCanvas plotCanvas) { - _plotCanvas = plotCanvas; - } - - public void setTickFont(Font font) { - _tickFont = font; - } - - /** - * Sets whether we want to draw the bin values on the x axis. Only relevant for - * histograms - * - * @param drawBinVal the value - */ - public void setDrawBinValue(boolean drawBinVal) { - if (_plotCanvas._dataSet.is1DHistoSet()) { - drawBinValue = drawBinVal; - } - } - - /** - * Draw the plot ticks - * - * @param g the Graphics context - */ - public void draw(Graphics g) { - Rectangle ab = _plotCanvas.getActiveBounds(); - if (ab == null) { - return; - } - - Rectangle.Double world = _plotCanvas.getWorld(); - if (world == null) { - return; - } - - g.setColor(_tickColor); - g.setFont(_tickFont); - - double xmin = world.x; - double ymin = world.y; - double xmax = world.getMaxX(); - double ymax = world.getMaxY(); - - double delx = (xmax - xmin) / (numMajorTickX + 1); - double dely = (ymax - ymin) / (numMajorTickY + 1); - - // major ticks - drawXTicks(g, xmin, xmax, world.getCenterY(), majorTickLen, numMajorTickX, ab, true); - drawYTicks(g, ymin, ymax, world.getCenterX(), majorTickLen, numMajorTickY, ab, true); - - // minor ticks - for (int i = 0; i <= numMajorTickX; i++) { - double xxmin = xmin + i * delx; - drawXTicks(g, xxmin, xxmin + delx, world.getCenterY(), minorTickLen, numMinorTickX, ab, false); - } - - // minor ticks - for (int i = 0; i <= numMajorTickY; i++) { - double yymin = ymin + i * dely; - drawYTicks(g, yymin, yymin + dely, world.getCenterX(), minorTickLen, numMinorTickY, ab, false); - } - - } - - // draw hisogram bin values - private void drawBinValues(Graphics g, double xmin, double xmax, double yc, int ticklen, int numtick, Rectangle ab, - boolean drawVal) { - - DataSet ds = _plotCanvas.getDataSet(); - if (!ds.is1DHistoSet()) { - return; - } - HistoData hd = ds.getColumn(0).getHistoData(); - if (hd == null) { - return; - } - - PlotParameters params = _plotCanvas.getParameters(); - FontMetrics fm = _plotCanvas.getFontMetrics(_tickFont); - double delx = (xmax - xmin) / (numtick + 1); - - int t = ab.y; - int b = t + ab.height; - int sb = b + fm.getHeight(); - - for (int i = 1; i <= (numtick + 1); i++) { - double value = xmin + (i - 0.5) * delx; - _wp.setLocation(value, yc); - _plotCanvas.worldToLocal(_pp, _wp); - g.drawLine(_pp.x, b, _pp.x, b - ticklen); - g.drawLine(_pp.x, t, _pp.x, t + ticklen); - - if (drawVal) { - int bin = hd.getBin(value) + 1; - String valStr = "" + bin; - int sw = fm.stringWidth(valStr); - g.drawString(valStr, _pp.x - sw / 2, sb); - - } // draw val - } // for - - } - - // draw x tick marks - private void drawXTicks(Graphics g, double xmin, double xmax, double yc, int ticklen, int numtick, Rectangle ab, - boolean drawVal) { - if (numtick < 1) { - return; - } - - if (drawBinValue) { - drawBinValues(g, xmin, xmax, yc, ticklen, numtick, ab, drawVal); - return; - } - - PlotParameters params = _plotCanvas.getParameters(); - FontMetrics fm = _plotCanvas.getFontMetrics(_tickFont); - double delx = (xmax - xmin) / (numtick + 1); - - int t = ab.y; - int b = t + ab.height; - int sb = b + fm.getHeight(); - - for (int i = 1; i <= numtick; i++) { - double value = xmin + i * delx; - _wp.setLocation(value, yc); - _plotCanvas.worldToLocal(_pp, _wp); - g.drawLine(_pp.x, b, _pp.x, b - ticklen); - g.drawLine(_pp.x, t, _pp.x, t + ticklen); - - if (drawVal) { - String valStr = DoubleFormat.doubleFormat(value, params.getNumDecimalX(), params.getMinExponentX()); - int sw = fm.stringWidth(valStr); - g.drawString(valStr, _pp.x - sw / 2, sb); - - } // draw val - } // for - - } - - // draw y tick marks - private void drawYTicks(Graphics g, double ymin, double ymax, double xc, int ticklen, int numtick, Rectangle ab, - boolean drawVal) { - if (numtick < 1) { - return; - } - - PlotParameters params = _plotCanvas.getParameters(); - FontMetrics fm = _plotCanvas.getFontMetrics(_tickFont); - double dely = (ymax - ymin) / (numtick + 1); - - int l = ab.x; - int r = l + ab.width; - int sb = l - 4; - - for (int i = 0; i <= (numtick + 1); i++) { - if ((i > 0) && (i < numtick + 1)) { - double value = ymin + i * dely; - _wp.setLocation(xc, value); - _plotCanvas.worldToLocal(_pp, _wp); - g.drawLine(l, _pp.y, l + ticklen, _pp.y); - g.drawLine(r, _pp.y, r - ticklen, _pp.y); - if (drawVal) { - String valstr = DoubleFormat.doubleFormat(value, params.getNumDecimalY(), params.getMinExponentY()); - int sw = fm.stringWidth(valstr); - GraphicsUtilities.drawRotatedText((Graphics2D) g, valstr, _tickFont, sb, _pp.y + sw / 2, 0, 0, -90); - } - } - } - - } - - public int getNumMajorTickX() { - return numMajorTickX; - } - - public void setNumMajorTickX(int numMajorTickX) { - this.numMajorTickX = numMajorTickX; - } - - public int getNumMinorTickX() { - return numMinorTickX; - } - - public void setNumMinorTickX(int numMinorTickX) { - this.numMinorTickX = numMinorTickX; - } - - public int getNumMajorTickY() { - return numMajorTickY; - } - - public void setNumMajorTickY(int numMajorTickY) { - this.numMajorTickY = numMajorTickY; - } - - public int getNumMinorTickY() { - return numMinorTickY; - } - - public void setNumMinorTickY(int numMinorTickY) { - this.numMinorTickY = numMinorTickY; - } - - public int getMajorTickLen() { - return majorTickLen; - } - - public void setMajorTickLen(int majorTickLen) { - this.majorTickLen = majorTickLen; - } - - public int getMinorTickLen() { - return minorTickLen; - } - - public void setMinorTickLen(int minorTickLen) { - this.minorTickLen = minorTickLen; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PrintUtilities.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PrintUtilities.java deleted file mode 100644 index c9b486e6c6..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/PrintUtilities.java +++ /dev/null @@ -1,59 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Component; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.print.PageFormat; -import java.awt.print.Printable; -import java.awt.print.PrinterException; -import java.awt.print.PrinterJob; - -public class PrintUtilities implements Printable { - - private static boolean _isPrinting; - private Component _componentToBePrinted; - - public static void printComponent(Component c) { - new PrintUtilities(c).print(); - } - - public PrintUtilities(Component componentToBePrinted) { - _componentToBePrinted = componentToBePrinted; - } - - public void print() { - PrinterJob printJob = PrinterJob.getPrinterJob(); - printJob.setPrintable(this); - if (printJob.printDialog()) - try { - printJob.print(); - } - catch (PrinterException pe) { - System.out.println("Error printing: " + pe); - } - } - - @Override - public int print(Graphics g, PageFormat pageFormat, int pageIndex) { - if (pageIndex > 0) { - return (NO_SUCH_PAGE); - } - else { - Graphics2D g2d = (Graphics2D) g; - - g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); - - // TODO CACULATE CORRECT SCALE FACTOR - g2d.scale(0.75, 0.75); - - _isPrinting = true; - _componentToBePrinted.printAll(g2d); - _isPrinting = false; - return (PAGE_EXISTS); - } - } - - public static boolean isPrinting() { - return _isPrinting; - } -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/SplotMenus.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/SplotMenus.java deleted file mode 100644 index c3535610ec..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/SplotMenus.java +++ /dev/null @@ -1,276 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Container; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPopupMenu; -import javax.swing.KeyStroke; - -import cnuphys.splot.edit.CurveEditorDialog; -import cnuphys.splot.edit.DialogUtilities; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetType; - -public class SplotMenus implements ActionListener { - - // the owner canvas - private PlotCanvas _plotCanvas; - - // the menus - protected JMenu _fileMenu; - protected JMenu _editMenu; - - // the menu items - protected JMenuItem _quitItem; - protected JMenuItem _prefItem; - protected JMenuItem _dataItem; - protected JMenuItem _clearItem; - protected JMenuItem _curveItem; - protected JMenuItem _axesItem; - - protected JCheckBoxMenuItem _showExtraCB; - - /** - * Create a set of menus and items for sPlot - * - * @param canvas the plot canvas being controlled - * @param menuBar the menu bar - * @param addQuit if true include a quit item - */ - public SplotMenus(PlotCanvas canvas, JMenuBar menuBar, boolean addQuit) { - _plotCanvas = canvas; - makeMenus(canvas, menuBar, addQuit); - } - - /** - * Create a set of menus and items for sPlot - * - * @param canvas the plot canvas being controlled - * @param popup a popup to hold the menus - * @param addQuit if true include a quit item - */ - public SplotMenus(PlotCanvas canvas, JPopupMenu popup, boolean addQuit) { - _plotCanvas = canvas; - makeMenus(canvas, popup, addQuit); - } - - // make the menus - private void makeMenus(PlotCanvas canvas, Container container, boolean addQuit) { -// makeFileMenu(container, addQuit); - makeEditMenu(canvas, container); - } - - // make the file menu - protected void makeFileMenu(Container container, boolean addQuit) { - _fileMenu = new JMenu("File"); - - if (addQuit) { -// _fileMenu.addSeparator(); - _quitItem = addMenuItem("Quit", 'Q', _fileMenu); - } - container.add(_fileMenu); - } - - // make the edit menu - protected void makeEditMenu(PlotCanvas canvas, Container container) { - _editMenu = new JMenu("Edit"); - _prefItem = addMenuItem("Preferences...", 'P', _editMenu); -// _dataItem = addMenuItem("Data...", 'D', _editMenu); - _curveItem = addMenuItem("Curves...", 'C', _editMenu); - _axesItem = addMenuItem("Axes...", 'A', _editMenu); - _editMenu.addSeparator(); - _showExtraCB = addMenuCheckBox("Show any Extra Text", _editMenu, canvas.getParameters().extraDrawing()); - _editMenu.addSeparator(); - _clearItem = addMenuItem("Clear Data", '\0', _editMenu); - container.add(_editMenu); - } - - /** - * Convenience routine for adding a menu item. - * - * @param label the menu label. - * @param accelChar the accelerator character. - * @param menu the menu to add the item to. - */ - - protected JMenuItem addMenuItem(String label, char accelChar, JMenu menu) { - JMenuItem mitem = null; - - if ((label != null) && (menu != null)) { - try { - mitem = new JMenuItem(label); - menu.add(mitem); - if (accelChar != '\0') { - KeyStroke keyStroke = KeyStroke.getKeyStroke("control " + accelChar); - mitem.setAccelerator(keyStroke); - } - - mitem.addActionListener(this); - } - catch (Exception e) { - } - } - - return mitem; - } - - protected JCheckBoxMenuItem addMenuCheckBox(String label, JMenu menu, boolean selected) { - JCheckBoxMenuItem cb = null; - - if ((label != null) && (menu != null)) { - try { - cb = new JCheckBoxMenuItem(label, selected); - menu.add(cb); - cb.addActionListener(this); - } - catch (Exception e) { - } - } - - return cb; - } - - @Override - public void actionPerformed(ActionEvent e) { - Object source = e.getSource(); - - if (source == _quitItem) { - System.exit(0); - } - else if (source == _prefItem) { - _plotCanvas.showPreferencesEditor(); - } - else if (source == _dataItem) { - _plotCanvas.showDataEditor(); - } - else if (source == _curveItem) { - CurveEditorDialog cd = new CurveEditorDialog(_plotCanvas); - DialogUtilities.centerDialog(cd); - cd.selectFirstCurve(); - cd.setVisible(true); - } - else if (source == _axesItem) { - DataSetType type = _plotCanvas.getType(); - // XYY, XYXY, XYEXYE, XYEEXYEE, H1D, H2D, STRIP, UNKNOWN; - switch (type) { - case UNKNOWN: - case H1D: - case H2D: - case STRIP: - JOptionPane.showMessageDialog(null, "Axes editing is not yet supported for this type of plot.", - "Not Supported", JOptionPane.INFORMATION_MESSAGE); - break; - - default: - break; - } - } - - else if (source == _clearItem) { - DataSet ds = _plotCanvas.getDataSet(); - DataSetType dsType = null; - if (ds != null) { - dsType = ds.getType(); - } -// _plotCanvas.clearPlot(); - - if (dsType != null) { - ds.clear(); - } -// if (dsType != null) { -// try { -// -// if (dsType == DataSetType.H1D) { -// ds = new DataSet(ds.getColumn(0).getHistoData()); -// } -// else if (dsType == DataSetType.H2D) { -// ds = new DataSet(ds.getColumn(0).getHistoData2D()); -// } -// else { -// ds = new DataSet(dsType); -// } -// _plotCanvas.setDataSet(ds); -// } -// catch (DataSetException e1) { -// e1.printStackTrace(); -// } -// } - - _plotCanvas.needsRedraw(true); - } - else if (source == _showExtraCB) { - _plotCanvas.getParameters().setExtraDrawing(_showExtraCB.isSelected()); - _plotCanvas.repaint(); - } - } - - /** - * Get the underlying plot canvas - * - * @return the plot canvas - */ - public PlotCanvas getPlotCanvas() { - return _plotCanvas; - } - - /** - * Get the file menu - * - * @return the file menu - */ - public JMenu getFileMenu() { - return _fileMenu; - } - - /** - * Get the edit menu - * - * @return the edit menu - */ - public JMenu getEditMenu() { - return _editMenu; - } - - /** - * Get the quit item (might be null) - * - * @return the quit item - */ - public JMenuItem getQuitItem() { - return _quitItem; - } - - /** - * Get the preferences item - * - * @return the preferences item - */ - public JMenuItem getPreferencesItem() { - return _prefItem; - } - - /** - * Get the clear (canvas) item - * - * @return the clear item - */ - public JMenuItem getClearItem() { - return _clearItem; - } - - /** - * Get the curve (editor) item - * - * @return the curve editor item - */ - public JMenuItem getCurveItem() { - return _curveItem; - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/StripChartPanel.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/StripChartPanel.java deleted file mode 100644 index 3c682758fa..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/StripChartPanel.java +++ /dev/null @@ -1,214 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Font; -import java.awt.Graphics; -import java.awt.Insets; - -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.SwingConstants; - -import cnuphys.splot.fit.IValueGetter; -import cnuphys.splot.pdata.DataSet; -import cnuphys.splot.pdata.DataSetException; -import cnuphys.splot.pdata.StripData; -import cnuphys.splot.style.SymbolType; - -public class StripChartPanel extends JPanel { - - protected PlotCanvas _canvas; - - private IValueGetter _getter; - private int _capacity; - private long _interval; - - // title related - private JLabel _titleLabel; - - // axes labels - private JLabel _xLabel; - private JLabel _yLabel; - - - /** - * Create a plot panel for a single xy dataset and a toolbar - * - * @param title - * @param xLabel - * @param yLabel - * @param getter - * @param capacity - * @param interval - */ - public StripChartPanel(String title, String xLabel, String yLabel, IValueGetter getter, int capacity, long interval) { - - _getter = getter; - _capacity = capacity; - _interval = interval; - - try { - _canvas = new PlotCanvas(createDataSet(), title, xLabel, yLabel); - } - catch (DataSetException e) { - e.printStackTrace(); - return; - } - - _canvas.setParent(this); - - Environment.getInstance().commonize(this, null); - setLayout(new BorderLayout(0, 0)); - - add(_canvas, BorderLayout.CENTER); - - addSouth(); - addNorth(); - addWest(); - - - setPreferences(); - } - - private void addSouth() { - // south panel for x axis and status - JPanel spanel = new JPanel(); - Environment.getInstance().commonize(spanel, null); - - spanel.setLayout(new BorderLayout()); - spanel.setOpaque(true); - spanel.setBackground(Color.white); - PlotParameters parameters = _canvas.getParameters(); - - // axes labels - _xLabel = makeJLabel(parameters.getXLabel(), parameters.getAxesFont(), SwingConstants.CENTER, Color.white, null, - false); - _xLabel.setAlignmentX(Component.CENTER_ALIGNMENT); - spanel.add(_xLabel, BorderLayout.CENTER); - - add(spanel, BorderLayout.SOUTH); - } - - // add the north component - private void addNorth() { - PlotParameters parameters = _canvas.getParameters(); - - - JPanel npanel = new JPanel(); - npanel.setOpaque(true); - npanel.setBackground(Color.white); - Environment.getInstance().commonize(npanel, null); - npanel.setLayout(new BorderLayout()); - - // title label - _titleLabel = makeJLabel(_canvas.getParameters().getPlotTitle(), parameters.getTitleFont(), - SwingConstants.CENTER, Color.white, null, false); - _titleLabel.setAlignmentX(Component.CENTER_ALIGNMENT); - - npanel.add(_titleLabel, BorderLayout.CENTER); - add(npanel, BorderLayout.NORTH); - } - - // add the west component - private void addWest() { - PlotParameters parameters = _canvas.getParameters(); - _yLabel = makeRotatedLabel(_canvas.getParameters().getYLabel(), parameters.getAxesFont(), Color.white, null); - add(_yLabel, BorderLayout.WEST); - } - - @Override - public Insets getInsets() { - Insets def = super.getInsets(); - return new Insets(def.top + 2, def.left + 2, def.bottom + 2, def.right + 2); - } - - - - // convenience function for making a label - private JLabel makeJLabel(String text, Font font, int alignment, Color bg, Color fg, boolean excludeFromPrint) { - - JLabel lab = null; - if (excludeFromPrint) { - lab = new JLabel(text != null ? text : " ") { - @Override - public void paint(Graphics g) { - // exclude from print - if (!PrintUtilities.isPrinting()) { - super.paint(g); - } - } - }; - } - else { - lab = new JLabel(text != null ? text : " "); - } - lab.setFont(font); - lab.setOpaque(true); - if (bg != null) { - lab.setBackground(bg); - } - if (fg != null) { - lab.setForeground(fg); - } - lab.setHorizontalAlignment(alignment); - lab.setVerticalAlignment(SwingConstants.CENTER); - return lab; - } - - // convenience function for making a rotated label for y axis label - private JLabel makeRotatedLabel(String text, Font font, Color bg, Color fg) { - JLabel lab = new JLabel(text); - lab.setFont(font); - lab.setOpaque(true); - lab.setUI(new VerticalLabelUI()); - lab.setHorizontalAlignment(SwingConstants.CENTER); - - if (bg != null) { - lab.setBackground(bg); - } - if (fg != null) { - lab.setForeground(bg); - } - return lab; - } - - /** - * Get the underlying plot canvas. - * @return the underlying plot canvas. - */ - public PlotCanvas getPlotCanvas() { - return _canvas; - } - - /** - * Create the data set - * @return the data set - * @throws DataSetException - */ - protected DataSet createDataSet() throws DataSetException { - StripData sd = new StripData("Data", _capacity, _getter, _interval); - return new DataSet(sd, "x", "y"); - } - - - - public void setPreferences() { - _canvas.getPlotTicks().setNumMajorTickY(3); - _canvas.getPlotTicks().setNumMinorTickY(0); - - DataSet ds = _canvas.getDataSet(); - ds.getCurveStyle(0).setFitLineColor(Color.red); - ds.getCurveStyle(0).setFillColor(new Color(128, 0, 0, 48)); - ds.getCurveStyle(0).setSymbolType(SymbolType.NOSYMBOL); - PlotParameters params = _canvas.getParameters(); - - params.setMinExponentY(6); - params.setNumDecimalY(2); - params.setXLimitsMethod(LimitsMethod.USEDATALIMITS); - params.mustIncludeYZero(true); - } - - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/TextFieldSlider.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/TextFieldSlider.java deleted file mode 100644 index 741d29eab2..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/TextFieldSlider.java +++ /dev/null @@ -1,203 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.Font; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.util.Hashtable; - -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JSlider; -import javax.swing.JTextField; -import javax.swing.SwingConstants; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - -public abstract class TextFieldSlider extends JPanel implements ChangeListener { - - // the underlying slider - private JSlider _slider; - - // underlying text field - private JTextField _textField; - - private int _defaultValue; - - private static Font _smallFont = Environment.getInstance().getCommonFont(9); - private static Font _tinyFont = Environment.getInstance().getCommonFont(8); - - public TextFieldSlider(int min, int max, int value, Font font, int minorTickSpacing, String labels[], - int sliderWidth, int textFieldWidth, String borderTitle) { - _defaultValue = value; - Environment.getInstance().commonize(this, null); - - _slider = new JSlider(SwingConstants.HORIZONTAL, min, max, value); - _slider.addChangeListener(this); - _slider.setFont(_smallFont); - Environment.getInstance().commonize(_slider, null); - - if (minorTickSpacing > 0) { - _slider.setMinorTickSpacing(minorTickSpacing); - _slider.setPaintTicks(true); - _slider.setPaintLabels(true); - } - - if ((labels != null) && (labels.length > 1)) { - // assume the labels are equally spaced - float del = ((float) (max - min)) / (labels.length - 1); - Hashtable labelTable = new Hashtable(); - - for (int i = 0; i < labels.length; i++) { - int sv = (int) (min + i * del); - labelTable.put(sv, makeLabel(labels[i])); - } - - _slider.setLabelTable(labelTable); - } - - if (sliderWidth > 0) { - Dimension d = _slider.getPreferredSize(); - d.width = sliderWidth; - _slider.setPreferredSize(d); - } - - // now the text field - _textField = new JTextField(valueString(sliderValueToRealValue())); - _textField.setFont(font); - - KeyAdapter keyAdapter = new KeyAdapter() { - @Override - public void keyReleased(KeyEvent kev) { - if (kev.getKeyCode() == KeyEvent.VK_ENTER) { - try { - double val = Double.parseDouble(_textField.getText()); - _slider.setValue(realValueToSliderValue(val)); - } - catch (Exception e) { - - } - } - } - }; - _textField.addKeyListener(keyAdapter); - - if (textFieldWidth > 0) { - Dimension d = _textField.getPreferredSize(); - d.width = textFieldWidth; - _textField.setPreferredSize(d); - } - - setLayout(new FlowLayout(FlowLayout.LEFT, 2, 0)); - add(_slider); - add(_textField); - - // border? - if (borderTitle != null) { - setBorder(new CommonBorder(borderTitle)); - } - - } - - @Override - public void setEnabled(boolean enabled) { - super.setEnabled(enabled); - _slider.setEnabled(enabled); - _textField.setEnabled(enabled); - } - - // make a quick label - private JLabel makeLabel(String s) { - JLabel j = new JLabel(s); - j.setFont(_tinyFont); - return j; - } - - @Override - public void stateChanged(ChangeEvent arg0) { - if (_textField != null) { - _textField.setText(valueString(sliderValueToRealValue())); - } - if (!_slider.getValueIsAdjusting()) { - valueChanged(); - } - } - - /** - * Take the current slider value and convert in to the real value. This allows, - * for example, to have a slider range of 0 to 100 mapped to a real-valued range - * that is not even necessarily linear. - * - * @return the real value corresponding to the current slider value. - */ - public abstract double sliderValueToRealValue(); - - /** - * Convert a real value to the corresponding slider value. This allows, for - * example, to have a slider range of 0 to 100 mapped to a real-valued range - * that is not even necessarily linear. - * - * @param val the real value to convert. - * @return the corresponding slider value. (The slider is not automatically set - * to this value) - */ - public abstract int realValueToSliderValue(double val); - - /** - * Convert format real value into a display string - * - * @param val the value to format - * @return the formatted value - */ - public abstract String valueString(double val); - - /** - * This is called when the value changes, with by the slider or by entering text - * into the text field and hitting return. - */ - public abstract void valueChanged(); - - /** - * Get the slider component - * - * @return the slider component - */ - public JSlider getSlider() { - return _slider; - } - - /** - * Get the text field component - * - * @return the text field component - */ - public JTextField getTextField() { - return _textField; - } - - /** - * Convenience method to set the slider value - * - * @param val the value to set - */ - public void setValue(int val) { - _slider.setValue(val); - } - - /** - * Convenience method to get the slider's current value. - * - * @return the slider's current value. - */ - public int getValue() { - return _slider.getValue(); - } - - /** - * Reset the slider back to its default value. - */ - public void reset() { - _slider.setValue(_defaultValue); - } -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/UnicodeSupport.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/UnicodeSupport.java deleted file mode 100644 index fc8a20c172..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/UnicodeSupport.java +++ /dev/null @@ -1,222 +0,0 @@ -package cnuphys.splot.plot; - -public class UnicodeSupport { - - public static final String SUPERPLUS = "\u207A"; - public static final String SUPERMINUS = "\u207B"; - public static final String DEGREE = "\u00B0"; - public static final String TIMES = "\u2715"; - public static final String SUPER2 = "\u00B2"; - public static final String SUBZERO = "\u2080"; - public static final String SUPERZERO = "\u2070"; - - public static final String SUBN = "\u2099"; - public static final String SUPERN = "\u207F"; - - public static final String PLUSMINUS = "\u00B1"; - public static final String APPROX = "\u2248"; - public static final String BULLET = "\u2219"; - public static final String DAGGER = "\u2020"; - public static final String SQRT = "\u221a"; - - public static final String LEQ = "\u2264"; - public static final String GEQ = "\u2265"; - public static final String LL = "\u226A"; // much less than - public static final String GG = "\u226B"; // much greater than - public static final String PROPTO = "\u221D"; - public static final String EQUIV = "\u2261"; - public static final String SIM = "\u2236"; - public static final String SIMEQ = "\u2243"; - public static final String NEQ = "\u2260"; - public static final String PERP = "\u22A5"; - public static final String PARALLEL = "\u2225"; - public static final String INFINITY = "\u221E"; - public static final String LARROW = "\u2190"; - public static final String UARROW = "\u2191"; - public static final String RARROW = "\u2192"; - public static final String DARROW = "\u2193"; - public static final String LRARROW = "\u2194"; - public static final String UDARROW = "\u2195"; - - // greek characters - public static final String CAPITAL_ALPHA = "\u0391"; - public static final String CAPITAL_BETA = "\u0392"; - public static final String CAPITAL_GAMMA = "\u0393"; - public static final String CAPITAL_DELTA = "\u0394"; - public static final String CAPITAL_EPSILON = "\u0395"; - public static final String CAPITAL_ZETA = "\u0396"; - public static final String CAPITAL_ETA = "\u0397"; - public static final String CAPITAL_THETA = "\u0398"; - public static final String CAPITAL_IOTA = "\u0399"; - public static final String CAPITAL_KAPPA = "\u039A"; - public static final String CAPITAL_LAMBDA = "\u039B"; - public static final String CAPITAL_MU = "\u039C"; - public static final String CAPITAL_NU = "\u039D"; - public static final String CAPITAL_XI = "\u039E"; - public static final String CAPITAL_OMICRON = "\u039F"; - public static final String CAPITAL_PI = "\u03A0"; - public static final String CAPITAL_RHO = "\u03A1"; - public static final String CAPITAL_SIGMA = "\u03A3"; - public static final String CAPITAL_TAU = "\u03A4"; - public static final String CAPITAL_UPSILON = "\u03A5"; - public static final String CAPITAL_PHI = "\u03A6"; - public static final String CAPITAL_CHI = "\u03A7"; - public static final String CAPITAL_PSI = "\u03A8"; - public static final String CAPITAL_OMEGA = "\u03A9"; - public static final String CAPITAL_IOTA_WITH_DIALYTIKA = "\u03AA"; - public static final String CAPITAL_UPSILON_WITH_DIALYTIKA = "\u03AB"; - public static final String SMALL_ALPHA_WITH_TONOS = "\u03AC"; - public static final String SMALL_EPSILON_WITH_TONOS = "\u03AD"; - public static final String SMALL_ETA_WITH_TONOS = "\u03AE"; - public static final String SMALL_IOTA_WITH_TONOS = "\u03AF"; - public static final String SMALL_ALPHA = "\u03B1"; - public static final String SMALL_BETA = "\u03B2"; - public static final String SMALL_GAMMA = "\u03B3"; - public static final String SMALL_DELTA = "\u03B4"; - public static final String SMALL_EPSILON = "\u03B5"; - public static final String SMALL_ZETA = "\u03B6"; - public static final String SMALL_ETA = "\u03B7"; - public static final String SMALL_THETA = "\u03B8"; - public static final String SMALL_IOTA = "\u03B9"; - public static final String SMALL_KAPPA = "\u03BA"; - public static final String SMALL_LAMBDA = "\u03BB"; - public static final String SMALL_MU = "\u03BC"; - public static final String SMALL_NU = "\u03BD"; - public static final String SMALL_XI = "\u03BE"; - public static final String SMALL_OMICRON = "\u03BF"; - public static final String SMALL_PI = "\u03C0"; - public static final String SMALL_RHO = "\u03C1"; - public static final String SMALL_FINAL_SIGMA = "\u03C2"; - public static final String SMALL_SIGMA = "\u03C3"; - public static final String SMALL_TAU = "\u03C4"; - public static final String SMALL_UPSILON = "\u03C5"; - public static final String SMALL_PHI = "\u03C6"; - public static final String SMALL_CHI = "\u03C7"; - public static final String SMALL_PSI = "\u03C8"; - public static final String SMALL_OMEGA = "\u03C9"; - public static final String SMALL_IOTA_WITH_DIALYTIKA = "\u03CA"; - public static final String SMALL_UPSILON_WITH_DIALYTIKA = "\u03CB"; - public static final String SMALL_OMICRON_WITH_TONOS = "\u03CC"; - public static final String SMALL_UPSILON_WITH_TONOS = "\u03CD"; - public static final String SMALL_OMEGA_WITH_TONOS = "\u03CE"; - - /** - * Replace the Latex-like special characters with their unicode equivalents. - * - * @param s the input string - * @return the output, where special character sequences are replaced by unicode - * characters. - */ - public static String specialCharReplace(String s) { - if (s == null) { - return null; - } - - if (s.indexOf("\\") < 0) { - return s; - } - - s = s.replace("\\Alpha", CAPITAL_ALPHA); - s = s.replace("\\alpha", SMALL_ALPHA); - - s = s.replace("\\Beta", CAPITAL_BETA); - s = s.replace("\\beta", SMALL_BETA); - - s = s.replace("\\Gamma", CAPITAL_GAMMA); - s = s.replace("\\gamma", SMALL_GAMMA); - - s = s.replace("\\Delta", CAPITAL_DELTA); - s = s.replace("\\delta", SMALL_DELTA); - - s = s.replace("\\Epsilon", CAPITAL_EPSILON); - s = s.replace("\\epsilon", SMALL_EPSILON); - - s = s.replace("\\Zeta", CAPITAL_ZETA); - s = s.replace("\\zeta", SMALL_ZETA); - - s = s.replace("\\Eta", CAPITAL_ETA); - s = s.replace("\\eta", SMALL_ETA); - - s = s.replace("\\Theta", CAPITAL_THETA); - s = s.replace("\\theta", SMALL_THETA); - - s = s.replace("\\Iota", CAPITAL_IOTA); - s = s.replace("\\iota", SMALL_IOTA); - - s = s.replace("\\Kappa", CAPITAL_KAPPA); - s = s.replace("\\kappa", SMALL_KAPPA); - - s = s.replace("\\Lambda", CAPITAL_LAMBDA); - s = s.replace("\\lambda", SMALL_LAMBDA); - - s = s.replace("\\Mu", CAPITAL_MU); - s = s.replace("\\mu", SMALL_MU); - - s = s.replace("\\Nu", CAPITAL_NU); - s = s.replace("\\nu", SMALL_NU); - - s = s.replace("\\Xi", CAPITAL_XI); - s = s.replace("\\xi", SMALL_XI); - - s = s.replace("\\Omicron", CAPITAL_OMICRON); - s = s.replace("\\omicron", SMALL_OMICRON); - - s = s.replace("\\Pi", CAPITAL_PI); - s = s.replace("\\pi", SMALL_PI); - - s = s.replace("\\Rho", CAPITAL_RHO); - s = s.replace("\\rho", SMALL_RHO); - - s = s.replace("\\Sigma", CAPITAL_SIGMA); - s = s.replace("\\sigma", SMALL_SIGMA); - - s = s.replace("\\Tau", CAPITAL_TAU); - s = s.replace("\\tau", SMALL_TAU); - - s = s.replace("\\Upsilon", CAPITAL_UPSILON); - s = s.replace("\\upsilon", SMALL_UPSILON); - - s = s.replace("\\Phi", CAPITAL_PHI); - s = s.replace("\\phi", SMALL_PHI); - - s = s.replace("\\Chi", CAPITAL_CHI); - s = s.replace("\\chi", SMALL_CHI); - - s = s.replace("\\Psi", CAPITAL_PSI); - s = s.replace("\\psi", SMALL_PSI); - - s = s.replace("\\Omega", CAPITAL_OMEGA); - s = s.replace("\\omega", SMALL_OMEGA); - - // some math symbols - s = s.replace("\\times", TIMES); - s = s.replace("\\degree", DEGREE); - s = s.replace("\\pm", PLUSMINUS); - s = s.replace("\\approx", APPROX); - s = s.replace("\\bullet", BULLET); - - s = s.replace("\\leq", LEQ); - s = s.replace("\\geq", GEQ); - s = s.replace("\\ll", LL); - s = s.replace("\\gg", GG); - s = s.replace("\\propto", PROPTO); - s = s.replace("\\equiv", EQUIV); - s = s.replace("\\sim", SIM); - s = s.replace("\\simeq", SIMEQ); - s = s.replace("\\neq", NEQ); - s = s.replace("\\perp", PERP); - s = s.replace("\\parallel", PARALLEL); - s = s.replace("\\infinity", INFINITY); - - s = s.replace("\\larrow", LARROW); - s = s.replace("\\uarrow", UARROW); - s = s.replace("\\rarrow", RARROW); - s = s.replace("\\darrow", DARROW); - s = s.replace("\\lrarrow", LRARROW); - s = s.replace("\\udarrow", UDARROW); - - s = s.replace("\\dagger", DAGGER); - return s; - } - -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/VerticalLabelUI.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/VerticalLabelUI.java deleted file mode 100644 index 5fea097bfa..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/VerticalLabelUI.java +++ /dev/null @@ -1,178 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Component; -import java.awt.Dimension; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Rectangle; - -import javax.swing.Icon; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.plaf.ComponentUI; -import javax.swing.plaf.basic.BasicLabelUI; - -/** - * A UI delegate for JLabel that rotates the label 90 deg - *

    - * Extends {@link BasicLabelUI}. - *

    - * The only difference between the appearance of labels in the Basic and Metal - * {@code L&Fs} is the manner in which diabled text is painted. As VerticalLabelUI does - * not override the method paintDisabledText, this class can be adapted for - * Metal {@code L&F} by extending MetalLabelUI instead of BasicLabelUI. - *

    - * No other changes are required. - * - * @author Darryl - */ -public class VerticalLabelUI extends BasicLabelUI { - - private boolean clockwise = false; - // see comment in BasicLabelUI - Rectangle verticalViewR = new Rectangle(); - Rectangle verticalIconR = new Rectangle(); - Rectangle verticalTextR = new Rectangle(); - protected static VerticalLabelUI verticalLabelUI = new VerticalLabelUI(); - - /** - * Constructs a VerticalLabelUI with the default anticlockwise - * rotation - */ - public VerticalLabelUI() { - } - - /** - * Constructs a VerticalLabelUI with the desired rotation. - *

    - * - * @param clockwise true to rotate clockwise, false for anticlockwise - */ - public VerticalLabelUI(boolean clockwise) { - this.clockwise = clockwise; - } - - /** - * @see ComponentUI#createUI(javax.swing.JComponent) - */ - public static ComponentUI createUI(JComponent c) { - return verticalLabelUI; - } - - /** - * Overridden to always return -1, since a vertical label does not have a - * meaningful baseline. - * - * @see ComponentUI#getBaseline(JComponent, int, int) - */ - @Override - public int getBaseline(JComponent c, int width, int height) { - super.getBaseline(c, width, height); - return -1; - } - - /** - * Overridden to always return Component.BaselineResizeBehavior.OTHER, since a - * vertical label does not have a meaningful baseline - * - * @see ComponentUI#getBaselineResizeBehavior(javax.swing.JComponent) - */ - @Override - public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c) { - super.getBaselineResizeBehavior(c); - return Component.BaselineResizeBehavior.OTHER; - } - - /** - * Transposes the view rectangles as appropriate for a vertical view before - * invoking the super method and copies them after they have been altered by - * {@code SwingUtilities#layoutCompoundLabel(FontMetrics, String, Icon, int, int, int, int, Rectangle, Rectangle, Rectangle, int)} - */ - @Override - protected String layoutCL(JLabel label, FontMetrics fontMetrics, String text, Icon icon, Rectangle viewR, - Rectangle iconR, Rectangle textR) { - - verticalViewR = transposeRectangle(viewR, verticalViewR); - verticalIconR = transposeRectangle(iconR, verticalIconR); - verticalTextR = transposeRectangle(textR, verticalTextR); - - text = super.layoutCL(label, fontMetrics, text, icon, verticalViewR, verticalIconR, verticalTextR); - - copyRectangle(verticalViewR, viewR); - copyRectangle(verticalIconR, iconR); - copyRectangle(verticalTextR, textR); - return text; - } - - /** - * Transforms the Graphics for vertical rendering and invokes the super method. - */ - @Override - public void paint(Graphics g, JComponent c) { - Graphics2D g2 = (Graphics2D) g.create(); - if (clockwise) { - g2.rotate(Math.PI / 2, c.getSize().width / 2, c.getSize().width / 2); - } - else { - g2.rotate(-Math.PI / 2, c.getSize().height / 2, c.getSize().height / 2); - } - super.paint(g2, c); - } - - /** - * Returns a Dimension appropriate for vertical rendering - * - * @see ComponentUI#getPreferredSize(javax.swing.JComponent) - */ - @Override - public Dimension getPreferredSize(JComponent c) { - return transposeDimension(super.getPreferredSize(c)); - } - - /** - * Returns a Dimension appropriate for vertical rendering - * - * @see ComponentUI#getMaximumSize(javax.swing.JComponent) - */ - @Override - public Dimension getMaximumSize(JComponent c) { - return transposeDimension(super.getMaximumSize(c)); - } - - /** - * Returns a Dimension appropriate for vertical rendering - * - * @see ComponentUI#getMinimumSize(javax.swing.JComponent) - */ - @Override - public Dimension getMinimumSize(JComponent c) { - return transposeDimension(super.getMinimumSize(c)); - } - - private Dimension transposeDimension(Dimension from) { - return new Dimension(from.height, from.width + 2); - } - - private Rectangle transposeRectangle(Rectangle from, Rectangle to) { - if (to == null) { - to = new Rectangle(); - } - to.x = from.y; - to.y = from.x; - to.width = from.height; - to.height = from.width; - return to; - } - - private Rectangle copyRectangle(Rectangle from, Rectangle to) { - if (to == null) { - to = new Rectangle(); - } - to.x = from.x; - to.y = from.y; - to.width = from.width; - to.height = from.height; - return to; - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/VerticalLine.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/VerticalLine.java deleted file mode 100644 index e4f6f67a8c..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/VerticalLine.java +++ /dev/null @@ -1,33 +0,0 @@ -package cnuphys.splot.plot; - -public class VerticalLine extends PlotLine { - - // the x value of the vertical line - private double _x; - - public VerticalLine(PlotCanvas canvas, double x) { - super(canvas); - _x = x; - } - - @Override - public double getX0() { - return _x; - } - - @Override - public double getX1() { - return _x; - } - - @Override - public double getY0() { - return _canvas.getWorld().getMinY(); - } - - @Override - public double getY1() { - return _canvas.getWorld().getMaxY(); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/X11Colors.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/X11Colors.java deleted file mode 100644 index e05008c60e..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/plot/X11Colors.java +++ /dev/null @@ -1,481 +0,0 @@ -package cnuphys.splot.plot; - -import java.awt.Color; -import java.util.Hashtable; - -public class X11Colors { - - // hash of the X11 colors, filled as requested. - private static Hashtable x11colors = new Hashtable(521); - - /** - * Gets an X11 color and sets the alpha - * - * @param name the name of the color - * @param alpha [0..255] (255 is opaque) - * @return the corresponding x11 color (not from cache) - */ - public static Color getX11Color(String name, int alpha) { - Color color = getX11Color(name); - if (color != null) { - int r = color.getRed(); - int g = color.getGreen(); - int b = color.getBlue(); - color = new Color(r, g, b, alpha); - } - return color; - } - - /** - * Gets the named color from the X11 color list. - * - * @param name the name of the X11 color. - * @return the named color from the X11 color list as a hex string. - */ - public static String getX11ColorAsHex(String name) { - Color color = getX11Color(name); - return GraphicsUtilities.colorToHex(color); - } - - /** - * Gets the named color from the X11 color list. - * - * @param name the name of the X11 color. - * @return the named color from the X11 color list, or null. - */ - public static Color getX11Color(String name) { - if (name == null) { - return null; - } - name = name.toLowerCase(); - - Color color = x11colors.get(name); - if (color == null) { - if (name.equalsIgnoreCase("Alice Blue")) { - color = new Color(240, 248, 255); - } - else if (name.equalsIgnoreCase("Antique White")) { - color = new Color(250, 235, 215); - } - else if (name.equalsIgnoreCase("Aqua")) { - color = new Color(0, 255, 255); - } - else if (name.equalsIgnoreCase("Aquamarine")) { - color = new Color(127, 255, 212); - } - else if (name.equalsIgnoreCase("Azure")) { - color = new Color(240, 255, 255); - } - else if (name.equalsIgnoreCase("Beige")) { - color = new Color(245, 245, 220); - } - else if (name.equalsIgnoreCase("Bisque")) { - color = new Color(255, 228, 196); - } - else if (name.equalsIgnoreCase("Black")) { - color = new Color(0, 0, 0); - } - else if (name.equalsIgnoreCase("Blanched Almond")) { - color = new Color(255, 235, 205); - } - else if (name.equalsIgnoreCase("Blue")) { - color = new Color(0, 0, 255); - } - else if (name.equalsIgnoreCase("Blue Violet")) { - color = new Color(138, 43, 226); - } - else if (name.equalsIgnoreCase("Brown")) { - color = new Color(165, 42, 42); - } - else if (name.equalsIgnoreCase("BurlyWood")) { - color = new Color(222, 184, 135); - } - else if (name.equalsIgnoreCase("Cadet Blue")) { - color = new Color(95, 158, 160); - } - else if (name.equalsIgnoreCase("Chartreuse")) { - color = new Color(127, 255, 0); - } - else if (name.equalsIgnoreCase("Chocolate")) { - color = new Color(210, 105, 30); - } - else if (name.equalsIgnoreCase("Coral")) { - color = new Color(255, 127, 80); - } - else if (name.equalsIgnoreCase("Cornflower")) { - color = new Color(100, 149, 237); - } - else if (name.equalsIgnoreCase("Cornsilk")) { - color = new Color(255, 248, 220); - } - else if (name.equalsIgnoreCase("Crimson")) { - color = new Color(220, 20, 60); - } - else if (name.equalsIgnoreCase("Cyan")) { - color = new Color(0, 255, 255); - } - else if (name.equalsIgnoreCase("Dark Blue")) { - color = new Color(0, 0, 139); - } - else if (name.equalsIgnoreCase("Dark Cyan")) { - color = new Color(0, 139, 139); - } - else if (name.equalsIgnoreCase("Dark Goldenrod")) { - color = new Color(184, 134, 11); - } - else if (name.equalsIgnoreCase("Dark Gray")) { - color = new Color(169, 169, 169); - } - else if (name.equalsIgnoreCase("Dark Green")) { - color = new Color(0, 100, 0); - } - else if (name.equalsIgnoreCase("Dark Khaki")) { - color = new Color(189, 183, 107); - } - else if (name.equalsIgnoreCase("Dark Magenta")) { - color = new Color(139, 0, 139); - } - else if (name.equalsIgnoreCase("Dark Olive Green")) { - color = new Color(85, 107, 47); - } - else if (name.equalsIgnoreCase("Dark Orange")) { - color = new Color(255, 140, 0); - } - else if (name.equalsIgnoreCase("Dark Orchid")) { - color = new Color(153, 50, 204); - } - else if (name.equalsIgnoreCase("Dark Red")) { - color = new Color(139, 0, 0); - } - else if (name.equalsIgnoreCase("Dark Salmon")) { - color = new Color(233, 150, 122); - } - else if (name.equalsIgnoreCase("Dark Sea Green")) { - color = new Color(143, 188, 143); - } - else if (name.equalsIgnoreCase("Dark Slate Blue")) { - color = new Color(72, 61, 139); - } - else if (name.equalsIgnoreCase("Dark Slate Gray")) { - color = new Color(47, 79, 79); - } - else if (name.equalsIgnoreCase("Dark Turquoise")) { - color = new Color(0, 206, 209); - } - else if (name.equalsIgnoreCase("Dark Violet")) { - color = new Color(148, 0, 211); - } - else if (name.equalsIgnoreCase("Deep Pink")) { - color = new Color(255, 20, 147); - } - else if (name.equalsIgnoreCase("Deep Sky Blue")) { - color = new Color(0, 191, 255); - } - else if (name.equalsIgnoreCase("Dim Gray")) { - color = new Color(105, 105, 105); - } - else if (name.equalsIgnoreCase("Dodger Blue")) { - color = new Color(30, 144, 255); - } - else if (name.equalsIgnoreCase("Firebrick")) { - color = new Color(178, 34, 34); - } - else if (name.equalsIgnoreCase("Floral White")) { - color = new Color(255, 250, 240); - } - else if (name.equalsIgnoreCase("Forest Green")) { - color = new Color(34, 139, 34); - } - else if (name.equalsIgnoreCase("Fuchsia")) { - color = new Color(255, 0, 255); - } - else if (name.equalsIgnoreCase("Gainsboro")) { - color = new Color(220, 220, 220); - } - else if (name.equalsIgnoreCase("Ghost White")) { - color = new Color(248, 248, 255); - } - else if (name.equalsIgnoreCase("Gold")) { - color = new Color(255, 215, 0); - } - else if (name.equalsIgnoreCase("Goldenrod")) { - color = new Color(218, 165, 32); - } - else if (name.equalsIgnoreCase("Gray")) { - color = new Color(127, 127, 127); - } - else if (name.equalsIgnoreCase("Green")) { - color = new Color(0, 127, 0); - } - else if (name.equalsIgnoreCase("Green Yellow")) { - color = new Color(173, 255, 47); - } - else if (name.equalsIgnoreCase("Honeydew")) { - color = new Color(240, 255, 240); - } - else if (name.equalsIgnoreCase("Hot Pink")) { - color = new Color(255, 105, 180); - } - else if (name.equalsIgnoreCase("Indian Red")) { - color = new Color(205, 92, 92); - } - else if (name.equalsIgnoreCase("Indigo")) { - color = new Color(75, 0, 130); - } - else if (name.equalsIgnoreCase("Ivory")) { - color = new Color(255, 255, 240); - } - else if (name.equalsIgnoreCase("Khaki")) { - color = new Color(240, 230, 140); - } - else if (name.equalsIgnoreCase("Lavender")) { - color = new Color(230, 230, 250); - } - else if (name.equalsIgnoreCase("Lavender Blush")) { - color = new Color(255, 240, 245); - } - else if (name.equalsIgnoreCase("Lawn Green")) { - color = new Color(124, 252, 0); - } - else if (name.equalsIgnoreCase("Lemon Chiffon")) { - color = new Color(255, 250, 205); - } - else if (name.equalsIgnoreCase("Light Blue")) { - color = new Color(173, 216, 230); - } - else if (name.equalsIgnoreCase("Light Coral")) { - color = new Color(240, 128, 128); - } - else if (name.equalsIgnoreCase("Light Cyan")) { - color = new Color(224, 255, 255); - } - else if (name.equalsIgnoreCase("Light Goldenrod")) { - color = new Color(250, 250, 210); - } - else if (name.equalsIgnoreCase("Light Green")) { - color = new Color(144, 238, 144); - } - else if (name.equalsIgnoreCase("Light Grey")) { - color = new Color(211, 211, 211); - } - else if (name.equalsIgnoreCase("Light Pink")) { - color = new Color(255, 182, 193); - } - else if (name.equalsIgnoreCase("Light Salmon")) { - color = new Color(255, 160, 122); - } - else if (name.equalsIgnoreCase("Light Sea Green")) { - color = new Color(32, 178, 170); - } - else if (name.equalsIgnoreCase("Light Sky Blue")) { - color = new Color(135, 206, 250); - } - else if (name.equalsIgnoreCase("Light Slate Gray")) { - color = new Color(119, 136, 153); - } - else if (name.equalsIgnoreCase("Light Steel Blue")) { - color = new Color(176, 196, 222); - } - else if (name.equalsIgnoreCase("Light Yellow")) { - color = new Color(255, 255, 224); - } - else if (name.equalsIgnoreCase("Lime")) { - color = new Color(0, 255, 0); - } - else if (name.equalsIgnoreCase("Lime Green")) { - color = new Color(50, 205, 50); - } - else if (name.equalsIgnoreCase("Linen")) { - color = new Color(250, 240, 230); - } - else if (name.equalsIgnoreCase("Magenta")) { - color = new Color(255, 0, 255); - } - else if (name.equalsIgnoreCase("Maroon")) { - color = new Color(127, 0, 0); - } - else if (name.equalsIgnoreCase("Medium Aquamarine")) { - color = new Color(102, 205, 170); - } - else if (name.equalsIgnoreCase("Medium Blue")) { - color = new Color(0, 0, 205); - } - else if (name.equalsIgnoreCase("Medium Orchid")) { - color = new Color(186, 85, 211); - } - else if (name.equalsIgnoreCase("Medium Purple")) { - color = new Color(147, 112, 219); - } - else if (name.equalsIgnoreCase("Medium Sea Green")) { - color = new Color(60, 179, 113); - } - else if (name.equalsIgnoreCase("Medium Slate Blue")) { - color = new Color(123, 104, 238); - } - else if (name.equalsIgnoreCase("Medium Spring Green")) { - color = new Color(0, 250, 154); - } - else if (name.equalsIgnoreCase("Medium Turquoise")) { - color = new Color(72, 209, 204); - } - else if (name.equalsIgnoreCase("Medium Violet Red")) { - color = new Color(199, 21, 133); - } - else if (name.equalsIgnoreCase("Midnight Blue")) { - color = new Color(25, 25, 112); - } - else if (name.equalsIgnoreCase("Mint Cream")) { - color = new Color(245, 255, 250); - } - else if (name.equalsIgnoreCase("Misty Rose")) { - color = new Color(255, 228, 225); - } - else if (name.equalsIgnoreCase("Moccasin")) { - color = new Color(255, 228, 181); - } - else if (name.equalsIgnoreCase("Navajo White")) { - color = new Color(255, 222, 173); - } - else if (name.equalsIgnoreCase("Navy")) { - color = new Color(0, 0, 128); - } - else if (name.equalsIgnoreCase("Old Lace")) { - color = new Color(253, 245, 230); - } - else if (name.equalsIgnoreCase("Olive")) { - color = new Color(128, 128, 0); - } - else if (name.equalsIgnoreCase("Olive Drab")) { - color = new Color(107, 142, 35); - } - else if (name.equalsIgnoreCase("Orange")) { - color = new Color(255, 165, 0); - } - else if (name.equalsIgnoreCase("Orange Red")) { - color = new Color(255, 69, 0); - } - else if (name.equalsIgnoreCase("Orchid")) { - color = new Color(218, 112, 214); - } - else if (name.equalsIgnoreCase("Pale Goldenrod")) { - color = new Color(238, 232, 170); - } - else if (name.equalsIgnoreCase("Pale Green")) { - color = new Color(152, 251, 152); - } - else if (name.equalsIgnoreCase("Pale Turquoise")) { - color = new Color(175, 238, 238); - } - else if (name.equalsIgnoreCase("Pale Violet Red")) { - color = new Color(219, 112, 147); - } - else if (name.equalsIgnoreCase("Papaya Whip")) { - color = new Color(255, 239, 213); - } - else if (name.equalsIgnoreCase("Peach Puff")) { - color = new Color(255, 218, 185); - } - else if (name.equalsIgnoreCase("Peru")) { - color = new Color(205, 133, 63); - } - else if (name.equalsIgnoreCase("Pink")) { - color = new Color(255, 192, 203); - } - else if (name.equalsIgnoreCase("Plum")) { - color = new Color(221, 160, 221); - } - else if (name.equalsIgnoreCase("Powder Blue")) { - color = new Color(176, 224, 230); - } - else if (name.equalsIgnoreCase("Purple")) { - color = new Color(127, 0, 127); - } - else if (name.equalsIgnoreCase("Red")) { - color = new Color(255, 0, 0); - } - else if (name.equalsIgnoreCase("Rosy Brown")) { - color = new Color(188, 143, 143); - } - else if (name.equalsIgnoreCase("Royal Blue")) { - color = new Color(65, 105, 225); - } - else if (name.equalsIgnoreCase("Saddle Brown")) { - color = new Color(139, 69, 19); - } - else if (name.equalsIgnoreCase("Salmon")) { - color = new Color(250, 128, 114); - } - else if (name.equalsIgnoreCase("Sandy Brown")) { - color = new Color(244, 164, 96); - } - else if (name.equalsIgnoreCase("Sea Green")) { - color = new Color(46, 139, 87); - } - else if (name.equalsIgnoreCase("Seashell")) { - color = new Color(255, 245, 238); - } - else if (name.equalsIgnoreCase("Sienna")) { - color = new Color(160, 82, 45); - } - else if (name.equalsIgnoreCase("Silver")) { - color = new Color(192, 192, 192); - } - else if (name.equalsIgnoreCase("Sky Blue")) { - color = new Color(135, 206, 235); - } - else if (name.equalsIgnoreCase("Slate Blue")) { - color = new Color(106, 90, 205); - } - else if (name.equalsIgnoreCase("Slate Gray")) { - color = new Color(112, 128, 144); - } - else if (name.equalsIgnoreCase("Snow")) { - color = new Color(255, 250, 250); - } - else if (name.equalsIgnoreCase("Spring Green")) { - color = new Color(0, 255, 127); - } - else if (name.equalsIgnoreCase("Steel Blue")) { - color = new Color(70, 130, 180); - } - else if (name.equalsIgnoreCase("Tan")) { - color = new Color(210, 180, 140); - } - else if (name.equalsIgnoreCase("Teal")) { - color = new Color(0, 128, 128); - } - else if (name.equalsIgnoreCase("Thistle")) { - color = new Color(216, 191, 216); - } - else if (name.equalsIgnoreCase("Tomato")) { - color = new Color(255, 99, 71); - } - else if (name.equalsIgnoreCase("Turquoise")) { - color = new Color(64, 224, 208); - } - else if (name.equalsIgnoreCase("Violet")) { - color = new Color(238, 130, 238); - } - else if (name.equalsIgnoreCase("Wheat")) { - color = new Color(245, 222, 179); - } - else if (name.equalsIgnoreCase("White")) { - color = new Color(255, 255, 255); - } - else if (name.equalsIgnoreCase("White Smoke")) { - color = new Color(245, 245, 245); - } - else if (name.equalsIgnoreCase("Yellow")) { - color = new Color(255, 255, 0); - } - else if (name.equalsIgnoreCase("Yellow Green")) { - color = new Color(154, 205, 50); - } - - if (color != null) { - x11colors.put(name, color); - } - } // end color == null - return color; - } -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/rubberband/.gitignore b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/rubberband/.gitignore deleted file mode 100644 index d840aef4ce..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/rubberband/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -/IRubberbanded.class -/Rubberband$1.class -/Rubberband$2.class -/Rubberband$Policy.class -/Rubberband.class diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/rubberband/IRubberbanded.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/rubberband/IRubberbanded.java deleted file mode 100644 index b1a781d09b..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/rubberband/IRubberbanded.java +++ /dev/null @@ -1,9 +0,0 @@ -package cnuphys.splot.rubberband; - -public interface IRubberbanded { - - /** - * This just signals that we are done rubber banding. - */ - public void doneRubberbanding(); -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/rubberband/Rubberband.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/rubberband/Rubberband.java deleted file mode 100644 index 18de8f6b21..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/rubberband/Rubberband.java +++ /dev/null @@ -1,635 +0,0 @@ -package cnuphys.splot.rubberband; - -import java.awt.Color; -import java.awt.Component; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Point; -import java.awt.Polygon; -import java.awt.Rectangle; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseMotionAdapter; -import java.awt.image.BufferedImage; - -import cnuphys.splot.plot.GraphicsUtilities; -import cnuphys.splot.plot.PlotCanvas; - -public final class Rubberband { - - // Needed by a hack that prevents a 1st time flash - private static boolean veryFirst = true; - - /** - * Enum of possible rubber banding polices. - */ - public static enum Policy { - RECTANGLE, RECTANGLE_PRESERVE_ASPECT, POLYGON, POLYLINE, OVAL, LINE, RADARC, XONLY, YONLY - } - - // The default fill color. Should be fairly transparent. - private static final Color _defaultFillColor = new Color(255, 128, 128, 96); - - // One default color for highlighted drawing of boundary. - public Color _highlightColor1 = Color.red; - - // Second default color for highlighted drawing of boundary. - public Color _highlightColor2 = Color.yellow; - - // The default shape policy for rubberbanding - private Policy _policy = Policy.RECTANGLE; - - // The anchor or starting screen point. - private Point _startPt = new Point(); - - // The current point during rubber banding - private Point _currentPt = new Point(); - - // Component being rubber banded. - private Component _component; - - // A transparent fill color. - private Color _fillColor = _defaultFillColor; - - // For collecting polygon points. - private Polygon _poly; - - // also used for collecting points - private Polygon _tempPoly; - - // Make sure we only start once - private boolean _started = false; - - // used for component image - private BufferedImage _backgroundImage; - private BufferedImage _image; - - // temporary mouse listeners - private MouseMotionAdapter _mouseMotionAdapter; - private MouseAdapter _mouseAdapter; - - // Flag for whether rubberband is active - private boolean _active = false; - - // Listener to notify when we are done. - private IRubberbanded _rubberbanded; - - private PlotCanvas _canvas; - - /** - * Create a Rubberband - * - * @param canvas - * @param rubberbanded who gets notified when we are done. - * @param policy the stretching shape policy. - */ - public Rubberband(PlotCanvas canvas, IRubberbanded rubberbanded, Policy policy) { - _canvas = canvas; - setComponent(canvas); - _rubberbanded = rubberbanded; - _policy = policy; - } - - /** - * This activates or deactivates the rubber banding. - * - * @param b the value of the active flag. - */ - public void setActive(boolean b) { - _active = b; - } - - /** - * Sets the component being controlled by this rubber band - * - * @param component the component being rubberbanded. - */ - private void setComponent(Component component) { - _component = component; - - // Make the component a listener for mouse events. - _mouseAdapter = new MouseAdapter() { - @Override - public void mousePressed(MouseEvent event) { - if (isActive()) { - if (polyMode()) { - if (_tempPoly == null) { - startRubberbanding(event.getPoint()); - } - else { - if (event.getClickCount() == 2) { - endRubberbanding(event.getPoint()); - } - else { - addPoint(_tempPoly, event.getX(), event.getY()); - } - } - } - else if (radArcMode()) { - if (_tempPoly == null) { - startRubberbanding(event.getPoint()); - } - else { - addPoint(_tempPoly, event.getX(), event.getY()); - if (_tempPoly.npoints == 3) { - endRubberbanding(event.getPoint()); - } - } - } - else if (lineMode()) { - if (_tempPoly == null) { - startRubberbanding(event.getPoint()); - } - else { - addPoint(_tempPoly, event.getX(), event.getY()); - if (_tempPoly.npoints == 2) { - endRubberbanding(event.getPoint()); - } - } - } - else { // rects and ovals by dragging - startRubberbanding(event.getPoint()); - } - } - } - - @Override - public void mouseClicked(MouseEvent event) { - if (isActive()) { - if (polyMode()) { - // double click to end - if (event.getClickCount() > 1) { - endRubberbanding(event.getPoint()); - } - } - } - } - - @Override - public void mouseReleased(MouseEvent event) { - if (isActive()) { - if (normalMode()) { - endRubberbanding(event.getPoint()); - } - } - } - }; - - // Make the rubber band a listener for mouse motion events. - _mouseMotionAdapter = new MouseMotionAdapter() { - @Override - public void mouseDragged(MouseEvent event) { - if (isActive()) { - if (normalMode()) { // rects and ovals - Point cp = event.getPoint(); - modifyCurrentPoint(cp); - setCurrent(cp); - } - } - } - - @Override - public void mouseMoved(MouseEvent event) { - if (isActive()) { - if ((polyMode() || radArcMode() || lineMode()) && (_tempPoly != null)) { - setCurrent(event.getPoint()); - } - } - } - }; - - component.addMouseListener(_mouseAdapter); - component.addMouseMotionListener(_mouseMotionAdapter); - } - - /** - * A hack that prevents the same point from being added consecutively. - * - * @param p the polygon in question. - * @param x the x coordinate. - * @param y the y coordinate. - */ - private void addPoint(Polygon p, int x, int y) { - int n = p.npoints; - - if (n > 0) { - int xp[] = p.xpoints; - int yp[] = p.ypoints; - if ((x == xp[n - 1]) && (y == yp[n - 1])) { - return; - } - } - p.addPoint(x, y); - } - - /** - * Convenience method to see we are in a poly mode. - * - * @return true if we are in a poly mode. - */ - private boolean polyMode() { - return (_policy == Policy.POLYGON) || (_policy == Policy.POLYLINE); - } - - /** - * Convenience method to see we are in radarc mode. - * - * @return true if we are in radarc mode. - */ - private boolean radArcMode() { - return (_policy == Policy.RADARC); - } - - /** - * Convenience method to see we are in line mode. - * - * @return true if we are in line mode. - */ - private boolean lineMode() { - return (_policy == Policy.LINE); - } - - /** - * Convenience method to see we are in rectangle/ellipse "normal" mode. - * - * @return true if we are in rectangle/ellipse "normal" mode. - */ - private boolean normalMode() { - return (!polyMode() && !radArcMode() && !lineMode()); - } - - /** - * Draw the rubber band outline. Erasing is not necessary because we are saving - * a background image. - * - * @param g the graphics context. - */ - private void draw(Graphics2D g) { - - Rectangle rect = getRubberbandBounds(); - - Polygon tpoly = null; - - switch (_policy) { - case RECTANGLE: - case XONLY: - case YONLY: - case RECTANGLE_PRESERVE_ASPECT: - g.fillRect(rect.x, rect.y, rect.width, rect.height); - GraphicsUtilities.drawHighlightedRectangle(g, rect, _highlightColor1, _highlightColor2); - break; - - case LINE: - GraphicsUtilities.drawHighlightedLine(g, _startPt.x, _startPt.y, _currentPt.x, _currentPt.y, - _highlightColor1, _highlightColor2); - break; - - case OVAL: - g.fillOval(rect.x, rect.y, rect.width, rect.height); - GraphicsUtilities.drawHighlightedOval(g, rect, _highlightColor1, _highlightColor2); - break; - - case RADARC: - - if (_tempPoly.npoints == 1) { - GraphicsUtilities.drawHighlightedLine(g, _tempPoly.xpoints[0], _tempPoly.ypoints[0], _currentPt.x, - _currentPt.y, _highlightColor1, _highlightColor2); - } - else if (_tempPoly.npoints == 2) { - double xc = _tempPoly.xpoints[0]; - double yc = _tempPoly.ypoints[0]; - double x1 = _tempPoly.xpoints[1]; - double y1 = _tempPoly.ypoints[1]; - double x2 = _currentPt.x; - double y2 = _currentPt.y; - double dx1 = x1 - xc; - double dy1 = y1 - yc; - double dx2 = x2 - xc; - double dy2 = y2 - yc; - double r1 = Math.sqrt(dx1 * dx1 + dy1 * dy1); - double r2 = Math.sqrt(dx2 * dx2 + dy2 * dy2); - - if (r1 < 0.99) { - return; - } - if (r2 < 0.99) { - return; - } - - double sAngle = Math.atan2(-dy1, dx1); - - double aAngle = Math.acos((dx1 * dx2 + dy1 * dy2) / (r1 * r2)); - if ((dx1 * dy2 - dx2 * dy1) > 0.0) { - aAngle = -aAngle; - } - - // scale to have save radius - double scale = r1 / r2; - dx2 *= scale; - dy2 *= scale; - x2 = xc + dx2; - y2 = yc + dy2; - - int startAngle = (int) Math.toDegrees(sAngle); - int arcAngle = (int) Math.toDegrees(aAngle); - - int pixrad = (int) r1; - int size = (int) (2 * r1); - - g.fillArc(_tempPoly.xpoints[0] - pixrad, _tempPoly.ypoints[0] - pixrad, size, size, startAngle, - arcAngle); - GraphicsUtilities.drawHighlightedArc(g, _tempPoly.xpoints[0] - pixrad, _tempPoly.ypoints[0] - pixrad, - size, size, startAngle, arcAngle, _highlightColor1, _highlightColor2); - - GraphicsUtilities.drawHighlightedLine(g, _tempPoly.xpoints[0], _tempPoly.ypoints[0], - _tempPoly.xpoints[1], _tempPoly.ypoints[1], _highlightColor1, _highlightColor2); - GraphicsUtilities.drawHighlightedLine(g, _tempPoly.xpoints[0], _tempPoly.ypoints[0], (int) x2, (int) y2, - _highlightColor1, _highlightColor2); - } - - break; - - case POLYLINE: - tpoly = new Polygon(_tempPoly.xpoints, _tempPoly.ypoints, _tempPoly.npoints); - addPoint(tpoly, _currentPt.x, _currentPt.y); - GraphicsUtilities.drawHighlightedPolyline(g, tpoly.xpoints, tpoly.ypoints, tpoly.npoints, _highlightColor1, - _highlightColor2); - break; - - case POLYGON: - tpoly = new Polygon(_tempPoly.xpoints, _tempPoly.ypoints, _tempPoly.npoints); - addPoint(tpoly, _currentPt.x, _currentPt.y); - g.fillPolygon(tpoly); - GraphicsUtilities.drawHighlightedShape(g, tpoly, _highlightColor1, _highlightColor2); - break; - } - } - - /** - * Here the current or stretched point can be modified to affect some - * policy--such as preserve the aspect ratio. The default is to do nothing. - * - * @param cp the new current point. - */ - private void modifyCurrentPoint(Point cp) { - Rectangle b = _canvas.getActiveBounds(); - if (_policy == Policy.RECTANGLE_PRESERVE_ASPECT) { - GraphicsUtilities.rectangleARFixedAdjust(b, getStart(), cp); - } - else if ((_policy == Policy.XONLY) && (cp != _startPt)) { - cp.y = b.y + b.height; - } - else if ((_policy == Policy.YONLY) && (cp != _startPt)) { - cp.x = b.x + b.width; - } - - cp.x = Math.max(1, Math.min(b.x + b.width - 1, cp.x)); - cp.y = Math.max(1, Math.min(b.y + b.height - 1, cp.y)); - - } - - /** - * Check whether this rubberband is active. - * - * @return true if active - */ - public boolean isActive() { - return _active; - } - - /** - * Get the starting screen point. - * - * @return the anchor (starting) screen point. - */ - public Point getStart() { - return _startPt; - } - - /** - * Get the current screen point. - * - * @return The current screen point. - */ - public Point getCurrent() { - return _currentPt; - } - - /** - * Set the starting point to the given point. Essentially reset the - * rubberbanding. - * - * @param anchorPt the new starting screen point. - */ - - public void startRubberbanding(Point anchorPt) { - if (_started) { - return; - } - _started = true; - - // first image is simply big enough for component - - _image = GraphicsUtilities.getComponentImageBuffer(_component); - - // this image holds background - _backgroundImage = GraphicsUtilities.getComponentImage(_component); - - // XONLY? (like for a time chart) - if (_policy == Policy.XONLY) { - Rectangle b = _canvas.getActiveBounds(); - anchorPt.y = b.y; - } - if (_policy == Policy.YONLY) { - Rectangle b = _canvas.getActiveBounds(); - anchorPt.x = b.x; - } - - _startPt.setLocation(anchorPt); - _currentPt.setLocation(anchorPt); - - if (polyMode() || radArcMode() || lineMode()) { - _tempPoly = new Polygon(); - addPoint(_tempPoly, anchorPt.x, anchorPt.y); - } - } - - /** - * Set the current point to the given point. - * - * @param newCurrentPoint the new current point. - */ - private void setCurrent(Point newCurrentPoint) { - - _currentPt.setLocation(newCurrentPoint); - if (_image == null) { - return; - } - - // we are drawing on the bare image - - Graphics2D g2 = _image.createGraphics(); - g2.setColor(_fillColor); - - // copy the background image to the image - g2.drawImage(_backgroundImage, 0, 0, _component); - draw(g2); - g2.dispose(); - - Graphics g = _component.getGraphics(); - // this causes that flash the first time i dinna ken why - // hack with veryFirst prevents flash - if (veryFirst) { - veryFirst = false; - } - else { - g.drawImage(_image, 0, 0, _component); - } - g.dispose(); - } - - /** - * Set the end point. - * - * @param p the end point. - */ - public void endRubberbanding(Point p) { - - modifyCurrentPoint(p); - _currentPt.setLocation(p); - _image = null; - _backgroundImage = null; - _poly = _tempPoly; - _tempPoly = null; - _active = false; - _started = false; - _component.removeMouseListener(_mouseAdapter); - _component.removeMouseMotionListener(_mouseMotionAdapter); - - // let someone know we are done. - if (_rubberbanded != null) { - _rubberbanded.doneRubberbanding(); - } - } - - /** - * Get the component being rubber banded. - * - * @return the component being rubber banded. - */ - public Component getComponent() { - return _component; - } - - /** - * This gets the rubber banded polygon, which will be null for - * rectangle or oval policies. - * - * @return the rubber banded polygon. - */ - Polygon getRubberbandPolygon() { - return _poly; - } - - /** - * Get the vertices of the rubber band. For an oval, it the corners of the - * enclosing rectangle. - * - * @return the rubber band vertices in a Point array. - */ - public Point[] getRubberbandVertices() { - switch (_policy) { - case POLYGON: - case POLYLINE: - case RADARC: - if ((_poly == null) || (_poly.npoints < 1)) { - return null; - } - else { - Point p[] = new Point[_poly.npoints]; - int x[] = _poly.xpoints; - int y[] = _poly.ypoints; - for (int i = 0; i < _poly.npoints; i++) { - p[i] = new Point(x[i], y[i]); - } - return p; - } - - default: - Rectangle r = getRubberbandBounds(); - Point p[] = new Point[4]; - int left = r.x; - int top = r.y; - int right = left + r.width; - int bottom = top + r.height; - p[0] = new Point(left, bottom); - p[1] = new Point(left, top); - p[2] = new Point(right, top); - p[3] = new Point(right, bottom); - return p; - } - } - - /** - * Return a rectangle that gives the final bounds of the rubber band. - * - * @return a bounding rectangle. - */ - public Rectangle getRubberbandBounds() { - - if (polyMode() || radArcMode()) { - if (_poly == null) { - return null; - } - else { - return _poly.getBounds(); - } - } - else { // rect or oval - return new Rectangle((_currentPt.x < _startPt.x) ? _currentPt.x : _startPt.x, - (_currentPt.y < _startPt.y) ? _currentPt.y : _startPt.y, Math.abs(_currentPt.x - _startPt.x), - Math.abs(_currentPt.y - _startPt.y)); - } - } - - /** - * Set the fill color for this rubber band. - * - * @param color the new fill color. - */ - public void setFillColor(Color color) { - _fillColor = color; - } - - /** - * Set one of the highlight colors used to stipple draw the boundary. - * - * @param highlightColor1 the value for the highlight color. - */ - public void setHighlightColor1(Color highlightColor1) { - _highlightColor1 = highlightColor1; - } - - /** - * Set the other highlight color used to stipple draw the boundary. - * - * @param highlightColor2 the value for the other highlight color. - */ - public void setHighlightColor2(Color highlightColor2) { - _highlightColor2 = highlightColor2; - } - - /** - * @return the _startPt - */ - public Point getStartPt() { - return _startPt; - } - - /** - * @return the _currentPt - */ - public Point getCurrentPt() { - return _currentPt; - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/.gitignore b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/.gitignore deleted file mode 100644 index 7bd53ebfb7..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -/EnumComboBox.class -/IStyled.class -/LineStyle$1.class -/LineStyle.class -/StyleEditorPanel$1.class -/StyleEditorPanel.class -/Styled.class -/SymbolDraw.class -/SymbolType$1.class -/SymbolType.class diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/EnumComboBox.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/EnumComboBox.java deleted file mode 100644 index fa7f331e40..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/EnumComboBox.java +++ /dev/null @@ -1,109 +0,0 @@ -package cnuphys.splot.style; - -import java.awt.Dimension; -import java.awt.Font; -import java.awt.FontMetrics; -import java.util.EnumMap; -import java.util.Hashtable; -import java.util.Set; - -import javax.swing.JComboBox; - -import cnuphys.splot.plot.Environment; - -public class EnumComboBox extends JComboBox { - - // reverse hash which takes a string and gives the enum - protected Hashtable> reverseHash; - - // an extra choce, not an enum name, like "any" - private String _extraChoice; - - protected static final Font _font = Environment.getInstance().getCommonFont(9); - - /** - * Create a combobox from an enum map. - * - * @param enumMap an {@code EnumMap}. The enum is the key, and the - * string, which will become the label, is the value. - * @param defaultKey the enum that should default to "on". - */ - public EnumComboBox(EnumMap enumMap, Enum defaultKey) { - this(enumMap, defaultKey, null); - } - - /** - * Create a combobox from an enum map. - * - * @param enumMap an {@code EnumMap}. The enum is the key, and the - * string, which will become the label, is the value. - * @param defaultKey the enum that should default to "on". - * @param extraChoice an optional extra choice, like "None" or "Any" - */ - public EnumComboBox(EnumMap enumMap, Enum defaultKey, String extraChoice) { - Set keySet = enumMap.keySet(); - - _extraChoice = extraChoice; - reverseHash = new Hashtable>(2 * keySet.size() + 1); - - // an extra choice? Like "any" - if (_extraChoice != null) { - addItem(_extraChoice); - } - - // in this enumMap the enum is the key, and a string is the value - for (Object key : keySet) { - String niceName = enumMap.get(key); - addItem(niceName); - reverseHash.put(niceName, (Enum) key); - } - - sizeComboBox(); - - if (defaultKey != null) { - setSelectedItem(enumMap.get(defaultKey)); - } - else if (_extraChoice != null) { - setSelectedItem(_extraChoice); - } - - setFont(_font); - - } - - /** - * Get the enum corresponding to the selected string, which is the nice name of - * the enum. - * - * @return the selected enum value. Returns null if "extra choice" - * was used and selected. - */ - public Enum getSelectedEnum() { - String niceName = (String) getSelectedItem(); - - // we signify the "extra" choice by returning null - if ((_extraChoice != null) && (_extraChoice.equals(niceName))) { - return null; - } - - return reverseHash.get(niceName); - } - - // size the combo box to just fit - protected void sizeComboBox() { - FontMetrics fm = getFontMetrics(getFont()); - - int maxSW = 0; - int count = getItemCount(); - Dimension d = getPreferredSize(); - for (int i = 0; i < count; i++) { - String s = (String) getItemAt(i); - maxSW = Math.max(maxSW, fm.stringWidth(s)); - } - - d.width = maxSW + 40; - setPreferredSize(d); - setMaximumSize(d); - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/IStyled.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/IStyled.java deleted file mode 100644 index a65e3288fb..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/IStyled.java +++ /dev/null @@ -1,149 +0,0 @@ -package cnuphys.splot.style; - -import java.awt.Color; - -public interface IStyled { - - /** - * Get the color used for fill the interior area. - * - * @return the fill color. - */ - public Color getFillColor(); - - /** - * Set the color used for fill the interior area. - * - * @param fillColor the fill color. - */ - public void setFillColor(Color fillColor); - - /** - * Get the color used for symbol borders. - * - * @return the symbol border color. - */ - public Color getBorderColor(); - - /** - * Set the color used for symbol borders. - * - * @param borderColor the border color. - */ - public void setBorderColor(Color borderColor); - - /** - * Get the color used for fits. - * - * @return the fit line color. - */ - - public Color getFitLineColor(); - - /** - * Get the color used for auxiliary lines. - * - * @return the auxiliary line color. - */ - - public Color getAuxLineColor(); - - /** - * Set the color used for the fit drawing. - * - * @param fitColor the fit color. - */ - public void setFitLineColor(Color fitColor); - - /** - * Set the color used for auxiliary lines. - * - * @param auxColor the auxiliary line color. - */ - public void setAuxLineColor(Color auxColor); - - /** - * Get the style used for drawing fits. - * - * @return the line style for fits. - */ - public LineStyle getFitLineStyle(); - - /** - * Get the style used for drawing fits. - * - * @return the line style for fits. - */ - public LineStyle getAuxLineStyle(); - - /** - * Set the style used for drawing fits. - * - * @param lineStyle the fit line style. - */ - public void setFitLineStyle(LineStyle lineStyle); - - /** - * Set the style used for drawing auxiliary lines. - * - * @param lineStyle the auxiliary line style. - */ - public void setAuxLineStyle(LineStyle lineStyle); - - /** - * Get the symbol used for drawing points. - * - * @return the symbol used for drawing points. - */ - public SymbolType getSymbolType(); - - /** - * Set the symbol used for drawing points. - * - * @param symbolType the symbol used for drawing points. - */ - public void setSymbolType(SymbolType symbolType); - - /** - * Get the line width for drawing fits. - * - * @return the fit line width in pixels. - */ - public float getFitLineWidth(); - - /** - * Get the line width for drawing auxiliary lines. - * - * @return the auxiliary line width in pixels. - */ - public float getAuxLineWidth(); - - /** - * Set the line width for drawing fit lines. - * - * @param lineWidth the line width in pixels. - */ - public void setFitLineWidth(float lineWidth); - - /** - * Set the line width for drawing auxiliary lines. - * - * @param lineWidth the auxiliary line width in pixels. - */ - public void setAuxLineWidth(float lineWidth); - - /** - * Get the symbol size (full width) in pixels. - * - * @return the symbol size (full width) in pixels. - */ - public int getSymbolSize(); - - /** - * Set symbol size (full width) in pixels. - * - * @param symbolSize symbol size (full width) in pixels. - */ - public void setSymbolSize(int symbolSize); - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/LineStyle.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/LineStyle.java deleted file mode 100644 index e1b0c1fba0..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/LineStyle.java +++ /dev/null @@ -1,89 +0,0 @@ -package cnuphys.splot.style; - -import java.awt.Dimension; -import java.awt.FontMetrics; -import java.util.EnumMap; - -public enum LineStyle { - SOLID, DASH, DOT_DASH, DOT, DOUBLE_DASH, LONG_DASH, LONG_DOT_DASH; - - /** - * A map for the names of the line styles - */ - public static EnumMap names = new EnumMap(LineStyle.class); - - static { - names.put(SOLID, "Solid"); - names.put(DASH, "Dashed"); - names.put(DOT_DASH, "Dot Dash"); - names.put(DOT, "Dotted"); - names.put(DOUBLE_DASH, "Double Dash"); - names.put(LONG_DASH, "Long Dash"); - names.put(LONG_DOT_DASH, "Long Dot Dash"); - } - - /** - * Get the nice name of the enum. - * - * @return the nice name, for combo boxes, menus, etc. - */ - public String getName() { - return names.get(this); - } - - /** - * Returns the enum value from the name. - * - * @param name the name to match. - * @return the LineStyle that corresponds to the name. Returns - * null if no match is found. Note it will check (case - * insensitive) both the map and the name() result, thus - * "Up Triangle" or "UPTRIANGLE" or "UpTrIaNgLe" will return the - * UPTRIANGLE value. - */ - public static LineStyle getValue(String name) { - if (name == null) { - return null; - } - - for (LineStyle val : values()) { - // check the nice name - if (name.equalsIgnoreCase(val.getName())) { - return val; - } - // check the base name - if (name.equalsIgnoreCase(val.name())) { - return val; - } - } - return null; - } - - /** - * Obtain a combo box of choices. - * - * @param defaultChoice - * @return the combo box of symbol choices - */ - public static EnumComboBox getComboBox(LineStyle defaultChoice) { - return new EnumComboBox(names, defaultChoice) { - // size the combo box to just fit - @Override - protected void sizeComboBox() { - Dimension d = getPreferredSize(); - - FontMetrics fm = getFontMetrics(_font); - int maxSW = 10; - - for (String s : names.values()) { - maxSW = Math.max(maxSW, fm.stringWidth(s)); - } - - d.width = maxSW + 50; - setPreferredSize(d); - setMaximumSize(d); - - } - }; - } -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/StyleEditorPanel.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/StyleEditorPanel.java deleted file mode 100644 index 5c98169aac..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/StyleEditorPanel.java +++ /dev/null @@ -1,292 +0,0 @@ -package cnuphys.splot.style; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.Font; - -import javax.swing.BoxLayout; -import javax.swing.JPanel; - -import cnuphys.splot.edit.ColorLabel; -import cnuphys.splot.pdata.DataSetType; -import cnuphys.splot.plot.CommonBorder; -import cnuphys.splot.plot.DoubleFormat; -import cnuphys.splot.plot.Environment; -import cnuphys.splot.plot.TextFieldSlider; - -public class StyleEditorPanel extends JPanel { - - public static final String SYMBOLSIZEPROP = "Symbol Size"; - public static final String LINEWIDTHPROP = "Line Width"; - - private static final Font _font = Environment.getInstance().getCommonFont(10); - - // change symbol type - private EnumComboBox _symbolSelector; - - // change symbol border style - private EnumComboBox _fitLineStyleSelector; - - // symbol border color - protected ColorLabel _borderColor; - - // fit line color - protected ColorLabel _fitLineColor; - - // symbol color - protected ColorLabel _symbolColor; - - // symbol size - protected TextFieldSlider _symbolSizeSelector; - - // curve line size - protected TextFieldSlider _lineSizeSelector; - - /** - * Create the stye editing panel. - */ - public StyleEditorPanel(DataSetType type) { - addContent(type); - setBorder(new CommonBorder("Style")); - - Environment.getInstance().commonize(this, null); - } - - // add the content - private void addContent(DataSetType type) { - setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - - // symbol panel - JPanel symPan = null; - if (type != DataSetType.H1D) { - symPan = flowPanel(FlowLayout.LEFT); - _symbolSelector = SymbolType.getComboBox(SymbolType.NOSYMBOL); - _symbolColor = new ColorLabel(null, Color.black, _font, "Symbol"); - symPan.add(_symbolSelector); - symPan.add(_symbolColor); - - _borderColor = new ColorLabel(null, Color.black, _font, "Symbol Border"); - symPan.add(_borderColor); - - } - else { - symPan = flowPanel(FlowLayout.LEFT); - _symbolColor = new ColorLabel(null, Color.black, _font, "Histogram Fill"); - symPan.add(_symbolColor); - - _borderColor = new ColorLabel(null, Color.black, _font, "Histogram Border"); - symPan.add(_borderColor); - } - - // symbol border panel - JPanel borderPanel = flowPanel(FlowLayout.LEFT); - _fitLineStyleSelector = LineStyle.getComboBox(LineStyle.SOLID); - - _fitLineColor = new ColorLabel(null, Color.black, _font, "Curve Line"); - - // make same size - if (_symbolSelector != null) { - Dimension dim1 = _symbolSelector.getPreferredSize(); - Dimension dim2 = _fitLineStyleSelector.getPreferredSize(); - int mw = Math.max(dim1.width, dim2.width); - dim1.width = mw; - _symbolSelector.setPreferredSize(dim1); - _fitLineStyleSelector.setPreferredSize(dim1); - } - - borderPanel.add(_fitLineStyleSelector); - borderPanel.add(_fitLineColor); - - if (type != DataSetType.H1D) { - String labels[] = { "4", "8", "12", "16", "20", "24", "28" }; - _symbolSizeSelector = new TextFieldSlider(4, 28, 8, _font, 1, labels, 180, 40, "Symbol Size") { - - @Override - public double sliderValueToRealValue() { - return getValue(); - } - - @Override - public int realValueToSliderValue(double val) { - return (int) val; - } - - @Override - public String valueString(double val) { - return "" + getValue(); - } - - @Override - public void valueChanged() { - firePropertyChange(SYMBOLSIZEPROP, -1, _symbolSizeSelector.getValue()); - } - - }; - } - - // line size - String szLabels[] = { "0", "2", "4", "6", "8", "10", "12" }; - _lineSizeSelector = new TextFieldSlider(0, 24, 1, _font, 1, szLabels, 180, 40, "Curve Line Width") { - - @Override - public double sliderValueToRealValue() { - return getValue() / 2.; - } - - @Override - public int realValueToSliderValue(double val) { - return (int) (2 * val); - } - - @Override - public String valueString(double val) { - double dval = sliderValueToRealValue(); - return DoubleFormat.doubleFormat(dval, 1); - } - - @Override - public void valueChanged() { - firePropertyChange(LINEWIDTHPROP, -1, _lineSizeSelector.getValue()); - } - - }; - - if (symPan != null) { - add(symPan); - } - add(borderPanel); - if (type != DataSetType.H1D) { - add(_symbolSizeSelector); - } - add(_lineSizeSelector); - - } - - private JPanel flowPanel(int constraint) { - JPanel sp = new JPanel(); - sp.setLayout(new FlowLayout(constraint)); - Environment.getInstance().commonize(sp, null); - return sp; - } - - // set components enabled - @Override - public void setEnabled(boolean enabled) { - super.setEnabled(enabled); - - if (_symbolSelector != null) { - _symbolSelector.setEnabled(enabled); - } - if (_fitLineStyleSelector != null) { - _fitLineStyleSelector.setEnabled(enabled); - } - if (_symbolColor != null) { - _symbolColor.setEnabled(enabled); - } - if (_borderColor != null) { - _borderColor.setEnabled(enabled); - } - if (_symbolSizeSelector != null) { - _symbolSizeSelector.setEnabled(enabled); - } - if (_lineSizeSelector != null) { - _lineSizeSelector.setEnabled(enabled); - } - if (_fitLineColor != null) { - _fitLineColor.setEnabled(enabled); - } - - } - - /** - * Set the choices - * - * @param style the new choices - */ - public void setStyle(IStyled style) { - if (style != null) { - if (_symbolSelector != null) { - _symbolSelector.setSelectedItem(style.getSymbolType().getName()); - } - if (_fitLineStyleSelector != null) { - _fitLineStyleSelector.setSelectedItem(style.getFitLineStyle().getName()); - } - if (_symbolColor != null) { - _symbolColor.setColor(style.getFillColor()); - } - if (_borderColor != null) { - _borderColor.setColor(style.getBorderColor()); - } - if (_fitLineColor != null) { - _fitLineColor.setColor(style.getFitLineColor()); - } - if (_symbolSizeSelector != null) { - _symbolSizeSelector.setValue(style.getSymbolSize()); - } - } - } - - /** - * Get the symbols size slider - * - * @return symbols size slider - */ - public TextFieldSlider getSymbolSizeSelector() { - return _symbolSizeSelector; - } - - /** - * Get the line width slider - * - * @return line width slider - */ - public TextFieldSlider getLineWidthSelector() { - return _lineSizeSelector; - } - - /** - * Get the symbol selector - * - * @return the symbol selector - */ - public EnumComboBox getSymbolSelector() { - return _symbolSelector; - } - - /** - * Get the border selector - * - * @return the border selector - */ - public EnumComboBox getBorderSelector() { - return _fitLineStyleSelector; - } - - /** - * Get the symbol color selector - * - * @return the symbol color selector - */ - public ColorLabel getSymbolColor() { - return _symbolColor; - } - - /** - * Get the line color selector - * - * @return the line color selector - */ - public ColorLabel getBorderColor() { - return _borderColor; - } - - /** - * Get the fit line color selector - * - * @return the fit line color selector - */ - public ColorLabel getFitLineColor() { - return _fitLineColor; - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/Styled.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/Styled.java deleted file mode 100644 index e5f4302587..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/Styled.java +++ /dev/null @@ -1,250 +0,0 @@ -package cnuphys.splot.style; - -import java.awt.Color; - -public class Styled implements IStyled { - - private static Color _defFillColor = new Color(0, 0, 255, 128); - private static Color _defBorderColor = new Color(192, 192, 192, 128); - private static Color _defAuxLineColor = new Color(160, 160, 160, 144); - - // default fill color half-alpha blue - private Color _fillColor = _defFillColor; - - // default line color is black - private Color _borderColor = _defBorderColor; - - // default fit color is null--will use line color - private Color _fitColor = Color.black; - - // default fit line style is solid - private LineStyle _fitLineStyle = LineStyle.SOLID; - - // auxiliary lines - // default fit color is null--will use line color - private Color _auxLineColor = _defAuxLineColor; - - // default auxiliary line style is solid - private LineStyle _auxLineStyle = LineStyle.DASH; - - // default fit line width is 1 - private float _fitLineWidth = 0.75f; - - // default auxiliary line width is 1 - private float _auxLineWidth = 0.75f; - - // default symbol type = square - private SymbolType _symbolType = SymbolType.SQUARE; - - // default full width symbol size - private int _symbolSize = 8; - - // for random combinations - private static final Color _colors[] = { Color.black, Color.red, Color.blue, Color.gray }; - private static final SymbolType _symbols[] = { SymbolType.SQUARE, SymbolType.CIRCLE, SymbolType.DIAMOND, - SymbolType.CROSS, SymbolType.DOWNTRIANGLE, SymbolType.UPTRIANGLE }; - - /** - * Create with all defaults. - */ - public Styled() { - } - - /** - * Generate a sort of random style - * - * @param index determines the style. Can be any integer - */ - public Styled(int index) { - _fillColor = _colors[index % _colors.length]; - _borderColor = _fillColor.darker(); - _symbolType = _symbols[index % _symbols.length]; - } - - /** - * Create a Styled object - * - * @param fillColor the fill color - * @param borderColor the symbol border color - * @param fitLineColor the fit line color - * @param auxLineColor the auxiliary line color - * @param fitLineStyle the fit line style - * @param auxLineStyle the auxiliary line style - * @param fitLineWidth the line width for fits - * @param auxLineWidth the line width for auxiliary lines - * @param symbolType the symbol type - * @param symbolSize the symbol size - */ - public Styled(Color fillColor, Color borderColor, Color fitLineColor, Color auxLineColor, LineStyle fitLineStyle, - LineStyle auxLineStyle, float fitLineWidth, float auxLineWidth, SymbolType symbolType, int symbolSize) { - _fillColor = fillColor; - _borderColor = borderColor; - _fitLineStyle = fitLineStyle; - _fitLineWidth = fitLineWidth; - _symbolType = symbolType; - _symbolSize = symbolSize; - - } - - /** - * Create with all defaults but the given fill color. - * - * @param fillColor the fill color to user. - */ - public Styled(Color fillColor) { - _fillColor = fillColor; - } - - /** - * Create with all defaults but the given fill color. The link color is set a - * little darker or lighter. - * - * @param fillColor the fill color to user. - * @param darkerLineColor if true/false make line color darker/lighter than fill - * color. - */ - public Styled(Color fillColor, boolean darkerLineColor) { - _fillColor = fillColor; - if (darkerLineColor) { - _borderColor = fillColor.darker(); - } - else { - _borderColor = fillColor.brighter(); - } - - } - - /** - * Get the fill color for the symbols - * - * @return the fill color for the symbols - */ - @Override - public Color getFillColor() { - return _fillColor; - } - - @Override - public Color getBorderColor() { - return _borderColor; - } - - @Override - public Color getFitLineColor() { - if (_fitColor == null) { - return _borderColor; - } - return _fitColor; - } - - @Override - public LineStyle getFitLineStyle() { - return _fitLineStyle; - } - - @Override - public float getFitLineWidth() { - return _fitLineWidth; - } - - @Override - public SymbolType getSymbolType() { - return _symbolType; - } - - @Override - public void setFillColor(Color fillColor) { - _fillColor = fillColor; - } - - @Override - public void setBorderColor(Color lineColor) { - _borderColor = lineColor; - } - - @Override - public void setFitLineColor(Color fitColor) { - _fitColor = fitColor; - } - - /** - * Set the line style - * - * @param lineStyle the new line style - */ - @Override - public void setFitLineStyle(LineStyle lineStyle) { - _fitLineStyle = lineStyle; - } - - /** - * Set the line width - * - * @param lineWidth the new line width - */ - @Override - public void setFitLineWidth(float lineWidth) { - _fitLineWidth = lineWidth; - } - - /** - * Set the symbol type - * - * @param symbolType the new symbol type - */ - @Override - public void setSymbolType(SymbolType symbolType) { - _symbolType = symbolType; - } - - /** - * Get the symbol size (full width) in pixels. - * - * @return the symbol size (full width) in pixels. - */ - @Override - public int getSymbolSize() { - return _symbolSize; - } - - /** - * Set symbol size (full width) in pixels. - * - * @param symbolSize symbol size (full width) in pixels. - */ - @Override - public void setSymbolSize(int symbolSize) { - _symbolSize = symbolSize; - } - - @Override - public Color getAuxLineColor() { - return _auxLineColor; - } - - @Override - public void setAuxLineColor(Color auxColor) { - _auxLineColor = auxColor; - } - - @Override - public LineStyle getAuxLineStyle() { - return _auxLineStyle; - } - - @Override - public void setAuxLineStyle(LineStyle lineStyle) { - _auxLineStyle = lineStyle; - } - - @Override - public float getAuxLineWidth() { - return _auxLineWidth; - } - - @Override - public void setAuxLineWidth(float lineWidth) { - _auxLineWidth = lineWidth; - - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/SymbolDraw.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/SymbolDraw.java deleted file mode 100644 index 4a1300e696..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/SymbolDraw.java +++ /dev/null @@ -1,293 +0,0 @@ -package cnuphys.splot.style; - -import java.awt.Color; -import java.awt.Graphics; -import java.awt.Polygon; - -public class SymbolDraw { - - /** - * Draws the appropriate symbol at the provided screen location. - * - * @param g the graphics context - * @param x the x screen coordinate. - * @param y the y screen coordinate. - * @param style the drawing style to use. - */ - - public static void drawSymbol(Graphics g, int x, int y, IStyled style) { - - drawSymbol(g, x, y, style.getSymbolType(), style.getSymbolSize(), style.getBorderColor(), style.getFillColor()); - } - - /** - * Draws the appropriate symbol at the provided screen location. - * - * @param g the graphics context - * @param x the x screen coordinate. - * @param y the y screen coordinate. - * @param style the drawing style to use. - */ - - public static void drawGhostSymbol(Graphics g, int x, int y, IStyled style) { - - drawSymbol(g, x, y + 1, style.getSymbolType(), style.getSymbolSize(), Color.white, style.getFillColor()); - drawSymbol(g, x, y, style.getSymbolType(), style.getSymbolSize(), style.getBorderColor(), style.getFillColor()); - drawSymbol(g, x, y - 1, style.getSymbolType(), style.getSymbolSize(), style.getBorderColor(), - style.getFillColor()); - } - - /** - * Draws the appropriate symbol at the provided screen location. - * - * @param g the graphics context - * @param x the x screen coordinate. - * @param y the y screen coordinate. - * @param symbol the symbol to use. - * @param symbolSize the size of the symbol in pixels--typically around 8. - * @param lineColor the outline color. - * @param fillColor the fill color, which is not relevant for some symbols. - */ - public static void drawSymbol(Graphics g, int x, int y, SymbolType symbol, int symbolSize, Color lineColor, - Color fillColor) { - - if (symbol == SymbolType.NOSYMBOL) { - return; - } - - int s2 = symbolSize / 2; - - switch (symbol) { - case SQUARE: - drawRectangle(g, x, y, s2, s2, lineColor, fillColor); - break; - - case CIRCLE: - drawOval(g, x, y, s2, s2, lineColor, fillColor); - break; - - case DIAMOND: - drawDiamond(g, x, y, s2, lineColor, fillColor); - break; - - case CROSS: - drawCross(g, x, y, s2, lineColor); - break; - - case UPTRIANGLE: - drawUpTriangle(g, x, y, s2, lineColor, fillColor); - break; - - case DOWNTRIANGLE: - drawDownTriangle(g, x, y, s2, lineColor, fillColor); - break; - - case X: - drawX(g, x, y, s2, lineColor); - break; - - case NOSYMBOL: - break; - - } - } - - /** - * Draw a simple rectangle - * - * @param g the graphics context - * @param x the horizontal center - * @param y the vertical center - * @param w2 the half width - * @param h2 the half height - * @param lc tThe line color - * @param fc tThe fillcolor - */ - public static void drawRectangle(Graphics g, int x, int y, int w2, int h2, Color lc, Color fc) { - - // this will ensure all symbols correct size - if (lc == null) { - lc = fc; - } - - if (fc != null) { - g.setColor(fc); - g.fillRect(x - w2, y - h2, 2 * w2, 2 * h2); - } - if (lc != null) { - g.setColor(lc); - g.drawRect(x - w2, y - h2, 2 * w2, 2 * h2); - } - } - - /** - * Draw a simple oval - * - * @param g the graphics context - * @param x the horizontal center - * @param y the vertical center - * @param w2 the half width - * @param h2 the half height - * @param lc the line color - * @param fc The fillcolor - */ - public static void drawOval(Graphics g, int x, int y, int w2, int h2, Color lc, Color fc) { - - // this will ensure all symbols correct size - if (lc == null) { - lc = fc; - } - - if (fc != null) { - g.setColor(fc); - g.fillOval(x - w2, y - h2, 2 * w2, 2 * h2); - } - if (lc != null) { - g.setColor(lc); - g.drawOval(x - w2, y - h2, 2 * w2, 2 * h2); - } - } - - /** - * Draw a simple up triangle - * - * @param g the graphics context - * @param x the horizontal center - * @param y the vertical center - * @param s2 the half-width - * @param lc the line color - * @param fc the fillcolor - */ - public static void drawUpTriangle(Graphics g, int x, int y, int s2, Color lc, Color fc) { - - // this will ensure all symbols correct size - if (lc == null) { - lc = fc; - } - - int l = x - s2; - int t = y - s2; - int r = x + s2; - int b = y + s2; - Polygon poly = new Polygon(); - poly.addPoint(l, b); - poly.addPoint(x, t); - poly.addPoint(r, b); - if (fc != null) { - g.setColor(fc); - g.fillPolygon(poly); - } - if (lc != null) { - g.setColor(lc); - g.drawPolygon(poly); - } - } - - /** - * Draw a simple down triangle - * - * @param g the graphics context - * @param x the horizontal center - * @param y the vertical center - * @param s2 the half-width - * @param lc the line color - * @param fc tThe fillcolor - */ - public static void drawDownTriangle(Graphics g, int x, int y, int s2, Color lc, Color fc) { - - // this will ensure all symbols correct size - if (lc == null) { - lc = fc; - } - - int l = x - s2; - int t = y - s2; - int r = x + s2; - int b = y + s2; - Polygon poly = new Polygon(); - poly.addPoint(l, t); - poly.addPoint(r, t); - poly.addPoint(x, b); - if (fc != null) { - g.setColor(fc); - g.fillPolygon(poly); - } - if (lc != null) { - g.setColor(lc); - g.drawPolygon(poly); - } - } - - /** - * Draw a simple cross - * - * @param g the graphics context - * @param x the horizontal center - * @param y the vertical center - * @param s2 the half-width - * @param lc the line color - */ - public static void drawCross(Graphics g, int x, int y, int s2, Color lc) { - - if (lc != null) { - g.setColor(lc); - g.drawLine(x - s2, y, x + s2, y); - g.drawLine(x, y - s2, x, y + s2); - } - } - - /** - * Draw a simple X symbol. - * - * @param g the graphics context - * @param x the horizontal center - * @param y the vertical center - * @param s2 the half-width width - * @param lc the line color - */ - public static void drawX(Graphics g, int x, int y, int s2, Color lc) { - - if (lc != null) { - g.setColor(lc); - g.drawLine(x - s2, y - s2, x + s2, y + s2); - g.drawLine(x - s2, y + s2, x + s2, y - s2); - } - } - - /** - * Draw a simple diamond - * - * @param g the graphics context - * @param x the horizontal center - * @param y the vertical center - * @param s2 the half-width - * @param lc the line color - * @param fc the fillcolor - */ - public static void drawDiamond(Graphics g, int x, int y, int s2, Color lc, Color fc) { - - // this will ensure all symbols correct size - if (lc == null) { - lc = fc; - } - - int l = x - s2; - int t = y - s2; - int r = x + s2; - int b = y + s2; - Polygon poly = new Polygon(); - poly.addPoint(l, y); - poly.addPoint(x, t); - poly.addPoint(r, y); - poly.addPoint(x, b); - if (fc != null) { - g.setColor(fc); - g.fillPolygon(poly); - } - if (lc != null) { - g.setColor(lc); - g.drawPolygon(poly); - } - } - -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/SymbolType.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/SymbolType.java deleted file mode 100644 index 3000f742ca..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/style/SymbolType.java +++ /dev/null @@ -1,91 +0,0 @@ -package cnuphys.splot.style; - -import java.awt.Dimension; -import java.awt.FontMetrics; -import java.util.EnumMap; - -public enum SymbolType { - NOSYMBOL, SQUARE, CIRCLE, CROSS, UPTRIANGLE, DOWNTRIANGLE, X, DIAMOND; - - /** - * A map for the names of the symbols - */ - public static EnumMap names = new EnumMap(SymbolType.class); - - static { - names.put(SQUARE, "Square"); - names.put(CIRCLE, "Circle"); - names.put(CROSS, "Cross"); - names.put(DOWNTRIANGLE, "Down Triangle"); - names.put(UPTRIANGLE, "Up Triangle"); - names.put(X, "X"); - names.put(DIAMOND, "Diamond"); - names.put(NOSYMBOL, "No Symbol"); - } - - /** - * Get the nice name of the enum. - * - * @return the nice name, for combo boxes, menus, etc. - */ - public String getName() { - return names.get(this); - } - - /** - * Returns the enum value from the name. - * - * @param name the name to match. - * @return the SymbolType that corresponds to the name. Returns - * null if no match is found. Note it will check (case - * insensitive) both the map and the name() result, thus - * "Up Triangle" or "UPTRIANGLE" or "dUpTrIaNgLe" will return the - * UPTRIANGLE value. - */ - public static SymbolType getValue(String name) { - if (name == null) { - return null; - } - - for (SymbolType val : values()) { - // check the nice name - if (name.equalsIgnoreCase(val.getName())) { - return val; - } - // check the base name - if (name.equalsIgnoreCase(val.name())) { - return val; - } - } - return null; - } - - /** - * Obtain a combo box of choices. - * - * @param defaultChoice - * @return the combo box of symbol choices - */ - public static EnumComboBox getComboBox(SymbolType defaultChoice) { - return new EnumComboBox(names, defaultChoice) { - // size the combo box to just fit - @Override - protected void sizeComboBox() { - Dimension d = getPreferredSize(); - - FontMetrics fm = getFontMetrics(_font); - int maxSW = 10; - - for (String s : names.values()) { - maxSW = Math.max(maxSW, fm.stringWidth(s)); - } - - d.width = maxSW + 50; - setPreferredSize(d); - setMaximumSize(d); - - } - }; - } - -} \ No newline at end of file diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/toolbar/.gitignore b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/toolbar/.gitignore deleted file mode 100644 index 4ba771825c..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/toolbar/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/CommonToolBar.class -/IToolBarListener.class -/ToolBarButton.class -/ToolBarToggleButton.class diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/toolbar/CommonToolBar.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/toolbar/CommonToolBar.java deleted file mode 100644 index 106ef4c16a..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/toolbar/CommonToolBar.java +++ /dev/null @@ -1,369 +0,0 @@ -package cnuphys.splot.toolbar; - -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.util.Enumeration; - -import javax.swing.AbstractButton; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.ButtonGroup; -import javax.swing.JToggleButton; -import javax.swing.JToolBar; -import javax.swing.event.EventListenerList; - -import cnuphys.splot.plot.Environment; - -public class CommonToolBar extends JToolBar implements ActionListener, ItemListener { - - // make all the toggle buttons mutually exclusive - private ButtonGroup _buttonGroup = new ButtonGroup(); - - // the default button - private ToolBarToggleButton _pointerButton; - - // box zoom - private ToolBarToggleButton _boxZoomButton; - - // recenter button - private ToolBarToggleButton _recenterButton; - - // List of toolBar listeners - private EventListenerList _listenerList; - - // command strings - public static final String ZOOMIN = "ZOOM IN"; - public static final String ZOOMOUT = "ZOOM OUT"; - public static final String POINTER = "POINTER"; - public static final String PRINT = "PRINT"; - public static final String BOXZOOM = "BOXZOOM"; - public static final String CENTER = "CENTER"; - public static final String WORLD = "WORLD"; - public static final String PNG = "PNG"; - - /** - * Creates a new tool bar with a specified name and orientation. All other - * constructors call this constructor. - * - * @param orientation the initial orientation -- it must be either - * HORIZONTAL or VERTICAL - */ - public CommonToolBar(int orientation) { - super("toolBar", orientation); - setFloatable(false); - - Environment.getInstance().commonize(this, null); - setBorder(BorderFactory.createEtchedBorder()); - - _pointerButton = new ToolBarToggleButton("images/pointer.gif", "Make selections", POINTER, 3, 1, - "images/pointercursor.gif"); - _pointerButton.setSelected(true); - add(_pointerButton); - - _boxZoomButton = new ToolBarToggleButton("images/box_zoom.gif", "Zoom to area", BOXZOOM, 3, 1, - "images/box_zoomcursor.gif"); - add(_boxZoomButton); - - _recenterButton = new ToolBarToggleButton("images/center.gif", "Recenter the plot", CENTER, -1, -1, - "images/centercursor.gif"); - - add(_recenterButton); - - addHGap(8); - add(new ToolBarButton("images/zoom_in.gif", "Zoom in", ZOOMIN)); - add(new ToolBarButton("images/zoom_out.gif", "Zoom out", ZOOMOUT)); - add(new ToolBarButton("images/world.gif", "Include all data", WORLD)); - add(new ToolBarButton("images/printer.gif", "Print the plot", PRINT)); - add(new ToolBarButton("images/camera.gif", "Save as PNG", PNG)); - } - - /** - * Set which toggle buttonis selected - */ - public void setSelectedToggle(String s) { - if (s == null) { - _pointerButton.setSelected(true); - } - else if (s.equals(BOXZOOM)) { - _boxZoomButton.setSelected(true); - } - else if (s.equals(CENTER)) { - _recenterButton.setSelected(true); - } - else { - _pointerButton.setSelected(true); - } - } - - /** - * Get the primary button group so that we can add other buttons to the group - * - * @return the primary button group so that we can add other buttons to the - * group - */ - public ButtonGroup getMainButtonGroup() { - return _buttonGroup; - } - - // add a gap between buttons - private void addHGap(int gap) { - add(Box.createHorizontalStrut(gap)); - } - - /** - * Add a regular button to the toolbar - * - * @param button the ToolBarButton to add. - */ - public void add(ToolBarButton button) { - super.add(button); - button.addActionListener(this); - } - - /** - * Add a toggle button to the toolbar. - * - * @param toggleButton the button to add. - */ - public void add(JToggleButton toggleButton) { - add(toggleButton, true); - } - - /** - * Add a toggle button to the toolbar. - * - * @param toggleButton the button to add. - * @param toGroup if true and to the primary button group - */ - public void add(JToggleButton toggleButton, boolean toGroup) { - super.add(toggleButton); - - if (toGroup) { - if (_buttonGroup == null) { - _buttonGroup = new ButtonGroup(); - } - _buttonGroup.add(toggleButton); - } - toggleButton.addItemListener(this); - } - - /** - * remove a toggle button from the toolbar. - * - * @param toggleButton the button to remove. - */ - public void remove(JToggleButton toggleButton) { - if (toggleButton != null) { - super.remove(toggleButton); - - if (_buttonGroup != null) { - _buttonGroup.remove(toggleButton); - } - } - } - - /** - * Get the default toggle button. This will become active if you click an active - * toggle button to turn it off. - * - * @return the default toggle buton. - */ - public JToggleButton getDefaultToggleButton() { - return _pointerButton; - } - - /** - * Set the default toggle button. This will become active if you click an active - * toggle button to turn it off. - * - * @param defaultToggleButton the default toggle button. - */ - public void setDefaultToggleButton(ToolBarToggleButton defaultToggleButton) { - _pointerButton = defaultToggleButton; - } - - /** - * Reset the default toggle button selection - */ - public void resetDefaultSelection() { - - if (_pointerButton != null) { - _pointerButton.doClick(); - } - } - - /** - * Get the command of the active toggle button - * - * @return the command of the active toggle button - */ - public String getActiveCommand() { - ToolBarToggleButton tbtb = getActiveButton(); - return (tbtb != null) ? tbtb.getActionCommand() : "??"; - } - - /** - * Get which tool bar toggle button from the primary button group is active - * - * @return the active toolbar toggle button (from the primary button group), or - * null. - */ - public ToolBarToggleButton getActiveButton() { - - if (_buttonGroup == null) { - return null; - } - - try { - for (Enumeration e = _buttonGroup.getElements(); e.hasMoreElements();) { - AbstractButton ab = e.nextElement(); - if (ab.isSelected()) { - return (ToolBarToggleButton) ab; - } - } - } - catch (Exception e) { - e.printStackTrace(); - } - - return null; - } - - /** - * Check whether the default button is active - * - * @return true if the default button is active. - */ - public boolean isDefaultActivated() { - ToolBarToggleButton tbtb = getActiveButton(); - return ((tbtb != null) && (tbtb == _pointerButton)); - } - - /** - * Check whether a given button is active - * - * @param tbtb the button to test - * @return true if the default button is active. - */ - public boolean isButtonActivated(AbstractButton tbtb) { - return ((tbtb != null) && (tbtb == getActiveButton())); - } - - // notify listeners of a change in the magnetic field - private void notifyListeners(AbstractButton button) { - - if (_listenerList == null) { - return; - } - - // Guaranteed to return a non-null array - Object[] listeners = _listenerList.getListenerList(); - - // This weird loop is the bullet proof way of notifying all listeners. - // for (int i = listeners.length - 2; i >= 0; i -= 2) { - // order is flipped so it goes in order as added - for (int i = 0; i < listeners.length; i += 2) { - if (listeners[i] == IToolBarListener.class) { - IToolBarListener listener = (IToolBarListener) listeners[i + 1]; - if (button instanceof ToolBarButton) { - listener.buttonPressed(this, (ToolBarButton) button); - } - if (button instanceof ToolBarToggleButton) { - listener.toggleButtonActivated(this, (ToolBarToggleButton) button); - } - } - - } - } - - /** - * Add a toolBar listener - * - * @param listener the listener to add - */ - public void addToolBarListener(IToolBarListener listener) { - - if (_listenerList == null) { - _listenerList = new EventListenerList(); - } - - // avoid adding duplicates - _listenerList.remove(IToolBarListener.class, listener); - _listenerList.add(IToolBarListener.class, listener); - } - - /** - * Remove a ToolBarListener. - * - * @param listener the ToolBarListener to remove. - */ - - public void removeToolBarListener(IToolBarListener listener) { - - if ((listener == null) || (_listenerList == null)) { - return; - } - - _listenerList.remove(IToolBarListener.class, listener); - } - - @Override - public void actionPerformed(ActionEvent e) { - Object source = e.getSource(); - if (source instanceof ToolBarButton) { - notifyListeners((ToolBarButton) source); - } - - } - - @Override - public void itemStateChanged(ItemEvent e) { - Object source = e.getSource(); - if (e.getStateChange() == ItemEvent.SELECTED) { - if (source instanceof ToolBarToggleButton) { - notifyListeners((ToolBarToggleButton) source); - } - } - } - - /** - * Find a button from the action command - * - * @param actionCommand the action command to match - * @return the button or null if not found - */ - public AbstractButton getButton(String actionCommand) { - if (actionCommand == null) { - return null; - } - Component array[] = getComponents(); - - for (Component c : array) { - if (c instanceof AbstractButton) { - AbstractButton b = (AbstractButton) c; - if (actionCommand.equalsIgnoreCase(b.getActionCommand())) { - return b; - } - } - } - - return null; - } - - /** - * Set a button enabled by the action command - * - * @param actionCommand the action command - * @param enabled the flag - */ - public void setButtonEnabled(String actionCommand, boolean enabled) { - AbstractButton b = getButton(actionCommand); - if (b != null) { - b.setEnabled(enabled); - } - } - -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/toolbar/IToolBarListener.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/toolbar/IToolBarListener.java deleted file mode 100644 index c3f14fd145..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/toolbar/IToolBarListener.java +++ /dev/null @@ -1,10 +0,0 @@ -package cnuphys.splot.toolbar; - -import java.util.EventListener; - -public interface IToolBarListener extends EventListener { - - public void buttonPressed(CommonToolBar toolbar, ToolBarButton button); - - public void toggleButtonActivated(CommonToolBar toolbar, ToolBarToggleButton button); -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/toolbar/ToolBarButton.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/toolbar/ToolBarButton.java deleted file mode 100644 index aafc51050b..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/toolbar/ToolBarButton.java +++ /dev/null @@ -1,64 +0,0 @@ -package cnuphys.splot.toolbar; - -import java.awt.Cursor; -import java.awt.Dimension; - -import javax.swing.ImageIcon; -import javax.swing.JButton; - -import cnuphys.splot.plot.ImageManager; - -public class ToolBarButton extends JButton { - - /** - * Preferred size for toolbar buttons. - */ - private static Dimension preferredSize = new Dimension(24, 24); - - /** - * Constructor - * - * @param imageFileName the name if the file holding the icon - * @param toolTip a string for a tool tip - * @param actionCommand - */ - public ToolBarButton(String imageFileName, String toolTip, String actionCommand) { - super(); - - setActionCommand(actionCommand); - ImageIcon imageIcon = ImageManager.getInstance().loadImageIcon(imageFileName); - setFocusPainted(true); - setBorderPainted(true); - - String bareName = new String(imageFileName); - int index = bareName.indexOf("."); - if (index > 1) { - bareName = bareName.substring(0, index); - } - - setToolTipText(toolTip); - setIcon(imageIcon); - setRolloverEnabled(true); - - } - - /** - * Get the appropriate cursor for this tool. - * - * @return the cursor appropriate when the mouse is in the container (and this - * button is active). - */ - public Cursor canvasCursor() { - return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); - } - - /** - * Get the preferred size. - * - * @return the preferred size for layout. - */ - @Override - public Dimension getPreferredSize() { - return preferredSize; - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/toolbar/ToolBarToggleButton.java b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/toolbar/ToolBarToggleButton.java deleted file mode 100644 index 22d234e921..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/toolbar/ToolBarToggleButton.java +++ /dev/null @@ -1,171 +0,0 @@ -package cnuphys.splot.toolbar; - -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.Image; -import java.awt.Point; -import java.awt.Toolkit; - -import javax.swing.ImageIcon; -import javax.swing.JToggleButton; - -import cnuphys.splot.plot.ImageManager; - -public class ToolBarToggleButton extends JToggleButton { - - /** - * preferred size. Default, for whatever reason, will be 24x24. - */ - protected Dimension preferredSize; - - /** - * Custom cursor. - */ - protected Cursor customCursor; - - /** - * Optional file with a custom cursor. - */ - protected String customCursorImageFile; - - /** - * Used in conjunction with custom cursor. - */ - protected boolean triedOnce = false; - - /** - * The x coordinate of hot spot of a custom cursor, if there is one. A negative - * value means it will use the center of the cursor. - */ - protected int xhot = -1; - - /** - * The y coordinate of hot spot of a custom cursor, if there is one. A negative - * value means it will use the center of the cursor. - */ - protected int yhot = -1; - - protected static int ICONSIZE = 24; - - /** - * Create a toolbar toggle button - * - * @param imageFileName the name if the file holding the icon - * @param toolTip a string for a tool tip - * @param actionCommand theaction command. - */ - public ToolBarToggleButton(String imageFileName, String toolTip, String actionCommand) { - this(imageFileName, toolTip, actionCommand, -1, -1, null); - } - - /** - * Create a toolbar toggle button - * - * @param imageFileName the name if the file holding the icon - * @param toolTip a string for a tool tip - * @param actionCommand theaction command. - * @param xh - * @param yh - * @param cursorImageFile - */ - public ToolBarToggleButton(String imageFileName, String toolTip, String actionCommand, int xh, int yh, - String cursorImageFile) { - this(imageFileName, toolTip, actionCommand, xh, yh, cursorImageFile, ICONSIZE, ICONSIZE); - } - - /** - * Create a toolbar toggle button - * - * @param imageFileName the name if the file holding the icon - * @param toolTip a string for a tool tip - * @param actionCommand theaction command. - * @param xh - * @param yh - * @param cursorImageFile - * @param iw - * @param ih - */ - public ToolBarToggleButton(String imageFileName, String toolTip, String actionCommand, int xh, int yh, - String cursorImageFile, int iw, int ih) { - super(); - preferredSize = new Dimension(iw, ih); - - xhot = xh; - yhot = yh; - customCursorImageFile = cursorImageFile; - - // setFocusPainted(false); - - setActionCommand(actionCommand); - ImageIcon imageIcon = ImageManager.getInstance().loadImageIcon(imageFileName); - - String bareName = new String(imageFileName); - int index = bareName.indexOf("."); - if (index > 1) { - bareName = bareName.substring(0, index); - } - - setFocusPainted(false); - setToolTipText(toolTip); - setIcon(imageIcon); - setRolloverEnabled(true); - - // try to get an enabled icon - if (index > 0) { - String baseName = imageFileName.substring(0, index); - String ext = imageFileName.substring(index); - String enabledFileName = baseName + "enabled" + ext; - try { - ImageIcon enabledImageIcon = ImageManager.getInstance().loadImageIcon(enabledFileName); - setSelectedIcon(enabledImageIcon); - } - catch (Exception e) { - e.printStackTrace(); - } - } - } - - /** - * Get the preferred size. - * - * @return the preferred size for layout. - */ - @Override - public Dimension getPreferredSize() { - return preferredSize; - } - - /** - * Get the appropriate cursor for this tool. - * - * @return The cursor appropriate when the mouse is in the container. The - * default will be a cross hair. - */ - public Cursor canvasCursor() { - - if (!triedOnce) { - if (customCursorImageFile != null) { - Image image = ImageManager.getInstance().loadImage(customCursorImageFile, this); - if (image != null) { - - if (xhot < 0) { - xhot = image.getWidth(this) / 2; - } - if (yhot < 0) { - yhot = image.getHeight(this) / 2; - } - customCursor = Toolkit.getDefaultToolkit().createCustomCursor(image, new Point(xhot, yhot), - "pointer"); - } - } - triedOnce = true; - } - - if (customCursor != null) { - return customCursor; - } - else { - return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); - } - } -} diff --git a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/xml/.gitignore b/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/xml/.gitignore deleted file mode 100644 index 84deee7eae..0000000000 --- a/common-tools/cnuphys/splot/src/main/java/cnuphys/splot/xml/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/XmlDomParser.class -/XmlPrintStreamWritable.class -/XmlPrintStreamWriter.class -/XmlSupport.class diff --git a/common-tools/cnuphys/swimmer/pom.xml b/common-tools/cnuphys/swimmer/pom.xml index a6263288c8..27397986a4 100644 --- a/common-tools/cnuphys/swimmer/pom.xml +++ b/common-tools/cnuphys/swimmer/pom.xml @@ -19,13 +19,6 @@ magfield 14.2.4-SNAPSHOT - - - cnuphys - splot - 14.2.4-SNAPSHOT - - diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/AdaptiveBeamlineSwimTest.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/AdaptiveBeamlineSwimTest.java- similarity index 100% rename from common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/AdaptiveBeamlineSwimTest.java rename to common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/AdaptiveBeamlineSwimTest.java- diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/AdaptiveResultDiff.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/AdaptiveResultDiff.java- similarity index 100% rename from common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/AdaptiveResultDiff.java rename to common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/AdaptiveResultDiff.java- diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/AdaptiveSectorSwimTest.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/AdaptiveSectorSwimTest.java- similarity index 100% rename from common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/AdaptiveSectorSwimTest.java rename to common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/AdaptiveSectorSwimTest.java- diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/AdaptiveTests.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/AdaptiveTests.java- similarity index 100% rename from common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/AdaptiveTests.java rename to common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/AdaptiveTests.java- diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/LineTestPlotGrid.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/LineTestPlotGrid.java- similarity index 100% rename from common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/LineTestPlotGrid.java rename to common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/LineTestPlotGrid.java- diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/ZTestPlotGrid.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/ZTestPlotGrid.java- similarity index 100% rename from common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/ZTestPlotGrid.java rename to common-tools/cnuphys/swimmer/src/main/java/cnuphys/adaptiveSwim/test/ZTestPlotGrid.java- diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/CreateTestTrajectories.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/CreateTestTrajectories.java- similarity index 100% rename from common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/CreateTestTrajectories.java rename to common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/CreateTestTrajectories.java- diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/RandomData.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/RandomData.java- similarity index 100% rename from common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/RandomData.java rename to common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/RandomData.java- diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SectorTest.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SectorTest.java- similarity index 100% rename from common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SectorTest.java rename to common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SectorTest.java- diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SmallDZTest.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SmallDZTest.java- similarity index 100% rename from common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SmallDZTest.java rename to common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SmallDZTest.java- diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SwimTest.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SwimTest.java- similarity index 100% rename from common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SwimTest.java rename to common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SwimTest.java- diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SwimTestData.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SwimTestData.java- similarity index 100% rename from common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SwimTestData.java rename to common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/SwimTestData.java- diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/TestTrajectories.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/TestTrajectories.java- similarity index 100% rename from common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/TestTrajectories.java rename to common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/TestTrajectories.java- diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/ThreadTest.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/ThreadTest.java- similarity index 100% rename from common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/ThreadTest.java rename to common-tools/cnuphys/swimmer/src/main/java/cnuphys/swimtest/ThreadTest.java- diff --git a/pom.xml b/pom.xml index 4c869d1666..af4b4073d1 100644 --- a/pom.xml +++ b/pom.xml @@ -24,11 +24,6 @@ code.jlab.org-hallb-clas12-maven https://code.jlab.org/api/v4/groups/3425/-/packages/maven - - - clasweb-clas12maven - https://clasweb.jlab.org/.clas12maven -