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

Annotation of /MITgcm_contrib/gael/profilesMatlabProcessing/profiles_IO_v2/MITprof_gcm2nc.m

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


Revision 1.3 - (hide annotations) (download)
Fri Jul 1 18:04:32 2011 UTC (14 years ago) by gforget
Branch: MAIN
Changes since 1.2: +19 -8 lines
profiles_IO_v2/MITprof_gcm2nc.m
        update defaults for the directory and MITprof files list
profiles_IO_v2/MITprof_load.m
        quick fix when date/lon/lat is NaN

1 gforget 1.3 function []=MITprof_gcm2nc(varargin);
2     %[]=MITprof_gcm2nc;
3     %[]=MITprof_gcm2nc;
4     %object: takes binary output from MITgcm/pkg/profiles (in dir_model)
5     % and recomposes a MITprof netcdf file (in dir_model/input)
6     %optional inputs:
7     % dir_model is the directory where the binary files are ('./' by default)
8     % list_model is the list of the corresponding MITprof files, which
9     % need to be copied or linked to dir_model/input
10     % ({'seals*','WOD09_XBT*','WOD09_CTD*','argo_at*','argo_pa*','argo_in*'} by default)
11     %
12     %e.g. dir_model='./';
13     % list_model={'seals*','WOD09_XBT*','WOD09_CTD*','argo_at*','argo_pa*','argo_in*'};
14 gforget 1.1 % MITprof_gcm2nc(dir_model,list_model);
15     %note:
16     % by assumption, dir_model contains the binaries,
17     % dir_model/input contains the matching MITprof file
18 roquet 1.2 % that was provided as input to MITgcm/pkg/profiles, and
19 gforget 1.1 % the recomposed MITprof file will be put in dir_model/output
20    
21     warning off MATLAB:mir_warning_variable_used_as_function;
22    
23 gforget 1.3 if naring==2; dir_model=varargin{1}; list_model=varargin{2};
24     else;
25     dir_model='./';
26     list_model={'seals*','WOD09_XBT*','WOD09_CTD*','argo_at*','argo_pa*','argo_in*'};
27     end;
28    
29 gforget 1.1 dir_out=[dir_model 'output/']; dir_data=[dir_model 'input/'];
30    
31     %loop over files:
32     for ff=1:length(list_model)
33 roquet 1.2
34     %initialize the process:
35     clear prof_*;
36     file_data=dir([dir_data list_model{ff} '*.nc']);
37     file_data2=file_data.name;
38    
39     %load the data:
40     MITprof=MITprof_load([dir_data file_data2]);
41    
42     %prepare relevant output:
43     varList={'T','S','U','V','ptr','ssh'}; varNum=zeros(6,1); varCount=0;
44     for v=1:6; vv=varList{v};
45     if isfield(MITprof,['prof_' vv]);
46     varCount=varCount+1; varNum(v)=varCount;
47     eval(['prof_' vv '=-9999*ones(size(MITprof.prof_' vv ')); prof_' vv 'mask=prof_' vv ';']);
48     end;
49     end;
50     varList={varList{find(varNum)}};
51     nr=length(MITprof.prof_depth);
52    
53     %list tile/processor model files:
54     eval(['model_list_model=dir(''' dir_model list_model{ff} '*.data'');']);
55    
56     %if no model files then stop
57     if size(model_list_model,1)==0; fprintf(['file: ' file_data2 ' \n, no model files found\n']);
58     else;
59    
60     %loop over model files:
61     for ffM=1:length(model_list_model)
62     file_model2=model_list_model(ffM).name;
63     np=model_list_model(ffM).bytes/8/2/(nr+1)/varCount;
64     tmp_prof=read2memory([dir_model file_model2],[nr+1 2 varCount np],64);
65    
66     for v=1:varCount; vv=varList{v};
67     tmp1=squeeze(tmp_prof(1:nr,1,v,:))'; tmp2=squeeze(tmp_prof(1:nr,2,v,:))'; tmp3=squeeze(tmp_prof(nr+1,1,v,:));
68     tmp4=find(tmp3>0); tmp1=tmp1(tmp4,:); tmp2=tmp2(tmp4,:); tmp3=tmp3(tmp4,:);
69     eval(['prof_' vv '(tmp3,:)=tmp1; prof_' vv 'mask(tmp3,:)=tmp2;']);
70     end;
71     end; %for ffM
72    
73     %include in structure:
74     for v=1:varCount; vv=varList{v}; eval(['prof_' vv '(prof_' vv 'mask==0)=-9999; MITprof.prof_' vv 'estim=prof_' vv ';']); end;
75    
76     %prepare fields list:
77     list_out=fieldnames(MITprof)';
78     ii=find(strncmp(list_out,'prof_U',6)+strncmp(list_out,'prof_S',6)+strncmp(list_out,'prof_T',6)+...
79     strncmp(list_out,'prof_V',6)+strncmp(list_out,'prof_ssh',8)+strncmp(list_out,'prof_ptr',8));
80     list_out={list_out{ii}};
81     %prepare other fields:
82     file_out=[file_data2(1:end-3) '_model.nc'];
83     nr=length(MITprof.prof_depth);
84     np=length(MITprof.prof_lon);
85     %write to file:
86     MITprof_write([dir_out file_out],MITprof);
87    
88     fprintf(['file: ' file_data2 ' \n has been processed \n']);
89     end %if size(model_list_model,1)~=0;
90 gforget 1.1 end%for ff=1:length(list_model)
91    
92    

  ViewVC Help
Powered by ViewVC 1.1.22