LoadWave Combining Date and Time

This snippet is an answer to http://www.igorexchange.com/node/1537.

The snippet loads the following data file:

dist_1:BL_XAS
Datum;Zeit;Z[mm];I1;I2;I3;I4
27.05.2010;09:00:00;9.37;0.00;0.00;0.00;0.00
27.05.2010;09:00:10;9.30;0.00;0.00;0.00;0.00
27.05.2010;09:00:20;9.28;0.00;0.00;0.00;0.00
27.05.2010;09:00:30;9.18;0.00;0.00;0.00;0.00
27.05.2010;09:00:40;9.09;0.00;0.00;0.00;0.00


The snippet illustrates several techniques such as using the LoadWave/B flag to specify wave names, handling a special column separator (semicolon in this case - /V flag), specifying the date format (/R flag) and combining date and time after loading.

The first two lines are ignored. The names are hard-coded into the loading routine. After loading the waves, the date and time wave are combined and the time wave is killed.

Menu "Load Waves"
    "Load Mangold File...", LoadMangoldFile("", "") // Display Open File dialog and load one file
End

Function LoadMangoldFile(fileName, pathName)
    String pathName             // Name of symbolic path or "" for dialog
    String fileName                 // Name of data file or "" for dialog
   
    Variable refNum

    // First get a valid reference to a file.
    if ((strlen(pathName)==0) || (strlen(fileName)==0))
        // Display dialog looking for file.
        Open/D/R/P=$pathName/M="Select Mangold data file" refNum as fileName
        fileName = S_fileName       // S_fileName is set by Open/D
        if (strlen(fileName) == 0)  // User cancelled?
            return -1
        endif
    endif
   
    String columnInfoStr = "N=Datum,F=6;N=Zeit,F=7;N=Zmm;N=I1;N=I2;N=I3;N=I4;"
   
    // /J specifies Load Delimited Text
    // /A means "auto-name & go" (don't display dialog asking user to confirm column names)
    // /L says the first data line is line 2 (zero-based)
    // /V sets the column separator as semicolon
    // /B sets column names and formats
    // /R sets the date format
    LoadWave /P=$pathName /J /A /L={0, 2, 0, 0, 0} /V={";", "", 0, 0} /B=columnInfoStr /R={German,2,2,2,2,"DayOfMonth.Month.Year",40} fileName
    if (V_flag < 7)
        Print "User Cancelled or Error Occurred"
        return -1;
    endif
   
    Wave Datum, Zeit
    Datum += Zeit               // Add time to date
    KillWaves/Z Zeit                // We don't need time anymore
   
    String title = ParseFilePath(3, S_fileName, ":", 0, 0)      // Remove extension from file name
    Edit /W=(9,47,674,304) Datum, Zmm, I1, I2, I3, I4 as title
    ModifyTable format(Datum)=8, width(Datum)=120
End
made some small changes to make the read-in more unified for the read-in of several types of PVSS Log files.

Menu "Load Waves"
    "Load PVSSLog File...", LoadPVSSLogFile("", "") // Display Open File dialog and load one file
End
 
Function LoadPVSSLogFile(fileName, pathName)
    String pathName             // Name of symbolic path or "" for dialog
    String fileName                 // Name of data file or "" for dialog
 
    Variable refNum
 
    // First get a valid reference to a file.
    if ((strlen(pathName)==0) || (strlen(fileName)==0))
        // Display dialog looking for file.
        Open/D/T="????"/R/P=$pathName/M="Select PVSS data file" refNum as fileName
        fileName = S_fileName       // S_fileName is set by Open/D
        if (strlen(fileName) == 0)  // User cancelled?
            return -1
        endif
    endif
 
    String columnInfoStr = "N=Datum,F=6;N=Zeit,F=7;N=Zmm;N=I1;N=I2;N=I3;N=I4;"
 
    // /J specifies Load Delimited Text
    // /A means "auto-name & go" (don't display dialog asking user to confirm column names)
    // /L says the first data line is line 2 (zero-based)
    // /V sets the column separator as semicolon
    // /B sets column names and formats
    // /R sets the date format
    //LoadWave /P=$pathName /J /A /L={0, 2, 0, 0, 0} /V={";", "", 0, 0} /B=columnInfoStr /R={German,2,2,2,2,"DayOfMonth.Month.Year",40} fileName
    LoadWave /A/O/W/P=$pathName /J /L={1, 2, 0, 0, 0} /V={";", " ", 0, 0} /R={German,2,2,2,2,"DayOfMonth.Month.Year",40} fileName
    if (V_flag < 3)
        Print "User Cancelled or Error Occurred"
        return -1;
    endif
 
    Wave Datum, Zeit
    Datum += Zeit               // Add time to date
    KillWaves/Z Zeit                // We don't need time anymore
 
    String title = ParseFilePath(3, S_fileName, ":", 0, 0)      // Remove extension from file name
    String titleG
    titleG = title + "_G"
    string WavesLoaded
    WavesLoaded = WaveList("*",";","")
    string WavesToTable
   
    dowindow/K $title
    dowindow/K $titleG
   
    Variable i=0
    do
        WavesToTable= StringFromList(i,WavesLoaded)
        if( strlen(WavesToTable) == 0 )
            if(i!=1)
                break
            endif
        endif
        if(i==0)
            Edit /W=(9,47,674,304) $WavesToTable as title
            dowindow/C $title
            ModifyTable format(Datum)=8, width(Datum)=120
        else
            appendtotable $WavesToTable
            if(i==1)
                display $WavesToTable vs Datum as titleG
                dowindow/C $titleG
                Legend/C/N=text0/F=0/A=MC
            elseif(i>1)
                appendtograph $WavesToTable vs Datum
            endif
        endif
       
        setcolor()
       
        i += 1
    while (1)   // exit is via break statement

   
    //Edit /W=(9,47,674,304) Datum, Zmm, I1, I2, I3, I4 as title
    //ModifyTable format(Datum)=8, width(Datum)=120
End

function setcolor()
    string trl=tracenamelist("",";",1), item
    variable items=itemsinlist(trl), i
    //variable ink=103/(items-1)
    variable ink=256/(items-1)
    colortab2wave SpectrumBlack
    wave/i/u M_colors
    for(i=0;i<items;i+=1)
        item=stringfromlist(i,trl)
        //ModifyGraph rgb($item)=(M_colors[140+i*ink][0],M_colors[140+i*ink][1],M_colors[140+i*ink][2])
        ModifyGraph rgb($item)=(M_colors[i*ink][0],M_colors[i*ink][1],M_colors[i*ink][2])
    endfor
    killwaves/z M_colors
end

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More