1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138:
| program DatUmw;
{$APPTYPE CONSOLE}
uses SysUtils; {$Define TwoByteInt} type {$IfDef TwoByteInt} tmyInt = smallint; tmyUint = word; {$Else} tmyInt = integer; tmyUint = Cardinal; {$EndIf}
tFtype = array[0..11] of char;
TTraceFileHdr = packed record fType :tFtype; intWidth, intExt, chnRec, hGain, leftBin, fpMode, bottomRef, vGain : TmyInt; fBottom , fScrn, datMin, datRng : single; recCount : TmyUint end;
TTraceBuffer = array[0..16999] of tMyInt; const FileType : tFtype = 'SR430_TRACE'+#$1a;
var inDatei : File; outDatei: textFile; Header : TTraceFileHdr; TraceBuffer : TTraceBuffer; a : single; i, DatenSaetze, gelesen : integer; bTest : boolean; begin If ParamCount <> 2 then exit;
If Not(fileExists(ParamStr(1))) then begin writeln('Eingabedatei existiert nicht'); Halt(1) end;
assign(inDatei,ParamStr(1));
reset(inDatei,1);
IF fileSize(inDatei) < SizeOf(Header) then begin closeFile(inDatei); writeln('Die Datei ist zu klein'); Halt(2); end;
BlockRead(InDatei,Header,SizeOf(Header),gelesen); iF Gelesen <> SizeOf(Header) then begin closeFile(inDatei); writeln('LeseFehler'); Halt(3); end;
bTest := true; I := 0; repeat bTest:= btest AND(Header.fType[i]=FileType[i]); inc(i); until Not(bTest) Or (I>High(TFtype));
IF Not(bTest) then begin writeln('Not a trace file!'); end;
assign(outDatei,ParamStr(2)); {$I-} rewrite(outDatei); {$I+}
If IoResult <> 0 then begin writeln('Kann '+ParamStr(2)+' nicht erstellen'); Halt(5); end; DatenSaetze := Header.chnRec*1024; IF SizeOf(TraceBuffer)<SizeOf(tmyInt)*Datensaetze then begin writeln('Zuviele Datensaetze'); Halt(6); end; BlockRead(inDatei,TraceBuffer,SizeOf(tmyInt)*DatenSaetze,gelesen); IF gelesen <>SizeOf(tmyInt)*DatenSaetze then begin writeln('Konnte nicht alles einlesen'); Halt(7); end;
if Header.fpMode = 0 then begin for i:= 0 to DatenSaetze do begin a := traceBuffer[i]; writeln(outDatei,Format('%d'#9#9'%e',[i,a])); end; end else begin for i:= 0 to DatenSaetze do begin a := cardinal(traceBuffer[i])*Header.datRng/65535.0 + Header.datMin; writeln(outDatei,Format('%d'#9#9'%e',[i,a])); end; end; closeFile(inDatei); closeFile(outDatei); readln; end. |