Hello
The goal of the script below is to generate files p_test_50.txt...p_test_97.txt that contain 2 columns of data. Column one - day of month and column two - number of hours since the initial time. (An example of how I want this file to look is at the very bottom of the message.)
The files read in are named merge*.txt, an abbreviated example below the MATLAB script, contain dates of the month (28:30) in column 5 and hours 0 to 23 in column 6.
However, I need hours since the initial time (00 UTC on the 28th) for each of the layers (50...97). I add 24, 48 to the hours within each day respectively.
In the script below I want to empty the data into p_test_50.txt...p_test_97.txt with dlmwrite.
clear
output = cell(500000,2);
days = 28:30;
day_long = length(days);
day_col = cell(500000,1);
day_index = cell(500000,1);
day_hrs = cell(500000,1);
hrs_elapsed = cell(500000,1);
date_col = cell(500000,1);
hr_match = cell(500000,1);
hrs_files = cell(1,10);
hrs = {0 24 48};
hr_long = length(hrs);
layers = [50 55 63 70 74 77 84 89 96 97];
in_files = dir('merge*.txt');
numfiles = length(in_files);
concat_output = cell(500000, 2);
vals = cell(1,length(in_files));
for n = 1:numfiles
vals{n} = load(in_files(n).name);
for k = 1:day_long
day_index{n} = find(vals{n}(:,5) == days(k))
day_col{n} = length(day_index{n});
for m = 1:numel(hrs)
hr_match{n} = repmat(hrs{m}, [day_col{n} 1]);
end
end
day_hrs{n} = vals{n}(day_index{n},6);
hrs_elapsed{n} = hr_match{n} + day_hrs{n};
date_col{n} = vals{n}(day_index{n},5);
output{n} = horzcat(date_col{n}, hrs_elapsed{n});
concat_output{n} = vertcat(output{n});
hrs_files = ['p_test_' num2str(layers(n)) '.txt'];
dlmwrite(hrs_files, concat_output{n}, 'delimiter', '\t');
end
An example of what is inside the merge*.txt files is
-57.074 -54.274 2012 12 28 0 50 55.229 50.976 1
-56.964 -52.024 2012 12 28 1 50 55.448 56.578 1
-56.837 -50.167 2012 12 28 2 50 55.663 68.813 1
-56.705 -48.579 2012 12 28 22 50 55.878 72.782 1
-56.574 -47.198 2012 12 28 23 50 56.093 56.164 1
-56.442 -45.966 2012 12 29 0 50 56.311 42.186 1
-56.304 -44.856 2012 12 29 1 50 56.526 45.649 1
-56.171 -43.84 2012 12 29 2 50 56.745 40.301 1
-56.038 -42.897 2012 12 29 22 50 56.96 43.586 1
-55.906 -42.015 2012 12 29 23 50 57.175 52.751 1
-55.773 -41.179 2012 12 30 0 50 57.394 43.205 1
-55.64 -40.378 2012 12 30 1 50 57.608 54.079 1
-55.504 -39.609 2012 12 30 2 50 57.823 44.869 1
-55.366 -38.86 2012 12 30 22 50 58.042 44.154 1
-55.226 -38.124 2012 12 30 23 50 58.257 55.105 1
Inside of each p_test*.txt files should be
28 0
28 1
28 2
28 22
28 23
29 24
29 25
29 26
29 46
29 47
30 48
30 49
30 50
30 70
30 71
but instead these files erroneously starts with
30 48
30 49
30 50
30 70
30 71
.
.
.
How can I get the files to print properly? PLEASE HELP
Jonathan
The goal of the script below is to generate files p_test_50.txt...p_test_97.txt that contain 2 columns of data. Column one - day of month and column two - number of hours since the initial time. (An example of how I want this file to look is at the very bottom of the message.)
The files read in are named merge*.txt, an abbreviated example below the MATLAB script, contain dates of the month (28:30) in column 5 and hours 0 to 23 in column 6.
However, I need hours since the initial time (00 UTC on the 28th) for each of the layers (50...97). I add 24, 48 to the hours within each day respectively.
In the script below I want to empty the data into p_test_50.txt...p_test_97.txt with dlmwrite.
clear
output = cell(500000,2);
days = 28:30;
day_long = length(days);
day_col = cell(500000,1);
day_index = cell(500000,1);
day_hrs = cell(500000,1);
hrs_elapsed = cell(500000,1);
date_col = cell(500000,1);
hr_match = cell(500000,1);
hrs_files = cell(1,10);
hrs = {0 24 48};
hr_long = length(hrs);
layers = [50 55 63 70 74 77 84 89 96 97];
in_files = dir('merge*.txt');
numfiles = length(in_files);
concat_output = cell(500000, 2);
vals = cell(1,length(in_files));
for n = 1:numfiles
vals{n} = load(in_files(n).name);
for k = 1:day_long
day_index{n} = find(vals{n}(:,5) == days(k))
day_col{n} = length(day_index{n});
for m = 1:numel(hrs)
hr_match{n} = repmat(hrs{m}, [day_col{n} 1]);
end
end
day_hrs{n} = vals{n}(day_index{n},6);
hrs_elapsed{n} = hr_match{n} + day_hrs{n};
date_col{n} = vals{n}(day_index{n},5);
output{n} = horzcat(date_col{n}, hrs_elapsed{n});
concat_output{n} = vertcat(output{n});
hrs_files = ['p_test_' num2str(layers(n)) '.txt'];
dlmwrite(hrs_files, concat_output{n}, 'delimiter', '\t');
end
An example of what is inside the merge*.txt files is
-57.074 -54.274 2012 12 28 0 50 55.229 50.976 1
-56.964 -52.024 2012 12 28 1 50 55.448 56.578 1
-56.837 -50.167 2012 12 28 2 50 55.663 68.813 1
-56.705 -48.579 2012 12 28 22 50 55.878 72.782 1
-56.574 -47.198 2012 12 28 23 50 56.093 56.164 1
-56.442 -45.966 2012 12 29 0 50 56.311 42.186 1
-56.304 -44.856 2012 12 29 1 50 56.526 45.649 1
-56.171 -43.84 2012 12 29 2 50 56.745 40.301 1
-56.038 -42.897 2012 12 29 22 50 56.96 43.586 1
-55.906 -42.015 2012 12 29 23 50 57.175 52.751 1
-55.773 -41.179 2012 12 30 0 50 57.394 43.205 1
-55.64 -40.378 2012 12 30 1 50 57.608 54.079 1
-55.504 -39.609 2012 12 30 2 50 57.823 44.869 1
-55.366 -38.86 2012 12 30 22 50 58.042 44.154 1
-55.226 -38.124 2012 12 30 23 50 58.257 55.105 1
Inside of each p_test*.txt files should be
28 0
28 1
28 2
28 22
28 23
29 24
29 25
29 26
29 46
29 47
30 48
30 49
30 50
30 70
30 71
but instead these files erroneously starts with
30 48
30 49
30 50
30 70
30 71
.
.
.
How can I get the files to print properly? PLEASE HELP
Jonathan