'changefreq.s2s '---------------------------------------------------- ' C h a n g e f r e q S c r i p t ' 'This script allows you to convert a file from a 'near-1kHz sample frequency to an exactly-1kHz sample 'frequency. This is done with the ChanSave() command 'which interpolates the data points when a channel is 'copied between files with different '"microseconds per unit time". That is set in the 'sampling configuration or with FileNew(). ' '12/18/06 '---------------------------------------------------- const kFalse% := 0, kTrue% := 1; var ok%, gDone%, gResult, gMain%, gMainUPT, gMainDur, gMainName$, gNext%, gNextUPT := 5, 'required for 1kHz sample rate gNextName$, gLog2%, pLogmX1 := 0, 'Log window pLogmY1 := 0, pLogmX2 := 30, pLogmY2 := 50, pLognX1 := 0, 'Log window pLognY1 := 50, pLognX2 := 30, pLognY2 := 100, pMainX1 := 30, 'scrolling data window pMainY1 := 0, pMainX2 := 100, pMainY2 := 50, pNextX1 := 30, 'scrolling data window pNextY1 := 50, pNextX2 := 100, pNextY2 := 100; gDone% := kFalse%; repeat view(gLog2%); fileClose(0,-1); 'close separately so no query fileClose(-1); 'close all files View(LogHandle()); 'Make log view the current view EditSelectAll(); 'Select all text in log view EditClear(); 'Delete it Window(pLogmX1, pLogmY1, pLogmX2, pLogmY2); 'Display it at the bottom of the screen frontview(loghandle()); gLog2% := FileNew(1,1); WindowTitle$("Log 2"); Window(pLognX1, pLognY1, pLognX2, pLognY2); 'Display it at the bottom of the screen frontview(gLog2%); 'open the *.smr file with the bad sampling frequencies gMain% := FileOpen("",0,1,"Select the file to convert to 1kHz sampling"); if (gMain% < 0) then halt; 'Stop if no file endif; cursorVisible(-1,0); 'hide all vertical cursors gMainDur := MaxTime(); gMainUPT := Binsize()*1e6; gMainName$ := filename$(3) + filename$(4); View(gMain%); Window(pMainX1, pMainY1, pMainX2, pMainY2); 'display in remaining space ChanShow(-1); 'show all channels Draw(0, MaxTime()); 'show the entire file PrintChanInfo(gMain%, loghandle()); DlgCreate("What do you want to do?"); DlgText("Convert this file?",1,1); DlgButton(0,"No"); DlgButton(1,"Yes"); ok% := DlgShow(); if ok% = kTrue% then 'Create the NEXT file with the proper time per unit sample, 'copying the traces will change the frequency an interpolate the 'data points. Tim Bergel says so, my examination confirms it gNext% := FileNew(7, 0, gNextUPT, 1, gMainDur); 'don't show gNextName$ := gMainName$ + "_" + "1kHz"; 'Copy the data from the MAIN file to the NEXT file View(gMain%); ChanSave(-1, -1, gNext%, 0, gMainDur, 0); 'copy the MAIN to the beginning of the file View(gNext%); windowTitle$(gNextName$); Window(pNextX1, pNextY1, pNextX2, pNextY2); 'display in remaining space ChanShow(-1); 'show all channels Draw(0, MaxTime()); 'show the entire file frontview(gNext%); gResult := filesaveas(gNextName$ + ".smr"); PrintChanInfo(gNext%, gLog2%); endif DlgCreate("What do you want to do?"); DlgText("Convert another file?",1,1); DlgButton(0,"No"); DlgButton(1,"Yes"); ok% := DlgShow(); if ok% = kFalse% then gDone% := kTrue%; else 'do nothing endif until gDone% = kTrue%; halt; '---------------------------------------------------- ' PrintChanInfo 'Put chan info in a text window. '12/21/06 '---------------------------------------------------- proc PrintChanInfo(aFileNum%, aLogView%); var i%, ok%, aStr$, aChanNum$, aChanFreq, aChanKind, aChanType$, aChanTitle$, aChanBinSize; View(aLogView%); 'Make log view the current view EditSelectAll(); 'Select all text in log view EditClear(); 'Delete it frontview(aLogView%); aStr$ := "Freq Report on:\n\n " + view(aFileNum%).FileName$(3) + view(aFileNum%).FileName$(5) + "\n\n"; aStr$ := aStr$ + print$("%5s","Chan") + print$("%10s","Freq") + print$("%14s","Interval") + print$("%12s","Name") + print$("%9s","Type") +"\n"; aStr$ := aStr$ + "---------------------------------------------------" + "\n"; for i% := 1 to 32 do view(aFileNum%); aChanKind := chanKind(i%); aChanNum$ := str$(i%); if i% < 10 then achanNum$ := "0" + aChanNum$; endif if aChanKind > 0 then aChanKind := chanKind(i%); aChanTitle$ := chantitle$(i%); aChanBinSize := Binsize(i%); aChanFreq := 1/aChanBinSize; docase case aChanKind = 1 then aChanType$ := print$("%10s","Waveform"); case aChanKind = 2 then aChanType$ := print$("%10s","Event(-)"); case aChanKind = 3 then aChanType$ := print$("%10s","Event(+)"); case aChanKind = 4 then aChanType$ := print$("%10s","Level"); case aChanKind = 5 then aChanType$ := print$("%10s","Marker"); case aChanKind = 6 then aChanType$ := print$("%10s","WaveMark"); case aChanKind = 7 then aChanType$ := print$("%10s","RealMark"); case aChanKind = 8 then aChanType$ := print$("%10s","TextMark"); case aChanKind = 9 then aChanType$ := print$("%10s","RealWave"); endcase; aStr$ := aStr$ + "ch " + aChanNum$ + ": " + print$("%10.2f",aChanFreq) + " " + print$("%10.8f",aChanBinSize) + " " + print$("%10s",aChanTitle$) + aChanType$ + "\n"; else aStr$ := aStr$ + "ch " + aChanNum$ + ": " + "\n"; endif next View(aLogView%); 'Make log view the current view print(aStr$); end 'PrintChanInfo