package initialconditions; import java.lang.*; import java.io.*; import main.BetterTokenizer; import main.Cell; import main.GeneralInput; public class CellIC extends InitialCondition { int xpos=-1, ypos=-1; public final boolean noiseAware = true; public CellIC() { super(); } public CellIC(String n, float iv, int x, int y) { super(); node = n; initValue = iv; xpos = x; ypos = y; } public void setModel(Cell [] cells) { float val = initValue; if(noiseLevel > 0.0f) { val += noiseLevel * (float)rng.nextGaussian(); if(val < 0.0f) val = 0.0f; } try { cells[(ypos*Cell.arrayWidth)+xpos].setInitialValue(node, val); } catch(Exception e) { System.out.println("Error setting initial condition CellIC for <" + node + ">: " + e.toString()); return; } } public void setFrom(Cell [] cells, boolean takePresentValue) throws Exception { if(!takePresentValue) { initValue = cells[(ypos*Cell.arrayWidth)+xpos].getInitialValue(node); } else { initValue = cells[(ypos*Cell.arrayWidth)+xpos].nodePeek(node); } } public void print() { System.out.println(node + " = " + initValue + " in row " + ypos + " position " + xpos + "; "); } protected void loadParameter(String info, BetterTokenizer tokenizer) throws Exception { if(info.equals("XPos")) { GeneralInput.nextToken(tokenizer); xpos = (int)tokenizer.nval; } else if(info.equals("YPos")) { GeneralInput.nextToken(tokenizer); ypos = (int)tokenizer.nval; } else super.loadParameter(info, tokenizer); } public void toString(PrintWriter pw, String indent) { super.toString(pw, indent); pw.println(indent + "&XPos\t" + xpos); pw.println(indent + "&YPos\t" + ypos); } }