function agg_sta2ncml(fid,server,prefix,stafile,mvals); % agg_sta2ntml: Write NcML to make agg time series file CF-compliant % Usage: agg_sta2ncml(fid,server,prefix,stafile,start,dt); % Inputs: % fid = file id of text file *already opened for writing* % server = first part of URL. For example: % 'http://stellwagen.er.usgs.gov/cgi-bin/nph-dods/' % OPeNDAP style % 'http://stellwagen.er.usgs.gov/' % HTTP style % '/Volumes/web/www_root/' % Path on Stellwagen % prefix = The time series directory (next part of URL). % 'DATAFILES/MBAY_LT/'; % 'DATAFILES/MYRTLEBEACH/'; % stafile = name of NetCDF file % '7201adc-a.nc'; % start = Matlab datenum, but in milliseconds (use double precision!) % dt = time interval in days (use double precision!) % Rich Signell (rsignell@usgs.gov) % Notes on making our Time Series Data CF-compliant: % Time: Our time series data use non CF-compliant time convention, % with "time" variable containing Julian days and "time2" containing % milliseconds since midnight. To make these CF-compliant, we use % NcML to construct a double precision time vector in Modified Julian Day, % one of the few internationally recognized time conventions that starts % at midnight. (See http://tycho.usno.navy.mil/mjd.html for more info.) % % We specify MJD as long variable type in milliseconds, which will give us accuracy of: % - better than 3.0e-5 milliseconds until August 31, 2132 and % - better than 3.0e-4 milliseconds until October 12, 4596! % start=mvals.mjd_start; % matlab datenum dt=mvals.dtms; % convert dt (seconds => days) % Find the netcdf variable name for temperature by finding % which long_name attribute starts with 'TEMPERATURE'. This could be % done also by finding variable names matching 'T_20','T_28', etc. % % Whatever temperature variable name we find, we rename % the temperature variable with the name 'temp' using NcML so % that we can aggregate for i=1:length(mvals.varnames); if length(mvals.long_names{i})>=11, if strmatch(upper(mvals.long_names{i}(1:11)),'TEMPERATURE'), var=mvals.varnames{i}; end end end start=(start-3600*24*1000*datenum(1858,11,17,0,0,0)); % convert datenum to MJD location=[server prefix stafile]; fprintf(fid,'\n',location); fprintf(fid,'\n'); fprintf(fid,' \n'); fprintf(fid,' \n'); fprintf(fid,' \n',start,dt); fprintf(fid,'\n'); fprintf(fid,'\n',var); fprintf(fid,'\n'); fprintf(fid,'\n'); fprintf(fid,'\n');