#pragma rtGlobals=1 // Use modern global access method. Menu "Data" "Load Inelastic Dumps",LoadInelasticDump("","","") End Menu "Load Waves" "Load Inelastic Dumps",LoadInelasticDump("","","") End Menu "Graph" "Inelastic Dump Style",InelasticDumpGraphStyle() End Function/S LoadInelasticDump(path,fileName,range) String path // igor file path to dumped file String fileName // name of dump file (full or partial relative to path) String range // range of scan to be loaded, if "", then put up dialog to choose if (strlen(path)<1) PathInfo dump if (V_flag) path = "dump" else path = "home" endif endif Variable refNum=0 Open/Z=1/R/P=$path refNum as fileName // try to open the file as passed if (V_flag) Open/Z=2/R/M="dumped data file"/P=$path refNum // select a fie and open it if (V_flag==-1) return "" endif endif if (strlen(S_fileName)<1) Abort "could not open the file '"+fileName+"'" endif S_fileName = ParseFilePath(5,S_fileName,":",0,0) // convert to mac style separators fileName = ParseFilePath(3,S_fileName,":",0,0) // get just the filename part, none of the path String line, expFile="",str FReadLine refNum, line Variable i = strsearch(line,"From Igor Experiment '",0) if (i<0) DoAlert 0, "Invalid dump file" Close refNum return "" endif expFile = line[22,Inf] i = strsearch(expFile,"'",0) if (i<1) DoAlert 0, "Invalid dump file" Close refNum return "" endif expFile = expFile[0,i-1] if (strlen(range)>0) // search file for the range str = ";range="+range+";" do // search for range in line starting with "DATAFILE=" FReadLine refNum, line if (strlen(line)<1) // EOF, quit hunting Close refNum return "" elseif (strsearch(line,str,0)>0) // break when found correct range break endif while(1) else // 'range' not given, so make list and put up dialog FSetPos refNum,0 // go up to top of file String chi,promptStr="" Variable Q str = ";range="+range+";" do // search for range in line starting with "DATAFILE=" FReadLine refNum, line if (strlen(line)<1) // EOF, quit hunting break elseif (strsearch(line,"DATAFILE=",0)==0) // check for info string at start of wave if (strlen(StringByKey("range",line,"="))<1) continue endif promptStr += "range="+StringByKey("range",line,"=") Q = NumberByKey("Q_Angstrom",line,"=") if (Q>0) sprintf str," Q=%.2f",Q promptStr += str endif chi = StringByKey("chi",line,"=") if (strlen(chi)) promptStr += " chi="+chi endif promptStr += " "+StringByKey("COMMENT",line,"=") promptStr += ";" endif while(1) if (strlen(promptStr)<1) DoAlert 0, "no valid waves found in file '"+fileName+"'" Close refNum return "" endif String fileId Prompt fileId,"file to load",popup,promptStr DoPrompt "file",fileId if (V_flag) Close refNum return "" endif // goto start of range str = ";"+fileId[0,strsearch(fileId," ",0)-1]+";" FSetPos refNum,0 // go up to top of file do // search for range in line starting with "DATAFILE=" FReadLine refNum, line if (strlen(line)<1) // EOF, quit hunting Close refNum return "" elseif (strsearch(line,str,0)>0) // check for correct range break endif while(1) range = StringByKey("range",line,"=") endif if (strlen(range)<1) DoAlert 0, "Unable to find wave to load" Close refNum return "" endif String noteStr = line FReadLine refNum, line String xName="",yName="", xUnits="",yUnits="" xName = StringFromList(0,line,"\t") yName = StringFromList(1,line,"\t") yName = RemoveEnding(yName,"\r") i = strsearch(xName,"[",0) if (i>=0) xUnits=xName[i+1,Inf] xName = xName[0,i-1] i = strsearch(xUnits,"]",0) xUnits = xUnits[0,i-1] endif i = strsearch(yName,"[",0) if (i>=0) yUnits=yName[i+1,Inf] yName = yName[0,i-1] i = strsearch(yUnits,"]",0) yUnits = yUnits[0,i-1] endif Variable r1,r2 r1 = str2num(range) r2 = lastInRange(range) xName = xName+"_"+expFile+"_"+num2istr(r1) yName = yName+"_"+expFile+"_"+num2istr(r1) if (r1!=r2) xName = xName+"_"+num2istr(r2) yName = yName+"_"+num2istr(r2) endif xName = ChangePartsOfString(xName,"(","") xName = ChangePartsOfString(xName,")","") xName = ChangePartsOfString(xName,",","") yName = ChangePartsOfString(yName,"(","") yName = ChangePartsOfString(yName,")","") yName = ChangePartsOfString(yName,",","") xName = CleanupName(xName,0) yName = CleanupName(yName,0) xName = ChangePartsOfString(xName,"__","_") yName = ChangePartsOfString(yName,"__","_") Variable length=1000 String fldrSav = GetDataFolder(1) NewDataFolder/O/S root:dumped String/G lastDumpFile=fileName NewPath /O/Q/Z dump, ParseFilePath(1,S_fileName,":",1,0) Make/N=(length)/O $xName,$yname Wave xw=$xName, yw=$yName SetScale d 0,0,xUnits, xw SetScale d 0,0,yUnits, yw Note/K xw Note xw, noteStr Note/K yw Note yw, noteStr SetDataFolder $fldrSav Variable N=0,xx,yy do FReadLine refNum, line sscanf line, "%g\t%g",xx,yy if (V_flag!=2) break endif if (N>=length) length += 1000 Redimension/N=(length) xw,yw endif xw[N] = xx yw[N] = yy N += 1 while(1) Redimension/N=(N) xw,yw if (ItemsInList(GetRTStackInfo(0))<2) printf "Loaded dump of Igor experiment '%s', range='%s'\r",expFile,range printf "to graph it use: Display %s vs %s\r",GetWavesDataFolder(yw,2),GetWavesDataFolder(xw,2) Variable plot Prompt plot,"plot this data?",popup,"Display in New Graph;Append to Top Graph;Do Not Plot" DoPrompt "plot",plot if (plot==3 || V_flag) return GetWavesDataFolder(yw,2)+";"+GetWavesDataFolder(xw,2) elseif (plot==2) AppendToGraph yw vs xw else Display yw vs xw endif Execute "InelasticDumpGraphStyle()" // if (exists("DumpInelasticGraphStyle")==5 || exists("DumpInelasticGraphStyle")==6) // Execute "DumpInelasticGraphStyle()" // else // DumpInelasticGraphStyleDefault() // endif endif return GetWavesDataFolder(yw,2)+";"+GetWavesDataFolder(xw,2) End Proc InelasticDumpGraphStyle() : GraphStyle if (exists("DumpInelasticGraphStyle")==5 || exists("DumpInelasticGraphStyle")==6) Execute "DumpInelasticGraphStyle()" else DumpInelasticGraphStyleDefault() endif End Function DumpInelasticGraphStyleDefault() : GraphStyle ModifyGraph gfSize=12, tick=2, minor=1, standoff=0, lowTrip=0.001, mirror=1 ModifyGraph axOffset(left)=-1.8,axOffset(bottom)=-0.8 String yName = TraceNameList("",";",1) if (strsearch(yName,"Sqw",2)) Label left "s(\\f02q\\f00,\\F'Symbol'\\f02w\\f00\\F]0) (\\e eV\\S -1 \\M\\S-3\\M)" elseif (strsearch(yName,"I_Io",2)) Label left "detector / I\\Bo\\M (\\E)" else Label left "" endif Label bottom "ÆE (\\U)" ModifyGraph/Z mode[0]=4,marker=19,msize=3,lstyle=1,rgb[0]=(0,0,65535) ModifyGraph zero=2 if (WhichListItem("legend0", AnnotationList(""))<0) Legend/K/N=legend0 Legend/C/N=legend0/S=3 endif String text=StringByKey("TEXT", AnnotationInfo("","legend0")) String line, find, newText="" String wName="" Variable Q,m=-2 do text = text[m+2,Inf] if (strlen(text)<1) break endif m = strsearch(text,"\\r",m) m = (m<0) ? strlen(text) : m line = text[0,m-1] sscanf line[3,inf],"(%s)",wName wName = RemoveEnding(wName,")") sprintf find,"\\\\s(%s) %s",wName,wName if (stringmatch(line,find)) Wave wav=TraceNameToWaveRef("",wName) Q = NumberByKey("Q_Angstrom", note(wav),"=") sprintf line,"\s(%s) Q=%.2f (\\S-1\\M) \Z09%s\M",wName,Q,wName endif line = ReplaceString("\\\\", line,"\\") if (strlen(newText)) newText += "\r" endif newText += line while(1) Legend/C/N=legend0/S=3 newText // Variable chi = specInfo(str2num(range),"chi") // if (abs(chi-90)>.5) // String str // sprintf str "\\F'Symbol'Dc\\F]0 = %g¡",90-chi // AppendText str // endif End Static Function/T ChangePartsOfString(str,delim,new) String str String delim String new Variable id=strlen(delim) Variable i do i = strsearch(str,delim,0 ) if (i>=0) str[i,i+id-1] = new endif while(i>=0) return str End Static Function lastInRange(range) String range Variable last,c,i = strlen(range)+1 do i -= 1 c = char2num(range[i-1]) while(c>=48 && c<=57 && i>0) // a digit, continue last=str2num(range[i,Inf]) if (c==45) if (i==1) return -last endif c = char2num(range[i-2]) // char preceeding minus sign if (c==45 || c==44) return -last endif endif return last End // this is an example of the top of a dump file // From Igor Experiment 'nio12', dumped Wed, Oct 6, 2004, 11:14:28 AM // // // // DATAFILE=./data/nio12;DATE=Sun, Jul 18, 2004;range=1;Q_Angstrom=3.5005;COMMENT=NiO (111) [(004)+(111)]); // dE[eV] S(q,w)[eV^-1 Angstrom^-3] // -0.983601 0.00230401 // -0.883601 0.00230537 // -0.783601 0.00049234