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
|
# File 'lib/directory_creator.rb', line 21
def self.subdirs_for_cmor_file(f)
names = %w(mip_era activity_id institution_id source_id experiment_id sub_experiment_id variant_label table_id variable_id grid_label creation_date)
ncdump_h_txt = %x(ncdump -h #{f})
global_attr_txt = ncdump_h_txt.split('// global attributes:').last
values = {}
names.each do |n|
match = /:#{n} = "(?<val>.*?)" ;/.match(global_attr_txt)
raise "can not find global attribute \"#{n}\"" unless match
values[n] = match[:val]
end
dir_templates = %w(mip_era activity_id institution_id source_id experiment_id member_id table_id variable_id grid_label version)
dir_names = dir_templates.map do |t|
if t == "member_id"
if(values['sub_experiment_id'] == "none")
values['variant_label']
else
"#{values['sub_experiment_id']}-#{values['variant_label']}"
end
elsif t == "version"
(Date.parse values['creation_date']).to_time.strftime "v%Y%m%d"
elsif t == "activity_id" values[t].split.first
else
values[t]
end
end
dir_names
end
|