Home > robbins > read_prs.m

read_prs

PURPOSE ^

READ_PRS Reads in standard *.PRS ascii file specified by flname

SYNOPSIS ^

function [p,t,s,o2,lat,lon] = read_prs(flname,dd);

DESCRIPTION ^

   READ_PRS Reads in standard *.PRS ascii file specified by flname

   Usage:  [p,t,s,o2,lat,lon] = read_prs(flname,decimation); 

 Output : (column vectors)
   p : pressure 
   t : (in situ) temperature
   s : salinity 
   ox: oxygen
   lat: latitude
   lon: longitude
  
  INPUT
    flname: file name (may include path)
    (opt) decimation: specify decimation interval (e.g. 20 for 20 dbar)

 Paul E. Robbins copywrite 1995

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [p,t,s,o2,lat,lon] = read_prs(flname,dd);
0002 
0003 %   READ_PRS Reads in standard *.PRS ascii file specified by flname
0004 %
0005 %   Usage:  [p,t,s,o2,lat,lon] = read_prs(flname,decimation);
0006 %
0007 % Output : (column vectors)
0008 %   p : pressure
0009 %   t : (in situ) temperature
0010 %   s : salinity
0011 %   ox: oxygen
0012 %   lat: latitude
0013 %   lon: longitude
0014 %
0015 %  INPUT
0016 %    flname: file name (may include path)
0017 %    (opt) decimation: specify decimation interval (e.g. 20 for 20 dbar)
0018 %
0019 % Paul E. Robbins copywrite 1995
0020 
0021 l = length(flname);
0022 if ~strcmp(flname(l-3:l),'prs') & ~strcmp(flname(l-1:l),'PRS');
0023    flname = [flname,'.prs'];
0024 end
0025 fid = fopen(flname,'r');
0026 
0027 if fid == -1
0028   %try to find file in matlab_data directory
0029   fid = fopen([getenv('MATLAB_DATA'),flname],'r');
0030   if fid == -1
0031     fid = fopen([getenv('MATLAB_DATA'),'/ctd/prs/',flname],'r');
0032     if fid == -1
0033       disp(['File ',flname,' not found'])
0034       break
0035    end
0036   end    
0037 end
0038 
0039 % read in 5 lines of header data
0040 for l = 1:5
0041   line = fgetl(fid);  
0042 end
0043 
0044 % read in lat and longitude
0045 lats = fscanf(fid,' St.Lat.:%d:%d:%d',3); fgetl(fid);
0046 if lats(1) > 0
0047   lat  = lats(1) + lats(2)/60 + lats(3)/3600;
0048 else 
0049   lat  = lats(1) - lats(2)/60 - lats(3)/3600;
0050 end
0051 
0052 lons = fscanf(fid,' St.Long:%d:%d:%d',3); fgetl(fid);
0053 if lons(1) > 0
0054   lon  = lons(1) + lons(2)/60 + lons(3)/3600;
0055 else 
0056   lon  = lons(1) - lons(2)/60 - lons(3)/3600;
0057 end
0058 
0059 % read in 8 more lines of header data
0060 for l = 1:8
0061   line = fgetl(fid);  
0062 end
0063 
0064 
0065 dat = fscanf(fid,'%f,%f,%f,%f,%f',[5 inf]);
0066 
0067 p = dat(1,:);
0068 t = dat(2,:);
0069 s = dat(3,:);
0070 o2 = dat(4,:);
0071 fclose(fid);
0072 
0073 if nargin > 1  % decimate data
0074   l = length(p);
0075   dp = diff(p(1:2));
0076   step = round(dd/dp);
0077   p = p(1:step:l);
0078   s = s(1:step:l);
0079   t = t(1:step:l);
0080   o2 = o2(1:step:l);
0081 end
0082 
0083 p = p(:); t = t(:); s = s(:); o2 = o2(:);
0084

Generated on Wed 30-Nov-2005 15:40:09 by m2html © 2003