#pragma rtGlobals=3 // use modern global access method and strict wave access. #pragma IgorVersion = 6.1 // minimum Igor version for this procedure //________________________________________________________________________________________________// // VAMAS file parser (XPS data) // version - 2014.05.29 //________________________________________________________________________________________________// Function LoadVMSdata(filePath) // parser for the VAMAS file format (incomplete specifications) String filePath // full path to file Variable refNum = 0 Open /R refNum as filePath // Open the file for reading if (refNum == 0) return -1 // Error opening file endif // extracted data String usercomment = "", scanmode = "", datetext = "" String source = "", EAmode = "" String Tspecies = "", Tlevel = "" String Xlabel = "", Xunit = "" Variable hv = 0, Epass = 0, workfkt = 0, dwell = 0, scans = 0 Variable Xstart = 0, Xstep = 1, points = 1 String currentline = "" Variable gencnt = 0, gennum = 0, datablocks = 0, sectioncounter = 0 // extract file header -------------- do // VAMAS head (ignoe blank lines) FReadLine refNum, currentline while (strlen(currentline) == 0) FReadLine refNum, currentline // institution FReadLine refNum, currentline // instrument model FReadLine refNum, currentline // operator FReadLine refNum, currentline // experiment descritption FReadLine refNum, currentline // number of comments gennum = str2num(currentline) // extract the number for (gencnt = 0; gencnt < gennum; gencnt += 1) FReadLine refNum, currentline // get comments usercomment += RemoveEnding(currentline,"\r") // save the comments endfor FReadLine refNum, currentline // experiement mode (MAP, MAPDP, NORM, or SDP) FReadLine refNum, currentline // scan mode (should be REGULAR) scanmode = RemoveEnding(currentline,"\r") FReadLine refNum, currentline // number of spectra datablocks = str2num(currentline) // extract the number // number of analysis positions, discrete x, and y coords only specified for experiment modes MAP and MAPDP FReadLine refNum, currentline // # experimental variables (=0) gennum = str2num(currentline) // extract the number for (gencnt = 0; gencnt < gennum; gencnt += 1) FReadLine refNum, currentline // variable description FReadLine refNum, currentline // variable unit endfor FReadLine refNum, currentline // relic line (=0) gennum = str2num(currentline) // extract the number if (gennum) Abort "Unsupported old file version." endif FReadLine refNum, currentline // # of manually entered items (=0) gennum = str2num(currentline) // extract the number for (gencnt = 0; gencnt < gennum; gencnt += 1) FReadLine refNum, currentline // read item endfor FReadLine refNum, currentline // # of future experiment upgrade entries (=0) gennum = str2num(currentline) // extract the number FReadLine refNum, currentline // # of future upgrade block entries (=0) for (gencnt = 0; gencnt < gennum; gencnt += 1) FReadLine refNum, currentline // read item endfor FReadLine refNum, currentline // number of data blocks (= # of spectra) gennum = str2num(currentline) // extract the number if (gennum != datablocks) Abort "Read error." endif // end of file header -------------- for (sectioncounter = 0; sectioncounter < datablocks; sectioncounter +=1) // extract block header -------------- FReadLine refNum, currentline // block identifier FReadLine refNum, currentline // sample identifier datetext = "" FReadLine refNum, currentline // year sprintf datetext, datetext+"%.4d-", str2num(currentline) // write year FReadLine refNum, currentline // month sprintf datetext, datetext+"%.2d-", str2num(currentline) // write month FReadLine refNum, currentline // day sprintf datetext, datetext+"%.2d ", str2num(currentline) // write day Variable RawTime = 0 FReadLine refNum, currentline // hour RawTime += str2num(currentline)*60*60 // write hour FReadLine refNum, currentline // minute RawTime += str2num(currentline)*60 // write minute FReadLine refNum, currentline // seconds RawTime += str2num(currentline) // write seconds FReadLine refNum, currentline // GMT offset datetext += Secs2Time(RawTime,3) // convert to string FReadLine refNum, currentline // comments again gennum = str2num(currentline) // extract the number for (gencnt = 0; gencnt < gennum; gencnt += 1) FReadLine refNum, currentline // get comments endfor FReadLine refNum, currentline // technique (XPS) FReadLine refNum, currentline // light source source = RemoveEnding(currentline,"\r") FReadLine refNum, currentline // light source energy hv = str2num(currentline) FReadLine refNum, currentline // light source strength FReadLine refNum, currentline // light source x width FReadLine refNum, currentline // light source y width FReadLine refNum, currentline // light source incident angle (polar) FReadLine refNum, currentline // light source incident angle (azimuth) FReadLine refNum, currentline // analyzer mode (FAT or CAE) EAmode = RemoveEnding(currentline,"\r") FReadLine refNum, currentline // analyzer pass energy or retardation Epass = str2num(currentline) FReadLine refNum, currentline // analyzer magnification FReadLine refNum, currentline // analyzer work function workfkt = str2num(currentline) FReadLine refNum, currentline // targetBias FReadLine refNum, currentline // analysis x width FReadLine refNum, currentline // analysis y width FReadLine refNum, currentline // analyzer axis take off (polar) FReadLine refNum, currentline // analyzer axis take off (azimuth) FReadLine refNum, currentline // sample species Tspecies = RemoveEnding(currentline,"\r") FReadLine refNum, currentline // species level Tlevel = RemoveEnding(currentline,"\r") FReadLine refNum, currentline // charge of detected particle (-1 for electron) if (stringmatch(scanmode, "REGULAR")) FReadLine refNum, currentline // x axis label Xlabel = RemoveEnding(currentline,"\r") FReadLine refNum, currentline // x axis unit Xunit = RemoveEnding(currentline,"\r") FReadLine refNum, currentline // x axis start Xstart = str2num(currentline) FReadLine refNum, currentline // x axis increment Xstep = str2num(currentline) endif FReadLine refNum, currentline // corresponding y axes (should be 1) FReadLine refNum, currentline // y axis label FReadLine refNum, currentline // y axis unit FReadLine refNum, currentline // signal mode FReadLine refNum, currentline // dwell dwell = str2num(currentline) FReadLine refNum, currentline // # of scans scans = str2num(currentline) FReadLine refNum, currentline // signal time correction FReadLine refNum, currentline // sample angle (tilt, polar) FReadLine refNum, currentline // sample angle (tilt, azimuth) FReadLine refNum, currentline // sample angle (rotation) FReadLine refNum, currentline // # of additional parameters (= 0) FReadLine refNum, currentline // # of values points = str2num(currentline) FReadLine refNum, currentline // min y FReadLine refNum, currentline // max y // end of block header --------------- Make/O/D/N=(points) TempLoadWave // create wave for data loading SetScale/P x Xstart, Xstep,Xunit, TempLoadWave for (gencnt = 0; gencnt < points; gencnt += 1) // extract data FReadLine refNum, currentline TempLoadWave[gencnt] = str2num(currentline) / scans endfor String dataname = ParseFilePath(3, filePath, ":", 0, 0) // append experiment note String DataNotes = "scan data " + dataname DataNotes += "\rfinished on " + datetext DataNotes += "\renergy mode=" + Xlabel DataNotes += "\ranalyzer mode=" + EAmode DataNotes += SelectString(stringmatch(EAmode,"CAE"),"\rpass energy=","\rretardation=") + num2str(Epass) + SelectString(stringmatch(EAmode,"CAE")," eV","") DataNotes += "\rwork function=" + num2str(workfkt) + " eV" DataNotes += "\rstart energy=" + num2str(Xstart) + " " + Xunit DataNotes += "\rend energy=" + num2str(Xstart+Xstep*(points-1)) + " " + Xunit DataNotes += "\renergy step=" + num2str(Xstep) + " " + Xunit DataNotes += "\rstep dwell=" + num2str(dwell) + " ms" DataNotes += "\rfull sweeps=" + num2str(scans) DataNotes += "\rXray source=" + source DataNotes += "\rXray energy=" + num2str(hv) if (strlen(usercomment) > 0) DataNotes += "\rnotes=" + usercomment endif DataNotes += "\rSpecies=" + Tspecies DataNotes += "\rEnergy level=" + Tlevel Note/K TempLoadWave, DataNotes dataname = dataname[0,30-strlen(Tspecies+Tlevel)-1] + "_" + Tspecies + Tlevel // watch out that the name doesn't get longer than 31 chars Duplicate/O TempLoadWave, $dataname KillWaves TempLoadWave endfor Close refNum return 0 End