changeset 5745:453328597808 octave-forge

address
author cdf
date Wed, 10 Jun 2009 17:26:22 +0000
parents d0db92dff014
children 26d8fad80571
files extra/secs1d/DESCRIPTION extra/secs1d/INDEX extra/secs1d/inst/DDG/DDGelectron_driftdiffusion.m extra/secs1d/inst/DDG/DDGgummelmap.m extra/secs1d/inst/DDG/DDGhole_driftdiffusion.m extra/secs1d/inst/DDG/DDGn2phin.m extra/secs1d/inst/DDG/DDGnlpoisson.m extra/secs1d/inst/DDG/DDGp2phip.m extra/secs1d/inst/DDG/DDGphin2n.m extra/secs1d/inst/DDG/DDGphip2p.m extra/secs1d/inst/DDG/DDGplotresults.m extra/secs1d/inst/DDN/DDNnewtonmap.m extra/secs1d/inst/Utilities/Ubern.m extra/secs1d/inst/Utilities/Ubernoulli.m extra/secs1d/inst/Utilities/Ucompconst.m extra/secs1d/inst/Utilities/Ucomplap.m extra/secs1d/inst/Utilities/Ucompmass.m extra/secs1d/inst/Utilities/Udriftdiffusion.m extra/secs1d/inst/Utilities/Umediaarmonica.m extra/secs1d/inst/Utilities/Uscharfettergummel.m extra/secs1d/inst/Utilities/constants.m extra/secs1d/inst/secs1d_demo_pndiode.m
diffstat 22 files changed, 756 insertions(+), 677 deletions(-) [+]
line wrap: on
line diff
--- a/extra/secs1d/DESCRIPTION	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/DESCRIPTION	Wed Jun 10 17:26:22 2009 +0000
@@ -1,6 +1,6 @@
 Name: SECS1D
-Version: 0.0.8
-Date: 2008-08-23
+Version: 0.0.6
+Date: 2008-04-29
 Author: Carlo de Falco
 Maintainer: Carlo de Falco
 Title: SEmi Conductor Simulator in 1D 
--- a/extra/secs1d/INDEX	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/INDEX	Wed Jun 10 17:26:22 2009 +0000
@@ -21,4 +21,3 @@
  Udriftdiffusion
  Umediaarmonica
  Uscharfettergummel
- secs1d
--- a/extra/secs1d/inst/DDG/DDGelectron_driftdiffusion.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/DDG/DDGelectron_driftdiffusion.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,20 +1,6 @@
-function n=DDGelectron_driftdiffusion(psi,x,ng,p,ni,tn,tp,un)
-  
-% n=DDGelectron_driftdiffusion(psi,x,ng,p)
-%     Solves the continuity equation for electrons
-%     input:  psi   electric potential
-% 	        x     integration domain
-%             ng    initial guess and BCs for electron density
-%             p     hole density (for SRH recombination)
-%     output: n     updated electron density
-  
-## This file is part of 
+## Copyright (C) 2004-2008  Carlo de Falco
 ##
 ## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-## -------------------------------------------------------------------
-## Copyright (C) 2004-2007  Carlo de Falco
-##
-##
 ##
 ##  SECS1D is free software; you can redistribute it and/or modify
 ##  it under the terms of the GNU General Public License as published by
@@ -28,7 +14,32 @@
 ##
 ##  You should have received a copy of the GNU General Public License
 ##  along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
 
+## -*- texinfo -*-
+##
+## @deftypefn {Function File}@
+## {@var{n}} = DDGelectron_driftdiffusion(@var{psi},@var{x},@var{ng},@var{p},@var{ni},@var{tn},@var{tp},@var{un})
+##
+## Solve the continuity equation for electrons
+##
+## Input:
+## @itemize @minus
+## @item psi: electric potential
+## @item x: integration domain
+## @item ng: initial guess and BCs for electron density
+## @item p: hole density (for SRH recombination)
+## @end itemize
+##
+## Output:
+## @itemize @minus
+## @item n: updated electron density
+## @end itemize
+##
+## @end deftypefn
+
+function n = DDGelectron_driftdiffusion(psi,x,ng,p,ni,tn,tp,un)
 
 nodes        = x;
 Nnodes     =length(nodes);
@@ -40,7 +51,6 @@
 
 nl = ng(1);
 nr = ng(Nnodes);
-
 h=nodes(elements(:,2))-nodes(elements(:,1));
 
 c=1./h;
@@ -55,7 +65,7 @@
 A = spdiags([dm1 d0 d1],-1:1,Nnodes,Nnodes);
 b = zeros(Nnodes,1);%- A * ng;
 
-% SRH Recombination term
+  ## SRH Recombination term
 SRHD = tp * (ng + ni) + tn * (p + ni);
 SRHL = p ./ SRHD;
 SRHR = ni.^2 ./ SRHD;
@@ -66,7 +76,7 @@
 A = A + ASRH;
 b = b + bSRH;
 
-% Boundary conditions
+  ## Boundary conditions
 b(Bcnodes)   = [];
 b(1)         = - A(2,1) * nl;
 b(end)       = - A(end-1,end) * nr;
@@ -75,8 +85,5 @@
 
 n = [nl; A\b ;nr];
 
+endfunction
 
-% Last Revision:
-% $Author$
-% $Date$
-
--- a/extra/secs1d/inst/DDG/DDGgummelmap.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/DDG/DDGgummelmap.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,48 +1,6 @@
-function [odata,it,res] =...
-      DDGgummelmap (x,idata,toll,maxit,ptoll,pmaxit,verbose)
-
- 
-%
-% [odata,it,res] =...
-%            DDGgummelmap (x,idata,toll,maxit,ptoll,pmaxit,verbose)
-%
-% Solves the scaled stationary bipolar DD equation system
-%     using Gummel algorithm
-%
-%     input: x          spatial grid
-%            idata.D    doping profile
-%            idata.p    initial guess for hole concentration
-%            idata.n    initial guess for electron concentration
-%            idata.V    initial guess for electrostatic potential
-%            idata.Fn   initial guess for electron Fermi potential
-%            idata.Fp   initial guess for hole Fermi potential
-%            idata.l2   scaled electric permittivity (diffusion coefficient in Poisson equation)
-%            idata.un   scaled electron mobility
-%            idata.up   scaled electron mobility
-%            idata.nis  scaled intrinsic carrier density
-%            idata.tn   scaled electron lifetime
-%            idata.tp   scaled hole lifetime
-%            toll       tolerance for Gummel iterarion convergence test
-%            maxit      maximum number of Gummel iterarions
-%            ptoll      tolerance for Newton iterarion convergence test for non linear Poisson
-%            pmaxit     maximum number of Newton iterarions
-%            verbose    verbosity level: 0,1,2
-%
-%     output: odata.n     electron concentration
-%             odata.p     hole concentration
-%             odata.V     electrostatic potential
-%             odata.Fn    electron Fermi potential
-%             odata.Fp    hole Fermi potential
-%             it          number of Gummel iterations performed
-%             res         total potential increment at each step
-
-## This file is part of 
+## Copyright (C) 2004-2008  Carlo de Falco
 ##
 ## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-## -------------------------------------------------------------------
-## Copyright (C) 2004-2007  Carlo de Falco
-##
-##
 ##
 ##  SECS1D is free software; you can redistribute it and/or modify
 ##  it under the terms of the GNU General Public License as published by
@@ -56,14 +14,60 @@
 ##
 ##  You should have received a copy of the GNU General Public License
 ##  along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
-
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
 
-odata = idata;
+## -*- texinfo -*-
+##
+## @deftypefn {Function File}@
+## {@var{odata},@var{it},@var{res}} =  DDGgummelmap(@var{x},@var{idata},@var{toll},@var{maxit},@var{ptoll},@var{pmaxit},@var{verbose})
+##
+## Solve the scaled stationary bipolar DD equation system using Gummel
+## algorithm
+##
+## Input:
+## @itemize @minus
+## @item x: spatial grid
+## @item idata.D: doping profile
+## @item idata.p: initial guess for hole concentration
+## @item idata.n: initial guess for electron concentration
+## @item idata.V: initial guess for electrostatic potential
+## @item idata.Fn: initial guess for electron Fermi potential
+## @item idata.Fp: initial guess for hole Fermi potential
+## @item idata.l2: scaled electric permittivity (diffusion coefficient in Poisson equation)
+## @item idata.un: scaled electron mobility
+## @item idata.up: scaled electron mobility
+## @item idata.nis: scaled intrinsic carrier density
+## @item idata.tn: scaled electron lifetime
+## @item idata.tp: scaled hole lifetime
+## @item toll: tolerance for Gummel iterarion convergence test
+## @item maxit: maximum number of Gummel iterarions
+## @item ptoll: tolerance for Newton iterarion convergence test for non linear Poisson
+## @item pmaxit: maximum number of Newton iterarions
+## @item verbose: verbosity level (0,1,2)
+## @end itemize
+##
+## Output:
+## @itemize @minus
+## @item odata.n: electron concentration
+## @item odata.p: hole concentration
+## @item odata.V: electrostatic potential
+## @item odata.Fn: electron Fermi potential
+## @item odata.Fp: hole Fermi potential
+## @item it: number of Gummel iterations performed
+## @item res: total potential increment at each step
+## @end itemize
+##
+## @end deftypefn
 
