Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Started working on a CSVWriter for the IOService to be used by the
Browse files Browse the repository at this point in the history
Reflectivity tests. Added ReflectivityCalculator and friends.

Signed-off-by: Jay Jay Billings <billingsjj@ornl.gov>
  • Loading branch information
Jay Jay Billings committed Jan 26, 2015
1 parent 025407f commit be54d3e
Show file tree
Hide file tree
Showing 5 changed files with 340 additions and 0 deletions.
71 changes: 71 additions & 0 deletions 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<String []\> 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<Entry> 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";
}

}
@@ -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;
}

}
@@ -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;

}
@@ -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");
}

}
@@ -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");
}

}

0 comments on commit be54d3e

Please sign in to comment.