资源简介

usemakedir为按照年份创建文件夹,duqu_ncep为读取ncep的风场nc文件,duqu_ecmwf为读取ECMWF的风场nc文件,windin为将读取完的风场数据分批储存,便于SWAN调用

资源截图

代码片段和文件信息

clear all; close all; clc;
tic
for yearnum=1979:2017
    cd([‘F:\pythondownload\separate\‘num2str(yearnum)])                   %打开年份文件夹
    for monthnum=6:12
    cd([‘F:\pythondownload\separate\‘num2str(yearnum)]); 
       if monthnum<10                                                      
          filename{monthnum}=[num2str(yearnum)‘0‘num2str(monthnum)];   
       else
          filename{monthnum}=[num2str(yearnum)num2str(monthnum)];
       end
       filen1=strcat([filename{monthnum}‘.nc‘]);                          %读入文件名
       ncid = netcdf.open(filen1‘NC_NOWRITE‘);                            %打开文件
       lat=double(ncread(filen1‘latitude‘));                              %读入‘2009年1月有效波高.nc‘文件中的纬度,变量名字不能改
       lon=double(ncread(filen1‘longitude‘));                             %读入经度
       [lon1lat1]=meshgrid(lonlat);
       %     [lat1lon1]=meshgrid(latlon);
       U10=ncread(filen1‘u10‘);                                           %读入有效波高
       V10=ncread(filen1‘v10‘);                                           %读入有效波高
       
       lonswn = [118:0.125:124]; %29 118 0 64 48 0.125 0.125
       latswn = [29:0.125:37];
       [lon2lat2] = meshgrid(lonswnlatswn);
       
       TimeData=ncread([filename{monthnum}‘.nc‘]‘time‘);
       disp(strcat(‘Done reading‘filen1));                                %显示功能显示所需要的数据变量等已经输入完毕
       %    A=u10(5050:)
       %    B=shiftdim(A2)
       T=double(TimeData);
       L=(T-T(1))/24;
       R=datenum(yearnummonthnum1000);
       format long;
       %    BEGIN=(datenum(20111213000)-R)*24;
       %    END=(datenum(201211201200)-R)*24;
       K=R+L;
       DateString = datestr(K‘yyyymmddHH‘);
       if mod(yearnum4)==0
           monthFeb=29;
       else
           monthFeb=28;
       end
           if monthnum==1 || monthnum==3 || monthnum==5 || monthnum==7 || monthnum==8 || monthnum==10 || monthnum==12
               daynum=31;
           elseif monthnum==2
               daynum=monthFeb;
           else
               daynum=30;
           end
       for i=1:(daynum*4)
           aa(i:)=strcat(DateString(i:)‘.txt‘);
       end
       %    aaa=DateString(1:)
       %    DateString = datestr(989550/24+R‘yyyymmddHH‘)
       
       cd([‘F:\pythondownload\windtxt\‘num2str(yearnum)‘\‘filename{monthnum}]);
       for i=1:(daynum*4)
           w=[];
           name=strcat(DateString(i:)‘.txt‘);
           curfold =pwd;
           fid=fopen(strcat(curfold‘\‘name)‘wt+‘);
           u=double(U10(::i)‘);
           v=double(V10(::i)‘);
           
           uq = griddata(lon1lat1ulon2lat2); uq(isnan(uq))=0;
           vq = griddata(lon1lat1vlon2lat2); vq(isnan(vq))=0;
           w = [uq;vq];
           dlmwrite(strcat(curfold‘\‘name)w‘delimiter‘‘\t‘);
           fclose(fid);
           x=w‘;
           %bb(i1:2)=x;
           
       end
       toc
       clearvars -exce

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       3425  2018-08-08 18:58  duqu_ecmwf.m

     文件       2069  2018-07-25 18:14  duqu_ncep.m

     文件       1700  2018-09-01 17:30  usemakedir.m

     文件       1365  2018-08-15 17:27  windin.m

----------- ---------  ---------- -----  ----

                 8559                    4


评论

共有 条评论