+function [odata,it,res] = DDGgummelmap (x,idata,toll,maxit,ptoll,pmaxit,verbose)
+
+  odata  = idata;
 Nnodes=rows(x);
 
 D         = idata.D;
 vout(:,1) = idata.V;
+
 hole_density (:,1) = idata.p;
 electron_density (:,1)= idata.n;
 fermin (:,1)=idata.Fn;
@@ -71,22 +75,22 @@
 
 for i=1:1:maxit
 	if (verbose>1)
-		fprintf(1,'*****************************************************************\n');  
-		fprintf(1,'****    start of gummel iteration number: %d\n',i);
-		fprintf(1,'*****************************************************************\n');  
-    end
+      fprintf(1,"*****************************************************************\n");  
+      fprintf(1,"****    start of gummel iteration number: %d\n",i);
+      fprintf(1,"*****************************************************************\n");  
+    endif
+    
+    if (verbose>1)
+      fprintf(1,"solving non linear poisson equation\n\n");
+    endif
 
-	if (verbose>1)
-		fprintf(1,'solving non linear poisson equation\n\n');
-    end
-	[vout(:,2),electron_density(:,2),hole_density(:,2)] =...
-	DDGnlpoisson (x,[1:Nnodes],vout (:,1),electron_density(:,1),hole_density(:,1),...
-	fermin(:,1),fermip(:,1),D,idata.l2,ptoll,pmaxit,verbose);
+    [vout(:,2),electron_density(:,2),hole_density(:,2)] =\
+	DDGnlpoisson (x,[1:Nnodes],vout(:,1),electron_density(:,1),hole_density(:,1),fermin(:,1),fermip(:,1),D,idata.l2,ptoll,pmaxit,verbose);
 	
-	if (verbose>1)
-		fprintf (1,'\n\nupdating electron qfl\n\n');
-    end
-	electron_density(:,3)=...
+    if (verbose>1)
+      fprintf (1,"\n\nupdating electron qfl\n\n");
+    endif
+    electron_density(:,3)=\
 	DDGelectron_driftdiffusion(vout(:,2), x, electron_density(:,2),hole_density(:,2),idata.nis,idata.tn,idata.tp,idata.un);
     
     fermin(:,2) = DDGn2phin(vout(:,2),electron_density(:,3));
@@ -94,29 +98,32 @@
     fermin(end:2) = idata.Fn(end);
     
 	if (verbose>1)
-		fprintf(1,'updating hole qfl\n\n');
-    end
+      fprintf(1,"updating hole qfl\n\n");
+    endif
 
-	hole_density(:,3)=...
+    hole_density(:,3) = \
     DDGhole_driftdiffusion(vout(:,2), x, hole_density(:,2),electron_density(:,2),idata.nis,idata.tn,idata.tp,idata.up);
+
     fermip(:,2) = DDGp2phip(vout(:,2),hole_density(:,3));
     fermip(1,2)   = idata.Fp(1);
     fermip(end,2) = idata.Fp(end);
     
     if (verbose>1)
-		fprintf(1,'checking for convergence\n\n');
-    end
+      fprintf(1,"checking for convergence\n\n");
+    endif
+
 	nrfn= norm(fermin(:,2)-fermin(:,1),inf);
 	nrfp= norm (fermip(:,2)-fermip(:,1),inf);
 	nrv = norm (vout(:,2)-vout(:,1),inf);
 	nrm(i) = max([nrfn;nrfp;nrv]);
 	
 	if (verbose>1)
-		fprintf (1,' max(|phin_(k+1)-phinn_(k)| , |phip_(k+1)-phip_(k)| , |v_(k+1)- v_(k)| )= %d\n',nrm(i));
-    end
+      fprintf (1," max(|phin_(k+1)-phinn_(k)| , |phip_(k+1)-phip_(k)| , |v_(k+1)- v_(k)| )= %d\n",nrm(i));
+    endif
+
 	if (nrm(i)<toll)
 		break
-    end
+    endif
 
 	vout(:,1) = vout(:,end);
 	hole_density (:,1) = hole_density (:,end) ;
@@ -127,15 +134,15 @@
 	
 	if(verbose)
 		DDGplotresults(x,electron_density,hole_density,vout,fermin,fermip);		
-    end
-end
+    endif
+  endfor
 
 it = i;
 res = nrm;
 
 if (verbose>0)
-	fprintf(1,'\n\nInitial guess computed by DD: # of Gummel iterations = %d\n\n',it);
-end
+    fprintf(1,"\n\nInitial guess computed by DD: # of Gummel iterations = %d\n\n",it);
+  endif
 
 odata.n     = electron_density(:,end);
 odata.p     = hole_density(:,end);
@@ -143,5 +150,4 @@
 odata.Fn    = fermin(:,end);
 odata.Fp    = fermip(:,end);
 
-
-
+endfunction
\ No newline at end of file
--- a/extra/secs1d/inst/DDG/DDGhole_driftdiffusion.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/DDG/DDGhole_driftdiffusion.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,21 +1,6 @@
-function p=DDGhole_driftdiffusion(psi,x,pg,n,ni,tn,tp,up)
-
-% p=DDGhole_driftdiffusion(psi,x,pg,n)
-%     Solves the continuity equation for holes
-%     input:  psi     electric potential
-%             x       spatial grid
-%             pg      initial guess and BCs for hole density
-%             n       electron density (to compute SRH recombination)
-%     output: p       updated hole density
-
-
-## This file is part of 
+## Copyright (C) 2004-2008  Carlo de Falco
 ##
 ## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-## -------------------------------------------------------------------
-## Copyright (C) 2004-2007  Carlo de Falco
-##
-##
 ##
 ##  SECS1D is free software; you can redistribute it and/or modify
 ##  it under the terms of the GNU General Public License as published by
@@ -29,21 +14,42 @@
 ##
 ##  You should have received a copy of the GNU General Public License
 ##  along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
 
+## -*- texinfo -*-
+##
+## @deftypefn {Function File}@
+## {@var{p}} = DDGhole_driftdiffusio(@var{psi},@var{x},@var{pg},@var{n},@var{ni},@var{tn},@var{tp},@var{up})
+##
+## Solve the continuity equation for holes
+##
+## Input:
+## @itemize @minus
+## @item psi: electric potential
+## @item x: spatial grid
+## @item ng: initial guess and BCs for electron density
+## @item n: electron density (for SRH recombination)
+## @end itemize
+##
+## Output:
+## @itemize @minus
+## @item p: updated hole density
+## @end itemize
+##
+## @end deftypefn
+
+function p = DDGhole_driftdiffusion(psi,x,pg,n,ni,tn,tp,up)
 
 nodes        = x;
 Nnodes     =length(nodes);
-
 elements   = [[1:Nnodes-1]' [2:Nnodes]'];
 Nelements=size(elements,1);
-
 Bcnodes = [1;Nnodes];
 
 pl = pg(1);
 pr = pg(Nnodes);
-
 h=nodes(elements(:,2))-nodes(elements(:,1));
-
 c=up./h;
 Bneg=Ubernoulli(-(psi(2:Nnodes)-psi(1:Nnodes-1)),1);
 Bpos=Ubernoulli( (psi(2:Nnodes)-psi(1:Nnodes-1)),1);
@@ -54,9 +60,9 @@
 dm1   = [-c.* Bpos;1000];
 
 A = spdiags([dm1 d0 d1],-1:1,Nnodes,Nnodes);
-b = zeros(Nnodes,1);% - A * pg;
+  b = zeros(Nnodes,1);## - A * pg;
 
-% SRH Recombination term
+  ## SRH Recombination term
 SRHD = tp * (n + ni) + tn * (pg + ni);
 SRHL = n ./ SRHD;
 SRHR = ni.^2 ./ SRHD;
@@ -67,7 +73,7 @@
 A = A + ASRH;
 b = b + bSRH;
 
-% Boundary conditions
+  ## Boundary conditions
 b(Bcnodes)   = [];
 b(1)         = - A(2,1) * pl;
 b(end)       = - A(end-1,end) * pr;
@@ -76,8 +82,6 @@
 
 p = [pl; A\b ;pr];
 
