/[MITgcm]/MITgcm_contrib/eh3/regrid/scrip_examples/remap_grid_LL128x64.m
ViewVC logotype

Contents of /MITgcm_contrib/eh3/regrid/scrip_examples/remap_grid_LL128x64.m

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


Revision 1.1 - (show annotations) (download)
Thu Aug 10 05:00:16 2006 UTC (19 years ago) by edhill
Branch: MAIN
CVS Tags: HEAD
initial ci

1 %
2 % %Id: $
3 %
4 % Ed Hill
5 %
6 % Create a netCDF file defining a global Lat-Lon grid for SCRIP.
7
8 clear all
9 close all
10
11 debug_lev = 0;
12
13 %
14 % JMC wants: 128x64
15 %
16 nlat = 64;
17 nlon = 128;
18 latcell = 180/nlat;
19 loncell = 360/nlon;
20 lat = linspace(-90+latcell/2, 90-latcell/2, nlat);
21 %
22 % Note: the APE grid needs to be [0, MAX_EAST]
23 % lon = linspace(-180+loncell/2, 180-loncell/2, nlon);
24 lon = linspace(0+loncell/2, 360-loncell/2, nlon);
25
26 dlat_t = diff(lat);
27 dlon_t = diff(lon);
28 dlat = 0.5*( [dlat_t(1) ; dlat_t(:)] + ...
29 [dlat_t(:) ; dlat_t(length(dlat_t))] );
30 dlon = 0.5*( [dlon_t(1) ; dlon_t(:)] + ...
31 [dlon_t(:) ; dlon_t(length(dlon_t))] );
32 clear dlat_t dlon_t
33
34 grid_size = nlat*nlon;
35 grid_rank = 2;
36 grid_corners = 4;
37
38 ! rm -f remap_grid_LL128x64.cdf
39
40 nc = netcdf(['remap_grid_LL128x64.cdf'], 'clobber');
41 nc.title = 'Global 2-degree Lat-Lon grid';
42 nc.author = 'Ed Hill';
43 nc('grid_size') = grid_size;
44 nc('grid_rank') = grid_rank;
45 nc('grid_corners') = grid_corners;
46
47 nc{'grid_dims'} = ncint('grid_rank');
48 nc{'grid_dims'}(:) = [ length(lon) length(lat) ];
49
50 nc{'grid_imask'} = ncint('grid_size');
51 nc{'grid_imask'}(:) = ones(length(grid_size),1);
52
53 nc{'grid_center_lat'} = ncdouble('grid_size');
54 nc{'grid_center_lon'} = ncdouble('grid_size');
55 nc{'grid_center_lat'}.units = 'degrees';
56 nc{'grid_center_lon'}.units = 'degrees';
57 nc{'grid_corner_lat'} = ncdouble('grid_size', 'grid_corners');
58 nc{'grid_corner_lon'} = ncdouble('grid_size', 'grid_corners');
59 nc{'grid_corner_lat'}.units = 'degrees';
60 nc{'grid_corner_lon'}.units = 'degrees';
61
62 cen_lat = zeros(grid_size,1);
63 cen_lon = zeros(grid_size,1);
64 cor_lat = zeros(grid_size,4);
65 cor_lon = zeros(grid_size,4);
66 j = 0;
67 for ilon = 1:length(lon)
68 for ilat = 1:length(lat)
69 j = j + 1;
70 latc = lat(ilat);
71 lonc = lon(ilon);
72 cen_lat(j) = latc;
73 cen_lon(j) = lonc;
74 % Note: grid points *MUST* be ordered CCW and here
75 % we start from the lower-left corner
76 da = dlat(ilat)/2.0;
77 do = dlon(ilon)/2.0;
78 cor_lat(j,:) = [ latc-da latc-da latc+da latc+da ];
79 cor_lon(j,:) = [ lonc-do lonc+do lonc+do lonc-do ];
80 % if debug_lev > 1
81 % pause(1)
82 % hold on
83 % plot([cor_lon(j,:) cor_lon(j,1)],...
84 % [cor_lat(j,:) cor_lat(j,1)],'o-g')
85 % plot(cen_lon(j),cen_lat(j),'xr')
86 % hold off
87 % end
88 end
89 end
90 nc{'grid_center_lat'}(:) = cen_lat;
91 nc{'grid_center_lon'}(:) = cen_lon;
92 nc{'grid_corner_lat'}(:) = cor_lat;
93 nc{'grid_corner_lon'}(:) = cor_lon;
94
95 close(nc)
96

  ViewVC Help
Powered by ViewVC 1.1.22