timport_php_file.m - cosmo - front and backend for Markov-Chain Monte Carlo inv… | |
git clone git://src.adamsgaard.dk/cosmo | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
timport_php_file.m (8593B) | |
--- | |
1 function [sample_id, name, email, ... | |
2 lat, long, ... | |
3 be_conc, al_conc, c_conc, ne_conc, ... | |
4 be_uncer, al_uncer, c_uncer, ne_uncer, ... | |
5 zobs, ... | |
6 be_prod_spall, al_prod_spall, c_prod_spall, ne_prod_spall, ... | |
7 be_prod_muon, al_prod_muon, c_prod_muon, ne_prod_muon, ... | |
8 rock_density, ... | |
9 epsilon_gla_min, epsilon_gla_max, ... | |
10 epsilon_int_min, epsilon_int_max, ... | |
11 t_degla_min, t_degla_max, ... | |
12 record, record_threshold_min, record_threshold_max, ... | |
13 nwalkers] = ... | |
14 import_php_file(filename, startRow, endRow) | |
15 | |
16 %% import_php_file.m | |
17 % Automatically generated using the `uiimport` tool in Matlab. | |
18 % If the output format in "uploadhistory.php" is changed, update this fi… | |
19 % accordingly. | |
20 % All columns are initially read as strings. Some of the columns (specif… | |
21 % by the col vector) are converted to numbers. | |
22 | |
23 %IMPORTFILE Import numeric data from a text file as column vectors. | |
24 % [SAMPLEID,NAME,EMAIL,LAT,LONG,BE_CONC,AL_CONC,C_CONC,NE_CONC,BE_UNCE… | |
25 % = IMPORTFILE(FILENAME) Reads data from text file FILENAME for the | |
26 % default selection. | |
27 % | |
28 % [SAMPLEID,NAME,EMAIL,LAT,LONG,BE_CONC,AL_CONC,C_CONC,NE_CONC,BE_UNCE… | |
29 % = IMPORTFILE(FILENAME, STARTROW, ENDROW) Reads data from rows STARTR… | |
30 % through ENDROW of text file FILENAME. | |
31 % | |
32 % Example: | |
33 % [sampleid,name,email,lat,long,be_conc,al_conc,c_conc,ne_conc,be_unce… | |
34 % = importfile('cosmo_pgpzvt',1, 1); | |
35 % | |
36 % See also TEXTSCAN. | |
37 | |
38 % Auto-generated by MATLAB on 2015/08/24 12:47:00 | |
39 | |
40 %% Initialize variables. | |
41 delimiter = '\t'; | |
42 if nargin<=2 | |
43 startRow = 1; | |
44 endRow = inf; | |
45 end | |
46 | |
47 %% Read columns of data as strings: | |
48 % For more information, see the TEXTSCAN documentation. | |
49 %formatSpec = '%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%[^… | |
50 formatSpec = '%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s… | |
51 | |
52 %% Open the text file. | |
53 fileID = fopen(filename,'r'); | |
54 | |
55 %% Read columns of data according to format string. | |
56 % This call is based on the structure of the file used to generate this | |
57 % code. If an error occurs for a different file, try regenerating the co… | |
58 % from the Import Tool. | |
59 dataArray = textscan(fileID, formatSpec, endRow(1)-startRow(1)+1, 'Delim… | |
60 for block=2:length(startRow) | |
61 frewind(fileID); | |
62 dataArrayBlock = textscan(fileID, formatSpec, endRow(block)-startRow… | |
63 for col=1:length(dataArray) | |
64 dataArray{col} = [dataArray{col};dataArrayBlock{col}]; | |
65 end | |
66 end | |
67 | |
68 %% Close the text file. | |
69 fclose(fileID); | |
70 | |
71 %% Convert the contents of columns containing numeric strings to numbers. | |
72 % Replace non-numeric strings with NaN. | |
73 raw = repmat({''},length(dataArray{1}),length(dataArray)-1); | |
74 for col=1:length(dataArray)-1 | |
75 raw(1:length(dataArray{col}),col) = dataArray{col}; | |
76 end | |
77 numericData = NaN(size(dataArray{1},1),size(dataArray,2)); | |
78 | |
79 % the columns in col are numeric] | |
80 for col=[6:29, 31:33] | |
81 % Converts strings in the input cell array to numbers. Replaced non-… | |
82 % strings with NaN. | |
83 rawData = dataArray{col}; | |
84 for row=1:size(rawData, 1); | |
85 % Create a regular expression to detect and remove non-numeric p… | |
86 % suffixes. | |
87 regexstr = '(?<prefix>.*?)(?<numbers>([-]*(\d+[\,]*)+[\.]{0,1}\d… | |
88 try | |
89 result = regexp(rawData{row}, regexstr, 'names'); | |
90 numbers = result.numbers; | |
91 | |
92 % Detected commas in non-thousand locations. | |
93 invalidThousandsSeparator = false; | |
94 if any(numbers==','); | |
95 thousandsRegExp = '^\d+?(\,\d{3})*\.{0,1}\d*$'; | |
96 if isempty(regexp(thousandsRegExp, ',', 'once')); | |
97 numbers = NaN; | |
98 invalidThousandsSeparator = true; | |
99 end | |
100 end | |
101 % Convert numeric strings to numbers. | |
102 if ~invalidThousandsSeparator; | |
103 numbers = textscan(strrep(numbers, ',', ''), '%f'); | |
104 numericData(row, col) = numbers{1}; | |
105 raw{row, col} = numbers{1}; | |
106 end | |
107 catch me | |
108 end | |
109 end | |
110 end | |
111 | |
112 | |
113 %% Split data into numeric and cell columns. | |
114 | |
115 % rows with numbers, check that range matches values in for loop l. 68 a… | |
116 % the list below | |
117 rawNumericColumns = raw(:, [6:29, 31:33]); | |
118 | |
119 % rows with strings | |
120 rawCellColumns = raw(:, [1:5, 30]); | |
121 | |
122 | |
123 %% Allocate imported array to column variable names | |
124 % use rawCellColumns(:, i) for text fields and | |
125 % cell2mat(rawNumericColumns(:, i)) for numeric fields | |
126 sample_id = rawCellColumns(:, 1); % 1 | |
127 name = rawCellColumns(:, 2); % 2 | |
128 email = rawCellColumns(:, 3); % 3 | |
129 lat = rawCellColumns(:, 4); % 4 | |
130 long = rawCellColumns(:, 5); % 5 | |
131 be_conc = cell2mat(rawNumericColumns(:, 1)); % 6 | |
132 al_conc = cell2mat(rawNumericColumns(:, 2)); % 7 | |
133 c_conc = cell2mat(rawNumericColumns(:, 3)); % 8 | |
134 ne_conc = cell2mat(rawNumericColumns(:, 4)); % 9 | |
135 be_uncer = cell2mat(rawNumericColumns(:, 5)); % 10 | |
136 al_uncer = cell2mat(rawNumericColumns(:, 6)); % 11 | |
137 c_uncer = cell2mat(rawNumericColumns(:, 7)); % 12 | |
138 ne_uncer = cell2mat(rawNumericColumns(:, 8)); % 13 | |
139 zobs = cell2mat(rawNumericColumns(:, 9)); % 14 | |
140 be_prod_spall = cell2mat(rawNumericColumns(:, 10)); % 15 | |
141 al_prod_spall = cell2mat(rawNumericColumns(:, 11)); % 16 | |
142 c_prod_spall = cell2mat(rawNumericColumns(:, 12)); % 17 | |
143 ne_prod_spall = cell2mat(rawNumericColumns(:, 13)); % 18 | |
144 be_prod_muon = cell2mat(rawNumericColumns(:, 14)); % 19 | |
145 al_prod_muon = cell2mat(rawNumericColumns(:, 15)); % 20 | |
146 c_prod_muon = cell2mat(rawNumericColumns(:, 16)); % 21 | |
147 ne_prod_muon = cell2mat(rawNumericColumns(:, 17)); % 22 | |
148 rock_density = cell2mat(rawNumericColumns(:, 18)); % 23 | |
149 epsilon_gla_min = cell2mat(rawNumericColumns(:, 19)); % 24 | |
150 epsilon_gla_max = cell2mat(rawNumericColumns(:, 20)); % 25 | |
151 epsilon_int_min = cell2mat(rawNumericColumns(:, 21)); % 26 | |
152 epsilon_int_max = cell2mat(rawNumericColumns(:, 22)); % 27 | |
153 t_degla_min = cell2mat(rawNumericColumns(:, 23)); % 28 | |
154 t_degla_max = cell2mat(rawNumericColumns(:, 24)); % 29 | |
155 record = rawCellColumns(:, 6); % 30 | |
156 record_threshold_min = cell2mat(rawNumericColumns(:, 25)); % 31 | |
157 record_threshold_max = cell2mat(rawNumericColumns(:, 26)); % 32 | |
158 nwalkers = cell2mat(rawNumericColumns(:, 27)); % 33 | |
159 | |
160 | |
161 %% Change units | |
162 be_conc = be_conc*1000.; % atoms/g to atoms/kg | |
163 al_conc = al_conc*1000.; % atoms/g to atoms/kg | |
164 c_conc = c_conc*1000.; % atoms/g to atoms/kg | |
165 ne_conc = ne_conc*1000.; % atoms/g to atoms/kg | |
166 | |
167 be_prod_spall = be_prod_spall*1000.; % atoms/g/yr to atoms/kg/yr | |
168 al_prod_spall = al_prod_spall*1000.; % atoms/g/yr to atoms/kg/yr | |
169 c_prod_spall = c_prod_spall*1000.; % atoms/g/yr to atoms/kg/yr | |
170 ne_prod_spall = ne_prod_spall*1000.; % atoms/g/yr to atoms/kg/yr | |
171 | |
172 be_prod_muon = be_prod_muon*1000.; % atoms/g/yr to atoms/kg/yr | |
173 al_prod_muon = al_prod_muon*1000.; % atoms/g/yr to atoms/kg/yr | |
174 c_prod_muon = c_prod_muon*1000.; % atoms/g/yr to atoms/kg/yr | |
175 ne_prod_muon = ne_prod_muon*1000.; % atoms/g/yr to atoms/kg/yr | |
176 | |
177 be_uncer = be_uncer/100.; % percent to fraction | |
178 al_uncer = al_uncer/100.; % percent to fraction | |
179 c_uncer = c_uncer/100.; % percent to fraction | |
180 ne_uncer = ne_uncer/100.; % percent to fraction | |
181 | |
182 epsilon_gla_min = epsilon_gla_min/1.0e6; % m/Myr to m/yr | |
183 epsilon_gla_max = epsilon_gla_max/1.0e6; % m/Myr to m/yr | |
184 epsilon_int_min = epsilon_int_min/1.0e6; % m/Myr to m/yr | |
185 |