#pragma TextEncoding = "UTF-8" #pragma rtGlobals = 1 // no wave range checking #pragma IgorVersion = 8.0 #pragma DefaultTab = {3,20,4} // set default tab width in Igor Pro 9 and later //________________________________________________________________________________________________ // *** quick normalization *** //________________________________________________________________________________________________ function NormTo1(wave inwave,[variable pos, variable toarea]) variable normval = ParamIsDefault(pos) ? wavemin(inwave) : inwave(pos) inwave -= normval MatrixOP/Free temp = replaceNaNs(inwave,0) normval = (!ParamIsDefault(toarea) && toarea == 1) ? area(temp) : wavemax(temp) inwave /= normval end //________________________________________________________________________________________________ // *** quick renaming of waves *** //________________________________________________________________________________________________ static function QuickRenameWrapper() string this, that; variable overwrite = 0 Prompt this, "Replace this (insert: pre = prepend; suf = append): " Prompt that, "With this: " Prompt overwrite, "Keep original?", popup, "No;Yes, try to copy item;Yes, copy and overwrite;" DoPrompt "Replace Part of the Name", this, that, overwrite if (!V_Flag) QuickRename(this, getSortedSelection(), that, copy=(overwrite-1)) endif end //------------------------------------------------------------------------------------------------ static function/S getSortedSelection() Make/free/T/N=0 select Make/free/N=0 order int i = 0 do string name = GetBrowserSelection(i++) if (!strlen(name)) break endif select[numpnts(select)] = {name} order[numpnts(order)] = {ItemsInList(name,":")} while(1) if (!DimSize(select,0)) return "" endif Sort/R order, select string list; wfprintf list, "%s;", select return list end //################################################################################################ function QuickRename(string this, string list, string withthis, [variable copy]) variable i, copyItem = !ParamIsDefault(copy) ? copy : 0 // copy: 0 = don't keep original; 1 = try copy but don't overwrite; 2 = copy and overwrite for (i = 0; i < ItemsInList(list); i++) string NewName = "", OldName = "", inFolder = "", name = StringFromList(i,list) wave/Z work = $name int isWave = WaveExists(work) if (!isWave) if (!CmpStr(name,"root:")) continue endif OldName = ParseFilePath(0, name, ":", 1, 0) inFolder= ParseFilePath(1, name, ":", 1, 0) else OldName = NameOfWave(work) endif if (StringMatch(this,"pre")) NewName = withthis+OldName elseif (StringMatch(this,"suf")) NewName = OldName+withthis else NewName = ReplaceString(this,OldName,withthis) endif if (isWave) wave/Z test = $(SelectString(strlen(inFolder),"root:",inFolder)+NewName) Switch(copyItem) case 0: if (!WaveExists(test)) Rename $Name, $NewName endif break case 1: if (!WaveExists(test)) Duplicate $Name, $NewName endif break case 2: Duplicate/O $Name, $NewName break EndSwitch else NewName = PossiblyQuoteName(ReplaceString("'",NewName,"")) Switch(copyItem) case 0: KillDataFolder/Z $(inFolder+NewName) DFREF testDir = $(inFolder+NewName) if (DataFolderRefStatus(testDir) == 0) RenameDataFolder $(inFolder+OldName), $(ReplaceString("'",NewName,"")) endif break case 1: DFREF testDir = $(inFolder+NewName) if (DataFolderRefStatus(testDir) == 0) DuplicateDataFolder $(inFolder+OldName), $(inFolder+NewName) endif break case 2: DuplicateDataFolder/O=3 $(inFolder+OldName), $(inFolder+NewName) break EndSwitch endif endfor return 0 end