From be54d3eb73f279fdc49737f50f835f23f9fd6d4c Mon Sep 17 00:00:00 2001 From: Jay Jay Billings Date: Mon, 26 Jan 2015 17:02:20 -0500 Subject: [PATCH] Started working on a CSVWriter for the IOService to be used by the Reflectivity tests. Added ReflectivityCalculator and friends. Signed-off-by: Jay Jay Billings --- .../src/org/eclipse/ice/io/csv/CSVReader.java | 71 ++++++++++ .../reflectivity/ReflectivityCalculator.java | 50 +++++++ .../org/eclipse/ice/reflectivity/Tile.java | 46 +++++++ .../ice/io/csv/test/CSVReaderTester.java | 129 ++++++++++++++++++ .../test/ReflectivityCalculatorTester.java | 44 ++++++ 5 files changed, 340 insertions(+) create mode 100644 src/org.eclipse.ice.io/src/org/eclipse/ice/io/csv/CSVReader.java create mode 100644 src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityCalculator.java create mode 100644 src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/Tile.java create mode 100644 tests/org.eclipse.ice.io.test/src/org/eclipse/ice/io/csv/test/CSVReaderTester.java create mode 100644 tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityCalculatorTester.java diff --git a/src/org.eclipse.ice.io/src/org/eclipse/ice/io/csv/CSVReader.java b/src/org.eclipse.ice.io/src/org/eclipse/ice/io/csv/CSVReader.java new file mode 100644 index 000000000..af977987a --- /dev/null +++ b/src/org.eclipse.ice.io/src/org/eclipse/ice/io/csv/CSVReader.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Initial API and implementation and/or initial documentation - + * Jay Jay Billings + *******************************************************************************/ +package org.eclipse.ice.io.csv; + +import java.util.ArrayList; + +import org.eclipse.core.resources.IFile; +import org.eclipse.ice.datastructures.form.Entry; +import org.eclipse.ice.datastructures.form.Form; +import org.eclipse.ice.io.serializable.IReader; + +/** + * This class implements the IReader interface to provide a reader for CSV + * files. It can read any well-formed CSV file. It stores its results in a + * ListComponent on the Form returned from read(). Each String [] in + * the ListComponent is a line of the file, split and trimmed but uncast. + * Clients must know the concrete type to which they want to cast. + * + * Comments are ignored and begin with the "#" character. + * + * @author Jay Jay Billings + * + */ +public class CSVReader implements IReader { + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ice.io.serializable.IReader#read(org.eclipse.core.resources + * .IFile) + */ + @Override + public Form read(IFile file) { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ice.io.serializable.IReader#findAll(org.eclipse.core.resources + * .IFile, java.lang.String) + */ + @Override + public ArrayList findAll(IFile file, String regex) { + // TODO Auto-generated method stub + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ice.io.serializable.IReader#getReaderType() + */ + @Override + public String getReaderType() { + return "csv"; + } + +} diff --git a/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityCalculator.java b/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityCalculator.java new file mode 100644 index 000000000..993a3b4bf --- /dev/null +++ b/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/ReflectivityCalculator.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Initial API and implementation and/or initial documentation - + * Jay Jay Billings + *******************************************************************************/ +package org.eclipse.ice.reflectivity; + +/** + * This class performs all of the operations necessary to calculate the + * reflectivity of a stack of materials. It follows the code originally + * developed by John Ankner at Oak Ridge National Laboratory. + * + * @author Jay Jay Billings, John Ankner + * + */ +public class ReflectivityCalculator { + + /** + * The constructor + */ + public ReflectivityCalculator() { + // TODO Auto-generated constructor stub + } + + /** + * This operation returns the value of the squared modulus of the specular + * reflectivity for a single wave vector Q. + * + * @param waveVectorQ + * the value of the wave vector + * @param wavelength + * the wavelength of the incident neutrons + * @param tiles + * the list of TIles that contains the physical parameters needed + * for the calculation, including the scattering densities, + * absorption parameters and thicknesses. + * @return the squared modulus of the specular reflectivity + */ + public double getSpecRefSqrdMod(double waveVectorQ, double wavelength, + Tile[] tiles) { + return 0.0; + } + +} diff --git a/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/Tile.java b/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/Tile.java new file mode 100644 index 000000000..6940eeb8b --- /dev/null +++ b/src/org.eclipse.ice.reflectivity/src/org/eclipse/ice/reflectivity/Tile.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Initial API and implementation and/or initial documentation - + * Jay Jay Billings + *******************************************************************************/ +package org.eclipse.ice.reflectivity; + +/** + * This class represents a tile or layer of material of a particular type in the + * reflectivity calculator. + * + * It has no accessors and everything is public because it is made for a + * calculation. It should not be used outside of its package. + * + * @author Jay Jay Billings, John Ankner + * + */ +public class Tile { + + /** + * The scattering length of the reflecting tile/layer. + */ + double scatteringLength = 0.0; + + /** + * The true absorption length of the reflecting tile/layer. + */ + double trueAbsLength = 0.0; + + /** + * The incoherent absorption length of the reflecting tile/layer. + */ + double incAbsLength = 0.0; + + /** + * The thickness of this tile/layer. + */ + double thickness = 0.0; + +} diff --git a/tests/org.eclipse.ice.io.test/src/org/eclipse/ice/io/csv/test/CSVReaderTester.java b/tests/org.eclipse.ice.io.test/src/org/eclipse/ice/io/csv/test/CSVReaderTester.java new file mode 100644 index 000000000..516bc54b6 --- /dev/null +++ b/tests/org.eclipse.ice.io.test/src/org/eclipse/ice/io/csv/test/CSVReaderTester.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Initial API and implementation and/or initial documentation - + * Jay Jay Billings + *******************************************************************************/ +package org.eclipse.ice.io.csv.test; + +import static org.junit.Assert.*; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URI; + +/** + * Test class for {@link org.eclipse.ice.io.csv.CSVReader}. + * + * @author Jay Jay Billings + * + */ +public class CSVReaderTester { + + private static IFile testFile; + + /** + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + // Get the file separator used on this system, which is different across + // OSes. + String separator = System.getProperty("file.separator"); + // Create the path for the reflectivity file in the ICE tests directory + String userHome = System.getProperty("user.home"); + IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); + URI defaultProjectLocation = null; + IProject project = null; + String projectName = "CSVLoaderTesterWorkspace"; + String filename = "getSpecRefSqrdMod_q841.csv"; + String fullFilename = userHome + separator + "ICETests" + separator + + projectName + separator + filename; + IPath projectPath = new Path(userHome + separator + "ICETests" + + separator + projectName + separator + ".project"); + + // Setup the project + try { + // Create the project description + IProjectDescription desc = ResourcesPlugin.getWorkspace() + .loadProjectDescription(projectPath); + // Get the project handle and create it + project = workspaceRoot.getProject(desc.getName()); + project.create(desc, new NullProgressMonitor()); + // Open the project if it is not already open + if (project.exists() && !project.isOpen()) { + project.open(new NullProgressMonitor()); + } + // Refresh the workspace + project.refreshLocal(IResource.DEPTH_INFINITE, + new NullProgressMonitor()); + // Create the IFile handle for the csv file + testFile = project.getFile(filename); + } catch (CoreException e) { + // Catch exception for creating the project + e.printStackTrace(); + fail(); + } + + return; + } + + /** + * Test method for + * {@link org.eclipse.ice.io.csv.CSVReader#read(org.eclipse.core.resources.IFile)} + * . + * + * @throws CoreException + * @throws IOException + */ + @Test + public void testRead() throws CoreException, IOException { + System.out.println(testFile.getLocation().toOSString()); + BufferedReader reader = new BufferedReader(new InputStreamReader( + testFile.getContents())); + System.out.println(reader.readLine()); + System.out.println(reader.readLine()); + fail("Not yet implemented"); + reader.close(); + } + + /** + * Test method for + * {@link org.eclipse.ice.io.csv.CSVReader#findAll(org.eclipse.core.resources.IFile, java.lang.String)} + * . + */ + @Test + public void testFindAll() { + fail("Not yet implemented"); + } + + /** + * Test method for {@link org.eclipse.ice.io.csv.CSVReader#getReaderType()}. + */ + @Test + public void testGetReaderType() { + fail("Not yet implemented"); + } + +} diff --git a/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityCalculatorTester.java b/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityCalculatorTester.java new file mode 100644 index 000000000..2f2a0b61d --- /dev/null +++ b/tests/org.eclipse.ice.reflectivity.test/src/org/eclipse/ice/reflectivity/test/ReflectivityCalculatorTester.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 UT-Battelle, LLC. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Initial API and implementation and/or initial documentation - + * Jay Jay Billings, John Ankner + *******************************************************************************/ +package org.eclipse.ice.reflectivity.test; + +import static org.junit.Assert.*; + +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * This class tests {@link org.eclipse.ice.reflectivity.ReflectivityCalculator}. + * + * @author Jay Jay Billings, John Ankner + * + */ +public class ReflectivityCalculatorTester { + + /** + * This class loads the files for the test. + * + * @throws java.lang.Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + } + + /** + * This class tests {@link ReflectivityCalculator#getSpectRefSqrdMod}. + */ + @Test + public void testGetSpecRefSqrdMod() { + fail("Not yet implemented"); + } + +}