3 #pragma IgorVersion = 6.36 4 #pragma ModuleName = PearlMatrixImport 38 static const string package_path =
"root:packages:pearl_matrix_import:";
47 dfref savedf = getdatafolderdfr()
50 newdatafolder /o/s packages
51 newdatafolder /o/s $package_name
53 variable /g loglevel = 3
54 string /g dataFilePath =
"" 55 string /g resultFilePath =
"" 56 variable /g runCycle = 0
57 variable /g scanCycle = 0
58 string /g channelName =
"" 59 variable /g brickletID = 0
60 variable /g V_MatrixFileReaderOverwrite = 1
61 variable /g V_MatrixFileReaderFolder = 0
62 variable /g V_MatrixFileReaderDouble = 0
74 if (DataFolderRefStatus(df_pack))
75 svar /sdfr=df_pack /z resultFilePath
76 if (!svar_exists(resultFilePath))
85 static variable
AfterFileOpenHook(variable refNum,
string file,
string pathName,
string type,
string creator, variable kind){
87 String file,pathName,type,creator
88 if( (kind >= 1) && (kind <= 2))
102 static variable
BeforeFileOpenHook(variable refNum,
string fileName,
string path,
string type,
string creator, variable kind){
104 String fileName,path,type,creator
106 Variable handledOpen = 0
109 newdatafolder /o /s matrix
125 variable nkeys = dimsize(metadata, 0)
128 message_keys =
"resultFileName;sampleName;channelName;" 129 message_keys +=
"XYScanner.Points.value;XYScanner.Raster_Time.value;XYScanner.Raster_Time.unit;XYScanner.Width.value;XYScanner.Width.unit;XYScanner.Height.value;XYScanner.Height.unit;" 130 message_keys +=
"GapVoltageControl.Voltage.value;GapVoltageControl.Voltage.unit;" 131 message_keys +=
"Regulator.Loop_Gain_1_I.value;Regulator.Loop_Gain_1_I.unit;Regulator.Setpoint_1.value;Regulator.Setpoint_1.unit;" 132 message_keys +=
"Spectroscopy.Device_1_Start.value;Spectroscopy.Device_1_Start.unit;Spectroscopy.Spectroscopy_Mode.value;" 136 for (ikey = 0; ikey < nkeys; ikey += 1)
137 key = metadata[ikey][0]
138 value = metadata[ikey][1]
139 if (WhichListItem(key, message_keys) >= 0)
140 message += key +
" = " + value +
"\r" 151 ModifyImage data ctab= {*,*,Mud,0}
152 ModifyGraph margin(left)=30,margin(bottom)=30,margin(top)=5,margin(right)=5,height={Plan,1,left,bottom}
155 ModifyGraph axThick=0.5
173 dfref saveDF = GetDataFolderDFR()
174 setdatafolder $package_path
176 svar s_preview_source
178 s_preview_file = filename
179 s_preview_source =
"" 180 wave /z preview_image
183 if (! svar_exists(s_file_info))
184 string /g s_file_info
186 if (strlen(s_preview_file) > 0)
213 Struct errorCode &errorCode
234 initStruct(errorCode)
236 #if exists("MFR_OpenResultFile")
238 if(V_flag != errorCode.
SUCCESS)
239 MFR_GetXOPErrorMessage
244 if(V_flag != errorCode.
SUCCESS)
245 MFR_GetXOPErrorMessage
249 MFR_GetBrickletMetaData
250 if(V_flag != errorCode.
SUCCESS)
251 MFR_GetXOPErrorMessage
294 variable
mtrx_parse_filename(
string fileName,
string* resultFile, variable* runCycle, variable* scanCycle,
string* channel){
301 variable fileType = 0
310 string extension =
"" 312 if (StringMatch(fileName,
"*.mtrx"))
313 regexp =
"(.+)_([[:digit:]]+)\.(.+)" 314 SplitString /E=regexp fileName, resultFile, index1, extension
317 regexp =
"(.+)--([[:digit:]]+)_([[:digit:]]+)\.((.+)_mtrx)" 318 SplitString /E=regexp fileName, resultFile, index1, index2, extension, channel
320 runCycle = str2num(index1)
321 scanCycle = str2num(index2)
339 regexp =
"([[:alpha:][:digit:]]+)[-_]([[:alpha:][:digit:]]+)[-_]([[:alpha:][:digit:]]+)[-_].+" 340 SplitString /E=regexp fileName, prefix, datepart, timepart
364 if (ParamIsDefault(df_base))
365 df_base = GetDataFolderDFR()
374 folderName =
"mtrx_" + datepart +
"_" + timepart
375 folderName = CleanupName(folderName, 0)
377 dfref df_save = GetDataFolderDFR()
379 newdatafolder /o /s $foldername
380 dfref df = GetDataFolderDFR()
382 setdatafolder df_save
405 dfr
mtrx_get_cycle_folder(dfref df_base = defaultValue, variable runCycle = defaultValue, variable scanCycle = defaultValue){
410 dfref df_save = GetDataFolderDFR()
412 if (ParamIsDefault(df_base))
413 df_base = GetDataFolderDFR()
415 if (ParamIsDefault(runCycle))
416 nvar /sdfr=df_pack defRunCycle = runCycle
417 runCycle = defRunCycle
419 if (ParamIsDefault(scanCycle))
420 nvar /sdfr=df_pack defScanCycle = scanCycle
421 scanCycle = defScanCycle
425 if ((runCycle >= 1) && (scanCycle >= 1))
426 sprintf dfname,
"r%us%u", runCycle, scanCycle
427 setdatafolder df_base
429 if (DataFolderRefStatus(df) == 0)
430 newdatafolder $dfname
437 setdatafolder df_save
467 dfref df_overview = NewFreeDataFolder()
472 string resultFileName
473 #if exists("MFR_OpenResultFile") 475 initStruct(errorCode)
477 sprintf resultFileName, "%s_%04u.mtrx
", resultFile, link 478 MFR_OpenResultFile /K resultFileName 479 if(V_flag != errorCode.SUCCESS) 482 MFR_CreateOverviewTable /DEST=df_overview 483 // dimension labels are: brickletID, scanCycleCount, runCycleCount, sequenceID, dimension, channelName 484 wave /t /sdfr=df_overview overviewTable 485 make /n=(dimsize(overviewTable, 0)) /i /u /free runcycles, scancycles, ids, match 486 make /n=(dimsize(overviewTable, 0)) /t /free channels 487 ids = str2num(overviewtable[p][%brickletID]) 489 runcycles = str2num(overviewtable[p][%runCycleCount]) 494 scancycles = str2num(overviewtable[p][%scanCycleCount]) 496 scancycles = scancycle 498 if (strlen(channel) > 0) 499 channels = overviewTable[p][%channelName] 503 Extract /FREE ids, match_ids, (scancycles == scanCycle) && (runcycles == runCycle) && (cmpstr(channels, channel) == 0) 504 if (numpnts(match_ids) > 0) 545 variable mtrx_open_file(string pathName, string fileNameOrPath){ 547 string fileNameOrPath 549 check_package_folder() 550 dfref df_save = GetDataFolderDFR() 551 dfref df_pack = $(package_path) 552 svar /sdfr=df_pack dataFilePath 553 svar /sdfr=df_pack resultFilePath 554 nvar /sdfr=df_pack runCycle 555 nvar /sdfr=df_pack scanCycle 556 svar /sdfr=df_pack channelName 557 nvar /sdfr=df_pack brickletID 559 string loc_resultFileName 560 string loc_resultFilePath 561 variable loc_runCycle 562 variable loc_scanCycle 563 string loc_channelName 565 // make sure we have a valid and complete file path 566 GetFileFolderInfo /P=$pathName /Q /Z=2 fileNameOrPath 568 if ((v_flag == 0) && (v_isFile)) 574 // get base file name 579 fileName = ParseFilePath(0, filePath, ":
", 1, 0) 580 fileDir = ParseFilePath(1, filePath, ":
", 1, 0) 581 fileType = mtrx_parse_filename(fileName, baseFileName, loc_runCycle, loc_scanCycle, loc_channelName) 586 variable using_cache = 0 588 struct errorCode errorCode 589 initStruct(errorCode) 591 sprintf loc_resultFileName, "%s_%04u.mtrx
", baseFileName, link 592 loc_resultFilePath = fileDir + loc_resultFileName 593 #if exists("MFR_OpenResultFile
") 594 if ((strlen(resultFilePath) == 0) || (cmpstr(loc_resultFilePath, resultFilePath) != 0)) 595 MFR_OpenResultFile /K loc_resultFilePath 596 if(V_flag != errorCode.SUCCESS) 597 MFR_GetXOPErrorMessage 601 resultFilePath = loc_resultFilePath 603 dataFilePath = filePath 611 MFR_CreateOverviewTable /DEST=df_pack 612 if(V_flag != errorCode.SUCCESS) 613 MFR_GetXOPErrorMessage 622 print "matrixfilereader.xop not installed
" 626 // dimension labels are: brickletID, scanCycleCount, runCycleCount, sequenceID, dimension, channelName 627 wave /t /sdfr=df_pack overviewTable 628 make /n=(dimsize(overviewTable, 0)) /i /u /o df_pack:runCycles, df_pack:scanCycles, df_pack:ids 629 make /n=(dimsize(overviewTable, 0)) /t /o df_pack:channels 630 wave /sdfr=df_pack ids, runCycles, scanCycles 631 wave /t /sdfr=df_pack channels 632 ids = str2num(overviewtable[p][%brickletID]) 633 runCycles = str2num(overviewtable[p][%runCycleCount]) 634 scanCycles = str2num(overviewtable[p][%scanCycleCount]) 635 channels = overviewTable[p][%channelName] 638 // if a data file is opened, make sure we found the right result file 639 if ((loc_runCycle > 0) && (loc_scanCycle > 0)) 640 Extract /FREE ids, match_ids, (runCycles == loc_runCycle) && (scanCycles == loc_scanCycle) && (cmpstr(channels, loc_channelName) == 0) 641 if (numpnts(match_ids) > 0) 643 runCycle = loc_runCycle 644 scanCycle = loc_scanCycle 645 channelName = loc_channelName 648 else if (using_cache) 682 string mtrx_load_preview(string destName, string pathName, string fileName, string traces = defaultValue){ 688 if (ParamIsDefault(traces)) 689 traces = "*Up;*Down;*ReUp;*ReDown;
" 692 dfref df_save = GetDataFolderDFR() 694 string datanames = "" 695 string datapaths = "" 696 variable filestatus = mtrx_open_file(pathName, fileName) 701 dfref df_pack = $(package_path) 702 svar /sdfr=df_pack dataFilePath 703 svar /sdfr=df_pack resultFilePath 704 nvar /sdfr=df_pack runCycle 705 nvar /sdfr=df_pack scanCycle 706 svar /sdfr=df_pack channelName 707 nvar /sdfr=df_pack brickletID 709 #if exists("MFR_OpenResultFile
") 710 dfref df_data = df_save 711 variable /g df_data:V_MatrixFileReaderOverwrite = 1 712 variable /g df_data:V_MatrixFileReaderFolder = 0 713 variable /g df_data:V_MatrixFileReaderDouble = 0 714 struct errorCode errorCode 715 initStruct(errorCode) 716 MFR_GetBrickletData /N=destName /R=(brickletID) /S=2 /DEST=df_data 717 if(V_flag == errorCode.SUCCESS) 718 datanames = S_waveNames 720 variable n = ItemsInList(datanames) 722 s = StringFromList(0, datanames) 724 mtrx_scale_dataset(data) 725 if (WaveDims(data) == 2) 726 subtract_line_bg(data) 728 datapaths = AddListItem(GetWavesDataFolder(data, 4), datapaths, ";
", inf) 729 for (i = 1; i < n; i += 1) 730 s = StringFromList(i, datanames) 734 MFR_GetXOPErrorMessage 736 //MFR_GetBrickletMetaData /N=ANickName /R=(brickletID) // /DEST=dfref 738 print "matrixfilereader.xop not installed
" 741 setdatafolder df_save 767 string mtrx_load_file(string pathName, string fileName, string traces = defaultValue){ 772 if (ParamIsDefault(traces)) 773 traces = "*Up;*Down;*ReUp;*ReDown;
" 776 dfref df_save = GetDataFolderDFR() 778 string datanames = "" 779 string datapaths = "" 780 variable filestatus = mtrx_open_file(pathName, fileName) 785 dfref df_pack = $(package_path) 786 svar /sdfr=df_pack dataFilePath 787 svar /sdfr=df_pack resultFilePath 788 nvar /sdfr=df_pack runCycle 789 nvar /sdfr=df_pack scanCycle 790 svar /sdfr=df_pack channelName 791 nvar /sdfr=df_pack brickletID 793 #if exists("MFR_OpenResultFile
") 794 string resultFileName = ParseFilePath(0, resultFilePath, ":
", 1, 0) 795 dfref df_result = mtrx_create_folder(resultFileName, df_base=df_save) 796 dfref df_data = mtrx_get_cycle_folder(df_base = df_result) 797 variable /g df_data:V_MatrixFileReaderOverwrite = 1 798 variable /g df_data:V_MatrixFileReaderFolder = 0 799 variable /g df_data:V_MatrixFileReaderDouble = 0 801 struct errorCode errorCode 802 initStruct(errorCode) 804 name = CleanupName(channelName, 0) 805 MFR_GetBrickletData /N=name /R=(brickletID) /DEST=df_data 806 if(V_flag == errorCode.SUCCESS) 807 datanames = S_waveNames 809 variable n = ItemsInList(datanames) 811 for (i = 0; i < n; i += 1) 812 s = StringFromList(i, datanames) 813 wave /sdfr=df_data data = $s 814 mtrx_scale_dataset(data) 815 datapaths = AddListItem(GetWavesDataFolder(data, 4), datapaths, ";
", inf) 818 MFR_GetXOPErrorMessage 820 //MFR_GetBrickletMetaData /N=ANickName /R=(brickletID) // /DEST=dfref 822 print "matrixfilereader.xop not installed
" 825 setdatafolder df_save 829 variable mtrx_scale_dataset(wave data){ 832 dfref df_pack = $(package_path) 833 nvar /sdfr=df_pack runCycle 834 nvar /sdfr=df_pack scanCycle 835 svar /sdfr=df_pack channelName 836 nvar /sdfr=df_pack brickletID 838 string scanDir = StringFromList(2, NameOfWave(data), "_
") 839 if (WaveDims(data) == 2) 840 Note data, "AxisLabelX=X
" 841 Note data, "AxisLabelY=Y
" 843 Note data, "AxisLabelD=
" + channelName 845 sprintf title, "%u-%u %s %s
", runCycle, scanCycle, channelName, scanDir 846 Note data, "Dataset=
" + title 863 string mtrx_load_info(string APathName, string AFileName){ 867 dfref saveDF = GetDataFolderDFR() 868 dfref fileDF = NewFreeDataFolder() 886 variable subtract_line_bg(wave img){ 889 variable nx = dimsize(img, 0) 890 variable ny = dimsize(img, 1) 892 make /n=(nx) /free line, fit 893 for (iy = 0; iy < ny; iy += 1) 895 if (numtype(sum(line)) == 0) 896 CurveFit /N /Q /NTHR=0 line line /D=fit 897 img[][iy] = line[p] - fit[p] static const string package_path
dfr mtrx_create_folder(string fileName, dfref df_base=defaultValue)
create or look up a data folder based on a matrix file name.
variable mtrx_file_brickletID(string resultFile, variable runCycle, variable scanCycle, string channel)
find out bricklet ID of a file
static variable initStruct(errorCode *errorCode)
from matrixfilereader help
string mtrx_split_filename(string fileName, string *prefix, string *datepart, string *timepart)
split a matrix filename and return the first three parts
variable matrix_preview_2d(wave data, wave metadata)
static wave preview_matrix_file(string filename)
load the preview of a Matrix data file
int32 INTERNAL_ERROR_CONVERTING_DATA
string mtrx_load_info(string APathName, string AFileName)
load descriptive info from a Matrix data file.
string matrix_format_elog_message(wave metadata)
generate elog message from bricklet metadata
from matrixfilereader help
variable mtrx_load_all()
load all data from a Matrix data file.
static const string ks_filematch_mtrx
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.
dfr mtrx_get_cycle_folder(dfref df_base=defaultValue, variable runCycle=defaultValue, variable scanCycle=defaultValue)
create a data folder for bricklet data.
static variable init_package()
initialize the package data folder.
variable mtrx_parse_filename(string fileName, string *resultFile, variable *runCycle, variable *scanCycle, string *channel)
parse matrix file names
string mtrx_load_preview(string destName, string pathName, string fileName, string traces=defaultValue)
load a preview image from a Matrix data file.
static variable BeforeFileOpenHook(variable refNum, string fileName, string path, string type, string creator, variable kind)
open a matrix file that was dropped into Igor.
static const string package_name
static variable check_package_folder()
check that the package data folder exists