
% Read the monthly sea ice reports, pick off the sea ice extent and
% area, and write it out as an ASCII file.
%
% Todd Mitchell, October 2012

% Download the data 
!wget 'ftp://sidads.colorado.edu/DATASETS/NOAA/G02135/Apr/*_04_area.txt'
!wget 'ftp://sidads.colorado.edu/DATASETS/NOAA/G02135/Aug/*_08_area.txt'
!wget 'ftp://sidads.colorado.edu/DATASETS/NOAA/G02135/Dec/*_12_area.txt'
!wget 'ftp://sidads.colorado.edu/DATASETS/NOAA/G02135/Feb/*_02_area.txt'
!wget 'ftp://sidads.colorado.edu/DATASETS/NOAA/G02135/Jan/*_01_area.txt'
!wget 'ftp://sidads.colorado.edu/DATASETS/NOAA/G02135/Jul/*_07_area.txt'
!wget 'ftp://sidads.colorado.edu/DATASETS/NOAA/G02135/Jun/*_06_area.txt'
!wget 'ftp://sidads.colorado.edu/DATASETS/NOAA/G02135/Mar/*_03_area.txt'
!wget 'ftp://sidads.colorado.edu/DATASETS/NOAA/G02135/May/*_05_area.txt'
!wget 'ftp://sidads.colorado.edu/DATASETS/NOAA/G02135/Nov/*_11_area.txt'
!wget 'ftp://sidads.colorado.edu/DATASETS/NOAA/G02135/Oct/*_10_area.txt'
!wget 'ftp://sidads.colorado.edu/DATASETS/NOAA/G02135/Sep/*_09_area.txt'

!ls *area.txt > table

yr1 = 1978
yr2 = 2012
nyr = yr2 - yr1 + 1
fdat = zeros(nyr*12,6)*NaN;

fk = fopen( 'table' )
fn = fgetl( fk )

while fn~=-1

fk2 = fopen( fn )
line = fgetl( fk2 );
line = fgetl( fk2 );

while ~isempty(line)
yearin = str2num(line(1:4));

monthin = str2num(line(6:7));
icnt = (yearin-yr1)*12 + monthin;
                                               
if strcmp( line(27), 'N' )
fdat(icnt,1:4) = ...
  [ yearin monthin str2num(line(30:34)) str2num(line(37:41)) ];
else
fdat(icnt,[1 2 5 6]) = ...
  [ yearin monthin str2num(line(30:34)) str2num(line(37:41)) ];
end
line = fgetl( fk2 )
end
fclose( fk2 );
fn = fgetl( fk )
end

fdat(fdat<0) = NaN;

save sea_ice_extent_area.ascii fdat -ascii