-% Last Revision:
-% $Author$
-% $Date$
+endfunction
 
 
--- a/extra/secs1d/inst/DDG/DDGn2phin.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/DDG/DDGn2phin.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,16 +1,6 @@
-function phin = DDGn2phin (V,n);
-
-% phin = DDGn2phin (V,n);
-%         computes the qfl for electrons using Maxwell-Boltzmann
-%         statistics.
-
-## This file is part of 
+## Copyright (C) 2004-2008  Carlo de Falco
 ##
 ## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-## -------------------------------------------------------------------
-## Copyright (C) 2004-2007  Carlo de Falco
-##
-##
 ##
 ##  SECS1D is free software; you can redistribute it and/or modify
 ##  it under the terms of the GNU General Public License as published by
@@ -24,15 +14,23 @@
 ##
 ##  You should have received a copy of the GNU General Public License
 ##  along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
-  
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
   
-% load constants
-nmin = 0;
+## -*- texinfo -*-
+##
+## @deftypefn {Function File}@
+## {@var{phin}} = DDGn2phin(@var{V},@var{n})
+##
+## Compute the qfl for electrons using Maxwell-Boltzmann statistics.
+##
+## @end deftypefn
+  
+function phin = DDGn2phin (V,n);
 
+  ## Load constants
+  nmin = 0;
 n    = n .* (n>nmin) + nmin * (n<=nmin); 
 phin = V - log(n) ;
 
-
-% Last Revision:
-% $Author$
-% $Date$
+endfunction
--- a/extra/secs1d/inst/DDG/DDGnlpoisson.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/DDG/DDGnlpoisson.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,37 +1,6 @@
-function [V,n,p,res,niter] = DDGnlpoisson (x,sinodes,Vin,nin,...
-					   pin,Fnin,Fpin,D,l2,toll,maxit,verbose)
-
-% [V,n,p,res,niter] = DDGnlpoisson (x,sinodes,Vin,nin,...
-%             pin,Fnin,Fpin,D,l2,toll,maxit,verbose)
-%     Solves the non linear Poisson equation
-%     $$ - lamda^2 *V'' + (n(V,Fn) - p(V,Fp) -D)=0 $$
-%     input:  x       spatial grid
-%             sinodes index of the nodes of the grid which are in the
-%                     semiconductor subdomain 
-%                     (remaining nodes are assumed to be in the oxide subdomain)
-%             Vin     initial guess for the electrostatic potential
-%             nin     initial guess for electron concentration
-%             pin     initial guess for hole concentration
-%             Fnin    initial guess for electron Fermi potential
-%             Fpin    initial guess for hole Fermi potential
-%             D       doping profile
-%             l2      scaled electric permittivity (diffusion coefficient)
-%             toll    tolerance for convergence test
-%             maxit   maximum number of Newton iterations
-%             verbose verbosity level: 0,1,2
-%     output: V       electrostatic potential
-%             n       electron concentration
-%             p       hole concentration
-%             res     residual norm at each step
-%             niter   number of Newton iterations
-
-## This file is part of 
+## Copyright (C) 2004-2008  Carlo de Falco
 ##
 ## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-## -------------------------------------------------------------------
-## Copyright (C) 2004-2007  Carlo de Falco
-##
-##
 ##
 ##  SECS1D is free software; you can redistribute it and/or modify
 ##  it under the terms of the GNU General Public License as published by
@@ -45,41 +14,64 @@
 ##
 ##  You should have received a copy of the GNU General Public License
 ##  along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
-
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
 
-%% Set some useful constants
+## -*- texinfo -*-
+##
+## @deftypefn {Function File}@
+## {@var{V},@var{n},@var{p},@var{res},@var{niter}} = @
+## DDGnlpoisson(@var{x},@var{sinodes},@var{Vin},@var{nin},@var{pin},@var{Fnin},@var{Fpin},@var{D},@var{l2},@var{toll},@var{maxit},@var{verbose})
+##
+## Solve the non linear Poisson equation
+## 
+## - lamda^2 *V'' + (n(V,Fn) - p(V,Fp) -D) = 0 
+##
+## Input:
+## @itemize @minus
+## @item x: spatial grid
+## @item sinodes: index of the nodes of the grid which are in the
+## semiconductor subdomain (remaining nodes are assumed to be in the oxide subdomain)
+## @item Vin: initial guess for the electrostatic potential
+## @item nin: initial guess for electron concentration
+## @item pin: initial guess for hole concentration
+## @item Fnin: initial guess for electron Fermi potential
+## @item Fpin: initial guess for hole Fermi potential
+## @item D: doping profile
+## @item l2: scaled electric permittivity (diffusion coefficient)
+## @item toll: tolerance for convergence test
+## @item maxit: maximum number of Newton iterations
+## @item verbose: verbosity level (0,1,2)
+## @end itemize
+##
+## Output:
+## @itemize @minus
+## @item V: electrostatic potential
+## @item n: electron concentration
+## @item p: hole concentration
+## @item res: residual norm at each step
+## @item niter: number of Newton iterations
+## @end itemize
+##
+## @end deftypefn
+
+function [V,n,p,res,niter] = DDGnlpoisson (x,sinodes,Vin,nin,pin,Fnin,Fpin,D,l2,toll,maxit,verbose)
+
+  ## Set some useful constants
 dampit 		= 10;
 dampcoeff	= 2;
 
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% convert grid info to FEM form
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
+  ## Convert grid info to FEM form
 Ndiricheletnodes 	= 2;
 nodes 		        = x;
 sielements          = sinodes(1:end-1);
-
 Nnodes		        = length(nodes);
-
-
 totdofs             = Nnodes - Ndiricheletnodes ;
-
 elements            = [[1:Nnodes-1]' , [2:Nnodes]'];
 Nelements           = size(elements,1);
-
 BCnodes             = [1;Nnodes];
 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%
-%% 		initialization:
-%% 		we're going to solve
-%% 		$$ -  lamda^2*(\delta V)'' +  (\frac{\partial n}{\partial V} -
-%%            \frac{\partial p}{\partial V})= -R $$
-%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%% set $$ n_1 = nin $$ and $$ V = Vin $$
+  ## Initialization
 V = Vin;
 Fn = Fnin;
 Fp = Fpin;
@@ -88,168 +80,133 @@
 if (sinodes(1)==1)
     n(1)=nin(1);
     p(1)=pin(1);
-end
+  endif
 if (sinodes(end)==Nnodes)
     n(end)=nin(end);
     p(end)=pin(end);
-end
+  endif
 
-%%%
-%%% Compute LHS matrices
-%%%
-
-%% let's compute  FEM approximation of $$ L = -  \frac{d^2}{x^2} $$
+  ## Compute LHS matrices
 L      = Ucomplap (nodes,Nnodes,elements,Nelements,l2.*ones(Nelements,1));
 
-%% compute $$ Mv =  ( n + p)  $$
-%% and the (lumped) mass matrix M
+  ## Compute Mv =  ( n + p)
 Mv            =  zeros(Nnodes,1);
 Mv(sinodes)   =  (n + p);
 Cv            =  zeros(Nelements,1);
 Cv(sielements)=  1;
 M             =  Ucompmass (nodes,Nnodes,elements,Nelements,Mv,Cv);
 
-%%%
-%%% Compute RHS vector (-residual)
-%%%
-
-%% now compute $$ T0 =  (n - p - D) $$
+  ## Compute RHS vector
 Tv0            =  zeros(Nnodes,1);
 Tv0(sinodes)   = (n - p - D);
 Cv            =  zeros(Nelements,1);
 Cv(sielements)=  1;
 T0             =  Ucompconst (nodes,Nnodes,elements,Nelements,Tv0,Cv);
 
-%% now we're ready to build LHS matrix and RHS of the linear system for 1st Newton step
+  ## Build LHS matrix and RHS of the linear system for 1st Newton step
 A 		= L + M;
 R 		= L * V  + T0; 
 
-%% Apply boundary conditions
+  ## Apply boundary conditions
 A(BCnodes,:)	= [];
 A(:,BCnodes)	= [];
-
 R(BCnodes)	= [];
 
-%% we need $$ \norm{R_1} $$ and $$ \norm{R_k} $$ for the convergence test   
+
 normr(1)		=  norm(R,inf);
 relresnorm 	= 1;
 reldVnorm   = 1;
 normrnew	= normr(1);
 
 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%
-%% START OF THE NEWTON CYCLE
-%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+  ## Start of the newton cycle
 for newtit=1:maxit
     if verbose
-        fprintf(1,'\n newton iteration: %d, reldVnorm = %e',newtit,reldVnorm);
-        
-    end
-
+        fprintf(1,"\n newton iteration: %d, reldVnorm = %e",newtit,reldVnorm);
+    endif
     dV =[0;(A)\(-R);0];
     
-    
-    
-    %%%%%%%%%%%%%%%%%%
-    %% Start of the damping procedure
-    %%%%%%%%%%%%%%%%%%
+    ## Start of the damping procedure
     tk = 1;
     for dit = 1:dampit
         if verbose
