/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Readers;
import Core.Data;
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
/**
*
* @author Amir
*/
public class XLSReader extends FileReader{
private Workbook excelWorkBook;
private Sheet sheet;
/**
* Constructs XLSReader
* @param dataFile
* Microsoft Excel Spreadsheet file's full path
* @throws IOException
* @throws BiffException
*/
public XLSReader(File dataFile) throws IOException, BiffException{
excelWorkBook = Workbook.getWorkbook(dataFile);
//we always work on the first sheet
try{
sheet = excelWorkBook.getSheet(0);
}catch(IndexOutOfBoundsException ex){
sheet = null;
throw new IndexOutOfBoundsException("No valid sheet in excel file");
}
}
@Override
public Data readData() {
Data data = new Data();
//readFirstLine();
Cell[] rowElement = sheet.getRow(0);
data.setNumOfElements((int) Double.parseDouble(rowElement[0].getContents()));
data.setPileLength(Double.parseDouble(rowElement[1].getContents()));
data.setEI(Double.parseDouble(rowElement[2].getContents()));
data.setPileDiameter(Double.parseDouble(rowElement[3].getContents()));
data.setNumOfPiles((int)Double.parseDouble(rowElement[4].getContents()));
data.setPoissonRation(Double.parseDouble(rowElement[5].getContents()));
data.setIterationNumber(Integer.parseInt(rowElement[6].getContents()));
int numOfPileElements = data.getNumOfElements();
//readPileNodeCoordinates();
rowElement = sheet.getRow(1);
for(int cellCounter=0;cellCounter<=numOfPileElements;cellCounter++){
double cellValue = Double.parseDouble(rowElement[cellCounter].getContents());
data.addPileNodeCoordinate(cellValue);
}
//readModOfSubgradeReaction();
rowElement = sheet.getRow(2);
for(int cellCounter=0;cellCounter<=numOfPileElements;cellCounter++){
double cellValue = Double.parseDouble(rowElement[cellCounter].getContents());
data.addModOfSubgradeReaction(cellValue);
}
//readLateralSoilMovement();
rowElement = sheet.getRow(3);
for(int cellCounter=0;cellCounter<=numOfPileElements;cellCounter++){
double cellValue = Double.parseDouble(rowElement[cellCounter].getContents());
data.addLateralSoilMovement(cellValue);
}
//readLimitSoilPressure();
rowElement = sheet.getRow(4);
for(int cellCounter=0;cellCounter<=numOfPileElements;cellCounter++){
double cellValue = Double.parseDouble(rowElement[cellCounter].getContents());
data.addLimitSoilPressure(cellValue);
}
//readPileCoordinates();
rowElement = sheet.getRow(1);
int numOfPiles = data.getNumOfPiles();
for(int i=1;i<=numOfPiles;i++){
int xCoIndex = i*2-2;
int yCoIndex = xCoIndex+1;
double xCo = Double.parseDouble(rowElement[xCoIndex].getContents());
double yCo = Double.parseDouble(rowElement[yCoIndex].getContents());
data.addPileCoordinates(xCo, yCo);
}
return data;
}
}