/[MITgcm]/MITgcm_contrib/gael/profilesMatlabProcessing/profiles_IO_v2/MITprof_write.m
ViewVC logotype

Contents of /MITgcm_contrib/gael/profilesMatlabProcessing/profiles_IO_v2/MITprof_write.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.10 - (show annotations) (download)
Mon Feb 1 14:35:06 2016 UTC (9 years, 5 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, HEAD
Changes since 1.9: +1 -1 lines
- MITprof_create.m: replace nProf,prof_depth inputs by MITprofCur;
  determine iINTERP based upon MITprofCur.prof_interp_weights.
- MITprof_write.m: update call to MITprof_create.

1 function []=MITprof_write(fileOut,MITprof,varargin);
2 %function: MITprof_write
3 %object: write data in a MITprof netcdf file
4 %author: Gael Forget (gforget@mit.edu)
5 %date: Nov 5th, 2010
6 %
7 %usage: []=MITprof_write(fileOut,MITprof, [list_vars] );
8 %
9 %inputs: fileOut data file name (absolute/relative path)
10 % .nc suffix is added if not already present
11 % MITprof struct containing profile data
12 % list_vars variable list (optional)
13 %
14 % Format description of MITprof struct input variable:
15 % list of fields always available:
16 % prof_depth [nDepth x 1]
17 % prof_descr {nProf x 1} --> will be converted into a char array
18 % prof_date [nProf x 1]
19 % prof_YYYYMMDD [nProf x 1]
20 % prof_HHMMSS [nProf x 1]
21 % prof_lon [nProf x 1]
22 % prof_lat [nProf x 1]
23 % prof_basin [nProf x 1]
24 % prof_point [nProf x 1]
25 %
26 % other fields generally available of size [nProf x nLev] :
27 % prof_T, prof_Tflag, prof_Terr, prof_Tweight, prof_Testim
28 % prof_S, prof_Sflag, prof_Serr, prof_Sweight, prof_Sestim
29 %
30 % if list_vars is not specified, every variables with a name starting
31 % with 'prof_', except prof_depth, will be saved in the MITprof
32 % netcdf file. An error will occur if the program try to save a
33 % variable that is not initialized in the MITprof netcdf file.
34 %
35 % if list_vars is specified, only variables present in the list will be
36 % saved.
37 %
38 % NaN are auomatically replaced by missing_value attribute (or _FillValue).
39 % the file fileOut will be created using MITprof_create if needed.
40 %
41
42
43
44 % check that file exists and add prefix and suffix if necessary
45 [pathstr, name, ext] = fileparts(fileOut);
46 if isempty(pathstr) | strcmp(pathstr,'.'), pathstr=pwd; end
47 if isempty(ext) | ~strcmp(ext,'.nc'), ext='.nc'; end
48 fileOut=[pathstr '/' name ext];
49
50 % build the list of variables that must be loaded
51 if nargin>2,
52 list_vars=varargin{1};
53 else
54 list1=fieldnames(MITprof); list_vars={};
55 I=strfind(list1,'prof_');
56 for kk=1:length(I),
57 if I{kk}==1,
58 list_vars{end+1}=list1{kk};
59 end
60 end
61 end
62
63 % stop if there are no profile in MITprof
64 nProf=length(MITprof.prof_lon);
65 if nProf==0, return, end
66
67 % create the file if needed
68 if ~exist(fileOut,'file'),
69 prof_depth=MITprof.prof_depth;
70 MITprof_create(fileOut,MITprof,list_vars);
71 end
72
73 % prof_descr: convert back from cell 2 array format
74 if isfield(MITprof,'prof_descr')
75 ncload(fileOut,'prof_descr'); nb_char=size(prof_descr,2);
76 prof_descr=char(MITprof.prof_descr);
77 if size(prof_descr,2)<nb_char,
78 prof_descr(:,size(prof_descr,2)+1:nb_char)=' ';
79 elseif size(prof_descr,2)>nb_char
80 disp('some profile descriptive strings have been shortened');
81 prof_descr=prof_descr(:,1:nb_char);
82 end
83 MITprof.prof_descr=prof_descr;
84 end
85
86 % write to file:
87 nc=ncopen(fileOut,'write');
88 vars=ncvars(nc);
89 list_vars=intersect(vars,list_vars);
90 for ii=1:length(list_vars);
91 varname=list_vars{ii};
92 data=getfield(MITprof,varname);
93 spval=ncgetFillVal(nc,varname);
94 if isnumeric(data)
95 if isempty(spval),
96 warning(['no FillVal for ' varname ': use of -9999 default value']);
97 spval=double(-9999);
98 end
99 data(isnan(data))=spval;
100 MITprof=setfield(MITprof,varname,data);
101 end
102 ncputvar(nc,varname,data);
103 end
104 ncclose(nc);
105
106
107

  ViewVC Help
Powered by ViewVC 1.1.22