-            fprintf(1,'\n damping iteration: %d, residual norm = %e',dit,normrnew);
-        end
+        fprintf(1,"\n damping iteration: %d, residual norm = %e",dit,normrnew);
+      endif
         Vnew   = V + tk * dV;
-        
         n = DDGphin2n(Vnew(sinodes),Fn);
         p = DDGphip2p(Vnew(sinodes),Fp);
         if (sinodes(1)==1)
             n(1)=nin(1);
             p(1)=pin(1);
-        end
+      endif
         if (sinodes(end)==Nnodes)
             n(end)=nin(end);
             p(end)=pin(end);
-        end
-        %%%
-        %%% Compute LHS matrices
-        %%%
+      endif
         
-        %% let's compute  FEM approximation of $$ L = -  \frac{d^2}{x^2} $$
-        %L      = Ucomplap (nodes,Nnodes,elements,Nelements,ones(Nelements,1));
-        
-        %% compute $$ Mv =  ( n + p)  $$
-        %% and the (lumped) mass matrix M
+      ## Compute LHS matrices
         Mv            =  zeros(Nnodes,1);
         Mv(sinodes)   =  (n + p);
         Cv            =  zeros(Nelements,1);
         Cv(sielements)=  1;        
         M    = Ucompmass (nodes,Nnodes,elements,Nelements,Mv,Cv);
         
-        %%%
-        %%% Compute RHS vector (-residual)
-        %%%
-        
-        %% now compute $$ T0 =  (n - p - D) $$
+      ## Compute RHS vector (-residual)
         Tv0            =  zeros(Nnodes,1);
         Tv0(sinodes)   =  (n - p - D);
         Cv            =  zeros(Nelements,1);
         Cv(sielements)=  1;
         T0     = Ucompconst (nodes,Nnodes,elements,Nelements,Tv0,Cv);
         
-        %% now we're ready to build LHS matrix and RHS of the linear system for 1st Newton step
+      ## Build LHS matrix and RHS of the linear system for 1st Newton step
         Anew 		= L + M;
         Rnew 		= L * Vnew  + T0; 
         
-        %% Apply boundary conditions
+      ## Apply boundary conditions
         Anew(BCnodes,:)	= [];
         Anew(:,BCnodes)	= [];
-        
         Rnew(BCnodes)	= [];
         
         if ((dit>1)&(norm(Rnew,inf)>=norm(R,inf)))
             if verbose
-                fprintf(1,'\nexiting damping cycle \n');
-            end
+          fprintf(1,"\nexiting damping cycle \n");
+        endif
             break
         else
             A = Anew;
             R = Rnew;
-        end
+      endif
     
-        %% compute $$ | R_{k+1} | $$ for the convergence test
+      ## Compute | R_{k+1} | for the convergence test
         normrnew= norm(R,inf);
         
-        % check if more damping is needed
+      ## Check if more damping is needed
         if (normrnew > normr(newtit))
             tk = tk/dampcoeff;
         else
             if verbose
-                fprintf(1,'\nexiting damping cycle because residual norm = %e \n',normrnew);
-            end		
+          fprintf(1,"\nexiting damping cycle because residual norm = %e \n",normrnew);
+        endif		
             break
-        end	
-    end
+      endif	
+    endfor
 
     V		            = Vnew;	
     normr(newtit+1) 	= normrnew;
     dVnorm              = norm(tk*dV,inf);
-    % check if convergence has been reached
+
+    ## Check if convergence has been reached
     reldVnorm           = dVnorm / norm(V,inf);
     if (reldVnorm <= toll)
         if(verbose)
-            fprintf(1,'\nexiting newton cycle because reldVnorm= %e \n',reldVnorm);
-        end
+        fprintf(1,"\nexiting newton cycle because reldVnorm= %e \n",reldVnorm);
+      endif
         break
-    end
-end
+    endif
+
+  endfor
 
 res = normr;
 niter = newtit;
 
-% Last Revision:
-% $Author$
-% $Date$
-
-
+endfunction
\ No newline at end of file
--- a/extra/secs1d/inst/DDG/DDGp2phip.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/DDG/DDGp2phip.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,38 +1,36 @@
+## Copyright (C) 2004-2008  Carlo de Falco
+##
+## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
+##
+## SECS1D is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## SECS1D is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
+
+## -*- texinfo -*-
+##
+## @deftypefn {Function File}@
+## {@var{phip}} = DDGn2phin(@var{V},@var{p})
+##
+## Compute the qfl for holes using Maxwell-Boltzmann statistics
+##
+## @end deftypefn
+  
 function phip = DDGp2phip (V,p);
 
-% phip = DDGp2phip (V,p);
-% computes the qfl for holes using Maxwell-Boltzmann statistics
- 
-% This file is part of 
-%
-%            MNME1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-%         -------------------------------------------------------------------
-%            Copyright (C) 2004  Carlo de Falco
-%
-%
-%
-%  MNME1D is free software; you can redistribute it and/or modify
-%  it under the terms of the GNU General Public License as published by
-%  the Free Software Foundation; either version 2 of the License, or
-%  (at your option) any later version.
-%
-%  MNME1D is distributed in the hope that it will be useful,
-%  but WITHOUT ANY WARRANTY; without even the implied warranty of
-%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-%  GNU General Public License for more details.
-%
-%  You should have received a copy of the GNU General Public License
-%  along with MNME1D; If not, see <http://www.gnu.org/licenses/>.
- 
-  
-% load constants
-
+  ## Load constants
   pmin = 0;
-    
   p    = p .* (p>pmin) + pmin * (p<=pmin);
   phip = V + log(p) ;
   
-
-  % Last Revision:
-  % $Author$
-  % $Date$
+endfunction
--- a/extra/secs1d/inst/DDG/DDGphin2n.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/DDG/DDGphin2n.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,17 +1,6 @@
-function n = DDGphin2n (V,phin);
-
-% n = DDGphin2n (V,phin);
-%         computes the electron density using Maxwell-Boltzmann
-%         statistics.
-
-
-## This file is part of 
+## Copyright (C) 2004-2008  Carlo de Falco
 ##
 ## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-## -------------------------------------------------------------------
-## Copyright (C) 2004-2007  Carlo de Falco
-##
-##
 ##
 ##  SECS1D is free software; you can redistribute it and/or modify
 ##  it under the terms of the GNU General Public License as published by
@@ -25,12 +14,22 @@
 ##
 ##  You should have received a copy of the GNU General Public License
 ##  along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
+
+## -*- texinfo -*-
+##
+## @deftypefn {Function File}@
+## {@var{n}} = DDGphin2n(@var{V},@var{phin})
+##
+## Compute the electron density using Maxwell-Boltzmann statistics
+##
+## @end deftypefn
   
+function n = DDGphin2n (V,phin);
   
   nmin = 0;
   n =  exp ((V-phin));
   n = n .* (n>nmin) + nmin * (n<=nmin);
 
-  % Last Revision:
-  % $Author$
-  % $Date$
+endfunction
--- a/extra/secs1d/inst/DDG/DDGphip2p.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/DDG/DDGphip2p.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,16 +1,6 @@
-function p = DDGphip2p (V,phip);
-
-% p = DDGphip2p (V,phip);
-%         computes the hole density using Maxwell-Boltzmann
-%         statistics.
-
-## This file is part of 
+## Copyright (C) 2004-2008  Carlo de Falco
 ##
 ## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-## -------------------------------------------------------------------
-## Copyright (C) 2004-2007  Carlo de Falco
-##
-##
 ##
 ##  SECS1D is free software; you can redistribute it and/or modify
 ##  it under the terms of the GNU General Public License as published by
@@ -24,16 +14,23 @@
 ##
 ##  You should have received a copy of the GNU General Public License
 ##  along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
-  
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
   
-%  load constants
+## -*- texinfo -*-
+##
+## @deftypefn {Function File}@
+## {@var{p}} = DDGphip2p(@var{V},@var{phip})
+##
+## Compute the hole density using Maxwell-Boltzmann statistic
+##
+## @end deftypefn
+  
+function p = DDGphip2p (V,phip);
 
-
+## Load constants
 pmin = 0;
-
 p = exp ((phip-V));
 p = p .* (p>pmin) + pmin * (p<=pmin);
 
-% Last Revision:
-% $Author$
-% $Date$
+endfunction
--- a/extra/secs1d/inst/DDG/DDGplotresults.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/DDG/DDGplotresults.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,14 +1,6 @@
-function DDGplotresults(x,n,p,V,Fn,Fp);
-
-% DDGplotresults(x,n,p,V,Fn,Fp);
-
-## This file is part of 
+## Copyright (C) 2004-2008  Carlo de Falco
 ##
 ## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-## -------------------------------------------------------------------
