function [float,number,timer,temp,pres,lat,lon,u,v,wwww] = rfcread1
%
%  The function [float,number,timer,temp,pres,lat,lon,u,v,wwww,head,start,finish] = rfcread1
%  reads an rfc file, keeps ONLY the values of the variables that correpospond
%  to values of velocity between -999. and 999., and loads the corresponding 
%  variables to the  vectors described in the input statement....
%
% ------------------------------------------------------------------
%  Written by Vassilis Zervakis, while at
%             AINCO-Interocean, Madrid, Spain, in November 1995
%             Modidied by Mike Sparrow in Jan. 1998
%-------------------------------------------------------------------
%
global float number timer temp pres lat lon u v wwww head start finish
global dataread handles header fileformat DATAPATH
%
fileformat = 'WHOI';
[filename, filepath] = uigetfile('*.*','Read a float file');
wholefile = [ filepath filename ];
DATAPATH = filepath
fif = fopen(wholefile,'rt'); 
%float = filename(4:6);
header = ' ';
% ------ Find the size of the file--------------
totalbytes = fseek(fif,0,'eof');
totalbytes = ftell(fif);
% ------Rewind and read the headers ------------
frewind(fif);
% ------Find whether the file is in WHOI format or in RFC format---
head = fgets(fif);
if (head(1:2) == ' *') | (head(1:2) == '* '),;
    fileformat = 'RFC '
    float = filename;
else
    float = filename;
end
frewind(fif);
%------------------------------------------------------------------
if fileformat == 'RFC ';
  for i = 1:15,
      head = fgetl(fif);
%     x1 = head(1)
%     x2 = head(2)
%head = strrez(head,80);
header = str2mat(header,head);
  end
  while (head(1:2) == ' *') | (head(1:2) == '* '),;
      head = fgetl(fif);
header = str2mat(header,head);
%     x1 = head(1)
%     x2 = head(2)
  end
  if fileformat == 'RFC ';
   start = (head(20:25));
   else,
   start = 0
  end
  i = 0;
  currentbytes = ftell(fif);
%   -------Actually read the data -----------------
  shower = waitbar(0.0,'Reading RFC file; please wait;');
  mikos = 0.2;
  step = 0.2;
  while currentbytes < (totalbytes - 1),;
    i = i + 1;
    A(i,1:10) = fscanf(fif,'%2d %4d %f %f %f %f %f %f %f %f',[1,10]);
    currentbytes = ftell(fif);
    rat = currentbytes / totalbytes;
    if rat >= mikos,
      waitbar(rat);
      mikos = mikos + step;
    end
    finish = i ;
    size(A);
    feof(fif);
  end            
  waitbar(1.0);
  close(shower);
  x2  = A(:,2);
  x3  = A(:,3); 
  x4  = A(:,4); 
  x5  = A(:,5); 
  x6  = A(:,6); 
  x7  = A(:,7); 
  x8  = A(:,8); 
  x9  = A(:,9); 
  x10 = A(:,10); 
%   clear A;
%
  frewind(fif)
  fclose(fif)
%
% -------------
% ---  Keep only the good data values
% -------------
%
  [n1, n2] = findgood(x8 , -999., 999);
% ------Keep only the good values -------------------
  number = x2(n1:n2);
  timer = x3(n1:n2);
  size(timer);
  temp  = x4(n1:n2);
  pres  = x5(n1:n2);
  lat   = x6(n1:n2);
  lon   = x7(n1:n2);
  u     = x8(n1:n2);
  v     = x9(n1:n2);
  wwww  = x10(n1:n2);
else,
% ---if file is in the 'WHOI' format,--------------------
%
  i = 0;
  currentbytes = ftell(fif);
%   -------Actually read the data -----------------
  shower = waitbar(0.0,'Reading & converting file; please wait;');
  mikos = 0.2;
  step = 0.2;
  A1 = [];
  while currentbytes < (totalbytes - 1),;
    i = i + 1;
%    test2 = fscanf(fif,'%3s %6s %2d %2d %2d %2d %2d %7f %7f %5s %1d %10f %10f %1c %9f %1c %9f',[1,17])
    linescan = fgetl(fif);
    s1 = linescan(1,1:3); 
    A1 = str2mat(A1, s1);
%    A(i, 1)  = linescan(4:9);
    A(i, 1) = 0;
    A(i, 2)  = str2num(linescan(10:11)); 
    A(i, 3)  = str2num(linescan(12:13)); 
    A(i, 4)  = str2num(linescan(14:15));
    if linescan(16:17) == '  ',
       A(i,5) = 0;
     else,
       A(i, 5)  = str2num(linescan(16:17)); 
    end
    if linescan(18:19) == '  ',
       A(i,6) = 0;
     else,
       A(i, 6)  = str2num(linescan(18:19)); 
    end
    A(i, 7)  = str2num(linescan(20:26)); 
    A(i, 8)  = str2num(linescan(27:34)); 
    s2 = linescan(35:39); 
    A2 = str2mat(A2, s2); 
    s3 = linescan(40); 
    A(i, 9)  = str2num(linescan(41:50)); 
    A(i,10)  = str2num(linescan(51:60)); 
    s4 = linescan(61); 
    A(i,11)  = str2num(linescan(62:70)); 
    s5 = linescan(71); 
    A(i,12)  = str2num(linescan(72:80)); 
    currentbytes = ftell(fif);
    rat = currentbytes / totalbytes;
    if rat >= mikos,
      waitbar(rat);
      mikos = mikos + step;
    end
    size(A);
    feof(fif);
  end            
  waitbar(1.0);
  close(shower);
  x1  = A(:,1);
  x2  = A(:,2); 
  x3  = A(:,3); 
  x4  = A(:,4); 
  x5  = A(:,5); 
  x6  = A(:,6); 
  x7  = A(:,7); 
  x8  = A(:,8); 
  x9  = A(:,9); 
  x10 = A(:,10); 
  x11 = A(:,11); 
  x12 = A(:,12); 
  frewind(fif)
  fclose(fif)
%
% -------------
% ---  Keep only the good data values
% -------------
%
  [n1, n2] = findgood(x10 , -999., 999);
% ------Keep only the good values -------------------
  number = [n1:n2,1];
  mmyear = x2(n1:n2);
  mmmont = x3(n1:n2);
  mmday  = x4(n1:n2);
  mmhour = x5(n1:n2);
  mmminu = x6(n1:n2);
  if mmyear > 50, 
     mmyear = mmyear + 1900;
   else
     mmyear = mmyear + 2000;
  end
  timer = dmy2rd(mmday,mmmont,mmyear) + (mmhour+mmminu/60.)/24.;
  lat   = x7(n1:n2);
  lon   = x8(n1:n2);
  valid = s2;
  algor = s3;
  u     = x9(n1:n2);
  v     = x10(n1:n2);
  if s4 == 'T',
    temp = x11(n1:n2);
  else,
    if s4 == 'P',
      pres = x11(n1:n2);
    end
  end
  if s5 == 'T',
    temp = x12(n1:n2);
  else,
    if s5 == 'P',
      pres = x12(n1:n2);
    end
  end
  wwww  = x10(n1:n2);
end
dataread = 'on';
close(handles(1));
harpro;
