Reply to last line of data written twice

Your name:

Reply:


Posted by Patrick on 08/29/06 20:06

Hi All,

Can someone take a look at my script and tell me if I am missing
something as to why the last line of data from my input file is being
written twice in the echo. I have included a short sample of the data
and the script.

Thanks,
Patrick

***Please note that data in this particualr file begins after first
line. I don't have control over this, it's the way I receive the data.***



Unit: T4
Mission: 383b
Cycle: 80
Stage: Ascent
Cycle Start Time: 08-22-06 04:20:11
Stage Time: 08-22-06 04:20:11
Latitude: 90.0000 Longitude: -360.0000
CTD 61.152 30.38 26.94 36.54
CTD 61.165 30.38 25.92 36.55
CTD 61.151 30.38 24.71 36.55
CTD 61.138 30.38 23.65 36.54
CTD 61.125 30.37 22.06 36.54
CTD 61.121 30.37 20.99 36.54
CTD 61.099 30.37 19.87 36.53

<?php
echo "<pre>\n";

// Assigns path to file a variable name
$atttxt = $filepath = "/usr3/BSOP/TEST/cycle-44ea88fb.att.txt";

// Opens file into variable
$readfile = fopen($atttxt, "r");

$i=0;

//***NOTE*** Line one in cycle files is empty. Data starts at
position 1

while(!feof($readfile))
{
// Reads file
$data = fgets($readfile);

if ($i == 1)
{
sscanf($data, "%s %s", $slop, $unit);
}

if ($i == 2)
{
sscanf($data, "%s %s", $slop, $mission);
}

if ($i == 3)
{
sscanf($data, "%s %s", $slop, $cycle);
}

if ($i == 4)
{
sscanf($data, "%s %s", $slop, $stage);
}
if ($i == 5)
{
sscanf($data, "%s %s %s %s %s", $slop, $slop, $slop,
$date, $time);
}

// Read of line 6 skipped due to duplicat value on line five
if ($i == 7)
{
sscanf($data, "%s %s %s %s", $slop, $lat, $slop, $lon);
}

$hline = "$unit $mission $cycle $stage $lat $lon $date $time";

If ($i >= 8)
{
sscanf($data, "%s %s %s %s %s", $slop, $cond, $temp, $press, $sal);

//echoing $i only for visual test of output

echo "$i $hline $cond $temp $press $sal\n";
}

$i = $i +1;

}

// Closes file
fclose ($readfile);

echo "</pre>\n";
?>

--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - College of Marine Science
http://ocgweb.marine.usf.edu Phone: 727 553-3334

The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация