Ignore:
Timestamp:
Mar 30, 2010 7:53:47 PM (14 years ago)
Author:
Jae Cho <jhjcho@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
f10063e
Parents:
64017a8
Message:

updated libigor files from NIST svn

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansmodels/src/libigor/libCylinder.c

    r222d75c7 r6e93a02  
    88#include "GaussWeights.h" 
    99#include "libCylinder.h" 
     10 
    1011/*      CylinderForm  :  calculates the form factor of a cylinder at the give x-value p->x 
    1112 
     
    2122        int i; 
    2223        double Pi; 
    23         double scale,radius,length,delrho,bkg,halfheight;               //local variables of coefficient wave 
     24        double scale,radius,length,delrho,bkg,halfheight,sldCyl,sldSolv;                //local variables of coefficient wave 
    2425        int nord=76;                    //order of integration 
    2526        double uplim,lolim;             //upper and lower integration limits 
    2627        double summ,zi,yyy,answer,vcyl;                 //running tally of integration 
    27  
     28         
    2829        Pi = 4.0*atan(1.0); 
    29         lolim = 0; 
     30        lolim = 0.0; 
    3031        uplim = Pi/2.0; 
    31  
     32         
    3233        summ = 0.0;                     //initialize intergral 
    33  
     34         
    3435        scale = dp[0];                  //make local copies in case memory moves 
    3536        radius = dp[1]; 
    3637        length = dp[2]; 
    37         delrho = dp[3]; 
    38         bkg = dp[4]; 
     38        sldCyl = dp[3]; 
     39        sldSolv = dp[4]; 
     40        bkg = dp[5]; 
     41         
     42        delrho = sldCyl-sldSolv; 
    3943        halfheight = length/2.0; 
    4044        for(i=0;i<nord;i++) { 
     
    4347                summ += yyy; 
    4448        } 
    45  
     49         
    4650        answer = (uplim-lolim)/2.0*summ; 
    4751        // Multiply by contrast^2 
     
    5761        // add in the background 
    5862        answer += bkg; 
    59  
     63         
    6064        return answer; 
    6165} 
     
    7579{ 
    7680        int i,j; 
    77         double Pi; 
     81        double Pi,slde,sld; 
    7882        double scale,ra,nu,length,delrho,bkg;           //local variables of coefficient wave 
    7983        int nord=76;                    //order of integration 
     
    8791        vaj=0.0; 
    8892        vbj=Pi;         //endpoints of inner integral 
    89  
     93         
    9094        summ = 0.0;                     //initialize intergral 
    91  
     95         
    9296        scale = dp[0];                  //make local copies in case memory moves 
    9397        ra = dp[1]; 
    9498        nu = dp[2]; 
    9599        length = dp[3]; 
    96         delrho = dp[4]; 
    97         bkg = dp[5]; 
     100        slde = dp[4]; 
     101        sld = dp[5]; 
     102        delrho = slde - sld; 
     103        bkg = dp[6]; 
     104         
    98105        for(i=0;i<nord;i++) { 
    99106                //setup inner integral over the ellipsoidal cross-section 
    100107                summj=0; 
    101108                zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;             //the "x" dummy 
    102                 arg = ra*sqrt(1-zi*zi); 
     109                arg = ra*sqrt(1.0-zi*zi); 
    103110                for(j=0;j<nord;j++) { 
    104111                        //76 gauss points for the inner integral as well 
     
    111118                //divide integral by Pi 
    112119                answer /=Pi; 
    113  
     120                 
    114121                //now calculate outer integral 
    115122                arg = q*length*zi/2.0; 
     
    135142        // add in the background 
    136143        answer += bkg; 
    137  
     144         
    138145        return answer; 
    139146} 
     
    154161{ 
    155162        int i,j; 
    156         double Pi; 
     163        double Pi,slde,sld; 
    157164        double scale,ra,nu,length,delrho,bkg;           //local variables of coefficient wave 
    158165        int nordi=76;                   //order of integration 
     
    167174        vaj=0.0; 
    168175        vbj=Pi;         //endpoints of inner integral 
    169  
     176         
    170177        summ = 0.0;                     //initialize intergral 
    171  
     178         
    172179        scale = dp[0];                  //make local copies in case memory moves 
    173180        ra = dp[1]; 
    174181        nu = dp[2]; 
    175182        length = dp[3]; 
    176         delrho = dp[4]; 
    177         bkg = dp[5]; 
     183        slde = dp[4]; 
     184        sld = dp[5]; 
     185        delrho = slde - sld; 
     186        bkg = dp[6]; 
     187         
    178188        for(i=0;i<nordi;i++) { 
    179189                //setup inner integral over the ellipsoidal cross-section 
    180190                summj=0; 
    181191                zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;             //the "x" dummy 
    182                 arg = ra*sqrt(1-zi*zi); 
     192                arg = ra*sqrt(1.0-zi*zi); 
    183193                for(j=0;j<nordj;j++) { 
    184194                        //20 gauss points for the inner integral 
     
    191201                //divide integral by Pi 
    192202                answer /=Pi; 
    193  
     203                 
    194204                //now calculate outer integral 
    195                 arg = q*length*zi/2; 
     205                arg = q*length*zi/2.0; 
    196206                if (arg == 0.0){ 
    197207                        si = 1.0; 
     
    202212                summ += yyy; 
    203213        } 
    204  
     214         
    205215        answer = (vb-va)/2.0*summ; 
    206216        // Multiply by contrast^2 
     
    240250        double va,vb;           //upper and lower integration limits 
    241251        double summ,zi,yyy,answer;                      //running tally of integration 
    242         double summj,vaj,vbj,zij;                       //for the inner integration 
    243  
     252        double summj,vaj,vbj,zij,slde,sld;                      //for the inner integration 
     253         
    244254        Pi = 4.0*atan(1.0); 
    245255        va = 0.0; 
     
    247257        vaj = 0.0; 
    248258        vbj = 1.0;              //endpoints of inner integral 
    249  
     259         
    250260        summ = 0.0;                     //initialize intergral 
    251  
     261         
    252262        scale = dp[0];                  //make local copies in case memory moves 
    253263        aa = dp[1]; 
    254264        bb = dp[2]; 
    255265        cc = dp[3]; 
    256         delrho = dp[4]; 
    257         bkg = dp[5]; 
     266        slde = dp[4]; 
     267        sld = dp[5]; 
     268        delrho = slde - sld; 
     269        bkg = dp[6]; 
    258270        for(i=0;i<nordi;i++) { 
    259271                //setup inner integral over the ellipsoidal cross-section 
    260                 summj=0; 
     272                summj=0.0; 
    261273                zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;             //the "x" dummy 
    262274                for(j=0;j<nordj;j++) { 
     
    268280                //now calculate the value of the inner integral 
    269281                answer = (vbj-vaj)/2.0*summj; 
    270  
     282                 
    271283                //now calculate outer integral 
    272284                yyy = Gauss76Wt[i] * answer; 
    273285                summ += yyy; 
    274286        }               //final scaling is done at the end of the function, after the NT_FP64 case 
    275  
     287         
    276288        answer = (vb-va)/2.0*summ; 
    277289        // Multiply by contrast^2 
     
    285297        // add in the background 
    286298        answer += bkg; 
    287  
     299         
    288300        return answer; 
    289301} 
     
    310322        double summ,yyy,answer;                 //running tally of integration 
    311323        double summj,vaj,vbj;                   //for the inner integration 
    312         double mu,mudum,arg,sigma,uu,vol; 
    313  
    314  
     324        double mu,mudum,arg,sigma,uu,vol,sldp,sld; 
     325         
     326         
    315327        //      Pi = 4.0*atan(1.0); 
    316328        va = 0.0; 
     
    320332 
    321333        summ = 0.0;                     //initialize intergral 
    322  
     334         
    323335        scale = dp[0];                  //make local copies in case memory moves 
    324336        aa = dp[1]; 
    325337        bb = dp[2]; 
    326338        cc = dp[3]; 
    327         delrho = dp[4]; 
    328         bkg = dp[5]; 
    329  
     339        sldp = dp[4]; 
     340        sld = dp[5]; 
     341        delrho = sldp - sld; 
     342        bkg = dp[6]; 
     343         
    330344        mu = q*bb; 
    331345        vol = aa*bb*cc; 
     
    333347        aa = aa/bb; 
    334348        cc = cc/bb; 
    335  
     349         
    336350        for(i=0;i<nordi;i++) { 
    337351                //setup inner integral over the ellipsoidal cross-section 
    338                 summj=0; 
     352                summj=0.0; 
    339353                sigma = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;          //the outer dummy 
    340  
     354                 
    341355                for(j=0;j<nordj;j++) { 
    342356                        //76 gauss points for the inner integral 
    343357                        uu = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0;         //the inner dummy 
    344                         mudum = mu*sqrt(1-sigma*sigma); 
     358                        mudum = mu*sqrt(1.0-sigma*sigma); 
    345359                        yyy = Gauss76Wt[j] * PPKernel(aa,mudum,uu); 
    346360                        summj += yyy; 
     
    355369                        answer *= sin(arg)*sin(arg)/arg/arg; 
    356370                } 
    357  
     371                 
    358372                //now sum up the outer integral 
    359373                yyy = Gauss76Wt[i] * answer; 
    360374                summ += yyy; 
    361375        }               //final scaling is done at the end of the function, after the NT_FP64 case 
    362  
     376         
    363377        answer = (vb-va)/2.0*summ; 
    364378        // Multiply by contrast^2 
     
    372386        // add in the background 
    373387        answer += bkg; 
    374  
     388         
    375389        return answer; 
    376390} 
     
    394408        int nord=76;                    //order of integration 
    395409        double va,vb,zi;                //upper and lower integration limits 
    396         double summ,answer,pi;                  //running tally of integration 
    397  
     410        double summ,answer,pi,sldc,sld;                 //running tally of integration 
     411         
    398412        pi = 4.0*atan(1.0); 
    399413        va = 0.0; 
     
    401415 
    402416        summ = 0.0;                     //initialize intergral 
    403  
     417         
    404418        scale = dp[0];          //make local copies in case memory moves 
    405419        rcore = dp[1]; 
    406420        rshell = dp[2]; 
    407421        length = dp[3]; 
    408         delrho = dp[4]; 
    409         bkg = dp[5]; 
    410  
     422        sldc = dp[4]; 
     423        sld = dp[5]; 
     424        delrho = sldc - sld; 
     425        bkg = dp[6]; 
     426         
    411427        for(i=0;i<nord;i++) { 
    412428                zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0; 
    413429                summ += Gauss76Wt[i] * HolCylKernel(q, rcore, rshell, length, zi); 
    414430        } 
    415  
     431         
    416432        answer = (vb-va)/2.0*summ; 
    417433        // Multiply by contrast^2 
     
    425441        // add in the background 
    426442        answer += bkg; 
    427  
     443         
    428444        return answer; 
    429445} 
     
    447463        int nord=76;                    //order of integration 
    448464        double va,vb,zi;                //upper and lower integration limits 
    449         double summ,answer,pi;                  //running tally of integration 
    450  
     465        double summ,answer,pi,slde,sld;                 //running tally of integration 
     466         
    451467        pi = 4.0*atan(1.0); 
    452468        va = 0.0; 
     
    454470 
    455471        summ = 0.0;                     //initialize intergral 
    456  
     472         
    457473        scale = dp[0];                  //make local copies in case memory moves 
    458474        nua = dp[1]; 
    459475        a = dp[2]; 
    460         delrho = dp[3]; 
    461         bkg = dp[4]; 
    462  
     476        slde = dp[3]; 
     477        sld = dp[4]; 
     478        delrho = slde - sld; 
     479        bkg = dp[5]; 
     480         
    463481        for(i=0;i<nord;i++) { 
    464482                zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0; 
    465483                summ += Gauss76Wt[i] * EllipsoidKernel(q, a, nua, zi); 
    466484        } 
    467  
     485         
    468486        answer = (vb-va)/2.0*summ; 
    469487        // Multiply by contrast^2 
     
    477495        // add in the background 
    478496        answer += bkg; 
    479  
     497         
    480498        return answer; 
    481499} 
     
    494512        double uplim,lolim;             //upper and lower integration limits 
    495513        double summ,zi,yyy,answer,Vpoly;                        //running tally of integration 
    496         double range,zz,Pi; 
    497  
     514        double range,zz,Pi,sldc,sld; 
     515         
    498516        Pi = 4.0*atan(1.0); 
    499517        range = 3.4; 
    500  
     518         
    501519        summ = 0.0;                     //initialize intergral 
    502  
     520         
    503521        scale = dp[0];                  //make local copies in case memory moves 
    504522        radius = dp[1]; 
    505523        length = dp[2]; 
    506524        pd = dp[3]; 
    507         delrho = dp[4]; 
    508         bkg = dp[5]; 
    509  
     525        sldc = dp[4]; 
     526        sld = dp[5]; 
     527        delrho = sldc - sld; 
     528        bkg = dp[6]; 
     529         
    510530        zz = (1.0/pd)*(1.0/pd) - 1.0; 
    511  
     531         
    512532        lolim = radius*(1.0-range*pd);          //set the upper/lower limits to cover the distribution 
    513         if(lolim<0) { 
    514                 lolim = 0; 
     533        if(lolim<0.0) { 
     534                lolim = 0.0; 
    515535        } 
    516536        if(pd>0.3) { 
     
    518538        } 
    519539        uplim = radius*(1.0+range*pd); 
    520  
     540         
    521541        for(i=0;i<nord;i++) { 
    522542                zi = ( Gauss20Z[i]*(uplim-lolim) + uplim + lolim )/2.0; 
     
    524544                summ += yyy; 
    525545        } 
    526  
     546         
    527547        answer = (uplim-lolim)/2.0*summ; 
    528548        //normalize by average cylinder volume 
     
    536556        // add in the background 
    537557        answer += bkg; 
    538  
     558         
    539559        return answer; 
    540560} 
     
    552572        double uplim,lolim;             //upper and lower integration limits 
    553573        double summ,zi,yyy,answer,Vpoly;                        //running tally of integration 
    554         double range,zz,Pi; 
    555  
    556  
     574        double range,zz,Pi,sldc,sld; 
     575         
     576         
    557577        Pi = 4.0*atan(1.0); 
    558578        range = 3.4; 
    559  
     579         
    560580        summ = 0.0;                     //initialize intergral 
    561  
     581         
    562582        scale = dp[0];                  //make local copies in case memory moves 
    563583        radius = dp[1]; 
    564584        length = dp[2]; 
    565585        pd = dp[3]; 
    566         delrho = dp[4]; 
    567         bkg = dp[5]; 
    568  
     586        sldc = dp[4]; 
     587        sld = dp[5]; 
     588        delrho = sldc - sld; 
     589        bkg = dp[6]; 
     590         
    569591        zz = (1.0/pd)*(1.0/pd) - 1.0; 
    570  
     592         
    571593        lolim = length*(1.0-range*pd);          //set the upper/lower limits to cover the distribution 
    572         if(lolim<0) { 
    573                 lolim = 0; 
     594        if(lolim<0.0) { 
     595                lolim = 0.0; 
    574596        } 
    575597        if(pd>0.3) { 
     
    577599        } 
    578600        uplim = length*(1.0+range*pd); 
    579  
     601         
    580602        for(i=0;i<nord;i++) { 
    581603                zi = ( Gauss20Z[i]*(uplim-lolim) + uplim + lolim )/2.0; 
     
    583605                summ += yyy; 
    584606        } 
    585  
     607         
    586608        answer = (uplim-lolim)/2.0*summ; 
    587609        //normalize by average cylinder volume (first moment) 
     
    595617        // add in the background 
    596618        answer += bkg; 
    597  
     619         
    598620        return answer; 
    599621} 
     
    613635        double summ,zi,yyy,answer,Vcyl;                 //running tally of integration 
    614636        double Pi; 
    615  
     637         
    616638        Pi = 4.0*atan(1.0); 
    617  
     639         
    618640        lolim = 0.0; 
    619641        uplim = Pi/2.0; 
    620  
     642         
    621643        summ = 0.0;                     //initialize intergral 
    622  
     644         
    623645        scale = dp[0];          //make local copies in case memory moves 
    624646        rcore = dp[1]; 
     
    629651        rhosolv = dp[6]; 
    630652        bkg = dp[7]; 
    631  
     653         
    632654        halfheight = length/2.0; 
    633  
     655         
    634656        for(i=0;i<nord;i++) { 
    635657                zi = ( Gauss76Z[i]*(uplim-lolim) + uplim + lolim )/2.0; 
     
    637659                summ += yyy; 
    638660        } 
    639  
     661         
    640662        answer = (uplim-lolim)/2.0*summ; 
    641         // length is the total core length 
     663        // length is the total core length  
    642664        Vcyl=Pi*(rcore+thick)*(rcore+thick)*(length+2.0*thick); 
    643665        answer /= Vcyl; 
     
    648670        // add in the background 
    649671        answer += bkg; 
    650  
     672         
    651673        return answer; 
    652674} 
     
    667689        double summ,yyy,answer,Vpoly;                   //running tally of integration 
    668690        double Pi,AR,Rsqrsumm,Rsqryyy,Rsqr; 
    669  
     691                 
    670692        Pi = 4.0*atan(1.0); 
    671  
     693         
    672694        summ = 0.0;                     //initialize intergral 
    673695        Rsqrsumm = 0.0; 
    674  
     696         
    675697        scale = dp[0]; 
    676698        radius = dp[1]; 
     
    683705        rhosolv = dp[8]; 
    684706        bkg = dp[9]; 
    685  
     707         
    686708        lolim = exp(log(radius)-(4.*sigma)); 
    687         if (lolim<0) { 
    688                 lolim=0;                //to avoid numerical error when  va<0 (-ve r value) 
     709        if (lolim<0.0) { 
     710                lolim=0.0;              //to avoid numerical error when  va<0 (-ve r value) 
    689711        } 
    690712        uplim = exp(log(radius)+(4.*sigma)); 
    691  
     713         
    692714        for(i=0;i<nord;i++) { 
    693715                rad = ( Gauss20Z[i]*(uplim-lolim) + uplim + lolim )/2.0; 
     
    698720                Rsqrsumm += Rsqryyy; 
    699721        } 
    700  
     722         
    701723        answer = (uplim-lolim)/2.0*summ; 
    702724        Rsqr = (uplim-lolim)/2.0*Rsqrsumm; 
     
    710732        // add in the background 
    711733        answer += bkg; 
    712  
     734         
    713735        return answer; 
    714736} 
     
    726748        double uplim,lolim;             //upper and lower integration limits 
    727749        double summ,zi,yyy,answer,oblatevol;                    //running tally of integration 
    728         double Pi; 
    729  
     750        double Pi,sldc,slds,sld; 
     751         
    730752        Pi = 4.0*atan(1.0); 
    731  
     753         
    732754        lolim = 0.0; 
    733755        uplim = 1.0; 
    734  
     756         
    735757        summ = 0.0;                     //initialize intergral 
    736  
    737  
     758         
     759         
    738760        scale = dp[0];          //make local copies in case memory moves 
    739761        crmaj = dp[1]; 
     
    741763        trmaj = dp[3]; 
    742764        trmin = dp[4]; 
    743         delpc = dp[5]; 
    744         delps = dp[6]; 
    745         bkg = dp[7]; 
     765        sldc = dp[5]; 
     766        slds = dp[6]; 
     767        sld = dp[7]; 
     768        delpc = sldc - slds;    //core - shell 
     769        delps = slds - sld;             //shell - solvent 
     770        bkg = dp[8]; 
    746771 
    747772        for(i=0;i<nord;i++) { 
     
    750775                summ += yyy; 
    751776        } 
    752  
     777         
    753778        answer = (uplim-lolim)/2.0*summ; 
    754779        // normalize by particle volume 
    755         oblatevol = 4*Pi/3*trmaj*trmaj*trmin; 
     780        oblatevol = 4.0*Pi/3.0*trmaj*trmaj*trmin; 
    756781        answer /= oblatevol; 
    757  
     782         
    758783        //convert to [cm-1] 
    759784        answer *= 1.0e8; 
     
    762787        // add in the background 
    763788        answer += bkg; 
    764  
     789         
    765790        return answer; 
    766791} 
     
    778803        double uplim,lolim;             //upper and lower integration limits 
    779804        double summ,zi,yyy,answer,prolatevol;                   //running tally of integration 
    780         double Pi; 
    781  
     805        double Pi,sldc,slds,sld; 
     806         
    782807        Pi = 4.0*atan(1.0); 
    783  
     808         
    784809        lolim = 0.0; 
    785810        uplim = 1.0; 
    786  
     811         
    787812        summ = 0.0;                     //initialize intergral 
    788  
     813         
    789814        scale = dp[0];          //make local copies in case memory moves 
    790815        crmaj = dp[1]; 
     
    792817        trmaj = dp[3]; 
    793818        trmin = dp[4]; 
    794         delpc = dp[5]; 
    795         delps = dp[6]; 
    796         bkg = dp[7]; 
     819        sldc = dp[5]; 
     820        slds = dp[6]; 
     821        sld = dp[7]; 
     822        delpc = sldc - slds;            //core - shell 
     823        delps = slds - sld;             //shell  - sovent 
     824        bkg = dp[8]; 
    797825 
    798826        for(i=0;i<nord;i++) { 
     
    801829                summ += yyy; 
    802830        } 
    803  
     831         
    804832        answer = (uplim-lolim)/2.0*summ; 
    805833        // normalize by particle volume 
    806834        prolatevol = 4.0*Pi/3.0*trmaj*trmin*trmin; 
    807835        answer /= prolatevol; 
    808  
     836         
    809837        //convert to [cm-1] 
    810838        answer *= 1.0e8; 
     
    813841        // add in the background 
    814842        answer += bkg; 
    815  
     843         
    816844        return answer; 
    817845} 
     
    830858        int nord=76;                    //order of integration 
    831859        double Pi; 
    832  
    833  
     860         
     861         
    834862        Pi = 4.0*atan(1.0); 
    835  
     863         
    836864        va = 0.0; 
    837865        vb = Pi/2.0; 
    838  
     866         
    839867        summ = 0.0;                     //initialize intergral 
    840  
     868         
    841869        scale = dp[0]; 
    842870        rcore = dp[1]; 
     
    849877        gsd = dp[8]; 
    850878        bkg = dp[9]; 
    851  
     879         
    852880        d=2.0*thick+length; 
    853881        halfheight = length/2.0; 
    854  
     882         
    855883        for(i=0;i<nord;i++) { 
    856884                zi = ( Gauss76Z[i]*(vb-va) + vb + va )/2.0; 
     
    858886                summ += yyy; 
    859887        } 
    860  
     888         
    861889        answer = (vb-va)/2.0*summ; 
    862         // length is the total core length 
     890        // length is the total core length  
    863891        vcyl=Pi*rcore*rcore*(2.0*thick+length)*N; 
    864892        answer /= vcyl; 
     
    869897        // add in the background 
    870898        answer += bkg; 
    871  
     899         
    872900        return answer; 
    873901} 
     
    882910        double scale,del,sig,contr,bkg;         //local variables of coefficient wave 
    883911        double inten, qval,Pq; 
    884         double Pi; 
    885  
    886  
     912        double Pi,sldb,sld; 
     913         
     914         
    887915        Pi = 4.0*atan(1.0); 
    888916        scale = dp[0]; 
    889917        del = dp[1]; 
    890918        sig = dp[2]*del; 
    891         contr = dp[3]; 
    892         bkg = dp[4]; 
    893         qval = q; 
    894  
     919        sldb = dp[3]; 
     920        sld = dp[4]; 
     921        contr = sldb - sld; 
     922        bkg = dp[5]; 
     923        qval=q; 
     924         
    895925        Pq = 2.0*contr*contr/qval/qval*(1.0-cos(qval*del)*exp(-0.5*qval*qval*sig*sig)); 
    896  
     926         
    897927        inten = 2.0*Pi*scale*Pq/(qval*qval);            //this is now dimensionless... 
    898  
     928         
    899929        inten /= del;                   //normalize by the thickness (in A) 
    900  
     930         
    901931        inten *= 1.0e8;         // 1/A to 1/cm 
    902  
     932         
    903933        return(inten+bkg); 
    904934} 
    905935 
    906936/*      LamellarPSX  :  calculates the form factor of a lamellar structure - with S(q) effects included 
    907 ------- 
    908 ------- resolution effects ARE included, but only a CONSTANT default value, not the real q-dependent resolution!! 
    909  
    910         */ 
     937--- now the proper resolution effects are used - the "default" resolution is turned off (= 0) and the 
     938model is smeared just like any other function 
     939*/ 
    911940double 
    912941LamellarPS(double dp[], double q) 
    913942{ 
    914943        double scale,dd,del,sig,contr,NN,Cp,bkg;                //local variables of coefficient wave 
    915         double inten, qval,Pq,Sq,alpha,temp,t1,t2,t3,dQ; 
    916         double Pi,Euler,dQDefault,fii; 
     944        double inten,qval,Pq,Sq,alpha,temp,t1,t2,t3,dQ; 
     945        double Pi,Euler,dQDefault,fii,sldb,sld; 
    917946        int ii,NNint; 
    918  
     947//      char buf[256]; 
     948 
     949         
    919950        Euler = 0.5772156649;           // Euler's constant 
    920         dQDefault = 0.0;//0.0025;               //[=] 1/A, q-resolution, default value 
     951//      dQDefault = 0.0025;             //[=] 1/A, q-resolution, default value 
     952        dQDefault = 0.0; 
    921953        dQ = dQDefault; 
    922  
     954         
    923955        Pi = 4.0*atan(1.0); 
    924956        qval = q; 
    925  
     957         
    926958        scale = dp[0]; 
    927959        dd = dp[1]; 
    928960        del = dp[2]; 
    929961        sig = dp[3]*del; 
    930         contr = dp[4]; 
    931         NN = trunc(dp[5]);              //be sure that NN is an integer 
    932         Cp = dp[6]; 
    933         bkg = dp[7]; 
    934  
     962        sldb = dp[4]; 
     963        sld = dp[5]; 
     964        contr = sldb - sld; 
     965        NN = trunc(dp[6]);              //be sure that NN is an integer 
     966        Cp = dp[7]; 
     967        bkg = dp[8]; 
     968         
    935969        Pq = 2.0*contr*contr/qval/qval*(1.0-cos(qval*del)*exp(-0.5*qval*qval*sig*sig)); 
    936  
     970         
    937971        NNint = (int)NN;                //cast to an integer for the loop 
     972         
     973//      sprintf(buf, "qval = %g\r", qval); 
     974//      XOPNotice(buf); 
     975         
    938976        ii=0; 
    939977        Sq = 0.0; 
    940978        for(ii=1;ii<(NNint-1);ii+=1) { 
    941  
     979         
    942980                fii = (double)ii;               //do I really need to do this? 
    943  
     981                 
    944982                temp = 0.0; 
    945                 alpha = Cp/4.0/Pi/Pi*(log(Pi*ii) + Euler); 
     983                alpha = Cp/4.0/Pi/Pi*(log(Pi*fii) + Euler); 
    946984                t1 = 2.0*dQ*dQ*dd*dd*alpha; 
    947985                t2 = 2.0*qval*qval*dd*dd*alpha; 
    948                 t3 = dQ*dQ*dd*dd*ii*ii; 
    949  
    950                 temp = 1.0-ii/NN; 
    951                 temp *= cos(dd*qval*ii/(1.0+t1)); 
     986                t3 = dQ*dQ*dd*dd*fii*fii; 
     987                 
     988                temp = 1.0-fii/NN; 
     989                temp *= cos(dd*qval*fii/(1.0+t1)); 
    952990                temp *= exp(-1.0*(t2 + t3)/(2.0*(1.0+t1)) ); 
    953991                temp /= sqrt(1.0+t1); 
    954  
     992                 
    955993                Sq += temp; 
    956994        } 
    957  
     995         
    958996        Sq *= 2.0; 
    959997        Sq += 1.0; 
    960  
     998         
    961999        inten = 2.0*Pi*scale*Pq*Sq/(dd*qval*qval); 
    962  
     1000         
    9631001        inten *= 1.0e8;         // 1/A to 1/cm 
    964  
     1002         
    9651003    return(inten+bkg); 
    9661004} 
     
    9681006 
    9691007/*      LamellarPS_HGX  :  calculates the form factor of a lamellar structure - with S(q) effects included 
    970 ------- 
    971 ------- resolution effects ARE included, but only a CONSTANT default value, not the real q-dependent resolution!! 
    972  
    973         */ 
     1008--- now the proper resolution effects are used - the "default" resolution is turned off (= 0) and the 
     1009model is smeared just like any other function 
     1010*/ 
    9741011double 
    9751012LamellarPS_HG(double dp[], double q) 
     
    9791016        double Pi,Euler,dQDefault,fii; 
    9801017        int ii,NNint; 
    981  
    982  
     1018         
     1019         
    9831020        Euler = 0.5772156649;           // Euler's constant 
    984         dQDefault = 0.0; //0.0025;              //[=] 1/A, q-resolution, default value 
     1021//      dQDefault = 0.0025;             //[=] 1/A, q-resolution, default value 
     1022        dQDefault = 0.0; 
    9851023        dQ = dQDefault; 
    986  
     1024         
    9871025        Pi = 4.0*atan(1.0); 
    9881026        qval= q; 
    989  
     1027         
    9901028        scale = dp[0]; 
    9911029        dd = dp[1]; 
     
    9981036        Cp = dp[8]; 
    9991037        bkg = dp[9]; 
    1000  
    1001  
     1038         
     1039         
    10021040        drh = SLD_H - SLD_S; 
    10031041        drt = SLD_T - SLD_S;    //correction 13FEB06 by L.Porcar 
    1004  
     1042         
    10051043        Pq = drh*(sin(qval*(delH+delT))-sin(qval*delT)) + drt*sin(qval*delT); 
    10061044        Pq *= Pq; 
    10071045        Pq *= 4.0/(qval*qval); 
    1008  
     1046         
    10091047        NNint = (int)NN;                //cast to an integer for the loop 
    10101048        ii=0; 
    10111049        Sq = 0.0; 
    10121050        for(ii=1;ii<(NNint-1);ii+=1) { 
    1013  
     1051         
    10141052                fii = (double)ii;               //do I really need to do this? 
    1015  
     1053                 
    10161054                temp = 0.0; 
    10171055                alpha = Cp/4.0/Pi/Pi*(log(Pi*ii) + Euler); 
     
    10191057                t2 = 2.0*qval*qval*dd*dd*alpha; 
    10201058                t3 = dQ*dQ*dd*dd*ii*ii; 
    1021  
     1059                 
    10221060                temp = 1.0-ii/NN; 
    10231061                temp *= cos(dd*qval*ii/(1.0+t1)); 
    10241062                temp *= exp(-1.0*(t2 + t3)/(2.0*(1.0+t1)) ); 
    10251063                temp /= sqrt(1.0+t1); 
    1026  
     1064                 
    10271065                Sq += temp; 
    10281066        } 
    1029  
     1067         
    10301068        Sq *= 2.0; 
    10311069        Sq += 1.0; 
    1032  
     1070         
    10331071        inten = 2.0*Pi*scale*Pq*Sq/(dd*qval*qval); 
    1034  
     1072         
    10351073        inten *= 1.0e8;         // 1/A to 1/cm 
    1036  
     1074         
    10371075        return(inten+bkg); 
    10381076} 
     
    10481086        double inten, qval,Pq,drh,drt; 
    10491087        double Pi; 
    1050  
    1051  
     1088         
     1089         
    10521090        Pi = 4.0*atan(1.0); 
    10531091        qval= q; 
     
    10591097        slds = dp[5]; 
    10601098        bkg = dp[6]; 
    1061  
    1062  
     1099         
     1100         
    10631101        drh = sldh - slds; 
    10641102        drt = sldt - slds;              //correction 13FEB06 by L.Porcar 
    1065  
     1103         
    10661104        Pq = drh*(sin(qval*(delH+delT))-sin(qval*delT)) + drt*sin(qval*delT); 
    10671105        Pq *= Pq; 
    10681106        Pq *= 4.0/(qval*qval); 
    1069  
     1107         
    10701108        inten = 2.0*Pi*scale*Pq/(qval*qval);            //dimensionless... 
    1071  
     1109         
    10721110        inten /= 2.0*(delT+delH);                       //normalize by the bilayer thickness 
    1073  
     1111         
    10741112        inten *= 1.0e8;         // 1/A to 1/cm 
    1075  
     1113         
    10761114        return(inten+bkg); 
    10771115} 
     
    10841122FlexExclVolCyl(double dp[], double q) 
    10851123{ 
    1086         double scale,L,B,bkg,rad,qr,cont; 
     1124        double scale,L,B,bkg,rad,qr,cont,sldc,slds; 
    10871125        double Pi,flex,crossSect,answer; 
    1088  
    1089  
     1126         
     1127         
    10901128        Pi = 4.0*atan(1.0); 
    1091  
     1129         
    10921130        scale = dp[0];          //make local copies in case memory moves 
    10931131        L = dp[1]; 
    10941132        B = dp[2]; 
    10951133        rad = dp[3]; 
    1096         cont = dp[4]; 
    1097         bkg = dp[5]; 
    1098  
    1099  
     1134        sldc = dp[4]; 
     1135        slds = dp[5]; 
     1136        cont = sldc-slds; 
     1137        bkg = dp[6]; 
     1138         
     1139     
    11001140        qr = q*rad; 
    1101  
     1141         
    11021142        flex = Sk_WR(q,L,B); 
    1103  
     1143         
    11041144        crossSect = (2.0*NR_BessJ1(qr)/qr)*(2.0*NR_BessJ1(qr)/qr); 
    11051145        flex *= crossSect; 
     
    11081148        flex *= 1.0e8; 
    11091149        answer = scale*flex + bkg; 
    1110  
     1150         
    11111151        return answer; 
    11121152} 
     
    11191159FlexCyl_Ellip(double dp[], double q) 
    11201160{ 
    1121         double scale,L,B,bkg,rad,qr,cont,ellRatio; 
     1161        double scale,L,B,bkg,rad,qr,cont,ellRatio,slds,sldc; 
    11221162        double Pi,flex,crossSect,answer; 
    1123  
    1124  
     1163         
     1164         
    11251165        Pi = 4.0*atan(1.0); 
    11261166        scale = dp[0];          //make local copies in case memory moves 
     
    11291169        rad = dp[3]; 
    11301170        ellRatio = dp[4]; 
    1131         cont = dp[5]; 
    1132         bkg = dp[6]; 
    1133  
     1171        sldc = dp[5]; 
     1172        slds = dp[6]; 
     1173        bkg = dp[7]; 
     1174         
     1175        cont = sldc - slds; 
    11341176        qr = q*rad; 
    1135  
     1177         
    11361178        flex = Sk_WR(q,L,B); 
    1137  
     1179         
    11381180        crossSect = EllipticalCross_fn(q,rad,(rad*ellRatio)); 
    11391181        flex *= crossSect; 
     
    11421184        flex *= 1.0e8; 
    11431185        answer = scale*flex + bkg; 
    1144  
     1186         
    11451187        return answer; 
    11461188} 
     
    11511193    double uplim,lolim,Pi,summ,arg,zi,yyy,answer; 
    11521194    int i,nord=76; 
    1153  
     1195     
    11541196    Pi = 4.0*atan(1.0); 
    11551197    lolim=0.0; 
    11561198    uplim=Pi/2.0; 
    11571199    summ=0.0; 
    1158  
     1200     
    11591201    for(i=0;i<nord;i++) { 
    11601202                zi = ( Gauss76Z[i]*(uplim-lolim) + uplim + lolim )/2.0; 
     
    11671209    answer *= 2.0/Pi; 
    11681210    return(answer); 
    1169  
     1211         
    11701212} 
    11711213/*      FlexCyl_PolyLenX  :  calculates the form factor of a flecible cylinder at the given x-value p->x 
     
    11771219{ 
    11781220        int i; 
    1179         double scale,radius,length,pd,delrho,bkg,lb;            //local variables of coefficient wave 
     1221        double scale,radius,length,pd,bkg,lb,delrho,sldc,slds;          //local variables of coefficient wave 
    11801222        int nord=20;                    //order of integration 
    11811223        double uplim,lolim;             //upper and lower integration limits 
    11821224        double summ,zi,yyy,answer,Vpoly;                        //running tally of integration 
    11831225        double range,zz,Pi; 
    1184  
     1226         
    11851227        Pi = 4.0*atan(1.0); 
    11861228        range = 3.4; 
    1187  
     1229         
    11881230        summ = 0.0;                     //initialize intergral 
    11891231        scale = dp[0];                  //make local copies in case memory moves 
     
    11921234        lb = dp[3]; 
    11931235        radius = dp[4]; 
    1194         delrho = dp[5]; 
    1195         bkg = dp[6]; 
    1196  
     1236        sldc = dp[5]; 
     1237        slds = dp[6]; 
     1238        bkg = dp[7]; 
     1239         
     1240        delrho = sldc - slds; 
    11971241        zz = (1.0/pd)*(1.0/pd) - 1.0; 
    1198  
     1242         
    11991243        lolim = length*(1.0-range*pd);          //set the upper/lower limits to cover the distribution 
    1200         if(lolim<0) { 
    1201                 lolim = 0; 
     1244        if(lolim<0.0) { 
     1245                lolim = 0.0; 
    12021246        } 
    12031247        if(pd>0.3) { 
     
    12051249        } 
    12061250        uplim = length*(1.0+range*pd); 
    1207  
     1251         
    12081252        for(i=0;i<nord;i++) { 
    12091253                zi = ( Gauss20Z[i]*(uplim-lolim) + uplim + lolim )/2.0; 
     
    12111255                summ += yyy; 
    12121256        } 
    1213  
     1257         
    12141258        answer = (uplim-lolim)/2.0*summ; 
    12151259        //normalize by average cylinder volume (first moment), using the average length 
    12161260        Vpoly=Pi*radius*radius*length; 
    12171261        answer /= Vpoly; 
    1218  
     1262         
    12191263        answer *=delrho*delrho; 
    1220  
     1264         
    12211265        //convert to [cm-1] 
    12221266        answer *= 1.0e8; 
     
    12251269        // add in the background 
    12261270        answer += bkg; 
    1227  
     1271         
    12281272        return answer; 
    12291273} 
     
    12371281{ 
    12381282        int i; 
    1239         double scale,radius,length,pd,delrho,bkg,lb;            //local variables of coefficient wave 
     1283        double scale,radius,length,pd,delrho,bkg,lb,sldc,slds;          //local variables of coefficient wave 
    12401284        int nord=76;                    //order of integration 
    12411285        double uplim,lolim;             //upper and lower integration limits 
    12421286        double summ,zi,yyy,answer,Vpoly;                        //running tally of integration 
    12431287        double range,zz,Pi; 
    1244  
    1245  
     1288         
     1289         
    12461290        Pi = 4.0*atan(1.0); 
    12471291        range = 3.4; 
    1248  
     1292         
    12491293        summ = 0.0;                     //initialize intergral 
    1250  
     1294         
    12511295        scale = dp[0];                  //make local copies in case memory moves 
    12521296        length = dp[1];                 //radius 
     
    12541298        radius = dp[3]; 
    12551299        pd = dp[4]; 
    1256         delrho = dp[5]; 
    1257         bkg = dp[6]; 
    1258  
     1300        sldc = dp[5]; 
     1301        slds = dp[6]; 
     1302        bkg = dp[7]; 
     1303         
     1304        delrho = sldc-slds; 
    12591305        zz = (1.0/pd)*(1.0/pd) - 1.0; 
    1260  
     1306         
    12611307        lolim = radius*(1.0-range*pd);          //set the upper/lower limits to cover the distribution 
    1262         if(lolim<0) { 
    1263                 lolim = 0; 
     1308        if(lolim<0.0) { 
     1309                lolim = 0.0; 
    12641310        } 
    12651311        if(pd>0.3) { 
     
    12671313        } 
    12681314        uplim = radius*(1.0+range*pd); 
    1269  
     1315         
    12701316        for(i=0;i<nord;i++) { 
    12711317                //zi = ( Gauss20Z[i]*(uplim-lolim) + uplim + lolim )/2.0; 
     
    12751321                summ += yyy; 
    12761322        } 
    1277  
     1323         
    12781324        answer = (uplim-lolim)/2.0*summ; 
    12791325        //normalize by average cylinder volume (second moment), using the average radius 
    12801326        Vpoly = Pi*radius*radius*length*(zz+2.0)/(zz+1.0); 
    12811327        answer /= Vpoly; 
    1282  
     1328         
    12831329        answer *=delrho*delrho; 
    1284  
     1330         
    12851331        //convert to [cm-1] 
    12861332        answer *= 1.0e8; 
     
    12891335        // add in the background 
    12901336        answer += bkg; 
    1291  
     1337         
    12921338        return answer; 
    12931339} 
     
    13001346        double p1,p2,p1short,p2short,q0,qconnect; 
    13011347        double C,epsilon,ans,q0short,Sexvmodify,pi; 
    1302  
     1348         
    13031349        pi = 4.0*atan(1.0); 
    1304  
     1350         
    13051351        p1 = 4.12; 
    13061352        p2 = 4.42; 
     
    13091355        q0 = 3.1; 
    13101356        qconnect = q0/b; 
    1311         // 
     1357        //       
    13121358        q0short = fmax(1.9/sqrt(Rgsquareshort(q,L,b)),3.0); 
    1313  
     1359         
    13141360        // 
    13151361        if(L/b > 10.0) { 
     
    13211367        } 
    13221368        // 
    1323  
     1369         
    13241370        if( L > 4*b ) { // Longer Chains 
    13251371                if (q*b <= 3.1) {               //Modified by Yun on Oct. 15, 
     
    13281374                } else { //q(i)*b > 3.1 
    13291375                        ans = a1long(q, L, b, p1, p2, q0)/(pow((q*b),p1)) + a2long(q, L, b, p1, p2, q0)/(pow((q*b),p2)) + pi/(q*L); 
    1330                 } 
     1376                }  
    13311377        } else { //L <= 4*b Shorter Chains 
    13321378                if (q*b <= fmax(1.9/sqrt(Rgsquareshort(q,L,b)),3.0) ) { 
     
    13401386                } 
    13411387        } 
    1342  
     1388         
    13431389        return(ans); 
    13441390        //return(a2long(q, L, b, p1, p2, q0)); 
     
    13511397    double yy; 
    13521398    yy = 0.5*(1 + tanh((x - 1.523)/0.1477)); 
    1353  
     1399         
    13541400    return (yy); 
    13551401} 
     
    13601406{ 
    13611407    double yy; 
    1362  
     1408         
    13631409    yy = Rgsquareshort(q,L,b)*q*q; 
    1364  
     1410     
    13651411    return (yy); 
    13661412} 
     
    13801426static double 
    13811427Rgsquarezero(double q, double L, double b) 
    1382 { 
     1428{     
    13831429    double yy; 
    13841430    yy = (L*b/6.0) * (1.0 - 1.5*(b/L) + 1.5*pow((b/L),2) - 0.75*pow((b/L),3)*(1.0 - exp(-2.0*(L/b)))); 
    1385  
     1431     
    13861432    return (yy); 
    13871433} 
     
    13901436static double 
    13911437Rgsquareshort(double q, double L, double b) 
    1392 { 
     1438{     
    13931439    double yy; 
    13941440    yy = AlphaSquare(L/b) * Rgsquarezero(q,L,b); 
    1395  
     1441     
    13961442    return (yy); 
    13971443} 
     
    14031449    double yy; 
    14041450    yy = AlphaSquare(L/b)*L*b/6.0; 
    1405  
     1451     
    14061452    return (yy); 
    14071453} 
     
    14101456static double 
    14111457AlphaSquare(double x) 
    1412 { 
     1458{     
    14131459    double yy; 
    14141460    yy = pow( (1.0 + (x/3.12)*(x/3.12) + (x/8.67)*(x/8.67)*(x/8.67)),(0.176/3.0) ); 
    1415  
     1461         
    14161462    return (yy); 
    14171463} 
     
    14201466static double 
    14211467miu(double x) 
    1422 { 
     1468{     
    14231469    double yy; 
    14241470    yy = (1.0/8.0)*(9.0*x - 2.0 + 2.0*log(1.0 + x)/x)*exp(1.0/2.565*(1.0/x + (1.0 - 1.0/(x*x))*log(1.0 + x))); 
    1425  
     1471     
    14261472    return (yy); 
    14271473} 
     
    14301476static double 
    14311477Sdebye(double q, double L, double b) 
    1432 { 
     1478{     
    14331479    double yy; 
    14341480    yy = 2.0*(exp(-u_WR(q,L,b)) + u_WR(q,L,b) -1.0)/(pow((u_WR(q,L,b)),2)); 
    1435  
     1481         
    14361482    return (yy); 
    14371483} 
     
    14401486static double 
    14411487Sdebye1(double q, double L, double b) 
    1442 { 
     1488{     
    14431489    double yy; 
    14441490    yy = 2.0*(exp(-u1(q,L,b)) + u1(q,L,b) -1.0)/( pow((u1(q,L,b)),2.0) ); 
    1445  
     1491     
    14461492    return (yy); 
    14471493} 
     
    14501496static double 
    14511497Sexv(double q, double L, double b) 
    1452 { 
     1498{     
    14531499    double yy,C1,C2,C3,miu,Rg2; 
    14541500    C1=1.22; 
     
    14561502    C3=-1.651; 
    14571503    miu = 0.585; 
    1458  
     1504         
    14591505    Rg2 = Rgsquare(q,L,b); 
    1460  
     1506     
    14611507    yy = (1.0 - w_WR(q*sqrt(Rg2)))*Sdebye(q,L,b) + w_WR(q*sqrt(Rg2))*(C1*pow((q*sqrt(Rg2)),(-1.0/miu)) +  C2*pow((q*sqrt(Rg2)),(-2.0/miu)) +    C3*pow((q*sqrt(Rg2)),(-3.0/miu))); 
    1462  
     1508     
    14631509    return (yy); 
    14641510} 
     
    14671513static double 
    14681514Sexvnew(double q, double L, double b) 
    1469 { 
     1515{     
    14701516    double yy,C1,C2,C3,miu; 
    14711517    double del=1.05,C_star2,Rg2; 
    1472  
     1518     
    14731519    C1=1.22; 
    14741520    C2=0.4288; 
    14751521    C3=-1.651; 
    14761522    miu = 0.585; 
    1477  
     1523         
    14781524    //calculating the derivative to decide on the corection (cutoff) term? 
    14791525    // I have modified this from WRs original code 
    1480  
     1526     
    14811527    if( (Sexv(q*del,L,b)-Sexv(q,L,b))/(q*del - q) >= 0.0 ) { 
    14821528        C_star2 = 0.0; 
     
    14841530        C_star2 = 1.0; 
    14851531    } 
    1486  
     1532         
    14871533    Rg2 = Rgsquare(q,L,b); 
    1488  
     1534     
    14891535        yy = (1.0 - w_WR(q*sqrt(Rg2)))*Sdebye(q,L,b) + C_star2*w_WR(q*sqrt(Rg2))*(C1*pow((q*sqrt(Rg2)),(-1.0/miu)) + C2*pow((q*sqrt(Rg2)),(-2.0/miu)) + C3*pow((q*sqrt(Rg2)),(-3.0/miu))); 
    1490  
     1536         
    14911537    return (yy); 
    14921538} 
     
    14951541static double 
    14961542a2short(double q, double L, double b, double p1short, double p2short, double q0) 
    1497 { 
     1543{     
    14981544    double yy,Rg2_sh; 
    14991545    double t1,E,Rg2_sh2,Et1,Emt1,q02,q0p; 
    15001546    double pi; 
    1501  
     1547         
    15021548    E = 2.718281828459045091; 
    15031549        pi = 4.0*atan(1.0); 
     
    15061552    t1 = ((q0*q0*Rg2_sh)/(b*b)); 
    15071553    Et1 = pow(E,t1); 
    1508     Emt1 =pow(E,-t1); 
     1554    Emt1 =pow(E,-t1);  
    15091555    q02 = q0*q0; 
    15101556    q0p = pow(q0,(-4.0 + p2short) ); 
    1511  
     1557     
    15121558    //E is the number e 
    15131559    yy = ((-(1.0/(L*((p1short - p2short))*Rg2_sh2)*((b*Emt1*q0p*((8.0*b*b*b*L - 8.0*b*b*b*Et1*L - 2.0*b*b*b*L*p1short + 2.0*b*b*b*Et1*L*p1short + 4.0*b*L*q02*Rg2_sh + 4.0*b*Et1*L*q02*Rg2_sh - 2.0*b*Et1*L*p1short*q02*Rg2_sh - Et1*pi*q02*q0*Rg2_sh2 + Et1*p1short*pi*q02*q0*Rg2_sh2))))))); 
    1514  
     1560         
    15151561    return (yy); 
    15161562} 
     
    15191565static double 
    15201566a1short(double q, double L, double b, double p1short, double p2short, double q0) 
    1521 { 
     1567{     
    15221568    double yy,Rg2_sh; 
    15231569    double t1,E,Rg2_sh2,Et1,Emt1,q02,q0p,b3; 
    15241570        double pi; 
    1525  
     1571     
    15261572    E = 2.718281828459045091; 
    15271573        pi = 4.0*atan(1.0); 
     
    15311577    t1 = ((q0*q0*Rg2_sh)/(b*b)); 
    15321578    Et1 = pow(E,t1); 
    1533     Emt1 =pow(E,-t1); 
     1579    Emt1 =pow(E,-t1);  
    15341580    q02 = q0*q0; 
    15351581    q0p = pow(q0,(-4.0 + p1short) ); 
     
    15471593    double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,pi; 
    15481594    double E,b2,b3,b4,q02,q03,q04,q05,Rg22; 
    1549  
     1595     
    15501596    pi = 4.0*atan(1.0); 
    15511597    E = 2.718281828459045091; 
     
    15551601        C = 1.0; 
    15561602    } 
    1557  
     1603         
    15581604    C1 = 1.22; 
    15591605    C2 = 0.4288; 
     
    15621608    C5 = 0.1477; 
    15631609    miu = 0.585; 
    1564  
     1610         
    15651611    Rg2 = Rgsquare(q,L,b); 
    15661612    Rg22 = Rg2*Rg2; 
     
    15721618    q04 = q03*q0; 
    15731619    q05 = q04*q0; 
    1574  
     1620     
    15751621    t1 = (1.0/(b* p1*pow(q0,((-1.0) - p1 - p2)) - b*p2*pow(q0,((-1.0) - p1 - p2)) )); 
    15761622 
     
    15811627    t4 = (b4*sqrt(Rg2)*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*pow(sech_WR(((-C4) + (sqrt(Rg2)*q0)/b)/C5),2))/(C5*q04*Rg22); 
    15821628 
    1583     t5 = (2.0*b4*(((2*q0*Rg2)/b - (2.0*pow(E,(-((q02*Rg2)/b2)))*q0*Rg2)/b))*((1.0 + 1.0/2.0*(((-1.0) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))))/(q04*Rg22); 
     1629    t5 = (2.0*b4*(((2.0*q0*Rg2)/b - (2.0*pow(E,(-((q02*Rg2)/b2)))*q0*Rg2)/b))*((1.0 + 1.0/2.0*(((-1.0) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))))/(q04*Rg22); 
    15841630 
    15851631    t6 = (8.0*b4*b*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*((1.0 + 1.0/2.0*(((-1) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))))/(q05*Rg22); 
     
    16021648static double 
    16031649sech_WR(double x) 
    1604 { 
     1650{        
    16051651        return(1/cosh(x)); 
    16061652} 
     
    16091655static double 
    16101656a1long(double q, double L, double b, double p1, double p2, double q0) 
    1611 { 
     1657{     
    16121658    double yy,C,C1,C2,C3,C4,C5,miu,Rg2; 
    16131659    double t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15; 
    16141660    double E,pi; 
    16151661    double b2,b3,b4,q02,q03,q04,q05,Rg22; 
    1616  
     1662         
    16171663    pi = 4.0*atan(1.0); 
    16181664    E = 2.718281828459045091; 
    1619  
     1665     
    16201666    if( L/b > 10.0) { 
    16211667        C = 3.06/pow((L/b),0.44); 
     
    16231669        C = 1.0; 
    16241670    } 
    1625  
     1671         
    16261672    C1 = 1.22; 
    16271673    C2 = 0.4288; 
     
    16301676    C5 = 0.1477; 
    16311677    miu = 0.585; 
    1632  
     1678         
    16331679    Rg2 = Rgsquare(q,L,b); 
    16341680    Rg22 = Rg2*Rg2; 
     
    16401686    q04 = q03*q0; 
    16411687    q05 = q04*q0; 
    1642  
     1688     
    16431689    t1 = (b*C*((4.0/15.0 - pow(E,(-((q02*Rg2)/b2)))*((11.0/15.0 + (7.0*b2)/(15.0*q02*Rg2))) + (7.0*b2)/(15.0*q02*Rg2)))); 
    1644  
     1690     
    16451691    t2 = (2.0*b4*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*((1.0 + 1.0/2.0*(((-1.0) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5)))))); 
    1646  
     1692     
    16471693    t3 = ((C3*pow((((sqrt(Rg2)*q0)/b)),((-3.0)/miu)) + C2*pow((((sqrt(Rg2)*q0)/b)),((-2.0)/miu)) + C1*pow((((sqrt(Rg2)*q0)/b)),((-1.0)/miu)))); 
    1648  
     1694     
    16491695    t4 = ((1.0 + tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))); 
    1650  
     1696         
    16511697    t5 = (1.0/(b*p1*pow(q0,((-1.0) - p1 - p2)) - b*p2*pow(q0,((-1.0) - p1 - p2)))); 
    1652  
     1698     
    16531699    t6 = (b*C*(((-((14.0*b3)/(15.0*q03*Rg2))) + (14.0*b3*pow(E,(-((q02*Rg2)/b2))))/(15.0*q03*Rg2) + (2.0*pow(E,(-((q02*Rg2)/b2)))*q0*((11.0/15.0 + (7.0*b2)/(15.0*q02*Rg2)))*Rg2)/b))); 
    1654  
     1700     
    16551701    t7 = (sqrt(Rg2)*((C3*pow((((sqrt(Rg2)*q0)/b)),((-3.0)/miu)) + C2*pow((((sqrt(Rg2)*q0)/b)),((-2.0)/miu)) + C1*pow((((sqrt(Rg2)*q0)/b)),((-1.0)/miu))))*pow(sech_WR(((-C4) + (sqrt(Rg2)*q0)/b)/C5),2)); 
    1656  
     1702     
    16571703    t8 = (b4*sqrt(Rg2)*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*pow(sech_WR(((-C4) + (sqrt(Rg2)*q0)/b)/C5),2)); 
    1658  
     1704     
    16591705    t9 = (2.0*b4*(((2.0*q0*Rg2)/b - (2.0*pow(E,(-((q02*Rg2)/b2)))*q0*Rg2)/b))*((1.0 + 1.0/2.0*(((-1.0) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5)))))); 
    1660  
     1706     
    16611707    t10 = (8.0*b4*b*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*((1.0 + 1.0/2.0*(((-1.0) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5)))))); 
    1662  
     1708     
    16631709    t11 = (((-((3.0*C3*sqrt(Rg2)*pow((((sqrt(Rg2)*q0)/b)),((-1.0) - 3.0/miu)))/miu)) - (2.0*C2*sqrt(Rg2)*pow((((sqrt(Rg2)*q0)/b)),((-1.0) - 2.0/miu)))/miu - (C1*sqrt(Rg2)*pow((((sqrt(Rg2)*q0)/b)),((-1.0) - 1.0/miu)))/miu)); 
    1664  
     1710     
    16651711    t12 = ((1.0 + tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))); 
    1666  
     1712     
    16671713    t13 = (b*C*((4.0/15.0 - pow(E,(-((q02*Rg2)/b2)))*((11.0/15.0 + (7.0*b2)/(15.0*q02* Rg2))) + (7.0*b2)/(15.0*q02*Rg2)))); 
    1668  
     1714     
    16691715    t14 = (2.0*b4*(((-1.0) + pow(E,(-((q02*Rg2)/b2))) + (q02*Rg2)/b2))*((1.0 + 1.0/2.0*(((-1.0) - tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5)))))); 
    1670  
     1716     
    16711717    t15 = ((C3*pow((((sqrt(Rg2)*q0)/b)),((-3.0)/miu)) + C2*pow((((sqrt(Rg2)*q0)/b)),((-2.0)/miu)) + C1*pow((((sqrt(Rg2)*q0)/b)),((-1.0)/miu)))); 
    1672  
    1673  
     1718         
     1719     
    16741720    yy = (pow(q0,p1)*(((-((b*pi)/(L*q0))) +t1/L +t2/(q04*Rg22) + 1.0/2.0*t3*t4)) + (t5*((pow(q0,(p1 - p2))*(((-pow(q0,(-p1)))*(((b2*pi)/(L*q02) +t6/L +t7/(2.0*C5) -t8/(C5*q04*Rg22) +t9/(q04*Rg22) -t10/(q05*Rg22) + 1.0/2.0*t11*t12)) - b*p1*pow(q0,((-1.0) - p1))*(((-((b*pi)/(L*q0))) +t13/L +t14/(q04*Rg22) + 1.0/2.0*t15*((1.0 + tanh(((-C4) + (sqrt(Rg2)*q0)/b)/C5))))))))))); 
    1675  
     1721         
    16761722    return (yy); 
    16771723} 
     
    16831729// 
    16841730//     FUNCTION gfn2:    CONTAINS F(Q,A,B,mu)**2  AS GIVEN 
    1685 //                       BY (53) AND (56,57) IN CHEN AND 
     1731//                       BY (53) AND (56,57) IN CHEN AND  
    16861732//                       KOTLARCHYK REFERENCE 
    16871733// 
     
    16951741 
    16961742        Pi = 4.0*atan(1.0); 
    1697  
     1743         
    16981744        pi43=4.0/3.0*Pi; 
    16991745        aa = crmaj; 
     
    17191765        gfn = gfnc+gfnt; 
    17201766        gfn2 = gfn*gfn; 
    1721  
     1767         
    17221768        return (gfn2); 
    17231769} 
     
    17291775// 
    17301776//       <OBLATE ELLIPSOID> 
    1731 // function gfn4 for oblate ellipsoids 
     1777// function gfn4 for oblate ellipsoids  
    17321778double 
    17331779gfn4(double xx, double crmaj, double crmin, double trmaj, double trmin, double delpc, double delps, double qq) 
     
    17601806        tgfn = gfnc+gfnt; 
    17611807        gfn4 = tgfn*tgfn; 
    1762  
     1808         
    17631809        return (gfn4); 
    17641810} 
     
    17691815    double Pq,vcyl,dl; 
    17701816    double Pi,qr; 
    1771  
     1817     
    17721818    Pi = 4.0*atan(1.0); 
    17731819    qr = q*radius; 
    1774  
     1820     
    17751821    Pq = Sk_WR(q,zi,lb);                //does not have cross section term 
    17761822    if (qr !=0){ 
    17771823        Pq *= (2.0*NR_BessJ1(qr)/qr)*(2.0*NR_BessJ1(qr)/qr); 
    1778     } //else Pk *=1; 
     1824    }  
    17791825    vcyl=Pi*radius*radius*zi; 
    17801826    Pq *= vcyl*vcyl; 
    1781  
     1827     
    17821828    dl = SchulzPoint_cpr(zi,length,zz); 
    1783     return (Pq*dl); 
    1784  
     1829    return (Pq*dl);      
     1830         
    17851831} 
    17861832 
     
    17901836    double Pq,vcyl,dr; 
    17911837    double Pi,qr; 
    1792  
     1838     
    17931839    Pi = 4.0*atan(1.0); 
    17941840    qr = q*zi; 
    1795  
     1841     
    17961842    Pq = Sk_WR(q,Lc,Lb);                //does not have cross section term 
    17971843    if (qr !=0){ 
     
    18011847    vcyl=Pi*zi*zi*Lc; 
    18021848    Pq *= vcyl*vcyl; 
    1803  
     1849     
    18041850    dr = SchulzPoint_cpr(zi,ravg,zz); 
    1805     return (Pq*dr); 
    1806  
     1851    return (Pq*dr);      
     1852         
    18071853} 
    18081854 
     
    18131859        double lolim,uplim,summ,yyy,zi; 
    18141860        int nord,i; 
    1815  
    1816         // set up the integration end points 
     1861         
     1862        // set up the integration end points  
    18171863        Pi = 4.0*atan(1.0); 
    18181864        nord = 76; 
    1819         lolim = 0; 
     1865        lolim = 0.0; 
    18201866        uplim = Pi/2.0; 
    18211867        halfheight = length/2.0; 
    1822  
     1868         
    18231869        summ = 0.0;                             // initialize integral 
    18241870        i=0; 
     
    18281874                summ += yyy; 
    18291875        } 
    1830  
     1876         
    18311877        // calculate value of integral to return 
    18321878        answer = (uplim-lolim)/2.0*summ; 
     
    18361882double 
    18371883CScyl(double qq, double rad, double radthick, double facthick, double rhoc, double rhos, double rhosolv, double length, double dum) 
    1838 { 
     1884{        
    18391885        // qq is the q-value for the calculation (1/A) 
    18401886        // radius is the core radius of the cylinder (A) 
    18411887        //  radthick and facthick are the radial and face layer thicknesses 
    18421888        // rho(n) are the respective SLD's 
    1843         // length is the *Half* CORE-LENGTH of the cylinder 
     1889        // length is the *Half* CORE-LENGTH of the cylinder  
    18441890        // dum is the dummy variable for the integration (theta) 
    18451891 
    18461892        double dr1,dr2,besarg1,besarg2,vol1,vol2,sinarg1,sinarg2,si1,si2,be1,be2,t1,t2,retval; 
    18471893        double Pi; 
    1848  
    1849         Pi = 4.0*atan(1.0); 
    1850  
     1894         
     1895        Pi = 4.0*atan(1.0);  
     1896         
    18511897        dr1 = rhoc-rhos; 
    18521898        dr2 = rhos-rhosolv; 
    18531899        vol1 = Pi*rad*rad*(2.0*length); 
    18541900        vol2 = Pi*(rad+radthick)*(rad+radthick)*(2.0*length+2.0*facthick); 
    1855  
     1901         
    18561902        besarg1 = qq*rad*sin(dum); 
    18571903        besarg2 = qq*(rad+radthick)*sin(dum); 
     
    18731919                si1 = sin(sinarg1)/sinarg1; 
    18741920        } 
    1875         if (besarg2 == 0.0){ 
     1921        if (sinarg2 == 0.0){ 
    18761922                si2 = 1.0; 
    18771923        }else{ 
     
    18841930        retval = ((t1+t2)*(t1+t2))*sin(dum); 
    18851931        return (retval); 
    1886  
     1932     
    18871933} 
    18881934 
     
    18941940    double dr1,dr2,besarg1,besarg2,vol1,vol2,sinarg1,sinarg2,si1,si2,be1,be2,t1,t2,retval; 
    18951941    double Pi; 
    1896  
     1942     
    18971943    Pi = 4.0*atan(1.0); 
    1898  
     1944     
    18991945    dr1 = rhoc-rhos; 
    19001946    dr2 = rhos-rhosolv; 
    19011947    vol1 = Pi*rcore*rcore*(2.0*length); 
    19021948    vol2 = Pi*(rcore+thick)*(rcore+thick)*(2.0*length+2.0*thick); 
    1903  
     1949     
    19041950    besarg1 = qq*rcore*sin(dum); 
    19051951    besarg2 = qq*(rcore+thick)*sin(dum); 
     
    19221968                si1 = sin(sinarg1)/sinarg1; 
    19231969        } 
    1924         if (besarg2 == 0.0){ 
     1970        if (sinarg2 == 0.0){ 
    19251971                si2 = 1.0; 
    19261972        }else{ 
     
    19321978 
    19331979    retval = ((t1+t2)*(t1+t2))*sin(dum); 
    1934  
     1980         
    19351981    return (retval); 
    19361982} 
     
    19391985Cyl_PolyLenKernel(double q, double radius, double len_avg, double zz, double delrho, double dumLen) 
    19401986{ 
    1941  
     1987         
    19421988    double halfheight,uplim,lolim,zi,summ,yyy,Pi; 
    19431989    double answer,dr,Vcyl; 
    19441990    int i,nord; 
    1945  
     1991     
    19461992    Pi = 4.0*atan(1.0); 
    1947     lolim = 0; 
     1993    lolim = 0.0; 
    19481994    uplim = Pi/2.0; 
    19491995    halfheight = dumLen/2.0; 
    19501996    nord=20; 
    19511997    summ = 0.0; 
    1952  
     1998     
    19531999    //do the cylinder orientational average 
    19542000    for(i=0;i<nord;i++) { 
     
    19642010    Vcyl = Pi*radius*radius*dumLen; 
    19652011    answer *= Vcyl*Vcyl; 
    1966  
     2012     
    19672013    dr = SchulzPoint_cpr(dumLen,len_avg,zz); 
    19682014    return(dr*answer); 
     
    19722018double 
    19732019Stackdisc_kern(double qq, double rcore, double rhoc, double rhol, double rhosolv, double length, double thick, double dum, double gsd, double d, double N) 
    1974 { 
     2020{                
    19752021        // qq is the q-value for the calculation (1/A) 
    19762022        // rcore is the core radius of the cylinder (A) 
     
    19832029        double Pi; 
    19842030        int kk; 
    1985  
     2031         
    19862032        Pi = 4.0*atan(1.0); 
    1987  
     2033         
    19882034        dr1 = rhoc-rhosolv; 
    19892035        dr2 = rhol-rhosolv; 
    19902036        area = Pi*rcore*rcore; 
    19912037        totald=2.0*(thick+length); 
    1992  
     2038         
    19932039        besarg1 = qq*rcore*sin(dum); 
    19942040        besarg2 = qq*rcore*sin(dum); 
    1995  
     2041         
    19962042        sinarg1 = qq*length*cos(dum); 
    19972043        sinarg2 = qq*(length+thick)*cos(dum); 
     
    20122058                si1 = sin(sinarg1)/sinarg1; 
    20132059        } 
    2014         if (besarg2 == 0.0){ 
     2060        if (sinarg2 == 0.0){ 
    20152061                si2 = 1.0; 
    20162062        }else{ 
     
    20222068 
    20232069        retval =((t1+t2)*(t1+t2))*sin(dum); 
    2024  
     2070         
    20252071        // loop for the structure facture S(q) 
    20262072        sqq=0.0; 
     
    20282074                dexpt=qq*cos(dum)*qq*cos(dum)*d*d*gsd*gsd*kk/2.0; 
    20292075                sqq=sqq+(N-kk)*cos(qq*cos(dum)*d*kk)*exp(-1.*dexpt); 
    2030         } 
    2031  
     2076        }                        
     2077         
    20322078        // end of loop for S(q) 
    20332079        sqq=1.0+2.0*sqq/N; 
    2034  
    20352080        retval *= sqq; 
    2036  
     2081     
    20372082        return(retval); 
    20382083} 
     
    20422087Cyl_PolyRadKernel(double q, double radius, double length, double zz, double delrho, double dumRad) 
    20432088{ 
    2044  
     2089         
    20452090    double halfheight,uplim,lolim,zi,summ,yyy,Pi; 
    20462091    double answer,dr,Vcyl; 
    20472092    int i,nord; 
    2048  
     2093     
    20492094    Pi = 4.0*atan(1.0); 
    2050     lolim = 0; 
     2095    lolim = 0.0; 
    20512096    uplim = Pi/2.0; 
    20522097    halfheight = length/2.0; 
     
    20542099    nord=76; 
    20552100    summ = 0.0; 
    2056  
     2101     
    20572102    //do the cylinder orientational average 
    20582103        //    for(i=0;i<nord;i++) { 
     
    20732118    Vcyl = Pi*dumRad*dumRad*length; 
    20742119    answer *= Vcyl*Vcyl; 
    2075  
     2120     
    20762121    dr = SchulzPoint_cpr(dumRad,radius,zz); 
    20772122    return(dr*answer); 
     
    20822127{ 
    20832128    double dr; 
    2084  
     2129     
    20852130    dr = zz*log(dumRad) - gammaln(zz+1.0) + (zz+1.0)*log((zz+1.0)/radius)-(dumRad/radius*(zz+1.0)); 
    20862131    return(exp(dr)); 
     
    20952140                0.1208650973866179e-2,-0.5395239384953e-5}; 
    20962141        int j; 
    2097  
     2142         
    20982143        y=x=xx; 
    20992144        tmp=x+5.5; 
     
    21092154{ 
    21102155    double arg,nu,retval;               //local variables 
    2111  
     2156         
    21122157    nu = nua/a; 
    2113     arg = qq*a*sqrt(1+dum*dum*(nu*nu-1)); 
     2158    arg = qq*a*sqrt(1.0+dum*dum*(nu*nu-1.0)); 
    21142159    if (arg == 0.0){ 
    21152160        retval =1.0/3.0; 
     
    21272172{ 
    21282173    double gamma,arg1,arg2,lam1,lam2,psi,sinarg,t2,retval;              //local variables 
    2129  
     2174     
    21302175    gamma = rcore/rshell; 
    2131     arg1 = qq*rshell*sqrt(1-dum*dum);           //1=shell (outer radius) 
    2132     arg2 = qq*rcore*sqrt(1-dum*dum);                    //2=core (inner radius) 
     2176    arg1 = qq*rshell*sqrt(1.0-dum*dum);         //1=shell (outer radius) 
     2177    arg2 = qq*rcore*sqrt(1.0-dum*dum);                  //2=core (inner radius) 
    21332178    if (arg1 == 0.0){ 
    21342179        lam1 = 1.0; 
     
    21512196 
    21522197    retval = psi*psi*t2*t2; 
    2153  
     2198     
    21542199    return(retval); 
    21552200}//Function HolCylKernel() 
     
    21602205    // mu passed in is really mu*sqrt(1-sig^2) 
    21612206    double arg1,arg2,Pi,tmp1,tmp2;                      //local variables 
    2162  
     2207         
    21632208    Pi = 4.0*atan(1.0); 
    2164  
     2209     
    21652210    //handle arg=0 separately, as sin(t)/t -> 1 as t->0 
    21662211    arg1 = (mu/2.0)*cos(Pi*uu/2.0); 
     
    21772222                tmp2 = sin(arg2)*sin(arg2)/arg2/arg2; 
    21782223    } 
    2179  
     2224         
    21802225    return (tmp1*tmp2); 
    2181  
     2226         
    21822227}//Function PPKernel() 
    21832228 
     
    21862231TriaxialKernel(double q, double aa, double bb, double cc, double dx, double dy) 
    21872232{ 
    2188  
     2233         
    21892234    double arg,val,pi;                  //local variables 
    2190  
     2235         
    21912236    pi = 4.0*atan(1.0); 
    2192  
     2237     
    21932238    arg = aa*aa*cos(pi*dx/2)*cos(pi*dx/2); 
    21942239    arg += bb*bb*sin(pi*dx/2)*sin(pi*dx/2)*(1-dy*dy); 
     
    22012246    } 
    22022247    return (val); 
    2203  
     2248         
    22042249}//Function TriaxialKernel() 
    22052250 
     
    22082253CylKernel(double qq, double rr,double h, double theta) 
    22092254{ 
    2210  
     2255         
    22112256        // qq is the q-value for the calculation (1/A) 
    22122257        // rr is the radius of the cylinder (A) 
     
    22192264    siarg = qq * h * cos(theta); 
    22202265    bj =NR_BessJ1(besarg); 
    2221  
     2266         
    22222267        //* Computing 2nd power */ 
    22232268    d1 = sin(siarg); 
     
    22452290 
    22462291    return (retval); 
    2247  
     2292         
    22482293}//Function CylKernel() 
    22492294 
     
    22512296EllipCylKernel(double qq, double ra,double nu, double theta) 
    22522297{ 
    2253         //this is the function LAMBDA1^2 in Feigin's notation 
     2298        //this is the function LAMBDA1^2 in Feigin's notation    
    22542299        // qq is the q-value for the calculation (1/A) 
    22552300        // ra is the transformed radius"a" in Feigin's notation 
    22562301        // nu is the ratio (major radius)/(minor radius) of the Ellipsoid [=] --- 
    22572302        // theta is the dummy variable of the integration 
    2258  
    2259         double retval,arg;               //Local variables 
    2260  
    2261         arg = qq*ra*sqrt((1+nu*nu)/2+(1-nu*nu)*cos(theta)/2); 
     2303         
     2304        double retval,arg;               //Local variables  
     2305         
     2306        arg = qq*ra*sqrt((1.0+nu*nu)/2+(1.0-nu*nu)*cos(theta)/2); 
    22622307        if (arg == 0.0){ 
    22632308                retval = 1.0; 
     
    22682313        //square it 
    22692314        retval *= retval; 
    2270  
     2315         
    22712316    return(retval); 
    2272  
     2317         
    22732318}//Function EllipCylKernel() 
    22742319 
     
    22772322        double ax,z; 
    22782323        double xx,y,ans,ans1,ans2; 
    2279  
     2324         
    22802325        if ((ax=fabs(x)) < 8.0) { 
    22812326                y=x*x; 
     
    22972342                if (x < 0.0) ans = -ans; 
    22982343        } 
    2299  
     2344         
    23002345        return(ans); 
    23012346} 
     2347 
     2348/*      Lamellar_ParaCrystal - Pedersen's model 
     2349 
     2350*/ 
     2351double 
     2352Lamellar_ParaCrystal(double w[], double q) 
     2353{ 
     2354//       Input (fitting) variables are: 
     2355        //[0] scale factor 
     2356        //[1]   thickness 
     2357        //[2]   number of layers 
     2358        //[3]   spacing between layers 
     2359        //[4]   polydispersity of spacing 
     2360        //[5] SLD lamellar 
     2361        //[6] SLD solvent 
     2362        //[7] incoherent background 
     2363//      give them nice names 
     2364        double inten,qval,scale,th,nl,davg,pd,contr,bkg,xn; 
     2365        double xi,ww,Pbil,Znq,Snq,an,sldLayer,sldSolvent,pi; 
     2366        long n1,n2; 
     2367         
     2368        pi = 4.0*atan(1.0); 
     2369        scale = w[0]; 
     2370        th = w[1]; 
     2371        nl = w[2]; 
     2372        davg = w[3]; 
     2373        pd = w[4]; 
     2374        sldLayer = w[5]; 
     2375        sldSolvent = w[6]; 
     2376        bkg = w[7]; 
     2377         
     2378        contr = w[5] - w[6]; 
     2379        qval = q; 
     2380                 
     2381        //get the fractional part of nl, to determine the "mixing" of N's 
     2382         
     2383        n1 = trunc(nl);         //rounds towards zero 
     2384        n2 = n1 + 1; 
     2385        xn = (double)n2 - nl;                   //fractional contribution of n1 
     2386         
     2387        ww = exp(-qval*qval*pd*pd*davg*davg/2.0); 
     2388         
     2389        //calculate the n1 contribution 
     2390        an = paraCryst_an(ww,qval,davg,n1); 
     2391        Snq = paraCryst_sn(ww,qval,davg,n1,an); 
     2392         
     2393        Znq = xn*Snq; 
     2394         
     2395        //calculate the n2 contribution 
     2396        an = paraCryst_an(ww,qval,davg,n2); 
     2397        Snq = paraCryst_sn(ww,qval,davg,n2,an); 
     2398         
     2399        Znq += (1.0-xn)*Snq; 
     2400         
     2401        //and the independent contribution 
     2402        Znq += (1.0-ww*ww)/(1.0+ww*ww-2.0*ww*cos(qval*davg)); 
     2403         
     2404        //the limit when NL approaches infinity 
     2405//      Zq = (1-ww^2)/(1+ww^2-2*ww*cos(qval*davg)) 
     2406         
     2407        xi = th/2.0;            //use 1/2 the bilayer thickness 
     2408        Pbil = (sin(qval*xi)/(qval*xi))*(sin(qval*xi)/(qval*xi)); 
     2409         
     2410        inten = 2.0*pi*contr*contr*Pbil*Znq/(qval*qval); 
     2411        inten *= 1.0e8; 
     2412         
     2413        return(scale*inten+bkg); 
     2414} 
     2415 
     2416// functions for the lamellar paracrystal model 
     2417double 
     2418paraCryst_sn(double ww, double qval, double davg, long nl, double an) { 
     2419         
     2420        double Snq; 
     2421         
     2422        Snq = an/( (double)nl*pow((1.0+ww*ww-2.0*ww*cos(qval*davg)),2) ); 
     2423         
     2424        return(Snq); 
     2425} 
     2426 
     2427 
     2428double 
     2429paraCryst_an(double ww, double qval, double davg, long nl) { 
     2430         
     2431        double an; 
     2432         
     2433        an = 4.0*ww*ww - 2.0*(ww*ww*ww+ww)*cos(qval*davg); 
     2434        an -= 4.0*pow(ww,(nl+2))*cos((double)nl*qval*davg); 
     2435        an += 2.0*pow(ww,(nl+3))*cos((double)(nl-1)*qval*davg); 
     2436        an += 2.0*pow(ww,(nl+1))*cos((double)(nl+1)*qval*davg); 
     2437         
     2438        return(an); 
     2439} 
     2440 
     2441 
     2442/*      Spherocylinder  : 
     2443 
     2444Uses 76 pt Gaussian quadrature for both integrals 
     2445*/ 
     2446double 
     2447Spherocylinder(double w[], double x) 
     2448{ 
     2449        int i,j; 
     2450        double Pi; 
     2451        double scale,contr,bkg,sldc,slds; 
     2452        double len,rad,hDist,endRad; 
     2453        int nordi=76;                   //order of integration 
     2454        int nordj=76; 
     2455        double va,vb;           //upper and lower integration limits 
     2456        double summ,zi,yyy,answer;                      //running tally of integration 
     2457        double summj,vaj,vbj,zij;                       //for the inner integration 
     2458        double SphCyl_tmp[7],arg1,arg2,inner,be; 
     2459         
     2460         
     2461        scale = w[0]; 
     2462        rad = w[1]; 
     2463        len = w[2]; 
     2464        sldc = w[3]; 
     2465        slds = w[4]; 
     2466        bkg = w[5]; 
     2467         
     2468        SphCyl_tmp[0] = w[0]; 
     2469        SphCyl_tmp[1] = w[1]; 
     2470        SphCyl_tmp[2] = w[2]; 
     2471        SphCyl_tmp[3] = w[1];           //end radius is same as cylinder radius 
     2472        SphCyl_tmp[4] = w[3]; 
     2473        SphCyl_tmp[5] = w[4]; 
     2474        SphCyl_tmp[6] = w[5]; 
     2475         
     2476        hDist = 0;              //by definition for this model 
     2477        endRad = rad; 
     2478         
     2479        contr = sldc-slds; 
     2480         
     2481        Pi = 4.0*atan(1.0); 
     2482        va = 0.0; 
     2483        vb = Pi/2.0;            //orintational average, outer integral 
     2484        vaj = -1.0*hDist/endRad; 
     2485        vbj = 1.0;              //endpoints of inner integral 
     2486 
     2487        summ = 0.0;                     //initialize intergral 
     2488 
     2489        for(i=0;i<nordi;i++) { 
     2490                //setup inner integral over the ellipsoidal cross-section 
     2491                summj=0.0; 
     2492                zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;             //the "theta" dummy 
     2493                 
     2494                for(j=0;j<nordj;j++) { 
     2495                        //20 gauss points for the inner integral 
     2496                        zij = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0;                //the "t" dummy 
     2497                        yyy = Gauss76Wt[j] * SphCyl_kernel(SphCyl_tmp,x,zij,zi); 
     2498                        summj += yyy; 
     2499                } 
     2500                //now calculate the value of the inner integral 
     2501                inner = (vbj-vaj)/2.0*summj; 
     2502                inner *= 4.0*Pi*endRad*endRad*endRad; 
     2503                 
     2504                //now calculate outer integrand 
     2505                arg1 = x*len/2.0*cos(zi); 
     2506                arg2 = x*rad*sin(zi); 
     2507                yyy = inner; 
     2508 
     2509                if(arg2 == 0) { 
     2510                        be = 0.5; 
     2511                } else { 
     2512                        be = NR_BessJ1(arg2)/arg2; 
     2513                } 
     2514                 
     2515                if(arg1 == 0.0) {               //limiting value of sinc(0) is 1; sinc is not defined in math.h 
     2516                        yyy += Pi*rad*rad*len*2.0*be; 
     2517                } else { 
     2518                        yyy += Pi*rad*rad*len*sin(arg1)/arg1*2.0*be; 
     2519                } 
     2520                yyy *= yyy; 
     2521                yyy *= sin(zi);         // = |A(q)|^2*sin(theta) 
     2522                yyy *= Gauss76Wt[i]; 
     2523                summ += yyy; 
     2524        }               //final scaling is done at the end of the function, after the NT_FP64 case 
     2525         
     2526        answer = (vb-va)/2.0*summ; 
     2527 
     2528        answer /= Pi*rad*rad*len + Pi*4.0*endRad*endRad*endRad/3.0;             //divide by volume 
     2529        answer *= 1.0e8;                //convert to cm^-1 
     2530        answer *= contr*contr; 
     2531        answer *= scale; 
     2532        answer += bkg; 
     2533                 
     2534        return answer; 
     2535} 
     2536 
     2537 
     2538// inner integral of the sphereocylinder model, special case of hDist = 0 
     2539// 
     2540double 
     2541SphCyl_kernel(double w[], double x, double tt, double theta) { 
     2542 
     2543        double val,arg1,arg2; 
     2544        double scale,bkg,sldc,slds; 
     2545        double len,rad,hDist,endRad,be; 
     2546        scale = w[0]; 
     2547        rad = w[1]; 
     2548        len = w[2]; 
     2549        endRad = w[3]; 
     2550        sldc = w[4]; 
     2551        slds = w[5]; 
     2552        bkg = w[6]; 
     2553         
     2554        hDist = 0.0; 
     2555                 
     2556        arg1 = x*cos(theta)*(endRad*tt+hDist+len/2.0); 
     2557        arg2 = x*endRad*sin(theta)*sqrt(1.0-tt*tt); 
     2558         
     2559        if(arg2 == 0) { 
     2560                be = 0.5; 
     2561        } else { 
     2562                be = NR_BessJ1(arg2)/arg2; 
     2563        } 
     2564        val = cos(arg1)*(1.0-tt*tt)*be; 
     2565         
     2566        return(val); 
     2567} 
     2568 
     2569 
     2570/*      Convex Lens  : special case where L ~ 0 and hDist < 0 
     2571 
     2572Uses 76 pt Gaussian quadrature for both integrals 
     2573*/ 
     2574double 
     2575ConvexLens(double w[], double x) 
     2576{ 
     2577        int i,j; 
     2578        double Pi; 
     2579        double scale,contr,bkg,sldc,slds; 
     2580        double len,rad,hDist,endRad; 
     2581        int nordi=76;                   //order of integration 
     2582        int nordj=76; 
     2583        double va,vb;           //upper and lower integration limits 
     2584        double summ,zi,yyy,answer;                      //running tally of integration 
     2585        double summj,vaj,vbj,zij;                       //for the inner integration 
     2586        double CLens_tmp[7],arg1,arg2,inner,hh,be; 
     2587         
     2588         
     2589        scale = w[0]; 
     2590        rad = w[1]; 
     2591//      len = w[2] 
     2592        endRad = w[2]; 
     2593        sldc = w[3]; 
     2594        slds = w[4]; 
     2595        bkg = w[5]; 
     2596         
     2597        len = 0.01; 
     2598         
     2599        CLens_tmp[0] = w[0]; 
     2600        CLens_tmp[1] = w[1]; 
     2601        CLens_tmp[2] = len;                     //length is some small number, essentially zero 
     2602        CLens_tmp[3] = w[2]; 
     2603        CLens_tmp[4] = w[3]; 
     2604        CLens_tmp[5] = w[4]; 
     2605        CLens_tmp[6] = w[5]; 
     2606                 
     2607        hDist = -1.0*sqrt(fabs(endRad*endRad-rad*rad));         //by definition for this model 
     2608         
     2609        contr = sldc-slds; 
     2610         
     2611        Pi = 4.0*atan(1.0); 
     2612        va = 0.0; 
     2613        vb = Pi/2.0;            //orintational average, outer integral 
     2614        vaj = -1.0*hDist/endRad; 
     2615        vbj = 1.0;              //endpoints of inner integral 
     2616 
     2617        summ = 0.0;                     //initialize intergral 
     2618 
     2619        for(i=0;i<nordi;i++) { 
     2620                //setup inner integral over the ellipsoidal cross-section 
     2621                summj=0.0; 
     2622                zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;             //the "theta" dummy 
     2623                 
     2624                for(j=0;j<nordj;j++) { 
     2625                        //20 gauss points for the inner integral 
     2626                        zij = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0;                //the "t" dummy 
     2627                        yyy = Gauss76Wt[j] * ConvLens_kernel(CLens_tmp,x,zij,zi); 
     2628                        summj += yyy; 
     2629                } 
     2630                //now calculate the value of the inner integral 
     2631                inner = (vbj-vaj)/2.0*summj; 
     2632                inner *= 4.0*Pi*endRad*endRad*endRad; 
     2633                 
     2634                //now calculate outer integrand 
     2635                arg1 = x*len/2.0*cos(zi); 
     2636                arg2 = x*rad*sin(zi); 
     2637                yyy = inner; 
     2638                 
     2639                if(arg2 == 0) { 
     2640                        be = 0.5; 
     2641                } else { 
     2642                        be = NR_BessJ1(arg2)/arg2; 
     2643                } 
     2644                 
     2645                if(arg1 == 0.0) {               //limiting value of sinc(0) is 1; sinc is not defined in math.h 
     2646                        yyy += Pi*rad*rad*len*2.0*be; 
     2647                } else { 
     2648                        yyy += Pi*rad*rad*len*sin(arg1)/arg1*2.0*be; 
     2649                } 
     2650                yyy *= yyy; 
     2651                yyy *= sin(zi);         // = |A(q)|^2*sin(theta) 
     2652                yyy *= Gauss76Wt[i]; 
     2653                summ += yyy; 
     2654        }               //final scaling is done at the end of the function, after the NT_FP64 case 
     2655         
     2656        answer = (vb-va)/2.0*summ; 
     2657 
     2658        hh = fabs(hDist);               //need positive value for spherical cap volume 
     2659        answer /= 2.0*(1.0/3.0*Pi*(endRad-hh)*(endRad-hh)*(2.0*endRad+hh));             //divide by volume 
     2660        answer *= 1.0e8;                //convert to cm^-1 
     2661        answer *= contr*contr; 
     2662        answer *= scale; 
     2663        answer += bkg; 
     2664                 
     2665        return answer; 
     2666} 
     2667 
     2668/*      Capped Cylinder  : special case where L is nonzero and hDist < 0 
     2669 
     2670 -- uses the same Kernel as the Convex Lens 
     2671  
     2672Uses 76 pt Gaussian quadrature for both integrals 
     2673*/ 
     2674double 
     2675CappedCylinder(double w[], double x) 
     2676{ 
     2677        int i,j; 
     2678        double Pi; 
     2679        double scale,contr,bkg,sldc,slds; 
     2680        double len,rad,hDist,endRad; 
     2681        int nordi=76;                   //order of integration 
     2682        int nordj=76; 
     2683        double va,vb;           //upper and lower integration limits 
     2684        double summ,zi,yyy,answer;                      //running tally of integration 
     2685        double summj,vaj,vbj,zij;                       //for the inner integration 
     2686        double arg1,arg2,inner,hh,be; 
     2687         
     2688         
     2689        scale = w[0]; 
     2690        rad = w[1]; 
     2691        len = w[2]; 
     2692        endRad = w[3]; 
     2693        sldc = w[4]; 
     2694        slds = w[5]; 
     2695        bkg = w[6]; 
     2696                 
     2697        hDist = -1.0*sqrt(fabs(endRad*endRad-rad*rad));         //by definition for this model 
     2698         
     2699        contr = sldc-slds; 
     2700         
     2701        Pi = 4.0*atan(1.0); 
     2702        va = 0.0; 
     2703        vb = Pi/2.0;            //orintational average, outer integral 
     2704        vaj = -1.0*hDist/endRad; 
     2705        vbj = 1.0;              //endpoints of inner integral 
     2706 
     2707        summ = 0.0;                     //initialize intergral 
     2708 
     2709        for(i=0;i<nordi;i++) { 
     2710                //setup inner integral over the ellipsoidal cross-section 
     2711                summj=0.0; 
     2712                zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;             //the "theta" dummy 
     2713                 
     2714                for(j=0;j<nordj;j++) { 
     2715                        //20 gauss points for the inner integral 
     2716                        zij = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0;                //the "t" dummy 
     2717                        yyy = Gauss76Wt[j] * ConvLens_kernel(w,x,zij,zi);               //uses the same kernel as ConvexLens, except here L != 0 
     2718                        summj += yyy; 
     2719                } 
     2720                //now calculate the value of the inner integral 
     2721                inner = (vbj-vaj)/2.0*summj; 
     2722                inner *= 4.0*Pi*endRad*endRad*endRad; 
     2723                 
     2724                //now calculate outer integrand 
     2725                arg1 = x*len/2.0*cos(zi); 
     2726                arg2 = x*rad*sin(zi); 
     2727                yyy = inner; 
     2728                 
     2729                if(arg2 == 0) { 
     2730                        be = 0.5; 
     2731                } else { 
     2732                        be = NR_BessJ1(arg2)/arg2; 
     2733                } 
     2734                 
     2735                if(arg1 == 0.0) {               //limiting value of sinc(0) is 1; sinc is not defined in math.h 
     2736                        yyy += Pi*rad*rad*len*2.0*be; 
     2737                } else { 
     2738                        yyy += Pi*rad*rad*len*sin(arg1)/arg1*2.0*be; 
     2739                } 
     2740                 
     2741                 
     2742                 
     2743                yyy *= yyy; 
     2744                yyy *= sin(zi);         // = |A(q)|^2*sin(theta) 
     2745                yyy *= Gauss76Wt[i]; 
     2746                summ += yyy; 
     2747        }               //final scaling is done at the end of the function, after the NT_FP64 case 
     2748         
     2749        answer = (vb-va)/2.0*summ; 
     2750 
     2751        hh = fabs(hDist);               //need positive value for spherical cap volume 
     2752        answer /= Pi*rad*rad*len + 2.0*(1.0/3.0*Pi*(endRad-hh)*(endRad-hh)*(2.0*endRad+hh));            //divide by volume 
     2753        answer *= 1.0e8;                //convert to cm^-1 
     2754        answer *= contr*contr; 
     2755        answer *= scale; 
     2756        answer += bkg; 
     2757                 
     2758        return answer; 
     2759} 
     2760 
     2761 
     2762 
     2763// inner integral of the ConvexLens model, special case where L ~ 0 and hDist < 0 
     2764// 
     2765double 
     2766ConvLens_kernel(double w[], double x, double tt, double theta) { 
     2767 
     2768        double val,arg1,arg2; 
     2769        double scale,bkg,sldc,slds; 
     2770        double len,rad,hDist,endRad,be; 
     2771        scale = w[0]; 
     2772        rad = w[1]; 
     2773        len = w[2]; 
     2774        endRad = w[3]; 
     2775        sldc = w[4]; 
     2776        slds = w[5]; 
     2777        bkg = w[6]; 
     2778         
     2779        hDist = -1.0*sqrt(fabs(endRad*endRad-rad*rad)); 
     2780                 
     2781        arg1 = x*cos(theta)*(endRad*tt+hDist+len/2.0); 
     2782        arg2 = x*endRad*sin(theta)*sqrt(1.0-tt*tt); 
     2783         
     2784        if(arg2 == 0) { 
     2785                be = 0.5; 
     2786        } else { 
     2787                be = NR_BessJ1(arg2)/arg2; 
     2788        } 
     2789         
     2790        val = cos(arg1)*(1.0-tt*tt)*be; 
     2791         
     2792        return(val); 
     2793} 
     2794 
     2795 
     2796/*      Dumbbell  : special case where L ~ 0 and hDist > 0 
     2797 
     2798Uses 76 pt Gaussian quadrature for both integrals 
     2799*/ 
     2800double 
     2801Dumbbell(double w[], double x) 
     2802{ 
     2803        int i,j; 
     2804        double Pi; 
     2805        double scale,contr,bkg,sldc,slds; 
     2806        double len,rad,hDist,endRad; 
     2807        int nordi=76;                   //order of integration 
     2808        int nordj=76; 
     2809        double va,vb;           //upper and lower integration limits 
     2810        double summ,zi,yyy,answer;                      //running tally of integration 
     2811        double summj,vaj,vbj,zij;                       //for the inner integration 
     2812        double Dumb_tmp[7],arg1,arg2,inner,be; 
     2813         
     2814         
     2815        scale = w[0]; 
     2816        rad = w[1]; 
     2817//      len = w[2] 
     2818        endRad = w[2]; 
     2819        sldc = w[3]; 
     2820        slds = w[4]; 
     2821        bkg = w[5]; 
     2822         
     2823        len = 0.01; 
     2824         
     2825        Dumb_tmp[0] = w[0]; 
     2826        Dumb_tmp[1] = w[1]; 
     2827        Dumb_tmp[2] = len;              //length is some small number, essentially zero 
     2828        Dumb_tmp[3] = w[2]; 
     2829        Dumb_tmp[4] = w[3]; 
     2830        Dumb_tmp[5] = w[4]; 
     2831        Dumb_tmp[6] = w[5]; 
     2832                         
     2833        hDist = sqrt(fabs(endRad*endRad-rad*rad));              //by definition for this model 
     2834         
     2835        contr = sldc-slds; 
     2836         
     2837        Pi = 4.0*atan(1.0); 
     2838        va = 0.0; 
     2839        vb = Pi/2.0;            //orintational average, outer integral 
     2840        vaj = -1.0*hDist/endRad; 
     2841        vbj = 1.0;              //endpoints of inner integral 
     2842 
     2843        summ = 0.0;                     //initialize intergral 
     2844 
     2845        for(i=0;i<nordi;i++) { 
     2846                //setup inner integral over the ellipsoidal cross-section 
     2847                summj=0.0; 
     2848                zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;             //the "theta" dummy 
     2849                 
     2850                for(j=0;j<nordj;j++) { 
     2851                        //20 gauss points for the inner integral 
     2852                        zij = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0;                //the "t" dummy 
     2853                        yyy = Gauss76Wt[j] * Dumb_kernel(Dumb_tmp,x,zij,zi); 
     2854                        summj += yyy; 
     2855                } 
     2856                //now calculate the value of the inner integral 
     2857                inner = (vbj-vaj)/2.0*summj; 
     2858                inner *= 4.0*Pi*endRad*endRad*endRad; 
     2859                 
     2860                //now calculate outer integrand 
     2861                arg1 = x*len/2.0*cos(zi); 
     2862                arg2 = x*rad*sin(zi); 
     2863                yyy = inner; 
     2864                 
     2865                if(arg2 == 0) { 
     2866                        be = 0.5; 
     2867                } else { 
     2868                        be = NR_BessJ1(arg2)/arg2; 
     2869                } 
     2870                 
     2871                if(arg1 == 0.0) {               //limiting value of sinc(0) is 1; sinc is not defined in math.h 
     2872                        yyy += Pi*rad*rad*len*2.0*be; 
     2873                } else { 
     2874                        yyy += Pi*rad*rad*len*sin(arg1)/arg1*2.0*be; 
     2875                } 
     2876                yyy *= yyy; 
     2877                yyy *= sin(zi);         // = |A(q)|^2*sin(theta) 
     2878                yyy *= Gauss76Wt[i]; 
     2879                summ += yyy; 
     2880        }               //final scaling is done at the end of the function, after the NT_FP64 case 
     2881         
     2882        answer = (vb-va)/2.0*summ; 
     2883 
     2884        answer /= 2.0*Pi*(2.0*endRad*endRad*endRad/3.0+endRad*endRad*hDist-hDist*hDist*hDist/3.0);              //divide by volume 
     2885        answer *= 1.0e8;                //convert to cm^-1 
     2886        answer *= contr*contr; 
     2887        answer *= scale; 
     2888        answer += bkg; 
     2889                 
     2890        return answer; 
     2891} 
     2892 
     2893 
     2894/*      Barbell  : "normal" case where L is nonzero 0 and hDist > 0 
     2895 
     2896-- uses the same kernel as the Dumbbell case 
     2897 
     2898Uses 76 pt Gaussian quadrature for both integrals 
     2899*/ 
     2900double 
     2901Barbell(double w[], double x) 
     2902{ 
     2903        int i,j; 
     2904        double Pi; 
     2905        double scale,contr,bkg,sldc,slds; 
     2906        double len,rad,hDist,endRad; 
     2907        int nordi=76;                   //order of integration 
     2908        int nordj=76; 
     2909        double va,vb;           //upper and lower integration limits 
     2910        double summ,zi,yyy,answer;                      //running tally of integration 
     2911        double summj,vaj,vbj,zij;                       //for the inner integration 
     2912        double arg1,arg2,inner,be; 
     2913         
     2914         
     2915        scale = w[0]; 
     2916        rad = w[1]; 
     2917        len = w[2]; 
     2918        endRad = w[3]; 
     2919        sldc = w[4]; 
     2920        slds = w[5]; 
     2921        bkg = w[6]; 
     2922                         
     2923        hDist = sqrt(fabs(endRad*endRad-rad*rad));              //by definition for this model 
     2924         
     2925        contr = sldc-slds; 
     2926         
     2927        Pi = 4.0*atan(1.0); 
     2928        va = 0.0; 
     2929        vb = Pi/2.0;            //orintational average, outer integral 
     2930        vaj = -1.0*hDist/endRad; 
     2931        vbj = 1.0;              //endpoints of inner integral 
     2932 
     2933        summ = 0.0;                     //initialize intergral 
     2934 
     2935        for(i=0;i<nordi;i++) { 
     2936                //setup inner integral over the ellipsoidal cross-section 
     2937                summj=0.0; 
     2938                zi = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;             //the "theta" dummy 
     2939                 
     2940                for(j=0;j<nordj;j++) { 
     2941                        //20 gauss points for the inner integral 
     2942                        zij = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0;                //the "t" dummy 
     2943                        yyy = Gauss76Wt[j] * Dumb_kernel(w,x,zij,zi);           //uses the same Kernel as the Dumbbell, here L>0 
     2944                        summj += yyy; 
     2945                } 
     2946                //now calculate the value of the inner integral 
     2947                inner = (vbj-vaj)/2.0*summj; 
     2948                inner *= 4.0*Pi*endRad*endRad*endRad; 
     2949                 
     2950                //now calculate outer integrand 
     2951                arg1 = x*len/2.0*cos(zi); 
     2952                arg2 = x*rad*sin(zi); 
     2953                yyy = inner; 
     2954                 
     2955                if(arg2 == 0) { 
     2956                        be = 0.5; 
     2957                } else { 
     2958                        be = NR_BessJ1(arg2)/arg2; 
     2959                } 
     2960                 
     2961                if(arg1 == 0.0) {               //limiting value of sinc(0) is 1; sinc is not defined in math.h 
     2962                        yyy += Pi*rad*rad*len*2.0*be; 
     2963                } else { 
     2964                        yyy += Pi*rad*rad*len*sin(arg1)/arg1*2.0*be; 
     2965                } 
     2966                yyy *= yyy; 
     2967                yyy *= sin(zi);         // = |A(q)|^2*sin(theta) 
     2968                yyy *= Gauss76Wt[i]; 
     2969                summ += yyy; 
     2970        }               //final scaling is done at the end of the function, after the NT_FP64 case 
     2971         
     2972        answer = (vb-va)/2.0*summ; 
     2973 
     2974        answer /= Pi*rad*rad*len + 2.0*Pi*(2.0*endRad*endRad*endRad/3.0+endRad*endRad*hDist-hDist*hDist*hDist/3.0);             //divide by volume 
     2975        answer *= 1.0e8;                //convert to cm^-1 
     2976        answer *= contr*contr; 
     2977        answer *= scale; 
     2978        answer += bkg; 
     2979                 
     2980        return answer; 
     2981} 
     2982 
     2983 
     2984 
     2985// inner integral of the Dumbbell model, special case where L ~ 0 and hDist > 0 
     2986// 
     2987// inner integral of the Barbell model if L is nonzero 
     2988// 
     2989double 
     2990Dumb_kernel(double w[], double x, double tt, double theta) { 
     2991 
     2992        double val,arg1,arg2; 
     2993        double scale,bkg,sldc,slds; 
     2994        double len,rad,hDist,endRad,be; 
     2995        scale = w[0]; 
     2996        rad = w[1]; 
     2997        len = w[2]; 
     2998        endRad = w[3]; 
     2999        sldc = w[4]; 
     3000        slds = w[5]; 
     3001        bkg = w[6]; 
     3002         
     3003        hDist = sqrt(fabs(endRad*endRad-rad*rad)); 
     3004                 
     3005        arg1 = x*cos(theta)*(endRad*tt+hDist+len/2.0); 
     3006        arg2 = x*endRad*sin(theta)*sqrt(1.0-tt*tt); 
     3007         
     3008        if(arg2 == 0) { 
     3009                be = 0.5; 
     3010        } else { 
     3011                be = NR_BessJ1(arg2)/arg2; 
     3012        } 
     3013        val = cos(arg1)*(1.0-tt*tt)*be; 
     3014         
     3015        return(val); 
     3016} 
     3017 
     3018double PolyCoreBicelle(double dp[], double q) 
     3019{ 
     3020        int i; 
     3021        int nord = 20; 
     3022        double scale, length, sigma, bkg, radius, radthick, facthick; 
     3023        double rhoc, rhoh, rhor, rhosolv; 
     3024        double answer, Vpoly; 
     3025        double Pi,lolim,uplim,summ,yyy,rad,AR,Rsqr,Rsqrsumm,Rsqryyy; 
     3026         
     3027        scale = dp[0]; 
     3028        radius = dp[1]; 
     3029        sigma = dp[2];                          //sigma is the standard mean deviation 
     3030        length = dp[3]; 
     3031        radthick = dp[4]; 
     3032        facthick= dp[5]; 
     3033        rhoc = dp[6]; 
     3034        rhoh = dp[7]; 
     3035        rhor=dp[8]; 
     3036        rhosolv = dp[9]; 
     3037        bkg = dp[10]; 
     3038         
     3039        Pi = 4.0*atan(1.0); 
     3040         
     3041        lolim = exp(log(radius)-(4.*sigma)); 
     3042        if (lolim<0.0) { 
     3043                lolim=0.0;              //to avoid numerical error when  va<0 (-ve r value) 
     3044        } 
     3045        uplim = exp(log(radius)+(4.*sigma)); 
     3046         
     3047        summ = 0.0; 
     3048        Rsqrsumm = 0.0; 
     3049         
     3050        for(i=0;i<nord;i++) { 
     3051                rad = ( Gauss20Z[i]*(uplim-lolim) + uplim + lolim )/2.0; 
     3052                AR=(1.0/(rad*sigma*sqrt(2.0*Pi)))*exp(-(0.5*((log(radius/rad))/sigma)*((log(radius/rad))/sigma))); 
     3053                yyy = AR* Gauss20Wt[i] * BicelleIntegration(q,rad,radthick,facthick,rhoc,rhoh,rhor,rhosolv,length); 
     3054                Rsqryyy= Gauss20Wt[i] * AR * (rad+radthick)*(rad+radthick);             //SRK normalize to total dimensions 
     3055                summ += yyy; 
     3056                Rsqrsumm += Rsqryyy; 
     3057        } 
     3058         
     3059        answer = (uplim-lolim)/2.0*summ; 
     3060        Rsqr = (uplim-lolim)/2.0*Rsqrsumm; 
     3061        //normalize by average cylinder volume 
     3062        Vpoly = Pi*Rsqr*(length+2*facthick); 
     3063        answer /= Vpoly; 
     3064        //convert to [cm-1] 
     3065        answer *= 1.0e8; 
     3066        //Scale 
     3067        answer *= scale; 
     3068        // add in the background 
     3069        answer += bkg; 
     3070                 
     3071        return answer; 
     3072         
     3073} 
     3074 
     3075double 
     3076BicelleIntegration(double qq, double rad, double radthick, double facthick, double rhoc, double rhoh, double rhor, double rhosolv, double length){ 
     3077 
     3078        double answer,halfheight,Pi; 
     3079        double lolim,uplim,summ,yyy,zi; 
     3080        int nord,i; 
     3081         
     3082        // set up the integration end points  
     3083        Pi = 4.0*atan(1.0); 
     3084        nord = 76; 
     3085        lolim = 0.0; 
     3086        uplim = Pi/2; 
     3087        halfheight = length/2.0; 
     3088         
     3089        summ = 0.0;                             // initialize integral 
     3090        i=0; 
     3091        for(i=0;i<nord;i++) { 
     3092                zi = ( Gauss76Z[i]*(uplim-lolim) + uplim + lolim )/2.0; 
     3093                yyy = Gauss76Wt[i] * BicelleKernel(qq, rad, radthick, facthick, rhoc, rhoh, rhor,rhosolv, halfheight, zi); 
     3094                summ += yyy; 
     3095        } 
     3096         
     3097        // calculate value of integral to return 
     3098        answer = (uplim-lolim)/2.0*summ; 
     3099        return(answer);  
     3100} 
     3101 
     3102double 
     3103BicelleKernel(double qq, double rad, double radthick, double facthick, double rhoc, double rhoh, double rhor, double rhosolv, double length, double dum) 
     3104{ 
     3105        double dr1,dr2,dr3; 
     3106        double besarg1,besarg2; 
     3107        double vol1,vol2,vol3; 
     3108        double sinarg1,sinarg2; 
     3109        double t1,t2,t3; 
     3110        double retval,si1,si2,be1,be2; 
     3111         
     3112        double Pi = 4.0*atan(1.0); 
     3113         
     3114        dr1 = rhoc-rhoh; 
     3115        dr2 = rhor-rhosolv; 
     3116        dr3=  rhoh-rhor; 
     3117        vol1 = Pi*rad*rad*(2.0*length); 
     3118        vol2 = Pi*(rad+radthick)*(rad+radthick)*(2.0*length+2.0*facthick); 
     3119        vol3= Pi*(rad)*(rad)*(2.0*length+2.0*facthick); 
     3120        besarg1 = qq*rad*sin(dum); 
     3121        besarg2 = qq*(rad+radthick)*sin(dum); 
     3122        sinarg1 = qq*length*cos(dum); 
     3123        sinarg2 = qq*(length+facthick)*cos(dum); 
     3124         
     3125        if(besarg1 == 0) { 
     3126                be1 = 0.5; 
     3127        } else { 
     3128                be1 = NR_BessJ1(besarg1)/besarg1; 
     3129        } 
     3130        if(besarg2 == 0) { 
     3131                be2 = 0.5; 
     3132        } else { 
     3133                be2 = NR_BessJ1(besarg2)/besarg2; 
     3134        }        
     3135        if(sinarg1 == 0) { 
     3136                si1 = 1.0; 
     3137        } else { 
     3138                si1 = sin(sinarg1)/sinarg1; 
     3139        } 
     3140        if(sinarg2 == 0) { 
     3141                si2 = 1.0; 
     3142        } else { 
     3143                si2 = sin(sinarg2)/sinarg2; 
     3144        } 
     3145        t1 = 2.0*vol1*dr1*si1*be1; 
     3146        t2 = 2.0*vol2*dr2*si2*be2; 
     3147        t3 = 2.0*vol3*dr3*si2*be1; 
     3148         
     3149        retval = ((t1+t2+t3)*(t1+t2+t3))*sin(dum); 
     3150        return(retval); 
     3151         
     3152} 
     3153 
     3154 
     3155double 
     3156CSPPKernel(double dp[], double mu, double uu) 
     3157{        
     3158        double aa,bb,cc, ta,tb,tc;  
     3159        double Vin,Vot,V1,V2; 
     3160        double rhoA,rhoB,rhoC, rhoP, rhosolv; 
     3161        double dr0, drA,drB, drC; 
     3162        double arg1,arg2,arg3,arg4,t1,t2, t3, t4; 
     3163        double Pi,retVal; 
     3164 
     3165        aa = dp[1]; 
     3166        bb = dp[2]; 
     3167        cc = dp[3]; 
     3168        ta = dp[4]; 
     3169        tb = dp[5]; 
     3170        tc = dp[6]; 
     3171        rhoA=dp[7]; 
     3172        rhoB=dp[8]; 
     3173        rhoC=dp[9]; 
     3174        rhoP=dp[10]; 
     3175        rhosolv=dp[11]; 
     3176        dr0=rhoP-rhosolv; 
     3177        drA=rhoA-rhosolv; 
     3178        drB=rhoB-rhosolv; 
     3179        drC=rhoC-rhosolv;  
     3180        Vin=(aa*bb*cc); 
     3181        Vot=(aa*bb*cc+2.0*ta*bb*cc+2.0*aa*tb*cc+2.0*aa*bb*tc); 
     3182        V1=(2.0*ta*bb*cc);   //  incorrect V1 (aa*bb*cc+2*ta*bb*cc) 
     3183        V2=(2.0*aa*tb*cc);  // incorrect V2(aa*bb*cc+2*aa*tb*cc) 
     3184        aa = aa/bb; 
     3185        ta=(aa+2.0*ta)/bb; 
     3186        tb=(aa+2.0*tb)/bb; 
     3187         
     3188        Pi = 4.0*atan(1.0); 
     3189         
     3190        arg1 = (mu*aa/2.0)*sin(Pi*uu/2.0); 
     3191        arg2 = (mu/2.0)*cos(Pi*uu/2.0); 
     3192        arg3=  (mu*ta/2.0)*sin(Pi*uu/2.0); 
     3193        arg4=  (mu*tb/2.0)*cos(Pi*uu/2.0); 
     3194                          
     3195        if(arg1==0.0){ 
     3196                t1 = 1.0; 
     3197        } else { 
     3198                t1 = (sin(arg1)/arg1);                //defn for CSPP model sin(arg1)/arg1    test:  (sin(arg1)/arg1)*(sin(arg1)/arg1)    
     3199        } 
     3200        if(arg2==0.0){ 
     3201                t2 = 1.0; 
     3202        } else { 
     3203                t2 = (sin(arg2)/arg2);           //defn for CSPP model sin(arg2)/arg2   test: (sin(arg2)/arg2)*(sin(arg2)/arg2)     
     3204        }        
     3205        if(arg3==0.0){ 
     3206                t3 = 1.0; 
     3207        } else { 
     3208                t3 = sin(arg3)/arg3; 
     3209        } 
     3210        if(arg4==0.0){ 
     3211                t4 = 1.0; 
     3212        } else { 
     3213                t4 = sin(arg4)/arg4; 
     3214        } 
     3215        retVal =( dr0*t1*t2*Vin + drA*(t3-t1)*t2*V1+ drB*t1*(t4-t2)*V2 )*( dr0*t1*t2*Vin + drA*(t3-t1)*t2*V1+ drB*t1*(t4-t2)*V2 );   //  correct FF : square of sum of phase factors 
     3216        return(retVal);  
     3217 
     3218} 
     3219 
     3220/*      CSParallelepiped  :  calculates the form factor of a Parallelepiped with a core-shell structure 
     3221 -- different SLDs can be used for the face and rim 
     3222 
     3223Uses 76 pt Gaussian quadrature for both integrals 
     3224*/ 
     3225double 
     3226CSParallelepiped(double dp[], double q) 
     3227{ 
     3228        int i,j; 
     3229        double scale,aa,bb,cc,ta,tb,tc,rhoA,rhoB,rhoC,rhoP,rhosolv,bkg;         //local variables of coefficient wave 
     3230        int nordi=76;                   //order of integration 
     3231        int nordj=76; 
     3232        double va,vb;           //upper and lower integration limits 
     3233        double summ,yyy,answer;                 //running tally of integration 
     3234        double summj,vaj,vbj;                   //for the inner integration 
     3235        double mu,mudum,arg,sigma,uu,vol; 
     3236         
     3237         
     3238        //      Pi = 4.0*atan(1.0); 
     3239        va = 0.0; 
     3240        vb = 1.0;               //orintational average, outer integral 
     3241        vaj = 0.0; 
     3242        vbj = 1.0;              //endpoints of inner integral 
     3243         
     3244        summ = 0.0;                     //initialize intergral 
     3245         
     3246        scale = dp[0]; 
     3247        aa = dp[1]; 
     3248        bb = dp[2]; 
     3249        cc = dp[3]; 
     3250        ta  = dp[4]; 
     3251        tb  = dp[5]; 
     3252        tc  = dp[6];   // is 0 at the moment   
     3253        rhoA=dp[7];   //rim A SLD 
     3254        rhoB=dp[8];   //rim B SLD 
     3255        rhoC=dp[9];    //rim C SLD 
     3256        rhoP = dp[10];   //Parallelpiped core SLD 
     3257        rhosolv=dp[11];  // Solvent SLD 
     3258        bkg = dp[12]; 
     3259         
     3260        mu = q*bb; 
     3261        vol = aa*bb*cc+2.0*ta*bb*cc+2.0*aa*tb*cc+2.0*aa*bb*tc;          //calculate volume before rescaling 
     3262         
     3263        // do the rescaling here, not in the kernel 
     3264        // normalize all WRT bb 
     3265        aa = aa/bb; 
     3266        cc = cc/bb; 
     3267         
     3268        for(i=0;i<nordi;i++) { 
     3269                //setup inner integral over the ellipsoidal cross-section 
     3270                summj=0.0; 
     3271                sigma = ( Gauss76Z[i]*(vb-va) + va + vb )/2.0;          //the outer dummy 
     3272                 
     3273                for(j=0;j<nordj;j++) { 
     3274                        //76 gauss points for the inner integral 
     3275                        uu = ( Gauss76Z[j]*(vbj-vaj) + vaj + vbj )/2.0;         //the inner dummy 
     3276                        mudum = mu*sqrt(1.0-sigma*sigma); 
     3277                        yyy = Gauss76Wt[j] * CSPPKernel(dp,mudum,uu); 
     3278                        summj += yyy; 
     3279                } 
     3280                //now calculate the value of the inner integral 
     3281                answer = (vbj-vaj)/2.0*summj; 
     3282                 
     3283                //finish the outer integral cc already scaled 
     3284                arg = mu*cc*sigma/2.0; 
     3285                if ( arg == 0.0 ) { 
     3286                        answer *= 1.0; 
     3287                } else { 
     3288                        answer *= sin(arg)*sin(arg)/arg/arg; 
     3289                } 
     3290                 
     3291                //now sum up the outer integral 
     3292                yyy = Gauss76Wt[i] * answer; 
     3293                summ += yyy; 
     3294        }               //final scaling is done at the end of the function, after the NT_FP64 case 
     3295         
     3296        answer = (vb-va)/2.0*summ; 
     3297 
     3298        //normalize by volume 
     3299        answer /= vol; 
     3300        //convert to [cm-1] 
     3301        answer *= 1.0e8; 
     3302        //Scale 
     3303        answer *= scale; 
     3304        // add in the background 
     3305        answer += bkg; 
     3306         
     3307        return answer; 
     3308} 
     3309 
Note: See TracChangeset for help on using the changeset viewer.