source: Roms_tools/Preprocessing_tools/add_doc.m @ 2

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

import Roms_Agrif

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