Index: pr_inversion/test/data_error_1.txt
===================================================================
--- pr_inversion/test/data_error_1.txt	(revision b00b487e2e68ed49f8b11454ab513171ef3a634a)
+++ pr_inversion/test/data_error_1.txt	(revision b00b487e2e68ed49f8b11454ab513171ef3a634a)
@@ -0,0 +1,87 @@
+<X>   <Y>   <dY>
+0.00231958  84.0171  -9.16608
+0.00259247  73.6644  -8.5828
+0.00286536  49.8047  -7.05724
+0.00313824  34.2893  5.85571
+0.00341113  24.1324  4.91248
+0.00368401  17.1548  4.14184
+0.0039569  12.0308  3.46855
+0.00422978  8.62062  2.93609
+0.00450266  6.40114  2.53005
+0.00477555  4.7518  2.17986
+0.00504842  3.58955  1.89461
+0.0053213  3.0119  1.73548
+0.00559418  2.39727  1.54831
+0.00586705  2.0773  1.44128
+0.00613993  1.65804  1.28765
+0.0064128  1.32639  1.15169
+0.00668567  1.23667  1.11206
+0.00695853  1.06648  1.0327
+0.0072314  0.854762  0.924533
+0.00750426  0.725025  0.851484
+0.00777712  0.636988  0.798115
+0.00804998  0.549  0.740946
+0.00832283  0.527819  0.726512
+0.00859569  0.448613  0.669785
+0.00886854  0.384463  0.620051
+0.00914139  0.36818  0.606778
+0.00941423  0.343939  0.586463
+0.00968707  0.328724  0.573345
+0.00995991  0.281235  0.530316
+0.0102327  0.239363  0.489247
+0.0105056  0.261195  0.511072
+0.0107784  0.241851  0.491783
+0.0110512  0.237327  0.487162
+0.0113241  0.214241  0.462862
+0.0115969  0.186748  0.432143
+0.0118697  0.161051  0.401312
+0.0121425  0.184622  0.429676
+0.0124153  0.168442  0.410417
+0.0126881  0.156892  0.396095
+0.0129609  0.148072  0.384801
+0.0132337  0.147115  0.383556
+0.0135065  0.168421  0.410392
+0.0137793  0.127737  0.357404
+0.0140521  0.128569  0.358565
+0.0143249  0.138782  0.372535
+0.0145977  0.161172  0.401462
+0.0148704  0.117663  0.343021
+0.0151432  0.136941  0.370056
+0.015416  0.149982  0.387275
+0.0156887  0.11796  0.343454
+0.0159615  0.104142  0.32271
+0.0162342  0.11449  0.338363
+0.016507  0.107782  0.328301
+0.0167797  0.126445  0.355591
+0.0170525  0.108571  0.329501
+0.0173252  0.114721  0.338705
+0.0175979  0.100336  0.316758
+0.0178706  0.119656  0.345913
+0.0181433  0.0821055  0.28654
+0.0184161  0.0929812  0.304928
+0.0186888  0.123417  0.351307
+0.0189615  0.0936499  0.306023
+0.0192341  0.104339  0.323015
+0.0195068  0.102485  0.320134
+0.0197795  0.0952812  0.308677
+0.0200522  0.0582846  0.241422
+0.0203249  0.111761  0.334307
+0.0205975  0.0842643  0.290283
+0.0208702  0.10902  0.330182
+0.0211428  0.0663487  0.257583
+0.0214155  0.109861  0.331453
+0.0216881  0.104081  0.322615
+0.0219607  0.084819  0.291237
+0.0222334  0.135506  0.368111
+0.022506  0.117578  0.342897
+0.0227786  0.0973008  0.311931
+0.0230512  0.107357  0.327654
+0.0233238  0.103988  0.322472
+0.0235964  0.0519642  0.227957
+0.023869  0.0703513  0.265238
+0.0241415  0.0653181  0.255574
+0.0244141  0.0094026  0.096967
+0.0246867  0.0754079  0.274605
+0.0249592  0.266365  0.516105
+0.0252318  0.166849  0.408472
+0.0255043  0.199736  0.446918
Index: pr_inversion/test/data_error_2.txt
===================================================================
--- pr_inversion/test/data_error_2.txt	(revision b00b487e2e68ed49f8b11454ab513171ef3a634a)
+++ pr_inversion/test/data_error_2.txt	(revision b00b487e2e68ed49f8b11454ab513171ef3a634a)
@@ -0,0 +1,87 @@
+<X>   <Y>   <dY>
+0.00231958  84.0171  0.
+0.00259247  73.6644  0.
+0.00286536  49.8047  7.05724
+0.00313824  34.2893  5.85571
+0.00341113  24.1324  4.91248
+0.00368401  17.1548  4.14184
+0.0039569  12.0308  3.46855
+0.00422978  8.62062  2.93609
+0.00450266  6.40114  2.53005
+0.00477555  4.7518  2.17986
+0.00504842  3.58955  1.89461
+0.0053213  3.0119  1.73548
+0.00559418  2.39727  1.54831
+0.00586705  2.0773  1.44128
+0.00613993  1.65804  1.28765
+0.0064128  1.32639  1.15169
+0.00668567  1.23667  1.11206
+0.00695853  1.06648  1.0327
+0.0072314  0.854762  0.924533
+0.00750426  0.725025  0.851484
+0.00777712  0.636988  0.798115
+0.00804998  0.549  0.740946
+0.00832283  0.527819  0.726512
+0.00859569  0.448613  0.669785
+0.00886854  0.384463  0.620051
+0.00914139  0.36818  0.606778
+0.00941423  0.343939  0.586463
+0.00968707  0.328724  0.573345
+0.00995991  0.281235  0.530316
+0.0102327  0.239363  0.489247
+0.0105056  0.261195  0.511072
+0.0107784  0.241851  0.491783
+0.0110512  0.237327  0.487162
+0.0113241  0.214241  0.462862
+0.0115969  0.186748  0.432143
+0.0118697  0.161051  0.401312
+0.0121425  0.184622  0.429676
+0.0124153  0.168442  0.410417
+0.0126881  0.156892  0.396095
+0.0129609  0.148072  0.384801
+0.0132337  0.147115  0.383556
+0.0135065  0.168421  0.410392
+0.0137793  0.127737  0.357404
+0.0140521  0.128569  0.358565
+0.0143249  0.138782  0.372535
+0.0145977  0.161172  0.401462
+0.0148704  0.117663  0.343021
+0.0151432  0.136941  0.370056
+0.015416  0.149982  0.387275
+0.0156887  0.11796  0.343454
+0.0159615  0.104142  0.32271
+0.0162342  0.11449  0.338363
+0.016507  0.107782  0.328301
+0.0167797  0.126445  0.355591
+0.0170525  0.108571  0.329501
+0.0173252  0.114721  0.338705
+0.0175979  0.100336  0.316758
+0.0178706  0.119656  0.345913
+0.0181433  0.0821055  0.28654
+0.0184161  0.0929812  0.304928
+0.0186888  0.123417  0.351307
+0.0189615  0.0936499  0.306023
+0.0192341  0.104339  0.323015
+0.0195068  0.102485  0.320134
+0.0197795  0.0952812  0.308677
+0.0200522  0.0582846  0.241422
+0.0203249  0.111761  0.334307
+0.0205975  0.0842643  0.290283
+0.0208702  0.10902  0.330182
+0.0211428  0.0663487  0.257583
+0.0214155  0.109861  0.331453
+0.0216881  0.104081  0.322615
+0.0219607  0.084819  0.291237
+0.0222334  0.135506  0.368111
+0.022506  0.117578  0.342897
+0.0227786  0.0973008  0.311931
+0.0230512  0.107357  0.327654
+0.0233238  0.103988  0.322472
+0.0235964  0.0519642  0.227957
+0.023869  0.0703513  0.265238
+0.0241415  0.0653181  0.255574
+0.0244141  0.0094026  0.096967
+0.0246867  0.0754079  0.274605
+0.0249592  0.266365  0.516105
+0.0252318  0.166849  0.408472
+0.0255043  0.199736  0.446918
Index: pr_inversion/test/data_error_3.txt
===================================================================
--- pr_inversion/test/data_error_3.txt	(revision b00b487e2e68ed49f8b11454ab513171ef3a634a)
+++ pr_inversion/test/data_error_3.txt	(revision b00b487e2e68ed49f8b11454ab513171ef3a634a)
@@ -0,0 +1,87 @@
+<X>   <Y>   <dY>
+0.00 84.0171  9.16608
+0.00259247  73.6644  8.5828
+0.00286536  49.8047  7.05724
+0.00313824  34.2893  5.85571
+0.00341113  24.1324  4.91248
+0.00368401  17.1548  4.14184
+0.0039569  12.0308  3.46855
+0.00422978  8.62062  2.93609
+0.00450266  6.40114  2.53005
+0.00477555  4.7518  2.17986
+0.00504842  3.58955  1.89461
+0.0053213  3.0119  1.73548
+0.00559418  2.39727  1.54831
+0.00586705  2.0773  1.44128
+0.00613993  1.65804  1.28765
+0.0064128  1.32639  1.15169
+0.00668567  1.23667  1.11206
+0.00695853  1.06648  1.0327
+0.0072314  0.854762  0.924533
+0.00750426  0.725025  0.851484
+0.00777712  0.636988  0.798115
+0.00804998  0.549  0.740946
+0.00832283  0.527819  0.726512
+0.00859569  0.448613  0.669785
+0.00886854  0.384463  0.620051
+0.00914139  0.36818  0.606778
+0.00941423  0.343939  0.586463
+0.00968707  0.328724  0.573345
+0.00995991  0.281235  0.530316
+0.0102327  0.239363  0.489247
+0.0105056  0.261195  0.511072
+0.0107784  0.241851  0.491783
+0.0110512  0.237327  0.487162
+0.0113241  0.214241  0.462862
+0.0115969  0.186748  0.432143
+0.0118697  0.161051  0.401312
+0.0121425  0.184622  0.429676
+0.0124153  0.168442  0.410417
+0.0126881  0.156892  0.396095
+0.0129609  0.148072  0.384801
+0.0132337  0.147115  0.383556
+0.0135065  0.168421  0.410392
+0.0137793  0.127737  0.357404
+0.0140521  0.128569  0.358565
+0.0143249  0.138782  0.372535
+0.0145977  0.161172  0.401462
+0.0148704  0.117663  0.343021
+0.0151432  0.136941  0.370056
+0.015416  0.149982  0.387275
+0.0156887  0.11796  0.343454
+0.0159615  0.104142  0.32271
+0.0162342  0.11449  0.338363
+0.016507  0.107782  0.328301
+0.0167797  0.126445  0.355591
+0.0170525  0.108571  0.329501
+0.0173252  0.114721  0.338705
+0.0175979  0.100336  0.316758
+0.0178706  0.119656  0.345913
+0.0181433  0.0821055  0.28654
+0.0184161  0.0929812  0.304928
+0.0186888  0.123417  0.351307
+0.0189615  0.0936499  0.306023
+0.0192341  0.104339  0.323015
+0.0195068  0.102485  0.320134
+0.0197795  0.0952812  0.308677
+0.0200522  0.0582846  0.241422
+0.0203249  0.111761  0.334307
+0.0205975  0.0842643  0.290283
+0.0208702  0.10902  0.330182
+0.0211428  0.0663487  0.257583
+0.0214155  0.109861  0.331453
+0.0216881  0.104081  0.322615
+0.0219607  0.084819  0.291237
+0.0222334  0.135506  0.368111
+0.022506  0.117578  0.342897
+0.0227786  0.0973008  0.311931
+0.0230512  0.107357  0.327654
+0.0233238  0.103988  0.322472
+0.0235964  0.0519642  0.227957
+0.023869  0.0703513  0.265238
+0.0241415  0.0653181  0.255574
+0.0244141  0.0094026  0.096967
+0.0246867  0.0754079  0.274605
+0.0249592  0.266365  0.516105
+0.0252318  0.166849  0.408472
+0.0255043  0.199736  0.446918
Index: pr_inversion/test/data_error_4.txt
===================================================================
--- pr_inversion/test/data_error_4.txt	(revision b00b487e2e68ed49f8b11454ab513171ef3a634a)
+++ pr_inversion/test/data_error_4.txt	(revision b00b487e2e68ed49f8b11454ab513171ef3a634a)
@@ -0,0 +1,87 @@
+<X>   <Y>   <dY>
+0.00231958  0.0  -9.16608
+0.00259247  73.6644  -8.5828
+0.00286536  49.8047  -7.05724
+0.00313824  34.2893  5.85571
+0.00341113  24.1324  4.91248
+0.00368401  17.1548  4.14184
+0.0039569  12.0308  3.46855
+0.00422978  8.62062  2.93609
+0.00450266  6.40114  2.53005
+0.00477555  4.7518  2.17986
+0.00504842  3.58955  1.89461
+0.0053213  3.0119  1.73548
+0.00559418  2.39727  1.54831
+0.00586705  2.0773  1.44128
+0.00613993  1.65804  1.28765
+0.0064128  1.32639  1.15169
+0.00668567  1.23667  1.11206
+0.00695853  1.06648  1.0327
+0.0072314  0.854762  0.924533
+0.00750426  0.725025  0.851484
+0.00777712  0.636988  0.798115
+0.00804998  0.549  0.740946
+0.00832283  0.527819  0.726512
+0.00859569  0.448613  0.669785
+0.00886854  0.384463  0.620051
+0.00914139  0.36818  0.606778
+0.00941423  0.343939  0.586463
+0.00968707  0.328724  0.573345
+0.00995991  0.281235  0.530316
+0.0102327  0.239363  0.489247
+0.0105056  0.261195  0.511072
+0.0107784  0.241851  0.491783
+0.0110512  0.237327  0.487162
+0.0113241  0.214241  0.462862
+0.0115969  0.186748  0.432143
+0.0118697  0.161051  0.401312
+0.0121425  0.184622  0.429676
+0.0124153  0.168442  0.410417
+0.0126881  0.156892  0.396095
+0.0129609  0.148072  0.384801
+0.0132337  0.147115  0.383556
+0.0135065  0.168421  0.410392
+0.0137793  0.127737  0.357404
+0.0140521  0.128569  0.358565
+0.0143249  0.138782  0.372535
+0.0145977  0.161172  0.401462
+0.0148704  0.117663  0.343021
+0.0151432  0.136941  0.370056
+0.015416  0.149982  0.387275
+0.0156887  0.11796  0.343454
+0.0159615  0.104142  0.32271
+0.0162342  0.11449  0.338363
+0.016507  0.107782  0.328301
+0.0167797  0.126445  0.355591
+0.0170525  0.108571  0.329501
+0.0173252  0.114721  0.338705
+0.0175979  0.100336  0.316758
+0.0178706  0.119656  0.345913
+0.0181433  0.0821055  0.28654
+0.0184161  0.0929812  0.304928
+0.0186888  0.123417  0.351307
+0.0189615  0.0936499  0.306023
+0.0192341  0.104339  0.323015
+0.0195068  0.102485  0.320134
+0.0197795  0.0952812  0.308677
+0.0200522  0.0582846  0.241422
+0.0203249  0.111761  0.334307
+0.0205975  0.0842643  0.290283
+0.0208702  0.10902  0.330182
+0.0211428  0.0663487  0.257583
+0.0214155  0.109861  0.331453
+0.0216881  0.104081  0.322615
+0.0219607  0.084819  0.291237
+0.0222334  0.135506  0.368111
+0.022506  0.117578  0.342897
+0.0227786  0.0973008  0.311931
+0.0230512  0.107357  0.327654
+0.0233238  0.103988  0.322472
+0.0235964  0.0519642  0.227957
+0.023869  0.0703513  0.265238
+0.0241415  0.0653181  0.255574
+0.0244141  0.0094026  0.096967
+0.0246867  0.0754079  0.274605
+0.0249592  0.266365  0.516105
+0.0252318  0.166849  0.408472
+0.0255043  0.199736  0.446918
Index: pr_inversion/test/data_error_5.txt
===================================================================
--- pr_inversion/test/data_error_5.txt	(revision b00b487e2e68ed49f8b11454ab513171ef3a634a)
+++ pr_inversion/test/data_error_5.txt	(revision b00b487e2e68ed49f8b11454ab513171ef3a634a)
@@ -0,0 +1,87 @@
+<X>   <Y>   <dY>
+-0.00231958  84.0171  -9.16608
+0.00259247  73.6644  -8.5828
+0.00286536  49.8047  -7.05724
+0.00313824  34.2893  5.85571
+0.00341113  24.1324  4.91248
+0.00368401  17.1548  4.14184
+0.0039569  12.0308  3.46855
+0.00422978  8.62062  2.93609
+0.00450266  6.40114  2.53005
+0.00477555  4.7518  2.17986
+0.00504842  3.58955  1.89461
+0.0053213  3.0119  1.73548
+0.00559418  2.39727  1.54831
+0.00586705  2.0773  1.44128
+0.00613993  1.65804  1.28765
+0.0064128  1.32639  1.15169
+0.00668567  1.23667  1.11206
+0.00695853  1.06648  1.0327
+0.0072314  0.854762  0.924533
+0.00750426  0.725025  0.851484
+0.00777712  0.636988  0.798115
+0.00804998  0.549  0.740946
+0.00832283  0.527819  0.726512
+0.00859569  0.448613  0.669785
+0.00886854  0.384463  0.620051
+0.00914139  0.36818  0.606778
+0.00941423  0.343939  0.586463
+0.00968707  0.328724  0.573345
+0.00995991  0.281235  0.530316
+0.0102327  0.239363  0.489247
+0.0105056  0.261195  0.511072
+0.0107784  0.241851  0.491783
+0.0110512  0.237327  0.487162
+0.0113241  0.214241  0.462862
+0.0115969  0.186748  0.432143
+0.0118697  0.161051  0.401312
+0.0121425  0.184622  0.429676
+0.0124153  0.168442  0.410417
+0.0126881  0.156892  0.396095
+0.0129609  0.148072  0.384801
+0.0132337  0.147115  0.383556
+0.0135065  0.168421  0.410392
+0.0137793  0.127737  0.357404
+0.0140521  0.128569  0.358565
+0.0143249  0.138782  0.372535
+0.0145977  0.161172  0.401462
+0.0148704  0.117663  0.343021
+0.0151432  0.136941  0.370056
+0.015416  0.149982  0.387275
+0.0156887  0.11796  0.343454
+0.0159615  0.104142  0.32271
+0.0162342  0.11449  0.338363
+0.016507  0.107782  0.328301
+0.0167797  0.126445  0.355591
+0.0170525  0.108571  0.329501
+0.0173252  0.114721  0.338705
+0.0175979  0.100336  0.316758
+0.0178706  0.119656  0.345913
+0.0181433  0.0821055  0.28654
+0.0184161  0.0929812  0.304928
+0.0186888  0.123417  0.351307
+0.0189615  0.0936499  0.306023
+0.0192341  0.104339  0.323015
+0.0195068  0.102485  0.320134
+0.0197795  0.0952812  0.308677
+0.0200522  0.0582846  0.241422
+0.0203249  0.111761  0.334307
+0.0205975  0.0842643  0.290283
+0.0208702  0.10902  0.330182
+0.0211428  0.0663487  0.257583
+0.0214155  0.109861  0.331453
+0.0216881  0.104081  0.322615
+0.0219607  0.084819  0.291237
+0.0222334  0.135506  0.368111
+0.022506  0.117578  0.342897
+0.0227786  0.0973008  0.311931
+0.0230512  0.107357  0.327654
+0.0233238  0.103988  0.322472
+0.0235964  0.0519642  0.227957
+0.023869  0.0703513  0.265238
+0.0241415  0.0653181  0.255574
+0.0244141  0.0094026  0.096967
+0.0246867  0.0754079  0.274605
+0.0249592  0.266365  0.516105
+0.0252318  0.166849  0.408472
+0.0255043  0.199736  0.446918
Index: pr_inversion/test/data_error_6.txt
===================================================================
--- pr_inversion/test/data_error_6.txt	(revision b00b487e2e68ed49f8b11454ab513171ef3a634a)
+++ pr_inversion/test/data_error_6.txt	(revision b00b487e2e68ed49f8b11454ab513171ef3a634a)
@@ -0,0 +1,87 @@
+<X>   <Y>   <dY>
+0.00231958  -84.0171  -9.16608
+0.00259247  73.6644  -8.5828
+0.00286536  49.8047  -7.05724
+0.00313824  34.2893  5.85571
+0.00341113  24.1324  4.91248
+0.00368401  17.1548  4.14184
+0.0039569  12.0308  3.46855
+0.00422978  8.62062  2.93609
+0.00450266  6.40114  2.53005
+0.00477555  4.7518  2.17986
+0.00504842  3.58955  1.89461
+0.0053213  3.0119  1.73548
+0.00559418  2.39727  1.54831
+0.00586705  2.0773  1.44128
+0.00613993  1.65804  1.28765
+0.0064128  1.32639  1.15169
+0.00668567  1.23667  1.11206
+0.00695853  1.06648  1.0327
+0.0072314  0.854762  0.924533
+0.00750426  0.725025  0.851484
+0.00777712  0.636988  0.798115
+0.00804998  0.549  0.740946
+0.00832283  0.527819  0.726512
+0.00859569  0.448613  0.669785
+0.00886854  0.384463  0.620051
+0.00914139  0.36818  0.606778
+0.00941423  0.343939  0.586463
+0.00968707  0.328724  0.573345
+0.00995991  0.281235  0.530316
+0.0102327  0.239363  0.489247
+0.0105056  0.261195  0.511072
+0.0107784  0.241851  0.491783
+0.0110512  0.237327  0.487162
+0.0113241  0.214241  0.462862
+0.0115969  0.186748  0.432143
+0.0118697  0.161051  0.401312
+0.0121425  0.184622  0.429676
+0.0124153  0.168442  0.410417
+0.0126881  0.156892  0.396095
+0.0129609  0.148072  0.384801
+0.0132337  0.147115  0.383556
+0.0135065  0.168421  0.410392
+0.0137793  0.127737  0.357404
+0.0140521  0.128569  0.358565
+0.0143249  0.138782  0.372535
+0.0145977  0.161172  0.401462
+0.0148704  0.117663  0.343021
+0.0151432  0.136941  0.370056
+0.015416  0.149982  0.387275
+0.0156887  0.11796  0.343454
+0.0159615  0.104142  0.32271
+0.0162342  0.11449  0.338363
+0.016507  0.107782  0.328301
+0.0167797  0.126445  0.355591
+0.0170525  0.108571  0.329501
+0.0173252  0.114721  0.338705
+0.0175979  0.100336  0.316758
+0.0178706  0.119656  0.345913
+0.0181433  0.0821055  0.28654
+0.0184161  0.0929812  0.304928
+0.0186888  0.123417  0.351307
+0.0189615  0.0936499  0.306023
+0.0192341  0.104339  0.323015
+0.0195068  0.102485  0.320134
+0.0197795  0.0952812  0.308677
+0.0200522  0.0582846  0.241422
+0.0203249  0.111761  0.334307
+0.0205975  0.0842643  0.290283
+0.0208702  0.10902  0.330182
+0.0211428  0.0663487  0.257583
+0.0214155  0.109861  0.331453
+0.0216881  0.104081  0.322615
+0.0219607  0.084819  0.291237
+0.0222334  0.135506  0.368111
+0.022506  0.117578  0.342897
+0.0227786  0.0973008  0.311931
+0.0230512  0.107357  0.327654
+0.0233238  0.103988  0.322472
+0.0235964  0.0519642  0.227957
+0.023869  0.0703513  0.265238
+0.0241415  0.0653181  0.255574
+0.0244141  0.0094026  0.096967
+0.0246867  0.0754079  0.274605
+0.0249592  0.266365  0.516105
+0.0252318  0.166849  0.408472
+0.0255043  0.199736  0.446918
Index: pr_inversion/test/test_output.txt
===================================================================
--- pr_inversion/test/test_output.txt	(revision f71287f458148547d69aae7ddc900f1afde663f6)
+++ pr_inversion/test/test_output.txt	(revision b00b487e2e68ed49f8b11454ab513171ef3a634a)
@@ -2,116 +2,116 @@
 #nfunc=10
 #alpha=0.0007
