Changeset 7


Ignore:
Timestamp:
05/04/11 17:34:07 (13 years ago)
Author:
cholod
Message:

patch_romstools_16_02_2011.tar : Bug in make_NCEP.m, get_NCEP_grid.m

Location:
Roms_tools/Aforc_NCEP
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Roms_tools/Aforc_NCEP/get_NCEP_grid.m

    r1 r7  
    7979lat=lat(j); 
    8080% 
     81% If we are in OpenDap (Get_My_Data=0) we need 
     82% a shift of decal=1, because the indexes begin at 0 in OpenDap. 
     83% If we use local data, Get_My_Data=1, there is no shift needed,  
     84% then decal=0; 
     85 
     86if Get_My_Data==1 
     87    decal=0; 
     88else 
     89    decal=1; 
     90end 
     91% 
    8192if ~isempty(i1) 
    82   i1min=min(i1)-1; 
    83   i1max=max(i1)-1; 
     93  i1min=min(i1)-decal; 
     94  i1max=max(i1)-decal; 
    8495else 
    8596  i1min=[]; 
     
    8798end 
    8899if ~isempty(i2) 
    89   i2min=min(i2)-1; 
    90   i2max=max(i2)-1; 
     100  i2min=min(i2)-decal; 
     101  i2max=max(i2)-decal; 
    91102else 
    92103  i2min=[]; 
     
    94105end 
    95106if ~isempty(i3) 
    96   i3min=min(i3)-1; 
    97   i3max=max(i3)-1; 
     107  i3min=min(i3)-decal; 
     108  i3max=max(i3)-decal; 
    98109else 
    99110  i3min=[]; 
     
    101112end 
    102113% 
    103 jmin=min(j)-1; 
    104 jmax=max(j)-1; 
     114jmin=min(j)-decal; 
     115jmax=max(j)-decal; 
    105116jrange=['[',num2str(jmin),':',num2str(jmax),']']; 
    106117 
  • Roms_tools/Aforc_NCEP/make_NCEP.m

    r1 r7  
    22% 
    33%  make_NCEP.m 
    4 %  
     4% 
    55%  Create and fill frc and bulk files with NCEP data. 
    66%  (NCEP Reanalysis) 
     
    88%  The on-line reference to NCEP is at 
    99%  http://www.cdc.noaa.gov/cdc/reanalysis/ 
    10 %  
    11 %  Further Information:   
     10% 
     11%  Further Information: 
    1212%  http://www.brest.ird.fr/Roms_tools/ 
    13 %   
     13% 
    1414%  This file is part of ROMSTOOLS 
    1515% 
     
    2929%  MA  02111-1307  USA 
    3030% 
    31 %  Copyright (c) 2005-2006 by Pierrick Penven  
    32 %  e-mail:Pierrick.Penven@ird.fr   
    33 %  
     31%  Copyright (c) 2005-2006 by Pierrick Penven 
     32%  e-mail:Pierrick.Penven@ird.fr 
     33% 
    3434%  Adapted from a previous verions from 
    3535%  Alvaro Peliz (U. Aveiro) & Patrick Marchesiello (IRD) - 2005 
     
    4848% 
    4949if NCEP_version==1 
    50   frc_prefix=[frc_prefix,'_NCEP1_'];                            
     50  frc_prefix=[frc_prefix,'_NCEP1_']; 
    5151  blk_prefix=[blk_prefix,'_NCEP1_']; 
    5252elseif NCEP_version==2 
    53   frc_prefix=[frc_prefix,'_NCEP2_'];                            
     53  frc_prefix=[frc_prefix,'_NCEP2_']; 
    5454  blk_prefix=[blk_prefix,'_NCEP2_']; 
    5555end 
     
    103103  disp(['====================']) 
    104104  download_NCEP(Ymin,Ymax,Mmin,Mmax,lonmin,lonmax,latmin,latmax,... 
    105                 NCEP_dir,NCEP_version,Yorig,Get_My_Data,My_NCEP_dir) 
     105                NCEP_dir,NCEP_version,Yorig,Get_My_Data,My_NCEP_dir) 
    106106  disp(['=====================']) 
    107107  disp(['DOWNLOAD STEP FINISH']) 
     
    125125  lat1=nc{'lat'}(:); 
    126126  [lon1,lat1]=meshgrid(lon1,lat1); 
    127    
     127 
    128128  if Get_My_Data~=1 
    129129    mask=1-squeeze(nc{'landsfc'}(:)); 
     
    131131    mask=1-squeeze(nc{'land'}(:)); 
    132132  end 
    133   mask(mask==0)=NaN;   
     133  mask(mask==0)=NaN; 
    134134  close(nc); 
    135    
     135 
    136136  % 
    137137  %Loop on the years and the months 
     
    144144  % 
    145145  for Y=Ymin:Ymax 
    146     if Y==Ymin  
     146    if Y==Ymin 
    147147      mo_min=Mmin; 
    148148    else 
     
    157157      disp(' ') 
    158158      disp(['Processing  year ',num2str(Y),... 
    159             ' - month ',num2str(M)]) 
     159            ' - month ',num2str(M)]) 
    160160      disp(' ') 
    161161      % 
     
    164164      if Get_My_Data~=1 
    165165        nc=netcdf([NCEP_dir,'tmp2m_Y',num2str(Y),'M',num2str(M),'.nc']); 
    166       elseif Get_My_Data==1    
     166      elseif Get_My_Data==1 
    167167        nc=netcdf([NCEP_dir,'prate_Y',num2str(Y),'M',num2str(M),'.nc']); 
    168168      end 
     
    180180      disp(['tlen=',num2str(tlen)]) 
    181181      disp(['Overlap is ',num2str(itolap_ncep),' it of 6 hours']) 
    182       disp(['Overlap is ',num2str(itolap_ncep/4),' days before and after'])      
     182      disp(['Overlap is ',num2str(itolap_ncep/4),' days before and after']) 
    183183      time=0*(1:tlen); 
    184       time(itolap_ncep+1:tlen0+itolap_ncep)=NCEP_time;    
     184      time(itolap_ncep+1:tlen0+itolap_ncep)=NCEP_time; 
    185185      disp(['=====================']) 
    186186      disp('Compute time for roms file') 
    187187      disp(['=====================']) 
    188188      for aa=1:itolap_ncep 
    189         time(aa)=time(itolap_ncep+1)-(itolap_ncep+1-aa)*dt; 
    190       end 
    191        
     189        time(aa)=time(itolap_ncep+1)-(itolap_ncep+1-aa)*dt; 
     190      end 
     191 
    192192      for aa=1:itolap_ncep 
    193193        time(tlen0+itolap_ncep+aa)=time(tlen0+itolap_ncep)+aa*dt; 
     
    199199      % Create the ROMS forcing files 
    200200      blkname=[blk_prefix,'Y',num2str(Y),... 
    201                'M',num2str(M),nc_suffix]; 
     201               'M',num2str(M),nc_suffix]; 
    202202      frcname=[frc_prefix,'Y',num2str(Y),... 
    203                'M',num2str(M),nc_suffix]; 
     203               'M',num2str(M),nc_suffix]; 
    204204      if makeblk==1 
    205         disp(['Create a new bulk file: ' blkname]) 
    206         create_bulk(blkname,grdname,ROMS_title,time,0); 
     205        disp(['Create a new bulk file: ' blkname]) 
     206        create_bulk(blkname,grdname,ROMS_title,time,0); 
    207207        disp([' ']) 
    208208      end 
    209209      if makefrc==1 
    210         disp(['Create a new forcing file: ' frcname]) 
     210        disp(['Create a new forcing file: ' frcname]) 
    211211        disp([' ']) 
    212         create_forcing(frcname,grdname,ROMS_title,... 
    213                        time,0,0,... 
    214                        0,0,0,... 
    215                        0,0,0,0,0,0) 
     212        create_forcing(frcname,grdname,ROMS_title,... 
     213                       time,0,0,... 
     214                       0,0,0,... 
     215                       0,0,0,0,0,0) 
    216216      end 
    217217      % 
     
    219219      % 
    220220      if add_tides==1 
    221         add_tidal_data(tidename,grdname,frcname,Y,M) 
     221        add_tidal_data(tidename,grdname,frcname,Y,M) 
    222222      end 
    223223      % 
    224224      % Open the ROMS forcing files 
    225225      if makefrc==1 
    226         nc_frc=netcdf(frcname,'write'); 
     226        nc_frc=netcdf(frcname,'write'); 
    227227      else 
    228         nc_frc=[]; 
     228        nc_frc=[]; 
    229229      end 
    230230      if makeblk==1 
    231         nc_blk=netcdf(blkname,'write'); 
     231        nc_blk=netcdf(blkname,'write'); 
    232232      else 
    233         nc_blk=[]; 
     233        nc_blk=[]; 
    234234      end 
    235235      % 
     
    238238      Ym=Y; 
    239239      if Mm==0 
    240         Mm=12; 
    241         Ym=Y-1; 
    242       end 
    243        
     240        Mm=12; 
     241        Ym=Y-1; 
     242      end 
     243 
    244244      if Get_My_Data~=1 
    245245        fname = [NCEP_dir,'tmp2m_Y',num2str(Ym),'M',num2str(Mm),'.nc']; 
    246246        nc=netcdf([NCEP_dir,'tmp2m_Y',num2str(Ym),'M',num2str(Mm),'.nc']); 
    247          
     247 
    248248      elseif Get_My_Data==1 
    249249        fname = [NCEP_dir,'prate_Y',num2str(Ym),'M',num2str(Mm),'.nc']; 
     
    253253      disp(' ') 
    254254      disp('======================================================') 
    255       disp('Perform interpolations for the previous month')       
     255      disp('Perform interpolations for the previous month') 
    256256      disp('======================================================') 
    257257      disp(' ') 
    258258      if exist(fname)==0 
    259         disp(['No data for the previous month: using current month']) 
    260         tndx=1; 
    261         Mm=M; 
    262         Ym=Y; 
     259        disp(['No data for the previous month: using current month']) 
     260        tndx=1; 
     261        Mm=M; 
     262        Ym=Y; 
    263263      else 
    264         nc=netcdf(fname); 
    265         tndx=length(nc('time')); 
     264        nc=netcdf(fname); 
     265        tndx=length(nc('time')); 
    266266        if makefrc==1 
    267           for aa=1:itolap_ncep 
     267          for aa=1:itolap_ncep 
    268268            nc_frc{'sms_time'}(aa)=nc{'time'}(tndx-(itolap_ncep-aa)); 
    269269          end 
    270270        end 
    271271        % 
    272         if makeblk==1 
    273           for aa=1:itolap_ncep 
     272        if makeblk==1 
     273          for aa=1:itolap_ncep 
    274274            nc_blk{'bulk_time'}(aa)=nc{'time'}(tndx-(itolap_ncep-aa)); 
    275275          end 
    276         end 
     276        end 
    277277        close(nc) 
    278278      end 
     
    281281      % 
    282282      for aa=1:itolap_ncep 
    283         aa0=itolap_ncep-aa;  
     283        aa0=itolap_ncep-aa; 
    284284        interp_NCEP(NCEP_dir,Ym,Mm,Roa,interp_method,lon1,lat1,... 
    285                     mask,tndx-aa0,nc_frc,nc_blk,lon,lat,angle,aa,Get_My_Data) 
    286       end   
    287       %######################################################################       
    288       %    
     285                    mask,tndx-aa0,nc_frc,nc_blk,lon,lat,angle,aa,Get_My_Data) 
     286      end 
     287      %###################################################################### 
     288      % 
    289289      disp(' ') 
    290290      disp('======================================================') 
     
    297297 
    298298      for tndx=1:tlen0 
    299         if mod(tndx,20)==0 
    300           disp(['Step: ',num2str(tndx),' of ',num2str(tlen0)]) 
    301         end 
     299        if mod(tndx,20)==0 
     300          disp(['Step: ',num2str(tndx),' of ',num2str(tlen0)]) 
     301        end 
    302302        interp_NCEP(NCEP_dir,Y,M,Roa,interp_method,lon1,lat1,... 
    303                     mask,tndx,nc_frc,nc_blk,lon,lat,angle,tndx+itolap_ncep,Get_My_Data)  
    304       end 
    305  
    306       disp(' ')       
    307       disp('======================================================') 
    308       disp('Perform interpolations for next month')     
     303                    mask,tndx,nc_frc,nc_blk,lon,lat,angle,tndx+itolap_ncep,Get_My_Data) 
     304      end 
     305 
     306      disp(' ') 
     307      disp('======================================================') 
     308      disp('Perform interpolations for next month') 
    309309      disp('======================================================') 
    310310      disp(' ') 
     
    314314      Mp=M+1; 
    315315      Yp=Y; 
     316      % 
     317      % Perform the interpolations for the next month 
     318      % 
     319      disp('Last steps') 
    316320      if Mp==13 
    317         Mp=1; 
    318         Yp=Y+1; 
    319       end 
    320        
     321        Mp=1; 
     322        Yp=Y+1; 
     323      end 
     324 
    321325      if Get_My_Data~=1 
    322326        fname=[NCEP_dir,'tmp2m_Y',num2str(Yp),'M',num2str(Mp),'.nc']; 
     
    324328        fname=[NCEP_dir,'prate_Y',num2str(Yp),'M',num2str(Mp),'.nc']; 
    325329      end 
    326        
     330 
    327331      if exist(fname)==0 
    328         disp(['No data for the next month: using current month']) 
    329         tndx=tlen0; 
    330         Mp=M; 
    331         Yp=Y; 
     332        disp(['No data for the next month: using current month']) 
     333        tndx=tlen0; 
     334        Mp=M; 
     335        Yp=Y; 
    332336      else 
    333337        nc=netcdf(fname); 
    334338        if makefrc==1 
    335339          disp('sms_time') 
    336           for tndx=tlen0+itolap_ncep:tlen; 
    337             nc_frc{'sms_time'}(tndx)=nc{'time'}(tndx-tlen0-(itolap_ncep-1)); 
     340          for tndx=tlen0+itolap_ncep+1:tlen; 
     341            nc_frc{'sms_time'}(tndx)=nc{'time'}(tndx-tlen0-itolap_ncep); 
    338342          end; 
    339343        end 
    340344        % 
    341         if makeblk==1 
     345        if makeblk==1 
    342346          disp('bulk_time') 
    343           for tndx=tlen0+itolap_ncep:tlen; 
    344             nc_blk{'bulk_time'}(tndx)=nc{'time'}(tndx-tlen0-(itolap_ncep-1)); 
    345           end; 
    346         end 
    347         close(nc) 
    348       end 
    349       % 
    350       % Perform the interpolations for the next month 
    351       % 
    352       disp('Last steps') 
     347          for tndx=tlen0+itolap_ncep+1:tlen; 
     348            nc_blk{'bulk_time'}(tndx)=nc{'time'}(tndx-tlen0-itolap_ncep); 
     349          end; 
     350        end 
     351        close(nc) 
     352      end 
     353      % 
    353354      for tndx=tlen0+itolap_ncep+1:tlen; 
    354         disp(['tndx= ',num2str(tndx)]) 
    355         tout=tndx; 
     355        disp(['tndx= ',num2str(tndx)]) 
     356        tout=tndx; 
    356357        disp(['tout=tndx ',num2str(tndx)]) 
    357         if Mp==M 
    358           tin=tlen0; % persistency if current month is used 
     358        if Mp==M 
     359          tin=tlen0; % persistency if current month is used 
    359360          disp(['tin=',num2str(tin)]) 
    360         else 
    361           tin=tndx-tlen0-itolap_ncep; 
     361        else 
     362          tin=tndx-tlen0-itolap_ncep; 
    362363          disp(['tin=',num2str(tin)]) 
    363         end 
    364         interp_NCEP(NCEP_dir,Yp,Mp,Roa,interp_method,lon1,lat1,... 
    365                     mask,tin,nc_frc,nc_blk,lon,lat,angle,tout,Get_My_Data)            
     364        end 
     365        interp_NCEP(NCEP_dir,Yp,Mp,Roa,interp_method,lon1,lat1,... 
     366                    mask,tin,nc_frc,nc_blk,lon,lat,angle,tout,Get_My_Data) 
    366367      end; 
    367368      % 
     
    369370      % 
    370371      if ~isempty(nc_frc) 
    371         close(nc_frc); 
     372        close(nc_frc); 
    372373      end 
    373374      if ~isempty(nc_blk) 
    374         close(nc_blk); 
     375        close(nc_blk); 
    375376      end 
    376377    end 
     
    382383% 
    383384disp('======================================================') 
    384 disp('Add spin up phase')       
     385disp('Add spin up phase') 
    385386if SPIN_Long>0 
    386387  M=Mmin-1; 
     
    389390    M=M+1; 
    390391    if M==13 
    391       M=1;  
     392      M=1; 
    392393      Y=Y+1; 
    393394    end 
     
    401402      frcname=[frc_prefix,'Y',num2str(Ymin),'M',num2str(M),nc_suffix]; 
    402403      frcname2=[frc_prefix,'Y',num2str(Y),'M',num2str(M),nc_suffix]; 
    403       disp(['Create ',frcname2])  
    404       eval(['!cp ',frcname,' ',frcname2])  
     404      disp(['Create ',frcname2]) 
     405      eval(['!cp ',frcname,' ',frcname2]) 
    405406      % 
    406407      % Change the time 
     
    424425      blkname=[blk_prefix,'Y',num2str(Ymin),'M',num2str(M),nc_suffix]; 
    425426      blkname2=[blk_prefix,'Y',num2str(Y),'M',num2str(M),nc_suffix]; 
    426       disp(['Create ',blkname2])  
    427       eval(['!cp ',blkname,' ',blkname2])  
     427      disp(['Create ',blkname2]) 
     428      eval(['!cp ',blkname,' ',blkname2]) 
    428429      % 
    429430      % Change the time 
     
    470471    test_forcing(frcname,grdname,'sustr',slides,3,coastfileplot) 
    471472    figure 
    472     test_forcing(frcname,grdname,'svstr',slides,3,coastfileplot)   
    473   end 
    474 end 
    475  
     473    test_forcing(frcname,grdname,'svstr',slides,3,coastfileplot) 
     474  end 
     475end 
     476 
Note: See TracChangeset for help on using the changeset viewer.