/*********************************************************************** * * McStas, neutron ray-tracing package * Copyright (C) 1997-2010, All rights reserved * Risoe National Laboratory, Roskilde, Denmark * Institut Laue Langevin, Grenoble, France * * Component: Filter_gen * %I * Written by: EF (from Flux_adapter) * Date: Dec, 15th, 2002 * Version: $Revision: 1.5 $ * Origin: ILL * Release: McStas 1.12b * * This components may either set the flux or change it (filter-like), using * an external data file. * *%D * This component changes the neutron flux (weight) in order to match * a reference table in a file. * Typically you may set the neutron flux (source-like), or multiply it * using a transmission table (filter-like). * The component may be placed after a source, in order to e.g. * simulate a real source from a reference table, or used as a filter (BeO) , or as a window (Al). The behaviour of the component is * specified using the 'options' parameter, or from the file itself (see below) * If the thickness for the transmission data file D was t0, and a different * thickness t1 would be required, then the resulting transmission is: * D^(t1/t0). * You may use the 'thickness' and 'scaling' parameter for that purpose. * * File format: * This file may be of any 2-columns free format (k[Angs-1],p), (omega[meV],p) * and (lambda[Angs],p) where p is the weight. The type of the file may be * written explicitely in the file, as a comment, or using the 'options' * parameter. * Non mumerical content in file is treated as comment (e.g. lines starting * with '#' character). * A table rebinning and linear interpolation are performed. * * EXAMPLE : in order to simulate a PG filter, using the lib/data/HOPG.trm file * Filter_gen(xmin = -0.1, xmax = 0.1, * ymin = -0.1, ymax = 0.1, * file="HOPG.trm") * * in this file, the comment line * # wavevector multiply * sets the behaviour of the component. One may as well have used * options="wavevector multiply" * in the component instance parameters. * *%P * file: [str] name of the file to look at (first two columns data) * data D should rather be sorted (ascending order) and monotonic * file may contain options (see below) as comment * options: [str] string that can contain: * "[ k p ]" or "wavector" for file type, * "[ omega p]" or "energy", * "[ lambda p ]" or "wavelength", * "set" to set the weight according to the table, * "multiply" to multiply (instead of set) the weight by factor, * "add" to add to current flux, * "verbose" to display additional informations. * thickness: [1] relative thickness. D = D^(thickness). * scaling: [1] scaling factor. D = D*scaling. * xmin: [m] dimension of filter * xmax: [m] dimension of filter * ymin: [m] dimension of filter * ymax: [m] dimension of filter * * %L * HOPG.trm file as an example. *%E ***********************************************************************/ DEFINE COMPONENT Filter_gen DEFINITION PARAMETERS (file=0, string options=0) SETTING PARAMETERS (xmin, xmax, ymin, ymax, thickness=1, scaling=1) OUTPUT PARAMETERS (pTable, Mode_Table, Type_Table) STATE PARAMETERS (x,y,z,vx,vy,vz,t,s1,s2,p) SHARE %{ #ifndef FILTER_GEN #define FILTER_GEN "1.0" #define UNKNOWN_TABLE 0 #define ENERGY_TABLE 1 #define WAVEVECTOR_TABLE 2 #define WAVELENGTH_TABLE 3 #define FLUX_ADAPT_SET 0 #define FLUX_ADAPT_MULT 1 #define FLUX_ADAPT_ADD 2 char FilterGen_Mode(char *str, char *Mode, char *Type, char *verbose) { long i; char *c; if (!str || !strlen(str)) return(0); c = malloc(strlen(str)); for (i=0; ixmin && xymin && y