function m_write(E) % M_WRITE - write specprr data from m1,m2, or m3 to SeaBASS % % Use as: m_wr m_ini for i = 1:length(E) PathS = ['\\tsunami.shore.mbari.org\oasis\eqpac\pete\realtimeprc\ftp_nasa\' E(i).id '.ftp']; eval(['x = ' E(i).id ';']); %====================== % Deal with Y2K issues %====================== %d = E(i).dat(:,3); %d = d + 1900; %============= % Format Time %============= %Year = floor(d); % The decimal day (d) needs to rounded to the nearest day (Bob's program isn't perfect) %leapYear = ~rem(Year,4); % Find the leap years %Leap = find(leapYear == 1); %notLeap = find(leapYear == 0); % The other years are not leap years %JulianDay = ones(size(d))*NaN; %if ~isempty(Leap) % JulianDay(Leap) = round((d(Leap) - Year(Leap))*366) + 1; %end %if ~isempty(notLeap) % JulianDay(notLeap) = round((d(notLeap) - Year(notLeap))*365) + 1; %end JulianDay = E(i).dat(:,1); Year = E(i).dat(:,end); %JTime = E(i).dat(:,1); %t = find(JTime == 1230); %JTime(t) = 1250; %JTime = JTime/2400; %JulianDay = JulianDay + JTime; sdn = jul2date(JulianDay, Year); % Convert to a serial date number [Year Month Day] = datevec(sdn); % Convert back to Year Month Day ymd = Year*10000+Month*100+Day; %=================== % Add Quality Flags %=================== %badFlagPrr620 = prod((E(i).dat(:,6:12) > -2)')'; %badFlagPrr600 = prod((E(i).dat(:,21:27) > -2)')'; %badFlagEd490 = E(i).dat(:,35) < -2; %fr = find(strcmp(ColumnS,'Lu683/Lu555[0m]')); %badFlagPrr620 = badFlagPrr620.*(E(i).dat(:,fr) <= 0.1) - 1; %fr = find(strcmp(ColumnS,'Lu683/Lu555[20m]')); %badFlagPrr600 = badFlagPrr600.*(E(i).dat(:,fr) <= 0.1) - 1; %=============== % Begin Writing %=============== fid = fopen(PathS,'wt'); % Open the file for writing %================== % Write the header %================== fprintf(fid,'/begin_header\n'); fprintf(fid,'/affiliations=Monterey_Bay_Aquarium_Research_Institute\n'); fprintf(fid,'/experiment=TAO_Moorings\n'); fprintf(fid,'/cruise=TAO_98\n'); fprintf(fid,'/investigators=Francisco_Chavez,Pete_Strutton,Brian_Schlining\n'); fprintf(fid,'/contact=chfr@mbari.org,stpe@mbari.org,brian@mbari.org\n'); fprintf(fid,'/parameters=Lu,Ed,Lw,K,Chl\n'); fprintf(fid,'/data_type=mooring\n'); fprintf(fid,'/original_file_name=%s\n',x.original_file_name); fprintf(fid,'/delimiter=space\n'); %Old missing code: fprintf(fid,'/missing=-99.99) fprintf(fid,'/missing=-999\n'); %Eaxample: fprintf(fid,'/north_latitude=-2.000[DEG]\n'); fprintf(fid,'/north_latitude=%-5.3f[DEG]\n',x.north_latitude); fprintf(fid,'/south_latitude=%-5.3f[DEG]\n',x.south_latitude); fprintf(fid,'/east_longitude=%-5.3f[DEG]\n',x.east_longitude); fprintf(fid,'/west_longitude=%-5.3f[DEG]\n',x.west_longitude); fprintf(fid,'/start_date=%8i\n',min(ymd)); fprintf(fid,'/end_date=%8i\n',max(ymd)); %Example: fprintf(fid,'/start_time=12:00:00[GMT]\n'); fprintf(fid,'/start_time=12:%02i:00[Local]\n',(E(i).dat(1,1) - 1200)); fprintf(fid,'/end_time=12:%02i:00[Local]\n',(E(i).dat(end,1) - 1200)); fprintf(fid,'/documents=MbariSeabassMooring.readme\n'); fprintf(fid,'/calibration_files=%s\n',x.calibration_files); fprintf(fid,'! Comments: Last column is quality flag; u=unchecked, g=good\n'); fprintf(fid,'! Comments: MorelChl[0-20m] is mean chl over the upper 20m calculated according to Morel (1988), OC2V2Chl[0m] is calculated from the surface Satlantic OCR-100 data, and Lu443/Lu555Chl at 0m and 20m calculated from an algorithm similar to Abbott and Letelier (1996), but with coefficients for the equatorial Pacific. See documentation.\n'); fprintf(fid,'! Comments: ELw is Lw calculated from the 1.5m Lu data, using an empirical relationship derived from Satlantic SPMR data for the equatorial Pacific, from June 1998.\n'); fprintf(fid,'! Comments: LLw is Lw calculated from a linear extrapolation of the 20m and 1.5m data, with a factor of 0.544 applied for transmission across the water-air interface.\n'); fprintf(fid,'! Comments: KLw is Lw calculated using the attenuation coefficient of downwelling irradiance at the relevant wavelength to back-propagate the 20m Lu data.\n'); fprintf(fid,'! Comments: Quality Flags: -1=bad 0=unchecked, 1=good\n'); % Write the fields...They are listed in ep_ini.m. Changes to field names or % the Field order need to be made there. fprintf(fid,'/fields=Date1,Time,Date2,'); for k = 3:length(ColumnS) fprintf(fid,'%s,',char(ColumnS(k))); end fprintf(fid,'Quality[0m],Quality[20m]\n'); % Write the Units fprintf(fid,'/fields=yyyymmdd,hh:mm:ss,mm/dd/yyyy,'); for k = 3:length(ColumnS) fprintf(fid,'%s,',char(UnitsS(k))); end fprintf(fid,'unitless,unitless\n'); fprintf(fid,'/end_header@\n'); %============ % Write Body %============ [r c] = size(E(i).dat); BAD = find(E(i).dat > 100000); E(i).dat(BAD) = NaN; BAD = find(isnan(E(i).dat) | isinf(E(i).dat)); E(i).dat(BAD) = -999; for n = 1:r fprintf(fid,'%8i ',ymd(n)); fprintf(fid,'12:%02i:00 ',(E(i).dat(n,1)-1200)); fprintf(fid,'%02i/%02i/%4i ', Month(n), Day(n), Year(n)); fprintf(fid,'%9.6f ', E(i).dat(n,3)); % DecimalYear fprintf(fid,'%9.3f ', E(i).dat(n,4:5)); % Temp Sal fprintf(fid,'%12.6f', E(i).dat(n,6:end)); % The data fprintf(fid,'%3i%3i\n',badFlagPrr620(n),badFlagPrr600(n)); % Quality flags end fclose(fid); end