1 | #! /usr/bin/octave -qf |
---|
2 | |
---|
3 | # ----------------------------------------------- |
---|
4 | # mola_build.m |
---|
5 | # Script to be used with Matlab or GNU-Octave |
---|
6 | # ----------------------------------------------- |
---|
7 | # Purpose: |
---|
8 | # MOLA MEGDR binary file >> WRF geogrid tiles |
---|
9 | # Author: |
---|
10 | # A. Spiga - 03/2007 |
---|
11 | # ----------------------------------------------- |
---|
12 | |
---|
13 | # Locate MOLA binary file |
---|
14 | filename = 'megt00n180gb.img'; |
---|
15 | resolution = 32; |
---|
16 | |
---|
17 | # Read topographical data (MSB/big endian, 16-bits/2-bytes integer) |
---|
18 | f = fopen(filename,'r','ieee-be'); |
---|
19 | el = fread(f,[360*resolution Inf],'int16')'; |
---|
20 | |
---|
21 | # Get rid of negative values and flip North/South |
---|
22 | el = el + 9000; |
---|
23 | el = flipud(el); |
---|
24 | |
---|
25 | # Create 2 WRF data tiles for geogrid |
---|
26 | tile=180*resolution; |
---|
27 | # Eastern part |
---|
28 | part = el(1:1:tile,1:1:tile)'; |
---|
29 | # |
---|
30 | #just have to change the names ! |
---|
31 | #-- xrange - yrange |
---|
32 | fid = fopen('00001-05760.00001-05760','wb','b'); |
---|
33 | fwrite(fid,part,'integer*2'); |
---|
34 | |
---|
35 | # Western part |
---|
36 | part2 = el(1:1:tile,tile+1:1:2*tile)'; |
---|
37 | fid = fopen('05761-11520.00001-05760','wb','b'); |
---|
38 | fwrite(fid,part2,'integer*2'); |
---|
39 | |
---|
40 | # Check the resulting arrays |
---|
41 | yeah = part(1:300:tile,1:300:tile); |
---|
42 | yeah2 = part2(1:300:tile,1:300:tile); |
---|
43 | contour(yeah) |
---|
44 | contour(yeah2) |
---|