EliotGann / QANT

6 stars 7 forks source link

SST_XDAC metadata changed for cycle 2023_3 #6

Open BijalBPatel opened 11 months ago

BijalBPatel commented 11 months ago

It looks like the metadata changed for the SST1 NEXAFS chamber between cycle 2023_2 and 2023_3.

Description of Issue: It breaks scan name and angle parsing for the QANT browser window:

image

Note: the data processing still works fine.

Root Cause of the Problem Another bit of text was added into the line that contains sample name, angle, and bias:

BijalBPatel commented 11 months ago

Proposed Solution [Live on the RSoXS Analysis PC at BNL]

To preserve compatibility with old data, I'd like to add a new filetype descriptor "SST_XDAC20233" by adding these functions to the 'QANT.ipf' file.

Its just a clone of the SST_XDAC implementation, with a revised grep and RegEx for the splitString command.

function /s QANT_NEXAFSfileEXt_SST_XDAC20233() // BP Revised XDAC after 2023-3 (new metadata in filename line)
    string pathn
    return "????"
end
function /s QANT_LoadNEXAFSfile_SST_XDAC20233(pathn) // BP Revised XDAC after 2023-3 (new metadata in filename line)
    string pathn
    variable fileref
    open/r/F="NEXAFS files (*.*,):*.*;" fileref as pathn
    string fullpath = s_filename
    FStatus fileref
    if(V_flag==0)
        return ""
    endif
    close fileref

    string scantime, scanname
    grep/Q/LIST/E="created on " fullpath
    splitstring /e="^\"([^\"]*)\" created on (.*) on 07-ID1" s_value, scanname, scantime

    if(strlen(scantime)<1)
        return ""
    endif

    string foldersave = getdatafolder(1)

    setdatafolder root:
    newdatafolder /O/S NEXAFS

    wave /T QANT_LUT
    newdatafolder /O/S Scans
    newdatafolder /O/S $cleanupname(scanname,0)

    killwaves /Z/A
    string /g filename = fullpath
    getfilefolderinfo /p=NEXAFSPath /q/z scanname
    string /g filesize
    sprintf filesize, "%d" ,v_logEOF
    string /g cdate
    sprintf cdate, "%d" ,v_creationdate
    string /g mdate
    sprintf mdate, "%d" ,v_modificationdate
    string syear, smonth, sday, shour, sminute, ssecond, sampm

    splitstring /e="^([1234567890]{1,2})/([1234567890]{1,2})/([1234567890]{4}) at ([1234567890]{1,2}):([1234567890]{2}):([1234567890.]*) ([A|P]M)" scantime, smonth, sday, syear, shour, sminute,ssecond,sampm

    variable year = str2num(syear)
    variable month = str2num(smonth)
    variable day = str2num(sday)
    variable hour = str2num(shour)
    hour += stringmatch(sampm,"AM")? 0 : 12
    variable minute = str2num(sminute)
    variable second = str2num(ssecond)

    string /g acqtime = num2str(year) + " " + num2str(month) + " " + num2str(day) + " " + num2str(hour)+":" + num2str(minute) +":" + num2str(second)

    string samp, angle, ecc,  bias
    //grep/Q/LIST/E="/Angle [1234567890]*/Bias" fullpath
    grep/Q/LIST/E="/Angle [1234567890]*" fullpath
    splitstring /e="^([^/]*)/Angle ([-.1234567890]*)/ecc ([-.1234567890]*)uA/Bias ([-.1234567890]*)" s_value, samp, angle, ecc, bias

    string notes2add =""

    grep/Q/LIST/E="XDAC" fullpath
    notes2add += s_value
    grep/Q/LIST/E="created on" fullpath
    notes2add += " - " +  s_value
    grep/Q/LIST/E="element" fullpath
    notes2add += " - " + s_value

    string /g notes = notes2add
    string /g anglestr = angle
    string /g otherstr = bias
    string /g EnOffsetstr = ""
    string /g SampleName = samp
    string /g SampleSet
    if(strlen(SampleSet)*0!=0)
        SampleSet = ""
    endif
    string /g refscan
    if(strlen(refscan)*0!=0)
        refscan = "Default"
    endif
    string /g darkscan
    if(strlen(darkscan)*0!=0)
        darkscan = "Default"
    endif
    string /g enoffset
    if(strlen(enoffset)*0!=0)
        enoffset = "Default"
    endif
    grep /INDX /Q /E="-----------------------" fullpath
    wave /z w_index
    if(w_index[0] < 1)
        setdatafolder ::
        killdatafolder /z $cleanupname(scanname,1)
        return ""
    endif
    try
        LoadWave/o/J/D/W/A/K=1/Q/V={"\t, "," $",0,2}/L={w_index[0]+1,w_index[0]+2,0,0,0} filename
    catch
        setdatafolder ::
        killdatafolder /z $cleanupname(scanname,1)
        return ""
    endtry
    wave /z Energy
    if(waveexists(Energy))
        duplicate Energy, EnergySetpoint
        string listofwaves = addlistitem("EnergySetpoint",S_wavenames)
        listofwaves = removelistitem(whichlistitem("Blank", listofwaves),listofwaves)
    else
        listofwaves = S_wavenames
    endif
    Make/ n=(itemsinlist(S_waveNames)) /T ColumnNames = stringfromlist(p,S_waveNames)

    setdatafolder foldersave
    print "Loaded NEXAFS file : " + cleanupname(scanname,1)
    return  cleanupname(scanname,1)
end