41 for (i = 0; i <
i_mon; i++) {
51 for (i = 0; i <
i_det; i++) {
53 delt[i] =
static_cast<float>(i);
54 len2[i] =
static_cast<float>(i);
56 tthe[i] =
static_cast<float>(i);
58 for (i = 0; i <
i_use; i++) {
59 for (j = 0; j <
i_det; j++) {
60 ut[i *
i_det + j] =
static_cast<float>(j);
75 for (i = 0; i <
i_det; i++) {
87 for (i = 0; i < 256; i++) {
96 for (i = 0; i <
t_ntc1 + 1; i++) {
104 for (i = 0; i <
u_len; i++) {
105 u_dat[i] =
static_cast<float>(i);
118#pragma warning(disable : 4996)
132 static const int hdr_size =
sizeof(
hdr) /
sizeof(
char);
133 static const int rrpb_size =
sizeof(
rpb) /
sizeof(
float);
134 static const int irpb_size =
sizeof(
rpb) /
sizeof(
int);
144 : m_crpt(crpt), frmt_ver_no(0), data_format(0), ver2(0), r_number(0), ver3(0), i_det(0), i_mon(0), i_use(0),
145 mdet(nullptr), monp(nullptr), spec(nullptr), delt(nullptr), len2(nullptr), code(nullptr), tthe(nullptr),
146 ut(nullptr), ver4(0), ver5(0), crat(nullptr), modn(nullptr), mpos(nullptr), timr(nullptr), udet(nullptr), ver6(0),
147 t_ntrg(0), t_nfpp(0), t_nper(0), t_nsp1(0), t_ntc1(0), t_pre1(0), t_tcb1(nullptr), ver7(0), u_dat(nullptr),
148 ver8(0), ddes(nullptr), dat1(nullptr) {
166 : m_crpt(crpt), frmt_ver_no(0), data_format(0), ver2(0), r_number(0), ver3(0), i_det(0), i_mon(0), i_use(0),
167 mdet(nullptr), monp(nullptr), spec(nullptr), delt(nullptr), len2(nullptr), code(nullptr), tthe(nullptr),
168 ut(nullptr), ver4(0), ver5(0), crat(nullptr), modn(nullptr), mpos(nullptr), timr(nullptr), udet(nullptr), ver6(0),
169 t_ntrg(0), t_nfpp(0), t_nper(0), t_nsp1(0), t_ntc1(0), t_pre1(0), t_tcb1(nullptr), ver7(0), u_dat(nullptr),
170 ver8(0), ddes(nullptr), dat1(nullptr) {
182 if (doUpdateFromCRPT) {
199 sprintf(buffer,
"%05d",
m_crpt->run_number);
206 sprintf(buffer,
"%8.2f",
m_crpt->good_uamph);
239 if (!strcmp(
m_crpt->beamstop_position,
"IN")) {
258 if (!stricmp(
m_crpt->sample_type,
"sample+can")) {
260 }
else if (!stricmp(
m_crpt->sample_type,
"empty can")) {
262 }
else if (!stricmp(
m_crpt->sample_type,
"vanadium")) {
264 }
else if (!stricmp(
m_crpt->sample_type,
"absorber")) {
266 }
else if (!stricmp(
m_crpt->sample_type,
"nothing")) {
268 }
else if (!stricmp(
m_crpt->sample_type,
"sample, no can")) {
274 if (!stricmp(
m_crpt->sample_geometry,
"cylinder") || !stricmp(
m_crpt->sample_geometry,
"cylindrical")) {
276 }
else if (!stricmp(
m_crpt->sample_geometry,
"flat plate")) {
278 }
else if (!stricmp(
m_crpt->sample_geometry,
"disc")) {
280 }
else if (!stricmp(
m_crpt->sample_geometry,
"single crystal")) {
327 if (
m_crpt->tcb_sync == FrameSyncInternalTest) {
335 for (i = 0; i <
m_crpt->ntrg; i++) {
351 for (i = 0; i < 256; i++) {
367 for (i = 0; i <
u_len; i++) {
380 if (
m_crpt->log_nlines > 0) {
402 int ndata, len_log, i;
403 fpos_t add_pos, dhdr_pos, keep_pos;
417 fgetpos(file, &add_pos);
455 ioRAW(file, &i, 1, from_file);
462 logger.error() <<
"Error in u_len value read from file, it would be " <<
u_len
463 <<
"; where it is calculated as "
464 "u_len = ad_data - ad_user - 2, where ad_data: "
472 fgetpos(file, &dhdr_pos);
474 int ndes, nout, nwords, outbuff_size = 100000, offset;
475 auto outbuff =
new char[outbuff_size];
483 for (i = 0; i < ndes; i++) {
484 int zero = fseek(file, 4 *
ddes[i].nwords, SEEK_CUR);
486 logger.error() <<
"Failed to seek position in file for index: " << i <<
"\n";
500 offset = 33 + ndes * 2;
503 for (i = 0; i < ndes; i++) {
506 ioRAW(file, outbuff, 4 * nwords, from_file);
510 nwords = (3 + nout) / 4;
514 ioRAW(file, outbuff, 4 * nwords, from_file);
531 int uncomp_filesize =
add.
ad_data - 1 + uncomp_data_size + len_log;
532 dhdr.
d_crdata =
static_cast<float>(uncomp_data_size) /
static_cast<float>(curr_data_size);
533 dhdr.
d_crfile =
static_cast<float>(uncomp_filesize) /
static_cast<float>(curr_filesize);
535 int zero = fgetpos(file, &keep_pos);
537 logger.error() <<
"Error when getting file position: " << strerror(errno) <<
'\n';
542 zero = fsetpos(file, &add_pos);
544 logger.error() <<
"Error when setting file position: " << strerror(errno) <<
'\n';
550 zero = fsetpos(file, &dhdr_pos);
552 logger.error() <<
"Error when setting file position to header: " << strerror(errno) <<
'\n';
558 zero = fsetpos(file, &keep_pos);
560 logger.error() <<
"Error when restoring file position: " << strerror(errno) <<
'\n';
569 ioRAW(file,
reinterpret_cast<char *
>(s),
sizeof(
HDR_STRUCT) * len, from_file);
575 ioRAW(file,
reinterpret_cast<int *
>(s), (
sizeof(
ADD_STRUCT) * len /
sizeof(
int)), from_file);
581 ioRAW(file,
reinterpret_cast<char *
>(s),
sizeof(
USER_STRUCT) * len, from_file);
588 for (i = 0; i < len; i++) {
589 ioRAW(file, &(s[i].r_dur), 7, from_file);
590 ioRAW(file, &(s[i].r_gd_prtn_chrg), 2, from_file);
591 ioRAW(file, &(s[i].r_goodfrm), 7, from_file);
592 ioRAW(file, s[i].r_enddate, 20, from_file);
593 ioRAW(file, &(s[i].r_prop), 11, from_file);
601 for (i = 0; i < len; i++) {
602 ioRAW(file, &(s[i].i_chfreq), 3, from_file);
603 ioRAW(file, &(s[i].delay_c1), 14, from_file);
604 ioRAW(file, &(s[i].i_xsect), 2, from_file);
605 ioRAW(file, &(s[i].i_posn), 3, from_file);
606 ioRAW(file, &(s[i].i_l1), 1, from_file);
607 ioRAW(file, &(s[i].i_rfreq), 1, from_file);
608 ioRAW(file, &(s[i].i_renergy), 2, from_file);
609 ioRAW(file, &(s[i].i_rslit), 2, from_file);
610 ioRAW(file, &(s[i].i_xcen), 2, from_file);
611 ioRAW(file, &(s[i].i_bestop), 1, from_file);
612 ioRAW(file, &(s[i].i_radbest), 4, from_file);
613 ioRAW(file, s[i].spare, 29, from_file);
621 for (i = 0; i < len; i++) {
622 ioRAW(file, &(s[i].e_posn), 3, from_file);
623 ioRAW(file, &(s[i].e_thick), 16, from_file);
624 ioRAW(file, s[i].e_name, 40, from_file);
625 ioRAW(file, &(s[i].e_equip), 35, from_file);
633 for (i = 0; i < len; i++) {
634 ioRAW(file, s[i].sep_name, 8, from_file);
635 ioRAW(file, &(s[i].sep_value), 2, from_file);
636 ioRAW(file, s[i].sep_units, 8, from_file);
637 ioRAW(file, &(s[i].sep_low_trip), 7, from_file);
638 ioRAW(file, &(s[i].sep_stable), 2, from_file);
639 ioRAW(file, &(s[i].sep_cam_addr), 17, from_file);
646 ioRAW(file,
reinterpret_cast<int *
>(s),
sizeof(
DAEP_STRUCT) * len /
sizeof(
int), from_file);
653 for (i = 0; i < len; i++) {
654 ioRAW(file, &(s[i].d_comp), 3, from_file);
655 ioRAW(file, &(s[i].d_crdata), 2, from_file);
656 ioRAW(file, &(s[i].d_exp_filesize), 27, from_file);
664 for (i = 0; i < len; i++) {
665 ioRAW(file, &(s[i].nwords), 2, from_file);
673 for (i = 0; i < len; i++) {
674 ioRAW(file, &(s[i].ver), 2, from_file);
675 ioRAW(file, &(s[i].lines), s[i].nlines, from_file);
683 memset(padding,
' ',
sizeof(padding));
685 for (i = 0; i < len; i++) {
686 ioRAW(file, &(s[i].len), 1, from_file);
687 int nbytes_rounded = 4 * (1 + (s[i].
len - 1) / 4);
688 ioRAW(file, &(s[i].data), s[i].len, from_file);
689 ioRAW(file, padding, nbytes_rounded - s[i].len, from_file);
696 if ((len <= 0) || (s ==
nullptr)) {
701 size_t n = fread(s,
sizeof(
char), len, file);
702 return static_cast<int>(
n - len);
704 fwrite(s,
sizeof(
char), len, file);
712 if ((len <= 0) || (s ==
nullptr)) {
717 size_t n = fread(s,
sizeof(
int), len, file);
718 return static_cast<int>(
n - len);
720 fwrite(s,
sizeof(
int), len, file);
728 if ((len <= 0) || (s ==
nullptr)) {
733 size_t n = fread(s,
sizeof(uint32_t), len, file);
734 return static_cast<int>(
n - len);
736 fwrite(s,
sizeof(uint32_t), len, file);
744 if ((len <= 0) || (s ==
nullptr)) {
749 size_t n = fread(s,
sizeof(
float), len, file);
751 return static_cast<int>(
n - len);
754 fwrite(s,
sizeof(
float), len, file);
766 ioRAW(file, *s, len, from_file);
772 ioRAW(file, *s, len, from_file);
784 ioRAW(file, *s, len, from_file);
790 ioRAW(file, *s, len, from_file);
801 *s =
new uint32_t[len];
802 ioRAW(file, *s, len, from_file);
808 ioRAW(file, *s, len, from_file);
820 ioRAW(file, *s, len, from_file);
826 ioRAW(file, *s, len, from_file);
838 ioRAW(file, *s, len, from_file);
844 ioRAW(file, *s, len, from_file);
856 ioRAW(file, *s, len, from_file);
862 ioRAW(file, *s, len, from_file);
874 ioRAW(file, *s, len, from_file);
880 ioRAW(file, *s, len, from_file);
893 for (
unsigned i = 0; i <
sizeof(size_check_array) /
sizeof(
int); i += 2) {
894 if (size_check_array[i] != size_check_array[i + 1]) {
895 logger.error() <<
"size check failed\n";
906 struct tm *tmstruct =
nullptr;
907#ifdef MS_VISUAL_STUDIO
908 errno_t err = localtime_s(tmstruct, &time_value);
913 tmstruct = localtime(&time_value);
915 n = strftime(timbuf, len,
"%d-%b-%Y %H:%M:%S", tmstruct);
916 for (i = 0; i <
n; i++) {
917 timbuf[i] = toupper(timbuf[i]);
924#ifdef MS_VISUAL_STUDIO
925 FILE *input_file = NULL;
926 if (fopen_s(&input_file, filename,
"rb") != 0) {
930 FILE *input_file = fopen(filename,
"rb");
932 if (input_file !=
nullptr) {
933 ioRAW(input_file,
true, read_data);
944 os <<
"INST section at " <<
add.
ad_inst <<
" 0x" << std::hex << 4 *
add.
ad_inst << std::dec <<
'\n';
945 os <<
"SE section at " <<
add.
ad_se <<
" 0x" << std::hex << 4 *
add.
ad_se << std::dec <<
'\n';
946 os <<
"Dae section at " <<
add.
ad_dae <<
" 0x" << std::hex << 4 *
add.
ad_dae << std::dec <<
'\n';
947 os <<
"Tcb section at " <<
add.
ad_tcb <<
" 0x" << std::hex << 4 *
add.
ad_tcb << std::dec <<
'\n';
948 os <<
"User section at " <<
add.
ad_user <<
" 0x" << std::hex << 4 *
add.
ad_user << std::dec <<
'\n';
949 os <<
"Data section at " <<
add.
ad_data <<
" 0x" << std::hex << 4 *
add.
ad_data << std::dec <<
'\n';
950 os <<
"Log section at " <<
add.
ad_log <<
" 0x" << std::hex << 4 *
add.
ad_log << std::dec <<
'\n';
951 os <<
"End section at " <<
add.
ad_end <<
" 0x" << std::hex << 4 *
add.
ad_end << std::dec <<
'\n';
952 os <<
"User data len " <<
u_len <<
'\n';
953 os <<
"Compression is " << (
dhdr.
d_comp == 0 ?
"NONE" :
"BYTE-RELATIVE") <<
'\n';
954 os <<
"Compression ratio of data = " <<
dhdr.
d_crdata <<
'\n';
955 os <<
"Offsets of spectrum data\n";
1000 for (i = 0; i <
t_ntc1 + 1; i++) {
int byte_rel_expn(const char *data_in, int n_in, int n_from, int *data_out, int n_out)
int byte_rel_comp(const int *data_in, int n_in, char *data_out, int max_out, int &n_out)
HDR_STRUCT hdr
header block (80 bytes)
float * ut
nuse UT* user tables (total size NUSE*NDET) ut01=phi
LOG_STRUCT logsect
log section
ISISCRPT_STRUCT * m_crpt
CRPT from ICP.
int t_tcm1[5]
time channel mode
int i_use
number of user defined UTn tables NUSE
SPB_STRUCT spb
sample parameter block (64*4 bytes)
float * delt
hold off table (size NDET)
int * modn
module number for each detector (size NDET)
float t_tcp1[5][4]
time channel parameters
int e_nse
number of controlled SEPs NSEP
int getTimeChannels(float *rtcb1, int n)
rtcb1 is of size t_ntc1+1
char i_inst[8]
instrument name
uint32_t * dat1
compressed data for (NTC1+1)*(NSP1+1)*NPER values
int ver2
run section version number VER2 (=1)
int t_ntrg
number of time regimes (=1)
int i_det
number of detectors NDET
DAEP_STRUCT daep
DAE parameter block (size 64*4 bytes)
DDES_STRUCT * ddes
(NSP1+1)*NPER items, totoal size (NSP1+1)*NPER*2*4 bytes
int * code
code for UTn tables (size NDET)
int t_nper
number of periods
DHDR_STRUCT dhdr
size 32*4 bytes
int printInfo(std::ostream &os)
stuff
int * t_tcb1
time channel boundaries in clock pulses (size NTC1+1)
int t_nsp1
number of spectra in time regime 1
int * mdet
detector number for monitors (size NMON)
int ver3
instrument section version number (=2)
static int vmstime(char *timbuf, int len, time_t time_value)
stuff
item_struct< char > m_char_items
dunno
int readFromFile(const char *filename, bool read_data=true)
stuff
item_struct< float > m_real_items
dunno
int ver5
DAE section version number (=2)
int ver7
user version number (=1)
int * timr
time regime for each detector (size NDET)
USER_STRUCT user
user information (8*20 bytes)
int updateFromCRPT()
stuff
int i_mon
number of monitors NMON
int * crat
crate number for each detector (size NDET)
virtual int ioRAW(FILE *file, bool from_file, bool read_data=true)
stuff
int ver4
SE section version number (=2)
int ver8
data version number (=2)
float * u_dat
user defined data (ULEN, max size 400 words)
int data_format
data section format (0 = by TC, 1 = by spectrum)
char r_title[80]
run title
int * mpos
module position for each detector (size NDET)
int t_nfpp
number of frames per period
int ver6
TCB section version number (=1)
IVPB_STRUCT ivpb
instrument parameter block (64*4 bytes)
int * udet
user detector number for each detector (size NDET)
int * monp
prescale value for each monitor (size NMON)
int u_len
length of user data section
RPB_STRUCT rpb
run parameter block (32*4 bytes)
int * spec
spectrum number table (size NDET)
SE_STRUCT * e_seblock
NSEP SE parameter blocks (total size NSEP*32*4 bytes)
struct ADD_STRUCT add
9*4 bytes
int t_ntc1
number of time channels in time regime 1
float * tthe
2theta scattering angle (size NDET)
float * len2
L2 table (size NDET)
item_struct< int > m_int_items
dunno
int t_pre1
prescale for 32MHz clock
int t_pmap[256]
period number for each basic period
int frmt_ver_no
format version number VER1 (=2)
The Logger class is in charge of the publishing messages from the framework through various channels.
int addItem(const std::string &name, const T *value, bool det_average=false, const int *dim0=nullptr, const int *dim1=nullptr)
Adds an item.
ISIS VMS raw file definitions.
address offsets to various sections (9*4 bytes)
int ad_dae
ad_se + 66 + nse*32
int ad_user
ad_tcb + 288 + (ntc1 + 1)
int ad_data
ad_user + 2 + ulen
int ad_tcb
ad_dae + 65 + 5*ndet
int ad_run
32 (1+offset_of(ver2))
int ad_se
ad_inst + 70 + 2*nmon+(5+nuse)*ndet
DAE parameters block (64*4 bytes)
int mon1_module
module for MON 1 ( 4 bits) ***B
int a_pars
Word length in bulk store memory.
int mon1_mask
mask for MON 1 (c4:m4:d12) ***B
int tr_shift[3]
set to shift value (us) of each TR if (using_tr_shift >
int ppp_raw_low
raw PPP total (low 32 bits) ***B
int ext_vetos[3]
External vetoes 0,1,2 (0 dis,1.
int a_delay
frame synch delay (4�s steps) ***B
int mon2_crate
crate for MON 2 ( 4 bits) ***B
int ppp_good_high
good PPP total (high 32 bits) ***B
int mon1_crate
crate for MON 1 ( 4 bits) ***B
int ppp_good_low
good PPP total (low 32 bits) ***B
int a_sync
frm snch origin(0:none/1:ext/2:int)***B
int mem_size
Length of bulk store memory (bytes)**A.
int ppp_raw_high
raw PPP total (high 32 bits) ***B
int mon2_mask
mask for MON 2 (c4:m4:d12) ***B
int mon2_detector
detector for MON 2 (12 bits) ***B
int mon2_module
module for MON 2 ( 4 bits) ***B
int a_smp
Secondary Master Pulse (0:en,1:dis)
int mon1_detector
detector for MON 1 (12 bits) ***B
int nwords
number of compressed words in spectrum
int offset
offset to compressed spectrum
data section header (32*4 bytes)
int d_comp
compression type (0=none, 1 = byte relative)
float d_crfile
compression ratio for whole file
float d_crdata
compression ratio for data
int d_exp_filesize
equivalent version 1 filesize
char hd_date[12]
start date
char hd_time[8]
start time
char inst_abrv[3]
instrument abbreviated name
char hd_dur[8]
run duration (uA.hour) constructor
char hd_user[20]
user name
char hd_title[24]
short title
instrument parameter block (64*4 bytes)
float i_ycen
LOQ y centre.
float i_xsect
beam aperture horizontal (mm)
float i_aofi
angle of incidence (CRISP)
float i_sddist
source to detector distance (LOQ)
float i_l1
L1 scattering length.
float i_xcen
LOQ x centre.
float i_ysect
beam aperture vertical (mm)
int i_bestop
beam_stop LOQ
float i_foeang
foe angle LOQ
int len
real length of data
char * data
padded to multiple of 4 bytes
LOG_LINE * lines
size nlines
int nlines
number of lines
Run parameter block (32*4 bytes)
int r_dur_secs
actual run duration in seconds
int r_freq
2**k where source frequency = 50 / 2**k
int r_mon_sum2
monitor sum 2
char r_endtime[8]
format HH-MM-SS
char r_enddate[12]
format DD-MMM-YYYY
float r_gd_prtn_chrg
good proton charge (uA.hour)
int r_durunits
scaler for above (1=seconds)
int r_mon_sum1
monitor sum 1
int r_mon_sum3
monitor sum 3
int r_dur
actual run duration
int r_prop
RB (proposal) number.
float r_tot_prtn_chrg
total proton charge (uA.hour)
sample environment block (32*4 bytes)
sample parameter block (64*4 bytes)
int e_type
sample type (1=sample+can,2=empty can)
float e_width
sample width (mm)
float e_phi
phi sample angle (degrees)
int e_geom
sample geometry
float e_height
sample height (mm)
float e_thick
sample thickness normal to sample (mm)
user information (8*20 bytes)
char r_instit[20]
institute
void vaxf_to_local(float *val, const int *n, int *errcode)
void local_to_vaxf(float *val, const int *n, int *errcode)