% This script makes a .mat-file for each EDF xbt file in a given % directory, as well as a summary .mat-file describing the bulk % properties related to each XBT profile. Comments, which include % information on what is produced, are embedded within this script % data directory can be relative or absolute, but the directory % must be writeable (Original data are not altered -- the EDF files % can be read only) data_dir = '../newxbt/'; % run a perl script that separates the data from the header -- making % files ending with EDF_dat and EDF_hdr -- and extracts info from the % header that is of interest (year, month, day, hour. minute, second, % longitude, latitude) into a file with the extension EDF_info eval(['!perl remove_header.pl ', data_dir]); % now use the info from the perl output to make a .mat-file for each % XBT cast. Each cast has a Matlab structure array with the same % name as the file, within that structure array are the following % elements: % year % month % day % hour % minute % second % longitude (in decimal degrees, negative longitudes are % degrees West) % latitude (in decimal degrees, negative values are degrees % north) % depth (vector of depths where XBT recordings are made, % NaN if empty) % temperature (vector of temperature recordings, NaN if % empty) % c_s (vector of sound speeds, NaN if empty) % date (date in Matlab's "datenum" format) % datestr (date in a string format) % The vectors depth, temperature, and c_s should all be the same length % % In addition, a mat-file called "summary" is made. It contains a % structured array called "summary" with the following elements % longitude (a vector of longitudes) % latitude (a vector of latitude) % date (a vector of dates in Matlab's "datenum" format % maxdepth (a vector of maximum depths) % fname (name of .mat-file containing data) % ncasts (number of casts) % datadir (data directory, whatever was used above) % Other than "ncasts", and "datadir", all elemens will have a % length of "ncasts". d = dir([data_dir, '*.EDF']); for i = 1:length(d) varname = getfilename(d(i).name); info = load([data_dir, d(i).name , '_info']); eval([varname, '.year = info(1);']); eval([varname, '.month = info(2);']); eval([varname, '.day = info(3);']); eval([varname, '.hour = info(4);']); eval([varname, '.minute = info(5);']); eval([varname, '.second = info(6);']); eval([varname, '.longitude = info(7);']); eval([varname, '.latitude = info(8);']); eval([varname, '.date = datenum(info(1:6)'');']); eval([varname, '.datestr = datestr(datenum(info(1:6)''));']); summary.lon(i) = info(7); summary.lat(i) = info(8); summary.date(i) = datenum(info(1:6)'); clear info data = load([data_dir, d(i).name, '_dat']); if(isempty(data)) eval([varname, '.depth = NaN;']); eval([varname, '.temperature = NaN;']); eval([varname, '.c_s = NaN;']); summary.maxdepth(i) = NaN; else eval([varname, '.depth = data(:,1);']); eval([varname, '.temperature = data(:,2);']); eval([varname, '.c_s = data(:,3);']); % note that speed of sound % assumes a salinity of % 33.50 ppt summary.maxdepth(i) = max(data(:,1)); end summary.datadir = data_dir; summary.fname{i} = varname; eval(['save ', data_dir, varname, ' ', varname]); eval(['clear ', varname]); end summary.ncasts = i; eval(['save ', data_dir, 'summary summary']); % remove files made by the perl script eval(['!rm ', data_dir, '*hdr']); eval(['!rm ', data_dir, '*dat']); eval(['!rm ', data_dir, '*info']);