-#chi2=16654.1
+#chi2=836.797
 #elapsed=0
-#alpha_estimate=2.23431
-#C_0=1254.55002508+-12.0889464446
-#C_1=386.59602793+-62.4851961458
-#C_2=5.10066421813+-235.84586924
-#C_3=48.454288318+-1217.94687676
-#C_4=0.4174373785+-213577.449972
-#C_5=17.3551976035+-2673.36274352
-#C_6=-0.228001082457+-692.661759936
-#C_7=1.95934734382+-332.134754291
-#C_8=-0.885447495+-200.862052487
-#C_9=0.401866788245+-137.064680609
+#alpha_estimate=4.58991e-006
+#C_0=217.876478953+-0.0394946442786
+#C_1=0.30164617344+-0.407412922728
+#C_2=7.15694574584+-2.73726481828
+#C_3=-0.79690812244+-5.7183647083
+#C_4=0.948333847403+-16.2086432642
+#C_5=-0.751612279429+-28.2108893047
+#C_6=-0.0796650783501+-52.0568306543
+#C_7=-0.518109559543+-88.6068891309
+#C_8=-0.129910831984+-141.7178308
+#C_9=-0.258134624641+-215.767430098
 <r>  <Pr>  <dPr>
 0  0  0
-1.6  236.371  235.678
-3.2  943.103  930.744
-4.8  2113.12  2049.82
-6.4  3734.86  3535.61
-8  5792.64  5311.37
-9.6  8267.09  7284.04
-11.2  11135.7  9348.1
-12.8  14373.5  11389.7
-14.4  17953.5  13291.4
-16  21847.7  14936.2
-17.6  26027.5  16212.7
-19.2  30464.2  17019.1
-20.8  35129.9  17267.8
-22.4  39997.6  16889.2
-24  45041.7  15836.1
-25.6  50238.2  14088.7
-27.2  55565.1  11662.9
-28.8  61002  8635.92
-30.4  66530.4  5281.73
-32  72133.5  3272.64
-33.6  77796  6067.26
-35.2  83503.6  10814.7
-36.8  89243.2  16028.2
-38.4  95001.9  21350.2
-40  100767  26561.2
-41.6  106527  31468
-43.2  112267  35887.3
-44.8  117975  39646.4
-46.4  123636  42586.2
-48  129233  44565.8
-49.6  134751  45467.6
-51.2  140171  45201.5
-52.8  145473  43709.8
-54.4  150638  40971.1
-56  155645  37005.5
-57.6  160473  31882.9
-59.2  165101  25742.1
-60.8  169508  18857.3
-62.4  173675  11970.1
-64  177583  8265.15
-65.6  181215  12750.9
-67.2  184556  21038.7
-68.8  187595  30104.6
-70.4  190321  39131.5
-72  192727  47705.7
-73.6  194808  55513.2
-75.2  196563  62282.7
-76.8  197991  67775.3
-78.4  199093  71784.5
-80  199873  74140.4
-81.6  200335  74714.1
-83.2  200484  73422.4
-84.8  200325  70232.5
-86.4  199862  65166
-88  199101  58304.9
-89.6  198044  49801.3
-91.2  196695  39903.5
-92.8  195056  29050.8
-94.4  193129  18346.5
-96  190915  12397.7
-97.6  188414  18724.8
-99.2  185629  30770.1
-100.8  182559  43834
-102.4  179206  56683.4
-104  175572  68726.9
-105.6  171661  79534.1
-107.2  167475  88745.8
-108.8  163019  96054.4
-110.4  158298  101203
-112  153320  103987
-113.6  148091  104262
-115.2  142620  101947
-116.8  136919  97026.9
-118.4  130998  89560.4
-120  124872  79680.9
-121.6  118558  67605.7
-123.2  112075  53655.8
-124.8  105448  38339.4
-126.4  98705.1  22821
-128  91877.8  13090.4
-129.6  85003.8  22520.4
-131.2  78125.5  39345.4
-132.8  71289.5  56946.4
-134.4  64546.5  73969.2
-136  57949.9  89741.1
-137.6  51554.5  103751
-139.2  45414.9  115564
-140.8  39583.1  124808
-142.4  34106.6  131176
-144  29025.7  134426
-145.6  24371.3  134390
-147.2  20162.8  130981
-148.8  16406  124194
-150.4  13091.6  114114
-152  10194.5  100912
-153.6  7673.45  84850.4
-155.2  5471.36  66272.7
-156.8  3516.48  45601.3
-158.4  1724.23  23326.7
+1.6  22.981  20.5137
+3.2  91.986  78.6612
+4.8  207.187  164.741
+6.4  368.819  264.129
+8  577.117  359.427
+9.6  832.224  433.162
+11.2  1134.11  470.89
+12.8  1482.46  464.814
+14.4  1876.63  419.086
+16  2315.57  360.693
+17.6  2797.81  353.245
+19.2  3321.46  448.357
+20.8  3884.25  611.481
+22.4  4483.6  786.464
+24  5116.72  934.559
+25.6  5780.7  1030.78
+27.2  6472.66  1062.21
+28.8  7189.82  1030.28
+30.4  7929.59  955.681
+32  8689.7  883.97
+33.6  9468.17  878.871
+35.2  10263.4  977.553
+36.8  11073.9  1152
+38.4  11898.7  1342.59
+40  12737  1498.3
+41.6  13587.7  1587.08
+43.2  14450.2  1596.95
+44.8  15323.5  1537.99
+46.4  16206.5  1445.58
+48  17098  1379.39
+49.6  17996.3  1401.86
+51.2  18899.8  1532.06
+52.8  19806.5  1728.86
+54.4  20714.3  1927.37
+56  21620.8  2073.39
+57.6  22524  2135.21
+59.2  23421.6  2106.97
+60.8  24311.7  2011.28
+62.4  25192.3  1900.75
+64  26061.8  1848.67
+65.6  26918.7  1912.83
+67.2  27761.7  2089.96
+68.8  28589.6  2319.48
+70.4  29401.3  2527.71
+72  30195.6  2658.76
+73.6  30971.4  2685.17
+75.2  31727.2  2611.68
+76.8  32461.5  2478.05
+78.4  33172.7  2357.19
+80  33858.8  2333.81
+81.6  34517.8  2453.43
+83.2  35147.6  2684.61
+84.8  35745.9  2945.13
+86.4  36310.5  3152.18
+88  36839.5  3249.59
+89.6  37330.9  3217.04
+91.2  37783.1  3074.61
+92.8  38194.6  2886.09
+94.4  38564.3  2752.58
+96  38891.1  2773.03
+97.6  39174.1  2973.02
+99.2  39412.6  3281.62
+100.8  39605.8  3587.59
+102.4  39752.6  3795.95
+104  39851.9  3850.56
+105.6  39902.4  3741.32
+107.2  39902.5  3510.03
+108.8  39850.1  3255.58
+110.4  39743.2  3120.25
+112  39579.6  3218.61
+113.6  39356.7  3539.26
+115.2  39072.3  3954.92
+116.8  38724.1  4317.73
+118.4  38310.3  4517.08
+120  37829  4494.86
+121.6  37278.9  4251.44
+123.2  36659  3856.58
+124.8  35968.4  3465.78
+126.4  35206.6  3306.22
+128  34373  3535.97
+129.6  33466.9  4074.35
+131.2  32487.5  4693.64
+132.8  31433.4  5186.14
+134.4  30303.1  5411.6
+136  29094.1  5295.75
+137.6  27803.8  4830.98
+139.2  26428.9  4092.02
+140.8  24965.9  3287.78
+142.4  23411.1  2858.06
+144  21761.3  3246.41
+145.6  20013.4  4237.67
+147.2  18165.4  5345.59
+148.8  16216.4  6256.27
+150.4  14166.9  6786.26
+152  12019  6829.04
+153.6  9776.61  6338.91
+155.2  7445.34  5326.31
+156.8  5032.57  3854
+158.4  2547.22  2030.4
Index: pr_inversion/test/utest_invertor.py
===================================================================
--- pr_inversion/test/utest_invertor.py	(revision ffca8f24855ba4c0e98eab725319c08b887cbc21)
+++ pr_inversion/test/utest_invertor.py	(revision b00b487e2e68ed49f8b11454ab513171ef3a634a)
@@ -224,5 +224,5 @@
         self.invertor.d_max = 160.0
         # Set a small alpha
