#pragma TextEncoding = "UTF-8" #pragma rtGlobals=3 #pragma version=1.01b // generic text file (GTF) loader // https://www.wavemetrics.com/user/tony // GUI for choosing files to load and editing the names of waves to be created. static constant kNwaves=3 // number of waves to load from each file static constant kOptionalX=2 // make one of the columns optional (column number, 1-based). menu "Macros" // a better place to put this would be in the Load Waves menu. "Load lots of text files...", /Q, MakeGTFLoaderPanel() end function MakeGTFLoaderPanel() dowindow /k GTFLoaderPanel NewDataFolder /O root:Packages NewDataFolder /O root:Packages:GTF DFREF dfr=root:Packages:GTF variable nColumns=1+kNwaves+(kOptionalX>0) variable success make /o /n=(0,nColumns)/T dfr:w_newList /WAVE=w_newList make /o/W/U /n=(3,5) dfr:w_color/WAVE=w_color w_color={{0,0,0},{65535,0,0},{39321,39321,39321},{0,0,65535},{0,65535,65535}} MatrixTranspose w_color // easier to enter as 3 rows, 5 cols make /o /n=(0,nColumns,3) dfr:w_selection /WAVE=w_selection SetDimLabel 2,1,backColors,w_selection // define plane 1 as background colors SetDimLabel 2,2,foreColors,w_selection make /o /n=(nColumns) /T dfr:w_titles /wave=w_titles w_titles="" w_titles[0]="file" if(kOptionalX) w_titles[kOptionalX]="x?" endif w_titles=selectstring(stringmatch(w_titles, ""), w_titles, "output") string /G dfr:s_edit="" success=GTFselectFiles() if(!success) return 0 endif GTFSanityCheck() NewPanel /K=1/N=GTFLoaderPanel/W=(20,20,710,380) as "GTF Loader" ModifyPanel /W=GTFLoaderPanel fixedSize=1, noedit=1 button buttonSelectFiles win=GTFLoaderPanel, pos={10,10},size={80,20},title="select files", proc=GTFButtons setvariable setvarLen win=GTFLoaderPanel, fsize=12, pos={450,10},size={230,20},title="character limit for wave names:",value=_NUM:29, limits={10,29,1}, proc=GTFSetvar ListBox listboxOut,win=GTFLoaderPanel, mode=9, selwave=w_selection, titlewave=w_titles, pos={10, 40},size={670, 280}, editstyle=1 ListBox listboxOut,win=GTFLoaderPanel, colorwave=w_color, listwave=w_newList, fsize=12, proc=GTFListBox, userColumnResize=1 ListBox listboxOut,win=GTFLoaderPanel, widths={10,2} Button buttonDoIt win=GTFLoaderPanel,pos={630,330},size={50,20},title="Do It", proc=GTFButtons Button buttonCancel win=GTFLoaderPanel,pos={560,330},size={60,20},title="Cancel", proc=GTFButtons end function GTFSetVar(s) : SetVariableControl STRUCT WMSetVariableAction &s if(s.eventCode==-1) return 0 endif if(stringmatch(s.ctrlName, "setvarLen")) GTFSanityCheck() endif end function GTFButtons(ba) STRUCT WMButtonAction &ba DFREF dfr=root:Packages:GTF wave /T w_newList=dfr:w_newList wave w_selection=dfr:w_selection wave w_color=dfr:w_color variable i, j if(ba.eventCode!=2) return 0 endif if(stringmatch(ba.ctrlName, "buttonSelectFiles")) variable success=GTFselectFiles() if(!success) return 0 endif GTFSanityCheck() elseif(stringmatch(ba.ctrlName, "buttonDoIt")) // ------ code for loading waves goes here ------ string columnInfoStr="" for(i=0;i0) redimension /N=(itemsinlist(S_fileName,"\r"), nColumns) w_newList redimension /n=(itemsinlist(S_fileName,"\r"),nColumns,3) w_selection w_newList[][0]=stringfromlist(p,S_fileName,"\r") variable count=0 j=1 do // j is column count //count=0 if(j!=kOptionalX) w_newList[][j]=parsefilepath(3, stringfromlist(p,S_fileName,"\r"), ":", 0,0) w_newList[][j]=selectstring (strlen(w_newList[p][j])>28, w_newList[p][j], (w_newList[p][j])[0,27]) w_newList[][j]=cleanupname(w_newList[p][j],0) if(kOptionalX && (j==(kOptionalX+1))) w_newList[][j]+="_x" else if(count) w_newList[][j]+="_"+num2str(count) endif count+=1 endif w_selection[][j][0]=2 endif j+=1 while(jv_value, listWave[p][q], (listWave[p][q])[0,v_value-1]) // i = row count, j = remaining row count, k = column count, m = remaining column count for (i=0; i