Index: trunk/psModules/src/camera/pmFPAfile.c
===================================================================
--- trunk/psModules/src/camera/pmFPAfile.c	(revision 42312)
+++ trunk/psModules/src/camera/pmFPAfile.c	(revision 42338)
@@ -539,4 +539,7 @@
     if (!strcasecmp(type, "LINEARITY"))  {
       return PM_FPA_FILE_LINEARITY;
+    }
+    if (!strcasecmp(type, "NEWNONLIN"))  {
+      return PM_FPA_FILE_NEWNONLIN;
     }
     if (!strcasecmp(type, "ASTROM"))     {
Index: trunk/psModules/src/camera/pmFPAfile.h
===================================================================
--- trunk/psModules/src/camera/pmFPAfile.h	(revision 42312)
+++ trunk/psModules/src/camera/pmFPAfile.h	(revision 42338)
@@ -54,4 +54,5 @@
     PM_FPA_FILE_PATTERN_ROW_AMP,
     PM_FPA_FILE_LINEARITY,
+    PM_FPA_FILE_NEWNONLIN,
     PM_FPA_FILE_EXPNUM,
 } pmFPAfileType;
Index: trunk/psModules/src/camera/pmFPAfileIO.c
===================================================================
--- trunk/psModules/src/camera/pmFPAfileIO.c	(revision 42312)
+++ trunk/psModules/src/camera/pmFPAfileIO.c	(revision 42338)
@@ -282,4 +282,5 @@
       case PM_FPA_FILE_KAPA:
       case PM_FPA_FILE_LINEARITY:
+      case PM_FPA_FILE_NEWNONLIN:
         break;
       default:
@@ -638,4 +639,5 @@
       case PM_FPA_FILE_PATTERN_ROW_AMP:
       case PM_FPA_FILE_LINEARITY:
+      case PM_FPA_FILE_NEWNONLIN:
       case PM_FPA_FILE_EXPNUM:
         psTrace ("psModules.camera", 5, "closing %s (%s) (%d:%d:%d)\n", file->filename, file->name, view->chip, view->cell, view->readout);
@@ -722,4 +724,5 @@
       case PM_FPA_FILE_KAPA:
       case PM_FPA_FILE_LINEARITY:
+      case PM_FPA_FILE_NEWNONLIN:
         psTrace ("psModules.camera", 5, "nothing to free for %s (%s)\n", file->filename, file->name);
         return true;
@@ -881,4 +884,5 @@
       case PM_FPA_FILE_PATTERN_ROW_AMP:
       case PM_FPA_FILE_LINEARITY:
