forked from mlhutchins/LWPC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lwpc_generate.m
157 lines (111 loc) · 4.03 KB
/
lwpc_generate.m
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
% lwpc_generate generates LWPC tables at a given resolution
%
% Written by: Michael Hutchins
%% Start pools
if parallel_check
parallel_start;
end
ticL=tic;
%% Load current station data and list inactive stations in MATLAB indexing
stations
removed_stations = [2,4,9,13,14,23,32,34];
%% List of stations to process in WWLLN indexing
masterList = {[26],... %Flash5
[27],... %Flash6
[28],... %Flash7
[29,30]}; %Flash8
%% Get current computer name (if dividing between flashes)
[check,cName] = system('hostname');
if ~isempty(strfind(cName,'flash5'))
stationList = masterList{1};
elseif ~isempty(strfind(cName,'flash6'))
stationList = masterList{2};
elseif ~isempty(strfind(cName,'flash7'))
stationList = masterList{3};
elseif ~isempty(strfind(cName,'flash8'))
stationList = masterList{4};
else
fprintf('Wrong computer/hostname\n');
end
%% Initialize cell arrays
lookupDay=cell(size(station_loc,1),1);
lookupNight=lookupDay;
lookupDist=lookupDay;
%% Go through each station to generate tables
for n = 1 : length(stationList)%stations
i = stationList(n) + 1;
fprintf('%s Station Started : %g seconds \n',station_name{i},toc(ticL));
div=1;
long=(1:div:360)-181+div/2;
lat=(1:div:180)-91+div/2;
lookup_day = zeros(length(long),length(lat),11);
lookup_night = lookup_day;
lookup_dist = lookup_day;
if ~ismember(i,removed_stations)
parfor m = 1 : 11
day_temp = zeros(length(long),length(lat));
night_temp = day_temp;
dist_temp = day_temp;
for j = 1 : length(long);
for k = 1 : length(lat);
long1 = long(j);
lat1 = lat(k);
if m == 1;
[day_temp(j,k),dist_temp(j,k)] = ...
LWPCpar(m+7,lat1,long1,[2000,01,01,00,00],...
station_loc(i,1),station_loc(i,2),'day');
night_temp(j,k) =...
LWPCpar2(m+7,lat1,long1,[2000,01,01,00,00],...
station_loc(i,1),station_loc(i,2),'night');
else
day_temp(j,k) =...
LWPCpar(m+7,lat1,long1,[2000,01,01,00,00],...
station_loc(i,1),station_loc(i,2),'day');
night_temp(j,k) =...
LWPCpar2(m+7,lat1,long1,[2000,01,01,00,00],...
station_loc(i,1),station_loc(i,2),'night');
end
end
end
lookup_day(:,:,m) = day_temp;
lookup_night(:,:,m) = night_temp;
lookup_dist(:,:,m) = dist_temp;
fprintf('%s - %s - Frequency %g kHz Done : %g seconds \n',datestr(now),station_name{i},m+7,toc(ticL));
end
end
lookup_dist = squeeze(lookup_dist(:,:,1));
lookupDay{i}=lookup_day;
lookupNight{i}=lookup_night;
lookupDist{i}=lookup_dist;
lookupName{i}=station_name{i};
fprintf('%s Station Finished : %g seconds \n',station_name{i},toc(ticL));
lookup_day_single=squeeze(mean(lookup_day,3));
lookup_night_single=squeeze(mean(lookup_night,3));
fid=fopen(sprintf('lookup_day_temp_%02g.dat',i-1),'a+');
fprintf(fid,sprintf('%s - %s\n',station_name{i},datestr(now)));
for K=1:size(lookup_day_single,1);
fprintf(fid,'%g\t',lookup_day_single(K,:));
fprintf(fid,'\n');
end
fprintf(fid,'\n');
fclose all;
fid=fopen(sprintf('lookup_night_temp_%02g.dat',i-1),'a+');
fprintf(fid,sprintf('%s - %s\n',station_name{i},datestr(now)));
for K=1:size(lookup_night_single,1);
fprintf(fid,'%g\t',lookup_night_single(K,:));
fprintf(fid,'\n');
end
fprintf(fid,'\n');
fclose all;
fid=fopen(sprintf('lookup_dist_temp_%02g.dat',i-1),'a+');
fprintf(fid,sprintf('%s - %s\n',station_name{i},datestr(now)));
for K=1:size(lookup_dist,1);
fprintf(fid,'%g\t',lookup_dist(K,:));
fprintf(fid,'\n');
end
fprintf(fid,'\n');
fclose all;
end
%% Save .mat file as backup
save lookup_generate
fprintf('Lookup Update Complete : %g seconds \n',toc(ticL));