0001 function Mobj = get_NAE2_forcing(Mobj, inputConf)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 subname = 'get_NAE2_forcing';
0040
0041 global ftbverbose;
0042 if(ftbverbose);
0043 fprintf('\n')
0044 fprintf(['begin : ' subname '\n'])
0045 end
0046
0047
0048 if isunix
0049 metfname = ['/bank/jane/met/',datestr(inputConf.startDate,'YYYY'),...
0050 '/',lower(datestr(inputConf.startDate,'mmmYY')),'nae10R.dat'];
0051 comprfname = '/login/jane/NAE2/metintco.cs3x.nae2.compress.2';
0052 setupfname = '/work/jane/cs3x/prep/setupcs3xSGIl.uda';
0053
0054
0055 elseif ispc
0056 metfname = ['\\store\bank\jane\met\',datestr(inputConf.startDate,'YYYY'),...
0057 '\',lower(datestr(inputConf.startDate,'mmmYY')),'nae10R.dat'];
0058 comprfname = '\\store\kthurs\from_Jane\metintco.cs3x.nae2.compress.2';
0059 setupfname = '\\store\work\jane\cs3x\prep\setupcs3xSGIl.uda';
0060
0061
0062 end
0063
0064
0065 cs3x_nx = 198;
0066 cs3x_ny = 207;
0067 cs3x_lonstart = -19-(5/6);
0068 cs3x_latstart = 40+(1/9);
0069 cs3x_loninc = 1/6;
0070 cs3x_latinc = 1/9;
0071 cs3x_lonfin = cs3x_lonstart+(cs3x_loninc*(cs3x_nx-1));
0072 cs3x_latfin = cs3x_latstart+(cs3x_latinc*(cs3x_ny-1));
0073 cs3x_lon = cs3x_lonstart:cs3x_loninc:cs3x_lonfin;
0074 cs3x_lat = cs3x_latstart:cs3x_latinc:cs3x_latfin;
0075
0076
0077
0078 if min(Mobj.lon) < cs3x_lonstart || max(Mobj.lon) > cs3x_lonfin || ...
0079 min(Mobj.lat) < cs3x_latstart || max(Mobj.lat) > cs3x_latfin
0080 error('Your FVCOM grid is bigger than the available cs3x grid. Choose another met forcing option or crop your FVCOM grid.')
0081 end
0082
0083
0084 fid = fopen(comprfname);
0085 tline = fgets(fid);
0086 count=0;
0087 while ischar(tline)
0088 count=count+1;
0089 compr_info{count}=tline;
0090 tline = fgets(fid);
0091 end
0092 fclose(fid);
0093
0094
0095
0096
0097
0098 temp = sscanf(char(compr_info{1}),'%u');
0099 NCCP = temp(1);
0100 NRRP = temp(2);
0101 NCCW = temp(3);
0102 NRRW = temp(4);
0103 NTOTI = temp(5);
0104
0105
0106 compr_array = nan(10,length(compr_info)-1);
0107
0108 for i=2:length(compr_info)
0109 temp = sscanf(char(compr_info{i}),'%8f');
0110 compr_array(:,i-1) = temp;
0111 end
0112
0113 nelf = max(compr_array(1:4*NTOTI))+1;
0114
0115
0116 IBLP = compr_array(1:NTOTI)-1;
0117 IBRP = compr_array(NTOTI+1:2*NTOTI)-1;
0118
0119
0120 IBLW = compr_array(2*NTOTI+1:3*NTOTI)-1;
0121 IBRW = compr_array(3*NTOTI+1:4*NTOTI)-1;
0122
0123
0124 WTRP = compr_array(4*NTOTI+1:5*NTOTI);
0125 WBRP = compr_array(5*NTOTI+1:6*NTOTI);
0126 WTLP = compr_array(6*NTOTI+1:7*NTOTI);
0127 WBLP = compr_array(7*NTOTI+1:8*NTOTI);
0128
0129
0130 WTRW = compr_array(8*NTOTI+1:9*NTOTI);
0131 WBRW = compr_array(9*NTOTI+1:10*NTOTI);
0132 WTLW = compr_array(10*NTOTI+1:11*NTOTI);
0133 WBLW = compr_array(11*NTOTI+1:12*NTOTI);
0134
0135
0136 COEFF1 = compr_array(12*NTOTI+1:13*NTOTI);
0137 COEFF2 = compr_array(13*NTOTI+1:14*NTOTI);
0138
0139 clear compr_info compr_array
0140
0141
0142 fid=fopen(setupfname,'r','b');
0143 temp=fread(fid,inf,'*int32','b');
0144 fclose(fid);
0145
0146 NRR = temp(2);
0147 NCC = temp(3);
0148 ITOT = temp(4);
0149 IINZ = temp(5);
0150
0151 NTRNS = temp(8:NRR+7);
0152 NTRNT = temp(NRR+10:2*NRR+9);
0153 NSUM = temp(2*NRR+12:3*NRR+11);
0154
0155 clear temp
0156
0157
0158 hw0 = 1;
0159 hw1 = 326;
0160 hw2 = 100;
0161 hw3 = 521;
0162 hw4 = 600;
0163 hw5 = (hw1-hw0)*(hw3-hw2);
0164
0165
0166
0167 ELFI = zeros(hw5,1);
0168 FIEJ = zeros(hw5,1);
0169
0170 count = 1;
0171 j = 1;
0172
0173 for iy = hw0:(hw1-1)
0174 for ix = hw2:(hw3-1)
0175 i = ix+iy*hw4;
0176 j = j+1;
0177 ELFI(count) = i-1;
0178 FIEJ(count) = j-1;
0179 count = count+1;
0180 end
0181 end
0182
0183 if max(ELFI)+1 > nelf
0184 nelf = max(ELFI)+1;
0185 end
0186
0187 if max(FIEJ)+1 > nelf
0188 nelf = max(FIEJ)+1;
0189 end
0190
0191
0192
0193
0194 timesteps = datevec(datenum(inputConf.startDate):datenum(inputConf.endDate)+1);
0195
0196
0197 [months,ia]=unique(timesteps(:,1:2),'rows');
0198
0199 for i=1:size(months,1)
0200
0201 if isunix
0202 metfname = ['/bank/jane/met/',num2str(timesteps(ia(i),1)),...
0203 '/',lower(datestr(timesteps(ia(i),:),'mmmYY')),'nae10R.dat'];
0204 elseif ispc
0205 metfname = ['\\store\bank\jane\met\',num2str(timesteps(ia(i),1)),...
0206 '\',lower(datestr(timesteps(ia(i),:),'mmmYY')),'nae10R.dat'];
0207 end
0208
0209 PASTIT = false;
0210 kline = 0;
0211
0212
0213 fid = fopen(metfname);
0214
0215
0216 I = fgets(fid);
0217 m1 = sscanf(I,'%u');
0218 data_seg = ceil(m1(1)/m1(2));
0219
0220 frewind(fid);
0221
0222 if i==1
0223
0224 met_temp = cell(1);
0225 end
0226
0227
0228 while PASTIT == false
0229 kline = kline + 2;
0230 I = fgets(fid);
0231 if I==-1
0232
0233 break
0234 end
0235 J = fgets(fid);
0236 if J==-1
0237
0238 break
0239 end
0240
0241
0242 datem = sscanf(J,'%u');
0243 datem = datenum(datem(4),datem(3),datem(2),datem(1),0,0);
0244
0245
0246
0247
0248 if (datem >= datenum(inputConf.startDate)) && ...
0249 (datem <= datenum(inputConf.endDate))
0250
0251 temp = cell(data_seg+2,1);
0252
0253 temp{1} = sscanf(I,'%u');
0254 temp{2} = sscanf(J,'%u');
0255
0256 for m = 1:data_seg
0257 I = fgetl(fid);
0258 temp{m+2} = sscanf(I,'%10f');
0259 end
0260 met_temp{end+1}=temp;
0261 clear temp;
0262 else
0263 PASTIT = true;
0264 end
0265 end
0266
0267 fclose(fid);
0268 end
0269
0270 met_temp = met_temp(2:end);
0271
0272
0273 JBLP = IBLP-NCCP;
0274 JBRP = IBRP-NCCP;
0275 JBLW = IBLW-NCCW;
0276 JBRW = IBRW-NCCW;
0277
0278 elf = zeros(nelf,1);
0279
0280
0281 P2 = zeros(NTOTI,1);
0282 tmpa = zeros(NTOTI,1);
0283 tmpb = zeros(NTOTI,1);
0284
0285
0286 kline = 1;
0287
0288
0289
0290 slp = zeros(Mobj.nVerts,size(met_temp,2)/3);
0291 uwnd = zeros(Mobj.nElems,size(met_temp,2)/3);
0292 vwnd = zeros(Mobj.nElems,size(met_temp,2)/3);
0293 time = zeros(size(met_temp,2)/3,1);
0294
0295
0296
0297 for m=0:3:size(met_temp,2)-1
0298 for ISW = 1:3
0299 kline = kline+2;
0300 ipts = met_temp{m+ISW}{1}(1);
0301 kpts = met_temp{m+ISW}{1}(2);
0302
0303
0304 if ISW == 1
0305 time((m/3)+1) = datenum(met_temp{m+ISW}{2}(4),...
0306 met_temp{m+ISW}{2}(3),met_temp{m+ISW}{2}(2),...
0307 met_temp{m+ISW}{2}(1),0,0);
0308 end
0309
0310
0311 field = NaN(8,data_seg);
0312
0313
0314 for n=1:data_seg
0315 field(:,n)=met_temp{m+ISW}{n+2};
0316 end
0317 field = reshape(field,data_seg*8,1);
0318
0319
0320 if size(met_temp{m+ISW}{end},1)<8
0321 too_many = 8-size(met_temp{m+ISW}{end},1);
0322 field = field(1:end-too_many);
0323 end
0324
0325 elf(ELFI)=field(FIEJ);
0326
0327
0328 if ISW == 1
0329 P2 = (WBLP.*elf(IBLP)')+(WBRP.*elf(IBRP)')+(WTLP.*elf(JBLP)')+...
0330 (WTRP.*elf(JBRP)');
0331 elseif ISW == 2
0332 tmpa = (WBLW.*elf(IBLW)')+(WBRW.*elf(IBRW)')+(WTLW.*elf(JBLW)')+...
0333 (WTRW.*elf(JBRW)');
0334 elseif ISW == 3
0335 tmpb = (WBLW.*elf(IBLW)')+(WBRW.*elf(IBRW)')+(WTLW.*elf(JBLW)')+...
0336 (WTRW.*elf(JBRW)');
0337 end
0338
0339 kline = kline+data_seg;
0340 end
0341
0342
0343 tmpc = (COEFF1.*tmpa)+(COEFF2.*tmpb);
0344 tmpd = (COEFF1.*tmpb)-(COEFF2.*tmpa);
0345
0346 k = 0;
0347
0348
0349 for j = 0:NRR-1
0350 I1 = NTRNT(j+1);
0351 I2 = NTRNS(j+1);
0352 for i = I1+1:I2
0353 k = k+1;
0354 PRESS(i,NRR-j) = P2(k);
0355 U10E(i,NRR-j) = tmpc(k);
0356 U10N(i,NRR-j) = tmpd(k);
0357 end
0358 end
0359
0360
0361 slp(:,(m/3)+1) = interp2(cs3x_lon,cs3x_lat,PRESS',Mobj.lon,Mobj.lat);
0362
0363
0364 xelement = mean(Mobj.lon(Mobj.tri(:,:)),2);
0365 yelement = mean(Mobj.lat(Mobj.tri(:,:)),2);
0366
0367
0368 uwnd(:,(m/3)+1) = interp2(cs3x_lon,cs3x_lat,U10E',xelement,yelement);
0369 vwnd(:,(m/3)+1) = interp2(cs3x_lon,cs3x_lat,U10N',xelement,yelement);
0370 end
0371
0372
0373 time = datevec(time);
0374 MJD_time = greg2mjulian(time(:,1),time(:,2),time(:,3),time(:,4),time(:,5),...
0375 time(:,6));
0376
0377
0378 Mobj.Met.slp.node = slp;
0379 Mobj.Met.uwnd.data = uwnd;
0380 Mobj.Met.vwnd.data = vwnd;
0381 Mobj.Met.time = MJD_time;
0382
0383 if(ftbverbose);
0384 fprintf(['end : ' subname '\n']);
0385 end