-## Copyright (C) 2004-2007  Carlo de Falco
-##
-##
 ##
 ##  SECS1D is free software; you can redistribute it and/or modify
 ##  it under the terms of the GNU General Public License as published by
@@ -22,32 +14,39 @@
 ##
 ##  You should have received a copy of the GNU General Public License
 ##  along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
+
+## -*- texinfo -*-
+##
+## @deftypefn {Function File}@
+## DDGplotresults(@var{x},@var{n},@var{p},@var{V},@var{Fn},@var{Fp})
+##
+## Plot densities and potentials
+##
+## @end deftypefn
+
+function DDGplotresults(x,n,p,V,Fn,Fp);
   
 subplot(2,3,1)
 title('Electron Density')
 semilogy(x,n)
 
-
 subplot(2,3,2)
 title('Hole Density')
 semilogy(x,p)
 
-
 subplot(2,3,4)
 title('Electron QFL')
 plot(x,Fn)
 
-
 subplot(2,3,5)
 title('Hole QFL')
 plot(x,Fp)
 
-
 subplot(2,3,6)
 title('Electric Potential')
 plot(x,V)
 pause(.1)
 
-% Last Revision:
-% $Author$
-% $Date$
+endfunction
--- a/extra/secs1d/inst/DDN/DDNnewtonmap.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/DDN/DDNnewtonmap.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,43 +1,6 @@
-function [odata,it,res] = DDNnewtonmap (x,idata,toll,maxit,verbose)
-
-%
-% [odata,it,res] = DDNnewtonmap (x,idata,toll,maxit,verbose)
-%
-%     Solves the scaled stationary bipolar DD equation system
-%     using a coupled Newton algorithm
-%
-%     input: x              spatial grid
-%            idata.D        doping profile
-%            idata.p        initial guess for hole concentration
-%            idata.n        initial guess for electron concentration
-%            idata.V        initial guess for electrostatic potential
-%            idata.Fn       initial guess for electron Fermi potential
-%            idata.Fp       initial guess for hole Fermi potential
-%            idata.l2       scaled electric permittivity (diffusion coefficient in Poisson equation)
-%            idata.un       scaled electron mobility
-%            idata.up       scaled electron mobility
-%            idata.nis      scaled intrinsic carrier density
-%            idata.tn       scaled electron lifetime
-%            idata.tp       scaled hole lifetime
-%            toll           tolerance for Newton iterarion convergence test
-%            maxit          maximum number of Newton iterarions
-%            verbose        verbosity level: 0,1,2
-%
-%     output: odata.n     electron concentration
-%             odata.p     hole concentration
-%             odata.V     electrostatic potential
-%             odata.Fn    electron Fermi potential
-%             odata.Fp    hole Fermi potential
-%             it          number of Newton iterations performed
-%             res         residual at each step         
-    
-## This file is part of 
+## Copyright (C) 2004-2008  Carlo de Falco
 ##
 ## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-## -------------------------------------------------------------------
-## Copyright (C) 2004-2007  Carlo de Falco
-##
-##
 ##
 ##  SECS1D is free software; you can redistribute it and/or modify
 ##  it under the terms of the GNU General Public License as published by
@@ -51,11 +14,54 @@
 ##
 ##  You should have received a copy of the GNU General Public License
 ##  along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
-
-odata = idata;
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
 
-Nnodes=rows(x);
+## -*- texinfo -*-
+##
+## @deftypefn {Function File}@
+## {@var{odata},@var{it},@var{res}} = DDNnewtonmap(@var{x},@var{idata},@var{toll},@var{maxit},@var{verbose})
+##
+## Solve the scaled stationary bipolar DD equation system using a
+## coupled Newton algorithm
+##
+## Input:
+## @itemize @minus
+## @item x: spatial grid
+## @item idata.D: doping profile
+## @item idata.p: initial guess for hole concentration
+## @item idata.n: initial guess for electron concentration
+## @item idata.V: initial guess for electrostatic potential
+## @item idata.Fn: initial guess for electron Fermi potential
+## @item idata.Fp: initial guess for hole Fermi potential
+## @item idata.l2: scaled electric permittivity (diffusion coefficient in Poisson equation)
+## @item idata.un: scaled electron mobility
+## @item idata.up: scaled electron mobility
+## @item idata.nis: scaled intrinsic carrier density
+## @item idata.tn: scaled electron lifetime
+## @item idata.tp: scaled hole lifetime
+## @item toll: tolerance for Newton iterarion convergence test
+## @item maxit: maximum number of Newton iterarions
+## @item verbose: verbosity level: 0,1,2
+## @end itemize
+##
+## Output:
+## @itemize @minus
+## @item odata.n: electron concentration
+## @item odata.p: hole concentration
+## @item odata.V: electrostatic potential
+## @item odata.Fn: electron Fermi potential
+## @item odata.Fp: hole Fermi potential
+## @item it: number of Newton iterations performed
+## @item res: residual at each step
+## @end itemize
+##
+## @end deftypefn
 
+function [odata,it,res] = DDNnewtonmap (x,idata,toll,maxit,verbose)
+
+  odata     = idata;
+  Nnodes    = rows(x);
 Nelements=Nnodes-1;
 elements=[1:Nnodes-1;2:Nnodes]';
 BCnodesp = [1,Nnodes];
@@ -69,48 +75,31 @@
 p = idata.p;
 D = idata.D;
 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% create the complete unknown vector
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+  ## Create the complete unknown vector
 u = [V; n; p];
 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% build fem matrices
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
+  ## Build fem matrices
 L = Ucomplap (x,Nnodes,elements,Nelements,idata.l2*ones(Nelements,1));
 M = Ucompmass (x,Nnodes,elements,Nelements,ones(Nnodes,1),ones(Nelements,1));
 DDn = Uscharfettergummel(x,Nnodes,elements,Nelements,idata.un,1,V);
 DDp = Uscharfettergummel(x,Nnodes,elements,Nelements,idata.up,1,-V);
 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% Initialise RHS 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+  ## Initialise RHS 
 r1  = L * V + M * (n - p - D); 
 r2  = DDn * n;
 r3  = DDp * p;
+  RHS = - [ r1; r2; r3 ];
 
-RHS =- [...
-r1;
-r2;
-r3
-];
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%  Apply BCs
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+  ##  Apply BCs
 RHS(BCnodes,:)= [];
-
 nrm = norm(RHS,inf);
 res(1) = nrm;
 
-%%%%%%%%%%%%%%%%%%%%%%%
-%% Begin Newton Cycle
-%%%%%%%%%%%%%%%%%%%%%%%
+  ## Begin Newton Cycle
 for count = 1: maxit
   if verbose
-    fprintf (1,'\n\n\nNewton Iteration Number:%d\n',count);	
-  end
+      fprintf (1,"\n\n\nNewton Iteration Number:%d\n",count);	
+    endif
     Ln = Ucomplap (x,Nnodes,elements,Nelements,Umediaarmonica(idata.un*n));
     Lp = Ucomplap (x,Nnodes,elements,Nelements,Umediaarmonica(idata.up*p));
     Z  = sparse(zeros(Nnodes));    
@@ -127,40 +116,32 @@
     H	= Z;
     I	= DDp;
     
-    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-    %% Build LHS
-    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+    ## Build LHS
     LHS =sparse([
 	[A	B C];
 	[DDD    E F];
 	[G      H I];
     ]);
     
-    %Apply BCs
+    ## Apply BCs
     LHS(BCnodes,:)=[];    
     LHS(:,BCnodes)=[];
     
-    %%%%%%%%%%%%%%%%%%%%%%%
-    % Solve the linearised system
-    %%%%%%%%%%%%%%%%%%%%%%%
+    ## Solve the linearised system
     dutmp = (LHS) \ (RHS);
     dv    = dutmp(1:totaldofs);
     dn    = dutmp(totaldofs+1:2*totaldofs);
     dp    = dutmp(2*totaldofs+1:3*totaldofs);
     du    = [0;dv;0;0;dn;0;0;dp;0];
     
-    %%%%%%%%%%%%%%%%%%%%%%%
-    %% Check Convergence
-    %%%%%%%%%%%%%%%%%%%%%%%
-    
+    ## Check Convergence
     nrm_u = norm(u,inf);
-	
     nrm_du = norm(du,inf);
 	
     ratio = nrm_du/nrm_u; 
     if verbose
-      fprintf (1,'ratio = %e\n', ratio);		
-    end
+      fprintf (1,"ratio = %e\n", ratio);		
+    endif
     
     if (ratio <= toll)
         V 	    = u(1:Nnodes);
@@ -168,31 +149,22 @@
         p	    = u(2*Nnodes+1:end);
         res(count)  = nrm;
         break;
-    end
-
+    endif
 
-    %%%%%%%%%%%%%%%%%%%%%%
-    %% begin damping cycle
-    %%%%%%%%%%%%%%%%%%%%%%
+    ## Begin damping cycle
     tj = 1;
     
