/[MITgcm]/MITgcm_contrib/gael/profilesMatlabProcessing/profiles_IO_external/profiles_read_seals.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/profilesMatlabProcessing/profiles_IO_external/profiles_read_seals.m

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


Revision 1.2 - (hide annotations) (download)
Fri Nov 12 23:39:51 2010 UTC (15 years, 11 months ago) by gforget
Branch: MAIN
Changes since 1.1: +13 -0 lines
- make this work both with the legacy mexnc stuff (as before)
  and with the modern matlab native netcdf implementation.

1 gforget 1.1 function [varargout]=profile_read_seals(dataset,nf,m);
2    
3     fileIn=[dataset.dirIn dataset.fileInList(nf).name];
4    
5     %output:
6     % ymd hms imonth lat lon direc p t s p_ERR t_ERR s_ERR
7    
8     %common block:
9     global PLATFORM_NUMBER_fillval PLATFORM_NUMBER;
10     global VECdateOBS LATITUDE LONGITUDE DIRECTION;
11     global PRES PRES_ADJUSTED PRES_ADJUSTED_QC PRES_fillval PRES_QC;
12     global TEMP TEMP_ADJUSTED TEMP_ADJUSTED_QC TEMP_fillval TEMP_QC TEMP_ADJUSTED_ERROR;
13     global PSAL PSAL_ADJUSTED PSAL_ADJUSTED_QC PSAL_fillval PSAL_QC PSAL_ADJUSTED_ERROR;
14    
15    
16     if m==0;
17     %read the file and put the data in common blocks:
18    
19     clear PRES* PSAL* TEMP*;
20     global PRES PRES_ADJUSTED PRES_ADJUSTED_QC PRES_fillval PRES_QC;
21     global TEMP TEMP_ADJUSTED TEMP_ADJUSTED_QC TEMP_fillval TEMP_QC TEMP_ADJUSTED_ERROR;
22     global PSAL PSAL_ADJUSTED PSAL_ADJUSTED_QC PSAL_fillval PSAL_QC PSAL_ADJUSTED_ERROR;
23     TEMP=8888*ones(500,1);PSAL=8888*ones(500,1);
24    
25     %WHAT IS WRONG HERE???
26     %if ( rep_nb~=1|isempty(findstr(fileIn,'20050911_prof')) )
27    
28    
29     eval(['ncload ' fileIn ';']);
30    
31     %some dimensions inversions exist for _QC variables (!?)
32     if size(PRES_QC,1)~=size(PRES,1)
33     PRES_QC=PRES_QC';
34     if ~isempty(who('PRES_ADJUSTED_QC'));PRES_ADJUSTED_QC=PRES_ADJUSTED_QC';end;
35     if ~isempty(who('PSAL_QC'));PSAL_QC=PSAL_QC';end;
36     if ~isempty(who('PSAL_ADJUSTED_QC'));PSAL_ADJUSTED_QC=PSAL_ADJUSTED_QC';end;
37     if ~isempty(who('TEMP_QC'));TEMP_QC=TEMP_QC';end;
38     if ~isempty(who('TEMP_ADJUSTED_QC'));TEMP_ADJUSTED_QC=TEMP_ADJUSTED_QC';end;
39     end
40    
41     if size(PLATFORM_NUMBER,1)~=size(PRES,1); PLATFORM_NUMBER=PLATFORM_NUMBER'; end; %'
42    
43     %get the fillvalues:
44 gforget 1.2
45     global useNativeMatlabNetcdf; if isempty(useNativeMatlabNetcdf); useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); end;
46     if (useNativeMatlabNetcdf);
47     ncid=netcdf.open(fileIn,'nowrite');
48     vv = netcdf.inqVarID(ncid,'PRES'); PRES_fillval=netcdf.getAtt(ncid,vv,'_FillValue');
49     if PSAL(1,1) ~= 8888; vv = netcdf.inqVarID(ncid,'PSAL'); PSAL_fillval=netcdf.getAtt(ncid,vv,'_FillValue'); end;
50     if TEMP(1,1) ~= 8888; vv = netcdf.inqVarID(ncid,'TEMP'); TEMP_fillval=netcdf.getAtt(ncid,vv,'_FillValue'); end;
51     vv = netcdf.inqVarID(ncid,'PLATFORM_NUMBER'); PLATFORM_NUMBER_fillval=netcdf.getAtt(ncid,vv,'_FillValue');
52     netcdf.close(ncid);
53     else;%try to use old mex stuff
54 gforget 1.1 nc = netcdf(fileIn, 'nowrite');
55     PRES_fillval=fillval(nc{'PRES'});
56     PSAL_fillval=fillval(nc{'PSAL'});
57     TEMP_fillval=fillval(nc{'TEMP'});
58     PLATFORM_NUMBER_fillval=fillval(nc{'PLATFORM_NUMBER'});
59     nc = close(nc);
60 gforget 1.2 end;
61    
62     if size(REFERENCE_DATE_TIME,1)>1; REFERENCE_DATE_TIME=REFERENCE_DATE_TIME'; end;
63 gforget 1.1
64     REFdateOBS=str2num(strvcat(REFERENCE_DATE_TIME(1:4),REFERENCE_DATE_TIME(5:6),REFERENCE_DATE_TIME(7:8),REFERENCE_DATE_TIME(9:10),REFERENCE_DATE_TIME(11:12),REFERENCE_DATE_TIME(13:14)))';%'
65     REFdateOBS=jul_0h(REFdateOBS);
66     VECdateOBS=REFdateOBS+JULD;
67    
68     xx=size(PRES);mloc=xx(1);mpts=xx(2);
69    
70     varargout(1) = {length(LONGITUDE)};
71    
72     else;%if m~=0;
73     %select one profile for output:
74    
75     %date, position, etc
76    
77     tmp1=greg_0h(VECdateOBS(m));
78     ymd=tmp1(1)*1e4+tmp1(2)*1e2+tmp1(3);
79     hms=tmp1(4)*1e4+tmp1(5)*1e2+tmp1(6);
80    
81     lat=LATITUDE(m);
82     lon=LONGITUDE(m);
83     if lon < 0; lon=lon+360; end;
84    
85     %%%%%%%ilon=find(((vec_lon-lon).^2)==min((vec_lon-lon).^2)); ilon=ilon(1);
86     %%%%%%%ilat=find(((vec_lat-lat).^2)==min((vec_lat-lat).^2)); ilat=ilat(1);
87    
88     direc=0;if(DIRECTION(m)=='A');direc=1;end;if(DIRECTION(m)=='D');direc=2;end
89    
90     pnum_txt=deblank(PLATFORM_NUMBER(m,:));
91     pnum_txt=pnum_txt(pnum_txt~=PLATFORM_NUMBER_fillval);
92     pnum=double(pnum_txt); pnum=pnum(find(pnum>=48&pnum<=57)); pnum=str2num(char(pnum));
93     if isempty(pnum); pnum_txt='9999'; pnum=9999; end;
94    
95     %observations
96    
97     % if ~isempty(PRES_ADJUSTED), %taking adjusted fields
98     % p=PRES_ADJUSTED(m,:);
99     % p_QC=PRES_ADJUSTED_QC(m,:);
100     % t=TEMP_ADJUSTED(m,:);
101     % t_QC=TEMP_ADJUSTED_QC(m,:);
102     % s=PSAL_ADJUSTED(m,:);
103     % s_QC=PSAL_ADJUSTED_QC(m,:);
104     % t_ERR=TEMP_ADJUSTED_ERROR(m,:);
105     % t_ERR(t_ERR==TEMP_fillval|isnan(t_ERR))=0;
106     % s_ERR=PSAL_ADJUSTED_ERROR(m,:);
107     % s_ERR(s_ERR==PSAL_fillval|isnan(s_ERR))=0;
108     %
109     % else
110     p=PRES(m,:);
111     p_QC=PRES_QC(m,:);
112     t=TEMP(m,:);
113     t_QC=TEMP_QC(m,:);
114     s=PSAL(m,:);
115     s_QC=PSAL_QC(m,:);
116     t_ERR=p*0; s_ERR=p*0;
117    
118     % end
119    
120    
121     p(isnan(p))=PRES_fillval;
122     p_QC(isnan(p))='5';
123     for n=1:length(p)-1;
124     tmp1=find(p(n+1:end)==p(n)&p(n+1:end)~=PRES_fillval);
125     p(n+tmp1)=PRES_fillval;p_QC(n+tmp1)='5';
126     end
127    
128     bad_P=0;
129     tmp1=find(p_QC=='4');
130     if(length(tmp1)<=5);
131     %get rid of these few bad points and keep the profile
132     p(tmp1)=PRES_fillval;p_QC(tmp1)='5';
133     else;
134     %flag the profile (will be masked in the main file)
135     %but keep the bad points (to interp and be able to CHECK)
136     bad_P=1;
137     end;
138    
139     p(p==PRES_fillval)=NaN;
140     p(p==PRES_fillval)=NaN;
141     if isempty(whos('t')); %this file does not contain salinity data...
142     t=NaN*p; t_ERR=0*p;
143     else;
144     t(t_QC~='1'&t_QC~='2')=NaN;
145     end;
146    
147     if isempty(whos('s')); %this file does not contain salinity data...
148     s=NaN*t; s_ERR=0*t_ERR;
149     else;
150     s(s_QC~='1'&s_QC~='2')=NaN;
151     end;
152    
153    
154     profileCur.pnum_txt=pnum_txt;
155     profileCur.ymd=ymd; profileCur.hms=hms;
156     profileCur.lat=lat; profileCur.lon=lon;
157     profileCur.direc=direc;
158     profileCur.t=t;
159     profileCur.s=s;
160     profileCur.p=p;
161     profileCur.t_ERR=t_ERR;
162     profileCur.s_ERR=s_ERR;
163     profileCur.PorZisBAD=bad_P;
164    
165     %bad_latlon=0;
166     %if profileCur.lat<-90|profileCur.lat>90; bad_latlon=1; end;
167     %if profileCur.lon<-180|profileCur.lon>360; bad_latlon=1; end;
168     %profileCur.LONorLATisBAD=bad_latlon;
169    
170     varargout = {profileCur};
171    
172     end;
173    
174    
175    

  ViewVC Help
Powered by ViewVC 1.1.22