PEARL Procedures  rev-distro-1.4.0-0-g80a01f2
Igor procedures for the analysis of PEARL data
pearl-elog.ipf
Go to the documentation of this file.
1 #pragma rtGlobals=3// Use modern global access method and strict wave access.
2 #pragma version = 1.40
3 #pragma IgorVersion = 6.2
4 #pragma ModuleName = PearlElog
5 
6 // author: matthias.muntwiler@psi.ch
7 // Copyright (c) 2013-16 Paul Scherrer Institut
8 
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 // http://www.apache.org/licenses/LICENSE-2.0
13 
79 
84 
85 static const string package_name = "pearl_elog";
86 static const string package_path = "root:packages:pearl_elog:";
87 
97 variable pearl_elog(string logbook){
98  string logbook
99 
100  if (init_package() == 0)
101  load_prefs()
102  string templates = list_logbooks(templates=1)
103  if (ItemsInList(templates) < 1)
105  endif
106  endif
107 
108  if (strlen(logbook) == 0)
109  logbook = elog_prompt_logbook()
110  endif
111 
112  string win_name = logbook + "ElogPanel"
113  if (strlen(logbook) > 0)
114  if (strlen(WinList(win_name, ";", "")) > 0)
115  DoWindow /F $win_name
116  else
117  win_name = PearlElogPanel(logbook)
118  STRUCT WMWinHookStruct s
119  s.eventCode = 0
120  s.winName = win_name
121  elog_panel_hook(s)
122  endif
123  endif
124 };
125 
127 static variable IgorBeforeNewHook(string igorApplicationNameStr){
128  string igorApplicationNameStr
129  save_prefs()
131  return 0
132 };
133 
135 static variable IgorQuitHook(string igorApplicationNameStr){
136  string igorApplicationNameStr
137  save_prefs()
139  return 0
140 };
141 
143 static variable AfterFileOpenHook(variable refNum, string file, string pathName, string type, string creator, variable kind){
144  Variable refNum,kind
145  String file,pathName,type,creator
146  if( (kind >= 1) && (kind <= 2))
147  init_package(clean=1)
148  load_prefs()
149  endif
150  return 0
151 };
152 
153 static const variable kdfRoot = 0;
154 static const variable kdfVolatile = 1;
155 static const variable kdfPersistent = 2;
156 static const variable kdfTemplates = 3;
157 
170 static dfr get_elog_df(string name, variable category){
171  string name
172  variable category
173 
174  dfref df_package = $package_path
175  dfref df_persistent = df_package:persistent
176  dfref df_volatile = df_package:volatile
177 
178  switch(category)
179  case kdfRoot:
180  dfref df_parent = df_package
181  break
182  case kdfPersistent:
183  dfref df_parent = df_persistent
184  break
185  case kdfTemplates:
186  dfref df_parent = df_persistent:templates
187  break
188  case kdfVolatile:
189  dfref df_parent = df_volatile
190  break
191  default:
192  Abort "get_elog_df: undefined data folder category."
193  endswitch
194 
195  if ((strlen(name) > 0) && (category >= 1))
196  if (category == kdfTemplates)
197  dfref df_logbooks = df_parent
198  else
199  dfref df_logbooks = df_parent:logbooks
200  endif
201  dfref df_logbook = df_logbooks:$name
202  return df_logbook
203  else
204  return df_parent
205  endif
206 };
207 
217 static variable init_package(variable clean = defaultValue){
218  variable clean
219 
220  if (ParamIsDefault(clean))
221  clean = 0
222  endif
223 
224  dfref savedf = getdatafolderdfr()
225  dfref df_root = get_elog_df("", kdfRoot)
226  if ((clean == 0) && (DataFolderRefStatus(df_root) == 1))
227  return 1
228  endif
229 
230  setdatafolder root:
231  newdatafolder /o/s packages
232  newdatafolder /o/s $package_name
233  dfref df_package_root = getdatafolderdfr()
234  newdatafolder /o/s volatile
235  dfref df_volatile = getdatafolderdfr()
236  newdatafolder /o logbooks
237  setdatafolder df_package_root
238  newdatafolder /o/s persistent
239  dfref df_persistent = getdatafolderdfr()
240  newdatafolder /o logbooks
241  newdatafolder /o templates
242 
243  // common configuration
244  setdatafolder df_persistent
245  string /g elog_path = "c:\\program files (x86)\\ELOG\\elog.exe"
246  string /g hostname = "localhost"
247  variable /g port = 0// 0 = unspecified (default)
248  variable /g ssl = 0// 0 = plain text (incl. passwords), 1 = secure connection
249  string /g subdir = ""
250  variable /g loglevel = 3
251 
252  setdatafolder savedf
253  return 0
254 };
255 
263  dfref savedf = getdatafolderdfr()
264 
265  dfref df_root = get_elog_df("", kdfRoot)
266  dfref df_persistent = get_elog_df("", kdfPersistent)
267  dfref df_templates = get_elog_df("", kdfTemplates)
268 
269  // Experiments template
270  setdatafolder df_templates
271  newdatafolder /o/s Experiments
272 
273  // attributes (persistent)
274  // available attributes
275  string /g attributes = "author;project;sample;source;task;technique;file;valid;"
276  // controls corresponding to attributes
277  // prefix determines the control type: sv_ = setvariable (string), pm_ = popup menu, cb = check box
278  string /g controls = "sv_author;sv_project;sv_sample;pm_source;pm_task;pm_technique;sv_file;cb_valid;"
279  // attributes with fixed options, value item declares the options string
280  string /g options = "source=sources;task=tasks;technique=techniques"
281  // attributes which must be defined
282  string /g required_attributes = "author;project;sample;source;task;technique;valid"
283 
284  // option lists
285  string /g sources = "Manual Entry;PShell;Scienta Data;SScan Data;Prosilica Data;OTF Data;Beamline Status;LEED Data;QMS Data;Matrix Data;Igor Pro;Other"
286  string /g tasks = "Measurement;Optimization;Analysis;Sample Preparation;Sample Storage;Comment;Development;Maintenance;Test;Other"
287  string /g techniques = "XPS;UPS;XPD;XAS;XMCD;PhD;ARUPS;STM;STS;LEED;AES;QMS;MBE;Sputter/Anneal;Test;Other"
288 
289  // Calculations template
290  setdatafolder df_templates
291  newdatafolder /o/s Calculations
292 
293  // attributes (persistent)
294  // available attributes
295  string /g attributes = "author;project;sample;program;revision;machine;job;experiment;source path;result path;valid"
296  // controls corresponding to attributes
297  // prefix determines the control type: sv_ = setvariable (string), pm_ = popup menu, cb = check box
298  string /g controls = "sv_author;sv_project;sv_sample;pm_program;sv_revision;pm_machine;sv_job;sv_experiment;sv_sourcepath;sv_resultpath;cb_valid"
299  // attributes with fixed options, value item declares the options string
300  string /g options = "program=programs;machine=machines"
301  // attributes which must be defined
302  string /g required_attributes = "author;project;sample"
303 
304  // option lists
305  string /g programs = "PMSCO;EDAC;MSC;SSC;MUFPOT;DMSUP;Other"
306  string /g machines = "PC;VM;Ra;Merlin;llcx;Other"
307 
308  // System template
309  setdatafolder df_templates
310  newdatafolder /o/s System
311 
312  // attributes (persistent)
313  // available attributes
314  string /g attributes = "author;type;system;source;file"
315  // controls corresponding to attributes
316  // prefix determines the control type: sv_ = setvariable (string), pm_ = popup menu, cb = check box
317  string /g controls = "sv_author;pm_type;pm_system;pm_source;sv_file"
318  // attributes with fixed options, value item declares the options string
319  string /g options = "type=types;system=systems;source=sources"
320  // attributes which must be defined
321  string /g required_attributes = "author;type;system"
322 
323  // option lists
324  string /g types = "Installation;Repair;Maintenance;Test;Commissioning;Bakeout;Incident;Cool-down;Warm-up;Storage;Other"
325  string /g systems = "Vacuum;Control System;BL;XA;XP;SA;SP;T;LL;Monochromator;Carving;Scienta;STM;PC-Scienta;PC-Matrix;PC-Console;PC-Console-Win;PC-XP;EPS;LAC;Desiccator"
326  string /g sources = "Manual Entry;PShell;Scienta Data;SScan Data;Prosilica Data;OTF Data;Beamline Status;LEED Data;QMS Data;Matrix Data;Igor Pro;Other"
327 
328  setdatafolder savedf
329  return 0
330 };
331 
340 static variable init_volatile_vars(){
341  dfref savedf = GetDataFolderDFR()
342 
343  dfref df_volatile_root = get_elog_df("", kdfVolatile)
344  dfref df_volatile_parent = df_volatile_root:logbooks
345 
346  string logbooks = list_logbooks()
347  string logbook
348  variable nlb = ItemsInList(logbooks)
349  variable ilb
350 
351  SetDataFolder df_volatile_root
352  if (exists("temp_graph_files") != 2)
353  string /g temp_graph_files = ""
354  endif
355 
356  for (ilb = 0; ilb < nlb; ilb += 1)
357  logbook = StringFromList(ilb, logbooks)
358 
359  SetDataFolder df_volatile_parent
360  if (DataFolderExists(logbook))
361  SetDataFolder $logbook
362  else
363  NewDataFolder /o/s $logbook
364  endif
365 
366  if (exists("username") != 2)
367  string /g username = ""
368  endif
369  if (exists("password") != 2)
370  string /g password = ""
371  endif
372  if (exists("msg_id") != 2)
373  variable /g msg_id = 0
374  endif
375  if (exists("att_list") != 1)
376  make /n=(0,3) /t /o attach_list
377  make /n=(0,3) /i /o attach_sel
378  endif
379  if (exists("url") != 2)
380  string /g url = ""
381  endif
382  endfor
383 
384  SetDataFolder savedf
385  return 0
386 };
387 
401 
414 variable elog_create_logbook(string name, string template = defaultValue){
415  string name
416  string template
417 
418  if (ParamIsDefault(template))
419  template = ""
420  endif
421 
422  dfref savedf = getdatafolderdfr()
423  dfref df_root = get_elog_df("", kdfRoot)
424  dfref df_persistent_root = get_elog_df("", kdfPersistent)
425  dfref df_persistent_parent = df_persistent_root:logbooks
426  dfref df_volatile_root = get_elog_df("", kdfVolatile)
427  dfref df_volatile_parent = df_volatile_root:logbooks
428 
429  setdatafolder df_persistent_parent
430  if (CheckName(name, 11) != 0)
431  setdatafolder savedf
432  Abort "invalid logbook name"
433  return -1
434  endif
435 
436  if (strlen(template) > 0)
437  dfref df_template = get_elog_df(template, kdfTemplates)
438  dfref df_existing = get_elog_df(name, kdfPersistent)
439  if (DataFolderRefStatus(df_existing))
440  KillDataFolder /Z df_existing
441  endif
442  DuplicateDataFolder df_template, df_persistent_parent:$name
443  else
444  NewDataFolder /o/s df_persistent_parent:$name
445 
446  // ELOG logbook name
447  string /g logbook = name
448  // attributes (persistent)
449  // available attributes
450  string /g attributes = ""
451  // controls corresponding to attributes
452  // prefix determines the control type: sv_ = setvariable (string), pm_ = popup menu, cb = check box
453  string /g controls = ""
454  // attributes with fixed options, value item declares the options string
455  string /g options = ""
456  // attributes which must be defined
457  string /g required_attributes = ""
458  endif
459 
460  // usage data (persistent)
461  setdatafolder get_elog_df(name, kdfPersistent)
462  string /g recent = ""
463  string /g recent_message = ""
464 
466 
467  setdatafolder savedf
468  return 0
469 };
470 
473 variable elog_config(string elog_path = defaultValue, string hostname = defaultValue, variable port = defaultValue, string subdir = defaultValue){
474  string elog_path
475  string hostname
476  variable port
477  string subdir
478 
479  dfref df = get_elog_df("", kdfPersistent)
480 
481  if (!ParamIsDefault(elog_path))
482  svar /sdfr=df g_elog_path = elog_path
483  g_elog_path = elog_path
484  endif
485  if (!ParamIsDefault(hostname))
486  svar /sdfr=df g_hostname = hostname
487  g_hostname = hostname
488  endif
489  if (!ParamIsDefault(port))
490  nvar /sdfr=df g_port = port
491  g_port = port
492  endif
493  if (!ParamIsDefault(subdir))
494  svar /sdfr=df g_subdir = subdir
495  g_subdir = subdir
496  endif
497 };
498 
513 variable elog_login(string logbook, string username, string password){
514  string logbook
515  string username
516  string password
517 
518  dfref df = get_elog_df(logbook, kdfVolatile)
519  svar /sdfr=df g_username=username
520  svar /sdfr=df g_password=password
521  g_username = username
522  g_password = password
523 };
524 
533 variable elog_logout(string logbook){
534  string logbook
535 
536  dfref df = get_elog_df(logbook, kdfVolatile)
537  if (strlen(logbook) > 0)
538  svar /z /sdfr=df g_username=username
539  svar /z /sdfr=df g_password=password
540  if (svar_exists(g_username))
541  g_username = ""
542  endif
543  if (svar_exists(g_password))
544  g_password = ""
545  endif
546  else
547  dfref df2 = df:logbooks
548  variable nlb = CountObjectsDFR(df2, 4)
549  variable ilb
550  string slb
551  for (ilb = 0; ilb < nlb; ilb += 1)
552  slb = GetIndexedObjNameDFR(df2, 4, ilb)
553  if (strlen(slb) > 0)
554  elog_logout(slb)
555  endif
556  endfor
557  endif
558 };
559 
564 static variable save_prefs(){
565  dfref saveDF = GetDataFolderDFR()
566 
567  dfref df = get_elog_df("", kdfPersistent)
568  if (DataFolderRefStatus(df) == 1)
569  string fullPath = SpecialDirPath("Packages", 0, 0, 0)
570  fullPath += package_name
571  NewPath/O/C/Q tempPackagePrefsPath, fullPath
572  fullPath += ":preferences.pxp"
573  SetDataFolder df
574  SaveData /O /Q /R fullPath
575  KillPath/Z tempPackagePrefsPath
576  endif
577 
578  SetDataFolder saveDF
579 };
580 
584 static variable load_prefs(){
585  dfref saveDF = GetDataFolderDFR()
586 
587  variable result = -1
588  init_package()
589  setdatafolder get_elog_df("", kdfPersistent)
590 
591  string fullPath = SpecialDirPath("Packages", 0, 0, 0)
592  fullPath += package_name
593 
594  GetFileFolderInfo /Q /Z fullPath
595  if (V_Flag == 0)// Disk directory exists?
596  fullPath += ":preferences.pxp"
597  GetFileFolderInfo /Q /Z fullPath
598  if (V_Flag == 0)// Preference file exist?
599  LoadData /O /R /Q fullPath
601  result = 0
602  endif
603  endif
604 
605  SetDataFolder saveDF
606  return result
607 };
608 
618 static string list_logbooks(variable templates = defaultValue){
619  variable templates
620 
621  if (ParamIsDefault(templates))
622  templates = 0
623  endif
624 
625  dfref df_persistent = get_elog_df("", kdfPersistent)
626  if (templates)
627  dfref df_logbooks = df_persistent:templates
628  else
629  dfref df_logbooks = df_persistent:logbooks
630  endif
631  string logbooks = ""
632 
633  variable nlb = CountObjectsDFR(df_logbooks, 4)
634  variable ilb
635  string slb
636  for (ilb = 0; ilb < nlb; ilb += 1)
637  slb = GetIndexedObjNameDFR(df_logbooks, 4, ilb)
638  if (strlen(slb) > 0)
639  logbooks = AddListItem(slb, logbooks)
640  endif
641  endfor
642 
643  return SortList(logbooks, ";", 16)
644 };
645 
653 variable elog_validate_attributes(string logbook, string attributes){
654 
655  string logbook// name of the logbook (as in igor folder name)
656  string attributes// key=value list of attributes, semicolon separated
657 
658  variable result = 0
659  return result
660 };
661 
685 variable elog_create_entry(string logbook, string attributes, string message, variable encoding = defaultValue, string graphs = defaultValue, variable replyto = defaultValue){
686  string logbook
687  string attributes
688  string message
689  variable encoding
690  string graphs
691  variable replyto
692 
693  if (ParamIsDefault(encoding))
694  encoding = 1
695  endif
696  if (ParamIsDefault(graphs))
697  graphs = ""
698  endif
699  if (ParamIsDefault(replyto))
700  replyto = 0
701  endif
702 
703  dfref savedf = getdatafolderdfr()
704  dfref df_general = get_elog_df("", kdfPersistent)
705  dfref df_volatile = get_elog_df(logbook, kdfVolatile)
706 
707  variable result = 0
708  nvar /sdfr=df_volatile msg_id
709  nvar /sdfr=df_general loglevel
710 
711  if (elog_validate_attributes(logbook,attributes) != 0)
712  if (loglevel >= 2)
713  print "ELOG: failed to validate attributes."
714  endif
715  result = -3
716  endif
717 
718  string cmd = prepare_command_line(logbook)
719  if (strlen(cmd) == 0)
720  if (loglevel >= 2)
721  print "ELOG: failed to prepare command line."
722  endif
723  result = -2
724  endif
725 
726  if (replyto >= 1)
727  cmd += " -r " + num2str(replyto)
728  endif
729  cmd += " -n " + num2str(encoding)
730 
731  variable nattr = ItemsInList(attributes, ";")
732  variable iattr
733  string sattr
734  for (iattr = 0; (iattr < nattr) && (result == 0); iattr += 1)
735  sattr = StringFromList(iattr, attributes, ";")
736  if (strlen(StringFromList(1, sattr, "=")) > 0)
737  sattr = ReplaceString("%", sattr, "")
738  cmd += " -a \"" + sattr + "\""
739  endif
740  endfor
741 
742  if (result == 0)
743  string cmd_graphs = prepare_graph_attachments(graphs)
744  cmd += " " + cmd_graphs
745  endif
746 
747  if ((result == 0) && (strlen(message) > 0))
748  string messagefile = create_message_file(message)
749  if (strlen(messagefile) > 0)
750  cmd += " -m \"" + messagefile + "\""
751  cmd += " > \"" + get_log_path() + "\""
752  if (loglevel >= 5)
753  print cmd
754  endif
755  string cmd_file_path = create_cmd_file(cmd)
756  ExecuteScriptText cmd_file_path
757  variable id = parse_result()
758  if (id > 0)
759  msg_id = id
760  if (loglevel >= 4)
761  print "ELOG: sent message " + num2str(id)
762  endif
763  else
764  if (loglevel >= 2)
765  print "ELOG: sending message failed."
766  endif
767  result = -4
768  endif
769  else
770  if (loglevel >= 2)
771  print "ELOG: failed to create temporary message file."
772  endif
773  result = -1
774  endif
775  endif
776 
777  setdatafolder savedf
778  return result
779 };
780 
788 variable elog_add_attachment(string logbook, variable id, string graphs){
789  string logbook
790  variable id// existing entry ID
791  string graphs// names of graph windows to be added as attachments, semicolon separated
792 
793  dfref savedf = getdatafolderdfr()
794  dfref df_general = get_elog_df("", kdfPersistent)
795  dfref df_volatile = get_elog_df(logbook, kdfVolatile)
796 
797  variable result = 0
798  nvar /sdfr=df_volatile msg_id
799  nvar /sdfr=df_general loglevel
800 
801  string cmd = prepare_command_line(logbook)
802  if (strlen(cmd) == 0)
803  result = -2// error: invalid/missing command line
804  endif
805 
806  cmd += " -e " + num2str(id)
807 
808  if (result == 0)
809  string cmd_graphs = prepare_graph_attachments(graphs)
810  if (strlen(cmd_graphs) == 0)
811  result = -3// error: invalid/missing graphs
812  endif
813  endif
814 
815  if (result == 0)
816  cmd += " " + cmd_graphs
817  cmd += " > \"" + get_log_path() + "\""
818  string cmd_file_path = create_cmd_file(cmd)
819  ExecuteScriptText cmd_file_path
820  id = parse_result()
821  if (id > 0)
822  msg_id = id
823  if (loglevel >= 4)
824  print "ELOG: attached graphs to message " + num2str(id)
825  endif
826  else
827  if (loglevel >= 2)
828  print "ELOG: failed to attach graphs."
829  endif
830  result = -4// error: elog returned error
831  endif
832  endif
833 
834  setdatafolder savedf
835  return result
836 };
837 
845 static string prepare_command_line(string logbook){
846  string logbook
847 
848  dfref df_general = get_elog_df("", kdfPersistent)
849  dfref df_persistent = get_elog_df(logbook, kdfPersistent)
850  dfref df_volatile = get_elog_df(logbook, kdfVolatile)
851 
852  svar /sdfr=df_general elog_path
853  svar /sdfr=df_general hostname
854  nvar /sdfr=df_general port
855  nvar /sdfr=df_general ssl
856  svar /sdfr=df_general subdir
857  nvar /sdfr=df_general loglevel
858  svar /sdfr=df_volatile username
859  svar /sdfr=df_volatile password
860 
861  string cmd
862  cmd = "\"" + elog_path + "\""
863  if (loglevel >= 5)
864  cmd += " -v"
865  endif
866  cmd += " -h " + hostname
867  if ((nvar_exists(port)) && (port > 0))
868  cmd += " -p " + num2str(port)
869  endif
870  if ((svar_exists(subdir)) && (strlen(subdir) > 0))
871  cmd += " -d " + subdir
872  endif
873  cmd += " -l \"" + logbook + "\""
874  if ((nvar_exists(ssl)) && (ssl != 0))
875  cmd += " -s"
876  endif
877  //cmd += " -w " + password
878  if (svar_exists(username) && svar_exists(password) && (strlen(username) > 0) && (strlen(password) > 0))
879  cmd += " -u " + username + " " + password
880  endif
881 
882  if (loglevel >= 5)
883  print cmd
884  endif
885 
886  return cmd
887 };
888 
894 static string format_url(string logbook){
895  string logbook
896 
897  dfref df_general = get_elog_df("", kdfPersistent)
898 
899  svar /sdfr=df_general hostname
900  nvar /sdfr=df_general port
901  nvar /sdfr=df_general ssl
902  svar /sdfr=df_general subdir
903 
904  string cmd = ""
905  if ((nvar_exists(ssl)) && (ssl != 0))
906  cmd += "https://"
907  else
908  cmd += "http://"
909  endif
910  cmd += hostname
911  if ((nvar_exists(port)) && (port > 0))
912  cmd += ":" + num2str(port)
913  endif
914  if ((svar_exists(subdir)) && (strlen(subdir) > 0))
915  cmd += "/" + subdir
916  endif
917  cmd += "/" + logbook
918 
919  return cmd
920 };
921 
930 static string prepare_graph_attachments(string graphs){
931  string graphs// names of graph windows to be added as attachments, semicolon separated
932 
933  string cmd = ""
934  variable ngraphs = ItemsInList(graphs, ";")
935  variable igraph
936  string sgraph
937  string graph_path
938  for (igraph = 0; igraph < ngraphs; igraph += 1)
939  sgraph = StringFromList(igraph, graphs, ";")
940  graph_path = create_graph_file(sgraph, igraph)
941  if (strlen(graph_path) > 0)
942  cmd += " -f \"" + graph_path + "\""
943  endif
944  endfor
945 
946  return cmd
947 };
948 
949 static string get_timestamp(string sep){
950  string sep
951  Variable now = DateTime
952  string dat = ReplaceString("-", Secs2Date(DateTime, -2), "")
953  string tim = ReplaceString(":", Secs2Time(DateTime, 3), "")
954  return dat + sep + tim
955 };
956 
957 static string create_message_file(string message){
958  string message
959 
960  message = ReplaceString("%", message, "")
961  string path = SpecialDirPath("Temporary", 0, 1, 0)
962  variable len = strlen(path)
963  if (numtype(len) == 0)
964  path += "elog_temp_message.txt"
965  variable f1
966  Open f1 as path
967  fprintf f1, message
968  Close f1
969  else
970  path = ""
971  endif
972 
973  return path
974 };
975 
976 static string create_graph_file(string graphname, variable fileindex){
977  string graphname
978  variable fileindex
979 
980  dfref df_volatile_root = get_elog_df("", kdfVolatile)
981  svar /sdfr=df_volatile_root temp_graph_files
982 
983  string path = SpecialDirPath("Temporary", 0, 1, 0)
984  string ts = get_timestamp("_")
985  variable len = strlen(path)
986  if (numtype(len) == 0)
987  path += "elog_" + ts + "_" + num2str(fileindex) + ".png"
988  SavePICT /B=72 /E=-5 /M /O /W=(0,0,8,6) /WIN=$graphname /Z as path
989  if (v_flag == 0)
990  temp_graph_files = AddListItem(path, temp_graph_files, ";", inf)
991  else
992  path = ""
993  endif
994  else
995  path = ""
996  endif
997 
998  return path
999 };
1000 
1001 static string create_cmd_file(string cmd){
1002  string cmd
1003 
1004  string path = SpecialDirPath("Temporary", 0, 1, 0)
1005  variable len = strlen(path)
1006  if (numtype(len) == 0)
1007  path += "elog_temp_cmd.bat"
1008  variable f1
1009  Open f1 as path
1010  fprintf f1, cmd
1011  Close f1
1012  else
1013  path = ""
1014  endif
1015 
1016  return path
1017 };
1018 
1019 static string get_log_path(){
1020  string path = SpecialDirPath("Temporary", 0, 1, 0)
1021  variable len = strlen(path)
1022  if (numtype(len) == 0)
1023  path += "elog.log"
1024  else
1025  path = ""
1026  endif
1027 
1028  return path
1029 };
1030 
1039 static variable cleanup_temp_files(){
1040  dfref df_volatile_root = get_elog_df("", kdfVolatile)
1041  if (DataFolderRefStatus(df_volatile_root))
1042  svar /sdfr=df_volatile_root /z temp_graph_files
1043  if (SVAR_Exists(temp_graph_files))
1044  variable nfi = ItemsInList(temp_graph_files)
1045  variable ifi
1046  string sfi
1047  for (ifi = 0; ifi < nfi; ifi += 1)
1048  sfi = StringFromList(ifi, temp_graph_files)
1049  DeleteFile /Z sfi
1050  endfor
1051  temp_graph_files = ""
1052  endif
1053  endif
1054  return 0
1055 };
1056 
1057 static const string elog_success_msg = "Message successfully transmitted";
1058 static const string elog_parse_id = "ID=%u";
1059 
1065 static variable parse_result(){
1066  dfref df_general = get_elog_df("", kdfPersistent)
1067  nvar /sdfr=df_general loglevel
1068 
1069  string path = get_log_path()
1070  string line = ""
1071  string output = ""
1072  variable success = 0
1073  variable id = -1
1074  string part1 = ""
1075  string part2 = ""
1076 
1077  variable len = strlen(path)
1078  if (numtype(len) == 0)
1079  variable f1
1080  Open /R/Z f1 as path
1081  if (v_flag == 0)
1082  do
1083  FReadLine f1, line
1084  if (strlen(line) > 0)
1085  part1 = StringFromList(0, line, ",")
1086  part2 = ReplaceString(" ", StringFromList(1, line, ","), "")
1087  success = cmpstr(part1, elog_success_msg) == 0
1088  if (success)
1089  sscanf part2, elog_parse_id, id
1090  endif
1091  else
1092  break
1093  endif
1094  output += line
1095  while(!success)
1096  Close f1
1097  endif
1098  endif
1099  if (loglevel >= 5)
1100  print output
1101  endif
1102 
1103  return id
1104 };
1105 
1109  string logbooks = list_logbooks(templates=0)
1110  logbooks = AddListItem("(new)", logbooks)
1111  string templates = list_logbooks(templates=1)
1112  templates = AddListItem("(none)", templates)
1113 
1114  string logbook = StringFromList(0, logbooks)
1115  string template = StringFromList(0, logbooks)
1116  string name = ""
1117  string username = ""
1118  string password = ""
1119 
1120  prompt logbook, "logbook", popup logbooks
1121  prompt template, "template", popup templates
1122  prompt name, "new logbook name"
1123 
1124  doprompt "select logbook", logbook, template, name
1125  if (!v_flag)
1126  if (cmpstr(logbook, "(new)") == 0)
1127  elog_create_logbook(name, template=template)
1128  logbook = name
1129  endif
1130  else
1131  logbook = ""
1132  endif
1133  return logbook
1134 };
1135 
1138 variable elog_prompt_login(string logbook){
1139  string logbook
1140 
1141  string logbooks = list_logbooks(templates=0)
1142 
1143  string username = ""
1144  string password = ""
1145 
1146  prompt logbook, "logbook", popup logbooks
1147  prompt username, "user name"
1148  prompt password, "password (blank to log out)"
1149 
1150  doprompt "log in to logbook", logbook, username, password
1151  if (!v_flag)
1152  elog_login(logbook, username, password)
1153  endif
1154 
1155  return v_flag
1156 };
1157 
1165 string PearlElogPanel(string logbook){
1166  string logbook
1167 
1168  dfref savedf = getdatafolderdfr()
1169  dfref df_general = get_elog_df("", kdfPersistent)
1170  dfref df_persistent = get_elog_df(logbook, kdfPersistent)
1171  dfref df_volatile = get_elog_df(logbook, kdfVolatile)
1172 
1173  string win_name = logbook + "ElogPanel"
1174  string win_title = "ELOG " + logbook
1175 
1176  NewPanel /K=1 /N=$win_name /W=(600,200,1200,700) as win_title
1177  win_name = s_name
1178  ModifyPanel /w=$win_name cbRGB=(52224,52224,65280)
1179 
1180  svar /sdfr=df_persistent attributes
1181  svar /sdfr=df_persistent controls
1182  svar /sdfr=df_persistent options
1183  wave /t /sdfr=df_volatile attach_list
1184  wave /sdfr=df_volatile attach_sel
1185  svar /sdfr=df_volatile url
1186 
1187  variable iattr
1188  variable nattr = ItemsInList(attributes, ";")
1189  string s_attr
1190  string s_control
1191  string s_option
1192  string persistent_path = GetDataFolder(1, df_persistent)
1193  string volatile_path = GetDataFolder(1, df_volatile)
1194  string options_path
1195  string variable_path
1196  variable ypos = 2
1197  variable height = 0
1198 
1199  for (iattr = 0; iattr < nattr; iattr += 1)
1200  s_attr = StringFromList(iattr, attributes, ";")
1201  s_control = StringFromList(iattr, controls, ";")
1202  strswitch(s_control[0,1])
1203  case "sv":
1204  SetVariable $s_control, win=$win_name, pos={0,ypos}, size={300,16}, bodyWidth=230
1205  SetVariable $s_control, win=$win_name, title=s_attr, value= _STR:""
1206  SetVariable $s_control, win=$win_name, userdata(attribute)=s_attr
1207  ypos += 18
1208  break
1209  case "pm":
1210  options_path = persistent_path + StringByKey(s_attr, options, "=", ";")
1211  PopupMenu $s_control, win=$win_name, pos={0,ypos}, size={300,21}, bodyWidth=230
1212  PopupMenu $s_control, win=$win_name, title=s_attr
1213  PopupMenu $s_control, win=$win_name, mode=1, popvalue="Test", value= #options_path
1214  PopupMenu $s_control, win=$win_name, userdata(attribute)=s_attr
1215  ypos += 23
1216  break
1217  case "cb":
1218  CheckBox $s_control, win=$win_name, pos={70,ypos}, size={300,14}
1219  CheckBox $s_control, win=$win_name, title=s_attr, value= 1
1220  CheckBox $s_control, win=$win_name, userdata(attribute)=s_attr
1221  ypos += 17
1222  break
1223  endswitch
1224  endfor
1225 
1226  TitleBox t_attach, win=$win_name, pos={308,5}, size={70,14}, title="Attachments", frame=0
1227  height = ypos - 21 - 4
1228  ListBox lb_attach, win=$win_name, pos={308,21}, size={264,height}
1229  ListBox lb_attach, win=$win_name, listWave=attach_list
1230  ListBox lb_attach, win=$win_name, mode=1, selWave=attach_sel, selRow=-1
1231  ListBox lb_attach, win=$win_name, widths={20,160,80}
1232  ListBox lb_attach, win=$win_name, help={"Choose graphs to attach to the message."}
1233 
1234  Button b_attach_top, win=$win_name, pos={420,2}, size={40,18}, title="top"
1235  Button b_attach_top, win=$win_name, fcolor=(56576,60928,47872)
1236  Button b_attach_top, win=$win_name, proc=PearlElog#bp_attach_top
1237  Button b_attach_top, win=$win_name, help={"Select top graph for attachment."}
1238  Button b_attach_all, win=$win_name, pos={460,2}, size={40,18}, title="all"
1239  Button b_attach_all, win=$win_name, fcolor=(56576,60928,47872)
1240  Button b_attach_all, win=$win_name, proc=PearlElog#bp_attach_allnone
1241  Button b_attach_all, win=$win_name, help={"Select all graphs for attachment."}
1242  Button b_attach_none, win=$win_name, pos={500,2}, size={40,18}, title="none"
1243  Button b_attach_none, win=$win_name, fcolor=(56576,60928,47872)
1244  Button b_attach_none, win=$win_name, proc=PearlElog#bp_attach_allnone
1245  Button b_attach_none, win=$win_name, help={"Deselect all attachments."}
1246  Button b_save_graphs, win=$win_name, pos={540,2}, size={40,18}, title="save"
1247  Button b_save_graphs, win=$win_name, fcolor=(56576,60928,47872)
1248  Button b_save_graphs, win=$win_name, proc=PearlElog#bp_save_graphs
1249  Button b_save_graphs, win=$win_name, help={"Save selected graphs as PNG bitmap files."}
1250  Button b_attach_up, win=$win_name, pos={576,20}, size={20,20}, title="\\W517"
1251  Button b_attach_up, win=$win_name, fcolor=(56576,60928,47872)
1252  Button b_attach_up, win=$win_name, proc=PearlElog#bp_attach_updown
1253  Button b_attach_up, win=$win_name, help={"Move selected graph up."}
1254  Button b_attach_dw, win=$win_name, pos={576,40}, size={20,20}, title="\\W523"
1255  Button b_attach_dw, win=$win_name, fcolor=(56576,60928,47872)
1256  Button b_attach_dw, win=$win_name, proc=PearlElog#bp_attach_updown
1257  Button b_attach_dw, win=$win_name, help={"Move selected graph down."}
1258 
1259  ypos += 246-160
1260  Button b_submit,win=$win_name, pos={70,ypos},size={46,20},proc=PearlElog#bp_submit,title="Submit"
1261  Button b_submit,win=$win_name, help={"Submit form data to ELOG (new entry)."}
1262  Button b_submit,win=$win_name, fcolor=(56576,60928,47872)
1263  Button b_clear,win=$win_name, pos={120,ypos},size={46,20},proc=PearlElog#bp_clear,title="Clear"
1264  Button b_clear,win=$win_name, help={"Clear the form fields"}
1265  Button b_clear,win=$win_name, fcolor=(56576,60928,47872)
1266 
1267  ypos += 272-246
1268  variable_path = volatile_path + "msg_id"
1269  SetVariable sv_id,win=$win_name, pos={51,ypos},size={119,16},bodyWidth=77
1270  SetVariable sv_id,win=$win_name, title="ID",value=$variable_path
1271  SetVariable sv_id,win=$win_name, help={"ID of last submitted message, or message to attach or reply to."}
1272 
1273  TitleBox t_host, win=$win_name, pos={170,ypos+4}, size={112.00,14.00}, frame=0
1274  TitleBox t_host, win=$win_name, variable=url
1275 
1276  ypos += 270-272
1277  Button b_attach,win=$win_name, pos={170,ypos},size={48,20},proc=PearlElog#bp_attach,title="Attach"
1278  Button b_attach,win=$win_name, help={"Attach the selected graph to an existing ELOG entry (correct ID required)."}
1279  Button b_attach,win=$win_name, fcolor=(56576,60928,47872)
1280  Button b_reply,win=$win_name, pos={220,ypos},size={48,20},proc=PearlElog#bp_submit,title="Reply"
1281  Button b_reply,win=$win_name, help={"Submit form data to ELOG as a reply to an existing message (correct ID required)."}
1282  Button b_reply,win=$win_name, fcolor=(56576,60928,47872)
1283  Button b_login,win=$win_name, pos={550,ypos},size={46,20},proc=PearlElog#bp_login,title="Login"
1284  Button b_login,win=$win_name, help={"Enter user name and password."}
1285  Button b_login,win=$win_name, fcolor=(56576,60928,47872)
1286  Button b_logout,win=$win_name, pos={550,ypos},size={46,20},proc=PearlElog#bp_logout,title="Logout"
1287  Button b_logout,win=$win_name, help={"Clear user name and password."}
1288  Button b_logout,win=$win_name, fcolor=(56576,60928,47872), disable=3
1289 
1290  SetWindow $win_name, hook(elogPanelHook)=PearlElog#elog_panel_hook
1291  SetWindow $win_name, userdata(logbook)=logbook
1292 
1293  ypos += 160-270
1294  TitleBox t_message,win=$win_name, pos={10,ypos},size={58,16},fixedSize=1,frame=0,anchor=RT,title="Message"
1295  DefineGuide UGH0={FT,ypos},UGV0={FL,70},UGH1={FB,-52},UGV1={FR,-2}
1296  NewNotebook /F=0 /N=Message /OPTS=3 /W=(115,404,345,341)/FG=(UGV0,UGH0,UGV1,UGH1) /HOST=#
1297  Notebook kwTopWin, defaultTab=20, statusWidth=0, autoSave=0
1298  Notebook kwTopWin fSize=10, fStyle=0, textRGB=(0,0,0)
1299  RenameWindow #,Message
1300  string nb_name = win_name + "#Message"
1301  SetActiveSubwindow ##
1302 
1303  // restore recently used attributes and message
1304  svar /z /sdfr=df_persistent recent
1305  if (svar_exists(recent) && (strlen(recent) > 0))
1306  set_panel_attributes(win_name, recent)
1307  endif
1308  svar /z /sdfr=df_persistent recent_message
1309  if (svar_exists(recent_message) && (strlen(recent_message) > 0))
1310  set_panel_message(win_name, recent_message)
1311  endif
1312  Notebook $nb_name selection={startOfFile,startOfFile}, findText={"",1}
1313 
1314  setdatafolder savedf
1315  return win_name
1316 };
1317 
1318 static variable elog_panel_hook(WMWinHookStruct* s){
1319  STRUCT WMWinHookStruct &s
1320 
1321  Variable hookResult = 0
1322 
1323  switch(s.eventCode)
1324  case 0:// activate
1325  string logbook = GetUserData(s.winName, "", "logbook")
1326  if (strlen(logbook) > 0)
1327  dfref df_volatile = get_elog_df(logbook, kdfVolatile)
1328  svar /sdfr=df_volatile url
1329  url = format_url(logbook)
1330  update_attach_items(logbook)
1331  endif
1332  break
1333  case 6:// resize
1334  // move bottom-aligned controls when the window is resized
1335  variable b_top = s.winRect.bottom + 4
1336  Button b_submit,pos={70,b_top}
1337  Button b_clear,pos={120,b_top}
1338  TitleBox t_host, pos={170,b_top+4}
1339  b_top += 24
1340  Button b_attach,pos={170,b_top}
1341  Button b_reply,pos={220,b_top}
1342  Button b_login, pos={550,b_top}
1343  Button b_logout, pos={550,b_top}
1344  b_top += 2
1345  SetVariable sv_id,pos={51,b_top}
1346  break
1347  endswitch
1348 
1349  return hookResult// 0 if nothing done, else 1
1350 };
1351 
1352 static const variable kAttachColSel = 0;
1353 static const variable kAttachColTitle = 1;
1354 static const variable kAttachColName = 2;
1355 
1357 static variable update_attach_items(string logbook){
1358  string logbook
1359 
1360  dfref savedf = getdatafolderdfr()
1361  dfref df_volatile = get_elog_df(logbook, kdfVolatile)
1362  wave /t /sdfr=df_volatile attach_list
1363  wave /sdfr=df_volatile attach_sel
1364 
1365  if (!waveexists(attach_list))
1366  return -1
1367  endif
1368  string names = WinList("*", ";", "WIN:1;VISIBLE:1")
1369  names = SortList(names, ";", 16)
1370 
1371  // remove closed graphs
1372  variable i
1373  variable k
1374  variable n = DimSize(attach_list, 0)
1375  string s
1376  for (i = n-1; i >= 0; i -= 1)
1377  s = attach_list[i][kAttachColName]
1378  if (WhichListItem(s, names) < 0)
1379  DeletePoints /M=0 i, 1, attach_list, attach_sel
1380  endif
1381  endfor
1382 
1383  // add new graphs
1384  n = ItemsInList(names)
1385  for (i = 0; i < n; i += 1)
1386  s = StringFromList(i, names)
1387  FindValue /text=s /txop=4 /z attach_list
1388  if (v_value < 0)
1389  k = DimSize(attach_list, 0)
1390  Redimension /n=(k+1,3) attach_list, attach_sel
1391  //InsertPoints /M=0 k, 1, attach_list, attach_sel
1392  attach_list[k][kAttachColSel] = ""
1393  attach_list[k][kAttachColTitle] = ""
1394  attach_list[k][kAttachColName] = s
1395  attach_sel[k][kAttachColSel] = 32
1396  attach_sel[k][kAttachColTitle] = 0
1397  attach_sel[k][kAttachColName] = 0
1398  endif
1399  endfor
1400 
1401  // update titles
1402  n = DimSize(attach_list, 0)
1403  for (i = n-1; i >= 0; i -= 1)
1404  s = attach_list[i][kAttachColName]
1405  getwindow /z $s, wtitle
1406  if (v_flag == 0)
1407  attach_list[i][kAttachColTitle] = s_value
1408  else
1409  attach_list[i][kAttachColTitle] = s
1410  endif
1411  endfor
1412 
1413  setdatafolder savedf
1414  return 0
1415 };
1416 
1418 static variable move_attach_item(string logbook, variable item, variable distance){
1419  string logbook
1420  variable item
1421  variable distance
1422 
1423  dfref savedf = getdatafolderdfr()
1424  dfref df_volatile = get_elog_df(logbook, kdfVolatile)
1425  wave /t /sdfr=df_volatile attach_list
1426  wave /sdfr=df_volatile attach_sel
1427  variable n = DimSize(attach_list, 0)
1428  variable dest = item + distance
1429 
1430  if ((item >= 0) && (item < n) && (dest >= 0) && (dest < n))
1431  string name = attach_list[item][kAttachColName]
1432  variable sel = attach_sel[item][kAttachColSel]
1433  DeletePoints /M=0 item, 1, attach_list, attach_sel
1434  InsertPoints /M=0 dest, 1, attach_list, attach_sel
1435  attach_list[dest][kAttachColName] = name
1436  update_attach_items(logbook)
1437  attach_sel[dest][kAttachColSel] = sel
1438  endif
1439 };
1440 
1442 static variable bp_attach_updown(WMButtonAction* ba){
1443  STRUCT WMButtonAction &ba
1444 
1445  switch( ba.eventCode )
1446  case 2:// mouse up
1447  string logbook = GetUserData(ba.win, "", "logbook")
1448  ControlInfo /w=$ba.win lb_attach
1449  variable row = v_value
1450  dfref df = $s_datafolder
1451  wave /t /sdfr=df attach_list = $s_value
1452  if (cmpstr(ba.ctrlName, "b_attach_up") == 0)
1453  // up button
1454  if (row >= 1)
1455  move_attach_item(logbook, row, -1)
1456  ListBox lb_attach, win=$ba.win, selRow=(row-1)
1457  endif
1458  else
1459  // down button
1460  if (row < DimSize(attach_list, 0) - 1)
1461  move_attach_item(logbook, row, +1)
1462  ListBox lb_attach, win=$ba.win, selRow=(row+1)
1463  endif
1464  endif
1465  break
1466  case -1:// control being killed
1467  break
1468  endswitch
1469 
1470  return 0
1471 };
1472 
1474 static variable bp_submit(WMButtonAction* ba){
1475  STRUCT WMButtonAction &ba
1476 
1477  switch( ba.eventCode )
1478  case 2:// mouse up
1479  string logbook = GetUserData(ba.win, "", "logbook")
1480  string attributes
1481  string message
1482  string graphs
1483  attributes = get_panel_attributes(ba.win)
1484  message = get_panel_message(ba.win)
1485  graphs = get_panel_graphs(ba.win)
1486 
1487  variable id
1488  if (cmpstr(ba.ctrlName, "b_reply") == 0)
1489  // Reply button
1490  ControlInfo /w=$ba.win sv_id
1491  id = v_value
1492  else
1493  // Submit button
1494  id = 0
1495  endif
1496 
1497  if ((elog_validate_attributes(logbook, attributes) == 0) && (strlen(message) > 0))
1498  variable result
1499  result = elog_create_entry(logbook, attributes, message, graphs=graphs, replyto=id)
1500  if (result == 0)
1501  dfref df = get_elog_df(logbook, kdfPersistent)
1502  svar /sdfr=df recent
1503  recent = attributes
1504  svar /sdfr=df recent_message
1505  recent_message = message
1506  else
1507  abort "Submission failed. Error code " + num2str(result) + "."
1508  endif
1509  else
1510  abort "Submission failed due to missing/invalid attribute."
1511  endif
1512  break
1513  case -1:// control being killed
1514  break
1515  endswitch
1516 
1517  return 0
1518 };
1519 
1521 static variable bp_attach_top(WMButtonAction* ba){
1522  STRUCT WMButtonAction &ba
1523 
1524  switch( ba.eventCode )
1525  case 2:// mouse up
1526  string graphs = WinName(0, 1, 1)
1527  set_panel_graphs(ba.win, graphs)
1528  break
1529  case -1:// control being killed
1530  break
1531  endswitch
1532 
1533  return 0
1534 };
1535 
1537 static variable bp_attach_allnone(WMButtonAction* ba){
1538  STRUCT WMButtonAction &ba
1539 
1540  switch( ba.eventCode )
1541  case 2:// mouse up
1542  string logbook = GetUserData(ba.win, "", "logbook")
1543  dfref df_volatile = get_elog_df(logbook, kdfVolatile)
1544  wave /sdfr=df_volatile attach_sel
1545  if (cmpstr(ba.ctrlName, "b_attach_all") == 0)
1546  attach_sel[][kAttachColSel] = attach_sel[p][kAttachColSel] | 16
1547  else
1548  attach_sel[][kAttachColSel] = attach_sel[p][kAttachColSel] & ~16
1549  endif
1550  break
1551  case -1:// control being killed
1552  break
1553  endswitch
1554 
1555  return 0
1556 };
1557 
1558 static variable bp_attach(WMButtonAction* ba){
1559  STRUCT WMButtonAction &ba
1560 
1561  switch( ba.eventCode )
1562  case 2:// mouse up
1563  string logbook = GetUserData(ba.win, "", "logbook")
1564  string graphs
1565  graphs = get_panel_graphs(ba.win)
1566 
1567  variable id
1568  ControlInfo /w=$ba.win sv_id
1569  id = v_value
1570 
1571  // TODO : is there a way around this restriction?
1572  DoAlert /T="ELOG" 1, "This operation will replace all existing attachments. Do you want to continue?"
1573 
1574  if ((id > 0) && (v_flag == 1))
1575  variable result
1576  result = elog_add_attachment(logbook, id, graphs)
1577  if (result != 0)
1578  abort "Submission failed. Error code " + num2str(result) + "."
1579  endif
1580  else
1581  abort "Submission failed due to missing/invalid attribute."
1582  endif
1583  break
1584  case -1:// control being killed
1585  break
1586  endswitch
1587 
1588  return 0
1589 };
1590 
1591 static variable bp_save_graphs(WMButtonAction* ba){
1592  STRUCT WMButtonAction &ba
1593 
1594  switch( ba.eventCode )
1595  case 2:// mouse up
1596  string logbook = GetUserData(ba.win, "", "logbook")
1597  string graphs = get_panel_graphs(ba.win)
1598  variable ngraphs = ItemsInList(graphs, ";")
1599 
1600  variable igraph
1601  string sgraph
1602  string graph_path
1603  for (igraph = 0; igraph < ngraphs; igraph += 1)
1604  sgraph = StringFromList(igraph, graphs, ";")
1605  graph_path = create_graph_file(sgraph, igraph)
1606  if (strlen(graph_path) > 0)
1607  print graph_path
1608  endif
1609  endfor
1610 
1611  break
1612  case -1:// control being killed
1613  break
1614  endswitch
1615 
1616  return 0
1617 };
1618 
1619 static variable bp_clear(WMButtonAction* ba){
1620  STRUCT WMButtonAction &ba
1621 
1622  switch( ba.eventCode )
1623  case 2:// mouse up
1624  set_panel_attributes(ba.win, "", clear=1)
1625  set_panel_message(ba.win, "")
1626  set_panel_graphs(ba.win, "")
1627  break
1628  case -1:// control being killed
1629  break
1630  endswitch
1631 
1632  return 0
1633 };
1634 
1635 static variable bp_login(WMButtonAction* ba){
1636  STRUCT WMButtonAction &ba
1637 
1638  switch( ba.eventCode )
1639  case 2:// mouse up
1640  string logbook = GetUserData(ba.win, "", "logbook")
1641  if (elog_prompt_login(logbook) == 0)
1642  Button b_login, win=$ba.win, disable=3
1643  Button b_logout, win=$ba.win, disable=0
1644  endif
1645  break
1646  case -1:// control being killed
1647  break
1648  endswitch
1649 
1650  return 0
1651 };
1652 
1653 static variable bp_logout(WMButtonAction* ba){
1654  STRUCT WMButtonAction &ba
1655 
1656  switch( ba.eventCode )
1657  case 2:// mouse up
1658  string logbook = GetUserData(ba.win, "", "logbook")
1659  elog_logout(logbook)
1660  Button b_login, win=$ba.win, disable=0
1661  Button b_logout, win=$ba.win, disable=3
1662  break
1663  case -1:// control being killed
1664  break
1665  endswitch
1666 
1667  return 0
1668 };
1669 
1670 static string get_default_panel_name(){
1671  string windowname
1672  windowname = StringFromList(0, WinList("*ElogPanel*", ";", "WIN:64"), ";")
1673  return windowname
1674 };
1675 
1683 static string get_panel_attributes(string windowname){
1684  string windowname
1685 
1686  if (strlen(windowname) == 0)
1687  windowname = get_default_panel_name()
1688  endif
1689  if (strlen(windowname) == 0)
1690  return ""
1691  endif
1692 
1693  string controls = ControlNameList(windowname, ";")
1694  string attributes = ""
1695  string control
1696  string attribute
1697  variable ico
1698  variable nco = ItemsInList(controls, ";")
1699  for (ico = 0; ico < nco; ico += 1)
1700  control = StringFromList(ico, controls, ";")
1701  attribute = GetUserData(windowname, control, "attribute")
1702  if (strlen(attribute) > 0)
1703  ControlInfo /w=$windowname $control
1704  switch(v_flag)
1705  case 2:// checkbox
1706  attributes = ReplaceNumberByKey(attribute, attributes, v_value, "=", ";")
1707  break
1708  case 3:// popupmenu
1709  case 5:// setvariable
1710  attributes = ReplaceStringByKey(attribute, attributes, s_value, "=", ";")
1711  break
1712  endswitch
1713  endif
1714  endfor
1715 
1716  return attributes
1717 };
1718 
1730 static string set_panel_attributes(string windowname, string attributes, variable clear = defaultValue){
1731  string windowname
1732  string attributes
1733  variable clear
1734 
1735  if (strlen(windowname) == 0)
1736  windowname = get_default_panel_name()
1737  endif
1738  if (strlen(windowname) == 0)
1739  return ""
1740  endif
1741  if (ParamIsDefault(clear))
1742  clear = 0
1743  endif
1744 
1745  string path
1746 
1747  string controls = ControlNameList(windowname, ";")
1748  string control
1749  string attribute
1750  string value
1751  variable numval
1752  variable ico
1753  variable nco = ItemsInList(controls, ";")
1754  for (ico = 0; ico < nco; ico += 1)
1755  control = StringFromList(ico, controls, ";")
1756  attribute = GetUserData(windowname, control, "attribute")
1757  if (strlen(attribute))
1758  value = StringByKey(attribute, attributes, "=", ";")
1759  if (strlen(value) || clear)
1760  ControlInfo /w=$windowname $control
1761  switch(v_flag)
1762  case 2:// checkbox
1763  numval = NumberByKey(attribute, attributes, "=", ";")
1764  if ((numtype(numval) != 0) && clear)
1765  numval = 0
1766  endif
1767  if (numtype(numval) == 0)
1768  CheckBox $control, value=numval, win=$windowname
1769  endif
1770  break
1771  case 3:// popupmenu
1772  PopupMenu $control, popvalue=value, win=$windowname
1773  break
1774  case 5:// setvariable
1775  SetVariable /z $control, value= _STR:value, win=$windowname
1776  break
1777  endswitch
1778  endif
1779  endif
1780  endfor
1781 
1782  return attributes
1783 };
1784 
1792 static string get_panel_message(string windowname){
1793  string windowname
1794 
1795  if (strlen(windowname) == 0)
1796  windowname = get_default_panel_name()
1797  endif
1798  if (strlen(windowname) == 0)
1799  return ""
1800  endif
1801 
1802  string nb = windowname + "#Message"
1803  notebook $nb selection={startOfFile, endOfFile}
1804  getselection notebook, $nb, 2
1805 
1806  return s_selection
1807 };
1808 
1818 static string set_panel_message(string windowname, string message){
1819  string windowname
1820  string message
1821 
1822  if (strlen(windowname) == 0)
1823  windowname = get_default_panel_name()
1824  endif
1825 
1826  string nb = windowname + "#Message"
1827  notebook $nb selection={startOfFile, endOfFile},text=message
1828 
1829  return message
1830 };
1831 
1838 static string get_panel_graphs(string windowname){
1839  string windowname// panel window name
1840 
1841  dfref savedf = getdatafolderdfr()
1842  if (strlen(windowname) == 0)
1843  windowname = get_default_panel_name()
1844  endif
1845  if (strlen(windowname) == 0)
1846  return ""
1847  endif
1848 
1849  string logbook = GetUserData(windowname, "", "logbook")
1850  dfref df_volatile = get_elog_df(logbook, kdfVolatile)
1851  wave /t /sdfr=df_volatile attach_list
1852  wave /sdfr=df_volatile attach_sel
1853  string graphs = ""
1854  string windows = ""
1855  string graphname
1856 
1857  variable n = DimSize(attach_sel, 0)
1858  variable i
1859  for (i = 0; i < n; i += 1)
1860  if (attach_sel[i][kAttachColSel] & 16)
1861  graphname = attach_list[i][kAttachColName]
1862  windows = WinList(graphname, ";", "WIN:1")
1863  if (ItemsInList(windows) == 1)
1864  graphs = AddListItem(graphname, graphs, ";", inf)
1865  endif
1866  endif
1867  endfor
1868 
1869  return graphs
1870 };
1871 
1878 static string set_panel_graphs(string windowname, string graphs){
1879  string windowname
1880  string graphs
1881 
1882  if (strlen(windowname) == 0)
1883  windowname = get_default_panel_name()
1884  endif
1885  if (strlen(windowname) == 0)
1886  return ""
1887  endif
1888 
1889  string logbook = GetUserData(windowname, "", "logbook")
1890  update_attach_items(logbook)
1891  dfref df_volatile = get_elog_df(logbook, kdfVolatile)
1892  wave /t /sdfr=df_volatile attach_list
1893  wave /sdfr=df_volatile attach_sel
1894 
1895  variable n = DimSize(attach_sel, 0)
1896  variable i
1897  string graphname
1898  for (i = 0; i < n; i += 1)
1899  graphname = attach_list[i][kAttachColName]
1900  if (WhichListItem(graphname, graphs)>= 0)
1901  attach_sel[i][kAttachColSel] = 48
1902  else
1903  attach_sel[i][kAttachColSel] = 32
1904  endif
1905  endfor
1906 };
1907 
variable elog_create_entry(string logbook, string attributes, string message, variable encoding=defaultValue, string graphs=defaultValue, variable replyto=defaultValue)
create a new entry in ELOG
Definition: pearl-elog.ipf:685
static variable AfterFileOpenHook(variable refNum, string file, string pathName, string type, string creator, variable kind)
initialize the package and reload preferences after an experiment is loaded.
Definition: pearl-elog.ipf:143
variable elog_add_attachment(string logbook, variable id, string graphs)
add one or more graphs to an existing ELOG entry
Definition: pearl-elog.ipf:788
static const string package_path
Definition: pearl-elog.ipf:86
static string get_panel_graphs(string windowname)
get the names of the graphs selected for attachment
static variable bp_attach_updown(WMButtonAction *ba)
button procedure for the attachment up and down buttons
static string create_message_file(string message)
Definition: pearl-elog.ipf:957
static variable parse_result()
parse the result file from an elog invokation.
variable elog_create_logbook(string name, string template=defaultValue)
create a new logbook.
Definition: pearl-elog.ipf:414
static string set_panel_attributes(string windowname, string attributes, variable clear=defaultValue)
set the fields of the ELOG panel
static variable bp_logout(WMButtonAction *ba)
static string get_default_panel_name()
static variable elog_panel_hook(WMWinHookStruct *s)
variable elog_config(string elog_path=defaultValue, string hostname=defaultValue, variable port=defaultValue, string subdir=defaultValue)
set global module configuration parameters
Definition: pearl-elog.ipf:473
interface for writing ELOG entries with Igor graphs as attachment.
static variable IgorBeforeNewHook(string igorApplicationNameStr)
save preferences and recent values before Igor opens a new experiment.
Definition: pearl-elog.ipf:127
static string set_panel_graphs(string windowname, string graphs)
update selection of graphs for attachment
variable elog_init_pearl_templates()
setup PEARL template logbooks.
Definition: pearl-elog.ipf:262
static string create_graph_file(string graphname, variable fileindex)
Definition: pearl-elog.ipf:976
static const variable kAttachColName
static variable bp_clear(WMButtonAction *ba)
variable elog_login(string logbook, string username, string password)
set username and password for login to a logbook
Definition: pearl-elog.ipf:513
static variable bp_attach_top(WMButtonAction *ba)
select top graph window for attachment
static const variable kAttachColSel
string PearlElogPanel(string logbook)
open a new panel for submitting data to ELOG.
variable elog_validate_attributes(string logbook, string attributes)
validate attributes
Definition: pearl-elog.ipf:653
static string prepare_graph_attachments(string graphs)
prepare screenshots of graph windows for attachments
Definition: pearl-elog.ipf:930
static string list_logbooks(variable templates=defaultValue)
get a list of configured logbooks or templates.
Definition: pearl-elog.ipf:618
static variable bp_attach(WMButtonAction *ba)
static variable move_attach_item(string logbook, variable item, variable distance)
move an attachment item in the list of attachments
static dfr get_elog_df(string name, variable category)
get the package, logbook, or template datafolder.
Definition: pearl-elog.ipf:170
string elog_prompt_logbook()
prompt to open or create a logbook
static variable bp_save_graphs(WMButtonAction *ba)
static variable update_attach_items(string logbook)
update the list of attachments
static variable bp_login(WMButtonAction *ba)
static const variable kdfVolatile
Definition: pearl-elog.ipf:154
static const variable kdfTemplates
Definition: pearl-elog.ipf:156
static string prepare_command_line(string logbook)
format the ELOG command and essential address arguments.
Definition: pearl-elog.ipf:845
static variable cleanup_temp_files()
delete temporary files created by the ELOG module.
static string get_log_path()
static const variable kAttachColTitle
static const string elog_parse_id
static string get_panel_message(string windowname)
get the message field of the ELOG panel
static string create_cmd_file(string cmd)
static variable init_volatile_vars()
initialize volatile variables.
Definition: pearl-elog.ipf:340
static variable load_prefs()
load persistent package data from the preferences file.
Definition: pearl-elog.ipf:584
static const variable kdfPersistent
Definition: pearl-elog.ipf:155
static variable init_package(variable clean=defaultValue)
initialize the package data folder.
Definition: pearl-elog.ipf:217
static variable save_prefs()
save persistent package data to the preferences file.
Definition: pearl-elog.ipf:564
static const variable kdfRoot
Definition: pearl-elog.ipf:153
variable elog_prompt_login(string logbook)
prompt the user for login to a logbook
static string set_panel_message(string windowname, string message)
set the message field of the ELOG panel
static variable IgorQuitHook(string igorApplicationNameStr)
save preferences and recent values before Igor quits.
Definition: pearl-elog.ipf:135
static variable bp_submit(WMButtonAction *ba)
button procedure for the Submit and Reply buttons
static variable bp_attach_allnone(WMButtonAction *ba)
select/deselect all graph windows for attachment
static string get_panel_attributes(string windowname)
get a list of attributes from the fields of the ELOG panel.
static const string elog_success_msg
static string get_timestamp(string sep)
Definition: pearl-elog.ipf:949
variable elog_logout(string logbook)
clear username and password of a logbook or all logbooks.
Definition: pearl-elog.ipf:533
variable pearl_elog(string logbook)
main function to initialize ELOG and to open an ELOG panel.
Definition: pearl-elog.ipf:97
static string format_url(string logbook)
format the URL for display to the user
Definition: pearl-elog.ipf:894
static const string package_name
Definition: pearl-elog.ipf:85