-	
     for cc = 1:maxdamp
       if verbose
-        fprintf (1,'\ndamping iteration number:%d\n',cc);
-        fprintf (1,'reference residual norm:%e\n',nrm);
-      end
-        %%%%%%%%%%%%%%%%%%%%%%%%%
-        %	Update the unknown vector		
-        %%%%%%%%%%%%%%%%%%%%%%%%%
+        fprintf (1,"\ndamping iteration number:%d\n",cc);
+        fprintf (1,"reference residual norm:%e\n",nrm);
+      endif
+      ## Update the unknown vector		
         utmp    = u + tj*du;
         Vnew 	    = utmp(1:Nnodes);
         nnew	    = utmp(Nnodes+1:2*Nnodes);
         pnew	    = utmp(2*Nnodes+1:end);
-        
-        %%%%%%%%%%%%%%%%%
-        %% try a new RHS
-        %%%%%%%%%%%%%%%%
+      ## Try a new RHS
         DDn = Uscharfettergummel(x,Nnodes,elements,Nelements,idata.un,1,Vnew);
         DDp = Uscharfettergummel(x,Nnodes,elements,Nelements,idata.up,1,-Vnew);
         
@@ -200,38 +172,28 @@
         r2  = DDn * nnew;
         r3  = DDp * pnew;
         
-        RHS =- [...
-        r1;
-        r2;
-        r3
-        ];
+      RHS =- [r1;r2;r3];
         
-        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-        %  Apply BCs
-        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-        RHS(BCnodes,:)= [];
-        
+      ## Apply BCs
+      RHS(BCnodes,:) = [];
         nrmtmp=norm(RHS,inf);
         
-        %%%%%%%%%%%%%%%%%%%%%%%%%
-        %% Update the damping coefficient
-        %%%%%%%%%%%%%%%%%%%%%%%%
+      ## Update the damping coefficient
         if verbose
-	  fprintf(1,'residual norm:%e\n\n', nrmtmp);
-        end
+	fprintf(1,"residual norm:%e\n\n", nrmtmp);
+      endif
         
 		if (nrmtmp>nrm)
 			tj = tj/(dampcoef*cc);
 			if verbose
-			  fprintf (1,'\ndamping coefficients = %e',tj);    
-			end
+	  fprintf (1,"\ndamping coefficients = %e",tj);    
+	endif
         else
 			break;
-        end
-    end
+      endif
+    endfor
 
     nrm_du = norm(tj*du,inf);
-	
     u 	= utmp;
     
     if (count>1)
@@ -242,30 +204,26 @@
             p	    = u(2*Nnodes+1:end);            
             res(count)  = nrm;
             break;           
-        end
-    end
-
+      endif
+    endif
     nrm = nrmtmp;
-    
     res(count)  = nrm;
-    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-    %% convert result vector into distinct output vectors 
-    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 	
+    ## Convert result vector into distinct output vectors 
     V 	    = u(1:Nnodes);
     n	    = u(Nnodes+1:2*Nnodes);
     p	    = u(2*Nnodes+1:end);    
-    
     nrm_du_old = nrm_du;
-end
+  endfor
 
 odata.V = V;
 odata.n = n;
 odata.p = p;
 Fn   = V - log(n);
 Fp   = V + log(p);
+it   = count; 
 
-it   = count; 
+endfunction
 
 
 
--- a/extra/secs1d/inst/Utilities/Ubern.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/Utilities/Ubern.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,19 +1,6 @@
-function [bp,bn]=Ubern(x)
-
-% [bp,bn]=Ubern(x)
-%
-% Bernoulli function
-% bp = B(x)=x/(exp(x)-1)
-% bn = B(-x)=x+B(x)
-
-
- ## This file is part of 
+## Copyright (C) 2004-2008  Carlo de Falco
   ##
   ## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-  ## -------------------------------------------------------------------
-  ## Copyright (C) 2004-2007  Carlo de Falco
-  ##
-  ##
   ##
   ##  SECS1D is free software; you can redistribute it and/or modify
   ##  it under the terms of the GNU General Public License as published by
@@ -27,28 +14,39 @@
   ##
   ##  You should have received a copy of the GNU General Public License
   ##  along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
 
+## -*- texinfo -*-
+##
+## @deftypefn {Function File} {@var{bp},@var{bn}} = Ubern(@var{x})
+##
+## Compute Bernoulli function for scalar x:
+##
+## @itemize @minus
+## @item @var{bp} = @var{x}/(exp(@var{x})-1)
+## @item @var{bn} = @var{x} + B( @var{x} )
+## @end itemize
+##
+## @end deftypefn
+
+function [bp,bn] = Ubern(x)
      
 xlim=1e-2;
 ax=abs(x);
 
-%
-% Calcola la funz. di Bernoulli per x=0
-%
+  ## Compute Bernoulli function for x = 0
 
 if (ax == 0)
    bp=1.;
    bn=1.;
    return
-end;
+  endif
 
-%
-% Calcola la funz. di Bernoulli per valori
-% asintotici dell'argomento
-%
+  ## Compute Bernoulli function for asymptotic values
 
-if (ax > 80),
-   if (x >0),
+  if (ax > 80)
+    if (x > 0)
       bp=0.;
       bn=x;
       return
@@ -56,25 +54,19 @@
       bp=-x;
       bn=0.;
       return
-   end;
-end;
+    endif
+  endif
 
-%
-% Calcola la funz. di Bernoulli per valori
-% intermedi dell'argomento
-%
+  ## Compute Bernoulli function for intermediate values
 
-if (ax > xlim),
+  if (ax > xlim)
    bp=x/(exp(x)-1);
    bn=x+bp;
    return
 else
+    ## Compute Bernoulli function for small x
+    ## via Taylor expansion
 
-%
-% Calcola la funz. di Bernoulli per valori
-% piccoli dell'argomento mediante sviluppo
-% di Taylor troncato dell'esponenziale
-%
    ii=1;
    fp=1.;
    fn=1.;
@@ -88,11 +80,8 @@
      fn=fn+segno*df;
      bp=1./fp;
      bn=1./fn;
-   end;
+    endwhile
    return
-end
+  endif
 
-
-% Last Revision:
-% $Author$
-% $Date$
+endfunction
\ No newline at end of file
--- a/extra/secs1d/inst/Utilities/Ubernoulli.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/Utilities/Ubernoulli.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,21 +1,6 @@
-
-function b=Ubernoulli(x,sg)
-
-%
-%   b=Ubernoulli(x,sg)
-%   
-%   Bernoulli function
-%   b = B(x)=x/(exp(x)-1) if sg==1
-%   b = B(-x)=x+B(x)      if sg==0
-%   also works if x is a vector
-  
- ## This file is part of 
+## Copyright (C) 2004-2008  Carlo de Falco
   ##
   ## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-  ## -------------------------------------------------------------------
-  ## Copyright (C) 2004-2007  Carlo de Falco
-  ##
-  ##
   ##
   ##  SECS1D is free software; you can redistribute it and/or modify
   ##  it under the terms of the GNU General Public License as published by
@@ -29,21 +14,34 @@
   ##
   ##  You should have received a copy of the GNU General Public License
   ##  along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
+
+## -*- texinfo -*-
+##
+## @deftypefn {Function File} {@var{b}} = Ubernoulli(@var{x},@var{sg})
+##
+## Compute Bernoulli function for vector x:
+##
+## @itemize @minus
+## @item @var{b} = @var{x}/(exp(@var{x})-1) if @var{sg} == 1
+## @item @var{b} = @var{x} + B( @var{x} ) if @var{sg} == 0
+## @end itemize
+##
+## @end deftypefn
+
+function b=Ubernoulli(x,sg)
   
   for count=1:length(x)
     [bp,bn] = Ubern(x(count));
     bernp(count,1)=bp;
     bernn(count,1)=bn;
-  end
+  endfor
   
   if (sg ==1)
     b=bernp;
   elseif (sg ==0)
     b=bernn;
-  end
-  
+  endif
   
-  % Last Revision:
-  % $Author$
-  % $Date$
-  
+endfunction
\ No newline at end of file
--- a/extra/secs1d/inst/Utilities/Ucompconst.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/Utilities/Ucompconst.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,14 +1,6 @@
-function R = Ucompconst (nodes,Nnodes,elements,Nelements,D,C)
-  
-% R = compconst (nodes,Nnodes,elements,Nelements,D,C);
-  
- ## This file is part of 
+## Copyright (C) 2004-2008  Carlo de Falco
   ##
   ## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-  ## -------------------------------------------------------------------
-  ## Copyright (C) 2004-2007  Carlo de Falco
-  ##
-  ##
   ##
   ##  SECS1D is free software; you can redistribute it and/or modify
   ##  it under the terms of the GNU General Public License as published by
