clear

path = '\\Atlas\chemwebdata\floats\8501\';
directory = dir(strcat(path,'*.log'));

posNum  = 1;
for fileNum=1:length(directory)
    fileName = strcat(path,directory(fileNum).name);
    fid = fopen(fileName);
    lineNum = 1;
    while ~feof(fid)
        inString = fgetl(fid);
        if (findstr('GPGGA', inString) > 0)
            fprintf(1, 'fileNum: %d   lineNum: %d   inString: %s\n', fileNum, lineNum, inString);
            GGAString{fileNum,posNum} = inString;
            
            [token, remain] = strtok(GGAString{fileNum,posNum}, '$GPGGA');
            [header, remain] = strtok(remain, ',');
            [floatGPSTime, remain] = strtok(remain, ',');
            [floatLat, remain] = strtok(remain, ',');
            [floatNS, remain] = strtok(remain, ',');
            [floatLon, remain] = strtok(remain, ',');
            [floatEW, remain] = strtok(remain, ',');
            
            floatPos(posNum).logFile = directory(fileNum).name;
            floatPos(posNum).time = inString(2:21);
            temp = sscanf(floatLat, '%2d%f');
            floatPos(posNum).latDecDeg = temp(1) + temp(2)/60.0;
            if floatNS == 'S'
                floatPos(posNum).latDecDeg = -1.0 * floatPos.latDecDeg;
            end
            
            temp = sscanf(floatLon, '%3d%f');
            floatPos(posNum).lonDecDeg = temp(1) + temp(2)/60.0;
            if floatEW == 'W'
                floatPos(posNum).lonDecDeg = -1.0 * floatPos(posNum).lonDecDeg;
            end
            
            posNum = posNum + 1;
        end
        lineNum = lineNum + 1;
    end
    fclose(fid);
end
    utmstruct = defaultm('utm');
    utmstruct.zone = '10S';
    wgs84 = wgs84Ellipsoid;
    ellipsoid = [wgs84.SemimajorAxis wgs84.Eccentricity];
    utmstruct.geoid = ellipsoid;
    utmstruct  = defaultm(utmstruct);
    [east, north] = mfwdtran(utmstruct, [floatPos(:).latDecDeg], [floatPos(:).lonDecDeg]);
    floatPos(:).east = east;
    floatPos(:).north = north;
