12682
|
1 |
|
2 % Tutorial for using ncArray |
|
3 |
|
4 % It is advised to run this script in an empty directory. |
|
5 % It will delete and overwrite files named file1.nc, file2.nc and file3.nc. |
|
6 |
|
7 % size of the example data (2x3) |
|
8 |
|
9 n = 3; |
|
10 m = 2; |
|
11 |
|
12 % create 3 files (file1.nc, file2.nc,...) with a 2x3 variable called SST |
|
13 data = zeros(n,m); |
|
14 |
|
15 disp('create example files: file1.nc, file2.nc, file3.nc') |
|
16 |
|
17 for i = 1:3 |
|
18 data(:) = i; |
|
19 files{i} = sprintf('file%d.nc',i); |
|
20 delete(files{i}); |
|
21 ncarray_example_file(files{i},data); |
|
22 end |
|
23 |
|
24 |
|
25 % Using ncArray |
|
26 |
|
27 SST = ncArray('file1.nc','SST'); |
|
28 |
|
29 disp('load the entire file') |
|
30 data = SST(:,:,:); |
|
31 |
|
32 disp('get the attribute units') |
|
33 units = SST.units; |
|
34 |
|
35 |
|
36 disp('load a particular value'); |
|
37 data = SST(3,2,1); |
|
38 |
|
39 % Using ncCatArray |
|
40 |
|
41 disp('concatenate the files over the 3rd dimension (here time)') |
|
42 |
|
43 SST = ncCatArray(3,{'file1.nc','file2.nc','file3.nc'},'SST'); |
|
44 |
|
45 % or just |
|
46 % SST = ncCatArray(3,'file*.nc','SST'); |
|
47 |
|
48 disp('load all 3 files'); |
|
49 data = SST(:,:,:); |
|
50 |
|
51 disp('load a particular value (1,2,1) of the 3rd file'); |
|
52 data = SST(1,2,3); |