PEARL Procedures  rev-distro-2.0.3-2-g58135e4-dirty
Igor procedures for the analysis of PEARL data
pearl-data-explorer.ipf
Go to the documentation of this file.
1 #pragma rtGlobals=3 // Use modern global access method and strict wave access.
2 #pragma IgorVersion = 6.1
3 #pragma ModuleName = PearlDataExplorer
4 #pragma version = 1.50
5 #include "pearl-area-import"
6 #include "pearl-area-profiles"
7 #include "pearl-area-display"
8 #include "pearl-compat"
9 #include "pearl-pshell-import"
10 #if exists("MFR_OpenResultFile")
11 #include "pearl-matrix-import"
12 #endif
13 
14 // copyright (c) 2013-16 Paul Scherrer Institut
15 //
16 // Licensed under the Apache License, Version 2.0 (the "License");
17 // you may not use this file except in compliance with the License.
18 // You may obtain a copy of the License at
19 // http:///www.apache.org/licenses/LICENSE-2.0
20 
31 
36 
37 static strconstant package_name = "pearl_explorer"
38 static strconstant package_path = "root:packages:pearl_explorer:"
39 
40 static strconstant ks_filematch_adh5 = "*.h5"
41 static strconstant ks_filematch_pshell = "psh*.h5"
42 static strconstant ks_filematch_itx = "*.itx"
43 static strconstant ks_filematch_mtrx = "*_mtrx"
44 
46  init_package()
47  load_prefs()
48  execute /q/z "PearlDataExplorer()"
49 end
50 
56 static function init_package()
57 
58  dfref savefolder = GetDataFolderDFR()
59  SetDataFolder root:
60  newdatafolder /o/s packages
61  newdatafolder /o/s $package_name
62  if (exists("v_InitPanelDone") == 2)
63  SetDataFolder savefolder
64  return 0
65  endif
66 
67  make /o/n=0/t wtFiles
68  make /o/n=0/i wSelectedFiles,wSelectedDatasets
69  make /o/n=0/t wtDatasets
70  make /o/n=0/t wtPositioners,wtDetectors
71  make /o/n=0/i wSelectedPositioners,wSelectedDetectors
72 
73  make /o/n=(1,1) preview_image // preview 2D data
74  make /o/n=0 preview_trace // preview 1D data
75  make /o/n=0/t attr_names, attr_values, attr_filter, attr_filter_summary
76 
77  // persistent strings and variables. persistent = saved in preferences
78  string /g s_filepath = "" // directory path to be listed
79  string /g s_hdf_options = "" // recently used HDF5 load options
80  string /g s_reduction_params = "" // recently used reduction parameters
81  string /g s_preview_pvs = "" // semicolon-separated list of EPICS PVs to display in preview.
82  // the list items can contain wildcards for StringMatch
83  s_preview_pvs = "*OP:CURRENT*;*Stats*Total*;*KEITHLEY*READOUT;*CADC*"
84 
85  // non-persistent strings and variables
86  string /g s_preview_file = "" // file or folder name of the current preview
87  string /g s_preview_source = "" // data source, e.g. EPICS channel name, of the current preview
88  string /g s_profiles_graph = "" // window name of the current preview if the data is two-dimensional
89  string /g s_preview_trace_graph = "" // window name of the current preview if the data is one-dimensional
90  string /g s_file_info = "" // description of selected file
91 
92  variable/g v_InitPanelDone = 1
93 
94  SetDataFolder savefolder
95 end
96 
97 static function save_prefs()
98  // saves persistent package data to the preferences file
99  // the data saved in the file are: data file path, attributes filter
100  dfref saveDF = GetDataFolderDFR()
101 
102  string fullPath = SpecialDirPath("Packages", 0, 0, 0)
103  fullPath += package_name
104  NewPath/O/C/Q tempPackagePrefsPath, fullPath
105  fullPath += ":preferences.pxp"
106 
107  SetDataFolder root:packages
108  SetDataFolder $package_name
109  string objects = "attr_filter;attr_filter_summary;s_filepath;s_hdf_options;s_reduction_params;s_preview_pvs"
110  SaveData /O /Q /J=objects fullPath
111 
112  KillPath/Z tempPackagePrefsPath
113 
114  SetDataFolder saveDF
115 end
116 
117 static function load_prefs()
118  // loads persistent package data from the preferences file
119  // the preferences file is an Igor packed experiment file in a special preferences folder
120  dfref saveDF = GetDataFolderDFR()
121 
122  variable result = -1
123  setdatafolder root:
124  NewDataFolder /O/S packages
125  NewDataFolder /O/S $package_name
126  dfref packageDF = GetDataFolderDFR()
127  string fullPath = SpecialDirPath("Packages", 0, 0, 0)
128  fullPath += package_name
129 
130  GetFileFolderInfo /Q /Z fullPath
131  if (V_Flag == 0) // Disk directory exists?
132  fullPath += ":preferences.pxp"
133  GetFileFolderInfo /Q /Z fullPath
134  if (V_Flag == 0) // Preference file exist?
135  LoadData /O /R /Q fullPath
136  result = 0
137  endif
138  endif
139 
140  if (result == 0)
141  svar /sdfr=packageDF filepath = s_filepath
142  NewPath /O/Z pearl_explorer_filepath, filepath
145  endif
146 
147  SetDataFolder saveDF
148  return result
149 end
150 
162 static function pearl_file_type(filename)
163  string filename
164 
165  if (StringMatch(filename, ks_filematch_pshell))
166  return 1
167  elseif (StringMatch(filename, ks_filematch_adh5))
168  return 2
169  elseif (StringMatch(filename, ks_filematch_itx))
170  return 3
171 #if exists("MFR_OpenResultFile")
172  elseif (StringMatch(filename, ks_filematch_mtrx))
173  return 4
174 #endif
175  else
176  return 0
177  endif
178 end
179 
185 static function update_filelist()
186  dfref saveDF = GetDataFolderDFR()
187 
188  string all_files
189  wave /t wtFiles = $(package_path + "wtFiles")
190  wave wSelectedFiles = $(package_path + "wSelectedFiles")
191  variable nn
192 
193  PathInfo pearl_explorer_filepath
194  if (v_flag == 1)
195  all_files = IndexedFile(pearl_explorer_filepath, -1, "????")
196  nn = ItemsInList(all_files)
197  else
198  all_files = ""
199  nn = 0
200  endif
201 
202  make /n=(nn) /t /free wtAllFiles
203  wtAllFiles = StringFromList(p, all_files)
204  Extract /o /t wtAllFiles, wtFiles, pearl_file_type(wtAllFiles[p])
205  Sort /A /R wtFiles, wtFiles
206 
207  redimension /n=(numpnts(wtFiles)) wSelectedFiles
208  wSelectedFiles = 0
209 
210  setdatafolder saveDF
211 end
212 
213 static function update_datasets()
214  // updates the list of imported datasets.
215  // a dataset means any top-level data folder
216  // which includes a string variable named pearl_explorer_import.
217  dfref saveDF = GetDataFolderDFR()
218 
219  setdatafolder root:
220  dfref rootdf = GetDataFolderDFR()
221  setdatafolder $package_path
222  dfref privatedf = GetDataFolderDFR()
223 
224  wave /t wtDatasets
225  wave wSelectedDatasets
226  variable maxdf = CountObjectsDFR(rootdf, 4)
227  redimension /n=(maxdf) wtDatasets
228 
229  variable idf = 0
230  variable ndf = 0
231  string sdf
232 
233  do
234  sdf = GetIndexedObjNameDFR(rootdf, 4, idf)
235  if (strlen(sdf) >= 1)
236  setdatafolder rootdf
237  setdatafolder $sdf
238  svar /z importer = pearl_explorer_import
239  if (svar_exists(importer))
240  wtDatasets[ndf] = sdf
241  ndf += 1
242  endif
243  else
244  break
245  endif
246  idf += 1
247  while(1)
248 
249  redimension /n=(ndf) wtDatasets, wSelectedDatasets
250  wSelectedDatasets = 0
251  sort wtDatasets, wtDatasets
252 
253  setdatafolder saveDF
254 end
255 
256 static function preview_file(filename)
257  string filename
258 
259  dfref saveDF = GetDataFolderDFR()
260 
261  variable ft = pearl_file_type(filename)
262  switch(ft)
263  case 1:
264  wave /z image = preview_pshell_file(filename)
265  break
266  case 2:
267  wave /z image = preview_hdf_file(filename)
268  break
269  case 3:
270  wave /z image = preview_itx_file(filename)
271  break
272  case 4:
273  wave /z image = preview_mtrx_file(filename)
274  break
275  default:
276  wave /z image = $""
277  endswitch
278 
279  if (WaveExists(image))
280  string graphname = show_preview_graph(image)
281  // preset ELOG panel - if available
282  if (exists("PearlElog#set_panel_attributes") == 6)
283  string cmd
284  sprintf cmd, "PearlElog#set_panel_attributes(\"\", \"File=%s\")", ParseFilePath(0, filename, ":", 1, 0)
285  execute /Q/Z cmd
286  if (strlen(graphname) > 0)
287  sprintf cmd, "PearlElog#set_panel_graphs(\"\", \"%s\")", graphname
288  execute /Q/Z cmd
289  endif
290  endif
291  endif
292 
293  setdatafolder saveDF
294  return 0
295 end
296 
308 static function /wave preview_pshell_file(filename)
309  string filename
310 
311  dfref saveDF = GetDataFolderDFR()
312 
313  setdatafolder $package_path
314  dfref previewDF = GetDataFolderDFR()
315  svar s_preview_file
316  svar s_preview_source
317  svar /z s_file_info
318  if (! svar_exists(s_file_info))
319  string /g s_file_info
320  endif
321 
322  dfref tempDF = NewFreeDataFolder()
323  setdatafolder tempDF
324  string dataname
325  dataname = psh5_load_preview("pearl_explorer_filepath", filename)
326 
327  s_preview_file = filename
328  s_preview_source = ""
329 
330  wave /z data = $dataname
331  if (waveexists(data))
332  duplicate /o data, previewDF:preview_image
333  else
334  print "no data found in file " + filename
335  endif
336 
337  if (strlen(s_preview_file) > 0)
338  s_file_info = psh5_load_info("pearl_explorer_filepath", filename)
339  else
340  s_file_info = ""
341  endif
342 
343  dfref attrDF = tempDF:attr
344  if (DataFolderRefStatus(attrDF))
345  preview_attributes(attrDF)
346  endif
347 
348  setdatafolder saveDF
349  wave /z /sdfr=previewDF preview_image
350  return preview_image
351 end
352 
364 static function /wave preview_hdf_file(filename)
365  string filename
366 
367  dfref saveDF = GetDataFolderDFR()
368  setdatafolder $package_path
369  svar s_preview_file
370  svar s_preview_source
371  adh5_load_preview("preview_image", "pearl_explorer_filepath", filename)
372  s_preview_file = filename
373  s_preview_source = ""
374  wave /z preview_image
375 
376  svar /z s_file_info
377  if (! svar_exists(s_file_info))
378  string /g s_file_info
379  endif
380  if (strlen(s_preview_file) > 0)
381  s_file_info = adh5_load_info("pearl_explorer_filepath", filename)
382  else
383  s_file_info = ""
384  endif
385 
386  if (DataFolderExists("attr"))
387  setdatafolder attr
388  preview_attributes(GetDataFolderDFR())
389  setdatafolder ::
390  endif
391 
392  setdatafolder saveDF
393  return preview_image
394 end
395 
415 static function /wave preview_itx_file(filename)
416  string filename
417 
418  dfref saveDF = GetDataFolderDFR()
419  setdatafolder $package_path
420  svar s_preview_file
421  svar s_preview_source
422  wave preview_image
423 
424  dfref dataDF = newfreedatafolder()
425  setdatafolder dataDF
426  LoadWave /t/p=pearl_explorer_filepath/q filename
427  s_preview_file = s_filename
428  s_preview_source = ""
429 
431  preview_attributes(dataDF, include_datawaves=0)
432 
433  setdatafolder saveDF
434  return preview_image
435 end
436 
451 static function /wave preview_mtrx_file(filename)
452  string filename
453 
454 #if exists("MFR_OpenResultFile")
455  dfref saveDF = GetDataFolderDFR()
456  setdatafolder $package_path
457  variable /g V_MatrixFileReaderOverwrite = 1
458  variable /g V_MatrixFileReaderFolder = 0
459  variable /g V_MatrixFileReaderDouble = 0
460  svar s_preview_file
461  svar s_preview_source
462  string datanames
463  string dataname
464  datanames = mtrx_load_preview("preview", "pearl_explorer_filepath", filename)
465  if (strlen(datanames) > 0)
466  s_preview_file = filename
467 
468  dataname = StringFromList(0, datanames)
469  wave data = $dataname
470  duplicate /o $dataname, preview_image
471  s_preview_source = StringByKey("Dataset", note(data), "=", "\r")
472 
473  svar /z s_file_info
474  if (svar_exists(s_file_info))
475  s_file_info = ""
476  endif
477 
478  variable i
479  variable n = ItemsInList(datanames)
480  string s
481  for (i = 0; i < n; i += 1)
482  s = StringFromList(i, datanames)
483  killwaves /z $s
484  endfor
485  endif
486  wave /z preview_image
487  setdatafolder saveDF
488 #else
489  wave /z preview_image = $""
490 #endif
491  return preview_image
492 end
493 
494 static function extract_preview_image(data, preview)
495  // extracts a preview image from a wave of arbitrary dimension
496  wave data
497  wave preview
498 
499  variable z1, z2
500 
501  // extract image
502  switch (WaveDims(data))
503  case 1:
504  redimension /n=(numpnts(data)) preview
505  preview = data[p]
506  break
507  case 2:
508  redimension /n=(dimsize(data, 0), dimsize(data, 1)) preview
509  preview = data
510  break
511  case 3:
512  redimension /n=(dimsize(data, 0), dimsize(data, 1)) preview
513  z1 = floor(DimSize(data, 2) / 2)
514  z2 = z1
515  wave slab = ad_extract_slab(data, nan, nan, nan, nan, z1, z2, "", pscale=1)
516  preview = slab
517  break
518  case 4:
519  // not implemented
520  endswitch
521 
522  switch (WaveDims(data))
523  case 4:
524  case 3:
525  case 2:
526  setscale /p y dimoffset(data, 1), dimdelta(data, 1), waveunits(data, 1), preview
527  case 1:
528  setscale /p x dimoffset(data, 0), dimdelta(data, 0), waveunits(data, 0), preview
529  setscale d 0, 0, waveunits(data, -1), preview
530  endswitch
531 end
532 
533 static function preview_dataset(datasetname)
534  string datasetname // name of a data folder under root
535 
536  dfref saveDF = GetDataFolderDFR()
537 
538  if (!DataFolderExists("root:" + datasetname))
539  return -1
540  endif
541  setdatafolder root:
542  setdatafolder $datasetname
543  dfref datadf = GetDataFolderDFR()
544  wave /z data
545 
546  setdatafolder $package_path
547  svar s_preview_file
548  svar s_preview_source
549  wave preview_image
550  if (WaveExists(data))
551  s_preview_file = datasetname
552  s_preview_source = ""
553  extract_preview_image(data, preview_image)
554  show_preview_graph(preview_image)
555  else
556  preview_image = nan
557  s_preview_file = datasetname
558  setdatafolder datadf
560  show_preview_graph(preview_image)
561  endif
562 
563  // attributes
564  setdatafolder datadf
565  if (DataFolderExists("attr"))
566  setdatafolder attr
567  preview_attributes(GetDataFolderDFR())
568  else
569  preview_attributes(GetDataFolderDFR(), include_datawaves=0)
570  endif
571 
572  setdatafolder saveDF
573  return 0
574 end
575 
576 static function preview_datafolder()
577  // preview data in the current data folder
578  dfref saveDF = GetDataFolderDFR()
579 
580  setdatafolder $package_path
581  svar s_preview_file
582  svar s_preview_source
583  svar s_preview_pvs
584  wave preview_image
585 
586  setdatafolder saveDF
587 
588  // select a wave to display
589  // consider only double-precision waves, i.e. ignore text and other special waves
590  // filter by matching PV name to s_preview_pvs
591  string d_names = WaveList("*", ";", "DP:1")
592  variable nw = ItemsInList(d_names, ";")
593  variable npv = ItemsInList(s_preview_pvs, ";")
594  variable iw, ipv
595  string wname, wnote, pv_name, pv_match
596  for (iw = 0; iw < nw; iw += 1)
597  wname = StringFromList(iw, d_names, ";")
598  wnote = note($wname)
599  pv_name = StringByKey("PV", wnote, "=", "\r")
600  // find matching data wave by PV name
601  for (ipv = 0; ipv < npv; ipv += 1)
602  pv_match = StringFromList(ipv, s_preview_pvs)
603  if (StringMatch(pv_name, pv_match))
604  wave data = $wname
605  s_preview_source = pv_name
606  extract_preview_image(data, preview_image)
607  preview_setscale_x(data, preview_image)
608  npv = 0
609  nw = 0
610  endif
611  endfor
612  endfor
613 
614  setdatafolder saveDF
615 end
616 
617 static function preview_setscale_x(data, preview)
618  // sets the approximate x scale of OTF data.
619  // requires an Axis1 tag with name of x wave in the wave note.
620  // if any of these conditions is true, the function does not change the scaling:
621  // 1) Axis1 tag or referenced wave is missing.
622  // 2) preview wave is not set to point scaling.
623  // 3) x wave is not monotonic (90% of the steps in the same direction).
624  wave data
625  wave preview
626 
627  if ((DimOffset(preview, 0) == 0) && (DimDelta(preview, 0) == 1))
628  string xname = StringByKey("Axis1", note(data), "=", "\r")
629  wave /z xwave = $xname
630  if (WaveExists(xwave))
631  // check for monotonicity
632  variable monotonic = 0
633  duplicate /free xwave, xdiff
634  differentiate /p xwave /D=xdiff
635  duplicate /free xdiff, xflag
636  xflag = xdiff > 0
637  monotonic = sum(xflag) > numpnts(xwave) * 0.9
638  xflag = xdiff < 0
639  monotonic = monotonic || (sum(xflag) > numpnts(xwave) * 0.9)
640  if (monotonic)
641  setscale /i x xwave[0], xwave[numpnts(xwave)-1], waveunits(xwave, -1), preview
642  endif
643  endif
644  endif
645 end
646 
647 static function preview_attributes(attr_folder, [dest_folder, attr_filter, include_datawaves, include_infowaves])
648  // copies the first elements of attributes in the specified folder to the preview waves
649  // by default, all existing attributes are copied
650  // if a text wave attr_filter exists in the pear_explorer folder, only the attributes referenced therein are copied
651  // to set up a filter, duplicate the attr_names wave of a template dataset, and remove unwanted items
652  dfref attr_folder // data folder which contains the attribute waves
653  dfref dest_folder // destination folder. the output is written to the attr_names and attr_values waves
654  // default = package folder
655  wave /t attr_filter // list of attributes allowed in the output
656  // default = use attr_filter of package folder
657  variable include_datawaves // 1 (default) = include data waves (any numeric wave which has a PV=name note)
658  // 0 = don't include attributes from data waves
659  variable include_infowaves // 1 (default) = include attributes from info waves (IN, ID, IV, IU)
660  // 0 = don't include attributes from info waves
661 
662  dfref saveDF = GetDataFolderDFR()
663  setdatafolder $package_path
664 
665  if (ParamIsDefault(dest_folder))
666  dest_folder = GetDataFolderDFR() // package folder
667  endif
668  if (ParamIsDefault(attr_filter))
669  wave /t /z attr_filter
670  endif
671  if (ParamIsDefault(include_datawaves))
672  include_datawaves = 1
673  endif
674  if (ParamIsDefault(include_infowaves))
675  include_infowaves = 1
676  endif
677 
678  setdatafolder dest_folder
679  wave /t /z attr_names, attr_values
680  if (!WaveExists(attr_names) || !WaveExists(attr_values))
681  make /n=(1) /o /t attr_names, attr_values
682  endif
683  attr_names = ""
684  attr_values = ""
685 
686  setdatafolder attr_folder
687  wave /t /z IN
688  wave /t /z ID
689  wave /t /z IV
690  wave /t /z IU
691 
692  // compile list of attributes
693  variable nattr // destination attributes
694  variable iattr
695  variable ninfo // info wave elements
696  variable iinfo
697  variable nw // attribute waves
698  variable iw
699  string sw
700  string ss
701 
702  if (WaveExists(IN) && include_infowaves)
703  ninfo = numpnts(IN)
704  else
705  ninfo = 0
706  endif
707  if (include_datawaves)
708  string waves = WaveList("*", ";", "")
709  string exceptions = "ID;IN;IU;IV"
710  waves = RemoveFromList(exceptions, waves)
711  nw = ItemsInList(waves, ";")
712  else
713  nw = 0
714  endif
715 
716  if (WaveExists(attr_filter) && (numpnts(attr_filter) >= 1))
717  nattr = numpnts(attr_filter)
718  redimension /n=(nattr) attr_names
719  attr_names = attr_filter
720  else
721  if(ninfo > 0)
722  redimension /n=(ninfo) attr_names
723  attr_names = SelectString(strlen(ID[p]) >= 0, IN[p], ID[p]) // use ID unless empty
724  endif
725 
726  nattr = ninfo + nw
727  iattr = ninfo
728  redimension /n=(nattr) attr_names
729  for (iw = 0; iw < nw; iw +=1 )
730  sw = StringFromList(iw, waves, ";")
731  ss = StringByKey("PV", note($sw), "=", "\r")
732  FindValue /text=sw attr_names
733  if ((v_value < 0) && (strlen(ss) >= 0))
734  attr_names[iattr] = sw
735  iattr += 1
736  endif
737  endfor
738  nattr = iattr
739  endif
740  redimension /n=(nattr) attr_names, attr_values
741  sort attr_names, attr_names
742 
743  // look up attribute values
744  for (iattr = 0; iattr < nattr; iattr += 1)
745  sw = attr_names[iattr]
746  // try info waves
747  if (ninfo > 0)
748  FindValue /text=sw ID
749  if (v_value >= 0)
750  attr_values[iattr] = IV[v_value]
751  endif
752  FindValue /text=sw IN
753  if (v_value >= 0)
754  attr_values[iattr] = IV[v_value]
755  endif
756  endif
757 
758  // override from attribute wave if existent
759  if (nw > 0)
760  switch (WaveType($sw, 1))
761  case 1: // numeric
762  wave /z w = $sw
763  if (WaveExists(w) && (numpnts(w) >= 1))
764  sprintf ss, "%g", w[0]
765  attr_values[iattr] = ss
766  endif
767  break
768  case 2: // text
769  wave /t/z wt = $sw
770  if (WaveExists(wt) && (numpnts(wt) >= 1))
771  attr_values[iattr] = wt[0]
772  endif
773  break
774  endswitch
775  endif
776  endfor
777 
778  setdatafolder saveDF
779 end
780 
781 static function display_dataset(datasetname)
782  // displays the graph of a loaded dataset in its own window
783  string datasetname // name of a data folder under root
784 
785  dfref saveDF = GetDataFolderDFR()
786 
787  if (!DataFolderExists("root:" + datasetname))
788  return -1
789  endif
790  setdatafolder root:
791  setdatafolder $datasetname
792  dfref datadf = GetDataFolderDFR()
793  wave /z data
794  if (!WaveExists(data))
795  wave /z data = data1
796  endif
797 
798  if (WaveExists(data))
799  switch(WaveDims(data))
800  case 2:
801  ad_display_profiles(data)
802  break
803  case 3:
804  ad_display_slice(data)
805  ad_brick_slicer(data)
806  break
807  endswitch
808  endif
809 
810  setdatafolder saveDF
811  return 0
812 end
813 
815  dfref df = GetDataFolderDFR()
816  wave /t /sdfr=df attr_names
817  wave /t /sdfr=df attr_values
818  attributes_notebook(attr_names, attr_values, GetDataFolder(0))
819 end
820 
821 static function attributes_notebook(attr_names, attr_values, title)
822  wave /t attr_names
823  wave /t attr_values
824  string title
825 
826  dfref saveDF = GetDataFolderDFR()
827  setdatafolder $package_path
828  wave /t/z attr_filter, attr_filter_summary
829 
830  string name = PearlCleanupName("nb_" + title[0,27])
831  if (WinType(name) == 5)
832  Notebook $name selection={startOfFile, endOfFile}
833  Notebook $name text=""
834  else
835  NewNotebook /F=1 /K=1 /N=$name as title
836  GetWindow $name wsize
837  v_right = v_left + 260
838  v_bottom = v_top + 360
839  MoveWindow /W=$name v_left, v_top, v_right, v_bottom
840  Notebook $name tabs={2*72}
841  endif
842 
843  // summary
844  if (WaveExists(attr_filter_summary) && (numpnts(attr_filter_summary) >= 1))
845  notebook $name fStyle=1, text="Summary\r\r"
846  notebook $name fStyle=0
847  notebook_add_attributes(name, attr_filter_summary, attr_names, attr_values)
848  notebook $name text="\r"
849  endif
850 
851  // all attributes
852  notebook $name fStyle=1, text="All Attributes\r\r"
853  notebook $name fStyle=0
854  notebook_add_attributes(name, $"", attr_names, attr_values)
855  notebook $name selection={startOfFile,startOfFile}, findText={"",1}
856 
857  setdatafolder saveDF
858 end
859 
860 static function notebook_add_attributes(notebook_name, attr_filter, attr_names, attr_values)
861  string notebook_name
862  wave /t /z attr_filter
863  wave /t attr_names
864  wave /t attr_values
865 
866  variable nw = numpnts(attr_names)
867  variable iw
868  string sw
869  string ss
870 
871  variable do_filter = WaveExists(attr_filter)
872 
873  for (iw = 0; iw < nw; iw += 1)
874  if (do_filter)
875  sw = attr_names[iw]
876  FindValue /text=sw attr_filter
877  else
878  v_value = 0
879  endif
880  if (v_value >= 0)
881  sprintf ss, "%s\t%s\r", attr_names[iw], attr_values[iw]
882  notebook $notebook_name text=ss
883  endif
884  endfor
885 end
886 
887 static function /s show_preview_graph(data, [xdata])
888  // displays a preview of one- or two-dimensional data
889  wave data // data to be displayed. must either one-dimensional or two-dimensional
890  wave xdata // positions on x axis
891 
892  dfref saveDF = GetDataFolderDFR()
893  setdatafolder $package_path
894 
895  svar s_profiles_graph
896  svar s_preview_file
897  svar s_preview_source
898  svar s_preview_trace_graph
899 
900  if ((strlen(s_profiles_graph) > 0) && (WinType(s_profiles_graph) == 1))
901  KillWindow $s_profiles_graph
902  endif
903  if ((strlen(s_preview_trace_graph) > 0) && (WinType(s_preview_trace_graph) == 1))
904  KillWindow $s_preview_trace_graph
905  endif
906 
907  string graphname
908  if (wavedims(data) == 2)
909  s_profiles_graph = ad_display_profiles(data)
910  ModifyGraph /w=$s_profiles_graph /z wbRGB=(48640,56832,60160)
911  graphname = s_profiles_graph
912  elseif (wavedims(data) == 1)
913  duplicate /o data, preview_trace
914  if (!ParamIsDefault(xdata))
915  duplicate /o xdata, preview_trace_x
916  else
917  duplicate /o data, preview_trace_x
918  preview_trace_x = x
919  setscale d 0, 0, WaveUnits(data, 0), preview_trace_x
920  endif
921  s_preview_trace_graph = display_preview_trace(preview_trace_x, preview_trace)
922  ModifyGraph /w=$s_preview_trace_graph wbRGB=(48640,56832,60160)
923  graphname = s_preview_trace_graph
924  else
925  return ""
926  endif
927 
928  string title = "Preview " + s_preview_file
929  if (strlen(s_preview_source) > 0)
930  title = title + " (" + s_preview_source[0,31] + ")"
931  endif
932  dowindow /f/t $graphname, title
933 
934  setdatafolder saveDF
935  return graphname
936 end
937 
938 static function /s display_preview_trace(xtrace, ytrace)
939  wave xtrace
940  wave ytrace
941 
942  display /n=pearl_explorer_1d /k=1 ytrace vs xtrace as "Preview"
943  string graphname = s_name
944  ModifyGraph /w=$graphname rgb[0]=(0,0,0)
945  ModifyGraph /w=$graphname grid=2
946  ModifyGraph /w=$graphname mirror=1
947  ModifyGraph /w=$graphname minor=1
948  ModifyGraph /w=$graphname axThick=0.5
949  ModifyGraph /w=$graphname gridRGB=(52224,52224,52224)
950  ModifyGraph /w=$graphname gridHair=0
951  ModifyGraph /w=$graphname tick=0
952  ModifyGraph /w=$graphname btLen=4
953 
954  // axis labels
955  string labels = note(ytrace)
956  string lab
957  lab = StringByKey("AxisLabelX", labels, "=", "\r")
958  if (!strlen(lab))
959  lab = "X"
960  endif
961  Label /w=$graphname bottom lab + " (\\U)"
962  lab = StringByKey("AxisLabelD", labels, "=", "\r")
963  if (!strlen(lab))
964  lab = "value"
965  endif
966  Label /w=$graphname left lab + " (\\U)"
967 
968  return s_name
969 end
970 
971 static function load_selected_files([options])
972  string options
973 
974  dfref saveDF = GetDataFolderDFR()
975  setdatafolder $package_path
976 
977  wave wSelectedFiles
978  wave/t wtFiles
979  variable nn = numpnts(wSelectedFiles)
980  variable ii
981  for (ii = 0; ii < nn; ii += 1)
982  if (wSelectedFiles[ii])
983  if (ParamIsDefault(options))
984  load_file(wtFiles[ii])
985  else
986  load_file(wtFiles[ii], options=options)
987  endif
988  endif
989  endfor
990 
992  setdatafolder saveDF
993 end
994 
995 static function load_file(filename, [options])
996  string filename
997  string options
998 
999  dfref saveDF = GetDataFolderDFR()
1000 
1001  variable ft = pearl_file_type(filename)
1002  switch(ft)
1003  case 1:
1004  if (ParamIsDefault(options))
1005  load_pshell_file(filename)
1006  else
1007  load_pshell_file(filename, options=options)
1008  endif
1009  break
1010  case 2:
1011  if (ParamIsDefault(options))
1012  load_hdf_file(filename)
1013  else
1014  load_hdf_file(filename, options=options)
1015  endif
1016  break
1017  case 3:
1018  load_itx_file(filename)
1019  break
1020  case 4:
1021  load_mtrx_file(filename)
1022  break
1023  default:
1024  break
1025  endswitch
1026 
1027  setdatafolder saveDF
1028 end
1029 
1030 static function prompt_hdf_options(options)
1031  string &options
1032 
1033  string mode = StringByKey("mode", options, ":", ";")
1034  string reduction_func = StringByKey("reduction_func", options, ":", ";")
1035 
1036  string modes = "load_reduced"
1037  string reduction_functions = adh5_list_reduction_funcs()
1038 
1039  if (strlen(mode) == 0)
1040  mode = StringFromList(0, modes, ";")
1041  endif
1042  if (strlen(reduction_func) == 0)
1043  reduction_func = StringFromList(0, reduction_functions, ";")
1044  endif
1045 
1046  prompt mode, "Mode", popup, modes
1047  prompt reduction_func, "Reduction Function", popup, reduction_functions
1048  doprompt "HDF5 Loading Options", mode, reduction_func
1049 
1050  if (v_flag == 0)
1051  options = ReplaceStringByKey("mode", options, mode, ":", ";")
1052  options = ReplaceStringByKey("reduction_func", options, reduction_func, ":", ";")
1053  endif
1054  return v_flag // 0 = OK, 1 = cancel
1055 end
1056 
1069 function prompt_default_process(param)
1070  string &param
1071 
1072  return 0
1073 end
1074 
1075 function prompt_func_params(func_name, func_param)
1076  string func_name
1077  string &func_param
1078 
1079  string prompt_name = "prompt_" + func_name
1080  if (exists(prompt_name) == 6)
1081  funcref prompt_default_process prompt_func = $prompt_name
1082  return prompt_func(func_param)
1083  else
1084  // ignore missing prompt function
1085  return 0
1086  endif
1087 end
1088 
1089 static function /df load_pshell_file(filename, [options])
1090  string filename
1091  string options
1092 
1093  dfref saveDF = GetDataFolderDFR()
1094  string nickname = ad_suggest_foldername(filename)
1095  string loaded_filename = ""
1096 
1097  if (ParamIsDefault(options))
1098  loaded_filename = psh5_load_complete(nickname, "pearl_explorer_filepath", filename)
1099  else
1100  if (strlen(options) == 0)
1101  svar pref_options = $(package_path + "s_hdf_options")
1102  options = pref_options
1103  if (prompt_hdf_options(options) == 0)
1104  // OK
1105  pref_options = options
1106  else
1107  // cancel
1108  options = ""
1109  endif
1110  endif
1111 
1112  string mode = StringByKey("mode", options, ":", ";")
1113 
1114  strswitch(mode)
1115  case "load_reduced":
1116  string reduction_func = StringByKey("reduction_func", options, ":", ";")
1117  svar pref_params = $(package_path + "s_reduction_params")
1118  string reduction_params = pref_params
1119  if (prompt_func_params(reduction_func, reduction_params) == 0)
1120  pref_params = reduction_params
1121  print reduction_func, reduction_params
1122  psh5_load_reduced(nickname, "pearl_explorer_filepath", filename, $reduction_func, reduction_params)
1123  svar s_filepath
1124  loaded_filename = s_filepath
1125  endif
1126  break
1127  endswitch
1128  endif
1129 
1130  dfref dataDF
1131  if (strlen(loaded_filename) > 0)
1132  setdatafolder $("root:" + nickname)
1133  dataDF = GetDataFolderDFR()
1134  string /g pearl_explorer_import = "load_pshell_file"
1135  endif
1136 
1137  setdatafolder saveDF
1138  return dataDF
1139 end
1140 
1141 static function /df load_hdf_file(filename, [options])
1142  string filename
1143  string options
1144 
1145  dfref saveDF = GetDataFolderDFR()
1146  string nickname = ad_suggest_foldername(filename)
1147  string loaded_filename = ""
1148 
1149  if (ParamIsDefault(options))
1150  loaded_filename = adh5_load_complete(nickname, "pearl_explorer_filepath", filename)
1151  else
1152  if (strlen(options) == 0)
1153  svar pref_options = $(package_path + "s_hdf_options")
1154  options = pref_options
1155  if (prompt_hdf_options(options) == 0)
1156  // OK
1157  pref_options = options
1158  else
1159  // cancel
1160  options = ""
1161  endif
1162  endif
1163 
1164  string mode = StringByKey("mode", options, ":", ";")
1165 
1166  strswitch(mode)
1167  case "load_reduced":
1168  string reduction_func = StringByKey("reduction_func", options, ":", ";")
1169  svar pref_params = $(package_path + "s_reduction_params")
1170  string reduction_params = pref_params
1171  if (prompt_func_params(reduction_func, reduction_params) == 0)
1172  pref_params = reduction_params
1173  print reduction_func, reduction_params
1174  loaded_filename = adh5_load_reduced(nickname, "pearl_explorer_filepath", filename, $reduction_func, reduction_params)
1175  endif
1176  break
1177  endswitch
1178  endif
1179 
1180  dfref dataDF
1181  if (strlen(loaded_filename) > 0)
1182  setdatafolder $("root:" + nickname)
1183  dataDF = GetDataFolderDFR()
1184  string /g pearl_explorer_import = "load_hdf_file"
1185  endif
1186 
1187  setdatafolder saveDF
1188  return dataDF
1189 end
1190 
1191 static function /df load_itx_file(filename, [options])
1192  string filename
1193  string options
1194 
1195  dfref saveDF = GetDataFolderDFR()
1196  string nickname = itx_suggest_foldername(filename)
1197 
1198  if (ParamIsDefault(options))
1199  options = ""
1200  endif
1201 
1202  setdatafolder root:
1203  newdatafolder /s/o $("root:" + nickname)
1204  dfref dataDF = GetDataFolderDFR()
1205 
1206  // note: some versions of PEARL data files save data to a new data folder,
1207  // and leave the newly created folder as the current folder.
1208  // the free data folder is used by those files which don't create their own data folder.
1209  // this is the new recommended behaviour
1210 
1211  LoadWave /t/p=pearl_explorer_filepath/q filename
1212  svar waves = s_wavenames
1213  dfref actDF = GetDataFolderDFR()
1214  if (v_flag > 0)
1215  string /g pearl_explorer_import = "load_itx_file"
1216  endif
1217 
1218  if (!DataFolderRefsEqual(actDF, dataDF))
1219  // the file created its own data folder.
1220  // let's kill the pre-allocated folder
1221  setdatafolder dataDF
1222  if (ItemsInList(WaveList("*", ";", ""), ";") == 0)
1223  killdatafolder /z dataDF
1224  endif
1225  endif
1226 
1227  setdatafolder saveDF
1228  return actDF
1229 end
1230 
1234 static function /df load_mtrx_file(filename, [options])
1235  string filename
1236  string options
1237 
1238  dfref saveDF = GetDataFolderDFR()
1239  dfref dataDF = $""
1240 
1241 #if exists("MFR_OpenResultFile")
1242  setdatafolder root:
1243  string datasets = ""
1244  datasets = mtrx_load_file("pearl_explorer_filepath", filename)
1245  if (strlen(datasets) > 0)
1246  string /g pearl_explorer_import = "load_mtrx_file"
1247  string s1 = StringFromList(0, datasets)
1248  wave w1 = $s1
1249  dataDF = GetWavesDataFolderDFR(w1)
1250  endif
1251 #endif
1252 
1253  setdatafolder saveDF
1254  return dataDF
1255 end
1256 
1257 function /s itx_suggest_foldername(filename, [ignoredate,sourcename,unique])
1258  // suggests the name of a data folder based on a file name
1259  // if the file name follows the naming convention source-date-index.extension,
1260  // the function tries to generate the nick name as source_date_index.
1261  // otherwise it's just a cleaned up version of the file name.
1262  string filename // file name, including extension. can also include a folder path (which is ignored)
1263  // the extension is currently ignored, but may be used later to select the parent folder
1264  variable ignoredate // if non-zero, the nick name will not include the date part
1265  // defaults to zero
1266  string sourcename // nick name of the data source
1267  // the function tries to detect the source from the file name
1268  // this option can be used to override auto-detection
1269  // allowed values: sscan, otf
1270  variable unique // if non-zero, the resulting name is made a unique data folder name in the current data folder
1271  // defaults to zero
1272 
1273  if (ParamIsDefault(ignoredate))
1274  ignoredate = 0
1275  endif
1276  if (ParamIsDefault(unique))
1277  unique = 0
1278  endif
1279 
1280  string basename = ParseFilePath(3, filename, ":", 0, 0)
1281  string extension = ParseFilePath(4, filename, ":", 0, 0)
1282  string nickname
1283 
1284  string autosource
1285  if (strsearch(basename, "X03DA_PC", 0, 2) >= 0)
1286  autosource = "sscan"
1287  basename = ReplaceString("_", basename, "-")
1288  ignoredate = 1
1289  elseif (strsearch(basename, "otf", 0, 2) >= 0)
1290  autosource = "otf"
1291  endif
1292  if (ParamIsDefault(sourcename))
1293  sourcename = autosource
1294  endif
1295 
1296  variable nparts = ItemsInList(basename, "-")
1297  if (nparts >= 3)
1298  string datepart = StringFromList(nparts - 2, basename, "-")
1299  string indexpart = StringFromList(nparts - 1, basename, "-")
1300  if (ignoredate)
1301  sprintf nickname, "%s_%s", sourcename, indexpart
1302  else
1303  sprintf nickname, "%s_%s_%s", sourcename, datepart, indexpart
1304  endif
1305  else
1306  nickname = PearlCleanupName(basename)
1307  endif
1308 
1309  if (unique && CheckName(nickname, 11))
1310  nickname = UniqueName(nickname + "_", 11, 0)
1311  endif
1312 
1313  return nickname
1314 end
1315 
1316 Window PearlDataExplorer() : Panel
1317  PauseUpdate; Silent 1 // building window...
1318  NewPanel /K=1 /W=(800,0,1530,444) as "PEARL Data Explorer"
1319  ModifyPanel cbRGB=(48640,56832,60160)
1320 
1321  GroupBox gb_filepath,pos={8,4},size={224,52},title="file system folder"
1322  TitleBox tb_filepath,pos={20,24},size={174,20},frame=2
1323  TitleBox tb_filepath,variable=root:packages:pearl_explorer:s_filepath,fixedSize=1
1324  Button b_browse_filepath,pos={200,24},size={20,20},proc=PearlDataExplorer#bp_browse_filepath,title="..."
1325  Button b_browse_filepath,fColor=(65280,48896,32768)
1326 
1327  GroupBox gb_prefs,pos={240,4},size={58,52},title="prefs",help={"explorer package preferences"}
1328  Button b_save_prefs,pos={252,20},size={32,17},proc=PearlDataExplorer#bp_save_prefs,title="save"
1329  Button b_save_prefs,help={"save preferences of the data explorer package (data file path, attributes filter)"}
1330  Button b_save_prefs,fColor=(65280,48896,32768)
1331  Button b_load_prefs,pos={252,36},size={32,17},proc=PearlDataExplorer#bp_load_prefs,title="load"
1332  Button b_load_prefs,help={"load preferences of the data explorer package"}
1333  Button b_load_prefs,fColor=(65280,48896,32768)
1334 
1335  GroupBox gb_filelist,pos={8,64},size={224,372},title="data files"
1336  ListBox lb_files,pos={20,84},size={200,212},proc=PearlDataExplorer#lbp_filelist
1337  ListBox lb_files,listWave=root:packages:pearl_explorer:wtFiles
1338  ListBox lb_files,selWave=root:packages:pearl_explorer:wSelectedFiles,row= 11,mode= 4
1339  TitleBox tb_file_info,pos={20,300},size={198,78},frame=2,fixedSize=1
1340  TitleBox tb_file_info,variable= root:packages:pearl_explorer:s_file_info
1341 
1342  Button b_update_filelist,pos={20,386},size={60,20},proc=PearlDataExplorer#bp_update_filelist,title="update list"
1343  Button b_update_filelist,fColor=(65280,48896,32768)
1344  CheckBox cb_file_preview,pos={84,390},size={60,20},title="preview"
1345  CheckBox cb_file_preview,help={"enable/disable automatic preview window when selecting a data file"}
1346  CheckBox cb_file_preview,value=1
1347  Button b_file_prev,pos={176,386},size={20,20},proc=PearlDataExplorer#bp_file_prev,title="\\W646"
1348  Button b_file_prev,help={"previous file"}
1349  Button b_file_prev,fColor=(65280,48896,32768)
1350  Button b_file_next,pos={200,386},size={20,20},proc=PearlDataExplorer#bp_file_next,title="\\W649"
1351  Button b_file_next,help={"next file"}
1352  Button b_file_next,fColor=(65280,48896,32768)
1353 
1354  Button b_load_files,pos={20,410},size={76,20},proc=PearlDataExplorer#bp_load_files,title="load complete"
1355  Button b_load_files,help={"load the complete contents from the selected files"}
1356  Button b_load_files,fColor=(65280,48896,32768)
1357  Button b_load_files_opt,pos={100,410},size={76,20},proc=PearlDataExplorer#bp_load_files_opt,title="load reduced"
1358  Button b_load_files_opt,help={"load data from the selected files with options (reduced dimensions)"}
1359  Button b_load_files_opt,fColor=(65280,48896,32768)
1360 
1361  // datasets group
1362  GroupBox gb_datasets,pos={240,64},size={224,372},title="datasets"
1363  ListBox lb_datasets,pos={252,84},size={200,300},proc=PearlDataExplorer#lbp_datasets,help={"list of loaded datasets"}
1364  ListBox lb_datasets,listWave=root:packages:pearl_explorer:wtDatasets
1365  ListBox lb_datasets,selWave=root:packages:pearl_explorer:wSelectedDatasets,mode= 1
1366  ListBox lb_datasets,selRow= -1
1367 
1368  Button b_update_datasets,pos={252,386},size={60,20},proc=PearlDataExplorer#bp_update_datasets,title="update list"
1369  Button b_update_datasets,help={"update the list of datasets"}
1370  Button b_update_datasets,fColor=(65280,48896,32768)
1371  CheckBox cb_dataset_preview,pos={316,390},size={60,20},title="preview"
1372  CheckBox cb_dataset_preview,help={"enable/disable automatic preview window when selecting a dataset"}
1373  CheckBox cb_dataset_preview,value=0
1374  Button b_dataset_prev,pos={408,386},size={20,20},proc=PearlDataExplorer#bp_dataset_prev,title="\\W646"
1375  Button b_dataset_prev,help={"goto previous dataset"}
1376  Button b_dataset_prev,fColor=(65280,48896,32768)
1377  Button b_dataset_next,pos={432,386},size={20,20},proc=PearlDataExplorer#bp_dataset_next,title="\\W649"
1378  Button b_dataset_next,help={"goto next dataset"}
1379  Button b_dataset_next,fColor=(65280,48896,32768)
1380 
1381  Button b_dataset_folder,pos={252,410},size={50,20},proc=PearlDataExplorer#bp_dataset_folder,title="goto DF"
1382  Button b_dataset_folder,help={"set the current data folder of the selected dataset"}
1383  Button b_dataset_folder,fColor=(65280,48896,32768)
1384  Button b_dataset_display,pos={306,410},size={50,20},proc=PearlDataExplorer#bp_dataset_display,title="display"
1385  Button b_dataset_display,help={"display the selected dataset in its own window"}
1386  Button b_dataset_display,fColor=(65280,48896,32768)
1387 
1388  GroupBox gb_preview,pos={472,4},size={250,52},title="preview"
1389  TitleBox tb_preview_file,pos={484,24},size={226,20},frame=2
1390  TitleBox tb_preview_file,variable=root:packages:pearl_explorer:s_preview_file,fixedSize=1
1391 
1392  GroupBox gb_attributes,pos={472,64},size={250,372},title="attributes"
1393  Button b_attr_notebook,pos={484,386},size={60,20},proc=PearlDataExplorer#bp_attr_notebook,title="notebook"
1394  Button b_attr_notebook,help={"show attribute list in a notebook"}
1395  Button b_attr_notebook,fColor=(65280,48896,32768)
1396 
1397  String fldrSav0= GetDataFolder(1)
1398  SetDataFolder root:packages:pearl_explorer:
1399  Edit/W=(484,84,710,384)/HOST=# attr_names,attr_values
1400  ModifyTable format(Point)=1,width(Point)=0,width(attr_names)=103,width(attr_values)=103
1401  ModifyTable statsArea=85
1402  SetDataFolder fldrSav0
1403  RenameWindow #,T0
1404  SetActiveSubwindow ##
1405 EndMacro
1406 
1407 static function bp_load_prefs(ba) : ButtonControl
1408  STRUCT WMButtonAction &ba
1409 
1410  switch( ba.eventCode )
1411  case 2: // mouse up
1412  load_prefs()
1413  break
1414  case -1: // control being killed
1415  break
1416  endswitch
1417 
1418  return 0
1419 End
1420 
1421 static function bp_save_prefs(ba) : ButtonControl
1422  STRUCT WMButtonAction &ba
1423 
1424  switch( ba.eventCode )
1425  case 2: // mouse up
1426  save_prefs()
1427  break
1428  case -1: // control being killed
1429  break
1430  endswitch
1431 
1432  return 0
1433 End
1434 
1435 static function bp_browse_filepath(ba) : ButtonControl
1436  STRUCT WMButtonAction &ba
1437 
1438  dfref saveDF = GetDataFolderDFR()
1439 
1440  switch( ba.eventCode )
1441  case 2: // mouse up
1442  PathInfo /S pearl_explorer_filepath
1443  NewPath /M="select data file folder" /O/Z pearl_explorer_filepath
1444  if (v_flag == 0)
1445  PathInfo /S pearl_explorer_filepath
1446  svar filepath = $(package_path + "s_filepath")
1447  filepath = s_path
1448  update_filelist()
1449  endif
1450  break
1451  case -1: // control being killed
1452  break
1453  endswitch
1454 
1455  setdatafolder saveDF
1456  return 0
1457 End
1458 
1459 static function bp_update_filelist(ba) : ButtonControl
1460  STRUCT WMButtonAction &ba
1461 
1462  switch( ba.eventCode )
1463  case 2: // mouse up
1464  update_filelist()
1465  break
1466  case -1: // control being killed
1467  break
1468  endswitch
1469 
1470  return 0
1471 End
1472 
1473 static function bp_load_files(ba) : ButtonControl
1474  STRUCT WMButtonAction &ba
1475 
1476  switch( ba.eventCode )
1477  case 2: // mouse up
1479  break
1480  case -1: // control being killed
1481  break
1482  endswitch
1483 
1484  return 0
1485 End
1486 
1487 static function bp_load_files_opt(ba) : ButtonControl
1488  STRUCT WMButtonAction &ba
1489 
1490  switch( ba.eventCode )
1491  case 2: // mouse up
1492  load_selected_files(options="")
1493  break
1494  case -1: // control being killed
1495  break
1496  endswitch
1497 
1498  return 0
1499 End
1500 
1501 static function bp_file_next(ba) : ButtonControl
1502  STRUCT WMButtonAction &ba
1503 
1504  dfref saveDF = GetDataFolderDFR()
1505 
1506  switch( ba.eventCode )
1507  case 2: // mouse up
1508  setdatafolder $package_path
1509  wave /t wtFiles
1510  wave wSelectedFiles
1511  FindValue /i=1 wSelectedFiles
1512  v_value += 1
1513  if (v_value >= numpnts(wtFiles))
1514  v_value = min(numpnts(wtFiles) - 1, 0)
1515  endif
1516  wSelectedFiles = p == v_value
1517  if (v_value >= 0)
1518  variable ifile = v_value
1519  ControlInfo /W=PearlDataExplorer cb_file_preview
1520  if (v_value)
1521  preview_file(wtFiles[ifile])
1522  endif
1523  endif
1524  break
1525  case -1: // control being killed
1526  break
1527  endswitch
1528 
1529  setdatafolder saveDF
1530  return 0
1531 End
1532 
1533 static function bp_file_prev(ba) : ButtonControl
1534  STRUCT WMButtonAction &ba
1535 
1536  dfref saveDF = GetDataFolderDFR()
1537 
1538  switch( ba.eventCode )
1539  case 2: // mouse up
1540  setdatafolder $package_path
1541  wave /t wtFiles
1542  wave wSelectedFiles
1543  FindValue /i=1 wSelectedFiles
1544  v_value -= 1
1545  if (v_value < 0)
1546  v_value = numpnts(wtFiles) - 1
1547  endif
1548  wSelectedFiles = p == v_value
1549  if (v_value >= 0)
1550  variable ifile = v_value
1551  ControlInfo /W=PearlDataExplorer cb_file_preview
1552  if (v_value)
1553  preview_file(wtFiles[ifile])
1554  endif
1555  endif
1556  break
1557  case -1: // control being killed
1558  break
1559  endswitch
1560 
1561  setdatafolder saveDF
1562  return 0
1563 End
1564 
1565 static function lbp_filelist(lba) : ListBoxControl
1566  STRUCT WMListboxAction &lba
1567 
1568  Variable row = lba.row
1569  Variable col = lba.col
1570  WAVE/T/Z listWave = lba.listWave
1571  WAVE/Z selWave = lba.selWave
1572 
1573  switch( lba.eventCode )
1574  case -1: // control being killed
1575  break
1576  case 1: // mouse down
1577  if (selWave[row])
1578  ControlInfo /W=PearlDataExplorer cb_file_preview
1579  if (v_value)
1580  preview_file(listWave[row])
1581  endif
1582  endif
1583  break
1584  case 3: // double click
1585  break
1586  case 4: // cell selection
1587  case 5: // cell selection plus shift key
1588  break
1589  case 6: // begin edit
1590  break
1591  case 7: // finish edit
1592  break
1593  case 13: // checkbox clicked (Igor 6.2 or later)
1594  break
1595  endswitch
1596 
1597  return 0
1598 End
1599 
1600 static function bp_update_datasets(ba) : ButtonControl
1601  STRUCT WMButtonAction &ba
1602 
1603  switch( ba.eventCode )
1604  case 2: // mouse up
1605  update_datasets()
1606  break
1607  case -1: // control being killed
1608  break
1609  endswitch
1610 
1611  return 0
1612 End
1613 
1614 static function bp_dataset_folder(ba) : ButtonControl
1615  STRUCT WMButtonAction &ba
1616 
1617  switch( ba.eventCode )
1618  case 2: // mouse up
1619  ControlInfo /W=PearlDataExplorer lb_datasets
1620  if (v_value >= 0)
1621  setdatafolder $package_path
1622  wave /t wtDatasets
1623  string dataset = wtDatasets[v_value]
1624  string cmd
1625  sprintf cmd, "setdatafolder root:%s", PossiblyQuoteName(dataset)
1626  execute /q /z cmd
1627  cmd = "setdatafolder :scan1"
1628  execute /q /z cmd
1629  sprintf cmd, "setdatafolder %s", GetDataFolder(1)
1630  print cmd
1631  endif
1632  break
1633  case -1: // control being killed
1634  break
1635  endswitch
1636 
1637  return 0
1638 End
1639 
1640 static function bp_dataset_display(ba) : ButtonControl
1641  STRUCT WMButtonAction &ba
1642 
1643  switch( ba.eventCode )
1644  case 2: // mouse up
1645  ControlInfo /W=PearlDataExplorer lb_datasets
1646  if (v_value >= 0)
1647  setdatafolder $package_path
1648  wave /t wtDatasets
1649  string dataset = wtDatasets[v_value]
1650  display_dataset(dataset)
1651  endif
1652  break
1653  case -1: // control being killed
1654  break
1655  endswitch
1656 
1657  return 0
1658 End
1659 
1660 static function bp_dataset_next(ba) : ButtonControl
1661  STRUCT WMButtonAction &ba
1662 
1663  switch( ba.eventCode )
1664  case 2: // mouse up
1665  ControlInfo /W=PearlDataExplorer lb_datasets
1666  wave /t wtDatasets = $(s_datafolder + s_value)
1667  v_value += 1
1668  if (v_value >= numpnts(wtDatasets))
1669  v_value = min(0, numpnts(wtDatasets) - 1)
1670  endif
1671  ListBox lb_datasets win=PearlDataExplorer, selRow=v_value
1672  if (v_value >= 0)
1673  variable ids = v_value
1674  ControlInfo /W=PearlDataExplorer cb_dataset_preview
1675  if (v_value)
1676  preview_dataset(wtDatasets[ids])
1677  endif
1678  endif
1679  break
1680  case -1: // control being killed
1681  break
1682  endswitch
1683 
1684  return 0
1685 End
1686 
1687 static function bp_dataset_prev(ba) : ButtonControl
1688  STRUCT WMButtonAction &ba
1689 
1690  switch( ba.eventCode )
1691  case 2: // mouse up
1692  ControlInfo /W=PearlDataExplorer lb_datasets
1693  wave /t wtDatasets = $(s_datafolder + s_value)
1694  v_value -= 1
1695  if (v_value < 0)
1696  v_value = max(-1, numpnts(wtDatasets) - 1)
1697  endif
1698  ListBox lb_datasets win=PearlDataExplorer, selRow=v_value
1699  if (v_value >= 0)
1700  variable ids = v_value
1701  ControlInfo /W=PearlDataExplorer cb_dataset_preview
1702  if (v_value)
1703  preview_dataset(wtDatasets[ids])
1704  endif
1705  endif
1706  break
1707  case -1: // control being killed
1708  break
1709  endswitch
1710 
1711  return 0
1712 End
1713 
1714 static function lbp_datasets(lba) : ListBoxControl
1715  STRUCT WMListboxAction &lba
1716 
1717  Variable row = lba.row
1718  Variable col = lba.col
1719  WAVE/T/Z listWave = lba.listWave
1720  WAVE/Z selWave = lba.selWave
1721 
1722  switch( lba.eventCode )
1723  case -1: // control being killed
1724  break
1725  case 1: // mouse down
1726  if (row >= 0)
1727  ControlInfo /W=PearlDataExplorer cb_dataset_preview
1728  if (v_value)
1729  preview_dataset(listWave[row])
1730  endif
1731  endif
1732  break
1733  case 3: // double click
1734  break
1735  case 4: // cell selection
1736  case 5: // cell selection plus shift key
1737  break
1738  case 6: // begin edit
1739  break
1740  case 7: // finish edit
1741  break
1742  case 13: // checkbox clicked (Igor 6.2 or later)
1743  break
1744  endswitch
1745 
1746  return 0
1747 End
1748 
1749 static function bp_attr_notebook(ba) : ButtonControl
1750  STRUCT WMButtonAction &ba
1751 
1752  dfref saveDF = GetDataFolderDFR()
1753 
1754  switch( ba.eventCode )
1755  case 2: // mouse up
1756  setdatafolder $package_path
1757  svar s_preview_file
1758  wave /t /z attr_names
1759  wave /t /z attr_values
1760  if (WaveExists(attr_names))
1761  attributes_notebook(attr_names, attr_values, s_preview_file)
1762  endif
1763  break
1764  case -1: // control being killed
1765  break
1766  endswitch
1767 
1768  setdatafolder saveDF
1769  return 0
1770 End
static dfr load_mtrx_file(string filename, string options=defaultValue)
load a matrix (STM) data file
static const string package_path
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.
static variable update_datasets()
string psh5_load_reduced(string ANickName, string APathName, string AFileName, funcref reduction_func, string reduction_param, variable progress=defaultValue, variable nthreads=defaultValue)
load and reduce the ScientaImage dataset of the first scan of a PShell data file. ...
static variable bp_browse_filepath(WMButtonAction *ba)
static variable preview_file(string filename)
variable prompt_default_process(string *param)
prototype for prompting for processing function parameters.
string adh5_load_info(string APathName, string AFileName)
load descriptive info from a HDF5 file created by the Area Detector software.
static variable bp_dataset_prev(WMButtonAction *ba)
static string display_preview_trace(wave xtrace, wave ytrace)
static variable bp_file_prev(WMButtonAction *ba)
variable ad_brick_slicer(wave data)
open a slicer panel for 3D data.
interface for writing ELOG entries with Igor graphs as attachment.
static variable lbp_datasets(WMListboxAction *lba)
static variable bp_load_files_opt(WMButtonAction *ba)
static variable load_selected_files(string options=defaultValue)
string PearlCleanupName(string name)
static variable bp_load_files(WMButtonAction *ba)
static variable preview_datafolder()
static variable bp_file_next(WMButtonAction *ba)
static variable lbp_filelist(WMListboxAction *lba)
static variable prompt_hdf_options(string *options)
static variable bp_update_datasets(WMButtonAction *ba)
static const string ks_filematch_pshell
static const string ks_filematch_adh5
static wave preview_mtrx_file(string filename)
load the preview of a Matrix STM file.
static variable init_package()
initialize the global variables of the data explorer.
static wave preview_pshell_file(string filename)
load the preview of a PShell HDF5 file.
static variable bp_dataset_folder(WMButtonAction *ba)
static variable preview_dataset(string datasetname)
static const string package_name
static variable update_filelist()
read a list of PEARL files from the file system
static dfr load_itx_file(string filename, string options=defaultValue)
string psh5_load_preview(string APathName, string AFileName, variable load_data=defaultValue, variable load_attr=defaultValue, string pref_scans=defaultValue, string pref_datasets=defaultValue)
load a preview image from a PShell data file.
static variable bp_attr_notebook(WMButtonAction *ba)
static variable load_file(string filename, string options=defaultValue)
preview and import panel for PEARL data
static variable bp_load_prefs(WMButtonAction *ba)
static variable preview_setscale_x(wave data, wave preview)
static variable bp_save_prefs(WMButtonAction *ba)
static dfr load_hdf_file(string filename, string options=defaultValue)
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.
static wave preview_hdf_file(string filename)
load the preview of a PEARL HDF5 file.
static variable pearl_file_type(string filename)
check whether a file can be imported by this module.
static variable bp_dataset_display(WMButtonAction *ba)
static const string ks_filematch_itx
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.
static variable bp_dataset_next(WMButtonAction *ba)
static variable extract_preview_image(wave data, wave preview)
string psh5_load_info(string APathName, string AFileName)
load descriptive info from a PShell data file.
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. ...
string ad_display_profiles(wave image, string filter=defaultValue)
open a new profiles graph window.
static variable bp_update_filelist(WMButtonAction *ba)
variable pearl_data_explorer()
string itx_suggest_foldername(string filename, variable ignoredate=defaultValue, string sourcename=defaultValue, variable unique=defaultValue)
string psh5_load_complete(string ANickName, string APathName, string AFileName, variable load_data=defaultValue, variable load_attr=defaultValue)
load everything from a PShell data file.
static variable load_prefs()
variable prompt_func_params(string func_name, string *func_param)
static wave preview_itx_file(string filename)
load the preview of a general ITX file.
static variable display_dataset(string datasetname)
static dfr load_pshell_file(string filename, string options=defaultValue)
static variable save_prefs()
variable test_attributes_notebook()
static string show_preview_graph(wave data, wave xdata=defaultValue)
string mtrx_load_preview(string destName, string pathName, string fileName, string traces=defaultValue)
load a preview image from a Matrix data file.
string ad_display_slice(wave data)
display three-dimensional data by 2D slice.
static const string ks_filematch_mtrx
static variable attributes_notebook(wave attr_names, wave attr_values, string title)
string mtrx_load_file(string pathName, string fileName, string traces=defaultValue)
load all data from a Matrix data file.
static variable preview_attributes(dfref attr_folder, dfref dest_folder=defaultValue, wave attr_filter=defaultValue, variable include_datawaves=defaultValue, variable include_infowaves=defaultValue)
string adh5_list_reduction_funcs()
get a list of functions which can be used as reduction functions.
static variable notebook_add_attributes(string notebook_name, wave attr_filter, wave attr_names, wave attr_values)
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