@@ -312,7 +312,6 @@ public final boolean[][] getFlag() {
312312 * @throws RuntimeException
313313 */
314314 public void checkExpression (final String name , final String expression ) throws RuntimeException {
315-
316315 // Test if name conflicts with standard columns (VIS2DATA)
317316 if (getColumnDesc (name ) != null ) {
318317 throw new IllegalArgumentException ("Column name [" + name + "] already existing (OIFITS standard) !" );
@@ -331,11 +330,12 @@ public void updateExpressionColumn(final String name, final String expression) {
331330 // remove column (descriptor and values) if existing:
332331 removeExpressionColumn (name );
333332
334- addDerivedColumnMeta (new WaveColumnMeta (name , "expression: " + expression ,
335- Types .TYPE_DBL , this , expression ));
333+ final WaveColumnMeta colMeta = new WaveColumnMeta (name , "expression: " + expression ,
334+ Types .TYPE_DBL , this , expression );
335+ addDerivedColumnMeta (colMeta );
336336
337337 // Force computation now (not lazy):
338- getExprColumnDoubles (name , expression );
338+ getExprColumnDoubles (name , colMeta );
339339 }
340340
341341 /**
@@ -345,6 +345,9 @@ public void updateExpressionColumn(final String name, final String expression) {
345345 public void removeExpressionColumn (final String name ) {
346346 final ColumnMeta column = getColumnDerivedDesc (name );
347347
348+ // anyway clear cached values:
349+ clearColumnsRangeValue (name );
350+
348351 // check if the column has an expression
349352 if (column instanceof WaveColumnMeta ) {
350353 final WaveColumnMeta colMeta = (WaveColumnMeta ) column ;
@@ -512,19 +515,19 @@ protected double[][] getSpatialCoord(final String name, final String coordName)
512515 }
513516
514517 /**
515- * Return the array with the given expression
518+ * Return the computed expression f[x][y] for the given column name
516519 * @param name derived column name
517- * @param expression expression entered by the user
520+ * @param colMeta the corresponding column descriptor
518521 * @return the computed expression f[x][y]
519522 */
520- protected double [][] getExprColumnDoubles (final String name , final String expression ) {
523+ protected double [][] getExprColumnDoubles (final String name , final WaveColumnMeta colMeta ) {
521524 // lazy: get previously computed results:
522525 double [][] exprResults = this .getColumnDerivedDoubles (name );
523526
524527 // check if expression changed ?
525- if (exprResults == null ) {
528+ if (( exprResults == null ) && ( colMeta . getExpression () != null ) ) {
526529 // not computed; do it now (LAZY):
527- exprResults = ExpressionEvaluator .getInstance ().eval (this , name , expression , false );
530+ exprResults = ExpressionEvaluator .getInstance ().eval (this , name , colMeta . getExpression () , false );
528531
529532 // store computed results for next time:
530533 this .setColumnDerivedValue (name , exprResults );
@@ -957,14 +960,12 @@ protected double[][] getDerivedColumnAsDoubles(final String name) {
957960 return getSpatialFreq ();
958961 }
959962 // handle user expressions
960- for (ColumnMeta column : getColumnDerivedDescCollection ()) {
961- if (column .getName ().equals (name )) {
962- if (column instanceof WaveColumnMeta ) {
963- WaveColumnMeta colMeta = (WaveColumnMeta ) column ;
963+ for (final ColumnMeta column : getColumnDerivedDescCollection ()) {
964+ if (column .getName ().equals (name ) && (column instanceof WaveColumnMeta )) {
965+ final WaveColumnMeta colMeta = (WaveColumnMeta ) column ;
964966
965- if (colMeta .getExpression () != null ) {
966- return getExprColumnDoubles (name , colMeta .getExpression ());
967- }
967+ if (colMeta .getExpression () != null ) {
968+ return getExprColumnDoubles (name , colMeta );
968969 }
969970 }
970971 }
0 commit comments