function [ctd,varlabel,names,sensors]=ctd_rd(cnv_file,FMT);
% CTD_RD Reads the SeaBird ASCII .CNV file format
%
% Usage: CTD=ctd_rd(cnv_file);
%
% Input: cnv_file = name of .CNV file (e.g. 'cast002.cnv')
%
% Output: CTD - a data structure containing the CTD data and header info.
%
% There are various formats possible for time/location information.
% Some of these can be handled with an optional second input parameter:
% CTD=ctd_rd(cnv_file,FORMAT)
%
% where FORMAT = 'NMEA' for SEASAVE output with GPS included through deckbox
%
% * System UpLoad Time = Oct 10 1999 18:20:32
% * NMEA Latitude = 48 36.69 N
% * NMEA Longitude = 123 13.07 W
% * NMEA UTC (Time) = Oct 10 1999 18:20:32
%
% 'IR' for an internally recording mode with a hand-typed
% header in this form:
%
% ** Latitude = 49 21.092 N
% ** Longitude = 121 49.028 W
% ** PST (Time) =Nov 23 2000 07:45
%
% will also work with SEASAVE output if no
% GPS NMEA string available.
% (default mode)
%
% If no '** Time' line gets it from System Upload Time
%
% 'RP' Ignore any header data but decode System Upload Time for
% the year, and the 'cast' line (DH command) for time -
% good for IR mode when to-yo-ing or otherwise too lazy
% to create proper headers.
%
% 'LAB' for a mode with no NMEA or header data (i.e. lab
% testing)
%
% Add more lat,lon and date string handling if your .CNV files are different.
%
% 4-8-98 Rich Signell (rsignell@usgs.gov)
% incorporates ideas from code by Derek Fong & Peter Brickley
% 19-9-99 R. pawlowicz (ric@ocgy.ubc.ca)
% - added a lot more decoding plus the idea of a data stucture for output
% 12-6-00 Changes variable names slightly.
% 19-2-02 dms as well as dmm.mm formats
% 20-5-11 modified by Rowan Fox (ro1@uvic.ca), adding in model #, temp
% sensor SN # & cond sensor SN
% 16-5-12 can now read new-format cnv files with xml info
if nargin==1,
FMT='IR';
end;
ctd.name='ctd';
ctd.station='';
% Open the .cnv file as read-only text
if isempty(findstr(lower(cnv_file),'.cnv')),
cnv_file=[cnv_file '.cnv'];
end;
fid=fopen(cnv_file,'r');
% Read the header.
lat=[];
lon=[];
gtime=NaN(1,6);
tzone='unknown';
% Stop at line that starts with '*END*'
str='*START*';
while (~strncmp(str,'*END*',5));
str=fgetl(fid);
switch FMT
case 'NMEA'
if (strncmp(str,'* NMEA Lat',10))
lat=get_lat(str);
elseif (strncmp(str,'* NMEA Lon',10))
lon=get_lon(str);
elseif (strncmp(str,'* NMEA UTC',10))
gtime=get_timestamp(str);
tzone='UTC';
end;
case 'IR',
if any(findstr(str,'Latitude')) | any(findstr(str,'Lati'))
lat=get_lat(str);
elseif any(findstr(str,'Longitude')) | any(findstr(str,'Long'))
lon=get_lon(str);
% Read the TIME string. This may vary with CTD setup. Will need
% ** xxxxxxxxxxTimexxxx = 21 Dec 2005 hh:mm:ss
% where timezone may also be in there somewhere.
elseif strncmp(str,'**',2) & any(findstr(str,'Time')),
gtime=get_timestamp(str);
tzone='unknown';
if any(findstr(str,'PST')),
tzone='PST';
elseif any(findstr(str,'PDT')),
tzone='PDT';
elseif any(findstr(str,'UTC')),
tzone='UTC';
elseif any(findstr(str,'EST')),
tzone='EST';
elseif any(findstr(str,'EDT')),
tzone='EDT';
end;
% The default - get a time from the 'upload' string (usually the other time
% strings are later in the file so they will overwrite this, if they exist).
elseif (strncmp(str,'* System UpLoad',15)),
tzone='unknown';
gtime=get_timestamp(str);
end;
case 'LAB',
if (strncmp(str,'* System UpLoad',15)),
tzone='unknown';
gtime=get_timestamp(str);
end;
case 'RP',
if (strncmp(str,'* System UpLoad',15))
is=findstr(str,'=');
%EXTRACT THE UPLOAD YEAR FOR CAST START TIME Roger 2003sep04
upyearstr=str(is+9:is+12);
end;
%-------------------------------------------------------------------
% READ CAST START TIME, SAMPLE RATE, COMPUTE mtime Roger 2003sep04
% * cast 0 06/23 17:38:06 samples 0 to 1334 sample rate = 1 scan every 0.5 seconds
if (strncmp(str,'* cast ',7))
%Find slash
indslash=find(str=='/');
indcolon=find(str==':');
if length(indslash)==1 & length(indcolon)>=2
datstr=[upyearstr ' '...
str(indslash-2:indslash-1) ' ' ...
str(indslash+1:indslash+2) ' ' ...
str(indcolon(1)-2:indcolon(1)-1) ' '...
str(indcolon(1)+1:indcolon(2)-1) ' '...
str(indcolon(2)+1:indcolon(2)+2)];
mtime=datenum(str2num(datstr));
gtime=datevec(mtime);
fprintf('Date from CAST START TIME in timezone of SBE clock\n');
else
error('ERROR: CAST START TIME: str does not have expected form')
end;
end
%
otherwise,
error('Unrecognized format specifier');
end;
%-----------------------------
%
% Read the station name from a comment line
%
if (strncmp(lower(str),'** station',10)),
ctd.station=fliplr(deblank(fliplr(deblank(str(min(findstr(str,':'))+2:end)))));
%-----------------------------
%
% Read the ctd model from a comment line
%
elseif (strncmp(str,'* Sea-Bird',10)),
ctd.model=str(findstr(str,'Sea-Bird SBE ')+13:findstr(str,' Data File')-1);
%-----------------------------
%
% Read the ctd temperature sensor SN from a comment line
%
elseif (strncmp(str,'* Temperature SN = ',19)),
ctd.tempsn=str(findstr(str,'* Temperature SN = ')+19:end);
%-----------------------------
%
% Read the ctd conductivity sensor SN from a comment line
%
elseif (strncmp(str,'* Conductivity SN = ',20)),
ctd.condsn=str(findstr(str,'* Conductivity SN = ')+20:end);
%-----------------------------
%
% Read the depth from a comment line
%
elseif (strncmp(lower(str),'** depth',8)),
idelim=findstr(str,':');
ctd.depth=sscanf(str(idelim+1:end),'%f');
if isempty(ctd.depth), ctd.depth=NaN; end;
% Units?
strrem=str(idelim+1:end);strrem(strrem>=48 & strrem<=57)=' ';
if any(findstr(str(idelim+1:end),' m')),
% OK
elseif any(findstr(str(idelim+1:end),' ft')) ,
ctd.depth=ctd.depth*0.3048;
end;
%------------------------------
%
% Get sampling interval
%
elseif (strncmp(str,'# interval',10)),
ctd.samp_interval=sscanf(str(findstr(str,':')+1:end),'%f');
%------------------------------
%
% Get start time
%
elseif (strncmp(str,'# start_time',12)),
ctd.start_time=str(15:end);
ctd.start_mtime=datenum(str(15:end),'mmm dd yyyy HH:MM:SS');
%------------------------------
%
% Read the variable names & units into a cell array
%
elseif (strncmp(str,'# name',6))
var=sscanf(str(7:10),'%d',1);
var=var+1;
ctd.varlabel{var}=str(findstr(str,'=')+2:min([findstr(str,':')-1 ...
findstr(str,'/')-1 findstr(str,'-')-1]));
%------------------------------
%
% Read the sensor names into a cell array
%
elseif (strncmp(str,'# sensor',8))
sens=sscanf(str(10:11),'%d',1);
sensors{sens+1}=str;
%---------------
CTD_RD_读取SBEctd文件_
版权申诉
5星 · 超过95%的资源 55 浏览量
2021-10-04
09:37:15
上传
评论 1
收藏 32KB ZIP 举报
何欣颜
- 粉丝: 69
- 资源: 4732
最新资源
- sony 索尼IMX334摄像头模组电路板AD版硬件PCB图(6层板).zip
- 基于flask和echarts融合交易策略的bitfinex可视化微服务.zip
- 包含了wvp-assist.tar wvp-talk.tar zlmediakit.tar .
- 3r4efgh53wgrf43tw
- 2024新版Java基础从入门到精通全套视频+资料下载
- Spring AI大模型视频教程+ChatGPT视频教程+OpenAI大模型视频教程(资料+视频教程)
- ABB工业机器人教程PDF版本
- 123321123323211
- yolov8实战第八天-pyqt5-yolov8实现车牌识别系统(论文(8700+字+数据集+完整部署代码+代码使用说明)
- 三相桥式全桥整流电路MATALB Simulink仿真文件
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