source: Roms_tools/Preprocessing_tools/add_o2.m @ 2

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

import Roms_Agrif

File size: 3.8 KB
Line 
1function add_o2(oafile,climfile,inifile,gridfile,seas_datafile,...
2                 ann_datafile,cycle,makeoa,makeclim);
3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4%
5%  function [longrd,latgrd,o2]=add_o2(climfile,gridfile,...
6%                                       seas_datafile,ann_datafile,...
7%                                       cycle);
8%
9%  pierrick 2001
10%
11%  Add oxygen (mMol 0 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,o2] : 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);
44zo2=nc{'Z'}(:);
45kmax=max(find(zo2<hmax))-1;
46zo2=zo2(1:kmax);
47close(nc)
48%
49% open the OA file 
50%
51if (makeoa)
52  disp('Add_o2: creating variables and attributes for the OA file')
53  nc=netcdf(oafile,'write');
54  redef(nc);
55  nc('o2_time') = length(t);
56  nc{'o2_time'} = ncdouble('o2_time') ;
57  nc('Zo2') = length(zo2);
58  nc{'Zo2'} = ncdouble('Zo2') ;
59  nc{'O2'} = ncdouble('o2_time','Zo2','eta_rho','xi_rho') ;
60%
61  nc{'o2_time'}.long_name = ncchar('time for oxygen');
62  nc{'o2_time'}.long_name = 'time for oxygen';
63  nc{'o2_time'}.units = ncchar('day');
64  nc{'o2_time'}.units = 'day';
65  if cycle~=0
66    nc{'o2_time'}.cycle_length = cycle;
67  end
68%
69  nc{'Zo2'}.long_name = ncchar('Depth for O2');
70  nc{'Zo2'}.long_name = 'Depth for O2';
71  nc{'Zo2'}.units = ncchar('m');
72  nc{'Zo2'}.units = 'm';
73%
74  nc{'O2'}.long_name = ncchar('Oxygen');
75  nc{'O2'}.long_name = 'Oxygen';
76  nc{'O2'}.units = ncchar('mMol O m-3');
77  nc{'O2'}.units = 'mMol O m-3';
78  nc{'O2'}.fields = ncchar('O2, scalar, series');
79  nc{'O2'}.fields = 'O2, scalar, series';
80%
81  endef(nc);
82%
83% record deth and time and close
84%
85  nc{'o2_time'}(:)=t*30; % if time in month in the dataset !!!
86  nc{'Zo2'}(:)=zo2;
87  close(nc)
88end
89%
90% Same thing for the Clim file
91%
92if (makeclim)
93  disp('Add_o2: 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('o2_time') = length(t);;
100  nc{'o2_time'} = ncdouble('o2_time') ;
101  nc{'O2'} = ncdouble('o2_time','s_rho','eta_rho','xi_rho') ;
102%
103  nc{'o2_time'}.long_name = ncchar('time for oxygen');
104  nc{'o2_time'}.long_name = 'time for oxygen';
105  nc{'o2_time'}.units = ncchar('day');
106  nc{'o2_time'}.units = 'day';
107  if cycle~=0
108    nc{'o2_time'}.cycle_length = cycle;
109  end
110%
111  nc{'O2'}.long_name = ncchar('Oxygen');
112  nc{'O2'}.long_name = 'Oxygen';
113  nc{'O2'}.units = ncchar('mMol O m-3');
114  nc{'O2'}.units = 'mMol O m-3';
115  nc{'O2'}.fields = ncchar('O2, scalar, series');
116  nc{'O2'}.fields = 'O2, scalar, series';
117%
118  endef(nc);
119%
120% record the time and close
121%
122  nc{'o2_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.