source: Roms_tools/Preprocessing_tools/add_chla.m @ 2

Last change on this file since 2 was 1, checked in by cholod, 13 years ago

import Roms_Agrif

File size: 4.3 KB
Line 
1function add_chla(climfile,gridfile,seas_datafile,cycle,Roa);
2
3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4%
5%  function add_chla(climfile,gridfile,seas_datafile,cycle);
6%
7%  Add chlorophyll (mg C) in a ROMS climatology file.
8%  take seasonal data for the surface levels and extrapole
9%  using Morel and Berthon (1989) parameterization for the
10%  lower levels. warning ! the unit is (micro mole/l) in the
11%  dataset.
12%  ref:  Morel and Berthon, Surface pigments, algal biomass
13%        profiles, and potential production of the euphotic layer:
14%        Relationships reinvestigated in view of remote-sensing
15%        applications. Limnol. Oceanogr., 34, 1989, 1545-1562.
16%
17%  input:
18%   
19%    climfile      : roms climatology file to process (netcdf)
20%    gridfile      : roms grid file (netcdf)
21%    seas_datafile : regular longitude - latitude - z seasonal data
22%                    file used for the upper levels  (netcdf)
23%    ann_datafile  : regular longitude - latitude - z annual data
24%                    file used for the lower levels  (netcdf)
25%    cycle         : time length (days) of climatology cycle (ex:360 for
26%                    annual cycle) - 0 if no cycle.
27%
28%  Further Information: 
29%  http://www.brest.ird.fr/Roms_tools/
30
31%  This file is part of ROMSTOOLS
32%
33%  ROMSTOOLS is free software; you can redistribute it and/or modify
34%  it under the terms of the GNU General Public License as published
35%  by the Free Software Foundation; either version 2 of the License,
36%  or (at your option) any later version.
37%
38%  ROMSTOOLS is distributed in the hope that it will be useful, but
39%  WITHOUT ANY WARRANTY; without even the implied warranty of
40%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
41%  GNU General Public License for more details.
42%
43%  You should have received a copy of the GNU General Public License
44%  along with this program; if not, write to the Free Software
45%  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
46%  MA  02111-1307  USA
47%
48%  Copyright (c) 2001-2006 by Pierrick Penven
49%  e-mail:Pierrick.Penven@ird.fr 
50%
51%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52%
53disp('Add_chla: creating variable and attribute')
54default=NaN;
55%
56% read in the datafile
57%
58ncseas=netcdf(seas_datafile);
59x=ncseas{'X'}(:);
60y=ncseas{'Y'}(:);
61t=ncseas{'T'}(:);
62tlen=length(t);
63%
64% open the grid file 
65%
66ng=netcdf(gridfile);
67lon=ng{'lon_rho'}(:);
68%lon(lon<0)=lon(lon<0)+360;
69lat=ng{'lat_rho'}(:);
70h=ng{'h'}(:);
71close(ng);
72[M,L]=size(lon);
73dl=2.;
74minlon=min(min(lon))-dl;
75maxlon=max(max(lon))+dl;
76minlat=min(min(lat))-dl;
77maxlat=max(max(lat))+dl;
78imin=max(find(x<=minlon));
79imax=min(find(x>=maxlon));
80jmin=max(find(y<=minlat));
81jmax=min(find(y>=maxlat));
82x=x(imin:imax);
83y=y(jmin:jmax);
84%
85% open the clim file 
86%
87nc=netcdf(climfile,'write');
88theta_s = nc{'theta_s'}(:);
89theta_b =  nc{'theta_b'}(:);
90Tcline  =  nc{'Tcline'}(:);
91N =  length(nc('s_rho'));
92redef(nc);
93nc('chla_time') = tlen;
94nc{'chla_time'} = ncdouble('chla_time') ;
95nc{'CHLA'} = ncdouble('chla_time','s_rho','eta_rho','xi_rho') ;
96%
97nc{'chla_time'}.long_name = ncchar('time for chlorophyll');
98nc{'chla_time'}.long_name = 'time for chlorophyll';
99nc{'chla_time'}.units = ncchar('day');
100nc{'chla_time'}.units = 'day';
101if cycle~=0
102  nc{'chla_time'}.cycle_length = cycle;
103end
104%
105nc{'CHLA'}.long_name = ncchar('Chlorophyll');
106nc{'CHLA'}.long_name = 'Chlorophyll';
107nc{'CHLA'}.units = ncchar('mg C');
108nc{'CHLA'}.units = 'mg C';
109nc{'CHLA'}.fields = ncchar('CHLA, scalar, series');
110nc{'CHLA'}.fields = 'CHLA, scalar, series';
111%
112endef(nc);
113%
114% Record the time
115%
116nc{'chla_time'}(:)=t*30; % if time in month in the dataset !!!
117%
118% Get the missing values
119%
120missval=ncseas{'chlorophyll'}.missing_value(:);
121%
122% loop on time
123%
124for l=1:tlen
125disp(['time index: ',num2str(l),' of total: ',num2str(tlen)])
126%
127% extrapole the annual dataset on the horizontal roms grid
128%
129  disp('Add_chla: horizontal interpolation of surface data')
130  surfchla=squeeze(ncseas{'chlorophyll'}(l,jmin:jmax,imin:imax));
131  surfchla=get_missing_val(x,y,surfchla,missval,Roa,default);
132  surfchlaroms=interp2(x,y,surfchla,lon,lat);
133%
134% extrapole the chlorophyll on the vertical
135%
136  zroms=zlevs(h,0.*h,theta_s,theta_b,Tcline,N,'r');
137  disp(['Add_chla: vertical ',...
138  'extrapolation of chlorophyll'])
139  chlaroms=extr_chlo(surfchlaroms,zroms);
140  nc{'CHLA'}(l,:,:,:)=chlaroms;
141end
142close(nc);
143close(ncseas);
144chla=squeeze(chlaroms(N,:,:));
145return
Note: See TracBrowser for help on using the repository browser.