-        self.invertor.alpha = .0007
+        self.invertor.alpha = .005
         # Set data
         self.invertor.x   = x
@@ -399,6 +399,6 @@
         self.assertEqual(self.invertor.d_max, 160.0)
         self.assertEqual(self.invertor.alpha, 0.0007)
-        self.assertEqual(self.invertor.chi2, 16654.1)
-        self.assertAlmostEqual(self.invertor.pr(self.invertor.out, 10.0), 8948.22689927, 4)
+        self.assertEqual(self.invertor.chi2, 836.797)
+        self.assertAlmostEqual(self.invertor.pr(self.invertor.out, 10.0), 903.31577041, 4)
         
     def test_qmin(self):
@@ -416,4 +416,122 @@
         self.invertor.q_max = None
         self.assertEqual(self.invertor.q_max, None)
+
+class TestErrorConditions(unittest.TestCase):
+    
+    def setUp(self):
+        self.invertor = Invertor()
+        self.invertor.d_max = 100.0
+        
+        # Test array
+        self.ntest = 5
+        self.x_in = numpy.ones(self.ntest)
+        for i in range(self.ntest):
+            self.x_in[i] = 1.0*(i+1)
+
+    def test_negative_errs(self):
+        """
+            Test an inversion for which we know the answer
+        """
+        x, y, err = load("data_error_1.txt")
+
+        # Choose the right d_max...
+        self.invertor.d_max = 160.0
+        # Set a small alpha
+        self.invertor.alpha = .0007
+        # Set data
+        self.invertor.x   = x
+        self.invertor.y   = y
+        self.invertor.err = err
+        # Perform inversion
+        
+        out, cov = self.invertor.lstsq(10)
+         
+    def test_zero_errs(self):
+        """
+            Have zero as an error should raise an exception
+        """
+        x, y, err = load("data_error_2.txt")
+
+        # Set data
+        self.invertor.x   = x
+        self.invertor.y   = y
+        self.invertor.err = err
+        # Perform inversion
+        self.assertRaises(ValueError, self.invertor.invert, 10)
+         
+        
+    def test_invalid(self):
+        """
+            Test an inversion for which we know the answer
+        """
+        x, y, err = load("data_error_1.txt")
+
+        # Set data
+        self.invertor.x   = x
+        self.invertor.y   = y
+        err = numpy.zeros(len(x)-1)
+        self.invertor.err = err
+        # Perform inversion
+        self.assertRaises(RuntimeError, self.invertor.invert, 10)
+         
+        
+    def test_zero_q(self):
+        """
+            One of the q-values is zero.
+            An exception should be raised.
+        """
+        x, y, err = load("data_error_3.txt")
+
+        # Set data
+        self.assertRaises(ValueError, self.invertor.__setattr__, 'x', x)
+        
+    def test_zero_Iq(self):
+        """
+            One of the I(q) points has a value of zero
+            Should not complain or crash.
+        """
+        x, y, err = load("data_error_4.txt")
+
+        # Set data
+        self.invertor.x   = x
+        self.invertor.y   = y
+        self.invertor.err = err
+        # Perform inversion
+        out, cov = self.invertor.lstsq(10)
+    
+    def test_negative_q(self):
+        """
+            One q value is negative.
+            Makes not sense, but should not complain or crash.
+        """
+        x, y, err = load("data_error_5.txt")
+
+        # Set data
+        self.invertor.x   = x
+        self.invertor.y   = y
+        self.invertor.err = err
+        # Perform inversion
+        out, cov = self.invertor.lstsq(10)
+    
+    def test_negative_Iq(self):
+        """
+            One I(q) value is negative.
+            Makes not sense, but should not complain or crash.
+        """
+        x, y, err = load("data_error_6.txt")
+
+        # Set data
+        self.invertor.x   = x
+        self.invertor.y   = y
+        self.invertor.err = err
+        # Perform inversion
+        out, cov = self.invertor.lstsq(10)
+        
+    def test_nodata(self):
+        """
+             No data was loaded. Should not complain.
+        """
+        out, cov = self.invertor.lstsq(10)
+    
 
         
@@ -433,4 +551,5 @@
     data_y   = numpy.zeros(0)
     data_err = numpy.zeros(0)
+    scale    = None
     if not path == None:
         input_f = open(path,'r')
@@ -442,10 +561,13 @@
                 x = float(toks[0])
                 y = float(toks[1])
+                if len(toks)>2:
+                    err = float(toks[2])
+                else:
+                    if scale==None:
+                        scale = 0.15*math.sqrt(y)
+                    err = scale*math.sqrt(y)
                 data_x = numpy.append(data_x, x)
                 data_y = numpy.append(data_y, y)
-                # Set the error of the first point to 5%
-                # to make theory look like data
-                scale = 0.1/math.sqrt(data_x[0])
-                data_err = numpy.append(data_err, scale*math.sqrt(y))
+                data_err = numpy.append(data_err, err)
             except:
                 pass
