File: gengeoid.m

package info (click to toggle)
rtklib 2.4.3%2Bdfsg1-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 41,796 kB
  • sloc: cpp: 51,592; ansic: 50,584; fortran: 987; makefile: 861; sh: 45
file content (46 lines) | stat: -rw-r--r-- 1,655 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function gengeoid(range,file)
% read geoid model file and generate c-source code

if nargin<1, range=[120,155,20,50]; end
if nargin<2, file='WW15MGH.GRD'; end

ofile='geoid.c';

[lat1,lat2,lon1,lon2,dy,dx]=textread(file,'%f %f %f %f %f %f',1);
lon=lon1:dx:lon2;
lat=lat1:dy:lat2;
nx=(lon2-lon1)/dx+1;;
ny=(lat2-lat1)/dy+1;

x=dlmread(file,'',1,0);
data=[];
for n=1:181:size(x,1)
    xx=reshape(x(n:n+180,1:8)',1,181*8);
    data=[data;xx(1:nx)];
end
data=flipud(data);
i=find(range(3)<=lat&lat<=range(4));
j=find(range(1)<=lon&lon<=range(2));

f=fopen(ofile,'w');
fprintf(f,'#define DLON   %.2f                 /* longitude increment (deg) */ \n',dx);
fprintf(f,'#define DLAT   %.2f                 /* latitude increment (deg) */ \n',dy);
fprintf(f,'static const double range[4];       /* geoid area range {W,E,S,N} (deg) */\n');
fprintf(f,'static const float geoid[%d][%d]; /* geoid heights (m) (lon x lat) */\n',length(j),length(i));
fprintf(f,'\n\n');
fprintf(f,'/*------------------------------------------------------------------------------\n');
fprintf(f,'* geoid heights (derived from %s)\n',file);
fprintf(f,'*-----------------------------------------------------------------------------*/\n');
fprintf(f,'static const double range[]={%.2f,%.2f,%.2f,%.2f};\n\n',range);
fprintf(f,'static const float geoid[%d][%d]={',length(j),length(i));
for m=1:length(j)
    fprintf(f,'{\n');
    for n=1:length(i)
        fprintf(f,'%7.3ff',data(i(n),j(m)));
        if n~=length(i), fprintf(f,','); end
        if mod(n,10)==0, fprintf(f,'\n'); end
    end
    if m==length(j), fprintf(f,'\n}'); else fprintf(f,'\n},'); end
end
fprintf(f,'};\n');
fclose(f);