function sta2ncml(fid,server,prefix,stafile,mvals,site); % sta2ntml: Write NcML to make time series files nominally CF-compliant % Usage: sta2ncml(fid,server,prefix,stafile,mvals, site); % Inputs: % fid = file id of text file *already opened for writing* % server = first part of URL. For example: % 'http://stellwagen.er.usgs.gov/opendap/' % 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'; % mvals = structure created by get_whfc_time, containing start,stop & dt % site = string site ID (mooring #)- required for 'station' types % % do_sta2ncml generates all the needed inputs, so it's easiest to run that. % 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 %.16f precision, 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! % % Lon,Lat and Depth: We give "lon" and "lat" CF-Compatible units of % "degrees_east" and "degrees_north", with not shape and give % "depth" the attribute of "positive=down" so that it recognized as a % vertical coordinate. % also add the site_id variable as required for a "station" type, and % attributes to allow CF to parse the data, and output start and stop % times as ISO8601 format start=(mvals.mjd_start-3600*24*1000*datenum(1858,11,17,0,0,0)); % convert datenum to MJD location=[server prefix stafile]; stub=[prefix stafile]; fprintf(fid,'\n',stafile,stub,stub); fprintf(fid,'all4services\n'); fprintf(fid,'\n',location); fprintf(fid,'\n'); fprintf(fid,' \n'); fprintf(fid,' \n'); fprintf(fid,' \n',start,mvals.dtms); fprintf(fid,'\n'); % get rid of old time2 fprintf(fid,'\n'); fprintf(fid,'\n'); fprintf(fid,' \n'); fprintf(fid,'\n'); fprintf(fid,'\n'); fprintf(fid,' \n'); fprintf(fid,'\n'); fprintf(fid,'\n'); fprintf(fid,' \n'); fprintf(fid,'\n'); % now add the site id to allow it to by "station" fprintf(fid,'\n'); fprintf(fid,'\n'); fprintf(fid,' "%s"\n', site); fprintf(fid,' \n'); % and these all important global attributes fprintf(fid,'\n'); fprintf(fid,'\n'); % re-write start_time and stop time attributes in ISO 8601 format fprintf(fid,'\n',datestr(mvals.jd_start,31)); fprintf(fid,'\n',datestr(mvals.jd_stop,31)); fprintf(fid,'\n'); fprintf(fid,'\n');