1 | function 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 | % |
---|
53 | disp('Add_chla: creating variable and attribute') |
---|
54 | default=NaN; |
---|
55 | % |
---|
56 | % read in the datafile |
---|
57 | % |
---|
58 | ncseas=netcdf(seas_datafile); |
---|
59 | x=ncseas{'X'}(:); |
---|
60 | y=ncseas{'Y'}(:); |
---|
61 | t=ncseas{'T'}(:); |
---|
62 | tlen=length(t); |
---|
63 | % |
---|
64 | % open the grid file |
---|
65 | % |
---|
66 | ng=netcdf(gridfile); |
---|
67 | lon=ng{'lon_rho'}(:); |
---|
68 | %lon(lon<0)=lon(lon<0)+360; |
---|
69 | lat=ng{'lat_rho'}(:); |
---|
70 | h=ng{'h'}(:); |
---|
71 | close(ng); |
---|
72 | [M,L]=size(lon); |
---|
73 | dl=2.; |
---|
74 | minlon=min(min(lon))-dl; |
---|
75 | maxlon=max(max(lon))+dl; |
---|
76 | minlat=min(min(lat))-dl; |
---|
77 | maxlat=max(max(lat))+dl; |
---|
78 | imin=max(find(x<=minlon)); |
---|
79 | imax=min(find(x>=maxlon)); |
---|
80 | jmin=max(find(y<=minlat)); |
---|
81 | jmax=min(find(y>=maxlat)); |
---|
82 | x=x(imin:imax); |
---|
83 | y=y(jmin:jmax); |
---|
84 | % |
---|
85 | % open the clim file |
---|
86 | % |
---|
87 | nc=netcdf(climfile,'write'); |
---|
88 | theta_s = nc{'theta_s'}(:); |
---|
89 | theta_b = nc{'theta_b'}(:); |
---|
90 | Tcline = nc{'Tcline'}(:); |
---|
91 | N = length(nc('s_rho')); |
---|
92 | redef(nc); |
---|
93 | nc('chla_time') = tlen; |
---|
94 | nc{'chla_time'} = ncdouble('chla_time') ; |
---|
95 | nc{'CHLA'} = ncdouble('chla_time','s_rho','eta_rho','xi_rho') ; |
---|
96 | % |
---|
97 | nc{'chla_time'}.long_name = ncchar('time for chlorophyll'); |
---|
98 | nc{'chla_time'}.long_name = 'time for chlorophyll'; |
---|
99 | nc{'chla_time'}.units = ncchar('day'); |
---|
100 | nc{'chla_time'}.units = 'day'; |
---|
101 | if cycle~=0 |
---|
102 | nc{'chla_time'}.cycle_length = cycle; |
---|
103 | end |
---|
104 | % |
---|
105 | nc{'CHLA'}.long_name = ncchar('Chlorophyll'); |
---|
106 | nc{'CHLA'}.long_name = 'Chlorophyll'; |
---|
107 | nc{'CHLA'}.units = ncchar('mg C'); |
---|
108 | nc{'CHLA'}.units = 'mg C'; |
---|
109 | nc{'CHLA'}.fields = ncchar('CHLA, scalar, series'); |
---|
110 | nc{'CHLA'}.fields = 'CHLA, scalar, series'; |
---|
111 | % |
---|
112 | endef(nc); |
---|
113 | % |
---|
114 | % Record the time |
---|
115 | % |
---|
116 | nc{'chla_time'}(:)=t*30; % if time in month in the dataset !!! |
---|
117 | % |
---|
118 | % Get the missing values |
---|
119 | % |
---|
120 | missval=ncseas{'chlorophyll'}.missing_value(:); |
---|
121 | % |
---|
122 | % loop on time |
---|
123 | % |
---|
124 | for l=1:tlen |
---|
125 | disp(['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; |
---|
141 | end |
---|
142 | close(nc); |
---|
143 | close(ncseas); |
---|
144 | chla=squeeze(chlaroms(N,:,:)); |
---|
145 | return |
---|