@@ -22,12 +14,30 @@
   ##
   ##  You should have received a copy of the GNU General Public License
   ##  along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
-  
-  h 	= (nodes(2:end)-nodes(1:end-1)).*C;
-  R	    = D.*[h(1)/2; (h(1:end-1)+h(2:end))/2; h(end)/2];
-  
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
   
-  % Last Revision:
-  % $Author$
-  % $Date$
+## -*- texinfo -*-
+##
+## @deftypefn {Function File}@
+## {@var{R}} = Ucompconst(@var{nodes},@var{Nnodes},@var{elements},@var{Nelements},@var{D},@var{C})
+##
+## Compute P1 finite element rhs:
+##
+## @itemize @minus
+## @item @var{nodes}: list of mesh nodes
+## @item @var{Nnodes}: number of mesh nodes
+## @item @var{elements}: list of mesh elements 
+## @item @var{Nelements}: number of mesh elements
+## @item @var{D}: piecewise linear reaction coefficient
+## @item @var{C}: piecewise constant reaction coefficient
+## @end itemize
+##
+## @end deftypefn
   
+function R = Ucompconst (nodes,Nnodes,elements,Nelements,D,C)
+  
+  h = (nodes(2:end)-nodes(1:end-1)).*C;
+  R = D.*[h(1)/2; (h(1:end-1)+h(2:end))/2; h(end)/2];
+  
+endfunction
\ No newline at end of file
--- a/extra/secs1d/inst/Utilities/Ucomplap.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/Utilities/Ucomplap.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,16 +1,6 @@
-function L = Ucomplap (nodes,Nnodes,elements,Nelements,coeff)
-
-% L = Ucomplap (nodes,Nnode,elements,Nelements,coeff)
-%    Computes the P1 finite element approximation of the 
-%    differential operator - d ( coeff d (.)\dx)\dx
-
- ## This file is part of 
+## Copyright (C) 2004-2008  Carlo de Falco
   ##
   ## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-  ## -------------------------------------------------------------------
-  ## Copyright (C) 2004-2007  Carlo de Falco
-  ##
-  ##
   ##
   ##  SECS1D is free software; you can redistribute it and/or modify
   ##  it under the terms of the GNU General Public License as published by
@@ -24,20 +14,36 @@
   ##
   ##  You should have received a copy of the GNU General Public License
   ##  along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
+  
+## -*- texinfo -*-
+##
+## @deftypefn {Function File}@
+## {@var{R}} = Ucomplap(@var{nodes},@var{Nnodes},@var{elements},@var{Nelements},@var{coeff})
+##
+## Compute P1 finite element approximation of the differential operator:
+## 
+##  - d ( coeff d (.)\dx)\dx
+##
+## @itemize @minus
+## @item @var{nodes}: list of mesh nodes
+## @item @var{Nnodes}: number of mesh nodes
+## @item @var{elements}: list of mesh elements 
+## @item @var{Nelements}: number of mesh elements
+## @item @var{coeff}: piecewise linear reaction coefficient
+## @end itemize
+##
+## @end deftypefn
+  
+function L = Ucomplap (nodes,Nnodes,elements,Nelements,coeff)
   
   h 	= nodes(2:end)-nodes(1:end-1);
-  
   d0 	= [ coeff(1)./h(1); 
             (coeff(1:end-1)./h(1:end-1))+(coeff(2:end)./h(2:end));
             coeff(end)./h(end)];
-  
   d1	= [1000; -coeff./h];
   dm1	= [ -coeff./h;1000];
-  
   L	= spdiags([dm1, d0, d1],-1:1,Nnodes,Nnodes);
   
-  
-  % Last Revision:
-  % $Author$
-  % $Date$
-  
+endfunction
\ No newline at end of file
--- a/extra/secs1d/inst/Utilities/Ucompmass.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/Utilities/Ucompmass.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,14 +1,6 @@
-function Bmat	= Ucompmass (nodes,Nnodes,elements,Nelements,Bvect,Cvect);
-  
-% Bmat	= Ucompmass (nodes,Nnodes,elements,Nelements,Bvect,Cvect);
-  
- ## This file is part of 
+## Copyright (C) 2004-2008  Carlo de Falco
   ##
   ## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-  ## -------------------------------------------------------------------
-  ## Copyright (C) 2004-2007  Carlo de Falco
-  ##
-  ##
   ##
   ##  SECS1D is free software; you can redistribute it and/or modify
   ##  it under the terms of the GNU General Public License as published by
@@ -22,13 +14,32 @@
   ##
   ##  You should have received a copy of the GNU General Public License
   ##  along with SECS1D; If not, see <http://www.gnu.org/licenses/>.  
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
+
+## -*- texinfo -*-
+##
+## @deftypefn {Function File}@
+## {@var{R}} = Ucompmass(@var{nodes},@var{Nnodes},@var{elements},@var{Nelements},@var{Bvect},@var{Cvect})
+##
+## Compute P1 finite element mass-matrix:
+##
+## @itemize @minus
+## @item @var{nodes}: list of mesh nodes
+## @item @var{Nnodes}: number of mesh nodes
+## @item @var{elements}: list of mesh elements 
+## @item @var{Nelements}: number of mesh elements
+## @item @var{Bvect}: piecewise linear reaction coefficient
+## @item @var{Cvect}: piecewise constant reaction coefficient
+## @end itemize
+##
+## @end deftypefn
+
+function Bmat	= Ucompmass (nodes,Nnodes,elements,Nelements,Bvect,Cvect);
   
   h 	= (nodes(2:end)-nodes(1:end-1)).*Cvect;
   d0	= Bvect.*[h(1)/2; (h(1:end-1)+h(2:end))/2; h(end)/2];
   Bmat  = spdiags(d0, 0, Nnodes,Nnodes);
   
+endfunction
   
-  % Last Revision:
-  % $Author$
-  % $Date$
-  
--- a/extra/secs1d/inst/Utilities/Udriftdiffusion.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/Utilities/Udriftdiffusion.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,18 +1,6 @@
-function A=Udriftdiffusion(x,psi,coeff)  
-  
-%A=Udriftdiffusion(x,psi,coeff)
-%
-% Builds the Scharfetter-Gummel approximation
-% of the differential operator - (coeff (n' - n psi'))' 
-%
-
- ## This file is part of 
+## Copyright (C) 2004-2008  Carlo de Falco
   ##
   ## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-  ## -------------------------------------------------------------------
-  ## Copyright (C) 2004-2007  Carlo de Falco
-  ##
-  ##
   ##
   ##  SECS1D is free software; you can redistribute it and/or modify
   ##  it under the terms of the GNU General Public License as published by
@@ -26,6 +14,28 @@
   ##
   ##  You should have received a copy of the GNU General Public License
   ##  along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
+
+## -*- texinfo -*-
+##
+## @deftypefn {Function File}@
+## {@var{A}} = Udriftdiffusion(@var{x},@var{psi},@var{coeff})
+##
+## Builds the Scharfetter-Gummel approximation of the differential
+## operator
+##
+## - (coeff (n' - n psi'))'
+##
+## @itemize @minus
+## @item @var{x}: list of mesh nodes
+## @item @var{psi}: piecewise linear potential values
+## @item @var{coeff}: piecewise linear diffusion coefficient
+## @end itemize
+##
+## @end deftypefn
+
+function A = Udriftdiffusion(x,psi,coeff)  
   
   nodes        = x;
   Nnodes     =length(nodes);
@@ -48,7 +58,4 @@
   
   A = spdiags([dm1 d0 d1],-1:1,Nnodes,Nnodes);
   
-  % Last Revision:
-  % $Author$
-  % $Date$
-  
+endfunction
\ No newline at end of file
--- a/extra/secs1d/inst/Utilities/Umediaarmonica.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/Utilities/Umediaarmonica.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,16 +1,6 @@
-function m = Umediaarmonica(w);
-  
-% m = mediaarmonica(w,x);
-% returns the harmonic mean value of w in each of the intervals x_i , x_i+1
-%
-  
-  ## This file is part of 
+## Copyright (C) 2004-2008  Carlo de Falco
   ##
   ## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-  ## -------------------------------------------------------------------
-  ## Copyright (C) 2004-2007  Carlo de Falco
-  ##
-  ##
   ##
   ##  SECS1D is free software; you can redistribute it and/or modify
   ##  it under the terms of the GNU General Public License as published by
@@ -24,12 +14,21 @@
   ##
   ##  You should have received a copy of the GNU General Public License
   ##  along with SECS1D; If not, see <http://www.gnu.org/licenses/>.     
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
     
-  dw 	   = (1./w(1:end-1))+(1./w(2:end));
-     m 	   = 2 ./ dw; 
-     
+## -*- texinfo -*-
+##
+## @deftypefn {Function File}@
+## {@var{m}} = Umediarmonica(@var{w})
+##
+## Return the harmonic mean value of @var{w}
+##
+## @end deftypefn
      
