PEARL Procedures  rev-distro-3.0.0-0-gfa24916-dirty
Igor procedures for the analysis of PEARL data
pearl-data-explorer.ipf
Go to the documentation of this file.
1 #pragma TextEncoding = "UTF-8"
2 #pragma rtGlobals=3 // Use modern global access method and strict wave access.
3 #pragma IgorVersion = 6.36
4 #pragma ModuleName = PearlDataExplorer
5 #pragma version = 2.1
6 #include <HierarchicalListWidget>, version >= 1.14
7 #include "pearl-area-import"
8 #include "pearl-area-profiles"
9 #include "pearl-area-display"
10 #include "pearl-compat"
11 #include "pearl-pshell-import"
12 
13 // copyright (c) 2013-22 Paul Scherrer Institut
14 //
15 // Licensed under the Apache License, Version 2.0 (the "License");
16 // you may not use this file except in compliance with the License.
17 // You may obtain a copy of the License at
18 // http:///www.apache.org/licenses/LICENSE-2.0
19 
29 
34 
35 static strconstant package_name = "pearl_explorer"
36 static strconstant package_path = "root:packages:pearl_explorer:"
37 
38 static strconstant ks_filematch_adh5 = "*.h5"
39 static strconstant ks_filematch_pshell = "psh*.h5"
40 static strconstant ks_filematch_itx = "*.itx"
41 
48  DoWindow /HIDE=0 /F PearlDataExplorer
49  if (v_flag == 0)
50  init_package()
51  load_prefs()
52  execute /q/z "PearlDataExplorer()"
53  MakeListIntoHierarchicalList("PearlDataExplorer", "lb_contents", "PearlDataExplorer#hlp_contents_open", selectionMode=WMHL_SelectionNonContinguous, pathSeparator="/")
54  WMHL_AddColumns("PearlDataExplorer", "lb_contents", 1)
55  WMHL_SetNotificationProc("PearlDataExplorer", "lb_contents", "PearlDataExplorer#hlp_contents_selection", WMHL_SetSelectNotificationProc)
56  ListBox lb_contents win=PearlDataExplorer, widths={6,60,20}
58  endif
59 end
60 
61 static function init_package()
62  dfref save_df = GetDataFolderDFR()
63  SetDataFolder root:
64  newdatafolder /o/s packages
65  newdatafolder /o/s $package_name
66  if (exists("v_InitPanelDone") == 2)
67  SetDataFolder save_df
68  return 0
69  endif
70 
71  make /o/n=0/t wtFiles
72  make /o/n=0/i wSelectedFiles,wSelectedDatasets
73  make /o/n=0/t wtDatasets
74  make /o/n=0/t wtPositioners,wtDetectors
75  make /o/n=0/i wSelectedPositioners,wSelectedDetectors
76 
77  make /o/n=(1,1) preview_image // preview 2D data
78  make /o/n=0 preview_trace // preview 1D data
79  make /o/n=0/t attr_names, attr_values, attr_filter, attr_filter_summary
80 
81  // persistent strings and variables. persistent = saved in preferences
82  string /g s_filepath = "" // directory path to be listed
83  string /g s_hdf_options = "" // recently used HDF5 load options
84  string /g s_reduction_params = "" // recently used reduction parameters
85  string /g s_preview_pvs = "" // semicolon-separated list of EPICS PVs to display in preview.
86  // the list items can contain wildcards for StringMatch
87  s_preview_pvs = "*OP:CURRENT*;*Stats*Total*;*KEITHLEY*READOUT;*CADC*"
88 
89  redimension /n=26 attr_filter_summary
90  attr_filter_summary[0] = "MonoEnergy"
91  attr_filter_summary[1] = "MonoGrating"
92  attr_filter_summary[2] = "ExitSlit"
93  attr_filter_summary[3] = "FrontendHSize"
94  attr_filter_summary[4] = "FrontendVSize"
95  attr_filter_summary[5] = "ManipulatorPhi"
96  attr_filter_summary[6] = "ManipulatorTheta"
97  attr_filter_summary[7] = "ManipulatorTilt"
98  attr_filter_summary[8] = "ManipulatorX"
99  attr_filter_summary[9] = "ManipulatorY"
100  attr_filter_summary[10] = "ManipulatorZ"
101  attr_filter_summary[11] = "PassEnergy"
102  attr_filter_summary[12] = "LensMode"
103  attr_filter_summary[13] = "ScientaDwellTime"
104  attr_filter_summary[14] = "ScientaCenterEnergy"
105  attr_filter_summary[15] = "ScientaChannelBegin"
106  attr_filter_summary[16] = "ScientaChannelEnd"
107  attr_filter_summary[17] = "ScientaSliceBegin"
108  attr_filter_summary[18] = "ScientaSliceEnd"
109  attr_filter_summary[19] = "ScientaNumChannels"
110  attr_filter_summary[20] = "StepSize"
111  attr_filter_summary[21] = "ScientaNumSlices"
112  attr_filter_summary[22] = "ManipulatorTempA"
113  attr_filter_summary[23] = "ManipulatorTempB"
114  attr_filter_summary[24] = "RefCurrent"
115  attr_filter_summary[25] = "SampleCurrent"
116 
117  // non-persistent strings and variables
118  string /g s_short_filepath = "" // abbreviated directory path
119  string /g s_selected_file = ""
120  string /g s_selected_dataset = ""
121  string /g s_preview_file = "" // file or folder name of the current preview
122  string /g s_preview_source = "" // data source, e.g. EPICS channel name, of the current preview
123  string /g s_profiles_graph = "" // window name of the current preview if the data is two-dimensional
124  string /g s_preview_trace_graph = "" // window name of the current preview if the data is one-dimensional
125  string /g s_preview_graph = "" // window name of the most recent preview graph
126  string /g s_file_info = "" // description of selected file
127  string /g s_result = "" // result of last operation
128 
129  variable/g v_InitPanelDone = 1
130 
131  SetDataFolder save_df
132 end
133 
139 static function save_prefs()
140  dfref save_df = GetDataFolderDFR()
141  dfref df = $package_path
142  if (DataFolderRefStatus(df) == 1)
143  string fullPath = SpecialDirPath("Packages", 0, 0, 0)
144  fullPath += package_name
145  NewPath/O/C/Q tempPackagePrefsPath, fullPath
146  fullPath += ":preferences.pxp"
147  SetDataFolder df
148  string objects = "attr_filter;attr_filter_summary;s_filepath;s_hdf_options;s_reduction_params;s_preview_pvs"
149  SaveData /O /Q /J=objects fullPath
150  KillPath/Z tempPackagePrefsPath
151  endif
152  SetDataFolder save_df
153 end
154 
155 static function load_prefs()
156  // loads persistent package data from the preferences file
157  // the preferences file is an Igor packed experiment file in a special preferences folder
158  dfref save_df = GetDataFolderDFR()
159 
160  variable result = -1
161  setdatafolder root:
162  NewDataFolder /O/S packages
163  NewDataFolder /O/S $package_name
164  dfref package_df = GetDataFolderDFR()
165  string fullPath = SpecialDirPath("Packages", 0, 0, 0)
166  fullPath += package_name
167 
168  GetFileFolderInfo /Q /Z fullPath
169  if (V_Flag == 0) // Disk directory exists?
170  fullPath += ":preferences.pxp"
171  GetFileFolderInfo /Q /Z fullPath
172  if (V_Flag == 0) // Preference file exist?
173  LoadData /O /R /Q fullPath
174  result = 0
175  endif
176  endif
177 
178  if (result == 0)
179  svar /sdfr=package_df filepath = s_filepath
180  NewPath /O/Z pearl_explorer_filepath, filepath
183  endif
184 
185  SetDataFolder save_df
186  return result
187 end
188 
199 static function pearl_file_type(filename)
200  string filename
201 
202  if (StringMatch(filename, ks_filematch_pshell))
203  return 1
204  elseif (StringMatch(filename, ks_filematch_adh5))
205  return 2
206  elseif (StringMatch(filename, ks_filematch_itx))
207  return 3
208  else
209  return 0
210  endif
211 end
212 
218 static function update_filepath()
219  PathInfo /S pearl_explorer_filepath
220  svar filepath = $(package_path + "s_filepath")
221  svar shortpath = $(package_path + "s_short_filepath")
222  filepath = s_path
223  shortpath = shorten_filepath(filepath, 40)
224 end
225 
231 static function update_filelist()
232  dfref save_df = GetDataFolderDFR()
233 
234  string all_files
235  wave /t wtFiles = $(package_path + "wtFiles")
236  wave wSelectedFiles = $(package_path + "wSelectedFiles")
237  variable nn
238 
239  PathInfo pearl_explorer_filepath
240  if (v_flag == 1)
241  all_files = IndexedFile(pearl_explorer_filepath, -1, "????")
242  nn = ItemsInList(all_files)
243  else
244  all_files = ""
245  nn = 0
246  endif
247 
248  make /n=(nn) /t /free wtAllFiles
249  wtAllFiles = StringFromList(p, all_files)
250  Extract /o /t wtAllFiles, wtFiles, pearl_file_type(wtAllFiles[p])
251  Sort /A /R wtFiles, wtFiles
252 
253  redimension /n=(numpnts(wtFiles)) wSelectedFiles
254  wSelectedFiles = 0
255 
256  setdatafolder save_df
257 end
258 
259 // ====== metadata ======
260 
273 static function get_file_info(filename)
274  string filename
275 
276  dfref save_df = GetDataFolderDFR()
277  dfref package_df = $package_path
278 
279  variable ft = pearl_file_type(filename)
280  variable result = 0
281 
282  switch(ft)
283  case 1:
284  case 2:
285  dfref file_df = get_pshell_info("pearl_explorer_filepath", filename)
286  result = hl_contents_update(file_df)
287  result = result >= 3 ? 0 : -2
288  break
289  default:
291  dfref file_df = package_df:file_info
292  KillDataFolder /z file_df
293  result = -1
294  endswitch
295 
296  setdatafolder save_df
297  return result
298 end
299 
301 static function attributes_notebook(filename)
302  string filename
303 
304  dfref save_df = GetDataFolderDFR()
305  dfref temp_df = NewFreeDataFolder()
306 
307  load_file(filename, options="mode:load_diags", dest_df=temp_df, quiet=1)
308  svar /sdfr=temp_df /z s_loaded_datasets
309  string scan
310  dfref scan_df
311  if (SVAR_Exists(s_loaded_datasets) && (strlen(s_loaded_datasets) >= 4))
312  scan = StringFromList(0, psh5_extract_scan_paths(s_loaded_datasets), ";")
313  scan_df = psh5_dataset_to_folder(temp_df, scan)
314  else
315  scan_df = temp_df
316  endif
317 
318  dfref attr_df = ps_find_attr_folder(scan_df)
319  if (DataFolderRefStatus(attr_df))
320  extract_attributes(attr_df, dest_df=temp_df)
321  wave /t /sdfr=temp_df /z attr_names
322  wave /t /sdfr=temp_df /z attr_values
323  if (WaveExists(attr_names) && WaveExists(attr_values))
324  create_attributes_notebook(attr_names, attr_values, filename)
325  endif
326  endif
327 
328  setdatafolder save_df
329 end
330 
347 static function extract_attributes(attr_df, [dest_df, attr_filter, include_datawaves, include_infowaves])
348  dfref attr_df
349  dfref dest_df
350  wave /t attr_filter
351  variable include_datawaves
352  variable include_infowaves
353 
354  dfref save_df = GetDataFolderDFR()
355  dfref package_df = $package_path
356 
357  if (ParamIsDefault(dest_df))
358  dest_df = GetDataFolderDFR()
359  endif
360  if (ParamIsDefault(attr_filter) || !WaveExists(attr_filter))
361  wave /t /sdfr=package_df /z attr_filter
362  endif
363  if (ParamIsDefault(include_datawaves))
364  include_datawaves = 1
365  endif
366  if (ParamIsDefault(include_infowaves))
367  include_infowaves = 1
368  endif
369 
370  setdatafolder dest_df
371  wave /t /z attr_names, attr_values
372  if (!WaveExists(attr_names) || !WaveExists(attr_values))
373  make /n=(1) /o /t attr_names, attr_values
374  endif
375  attr_names = ""
376  attr_values = ""
377 
378  setdatafolder attr_df
379  wave /t /z IN
380  wave /t /z ID
381  wave /t /z IV
382  wave /t /z IU
383 
384  // compile list of attributes
385  variable nattr // destination attributes
386  variable iattr
387  variable ninfo // info wave elements
388  variable iinfo
389  variable nw // attribute waves
390  variable iw
391  string sw
392  string ss
393 
394  if (WaveExists(IN) && include_infowaves)
395  ninfo = numpnts(IN)
396  else
397  ninfo = 0
398  endif
399  if (include_datawaves)
400  string waves = WaveList("*", ";", "")
401  string exceptions = "ID;IN;IU;IV"
402  waves = RemoveFromList(exceptions, waves)
403  nw = ItemsInList(waves, ";")
404  else
405  nw = 0
406  endif
407 
408  if (WaveExists(attr_filter) && (numpnts(attr_filter) >= 1))
409  nattr = numpnts(attr_filter)
410  redimension /n=(nattr) attr_names
411  attr_names = attr_filter
412  else
413  if(ninfo > 0)
414  redimension /n=(ninfo) attr_names
415  attr_names = SelectString(strlen(ID[p]) >= 0, IN[p], ID[p]) // use ID unless empty
416  endif
417 
418  nattr = ninfo + nw
419  iattr = ninfo
420  redimension /n=(nattr) attr_names
421  for (iw = 0; iw < nw; iw +=1 )
422  sw = StringFromList(iw, waves, ";")
423  ss = StringByKey("PV", note($sw), "=", "\r")
424  FindValue /text=sw attr_names
425  if ((v_value < 0) && (strlen(ss) >= 0))
426  attr_names[iattr] = sw
427  iattr += 1
428  endif
429  endfor
430  nattr = iattr
431  endif
432  redimension /n=(nattr) attr_names, attr_values
433  sort attr_names, attr_names
434 
435  // look up attribute values
436  for (iattr = 0; iattr < nattr; iattr += 1)
437  sw = attr_names[iattr]
438  // try info waves
439  if (ninfo > 0)
440  FindValue /text=sw ID
441  if (v_value >= 0)
442  attr_values[iattr] = IV[v_value]
443  endif
444  FindValue /text=sw IN
445  if (v_value >= 0)
446  attr_values[iattr] = IV[v_value]
447  endif
448  endif
449 
450  // override from attribute wave if existent
451  if (nw > 0)
452  switch (WaveType($sw, 1))
453  case 1: // numeric
454  wave /z w = $sw
455  if (WaveExists(w) && (numpnts(w) >= 1))
456  sprintf ss, "%g", w[0]
457  attr_values[iattr] = ss
458  endif
459  break
460  case 2: // text
461  wave /t/z wt = $sw
462  if (WaveExists(wt) && (numpnts(wt) >= 1))
463  attr_values[iattr] = wt[0]
464  endif
465  break
466  endswitch
467  endif
468  endfor
469 
470  setdatafolder save_df
471 end
472 
474  dfref df = GetDataFolderDFR()
475  wave /t /sdfr=df attr_names
476  wave /t /sdfr=df attr_values
477  create_attributes_notebook(attr_names, attr_values, GetDataFolder(0))
478 end
479 
480 static function create_attributes_notebook(attr_names, attr_values, title)
481  wave /t attr_names
482  wave /t attr_values
483  string title
484 
485  dfref save_df = GetDataFolderDFR()
486  setdatafolder $package_path
487  wave /t/z attr_filter, attr_filter_summary
488 
489  string name = PearlCleanupName("nb_" + title[0,27])
490  if (WinType(name) == 5)
491  Notebook $name selection={startOfFile, endOfFile}
492  Notebook $name text=""
493  else
494  NewNotebook /F=1 /K=1 /N=$name as title
495  GetWindow $name wsize
496  v_right = v_left + 260
497  v_bottom = v_top + 360
498  MoveWindow /W=$name v_left, v_top, v_right, v_bottom
499  Notebook $name tabs={2*72}
500  endif
501 
502  // summary
503  if (WaveExists(attr_filter_summary) && (numpnts(attr_filter_summary) >= 1))
504  notebook $name fStyle=1, text="Summary\r\r"
505  notebook $name fStyle=0
506  notebook_add_attributes(name, attr_filter_summary, attr_names, attr_values)
507  notebook $name text="\r"
508  endif
509 
510  // all attributes
511  notebook $name fStyle=1, text="All Attributes\r\r"
512  notebook $name fStyle=0
513  notebook_add_attributes(name, $"", attr_names, attr_values)
514  notebook $name selection={startOfFile,startOfFile}, findText={"",1}
515 
516  setdatafolder save_df
517 end
518 
519 static function notebook_add_attributes(notebook_name, attr_filter, attr_names, attr_values)
520  string notebook_name
521  wave /t /z attr_filter
522  wave /t attr_names
523  wave /t attr_values
524 
525  variable nw = numpnts(attr_names)
526  variable iw
527  string sw
528  string ss
529 
530  variable do_filter = WaveExists(attr_filter)
531 
532  for (iw = 0; iw < nw; iw += 1)
533  if (do_filter)
534  sw = attr_names[iw]
535  FindValue /text=sw attr_filter
536  else
537  v_value = 0
538  endif
539  if (v_value >= 0)
540  sprintf ss, "%s\t%s\r", attr_names[iw], attr_values[iw]
541  notebook $notebook_name text=ss
542  endif
543  endfor
544 end
545 
568 static function set_elog_attributes(file_df, [filename, graphname])
569  dfref file_df
570  string filename
571  string graphname
572 
573  if (ParamIsDefault(filename))
574  svar /sdfr=file_df /z loaded_file=s_filepath
575  if (svar_Exists(loaded_file))
576  filename = loaded_file
577  else
578  filename = ""
579  endif
580  endif
581 
582  if (ParamIsDefault(graphname))
583  graphname = ""
584  endif
585 
586  string cmd
587 
588  if (exists("PearlElog#set_panel_attributes") == 6)
589  sprintf cmd, "PearlElog#set_panel_attributes(\"\", \"File=%s\")", ParseFilePath(0, filename, ":", 1, 0)
590  execute /Q/Z cmd
591  if ((strlen(graphname) > 0) && (WinType(graphname) == 1))
592  sprintf cmd, "PearlElog#set_panel_graphs(\"\", \"%s\")", graphname
593  execute /Q/Z cmd
594  endif
595  svar /sdfr=file_df /z authors
596  if (svar_Exists(authors))
597  if (strlen(authors)>=1)
598  sprintf cmd, "PearlElog#set_panel_attributes(\"\", \"author=%s\")", authors
599  execute /Q/Z cmd
600  endif
601  endif
602  svar /sdfr=file_df /z pgroup
603  if (svar_Exists(pgroup))
604  if (strlen(pgroup)>=1)
605  sprintf cmd, "PearlElog#set_panel_attributes(\"\", \"p-group=%s\")", pgroup
606  execute /Q/Z cmd
607  endif
608  endif
609  svar /sdfr=file_df /z proposal
610  if (svar_Exists(proposal))
611  if (strlen(proposal)>=1)
612  sprintf cmd, "PearlElog#set_panel_attributes(\"\", \"project=%s\")", proposal
613  execute /Q/Z cmd
614  endif
615  endif
616  svar /sdfr=file_df /z proposer
617  svar /sdfr=file_df /z sample
618  if (svar_Exists(sample))
619  if (strlen(sample)>=1)
620  sprintf cmd, "PearlElog#set_panel_attributes(\"\", \"sample=%s\")", sample
621  execute /Q/Z cmd
622  endif
623  endif
624  endif
625 end
626 
627 // ====== preview ======
628 
629 static function preview_file(filename)
630  string filename
631 
632  dfref save_df = GetDataFolderDFR()
633  dfref preview_df = $package_path
634 
635  killStrings /z authors, pgroup, proposal, proposer, sample
636 
637  variable ft = pearl_file_type(filename)
638  switch(ft)
639  case 1:
640  wave /z image = preview_pshell_file(filename)
641  break
642  case 2:
643  wave /z image = preview_hdf_file(filename)
644  break
645  case 3:
646  wave /z image = preview_itx_file(filename)
647  break
648  default:
649  wave /z image = $""
650  endswitch
651 
652  if (WaveExists(image))
653  show_preview_graph(image)
654  endif
655 
656  setdatafolder save_df
657  return 0
658 end
659 
671 static function /wave preview_pshell_file(filename)
672  string filename
673 
674  dfref save_df = GetDataFolderDFR()
675 
676  setdatafolder $package_path
677  dfref preview_df = GetDataFolderDFR()
678  svar s_preview_file
679  svar s_preview_source
680  svar /z s_file_info
681  if (! svar_exists(s_file_info))
682  string /g s_file_info
683  endif
684 
685  dfref temp_df = NewFreeDataFolder()
686  dfref file_df = psh5_preview("pearl_explorer_filepath", filename, dest_df=temp_df)
687  svar /z /sdfr=temp_df dataname=s_preview_wave
688 
689  s_preview_file = filename
690  s_preview_source = ""
691 
692  wave /z /sdfr=temp_df data = $dataname
693  if (waveexists(data))
694  duplicate /o data, preview_df:preview_image
695  else
696  print "no data found in file " + filename
697  endif
698 
699  s_file_info = ""
700 
701  setdatafolder save_df
702  wave /z /sdfr=preview_df preview_image
703  return preview_image
704 end
705 
717 static function /wave preview_hdf_file(filename)
718  string filename
719 
720  dfref save_df = GetDataFolderDFR()
721  setdatafolder $package_path
722  svar s_preview_file
723  svar s_preview_source
724  adh5_load_preview("preview_image", "pearl_explorer_filepath", filename)
725  s_preview_file = filename
726  s_preview_source = ""
727  wave /z preview_image
728 
729  svar /z s_file_info
730  if (! svar_exists(s_file_info))
731  string /g s_file_info
732  endif
733  if (strlen(s_preview_file) > 0)
734  s_file_info = adh5_load_info("pearl_explorer_filepath", filename)
735  else
736  s_file_info = ""
737  endif
738 
739  setdatafolder save_df
740  return preview_image
741 end
742 
762 static function /wave preview_itx_file(filename)
763  string filename
764 
765  dfref save_df = GetDataFolderDFR()
766  setdatafolder $package_path
767  svar s_preview_file
768  svar s_preview_source
769  wave preview_image
770 
771  dfref data_df = newfreedatafolder()
772  setdatafolder data_df
773  LoadWave /t/p=pearl_explorer_filepath/q filename
774  s_preview_file = s_filename
775  s_preview_source = ""
776 
778 
779  setdatafolder save_df
780  return preview_image
781 end
782 
784 static function extract_preview_image(data, preview)
785  wave data
786  wave preview
787 
788  variable z1, z2
789 
790  // extract image
791  switch (WaveDims(data))
792  case 1:
793  redimension /n=(numpnts(data)) preview
794  preview = data[p]
795  break
796  case 2:
797  redimension /n=(dimsize(data, 0), dimsize(data, 1)) preview
798  preview = data
799  break
800  case 3:
801  redimension /n=(dimsize(data, 0), dimsize(data, 1)) preview
802  z1 = floor(DimSize(data, 2) / 2)
803  z2 = z1
804  wave slab = ad_extract_slab(data, nan, nan, nan, nan, z1, z2, "", pscale=1)
805  preview = slab
806  break
807  case 4:
808  // not implemented
809  endswitch
810 
811  switch (WaveDims(data))
812  case 4:
813  case 3:
814  case 2:
815  setscale /p y dimoffset(data, 1), dimdelta(data, 1), waveunits(data, 1), preview
816  case 1:
817  setscale /p x dimoffset(data, 0), dimdelta(data, 0), waveunits(data, 0), preview
818  setscale d 0, 0, waveunits(data, -1), preview
819  endswitch
820 end
821 
826 static function preview_datafolder()
827  dfref save_df = GetDataFolderDFR()
828 
829  setdatafolder $package_path
830  svar s_preview_file
831  svar s_preview_source
832  svar s_preview_pvs
833  wave preview_image
834 
835  setdatafolder save_df
836 
837  // select a wave to display
838  // consider only double-precision waves, i.e. ignore text and other special waves
839  // filter by matching PV name to s_preview_pvs
840  string d_names = WaveList("*", ";", "DP:1")
841  variable nw = ItemsInList(d_names, ";")
842  variable npv = ItemsInList(s_preview_pvs, ";")
843  variable iw, ipv
844  string wname, wnote, pv_name, pv_match
845  for (iw = 0; iw < nw; iw += 1)
846  wname = StringFromList(iw, d_names, ";")
847  wnote = note($wname)
848  pv_name = StringByKey("PV", wnote, "=", "\r")
849  // find matching data wave by PV name
850  for (ipv = 0; ipv < npv; ipv += 1)
851  pv_match = StringFromList(ipv, s_preview_pvs)
852  if (StringMatch(pv_name, pv_match))
853  wave data = $wname
854  s_preview_source = pv_name
855  extract_preview_image(data, preview_image)
856  preview_setscale_x(data, preview_image)
857  npv = 0
858  nw = 0
859  endif
860  endfor
861  endfor
862 
863  setdatafolder save_df
864 end
865 
866 static function preview_setscale_x(data, preview)
867  // sets the approximate x scale of OTF data.
868  // requires an Axis1 tag with name of x wave in the wave note.
869  // if any of these conditions is true, the function does not change the scaling:
870  // 1) Axis1 tag or referenced wave is missing.
871  // 2) preview wave is not set to point scaling.
872  // 3) x wave is not monotonic (90% of the steps in the same direction).
873  wave data
874  wave preview
875 
876  if ((DimOffset(preview, 0) == 0) && (DimDelta(preview, 0) == 1))
877  string xname = StringByKey("Axis1", note(data), "=", "\r")
878  wave /z xwave = $xname
879  if (WaveExists(xwave))
880  // check for monotonicity
881  variable monotonic = 0
882  duplicate /free xwave, xdiff
883  differentiate /p xwave /D=xdiff
884  duplicate /free xdiff, xflag
885  xflag = xdiff > 0
886  monotonic = sum(xflag) > numpnts(xwave) * 0.9
887  xflag = xdiff < 0
888  monotonic = monotonic || (sum(xflag) > numpnts(xwave) * 0.9)
889  if (monotonic)
890  setscale /i x xwave[0], xwave[numpnts(xwave)-1], waveunits(xwave, -1), preview
891  endif
892  endif
893  endif
894 end
895 
897 static function display_dataset(file_df, dataset)
898  dfref file_df // top data folder of file
899  string dataset // dataset path inside data folder
900 
901  dfref save_df = GetDataFolderDFR()
902 
903  dfref data_df = psh5_dataset_to_folder(file_df, dataset)
904  SetDataFolder data_df
905  string data_name = StringFromList(ItemsInList(dataset, "/") - 1, dataset, "/")
906  wave /z data=$data_name
907 
908  if (WaveExists(data))
909  switch(WaveDims(data))
910  case 1:
911  case 2:
912  show_preview_graph(data)
913  break
914  case 3:
915  ad_display_slice(data)
916  ad_brick_slicer(data)
917  break
918  endswitch
919  endif
920 
921  setdatafolder save_df
922  return 0
923 end
924 
925 static function /s show_preview_graph(data, [xdata])
926  // displays a preview of one- or two-dimensional data
927  wave data // data to be displayed. must either one-dimensional or two-dimensional
928  wave xdata // positions on x axis
929 
930  dfref save_df = GetDataFolderDFR()
931  setdatafolder $package_path
932 
933  svar s_profiles_graph
934  svar s_preview_file
935  svar s_preview_source
936  svar s_preview_trace_graph
937  svar s_preview_graph
938 
939  if ((strlen(s_profiles_graph) > 0) && (WinType(s_profiles_graph) == 1))
940  KillWindow $s_profiles_graph
941  endif
942  if ((strlen(s_preview_trace_graph) > 0) && (WinType(s_preview_trace_graph) == 1))
943  KillWindow $s_preview_trace_graph
944  endif
945 
946  string graphname
947  if (wavedims(data) == 2)
948  s_profiles_graph = ad_display_profiles(data)
949  ModifyGraph /w=$s_profiles_graph /z wbRGB=(48640,56832,60160)
950  graphname = s_profiles_graph
951  elseif (wavedims(data) == 1)
952  duplicate /o data, preview_trace
953  if (!ParamIsDefault(xdata))
954  duplicate /o xdata, preview_trace_x
955  else
956  duplicate /o data, preview_trace_x
957  preview_trace_x = x
958  setscale d 0, 0, WaveUnits(data, 0), preview_trace_x
959  endif
960  s_preview_trace_graph = display_preview_trace(preview_trace_x, preview_trace)
961  ModifyGraph /w=$s_preview_trace_graph wbRGB=(48640,56832,60160)
962  graphname = s_preview_trace_graph
963  else
964  return ""
965  endif
966 
967  string title = "Preview " + s_preview_file
968  if (strlen(s_preview_source) > 0)
969  title = title + " (" + s_preview_source[0,31] + ")"
970  endif
971  dowindow /f/t $graphname, title
972  s_preview_graph = graphname
973 
974  setdatafolder save_df
975  return graphname
976 end
977 
978 static function /s display_preview_trace(xtrace, ytrace)
979  wave /z xtrace
980  wave ytrace
981 
982  if (WaveExists(xtrace))
983  display /n=pearl_explorer_1d /k=1 ytrace vs xtrace as "Preview"
984  else
985  display /n=pearl_explorer_1d /k=1 ytrace as "Preview"
986  endif
987 
988  string graphname = s_name
989  ModifyGraph /w=$graphname rgb[0]=(0,0,0)
990  ModifyGraph /w=$graphname grid=2
991  ModifyGraph /w=$graphname mirror=1
992  ModifyGraph /w=$graphname minor=1
993  ModifyGraph /w=$graphname axThick=0.5
994  ModifyGraph /w=$graphname gridRGB=(52224,52224,52224)
995  ModifyGraph /w=$graphname gridHair=0
996  ModifyGraph /w=$graphname tick=0
997  ModifyGraph /w=$graphname btLen=4
998 
999  // axis labels
1000  string labels = note(ytrace)
1001  string lab
1002  lab = StringByKey("AxisLabelX", labels, "=", "\r")
1003  if (!strlen(lab))
1004  lab = "X"
1005  endif
1006  Label /w=$graphname bottom lab + " (\\U)"
1007  lab = StringByKey("Dataset", labels, "=", "\r")
1008  if (!strlen(lab))
1009  lab = "value"
1010  endif
1011  Label /w=$graphname left lab + " (\\U)"
1012 
1013  return s_name
1014 end
1015 
1016 // ====== file loading ======
1017 
1025 static function load_selected_files([options])
1026  string options
1027 
1028  dfref save_df = GetDataFolderDFR()
1029  setdatafolder $package_path
1030 
1031  wave wSelectedFiles
1032  wave/t wtFiles
1033  variable nn = numpnts(wSelectedFiles)
1034  variable ii
1035  for (ii = 0; ii < nn; ii += 1)
1036  if (wSelectedFiles[ii])
1037  setdatafolder save_df
1038  if (ParamIsDefault(options))
1039  load_file(wtFiles[ii])
1040  else
1041  load_file(wtFiles[ii], options=options)
1042  endif
1043  endif
1044  endfor
1045 end
1046 
1064 static function load_file(filename, [options, dest_df, quiet])
1065  string filename
1066  string options
1067  dfref dest_df
1068  variable quiet
1069 
1070  if (ParamIsDefault(options))
1071  options = ""
1072  endif
1073 
1074  variable ft = pearl_file_type(filename)
1075  switch(ft)
1076  case 1:
1077  load_pshell_file(filename, options=options, dest_df=dest_df, quiet=quiet)
1078  break
1079  case 2:
1080  load_hdf_file(filename, options=options, dest_df=dest_df, quiet=quiet)
1081  break
1082  case 3:
1083  load_itx_file(filename, dest_df=dest_df, quiet=quiet)
1084  break
1085  default:
1086  break
1087  endswitch
1088 end
1089 
1090 static function prompt_hdf_options(options)
1091  string &options
1092 
1093  string mode = StringByKey("mode", options, ":", ";")
1094  string reduction_func = StringByKey("reduction_func", options, ":", ";")
1095 
1096  string modes = "load_scan;load_region;load_dataset;load_diags;load_complete;"
1097  string reduction_funcs = adh5_list_reduction_funcs()
1098  reduction_funcs = RemoveFromList("adh5_default_reduction", reduction_funcs, ";")
1099 
1100  if (strlen(mode) == 0)
1101  mode = StringFromList(0, modes, ";")
1102  endif
1103  if (strlen(reduction_func) == 0)
1104  reduction_func = StringFromList(0, reduction_funcs, ";")
1105  endif
1106 
1107  prompt mode, "Mode", popup, modes
1108  prompt reduction_func, "Reduction Function", popup, reduction_funcs
1109  doprompt "HDF5 Loading Options", mode, reduction_func
1110 
1111  if (v_flag == 0)
1112  options = ReplaceStringByKey("mode", options, mode, ":", ";")
1113  options = ReplaceStringByKey("reduction_func", options, reduction_func, ":", ";")
1114  endif
1115  return v_flag // 0 = OK, 1 = cancel
1116 end
1117 
1130 function prompt_default_process(param)
1131  string &param
1132 
1133  return 0
1134 end
1135 
1136 function prompt_func_params(func_name, func_param)
1137  string func_name
1138  string &func_param
1139 
1140  string prompt_name = "prompt_" + func_name
1141  if (exists(prompt_name) == 6)
1142  funcref prompt_default_process prompt_func = $prompt_name
1143  return prompt_func(func_param)
1144  else
1145  // ignore missing prompt function
1146  return 0
1147  endif
1148 end
1149 
1188 static function /df load_pshell_file(filename, [options, dest_df, quiet])
1189  string filename
1190  string options
1191  dfref dest_df
1192  variable quiet
1193 
1194  dfref save_df = GetDataFolderDFR()
1195 
1196  svar pref_options = $(package_path + "s_hdf_options")
1197  svar pref_params = $(package_path + "s_reduction_params")
1198  string path = "pearl_explorer_filepath"
1199 
1200  if (ParamIsDefault(options))
1201  options = pref_options
1202  endif
1203 
1204  if (strlen(options) == 0)
1205  if (prompt_hdf_options(options) == 0)
1206  pref_options = options
1207  else
1208  return $""
1209  endif
1210  endif
1211 
1212  string reduction_func = StringByKey("reduction_func", options, ":", ";")
1213  string reduction_params = pref_params
1214  variable max_rank = 2
1215 
1216  if (exists(reduction_func) == 6)
1217  max_rank = 3
1218  if (prompt_func_params(reduction_func, reduction_params) == 0)
1219  pref_params = reduction_params
1220  else
1221  return $""
1222  endif
1223  endif
1224 
1225  string mode = StringByKey("mode", options, ":", ";")
1226  string selected_datasets = WMHL_SelectedObjectsList("PearlDataExplorer", "lb_contents")
1227  string selected_scans = psh5_extract_scan_paths(selected_datasets)
1228  string selected_regions = psh5_extract_region_paths(selected_datasets)
1229  variable dsc
1230 
1231  if (!quiet)
1232  print mode, filename
1233  if (strlen(reduction_func))
1234  print reduction_func, reduction_params
1235  endif
1236  endif
1237 
1238  strswitch(mode)
1239  case "load_complete":
1240  dsc = kDSCAll
1241  dfref file_df = psh5_load(path, filename, "", "", "*", classes=dsc, reduction_func=reduction_func, reduction_params=reduction_params, dest_df=dest_df)
1242  break
1243  case "load_diags":
1244  if (ItemsInList(selected_scans, ";") == 0)
1245  if (!quiet)
1246  print "no scan selected - defaulting to scan 1."
1247  endif
1248  selected_scans = "/scan1;"
1249  endif
1251  dfref file_df = psh5_load(path, filename, selected_scans, "", "", classes=dsc, dest_df=dest_df)
1252  break
1253  case "load_scan":
1254  if (ItemsInList(selected_scans, ";") == 0)
1255  if (!quiet)
1256  print "no scan selected - defaulting to scan 1."
1257  endif
1258  selected_scans = "/scan1;"
1259  endif
1261  dfref file_df = psh5_load(path, filename, selected_scans, "", "", classes=dsc, max_rank=max_rank, reduction_func=reduction_func, reduction_params=reduction_params, dest_df=dest_df)
1262  break
1263  case "load_region":
1264  if (ItemsInList(selected_regions, ";") == 0)
1265  if (!quiet)
1266  print "no region selected - defaulting to scan 1/region 1."
1267  endif
1268  selected_regions = "/scan1/region1;"
1269  endif
1271  dfref file_df = psh5_load(path, filename, "", selected_regions, "", classes=dsc, max_rank=max_rank, reduction_func=reduction_func, reduction_params=reduction_params, dest_df=dest_df)
1272  break
1273  case "load_dataset":
1274  if (ItemsInList(selected_datasets, ";") > 0)
1275  dsc = kDSCAll
1276  dfref file_df = psh5_load(path, filename, "", "", selected_datasets, classes=dsc, reduction_func=reduction_func, reduction_params=reduction_params, dest_df=dest_df)
1277  else
1278  if (!quiet)
1279  DoAlert /T="PShell Import" 0, "Please select the datasets to load."
1280  endif
1281  endif
1282  break
1283  endswitch
1284 
1285  if (DataFolderRefStatus(file_df))
1286  setdatafolder file_df
1287  string /g pearl_explorer_import = "load_pshell_file"
1288  if (!quiet)
1289  print "data loaded to", GetDataFolder(1)
1290  endif
1291  else
1292  setdatafolder save_df
1293  endif
1294 
1295  return file_df
1296 end
1297 
1298 static function /df load_hdf_file(filename, [options, dest_df, quiet])
1299  string filename
1300  string options
1301  dfref dest_df
1302  variable quiet
1303 
1304  dfref save_df = GetDataFolderDFR()
1305  string nickname = ad_suggest_foldername(filename)
1306  string loaded_filename = ""
1307 
1308  if (ParamIsDefault(dest_df) || !DataFolderRefStatus(dest_df))
1309  //
1310  else
1311  DoAlert /T="load_hdf_file" 0, "optional argument dest_df not supported."
1312  return $""
1313  endif
1314 
1315  if (ParamIsDefault(options))
1316  loaded_filename = adh5_load_complete(nickname, "pearl_explorer_filepath", filename)
1317  else
1318  if (strlen(options) == 0)
1319  svar pref_options = $(package_path + "s_hdf_options")
1320  options = pref_options
1321  if (prompt_hdf_options(options) == 0)
1322  // OK
1323  pref_options = options
1324  else
1325  // cancel
1326  options = ""
1327  endif
1328  endif
1329 
1330  string mode = StringByKey("mode", options, ":", ";")
1331 
1332  strswitch(mode)
1333  case "load_reduced":
1334  string reduction_func = StringByKey("reduction_func", options, ":", ";")
1335  svar pref_params = $(package_path + "s_reduction_params")
1336  string reduction_params = pref_params
1337  if (prompt_func_params(reduction_func, reduction_params) == 0)
1338  pref_params = reduction_params
1339  print reduction_func, reduction_params
1340  loaded_filename = adh5_load_reduced(nickname, "pearl_explorer_filepath", filename, $reduction_func, reduction_params)
1341  endif
1342  break
1343  endswitch
1344  endif
1345 
1346  dfref data_df
1347  if (strlen(loaded_filename) > 0)
1348  setdatafolder $("root:" + nickname)
1349  data_df = GetDataFolderDFR()
1350  string /g pearl_explorer_import = "load_hdf_file"
1351  else
1352  setdatafolder save_df
1353  endif
1354 
1355  return data_df
1356 end
1357 
1358 static function /df load_itx_file(filename, [options, dest_df, quiet])
1359  string filename
1360  string options
1361  dfref dest_df
1362  variable quiet
1363 
1364  dfref save_df = GetDataFolderDFR()
1365  string nickname = itx_suggest_foldername(filename)
1366 
1367  if (ParamIsDefault(options))
1368  options = ""
1369  endif
1370 
1371  variable own_data_df = 0
1372  if (ParamIsDefault(dest_df) || !DataFolderRefStatus(dest_df))
1373  setdatafolder root:
1374  newdatafolder /s/o $("root:" + nickname)
1375  own_data_df = 1
1376  else
1377  setdatafolder dest_df
1378  endif
1379  dfref data_df = GetDataFolderDFR()
1380 
1381  // note: some versions of PEARL data files save data to a new data folder,
1382  // and leave the newly created folder as the current folder.
1383  // the free data folder is used by those files which don't create their own data folder.
1384  // this is the new recommended behaviour
1385 
1386  LoadWave /t/p=pearl_explorer_filepath/q filename
1387  svar waves = s_wavenames
1388  dfref act_df = GetDataFolderDFR()
1389  if (v_flag > 0)
1390  string /g pearl_explorer_import = "load_itx_file"
1391  endif
1392 
1393  if (!DataFolderRefsEqual(act_df, data_df) && own_data_df)
1394  // the file created its own data folder.
1395  // let's kill the pre-allocated folder
1396  setdatafolder data_df
1397  if (ItemsInList(WaveList("*", ";", ""), ";") == 0)
1398  killdatafolder /z data_df
1399  endif
1400  endif
1401 
1402  setdatafolder save_df
1403  return act_df
1404 end
1405 
1427 function /s itx_suggest_foldername(filename, [ignoredate,sourcename,unique])
1428  string filename
1429  variable ignoredate
1430  string sourcename
1431  variable unique
1432 
1433  if (ParamIsDefault(ignoredate))
1434  ignoredate = 0
1435  endif
1436  if (ParamIsDefault(unique))
1437  unique = 0
1438  endif
1439 
1440  string basename = ParseFilePath(3, filename, ":", 0, 0)
1441  string extension = ParseFilePath(4, filename, ":", 0, 0)
1442  string nickname
1443 
1444  string autosource
1445  if (strsearch(basename, "X03DA_PC", 0, 2) >= 0)
1446  autosource = "sscan"
1447  basename = ReplaceString("_", basename, "-")
1448  ignoredate = 1
1449  elseif (strsearch(basename, "otf", 0, 2) >= 0)
1450  autosource = "otf"
1451  endif
1452  if (ParamIsDefault(sourcename))
1453  sourcename = autosource
1454  endif
1455 
1456  variable nparts = ItemsInList(basename, "-")
1457  if (nparts >= 3)
1458  string datepart = StringFromList(nparts - 2, basename, "-")
1459  string indexpart = StringFromList(nparts - 1, basename, "-")
1460  if (ignoredate)
1461  sprintf nickname, "%s_%s", sourcename, indexpart
1462  else
1463  sprintf nickname, "%s_%s_%s", sourcename, datepart, indexpart
1464  endif
1465  else
1466  nickname = PearlCleanupName(basename)
1467  endif
1468 
1469  if (unique && CheckName(nickname, 11))
1470  nickname = UniqueName(nickname + "_", 11, 0)
1471  endif
1472 
1473  return nickname
1474 end
1475 
1476 // ====== panel ======
1477 
1478 Window PearlDataExplorer() : Panel
1479  PauseUpdate; Silent 1 // building window...
1480  NewPanel /K=1 /W=(510,45,1190,539) as "PEARL Data Explorer"
1481  ModifyPanel cbRGB=(48640,56832,60160)
1482  GroupBox g_data_reduction,pos={355.00,370.00},size={306.00,49.00},title="data reduction"
1483  GroupBox g_data_reduction,help={"data reduction of 3D ScientaImage"}
1484  GroupBox gb_filepath,pos={8.00,4.00},size={328.00,48.00},title="file system folder"
1485  TitleBox tb_filepath,pos={20.00,28.00},size={279.00,21.00},frame=0
1486  TitleBox tb_filepath,variable= root:packages:pearl_explorer:s_short_filepath,fixedSize=1
1487  Button b_browse_filepath,pos={303.00,24.00},size={20.00,20.00},proc=PearlDataExplorer#bp_browse_filepath,title="..."
1488  Button b_browse_filepath,fColor=(65280,48896,32768)
1489  GroupBox gb_prefs,pos={8.00,351.00},size={65.00,131.00},title="prefs"
1490  GroupBox gb_prefs,help={"explorer package preferences"}
1491  Button b_save_prefs,pos={21.00,394.00},size={38.00,17.00},proc=PearlDataExplorer#bp_save_prefs,title="save"
1492  Button b_save_prefs,help={"save preferences of the data explorer package (data file path, attributes filter)"}
1493  Button b_save_prefs,fColor=(65280,48896,32768)
1494  Button b_load_prefs,pos={21.00,374.00},size={38.00,17.00},proc=PearlDataExplorer#bp_load_prefs,title="load"
1495  Button b_load_prefs,help={"load preferences of the data explorer package"}
1496  Button b_load_prefs,fColor=(65280,48896,32768)
1497  GroupBox gb_filelist,pos={8.00,55.00},size={328.00,293.00},title="data files"
1498  ListBox lb_files,pos={20.00,83.00},size={303.00,222.00},proc=PearlDataExplorer#lbp_filelist
1499  ListBox lb_files,listWave=root:packages:pearl_explorer:wtFiles
1500  ListBox lb_files,selWave=root:packages:pearl_explorer:wSelectedFiles,mode= 4
1501  Button b_update_filelist,pos={246.00,315.00},size={76.00,22.00},proc=PearlDataExplorer#bp_update_filelist,title="update list"
1502  Button b_update_filelist,fColor=(65280,48896,32768)
1503  CheckBox cb_file_preview,pos={78.00,318.00},size={59.00,14.00},title="preview"
1504  CheckBox cb_file_preview,help={"enable/disable automatic preview window when selecting a data file"}
1505  CheckBox cb_file_preview,value= 0
1506  Button b_file_prev,pos={20.00,314.00},size={22.00,22.00},proc=PearlDataExplorer#bp_file_prev,title="\\W646"
1507  Button b_file_prev,help={"previous file"},fColor=(65280,48896,32768)
1508  Button b_file_next,pos={44.00,314.00},size={22.00,22.00},proc=PearlDataExplorer#bp_file_next,title="\\W649"
1509  Button b_file_next,help={"next file"},fColor=(65280,48896,32768)
1510  Button b_goto_dataset,pos={355.00,315.00},size={64.00,22.00},disable=2,proc=PearlDataExplorer#bp_goto_dataset,title="goto DF"
1511  Button b_goto_dataset,help={"change the current data folder ot where the selected dataset could be located"}
1512  Button b_goto_dataset,fColor=(65280,48896,32768)
1513  Button b_display_dataset,pos={423.00,315.00},size={64.00,22.00},disable=2,proc=PearlDataExplorer#bp_display_dataset,title="display"
1514  Button b_display_dataset,help={"display the selected dataset in its own window"}
1515  Button b_display_dataset,fColor=(65280,48896,32768)
1516  Button b_load_complete,pos={355.00,451.00},size={92.00,22.00},disable=2,proc=PearlDataExplorer#bp_load_options,title="all data"
1517  Button b_load_complete,help={"load all datasets of the selected file."}
1518  Button b_load_complete,userdata= "mode:load_complete;"
1519  Button b_load_complete,fColor=(65280,48896,32768)
1520  TitleBox tb_selected_file,pos={360.00,28.00},size={309.00,22.00},frame=0
1521  TitleBox tb_selected_file,variable= root:packages:pearl_explorer:s_selected_file,fixedSize=1
1522  GroupBox gb_contents,pos={346.00,55.00},size={327.00,294.00},title="datasets"
1523  Button b_attr_notebook,pos={97.00,375.00},size={64.00,22.00},disable=2,proc=PearlDataExplorer#bp_attr_notebook,title="notebook"
1524  Button b_attr_notebook,help={"show a summary of attributes in a notebook window"}
1525  Button b_attr_notebook,fColor=(65280,48896,32768)
1526  ListBox lb_contents,pos={355.00,84.00},size={305.00,222.00}
1527  ListBox lb_contents,keySelectCol= 1
1528  GroupBox gb_selected_file,pos={346.00,4.00},size={328.00,48.00},title="selected file"
1529  Button b_load_region,pos={355.00,426.00},size={92.00,22.00},disable=2,proc=PearlDataExplorer#bp_load_options,title="region"
1530  Button b_load_region,help={"load the selected region"}
1531  Button b_load_region,userdata= "mode:load_region;",fColor=(65280,48896,32768)
1532  PopupMenu popup_reduction,pos={366.00,391.00},size={200.00,17.00},bodyWidth=200,proc=PearlDataExplorer#pmp_reduction_func
1533  PopupMenu popup_reduction,help={"data reduction of 3d ScientaImage. note: the list may contain unsuitable functions. check the code or documentation!"}
1534  PopupMenu popup_reduction,mode=1,popvalue="None",value= #"PearlDataExplorer#pm_reduction_values()"
1535  GroupBox group_import,pos={346.00,351.00},size={326.00,131.00},title="import"
1536  Button b_load_scan,pos={450.00,426.00},size={94.00,22.00},disable=2,proc=PearlDataExplorer#bp_load_options,title="scan"
1537  Button b_load_scan,help={"load the selected scan"},userdata= "mode:load_scan;"
1538  Button b_load_scan,fColor=(65280,48896,32768)
1539  Button b_load_diags,pos={450.00,451.00},size={94.00,22.00},disable=2,proc=PearlDataExplorer#bp_load_options,title="diagnostics"
1540  Button b_load_diags,help={"load diagnostics of selected scans"},userdata= "mode:load_diags;"
1541  Button b_load_diags,fColor=(65280,48896,32768)
1542  Button b_load_dataset,pos={547.00,426.00},size={101.00,22.00},disable=2,proc=PearlDataExplorer#bp_load_options,title="dataset"
1543  Button b_load_dataset,help={"load the selected datasets"}
1544  Button b_load_dataset,userdata= "mode:load_dataset;",fColor=(65280,48896,32768)
1545  Button b_reduction_params,pos={571.00,390.00},size={71.00,19.00},disable=2,proc=PearlDataExplorer#bp_reduction_params,title="set params"
1546  Button b_reduction_params,help={"set data reduction parameters"}
1547  Button b_reduction_params,fColor=(65280,48896,32768)
1548  GroupBox g_fileinfo,pos={85.00,351.00},size={251.00,131.00},title="file info"
1549  Button b_elog,pos={97.00,401.00},size={64.00,22.00},disable=2,proc=PearlDataExplorer#bp_elog,title="ELOG"
1550  Button b_elog,help={"send file metadata to ELOG panel (does not submit to ELOG)"}
1551  Button b_elog,fColor=(65280,48896,32768)
1552  ToolsGrid grid=(0,28.35,5)
1553 EndMacro
1554 
1557 static function update_controls()
1558  dfref package_df = $package_path
1559  svar /z /sdfr=package_df hl_contents_datasets
1560  wave /z /sdfr=package_df wSelectedFiles
1561 
1562  variable file_selected = 0
1563  if (WaveExists(wSelectedFiles))
1564  file_selected = sum(wSelectedFiles)
1565  endif
1566 
1567  string selected_datasets = WMHL_SelectedObjectsList("PearlDataExplorer", "lb_contents")
1568  variable scan_selected = strsearch(selected_datasets, "scan", 0, 2) == 0
1569  variable region_selected = strsearch(selected_datasets, "region", 0, 2) >= 0
1570 
1571  variable dataset_selected = 0
1572  variable nds = ItemsInList(selected_datasets, ";")
1573  variable ids
1574  string ds
1575  if (svar_exists(hl_contents_datasets))
1576  for (ids = 0; ids < nds; ids += 1)
1577  ds = "/" + StringFromList(ids, selected_datasets, ";")
1578  if (NumType(NumberByKey(ds, hl_contents_datasets, ":", ";")) == 0)
1579  dataset_selected = 1
1580  break
1581  endif
1582  endfor
1583  else
1584  nds = 0
1585  endif
1586 
1587  variable dis
1588  dis = file_selected ? 0 : 2
1589  Button b_load_complete win=PearlDataExplorer,disable=dis
1590  Button b_load_diags win=PearlDataExplorer,disable=dis
1591  dis = file_selected && scan_selected ? 0 : 2
1592  Button b_attr_notebook win=PearlDataExplorer,disable=dis
1593 
1594  dis = file_selected && (strlen(WinList("*ElogPanel*", ";", "WIN:64")) > 1) ? 0 : 2
1595  Button b_elog win=PearlDataExplorer,disable=dis
1596  dis = scan_selected ? 0 : 2
1597  Button b_load_scan win=PearlDataExplorer,disable=dis
1598  dis = region_selected ? 0 : 2
1599  Button b_load_region win=PearlDataExplorer,disable=dis
1600  dis = dataset_selected ? 0 : 2
1601  Button b_load_dataset win=PearlDataExplorer,disable=dis
1602  Button b_display_dataset win=PearlDataExplorer,disable=dis
1603  dis = file_selected && (nds > 0) ? 0 : 2
1604  Button b_goto_dataset win=PearlDataExplorer,disable=dis
1605 
1606  ControlInfo /W=PearlDataExplorer popup_reduction
1607  if ((cmpstr(S_Value, "None") != 0) && (exists(S_Value) == 6))
1608  GroupBox g_data_reduction win=PearlDataExplorer,labelBack=(65535,49151,49151)
1609  Button b_reduction_params win=PearlDataExplorer,disable=0
1610  else
1611  GroupBox g_data_reduction win=PearlDataExplorer,labelBack=0
1612  Button b_reduction_params win=PearlDataExplorer,disable=2
1613  endif
1614 
1615  return 0
1616 end
1617 
1618 static function bp_load_prefs(ba) : ButtonControl
1619  STRUCT WMButtonAction &ba
1620 
1621  switch( ba.eventCode )
1622  case 2: // mouse up
1623  load_prefs()
1624  update_controls()
1625  break
1626  case -1: // control being killed
1627  break
1628  endswitch
1629 
1630  return 0
1631 End
1632 
1633 static function bp_save_prefs(ba) : ButtonControl
1634  STRUCT WMButtonAction &ba
1635 
1636  switch( ba.eventCode )
1637  case 2: // mouse up
1638  save_prefs()
1639  break
1640  case -1: // control being killed
1641  break
1642  endswitch
1643 
1644  return 0
1645 End
1646 
1651 static function /s shorten_filepath(long_path, max_len)
1652  string long_path
1653  variable max_len
1654 
1655  string path = long_path
1656  variable ellipsis = 0
1657  do
1658  if (strlen(path) > max_len)
1659  path = RemoveListItem(1, path, ":")
1660  ellipsis += 1
1661  else
1662  break
1663  endif
1664  while (1)
1665 
1666  if (ellipsis >= 1)
1667  path = AddListItem("
", path, ":", 1)
1668  endif
1669 
1670  return path
1671 end
1672 
1673 static function bp_browse_filepath(ba) : ButtonControl
1674  STRUCT WMButtonAction &ba
1675 
1676  dfref save_df = GetDataFolderDFR()
1677 
1678  switch( ba.eventCode )
1679  case 2: // mouse up
1680  PathInfo /S pearl_explorer_filepath
1681  NewPath /M="select data file folder" /O/Z pearl_explorer_filepath
1682  if (v_flag == 0)
1683  update_filepath()
1684  update_filelist()
1685  update_controls()
1686  endif
1687  break
1688  case -1: // control being killed
1689  break
1690  endswitch
1691 
1692  setdatafolder save_df
1693  return 0
1694 End
1695 
1696 static function bp_update_filelist(ba) : ButtonControl
1697  STRUCT WMButtonAction &ba
1698 
1699  switch( ba.eventCode )
1700  case 2: // mouse up
1701  update_filelist()
1702  update_controls()
1703  break
1704  case -1: // control being killed
1705  break
1706  endswitch
1707 
1708  return 0
1709 End
1710 
1712 static function /s pm_reduction_values()
1713  string reduction_funcs = adh5_list_reduction_funcs()
1714  reduction_funcs = RemoveFromList("adh5_default_reduction", reduction_funcs, ";")
1715  reduction_funcs = AddListItem("None", reduction_funcs, ";", 0)
1716  return reduction_funcs
1717 end
1718 
1719 static function pmp_reduction_func(pa) : PopupMenuControl
1720  STRUCT WMPopupAction &pa
1721 
1722  switch( pa.eventCode )
1723  case 2: // mouse up
1724  Variable popNum = pa.popNum
1725  String popStr = pa.popStr
1726  update_controls()
1727  break
1728  case -1: // control being killed
1729  break
1730  endswitch
1731 
1732  return 0
1733 End
1734 
1735 static function bp_reduction_params(ba) : ButtonControl
1736  STRUCT WMButtonAction &ba
1737 
1738  switch( ba.eventCode )
1739  case 2: // mouse up
1740  ControlInfo /W=PearlDataExplorer popup_reduction
1741  if ((cmpstr(S_Value, "None") != 0) && (exists(S_Value) == 6))
1742  svar pref_params = $(package_path + "s_reduction_params")
1743  string reduction_func = S_Value
1744  string reduction_params = pref_params
1745  if (prompt_func_params(reduction_func, reduction_params) == 0)
1746  pref_params = reduction_params
1747  endif
1748  endif
1749  break
1750  case -1: // control being killed
1751  break
1752  endswitch
1753 
1754  return 0
1755 End
1756 
1757 static function bp_load_options(ba) : ButtonControl
1758  STRUCT WMButtonAction &ba
1759 
1760  switch( ba.eventCode )
1761  case 2: // mouse up
1762  // options must be in the button's unnamed user data in the form: "mode:load_complete".
1763  // see load_pshell_file for recognized values.
1764  string options=ba.userData
1765 
1766  // data reduction popup
1767  ControlInfo /W=PearlDataExplorer popup_reduction
1768  if ((cmpstr(S_Value, "None") != 0) && (exists(S_Value) == 6))
1769  options = ReplaceStringByKey("reduction_func", options, S_Value, ":", ";")
1770  endif
1771 
1772  load_selected_files(options=options)
1773  break
1774  case -1: // control being killed
1775  break
1776  endswitch
1777 
1778  return 0
1779 End
1780 
1791 static function selected_file(file, do_preview)
1792  string file
1793  variable do_preview
1794 
1795  dfref save_df = GetDataFolderDFR()
1796  setdatafolder $package_path
1797  svar s_selected_file
1798  s_selected_file = file
1799  get_file_info(file)
1800  if (do_preview)
1801  preview_file(file)
1802  endif
1803  update_controls()
1804 
1805  setdatafolder save_df
1806  return 0
1807 end
1808 
1809 static function bp_file_next(ba) : ButtonControl
1810  STRUCT WMButtonAction &ba
1811 
1812  dfref save_df = GetDataFolderDFR()
1813 
1814  switch( ba.eventCode )
1815  case 2: // mouse up
1816  setdatafolder $package_path
1817  wave /t wtFiles
1818  wave wSelectedFiles
1819  FindValue /i=1 wSelectedFiles
1820  v_value += 1
1821  if (v_value >= numpnts(wtFiles))
1822  v_value = min(numpnts(wtFiles) - 1, 0)
1823  endif
1824  wSelectedFiles = p == v_value
1825  if (v_value >= 0)
1826  variable ifile = v_value
1827  ControlInfo /W=PearlDataExplorer cb_file_preview
1828  selected_file(wtFiles[ifile], v_value)
1829  endif
1830  update_controls()
1831  break
1832  case -1: // control being killed
1833  break
1834  endswitch
1835 
1836  setdatafolder save_df
1837  return 0
1838 End
1839 
1840 static function bp_file_prev(ba) : ButtonControl
1841  STRUCT WMButtonAction &ba
1842 
1843  dfref save_df = GetDataFolderDFR()
1844 
1845  switch( ba.eventCode )
1846  case 2: // mouse up
1847  setdatafolder $package_path
1848  wave /t wtFiles
1849  wave wSelectedFiles
1850  FindValue /i=1 wSelectedFiles
1851  v_value -= 1
1852  if (v_value < 0)
1853  v_value = numpnts(wtFiles) - 1
1854  endif
1855  wSelectedFiles = p == v_value
1856  if (v_value >= 0)
1857  variable ifile = v_value
1858  ControlInfo /W=PearlDataExplorer cb_file_preview
1859  selected_file(wtFiles[ifile], v_value)
1860  endif
1861  update_controls()
1862  break
1863  case -1: // control being killed
1864  break
1865  endswitch
1866 
1867  setdatafolder save_df
1868  return 0
1869 End
1870 
1871 static function lbp_filelist(lba) : ListBoxControl
1872  STRUCT WMListboxAction &lba
1873 
1874  dfref save_df = GetDataFolderDFR()
1875 
1876  Variable row = lba.row
1877  Variable col = lba.col
1878  WAVE/T/Z listWave = lba.listWave
1879  WAVE/Z selWave = lba.selWave
1880 
1881  switch( lba.eventCode )
1882  case -1: // control being killed
1883  break
1884  case 1: // mouse down
1885  setdatafolder $package_path
1886  wave wSelectedFiles
1887  if (selWave[row])
1888  if (sum(wSelectedFiles) == 1)
1889  ControlInfo /W=PearlDataExplorer cb_file_preview
1890  selected_file(listWave[row], v_value)
1891  else
1892  selected_file(listWave[row], 0)
1893  endif
1894  endif
1895  update_controls()
1896  break
1897  case 3: // double click
1898  break
1899  case 4: // cell selection
1900  case 5: // cell selection plus shift key
1901  break
1902  case 6: // begin edit
1903  break
1904  case 7: // finish edit
1905  break
1906  case 13: // checkbox clicked (Igor 6.2 or later)
1907  break
1908  endswitch
1909 
1910  setdatafolder save_df
1911  return 0
1912 End
1913 
1914 static function bp_attr_notebook(ba) : ButtonControl
1915  STRUCT WMButtonAction &ba
1916 
1917  dfref save_df = GetDataFolderDFR()
1918 
1919  switch( ba.eventCode )
1920  case 2: // mouse up
1921  setdatafolder $package_path
1922  wave wSelectedFiles
1923  wave/t wtFiles
1924  variable nn = numpnts(wSelectedFiles)
1925  variable ii
1926  for (ii = 0; ii < nn; ii += 1)
1927  if (wSelectedFiles[ii])
1928  attributes_notebook(wtFiles[ii])
1929  break
1930  endif
1931  endfor
1932  break
1933  case -1: // control being killed
1934  break
1935  endswitch
1936 
1937  setdatafolder save_df
1938  return 0
1939 End
1940 
1941 
1942 static function hlp_setup()
1943  dfref save_df = GetDataFolderDFR()
1944  setdatafolder $package_path
1945 
1946  MakeListIntoHierarchicalList("PearlDataExplorer", "lb_contents", "hlp_contents_open", selectionMode=WMHL_SelectionSingle, pathSeparator="/")
1947 
1948  setdatafolder save_df
1949  return 0
1950 end
1951 
1952 static function hl_contents_clear()
1953  do
1954  if (cmpstr(WMHL_GetItemForRowNumber("PearlDataExplorer", "lb_contents", 0), "<uninitialized>") != 0)
1955  WMHL_DeleteRowAndChildren("PearlDataExplorer", "lb_contents", 0)
1956  else
1957  break
1958  endif
1959  while (1)
1960 end
1961 
1966 static function hl_contents_update(file_df)
1967  dfref file_df
1968 
1969  dfref save_df = GetDataFolderDFR()
1970  setdatafolder $package_path
1972 
1973  variable nds
1974  variable ids
1975  string ds
1976  string extra
1977  string /g hl_contents_datasets = ""
1978 
1979  if (DataFolderRefStatus(file_df))
1980  svar /sdfr=file_df datasets = s_datasets
1981  svar /sdfr=file_df datatypes = s_datasets_datatypes
1982  svar /sdfr=file_df ranks = s_datasets_ranks
1983  svar /sdfr=file_df dimensions = s_datasets_dimensions
1984 
1985  nds = ItemsInList(datasets, ";")
1986  for (ids = 0; ids < nds; ids += 1)
1987  ds = StringFromList(ids, datasets, ";")
1988  extra = StringFromList(ids, dimensions, ";")
1989  hl_contents_datasets = ReplaceStringByKey(ds, hl_contents_datasets, extra, ":", ";")
1990  endfor
1991  endif
1992 
1993  variable nobj = hl_add_objects("", hl_contents_datasets)
1994  hl_expand_scans()
1996  setdatafolder save_df
1997 
1998  return nobj
1999 end
2000 
2001 static function /df get_pshell_info(path_name, file_name, [dest_df])
2002  string path_name
2003  string file_name
2004  dfref dest_df
2005 
2006  dfref save_df = GetDataFolderDFR()
2007 
2008  if (!ParamIsDefault(dest_df))
2009  setdatafolder dest_df
2010  else
2011  setdatafolder $package_path
2012  NewDataFolder /o /s file_info
2013  endif
2014 
2015  dfref file_df = psh5_open_file(path_name, file_name, dest_df=GetDataFolderDFR())
2016  if (DataFolderRefStatus(file_df))
2017  psh5_load_general_group(file_df)
2018  psh5_close_file(file_df)
2019  endif
2020 
2021  setdatafolder save_df
2022  return file_df
2023 end
2024 
2029 static function hl_add_objects(parent_path, objects)
2030  string parent_path // e.g. "/a/b"
2031  string objects // all objects that might appear in the list. e.g. "/a/b/c:col0|col1;/a/b/d:col0|col1;/d/e/f:col0|col1;"
2032 
2033  if (cmpstr(parent_path[0], "/") != 0)
2034  parent_path = "/" + parent_path
2035  endif
2036 
2037  variable nobj = ItemsInList(objects, ";")
2038  variable iobj
2039  string obj
2040  string extra
2041  variable nel
2042 
2043  string child_path = ""
2044  string child_name = ""
2045  string child_names = "" // e.g., "child1:1;child3:2;"
2046  string extra_data = "" // e.g., "child1:col0|col1;child2:col0|col1;"
2047 
2048  // filter children of parent
2049  for (iobj = 0; iobj < nobj; iobj += 1)
2050  obj = StringFromList(iobj, objects, ";")
2051 
2052  if (cmpstr(obj[0, strlen(parent_path)-1], parent_path) == 0)
2053  child_path = StringFromList(0, obj, ":")
2054  child_path = child_path[strlen(parent_path), strlen(child_path)-1]
2055  if (cmpstr(child_path[0], "/") == 0)
2056  child_path = child_path[1, strlen(child_path)-1]
2057  endif
2058  child_name = StringFromList(0, child_path, "/")
2059  nel = ItemsInList(child_path, "/")
2060  child_names = ReplaceNumberByKey(child_name, child_names, nel)
2061  if (nel == 1)
2062  extra = RemoveListItem(0, obj, ":")
2063  extra_data = ReplaceStringByKey(child_name, extra_data, extra)
2064  endif
2065  endif
2066  endfor
2067 
2068  // add rows
2069  variable row
2070  variable children
2071  nobj = ItemsInList(child_names)
2072  for (iobj = 0; iobj < nobj; iobj += 1)
2073  obj = StringFromList(iobj, child_names)
2074  child_name = StringFromList(0, obj, ":")
2075  nel = NumberByKey(child_name, child_names)
2076  WMHL_AddObject("PearlDataExplorer", "lb_contents", parent_path[1, strlen(parent_path)], child_name, nel > 1)
2077  if (nel == 1)
2078  extra = StringByKey(child_name, extra_data)
2079  row = WMHL_GetRowNumberForItem("PearlDataExplorer", "lb_contents", parent_path[1, strlen(parent_path)] + "/" + child_name)
2080  if (row >= 0)
2081  WMHL_ExtraColumnData("PearlDataExplorer", "lb_contents", 0, row, StringFromList(0, extra, "|"), 0)
2082  endif
2083  endif
2084  endfor
2085 
2086  return nobj
2087 end
2088 
2089 static function hl_expand_scans()
2090  dfref save_df = GetDataFolderDFR()
2091  setdatafolder $package_path
2092 
2093  svar hl_contents_datasets
2094  variable nds = ItemsInList(hl_contents_datasets, ";")
2095  variable ids
2096  string sds
2097  string scan
2098  string scans = ""
2099  for (ids = 0; ids < nds; ids += 1)
2100  sds = StringFromList(ids, hl_contents_datasets, ";")
2101  if (cmpstr(sds[0,4], "/scan", 0) == 0)
2102  scan = StringFromList(1, sds, "/")
2103  scans = ReplaceNumberByKey(scan, scans, 1)
2104  endif
2105  endfor
2106 
2107  variable nscans = ItemsInList(scans)
2108  variable iscan
2109  for (iscan = 0; iscan < nscans; iscan += 1)
2110  scan = StringFromList(iscan, scans)
2111  scan = StringFromList(0, scan, ":")
2112  WMHL_OpenAContainer("PearlDataExplorer", "lb_contents", scan)
2113  endfor
2114 
2115  setdatafolder save_df
2116 end
2117 
2118 static function hl_default_selection()
2119  variable row
2120  row = WMHL_GetRowNumberForItem("PearlDataExplorer", "lb_contents", "scan 1")
2121  if (row < 0)
2122  row = WMHL_GetRowNumberForItem("PearlDataExplorer", "lb_contents", "scan1")
2123  endif
2124  if (row >= 0)
2125  WMHL_SelectARow("PearlDataExplorer", "lb_contents", row, 1)
2126  endif
2127 end
2128 
2129 static function hlp_contents_open(HostWindow, ListControlName, ContainerPath)
2130  String HostWindow, ListControlName, ContainerPath
2131 
2132  dfref save_df = GetDataFolderDFR()
2133  setdatafolder $package_path
2134  svar hl_contents_datasets
2135  hl_add_objects(ContainerPath, hl_contents_datasets)
2136  setdatafolder save_df
2137 end
2138 
2139 static function hlp_contents_selection(HostWindow, ListControlName, SelectedItem, EventCode)
2140  String HostWindow, ListControlName
2141  String SelectedItem
2142  Variable EventCode
2143 
2144  dfref save_df = GetDataFolderDFR()
2145  setdatafolder $package_path
2146 
2147  switch (eventCode)
2148  case 3: // double click
2149  // todo: load dataset?
2150  break
2151  case 4: // cell selection
2152  case 5: // cell selection plus shift key
2153  update_controls()
2154  break
2155  endswitch
2156 
2157  setdatafolder save_df
2158  return 0
2159 end
2160 
2175 static function goto_dataset_folder(filename, datapath)
2176  string filename
2177  string datapath
2178 
2179  dfref save_df = GetDataFolderDFR()
2180  setdatafolder $package_path
2181 
2182  variable ft = pearl_file_type(filename)
2183  string parent_folder
2184  string folder
2185  string path
2186 
2187  switch(ft)
2188  case 1:
2189  case 2:
2190  parent_folder = ad_suggest_foldername(filename)
2191  path = "root:" + parent_folder
2192  if (DataFolderExists(path))
2193  setdatafolder $path
2194  else
2195  return -2
2196  endif
2197 
2198  variable nparts = ItemsInList(datapath, "/")
2199  variable ipart
2200  for (ipart = 0; ipart < nparts; ipart += 1)
2201  folder = StringFromList(ipart, datapath, "/")
2202  path = ":" + ps_fix_folder_name(folder)
2203  if (DataFolderExists(path))
2204  setdatafolder $path
2205  endif
2206  endfor
2207  break
2208 
2209  case 3:
2210  parent_folder = "root:" + itx_suggest_foldername(filename)
2211  if (DataFolderExists(parent_folder))
2212  setdatafolder $parent_folder
2213  else
2214  return -2
2215  endif
2216  break
2217 
2218  default:
2219  // unsupported file type
2220  return -1
2221  endswitch
2222 
2223  return 0
2224 end
2225 
2231 static function bp_goto_dataset(ba) : ButtonControl
2232  STRUCT WMButtonAction &ba
2233 
2234  switch( ba.eventCode )
2235  case 2: // mouse up
2236  dfref save_df = GetDataFolderDFR()
2237  setdatafolder $package_path
2238  svar s_selected_file
2239  svar hl_contents_datasets
2240  string datapath = StringFromList(0, WMHL_SelectedObjectsList("PearlDataExplorer", "lb_contents"))
2241  if (strsearch(hl_contents_datasets, datapath, 0) != 0)
2242  datapath = datapath + "/"
2243  endif
2244  variable result = goto_dataset_folder(s_selected_file, datapath)
2245  if (result != 0)
2246  setdatafolder save_df
2247  string msg
2248  msg = "Can't find data folder. Has the file been loaded?"
2249  DoAlert /T="Goto DF" 0, msg
2250  endif
2251 
2252  break
2253  case -1: // control being killed
2254  break
2255  endswitch
2256 
2257  return 0
2258 End
2259 
2263 static function bp_display_dataset(ba) : ButtonControl
2264  STRUCT WMButtonAction &ba
2265 
2266  switch( ba.eventCode )
2267  case 2: // mouse up
2268  dfref save_df = GetDataFolderDFR()
2269  setdatafolder $package_path
2270  svar s_selected_file
2271  svar hl_contents_datasets
2272  string datapath = StringFromList(0, WMHL_SelectedObjectsList("PearlDataExplorer", "lb_contents"))
2273  if (strsearch(hl_contents_datasets, datapath, 0) < 0)
2274  // path leads to folder
2275  return 0
2276  endif
2277  goto_dataset_folder(s_selected_file, "")
2278  display_dataset(GetDataFolderDFR(), datapath)
2279  setdatafolder save_df
2280  break
2281  case -1: // control being killed
2282  break
2283  endswitch
2284 
2285  return 0
2286 End
2287 
2295 static function send_to_elog()
2296  dfref save_df = GetDataFolderDFR()
2297 
2298  dfref preview_df = $package_path
2299  svar /z /sdfr=preview_df s_selected_file
2300  svar /z /sdfr=preview_df s_preview_file
2301  svar /z /sdfr=preview_df s_preview_graph
2302 
2303  if (!SVAR_Exists(s_selected_file) || (strlen(s_selected_file) < 1))
2304  return 0
2305  endif
2306 
2307  // check data folder
2308  variable result = -1
2309  result = goto_dataset_folder(s_selected_file, "")
2310  if (result == 0)
2311  dfref data_df = GetDataFolderDFR()
2312  svar /sdfr=data_df /z authors
2313  if (!svar_Exists(authors))
2314  result = -1
2315  endif
2316  endif
2317 
2318  // file info folder
2319  dfref infoDF = preview_df:file_info
2320  if ((result != 0) && (DataFolderRefStatus(infoDF)))
2321  svar /z /sdfr=infoDF s_filepath
2322  if (SVAR_Exists(s_filepath) && (strsearch(s_filepath, s_selected_file, inf, 1) >= 0))
2323  dfref data_df = infoDF
2324  result = 0
2325  endif
2326  endif
2327 
2328  // check preview (package) folder
2329  if ((result != 0) && (SVAR_Exists(s_preview_file) && (cmpstr(s_preview_file, s_selected_file) == 0)))
2330  dfref data_df = preview_df
2331  result = 0
2332  endif
2333 
2334  string graphname
2335  if (SVAR_Exists(s_preview_graph) && (WinType(s_preview_graph) == 1))
2336  graphname = s_preview_graph
2337  else
2338  graphname = ""
2339  endif
2340 
2341  if (result == 0)
2342  set_elog_attributes(data_df, filename=s_selected_file, graphname=graphname)
2343  string windowname
2344  windowname = StringFromList(0, WinList("*ElogPanel*", ";", "WIN:64"), ";")
2345  DoWindow /F $windowname
2346  endif
2347 
2348  setdatafolder save_df
2349 end
2350 
2351 static function bp_elog(ba) : ButtonControl
2352  STRUCT WMButtonAction &ba
2353 
2354  switch( ba.eventCode )
2355  case 2: // mouse up
2356  send_to_elog()
2357  break
2358  case -1: // control being killed
2359  break
2360  endswitch
2361 
2362  return 0
2363 End
2364 
pearl_data_explorer
variable pearl_data_explorer()
show the pearl data explorer window
Definition: pearl-data-explorer.ipf:47
save_prefs
static variable save_prefs()
save persistent package data to the preferences file.
Definition: pearl-data-explorer.ipf:139
bp_goto_dataset
static variable bp_goto_dataset(WMButtonAction *ba)
"goto DF" button
Definition: pearl-data-explorer.ipf:2231
ps_fix_folder_name
string ps_fix_folder_name(string group_name)
convert HDF5 group name to data folder name and fix compatibility issues
Definition: pearl-pshell-import.ipf:1065
hlp_contents_selection
static variable hlp_contents_selection(string HostWindow, string ListControlName, string SelectedItem, variable EventCode)
Definition: pearl-data-explorer.ipf:2139
adh5_list_reduction_funcs
string adh5_list_reduction_funcs()
get a list of functions which can be used as reduction functions.
Definition: pearl-area-import.ipf:1045
show_preview_graph
static string show_preview_graph(wave data, wave xdata=defaultValue)
Definition: pearl-data-explorer.ipf:925
ad_display_slice
string ad_display_slice(wave data)
display three-dimensional data by 2D slice.
Definition: pearl-area-display.ipf:1406
preview_datafolder
static variable preview_datafolder()
preview data in the current data folder
Definition: pearl-data-explorer.ipf:826
kDSCEssentialDiags
const variable kDSCEssentialDiags
Definition: pearl-pshell-import.ipf:78
update_controls
static variable update_controls()
update controls state
Definition: pearl-data-explorer.ipf:1557
ks_filematch_pshell
static const string ks_filematch_pshell
Definition: pearl-data-explorer.ipf:39
prompt_default_process
variable prompt_default_process(string *param)
prototype for prompting for processing function parameters.
Definition: pearl-data-explorer.ipf:1130
get_pshell_info
static dfr get_pshell_info(string path_name, string file_name, dfref dest_df=defaultValue)
Definition: pearl-data-explorer.ipf:2001
adh5_load_preview
string adh5_load_preview(string ANickName, string APathName, string AFileName, variable load_data=defaultValue, variable load_attr=defaultValue)
load a single image from a HDF5 file created by the Area Detector software.
Definition: pearl-area-import.ipf:391
load_selected_files
static variable load_selected_files(string options=defaultValue)
load the selected files
Definition: pearl-data-explorer.ipf:1025
psh5_load_general_group
string psh5_load_general_group(dfref file_df)
load organizational metadata from the general group.
Definition: pearl-pshell-import.ipf:1803
bp_elog
static variable bp_elog(WMButtonAction *ba)
Definition: pearl-data-explorer.ipf:2351
update_filelist
static variable update_filelist()
read a list of PEARL files from the file system
Definition: pearl-data-explorer.ipf:231
create_attributes_notebook
static variable create_attributes_notebook(wave attr_names, wave attr_values, string title)
Definition: pearl-data-explorer.ipf:480
hl_default_selection
static variable hl_default_selection()
Definition: pearl-data-explorer.ipf:2118
adh5_load_info
string adh5_load_info(string APathName, string AFileName)
load descriptive info from a HDF5 file created by the Area Detector software.
Definition: pearl-area-import.ipf:501
notebook_add_attributes
static variable notebook_add_attributes(string notebook_name, wave attr_filter, wave attr_names, wave attr_values)
Definition: pearl-data-explorer.ipf:519
kDSCMonitors
const variable kDSCMonitors
Definition: pearl-pshell-import.ipf:83
pmp_reduction_func
static variable pmp_reduction_func(WMPopupAction *pa)
Definition: pearl-data-explorer.ipf:1719
prompt_hdf_options
static variable prompt_hdf_options(string *options)
Definition: pearl-data-explorer.ipf:1090
load_file
static variable load_file(string filename, string options=defaultValue, dfref dest_df=defaultValue, variable quiet=defaultValue)
load one file
Definition: pearl-data-explorer.ipf:1064
hl_contents_clear
static variable hl_contents_clear()
Definition: pearl-data-explorer.ipf:1952
kDSCPositioners
const variable kDSCPositioners
Definition: pearl-pshell-import.ipf:74
ks_filematch_adh5
static const string ks_filematch_adh5
Definition: pearl-data-explorer.ipf:38
bp_attr_notebook
static variable bp_attr_notebook(WMButtonAction *ba)
Definition: pearl-data-explorer.ipf:1914
PearlDataExplorer
void PearlDataExplorer()
Definition: pearl-data-explorer.ipf:1478
preview_pshell_file
static wave preview_pshell_file(string filename)
load the preview of a PShell HDF5 file.
Definition: pearl-data-explorer.ipf:671
bp_load_prefs
static variable bp_load_prefs(WMButtonAction *ba)
Definition: pearl-data-explorer.ipf:1618
ks_filematch_itx
static const string ks_filematch_itx
Definition: pearl-data-explorer.ipf:40
kDSCScientaScaling
const variable kDSCScientaScaling
Definition: pearl-pshell-import.ipf:76
bp_save_prefs
static variable bp_save_prefs(WMButtonAction *ba)
Definition: pearl-data-explorer.ipf:1633
PearlElog
interface for writing ELOG entries with Igor graphs as attachment.
psh5_extract_region_paths
string psh5_extract_region_paths(string datasets)
trim dataset paths to the scan/region part
Definition: pearl-pshell-import.ipf:853
selected_file
static variable selected_file(string file, variable do_preview)
actions after a file has been selected
Definition: pearl-data-explorer.ipf:1791
display_dataset
static variable display_dataset(dfref file_df, string dataset)
displays the graph of a loaded dataset in its own window
Definition: pearl-data-explorer.ipf:897
init_package
static variable init_package()
Definition: pearl-data-explorer.ipf:61
preview_setscale_x
static variable preview_setscale_x(wave data, wave preview)
Definition: pearl-data-explorer.ipf:866
shorten_filepath
static string shorten_filepath(string long_path, variable max_len)
shorten a file path for display
Definition: pearl-data-explorer.ipf:1651
bp_browse_filepath
static variable bp_browse_filepath(WMButtonAction *ba)
Definition: pearl-data-explorer.ipf:1673
set_elog_attributes
static variable set_elog_attributes(dfref file_df, string filename=defaultValue, string graphname=defaultValue)
send general metadata to ELOG panel - if available
Definition: pearl-data-explorer.ipf:568
lbp_filelist
static variable lbp_filelist(WMListboxAction *lba)
Definition: pearl-data-explorer.ipf:1871
bp_display_dataset
static variable bp_display_dataset(WMButtonAction *ba)
"display dataset" button
Definition: pearl-data-explorer.ipf:2263
extract_attributes
static variable extract_attributes(dfref attr_df, dfref dest_df=defaultValue, wave attr_filter=defaultValue, variable include_datawaves=defaultValue, variable include_infowaves=defaultValue)
extract summary from attribute waves
Definition: pearl-data-explorer.ipf:347
kDSCSnaps
const variable kDSCSnaps
Definition: pearl-pshell-import.ipf:81
attributes_notebook
static variable attributes_notebook(string filename)
load attributes
Definition: pearl-data-explorer.ipf:301
psh5_dataset_to_folder
dfr psh5_dataset_to_folder(dfref parent_df, string datasetpath)
map dataset path to datafolder path
Definition: pearl-pshell-import.ipf:1034
ad_suggest_foldername
string ad_suggest_foldername(string filename, variable ignoredate=defaultValue, string sourcename=defaultValue, variable unique=defaultValue)
generate the name of a data folder based on a file name.
Definition: pearl-area-import.ipf:110
kDSCMeta
const variable kDSCMeta
Definition: pearl-pshell-import.ipf:82
load_itx_file
static dfr load_itx_file(string filename, string options=defaultValue, dfref dest_df=defaultValue, variable quiet=defaultValue)
Definition: pearl-data-explorer.ipf:1358
kDSCDiags
const variable kDSCDiags
Definition: pearl-pshell-import.ipf:80
goto_dataset_folder
static variable goto_dataset_folder(string filename, string datapath)
open data folder corresponding to a file and data path
Definition: pearl-data-explorer.ipf:2175
get_file_info
static variable get_file_info(string filename)
load the internal structure of a file
Definition: pearl-data-explorer.ipf:273
load_pshell_file
static dfr load_pshell_file(string filename, string options=defaultValue, dfref dest_df=defaultValue, variable quiet=defaultValue)
load a pshell file
Definition: pearl-data-explorer.ipf:1188
adh5_load_complete
string adh5_load_complete(string ANickName, string APathName, string AFileName, variable load_data=defaultValue, variable load_attr=defaultValue)
import everything from a HDF5 file created by the Area Detector software.
Definition: pearl-area-import.ipf:211
ps_find_attr_folder
dfr ps_find_attr_folder(dfref scan_df)
find the attributes data folder
Definition: pearl-pshell-import.ipf:2134
hl_contents_update
static variable hl_contents_update(dfref file_df)
populate the contents list box with the internal directory of a HDF5 file
Definition: pearl-data-explorer.ipf:1966
itx_suggest_foldername
string itx_suggest_foldername(string filename, variable ignoredate=defaultValue, string sourcename=defaultValue, variable unique=defaultValue)
suggest the name of a data folder based on an igor-text file name
Definition: pearl-data-explorer.ipf:1427
kDSCAttrs
const variable kDSCAttrs
Definition: pearl-pshell-import.ipf:79
bp_reduction_params
static variable bp_reduction_params(WMButtonAction *ba)
Definition: pearl-data-explorer.ipf:1735
send_to_elog
static variable send_to_elog()
send file metadata to the ELOG panel
Definition: pearl-data-explorer.ipf:2295
bp_file_next
static variable bp_file_next(WMButtonAction *ba)
Definition: pearl-data-explorer.ipf:1809
hlp_setup
static variable hlp_setup()
Definition: pearl-data-explorer.ipf:1942
adh5_default_reduction
threadsafe wave adh5_default_reduction(wave source, string *param)
function prototype for adh5_load_reduced_detector
Definition: pearl-area-import.ipf:1115
ad_extract_slab
threadsafe wave ad_extract_slab(wave dataset, variable x1, variable x2, variable y1, variable y2, variable z1, variable z2, string destname, variable noavg=defaultValue, variable pscale=defaultValue)
2D cut through 3D dataset, integrate in normal dimension
Definition: pearl-area-profiles.ipf:314
preview_itx_file
static wave preview_itx_file(string filename)
load the preview of a general ITX file.
Definition: pearl-data-explorer.ipf:762
update_filepath
static variable update_filepath()
update the file path after path change
Definition: pearl-data-explorer.ipf:218
kDSCDetectors
const variable kDSCDetectors
Definition: pearl-pshell-import.ipf:75
psh5_preview
dfr psh5_preview(string path_name, string file_name, dfref dest_df=defaultValue, string preview_datasets=defaultValue)
load preview
Definition: pearl-pshell-import.ipf:345
test_attributes_notebook
variable test_attributes_notebook()
Definition: pearl-data-explorer.ipf:473
pearl_file_type
static variable pearl_file_type(string filename)
check whether a file can be imported by this module.
Definition: pearl-data-explorer.ipf:199
psh5_close_file
variable psh5_close_file(dfref file_df)
close a HDF5 file opened by psh5_open_file.
Definition: pearl-pshell-import.ipf:509
version
version
Definition: pearl-data-explorer.ipf:6
adh5_load_reduced
string adh5_load_reduced(string ANickName, string APathName, string AFileName, funcref reduction_func, string reduction_param, variable load_data=defaultValue, variable load_attr=defaultValue, variable progress=defaultValue)
load and reduce a dataset from a HDF5 file created by the Area Detector software.
Definition: pearl-area-import.ipf:306
pm_reduction_values
static string pm_reduction_values()
items for data reduction popup
Definition: pearl-data-explorer.ipf:1712
PearlCleanupName
string PearlCleanupName(string name)
Definition: pearl-compat.ipf:48
load_prefs
static variable load_prefs()
Definition: pearl-data-explorer.ipf:155
prompt_func_params
variable prompt_func_params(string func_name, string *func_param)
Definition: pearl-data-explorer.ipf:1136
psh5_load
dfr psh5_load(string path_name, string file_name, string scans, string regions, string datasets, variable classes=defaultValue, variable max_rank=defaultValue, string reduction_func=defaultValue, string reduction_params=defaultValue, dfref dest_df=defaultValue)
main data loading function
Definition: pearl-pshell-import.ipf:158
load_hdf_file
static dfr load_hdf_file(string filename, string options=defaultValue, dfref dest_df=defaultValue, variable quiet=defaultValue)
Definition: pearl-data-explorer.ipf:1298
hlp_contents_open
static variable hlp_contents_open(string HostWindow, string ListControlName, string ContainerPath)
Definition: pearl-data-explorer.ipf:2129
bp_update_filelist
static variable bp_update_filelist(WMButtonAction *ba)
Definition: pearl-data-explorer.ipf:1696
extract_preview_image
static variable extract_preview_image(wave data, wave preview)
extract a preview image from a wave of arbitrary dimension
Definition: pearl-data-explorer.ipf:784
bp_file_prev
static variable bp_file_prev(WMButtonAction *ba)
Definition: pearl-data-explorer.ipf:1840
ad_display_profiles
string ad_display_profiles(wave image, string filter=defaultValue)
open a new profiles graph window.
Definition: pearl-area-display.ipf:168
ad_brick_slicer
variable ad_brick_slicer(wave data)
open a slicer panel for 3D data.
Definition: pearl-area-display.ipf:1258
preview_file
static variable preview_file(string filename)
Definition: pearl-data-explorer.ipf:629
psh5_extract_scan_paths
string psh5_extract_scan_paths(string datasets)
trim dataset paths to the scan part
Definition: pearl-pshell-import.ipf:803
psh5_open_file
dfr psh5_open_file(string path_name, string file_name, dfref dest_df=defaultValue)
open a HDF5 file created by the PShell data acquisition program and prepare the data folder.
Definition: pearl-pshell-import.ipf:450
package_name
static const string package_name
package name is used as data folder name
Definition: pearl-anglescan-panel.ipf:48
display_preview_trace
static string display_preview_trace(wave xtrace, wave ytrace)
Definition: pearl-data-explorer.ipf:978
hl_expand_scans
static variable hl_expand_scans()
Definition: pearl-data-explorer.ipf:2089
bp_load_options
static variable bp_load_options(WMButtonAction *ba)
Definition: pearl-data-explorer.ipf:1757
hl_add_objects
static variable hl_add_objects(string parent_path, string objects)
populate the contents list box with the given hierarchical paths
Definition: pearl-data-explorer.ipf:2029
package_path
static const string package_path
Definition: pearl-data-explorer.ipf:36
kDSCAll
const variable kDSCAll
Definition: pearl-pshell-import.ipf:86
preview_hdf_file
static wave preview_hdf_file(string filename)
load the preview of a PEARL HDF5 file.
Definition: pearl-data-explorer.ipf:717