/******************************************************************************* * * McStas, neutron ray-tracing package * Copyright 1997-2002, All rights reserved * Risoe National Laboratory, Roskilde, Denmark * Institut Laue Langevin, Grenoble, France * * Component: Virtual_tripoli4_output * * %I * Written by: Guillaume Campioni * Date: Sep 28th, 2001 * Origin: LLB * * Detector-like component that writes neutron state parameters into a * 'virtual source' neutron file when neutrons come from the source : * Virtual_tripoli4_input.comp * * %D * Detector-like component writing neutron state parameters to a * virtual source neutron file when neutron are coming from a * Virtual_tripoli4_input.comp. * As McStas keeps the notion of batch with this component, it's possible * to calculate standard deviations for the flux in differents energy groupes. * The component geometry is the full plane, and saves the neutron state as * it exits from the previous component. * Format is the one used by TRIPOLI4.4 stock files : * * NEUTRON energy position_X position_Y position_Z dir_X dir_Y dir_Z weight * * energy is in Mega eV * positions are in cm and the direction vector is normalized to 1. * * %BUGS * This component will NOT work with parallel execution (MPI). * * EXAMPLE: * To create a file collecting all neutron states with TRIPOLI4 format * COMPONENT T4output = Virtual_tripoli4_output( * filename = "exit_guide_result.dat", * virtual_tripoli4_input_comp = source_file_tripoli ) * at the position where will be the Virtual_tripoli4_input. * * %P * INPUT PARAMETERS * filename: [str] name of the Tripoli4 neutron output file, * or stdout if left to 0. * batch: [1] index of the Tripoli batch to generate, when no * Tripoli4_input component is available in instrument. * Virtual_tripoli_input_comp: [comp] Name of the Tripoli4_input component * from which is to be obtained batch information * use '0' if not defined. * * %L * Tripoli * Virtual_tripoli4_input * * %E *******************************************************************************/ DEFINE COMPONENT Virtual_tripoli4_output DEFINITION PARAMETERS (virtual_tripoli4_input_comp=0) SETTING PARAMETERS (string filename=0, batch=1) OUTPUT PARAMETERS (hfile,previous_batch) /* Neutron parameters: (x,y,z,vx,vy,vz,t,sx,sy,sz,p) */ DECLARE %{ long previous_batch; FILE *hfile; %} INITIALIZE %{ previous_batch=0; int i; char ** head; long nl; #if defined (USE_MPI) exit(printf("Tripoli4_output: %s: ERROR: This component can not be used in parallel execution mode (MPI). Abort.\n", NAME_CURRENT_COMP)); #endif /* Open neutron output file. */ if(filename && strcmp(filename,"NULL") && strcmp(filename,"0") && strcmp(filename,"stdout")) hfile = fopen(filename, "w"); else hfile = stdout; if(!hfile) { fprintf(stderr, "Tripoli4_output: %s: Error: Cannot open output file %s.\n", NAME_CURRENT_COMP, (filename && strcmp(filename,"NULL") && strcmp(filename,"0") && strcmp(filename,"stdout") ? filename : "stdout")); exit(1); } fprintf(hfile,"# Tripoli4 batch file %s written by %s\n", (filename && strcmp(filename,"NULL") && strcmp(filename,"0") && strcmp(filename,"stdout") ? filename : "stdout"), MCCODE_STRING); fprintf(hfile,"# Generated by component %s in instrument %s (%s)\n", NAME_CURRENT_COMP, mcinstrument_name, mcinstrument_source); fprintf(hfile,"# Format: Tripoli4 data text file with header\n"); #ifdef TRIPOLI4_INPUT_DEFS /* use header information from Virtual_tripoli4_input component instance */ head = (MC_GETPAR(virtual_tripoli4_input_comp, head));/* header buffer */ nl = (MC_GETPAR(virtual_tripoli4_input_comp, nl)); /* nb of lines in header */ for(i=0;i