McCode icon indicating copy to clipboard operation
McCode copied to clipboard

TOFRes_sample issue in McStas 3.4: Missing modifications long the lines of Res_sample

Open willend opened this issue 10 months ago • 2 comments

TOFRes_sample should use component-injected USERVARS as in Res_sample, see e.g. https://github.com/McStasMcXtrace/McCode/commit/0561e40d3cde6098cb32f659d990d8a713860582

Issue reported by Ryoichi Kajimoto via mcstas-users (https://mailman2.mcstas.org/pipermail/mcstas-users/2023q4/001508.html) and quoted below.

Also, a test/unit-test instrument should be defined for TOFRes_sample.

Hi,

I'm simulating a resolution function of a direct-geometry TOF spectrometer. I use TOFRes_sample() for the sample and Res_monitor() for the monitor.

My code worked with McStas 3.1, but it cannot be compiled with McStas 3.4. I would appreciate if you could provide any solution.

Converting the .instr file to .c with mcstas command worked fine without an error, but compiling it with gcc -O3 -lm stops with an error message attached below.

I found that Res_monitor.comp and Res_sample.comp were greatly updated in McStas 3.4 but TOFRes_sample.comp was unchanged. I suspect that TOFRes_sample.comp is not compatible with Res_monitor.comp...

Thank you in advance,

Ryoichi Kajimoto

==================================

SIKIResSim.c: In function ‘Table_Read_Handle’: SIKIResSim.c:7518:60: warning: format ‘%i’ expects argument of type ‘int’, but argument 5 has type ‘long int’ [-Wformat=] 7518 | fprintf(stderr,"Warning: Read_Table :%s %s Data has %i invalid lines (*****). Ignored.\n", | ~^ | | | int | %li ...... 7521 | count_invalid); | ~~~~~~~~~~~~~ | | | long int SIKIResSim.c: In function ‘_resmonitor_setpos’: SIKIResSim.c:13221:6: error: ‘RSsample’ undeclared (first use in this function) 13221 | if(RSsample && strlen(RSsample)) | ^~~~~~~~ SIKIResSim.c:13221:6: note: each undeclared identifier is reported only once for each function it appears in SIKIResSim.c: In function ‘class_Res_monitor_init’: SIKIResSim.c:663:33: warning: format not a string literal and no format arguments [-Wformat-security] 663 | #define NAME_CURRENT_COMP (_comp->_name) | ~~~~~~^~~~~~~~ SIKIResSim.c:13781:48: note: in expansion of macro ‘NAME_CURRENT_COMP’ 13781 | if (!strcmp(filename,"\0")) sprintf(filename,NAME_CURRENT_COMP); | ^~~~~~~~~~~~~~~~~ SIKIResSim.c:641:10: error: ‘_class_Res_sample_parameters’ undeclared (first use in this function); did you mean ‘_class_TOFRes_sample_parameters’? 641 | &( ((class ## type ##_parameters *) _getvar_parameters(compname))->par ) | ^~~~~~~ SIKIResSim.c:13835:18: note: in expansion of macro ‘COMP_GETPAR3’ 13835 | int *index_ptr=COMP_GETPAR3(Res_sample, res_sample_comp, compindex); | ^~~~~~~~~~~~ SIKIResSim.c:641:41: error: expected expression before ‘)’ token 641 | &( ((class ## type ##_parameters *) _getvar_parameters(compname))->par ) | ^ SIKIResSim.c:13835:18: note: in expansion of macro ‘COMP_GETPAR3’ 13835 | int *index_ptr=COMP_GETPAR3(Res_sample, res_sample_comp, compindex); | ^~~~~~~~~~~~

==================================

This is how I use TOFRes_sample() and Res_monitor():

==================================

SPLIT COMPONENT RSsample = TOFRes_sample( thickness = sample_r-0.0001, radius = sample_r, yheight = sample_h, focus_xw = Wdx+0.001, focus_yh = Wdy+0.001, target_x = sample_det_x, target_y = sample_det_y, target_z = sample_det_z, time_bin = (ts+tsd+toffset)1e6, time_width = Dtsd1e6 ) AT (0,0,L1) RELATIVE mod

COMPONENT det_pos = Arm() AT (sample_det_x,sample_det_y,sample_det_z) RELATIVE RSsample ROTATED (0,atan(sample_det_x/sample_det_z)*RAD2DEG,0) RELATIVE RSsample

COMPONENT resmonitor = Res_monitor( res_sample_comp = RSsample, options = "cylinder", xwidth = Wdx, yheight = Wdy, filename = "resmonitor.dat" ) AT (0,0,0) RELATIVE det_pos

willend avatar Oct 23 '23 18:10 willend

The Test_TOFRes_sample.instr instrument has received a documentation header in this main branch commit: be00e4b5c

And even though McStas 2.x is bordering "unsupported", the TOFRes_sample and the same instrument can be found on mccode-legacy at f30282c45

willend avatar Oct 25 '23 14:10 willend

Unless I hear loud noises, I deem this "ready for release"

willend avatar Oct 25 '23 14:10 willend