
load aerigoes_values

% average the data for 30 minute intervals.  time tag at 00:15, 00:45, ...
nss1970p = (nosecsince1970(1998,7,25,0,15,0):60*30:nosecsince1970(1998,9,21,23,45,00))';
n = length(nss1970p);
for i = 1:n
  ind = find(ag.nss1970 >= nss1970p(i)-15*60 & ag.nss1970 < nss1970p(i)+15*60);
  pwv(i) = mean(ag.pwv(ind));
  imrt(i) = mean(ag.imrt(ind));
  alt(i) = mean(ag.alt(ind));
  t1(i) = mean(ag.t1(ind));
  p1(i) = mean(ag.t1(ind));
  h1(i) = mean(ag.h1(ind));  
  cbh(i) = mean(ag.cbh(ind));  
end


fid=fopen('aerigoes_values_30min.asc','w');

fprintf(fid,' \n');
fprintf(fid,' AERI/GOES parameters for CAMEX3. 30 minute averages.\n');
fprintf(fid,' from Andros Island (lon=-77.7687,lat=24.6998)\n');
fprintf(fid,' \n');
fprintf(fid,'  column 1: time (# seconds since 1970) \n');
fprintf(fid,'  column 2: readable date and time (UTC) \n');
fprintf(fid,'  column 3: altitude (meters above sea level) \n');
fprintf(fid,'  column 4: first level pressure (mbar) \n');
fprintf(fid,'  column 5: first level height (km) \n');
fprintf(fid,'  column 6: first level temperature (K) \n');
fprintf(fid,'  column 7: cloud base height (km, <0 = no cloud)\n');
fprintf(fid,'  column 8: pwv (cm) \n');
fprintf(fid,'  column 9: integrated mean radiating temperature (K) \n');
fprintf(fid,' \n');

for i = 1:length (nss1970p)
fprintf(fid,'%10i %s %10.3f %10.3f %10.3f %10.3f %10.3f %10.3f %10.3f\n',...
   nss1970p(i),datestr(dn(nss1970p(i))),alt(i),p1(i),h1(i),t1(i),cbh(i),pwv(i),imrt(i));

end
fclose(fid)

