1 |
gforget |
1.1 |
%function: MITprof_write |
2 |
|
|
%object: read netcdf data files in the "MIT format" |
3 |
|
|
%author: Gael Forget (gforget@mit.edu) |
4 |
|
|
%date: june 21th, 2006 |
5 |
|
|
% |
6 |
gforget |
1.2 |
%usage: []=MITprof_write(fileOut,MITprof); |
7 |
|
|
% ---> writes MITprof to the fileOut file |
8 |
gforget |
1.1 |
% that has previously been created using MITprof_create |
9 |
|
|
% |
10 |
gforget |
1.2 |
%inputs: fileOut data file name |
11 |
|
|
% list_vars variable list (optional) |
12 |
gforget |
1.1 |
% |
13 |
gforget |
1.2 |
%outputs: MITprof structure containing the various arrays |
14 |
gforget |
1.1 |
|
15 |
gforget |
1.2 |
function []=MITprof_write(fileOut,MITprof); |
16 |
|
|
|
17 |
|
|
%get directory name: |
18 |
|
|
tmp1=strfind(fileOut,'/'); |
19 |
|
|
if ~isempty(tmp1); dirOut=fileOut(1:tmp1(end)); else; dirOut='./'; end; |
20 |
|
|
%check that file exists: |
21 |
|
|
tmp1=dir(fileOut); |
22 |
|
|
if isempty(tmp1); tmp1=dir([fileOut '.nc']); end; |
23 |
|
|
if isempty(tmp1); error([fileOut ' file not found']); end; |
24 |
|
|
%open file: |
25 |
|
|
nc=netcdf([dirOut tmp1.name],'write'); |
26 |
gforget |
1.1 |
|
27 |
|
|
|
28 |
|
|
list_vars=fieldnames(MITprof); |
29 |
|
|
for ii=1:length(list_vars); |
30 |
|
|
eval(['tmp1=MITprof.' list_vars{ii} ';']); |
31 |
|
|
nc{list_vars{ii}}(:)=tmp1; |
32 |
|
|
end; |
33 |
|
|
|
34 |
|
|
close(nc); |
35 |
|
|
|