ICP  1
isisraw.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 #include "isisraw.h"
3 #include "vms_convert.h"
4 #include "DAEstatus.h"
5 #include "byte_rel_comp.h"
6 
7 ISISRAW::ISISRAW() : m_crpt(NULL), m_ntc1(0), m_nsp1(0), m_nper(0)
8 {
9  int i, j;
10  // section 1
11  frmt_ver_no = 2; // format version number VER1 (=2)
12  data_format = 0; // data section format (0 = by TC, 1 = by spectrum)
13  // section 2
14  ver2 = 1; // run section version number VER2 (=1)
15  r_number = 0; // run number
16  memset(r_title, ' ', sizeof(r_title)); // run title
17  // section 3
18  ver3 = 2; // instrument section version number (=2)
19  memset(i_inst, ' ', sizeof(i_inst)); // instrument name
20  i_det = 1; // number of detectors NDET
21  i_mon = 1; // number of monitors NMON
22  i_use = 1; // number of user defined UTn tables NUSE
23  // I_TABLES is address of MDET
24  mdet = new int[i_mon]; // detector number for monitors (size NMON)
25  monp = new int[i_mon]; // prescale value for each monitor (size NMON)
26  for(i=0; i<i_mon; i++)
27  {
28  mdet[i] = i + 1;
29  monp[i] = 1;
30  }
31  spec = new int[i_det]; // spectrum number table (size NDET)
32  delt = new float[i_det]; // hold off table (size NDET)
33  len2 = new float[i_det]; // L2 table (size NDET)
34  code = new int[i_det]; // code for UTn tables (size NDET)
35  tthe = new float[i_det]; // 2theta scattering angle (size NDET)
36  ut = new float[i_use*i_det]; // nuse UT* user tables (total size NUSE*NDET) ut01=phi
37  for(i=0; i<i_det; i++)
38  {
39  spec[i] = i + 1; // we have t_nsp1 = i_det
40  delt[i] = (float)i;
41  len2[i] = (float)i;
42  code[i] = i + 1;
43  tthe[i] = (float)i;
44  }
45  for(i=0; i<i_use; i++)
46  {
47  for(j=0; j<i_det; j++)
48  {
49  ut[i*i_det+j] = (float)j;
50  }
51  }
52  // section 4
53  ver4 = 2; // SE section version number (=2)
54  e_nse = 1; // number of controlled SEPs NSEP
55  e_seblock = new SE_STRUCT[e_nse]; // NSEP SE parameter blocks (total size NSEP*32*4 bytes)
56  // section 5
57  ver5 = 2; // DAE section version number (=2)
58  crat = new int[i_det]; // crate number for each detector (size NDET)
59  modn = new int[i_det]; // module number for each detector (size NDET)
60  mpos = new int[i_det]; // module position for each detector (size NDET)
61  timr = new int[i_det]; // time regime for each detector (size NDET)
62  udet = new int[i_det]; // user detector number for each detector (size NDET)
63  for(i=0; i<i_det; i++)
64  {
65  crat[i] = 1;
66  modn[i] = 1;
67  mpos[i] = i;
68  timr[i] = 1;
69  udet[i] = i;
70  }
71  // section 6
72  ver6 = 1; // TCB section version number (=1)
73  t_ntrg = 1; // number of time regimes (=1)
74  t_nfpp = 1; // number of frames per period
75  t_nper = 1; // number of periods
76  for(i=0; i<256; i++)
77  {
78  t_pmap[i] = 1; // period number for each basic period
79  }
80  t_nsp1 = i_det; // number of spectra in time regime 1
81  t_ntc1 = 10; // number of time channels in time regime 1
82  memset(t_tcm1, 0, sizeof(t_tcm1)); // time channel mode
83  memset(t_tcp1, 0, sizeof(t_tcp1)); // time channel parameters
84  t_pre1 = 1; // prescale for 32MHz clock
85  t_tcb1 = new int[t_ntc1+1]; // time channel boundaries in clock pulses (size NTC1+1)
86  for(i=0; i<t_ntc1+1; i++)
87  {
88  t_tcb1[i] = i;
89  }
90  // section 7
91  // write NCHAN = NTC1+1 time channel boundaries
92  ver7 = 1; // user version number (=1)
93  u_len = 1;
94  u_dat = new float[u_len]; // user defined data (ULEN, max size 400 words)
95  for(i=0; i<u_len; i++)
96  {
97  u_dat[i] = (float)i;
98  }
99  // section 8
100  ver8 = 2; // data version number (=2)
101  // D_DATA points at ddes
102  ddes = new DDES_STRUCT[(t_nsp1+1)*t_nper]; // (NSP1+1)*NPER items, totoal size (NSP1+1)*NPER*2*4 bytes
103  dat1 = new isisU32_t[(t_ntc1+1)*(t_nsp1+1)*t_nper]; // compressed data for (NTC1+1)*(NSP1+1)*NPER values
104  for(i=0; i<(t_ntc1+1)*(t_nsp1+1)*t_nper; i++)
105  {
106  dat1[i] = i;
107  }
108  logsect.nlines = 1;
110  for(i=0; i<logsect.nlines; i++)
111  {
112  logsect.lines[i].data = "test log line";
113  logsect.lines[i].len = static_cast<int>(strlen(logsect.lines[i].data));
114  }
115  addItems();
116 }
117 
119 {
120  static const int hdr_size = sizeof(hdr) / sizeof(char);
121  static const int rrpb_size = sizeof(rpb) / sizeof(float);
122  static const int irpb_size = sizeof(rpb) / sizeof(int);
123  m_char_items.addItem("HDR", (const char*)&hdr, false, &hdr_size);
124  m_real_items.addItem("RRPB", (float*)&rpb, false, &rrpb_size);
125  m_int_items.addItem("IRPB", (int*)&rpb, false, &irpb_size);
126  return 0;
127 }
128 
129 // create one bound to a CRPT
130 ISISRAW::ISISRAW(ISISCRPT_STRUCT* crpt, isisU32_t* raw_data) : m_crpt(crpt), m_ntc1(0), m_nsp1(0), m_nper(0)
131 {
132  e_nse = 0;
133  e_seblock = 0;
134  u_dat = 0;
135  u_len = 0;
136  ddes = 0;
137  dat1 = 0;
138  logsect.nlines = 0;
139  logsect.lines = 0;
140  addItems();
141  dat1 = raw_data;
142  updateFromCRPT(crpt);
143 }
144 
145 // update from bound CRPT
147 {
148  char buffer[256];
149  if (crpt == NULL)
150  {
151  return 0;
152  }
153  int i;
154  spacePadCopy(hdr.inst_abrv, crpt->inst_abrv, sizeof(hdr.inst_abrv));
155 // workaround for numbers over 100000 - the real run number is stored in the r_number field
156  sprintf(buffer, "%05d", crpt->run_number % VMS_RUN_MASK);
157  spacePadCopy(hdr.hd_run, buffer, sizeof(hdr.hd_run));
158  spacePadCopy(hdr.hd_user, crpt->user_name, sizeof(hdr.hd_user));
159 // spacePadCopy(hdr.hd_title, crpt->short_title, sizeof(hdr.hd_title));
160  spacePadCopy(hdr.hd_title, crpt->long_title, sizeof(hdr.hd_title));
161  vmstime(buffer, sizeof(buffer), crpt->start_time);
162  spacePadCopy(hdr.hd_date, buffer, sizeof(hdr.hd_date)+sizeof(hdr.hd_time));
163  sprintf(buffer, "%8.2f", crpt->good_uamph);
164  spacePadCopy(hdr.hd_dur, buffer, sizeof(hdr.hd_dur));
165 
166  // section 1
167  frmt_ver_no = 2; // format version number VER1 (=2)
168  data_format = 0; // data section format (0 = by TC, 1 = by spectrum)
169  // section 2
170  ver2 = 1; // run section version number VER2 (=1)
171  r_number = crpt->run_number; // run number
172  spacePadCopy(r_title, crpt->long_title, sizeof(r_title)); // run title
173  spacePadCopy(user.r_user, crpt->user_name, sizeof(user.r_user));
174  spacePadCopy(user.r_instit, crpt->institute, sizeof(user.r_instit));
175  // rpb
176  rpb.r_dur = static_cast<int>(crpt->duration);
177  rpb.r_durunits = 1; // seconds
178  rpb.r_freq = 1; // 50Hz
179  rpb.r_gd_prtn_chrg = crpt->good_uamph;
181  rpb.r_goodfrm = crpt->good_frames;
182  rpb.r_rawfrm = crpt->total_frames;
183  rpb.r_dur_secs = static_cast<int>(crpt->duration);
184  rpb.r_mon_sum1 = ( (crpt->nmon > 0) ? crpt->monitor_sum[0] : 0 );
185  rpb.r_mon_sum2 = ( (crpt->nmon > 1) ? crpt->monitor_sum[1] : 0 );
186  rpb.r_mon_sum3 = ( (crpt->nmon > 2) ? crpt->monitor_sum[2] : 0 );
187  vmstime(buffer, sizeof(buffer), crpt->stop_time);
188  spacePadCopy(rpb.r_enddate, buffer, sizeof(rpb.r_enddate)+sizeof(rpb.r_endtime));
189  rpb.r_prop = crpt->rb_number;
190 
191  // section 3
192  ver3 = 2; // instrument section version number (=2)
193  spacePadCopy(i_inst, crpt->inst_name, sizeof(i_inst)); // instrument name
194  ivpb.i_l1 = crpt->i_l1;
195  if (!strcmp(crpt->beamstop_position, "IN"))
196  {
197  ivpb.i_bestop = 0;
198  }
199  else
200  {
201  ivpb.i_bestop = 1;
202  }
203  ivpb.i_xsect = crpt->aperture1;
204  ivpb.i_ysect = crpt->aperture2;
205  ivpb.i_sddist = crpt->sdd;
206 
208  ivpb.i_xcen = crpt->beam_centre_x;
209  ivpb.i_ycen = crpt->beam_centre_y;
212 
213  spb.e_phi = crpt->sample_phi_angle;
214  spb.e_height = crpt->sample_height;
215  spb.e_width = crpt->sample_width;
216  spb.e_thick = crpt->sample_thickness;
217  if (!stricmp(crpt->sample_type, "sample+can"))
218  {
219  spb.e_type = 1;
220  }
221  else if (!stricmp(crpt->sample_type, "empty can"))
222  {
223  spb.e_type = 2;
224  }
225  else if (!stricmp(crpt->sample_type, "vanadium"))
226  {
227  spb.e_type = 3;
228  }
229  else if (!stricmp(crpt->sample_type, "absorber"))
230  {
231  spb.e_type = 4;
232  }
233  else if (!stricmp(crpt->sample_type, "nothing"))
234  {
235  spb.e_type = 5;
236  }
237  else if (!stricmp(crpt->sample_type, "sample, no can"))
238  {
239  spb.e_type = 6;
240  }
241  else
242  {
243  spb.e_type = 1;
244  }
245 
246  if (!stricmp(crpt->sample_geometry, "cylinder") || !stricmp(crpt->sample_geometry, "cylindrical"))
247  {
248  spb.e_geom = 1;
249  }
250  else if (!stricmp(crpt->sample_geometry, "flat plate"))
251  {
252  spb.e_geom = 2;
253  }
254  else if (!stricmp(crpt->sample_geometry, "disc"))
255  {
256  spb.e_geom = 3;
257  }
258  else if (!stricmp(crpt->sample_geometry, "single crystal"))
259  {
260  spb.e_geom = 4;
261  }
262  else
263  {
264  spb.e_geom = 1;
265  }
266 
267  i_det = crpt->ndet; // number of detectors NDET
268  i_mon = crpt->nmon; // number of monitors NMON
269  i_use = crpt->nuse; // number of user defined UTn tables NUSE
270  // I_TABLES is address of MDET
271  mdet = crpt->mdet.c_array(); // detector number for monitors (size NMON)
272  monp = crpt->monp.c_array(); // prescale value for each monitor (size NMON)
273  spec = crpt->spec; // spectrum number table (size NDET)
274  delt = crpt->delt; // hold off table (size NDET)
275  len2 = crpt->len2; // L2 table (size NDET)
276  code = crpt->code; // code for UTn tables (size NDET)
277  tthe = crpt->tthe; // 2theta scattering angle (size NDET)
278  ut = crpt->ut; // nuse UT* user tables (total size NUSE*NDET) ut01=phi
279 
280  // section 4
281  ver4 = 2; // SE section version number (=2)
282  e_nse = 1; // number of controlled SEPs NSEP
283  delete[] e_seblock;
284  e_seblock = new SE_STRUCT[e_nse]; // NSEP SE parameter blocks (total size NSEP*32*4 bytes)
285  // section 5
286  ver5 = 2; // DAE section version number (=2)
287  daep.a_pars = 4; // 32bit dae memory
288  daep.mem_size = daep.a_pars * (crpt->nsp[0] + 1) * (crpt->ntc[0] + 1) * crpt->nper_daq;
289 
294 
295  if (crpt->nmon > 0)
296  {
297  i = crpt->mdet[0] - 1;
298  daep.mon1_detector = crpt->mpos[i];
299  daep.mon1_module = crpt->modn[i];
300  daep.mon1_crate = crpt->crat[i];
302  }
303  else
304  {
306  }
307  if (crpt->nmon > 1)
308  {
309  i = crpt->mdet[1] - 1;
310  daep.mon2_detector = crpt->mpos[i];
311  daep.mon2_module = crpt->modn[i];
312  daep.mon2_crate = crpt->crat[i];
314  }
315  else
316  {
318  }
319 
320  daep.a_smp = (crpt->vetos[SMPVeto].enabled != 0);
321  daep.ext_vetos[0] = (crpt->vetos[Ext0Veto].enabled != 0);
322  daep.ext_vetos[1] = (crpt->vetos[Ext1Veto].enabled != 0);
323  daep.ext_vetos[2] = (crpt->vetos[Ext2Veto].enabled != 0);
324  daep.a_delay = crpt->tcb_delay / 4;
325  switch(crpt->tcb_sync)
326  {
328  daep.a_sync = 1; // test clock
329  break;
330 
331  case FrameSyncISIS:
332  case FrameSyncSMP:
333  daep.a_sync = 0; // external
334  break;
335 
336  default:
337  daep.a_sync = crpt->tcb_sync; // others: muon, ts2onts1 (10Hz) etc.
338  break;
339  }
340  // two time regime mods
341  if (crpt->ntrg > 1)
342  {
343  daep.n_tr_shift = crpt->ntrg;
344  for(i=0; i<crpt->ntrg; i++)
345  {
346  daep.tr_shift[i] = crpt->tcb_trdelay[i];
347  }
348  }
349  else
350  {
351  daep.n_tr_shift = 0;
352  }
353  crat = crpt->crat; // crate number for each detector (size NDET)
354  modn = crpt->modn; // module number for each detector (size NDET)
355  mpos = crpt->mpos; // module position for each detector (size NDET)
356  timr = crpt->timr_crpt; // time regime for each detector (size NDET)
357  udet = crpt->udet; // user detector number for each detector (size NDET)
358  // section 6
359  ver6 = 1; // TCB section version number (=1)
360  t_ntrg = 1; // number of time regimes (=1)
361  t_nfpp = 1; // number of frames per period
362  t_nper = crpt->nper_daq; // number of periods
363  for(i=0; i<256; i++)
364  {
365  t_pmap[i] = 1; // period number for each basic period
366  }
367  // ISIS / OSIRIS
368  if ( (crpt->ntrg == 2) && (crpt->ntc[0] == crpt->ntc[1]) )
369  {
370  t_nsp1 = crpt->nsp[0] + crpt->nsp[1]; // number of spectra in time regime 1
371  }
372  else
373  {
374  t_nsp1 = crpt->nsp[0]; // number of spectra in time regime 1
375  }
376  t_ntc1 = crpt->ntc[0]; // number of time channels in time regime 1
377 
378  memset(t_tcm1, 0, sizeof(t_tcm1)); // time channel mode
379  memset(t_tcp1, 0, sizeof(t_tcp1)); // time channel parameters
380  // only 1 time regime
381  for(i=0; i<5; i++)
382  {
383  switch(crpt->tcr[0][i].mode)
384  {
385  case TCBRANGE_FILE:
386  t_tcm1[i] = 0;
387  break;
388  case TCBRANGE_CONST_T:
389  t_tcm1[i] = 1;
390  break;
391  case TCBRANGE_INC_T:
392  t_tcm1[i] = 2;
393  break;
394  default:
395  t_tcm1[i] = -1;
396  break;
397  }
398  t_tcp1[i][0] = crpt->tcr[0][i].start;
399  t_tcp1[i][1] = crpt->tcr[0][i].end;
400  t_tcp1[i][2] = crpt->tcr[0][i].tcpar[0]; // step
401  t_tcp1[i][3] = 0.0;
402  }
403  t_pre1 = 1; // prescale for 32MHz clock
404  t_tcb1 = crpt->tcb[0]; // time channel boundaries in clock pulses (size NTC1+1)
405  // section 7
406  // write NCHAN = NTC1+1 time channel boundaries
407  ver7 = 1; // user version number (=1)
408  u_len = 1;
409  delete[] u_dat;
410  u_dat = new float[u_len]; // user defined data (ULEN, max size 400 words)
411  for(i=0; i<u_len; i++)
412  {
413  u_dat[i] = (float)i;
414  }
415  // section 8
416  ver8 = 2; // data version number (=2)
417  // D_DATA points at ddes
418  if ((t_nsp1 != m_nsp1) || (t_nper != m_nper))
419  {
420  delete[] ddes;
421  ddes = new DDES_STRUCT[(t_nsp1+1)*t_nper]; // (NSP1+1)*NPER items, totoal size (NSP1+1)*NPER*2*4 bytes
422  }
423  if (crpt->log_nlines > 0)
424  {
425  logsect.nlines = crpt->log_nlines;
426  delete[]logsect.lines;
428  for(i=0; i<logsect.nlines; i++)
429  {
430  logsect.lines[i].data = &(crpt->log_data[i][0]);
431  logsect.lines[i].len = static_cast<int>(strlen(logsect.lines[i].data));
432  }
433  }
434  else
435  {
436  logsect.nlines = 0;
437  logsect.lines = NULL;
438  }
439  // for caching on updates
440  m_ntc1 = t_ntc1;
441  m_nsp1 = t_nsp1;
442  m_nper = t_nper;
443  return 0;
444 }
445 
447 {
448  if (crpt == NULL)
449  {
450  return 0;
451  }
452  int i;
453 
456 
457  spaceTrimCopy(crpt->inst_abrv, sizeof(crpt->inst_abrv), hdr.inst_abrv, sizeof(hdr.inst_abrv));
458  crpt->start_time = from_vmstime(hdr.hd_date, sizeof(hdr.hd_date)+sizeof(hdr.hd_time));
459  crpt->run_number = r_number; // run number
460  spaceTrimCopy(crpt->long_title, sizeof(crpt->long_title), r_title, sizeof(r_title));
461  spaceTrimCopy(crpt->user_name, sizeof(crpt->user_name), user.r_user, sizeof(user.r_user));
462  spaceTrimCopy(crpt->institute, sizeof(crpt->institute), user.r_instit, sizeof(user.r_instit));
463  // rpb
464  crpt->duration = rpb.r_dur_secs; // should also be same as rpb.r_dur
465  crpt->good_uamph = rpb.r_gd_prtn_chrg;
467  crpt->good_frames = rpb.r_goodfrm;
468  crpt->total_frames = rpb.r_rawfrm;
469  crpt->stop_time = from_vmstime(rpb.r_enddate, sizeof(rpb.r_enddate)+sizeof(rpb.r_endtime));
470  crpt->rb_number = rpb.r_prop;
471 
472  // section 3
473  spaceTrimCopy(crpt->inst_name, sizeof(crpt->inst_name), i_inst, sizeof(i_inst)); // instrument name
474  crpt->i_l1 = ivpb.i_l1;
475  if (ivpb.i_bestop == 0)
476  {
477  strcpy(crpt->beamstop_position, "IN");
478  }
479  else
480  {
481  strcpy(crpt->beamstop_position, "OUT");
482  }
483  crpt->aperture1 = ivpb.i_xsect;
484  crpt->aperture2 = ivpb.i_ysect;
485  crpt->sdd = ivpb.i_sddist;
486 
488  crpt->beam_centre_x = ivpb.i_xcen;
489  crpt->beam_centre_y = ivpb.i_ycen;
492 
493  crpt->sample_phi_angle = spb.e_phi;
494  crpt->sample_height = spb.e_height;
495  crpt->sample_width = spb.e_width;
496  crpt->sample_thickness = spb.e_thick;
497 
498  switch(spb.e_type)
499  {
500  case 1:
501  strcpy(crpt->sample_type, "sample+can");
502  break;
503 
504  case 2:
505  strcpy(crpt->sample_type, "empty can");
506  break;
507 
508  case 3:
509  strcpy(crpt->sample_type, "vanadium");
510  break;
511 
512  case 4:
513  strcpy(crpt->sample_type, "absorber");
514  break;
515 
516  case 5:
517  strcpy(crpt->sample_type, "nothing");
518  break;
519 
520  case 6:
521  strcpy(crpt->sample_type, "sample, no can");
522  break;
523 
524  default:
525  strcpy(crpt->sample_type, "sample+can");
526  break;
527  }
528 
529  switch(spb.e_geom)
530  {
531  case 1:
532  strcpy(crpt->sample_geometry, "cylinder");
533  break;
534  case 2:
535  strcpy(crpt->sample_geometry, "flat plate");
536  break;
537  case 3:
538  strcpy(crpt->sample_geometry, "disc");
539  break;
540  case 4:
541  strcpy(crpt->sample_geometry, "single crystal");
542  break;
543  default:
544  strcpy(crpt->sample_geometry, "cylinder");
545  break;
546  }
547 
548  crpt->ndet = i_det; // number of detectors NDET
549  crpt->nmon = i_mon; // number of monitors NMON
550  crpt->nuse = i_use; // number of user defined UTn tables NUSE
551  // I_TABLES is address of MDET
552  if (crpt->mdet.c_array() != mdet)
553  {
554  memcpy(crpt->mdet.c_array(), mdet, i_mon * sizeof(int)); // detector number for monitors (size NMON)
555  memcpy(crpt->monp.c_array(), monp, i_mon * sizeof(int)); // prescale value for each monitor (size NMON)
556  memcpy(crpt->spec, spec, i_det * sizeof(int)); // spectrum number table (size NDET)
557  memcpy(crpt->delt, delt, i_det * sizeof(float)); // hold off table (size NDET)
558  memcpy(crpt->len2, len2, i_det * sizeof(float)); // L2 table (size NDET)
559  memcpy(crpt->code, code, i_det * sizeof(int)); // code for UTn tables (size NDET)
560  memcpy(crpt->tthe, tthe, i_det * sizeof(float)); // 2theta scattering angle (size NDET)
561  memcpy(crpt->ut, ut, i_det * i_use * sizeof(float)); // nuse UT* user tables (total size NUSE*NDET) ut01=phi
562  }
567  crpt->vetos[SMPVeto].enabled = (daep.a_smp != 0);
568  crpt->vetos[Ext0Veto].enabled = (daep.ext_vetos[0] != 0);
569  crpt->vetos[Ext1Veto].enabled = (daep.ext_vetos[1] != 0);
570  crpt->vetos[Ext2Veto].enabled = (daep.ext_vetos[2] != 0);
571  crpt->tcb_delay = 4 * daep.a_delay;
572  if (daep.a_sync == 1)
573  {
575  }
576  else if (daep.a_sync == 0)
577  {
578  crpt->tcb_sync = FrameSyncISIS;
579  }
580  else
581  {
582  crpt->tcb_sync = (FrameSync)daep.a_sync;
583  }
584  if (crpt->crat != crat)
585  {
586  memcpy(crpt->crat, crat, i_det * sizeof(int)); // crate number for each detector (size NDET)
587  memcpy(crpt->modn, modn, i_det * sizeof(int)); // module number for each detector (size NDET)
588  memcpy(crpt->mpos, mpos, i_det * sizeof(int)); // module position for each detector (size NDET)
589  memcpy(crpt->timr_dae, timr, i_det * sizeof(int)); // time regime for each detector (size NDET)
590  memcpy(crpt->timr_crpt, timr, i_det * sizeof(int)); // time regime for each detector (size NDET)
591  memcpy(crpt->timr_file, timr, i_det * sizeof(int)); // time regime for each detector (size NDET)
592  memcpy(crpt->udet, udet, i_det * sizeof(int)); // user detector number for each detector (size NDET)
593  }
594  // section 6
595  // two time regime mods
596  if (daep.n_tr_shift > 0)
597  {
598  crpt->ntrg = daep.n_tr_shift;
599  for(i=0; i<crpt->ntrg; i++)
600  {
601  crpt->tcb_trdelay[i] = daep.tr_shift[i];
602  }
603  }
604  else
605  {
606  crpt->ntrg = t_ntrg;
607  }
608  crpt->nper = crpt->nper_daq = t_nper; // number of periods
609  crpt->nsp[0] = t_nsp1; // number of spectra in time regime 1
610  crpt->ntc[0] = t_ntc1; // number of time channels in time regime 1
611 
612 // memset(t_tcm1, 0, sizeof(t_tcm1)); // time channel mode
613 // memset(t_tcp1, 0, sizeof(t_tcp1)); // time channel parameters
614  if (crpt->tcb[0] != t_tcb1)
615  {
616  memcpy(crpt->tcb[0], t_tcb1, (t_ntc1+1)* sizeof(int)); // time channel boundaries in clock pulses (size NTC1+1)
617  }
618  crpt->time_scaler = 6; // microseconds as neutron dae
619  for(i=0; i<t_ntc1+1; i++)
620  {
621  crpt->rtcb[0][i] = 4 * daep.a_delay + t_tcb1[i] / 32.0f;
622  }
623  // section 7
624  // write NCHAN = NTC1+1 time channel boundaries
625  // section 8
626  // D_DATA points at ddes
627 // memcpy(crpt->raw_data, dat1, ;
628  crpt->log_nlines = logsect.nlines;
629  if (logsect.nlines > 0)
630  {
631  for(i=0; i<logsect.nlines; i++)
632  {
633  strcpy(&(crpt->log_data[i][0]), logsect.lines[i].data);
634  }
635  }
636  return 0;
637 }
638 
639 int ISISRAW::ioRAW(FILE* file, bool from_file)
640  {
641  int ndata, len_log, i;
642  fpos_t add_pos, dhdr_pos, keep_pos;
643  if (!from_file)
644  {
645  add.ad_run = 32;
646  add.ad_inst = add.ad_run + 94;
647  add.ad_se = add.ad_inst + 70 + 2*i_mon + (5+i_use)*i_det;
648  add.ad_dae = add.ad_se + 66 + e_nse*32;
649  add.ad_tcb = add.ad_dae + 65 + 5*i_det;
650  add.ad_user = add.ad_tcb + 288 + (t_ntc1 + 1);
651  add.ad_data = add.ad_user + 2 + u_len;
652  add.ad_log = 0; // we don't know it yet
653  add.ad_end = 0;
654  }
655  ioRAW(file, &hdr, 1, from_file);
656  ioRAW(file, &frmt_ver_no, 1, from_file);
657  fgetpos(file, &add_pos);
658  ioRAW(file, &add, 1, from_file);
659  ioRAW(file, &data_format, 3, from_file);
660  ioRAW(file, r_title, 80, from_file);
661  ioRAW(file, &user, 1, from_file);
662  ioRAW(file, &rpb, 1, from_file);
663  ioRAW(file, &ver3, 1, from_file);
664  ioRAW(file, i_inst, 8, from_file);
665  ioRAW(file, &ivpb, 1, from_file);
666  ioRAW(file, &i_det, 3, from_file);
667  ioRAW(file, &mdet, i_mon, from_file);
668  ioRAW(file, &monp, i_mon, from_file);
669  ioRAW(file, &spec, i_det, from_file);
670  ioRAW(file, &delt, i_det, from_file);
671  ioRAW(file, &len2, i_det, from_file);
672  ioRAW(file, &code, i_det, from_file);
673  ioRAW(file, &tthe, i_det, from_file);
674  ioRAW(file, &ut, i_use * i_det, from_file);
675  ioRAW(file, &ver4, 1, from_file);
676  ioRAW(file, &spb, 1, from_file);
677  ioRAW(file, &e_nse, 1, from_file);
678  ioRAW(file, &e_seblock, e_nse, from_file);
679  ioRAW(file, &ver5, 1, from_file);
680  ioRAW(file, &daep, 1, from_file);
681  ioRAW(file, &crat, i_det, from_file);
682  ioRAW(file, &modn, i_det, from_file);
683  ioRAW(file, &mpos, i_det, from_file);
684  ioRAW(file, &timr, i_det, from_file);
685  ioRAW(file, &udet, i_det, from_file);
686  ioRAW(file, &ver6, 267, from_file);
687  ioRAW(file, &(t_tcp1[0][0]), 20, from_file);
688  ioRAW(file, &t_pre1, 1, from_file);
689  ioRAW(file, &t_tcb1, t_ntc1+1, from_file);
690  ioRAW(file, &ver7, 1, from_file);
691 // it appear that the VMS ICP traditionally sets u_len to 1 regardless
692 // of its real size; thus we cannot rely on it for reading and must instead
693 // use section offsets
694  i = 0;
695  ioRAW(file, &i, 1, from_file);
696 // ioRAW(file, &u_len, 1, from_file);
697  if (from_file)
698  {
699  u_len = add.ad_data - add.ad_user - 2;
700  }
701  ioRAW(file, &u_dat, u_len, from_file);
702  ioRAW(file, &ver8, 1, from_file);
703  fgetpos(file, &dhdr_pos);
704  ioRAW(file, &dhdr, 1, from_file);
705  int ndes, nout, nwords, outbuff_size = 5 * (t_ntc1+1), offset;
706  if (outbuff_size < 100000)
707  outbuff_size = 100000; // this is just me being very cautious
708  char* outbuff = new char[outbuff_size];
709  if (dhdr.d_comp == 0)
710  {
711  ndata = t_nper * (t_nsp1+1) * (t_ntc1+1);
712  ndes = 0;
713  ioRAW(file, &dat1, ndata, from_file);
714  }
715  else
716  {
717  ndata = 0;
718  ndes = t_nper * (t_nsp1+1);
719  ioRAW(file, &ddes, ndes, from_file);
720  if (from_file)
721  {
722  if (dat1 != NULL && m_crpt == NULL) // we are not bound to a crpt
723  {
724  delete[] dat1;
725  dat1 = NULL;
726  }
727  if (dat1 == NULL)
728  {
729  dat1 = new isisU32_t[ndes*(t_ntc1+1)];
730  }
731  }
732  offset = 33 + ndes * 2;
733  DAEstatus status;
734  memset(outbuff, 0, outbuff_size); // so when we round up words we get a zero written
735  for(i=0; i<ndes; i++)
736  {
737  if (from_file)
738  {
739  nwords = ddes[i].nwords;
740  ioRAW(file, outbuff, 4*nwords, from_file);
741  byte_rel_expn(outbuff, 4*nwords, 0, (int*)&dat1[i*(t_ntc1+1)], t_ntc1+1, status);
742  }
743  else
744  {
745  byte_rel_comp((int*)&dat1[i*(t_ntc1+1)], t_ntc1+1, outbuff, outbuff_size, nout, status);
746  nwords = (3 + nout) / 4; // round up to words
747  ddes[i].nwords = nwords;
748  ddes[i].offset = offset + ndata;
749  ndata += nwords;
750  ioRAW(file, outbuff, 4*nwords, from_file);
751  }
752  }
753  }
754  delete[] outbuff;
755  // log section
756  ioRAW(file, &logsect, 1, from_file);
757  len_log = 2 + logsect.nlines;
758  for(i=0; i<logsect.nlines; i++)
759  {
760  len_log += (1 + (logsect.lines[i].len - 1)/4);
761  }
762  if (!from_file)
763  {
764  add.ad_log = add.ad_data + 33 + 2*ndes + ndata;
765  add.ad_end = add.ad_log + len_log;
766  int curr_data_size = add.ad_log - add.ad_data;
767  int uncomp_data_size = 33 + t_nper*(t_nsp1+1)*(t_ntc1+1);
768  int curr_filesize = add.ad_end - 1;
769  int uncomp_filesize = add.ad_data - 1 + uncomp_data_size + len_log;
770  dhdr.d_crdata = (float)uncomp_data_size / (float)curr_data_size;
771  dhdr.d_crfile = (float)uncomp_filesize / (float)curr_filesize;
772  dhdr.d_exp_filesize = uncomp_filesize / 128; // in 512 byte blocks (vms default allocation unit)
773  fgetpos(file, &keep_pos);
774  // update section addresses
775  fsetpos(file, &add_pos);
776  ioRAW(file, &add, 1, from_file);
777  // update data header and descriptors etc.
778  fsetpos(file, &dhdr_pos);
779  ioRAW(file, &dhdr, 1, from_file);
780  ioRAW(file, &ddes, ndes, from_file);
781  fsetpos(file, &keep_pos);
782  }
783  return 0;
784  }
785 
786  int ISISRAW::ioRAW(FILE* file, HDR_STRUCT* s, int len, bool from_file)
787  {
788  ioRAW(file, (char*)s, sizeof(HDR_STRUCT) * len, from_file);
789  return 0;
790  }
791 
792  int ISISRAW::ioRAW(FILE* file, ADD_STRUCT* s, int len, bool from_file)
793  {
794  ioRAW(file, (int*)s, (sizeof(ADD_STRUCT) * len / sizeof(int)), from_file);
795  return 0;
796  }
797 
798  int ISISRAW::ioRAW(FILE* file, USER_STRUCT* s, int len, bool from_file)
799  {
800  ioRAW(file, (char*)s, sizeof(USER_STRUCT) * len, from_file);
801  return 0;
802  }
803 
804  int ISISRAW::ioRAW(FILE* file, RPB_STRUCT* s, int len, bool from_file)
805  {
806  int i;
807  for(i=0; i<len; i++)
808  {
809  ioRAW(file, &(s[i].r_dur), 7, from_file);
810  ioRAW(file, &(s[i].r_gd_prtn_chrg), 2, from_file);
811  ioRAW(file, &(s[i].r_goodfrm), 7, from_file);
812  ioRAW(file, s[i].r_enddate, 20, from_file);
813  ioRAW(file, &(s[i].r_prop), 11, from_file);
814  }
815  return 0;
816  }
817 
818 
819  int ISISRAW::ioRAW(FILE* file, IVPB_STRUCT* s, int len, bool from_file)
820  {
821  int i;
822  for(i=0; i<len; i++)
823  {
824  ioRAW(file, &(s[i].i_chfreq), 3, from_file);
825  ioRAW(file, &(s[i].delay_c1), 14, from_file);
826  ioRAW(file, &(s[i].i_xsect), 2, from_file);
827  ioRAW(file, &(s[i].i_posn), 3, from_file);
828  ioRAW(file, &(s[i].i_l1), 1, from_file);
829  ioRAW(file, &(s[i].i_rfreq), 1, from_file);
830  ioRAW(file, &(s[i].i_renergy), 2, from_file);
831  ioRAW(file, &(s[i].i_rslit), 2, from_file);
832  ioRAW(file, &(s[i].i_xcen), 2, from_file);
833  ioRAW(file, &(s[i].i_bestop), 1, from_file);
834  ioRAW(file, &(s[i].i_radbest), 4, from_file);
835  ioRAW(file, s[i].spare, 29, from_file);
836  }
837  return 0;
838  }
839 
840  int ISISRAW::ioRAW(FILE* file, SPB_STRUCT* s, int len, bool from_file)
841  {
842  int i;
843  for(i=0; i<len; i++)
844  {
845  ioRAW(file, &(s[i].e_posn), 3, from_file);
846  ioRAW(file, &(s[i].e_thick), 16, from_file);
847  ioRAW(file, s[i].e_name, 40, from_file);
848  ioRAW(file, &(s[i].e_equip), 35, from_file);
849  }
850  return 0;
851  }
852 
853  int ISISRAW::ioRAW(FILE* file, SE_STRUCT* s, int len, bool from_file)
854  {
855  int i;
856  for(i=0; i<len; i++)
857  {
858  ioRAW(file, s[i].sep_name, 8, from_file);
859  ioRAW(file, &(s[i].sep_value), 2, from_file);
860  ioRAW(file, s[i].sep_units, 8, from_file);
861  ioRAW(file, &(s[i].sep_low_trip), 7, from_file);
862  ioRAW(file, &(s[i].sep_stable), 2, from_file);
863  ioRAW(file, &(s[i].sep_cam_addr), 17, from_file);
864  }
865  return 0;
866  }
867 
868  int ISISRAW::ioRAW(FILE* file, DAEP_STRUCT* s, int len, bool from_file)
869  {
870  ioRAW(file, (int*)s, sizeof(DAEP_STRUCT) * len / sizeof(int), from_file);
871  return 0;
872  }
873 
874  int ISISRAW::ioRAW(FILE* file, DHDR_STRUCT* s, int len, bool from_file)
875  {
876  int i;
877  for(i=0; i<len; i++)
878  {
879  ioRAW(file, &(s[i].d_comp), 3, from_file);
880  ioRAW(file, &(s[i].d_crdata), 2, from_file);
881  ioRAW(file, &(s[i].d_exp_filesize), 27, from_file);
882  }
883  return 0;
884  }
885 
886  int ISISRAW::ioRAW(FILE* file, DDES_STRUCT* s, int len, bool from_file)
887  {
888  int i;
889  for(i=0; i<len; i++)
890  {
891  ioRAW(file, &(s[i].nwords), 2, from_file);
892  }
893  return 0;
894  }
895 
896  int ISISRAW::ioRAW(FILE* file, LOG_STRUCT* s, int len, bool from_file)
897  {
898  int i;
899  for(i=0; i<len; i++)
900  {
901  ioRAW(file, &(s[i].ver), 2, from_file);
902  ioRAW(file, &(s[i].lines), s[i].nlines, from_file);
903  }
904  return 0;
905  }
906 
907  int ISISRAW::ioRAW(FILE* file, LOG_LINE* s, int len, bool from_file)
908  {
909  char padding[5];
910  memset(padding, ' ', sizeof(padding));
911  int i, nbytes_rounded;
912  for(i=0; i<len; i++)
913  {
914  ioRAW(file, &(s[i].len), 1, from_file);
915  nbytes_rounded = 4 * (1 + (s[i].len-1)/4);
916  ioRAW(file, &(s[i].data), s[i].len, from_file);
917  ioRAW(file, padding, nbytes_rounded - s[i].len, from_file);
918  }
919  return 0;
920  }
921 
922  int ISISRAW::ioRAW(FILE* file, char* s, int len, bool from_file)
923  {
924  size_t n;
925  if ( (len <= 0) || (s == 0) )
926  {
927  return 0;
928  }
929  if (from_file)
930  {
931  n = fread(s, sizeof(char), len, file);
932  }
933  else
934  {
935  n = fwrite(s, sizeof(char), len, file);
936  }
937  return 0;
938  }
939 
940  int ISISRAW::ioRAW(FILE* file, int* s, int len, bool from_file)
941  {
942  size_t n;
943  if ( (len <= 0) || (s == 0) )
944  {
945  return 0;
946  }
947  if (from_file)
948  {
949  n = fread(s, sizeof(int), len, file);
950  }
951  else
952  {
953  n = fwrite(s, sizeof(int), len, file);
954  }
955  return 0;
956  }
957 
958  int ISISRAW::ioRAW(FILE* file, isisU32_t* s, int len, bool from_file)
959  {
960  size_t n;
961  if ( (len <= 0) || (s == 0) )
962  {
963  return 0;
964  }
965  if (from_file)
966  {
967  n = fread(s, sizeof(isisU32_t), len, file);
968  }
969  else
970  {
971  n = fwrite(s, sizeof(isisU32_t), len, file);
972  }
973  return 0;
974  }
975 
976  int ISISRAW::ioRAW(FILE* file, float* s, int len, bool from_file)
977  {
978  size_t n;
979  int errcode = 0;
980  if ( (len <= 0) || (s == 0) )
981  {
982  return 0;
983  }
984  if (from_file)
985  {
986  n = fread(s, sizeof(float), len, file);
987  vaxf_to_local(s, &len, &errcode);
988  }
989  else
990  {
991  local_to_vaxf(s, &len, &errcode);
992  n = fwrite(s, sizeof(float), len, file);
993  vaxf_to_local(s, &len, &errcode);
994  }
995  return 0;
996  }
997 
998  int ISISRAW::ioRAW(FILE* file, char** s, int len, bool from_file)
999  {
1000  if (from_file)
1001  {
1002  if (len > 0)
1003  {
1004  *s = new char[len];
1005  ioRAW(file, *s, len, from_file);
1006  }
1007  else
1008  {
1009  *s = 0;
1010  }
1011  }
1012  else
1013  {
1014  if (*s != 0)
1015  {
1016  ioRAW(file, *s, len, from_file);
1017  }
1018  }
1019  return 0;
1020  }
1021 
1022  int ISISRAW::ioRAW(FILE* file, int** s, int len, bool from_file)
1023  {
1024  if (from_file)
1025  {
1026  if (len > 0)
1027  {
1028  *s = new int[len];
1029  ioRAW(file, *s, len, from_file);
1030  }
1031  else
1032  {
1033  *s = 0;
1034  }
1035  }
1036  else
1037  {
1038  if (*s != 0)
1039  {
1040  ioRAW(file, *s, len, from_file);
1041  }
1042  }
1043  return 0;
1044  }
1045 
1046  int ISISRAW::ioRAW(FILE* file, isisU32_t** s, int len, bool from_file)
1047  {
1048  if (from_file)
1049  {
1050  if (len > 0)
1051  {
1052  *s = new isisU32_t[len];
1053  ioRAW(file, *s, len, from_file);
1054  }
1055  else
1056  {
1057  *s = 0;
1058  }
1059  }
1060  else
1061  {
1062  if (*s != 0)
1063  {
1064  ioRAW(file, *s, len, from_file);
1065  }
1066  }
1067  return 0;
1068  }
1069 
1070 
1071  int ISISRAW::ioRAW(FILE* file, float** s, int len, bool from_file)
1072  {
1073  if (from_file)
1074  {
1075  if (len > 0)
1076  {
1077  *s = new float[len];
1078  ioRAW(file, *s, len, from_file);
1079  }
1080  else
1081  {
1082  *s = 0;
1083  }
1084  }
1085  else
1086  {
1087  if (*s != 0)
1088  {
1089  ioRAW(file, *s, len, from_file);
1090  }
1091  }
1092  return 0;
1093  }
1094 
1095  int ISISRAW::ioRAW(FILE* file, SE_STRUCT** s, int len, bool from_file)
1096  {
1097  if (from_file)
1098  {
1099  if (len > 0)
1100  {
1101  *s = new SE_STRUCT[len];
1102  ioRAW(file, *s, len, from_file);
1103  }
1104  else
1105  {
1106  *s = 0;
1107  }
1108  }
1109  else
1110  {
1111  if (*s != 0)
1112  {
1113  ioRAW(file, *s, len, from_file);
1114  }
1115  }
1116  return 0;
1117  }
1118 
1119  int ISISRAW::ioRAW(FILE* file, DDES_STRUCT** s, int len, bool from_file)
1120  {
1121  if (from_file)
1122  {
1123  if (len > 0)
1124  {
1125  *s = new DDES_STRUCT[len];
1126  ioRAW(file, *s, len, from_file);
1127  }
1128  else
1129  {
1130  *s = 0;
1131  }
1132  }
1133  else
1134  {
1135  if (*s != 0)
1136  {
1137  ioRAW(file, *s, len, from_file);
1138  }
1139  }
1140  return 0;
1141  }
1142 
1143  int ISISRAW::ioRAW(FILE* file, LOG_LINE** s, int len, bool from_file)
1144  {
1145  if (from_file)
1146  {
1147  if (len > 0)
1148  {
1149  *s = new LOG_LINE[len];
1150  ioRAW(file, *s, len, from_file);
1151  }
1152  else
1153  {
1154  *s = 0;
1155  }
1156  }
1157  else
1158  {
1159  if (*s != 0)
1160  {
1161  ioRAW(file, *s, len, from_file);
1162  }
1163  }
1164  return 0;
1165  }
1166 
1168  {
1169  static int size_check_array[] = {
1170  sizeof(HDR_STRUCT), 80,
1171  sizeof(ADD_STRUCT), 9*4,
1172  sizeof(USER_STRUCT), 8*20,
1173  sizeof(RPB_STRUCT), 32*4,
1174  sizeof(IVPB_STRUCT), 64*4,
1175  sizeof(SPB_STRUCT), 64*4,
1176  sizeof(SE_STRUCT), 32*4,
1177  sizeof(DAEP_STRUCT), 64*4,
1178  sizeof(DHDR_STRUCT), 32*4,
1179  sizeof(DDES_STRUCT), 2*4
1180  };
1181  int i;
1182  for(i=0; i<sizeof(size_check_array)/sizeof(int); i += 2)
1183  {
1184  if (size_check_array[i] != size_check_array[i+1])
1185  {
1186  std::cerr << "ISISRAW size check failed for " << i/2 << std::endl;
1187  return -1;
1188  }
1189  }
1190  return 0;
1191  }
1192 int ISISRAW::vmstime(char* timbuf, int len, time_t time_value)
1193 {
1194 /*
1195  * get time in VMS format 01-JAN-1970 00:00:00
1196  */
1197  size_t i, n;
1198  struct tm *tmstruct;
1199  tmstruct = localtime((time_t*)&time_value);
1200  n = strftime(timbuf, len, "%d-%b-%Y %H:%M:%S", tmstruct);
1201  for(i=0; i<n; i++)
1202  {
1203  timbuf[i] = toupper(timbuf[i]);
1204  }
1205  return DAEstatus::Success;
1206 }
1207 
1208 static const char* months[] = { "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
1209  "JUL", "AUG", "SEP", "OCT", "NOV", "DEC", NULL };
1210 
1211 time_t ISISRAW::from_vmstime(const char* timbuf, int len)
1212 {
1213  char month[4];
1214  int year, i, n;
1215  struct tm tms;
1216  char* timstr = new char[len+1];
1217  strncpy(timstr, timbuf, len);
1218  timstr[len] = '\0';
1219  n = sscanf(timstr, "%d-%3c-%d %d:%d:%d", &(tms.tm_mday), month, &year,
1220  &(tms.tm_hour), &(tms.tm_min), &(tms.tm_sec));
1221  delete[] timstr;
1222  if (n != 6)
1223  {
1224  return (time_t)-1;
1225  }
1226  month[3] = '\0';
1227  tms.tm_year = year - 1900;
1228  tms.tm_isdst = -1;
1229  tms.tm_mon = 0;
1230  for(i = 0; months[i] != NULL; i++)
1231  {
1232  if (!strcmp(months[i], month))
1233  tms.tm_mon = i;
1234  }
1235  return mktime(&tms);
1236 }
1237 
1238 
1239 int ISISRAW::readFromFile(const char* filename)
1240 {
1241  FILE* input_file = _fsopen(filename,"rbN",_SH_DENYWR);
1242  if (input_file != NULL)
1243  {
1244  ioRAW(input_file, true);
1245  fclose(input_file);
1246  return 0;
1247  }
1248  else
1249  {
1250  return -1;
1251  }
1252 }
1253 
1254 
1255 int ISISRAW::writeToFile(const char* filename)
1256 {
1257  unsigned char zero_pad[512];
1258  int npad;
1259  long pos;
1260  memset(zero_pad, 0, sizeof(zero_pad));
1261  remove(filename);
1262  FILE* output_file = _fsopen(filename,"w+bcN",_SH_DENYWR);
1263  if (output_file != NULL)
1264  {
1265  ioRAW(output_file, false);
1266  fflush(output_file);
1267  // we need to pad to a multiple of 512 bytes for VMS compatibility
1268  fseek(output_file, 0, SEEK_END);
1269  pos = ftell(output_file);
1270  if (pos % 512 > 0)
1271  {
1272  npad = 512 - pos % 512;
1273  fwrite(zero_pad, 1, npad, output_file);
1274  }
1275  fclose(output_file);
1276  return 0;
1277  }
1278  else
1279  {
1280  return -1;
1281  }
1282 }
1283 
1284 int ISISRAW::printInfo(std::ostream& os)
1285 {
1286  long offset;
1287  os << "INST section at " << add.ad_inst << " 0x" << std::hex << 4*add.ad_inst << std::dec << std::endl;
1288  os << "SE section at " << add.ad_se << " 0x" << std::hex << 4*add.ad_se << std::dec << std::endl;
1289  os << "Dae section at " << add.ad_dae << " 0x" << std::hex << 4*add.ad_dae << std::dec << std::endl;
1290  os << "Tcb section at " << add.ad_tcb << " 0x" << std::hex << 4*add.ad_tcb << std::dec << std::endl;
1291  os << "User section at " << add.ad_user << " 0x" << std::hex << 4*add.ad_user << std::dec << std::endl;
1292  os << "Data section at " << add.ad_data << " 0x" << std::hex << 4*add.ad_data << std::dec << std::endl;
1293  os << "Log section at " << add.ad_log << " 0x" << std::hex << 4*add.ad_log << std::dec << std::endl;
1294  os << "End section at " << add.ad_end << " 0x" << std::hex << 4*add.ad_end << std::dec << std::endl;
1295  os << "User data len " << u_len << std::endl;
1296  os << "Compression is " << (dhdr.d_comp == 0 ? "NONE" : "BYTE-RELATIVE") << std::endl;
1297  os << "Compression ratio of data = " << dhdr.d_crdata << std::endl;
1298  os << "Offsets of spectrum data" << std::endl;
1299  offset = add.ad_data;
1300 // for(i=0; i < ((t_nsp1+1) * t_nper); i++)
1301 // {
1302 // os << i << " " << ddes[i].nwords << " words at offset " << ddes[i].offset << std::endl;
1303 // }
1304  return 0;
1305 }
1306 
1308 {
1309  if (m_crpt == NULL && dat1 != NULL)
1310  {
1311  delete[] dat1;
1312  }
1313  delete[] ddes;
1314  delete[] e_seblock;
1315  delete[] u_dat;
1316  delete[] logsect.lines;
1317 }
int t_ntrg
Definition: isisraw.h:297
DDES_STRUCT * ddes
Definition: isisraw.h:316
int * udet
Definition: isisraw.h:294
USER_STRUCT user
Definition: isisraw.h:263
int ioRAW(FILE *file, bool from_file)
Definition: isisraw.cpp:639
char sample_geometry[80]
Definition: isiscrpt.h:416
float i_xcen
Definition: isisraw.h:102
int r_dur_secs
Definition: isisraw.h:61
int timr_crpt[ISISCRPT_MAX_DETECTOR]
Definition: isiscrpt.h:313
int code[ISISCRPT_MAX_DETECTOR]
Definition: isiscrpt.h:304
ISISCRPT_STRUCT * m_crpt
Definition: isisraw.h:242
int udet[ISISCRPT_MAX_DETECTOR]
Definition: isiscrpt.h:315
char log_data[ISISCRPT_LOG_MAXLINES][ISISCRPT_LOG_LINELEN]
Definition: isiscrpt.h:429
int byte_rel_comp(int *data_in, int n_in, char *data_out, int max_out, int &n_out, DAEstatus &status)
int * monp
Definition: isisraw.h:274
int r_goodfrm
Definition: isisraw.h:58
float sample_phi_angle
Definition: isiscrpt.h:422
float rtcb[ISISCRPT_MAX_NTRG][ISISCRPT_MAX_TIMECHANB]
Definition: isiscrpt.h:344
int a_smp
Definition: isisraw.h:193
int ver5
Definition: isisraw.h:287
int t_tcm1[5]
Definition: isisraw.h:303
int modn[ISISCRPT_MAX_DETECTOR]
Definition: isiscrpt.h:308
int r_durunits
Definition: isisraw.h:50
int t_pre1
Definition: isisraw.h:305
int r_rawfrm
Definition: isisraw.h:59
int ppp_raw_low
Definition: isisraw.h:174
float sample_thickness
Definition: isiscrpt.h:412
float sample_height
Definition: isiscrpt.h:411
char hd_time[8]
Definition: isisraw.h:16
int ver3
Definition: isisraw.h:266
int ppp_good_low
Definition: isisraw.h:172
float i_ysect
Definition: isisraw.h:92
int ad_data
Definition: isisraw.h:30
static int vmstime(char *timbuf, int len, time_t time_value)
Definition: isisraw.cpp:1192
int frmt_ver_no
Definition: isisraw.h:256
boost::array< float, ISISCRPT_MAX_TCPAR > tcpar
Definition: isiscrpt.h:132
int a_pars
Definition: isisraw.h:168
float r_gd_prtn_chrg
Definition: isisraw.h:56
time_t start_time
Definition: isiscrpt.h:254
int t_pmap[256]
Definition: isisraw.h:300
float sample_width
Definition: isiscrpt.h:410
unsigned long isisU32_t
Definition: isisvme_types.h:8
int ppp_raw_high
Definition: isisraw.h:173
int readFromFile(const char *filename)
Definition: isisraw.cpp:1239
float t_tcp1[5][4]
Definition: isisraw.h:304
#define TCBRANGE_CONST_T
dt=c
Definition: isiscrpt.h:121
DHDR_STRUCT dhdr
Definition: isisraw.h:314
int offset
Definition: isisraw.h:218
float i_ycen
Definition: isisraw.h:103
int mode
must be a TCBRANGE_* define
Definition: isiscrpt.h:129
float i_aofi
Definition: isisraw.h:108
float * delt
Definition: isisraw.h:276
int spaceTrimCopy(char *output, int output_size, const char *input, int input_size)
Definition: isiscrpt.cpp:161
int mpos[ISISCRPT_MAX_DETECTOR]
Definition: isiscrpt.h:309
int printInfo(std::ostream &os)
Definition: isisraw.cpp:1284
float total_uamph
Definition: isiscrpt.h:281
static const int Success
Definition: DAEstatus.h:140
unsigned good_frames
Definition: isiscrpt.h:278
int mon2_mask
Definition: isisraw.h:188
int mon1_module
Definition: isisraw.h:182
static time_t from_vmstime(const char *timbuf, int len)
Definition: isisraw.cpp:1211
boost::array< int, ISISCRPT_MAX_MONITOR > monp
Definition: isiscrpt.h:296
int mon1_detector
Definition: isisraw.h:181
static int size_check()
Definition: isisraw.cpp:1167
int mon2_crate
Definition: isisraw.h:187
int m_nsp1
Definition: isisraw.h:245
float aperture2
Definition: isiscrpt.h:409
#define TCBRANGE_FILE
read from file
Definition: isiscrpt.h:119
float beam_centre_x
Definition: isiscrpt.h:406
int * code
Definition: isisraw.h:278
void local_to_vaxf(float *val, const int *n, int *errcode)
char beamstop_position[16]
Definition: isiscrpt.h:414
ISISRAW()
Definition: isisraw.cpp:7
int i_bestop
Definition: isisraw.h:104
int timr_dae[ISISCRPT_MAX_DETECTOR]
Definition: isiscrpt.h:312
float * tthe
Definition: isisraw.h:279
int mon1_mask
Definition: isisraw.h:184
float tthe[ISISCRPT_MAX_DETECTOR]
Definition: isiscrpt.h:305
int * modn
Definition: isisraw.h:291
float * ut
Definition: isisraw.h:280
char * data
Definition: isisraw.h:226
boost::array< VETO, ISISCRPT_NUM_VETOS > vetos
Definition: isiscrpt.h:360
int ppp_good_high
Definition: isisraw.h:171
int i_use
Definition: isisraw.h:271
char institute[ISISCRPT_INSTITUTE_NAME_LEN+1]
Definition: isiscrpt.h:354
char r_enddate[12]
Definition: isisraw.h:65
item_struct< char > m_char_items
Definition: isisraw.h:248
isisU32_t good_ppp_high
Definition: isiscrpt.h:283
int byte_rel_expn(char *data_in, int n_in, int n_from, int *data_out, int n_out, DAEstatus &status)
float d_crdata
Definition: isisraw.h:208
isisU32_t total_ppp_high
Definition: isiscrpt.h:285
int r_mon_sum1
Definition: isisraw.h:62
float * u_dat
Definition: isisraw.h:311
int ad_end
Definition: isisraw.h:32
float r_tot_prtn_chrg
Definition: isisraw.h:57
float delt[ISISCRPT_MAX_DETECTOR]
Definition: isiscrpt.h:302
int updateFromCRPT()
Definition: isisraw.h:331
int mon2_detector
Definition: isisraw.h:185
char hd_title[24]
Definition: isisraw.h:14
float i_l1
Definition: isisraw.h:96
char i_inst[8]
Definition: isisraw.h:267
int dae_type
time CRPT unloaded (may not be set if program crashed)
Definition: isiscrpt.h:247
int t_nper
Definition: isisraw.h:299
char long_title[ISISCRPT_TITLE_LEN+1]
Definition: isiscrpt.h:350
int r_number
Definition: isisraw.h:261
int e_type
Definition: isisraw.h:116
boost::array< unsigned, ISISCRPT_MAX_MONITOR > monitor_sum
Definition: isiscrpt.h:300
int r_prop
Definition: isisraw.h:67
int ver7
Definition: isisraw.h:309
float d_crfile
Definition: isisraw.h:209
time_t stop_time
Definition: isiscrpt.h:256
float i_sddist
Definition: isisraw.h:106
int i_det
Definition: isisraw.h:269
int mem_size
Definition: isisraw.h:169
#define TCBRANGE_INC_T
dt/t=c
Definition: isiscrpt.h:122
int * timr
Definition: isisraw.h:293
char inst_abrv[3]
Definition: isisraw.h:11
int ad_dae
Definition: isisraw.h:27
int r_mon_sum2
Definition: isisraw.h:63
float angle_of_incidence
Definition: isiscrpt.h:421
int tcb[ISISCRPT_MAX_NTRG][ISISCRPT_MAX_TIMECHANB]
Definition: isiscrpt.h:343
isisU32_t * dat1
Definition: isisraw.h:317
int d_comp
Definition: isisraw.h:205
int r_mon_sum3
Definition: isisraw.h:64
int d_exp_filesize
Definition: isisraw.h:210
LOG_LINE * lines
Definition: isisraw.h:234
boost::array< int, ISISCRPT_MAX_NTRG > tcb_trdelay
Definition: isiscrpt.h:270
FrameSync
Definition: isiscrpt_types.h:5
int spec[ISISCRPT_MAX_DETECTOR]
Definition: isiscrpt.h:301
float chopper_opening_angle
Definition: isiscrpt.h:415
int data_format
Definition: isisraw.h:258
unsigned total_frames
Definition: isiscrpt.h:279
int ad_log
Definition: isisraw.h:31
boost::array< int, ISISCRPT_MAX_MONITOR > mdet
Definition: isiscrpt.h:295
isisU32_t good_ppp_low
Definition: isiscrpt.h:282
int t_nsp1
Definition: isisraw.h:301
int writeToFile(const char *filename)
Definition: isisraw.cpp:1255
float e_height
Definition: isisraw.h:119
int addItems()
Definition: isisraw.cpp:118
float good_uamph
Definition: isiscrpt.h:280
int i_mon
Definition: isisraw.h:270
char hd_date[12]
Definition: isisraw.h:15
float i_chopsiz
Definition: isisraw.h:83
float foe_mirror_angle
Definition: isiscrpt.h:413
int * t_tcb1
Definition: isisraw.h:306
RPB_STRUCT rpb
Definition: isisraw.h:264
LOG_STRUCT logsect
Definition: isisraw.h:318
char inst_abrv[ISISCRPT_INST_ABRV_LEN+1]
Definition: isiscrpt.h:352
int t_nfpp
Definition: isisraw.h:298
int ad_tcb
Definition: isisraw.h:28
int ver4
Definition: isisraw.h:282
char hd_dur[8]
Definition: isisraw.h:17
int nwords
Definition: isisraw.h:217
int * mdet
Definition: isisraw.h:273
SPB_STRUCT spb
Definition: isisraw.h:283
int sendToCRPT()
Definition: isisraw.h:332
int crat[ISISCRPT_MAX_DETECTOR]
Definition: isiscrpt.h:307
float i_xsect
Definition: isisraw.h:91
int * spec
Definition: isisraw.h:275
int ad_se
Definition: isisraw.h:26
item_struct< int > m_int_items
Definition: isisraw.h:250
float e_phi
Definition: isisraw.h:123
char r_user[20]
Definition: isisraw.h:38
DAEP_STRUCT daep
Definition: isisraw.h:288
int nlines
Definition: isisraw.h:233
int timr_file[ISISCRPT_MAX_DETECTOR]
Definition: isiscrpt.h:314
int ver8
Definition: isisraw.h:313
int t_ntc1
Definition: isisraw.h:302
char sample_type[80]
Definition: isiscrpt.h:417
int mon2_module
Definition: isisraw.h:186
char r_title[80]
Definition: isisraw.h:262
TCBRANGE tcr[ISISCRPT_MAX_NTRG][ISISCRPT_MAX_TCR]
Definition: isiscrpt.h:338
boost::array< int, ISISCRPT_MAX_NTRG > ntc
number of time channels per CRPT time regime
Definition: isiscrpt.h:346
static const char * months[]
Definition: isisraw.cpp:1208
int * mpos
Definition: isisraw.h:292
int mon1_crate
Definition: isisraw.h:183
time_t duration
Definition: isiscrpt.h:257
char user_name[ISISCRPT_USER_NAME_LEN+1]
Definition: isiscrpt.h:353
char inst_name[ISISCRPT_INST_LEN+1]
Definition: isiscrpt.h:351
HDR_STRUCT hdr
Definition: isisraw.h:255
float * len2
Definition: isisraw.h:277
int ext_vetos[3]
Definition: isisraw.h:194
isisU32_t total_ppp_low
Definition: isiscrpt.h:284
int ad_inst
Definition: isisraw.h:25
int e_geom
Definition: isisraw.h:117
int n_tr_shift
Definition: isisraw.h:196
float end
Definition: isiscrpt.h:131
struct ADD_STRUCT add
Definition: isisraw.h:257
float i_foeang
Definition: isisraw.h:107
#define VMS_RUN_MASK
need to wrap VMS run numbers to fit into 5 digits
Definition: isisraw.h:7
float aperture1
Definition: isiscrpt.h:408
int e_nse
Definition: isisraw.h:284
FrameSync tcb_sync
Definition: isiscrpt.h:271
float len2[ISISCRPT_MAX_DETECTOR]
Definition: isiscrpt.h:303
int ver2
Definition: isisraw.h:260
char r_instit[20]
Definition: isisraw.h:42
float ut[ISISCRPT_MAX_USER *ISISCRPT_MAX_DETECTOR]
Definition: isiscrpt.h:306
int a_sync
Definition: isisraw.h:192
int ad_run
Definition: isisraw.h:24
int ver6
Definition: isisraw.h:296
SE_STRUCT * e_seblock
Definition: isisraw.h:285
char hd_run[5]
Definition: isisraw.h:12
int a_delay
Definition: isisraw.h:191
void vaxf_to_local(float *val, const int *n, int *errcode)
int r_freq
Definition: isisraw.h:55
int m_ntc1
Definition: isisraw.h:244
item_struct< float > m_real_items
Definition: isisraw.h:249
float beam_centre_y
Definition: isiscrpt.h:407
boost::array< int, ISISCRPT_MAX_NTRG > nsp
number of spectra per CRPT time regime
Definition: isiscrpt.h:334
int len
Definition: isisraw.h:225
int * crat
Definition: isisraw.h:290
IVPB_STRUCT ivpb
Definition: isisraw.h:268
char r_endtime[8]
Definition: isisraw.h:66
float e_thick
Definition: isisraw.h:118
char hd_user[20]
Definition: isisraw.h:13
int ad_user
Definition: isisraw.h:29
int spacePadCopy(char *output, const char *input, int output_size)
Definition: isiscrpt.cpp:127
int addItem(const std::string &name, const T *value, bool det_average=false, const int *dim0=NULL, const int *dim1=NULL)
Definition: item_struct.h:26
int u_len
Definition: isisraw.h:310
int r_dur
Definition: isisraw.h:49
int m_nper
Definition: isisraw.h:246
float e_width
Definition: isisraw.h:120
~ISISRAW()
Definition: isisraw.cpp:1307
float start
Definition: isiscrpt.h:130
int tr_shift[3]
Definition: isisraw.h:197