-     % Last Revision:
-     % $Author$
-     % $Date$
+function m = Umediaarmonica(w);
      
+  dw = (1./w(1:end-1))+(1./w(2:end));
+  m  = 2 ./ dw; 
+     
+endfunction     
--- a/extra/secs1d/inst/Utilities/Uscharfettergummel.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/Utilities/Uscharfettergummel.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,40 +1,45 @@
-function A=Uscharfettergummel(nodes,Nnodes,elements,Nelements,acoeff,bcoeff,v)
-  
-%A=Uscharfettergummel(nodes,Nnodes,elements,Nelements,acoeff,bcoeff,v)
-%
-% Builds the Scharfetter-Gummel  matrix for the 
-% the discretization of the LHS 
-% of the Drift-Diffusion equation:
-%
-% $ -(a(x) (u' - b v'(x) u))'= f $
-%
-% where a(x) is piecewise constant
-% and v(x) is piecewise linear, so that 
-% v'(x) is still piecewise constant
-% b is a constant independent of x
-% and u is the unknown
-%
-
-  ## This file is part of 
+## Copyright (C) 2004-2008  Carlo de Falco
   ##
   ## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-  ## -------------------------------------------------------------------
-  ## Copyright (C) 2004-2007  Carlo de Falco
   ##
-  ##
-  ##
-  ##  SECS2D is free software; you can redistribute it and/or modify
+## SECS1D is free software; you can redistribute it and/or modify
   ##  it under the terms of the GNU General Public License as published by
   ##  the Free Software Foundation; either version 2 of the License, or
   ##  (at your option) any later version.
   ##
-  ##  SECS2D is distributed in the hope that it will be useful,
+## SECS1D is distributed in the hope that it will be useful,
   ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
   ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   ##  GNU General Public License for more details.
   ##
   ##  You should have received a copy of the GNU General Public License
-  ##  along with SECS2D; If not, see <http://www.gnu.org/licenses/>.
+## along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
+
+## -*- texinfo -*-
+##
+## @deftypefn {Function File}@
+## {@var{R}} = Uscharfettergummel(@var{nodes},@var{Nnodes},@var{elements},@var{Nelements},@var{acoeff},@var{bcoeff},@var{v})
+##
+## Build the Scharfetter-Gummel matrix for the the discretization of
+## the LHS of the Drift-Diffusion equation:
+##
+##  -(a(x) (u' - b v'(x) u))'= f
+##
+## @itemize @minus
+## @item @var{nodes}: list of mesh nodes
+## @item @var{Nnodes}: number of mesh nodes
+## @item @var{elements}: list of mesh elements 
+## @item @var{Nelements}: number of mesh elements
+## @item @var{acoeff}: piecewise linear diffusion coefficient
+## @item @var{bcoeff}: piecewise constant drift constant coefficient
+## @item @var{v}: piecewise linear drift potential
+## @end itemize
+##
+## @end deftypefn
+
+function A = Uscharfettergummel(nodes,Nnodes,elements,Nelements,acoeff,bcoeff,v)
 
   h=nodes(elements(:,2))-nodes(elements(:,1));
   
@@ -49,6 +54,4 @@
   
   A = spdiags([dm1 d0 d1],-1:1,Nnodes,Nnodes);
   
-  % Last Revision:
-  % $Author$
-  % $Date$
+endfunction
--- a/extra/secs1d/inst/Utilities/constants.m	Wed Jun 10 13:07:24 2009 +0000
+++ b/extra/secs1d/inst/Utilities/constants.m	Wed Jun 10 17:26:22 2009 +0000
@@ -1,3 +1,31 @@
+## Copyright (C) 2004-2008  Carlo de Falco
+##
+## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
+##
+## SECS1D is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## SECS1D is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
+
+## -*- texinfo -*-
+##
+## @deftypefn {Script File} constants
+##
+## Compute global constants needed for Drift-Diffusion simulation
+##
+## @end deftypefn
+
+
 
 Kb           = 1.3806503e-23;
 q            = 1.602176462e-19;
@@ -44,30 +72,3 @@
 
 ni              = sqrt(Nc*Nv)*exp(-Egap/(2*(Kb * T0)));
 Phims           = - Egap /(2*q);
-
-
-## This file is part of 
-##
-## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
-## -------------------------------------------------------------------
-## Copyright (C) 2004-2007  Carlo de Falco
-##
-##
-##
-##  SECS1D is free software; you can redistribute it and/or modify
-##  it under the terms of the GNU General Public License as published by
-##  the Free Software Foundation; either version 2 of the License, or
-##  (at your option) any later version.
-##
-##  SECS1D is distributed in the hope that it will be useful,
-##  but WITHOUT ANY WARRANTY; without even the implied warranty of
-##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-##  GNU General Public License for more details.
-##
-##  You should have received a copy of the GNU General Public License
-##  along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
-
-% Last Revision:
-% $Author$
-% $Date$
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/secs1d/inst/secs1d_demo_pndiode.m	Wed Jun 10 17:26:22 2009 +0000
@@ -0,0 +1,133 @@
+## Copyright (C) 2009  Carlo de Falco
+##
+## SECS1D - A 1-D Drift--Diffusion Semiconductor Device Simulator
+##
+## SECS1D is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## SECS1D is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with SECS1D; If not, see <http://www.gnu.org/licenses/>.
+##
+## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
+
+function secs1d_demo_pndiode ()
+
+  constants
+
+  len = 1e-6;
+  Nnodes = 1000;
+
+  vmin = -2;
+  vmax =  2;
+
+  vstep=.4;
+
+  istep = 1;
+  va = vmin
+  
+  x = linspace(0,len,Nnodes)';
+  xm = mean(x);
+  
+  Nd=1e25;
+  Na=1e25;
+  
+  D = Nd * (x>xm) - Na * (x<=xm);
+
+  nn = (Nd + sqrt(Nd^2+4*ni^2))/2;
+  pp = (Na + sqrt(Na^2+4*ni^2))/2;
+    
+  xn = xm+1e-7;
+  xp = xm-1e-7;
+
+  %% Scaling coefficients
+  xs  = len;
+  ns  = norm(D,inf);
+  idata.D = D/ns;
+  Vs  = Vth;
+  us  = un;
+  Js  = xs / (us * Vs * q * ns);
+
+
+  while va <= vmax
+    
+    vvect(istep) = va;
+    
+    n(:,istep) = nn * (x>=xn) + (ni^2)/pp * (x<xn);
+    p(:,istep) = (ni^2)/nn * (x>xp) + pp * (x<=xp);
+    
+    Fn = va*(x<=xm);
+    Fp = Fn;
+    
+    V(:,istep) = (Fn - Vth * log(p(:,istep)/ni)); 
+  
+    %% Scaling    
+    xin   = x/xs;
+    idata.n   = n(:,istep)/ns;
+    idata.p   = p(:,istep)/ns;
+    idata.V   = V(:,istep)/Vs;
+    idata.Fn  = (Fn - Vs * log(ni/ns))/Vs;
+    idata.Fp  = (Fp + Vs * log(ni/ns))/Vs;
+    
+    lambda2(istep) = idata.l2 = (Vs*esi)/(q*ns*xs^2);
+    idata.nis   = ni/ns;
+    idata.un   = un/us;
+    idata.up   = up/us;
+    
+    %% Solution of DD system
+    
+    %% Algorithm parameters
+    toll  = 1e-5;
+    maxit = 100;
+    ptoll  = 1e-10;
+    pmaxit = 100;
+    verbose = 0;
+    sinodes = [1:length(x)];
+    idata.tn = inf;
+    idata.tp = inf;
+    
+    [odata,it,res] = DDGgummelmap (xin,idata,1e-3, 10,ptoll,pmaxit,verbose);
+    [odata,it,res] = DDNnewtonmap (xin,odata,toll, maxit,verbose);
+
+    n(:,istep) = odata.n;
+    p(:,istep) = odata.p;
+    V(:,istep) = odata.V;
+    
+    DV(istep)  = odata.V(end) - odata.V(1);
+    Emax(istep) = max(abs(diff(odata.V)./diff(xin)))
+
+    va = va+vstep
+    istep = istep+1;
+    
+  endwhile
+
+  %% Descaling
+  n     = n*ns;
+  p     = p*ns;
+  V     = V*Vs;
+
+
+  close all
+  
+  figure(1);
+  plot(xin,n.')
+  xlabel("x")
+  ylabel("n")
+  
+  figure(2);
+  plot(DV,lambda2)
+  xlabel("V")
+  ylabel("\\lambda^2")
+  
+  figure(3);
+  plot(DV,Emax)
+  xlabel("V")
+  ylabel("max(abs(\\phi^''))")
+  
+endfunction
\ No newline at end of file