Functions | |
void | outputProfile (Parratt *par) |
Write the SLD profile to file. | |
void | outputReflectivity (Parratt *par) |
Write the reflectivity to file. |
void outputProfile | ( | Parratt * | par | ) |
This function just writes the SLD profile to file, through calls to the function calcProfile()
.
00025 { 00026 int i, idx; 00027 double z, minz, maxz; 00028 double sld, tmp; 00029 FILE *fp; 00030 00031 00032 /*------------------------------------------------ 00033 * Calc minimum z : 00034 * Start near zero and step negative until sld of bulk layer 00035 * is reached within small tolerance. 00036 */ 00037 /* index the first layer */ 00038 idx = par->l.idx[0]; 00039 sld = par->m.par[idx+2] + par->m.par[idx+4]; 00040 par->g.plz = POLARIZED_UP; 00041 minz = 0.1; 00042 do 00043 { 00044 minz -= 0.1; 00045 tmp = calcProfile(minz, par->m.par, par); 00046 } while (fabs(tmp - sld) >= 0.001); 00047 minz -= 1.0; 00048 /* If polarized, calculated the spin down case */ 00049 if (par->s.pntp == POLARIZED) 00050 { 00051 sld = par->m.par[idx+2] - par->m.par[idx+4]; 00052 par->g.plz = POLARIZED_DOWN; 00053 z = minz; 00054 minz = 0.1; 00055 do 00056 { 00057 minz -= 0.1; 00058 tmp = calcProfile(minz, par->m.par, par); 00059 } while (fabs(tmp - sld) >= 0.001); 00060 minz -= 1.0; 00061 if (z < minz) minz = z; 00062 } 00063 00064 00065 /*------------------------------------------------ 00066 * Calc maximum z : 00067 * Start maxz at the sum of layer thicknesses, 00068 * and step positive until sld of bulk is reached 00069 * within small tolerance. 00070 */ 00071 maxz = 0.0; 00072 for (i=1; i<par->l.num; i++) 00073 { 00074 idx = par->l.idx[i]; 00075 maxz += par->m.par[idx+0]; 00076 } 00077 /* index of the last layer */ 00078 idx = par->l.idx[par->l.num-1]; 00079 sld = par->m.par[idx+2]+par->m.par[idx+4]; 00080 par->g.plz = POLARIZED_UP; 00081 maxz -= 1.0; 00082 do 00083 { 00084 maxz += 0.1; 00085 tmp = calcProfile(maxz, par->m.par, par); 00086 } while (fabs(tmp - sld) >= 0.001); 00087 maxz += 1.0; 00088 /* If polarized, calculated the spin down case */ 00089 if (par->s.pntp == POLARIZED) 00090 { 00091 sld = par->m.par[idx+2]-par->m.par[idx+4]; 00092 par->g.plz = POLARIZED_DOWN; 00093 z = maxz; 00094 maxz -= 1.0; 00095 do 00096 { 00097 maxz += 0.1; 00098 tmp = calcProfile(maxz, par->m.par, par); 00099 } while (fabs(tmp - sld) >= 0.001); 00100 maxz += 1.0; 00101 if (z > maxz) maxz = z; 00102 } 00103 00104 00105 /*------------------------------------------------ 00106 * 00107 */ 00108 fp = fopen(par->s.prof, "w"); 00109 if (fp == NULL) error("Can't open profile file for writing"); 00110 for (i=0; i<par->s.numz; i++) 00111 { 00112 z = ((maxz - minz) * (double)i / (double)par->s.numz) + minz; 00113 00114 par->g.plz = POLARIZED_UP; 00115 tmp = calcProfile(z, par->m.par, par); 00116 fprintf(fp, "%f\t%f\t", z, tmp); 00117 00118 if (par->s.pntp == POLARIZED) 00119 { 00120 par->g.plz = POLARIZED_DOWN; 00121 tmp = calcProfile(z, par->m.par, par); 00122 fprintf(fp, "%f\t", tmp); 00123 } 00124 00125 fprintf(fp, "\n"); 00126 } 00127 fclose(fp); 00128 }
void outputReflectivity | ( | Parratt * | par | ) |
This function just writes the reflectivity to file, through calls to the function calcReflectivity()
.
00132 { 00133 int i; 00134 double dq, q, tmp; 00135 FILE *fp; 00136 00137 dq = (par->s.qmax - par->s.qmin) / (double)par->s.numq; 00138 fp = fopen(par->s.refl, "w"); 00139 if (fp == NULL) error("Can't open reflectivity file for writing"); 00140 00141 for (i=0; i<par->s.numq; i++) 00142 { 00143 q = dq * (double)i + par->s.qmin; 00144 00145 par->g.plz = POLARIZED_UP; 00146 tmp = calcReflectivity(q, par->m.par, par); 00147 fprintf(fp, "%f\t%g\t", q, tmp); 00148 00149 if (par->s.pntp == POLARIZED) 00150 { 00151 par->g.plz = POLARIZED_DOWN; 00152 tmp = calcReflectivity(q, par->m.par, par); 00153 fprintf(fp, "%g\t", tmp); 00154 } 00155 fprintf(fp, "\n"); 00156 } 00157 fclose(fp); 00158 return; 00159 }