source: Roms_tools/Preprocessing_tools/add_dic.m @ 1

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

import Roms_Agrif

File size: 3.9 KB
Line 
1function add_dic(oafile,climfile,inifile,gridfile,seas_datafile,...
2                 ann_datafile,cycle,makeoa,makeclim);
3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4%
5%  function [longrd,latgrd,dic]=add_dic(climfile,gridfile,...
6%                                       seas_datafile,ann_datafile,...
7%                                       cycle);
8%
9%  pierrick 2001
10%
11%  Add DIC (mMol C m-3) in a ROMS climatology file
12%  take seasonal data for the upper levels and annual data for the
13%  lower levels
14%
15%  input:
16%   
17%    climfile      : roms climatology file to process (netcdf)
18%    gridfile      : roms grid file (netcdf)
19%    seas_datafile : regular longitude - latitude - z seasonal data
20%                    file used for the upper levels  (netcdf)
21%    ann_datafile  : regular longitude - latitude - z annual data
22%                    file used for the lower levels  (netcdf)
23%    cycle         : time length (days) of climatology cycle (ex:360 for
24%                    annual cycle) - 0 if no cycle.
25%
26%   output:
27%
28%    [longrd,latgrd,dic] : surface field to plot (as an illustration)
29%
30%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31%
32% Read in the grid
33%
34nc=netcdf(gridfile);
35hmax=max(max(nc{'h'}(:)));
36close(nc);
37%
38% read in the datafiles
39%
40nc=netcdf(seas_datafile);
41t=nc{'T'}(:);
42close(nc)
43nc=netcdf(ann_datafile);
44zdic=nc{'Z'}(:);
45kmax=max(find(zdic<hmax))-1;
46zdic=zdic(1:kmax);
47close(nc)
48%
49% open the OA file 
50%
51if (makeoa)
52  disp('Add_dic: creating variables and attributes for the OA file')
53  nc=netcdf(oafile,'write');
54  redef(nc);
55  nc('dic_time') = length(t);
56  nc{'dic_time'} = ncdouble('dic_time') ;
57  nc('Zdic') = length(zdic);
58  nc{'Zdic'} = ncdouble('Zdic') ;
59  nc{'DIC'} = ncdouble('dic_time','Zdic','eta_rho','xi_rho') ;
60%
61  nc{'dic_time'}.long_name = ncchar('time for DIC');
62  nc{'dic_time'}.long_name = 'time for DIC';
63  nc{'dic_time'}.units = ncchar('day');
64  nc{'dic_time'}.units = 'day';
65  if cycle~=0
66    nc{'dic_time'}.cycle_length = cycle;
67  end
68%
69  nc{'Zdic'}.long_name = ncchar('Depth for DIC');
70  nc{'Zdic'}.long_name = 'Depth for DIC';
71  nc{'Zdic'}.units = ncchar('m');
72  nc{'Zdic'}.units = 'm';
73%
74  nc{'DIC'}.long_name = ncchar('DIC');
75  nc{'DIC'}.long_name = 'DIC';
76  nc{'DIC'}.units = ncchar('mMol C m-3');
77  nc{'DIC'}.units = 'mMol C m-3';
78  nc{'DIC'}.fields = ncchar('DIC, scalar, series');
79  nc{'DIC'}.fields = 'DIC, scalar, series';
80%
81  endef(nc);
82%
83% record deth and time and close
84%
85  nc{'dic_time'}(:)=t*30; % if time in month in the dataset !!!
86  nc{'Zdic'}(:)=zdic;
87  close(nc)
88end
89%
90% Same thing for the Clim file
91%
92if (makeclim)
93  disp('Add_dic: creating variables and attributes for the Climatology file')
94%
95% open the clim file 
96%
97  nc=netcdf(climfile,'write');
98  redef(nc);
99  nc('dic_time') = length(t);;
100  nc{'dic_time'} = ncdouble('dic_time') ;
101  nc{'DIC'} = ncdouble('dic_time','s_rho','eta_rho','xi_rho') ;
102%
103  nc{'dic_time'}.long_name = ncchar('time for DIC');
104  nc{'dic_time'}.long_name = 'time for DIC';
105  nc{'dic_time'}.units = ncchar('day');
106  nc{'dic_time'}.units = 'day';
107  if cycle~=0
108    nc{'dic_time'}.cycle_length = cycle;
109  end
110%
111  nc{'DIC'}.long_name = ncchar('DIC');
112  nc{'DIC'}.long_name = 'DIC';
113  nc{'DIC'}.units = ncchar('mMol C m-3');
114  nc{'DIC'}.units = 'mMol C m-3';
115  nc{'DIC'}.fields = ncchar('DIC, scalar, series');
116  nc{'DIC'}.fields = 'DIC, scalar, series';
117%
118  endef(nc);
119%
120% record the time and close
121%
122  nc{'dic_time'}(:)=t*30; % if time in month in the dataset !!!
123  close(nc)
124end
125%
126% Same thing for the Initial file
127%
128%disp('Add_no3: creating variables and attributes for the Initial file')
129%
130% open the clim file 
131%
132%nc=netcdf(inifile,'write');
133%redef(nc);
134%nc{'NO3'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
135%
136%nc{'NO3'}.long_name = ncchar('Nitrate');
137%nc{'NO3'}.long_name = 'Nitrate';
138%nc{'NO3'}.units = ncchar('mMol N m-3');
139%nc{'NO3'}.units = 'mMol N m-3';
140%
141%endef(nc);
142%close(nc)
143
144return
Note: See TracBrowser for help on using the repository browser.