+      case PM_FPA_FILE_NEWNONLIN:
       case PM_FPA_FILE_EXPNUM:
         psTrace ("psModules.camera", 5, "opening %s (%s) (%d:%d:%d)\n",
Index: trunk/psModules/src/detrend/Makefile.am
===================================================================
--- trunk/psModules/src/detrend/Makefile.am	(revision 42312)
+++ trunk/psModules/src/detrend/Makefile.am	(revision 42338)
@@ -10,4 +10,5 @@
 	pmMaskStats.c \
 	pmNonLinear.c \
+	pmNewNonLinear.c \
 	pmBias.c \
 	pmOverscan.c \
@@ -30,4 +31,5 @@
 	pmMaskStats.h \
 	pmNonLinear.h \
+	pmNewNonLinear.h \
 	pmBias.h \
 	pmOverscan.h \
Index: trunk/psModules/src/detrend/pmDetrendDB.h
===================================================================
--- trunk/psModules/src/detrend/pmDetrendDB.h	(revision 42312)
+++ trunk/psModules/src/detrend/pmDetrendDB.h	(revision 42338)
@@ -39,4 +39,5 @@
     PM_DETREND_TYPE_VIDEODARK,
     PM_DETREND_TYPE_LINEARITY,
+    PM_DETREND_TYPE_NEWNONLIN,
     PM_DETREND_TYPE_AUXMASK,
     PM_DETREND_TYPE_KH_CORRECT,
Index: trunk/psModules/src/detrend/pmNewNonLinear.c
===================================================================
--- trunk/psModules/src/detrend/pmNewNonLinear.c	(revision 42338)
+++ trunk/psModules/src/detrend/pmNewNonLinear.c	(revision 42338)
@@ -0,0 +1,56 @@
+#include <stdio.h>
+#include <pslib.h>
+
+#include "pmHDU.h"
+#include "pmFPA.h"
+#include "pmNewNonLinear.h"
+
+// model is stored as a FITS table, read into an array
+// each row is one knot, with (X, Y, dY2)
+bool pmNewNonLinearityApply(pmReadout *inputReadout, psArray *table)
+{
+    PS_ASSERT_PTR_NON_NULL(table, false);
+    PS_ASSERT_PTR_NON_NULL(inputReadout, false);
+    PS_ASSERT_PTR_NON_NULL(inputReadout->image, false);
+    PS_ASSERT_IMAGE_TYPE(inputReadout->image, PS_TYPE_F32, false);
+
+    psTimerStart ("nonlinear");
+
+    psImage *image = inputReadout->image;
+
+    // create an empty 1D spline with table->n knots
+    psSpline1D *model = psSpline1DCreate(table->n);
+    
+    // parse the table entries
+    for (int i = 0; i < table->n; i++) {
+	psMetadata *row = table->data[i];
+	
+	bool status;
+	model->xKnots[i]   = psMetadataLookupF32(&status, row, "X_KNOT");
+	model->yKnots[i]   = psMetadataLookupF32(&status, row, "Y_KNOT");
+	model->d2yKnots[i] = psMetadataLookupF32(&status, row, "DY2_DX");
+    }
+
+    // set equal spacing info?
+    // psSpline1DisEqualSpacing (model);
+
+    for (int i = 0; i < image->numRows; i++) { // Loop over rows : note: problem with discontinuity here
+	for (int j = 0; j < image->numCols; j++) { // Loop over columns
+	    // Calculate correction factor contribution for this pixel.
+	    psF32 flux = image->data.F32[i][j];
+	    psF32 lFlux = log10(flux);
+	    
+	    psF32 factor = psSpline1DEval (model, lFlux);
+	    
+	    // Apply correction to image data
+	    image->data.F32[i][j] = flux * factor;
+
+	}
+    }
+    psLogMsg ("psModules", PS_LOG_MINUTIA, "apply correction: %f sec\n", psTimerMark ("nonlinear"));
+
+    psFree (model);
+  
+    return(true);
+}
+
Index: trunk/psModules/src/detrend/pmNewNonLinear.h
===================================================================
--- trunk/psModules/src/detrend/pmNewNonLinear.h	(revision 42338)
+++ trunk/psModules/src/detrend/pmNewNonLinear.h	(revision 42338)
@@ -0,0 +1,18 @@
+/* @file pmNewNonLinear.h
+ * @brief Perform new (2023) non-linear correction using spline fits
+ *
+ * @author Eugene Magnier, IfA
+ * Copyright 2023 Institute for Astronomy, University of Hawaii
+ */
+
+#ifndef PM_NEW_NON_LINEAR_H
+#define PM_NEW_NON_LINEAR_H
+
+/// @addtogroup detrend Detrend Creation and Application
+/// @{
+
+/// Correct non-linearity using spline
+bool pmNewNonLinearityApply(pmReadout *inputReadout, psArray *table);
+
+/// @}
+#endif
Index: trunk/psModules/src/detrend/pmOverscan.c
===================================================================
--- trunk/psModules/src/detrend/pmOverscan.c	(revision 42312)
+++ trunk/psModules/src/detrend/pmOverscan.c	(revision 42338)
@@ -136,8 +136,12 @@
         break;
       case PM_FIT_SPLINE:
-        // XXX I don't think psSpline1D is up to scratch yet --- it has no mask, and requires an
-        // input spline
-        overscanOpts->spline = psVectorFitSpline1D(reduced, ordinate);
-        fitted = psSpline1DEvalVector(overscanOpts->spline, ordinate);
+
+        // XXX I don't think psSpline1D is up to scratch yet --- it has no mask, and it assumes
+	// a knot for every input point.  it needs an argument like 'number of knots' for the
+	// output spline.  EAM: still true 2023.01.22
+
+        // overscanOpts->spline = psVectorFitSpline1D(reduced, ordinate);
+        // fitted = psSpline1DEvalVector(overscanOpts->spline, ordinate);
+        psError(PS_ERR_UNKNOWN, true, "Spline overscan fitting is broken\n");
         break;
       default:
@@ -185,4 +189,5 @@
       }
       case PM_FIT_SPLINE: {
+	/*
 	  psSpline1D *spline = overscanOpts->spline; // The spline
 	  for (int i = 0; i < spline->n; i++) {
@@ -197,4 +202,5 @@
 	      comment = NULL;
 	  }
+	*/
 	  // write metadata header value
 	  psMetadataAddF32(hdu->header, PS_LIST_TAIL, "OVER_VAL", PS_META_REPLACE,
Index: trunk/psModules/src/psmodules.h
===================================================================
--- trunk/psModules/src/psmodules.h	(revision 42312)
+++ trunk/psModules/src/psmodules.h	(revision 42338)
@@ -77,4 +77,5 @@
 #include <pmMaskStats.h>
 #include <pmNonLinear.h>
+#include <pmNewNonLinear.h>
 #include <pmOverscan.h>
 #include <pmBias.h>
