@@ -36,27 +36,20 @@ implementation
3636procedure ProcessMeasurements (var buffer: array of char; bufferLength: integer;
3737 var results: TFPHashList);
3838var
39- currentChar: char;
4039 idx: integer = 0 ;
4140 currentTempSign: integer = 1 ;
4241 temp, cityStart: integer;
4342 city: shortstring;
4443 reading: PTCityTemp;
4544begin
46- // Writeln('bufferLength: ', bufferLength);
4745 while idx < (bufferLength - 1 ) do
4846 begin
49- { slurp up the city}
50- city := ' ' ;
47+ // read the city until separator
48+ // city := '';
5149 cityStart := idx;
52- currentChar := buffer[idx];
53- while currentChar <> REC_SEP do
54- begin
55- Inc(idx);
56- currentChar := buffer[idx];
57- end ;
50+ while buffer[idx] <> REC_SEP do Inc(idx);
5851 SetString(city, @buffer[cityStart], (idx - cityStart));
59- { slurp up the temp reading}
52+ // increment through temp reading and calculate integer temp (*100)
6053 Inc(idx); // move pointer past the ;
6154 currentTempSign := 1 ;
6255 // check for negative sign, if so flag the multiplier and then move past neg sign
@@ -66,30 +59,20 @@ procedure ProcessMeasurements(var buffer: array of char; bufferLength: integer;
6659 Inc(idx);
6760 end ;
6861 // look ahead - is decimal point 2 spaces away then we have two digits
69- temp := 0 ;
7062 if buffer[idx + 2 ] = DECIMAL_POINT then
7163 begin
72- temp := 100 * (byte(buffer[idx]) - ANSI_ZERO);
73- Inc(idx);
74- end ;
75- temp := temp + 10 * (byte(buffer[idx]) - ANSI_ZERO);
76- idx := idx + 2 ;
77- temp := currentTempSign * (temp + (byte(buffer[idx]) - ANSI_ZERO));
78- if temp > 999 then
79- begin
80- WriteLn(' Somethign wrong!' , city, ' | ' , temp, ' | ' , buffer[idx - 3 ],
81- ' | ' , buffer[idx - 2 ],
82- ' | ' , buffer[idx - 1 ], ' | ' , buffer[idx]);
83- break;
84- end ;
85-
86- currentChar := buffer[idx];
87- while currentChar <> LF do
64+ temp := currentTempSign * (100 * byte(buffer[idx]) + 10 *
65+ byte(buffer[idx + 1 ]) + byte(buffer[idx + 2 ]) - 5328 );
66+ // move past digits and CRLF and position pointer to first character of next record
67+ idx := idx + 6 ;
68+ end
69+ else
8870 begin
89- Inc(idx);
90- currentChar := buffer[idx];
71+ temp := currentTempSign * (10 * byte(buffer[idx + 1 ]) +
72+ byte(buffer[idx + 2 ]) - 528 );
73+ // move past digits and CRLF and position pointer to first character of next record
74+ idx := idx + 5 ;
9175 end ;
92- Inc(idx);
9376 reading := results.Find(city);
9477 if reading = nil then
9578 begin
@@ -109,7 +92,6 @@ procedure ProcessMeasurements(var buffer: array of char; bufferLength: integer;
10992 reading^.numReadings := reading^.numReadings + 1 ;
11093 end ;
11194 end ;
112- // WriteLn('results: ', results.Count);
11395end ;
11496
11597function PascalRound (x: double): double;
0 commit comments