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